Re: [Tutor] (no subject). Ord and Chr query
--- John Carmona <[EMAIL PROTECTED]> wrote: > Ben I could not get your script working indentation? ___ Can't remember an address in your address book? Enter the first few letters and Address AutoComplete will automatically finish it. Get Yahoo! Mail http://uk.mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject). Ord and Chr query
To all that have answered, many thanks. I will check the tutorials that have been pointed out to me. I have also got the Dive into Python printed and I will start reading that one too pretty soon. I am off on holiday starting Tuesday so I won't have the time to study too much in the next couple of days (maybe at work if it is quiet...). Speak to you soon guys and thanks again JC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] all methods in a module
hello >>> import random >>> print random.setstate.__doc__ Restore internal state from object returned by getstate(). my question is " how can i loop through all the methods in a module and print out their '__doc__' content ? >>> for d in dir( random ): print random.???d???.__doc__ thanks jmcs3 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] all methods in a module
Johan Meskens CS3 jmcs3 wrote: > my question is > " how can i loop through all the methods in a module > and print out their '__doc__' content ? > > for d in dir( random ): > > print random.???d???.__doc__ print getattr(random, d).__doc__ in general you should be prepared to catch AttributeErrors (for items that don't have __doc__ attributes) but for random you are OK. BTW dir() will show all attributes, not just methods. You might want to try help(random) as well... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] all methods in a module
Hi! I've the following solution: >>> for d in [ "random." + d for d in dir(random)]: ... if callable( eval(d) ): ... print "%30s :\n\n %s" % ( d, eval( "%s.__doc__" % ( d))) ... random.Random : Random number generator base class used by bound module functions. HTH Ewald on Fri, 27 May 2005 12:46:46 +0100 "Johan Meskens CS3 jmcs3" <[EMAIL PROTECTED]> wrote : - Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > hello Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > >>> import random Johan Meskens CS3 jmcs3 > >>> print random.setstate.__doc__ Johan Meskens CS3 jmcs3 > Restore internal state from object returned by getstate(). Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > my question is Johan Meskens CS3 jmcs3 > " how can i loop through all the methods in a module Johan Meskens CS3 jmcs3 > and print out their '__doc__' content ? Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > >>> for d in dir( random ): Johan Meskens CS3 jmcs3 > print random.???d???.__doc__ Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > Johan Meskens CS3 jmcs3 > thanks Johan Meskens CS3 jmcs3 > jmcs3 Johan Meskens CS3 jmcs3 > ___ Johan Meskens CS3 jmcs3 > Tutor maillist - Tutor@python.org Johan Meskens CS3 jmcs3 > http://mail.python.org/mailman/listinfo/tutor Johan Meskens CS3 jmcs3 > --- end -- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] all methods in a module
Johan Meskens CS3 jmcs3 wrote: > hello > > >>> import random > >>> print random.setstate.__doc__ > Restore internal state from object returned by getstate(). > > > my question is > " how can i loop through all the methods in a module > and print out their '__doc__' content ? > > >>> for d in dir( random ): > print random.???d???.__doc__ >>> for d in dir( random ): print getattr( random, d ).__doc__ > > thanks > jmcs3 > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] all methods in a module
Johan Meskens CS3 jmcs3 wrote: > hello > > import random print random.setstate.__doc__ > > Restore internal state from object returned by getstate(). > > > my question is > " how can i loop through all the methods in a module > and print out their '__doc__' content ? > > for d in dir( random ): > > print random.???d???.__doc__ > > > thanks > jmcs3 Untest no-brainer with "eval", there might be better solutions: >>> import random >>> for d in dir(random): ... print eval('random.%s.__doc__' % d) HTH, Wolfram ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Eclipse and Member Function Availability
I am building a class and using a "main.py" script as the "driver" for testing. Where I am having problems is that the class is defined in another file ( say the class is "MyClass" and the file is "MyClass.py" that I am importing as a module. The problem itself ( not a major one ), is that when using autocomplete feature within Eclipse, where you type in the name of the module or a class and it lists the functions/variables that are available in a popup menu, it only shows the modules methods and variables. Hopefully this example will make things clear: -- import MyClass def main(): myObject = MyClass.MyClass """ Here I type in the name of the class, expecting a list of the classes member functions/etc to popup """ myObject. """<--- here I see a list of functions available to the module, not the class """ main() - Now, if I take all of the classes methods out of the class and make them global within the module file, then I can see all of them using the autocomplete function, however, doesn't this defeat the purpose of OO? Should I use a module instead of a class, and pretend the module is a class? This would make the autocomplete available but make it more difficult to migrate the code from Python to say, Java or C++. Any advice is welcome. Thank You, John A. Gooch Systems Administrator IT - Tools EchoStar Satellite L.L.C. 9601 S. Meridian Blvd. Englewood, CO 80112 Desk: 720-514-5708 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Formatted writing to a file
I am trying to write to a file multiple times before close. Using the following sequence: outfile = open(data_file, 'w' ) x=5 while x > 0 x = x - 1 datax is read from a file. outfile.write('%25s' %datax + "|\n") This loop will write 5 lines at column position 25. I later come back to the same code and want to write 5 more lines at column 50. My questions are: 1. how can I format outfile so i can write multiple lines and then apend multiple lines later before closing the file? 2. how can I make data formatting string '%25s' intiger (in this case 25) a variable? Thanks in advance. [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] all methods in a module
At 04:46 AM 5/27/2005, Johan Meskens CS3 jmcs3 wrote: hello >>> import random >>> print random.setstate.__doc__ Restore internal state from object returned by getstate(). my question is " how can i loop through all the methods in a module and print out their '__doc__' content ? >>> for d in dir( random ): print random.???d???.__doc__ The prior responses use dir(), requiring then the use of eval() to get the object. You can get the name and object directly from random.__dict__. The following comprehension seems to handle all the stuff in random's dict: methods = [name, str(object.__doc__) for name, object in random.__dict__.iteritems() if callable(object) and object.__doc__] Then you can iterate over methods and format/print as desired. Bob Gailer mailto:[EMAIL PROTECTED] 510 558 3275 home 720 938 2625 cell ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] two windows
I asked for help on my problem but unfortunately now help yet. I am trying to put up instructions for a board game and then have the person read and then proceed onto the game. The following is what I have that displays the instructions just fine but will not let the game proceed on to the board and the game.: The instruction section works fine and the game part works fine but not together. I guess I need the widget to have a button that allows the reader to proceed. Appreciate help as I am just learning. I am thinking that the widget doesn’t qualify as a screen. Gene import random, math from livewires import games, color from Tkinter import * SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 768 THE_SCREEN = games.Screen(SCREEN_WIDTH, SCREEN_HEIGHT) class Application(Frame): def __init__(self, master): """ Initialize the frame. """ Frame.__init__(self, master) self.grid() self.create_widgets() def create_widgets(self): """ Create button, text, and entry widgets. """ # create instruction label self.inst_lbl = Label(self, text = "Enter your Name, please") self.inst_lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W) # create label for name input self.pw_lbl = Label(self, text = "Name: ") self.pw_lbl.grid(row = 1, column = 0, sticky = W) # create entry widget to accept name self.pw_ent = Entry(self) self.pw_ent.grid(row = 1, column = 1, sticky = W) # create submit button self.submit_bttn = Button(self, text = "Submit", command = self.reveal) self.submit_bttn.grid(row = 2, column = 0, sticky = W) # create text widget to display message self.instruction_txt = Text(self, width = 65, height = 30, wrap = WORD) self.instruction_txt.grid(row = 3, column = 0, columnspan = 3, sticky = W) def reveal(self): """ Display message based on name. """ contents = self.pw_ent.get() if contents == "Joe": message = """ The rules of the game are: etc. etc. """ else: message = "That's not your first name, try again!" self.instruction_txt.delete(0.0, END) self.instruction_txt.insert(0.0, message) # main root = Tk() root.title("Name") root.geometry("1280x768") app = Application(root) my_screen = THE_SCREEN wall_image = games.load_image("board.jpg", transparent = False) my_screen.set_background(board_image) etc. etc. my_screen.mainloop() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] all methods in a module
Bob Gailer wrote: >> my question is >> " how can i loop through all the methods in a module >> and print out their '__doc__' content ? >> >> >>> for d in dir( random ): >> print random.???d???.__doc__ > > > The prior responses use dir(), requiring then the use of eval() to get > the object. eval() is not required, getattr() is a better solution as I showed in my previous reply. > You can get the name and object directly from random.__dict__. The > following comprehension seems to handle all the stuff in random's dict: > > methods = [name, str(object.__doc__) > for name, object in random.__dict__.iteritems() > if callable(object) and object.__doc__] For the general case it would be prudent to say if callable(object) and hasattr(object, '__doc__') and object.__doc__ so a missing docstring doesn't terminate the loop. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formatted writing to a file
>Content-Type: text/html; format=flowed > > [...] What a mess. You should to post to the list in plain text. Someone might take the time to weed through that for your question, but you will get a lot more help and a lot sooner if you just configure your mailer to send plain text. _ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Eclipse and Member Function Availability
>using autocomplete feature within Eclipse Are you using pydev? http://pydev.sourceforge.net/ Their website says: """ New Release: 0.9.3!! Wohooo!! Code completion Rules! Check it out! """ So apparently this is something they are actively working on. You may have an old version, or you may have found a bug. Maybe try the users forum there: http://sourceforge.net/forum/forum.php?forum_id=293649 _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Any Python interface to USPTO web site?
I have the need to run periodic searches on the US Patent and Trademark Office website, www.uspto.gov. Before I reinvent the wheel, I thought I'd check to see if anyone knew of such a beast. For instance, It's like to be able to pass an argument like one of these: an/"dis corporation" in/newmar-julie to http://patft.uspto.gov/netahtml/search-adv.htm and get a list of all the patents owned by Dis Corporation, or invented by the 1960s Catwoman actress; or pass a patent number like 4,150,505 to http://patft.uspto.gov/netahtml/srchnum.htm to bring up a particular patent. Then I want to be able to parse out the patent metadata, e.g. inventor names, dates filed and issued, etc. Has this already been done? The closest my google searches have turned up is http://hacks.oreilly.com/pub/h/1724 , but that turns out to be Perl rather than Python, and not quite dead-on anyway. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formatted writing to a file
> 1. how can I format outfile so i can write multiple lines > and then apend multiple lines later before closing the file? I think you mean add a new column to the existing lines? try something like line = line + '%25s' % newdata > 2. how can I make data formatting string '%25s' intiger (in this case 25) a variable? Just create the string outsoide the formatting line: fmtString = '%%ds' % width s = fmtString % data HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help: wget-- how does it work?
On Fri, 27 May 2005, Aaron Elbaz wrote: > First, I found the progress bar class from aspn > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/168639 > > This could be used to simulate wgets progress bar. What I'm trying to > figure out now is how one would stat a file as it was being downloaded > so that I can feed information to the progress bar, and what the most > optimal way to do this is? I use this for an app I have that reads the 27-meg Unihan.txt file; but I think I cheat and hardcode the 27-meg no. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formatted writing to a file
1. how can I format outfile so i can write multiple lines and then apend multiple lines later before closing the file? It sounds like you want to update the file in successive passes. This is hard or impossible. Your best bet is to read one file and write another. 2. how can I make data formatting string '%25s' intiger (in this case 25) a variable? Use %*s. Assuming width = 25: %25s' % 3 == '%*s' % (width, 3) Bob Gailer mailto:[EMAIL PROTECTED] 510 558 3275 home 720 938 2625 cell ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help: wget-- how does it work?
One of my favourite unix applications is wget. Thinking how easy (and fun) it might be to implement with pythons excellent librairies has led me to a few questions. First, I found the progress bar class from aspn http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/168639 This could be used to simulate wgets progress bar. What I'm trying to figure out now is how one would stat a file as it was being downloaded so that I can feed information to the progress bar, and what the most optimal way to do this is? I realize you could request the filesize if it was on an ftp server, and then use 'os' to check the filesize. But how would you do this with regular http? Are there any tricks the experts have? How does wget do it? -thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help: wget-- how does it work?
Aaron Elbaz wrote: > One of my favourite unix applications is wget. > > This could be used to simulate wgets progress bar. What I'm trying to > figure out now is how one would stat a file as it was being downloaded > so that I can feed information to the progress bar, and what the most > optimal way to do this is? You can get the content-length header from the object returned from urllib2.urlopen(): >>> import urllib2 >>> f=urllib2.urlopen('http://www.google.com') >>> f > >>> f.info() >>> i=f.info() >>> i.getheader('content-length') '1983' Now you can read the data in chunks (using f.read(n)) and update your status bar as you go. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] increment operator
Hello Is there a increment operator in python similar to c++ like so "SomeVariable++" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] increment operator
I find the following invaluable - maybe you will also. http://rgruet.free.fr/PQR24/PQR2.4.html Lee C On May 27, 2005, at 11:25 PM, Servando Garcia wrote: > Hello > Is there a increment operator in python similar to c++ > like so "SomeVariable++" > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] increment operator
At 08:25 PM 5/27/2005, Servando Garcia wrote: Is there an increment operator in python similar to c++ like SomeVariable++ No. Closest is SomeVariable += 1. Bob Gailer mailto:[EMAIL PROTECTED] 510 558 3275 home 720 938 2625 cell ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formatted writing to a file
At 02:58 PM 5/27/2005, Alan G wrote: > 1. how can I format outfile so i can write multiple lines > and then apend multiple lines later before closing the file? I think you mean add a new column to the existing lines? try something like line = line + '%25s' % newdata > 2. how can I make data formatting string '%25s' intiger (in this case 25) a variable? Just create the string outsoide the formatting line: fmtString = '%%ds' % width I think it should be '%%%ds' % width s = fmtString % data HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Bob Gailer mailto:[EMAIL PROTECTED] 510 558 3275 home 720 938 2625 cell ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor