From darnold02 at sprynet.com Thu Jan 1 01:17:34 2004 From: darnold02 at sprynet.com (don arnold) Date: Thu Jan 1 01:17:45 2004 Subject: [Tutor] Questor References: <20031230195457.54072.qmail@web13607.mail.yahoo.com> Message-ID: <070201c3d02e$f320c530$ce11ba3f@don2uvsu54fwiq> ----- Original Message ----- From: "moore william" To: "Python" Sent: Tuesday, December 30, 2003 1:54 PM Subject: [Tutor] Questor > Did anyone every find the anwser to Questor.py? Since no one has responded yet, I'll bite: What is Questor.py, and what was the question? Don From from_python_tutor at SSokolow.com Thu Jan 1 01:20:23 2004 From: from_python_tutor at SSokolow.com (SSokolow) Date: Thu Jan 1 01:20:25 2004 Subject: [Tutor] Modfying Proxy, HTTP 1.1, and chunked mode Message-ID: <3FF3BC27.9070201@SSokolow.com> I enjoy reading the Anime Addventure ( http://addventure.bast-enterprises.de ) but the sheer size of it makes it difficult to track where I've been. After finding that my usual method (write a CGI Proxy in Perl) was unsatisfactory, I decided to start into python. After a few failed attempts to write a proxy from scratch ( no surprise considering that it's my first project ), I managed to find Munchy by Neil Schemenauer and Tiny HTTP Proxy by Suzuki Hisao. I decided to use Tiny HTTP Proxy and I've completely commented the code (great learning experience) and made some improvements. I did manage to implement the non-expiring page history but I don't want to limit the proxy to HTTP 1.0 and I don't know of any easy way to modify a HTTP 1.1 chunked data stream. My goal is to wrap any link I've already visited in tags but all I can do so far is have the Python console print "You have already been to %s". *My question:* Is there any simple way to apply the requred changes to Tiny HTTP Proxy ( http://mail.python.org/pipermail/python-list/2003-June/168957.html ) or do I have to go with one of the more complicated proxies on sourceforge? I just want something that will give me a secondary non-expiring history list within the confines of addventure.bast-enterprises.de and provide a platform for some other features in the future. You can get the sources as http://leary.csoft.net/~ssokolow/python/pyAddWrap.zip since I thought that they were a little too long to be attached inline and I don't know what happens to attachments which are sent to the mailing list. (this is my first time on a mailing list of ANY kind) If you lose the URL, you can also just go to www.ssokolow.com and browse to the Python section. Thanks in advance and sorry for the length Stephan Sokolow From alan.gauld at blueyonder.co.uk Thu Jan 1 05:24:35 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 05:24:18 2004 Subject: [Tutor] Saving Data References: <20031230180835.74569.qmail@web13608.mail.yahoo.com> Message-ID: <005701c3d051$73f23f50$6401a8c0@xp> > I am lookign for a toutorial on how to save data > created in a program so that it can be used when the > parogram is started again. Try looking at the file handling topic in my tutor. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld From alan.gauld at blueyonder.co.uk Thu Jan 1 05:33:40 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 05:33:24 2004 Subject: [Tutor] mistake naming class References: <1072815723.7933.0.camel@quercus> Message-ID: <006601c3d052$b94b95a0$6401a8c0@xp> > class open(object): > def __init__(world, person, animal): > open('foo.txt', 'r') > > Any solutions other then renaming my class, because going through the > code looking for calls to class open is not going to be fun It might not be fun but you really should do it. Naming a class after a system name is a big problem(unless you really want to hide the system name and provide alternative functionality. Even then its probably better to do it with an alias. Conventionally class names start with an uppercase letter. If you had followed the convention this problem would not have arisen. As to changing it, use a search tool like grep to find all of the occurences. You will have to manually validate whether it should be a call to your class or to the system open() Incidentally its very unusualy to name a class after a verb. Objects are things so the class name is usually a noun. Are you sure you need a class and not just a function? Just a thought... [BTW there are several modules with an open function in them, but they are doing so deliberately, usualky with 'file-like' objects and are a good example of why you should never use the from foo import * style...] Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld From alan.gauld at blueyonder.co.uk Thu Jan 1 05:41:27 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 05:41:07 2004 Subject: [Tutor] Lambdas References: <1072815771.7933.2.camel@quercus> Message-ID: <006b01c3d053$cf3536e0$6401a8c0@xp> > Okay well I guess I chose I bad example for lambdas, but i cant find any > good tutorials on them on the web. They are covered briefly in my titor in the functional programming topic. But for a more in depth coverage you will need to turn to tutorials on Lisp/Scheme or other functional languages like Haskell. Thre is a also whole branch of math dedicated to this too, known as lamda calculus, and it is the theoretical underpinning of functional programming (and indeed most other programming styles too) It depends just how dep you want to go... > Where is an in depth tutorial on lambdas. Even though there not all that > necessary lambdas are fundamental and essential, but you don't need to use the work "lambda" to create one. In Python most function definitions can be thought of as a lambda: def f(x): return g(x) is identical to the lambda form f = lambda x: g(x) After either we can assign the function object to another variable: h = f and call h(5) or whatever. We can also pass the function object to another function as a parameter etc... So the only use of lambda in Python is for anonymous functions, and they can always be got around with traditional function declarations. But understanding the ideas behind lambdas is vitally important to understanding the principles of good programming, in any language. Alan G. From alan.gauld at blueyonder.co.uk Thu Jan 1 05:45:54 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 05:45:35 2004 Subject: [Tutor] writing a program in Python References: <20031230233033.26483.qmail@web12403.mail.yahoo.com> Message-ID: <007401c3d054$6e8bc5b0$6401a8c0@xp> > How do you actually write a program in Python? I know > how to use IDLE to manipulate data, but how do I write > several lines of code that goes out and does stuff. Can you give us an example of what you thoink of as a real program? Most real programs just "manipulate data". What do you think is missing? What else would you like to do? As for how to write the program physically, just use the File->New menu to create a blank text editor window. Type the code into that window and save it as a file of type .py. Double clicking the file in Explorer will run it. (You can also run it within Idle using the Edit->Run menu, which is handy when fixing bugs) HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld From alan.gauld at blueyonder.co.uk Thu Jan 1 05:48:30 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 05:48:09 2004 Subject: [Tutor] Looking for a Python IDE References: <742DADBF-3B28-11D8-9C38-00039314F97E@mac.com> Message-ID: <007901c3d054$cb6e2750$6401a8c0@xp> > hi everybody, can someone please suggest me a good python IDE for Mac > Os X ? There's nothing as good as Pythonwin that I've seen. You can run IDLE under X windows with some fussing around with Tcl/Tk and fink. But to be honest I just use the standard Mac IDE even though its a bit primitive. Mostly I use vim (or BBEdit) and just run the code from a Terminal session. Alan G From alan.gauld at blueyonder.co.uk Thu Jan 1 06:01:08 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 06:00:47 2004 Subject: [Tutor] Are there any free project to download for studying? References: <200312301324625.SM01292@chenren> Message-ID: <00dd01c3d056$8f1a0d80$6401a8c0@xp> > But I want to see what else Python can do. For serious projects go to sourceforge.net and search for projects where the development language is Python - there are dozens(hundreds?) > So I want to see other good programs and > project. If you want to read the code then a collection of smaller programs is found at the Useless Python website. It is explicitly aimed at providing beginners with little sample programs to study. Alan G. From alan.gauld at blueyonder.co.uk Thu Jan 1 06:03:26 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 06:03:04 2004 Subject: [Tutor] How to store key->multiple values? References: <5.2.0.9.0.20031230224251.02ce9df0@mbox.jaring.my> Message-ID: <00ea01c3d056$e1c477a0$6401a8c0@xp> > I thought of using a dictionary but I found that dictionary only allows one > value per key. But the value can be a list :-) > Can I use lists instead? How do I create a multidimensional > list or tuple? How would I insert the values into a > multidimensional list? Have a look at the Raw Materials topic in my tutor. Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld From matteolovatti at mac.com Thu Jan 1 08:03:46 2004 From: matteolovatti at mac.com (matteo) Date: Thu Jan 1 08:03:57 2004 Subject: [Tutor] Looking for a Python IDE In-Reply-To: <007901c3d054$cb6e2750$6401a8c0@xp> References: <742DADBF-3B28-11D8-9C38-00039314F97E@mac.com> <007901c3d054$cb6e2750$6401a8c0@xp> Message-ID: On 01/gen/04, at 11:48, Alan Gauld wrote: > >> hi everybody, can someone please suggest me a good python IDE for > Mac >> Os X ? > > There's nothing as good as Pythonwin that I've seen. > You can run IDLE under X windows with some fussing around > with Tcl/Tk and fink. > > But to be honest I just use the standard Mac IDE even though > its a bit primitive. Mostly I use vim (or BBEdit) and just run > the code from a Terminal session. Yesterday i've found this.. http://mail.python.org/pipermail/pythonmac-sig/2003-August/008468.html it's similar to the carbon versione but at least has syntax-coloring ! matteo. From brian at coolnamehere.com Thu Jan 1 08:22:00 2004 From: brian at coolnamehere.com (Brian Wisti) Date: Thu Jan 1 08:21:59 2004 Subject: [Tutor] Looking for a Python IDE In-Reply-To: <007901c3d054$cb6e2750$6401a8c0@xp> References: <742DADBF-3B28-11D8-9C38-00039314F97E@mac.com> <007901c3d054$cb6e2750$6401a8c0@xp> Message-ID: <3FF41EF8.2090801@coolnamehere.com> Hi, Alan Gauld wrote: >>hi everybody, can someone please suggest me a good python IDE for >> >> >Mac > > >>Os X ? >> >> > >There's nothing as good as Pythonwin that I've seen. >You can run IDLE under X windows with some fussing around >with Tcl/Tk and fink. > >But to be honest I just use the standard Mac IDE even though >its a bit primitive. Mostly I use vim (or BBEdit) and just run >the code from a Terminal session. > >Alan G > > > Thought I'd mention. There are a few sorts of options, if you are looking at the concept of fiddling with things: - http://pythonmac.org/wiki/XcodeIntegration Folks are working on integrating OS X 10.3's nifty XCode tool with Python. - http://homepages.cwi.nl/~jack/macpython/download.html This binary download of Python includes a Carbonized version of Tkinter and IDLE. No tweaking needed, but it's noticeably slow. I'm sure there are more options, but those popped right into my head. If you're feeling less bold, I'd go for the Carbonized MacPython. Kind Regards, Brian Wisti http://coolnamehere.com/ From ubabu at cse.iitk.ac.in Thu Jan 1 10:59:26 2004 From: ubabu at cse.iitk.ac.in (Uppala Babu) Date: Thu Jan 1 10:56:44 2004 Subject: [Tutor] Tkinter - How to get multilple windows In-Reply-To: <3FF41EF8.2090801@coolnamehere.com> Message-ID: I have one window which has some buttons and menus. On clicking the button , how can i get a new window which has some other buttons and menus. Window has "Options" button. On cliking it, i need one more window which has check boxes, buttons ..(widgets) etc. Can any one please tell me how to do it in Tkinter -- Babu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " Character is repeated habits and Only repeated habits can reform the Character " - Swami Vivekananda. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ U Babu M.Tech (Y211107) , CSE Indian Institute of Technology ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From alan.gauld at blueyonder.co.uk Thu Jan 1 13:29:38 2004 From: alan.gauld at blueyonder.co.uk (Alan Gauld) Date: Thu Jan 1 13:29:12 2004 Subject: [Tutor] Tkinter - How to get multilple windows References: Message-ID: <014901c3d095$3707fa00$6401a8c0@xp> > I have one window which has some buttons and menus. > On clicking the button, how can i get a new window > which has some other buttons and menus. Instantiate a new window object which inherits from TopLevel rather than a simple Frame. Alan g. From ubabu at cse.iitk.ac.in Thu Jan 1 13:42:36 2004 From: ubabu at cse.iitk.ac.in (Uppala Babu) Date: Thu Jan 1 13:39:45 2004 Subject: [Tutor] Tkinter - How to get multilple windows In-Reply-To: <014901c3d095$3707fa00$6401a8c0@xp> Message-ID: >> I have one window which has some buttons and menus. >> On clicking the button, how can i get a new window >> which has some other buttons and menus. >Instantiate a new window object which inherits from >TopLevel rather than a simple Frame. from Tkinter import * # Interface to TK Widgets #class which has the test button only #oncliking the test button i need the One more window but here it is coming befo class App(Frame): global quitButton , master def __init__(self, master=None): Frame.__init__(self,master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button(self,text="Test",command=self.openNew() self.quitButton.grid() def openNew(self): app1 = App1(self) app1.mainloop() #quit class class App1(Toplevel): def __init__(self,master=None): Toplevel.__init__(self,master) self.grid() self.createWidgets() def createWidgets(self): textButton = Button(self,text="Quit",command=self.quit) textButton.grid() app = App() #instance of the Application app.master.title("Sample program") app.mainloop() #wait for the events 1. I am getting two windows 2. I want only the object of APP1 to quit not the entire program. Can any please help me? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " Character is repeated habits and Only repeated habits can reform the Character " - Swami Vivekananda. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ U.Babu Parvathi Puram (village) Madhavaram - 1 (post) Sidhout (Mandal) Kadapa (Dist) AP - 516247 ---------------------------------------------------- Phones : 08589-270716(Home) 0512-2597592 (Off) Mail IDs: uppala_babu@yahoo.co.in ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From missive at hotmail.com Thu Jan 1 17:53:08 2004 From: missive at hotmail.com (Lee Harr) Date: Thu Jan 1 17:53:13 2004 Subject: [Tutor] Re: Tkinter - How to get multilple windows Message-ID: from Tkinter import * # Interface to TK Widgets #class which has the test button only #oncliking the test button i need the #One more window but here it is coming befo class App(Frame): global quitButton, master def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.createNewButton = Button(self, text="Create New Window", command=self.openNew) self.createNewButton.grid() self.quitButton = Button(self, text="Quit Application", command=self.quit) self.quitButton.grid() def openNew(self): self.app1 = App1(self) #app1.mainloop() #quit class class App1(Toplevel): def __init__(self, master=None): Toplevel.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): textButton = Button(self, text="Close This Window", command=self.destroy) textButton.grid() app = App() #instance of the Application app.master.title("Sample program") app.mainloop() #wait for the events _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail From klappnase at freenet.de Thu Jan 1 17:19:09 2004 From: klappnase at freenet.de (Michael Lange) Date: Thu Jan 1 19:45:15 2004 Subject: [Tutor] Tkinter - How to get multilple windows In-Reply-To: References: <014901c3d095$3707fa00$6401a8c0@xp> Message-ID: <20040101231909.7b477a94.klappnase@freenet.de> On Fri, 2 Jan 2004 00:12:36 +0530 (IST) Uppala Babu wrote: > >> I have one window which has some buttons and menus. > >> On clicking the button, how can i get a new window > >> which has some other buttons and menus. > > >Instantiate a new window object which inherits from > >TopLevel rather than a simple Frame. > > > > from Tkinter import * # Interface to TK Widgets > > > #class which has the test button only > #oncliking the test button i need the One more window but here it is > coming befo > class App(Frame): > global quitButton , master > def __init__(self, master=None): > Frame.__init__(self,master) > self.grid() > self.createWidgets() > > def createWidgets(self): > self.quitButton = > Button(self,text="Test",command=self.openNew() > self.quitButton.grid() > > > def openNew(self): > app1 = App1(self) > app1.mainloop() > > > #quit class > class App1(Toplevel): > def __init__(self,master=None): > Toplevel.__init__(self,master) > self.grid() > self.createWidgets() > > def createWidgets(self): > textButton = Button(self,text="Quit",command=self.quit) > textButton.grid() > app = App() #instance of the Application > app.master.title("Sample program") > app.mainloop() #wait for the events > > > > > 1. I am getting two windows > 2. I want only the object of APP1 to quit not the entire program. > > Can any please help me? > > > 1. In your createWidgets method you defined the button with the "command=self.openNew()" option; the brackets after "openNew" were the mistake, if the command option is specified this way, the command will be executed the moment the button is created. Use "command=self.openNew" instead. 2. The "quit" command exits the mainloop and "quits" the application this way; if you just want to "destroy" one widget (like a Toplevel window) use its "destroy" method instead: textButton = Button(self,text="Quit",command=self.destroy) (BTW , you do not need an own mainloop() for your Toplevel window as you defined in your App.openNew() method.) I hope this helps Good luck Michael From matteolovatti at mac.com Thu Jan 1 21:32:40 2004 From: matteolovatti at mac.com (matteo) Date: Thu Jan 1 21:32:48 2004 Subject: [Tutor] keeping the program alive Message-ID: hi everybody! i've put this in my small program, just to keep it running continuosly while 1: connect_to_server() #it does some things.. sleep(120) i execute the program with "python script.py &" it runs well for about 5 minutes but then it quits. how can i fix it ? thanks matteo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 344 bytes Desc: not available Url : http://mail.python.org/pipermail/tutor/attachments/20040102/e05df8e9/attachment.bin From missive at hotmail.com Thu Jan 1 22:18:40 2004 From: missive at hotmail.com (Lee Harr) Date: Thu Jan 1 22:18:45 2004 Subject: [Tutor] Re: keeping the program alive Message-ID: >i've put this in my small program, just to keep it running continuosly > >while 1: > connect_to_server() #it does some things.. > sleep(120) > >i execute the program with "python script.py &" >it runs well for about 5 minutes but then it quits. >how can i fix it ? We're going to need a bit more ... Try running it without the & and see if you get an error message. _________________________________________________________________ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail From from_python_tutor at SSokolow.com Fri Jan 2 02:55:13 2004 From: from_python_tutor at SSokolow.com (SSokolow) Date: Fri Jan 2 02:55:18 2004 Subject: [Tutor] Best way to alter sections of a string which match dictionary keys? Message-ID: <3FF523E1.6060702@SSokolow.com> I have a proxy which stores a list of URLs visited withing a certain server as keys in a dictionary and currently all the values are just set to 1 (I have some ideas for future expansion though.) Originally this was just because it was the easiest way to prevent duplication of entries. Example: {'/2048.html': 1, '/index.html': 1, '/1.html': 1} My problem is that I want to add beside every hyperlinked block of text which links to one of these URLs. A while ago when I made the Perl CGI version (aborted), the only way I could find was to waste resources using this code: while( ($key, $value)=each %viewedEpisodes) { $file=~s/(.*)(.*)/$1$5/ig; } which is roughly equivalent to: (I didn't have time to test this) for URL in viewedEpisodes|.keys() file = re.sub(r'||(?i)||(\1') |I could just use that code in Python (It would work, right?) but it would be a complete waste of processor cycles. What would be the best way to accomplish the task without wasting so much time looping? Thanks Stephan Sokolow From piir at earthlink.net Fri Jan 2 08:43:37 2004 From: piir at earthlink.net (Todd G. Gardner) Date: Fri Jan 2 08:43:42 2004 Subject: [Tutor] to/from binary to/from integer (i.e.'01010101' = 85) Message-ID: Hello everyone, I was wondering if anyone happens to know how to convert to/from binary to/from integer (i.e.'01010101' = 85) Thanks for any pointers, Todd From carroll at tjc.com Fri Jan 2 12:03:45 2004 From: carroll at tjc.com (Terry Carroll) Date: Fri Jan 2 12:03:51 2004 Subject: [Tutor] to/from binary to/from integer (i.e.'01010101' = 85) In-Reply-To: Message-ID: On Fri, 2 Jan 2004, Todd G. Gardner wrote: > I was wondering if anyone happens to know how to convert to/from binary > to/from integer (i.e.'01010101' = 85) Here's a quick and dirty, with no error checking: def binstring2dec(str): result = 0 for i in range(0,len(str)): result = (result*2)+(str[i]=="1") return result It just loops through the string, multiplying an accumulated result by two each time, and incrementing it when a 1 is detected. As I said, it does no error checking; it assumes that each character in the string is either a "1" or a "0", so a bug is that if you send it a noncompliant string, any non-1 character will be treated as a zero: >>> binstring2dec("01010101") 85 >>> binstring2dec("21212121") 85 >>> binstring2dec("x1x1x1x1") 85 Come to think of it, here's better one, that's a little cleaner (it doesn't depend on True == 1), and will choke on bad data: def binstring2dec(str): result = 0 lookup = {'0':0, '1':1} for i in range(0,len(str)): result = (result*2)+lookup[str[i]] return result >>> binstring2dec("01010101") 85 >>> binstring2dec("21212121") Traceback (most recent call last): File "", line 1, in ? File "bintest.py", line 11, in binstring2dec result = (result*2)+lookup[str[i]] KeyError: '2' -- Terry Carroll Santa Clara, CA carroll@tjc.com From darnold02 at sprynet.com Fri Jan 2 12:17:02 2004 From: darnold02 at sprynet.com (don arnold) Date: Fri Jan 2 12:17:54 2004 Subject: [Tutor] to/from binary to/from integer (i.e.'01010101' = 85) References: Message-ID: <018801c3d154$507a5b80$7710ba3f@don2uvsu54fwiq> ----- Original Message ----- From: "Todd G. Gardner" To: "Tutor@Python. Org" Sent: Friday, January 02, 2004 7:43 AM Subject: [Tutor] to/from binary to/from integer (i.e.'01010101' = 85) > Hello everyone, > > I was wondering if anyone happens to know how to convert to/from binary > to/from integer (i.e.'01010101' = 85) > > Thanks for any pointers, > > Todd The int() function will do the conversion from binary (and other bases) for you if you supply the optional base parameter: >>> int('1111111',2) 127 >>> int('001',2) 1 >>> int('17',8) 15 I _thought_ there was a function somewhere to convert an int to a binary string, but I couldn't find it. So, here's a function that will convert an int to string of any base up to 36: import string digits = string.digits + string.ascii_uppercase def convert(num, base): res = [] divisor = 1 while num >= divisor * base: divisor *= base remainder = num while divisor >= 1: index, remainder = divmod(remainder,divisor) res.append(digits[index]) divisor /= base res = ''.join(res) if int(res, base) != num: raise 'bad conversion!' return res if __name__ == '__main__': while 1: num = raw_input('number to convert: ') if num == '': break num = int(num) base = int(raw_input('base : ')) print '%d in base %d is %s' % (num, base, convert(num,base)) print [example output:] number to convert: 255 base : 2 255 in base 2 is 11111111 number to convert: 255 base : 16 255 in base 16 is FF number to convert: 255 base : 10 255 in base 10 is 255 number to convert: 255 base : 8 255 in base 8 is 377 number to convert: HTH, Don From carroll at tjc.com Fri Jan 2 12:43:20 2004 From: carroll at tjc.com (Terry Carroll) Date: Fri Jan 2 12:43:26 2004 Subject: [Tutor] to/from binary to/from integer (i.e.'01010101' = 85) In-Reply-To: <018801c3d154$507a5b80$7710ba3f@don2uvsu54fwiq> Message-ID: On Fri, 2 Jan 2004, don arnold wrote: > The int() function will do the conversion from binary (and other bases) > for you if you supply the optional base parameter: > > >>> int('1111111',2) > 127 Well, heck, that takes all the fun out of it. :-) -- Terry Carroll Santa Clara, CA carroll@tjc.com From bgailer at alum.rpi.edu Fri Jan 2 13:24:17 2004 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri Jan 2 13:24:26 2004 Subject: [Tutor] Best way to alter sections of a string which match dictionary keys? In-Reply-To: <3FF523E1.6060702@SSokolow.com> References: <3FF523E1.6060702@SSokolow.com> Message-ID: <6.0.0.22.0.20040102105052.034f56e0@mail.mric.net> At 12:55 AM 1/2/2004, SSokolow wrote: >I have a proxy which stores a list of URLs visited withing a certain >server as keys in a dictionary and currently all the values are just set >to 1 (I have some ideas for future expansion though.) Originally this was >just because it was the easiest way to prevent duplication of entries. > >Example: {'/2048.html': 1, '/index.html': 1, '/1.html': 1} > >My problem is that I want to add beside >every hyperlinked block of text which links to one of these URLs. A while >ago when I made the Perl CGI version (aborted), the only way I could find >was to waste resources using this code: > >while( ($key, $value)=each %viewedEpisodes) { > $file=~s/(.*)(.*)/$1 src="$imgDir\/check.png">$5/ig; >} > >which is roughly equivalent to: (I didn't have time to test this) > >for URL in viewedEpisodes|.keys() > file = re.sub(r'||(?i)||( src="' + imgDir + r'/check.png">\1') I am reluctant to answer this question (since it takes some time and energy to construct a thoughtful reply), but since no one else has... This question is hard to tackle for the following reasons. I hope you will be able to restructure the question so we can really help you, and that in the future you will be able to ask questions that are clear and to the point. 1) many of us do not know Perl. so including Perl code does not help us. 2) "I didn't have time to test this" is obvious since the code does not compile. Please either present tested code or ask questions without code. It is also unclear what you want from the vertical bars in the re match string (vertical bars are used as OR operators to separate regular expressions. 3) what would be most useful is to give us a before and after example e.g. '/2048.html becomes blahblahblah (I have no idea what the desired outcome is) 4) file is a built-in function. It is inadvisable to rebind the name to a string. >I could just use that code in Python (It would work, right?) but it would >be a complete waste of processor cycles. >What would be the best way to accomplish the task without wasting so much >time looping? 5) How much time is "wasted"? Did you measure it? Processing multiple items requires looping. The alternatives to for statements in Python is list comprehension and while. 6) usually we like to write code that does the job, then assess the efficiency aspect. Often the code we write does the job in less time than we thought, and is OK as is. Bob Gailer bgailer@alum.rpi.edu 303 442 2625 home 720 938 2625 cell -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.556 / Virus Database: 348 - Release Date: 12/26/2003 From anschau at shaw.ca Fri Jan 2 14:41:49 2004 From: anschau at shaw.ca (Anschau Gesicht) Date: Fri Jan 2 14:45:13 2004 Subject: [Tutor] Segmentation Fault Problem Message-ID: <20040102134149.54596999.anschau@shaw.ca> I continue on my endless(and seemingly futile)attempt to learn a programming language. Currently I'm attempting small scripts in Python/Tkinter. The particular script is a textbox script at follows #!/usr/lib/python2.2 from Tkinter import * from ScrolledText import * import sys def die(event): sys.exit(0) root = Tk() f = Frame(root) f.pack(expand=1, fill=BOTH) button = Button(f, width=25) button["text"] = "Button" button.bind("