From sheila@thinkspot.net Sun Apr 1 00:20:12 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 31 Mar 2001 16:20:12 -0800 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: References: <5F0FF742F1D@kserver.org> Message-ID: <738F32F4A49@kserver.org> On Sat, 31 Mar 2001 14:52:00 -0500, "Tim Peters" wrote about RE: [Tutor] Still confused about Python references/objects: :[Sheila King] :> ... :> However, just for illustration, I was trying to write a swap :> function. And, I thought that all parameters were passed by reference. : :"by reference" isn't really a useful concept in Python. People bring that :with them from other languages, and get into all sorts of trouble trying to :force it to fit. You're telling me! (I bring background experience from a few different languages: Pascal, Fortran, VB, C++, and they ALL behaved that way! It is so difficult to get used to this new way of thinking.) : Python is *simpler* than that. It's easier (in the end :) to think of argument-passing in Python as being "pass by object": :don't think of passing names, or pointers, or references, or even values, but :think of passing objects directly. OK... ...... :The other half of the story is that a statement of the form : : x = y : :is *not* an operation on objects, it's an operation on namespaces, and all it :means is "whatever object the name 'y' refers to at this moment, also give :that object the name 'x' (and in the local namespace, provided 'x' hasn't :been declared global)". : :Argument passing is exactly like : : x = y : :in all respects: the objects in the argument list are merely given names in :the called function's local namespace. The names they're given are, of :course, the function's formal argument names. ...... OK, so I think I get what you're saying. It sounds like, in order to have a function modify an object in the calling functions space, either it has to be a mutable object, or else I would (I think?) have to return the new version I want, and assign it to a name in the calling function's namespace ??? Does this sound right? So, now I think I know what I'm doing, and I try this: >>> def swap(two_tuple): x,y = two_tuple return y, x >>> a = 2 >>> b = 3 >>> print a, " ", b 2 3 >>> a,b = swap((a,b)) >>> print a, " ", b 3 2 >>> OK, I think I got it. The only way to think of a function as modifying something in the calling namespace, is either if it is a mutable object, or else it has to return the new object that I want to reference. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dyoo@hkn.eecs.berkeley.edu Sun Apr 1 04:37:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 31 Mar 2001 19:37:05 -0800 (PST) Subject: [Tutor] Timer? In-Reply-To: <3AC60E1A.4D6A1EC2@lindbergs.org> Message-ID: On Sat, 31 Mar 2001, VanL wrote: > > > > ### > > from Tkinter import * > > > > class BlinkingButton(Button): > > def __init__(self, master, **kwargs): > > Button.__init__(self, master, **kwargs) > > self.blinkerson = 1 > > self.blink() > > > > def blink(self): > > if self.blinkerson: > > self.flash() > > self.after(1000, self.blink) > > > > if __name__ == '__main__': > > root = Tk() > > BlinkingButton(root, text="Blinking Button!").pack() > > mainloop() > > ### > > I was testing out what you said and this code didn't work for me. It created a > button, but it didn't blink. > Do you know why? Hmm... the code is Python 2.0 specific, since I'm doing the call: Button.__init__(self, master, **kwargs) If this is what's causing problems, then let's replace it with something more compatible: apply(Button.__init__, [self, master], kwargs) They both do the same thing: they call the Button.__init__ function while giving the user lots of freedom to specify keyword arguments. However, I've only been able to test this on my Linux computer; has anyone else had success with this? From dyoo@hkn.eecs.berkeley.edu Sun Apr 1 04:45:36 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 31 Mar 2001 19:45:36 -0800 (PST) Subject: [Tutor] Scripts In-Reply-To: <005C01D254FAD411BF8800B0D03E0AB632F81D@MICROPHONE> Message-ID: On Fri, 30 Mar 2001, Larry Lam wrote: > How can I call and receive phone calls thru a modem using python scripts? > How to kill a telnet section with python? On a Unix computer, the modem is a serial device that can be opened like a file. On my system, it's '/dev/cua1' (COM2), so one way to send commands to the modem would be: ### modem = open('/dev/cua1', 'w') modem.write('ATZ\n') ### However, I don't have a modem anymore, so I'm unable to test any modem-like stuff at the moment. Windows, too, has support for serial-port communications, and there are a few modules available that might be helpful for you: http://www.vex.net/parnassus/apyllo.py?i=15173005 http://starship.python.net/crew/roger/ About closing a telnet session: assuming that the session was opened with telnetlib, you should be able to simply close() the connection, according to: http://python.org/doc/current/lib/telnet-objects.html Good luck to you! From tim.one@home.com Sun Apr 1 04:51:39 2001 From: tim.one@home.com (Tim Peters) Date: Sat, 31 Mar 2001 22:51:39 -0500 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <738F32F4A49@kserver.org> Message-ID: [Sheila King, on trying to understand Python via reference semantics] > You're telling me! (I bring background experience from a few different > languages: Pascal, Fortran, VB, C++, and they ALL behaved that > way! It is so difficult to get used to this new way of thinking.) If it's any consolation, those to whom Python is a first language have no trouble at all with it, and probably suffer even greater trying to keep track of the new mysteries that pop up when they move to other languages. The eff-bot (Fredrik Lundh) wrote a very nice and tiny intro, here: http://w1.132.telia.com/~u13208596/guides/python-objects.htm Check it out! The first instruction is vital, though: "Reset your brain.". Once you do, "the rules" are short and sweet (his writeup is less than one page of text, including examples). > ... > OK, so I think I get what you're saying. It sounds like, in order to > have a function modify an object in the calling functions space, either > it has to be a mutable object, or else I would (I think?) have to > return the new version I want, and assign it to a name in the calling > function's namespace ??? Yup! Note too that module-global objects are visible from *all* function and method namespaces, so that's another possibility: def f(): global x x = 42 y = 42 g(y) print x # happens to prints 666 print y # prints 42, and no matter *what* g() does def g(a): global x x = 666 f() But heavy use of globals is bad practice, in part precisely *because* any call can change global bindings at any time. You can see this in the body of f: you can't possibly guess what "print x" is going to do without tracking down and studying the source code for g, but you can be certain that "print y" will print 42 without looking at g. This makes the use of y much easier to understand in isolation, and the larger your programs get, the more valuable it is to limit the amount of code you need to examine. Local names and immutable objects can both help with that. > ... > So, now I think I know what I'm doing, and I try this: > > >>> def swap(two_tuple): > x,y = two_tuple > return y, x > > >>> a = 2 > >>> b = 3 > >>> print a, " ", b > 2 3 > >>> a,b = swap((a,b)) > >>> print a, " ", b > 3 2 > >>> Little-known feature: just like you can do x, y = two_tuple and Python will "magically" unpack the two_tuple into x and y, you can also do that in formal argument lists. So def swap((x, y)): return y, x also works. > OK, I think I got it. The only way to think of a function as modifying > something in the calling namespace, is either if it is a mutable > object, or else it has to return the new object that I want to > reference. Yes, and because (1) the called function simply has no access to its caller's namespace, and (2) there is no pointer type in Python, so you *can't* pass "a reference" to an object (btw, I think *that's* the fundamental reason why trying to think about Python in "call by reference" terms ends up confusing people: Python simply doesn't have references in that sense; I call it "call by object" to force people to break out of inappropriate mental models). you're-well-on-the-road-to-a-full-recovery-ly y'rs - tim From syrinx@simplecom.net Sun Apr 1 04:52:47 2001 From: syrinx@simplecom.net (Scott) Date: Sat, 31 Mar 2001 21:52:47 -0600 Subject: [Tutor] valid filenames Message-ID: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> Is there a Python module that contains a function that determines if a string is a valid filename? If not, can someone refresh my memory; what is a valid filename in Unix? I think it can be up to 255 characters, but which characters are disallowed? From dkstewaP@netscape.net Sun Apr 1 08:41:26 2001 From: dkstewaP@netscape.net (dkstewaP@netscape.net) Date: Sun, 01 Apr 2001 03:41:26 -0400 Subject: [Tutor] Help passing parameters to cancel callback (after_cancel) Message-ID: <26630645.5B2F134B.00978E7F@netscape.net> I am trying to build a demonstration/test module for process control application using Tkinter. I want to include a clock updating in one second intervals that can be started and stopped by the user (effictively a stop watch type application). My previous programming experience has been in various flavours of basic including VBA for quite complex applications in msWord and Excel. I am very confused as to how I pass the id parameter from the call to after() to the after_cancel() function. I think my problems are related to the scope of variables (namespaces in python) and how to refer to the variable in the various namespaces. The combination of using a class to define my functions and having to pass additional namespace info to Tkinter has really got me beat. My sample code follows (adapted from the hello word example in "An Introduction to Tkinter"). Any help to fix the code and to help me understand Python would be gratefully appreciated. David Brisbane, Australia # File: hello2.py """Display System Time String - potential GUI for stop watch or similar module Stop button should cleanly break out of the polling loop""" from Tkinter import * from time import * class App: def __init__(self, master): self.idn = 0 self.master = master frame = Frame(master, width = 512 , height = 256,) frame.pack() self.label = Label(frame, text="The system time is") self.label.place(relx=0.1, rely=0.2) self.label2 = Label(frame, text=" ", width = 36 , height = 1, relief=RAISED) self.label2.place(relx=0.5, rely=0.2) self.button = Button(frame, text="STOP", fg="red", command=self.stop(self.idn)) self.button.place(relx=0.5, rely=0.8) self.hi_there = Button(frame, text="Quit", command=sys.exit) self.hi_there.place(relx=0.7, rely=0.8) self.idn = self.poll() # start polling def stop(self, idn): self.master.after_cancel(idn) def poll(self): count = time() self.label2.configure(text=str(count)) nn = self.master.after(1000, self.poll) return nn root = Tk() app = App(root) root.mainloop() __________________________________________________________________ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/ From deirdre@deirdre.net Sun Apr 1 08:53:18 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sat, 31 Mar 2001 23:53:18 -0800 (PST) Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: <20010331102136.D4184@gandalf> Message-ID: On Sat, 31 Mar 2001, Aaron Mathews wrote: > On Fri, Mar 30, 2001 at 09:38:49AM -0500, Scott Ralph Comboni wrote: > > Does anyone now if there is a bugtracking tool like bugzilla written in > > Python? > > Not that I know of. Bugzilla is one on a *very* short list of open > source bugtracking systems. I personally would love to see bugzilla > reimplemented in python, it would be a heck of a lot easier to > customize (which I unfortunately have had to do during the last few > weeks). Modifying squirrely perl code is not exactly my idea of fun. > But then again, bugzilla works better than any of the alternatives > I've seen, so that's the way it goes. Actually, that's what HellDesk was, but it was never released. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From pdiaz88@terra.es Sun Apr 1 13:18:06 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sun, 1 Apr 2001 14:18:06 +0200 Subject: [Tutor] installing python 2.0 on redhat 7.0 In-Reply-To: <000b01c0b9b0$b4aea160$7001a8c0@sagga> References: <000b01c0b9b0$b4aea160$7001a8c0@sagga> Message-ID: <01040114180600.01550@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 31 March 2001 09:03, Steve A. wrote: > Hello. > > Seems that to install python 2.0 on redhat 7 I'll need to reinstall > glibc.. well, basically, considering all the file dependencies, it's just > not worth it. I'm wondering if anyone has installed python 2.0 or 2.1 on > redhat 7, and if there are any RPMS out there to make it a relatively > painless process. Otherwise it looks like I'm going to have to go back to > 6.2. argh! > > -Steve Well, in a normal situation I would advice you to compile the sources (not too dificult) but considering that RH 7.0 has an almost broken compiler and other security flaws, I think It would be better for you to go back to 6.2 or switch to another distro Cheers Pedro - ---------------------------------------- Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1" Content-Transfer-Encoding: quoted-printable Content-Description: - ---------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6xxyQnu53feEYxlERAkNAAJ9GfYrjULCJQ6NEuSheBi/RAywmbQCfVTsG fxXMyUisoZey4RTC9idrtG8= =Ubwv -----END PGP SIGNATURE----- From arcege@dsl254-114-246.nyc1.dsl.speakeasy.net Sun Apr 1 13:45:35 2001 From: arcege@dsl254-114-246.nyc1.dsl.speakeasy.net (Michael P. Reilly) Date: Sun, 1 Apr 2001 08:45:35 -0400 (EDT) Subject: [Tutor] valid filenames In-Reply-To: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> from "Scott" at Mar 31, 2001 09:52:47 PM Message-ID: <200104011245.f31CjZs08501@dsl254-114-246.nyc1.dsl.speakeasy.net> Scott wrote > Is there a Python module that contains a function that determines if a > string is a valid filename? If not, can someone refresh my memory; > what is a valid filename in Unix? I think it can be up to 255 > characters, but which characters are disallowed? Not one to say if a pathname/filename is "valid" specifically, but there is one to test if a file exists ('os.path.exists'). Filenames may contain any character except the slash (/, '\057\) and the null character ('\000'). Name components in a full pathname to a file are seperated by slashes (e.g. "/home/arcege/.login"). And in the language C, strings are terminated by the null character; an embedded null character would mean that most every program in UNIX would see a shortened filename. A UNIX filename can be just about anything, UNIX won't really care. Some utilities and scripting languages will have problems tho. Python will take "weird" filename as just another string and use it without problems (except that Python can embedded null characters). But in general, filenames can be kept to lower-case and upper-case characters, numerals and punctuation. You might want to look into the fnmatch module. :OT: There was a recent thread here about the "disadvantages of UNIX not evaluating filename extentions". UNIX evaluates nothing - a filename can be anything. It is up to the application to handle the file. There are utilities to determine file type (for example, file(1)), having the operating system determine this is detrimental to the power of UNIX. :OT: -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From rick@niof.net Sun Apr 1 15:18:32 2001 From: rick@niof.net (Rick Pasotto) Date: Sun, 1 Apr 2001 10:18:32 -0400 Subject: [Tutor] Help passing parameters to cancel callback (after_cancel) In-Reply-To: <26630645.5B2F134B.00978E7F@netscape.net>; from dkstewaP@netscape.net on Sun, Apr 01, 2001 at 03:41:26AM -0400 References: <26630645.5B2F134B.00978E7F@netscape.net> Message-ID: <20010401101832.Q26119@tc.niof.net> On Sun, Apr 01, 2001 at 03:41:26AM -0400, dkstewaP@netscape.net wrote: > I am trying to build a demonstration/test module for process control > application using Tkinter. I want to include a clock updating in one > second intervals that can be started and stopped by the user > (effictively a stop watch type application). My previous programming > experience has been in various flavours of basic including VBA for > quite complex applications in msWord and Excel. > > I am very confused as to how I pass the id parameter from the call to > after() to the after_cancel() function. I think my problems are > related to the scope of variables (namespaces in python) and how to > refer to the variable in the various namespaces. The combination of > using a class to define my functions and having to pass additional > namespace info to Tkinter has really got me beat. Your class is a namespace. Each instance of the class is a namespace. The easiest way to do what you want is to save the return value in self.return_value. Following is my version of a program that does what you want (and a little more). I've interspersed some comments. Note that you can't pass a parameter to a function specified in a 'command =' parameter. (At least not directly. You can fudge it with a lambda.) The reason is that 'command =' takes the *name* of a function not the function itself - thus there are no parens. #!/usr/bin/evn python from Tkinter import * import time # avoid possible name collisions class Main: def __init__(self,win): self.win = win self.lbl = Label(self.win,width=40,height=3,bg='lightpink') self.lbl.pack(padx=5,pady=5) frm = Frame(self.win) self.start = Button(frm,text='Start',command=self.do_start) self.start.pack(side=LEFT,padx=15,pady=5) self.stop = Button(frm,text='Stop',command=self.do_stop) self.stop.pack(side=LEFT,padx=15,pady=5) frm.pack() self.go = 0 # set a global to know whether or not the clock is running def do_start(self): if not self.go: self.go = 1 self.set_time() def set_time(self): self.lbl.config(text="\n%s" % time.ctime(time.time())) # time.time() returns the number of seconds since the epoch # formatting it looks nicer self.rtn = self.win.after(1000,self.set_time) print self.rtn # notice that the return value is different every time def do_stop(self): if self.go: self.go = 0 self.win.after_cancel(self.rtn) if __name__ == '__main__': root = Tk() main = Main(root) root.mainloop() > My sample code follows (adapted from the hello word example in "An > Introduction to Tkinter"). Any help to fix the code and to help me > understand Python would be gratefully appreciated. > > David > Brisbane, Australia > > # File: hello2.py > """Display System Time String - potential GUI for stop watch or similar module > > Stop button should cleanly break out of the polling loop""" > > from Tkinter import * > from time import * > > class App: > > def __init__(self, master): > > self.idn = 0 > self.master = master > frame = Frame(master, width = 512 , height = 256,) > frame.pack() > > self.label = Label(frame, text="The system time is") > self.label.place(relx=0.1, rely=0.2) > > self.label2 = Label(frame, text=" ", width = 36 , height = 1, relief=RAISED) > self.label2.place(relx=0.5, rely=0.2) > > self.button = Button(frame, text="STOP", fg="red", command=self.stop(self.idn)) > self.button.place(relx=0.5, rely=0.8) > > self.hi_there = Button(frame, text="Quit", command=sys.exit) > self.hi_there.place(relx=0.7, rely=0.8) > > self.idn = self.poll() # start polling > > def stop(self, idn): > self.master.after_cancel(idn) > > def poll(self): > count = time() > self.label2.configure(text=str(count)) > nn = self.master.after(1000, self.poll) > return nn > > root = Tk() > app = App(root) > root.mainloop() -- "Prohibition...goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation and makes a crime out things that are not crimes. A prohibition law strikes a blow at the very principles upon which our government was founded." -- Abraham Lincoln, Dec. 1840 Rick Pasotto email: rickp@telocity.com From lumbricus@gmx.net Sun Apr 1 16:02:57 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Sun, 1 Apr 2001 17:02:57 +0200 Subject: [Tutor] valid filenames In-Reply-To: <200104011245.f31CjZs08501@dsl254-114-246.nyc1.dsl.speakeasy.net>; from arcege@dsl254-114-246.nyc1.dsl.speakeasy.net on Sun, Apr 01, 2001 at 08:45:35AM -0400 References: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> <200104011245.f31CjZs08501@dsl254-114-246.nyc1.dsl.speakeasy.net> Message-ID: <20010401170257.B5874@Laplace.localdomain> Hi all!!! > But in general, filenames can be kept to lower-case and upper-case > characters, numerals and punctuation. You might want to look into the > fnmatch module. > U can avoid by not using names like -anything ^ names containing whitespace (this goes to m$-windoze and mac especially *grrrrrr*) and other special characters all allowed in UNIX but generally a bad idea. grreetings!! From lumbricus@gmx.net Sun Apr 1 15:44:45 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Sun, 1 Apr 2001 16:44:45 +0200 Subject: [Tutor] Scripts In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Sat, Mar 31, 2001 at 07:45:36PM -0800 References: <005C01D254FAD411BF8800B0D03E0AB632F81D@MICROPHONE> Message-ID: <20010401164445.A5874@Laplace.localdomain> Hello!!! > > > How can I call and receive phone calls thru a modem using python scripts? > > How to kill a telnet section with python? > > On a Unix computer, the modem is a serial device that can be opened like a > file. On my system, it's '/dev/cua1' (COM2), so one way to send commands ^^^^^^^^^^^ don't use this anymore (baeh bah !!! ;-)) Use /dev/ttyS (/dev/ttyS1 for com2) because cua can be more easyly tricked to dial out even when DCD control signal sez not to. that's why in former times programmers used cua for dialing out and ttyS for in since kernel 2.2 you get a warning in the logs when you use cua. just my 0.02 $ grrrrreetings jö! From scarblac@pino.selwerd.nl Sun Apr 1 16:17:44 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 1 Apr 2001 17:17:44 +0200 Subject: [Tutor] valid filenames In-Reply-To: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com>; from syrinx@simplecom.net on Sat, Mar 31, 2001 at 09:52:47PM -0600 References: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> Message-ID: <20010401171744.A2066@pino.selwerd.nl> On Sat, Mar 31, 2001 at 09:52:47PM -0600, Scott wrote: > Is there a Python module that contains a function that determines if a > string is a valid filename? If not, can someone refresh my memory; > what is a valid filename in Unix? I think it can be up to 255 > characters, but which characters are disallowed? '/' is disallowed, and '\0' (null). -- Remco Gerlich From sheila@thinkspot.net Sun Apr 1 17:08:46 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 01 Apr 2001 09:08:46 -0700 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: References: <738F32F4A49@kserver.org> Message-ID: <2A5D2F922F0@kserver.org> On Sat, 31 Mar 2001 22:51:39 -0500, "Tim Peters" wrote about RE: [Tutor] Still confused about Python references/objects: :[Sheila King, on trying to understand Python via reference semantics] :> You're telling me! (I bring background experience from a few different :> languages: Pascal, Fortran, VB, C++, and they ALL behaved that :> way! It is so difficult to get used to this new way of thinking.) : :If it's any consolation, those to whom Python is a first language have no :trouble at all with it, and probably suffer even greater trying to keep track :of the new mysteries that pop up when they move to other languages. Well, that's why I was wondering about whether Python is really a good first language. It seems to me, it would be much more difficult to get used to strongly typed languages and references/values/pointers after using Python first. Dunno. :The eff-bot (Fredrik Lundh) wrote a very nice and tiny intro, here: : : http://w1.132.telia.com/~u13208596/guides/python-objects.htm : :Check it out! Been there, done that. I'm one of the types that has to go over an idea many times until it sinks in. ...... :Yup! Note too that module-global objects are visible from *all* function and :method namespaces, so that's another possibility: I haven't messed with the global module, yet. ...... :But heavy use of globals is bad practice, in part precisely *because* any :call can change global bindings at any time. Yes, I teach C++ programming and I tell my students: global constants = good global variables = bad And usually they are not allowed to use global variables in their programs, precisely because of the reasons you mention below. I think that we did some stuff with graphics/gui windows once, and IIRC the main window had to be a global variable in order for the program to work correctly. : You can see this in the body of :f: you can't possibly guess what "print x" is going to do without tracking :down and studying the source code for g, but you can be certain that "print :y" will print 42 without looking at g. This makes the use of y much easier :to understand in isolation, and the larger your programs get, the more :valuable it is to limit the amount of code you need to examine. Local names :and immutable objects can both help with that. ...... :Little-known feature: just like you can do : : x, y = two_tuple : :and Python will "magically" unpack the two_tuple into x and y, you can also :do that in formal argument lists. So : :def swap((x, y)): : return y, x : :also works. OK, cool. I almost tried that. :you're-well-on-the-road-to-a-full-recovery-ly y'rs - tim -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Sun Apr 1 17:24:06 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 01 Apr 2001 09:24:06 -0700 Subject: [Tutor] valid filenames In-Reply-To: <20010401170257.B5874@Laplace.localdomain> References: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> <200104011245.f31CjZs08501@dsl254-114-246.nyc1.dsl.speakeasy.net> <20010401170257.B5874@Laplace.localdomain> Message-ID: <2B3C91C4233@kserver.org> On Sun, 1 Apr 2001 17:02:57 +0200, lumbricus@gmx.net wrote about Re: [Tutor] valid filenames: :U can avoid by not using :names like -anything : ^ The hyphen is not that uncommon in file names on Unix. For example, Qmail expects hyphens in the .qmail filenames that can be used for filtering email on the RCPT field of the email envelope, and from there invoking scripts or forwarding to other addresses or whatever. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From rick@niof.net Sun Apr 1 17:37:24 2001 From: rick@niof.net (Rick Pasotto) Date: Sun, 1 Apr 2001 12:37:24 -0400 Subject: [Tutor] valid filenames In-Reply-To: <2B3C91C4233@kserver.org>; from sheila@thinkspot.net on Sun, Apr 01, 2001 at 09:24:06AM -0700 References: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> <200104011245.f31CjZs08501@dsl254-114-246.nyc1.dsl.speakeasy.net> <20010401170257.B5874@Laplace.localdomain> <2B3C91C4233@kserver.org> Message-ID: <20010401123724.R26119@tc.niof.net> On Sun, Apr 01, 2001 at 09:24:06AM -0700, Sheila King wrote: > On Sun, 1 Apr 2001 17:02:57 +0200, lumbricus@gmx.net wrote about Re: > [Tutor] > valid filenames: > > :U can avoid by not using > :names like -anything > : ^ > > The hyphen is not that uncommon in file names on Unix. For example, > Qmail expects hyphens in the .qmail filenames that can be used for > filtering email on the RCPT field of the email envelope, and from > there invoking scripts or forwarding to other addresses or whatever. The only problem with a hyphen is when it's the first character of the file name. Doing that causes many commands to confuse it with an option and special steps have to be taken to get around that. -- "A man who has nothing he is willing to fight for, nothing which he cares more about than he does his own personal safety, is a miserable creature, who has no chance of being free unless made and kept so by the exertions of men better than himself. As long as justice and injustice have not terminated their ever- renewing fight...human beings must be willing...to do battle for the one against the other." -- John Stuart Mill Rick Pasotto email: rickp@telocity.com From lumbricus@gmx.net Sun Apr 1 17:49:45 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Sun, 1 Apr 2001 18:49:45 +0200 Subject: [Tutor] Re: filename troubles Message-ID: <20010401184945.A6288@Laplace.localdomain> > > > > :U can avoid by not using > > :names like -anything > > : ^ > > > > The hyphen is not that uncommon in file names on Unix. For example, > > Qmail expects hyphens in the .qmail filenames that can be used for > > filtering email on the RCPT field of the email envelope, and from > > there invoking scripts or forwarding to other addresses or whatever. > > The only problem with a hyphen is when it's the first character of the > file name. Doing that causes many commands to confuse it with an option > and special steps have to be taken to get around that. > thats exactly what i wanted to say ;-) thx Jö! From Aaron.Mathews@Gentner.COM Sun Apr 1 11:04:15 2001 From: Aaron.Mathews@Gentner.COM (Aaron Mathews) Date: Sun, 1 Apr 2001 04:04:15 -0600 Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: ; from deirdre@deirdre.net on Sat, Mar 31, 2001 at 11:53:18PM -0800 References: <20010331102136.D4184@gandalf> Message-ID: <20010401040415.G4184@gandalf> On Sat, Mar 31, 2001 at 11:53:18PM -0800, Deirdre Saoirse wrote: > > > Actually, that's what HellDesk was, but it was never released. > Oh really? Whose project was that? A released python bug/helpdesk tracker system would make my consulting life a *lot* easier :) -- Aaron Mathews work: Aaron.Mathews@Gentner.COM - http://gentner.com/ play: Aaronm@Hobbiton.ORG - http://pukka.dyndns.org/ From scarblac@pino.selwerd.nl Sun Apr 1 20:06:23 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 1 Apr 2001 21:06:23 +0200 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <738F32F4A49@kserver.org>; from sheila@thinkspot.net on Sat, Mar 31, 2001 at 04:20:12PM -0800 References: <5F0FF742F1D@kserver.org> <738F32F4A49@kserver.org> Message-ID: <20010401210623.A2325@pino.selwerd.nl> On Sat, Mar 31, 2001 at 04:20:12PM -0800, Sheila King wrote: > On Sat, 31 Mar 2001 14:52:00 -0500, "Tim Peters" wrote > about RE: [Tutor] Still confused about Python references/objects: > > :[Sheila King] > :> ... > :> However, just for illustration, I was trying to write a swap > :> function. And, I thought that all parameters were passed by reference. > : > :"by reference" isn't really a useful concept in Python. People bring that > :with them from other languages, and get into all sorts of trouble trying to > :force it to fit. > > You're telling me! (I bring background experience from a few different > languages: Pascal, Fortran, VB, C++, and they ALL behaved that way! It is so > difficult to get used to this new way of thinking.) This point may be hard to get at first, but luckily it's one of the few things! I think once you understand: 1 Everything is by reference 2 Some objects can be changed, some can't - but no changes are made by simple assignment to a name. 3 Namespaces - everything is just a name for some object, even functions, modules, the results of import, etc - is this a special case of 1 and 2? 4 A variable is global if it's not assigned to here or if there is a "global x" statement nearby - otherwise it's local*. 5 Things like "def" happen at runtime (almost everything does*) 6 Calling a method on some instance passes "self" as 1st argument Then you understand all of the key points of the language Python (what did I forget?). I don't think I missed much. This list is enormously smaller than for other languages. Unfortunately the * things become a tiny bit more complex in versions in the near future. > OK, so I think I get what you're saying. It sounds like, in order to have a > function modify an object in the calling functions space, either it has to be > a mutable object, or else I would (I think?) have to return the new version I > want, and assign it to a name in the calling function's namespace ??? In order to have a function modify an object, to object has to be modifyable (mutable). Or, the function could return something, and the caller's code can keep it around, like binding some name to it. So yes :) > Does this sound right? > > So, now I think I know what I'm doing, and I try this: > > >>> def swap(two_tuple): > x,y = two_tuple > return y, x > > >>> a = 2 > >>> b = 3 > >>> print a, " ", b > 2 3 > >>> a,b = swap((a,b)) > >>> print a, " ", b > 3 2 > >>> Yes. Simpler would be a, b = b, a :) -- Remco Gerlich From deirdre@deirdre.net Sun Apr 1 20:08:06 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Sun, 1 Apr 2001 12:08:06 -0700 (PDT) Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: <20010401040415.G4184@gandalf> Message-ID: On Sun, 1 Apr 2001, Aaron Mathews wrote: > > Actually, that's what HellDesk was, but it was never released. > > Oh really? Whose project was that? A released python bug/helpdesk > tracker system would make my consulting life a *lot* easier :) Mine, among others. It was mostly done when several of us left Linuxcare, but was dropped immediately thereafter. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From sheila@thinkspot.net Sun Apr 1 22:08:05 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 01 Apr 2001 14:08:05 -0700 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <20010401210623.A2325@pino.selwerd.nl> References: <5F0FF742F1D@kserver.org> <738F32F4A49@kserver.org> <20010401210623.A2325@pino.selwerd.nl> Message-ID: <3B5AFA51A7A@kserver.org> On Sun, 1 Apr 2001 21:06:23 +0200, Remco Gerlich wrote about Re: [Tutor] Still confused about Python references/objects: :On Sat, Mar 31, 2001 at 04:20:12PM -0800, Sheila King wrote: :> On Sat, 31 Mar 2001 14:52:00 -0500, "Tim Peters" wrote :> about RE: [Tutor] Still confused about Python references/objects: :> :> :"by reference" isn't really a useful concept in Python. People bring that :> :with them from other languages, and get into all sorts of trouble trying to :> :force it to fit. :> :> You're telling me! (I bring background experience from a few different :> languages: Pascal, Fortran, VB, C++, and they ALL behaved that way! It is so :> difficult to get used to this new way of thinking.) : :This point may be hard to get at first, but luckily it's one of the few :things! : :I think once you understand: :1 Everything is by reference No, your point number one is not really useful (at least for me). I had read remarks like that already in the comp.lang.python newsgroup and here on the tutor mailing list. And that's why I was thinking that if I wrote a function like: def swap( a, b): That the function swap could affect the objects that were passed to a and b. But, unless a and b are mutable objects, it can't. So saying "everything is by reference" is actually confusing and misleading. I like what Tim suggested, saying that it is "by object". Anyhow, now I get it. It just took a few times to get it through my thick head. That is the usual way with me. My thesis advisor has basically said the same thing about me. :2 Some objects can be changed, some can't - but no changes are made by : simple assignment to a name. :3 Namespaces - everything is just a name for some object, even functions, : modules, the results of import, etc - is this a special case of 1 and 2? :4 A variable is global if it's not assigned to here or if there is a : "global x" statement nearby - otherwise it's local*. :5 Things like "def" happen at runtime (almost everything does*) :6 Calling a method on some instance passes "self" as 1st argument Thanks for this list. I will go over it again and again, until it all makes sense to me. :Then you understand all of the key points of the language Python (what did I :forget?). I don't think I missed much. This list is enormously smaller than :for other languages. : :Unfortunately the * things become a tiny bit more complex in versions in the :near future. Er, can't say I'm looking forward to that. I hope it doesn't create compatibility issues. My web host is still running 1.5.1, and I daresay a lot of people are still using 1.5.2, and not likely to upgrade any time soon. ...... :> So, now I think I know what I'm doing, and I try this: :> :> >>> def swap(two_tuple): :> x,y = two_tuple :> return y, x :> :> >>> a = 2 :> >>> b = 3 :> >>> print a, " ", b :> 2 3 :> >>> a,b = swap((a,b)) :> >>> print a, " ", b :> 3 2 :> >>> : :Yes. : :Simpler would be : :a, b = b, a I already knew about that and posted it in my original question. This was a study in passing parameters, so I picked an example I knew how to do without a function that was familiar to me. I thought that was a good choice. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From scarblac@pino.selwerd.nl Sun Apr 1 22:19:26 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 1 Apr 2001 23:19:26 +0200 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <3B5AFA51A7A@kserver.org>; from sheila@thinkspot.net on Sun, Apr 01, 2001 at 02:08:05PM -0700 References: <5F0FF742F1D@kserver.org> <738F32F4A49@kserver.org> <20010401210623.A2325@pino.selwerd.nl> <3B5AFA51A7A@kserver.org> Message-ID: <20010401231926.A2520@pino.selwerd.nl> On Sun, Apr 01, 2001 at 02:08:05PM -0700, Sheila King wrote: > On Sun, 1 Apr 2001 21:06:23 +0200, Remco Gerlich > wrote about Re: [Tutor] Still confused about Python references/objects: > > :On Sat, Mar 31, 2001 at 04:20:12PM -0800, Sheila King wrote: > :> On Sat, 31 Mar 2001 14:52:00 -0500, "Tim Peters" wrote > :> about RE: [Tutor] Still confused about Python references/objects: > :> > :> :"by reference" isn't really a useful concept in Python. People bring that > :> :with them from other languages, and get into all sorts of trouble trying to > :> :force it to fit. > :> > :> You're telling me! (I bring background experience from a few different > :> languages: Pascal, Fortran, VB, C++, and they ALL behaved that way! It is so > :> difficult to get used to this new way of thinking.) > : > :This point may be hard to get at first, but luckily it's one of the few > :things! > : > :I think once you understand: > :1 Everything is by reference > > No, your point number one is not really useful (at least for me). I had read > remarks like that already in the comp.lang.python newsgroup and here on the > tutor mailing list. And that's why I was thinking that if I wrote a function > like: > > def swap( a, b): > > > That the function swap could affect the objects that were passed to a and b. Ah yes, I forgot the meaning of 'by reference' in other languages. I meant 1) *Everything* is by reference. Including the assignments you did in the function, so they didn't have an effect... > But, unless a and b are mutable objects, it can't. So saying "everything is by > reference" is actually confusing and misleading. I like what Tim suggested, > saying that it is "by object". Anyhow, now I get it. It just took a few times > to get it through my thick head. That is the usual way with me. My thesis > advisor has basically said the same thing about me. > > :2 Some objects can be changed, some can't - but no changes are made by > : simple assignment to a name. > :3 Namespaces - everything is just a name for some object, even functions, > : modules, the results of import, etc - is this a special case of 1 and 2? > :4 A variable is global if it's not assigned to here or if there is a > : "global x" statement nearby - otherwise it's local*. > :5 Things like "def" happen at runtime (almost everything does*) > :6 Calling a method on some instance passes "self" as 1st argument > > Thanks for this list. I will go over it again and again, until it all makes > sense to me. Wait until others give their corrections, I tend to make mistakes... > :Then you understand all of the key points of the language Python (what did I > :forget?). I don't think I missed much. This list is enormously smaller than > :for other languages. > : > :Unfortunately the * things become a tiny bit more complex in versions in the > :near future. > > Er, can't say I'm looking forward to that. I hope it doesn't create > compatibility issues. My web host is still running 1.5.1, and I daresay a lot > of people are still using 1.5.2, and not likely to upgrade any time soon. Not that much is changing. "from __future__ import nested_scopes" acts at compile time, but you don't have to use it, ignore. The nested scopes themselves will become mandatory in 2.2 or so. Then the simple rule becomes something like: x) If you use a name that isn't assigned to in this scope, it is looked up (recursively) in the scope above this one. Which will be *very* cool for the simplified lambdas alone. > :a, b = b, a > > I already knew about that and posted it in my original question. This was a > study in passing parameters, so I picked an example I knew how to do without a > function that was familiar to me. I thought that was a good choice. I know now, but I had been away for a few days and was reading mail new-to-old... -- Remco Gerlich From tim.one@home.com Mon Apr 2 00:51:18 2001 From: tim.one@home.com (Tim Peters) Date: Sun, 1 Apr 2001 19:51:18 -0400 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <2A5D2F922F0@kserver.org> Message-ID: [Sheila King] > Well, that's why I was wondering about whether Python is really a > good first language. It seems to me, it would be much more difficult > to get used to strongly typed languages and references/values/pointers > after using Python first. Dunno. I'd say this depends on what you consider to be the *goals* of a first language. Python, like ABC before it, thinks newcomers should be able to do "interesting" things their first day. If newbies aren't to spend their entire time wrestling with the tool instead of with the problems they set out to solve, their first language should hide as much artificial complexity as possible. Things like worrying about how to allocate memory, or the differences between objects and pointers to objects and pointers to pointers to etc, are artifacts of using low-level ("close to the hardware") languages, not inherent characteristics of interesting problem domains. It so happens I learned assembly language first, as close to the hardware as things get. And I recommend that everyone learn assembler first too -- provided they intend to make a career of writing compilers, which I intended at the time . For everyone else, the higher level the better, lest they give up in frustration the first week. It's quite possible they never need to learn another language, in which case Python is a fine place to stop as well as to start. If they need to learn C or C++ or Java or ... too, the maze of new rules and requirements will drive them mad, *until* they learn something about how computers work internally. Without learning the latter, the *purpose* of all those low-level restrictions will never make good sense to them. They may learn them by rote, but they'll never achieve true skill before understanding the machine-level purposes behind having 16-bit ints *and* 32-bit ints *and* confusing pointers with arrays *and* confusing characters with little integers *and* etc etc. That stuff is all driven by what's easiest for the *hardware* to do. In Python's view, you simply don't need to worry about all that at the start (or, if you're lucky, ever!). BTW, Python is more strongly typed than C or C++: Python *never* lets you get away with a type-unsafe operation. I expect you have in mind that Python isn't *statically* typed (Python delays type checks until runtime). Static typing can also be hard to get used to, in large part because it's yet another little sub-language with its own arcane rules to trip over. If the purpose of a first language is to teach people that programming languages are a veritable minefield of inconsistent little gotchas, ya, Python is a rotten first language . let-'em-taste-success-today-and-tomorrow-is-time-enough-for-failure-ly y'rs - tim From syrinx@simplecom.net Mon Apr 2 01:38:12 2001 From: syrinx@simplecom.net (Scott) Date: Sun, 01 Apr 2001 19:38:12 -0500 Subject: [Tutor] upgrading to 2.0 on Redhat Message-ID: This is only tangentially on topic, I hope it's OK to ask. I've got Redhat 7.0, which includes python-1.5.2-27. I downloaded and installed BeOpen-Python-2.0-1. Is it possible/advisable to get rid of the old version with '--nodeps' or something. Or will this break the dependencies? It seems to be a waste of disk space, as well as a bit cluttered and confusing to keep both versions, but I don't want to break my system. Thanks. Scott Tullos From kstoner@netins.net Mon Apr 2 02:58:49 2001 From: kstoner@netins.net (Katharine Stoner) Date: Sun, 1 Apr 2001 20:58:49 -0500 Subject: [Tutor] arrays Message-ID: <000801c0bb18$78287360$e152b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0BAEE.8C9A9E60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Can you put an array inside of another array? -Cameron ------=_NextPart_000_0005_01C0BAEE.8C9A9E60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
Can you put an array inside of another=20 array?
 
-Cameron
------=_NextPart_000_0005_01C0BAEE.8C9A9E60-- From tescoil@irtc.net Mon Apr 2 02:37:20 2001 From: tescoil@irtc.net (Tesla Coil) Date: Sun, 01 Apr 2001 21:37:20 -0400 Subject: [Tutor] upgrading to 2.0 on Redhat References: Message-ID: <3AC7D7D0.9D902CB5@irtc.net> On 1 Apr 2001, Scott wrote: > This is only tangentially on topic, I hope it's > OK to ask. I hope so too--it's a good question. > I've got Redhat 7.0, which includes python-1.5.2-27. > I downloaded and installed BeOpen-Python-2.0-1. > Is it possible/advisable to get rid of the old > version with '--nodeps' or something. Or will > this break the dependencies? Possible that installing 2.0 breaks dependencies itself, whether you uninstall 1.5.2 or not. The BeOpen-Python-2.0-1.i386.rpm will put Python 2.0 answering calls for python even as 1.5.2 remains on board. Do an 'rpm -q --whatrequires python' and everything listed probably expects 1.5.2... From Aaron.Mathews@Gentner.COM Sun Apr 1 21:08:22 2001 From: Aaron.Mathews@Gentner.COM (Aaron Mathews) Date: Sun, 1 Apr 2001 14:08:22 -0600 Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: ; from deirdre@deirdre.net on Sun, Apr 01, 2001 at 12:08:06PM -0700 References: <20010401040415.G4184@gandalf> Message-ID: <20010401140822.I4184@gandalf> On Sun, Apr 01, 2001 at 12:08:06PM -0700, Deirdre Saoirse wrote: > On Sun, 1 Apr 2001, Aaron Mathews wrote: > > > > Actually, that's what HellDesk was, but it was never released. > > > > Oh really? Whose project was that? A released python bug/helpdesk > > tracker system would make my consulting life a *lot* easier :) > > Mine, among others. It was mostly done when several of us left Linuxcare, > but was dropped immediately thereafter. Too bad it didn't make it out of Linuxcare alive. Looks like I'll have to build a new toolkit myself ;) -- Aaron Mathews work: Aaron.Mathews@Gentner.COM - http://gentner.com/ play: Aaronm@Hobbiton.ORG - http://pukka.dyndns.org/ From kalle@gnupung.net Mon Apr 2 04:17:05 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Mon, 2 Apr 2001 05:17:05 +0200 Subject: [Tutor] arrays In-Reply-To: <000801c0bb18$78287360$e152b1cf@oemcomputer>; from kstoner@netins.net on Sun, Apr 01, 2001 at 08:58:49PM -0500 References: <000801c0bb18$78287360$e152b1cf@oemcomputer> Message-ID: <20010402051705.A20273@father> Sez Katharine Stoner: > Hi all, > > Can you put an array inside of another array? Do you mean Python lists (builtin), NumPy Arrays or something else? If you mean lists, the answer is yes: >>> l = ["a", ["nested"], "list"] >>> l.append(["another", ["nested", "list"]]) >>> l ['a', ['nested'], 'list', ['another', ['nested', 'list']]] >>> Otherwise, the answer is "Maybe, I don't know". Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From DOUGS@oceanic.com Mon Apr 2 04:26:09 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Sun, 1 Apr 2001 17:26:09 -1000 Subject: [Tutor] arrays Message-ID: <8457258D741DD411BD3D0050DA62365907A721@huina.oceanic.com> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C0BB24.A943BF20 Content-Type: text/plain; charset="iso-8859-1" I don't know, what's an array? ;-) Seriously, 'array' as such isn't a basic Python data type, so you may need to better define what you're trying to do. I'll take a stab at being psychot^h^hic and guessing what you mean. I'll assume you're trying to use lists and play around in the interpreter: [dougs@lawehana dougs]$ python Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> one = ['this','and','that'] >>> two = ['the','other'] >>> spam = [one,two] >>> spam [['this', 'and', 'that'], ['the', 'other']] >>> eggs = [spam[0],'and',spam[1]] >>> eggs [['this', 'and', 'that'], 'and', ['the', 'other']] >>> eggs[0][1] == eggs[1] >>> HTH -Doug- -----Original Message----- From: Katharine Stoner [mailto:kstoner@netins.net] Sent: Sunday, April 01, 2001 3:59 PM To: python tutor Subject: [Tutor] arrays Hi all, Can you put an array inside of another array? -Cameron ------_=_NextPart_001_01C0BB24.A943BF20 Content-Type: text/html; charset="iso-8859-1"
I don't know, what's an array? ;-)
 
Seriously, 'array' as such isn't a basic Python data type, so you may need to better define what you're trying to do. I'll take a stab at being psychot^h^hic and guessing what you mean.
 
I'll assume you're trying to use lists and play around in the interpreter:
 
[dougs@lawehana dougs]$ python
Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201 (egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> one = ['this','and','that']
>>> two = ['the','other']
>>> spam = [one,two]
>>> spam
[['this', 'and', 'that'], ['the', 'other']]
>>> eggs = [spam[0],'and',spam[1]]
>>> eggs
[['this', 'and', 'that'], 'and', ['the', 'other']]
>>> eggs[0][1] == eggs[1]
>>>
 
HTH
 
-Doug-
-----Original Message-----
From: Katharine Stoner [mailto:kstoner@netins.net]
Sent: Sunday, April 01, 2001 3:59 PM
To: python tutor
Subject: [Tutor] arrays

Hi all,
 
Can you put an array inside of another array?
 
-Cameron
------_=_NextPart_001_01C0BB24.A943BF20-- From Aaron.Mathews@Gentner.COM Sun Apr 1 23:06:21 2001 From: Aaron.Mathews@Gentner.COM (Aaron Mathews) Date: Sun, 1 Apr 2001 16:06:21 -0600 Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: ; from deirdre@deirdre.net on Sun, Apr 01, 2001 at 08:08:35PM -0700 References: <20010401140822.I4184@gandalf> Message-ID: <20010401160621.J4184@gandalf> On Sun, Apr 01, 2001 at 08:08:35PM -0700, Deirdre Saoirse wrote: > > That's, in part, because I almost didn't make it out alive -- a very bad > kidney infection that I contracted when I was fired nearly killed me. > Bleeding from the kidneys is NOT good. > > Thus, I just haven't worked on it. Sorry to hear about your infection. It seems that bad things come in pairs these days :( I'm sure you could find a nice home for the code, helldesk.sourceforge.net anyone? ;-) -- Aaron Mathews work: Aaron.Mathews@Gentner.COM - http://gentner.com/ play: Aaronm@Hobbiton.ORG - http://pukka.dyndns.org/ From kstoner@netins.net Mon Apr 2 13:54:12 2001 From: kstoner@netins.net (Katharine Stoner) Date: Mon, 2 Apr 2001 07:54:12 -0500 Subject: [Tutor] Re arrays Message-ID: <001801c0bb74$04b5d600$dc52b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0015_01C0BB4A.1B48BE20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable What I mean is can you take an array full of some thing and put it into = another section of an array. 1st array J1 J2 J3 J4 J5=20 2nd array H1 H2 H3 H4 H5=20 Can you put the 2nd array in the 1st array's J1. I don't mean lists = either. Perhaps you would have to write a function maybe to do this? -Cameron ------=_NextPart_000_0015_01C0BB4A.1B48BE20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
What I mean is can you take an array = full of some=20 thing and put it into another section of an array.
 
1st array J1 J2 J3 J4 J5
 
2nd array H1 H2 H3 H4 H5
 
Can you put the 2nd array in the 1st = array's=20 J1.  I don't mean lists either.  Perhaps you would have to = write a=20 function maybe to do this?
 
-Cameron
------=_NextPart_000_0015_01C0BB4A.1B48BE20-- From Rob Andrews" Message-ID: <000901c0bb7d$22279760$9600a8c0@Planhouse5> As the maintainer of Useless Python, I'd like to say *Thanks* to Danny for mentioning Useless, and re-invite anyone interested to fire off code to me at rob@jam.rr.com. (And it doesn't really have to be useless!) Rob rob@jam.rr.com ----- Original Message ----- From: "Daniel Yoo" To: "Scott" Cc: Sent: Saturday, March 31, 2001 12:41 AM Subject: Re: [Tutor] posting scripts > On Fri, 30 Mar 2001, Scott wrote: > > > If I had a script that I wanted to get feedback on, would it be okay > > to post it here? How long of one could I get away with? I just don't > > want to annoy anyone x days in the future... > > It's perfectly ok to post it up, as long as it isn't too long. *grin* > Feel free to post it up! > > A "long" script would probably be more that 2 pages, just because many > people like to look at code that fits on one screen. For long scripts, > you can submit your script to Useless Python: > > http://www.lowerstandard.com/python/pythonsource.html > > and point people to the url where your script is located. Useless Python > is set up so that you can share your scripts with others, so it's a good > resource to use. > > In any event, don't worry about "annoying" us; we're here to help and > learn. Good luck! > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Mon Apr 2 15:22:43 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Apr 2001 15:22:43 +0100 Subject: [Tutor] Still confused about Python references/objects Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D694@mbtlipnt02.btlabs.bt.co.uk> > I'd say this depends on what you consider to be > the *goals* of a first language. I agree. If you want to teach the basic concepts of programming: sequences, loops, branching, variables etc. then static typing just gets in the way. Python is great for that. If you want to teach how computers work the Python is not so good, C is better (assembler better still but just toooo painful :-) > It so happens I learned assembly language first, as close to > the hardware as things get. And I recommend that everyone learn > assembler first too -- provided they intend to make a career > of writing compilers, Or are actually interested inbuilding hardware - interface cards etc. Thats why I learned assembler first I actually wanted to know what was happening at bit level so that I could build interfaces to it. > It's quite possible they never need to learn another > language, Possible but unlikely. In my experience most real world projects use multiple languages. (I think my maximum was 12!) The average for most projects has been about 5 or 6 languages (if you include SQL and HTML as languages :-) > or C++ or Java or ... too, the maze of new rules and > requirements will drive them mad, *until* they learn > something about how computers work internally. And this raises an interesting point. Recently my company took on some MSc students who got their MSc as a 1 year conversion course from Arts subjects (rather than by specialising in an advance CS/Engineering topic) While they can all do the basics and write programs (in Java) to a spec they are without exception ignorant of how the computer actiually works. This in turn limits them in all sorts of ways (performance tuning is a complete mystery for example). We are now trying (so far in vain) to find some kind of training course which covers computer architectures etc. One of the nice things about Python is that while you can start at a purely abstract level you can also delve into the guts fairly easily through the wrapper modules available. Alan G/ From alan.gauld@bt.com Mon Apr 2 15:31:01 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Apr 2001 15:31:01 +0100 Subject: [Tutor] arrays Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D695@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0BB81.8A6FC550 Content-type: text/plain; charset="iso-8859-1" Can you put an array inside of another array? Usually, it depends on the language. Since Python doesn't have arrays you need to use lists and yes you can put a list inside amnother list: >>> L1 = [1,2,3] >>> L2 = ['a','b','c'] >>> L3 = [L1,L2] # create nested lists >>> print L3 [ [1, 2, 3], ['a', 'b', 'c'] ] >>> print L3[1][1] # how to access members b >>> L1.append(L2) # another way of nesting lists >>> print L1 [1, 2, 3, ['a', 'b', 'c'] ] HTH, Alan G ------_=_NextPart_001_01C0BB81.8A6FC550 Content-type: text/html; charset="iso-8859-1"
Can you put an array inside of another array? 
 
Usually, it depends on the language.
Since Python doesn't have arrays you need to use lists and
yes you can put a list inside amnother list:
 
>>> L1 = [1,2,3]
>>> L2 = ['a','b','c']
>>> L3 = [L1,L2]  # create nested lists
>>> print L3
[ [1, 2, 3], ['a', 'b', 'c'] ]
>>> print L3[1][1]   # how to access members
b
>>> L1.append(L2) # another way of nesting lists
>>> print L1
[1, 2, 3, ['a', 'b', 'c'] ]
 
HTH,
 
Alan G
 
------_=_NextPart_001_01C0BB81.8A6FC550-- From bdupire@seatech.fau.edu Mon Apr 2 16:58:48 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 02 Apr 2001 11:58:48 -0400 Subject: [Tutor] arrays References: <5104D4DBC598D211B5FE0000F8FE7EB20751D695@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <3AC8A1B8.2738BE5A@seatech.fau.edu> Maybe Katharine means she wants to use the array module ??? From ium@micromuse.com Mon Apr 2 17:55:49 2001 From: ium@micromuse.com (ibraheem umaru-mohammed) Date: Mon, 2 Apr 2001 17:55:49 +0100 Subject: [Tutor] Re arrays In-Reply-To: <001801c0bb74$04b5d600$dc52b1cf@oemcomputer>; from kstoner@netins.net on Mon, Apr 02, 2001 at 07:54:12AM -0500 References: <001801c0bb74$04b5d600$dc52b1cf@oemcomputer> Message-ID: <20010402175549.A3747@ignoramus> [Katharine Stoner wrote...] > What I mean is can you take an array full of some thing and put it into a= nother section of an array. >=20 > 1st array J1 J2 J3 J4 J5=20 >=20 > 2nd array H1 H2 H3 H4 H5=20 >=20 > Can you put the 2nd array in the 1st array's J1. I don't mean lists eith= er. Perhaps you would have to write=20 > a function maybe to do this? >=20 If that is the case, then "no", I don't think you can do this. An array is = used to hold items of the same type. -- Kindest regards, --ibs. -------------------------- Ibraheem Umaru-Mohammed ----------------------= ----- -- Email:ium@micromuse.com -- -- Micromuse Ltd, Disraeli House, 90 Putney Bridge Road, London SW18 1DA -- -- http://www.micromuse.com -- =09 --=20 From Rob Andrews" According to several articles found on the web (all dated the 1st of April) in places like perl.com, python.org, and oreilly.com, Parrot is a language in development intended to merge Python and Perl. Does anyone know what the story is? http://www.perl.com/pub/2001/04/01/parrot.htm Rob From jthing@frisurf.no Mon Apr 2 18:58:26 2001 From: jthing@frisurf.no (John Thingstad) Date: Mon, 02 Apr 2001 19:58:26 +0200 Subject: [Tutor] distutils with Borland compiler Message-ID: <200104021803.UAA28513@mail44.fg.online.no> I am using a Win98 machine for running Python. It has a Borland C++ 5.1 compiler but no Microsoft compiler. How can I setup the distutils package to use this instead? I have looked at the distutils source and see that there is even a Borland compiler module , but try as I may I can't find and informations of how to setup default compiler environment for a system. From kstoner@netins.net Mon Apr 2 21:26:45 2001 From: kstoner@netins.net (Katharine Stoner) Date: Mon, 2 Apr 2001 15:26:45 -0500 Subject: [Tutor] i'm a guy Message-ID: <001101c0bbb3$3d5e3c60$3e52b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C0BB89.53F12480 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Dear python people, I'm a guy named Cameron. Katharine is my mom. I'm just using her = account. -Cameron ------=_NextPart_000_000E_01C0BB89.53F12480 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Dear python people,
 
I'm a guy named Cameron.  = Katharine is my=20 mom.  I'm just using her account.
 
-Cameron
------=_NextPart_000_000E_01C0BB89.53F12480-- From deirdre@deirdre.net Mon Apr 2 21:36:57 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 2 Apr 2001 13:36:57 -0700 (PDT) Subject: [Tutor] i'm a guy In-Reply-To: <001101c0bbb3$3d5e3c60$3e52b1cf@oemcomputer> Message-ID: On Mon, 2 Apr 2001, Katharine Stoner wrote: > I'm a guy named Cameron. Katharine is my mom. I'm just using her > account. Works for us. Just remind us from time to time if we forget. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From pdiaz88@terra.es Mon Apr 2 21:40:49 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 2 Apr 2001 22:40:49 +0200 Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: <001101c0bb9b$042c21e0$9600a8c0@Planhouse5> References: <001101c0bb9b$042c21e0$9600a8c0@Planhouse5> Message-ID: <01040222404900.04659@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Pretty sure is a joke. Was on the april fool's series in slashdot Cheers Pedro On Monday 02 April 2001 19:33, Rob Andrews wrote: > According to several articles found on the web (all dated the 1st of April) > in places like perl.com, python.org, and oreilly.com, Parrot is a language > in development intended to merge Python and Perl. Does anyone know what the > story is? > > http://www.perl.com/pub/2001/04/01/parrot.htm > > Rob > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6yOPZnu53feEYxlERAl8jAJ93Ys/SVgfjl1Eu7LaX/GBKAo/ZfACZAYob 6e0EWaV80pMiT4qvEgWucTI= =R6bD -----END PGP SIGNATURE----- From bdupire@seatech.fau.edu Mon Apr 2 21:52:30 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 02 Apr 2001 16:52:30 -0400 Subject: [Tutor] i'm a guy References: <001101c0bbb3$3d5e3c60$3e52b1cf@oemcomputer> Message-ID: <3AC8E68E.60D46CEE@seatech.fau.edu> Got too many chat propositions ??? :))))))))))) (Just kidding!) ooops! yes, I wrote something like 'she' in my post.... sorry! Just to go back to the issue, the 'Array' module defines a new object type which can efficiently represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. You can concatenate 2 arrays like this... >>> import array >>> a= array.array('I', [11, 32, 35, 1, 5]) >>> b= array.array('I', [8, 11, 12]) >>> a[0:0]=b >>> print a array('I', [8L, 11L, 12L, 11L, 32L, 35L, 1L, 5L]) >>> c=a.tolist() >>> print c [8L, 11L, 12L, 11L, 32L, 35L, 1L, 5L] The tolist() method converts it to a list.... it's just an optimization. Look at: http://www.python.org/doc/current/lib/module-array.html Katharine Stoner wrote: > Dear python people, I'm a guy named Cameron. Katharine is my mom. > I'm just using her account. -Cameron -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From Rob Andrews" <01040222404900.04659@tajo> Message-ID: <004701c0bbb8$5e33bf00$9600a8c0@Planhouse5> I've assumed it's just a prank, but the idea is so freakish that some of the people here in the office claim to like the prospect. Aside from the fact that the articles were all dated Apr 1, the code snippets they provided were just implausible. (Using closing curly braces to end nested blocks?! Hardly.) Rob > Pretty sure is a joke. Was on the april fool's series in slashdot > > Cheers > Pedro > > On Monday 02 April 2001 19:33, Rob Andrews wrote: > > According to several articles found on the web (all dated the 1st of April) > > in places like perl.com, python.org, and oreilly.com, Parrot is a language > > in development intended to merge Python and Perl. Does anyone know what the > > story is? > > > > http://www.perl.com/pub/2001/04/01/parrot.htm > > > > Rob > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.4 (GNU/Linux) > Comment: For info see http://www.gnupg.org > > iD8DBQE6yOPZnu53feEYxlERAl8jAJ93Ys/SVgfjl1Eu7LaX/GBKAo/ZfACZAYob > 6e0EWaV80pMiT4qvEgWucTI= > =R6bD > -----END PGP SIGNATURE----- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Mon Apr 2 22:03:11 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 2 Apr 2001 14:03:11 -0700 (PDT) Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: <001101c0bb9b$042c21e0$9600a8c0@Planhouse5> Message-ID: On Mon, 2 Apr 2001, Rob Andrews wrote: > According to several articles found on the web (all dated the 1st of April) > in places like perl.com, python.org, and oreilly.com, Parrot is a language > in development intended to merge Python and Perl. Does anyone know what the > story is? > > http://www.perl.com/pub/2001/04/01/parrot.htm It's a joke. Read the example source code that GvR and LR show: it's hilarious because it's so clunky and shows precisely what might happen in a committee-driven language. ### GvR: Obviously there aren't any full-size Parrot programs available at the moment, just pieces of example code. This is an example written by Tim Peters: # copy stdin to stdout, except for lines starting with # while left_angle_right_angle: if dollar_underscore[0] =eq= "#": continue_next; } print dollar_underscore; } LW: I think this shows exactly what we were trying to achieve: it's immediately obvious to both Perl and Python programmers what that does. We've got a great compromise between Perl's brace-structured blocks and Python's white-space blocks; we've merged the names of language keywords in an elegant way; we've kept the idea of Perl's shortcut variables, but we've combined that with Python's readability. GvR: Of course, this is just one way you could write that program. There's more than one way to do it, right, Larry? LW: Sure. I'd probably write the program something like this: while(@line = Sys::Stdin->readline()): continue_next if $line[0] =eq= "#": print @line; } ### From dyoo@hkn.eecs.berkeley.edu Mon Apr 2 22:11:02 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 2 Apr 2001 14:11:02 -0700 (PDT) Subject: [Tutor] Re arrays In-Reply-To: <001801c0bb74$04b5d600$dc52b1cf@oemcomputer> Message-ID: On Mon, 2 Apr 2001, Katharine Stoner wrote: > What I mean is can you take an array full of some thing and put it > into another section of an array. > > 1st array J1 J2 J3 J4 J5 > > 2nd array H1 H2 H3 H4 H5 > > Can you put the 2nd array in the 1st array's J1. I don't mean lists > either. Perhaps you would have to write a function maybe to do this? Can you show us an example of how you'd use this? (Just to make sure I'm understanding what's happening.) There's a way to "squeeze" the second array into the first: ### >>> x = ['j1', 'j2', 'j3', 'j4', 'j5'] >>> y = ['h1', 'h2', 'h3', 'h4', 'h5'] >>> x[0:0] = y >>> x ['h1', 'h2', 'h3', 'h4', 'h5', 'j1', 'j2', 'j3', 'j4', 'j5'] ### but I'm pretty sure that this isn't what you're looking for. There are so many ways to "put" something into another, so we might be maddeningly off the mark for a while. Hope you find what you're looking for! From dyoo@hkn.eecs.berkeley.edu Mon Apr 2 22:17:17 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 2 Apr 2001 14:17:17 -0700 (PDT) Subject: [Tutor] Help passing parameters to cancel callback (after_cancel) In-Reply-To: <26630645.5B2F134B.00978E7F@netscape.net> Message-ID: On Sun, 1 Apr 2001 dkstewaP@netscape.net wrote: > I am very confused as to how I pass the id parameter from the call to > after() to the after_cancel() function. I think my problems are > related to the scope of variables (namespaces in python) and how to > refer to the variable in the various namespaces. The combination of > using a class to define my functions and having to pass additional > namespace info to Tkinter has really got me beat. One way that you can do this is to store the id into your "self". def poll(self): count = time() self.label2.configure(text=str(count)) nn = self.master.after(1000, self.poll) self.nn = nn The reason this is useful is because the after_cancel() method has access to its "self", so it can lookup "self.nn" too: def stop(self): self.master.after_cancel(self.nn) Use your instance to store the kind of state that needs to be passed between your functions. If you have more questions, feel free to ask us. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Mon Apr 2 22:21:43 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 2 Apr 2001 14:21:43 -0700 (PDT) Subject: [Tutor] upgrading to 2.0 on Redhat In-Reply-To: Message-ID: On Sun, 1 Apr 2001, Scott wrote: > This is only tangentially on topic, I hope it's OK to ask. > > I've got Redhat 7.0, which includes python-1.5.2-27. I downloaded and > installed BeOpen-Python-2.0-1. Is it possible/advisable to get rid of > the old version with '--nodeps' or something. Or will this break the > dependencies? It seems to be a waste of disk space, as well as a bit > cluttered and confusing to keep both versions, but I don't want to > break my system. Thanks. You might want to keep it; I know that Red Hat depends on Python for a lot of its system scripting; it will probably break your dependencies. Red Hat added a bunch of extensions that only work with Python 1.52, so I'm not sure what the upgrade path is like. For me, I've installed Python 2.0 in /usr/local/python2.0. Also, I've made it so PATH looks at /usr/local/bin first; for the most part, this should be safer, since it leaves the system alone, but allows you to work with Python 2.0. Good luck to you. From dyoo@hkn.eecs.berkeley.edu Mon Apr 2 22:24:32 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 2 Apr 2001 14:24:32 -0700 (PDT) Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: Message-ID: On Mon, 2 Apr 2001, Daniel Yoo wrote: > On Mon, 2 Apr 2001, Rob Andrews wrote: > > > According to several articles found on the web (all dated the 1st of April) > > in places like perl.com, python.org, and oreilly.com, Parrot is a language > > in development intended to merge Python and Perl. Does anyone know what the > > story is? > > > > http://www.perl.com/pub/2001/04/01/parrot.htm > > It's a joke. Read the example source code that GvR and LR show: it's ^^ Waaa.. I'm reading too much into LR parsing... meant to say Larry Wall. Sorry about that. From dsh8290@rit.edu Mon Apr 2 22:26:35 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 2 Apr 2001 17:26:35 -0400 Subject: [Tutor] valid filenames In-Reply-To: <20010401123724.R26119@tc.niof.net>; from rick@niof.net on Sun, Apr 01, 2001 at 12:37:24PM -0400 References: <0c9dctsgsj3mcgvt0c0gubnjb6s7soo3k4@4ax.com> <200104011245.f31CjZs08501@dsl254-114-246.nyc1.dsl.speakeasy.net> <20010401170257.B5874@Laplace.localdomain> <2B3C91C4233@kserver.org> <"from sheila"@thinkspot.net> <20010401123724.R26119@tc.niof.net> Message-ID: <20010402172634.A23334@harmony.cs.rit.edu> On Sun, Apr 01, 2001 at 12:37:24PM -0400, Rick Pasotto wrote: | On Sun, Apr 01, 2001 at 09:24:06AM -0700, Sheila King wrote: | > On Sun, 1 Apr 2001 17:02:57 +0200, lumbricus@gmx.net wrote about Re: | > [Tutor] | > valid filenames: | > | > :U can avoid by not using | > :names like -anything | > : ^ | > | > The hyphen is not that uncommon in file names on Unix. For example, | > Qmail expects hyphens in the .qmail filenames that can be used for | > filtering email on the RCPT field of the email envelope, and from | > there invoking scripts or forwarding to other addresses or whatever. | | The only problem with a hyphen is when it's the first character of the | file name. Doing that causes many commands to confuse it with an option | and special steps have to be taken to get around that. For example, try to remove that file : $ rm -anything rm: illegal option -- a rm: illegal option -- n rm: illegal option -- y rm: illegal option -- t rm: illegal option -- h rm: illegal option -- n rm: illegal option -- g usage: rm [-fiRr] file ... It wasn't even able to tell me the file DNE. -D From bdupire@seatech.fau.edu Mon Apr 2 22:36:43 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 02 Apr 2001 17:36:43 -0400 Subject: [Tutor] Is Parrot an April Fool's joke? References: Message-ID: <3AC8F0EB.D7AA0218@seatech.fau.edu> Daniel Yoo wrote: > On Mon, 2 Apr 2001, Daniel Yoo wrote: > > > On Mon, 2 Apr 2001, Rob Andrews wrote: > > > http://www.perl.com/pub/2001/04/01/parrot.htm > > > > It's a joke. Read the example source code that GvR and LR show: it's > ^^ > > Waaa.. I'm reading too much into LR parsing... meant to say Larry Wall. > Sorry about that. I would be interested to know how LR parsing works... I don't want to take much of your time, it's slightly off context... If you could explain it very briefly.. thanks.. Benoit From dsh8290@rit.edu Mon Apr 2 22:44:43 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 2 Apr 2001 17:44:43 -0400 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D694@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Mon, Apr 02, 2001 at 03:22:43PM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D694@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010402174443.B23334@harmony.cs.rit.edu> On Mon, Apr 02, 2001 at 03:22:43PM +0100, alan.gauld@bt.com wrote: | > I'd say this depends on what you consider to be | > the *goals* of a first language. | | I agree. If you want to teach the basic concepts of | programming: sequences, loops, branching, variables | etc. then static typing just gets in the way. | Python is great for that. Ditto. Actually, (IMO) static typing gets in the way most of the time. That's pretty much how I feel when I use Java. | If you want to teach how computers work the Python | is not so good, C is better (assembler better still | but just toooo painful :-) Did you learn x86 assembly? I learned m68k assembly (required class for my major) after Eiffel, C++, Java, and C (ok, so I didn't know Java real well, and I had only read through a C tutorial but not actually used it) and found it to be quite painful. The prof then spent a day giving an introduction to x86 assembly and its architecture. It looked many times more painful than the m68k was. I remember spending several hours getting 10.0 + 5.0 to yield 15.0 (the m68k has no fpu so one lab was to implement IEEE floating point in software -- ugh!). | While they can all do the basics and write programs | (in Java) to a spec they are without exception ignorant | of how the computer actiually works. This in turn limits | them in all sorts of ways (performance tuning is a | complete mystery for example). We are now trying (so | far in vain) to find some kind of training course which | covers computer architectures etc. Would a college course be an option? If you are in western new york, RIT has a good "Introcudtion to Assembly Language Programming" course that basically covers the architecture as well. The prof even gave an example (simlified!) cpu and went over the various components and how they work with the clock cycles, stepping through a couple of instructions cycle-by-cycle. -D (who is very glad the bird didn't kill the snake) From dsh8290@rit.edu Mon Apr 2 22:48:12 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 2 Apr 2001 17:48:12 -0400 Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: <3AC8F0EB.D7AA0218@seatech.fau.edu>; from bdupire@seatech.fau.edu on Mon, Apr 02, 2001 at 05:36:43PM -0400 References: <3AC8F0EB.D7AA0218@seatech.fau.edu> Message-ID: <20010402174812.C23334@harmony.cs.rit.edu> On Mon, Apr 02, 2001 at 05:36:43PM -0400, Benoit Dupire wrote: | Daniel Yoo wrote: | > Waaa.. I'm reading too much into LR parsing... meant to say Larry Wall. | > Sorry about that. | | I would be interested to know how LR parsing works... | I don't want to take much of your time, it's slightly off context... slightly ot, maybe, but interesting nonetheless (I suppose, I find most comp sci type things interesting) | If you could explain it very briefly.. thanks.. If so, on-list please ... (is it related to yacc at all? I used lex/yacc for a small project once. Many times easier than writing the whole thing in C++ from the ground up (in an earlier course)) -D From scarblac@pino.selwerd.nl Mon Apr 2 22:50:52 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 2 Apr 2001 23:50:52 +0200 Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: <3AC8F0EB.D7AA0218@seatech.fau.edu>; from bdupire@seatech.fau.edu on Mon, Apr 02, 2001 at 05:36:43PM -0400 References: <3AC8F0EB.D7AA0218@seatech.fau.edu> Message-ID: <20010402235052.A4659@pino.selwerd.nl> On Mon, Apr 02, 2001 at 05:36:43PM -0400, Benoit Dupire wrote: > Daniel Yoo wrote: > > > On Mon, 2 Apr 2001, Daniel Yoo wrote: > > > > > On Mon, 2 Apr 2001, Rob Andrews wrote: > > > > http://www.perl.com/pub/2001/04/01/parrot.htm > > > > > > It's a joke. Read the example source code that GvR and LR show: it's > > ^^ > > > > Waaa.. I'm reading too much into LR parsing... meant to say Larry Wall. > > Sorry about that. > > I would be interested to know how LR parsing works... > I don't want to take much of your time, it's slightly off context... > If you could explain it very briefly.. thanks.. I think this is really too off-topic for the list, it takes quite some explaining. It typed "lr parsing" into Google though, and the first link is to "PyLR - fast LR parsing in Python" at http://starship.python.net/crew/scott/PyLR.html The only introduction I see is at http://cs.wwc.edu/~aabyan/464/BUP.html , but that's still far from easy. Try some other links :) There are several ways to go from a BNF grammar notation to a working parser for that language, they result in different types of parser. An LR parser is one type. If you are currently learning Assembler because Tim Peters told you that you had to do that if you wanted to find a job building compilers, you also want to learn all about LL, LR, LALR etc parsers... I learned about it at the uni from the book "Crafting a Compiler", which is quite thorough. But no fun :) -- Remco Gerlich From pdiaz88@terra.es Mon Apr 2 23:18:17 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Tue, 3 Apr 2001 00:18:17 +0200 Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: <004701c0bbb8$5e33bf00$9600a8c0@Planhouse5> References: <001101c0bb9b$042c21e0$9600a8c0@Planhouse5> <01040222404900.04659@tajo> <004701c0bbb8$5e33bf00$9600a8c0@Planhouse5> Message-ID: <01040300181701.04659@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Yeah, I saw the code. In one word: Joke for the people who didn't saw it, it was something like: function open_curly_brace if dolar_sign_A == "some text" open_curly_brace .... close_curly_brace close_curly_brace hah! Cheers Pedro On Monday 02 April 2001 23:03, Rob Andrews wrote: > I've assumed it's just a prank, but the idea is so freakish that some of > the people here in the office claim to like the prospect. Aside from the > fact that the articles were all dated Apr 1, the code snippets they > provided were just implausible. (Using closing curly braces to end nested > blocks?! Hardly.) > > Rob > > > Pretty sure is a joke. Was on the april fool's series in slashdot > > > > Cheers > > Pedro > > > > On Monday 02 April 2001 19:33, Rob Andrews wrote: > > > According to several articles found on the web (all dated the 1st of > > April) > > > > in places like perl.com, python.org, and oreilly.com, Parrot is a > > language > > > > in development intended to merge Python and Perl. Does anyone know what > > the > > > > story is? > > > > > > http://www.perl.com/pub/2001/04/01/parrot.htm > > > > > > Rob > > > > > > > > > _______________________________________________ > > > Tutor maillist - Tutor@python.org > > > http://mail.python.org/mailman/listinfo/tutor > > > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.0.4 (GNU/Linux) > > Comment: For info see http://www.gnupg.org > > > > iD8DBQE6yOPZnu53feEYxlERAl8jAJ93Ys/SVgfjl1Eu7LaX/GBKAo/ZfACZAYob > > 6e0EWaV80pMiT4qvEgWucTI= > > =R6bD > > -----END PGP SIGNATURE----- > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6yPqqnu53feEYxlERAhZHAKDHw8VXuRTdB5hpemjj+wIHcNAgiwCgruON /2WHRvhRuj6gBUL8OsTds2o= =0kVx -----END PGP SIGNATURE----- From bsass@freenet.edmonton.ab.ca Mon Apr 2 23:14:32 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Mon, 2 Apr 2001 16:14:32 -0600 (MDT) Subject: [Tutor] valid filenames In-Reply-To: <20010402172634.A23334@harmony.cs.rit.edu> Message-ID: On Mon, 2 Apr 2001, D-Man wrote: <...> > | The only problem with a hyphen is when it's the first character of the > | file name. Doing that causes many commands to confuse it with an option > | and special steps have to be taken to get around that. > > For example, try to remove that file : > > $ rm -anything <...> rm -- -anything (as per "info rm" ;) - Bruce From rear@sirius.com Mon Apr 2 23:42:38 2001 From: rear@sirius.com (Bob Rea) Date: Mon, 02 Apr 2001 15:42:38 -0700 Subject: [Tutor] where is IDLE in 2.0 Message-ID: <3AC9005E.2080000@sirius.com> the site says there is a new idle 6 with 2.0 where is is located? -- Bob Rea Freedom is only privilege extended unless enjoyed by one and all --Billy Bragg rear@sirius.com http://www.sirius.com/~rear From lha2@columbia.edu Mon Apr 2 23:50:15 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Mon, 02 Apr 2001 18:50:15 -0400 Subject: [Tutor] valid filenames References: Message-ID: <3AC90227.5CFB23FE@mail.verizon.net> > Message: 15 > Date: Mon, 2 Apr 2001 17:26:35 -0400 > From: D-Man > To: tutor@python.org > Subject: Re: [Tutor] valid filenames > > On Sun, Apr 01, 2001 at 12:37:24PM -0400, Rick Pasotto wrote: > | On Sun, Apr 01, 2001 at 09:24:06AM -0700, Sheila King wrote: > | > On Sun, 1 Apr 2001 17:02:57 +0200, lumbricus@gmx.net wrote about Re: > | > [Tutor] > | > valid filenames: > | > > | > :U can avoid by not using > | > :names like -anything > | > : ^ > | > > | > The hyphen is not that uncommon in file names on Unix. For example, > | > Qmail expects hyphens in the .qmail filenames that can be used for > | > filtering email on the RCPT field of the email envelope, and from > | > there invoking scripts or forwarding to other addresses or whatever. > | > | The only problem with a hyphen is when it's the first character of the > | file name. Doing that causes many commands to confuse it with an option > | and special steps have to be taken to get around that. > > For example, try to remove that file : > > $ rm -anything > > rm: illegal option -- a > rm: illegal option -- n > rm: illegal option -- y > rm: illegal option -- t > rm: illegal option -- h > rm: illegal option -- n > rm: illegal option -- g > usage: rm [-fiRr] file ... > > It wasn't even able to tell me the file DNE. I was going to write that it would be a really bad idea to name a file '-rf ~&', but then I was afraid that someone would actually try it. A friend from undergrad used to have the .finger file [10] rm -rf ~ done or however it would look (don't have access to unix at the moment). From dsh8290@rit.edu Mon Apr 2 23:58:47 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 2 Apr 2001 18:58:47 -0400 Subject: [Tutor] valid filenames In-Reply-To: <3AC90227.5CFB23FE@mail.verizon.net>; from vze2f978@mail.verizon.net on Mon, Apr 02, 2001 at 06:50:15PM -0400 References: <3AC90227.5CFB23FE@mail.verizon.net> Message-ID: <20010402185846.A23622@harmony.cs.rit.edu> On Mon, Apr 02, 2001 at 06:50:15PM -0400, Lloyd Hugh Allen wrote: | I was going to write that it would be a really bad idea to name a file | '-rf ~&', but then I was afraid that someone would actually try it. A That's a good one . I wouldn't have tried that ;-). -D From bdupire@seatech.fau.edu Mon Apr 2 23:54:00 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 02 Apr 2001 18:54:00 -0400 Subject: [Tutor] converting a Python var to a C-type Message-ID: <3AC90307.2A184EEF@seatech.fau.edu> My problem consists of storing a variable X in a structure (in an init phase) so that i can pass it to a C-extension module later on (at run-time). # init time my_dictionary['X']=value # at run time cmodule.load( my_dictionary['X']) I would like to make sure at init-time that the value I pass to the C side at run-time will 'fit' the C variable, without raising an exception. the type the C side would accept is contained in a Python string variable: examples: "int", "short", "double", "float", "ulong", "uint", "ushort", "ubyte", "char".. Is there an easy way to make sure that the Python variable will fit the C format ? The intuitive (and tedious) way to do it would be: value= -3.14 if desired_type="int": # convert value to -3 if desired_type ="ushort": # raise ValueError Another way to do it would be another C-extension just to test whether it fits.. and then Python would take care of raising the exception if it does not work... So i will have (on the C-side) several functions which would only be 'stubs', and would return either an exception or the 'casted' variable if the variable can 'fit'. static PyObject * wrap_try_float (PyObject * self, PyObject * args) {<...>} static PyObject * wrap_try_unsigned_int ( PyObject * self, PyObject * args) {<...>} etc... Does anyone know a 'better' way ? Thanks !!!! -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From dsh8290@rit.edu Mon Apr 2 23:59:57 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 2 Apr 2001 18:59:57 -0400 Subject: [Tutor] Is Parrot an April Fool's joke? In-Reply-To: <20010402235052.A4659@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Mon, Apr 02, 2001 at 11:50:52PM +0200 References: <3AC8F0EB.D7AA0218@seatech.fau.edu> <"from bdupire"@seatech.fau.edu> <20010402235052.A4659@pino.selwerd.nl> Message-ID: <20010402185957.B23622@harmony.cs.rit.edu> On Mon, Apr 02, 2001 at 11:50:52PM +0200, Remco Gerlich wrote: | On Mon, Apr 02, 2001 at 05:36:43PM -0400, Benoit Dupire wrote: | > Daniel Yoo wrote: | > | > I would be interested to know how LR parsing works... | > I don't want to take much of your time, it's slightly off context... | > If you could explain it very briefly.. thanks.. | | I think this is really too off-topic for the list, it takes quite some ... ok, thanks for that much of an intro -D From dsh8290@rit.edu Tue Apr 3 00:03:56 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 2 Apr 2001 19:03:56 -0400 Subject: [Tutor] Is There a Bugtracking tool written in Python In-Reply-To: <200103301436.JAA23470@scott.zenplex.com>; from scott@zenplex.com on Fri, Mar 30, 2001 at 09:38:49AM -0500 References: <200103301436.JAA23470@scott.zenplex.com> Message-ID: <20010402190356.C23622@harmony.cs.rit.edu> On Fri, Mar 30, 2001 at 09:38:49AM -0500, Scott Ralph Comboni wrote: | Does anyone now if there is a bugtracking tool like bugzilla written in | Python? For those who don't follow python-list (comp.lang.python) as well, Moshe Zadka mentioned Roundup by Ka-Ping Yee. http://www.lfw.org/ping/roundup.html -D From bsass@freenet.edmonton.ab.ca Tue Apr 3 00:02:38 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Mon, 2 Apr 2001 17:02:38 -0600 (MDT) Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <20010402174443.B23334@harmony.cs.rit.edu> Message-ID: On Mon, 2 Apr 2001, D-Man wrote: > On Mon, Apr 02, 2001 at 03:22:43PM +0100, alan.gauld@bt.com wrote: > | If you want to teach how computers work the Python > | is not so good, C is better (assembler better still > | but just toooo painful :-) > > Did you learn x86 assembly? I learned m68k assembly (required class > for my major) after Eiffel, C++, Java, and C (ok, so I didn't know > Java real well, and I had only read through a C tutorial but not > actually used it) and found it to be quite painful. The prof then > spent a day giving an introduction to x86 assembly and its > architecture. It looked many times more painful than the m68k was. I > remember spending several hours getting 10.0 + 5.0 to yield 15.0 (the > m68k has no fpu so one lab was to implement IEEE floating point in > software -- ugh!). Although I would assert that assembler (or even machine language) is the best introduction to computing you can get, I would have to qualify it by saying that x86, m68k, or even Z80 (8-bit), is too much. Something with a really basic instruction set and few registers, like the 6502, and a crash course in making data structures out of the various addressing modes, would let beginners see what is at the basis of all languages... learning a new language is then a matter of figuring out how the semantics relate to the basic operations CPUs do. - Bruce From lumbricus@gmx.net Tue Apr 3 00:21:46 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Tue, 3 Apr 2001 01:21:46 +0200 Subject: [Tutor] valid filenames In-Reply-To: ; from bsass@freenet.edmonton.ab.ca on Mon, Apr 02, 2001 at 04:14:32PM -0600 References: <20010402172634.A23334@harmony.cs.rit.edu> Message-ID: <20010403012146.A2185@Laplace.localdomain> > > rm -- -anything > > (as per "info rm" ;) > or the less elegant way: $ rm ./-anything ;-) sorry-if-that-gets-double-posted-but-i-hit-a-wrong-key-with-my-new-mail-reader-grrrrreeetings Jö! From tbrauch@mindless.com Tue Apr 3 00:36:01 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Mon, 02 Apr 2001 19:36:01 -0400 Subject: [Tutor] Python In The Wild Message-ID: <3AC90CE1.58996CC8@mindless.com> I just noticed that on Yahoo!'s maps page, they seem to be using a Python script. Just thought you might like to know I had a Python siting in the the wild. - Tim From lumbricus@gmx.net Tue Apr 3 00:39:31 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Tue, 3 Apr 2001 01:39:31 +0200 Subject: [Tutor] valid filenames In-Reply-To: <20010402185846.A23622@harmony.cs.rit.edu>; from dsh8290@rit.edu on Mon, Apr 02, 2001 at 06:58:47PM -0400 References: <3AC90227.5CFB23FE@mail.verizon.net> <20010402185846.A23622@harmony.cs.rit.edu> Message-ID: <20010403013931.A2252@Laplace.localdomain> > | I was going to write that it would be a really bad idea to name a file > | '-rf ~&', but then I was afraid that someone would actually try it. A > Oh damn *shudder* actually you can try it by locking that beast up in backtics and using echo ? $ echo `rm -rfvv ~` ^^ to get some output grrrrrrreetings-to-all-the-m$-windoze-users-on-this-list-who-are-bored by-this-thread*wink* Jö! From lumbricus@gmx.net Tue Apr 3 01:12:55 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Tue, 3 Apr 2001 02:12:55 +0200 Subject: [Tutor] valid filenames In-Reply-To: <20010403013931.A2252@Laplace.localdomain>; from lumbricus@gmx.net on Tue, Apr 03, 2001 at 01:39:31AM +0200 References: <3AC90227.5CFB23FE@mail.verizon.net> <20010402185846.A23622@harmony.cs.rit.edu> <20010403013931.A2252@Laplace.localdomain> Message-ID: <20010403021255.A2484@Laplace.localdomain> On Tue, Apr 03, 2001 at 01:39:31AM +0200, lumbricus@gmx.net wrote: > > | I was going to write that it would be a really bad idea to name a file > > | '-rf ~&', but then I was afraid that someone would actually try it. A > > > Oh damn *shudder* > actually you can try it by locking that beast up in backtics and > using echo ? > $ echo `rm -rfvv ~` > ^^ > to get some output > > grrrrrrreetings-to-all-the-m$-windoze-users-on-this-list-who-are-bored > by-this-thread*wink* > Jö! > to make it clear this was a (OT) QUESTION!!! not an advice From lha2@columbia.edu Tue Apr 3 01:37:44 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Mon, 02 Apr 2001 20:37:44 -0400 Subject: [Tutor] dovetail shuffle Message-ID: <3AC91B58.AB4888DD@mail.verizon.net> I can't remember whether it was on here or c.l.p that someone was talking about shuffling cards; here's my go, based on my recollection of a paper I read a bit ago. --------begin module dovetail.py-------------- import random def dovetail(deck,splitprecision=2,thumb=2): """Shuffles a deck in a fashion that (hopefully) approximates a "real" shuffle This performs something that hopefully approximates the dovetail shuffle that I remember reading about two years ago when taking a course from Dave Bayer. See Bayer, D. and Diaconis, P. (1992). 'Trailing the dovetail shuffle to its lair.' Ann. Appl. Probab. 2 (1992), no. 2 , 294-313.""" split=-1 #initialize split to a value that guarantees that the while loop goes newdeck=[] #initialize the object to be returned at the end of the day deck.reverse() #because we will be popping elements off of the top, instead of the bottom if len(deck)>1: #abort if we are given an empty deck while split<0 or split>len(deck): #generate a place to split the deck split=len(deck)/2+random.randint(-1*splitprecision,splitprecision) left=deck[:-1*split] #perform the split right=deck[split:] while len(left)>0 or len(right)>0: if len(left)>0: #if there are no cards in the left hand, please don't pop from the left for count in range(random.randint(1,min([len(left),thumb+1]))): newdeck.append(left.pop()) #take [1,3] cards (usually) from this hand if len(right)>0: for count in range(random.randint(1,min([len(right),thumb+1]))): newdeck.append(right.pop()) return newdeck #here is your shuffled deck From dyoo@hkn.eecs.berkeley.edu Tue Apr 3 08:46:25 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 3 Apr 2001 00:46:25 -0700 (PDT) Subject: [Tutor] converting a Python var to a C-type In-Reply-To: <3AC90307.2A184EEF@seatech.fau.edu> Message-ID: On Mon, 2 Apr 2001, Benoit Dupire wrote: > the type the C side would accept is contained in a Python string > variable: > examples: "int", "short", "double", "float", "ulong", "uint", "ushort", > "ubyte", "char".. I'm not quite sure if this will help, but the struct module has a nice function calcsize() which will calculate how large a type will be: http://python.org/doc/current/lib/module-struct.html and the rest of the module itself might be very useful, since it does deal with C-style variables. pack() and unpack(), too, sound relevant. I'm not quite sure what you mean by "fit"; do you mean "fit" by the size of the structure, or range? One way I can see about doing this is with a data-directed programming style: keep a dictionary that matches desired_types with your stubs: type_funcs = { 'int' : convertInt, 'ushort' : convertShort, ... } This becomes useful because we can later do a: func = type_funcs[desired_type] return func(value) and have each of your conversion functions take responsibility for either converting things or raising ValueErrors. It makes it easier to add new times as you experiment because it involves just adding another element to your dictionary. There's probably a better way to do this, but I'm getting sleepy at the moment. *grin* Anyway, hope this helps! From alan.gauld@bt.com Tue Apr 3 10:57:54 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 3 Apr 2001 10:57:54 +0100 Subject: [Tutor] Still confused about Python references/objects Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D69D@mbtlipnt02.btlabs.bt.co.uk> > > On Mon, Apr 02, 2001 at 03:22:43PM +0100, alan.gauld@bt.com > > | is not so good, C is better (assembler better still > > | but just toooo painful :-) > > Did you learn x86 assembly? No, far to modern. I learnt 6502, 8080 and the then new Z80. I later played with a 6809 for a motor speed control application for an industrial milling machine. > Something with a really basic instruction set > and few registers, like the 6502, I agree, and there are some nice assember environments out there for emulating the chips so you don't have to struggle with the really primitive development tools we used (Anyone else recall the Rockwell AIM65 - a keyboard, line of 7 segment LEDs and a till-roll printer ;-) [ At this point cue the Python(?) sketch "You had XXX, you were lucky, we..." ] Alan g From NHYTRO@compuserve.com Tue Apr 3 12:07:10 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Tue, 3 Apr 2001 06:07:10 -0500 Subject: [Tutor] ODBC, MS ACCESS Message-ID: <200104030507_MC2-CB07-3B30@compuserve.com> Could someone point me to a tutorial or a Module that gives me access to = MS ACCESS( no pun intended)? I=B4ve searched FAQTS and the vaults of Parness= us and came up with mxODBC which is not free anymore, I would need a free or= open solution for my application Best regards Sharriff From scarblac@pino.selwerd.nl Tue Apr 3 11:13:52 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 3 Apr 2001 12:13:52 +0200 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D69D@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Tue, Apr 03, 2001 at 10:57:54AM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D69D@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010403121352.A5891@pino.selwerd.nl> On Tue, Apr 03, 2001 at 10:57:54AM +0100, alan.gauld@bt.com wrote: > [ At this point cue the Python(?) sketch > "You had XXX, you were lucky, we..." ] Nah, I started on a 6502 as well (I was a kid, had a C64, and there were things that BASIC didn't do... Had to calculate the byte values on paper and put them in DATA statements, though. Assembler? Luxury!) However, I do have the Four Yorkshiremen sketch on .mpg, so if anyone hasn't seen it yet and has no problem downloading 33M, here it is... http://pino.selwerd.nl/Monty_Python-Four_Yorkshiremen.mpg (removing it in a day or two) (had to watch it immediately when you mentioned it, etc ;-)) -- Remco Gerlich From mbc2@netdoor.com Tue Apr 3 13:07:00 2001 From: mbc2@netdoor.com (mbc2@netdoor.com) Date: Tue, 3 Apr 2001 07:07:00 -0500 (CDT) Subject: [Tutor] ODBC, MS ACCESS In-Reply-To: <200104030507_MC2-CB07-3B30@compuserve.com> Message-ID: Its not immediately apparent, but there is ODBC connectivity included with python already, at least on the ActiveState Windows version I'm using. Look at the database modules (under Special Topics) section of the Python website. There's an ODBC module listed there. There isn't alot of documentation on it, but it's been working fine for me. On Tue, 3 Apr 2001, Sharriff Aina wrote: > Could someone point me to a tutorial or a Module that gives me access to = MS > ACCESS( no pun intended)? I=B4ve searched FAQTS and the vaults of Parness= us > and came up with mxODBC which is not free anymore, I would need a free or > open solution for my application >=20 > Best regards >=20 > Sharriff >=20 > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor >=20 From bdupire@seatech.fau.edu Tue Apr 3 13:53:45 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 03 Apr 2001 08:53:45 -0400 Subject: [Tutor] converting a Python var to a C-type References: Message-ID: <3AC9C7D9.931EA955@seatech.fau.edu> Daniel Yoo wrote: > On Mon, 2 Apr 2001, Benoit Dupire wrote: > > > the type the C side would accept is contained in a Python string > > variable: > > examples: "int", "short", "double", "float", "ulong", "uint", "ushort", > > "ubyte", "char".. > > > > > I'm not quite sure what you mean by "fit"; do you mean "fit" by the size > of the structure, or range? both actually... if i pass 257 for a char variable, i would like to detect this at init time before it fails at run-time. > > There's probably a better way to do this, but I'm getting sleepy at the > moment. *grin* that's not so bad ;)))) > > > Anyway, hope this helps! sure! tks From pythoperson@yahoo.com Tue Apr 3 14:49:48 2001 From: pythoperson@yahoo.com (folklore hopeful) Date: Tue, 3 Apr 2001 06:49:48 -0700 (PDT) Subject: [Tutor] Burning python onto CD-ROM? Message-ID: <20010403134948.27064.qmail@web12403.mail.yahoo.com> Hello everyone out there, Here's a wacky question. Would it be possible to burn an installed copy of python onto CD-ROM, along with a *.py script file, so that I could put the cd-rom into any windows 95 PC and run the script without installing python onto the harddrive? What are the issues that I need to be aware of in attempting this? What files necessary to run python2.0 are placed outside of the python20 directory tree, if any? (this would hypothetically be python2.0 with windows 95) I'm not sure if I worded this question correctly, so maybe I'll need to clarify. Thanks in advance for the advice! __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From dsh8290@rit.edu Tue Apr 3 15:49:29 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 3 Apr 2001 10:49:29 -0400 Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <20010403121352.A5891@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Tue, Apr 03, 2001 at 12:13:52PM +0200 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D69D@mbtlipnt02.btlabs.bt.co.uk> <"from alan.gauld"@bt.com> <20010403121352.A5891@pino.selwerd.nl> Message-ID: <20010403104929.B28039@harmony.cs.rit.edu> On Tue, Apr 03, 2001 at 12:13:52PM +0200, Remco Gerlich wrote: | On Tue, Apr 03, 2001 at 10:57:54AM +0100, alan.gauld@bt.com wrote: | | However, I do have the Four Yorkshiremen sketch on .mpg, so if anyone hasn't | seen it yet and has no problem downloading 33M, here it is... | | http://pino.selwerd.nl/Monty_Python-Four_Yorkshiremen.mpg Thanks. Pretty funny! (btw, netscape had trouble with it -- it tried to show it as ascii in the browser, ftp access was fine though) -D From scarblac@pino.selwerd.nl Tue Apr 3 16:28:59 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 3 Apr 2001 17:28:59 +0200 Subject: [Tutor] Burning python onto CD-ROM? In-Reply-To: <20010403134948.27064.qmail@web12403.mail.yahoo.com>; from pythoperson@yahoo.com on Tue, Apr 03, 2001 at 06:49:48AM -0700 References: <20010403134948.27064.qmail@web12403.mail.yahoo.com> Message-ID: <20010403172859.B6540@pino.selwerd.nl> On Tue, Apr 03, 2001 at 06:49:48AM -0700, folklore hopeful wrote: > Hello everyone out there, > > Here's a wacky question. Would it be possible to burn an installed copy of > python onto CD-ROM, along with a *.py script file, so that I could put the > cd-rom into any windows 95 PC and run the script without installing python > onto the harddrive? > > What are the issues that I need to be aware of in attempting this? What > files necessary to run python2.0 are placed outside of the python20 directory > tree, if any? > > (this would hypothetically be python2.0 with windows 95) > > I'm not sure if I worded this question correctly, so maybe I'll need to > clarify. Thanks in advance for the advice! If you get Pythonware's PY20 version of Python 2.0, you have a version that installs into a directory, and uses nothing outside of it, no registry, nothing. So you can burn that to a CD and it should work. PY20 also comes with some cool libraries like PIL. See http://www.secretlabs.com/products/python/index.htm -- Remco Gerlich From chessucat@yahoo.com Tue Apr 3 17:02:29 2001 From: chessucat@yahoo.com (Charles Cheshier) Date: Tue, 3 Apr 2001 09:02:29 -0700 (PDT) Subject: [Tutor] Python In The Wild In-Reply-To: <3AC90CE1.58996CC8@mindless.com> Message-ID: <20010403160229.27216.qmail@web509.mail.yahoo.com> Hey, I just noticed that too. That Yahoo! seem to be using python on their site. I wonder why? Python reminds me of this programming language called ABC, written by some dutch prof. ABC is very easy to use and understand! It had one interesting feature, when started to type a reserved command, like W(rite?) it would fill in what you might have intended. Pretty neat! I haven't done much programming in my life. I do enjoy reading them and trying to decipher their meaning. Kinda like doing a cryptogram or crossword! ~Charles --- "Timothy M. Brauch" wrote: > I just noticed that on Yahoo!'s maps page, > they seem to be > using a Python > script. Just thought you might like to know I had a > Python siting in > the the wild. > > - Tim > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From kalle@gnupung.net Tue Apr 3 17:26:27 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 3 Apr 2001 18:26:27 +0200 Subject: [Tutor] Python In The Wild In-Reply-To: <20010403160229.27216.qmail@web509.mail.yahoo.com>; from chessucat@yahoo.com on Tue, Apr 03, 2001 at 09:02:29AM -0700 References: <3AC90CE1.58996CC8@mindless.com> <20010403160229.27216.qmail@web509.mail.yahoo.com> Message-ID: <20010403182627.A537@apone.network.loc> Sez Charles Cheshier: > Python > reminds me of this programming language called ABC, > written by some dutch prof. The similarities are not coincidential. In fact, Guido van Rossum, the creator of Python, worked with the ABC group at CWI from 1982 to 1986. Look at http://www.python.org/doc/essays/foreword.html for more about Python design influences and philosophy. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From szz@philoslabs.com Tue Apr 3 18:08:47 2001 From: szz@philoslabs.com (Szalay Zoltan) Date: Tue, 03 Apr 2001 19:08:47 +0200 Subject: [Tutor] Help: wxTreeCtrl doesn't display images Message-ID: <3ACA039F.1070603@philoslabs.com> Hello! Could anyone please tell me why the hell wxTreeCtrl doesn't display images? Here comes what I do: #----------------------------------- class MyTreeCtrl(wx.wxTreeCtrl): def __init__(...): ... wx.wxInitAllImageHandlers() folderbitmap=wx.wxImage("folder.bmp",wx.wxBITMAP_TYPE_BMP).ConvertToBitmap() imagelist=wx.wxImageList(16,16) idx=imagelist.Add(folderbitmap) self.SetImageList(imagelist) root=self.AddRoot("root",idx,-1) #------------------------------------- Thanx Zoltan Szalay szz@philoslabs.com From bsass@freenet.edmonton.ab.ca Tue Apr 3 18:08:10 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Tue, 3 Apr 2001 11:08:10 -0600 (MDT) Subject: [Tutor] Still confused about Python references/objects In-Reply-To: <20010403121352.A5891@pino.selwerd.nl> Message-ID: On Tue, 3 Apr 2001, Remco Gerlich wrote: > On Tue, Apr 03, 2001 at 10:57:54AM +0100, alan.gauld@bt.com wrote: > > [ At this point cue the Python(?) sketch > > "You had XXX, you were lucky, we..." ] > > Nah, I started on a 6502 as well (I was a kid, had a C64, and there were > things that BASIC didn't do... Had to calculate the byte values on paper and > put them in DATA statements, though. Assembler? Luxury!) A C64, the lap of luxury, you had a spot for ML starting at 49152 and a nice bunch of devel tools to choose from. A ZX81, on the other hand, forced you to poke bytes into a rem statement's text because Sir Clive's little box didn't have enough RAM to put any aside for ML. - Bruce (I guess we've bored most everyone under 35 now, eh ;) From dsh8290@rit.edu Tue Apr 3 19:24:38 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 3 Apr 2001 14:24:38 -0400 Subject: [Tutor] Help: wxTreeCtrl doesn't display images In-Reply-To: <3ACA039F.1070603@philoslabs.com>; from szz@philoslabs.com on Tue, Apr 03, 2001 at 07:08:47PM +0200 References: <3ACA039F.1070603@philoslabs.com> Message-ID: <20010403142438.E28277@harmony.cs.rit.edu> I'm not familiar enough with wxPython to anwser helpfully, but the wxPython users list might be a better place? I was subscribed to it for a while, and Robin Dunn (wxPython maintainer) is quite helpful on that list. (see www.wxwindows.org for details on the list) HTH, -D On Tue, Apr 03, 2001 at 07:08:47PM +0200, Szalay Zoltan wrote: | Hello! | | Could anyone please tell me why the hell wxTreeCtrl doesn't display images? | Here comes what I do: | | | #----------------------------------- | class MyTreeCtrl(wx.wxTreeCtrl): | def __init__(...): | ... | wx.wxInitAllImageHandlers() | | folderbitmap=wx.wxImage("folder.bmp",wx.wxBITMAP_TYPE_BMP).ConvertToBitmap() | imagelist=wx.wxImageList(16,16) | idx=imagelist.Add(folderbitmap) | self.SetImageList(imagelist) | root=self.AddRoot("root",idx,-1) | #------------------------------------- | | Thanx | Zoltan Szalay | szz@philoslabs.com From bdupire@seatech.fau.edu Tue Apr 3 19:40:29 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 03 Apr 2001 14:40:29 -0400 Subject: [Tutor] debugging a module from a Package with IDLE interpreter Message-ID: <3ACA191D.83E6D194@seatech.fau.edu> I am trying to debug a python program with IDLE... it's really a pain in the neck.. Here is an example... i want to load src.chasm.loader (.py) to debug it. Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.6 -- press F1 for help >>> import src.chasm.loader Traceback (innermost last): ImportError: No module named setNavBehavior.py ### <<< A bug was found >>> ### ### <<< i fix the bug in my editor >>>#### ### << I want to (re) load src.chasm.loader to find the next bug>> ### ## Here are the tries to reload this f #%&?g module. >>> import src.chasm.loader >>> dir(src.chasm.loader) Traceback (innermost last): File "", line 1, in ? dir(src.chasm.loader) AttributeError: loader >>> dir (src) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'chasm', 'resourceFiles'] >>> dir(src.chasm) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'action', 'file', 'loaderException', 'loaderconst', 'navlibconst', 'state'] >>> import src.chasm >>> dir(src.chasm) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'action', 'file', 'loaderException', 'loaderconst', 'navlibconst', 'state'] # no change... >>> from src.chasm import loader Traceback (innermost last): File "", line 1, in ? from src.chasm import loader ImportError: cannot import name loader Do i miss something ? The only thing I found is to kill the Python interpreter and to rerun it..... Thanks for any advice... ben -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From NHYTRO@compuserve.com Tue Apr 3 20:44:39 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Tue, 3 Apr 2001 14:44:39 -0500 Subject: [Tutor] ODBC Message-ID: <200104031344_MC2-CB2D-AF6E@compuserve.com> Nachricht geschrieben von INTERNET:tutor@python.org >From: mbc2@netdoor.com Date: Tue, 3 Apr 2001 07:07:00 -0500 (CDT) To: tutor@python.org Subject: Re: [Tutor] ODBC, MS ACCESS Its not immediately apparent, but there is ODBC connectivity included wit= h python already, at least on the ActiveState Windows version I'm using. Look at the database modules (under Special Topics) section of the= Python website. There's an ODBC module listed there. There isn't alot of documentation on it, but it's been working fine for me.< Thanks, few minutes after my post I discovered a link to Active state :-)= My only problem is: how can I access a database over a network? or with = a Python CGI Script? boy, documentation on this stuff is mighty hard to fin= d. I would be extremy greatful if you could give me an example of remote access from another PC over a network and maybe one with CGI. Great thanks and regards Sharriff From deirdre@deirdre.net Tue Apr 3 19:58:38 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Tue, 3 Apr 2001 11:58:38 -0700 (PDT) Subject: [Tutor] Python In The Wild In-Reply-To: <20010403160229.27216.qmail@web509.mail.yahoo.com> Message-ID: On Tue, 3 Apr 2001, Charles Cheshier wrote: > Hey, I just noticed that too. That Yahoo! seem to be using python on > their site. I wonder why? Python reminds me of this programming > language called ABC, written by some dutch prof. ABC was a precursor language to Python. Guido van Rossum, who is Dutch, was one of the people who worked on ABC and he is the designer for Python. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kauphlyn@speakeasy.org Tue Apr 3 20:23:00 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Tue, 3 Apr 2001 12:23:00 -0700 (PDT) Subject: [Tutor] ODBC In-Reply-To: <200104031344_MC2-CB2D-AF6E@compuserve.com> Message-ID: try this: http://www.python.org/windows/win32/odbc.html its not much, but it gets the job the done. you have set up a DSN with odbc? if not, you have to control panel/odbc or data sources , and then add a system DSN using the ms access driver. hope this helps ~d On Tue, 3 Apr 2001, Sharriff Aina wrote: > Thanks, few minutes after my post I discovered a link to Active state :-) > My only problem is: how can I access a database over a network? or with a > Python CGI Script? boy, documentation on this stuff is mighty hard to find. > I would be extremy greatful if you could give me an example of remote > access from another PC over a network and maybe one with CGI. From dsh8290@rit.edu Tue Apr 3 20:25:26 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 3 Apr 2001 15:25:26 -0400 Subject: [Tutor] debugging a module from a Package with IDLE interpreter In-Reply-To: <3ACA191D.83E6D194@seatech.fau.edu>; from bdupire@seatech.fau.edu on Tue, Apr 03, 2001 at 02:40:29PM -0400 References: <3ACA191D.83E6D194@seatech.fau.edu> Message-ID: <20010403152526.C29241@harmony.cs.rit.edu> On Tue, Apr 03, 2001 at 02:40:29PM -0400, Benoit Dupire wrote: | I am trying to debug a python program with IDLE... it's really a pain in | the neck.. | Here is an example... i want to load src.chasm.loader (.py) to debug it. | | Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 | Type "copyright", "credits" or "license" for more information. | IDLE 0.6 -- press F1 for help | | >>> import src.chasm.loader | Traceback (innermost last): | ImportError: No module named setNavBehavior.py | | ### <<< A bug was found >>> ### | ### <<< i fix the bug in my editor >>>#### | ### << I want to (re) load src.chasm.loader to find the next bug>> ### | ... | Do i miss something ? Yes . CPython tries to be smart (err, fast at least) -- when you import a module, it cahces it. The next time you import it it simply gives you a reference. It doesn't read the file from disk again. Use the reload() function to force the interpreter to read the module from disk again. (I've heard that it doesn't work quite right in PythonWin or Idle or some IDE, but I don't remember which) >>> print reload.__doc__ reload(module) -> module Reload the module. The module must have been successfully imported before. >>> Hmm, it must have been successfully imported before. I suppose the following might work in your situation : import src import sys.chasm.loader ... errors, fix bug reload( src ) import src.chasm.loader HTH, -D From bdupire@seatech.fau.edu Tue Apr 3 20:50:25 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 03 Apr 2001 15:50:25 -0400 Subject: [Tutor] debugging a module from a Package with IDLE interpreter References: <3ACA191D.83E6D194@seatech.fau.edu> <20010403152526.C29241@harmony.cs.rit.edu> Message-ID: <3ACA2981.81D60062@seatech.fau.edu> D-Man wrote: > On Tue, Apr 03, 2001 at 02:40:29PM -0400, Benoit Dupire wrote: > | I am trying to debug a python program with IDLE... it's really a pain in > | the neck.. > | Here is an example... i want to load src.chasm.loader (.py) to debug it. > | > | Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 > | Type "copyright", "credits" or "license" for more information. > | IDLE 0.6 -- press F1 for help > | > | >>> import src.chasm.loader > | Traceback (innermost last): > | ImportError: No module named setNavBehavior.py > | > | ### <<< A bug was found >>> ### > | ### <<< i fix the bug in my editor >>>#### > | ### << I want to (re) load src.chasm.loader to find the next bug>> ### > | > > ... > > Hmm, it must have been successfully imported before. I suppose the > following might work in your situation : Yep, that's my pb. The module was not successfully imported before. > > import src > import src.chasm.loader > ...<<< errors, fix bug>>> > reload( src ) > import src.chasm.loader looks like a good idea... However it does not perform as wanted... >>> import src.chasm.loader NameError: There is no variable named 'neNavBehavior' >>> dir() ['__builtins__', '__doc__', '__name__'] ## src is unknown! >>> import src.chasm.loader >>> dir() ['__builtins__', '__doc__', '__name__', 'src'] >>> reload(src) >>> import src.chasm.loader >>> reload(src.chasm) >>> import src.chasm.loader >>> dir(src.chasm) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'action', 'file', 'loaderException', 'loaderconst', 'navlibconst', 'state'] >>> src.chasm.loader is still unknown.... I think the pb comes from IDLE... ben From ryanbooz@alumni.psu.edu Tue Apr 3 21:00:11 2001 From: ryanbooz@alumni.psu.edu (Ryan Booz) Date: Tue, 03 Apr 2001 16:00:11 -0400 Subject: [Tutor] Tkinter callback question Message-ID: <3ACA2BCB.F5A5611E@alumni.psu.edu> Hello gang, I'm new to the group. And will be honest that I'm not taking the best road to learning with Python. I'm trying to teach it at a small school that has never had programming before. When it came time to jump into classes, I started stalling because I just hadn't gotten far enough ahead of the students and had to play catch-up. So, somewhat stupidly I introduced them to simple Tkinter concepts. Of course the students are very interested in making little GUI programs and so I got caught again. I think I'm looking for an explanation or at least a point in the right direction for the answer... but I'm pretty sure it relates to classes (or the concept at least). How do I get a widget (let's say a button) to execute a command that changes another widget (say a label). This seems like it should be pretty trivial, and I've looked for two days now and only run into more stuff I have to learn (which is ok, just can't get it all done at once). Let's say I make a Label with some text "Hello" and I have two other buttons ("Good-bye", "Hi There") that when pressed would change the Label to their text (or buttons for changing colors or something). How do I do this with one function? In a regular python function you could pass a variable that would make this happen. But if you pass a variable in the command line, it executes at conception and not after that. The only way I can get it to work right now is to have a separate function for each button that changes one one set of things - there's no "variable" in it. If I'm not making any sense, let me know and I'll try to add some examples of what I've done and what I want, but at the moment I have to go teach. Thanks for any help and for your understanding of asking what I'm sure is a straightforward answer that should be obvious. IT's a perspective issue probably. Thanks again, Ryan Booz Tech Coordinator Belleville Mennonite School From cdwom@mpinet.net Tue Apr 3 21:22:58 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Tue, 3 Apr 2001 16:22:58 -0400 Subject: [Tutor] Random Numbers Message-ID: <000901c0bc7b$e0b91880$98dc35d8@KellyJoW> How does one generate random numbers in python? Say from 1-10 for example? Thanks! Corey p.s. I'm still having focus() problems with my texteditor if anyone read those posts :( From rick@niof.net Tue Apr 3 22:21:21 2001 From: rick@niof.net (Rick Pasotto) Date: Tue, 3 Apr 2001 17:21:21 -0400 Subject: [Tutor] Tkinter callback question In-Reply-To: <3ACA2BCB.F5A5611E@alumni.psu.edu>; from ryanbooz@alumni.psu.edu on Tue, Apr 03, 2001 at 04:00:11PM -0400 References: <3ACA2BCB.F5A5611E@alumni.psu.edu> Message-ID: <20010403172121.A4858@tc.niof.net> On Tue, Apr 03, 2001 at 04:00:11PM -0400, Ryan Booz wrote: > > How do I get a widget (let's say a button) to execute a command that > changes another widget (say a label). This seems like it should be > pretty trivial, and I've looked for two days now and only run into more > stuff I have to learn (which is ok, just can't get it all done at > once). Let's say I make a Label with some text "Hello" and I have two > other buttons ("Good-bye", "Hi There") that when pressed would change > the Label to their text (or buttons for changing colors or something). > How do I do this with one function? In a regular python function you > could pass a variable that would make this happen. But if you pass a > variable in the command line, it executes at conception and not after > that. The only way I can get it to work right now is to have a separate > function for each button that changes one one set of things - there's no > "variable" in it. The following code will do what you want. There may be a better way and if so I'd like to know it. In order to pass a parameter to a widget's command I think you need to use a lambda but the lambda namespace does not include the instance's namespace. Thus, since the actual function needs to be outside the class, you need to pass the instance as a parameter. from Tkinter import * class Main: def __init__(self,root): self.root=root self.label = Label(root,width=30,height=3) self.label.pack() frm = Frame(root) self.button1 = Button(frm,text='Hello!', command=lambda x=self:do_change(x,1)) self.button1.pack(side=LEFT,padx=10,pady=5) self.button2 = Button(frm,text='Type it in', command=lambda x=self:do_change(x,2)) self.button2.pack(side=LEFT,padx=10,pady=5) self.button3 = Button(frm,text='Goodbye!', command=lambda x=self:do_change(x,3)) self.button3.pack(side=LEFT,padx=10,pady=5) frm.pack(expand=TRUE,fill=BOTH) self.entry = Entry(bg='white',width=20) self.entry.pack(padx=10,pady=5) def do_change(self,button=0): if button == 1: self.label.config(text='Hello!') if button == 2: txt = self.entry.get() self.label.config(text=txt) if button == 3: self.label.config(text='Goodbye!') if __name__=='__main__': root = Tk() main = Main(root) root.mainloop() -- "In the U.S. you have to be a deviant or exist in extreme boredom... Make no mistake; all intellectuals are deviants in the U.S." -- William Burroughs Rick Pasotto email: rickp@telocity.com From bsass@freenet.edmonton.ab.ca Tue Apr 3 22:36:34 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Tue, 3 Apr 2001 15:36:34 -0600 (MDT) Subject: [Tutor] Random Numbers In-Reply-To: <000901c0bc7b$e0b91880$98dc35d8@KellyJoW> Message-ID: On Tue, 3 Apr 2001, Corey Woodworth wrote: > How does one generate random numbers in python? Say from 1-10 for example? >>> import random >>> random.randint(1,10) 7 - Bruce From Rob Andrews" Message-ID: <00f101c0bc87$130e8760$9600a8c0@Planhouse5> A quick reference for random stuff in Python is the Python Library Reference: http://www.python.org/doc/current/lib/module-whrandom.html http://www.python.org/doc/current/lib/module-random.html Here's a really terse example: >>> import whrandom >>> doh = whrandom.randint(1, 10) >>> dog = whrandom.randint(1, 10) >>> doh 5 >>> dog 7 Someone less newbie-like than I am can likely explain them better, but I think this should do it. There are some source examples on Useless Python (http://www.lowerstandard.com/python/pythonsource.html) that demonstrate a few other things that may be done randomly in Python. Rob > How does one generate random numbers in python? Say from 1-10 for example? > > Thanks! > Corey > > p.s. I'm still having focus() problems with my texteditor if anyone read > those posts :( > From charliederr@organicmeat.net Tue Apr 3 22:52:34 2001 From: charliederr@organicmeat.net (Charlie Derr) Date: Tue, 3 Apr 2001 17:52:34 -0400 Subject: [Tutor] Random Numbers In-Reply-To: <000901c0bc7b$e0b91880$98dc35d8@KellyJoW> Message-ID: ~ -----Original Message----- ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ Corey Woodworth ~ Sent: Tuesday, April 03, 2001 4:23 PM ~ To: Python Tutor List ~ Subject: [Tutor] Random Numbers ~ ~ ~ How does one generate random numbers in python? Say from 1-10 for example? >>> import random >>> my_random_number = random.choice(range(1,11)) >>> my_random_number 1 >>> another_one = random.choice(range(1,11)) >>> another_one 5 >>> ~ ~ Thanks! ~ Corey yw ~ ~ p.s. I'm still having focus() problems with my texteditor if anyone read ~ those posts :( sorry, didn't read those posts ~ ~ ~ _______________________________________________ ~ Tutor maillist - Tutor@python.org ~ http://mail.python.org/mailman/listinfo/tutor ~ From lha2@columbia.edu Tue Apr 3 23:23:03 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Tue, 03 Apr 2001 18:23:03 -0400 Subject: [Tutor] dovetail shuffle References: Message-ID: <3ACA4D47.DE8D4D38@mail.verizon.net> Last night while procrastinating, I wrote: > --------begin module dovetail.py-------------- > import random > > def dovetail(deck,splitprecision=2,thumb=2): > """Shuffles a deck in a fashion that (hopefully) approximates a "real" shuffle > > This performs something that hopefully approximates the dovetail shuffle > that I remember reading about two years ago when taking a course from Dave > Bayer. See Bayer, D. and Diaconis, P. (1992). 'Trailing the dovetail > shuffle to its lair.' Ann. Appl. Probab. 2 (1992), no. 2 , 294-313.""" #stuff > left=deck[:-1*split] #perform the split > right=deck[split:] #stuff this should be changed to left=deck[:split] #perform the split right=deck[split + 1:] Silly me...I was trying to figure out over lunch why my deck kept growing, and growing, and growing...but that's what happens if every so often you take the first 28 cards and the last 28 cards of a 52 card deck and shuffle them together. Sorry to respond to my own post. Now to figure out how to make this a thingamajiggy-in-place doohickey on a deck object. From jgbrawley@earthlink.net Tue Apr 3 23:45:03 2001 From: jgbrawley@earthlink.net (John Brawley) Date: Tue, 3 Apr 2001 17:45:03 -0500 Subject: [Tutor] Nondestructive interrupting Message-ID: <006601c0bc8f$bec4fd20$bd76d918@jb2> Hello, all; newbie here. I've got a script that runs endlessly (on purpose). It creates a spherical region of space and starts moving points in the space around, and is intended to run forever. However, in the process of fine-tuning it, I need to be able to stop it (without raising an error or exception, as happens now when I stop it with a ctrl-C), and then do "one more thing." There are reasons why I can't do this last thing inside the main part ofthe script, and reasons why I can't do it after the script has terminated with the keyboard interruption (ctrl-C). I tried to use msvcrt --from sys.platform, but it won't work for me (and I'd rather not use Win-Doze-specific in the Python). All I want to do is insert a "watchdog" line in the main body of the script, which repeatedly checks to see if a key has been pressed (_any_ key, although a specific key would be fine also), and then does this last thing and terminates the script. _Why_ I can't find such a simple thing in any of the Python docs, manuals, tutorials, at python.org, or anywhere else, frazzles me; it ought to be an obvious and basic function.... Can anyone tell me? Thanks JB jgbrawley@earthlink.net Web: http://www.jcn1.com/jbrawley http://home.earthlink.net/~jgbrawley From vlindberg@verio.net Wed Apr 4 01:46:22 2001 From: vlindberg@verio.net (VanL) Date: Tue, 03 Apr 2001 18:46:22 -0600 Subject: [Tutor] Still on Linked Lists Message-ID: <3ACA6EDE.77866BBC@verio.net> I know that all of you are probably going to groan, but I really don't have any special affection for linked lists. I am just trying to use them as a tool to learn stuff. That said, I have two questions. I will raise one in this email and the other in the next. 1. I put together a new implementation of a linked list class: class LinkedList2: """ This class provides a generic node for linked lists. Other python classes or objects can inherit from this class to get the ability to represent themselves as a linked list. """ def __init__(self, name, data=None, object=None): self = (name, data, object) def next(self): return self[2] def label(self): return self[0] def setdata(self, object): self[1] = object def getdata(self): return self[1] def link(self, object): self[2] = object def unlink(self): self[2] = None def rename(self, name): self[0] = name However, this doesn't work: >>> from LinkedList2 import * >>> this = LinkedList2('thisname') >>> that = LinkedList2('thatname', 'somedata', this) >>> theother = LinkedList2('theothername', 'someotherdata', that) >>> print theother Traceback (most recent call last): File "", line 1, in ? File "LinkedList2.py", line 32, in __str__ print self[0], self[1], self[2] AttributeError: 'LinkedList2' instance has no attribute '__getitem__' >>> Why? Thanks, Van From vlindberg@verio.net Wed Apr 4 01:52:28 2001 From: vlindberg@verio.net (VanL) Date: Tue, 03 Apr 2001 18:52:28 -0600 Subject: [Tutor] Classes Message-ID: <3ACA704C.249A6551@verio.net> Here is my second question: I am investigating python's inheritance structure. Given the class LinkedList: class LinkedList: """ This class provides a generic node for linked lists. Other python classes or objects can inherit from this class to get the ability to represent themselves as a linked list. """ def __init__(self, name, object=None): self.__label = name if object: self.__link = object else: self.__link = None [snip to end] and the class NewClass: class NewClass(LinkedList): def __init__(self): NewString = "This is a new string" def NewString(self): print NewString How do I supply the superclass constructor arguments when instancing an object of type newclass? How does this change if I inherit from multiple classes? Thanks, Van From tim.one@home.com Wed Apr 4 00:51:05 2001 From: tim.one@home.com (Tim Peters) Date: Tue, 3 Apr 2001 19:51:05 -0400 Subject: [Tutor] Random Numbers In-Reply-To: <00f101c0bc87$130e8760$9600a8c0@Planhouse5> Message-ID: [Rob Andrews] > Here's a really terse example: > > >>> import whrandom > >>> doh = whrandom.randint(1, 10) > >>> dog = whrandom.randint(1, 10) > >>> doh > 5 > >>> dog > 7 Please don't use whrandom. This was a long-standing confusion in the docs and the code, finally cleared up in 2.1: whrandom will go away some day. "random" is what you want. >>> import random >>> random.randint(1, 10) 4 >>> From lha2@columbia.edu Wed Apr 4 02:27:58 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Tue, 03 Apr 2001 21:27:58 -0400 Subject: [Tutor] debugging a module from a Package with IDLE interpreter Message-ID: <3ACA789E.3A2A32DE@mail.verizon.net> Message from Benoit Dupire begins ------------ I am trying to debug a python program with IDLE... it's really a pain in the neck.. >>> from src.chasm import loader Traceback (innermost last): File "", line 1, in ? from src.chasm import loader ImportError: cannot import name loader Do i miss something ? The only thing I found is to kill the Python interpreter and to rerun it..... Thanks for any advice... -----ends--------------- You have two windows open: the Python Shell and the module with which you are playing. Save your module, and, WITH THE MODULE YOU JUST MODIFIED (and saved) IN THE FOREGROUND, hit f5. It'll reload. I had the same problem and started poking around in the Idle documentation--there's a lot of neat stuff in there. Even figured out (a little) how to run the debugger. Nothing for figuring out scope like watching the debugger run. Few things as tedious, also. -LHA From arcege@shore.net Wed Apr 4 02:48:30 2001 From: arcege@shore.net (Michael P. Reilly) Date: Tue, 3 Apr 2001 21:48:30 -0400 (EDT) Subject: [Tutor] Nondestructive interrupting In-Reply-To: <006601c0bc8f$bec4fd20$bd76d918@jb2> from "John Brawley" at Apr 03, 2001 05:45:03 PM Message-ID: <200104040148.f341mU002205@dsl254-114-246.nyc1.dsl.speakeasy.net> John Brawley wrote > Hello, all; newbie here. > > I've got a script that runs endlessly (on purpose). > It creates a spherical region of space and starts moving points in the > space around, and is intended to run forever. > > However, in the process of fine-tuning it, I need to be able to stop it > (without raising an error or exception, as happens now when I stop it > with a ctrl-C), and then do "one more thing." The Ctrl-C causes the KeyboardInterrupt to be raised. This can be caught inside your loop or just outside it. inside def main(): while 1: try: do_something_fun() except KeyboardInterrupt: do_one_more_thing() break main() outside def main(): try: while 1: do_something_fun() except KeyboardInterrupt: do_one_more_thing() main() You can also deal with the routine regardless of how the program was stopped by using try-finally. def main(): while 1: do_something_fun() try: main() finally: # always gets called do_one_more_thing() > There are reasons why I can't do this last thing inside the main part > ofthe script, and reasons why I can't do it after the script has > terminated with the keyboard interruption (ctrl-C). > > I tried to use msvcrt --from sys.platform, but it won't work for me > (and I'd rather not use Win-Doze-specific in the Python). > > All I want to do is insert a "watchdog" line in the main body of the > script, which repeatedly checks to see if a key has been pressed (_any_ > key, although a specific key would be fine also), and then does this > last thing and terminates the script. Checking for a hardware event like that is bit more difficult. Python tried hard to be as platform independant as possible, and checking for a keyboard press is very platform dependant. -Arcege > _Why_ I can't find such a simple thing in any of the Python docs, > manuals, tutorials, at python.org, or anywhere else, frazzles me; it > ought to be an obvious and basic function.... References: Python Tutorial, section 2.2.1 Error Handling Python Library Reference, section 2.2 Built-in Exceptions Python Tutorial, section 8.3 Handling Exceptions -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From john_maldives@hotmail.com Wed Apr 4 04:53:30 2001 From: john_maldives@hotmail.com (John Lenon) Date: Wed, 04 Apr 2001 08:53:30 +0500 Subject: [Tutor] attention Message-ID: i want to get posted t othe list _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From scarblac@pino.selwerd.nl Wed Apr 4 07:30:25 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 4 Apr 2001 08:30:25 +0200 Subject: [Tutor] Classes In-Reply-To: <3ACA704C.249A6551@verio.net>; from vlindberg@verio.net on Tue, Apr 03, 2001 at 06:52:28PM -0600 References: <3ACA704C.249A6551@verio.net> Message-ID: <20010404083025.B7460@pino.selwerd.nl> On Tue, Apr 03, 2001 at 06:52:28PM -0600, VanL wrote: > Here is my second question: > > I am investigating python's inheritance structure. Given the class > LinkedList: > > class LinkedList: > > """ This class provides a generic node for linked lists. Other > python classes or > objects can inherit from this class to get the ability to represent > themselves as > a linked list. """ > > def __init__(self, name, object=None): > self.__label = name > if object: self.__link = object > else: self.__link = None > > [snip to end] > > > and the class NewClass: > > class NewClass(LinkedList): > > def __init__(self): > NewString = "This is a new string" LinkedList.__init__(self, "somename") > > def NewString(self): > print NewString > > > How do I supply the superclass constructor arguments when instancing an > object of type newclass? How does this change if I inherit from > multiple classes? If you inherit from multiple classes you can call __init__ in each of them, if necessary. Btw, the NewString doesn't work, the variable has to be 'self.NewString', and the function needs a different name (otherwise the self.NewString assignment in __init__ would overwrite the function). -- Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Wed Apr 4 07:56:07 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 3 Apr 2001 23:56:07 -0700 (PDT) Subject: [Tutor] Tkinter callback question [and the Command class] In-Reply-To: <3ACA2BCB.F5A5611E@alumni.psu.edu> Message-ID: On Tue, 3 Apr 2001, Ryan Booz wrote: > How do I get a widget (let's say a button) to execute a command that > changes another widget (say a label). This seems like it should be [warning --- slightly long message] One way to change the contents of a label is to use StringVar()'s. Here's an example of a StringVar: s = StringVar() StringVars allow us to change the contents of a label, as long as we created the Label to listen to it. That is, when we make the label: l = Label(textvariable=s) we can later call the set() or get() methods of our StringVar. Whenever we do something to our StringVar, something will happen to the label. For example: ### from Tkinter import * root = Tk() s = StringVar() l = Label(root, textvariable=s) s.set("Hello World!") ### is a small script that uses StringVars. I think the real question that you're asking about is how to use Tkinter callbacks, and how to pass arguments off to functions that we haven't called yet. It won't do if we try to do something like: b = Button(text='Goodbye', command=s.set('goodbye!')) simply because s.set() is being called too early: we want to somehow "delay" the call to the function, but still pass that particular argument when the time is right. Here's something that will do what you want: take a look below at the sample code: ### from Tkinter import * class Command: """ A class we can use to avoid using the tricky "Lambda" expression. "Python and Tkinter Programming" by John Grayson, introduces this idiom.""" def __init__(self, func, *args, **kwargs): self.func = func self.args = args self.kwargs = kwargs def __call__(self): apply(self.func, self.args, self.kwargs) if __name__ == '__main__': root = Tk() contents = StringVar() contents.set("Default message") l = Label(root, textvariable=contents) l.pack() b1 = Button(root, text="Goodbye", command=Command(contents.set, "goodbye!")) b2 = Button(root, text="Hello", command=Command(contents.set, "greetings!")) b1.pack() b2.pack() mainloop() ### The idea is to use a "Command" class: it takes in a function's name and the arguments that you want to pass to that function. Rather than calling the function immediately, it acts as the delayer. For example: ### def sayHello(name): print "Hello", name hiRyan = Command(sayHello, 'Ryan') # a delayed sayHello hiRyan() # Here's where we actually call the function. ### In this case, "hiRyan" takes on the value of a function, and only after we call it does sayHello() fire off. Likewise,i n the Tkinter example, we're giving our buttons a function that knows exactly what arguments to pass to contents.set(), without actually doing it immediately. This avoids the problem of having the functions fire off too quickly, and also lets us pass in our arguments. (Side note: the more traditional way to do the above is to use lambda's, but after being exposed to this Command idiom, I'm really leaning toward using the Command class: it's easier to read.) If you want to show this to your students, it's probably a good idea to just give them the Command class to play with: tell them how to use it, and point them to us when they want to know how it actually works. *grin* > If I'm not making any sense, let me know and I'll try to add some > examples of what I've done and what I want, but at the moment I have > to go teach. Thanks for any help and for your understanding of asking > what I'm sure is a straightforward answer that should be obvious. > IT's a perspective issue probably. You're making sense. Still, it'd be cool to see what you've shown your students. Can you show us some examples? Good luck to you! From sheila@thinkspot.net Wed Apr 4 08:00:09 2001 From: sheila@thinkspot.net (Sheila King) Date: Wed, 04 Apr 2001 00:00:09 -0700 Subject: [Tutor] Still on Linked Lists In-Reply-To: <3ACA6EDE.77866BBC@verio.net> References: <3ACA6EDE.77866BBC@verio.net> Message-ID: <38EACCC09B9@kserver.org> On Tue, 03 Apr 2001 18:46:22 -0600, VanL wrote about [Tutor] Still on Linked Lists: :1. I put together a new implementation of a linked list class: : :class LinkedList2: : : """ This class provides a generic node for linked lists. Other :python classes or : objects can inherit from this class to get the ability to represent :themselves as : a linked list. """ : : def __init__(self, name, data=None, object=None): : self = (name, data, object) : : def next(self): : return self[2] : : def label(self): : return self[0] : : def setdata(self, object): : self[1] = object : : def getdata(self): : return self[1] : : def link(self, object): : self[2] = object : : def unlink(self): : self[2] = None : : def rename(self, name): : self[0] = name It looked fine to me, so I pasted the above into an interpreter session, and then tried your commands below: :However, this doesn't work: : :>>> from LinkedList2 import * :>>> this = LinkedList2('thisname') :>>> that = LinkedList2('thatname', 'somedata', this) :>>> theother = LinkedList2('theothername', 'someotherdata', that) :>>> print theother : :Traceback (most recent call last): : File "", line 1, in ? : File "LinkedList2.py", line 32, in __str__ : print self[0], self[1], self[2] :AttributeError: 'LinkedList2' instance has no attribute '__getitem__' :>>> I got no error. Here is my interpreter session: >>> this = LinkedList2('thisname') >>> that = LinkedList2('thatname', 'somedata', this) >>> theother = LinkedList2('theothername', 'someotherdata', that) >>> print theother <__main__.LinkedList2 instance at 00B3601C> >>> Mind you, since I pasted the code for your class definition directly into the interpreter, I didn't need to use the "import" statement. I suspect this is where you're having trouble. So, I'll save your class as a file, called LinkedList2.py and try again, in a new interpreter session. Here it is: Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.6 -- press F1 for help >>> from LinkedList2 import * >>> this = LinkedList2('thisname') >>> that = LinkedList2('thatname', 'somedata', this) >>> theother = LinkedList2('theothername', 'someotherdata', that) >>> print theother >>> Hmm. Beats me why it doesn't work for you. Seems to work for me just fine ??? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From scarblac@pino.selwerd.nl Wed Apr 4 08:11:07 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 4 Apr 2001 09:11:07 +0200 Subject: [Tutor] Still on Linked Lists In-Reply-To: <38EACCC09B9@kserver.org>; from sheila@thinkspot.net on Wed, Apr 04, 2001 at 12:00:09AM -0700 References: <3ACA6EDE.77866BBC@verio.net> <38EACCC09B9@kserver.org> Message-ID: <20010404091107.A8056@pino.selwerd.nl> On Wed, Apr 04, 2001 at 12:00:09AM -0700, Sheila King wrote: > I got no error. Here is my interpreter session: > > >>> this = LinkedList2('thisname') > >>> that = LinkedList2('thatname', 'somedata', this) > >>> theother = LinkedList2('theothername', 'someotherdata', that) > >>> print theother > <__main__.LinkedList2 instance at 00B3601C> > >>> The reason you get no error on 'print' is that his code as posted didn't contain the __str__ function, but his original error came from that, so we didn't see something. However, the whole construct with 'self = (a,b,c)' and returning 'self[1]' can't work. Try some of the other functions. __init__ can't make the object into something else, it can only *change* the existing object; for instance, by assigning to something 'inside' it, i.e., self.name = name. And it's a good thing too, if assigning a tuple to self did work, then the methods would be gone, since a tuple doesn't have them :-). -- Remco Gerlich From dyoo@hkn.eecs.berkeley.edu Wed Apr 4 08:26:36 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 4 Apr 2001 00:26:36 -0700 (PDT) Subject: [Tutor] Still on Linked Lists [References, UserDict] In-Reply-To: <3ACA6EDE.77866BBC@verio.net> Message-ID: On Tue, 3 Apr 2001, VanL wrote: > I know that all of you are probably going to groan, but I really don't > have any special affection for linked lists. I am just trying to use > them as a tool to learn stuff. No prob, don't worry about it. > That said, I have two questions. I will raise one in this email and the > other in the next. > > 1. I put together a new implementation of a linked list class: > > class LinkedList2: > > """ This class provides a generic node for linked lists. Other > python classes or > objects can inherit from this class to get the ability to represent > themselves as > a linked list. """ > > def __init__(self, name, data=None, object=None): > self = (name, data, object) There's something here that you'll need to fix; unfortunately, the tuple assignment here doesn't quite work, since self is more like a dictionary than a list. To set things inside self, we need to use the period scoping operator ("."). For example, we'll want something like: def __init__(self, name, data=None, object=None): self.name, self.data, self.object = name, data, object which will do the assignment. What you had before did something different: it assigned the name "self" to the tuple (name, data, object), which won't work. Let's take a look again: > def __init__(self, name, data=None, object=None): > self = (name, data, object) It's the situation that Shelia King ran across with references: here, we're saying that, locally, "self" now stands for a tuple of 3 elements, which is certainly not what we want; we want to change the object that "self" refers to, and not redirect "self" to a new object. In any case, with those changes in mind, the accessor functions will need to change, since we're using "self" this way: > def next(self): > return self[2] becomes: def next(self): return self.object > def label(self): > return self[0] becomes: def label(self): return self.name etc. > However, this doesn't work: > > >>> from LinkedList2 import * > >>> this = LinkedList2('thisname') > >>> that = LinkedList2('thatname', 'somedata', this) > >>> theother = LinkedList2('theothername', 'someotherdata', that) > >>> print theother > > Traceback (most recent call last): > File "", line 1, in ? > File "LinkedList2.py", line 32, in __str__ > print self[0], self[1], self[2] > AttributeError: 'LinkedList2' instance has no attribute '__getitem__' By default, we need to change the components of self using that period-scoping syntax. Indexing on "self" doesn't work by default; that's where that AttributeError is coming from. However, it is possible to do this, but it takes some extra work by using UserDict: http://python.org/doc/current/lib/module-UserDict.html If you use UserDict, then your code will work: ### import UserDict class LinkedList2(UserDict.UserDict): def __init__(self, name, data=None, object=None): UserDict.UserDict.__init__(self) self[0], self[1], self[2] = name, data, object # and everything else stays the same. ### But you'll need to experiment with UserDict a bit, just to see how it works. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Wed Apr 4 08:45:10 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 4 Apr 2001 00:45:10 -0700 (PDT) Subject: [Tutor] Classes In-Reply-To: <3ACA704C.249A6551@verio.net> Message-ID: On Tue, 3 Apr 2001, VanL wrote: > Here is my second question: > > I am investigating python's inheritance structure. Given the class > LinkedList: > > class LinkedList: > > """ This class provides a generic node for linked lists. Other > python classes or > objects can inherit from this class to get the ability to represent > themselves as > a linked list. """ > > def __init__(self, name, object=None): > self.__label = name > if object: self.__link = object > else: self.__link = None > > [snip to end] > > > and the class NewClass: > > class NewClass(LinkedList): > > def __init__(self): > NewString = "This is a new string" > > def NewString(self): > print NewString > > > How do I supply the superclass constructor arguments when instancing an > object of type newclass? How does this change if I inherit from > multiple classes? In Python, you'll need to call the superclass's constructor explicitely. If you're coming from a Java or C++ background, this will come as a small shock, since those languages take implicit steps to get constructors to run. Here's a definition of NewClass's constructor that calls the parent's constructor: ### class NewClass(LinkedList): def __init__(self): LinkedList.__init__(self) # Calling superclass's constructor NewString = "This is a new string" ### Dealing with multiple inheritance is similar: just call each parent's init function. Another way to do it is to be a little more implicit: every instance implicitely knows where it came from, that is, what class it's from. For example, we can say something like: self.__class__ and get access to the class, which is pretty neat. But more importantly, we can get to the parents of any particular class through the __bases__ of a class: ### >>> class Parent: ... def __init__(self): ... print "I am a parent" ... >>> p = Parent() I am a parent >>> class Child(Parent): ... def __init__(self): ... print self.__class__.__bases__, 'is a tuple of my parents.' ... self.__class__.__bases__[0]() # Call the parent's constructor ... print "End of child's constructor" ... >>> c = Child() (,) is a tuple of my parents. I am a parent End of child's constructor ### I know I'm going a little too fast and informal, but I hope this gives a taste of how to call parent constructors. Hope this helps! From alan.gauld@bt.com Wed Apr 4 11:25:22 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 4 Apr 2001 11:25:22 +0100 Subject: [Tutor] Tkinter callback question Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6A8@mbtlipnt02.btlabs.bt.co.uk> > and so I got caught again. I think I'm looking for an > explanation or at least a point in the right direction Your timing is good. I just loaded the latest update to my Tkinter topic. Try http://www.crosswinds.net/~agauld/tutgui.htm It covers exactly what you ask for plus a lot more. It has one section to be completed plus some hyperlinks to F/s tutor. Also it includes a Tcl/Tk for comparison and a wxPython example to show what else is available. Hopefully I'll finish the page this weekend. > sure it relates to classes (or the concept at least). Nope - that's the bit I haven't done yet :-) But you don't need classes for Tkinter. Enjoy, Alan g http;//www.crosswinds.net/~agauld/ From danny@intuitivemedia.com Wed Apr 4 11:44:58 2001 From: danny@intuitivemedia.com (Danny Ruttle) Date: Wed, 04 Apr 2001 11:44:58 +0100 Subject: [Tutor] libpq and PgSQL modules Message-ID: <5.0.2.1.0.20010404114144.00a20310@mail.moonshine.co.uk> Hi I'm desperately trying to locate the source code for these Postgres API modules. Please please please could someone post some URLs to these files. I'm running FreeBSD 4.0 on i386 platform. regards Danny From alan.gauld@bt.com Wed Apr 4 11:39:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 4 Apr 2001 11:39:45 +0100 Subject: [Tutor] Still on Linked Lists Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6A9@mbtlipnt02.btlabs.bt.co.uk> > class LinkedList2: > def __init__(self, name, data=None, object=None): > self = (name, data, object) AArgh! This is a really bad idea. Never, ever, mess with self(OK, Never say never but...) self represents the instance itself thus you are trying to replace your object with a tuple! That's not smart. Instead create an instance variable that holds the tuple: self.items = (name, data, object) > def next(self): > return self[2] This won't work because self no longer exists as an object. (Indeed you couldn't actually even call it!) If you do as suggested above you need to rewrite the methods as: def next(self): return self.items[2] > Traceback (most recent call last): > File "", line 1, in ? > File "LinkedList2.py", line 32, in __str__ > print self[0], self[1], self[2] > AttributeError: 'LinkedList2' instance has no attribute '__getitem__' If you really want to access self as a sequence you need to provide a __getitem__ method. Since you didn't the call fails. You could have done: def __getitem__(self, i): return self.items[i] And it might have worked - but I haven't tried... adding an instance variable is better IMO. Alan G From alan.gauld@bt.com Wed Apr 4 11:43:28 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 4 Apr 2001 11:43:28 +0100 Subject: [Tutor] Nondestructive interrupting Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6AA@mbtlipnt02.btlabs.bt.co.uk> > tried hard to be as platform independant as possible, > and checking for a keyboard press is very platform dependant. But not too hard if you wrap the program in a Tkinter wrapper. Just a very small window which coulkd be iconified would do it. But I think checking for the Interrupt error as already suggested should suffice. Alan G. From joerg.sporer@opencom.de Wed Apr 4 14:42:05 2001 From: joerg.sporer@opencom.de (=?iso-8859-1?Q?J=F6rg_Sporer?=) Date: Wed, 4 Apr 2001 15:42:05 +0200 Subject: [Tutor] Memory Management? Message-ID: <000001c0bd0d$0a0db970$3701000a@arthur> SGVsbG8gZXZlcnlvbmUhDQoNCldoZW4gSSBydW4gbXkgUHl0aG9uIHByb2dyYW0gKGFib3V0IDMw MCBsb2Mgd2l0aCBUa2ludGVyIEd1aSkgaXQgdXNlcyBhYm91dA0KOCBNQiBtZW1vcnkhDQpBZnRl ciBJIG1pbmltaXplIGl0IHRvIHRoZSB0YXNrYmFyIGFuZCBvcGVuIGl0IGFnYWluIGl0IG9ubHkg dXNlcyB+MU1CLiBJcw0KdGhlcmUgYSBnYXJiYWdlIGNvbGxlY3RvciBvciBzb21ldGhpbmcgd29y a2luZyBpbiB0aGUgYmFja2dyb3VuZD8NCg0KVGhhbmtzDQpK9nJnDQoNCg== From dsh8290@rit.edu Wed Apr 4 15:40:56 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 4 Apr 2001 10:40:56 -0400 Subject: [Tutor] attention In-Reply-To: ; from john_maldives@hotmail.com on Wed, Apr 04, 2001 at 08:53:30AM +0500 References: Message-ID: <20010404104056.C1602@harmony.cs.rit.edu> On Wed, Apr 04, 2001 at 08:53:30AM +0500, John Lenon wrote: | i want to get posted t othe list You must join the list to recieve posts that are sent to the list. See http://mail.python.org/mailman/listinfo/tutor for instructions on joining the list. To post a message, simply send an e-mail to tutor@python.org (as you did for this message). When you have questions regarding python, just ask and somebody will answer it. -D From dsh8290@rit.edu Wed Apr 4 16:12:12 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 4 Apr 2001 11:12:12 -0400 Subject: [Tutor] debugging a module from a Package with IDLE interpreter In-Reply-To: <3ACA2981.81D60062@seatech.fau.edu>; from bdupire@seatech.fau.edu on Tue, Apr 03, 2001 at 03:50:25PM -0400 References: <3ACA191D.83E6D194@seatech.fau.edu> <20010403152526.C29241@harmony.cs.rit.edu> <3ACA2981.81D60062@seatech.fau.edu> Message-ID: <20010404111212.C1802@harmony.cs.rit.edu> On Tue, Apr 03, 2001 at 03:50:25PM -0400, Benoit Dupire wrote: | D-Man wrote: ... | > Hmm, it must have been successfully imported before. I suppose the | > following might work in your situation : | | Yep, that's my pb. The module was not successfully imported before. | ... | looks like a good idea... | However it does not perform as wanted... ... | I think the pb comes from IDLE... Could be. If you aren't using any special features from IDLE (other than the interactiveness, of course) then may I suggest using the command line? If you are using windows, get cygwin. Bash is far superior to DOS. My technique tends to be one of using (g)vim to edit and an "xterm" (ok, so I'm on windows too now, it's a DOS-term with cygwin) to run/test. If it fails I can simply type "!![enter]" to execute the command again. This is much easier and faster than hunting down idle in the start menu and then setting it up again. -D From jgbrawley@earthlink.net Wed Apr 4 16:28:24 2001 From: jgbrawley@earthlink.net (John Brawley) Date: Wed, 4 Apr 2001 10:28:24 -0500 Subject: [Tutor] Nondestructive interrupting References: <5104D4DBC598D211B5FE0000F8FE7EB20751D6AA@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <001301c0bd1b$e5b6c120$bd76d918@jb2> Yes, Alan. Thank you. The suggested method(s) generated a cure, which I will use. Of course re: Tkinter: ----- Original Message ----- From: Me: > > tried hard to be as platform independant as possible, > > and checking for a keyboard press is very platform dependant. > > But not too hard if you wrap the program in a Tkinter > wrapper. Just a very small window which coulkd be iconified > would do it. When the script starts looking like a "program," I will of course have to tackle Tkinter (which I look forward to), but for now I have to make sure the "guts" of the program does exactly what I want it to. Designing a Tkinter GUI interface is going to be fun, but it's not required: basically I'm researching something of extreme importance only to me. Yes, there is a small community of people (like, maybe three or four(*g*)) interested in seeing what the program puts out, but they are mostly all programmers with an interest in "Elastic Interval Geometry," so the one or two also doing Python could use the script/program without needing a GUI, the ones not can see the image files the others put out, and I certainly don't need one for myself. Thanks for the help! JB jgbrawley@earthlink.net Web: http://www.jcn1.com/jbrawley http://home.earthlink.net/~jgbrawley From vlindberg@verio.net Wed Apr 4 21:25:09 2001 From: vlindberg@verio.net (VanL) Date: Wed, 04 Apr 2001 14:25:09 -0600 Subject: [Tutor] Sorting algorithm? Message-ID: <3ACB8325.26C23E2D@verio.net> What sorting algorithm is used to sort lists? given >>> list = ['base', 'ball', 'mound', 'bat', 'glove', 'batter'] >>> list.sort() >>> print list ['ball', 'base', 'bat', 'batter', 'glove', 'mound'] What happens behind the scenes? Quicksort, a la Perl? or some other algorithm, possibly depending on the size of n? From shaleh@valinux.com Wed Apr 4 21:41:30 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 04 Apr 2001 13:41:30 -0700 (PDT) Subject: [Tutor] Sorting algorithm? In-Reply-To: <3ACB8325.26C23E2D@verio.net> Message-ID: On 04-Apr-2001 VanL wrote: > > What sorting algorithm is used to sort lists? > > given >>>> list = ['base', 'ball', 'mound', 'bat', 'glove', 'batter'] >>>> list.sort() >>>> print list > ['ball', 'base', 'bat', 'batter', 'glove', 'mound'] > > What happens behind the scenes? Quicksort, a la Perl? or some other > algorithm, possibly depending on the size of n? In the python source, look at Objects/listobject.c. From vlindberg@verio.net Wed Apr 4 22:05:51 2001 From: vlindberg@verio.net (VanL) Date: Wed, 04 Apr 2001 15:05:51 -0600 Subject: [Tutor] Sorting algorithm? References: Message-ID: <3ACB8CAF.7A10DC37@verio.net> Sean 'Shaleh' Perry wrote: > In the python source, look at Objects/listobject.c. I would, but I don't have a copy of the source handy... I thought that someone might know offhand. -V- From tutor@python.org Wed Apr 4 22:07:10 2001 From: tutor@python.org (Tim Peters) Date: Wed, 4 Apr 2001 17:07:10 -0400 Subject: [Tutor] Sorting algorithm? In-Reply-To: <3ACB8325.26C23E2D@verio.net> Message-ID: [VanL] > What sorting algorithm is used to sort lists? > > given > >>> list = ['base', 'ball', 'mound', 'bat', 'glove', 'batter'] > >>> list.sort() > >>> print list > ['ball', 'base', 'bat', 'batter', 'glove', 'mound'] > > What happens behind the scenes? Quicksort, a la Perl? or some other > algorithm, possibly depending on the size of n? It's a hybrid algorithm, using binary insertion sort on "small" slices and samplesort on "large" slices. samplesort is an extreme variation of quicksort, that reduces the asymptotic number of expected compares down to N * log2(N). This makes the expected number of compares comparable to mergesort (close to the theoretical minimum), but samplesort requires far less data movement than mergesort. Compares are expensive in Python, so minimizing compares is the primary goal for a Python sort. Sorry there isn't an easy answer, but Python's .sort() method is in fact complicated. A long time ago, Python *did* use the platform C library's qsort() function, but that was much slower, and on some platforms had bugs we couldn't worm around. From vlindberg@verio.net Wed Apr 4 22:57:07 2001 From: vlindberg@verio.net (VanL) Date: Wed, 04 Apr 2001 15:57:07 -0600 Subject: [Tutor] Sorting algorithm? References: Message-ID: <3ACB98B3.81C5EAF1@verio.net> Tim Peters wrote: > > It's a hybrid algorithm, using binary insertion sort on "small" slices and > samplesort on "large" slices. samplesort is an extreme variation of > quicksort, that reduces the asymptotic number of expected compares down to N > * log2(N). This makes the expected number of compares comparable to > mergesort (close to the theoretical minimum), but samplesort requires far > less data movement than mergesort. Compares are expensive in Python, so > minimizing compares is the primary goal for a Python sort. Thanks for your informative reply. Just two quick questions: 1. Why are compares expensive in Python? Is this because type must be idenitfied first? 2. Do you know of a good page that describes the samplesort algorithm? A search or two on google found some notes on parallel implementation of the algorithm, but none on the algorithm itself. Thank you, Van From tutor@python.org Wed Apr 4 23:05:49 2001 From: tutor@python.org (Tim Peters) Date: Wed, 4 Apr 2001 18:05:49 -0400 Subject: [Tutor] Sorting algorithm? In-Reply-To: <3ACB98B3.81C5EAF1@verio.net> Message-ID: [VanL] > 1. Why are compares expensive in Python? Is this because type must be > idenitfied first? Mostly, yes. There are always at least several layers of C function call involved in each comparison made by list.sort(), even if the "real work" consists of just one or two machine instructions. If you pass a custom comparison function, or have objects that implement their own __cmp__ method, then a (at least one) *Python*-level function call is also required for each comparison. > 2. Do you know of a good page that describes the samplesort > algorithm? A search or two on google found some notes on parallel > implementation of the algorithm, but none on the algorithm itself. Sorry, the best description I know of is the one I wrote up in comments in Python's list.sort() code. If you understand quicksort, samplesort works by first sorting a relatively large random sample from the array, and then using those sorted elements as pivots for an equal number of quicksort partitioning steps. User a large sample ensures that (probabilistically) the pivots are excellent estimates of the true medians. Note that all of Python's source code is available online. For example, the source code for list.sort() is in listobject.c, available by browsing the Python CVS repository on SourceForge (sorry, but you'll have to paste this line together by hand): http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/ python/dist/src/Objects/listobject.c?cvsroot=python From rick@niof.net Wed Apr 4 23:16:36 2001 From: rick@niof.net (Rick Pasotto) Date: Wed, 4 Apr 2001 18:16:36 -0400 Subject: [Tutor] python on windows / mysql on linux Message-ID: <20010404181636.B4858@tc.niof.net> How can I access a MySQL database on my linux box from my windows box using python? Python on the linux box works great. -- "I will not be pushed, filed, stamped, indexed, briefed, debriefed, or numbered. My life is my own." -- The Prisoner Rick Pasotto email: rickp@telocity.com From dsh8290@rit.edu Wed Apr 4 23:46:05 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 4 Apr 2001 18:46:05 -0400 Subject: [Tutor] python on windows / mysql on linux In-Reply-To: <20010404181636.B4858@tc.niof.net>; from rick@niof.net on Wed, Apr 04, 2001 at 06:16:36PM -0400 References: <20010404181636.B4858@tc.niof.net> Message-ID: <20010404184605.B4249@harmony.cs.rit.edu> On Wed, Apr 04, 2001 at 06:16:36PM -0400, Rick Pasotto wrote: | How can I access a MySQL database on my linux box from my windows box | using python? Python on the linux box works great. Does MySQL have something similar to Postgres' "postmaster"? With Postgres you set up the postmaster to accept requests and the postmaster hooks the client up with the actual db. I haven't had much experience, but I've read some docs. I believe the postmaster can recieve requests over TCP/IP, not just from local clients (after all, what use would it be if you couldn't have nice remote client-server connections?). -D From deirdre@deirdre.net Thu Apr 5 00:12:56 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 4 Apr 2001 16:12:56 -0700 (PDT) Subject: [Tutor] python on windows / mysql on linux In-Reply-To: <20010404184605.B4249@harmony.cs.rit.edu> Message-ID: On Wed, 4 Apr 2001, D-Man wrote: > On Wed, Apr 04, 2001 at 06:16:36PM -0400, Rick Pasotto wrote: > | How can I access a MySQL database on my linux box from my windows box > | using python? Python on the linux box works great. > > Does MySQL have something similar to Postgres' "postmaster"? MySQL supports ODBC; since Windows does that as well, it seems the logical choice to connect the two. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From pdiaz88@terra.es Thu Apr 5 00:19:35 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Thu, 5 Apr 2001 01:19:35 +0200 Subject: [Tutor] python on windows / mysql on linux In-Reply-To: <20010404181636.B4858@tc.niof.net> References: <20010404181636.B4858@tc.niof.net> Message-ID: <01040501193502.30149@tajo> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 05 April 2001 00:16, Rick Pasotto wrote: > How can I access a MySQL database on my linux box from my windows box > using python? Python on the linux box works great. Does python on the win box work? Yes, MySQL can accept queries over a network. Suposing that the MySQL module is also supported on the Win box, you only have to use the connect() method. An easy example: import MySQLdb db_conn = MySQLdb.connect( user="myuser", passwd="mypasswd", db="mydb",\ host="myhost" ) db_cur = db_conn.cursor() db_cur.execute( some_query ) print db_cur.fetchone() Take a look at the DB API in the python doc Cheers Pedro -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6y6wHnu53feEYxlERAnOrAKDIiy0vOpJ9VTHN6p39EMtXeN1AWACgyYht XV5zxGBs6RtXlUyNYiTLpF0= =TCsA -----END PGP SIGNATURE----- From rick@niof.net Thu Apr 5 02:44:20 2001 From: rick@niof.net (Rick Pasotto) Date: Wed, 4 Apr 2001 21:44:20 -0400 Subject: [Tutor] python on windows / mysql on linux In-Reply-To: <01040501193502.30149@tajo>; from pdiaz88@terra.es on Thu, Apr 05, 2001 at 01:19:35AM +0200 References: <20010404181636.B4858@tc.niof.net> <01040501193502.30149@tajo> Message-ID: <20010404214420.C4858@tc.niof.net> On Thu, Apr 05, 2001 at 01:19:35AM +0200, Pedro Diaz Jimenez wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Thursday 05 April 2001 00:16, Rick Pasotto wrote: > > How can I access a MySQL database on my linux box from my windows box > > using python? Python on the linux box works great. > Does python on the win box work? Python works but I can't figure out how to install MySQLdb. The README file doesn't even mention Windows, just linux, even though the zip file is called MySQL-python-0.3.5-win32-1.zip. I edited the setup.py file to change the references to d: to c: and then from within idle ran 'setup.py build' and'setup.py install'. Both printed a 0 (does that mean a successful completion?). But when I then try to import MySQLdb it can't be found. I know very little about windoz and so I have no idea how to figure what I'm doing wrong. > Yes, MySQL can accept queries over a network. Suposing that the MySQL module > is also supported on the Win box, you only have to use the connect() method. > An easy example: > > import MySQLdb > > db_conn = MySQLdb.connect( user="myuser", passwd="mypasswd", db="mydb",\ > host="myhost" ) > db_cur = db_conn.cursor() > db_cur.execute( some_query ) > print db_cur.fetchone() Yes, that's what I do on the linux box. But first I have to get the import to work. Surely there must be some simple instructions somewhere showing how to install the MySQLdb module on the windoz box. -- Most of the presidential candidates' economic packages involve 'tax breaks,' which is when the government, amid great fanfare, generously decides not to take quite so much of your income. In other words, these candidates are trying to buy your votes with your own money. -- Dave Barry Rick Pasotto email: rickp@telocity.com From van@lindbergs.org Thu Apr 5 05:19:43 2001 From: van@lindbergs.org (VanL) Date: Wed, 04 Apr 2001 22:19:43 -0600 Subject: [Tutor] python on windows / mysql on linux References: <20010404181636.B4858@tc.niof.net> <01040501193502.30149@tajo> <20010404214420.C4858@tc.niof.net> Message-ID: <3ACBF25F.3ED5C46A@lindbergs.org> > I edited the setup.py file to change the references to d: to c: and then > from within idle ran 'setup.py build' and'setup.py install'. Both > printed a 0 (does that mean a successful completion?). But when I then > try to import MySQLdb it can't be found. There are two things that may be: 1. Did you run "setup.py install"? The built module is not installed by default. 2. The module is built -- try going into the build directory, and then a directory called something like "lib.win32.-2.0".** Copy all the files in that directory into your pythonpath (or open up a python interpreter in that directory). The import should then work. ** This directory name is approximate. Van From mylene.reiners@cmg.nl Thu Apr 5 08:20:37 2001 From: mylene.reiners@cmg.nl (Mylene Reiners) Date: Thu, 5 Apr 2001 09:20:37 +0200 Subject: [Tutor] Q: return-values Message-ID: Hi, I'm writing a program that will handle some rather free-form text, = select some values, and write those values to a CSV-file. The problem is with the free-form text - the lines I have to select are = not always the same: Input: One or more unimportant lines Date: 15-04-2001 Mr. Ir. Drs. A. Somename Somestreet 20, 1234 AB Someplace One or more unimportant lines Datum: 15-04-2001 Aanhef: Dhr. Titel: Voornaam: A. Achternaam: Somename Straat: Somestreet 20 Postcode: 1234 AB Woonplaats: Someplace Output: Datum;Aanhef:Titel;Voornaam;Achternaam;Straat;Postcode;Woonplaats 15-04-2001;Mr;Ir. Drs;A.;Somename;Somestreet 20;1234 AB;Someplace 15-04-2001;Dhr;;A.;Somename;Somestreet 20;1234 AB;Someplace Program: for line in input.readlines(): i =3D 0 test =3D -1 while i < lengte and test < 0: sub =3D ignoreList[i] test =3D string.find(line, sub, 0, 100) i =3D i + 1 if test < 0: < try to determine what lines are filled, and put them at the appropriate spot in the CSV-output> voorkeur =3D bepaal_voorkeur (line) For the last part I want to write some code, first to determine what I = have to put in the CSV-output def bepaal_voorkeur(regel): str =3D "Date " start =3D string.find(regel, str, 0, 250) if start !=3D -1: splitList =3D string.split(regel,":") voork =3D splitList[1] splitList =3D string.split(voork,"\n") voork =3D splitList[0] else: str =3D "Datum:" start =3D string.find(regel, str, 0, 250) if start !=3D -1: splitList =3D string.split(regel,":") voork =3D splitList[1] splitList =3D string.split(voork,"\n") voork =3D splitList[0] else: voork =3D " " return voork But then I have to determine whether I handled the "voorkeur" (the date = can be blank...) So I want to set a boolean to determine. But I can't figure out how...(handle more than one return-value with different meanings - string and boolean). Can anyone help me out? If you have some better ideas than I have about the coding, I would be = very grateful too... TIA, Myl=E8ne ---------------------+ Myl=E8ne Reiners | CMG Eindhoven B.V. | Calculating in binary Luchthavenweg 57 | code is as easy as=20 5657 EA Eindhoven | 01,10,11. The Netherlands | Tel Nr.+31(0)40-2957777 | Fax Nr.+31(0)40-2957600 | I don't speak for CMG, Mob Nr.+31(0)6-25068391 | nor vice-versa. ------------------------+ From ryanbooz@alumni.psu.edu Thu Apr 5 14:02:19 2001 From: ryanbooz@alumni.psu.edu (Ryan Booz) Date: Thu, 05 Apr 2001 09:02:19 -0400 Subject: [Tutor] Tkinter callback question [and the Command class] References: Message-ID: <3ACC6CDB.825CFC90@alumni.psu.edu> Daniel, (and others!) Thank you for your help. All of your comments have gotten me headed in a much better (and clearer) direction. I really appreciate it. As per your request Daniel, I will try to post some of the things my class does as we finish them. I'm not sure how productive or useful they are, but as I said, we're all just learning! Thanks again! Ryan Booz Tech Coordinator Belleville Mennonite School From scott@zenplex.com Thu Apr 5 19:25:44 2001 From: scott@zenplex.com (Scott Ralph Comboni) Date: 05 Apr 2001 14:25:44 -0400 Subject: [Tutor] shutil question? on copying files Message-ID: <986495148.1349.0.camel@scoot.zenplex.com> I have a question in regards to the shutil module. I'm trying to copy via a wildcard shutil.copy('/project/tambora/packages/*tar*', '/tmp') and I get this. File "", line 1, in ? File "/usr/local/lib/python2.0/shutil.py", line 26, in copyfile fsrc = open(src, 'rb') IOError: [Errno 2] No such file or directory: '/projects/tambora/packages/*tar*' It works fine if I put the complete path name in but I'd like to be able to wildcard this. IS there a way to do this or another module to use? I need to preform this function on *NIX and NT. Thanks Scott From scarblac@pino.selwerd.nl Thu Apr 5 19:32:54 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 5 Apr 2001 20:32:54 +0200 Subject: [Tutor] shutil question? on copying files In-Reply-To: <986495148.1349.0.camel@scoot.zenplex.com>; from scott@zenplex.com on Thu, Apr 05, 2001 at 02:25:44PM -0400 References: <986495148.1349.0.camel@scoot.zenplex.com> Message-ID: <20010405203254.A18962@pino.selwerd.nl> On 0, Scott Ralph Comboni wrote: > I have a question in regards to the shutil module. I'm trying to copy > via a wildcard shutil.copy('/project/tambora/packages/*tar*', '/tmp') > and I get this. > > File "", line 1, in ? > File "/usr/local/lib/python2.0/shutil.py", line 26, in copyfile > fsrc = open(src, 'rb') > IOError: [Errno 2] No such file or directory: > '/projects/tambora/packages/*tar*' > > It works fine if I put the complete path name in but I'd like to be able > to wildcard this. IS there a way to do this or another module to use? I > need to preform this function on *NIX and NT. shutil does not do wildcars, but for that there is glob; try import shutil, glob for file in glob.glob('/projects/tambora/packages/*tar*'): shutil.copy(file, '/tmp') -- Remco Gerlich From ium@micromuse.com Thu Apr 5 19:39:14 2001 From: ium@micromuse.com (ibraheem umaru-mohammed) Date: Thu, 5 Apr 2001 19:39:14 +0100 Subject: [Tutor] shutil question? on copying files In-Reply-To: <986495148.1349.0.camel@scoot.zenplex.com>; from scott@zenplex.com on Thu, Apr 05, 2001 at 02:25:44PM -0400 References: <986495148.1349.0.camel@scoot.zenplex.com> Message-ID: <20010405193914.B22759@ignoramus> [Scott Ralph Comboni wrote...] -| I have a question in regards to the shutil module. I'm trying to copy -| via a wildcard shutil.copy('/project/tambora/packages/*tar*', '/tmp') -| and I get this. -| -| File "", line 1, in ? -| File "/usr/local/lib/python2.0/shutil.py", line 26, in copyfile -| fsrc = open(src, 'rb') -| IOError: [Errno 2] No such file or directory: -| '/projects/tambora/packages/*tar*' -| -| It works fine if I put the complete path name in but I'd like to be able -| to wildcard this. IS there a way to do this or another module to use? I -| need to preform this function on *NIX and NT. I don't know how you would do it under NT but you can try using the glob module under *nixes: >>>import glob >>> glob.glob("/boot/*") ['/boot/System.map', '/boot/System.map-2.4.0-test9', '/boot/boot.0300', '/boot/boot.0303', '/boot/boot.b', '/boot/chain.b', '/boot/kernel.h', '/boot/lost+found', '/boot/map', '/boot/module-info', '/boot/os2_d.b', '/boot/System.map.old', '/boot/boot.0305', '/boot/boot.0200', '/boot/System.map-2.2.18', '/boot/vmlinuz.old', '/boot/vmlinuz-2.4.0-test9', '/boot/vmlinuz-2.2.18', '/boot/vmlinuz-2.2.18.prev', '/boot/boot.0306', '/boot/boot.lnx'] >>> HTH, Kindest regards, --ibs. -- Live never to be ashamed if anything you do or say is published around the world -- even if what is published is not true. -- Messiah's Handbook : Reminders for the Advanced Soul From scott@zenplex.com Thu Apr 5 20:09:49 2001 From: scott@zenplex.com (Scott Ralph Comboni) Date: 05 Apr 2001 15:09:49 -0400 Subject: [Tutor] shutil question? on copying files In-Reply-To: <20010405203254.A18962@pino.selwerd.nl> References: <986495148.1349.0.camel@scoot.zenplex.com> <20010405203254.A18962@pino.selwerd.nl> Message-ID: <986497791.1350.2.camel@scoot.zenplex.com> > On 05 Apr 2001 20:32:54 +0200, Remco Gerlich wrote: > On 0, Scott Ralph Comboni wrote: > > I have a question in regards to the shutil module. I'm trying to copy > > via a wildcard shutil.copy('/project/tambora/packages/*tar*', '/tmp') > > and I get this. > > > > File "", line 1, in ? > > File "/usr/local/lib/python2.0/shutil.py", line 26, in copyfile > > fsrc = open(src, 'rb') > > IOError: [Errno 2] No such file or directory: > > '/projects/tambora/packages/*tar*' > > > > It works fine if I put the complete path name in but I'd like to be able > > to wildcard this. IS there a way to do this or another module to use? I > > need to preform this function on *NIX and NT. > > shutil does not do wildcars, but for that there is glob; try > > import shutil, glob > > for file in glob.glob('/projects/tambora/packages/*tar*'): > shutil.copy(file, '/tmp') > > -- > Remco Gerlich > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor Thanks that solved my problem. I should have thought of that still a little green. Scott -- Scott Ralph Comboni http://www.zenplex.com http://www.zenplex.org http://tambora.zenplex.org From syrinx@simplecom.net Fri Apr 6 01:33:57 2001 From: syrinx@simplecom.net (Scott) Date: Thu, 05 Apr 2001 19:33:57 -0500 Subject: [Tutor] out of memory conditions Message-ID: If you're going to be using a LOT of memory, how do you make sure you don't run out? I did this as an experiment, in X (Gnome): x =3D 0 y =3D [] while 1: y.append(' ' * 1000000) x =3D x + 1 print x I thought this would raise an exception, but it didn't. When x got to about 163, I got thrown out of X. I redid 'startx', and everything seemed back to normal, except I couldn't run Agent newsreader under Wine. If you're going to be a memory-hog, do you just have to keep up with it yourself? From van@lindbergs.org Fri Apr 6 04:07:01 2001 From: van@lindbergs.org (VanL) Date: Thu, 05 Apr 2001 21:07:01 -0600 Subject: [Tutor] out of memory conditions References: Message-ID: <3ACD32D5.B9C4A906@lindbergs.org> > I did this as an experiment, in X (Gnome): > > x = 0 > y = [] > while 1: > y.append(' ' * 1000000) > x = x + 1 > print x > > I thought this would raise an exception, but it didn't. > > When x got to about 163, I got thrown out of X. I redid 'startx', and > everything seemed back to normal, except I couldn't run Agent > newsreader under Wine. This is interesting.... >>> y = [] >>> for x in range(1000): ... y.append(' ' * 10000000) ... print x ... 0 1 2 3 4 [snip] 61 62 63 64 Traceback (most recent call last): File "", line 2, in ? MemoryError >>> y = 1 (Memory is freed. Memory consumption drops by ~650 MB) Of course, this is on Win2K, with a hard limit on the size of my swapfile. Are you using a swapfile or swap partition? Linux or a BSD? -VanL From syrinx@simplecom.net Fri Apr 6 03:08:58 2001 From: syrinx@simplecom.net (Scott) Date: Thu, 05 Apr 2001 21:08:58 -0500 Subject: [Tutor] out of memory conditions In-Reply-To: <3ACD32D5.B9C4A906@lindbergs.org> References: <3ACD32D5.B9C4A906@lindbergs.org> Message-ID: >Of course, this is on Win2K, with a hard limit on the size of my >swapfile. Are you using a swapfile or swap partition? Linux or a BSD? 128 megs ram. Equal size swap partition. From wmperry@swbell.net Fri Apr 6 04:19:10 2001 From: wmperry@swbell.net (William Perry) Date: Thu, 05 Apr 2001 22:19:10 -0500 Subject: [Tutor] User selections question Message-ID: <200104052219100830.00A74303@mail.swbell.net> --=====_98652715029358=_ Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Obligatory background "stuff "; I'm still new at this programing hobby and all self-taught. I've gone thru= Alan's online tutorial, Teach Yourself Python in 24 hrs, most of Learning= Python and the Tutorial packaged with Python (and hung around this list= about 6 months). I wanted to try writing something from scratch to see if= any of it had sunk in. It appears it did because what was to be a simple function has grown into 4= stand alone modules that properly combined will actually automate a very= boring task where I work. At least according to the 'alpha testers' at the= job who are clamoring for a finished product. The problem; I have a working function that takes user selections and selects among the= sub-modules returning values to send to the final data module but it feels= clumsy. Since this is still after all a learning project I'm looking for= how to find the answer rather than the answer it's self. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D what I want to= do=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1)user selects from a listing of available functions 2)the selected functions run and return a list of values 3)the combine function processes the list to a final value 4)print to screen/printer =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D I'm hung up on step 1 This is what I came up with just playing with the idea. (yes I did do some= BASIC back in the late 70's ) def com_rate(): l=3D[] tst=3D1 y=3D99 print;print"enter area # for area to rate \n 1-area 1 \n 2-area 2" print "enter y to begin" print;print while tst: area=3Dinput("enter ") if area =3D=3D 1: res=3Darea1() l.append(res) elif area =3D=3D 2: res=3Darea2() l.append(res) elif area =3D=3D 99: combn(l) break else: tst=3D0 def area1(): out=3D11 return out def area2(): out=3D5 return out def combn(l): print l tst=3D0 return tst com_rate() ************************************Something else i= tried********************************** #! usr/bin/python def com_test(): l=3D[] print" Enter number of areas to be rated " arl=3Dinput("Enter ") print;print"enter area # for area to rate \n 1-area 1 \n 2-area 2" for ar in range (arl): ar=3Dinput("? ") l.append (ar) print l com_test() (and like even less) --=====_98652715029358=_ Content-Type: text/html; charset="us-ascii"
Obligatory background "stuff ";
 
I'm still new at this programing hobby and all self-taught. I've gone thru Alan's online tutorial, Teach Yourself Python in 24 hrs, most of Learning Python and the Tutorial packaged with Python (and hung around this list about 6 months). I wanted to try writing something from scratch to see if any of it had sunk in.
 
It appears it did because what was to be a simple function has grown into 4 stand alone modules that properly combined will actually automate a very boring task where I work. At least according to the 'alpha testers' at the job who are clamoring for a finished product.
 
The problem;
 
I have a working function that takes user selections and selects among the sub-modules returning values to send to the final data module but it feels clumsy. Since this is still after all a learning project I'm looking for how to find the answer rather than the answer it's self.
 
=================== what I want to do============
 
1)user selects from a listing of available functions
2)the selected functions run and return a list of values
3)the combine function processes the list to a final value
4)print to screen/printer
=======================================================
 
I'm hung up on step 1
 

This is what I came up with just playing with the idea. (yes I did do some BASIC back in the late 70's )
 
 
 
def com_rate():
 l=[]
 tst=1
 y=99
 print;print"enter area # for area to rate \n 1-area 1 \n 2-area 2"
 print "enter y to begin"
 print;print
 while tst:
  
         area=input("enter ")
         if area == 1:
      res=area1()
      l.append(res)
         elif area == 2:
      res=area2()
      l.append(res)
         elif area == 99:
      combn(l)
      break
         else:
      tst=0
 
def area1():
 out=11
 return out
 
def area2():
 out=5
 return out
 
def combn(l):
 print l
 tst=0
 return tst
 
com_rate()
 
 
 
 
 
************************************Something else i tried**********************************
 
#! usr/bin/python
 
def com_test():
    l=[]
    print" Enter number of areas to be rated "
    arl=input("Enter ")
    print;print"enter area # for area to rate \n 1-area 1 \n 2-area 2"
    for ar in range (arl):
        ar=input("? ")
        l.append (ar)
       
    print l
 
com_test()
 

   
   
   
(and like even less)
--=====_98652715029358=_-- From tutor@python.org Fri Apr 6 07:09:12 2001 From: tutor@python.org (Tim Peters) Date: Fri, 6 Apr 2001 02:09:12 -0400 Subject: [Tutor] out of memory conditions In-Reply-To: Message-ID: [Scott] > If you're going to be using a LOT of memory, how do you make sure you > don't run out? It depends on the platform. Python raises MemoryError whenever the system malloc function returns NULL (as VanL demonstrated on Win2K). It appears to be "a feature" of Linux that malloc may return a non-NULL pointer even if there's no memory left, based on swapfile heuristics that don't always work. You can complain about that to the Linux developers, but there's nothing Python can do about it on its own. > ... > If you're going to be a memory-hog, do you just have to keep up with > it yourself? You're peering over the edge of a very deep pit. You can dive in headfirst or leap back to safety, just don't stand there staring too long <0.9 wink>. From dyoo@hkn.eecs.berkeley.edu Fri Apr 6 08:30:01 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 6 Apr 2001 00:30:01 -0700 (PDT) Subject: [Tutor] out of memory conditions In-Reply-To: Message-ID: On Thu, 5 Apr 2001, Scott wrote: > > If you're going to be using a LOT of memory, how do you make sure you > don't run out? > > I thought this would raise an exception, but it didn't. > > When x got to about 163, I got thrown out of X. I redid 'startx', and > everything seemed back to normal, except I couldn't run Agent > newsreader under Wine. Hmmm... Strange! Which version of Python? Also, if you're running a Linux 2.4 kernel, I believe that under extreme stress, the Linux kernel will try killing processes to keep the system from going down. From wong_chow_cheok@hotmail.com Fri Apr 6 09:37:25 2001 From: wong_chow_cheok@hotmail.com (wong chow cheok) Date: Fri, 06 Apr 2001 16:37:25 +0800 Subject: [Tutor] (no subject) Message-ID: hai chow cheok here again. this is a program i wrote import re import urllib import sys import string name={'AS':'Alor Setar '} if sys.argv[1]==["upper()"]: p=re.compile('min:\s\s\d\d\s.^*', re.IGNORECASE) q=re.compile('max:\s\s\d\d\s.^*', re.IGNORECASE) a=re.compile('whole day^*|morning^*|afternoon^*|evening^*', re.IGNORECASE) b=re.compile('fcastimg/(.*?).gif^*', re.IGNORECASE) html=urllib.urlopen("http://www.kjc.gov.my/cgi-bin/fcastdisplay.cgi?lang=EN&loc="+sys.argv[1]).read() mintemp=p.search(html) maxtemp=q.search(html) time=a.search(html) con=b.search(html) print 'Temperature for ',name[sys.argv[1]], mintemp.group(),'and ', maxtemp.group() print 'Weather for the day is ',con.groups(1)[0],'in the ', time.group() else: print 'all caps' what i want to do is to make sure my argument variable is in caps. if it is not it will return an error message. for example when i type in 'python weather AS' it will return the weather output but 'python weather as' will return 'all caps'. also is there anyway to make sure i don't type the wrong argument variable. for example if i type python weather USA, it is caps but out of my range. a few pointers would be great. any help is very appreciated. thank you. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From dyoo@hkn.eecs.berkeley.edu Fri Apr 6 10:37:52 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 6 Apr 2001 02:37:52 -0700 (PDT) Subject: [Tutor] User selections question In-Reply-To: <200104052219100830.00A74303@mail.swbell.net> Message-ID: On Thu, 5 Apr 2001, William Perry wrote: > =================== what I want to do============ > > 1)user selects from a listing of available functions > 2)the selected functions run and return a list of values > 3)the combine function processes the list to a final value > 4)print to screen/printer > ======================================================= > > I'm hung up on step 1 > > > This is what I came up with just playing with the idea. (yes I did do > some BASIC back in the late 70's No problem. I have somewhat fond memories of using Basic too. Let's take a look at your program. > def com_rate(): > l=[] > tst=1 > y=99 > print;print"enter area # for area to rate \n 1-area 1 \n 2-area 2" > print "enter y to begin" > print;print > while tst: > > area=input("enter ") > if area == 1: > res=area1() > l.append(res) > elif area == 2: > res=area2() > l.append(res) > elif area == 99: > combn(l) > break > else: > tst=0 The indentation of the code feels a little weird to me; it might be better to indent this like: while tst: area = input("enter ") if area == 1: res = area1() l.append(res) ... When I tried entering your code, it complained of a "inconsistent dedent", which means that Python expects code that follows an if statement to be more indented. Otherwise, what you have looks ok, as long as there are only two choices. But as you add more choices, the code might become more unwieldy. If you really want to generalize the idea of choosing functions and combiners, it's possible by using a dictionary that, given the input(), returns back to us the appropriate function and combiner. Here's a related example that might help explain the idea: ### import sys def mult(): a = input('Enter a.') b = input('Enter b.') return a * b def concat(): a = input('Enter s1.') b = input('Enter s2.') return a + b def quit(): print "Goodbye" sys.quit() if __name__ == '__main__': command_functions = { 'multiply': mult, 'concatenate' : concat, 'quit': quit } while 1: print 'You have the following possible commands: ' print command_functions.keys(), '\n' cmd = input('Enter your choice: ') if command_functions.has_key(cmd): function = command_functions[cmd] print function() ### The idea is that if we need to extend the commands that our program should understand, we only need to add an entry to the command_functions dictionary --- we don't even need to touch program logic! We can even extend this style of programming to use the appropriate combiner of the function's results --- we can have something like: ### command_functions = { 1 : (area1, l.append), 2 : (area2, l.append), 99: (get_l, combn) } # Assume that get_l is some sort of function that returns l. while 1: area = input("enter ") if command_functions.has_key(area): function, combiner = command_functions[area] result = function() combiner(result) else: break ### which, with some fiddling, should have the same behavior as what you had before. In any case, this idea is, admittedly, very weird, but it's very neat when it makes sense. *grin* If you have any questions, please feel free to ask us. Good luck! From turhan@incubatr.com Fri Apr 6 10:53:37 2001 From: turhan@incubatr.com (Turhan Arun) Date: Fri, 6 Apr 2001 12:53:37 +0300 Subject: [Tutor] Date subtraction Message-ID: This is a multi-part message in MIME format. ------_=_NextPart_001_01C0BE7F.7348B557 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I just started learning python... Now, my question is: I want to have a user enter a date in format dd/mm/YYYY like 06/04/2001 and another date in the same format like 22/04/2001 depending on these two inputs. I just want to create a list of date strings like ['06/04/2001','07/04/2001','08/04/2001'....] It will be great if you could give some idea. Thanks, Turhan Arun ------_=_NextPart_001_01C0BE7F.7348B557 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date subtraction

Hi all,
I just started learning python...
Now, my question is:
I want to have a user enter a date in format = dd/mm/YYYY like 06/04/2001
and another date in the same format like = 22/04/2001
depending on these two inputs. I just want to = create a list of date strings like
['06/04/2001','07/04/2001','08/04/2001'....]
It will be great if you could give some = idea.

Thanks,
Turhan Arun

------_=_NextPart_001_01C0BE7F.7348B557-- From dyoo@hkn.eecs.berkeley.edu Fri Apr 6 11:08:54 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 6 Apr 2001 03:08:54 -0700 (PDT) Subject: [Tutor] Date subtraction In-Reply-To: Message-ID: On Fri, 6 Apr 2001, Turhan Arun wrote: > Hi all, > I just started learning python... > Now, my question is: > I want to have a user enter a date in format dd/mm/YYYY like 06/04/2001 > and another date in the same format like 22/04/2001 > depending on these two inputs. I just want to create a list of date > strings like > ['06/04/2001','07/04/2001','08/04/2001'....] > It will be great if you could give some idea. It sounds like using the string.split() function will be useful for you. string.split() takes in a string, as well as a "delimiter" string, and it tries to break down a string into a list of smaller strings: ### >>> import string >>> string.split('www.python.org', '.') ['www', 'python', 'org'] >>> string.split('06/04/2001', '.') ['06/04/2001'] # Whoops, the delimiter matters! >>> string.split('06/04/2001', '/') ['06', '04', '2001'] ### By using string.split(), it'll be easier to get the "day" part of any date. If you want more formal documentation: http://python.org/doc/current/lib/module-string.html talks about many of the things that you can do with strings. By the way, if you're going to be "adding" days to your date, you'll probably need to turn your day string into a number first, just so the addition works out. Here's a small interpreter session that explores what this means: ### >>> '06' + 1 Traceback (innermost last): File "", line 1, in ? TypeError: illegal argument type for built-in operation >>> int('06') + 1 7 >>> str(int('06') + 1) '7' >>> string.zfill(int('06') + 1, 2) '07' ### The last part is a function called string.zfill() --- it's a function that takes a number, and turns it back into a string, while padding it with left zeros if it needs them. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Fri Apr 6 11:19:46 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 6 Apr 2001 03:19:46 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Fri, 6 Apr 2001, wong chow cheok wrote: > hai chow cheok here again. this is a program i wrote > > import re > import urllib > import sys > import string > > name={'AS':'Alor Setar '} > if sys.argv[1]==["upper()"]: > p=re.compile('min:\s\s\d\d\s.^*', re.IGNORECASE) > q=re.compile('max:\s\s\d\d\s.^*', re.IGNORECASE) > a=re.compile('whole day^*|morning^*|afternoon^*|evening^*', > re.IGNORECASE) > b=re.compile('fcastimg/(.*?).gif^*', re.IGNORECASE) > > html=urllib.urlopen("http://www.kjc.gov.my/cgi-bin/fcastdisplay.cgi?lang=EN&loc="+sys.argv[1]).read() > mintemp=p.search(html) > maxtemp=q.search(html) > time=a.search(html) > con=b.search(html) > print 'Temperature for ',name[sys.argv[1]], mintemp.group(),'and ', > maxtemp.group() > print 'Weather for the day is ',con.groups(1)[0],'in the ', time.group() > > else: > print 'all caps' > > what i want to do is to make sure my argument variable is in caps. if it is > not it will return an error message. for example when i type in One way to check if something is in capitals is to compare a particular string with its capitalized form. In Python 2.0, we can write the following code: ### >>> mailing_list = 'tutor@python.org' >>> if mailing_list.upper() == mailing_list: ... print 'ok' ... else: ... print 'all caps' ... all caps >>> shouting = 'TUTOR@PYTHON.ORG' >>> if shouting.upper() == shouting: ... print 'ok' ... else: ... print 'all caps' ... ok ### If you're using Python 1.52, the function string.upper() will also work to convert a string to all caps. > also is there anyway to make sure i don't type the wrong argument variable. > for example if i type > > python weather USA, it is caps but out of my range. a few pointers would be > great. Sure! If the search is unsuccessful, the search()ing function of your regular expressions will return the None value to show that it wasn't able to find anything. http://python.org/doc/current/lib/Contents_of_Module_re.html mentions this briefly. With this, we can check for these missing values in several ways: if mintemp == None or maxtemp == None or time == None or con == None: ... is one way to do it. However, there's a nice Python idiom to say this: if None in [mintemp, maxtemp, time, con]: ... Hope this helps! From scarblac@pino.selwerd.nl Fri Apr 6 11:36:00 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Fri, 6 Apr 2001 12:36:00 +0200 Subject: [Tutor] Date subtraction In-Reply-To: ; from turhan@incubatr.com on Fri, Apr 06, 2001 at 12:53:37PM +0300 References: Message-ID: <20010406123600.A19531@pino.selwerd.nl> On 0, Turhan Arun wrote: > Hi all, > I just started learning python... > Now, my question is: > I want to have a user enter a date in format dd/mm/YYYY like 06/04/2001 > and another date in the same format like 22/04/2001 > depending on these two inputs. I just want to create a list of date > strings like > ['06/04/2001','07/04/2001','08/04/2001'....] > It will be great if you could give some idea. Two things: you need to parse a date, and you need to do arithmetic with it. Parsing. The good news is that the Python standard library has the very cool time.strptime() function. The bad news is that it's only available on (most) types of Unix. Luckily someone has made an implementation in Python, so if you don't have a Unix system you can get http://www.fukt.hk-r.se/~flognat/hacks/strptime.py and use that. This then looks like import time # Or import strptimeif you use that datestr = raw_input("Give date:") date = time.strptime(datestr, "%d/%m/%Y") # See library ref of strftime for # possible format strings # use strptime.strptime in the case # of the module You know have a date in tuple format that the other time functions can use. time.mktime(date) gives the date in seconds since 1970 (Unix time). time.strftime("%d/%m/%Y", date) gives the same string back. Arithmetic. The naive way to add a day to the date is to simply add a day's worth a seconds to the seconds since 1970, then print that date. We get something like import time date1 = "06/04/2001" date2 = "22/04/2001" format = "%d/%m/%Y" date1_s = time.mktime(time.strptime(date1, format)) # Get seconds date2_s = time.mktime(time.strptime(date2, format)) if date2_s < date1_s: raise ValueError # Second date can't be earlier current = date1_s datelist = [] while 1: date = time.strftime(format, time.localtime(current)) # String from secs datelist.append(date) if (date == date2) or (current > date2_s): break current += 24*60*60 # Add one day print datelist (this is untested) This is naive because there may be things like leap seconds and whatnot, breaking this code. mxDateTime is a package that's intended for handling date arithmetic, so if you want a great program you should look at that. I never used it myself, but it has a great reputation: http://www.lemburg.com/files/python/mxDateTime.html -- Remco Gerlich From alan.gauld@bt.com Fri Apr 6 11:54:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Apr 2001 11:54:45 +0100 Subject: [Tutor] Date subtraction Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6C0@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0BE87.FE0385C0 Content-type: text/plain; charset="iso-8859-1" Look at the time module. > I want to have a user enter a date in format > dd/mm/YYYY like 06/04/2001 and another date > in the same format like 22/04/2001 Here is some pseudo code: #------------- start = raw_inpu('start date dd/mm/yyyy ') end = raw_input('end date dd/mm/yyyy ') startTime = convert time string to time value endTime = convert time string to time value times = [] timestrings = [] newTime = startTime while newTime < end: times.append(newTime) newTime = newTime + 1 day for t in times: str = convert t to time string timestrings.append(str) #-------------- The time module contains all the bits you need to do the conversions. HTH, Alan G ------_=_NextPart_001_01C0BE87.FE0385C0 Content-type: text/html; charset="iso-8859-1" Date subtraction
Look at the time module.
 
>  I want to have a user enter a date in format  
>  dd/mm/YYYY like 06/04/2001 and another date  
>  in the same format like 22/04/2001 
 
Here is some pseudo code:
 
#------------- 
start = raw_inpu('start date dd/mm/yyyy ')
end = raw_input('end date dd/mm/yyyy ')
startTime = convert time string to time value
endTime = convert time string to time value
 
times = []
timestrings = []
newTime = startTime
while newTime < end:
    times.append(newTime)
    newTime = newTime + 1 day
 
for t in times:
   str = convert t to time string
   timestrings.append(str)
 
#--------------
The time module contains all the bits you need to do the conversions.
 
HTH,
 
Alan G

 

------_=_NextPart_001_01C0BE87.FE0385C0-- From tirakala@yahoo.com Fri Apr 6 13:12:45 2001 From: tirakala@yahoo.com (mohan tirakala) Date: Fri, 6 Apr 2001 05:12:45 -0700 (PDT) Subject: [Tutor] send me vb tutor Message-ID: <20010406121245.3856.qmail@web13607.mail.yahoo.com> respective sir pliase send me vb tutor and turorial __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From wheelege@tsn.cc Fri Apr 6 13:47:39 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Fri, 6 Apr 2001 22:47:39 +1000 Subject: [Tutor] urllib, urlopen and the evil frames References: Message-ID: <002601c0be97$c49c7160$0200a8c0@ACE> Hi all, I've noticed alot of use of Urllib lately and I thought it would be funky to be able to navigate around and pass arguments to cgi scripts through a python script. But I've hit a kind of snag. Basically, this is what I am looking at wanting to do... 1. Log into server 2. Navigate to a page with some prices 3. Take the page html code as input then.. 4. Use regular expressions to tell the user of the prices, then do what they tell you -OR- 4. Go into complete auto-mode and do some buying, selling, etc based on some rules and things like that. This is for an online game, before any of you suspicious types start looking my direction :) And no it's not bad to do it on this game server....I think. Anyway, I've gotten past step 1, and I logged in by just passing arguments to a few cgi scripts in an order using urllip.urlopen but when I get to navigating around in step 2 I just get returned (through ye olde urllib) 'blah blah This browser does not support frames'. So I thought 'bah who needs that page anyway' and then tried to access the market cgi-script using urlopen but then it spits at me saying I haven't logged in yet. So now I'm stuck. Surely there must be a way to just go 'look website, I don't care about frames just let me take all the source you've got, I don't care how many frames/html files you have'. Thanks guys, Glen. From wheelege@tsn.cc Fri Apr 6 14:18:02 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Fri, 6 Apr 2001 23:18:02 +1000 Subject: [Tutor] webbrowser module, weird weird behaviour Message-ID: <006801c0be9c$039d7400$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_0065_01C0BEEF.D3E909A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello everyone again, I thought my anguish was for naught when I was looking through the = docs and located the module 'webbrowser' however this module appeared to = do nothing, and in fact had a very strange characteristic...to me at = least. Here is my interpreter session : >>> import webbrowser >>> dir(webbrowser) ['__builtins__', '__doc__', '__file__', '__name__', 'webbrowser'] >>> dir(webbrowser.__doc__) [] ## expected.... >>> dir(webbrowser.webbrowser) ['__builtins__', '__doc__', '__file__', '__name__', 'webbrowser'] >>> dir(webbrowser.webbrowser.webbrowser) ['__builtins__', '__doc__', '__file__', '__name__', 'webbrowser'] >>> dir(webbrowser.webbrowser.webbrowser.webbrowser.webbrowser) ['__builtins__', '__doc__', '__file__', '__name__', 'webbrowser'] ## = yup I'm confused :) >>> dir() ['__builtins__', '__doc__', '__name__', 'pywin', 'webbrowser'] >>> dir(pywin) ['__builtins__', '__doc__', '__file__', '__name__', '__path__', = 'debugger', 'framework', 'idle', 'mfc', 'scintilla', 'sys', 'tools'] >>> import time ## I thought I'd check if it was normal for modules to = do the recursive dir dance... >>> dir() ['__builtins__', '__doc__', '__name__', 'pywin', 'time', 'webbrowser'] =20 >>> dir(time) ['__doc__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', = 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', = 'strftime', 'time', 'timezone', 'tzname'] >>> dir(time.time) ['__doc__', '__name__', '__self__'] ## nope behaves as expected... >>>=20 So, well though this doesn't have anything to really do with the = function of the webbrowser module or how to use it, I think it's still = curious and worth posting...can anyone plz explain?? Thanks, Glen. ------=_NextPart_000_0065_01C0BEEF.D3E909A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hello everyone again,
 
  I thought my anguish was for naught when I was looking = through the=20 docs and located the module 'webbrowser' however this module appeared to = do=20 nothing, and in fact had a very strange characteristic...to me at = least. =20 Here is my interpreter session :
 
>>> import webbrowser
>>> dir(webbrowser)
['__builtins__', '__doc__', = '__file__',=20 '__name__', 'webbrowser']
>>> = dir(webbrowser.__doc__)
[]  ##=20 expected....
>>> = dir(webbrowser.webbrowser)
['__builtins__',=20 '__doc__', '__file__', '__name__', 'webbrowser']
>>>=20 dir(webbrowser.webbrowser.webbrowser)
['__builtins__', '__doc__', = '__file__',=20 '__name__', 'webbrowser']
>>>=20 dir(webbrowser.webbrowser.webbrowser.webbrowser.webbrowser)
['__builti= ns__',=20 '__doc__', '__file__', '__name__', 'webbrowser']  ## yup I'm = confused=20 :)
>>> dir()
['__builtins__', '__doc__', '__name__', = 'pywin',=20 'webbrowser']
>>> dir(pywin)
['__builtins__', '__doc__',=20 '__file__', '__name__', '__path__', 'debugger', 'framework', 'idle', = 'mfc',=20 'scintilla', 'sys', 'tools']
>>> import time  ## I = thought I'd=20 check if it was normal for modules to do the recursive dir=20 dance...
>>> dir()
['__builtins__', '__doc__', = '__name__',=20 'pywin', 'time', 'webbrowser'] 
>>> = dir(time)
['__doc__',=20 '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', = 'daylight',=20 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'time', = 'timezone',=20 'tzname']
>>> dir(time.time)
['__doc__', '__name__',=20 '__self__']  ## nope behaves as expected...
>>>
 
  So, well though this doesn't have anything to really do with = the=20 function of the webbrowser module or how to use it, I think it's still = curious=20 and worth posting...can anyone plz explain??
 
  Thanks,
  Glen.
------=_NextPart_000_0065_01C0BEEF.D3E909A0-- From syrinx@simplecom.net Fri Apr 6 13:35:45 2001 From: syrinx@simplecom.net (Scott) Date: Fri, 06 Apr 2001 07:35:45 -0500 Subject: [Tutor] out of memory conditions In-Reply-To: References: Message-ID: >Hmmm... Strange! Which version of Python? This is python 1.5.2, Redhat Linux 7.0 (perhaps the single buggest dist release in Linux history). From kalle@gnupung.net Fri Apr 6 14:48:11 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 6 Apr 2001 15:48:11 +0200 Subject: [Tutor] webbrowser module, weird weird behaviour In-Reply-To: <006801c0be9c$039d7400$0200a8c0@ACE>; from wheelege@tsn.cc on Fri, Apr 06, 2001 at 11:18:02PM +1000 References: <006801c0be9c$039d7400$0200a8c0@ACE> Message-ID: <20010406154811.A16170@father> Sez Glen Wheeler: > Hello everyone again, > > I thought my anguish was for naught when I was looking through the docs > and located the module 'webbrowser' however this module appeared to do > nothing, and in fact had a very strange characteristic...to me at least. > Here is my interpreter session : > > >>> import webbrowser > >>> dir(webbrowser) > ['__builtins__', '__doc__', '__file__', '__name__', 'webbrowser'] That's some funky sh*t! I've never seen that behavior, but I'm limited to one platform (GNU/Linux). What's your platform and Python version? Anyway, check http://www.python.org/doc/current/lib/module-webbrowser.html (URL from memory...) for what it's supposed to do. I've read your previous message, btw, but I have no time at the moment. Will try to get a reply out tonight. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From wheelege@tsn.cc Fri Apr 6 14:49:00 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Fri, 6 Apr 2001 23:49:00 +1000 Subject: [Tutor] webbrowser module, weird weird behaviour References: <006801c0be9c$039d7400$0200a8c0@ACE> <20010406154811.A16170@father> Message-ID: <001301c0bea0$56d1aac0$0200a8c0@ACE> It is a little strange isn't it...thanks for the incoming reply :) I'm running win98 here. ----- Original Message ----- From: Kalle Svensson To: Sent: Friday, April 06, 2001 11:48 PM Subject: Re: [Tutor] webbrowser module, weird weird behaviour > Sez Glen Wheeler: > > Hello everyone again, > > > > I thought my anguish was for naught when I was looking through the docs > > and located the module 'webbrowser' however this module appeared to do > > nothing, and in fact had a very strange characteristic...to me at least. > > Here is my interpreter session : > > > > >>> import webbrowser > > >>> dir(webbrowser) > > ['__builtins__', '__doc__', '__file__', '__name__', 'webbrowser'] > > That's some funky sh*t! I've never seen that behavior, but I'm limited to > one platform (GNU/Linux). What's your platform and Python version? > > Anyway, check http://www.python.org/doc/current/lib/module-webbrowser.html > (URL from memory...) for what it's supposed to do. > > I've read your previous message, btw, but I have no time at the moment. > Will try to get a reply out tonight. > > Peace, > Kalle > -- > Email: kalle@gnupung.net | You can tune a filesystem, but you > Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) > PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD > [ Not signed due to lossage. Blame Microsoft Outlook Express. ] > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From dsh8290@rit.edu Fri Apr 6 16:40:54 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 6 Apr 2001 11:40:54 -0400 Subject: [Tutor] out of memory conditions In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Fri, Apr 06, 2001 at 12:30:01AM -0700 References: Message-ID: <20010406114054.A12699@harmony.cs.rit.edu> On Fri, Apr 06, 2001 at 12:30:01AM -0700, Daniel Yoo wrote: | | Also, if you're running a Linux 2.4 kernel, I believe that under extreme | stress, the Linux kernel will try killing processes to keep the system | from going down. Just for another data point, I was using Gnumeric on RH7 a while back. I clicked that button in the upper left corner to select all cells, then changed some properties (size, font, etc). When I went to save my work, it took a very long time. I got a snack, came back, and was at the GDM login screen. This was kernel 2.2.16. I tried again, but used gtop to see what was happening. Gnumeric's memory usage keep increasing till the system booted me. It must have thought I wasn't playing nice with the other users (umm, which users?) ;-). -D From alan.gauld@bt.com Fri Apr 6 16:29:08 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Apr 2001 16:29:08 +0100 Subject: [Tutor] Tkinter topic completed Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6C6@mbtlipnt02.btlabs.bt.co.uk> I've just uploaded the final (at least so far as technical content goes) GUI tutor topic to my web site. It is now linked from the contents frame If anyone has comments I'm pleased to receive them, particularly on the wxPython section since I don't use wxPython much (altho' I might now that I've started :-) http://www.crosswinds.net/~agauld/tutgui.htm Enjoy, Alan G From alan.gauld@bt.com Fri Apr 6 16:57:31 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Apr 2001 16:57:31 +0100 Subject: [Tutor] send me vb tutor Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6C8@mbtlipnt02.btlabs.bt.co.uk> > pliase send me vb tutor and turorial I'm afraid this is a mailing list for those learning the Python language. You might have a better chance of locating a VB tutor on a VB mailing list or news group. Alternatively try the various web search engines. For example Yahoo has a comprehensive list of programming tutorials, I'm sure you can find a VB one there. On the other hand, why not try Python? :-) http://www.python.org/ Alan G. From alan.gauld@bt.com Fri Apr 6 17:05:48 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Apr 2001 17:05:48 +0100 Subject: [Tutor] urllib, urlopen and the evil frames Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6C9@mbtlipnt02.btlabs.bt.co.uk> > in step 2 I just get returned (through ye olde urllib) > 'blah blah This browser does not support frames'. > needs that page anyway' and then tried to access the market > cgi-script using urlopen but then it spits at me saying I > haven't logged in yet. > So now I'm stuck. Surely there must be a way to just go > 'look website, I don't care about frames You'll need to go to the site with a Frames equipped browser and open the login frame in a separate window. That should give you the url of the real login page. Then use that to login programmatically (using urllib) then (somehow... anyone?) catch the cookie which presumably is being sent back to the 'browser' ... Using that cookie you can (probably) get access to the cgi page. If you are really lucky they aren't using cookies and just hidden fields but thats unlikely... HTH, Alan g. From samus@feudalkingdoms.tzo.org Fri Apr 6 17:59:11 2001 From: samus@feudalkingdoms.tzo.org (Sam Corder) Date: Fri, 06 Apr 2001 16:59:11 +0000 Subject: [Tutor] webbrowser module, weird weird behaviour Message-ID: If all you want to do is control a web browser and you don't care about being cross platform ie is pretty easy to control using com. The nice thing about this approach is that ie lets you at the dom objects. You can do strange stuff from reparenting table rows to filling out forms and pressing buttons. Its not cross platform by any stretch but its pretty easy. I would also suggest getting the web developer accessories from MS. It lets you right click on a page and either view partial source (selected text) or view the document tree. Anyway just a suggestion on the easy way out for windows. The harder more cross platform way would be to dump the page into a dom parser keeping track of cookies and sending post data etc but that leaves you simulating a lot of a web browser just not the rendering engine. Anyway good luck. -Sam wheelege@tsn.cc, tutor@python.org wrote: > >It is a little strange isn't it...thanks for the incoming reply :) > I'm running win98 here. From kalle@gnupung.net Fri Apr 6 18:50:19 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 6 Apr 2001 19:50:19 +0200 Subject: [Tutor] urllib, urlopen and the evil frames In-Reply-To: <002601c0be97$c49c7160$0200a8c0@ACE>; from wheelege@tsn.cc on Fri, Apr 06, 2001 at 10:47:39PM +1000 References: <002601c0be97$c49c7160$0200a8c0@ACE> Message-ID: <20010406195019.A374@apone.network.loc> Sez Glen Wheeler: > Anyway, I've gotten past step 1, and I logged in by just passing > arguments to a few cgi scripts in an order using urllip.urlopen but when I > get to navigating around in step 2 I just get returned (through ye olde > urllib) 'blah blah This browser does not support frames'. So I thought > 'bah who needs that page anyway' and then tried to access the market > cgi-script using urlopen but then it spits at me saying I haven't logged > in yet. This sounds like a cookie problem. I had aone like it a while ago, and I have some extremely undocumented, unsupported and application-specific code to send you if you're interested. Basically, I grab a cookie from the login page and then use that cookie to authenticate myself to the script I want to access. The frames problem is most easily solved by parsing the html and then urlopening the frame contents too. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From deirdre@deirdre.net Fri Apr 6 19:17:50 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 6 Apr 2001 11:17:50 -0700 (PDT) Subject: [Tutor] Date subtraction In-Reply-To: Message-ID: On Fri, 6 Apr 2001, Turhan Arun wrote: > I want to have a user enter a date in format dd/mm/YYYY like 06/04/2001 > and another date in the same format like 22/04/2001 > depending on these two inputs. I just want to create a list of date > strings like > ['06/04/2001','07/04/2001','08/04/2001'....] > It will be great if you could give some idea. Convert them from those dates into numeric representations of dates using the time module: import time datea = '06/04/2001' dateb = '07/04/2001' tuplea= time.strptime(datea, '%m/%d/%Y') tupleb= time.strptime(dateb, '%m/%d/%Y') (etc) -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From scott@zenplex.com Fri Apr 6 19:53:46 2001 From: scott@zenplex.com (Scott Ralph Comboni) Date: 06 Apr 2001 14:53:46 -0400 Subject: [Tutor] reg expression substitution question Message-ID: <986583230.1285.11.camel@scoot.zenplex.com> I have used perl -p -i -e 's/someName/replaceName/g' . Is there a way to do this type of substitution with the re module? I have tried various ways but all I can come up with is this>> file = open('config.h').read() newfile = open('config.h.new','w') s = re.sub('8192', '32768', file) newfile.write(s) newfile.close() Is there a way I can just read and write to the same file? Thanks Scott -- Scott Ralph Comboni http://www.zenplex.com http://www.zenplex.org http://tambora.zenplex.org From dsh8290@rit.edu Fri Apr 6 21:21:28 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 6 Apr 2001 16:21:28 -0400 Subject: [Tutor] reg expression substitution question In-Reply-To: <986583230.1285.11.camel@scoot.zenplex.com>; from scott@zenplex.com on Fri, Apr 06, 2001 at 02:53:46PM -0400 References: <986583230.1285.11.camel@scoot.zenplex.com> Message-ID: <20010406162128.A14647@harmony.cs.rit.edu> On Fri, Apr 06, 2001 at 02:53:46PM -0400, Scott Ralph Comboni wrote: | | file = open('config.h').read() | newfile = open('config.h.new','w') | s = re.sub('8192', '32768', file) | newfile.write(s) | newfile.close() | | Is there a way I can just read and write to the same file? Same as in C : file = open( 'config.h' , 'r+' ) data = file.read() data = re.sub( '8192' , '32768' , data ) file.seek( 0 ) # go back to the begining file.write( data ) file.close() This, however, will have extra junk at the end of the file if the data to write to the file is shorter than the existing data. To solve that I would recommend the following : file = open( 'config.h' , 'r' ) # open in 'read' mode data = file.read() file.close() # we have all the data, let's close the file data = re.sub( ... ) file = open( 'config.h' , 'w' ) # open it for writing, note that the # file was just truncated to have length 0 file.write( data ) file.close() Perhaps using different names for the 'before' and 'after' file/data objects would be better... HTH, -D From scott@zenplex.com Fri Apr 6 21:49:01 2001 From: scott@zenplex.com (Scott Ralph Comboni) Date: 06 Apr 2001 16:49:01 -0400 Subject: [Tutor] reg expression substitution question In-Reply-To: <20010406162128.A14647@harmony.cs.rit.edu> References: <986583230.1285.11.camel@scoot.zenplex.com> <20010406162128.A14647@harmony.cs.rit.edu> Message-ID: <986590146.1134.1.camel@scoot.zenplex.com> Ok Now I understand that a little better. Thanks. Scott On 06 Apr 2001 16:21:28 -0400, D-Man wrote: > On Fri, Apr 06, 2001 at 02:53:46PM -0400, Scott Ralph Comboni wrote: > | > | file = open('config.h').read() > | newfile = open('config.h.new','w') > | s = re.sub('8192', '32768', file) > | newfile.write(s) > | newfile.close() > | > | Is there a way I can just read and write to the same file? > > Same as in C : > > file = open( 'config.h' , 'r+' ) > data = file.read() > data = re.sub( '8192' , '32768' , data ) > file.seek( 0 ) # go back to the begining > file.write( data ) > file.close() > > > This, however, will have extra junk at the end of the file if the data > to write to the file is shorter than the existing data. > > To solve that I would recommend the following : > > file = open( 'config.h' , 'r' ) # open in 'read' mode > data = file.read() > file.close() # we have all the data, let's close the file > > data = re.sub( ... ) > > file = open( 'config.h' , 'w' ) # open it for writing, note that the > # file was just truncated to have length 0 > file.write( data ) > file.close() > > > Perhaps using different names for the 'before' and 'after' file/data > objects would be better... > > HTH, > -D > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Scott Ralph Comboni president Zenplex, Inc. 317 Madison Ave. Suite 1500 New York NY, 10017 212.499.0668 ext2219 http://www.zenplex.com http://www.zenplex.org http://tambora.zenplex.org From arcege@shore.net Fri Apr 6 21:58:19 2001 From: arcege@shore.net (Michael P. Reilly) Date: Fri, 6 Apr 2001 16:58:19 -0400 (EDT) Subject: [Tutor] reg expression substitution questiony In-Reply-To: <986583230.1285.11.camel@scoot.zenplex.com> from "Scott Ralph Comboni" at Apr 06, 2001 02:53:46 PM Message-ID: <200104062058.f36KwJd07430@dsl254-114-246.nyc1.dsl.speakeasy.net> Scott Ralph Comboni wrote > I have used perl -p -i -e 's/someName/replaceName/g' . Is > there a way to do this type of substitution with the re module? > I have tried various ways but all I can come up with is this>> > > file = open('config.h').read() > newfile = open('config.h.new','w') > s = re.sub('8192', '32768', file) > newfile.write(s) > newfile.close() > > Is there a way I can just read and write to the same file? > Thanks Scott There is no nice way to read and write to the same file (Perl doesn't do it - it moves the original out of the way first). Doing so creates seeking problems and possible bytes at the end of the file (if the new data is shorter). Python's equivalent of Perl's "-n" and "-p" (with -i) options is the fileinput module: import fileinput, re, sys for line in fileinput.input(inplace=1, backup='.bak'): # or fileinput.input(['config.h'], inplace=1, backup='.bak') for your file newline = re.sub('8192', '32768', line) # sys.stdout gets changed to the output file sys.stdout.write(s) # files are closed automatically Good luck, -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. (Arcege) Reilly | arcege@speakeasy.net | From wmperry@swbell.net Sat Apr 7 01:16:59 2001 From: wmperry@swbell.net (William Perry) Date: Fri, 06 Apr 2001 19:16:59 -0500 Subject: [Tutor] User selections question In-Reply-To: References: Message-ID: <200104061916590610.0526FF89@mail.swbell.net> *********** REPLY SEPARATOR *********** On 4/6/01 at 2:37 AM Daniel Yoo wrote: >The indentation of the code feels a little weird to me; it might be better >to indent this like: > > while tst: > area =3D input("enter ") > if area =3D=3D 1: > res =3D area1() > l.append(res) > > ... I noticed that the indenation was changed in the posted message. In the= functional code it matches your example. I'll digest your changes. It looks like a cleaner way to do it. and Yes,= the number of possible inputs in a full featured version of what I'd= trying would be in the 20-30 range so expandability is needed from the= start. Thanks !!!! Bill Perry From linuxboy_xjtu@263.net Sat Apr 7 16:43:21 2001 From: linuxboy_xjtu@263.net (Áõ±ó) Date: Sat, 7 Apr 2001 23:43:21 +0800 (CST) Subject: [Tutor] how can i reload a module under win2000 Message-ID: <3ACF3599.27688@mta5> 1 ,i use win2000+idle(python gui),i have import a module when i alter the file ,should i reload the module by "import" ,i have try so,but it seems not work,who can help me ? 2 in my file i use function int() and str(),but when i run the file there is some error : ValueError: invalid literal for int(): thanks a lot! _____________________________________________ ÇéÊ¥½µÁÙ263ÉÌ³Ç http://shopping.263.net/fs/hododo/index.htm ÇåÁ¹Ò»ÏÄ£¬¿Õµ÷ÈÈÂô http://shopping.263.net/hotsale/aircondition/index.asp From lumbricus@gmx.net Sat Apr 7 18:38:17 2001 From: lumbricus@gmx.net (lumbricus@gmx.net) Date: Sat, 7 Apr 2001 19:38:17 +0200 Subject: [Tutor] how can i reload a module under win2000 In-Reply-To: <3ACF3599.27688@mta5>; from linuxboy_xjtu@263.net on Sat, Apr 07, 2001 at 11:43:21PM +0800 References: <3ACF3599.27688@mta5> Message-ID: <20010407193817.A15108@Laplace.localdomain> On Sat, Apr 07, 2001 at 11:43:21PM +0800, Áõ±ó wrote: > 1 ,i use win2000+idle(python gui),i have import a module when i alter the file ,should i reload the module by "import" ,i have try so,but it seems not work,who can help me ? reload(module) > 2 in my file i use function int() and str(),but when i run the file there is some error : > ValueError: invalid literal for int(): > > > thanks a lot! HTH > > _____________________________________________ > ÇéÊ¥½µÁÙ263ÉÌ³Ç http://shopping.263.net/fs/hododo/index.htm > ÇåÁ¹Ò»ÏÄ£¬¿Õµ÷ÈÈÂô http://shopping.263.net/hotsale/aircondition/index.asp > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Tact in audacity is knowing how far you can go without going too far. -- Jean Cocteau From van@lindbergs.org Sat Apr 7 18:55:25 2001 From: van@lindbergs.org (VanL) Date: Sat, 07 Apr 2001 11:55:25 -0600 Subject: [Tutor] how can i reload a module under win2000 References: <3ACF3599.27688@mta5> Message-ID: <3ACF548D.FE7ACDA8@lindbergs.org> Try the builtin function reload. For example: vanl@MOUSE ~/winhome $ python Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import os >>> reload(os) >>> From jthing@frisurf.no Sat Apr 7 19:22:50 2001 From: jthing@frisurf.no (John Thingstad) Date: Sat, 07 Apr 2001 20:22:50 +0200 Subject: Subject: [Tutor] Tkinter topic completed Message-ID: <200104071828.UAA27681@mail48.fg.online.no> >If anyone has comments I'm pleased to receive them, particularly on >the wxPython section since I don't use wxPython much (altho' I >might now that I've started :-) The layout scheme using absolute coordinates in wxWindows is wastfull and produces code which is difficult to port. It is better to use wxWindows layput classes. Heres an example of using a notebook inteface. Notice the wmBoxSizer. #!/usr/env python #----------------------------------------------------------------------------- # Python source generated by wxDesigner from file: notebook.wdr # Do not modify this file, all changes will be lost! #----------------------------------------------------------------------------- # Include wxWindows' modules from wxPython.wx import * # Window functions ID_TEXTCTRL = 10000 def PageOneFunc( parent, call_fit = true, set_sizer = true ): item0 = wxBoxSizer( wxVERTICAL ) item1 = wxTextCtrl( parent, ID_TEXTCTRL, "", wxDefaultPosition, wxSize(200,-1), 0 ) item0.AddWindow( item1, 0, wxALIGN_CENTRE|wxALL, 20 ) item2 = wxTextCtrl( parent, ID_TEXTCTRL, "", wxDefaultPosition, wxSize(200,90), wxTE_MULTILINE ) item0.AddWindow( item2, 0, wxALIGN_CENTRE|wxALL, 20 ) if set_sizer == true: parent.SetAutoLayout( true ) parent.SetSizer( item0 ) if call_fit == true: item0.Fit( parent ) item0.SetSizeHints( parent ) return item0 ID_CHECKBOX = 10001 ID_BUTTON = 10002 def PageTwoFunc( parent, call_fit = true, set_sizer = true ): item0 = wxBoxSizer( wxVERTICAL ) item2 = wxStaticBox( parent, -1, "Checks" ) item1 = wxStaticBoxSizer( item2, wxHORIZONTAL ) item3 = wxCheckBox( parent, ID_CHECKBOX, "Check", wxDefaultPosition, wxDefaultSize, 0 ) item1.AddWindow( item3, 0, wxALIGN_CENTRE|wxALL, 5 ) item4 = wxCheckBox( parent, ID_CHECKBOX, "Check", wxDefaultPosition, wxDefaultSize, 0 ) item1.AddWindow( item4, 0, wxALIGN_CENTRE|wxALL, 5 ) item5 = wxCheckBox( parent, ID_CHECKBOX, "Check", wxDefaultPosition, wxDefaultSize, 0 ) item1.AddWindow( item5, 0, wxALIGN_CENTRE|wxALL, 5 ) item0.AddSizer( item1, 0, wxALIGN_CENTRE|wxALL, 5 ) item7 = wxStaticBox( parent, -1, "Buttons" ) item6 = wxStaticBoxSizer( item7, wxVERTICAL ) item8 = wxButton( parent, ID_BUTTON, "OK", wxDefaultPosition, wxDefaultSize, 0 ) item6.AddWindow( item8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ) item9 = wxButton( parent, ID_BUTTON, "OK", wxDefaultPosition, wxDefaultSize, 0 ) item6.AddWindow( item9, 0, wxALIGN_CENTRE|wxALL, 5 ) item10 = wxButton( parent, ID_BUTTON, "OK", wxDefaultPosition, wxDefaultSize, 0 ) item6.AddWindow( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ) item0.AddSizer( item6, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ) if set_sizer == true: parent.SetAutoLayout( true ) parent.SetSizer( item0 ) if call_fit == true: item0.Fit( parent ) item0.SetSizeHints( parent ) return item0 ID_NOTEBOOK = 10003 ID_LINE = 10004 def NotebookFunc( parent, call_fit = true, set_sizer = true ): item0 = wxBoxSizer( wxVERTICAL ) item2 = wxNotebook( parent, ID_NOTEBOOK, wxDefaultPosition, wxSize(200,160), 0 ) item1 = wxNotebookSizer( item2 ) item3 = wxPanel( item2, -1 ) PageOneFunc( item3, false ) item2.AddPage( item3, "Page 1" ) item4 = wxPanel( item2, -1 ) PageTwoFunc( item4, false ) item2.AddPage( item4, "Page 2" ) item0.AddSizer( item1, 0, wxALIGN_CENTRE|wxALL, 5 ) item5 = wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL ) item0.AddWindow( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ) item6 = wxBoxSizer( wxHORIZONTAL ) item7 = wxButton( parent, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize, 0 ) item7.SetDefault() item6.AddWindow( item7, 0, wxALIGN_CENTRE|wxALL, 5 ) item8 = wxButton( parent, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize, 0 ) item6.AddWindow( item8, 0, wxALIGN_CENTRE|wxALL, 5 ) item0.AddSizer( item6, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxBOTTOM, 5 ) if set_sizer == true: parent.SetAutoLayout( true ) parent.SetSizer( item0 ) if call_fit == true: item0.Fit( parent ) item0.SetSizeHints( parent ) return item0 # Bitmap functions # End of generated file From cdwom@mpinet.net Sat Apr 7 23:42:37 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Sat, 7 Apr 2001 18:42:37 -0400 Subject: [Tutor] E-mail in python Message-ID: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> Would it be plausible to write an e-mail client in Python? The reason I ask is because Outlook has more than pissed me off too much. I know that I couldn't write something that complex yet, but Its a goal :) So, would A. it be plausible. and B. Where should I start? Thanks, Corey From arcege@shore.net Sun Apr 8 00:11:15 2001 From: arcege@shore.net (Michael P. Reilly) Date: Sat, 7 Apr 2001 19:11:15 -0400 (EDT) Subject: [Tutor] E-mail in python In-Reply-To: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> from "Corey Woodworth" at Apr 07, 2001 06:42:37 PM Message-ID: <200104072311.f37NBFT01669@dsl254-114-246.nyc1.dsl.speakeasy.net> Corey Woodworth wrote > Would it be plausible to write an e-mail client in Python? The reason I ask > is because Outlook has more than pissed me off too much. I know that I > couldn't write something that complex yet, but Its a goal :) So, would A. it > be plausible. and B. Where should I start? There is a semi-decent, cross-platform one called "PyMailGui" that comes with the 2nd Edition of Mark Lutz's _Programming Python_. There's a lot to be added to it, but it is open source and looks pretty well extensible. Within Python itself, there are smtplib, poplib and imaplib modules to deal with the sending and receiving of e-mail messages. As well as rfc822, mimecntl and mailbox modules. To do a little self-promoting, there is also a more useful MIME module (for programming) than those that come with Python called "mimecntl" available at . -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From syrinx@simplecom.net Sun Apr 8 00:37:31 2001 From: syrinx@simplecom.net (Scott) Date: Sat, 07 Apr 2001 18:37:31 -0500 Subject: [Tutor] for each dictionary key... Message-ID: I've been doing this: keys =3D self.someclass.keys() for key in keys: ( do something ) What's the shorter way? From DOUGS@oceanic.com Sun Apr 8 01:05:34 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Sat, 7 Apr 2001 14:05:34 -1000 Subject: [Tutor] for each dictionary key... Message-ID: <8457258D741DD411BD3D0050DA62365907A745@huina.oceanic.com> Well, for key in self.someclass.keys(): ( do something ) But shorter doesn't always mean better if it reduces the ability to easily understand the code. Thats a judgement call you have to make. Also, if you decided later that you needed to sort those keys, you'd probably have to go back to your original with the addition of... keys.sort() HTH -Doug- > -----Original Message----- > From: Scott [mailto:syrinx@simplecom.net] > Sent: Saturday, April 07, 2001 1:38 PM > To: tutor@python.org > Subject: [Tutor] for each dictionary key... > > > > I've been doing this: > > keys = self.someclass.keys() > for key in keys: > ( do something ) > > What's the shorter way? > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From dsh8290@rit.edu Sun Apr 8 03:36:54 2001 From: dsh8290@rit.edu (D-Man) Date: Sat, 7 Apr 2001 22:36:54 -0400 Subject: [Tutor] E-mail in python In-Reply-To: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW>; from cdwom@mpinet.net on Sat, Apr 07, 2001 at 06:42:37PM -0400 References: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> Message-ID: <20010407223653.A22169@harmony.cs.rit.edu> On Sat, Apr 07, 2001 at 06:42:37PM -0400, Corey Woodworth wrote: | Would it be plausible to write an e-mail client in Python? The reason I ask | is because Outlook has more than pissed me off too much. I know that I | couldn't write something that complex yet, but Its a goal :) So, would A. it | be plausible. and B. Where should I start? I would recommend starting with pmail or PMS. I don't know if pmail would work on windows or not (probably not -- I think it uses the GNOME desktop for some stuff) but I couldn't get it to work when I tried it on my linux box. PMS (Python Mail System) is a project that Moshe Zadka started/is working on to make a mail client in python. Talk to him about working on it. HTH, -D From jsc_lists@rock-tnsc.com Mon Apr 9 03:51:08 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Sun, 08 Apr 2001 18:51:08 -0800 Subject: [Tutor] E-mail in python References: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> Message-ID: <3AD1239C.6010403@rock-tnsc.com> Corey Woodworth wrote: > Would it be plausible to write an e-mail client in Python? The reason I ask > is because Outlook has more than pissed me off too much. I know that I > couldn't write something that complex yet, but Its a goal :) So, would A. it > be plausible. and B. Where should I start? > > Thanks, > Corey > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor As I remember there is a quite advanced gui e-mail client program based on wxpython. I think it is called Balsa or Mahogany. Check on the wxPython page for links. Jethro From moshez@zadka.site.co.il Sun Apr 8 13:49:01 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Sun, 08 Apr 2001 14:49:01 +0200 Subject: [Tutor] (no subject) In-Reply-To: References: Message-ID: On Thu, 29 Mar 2001 13:01:00 -0800, Glen Bunting wrote: > Let me rephrase the question. I didn't state the question very clearly. I > am trying to write a python script on Mandrake Linux that will check the > amount of free memory available, similar to using the 'free' command. I > already have a script written in sh which does this by calling the free > command, but I am trying to re-write it completely in python. os.popen("free") You're free to go dig around in /proc if you really want to, but free will always know more then you do. -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org From moshez@zadka.site.co.il Sun Apr 8 14:00:09 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Sun, 08 Apr 2001 15:00:09 +0200 Subject: [Tutor] E-mail in python In-Reply-To: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> References: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> Message-ID: On Sat, 7 Apr 2001 18:42:37 -0400, "Corey Woodworth" wrote: > Would it be plausible to write an e-mail client in Python? The reason I ask > is because Outlook has more than pissed me off too much. I know that I > couldn't write something that complex yet, but Its a goal :) So, would A. it > be plausible. and B. Where should I start? One place is http://pythonms.sourceforge.net It's my e-mail client. It's in the public domain, so you can do anything you want with it. -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org From spi" When doing a POST to a server with httplib.HTTPConnection and grabbing the response "response = connection.getresponse()", the server will always send back a "100 Continue" before sending the real response, how do I read the real response? From julieta_rangel@hotmail.com Sun Apr 8 23:12:08 2001 From: julieta_rangel@hotmail.com (Julieta) Date: Sun, 8 Apr 2001 17:12:08 -0500 Subject: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0C04F.0B0992A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable The primes, 2,3,4,5,7, . . . can be arranged on a two-dimensional plane = in the form of a rectangular spiral. <-represents left -> represents right ^represents up | = represents down 59 <- 53 <- 47 <- 43 <- 41 ^ 11 <- 7 <- 5 <- 37 | ^ ^ 13 2 -> 3 31 | ^=20 17 -> 19 -> 23 -> 29 How could I write a program which inputs integers M and N and outputs = the value of the number at location (M, N) on the plane? The initial 2 = is stored at position (0,0). This means that an input of ( 0, 0 ) = should output 2. An input of, say, ( -1, 1) should output 11; an input = of (-1,2) should output 53, and so on. I don't have any programming experience nor have I ever taken a computer = programming class, however, I would like to start learning. I've = written very small programs (20 lines long) in my TI - 92 calculator and = in Python, and I'm trying to build on that. Right now I'm trying to = learn some Python, so any kind of input on this problem would help = tremendously. ------=_NextPart_000_0005_01C0C04F.0B0992A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
The primes, 2,3,4,5,7, . . . can be = arranged on a=20 two-dimensional plane in the form of a rectangular spiral.
<-represents left   -> = represents=20 right    ^represents up     | = represents=20 down
 
59 <-  53 <-  47 = <- =20 43    <-   41
          &nbs= p;            = ;            = =20          ^
        11=20 <-   7    <-  =20 5   <-     37
         =20 |            =        =20 ^           =20 ^
       =20 13       2   ->  =20 3          31
          |&nb= sp;           &nbs= p;            = ;      =20 ^
        17  = -> =20 19  ->  23   ->    = 29
 
How could I write a program which = inputs integers M=20 and N and outputs the value of the number at location (M, N) on the = plane? =20 The initial 2 is stored at position  (0,0).   This means = that an=20 input of ( 0, 0 ) should output 2.  An input=20 of, say, ( -1, 1) should output 11; an input of (-1,2) should output 53, = and so=20 on.
 
I don't have any programming experience = nor have I=20 ever taken a computer programming class, however, I would like to start=20 learning.  I've written very small programs (20 lines long) in my = TI - 92=20 calculator and in Python, and I'm trying to build on that.  Right = now I'm=20 trying to learn some Python, so any kind of input on this problem would = help=20 tremendously.
 
 
------=_NextPart_000_0005_01C0C04F.0B0992A0-- From britt_green@hotmail.com Mon Apr 9 01:28:31 2001 From: britt_green@hotmail.com (Britt Green) Date: Sun, 08 Apr 2001 17:28:31 -0700 Subject: [Tutor] Naming Instances of Classes Message-ID: I have a little problem thats been vexing me for the past week. If I have a class, how do you name the instances of that class? In all the code I've seen its always been hardcoded like this: class Employee: pass john = Employee() Instead of hardcoding it, how can I make my program automatically give a unique name or number to a new class? Britt -- It is pitch black. You are likely to be eaten by a grue. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From rick@niof.net Mon Apr 9 01:56:11 2001 From: rick@niof.net (Rick Pasotto) Date: Sun, 8 Apr 2001 20:56:11 -0400 Subject: [Tutor] Naming Instances of Classes In-Reply-To: ; from britt_green@hotmail.com on Sun, Apr 08, 2001 at 05:28:31PM -0700 References: Message-ID: <20010408205611.A554@tc.niof.net> On Sun, Apr 08, 2001 at 05:28:31PM -0700, Britt Green wrote: > I have a little problem thats been vexing me for the past week. If I > have a class, how do you name the instances of that class? In all the > code I've seen its always been hardcoded like this: > > class Employee: pass > > john = Employee() > > Instead of hardcoding it, how can I make my program automatically give > a unique name or number to a new class? How are you going to refer to it if you don't give it a name? -- "Democracy is being allowed to vote for the candidate you dislike least." -- Robert Byrne Rick Pasotto email: rickp@telocity.com From dsh8290@rit.edu Mon Apr 9 02:24:36 2001 From: dsh8290@rit.edu (D-Man) Date: Sun, 8 Apr 2001 21:24:36 -0400 Subject: [Tutor] E-mail in python In-Reply-To: <3AD1239C.6010403@rock-tnsc.com>; from jsc_lists@rock-tnsc.com on Sun, Apr 08, 2001 at 06:51:08PM -0800 References: <000d01c0bfb4$0c382b00$0adc35d8@KellyJoW> <3AD1239C.6010403@rock-tnsc.com> Message-ID: <20010408212436.A24057@harmony.cs.rit.edu> On Sun, Apr 08, 2001 at 06:51:08PM -0800, Jethro Cramp wrote: | Corey Woodworth wrote: | | > Would it be plausible to write an e-mail client in Python? The reason I ask | > is because Outlook has more than pissed me off too much. I know that I | > couldn't write something that complex yet, but Its a goal :) So, would A. it | > be plausible. and B. Where should I start? | | As I remember there is a quite advanced gui e-mail client program based | on wxpython. I think it is called Balsa or Mahogany. Check on the | wxPython page for links. Balsa is based on GTK+ and GNOME. Mahogany is based on wxWindows and embeds Python for extensibility. It now has a Win32 build available too. Another client you may want to check out is mutt. It is console based (ncurses) but is quite flexible and useable. I like it a lot. It works well on Windows systems with Cygwin (just change all 'fopen' calls to use binary mode or all attachments will be corrupt). -D From dyoo@hkn.eecs.berkeley.edu Mon Apr 9 03:29:35 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 8 Apr 2001 19:29:35 -0700 (PDT) Subject: [Tutor] Naming Instances of Classes In-Reply-To: <20010408205611.A554@tc.niof.net> Message-ID: On Sun, 8 Apr 2001, Rick Pasotto wrote: > On Sun, Apr 08, 2001 at 05:28:31PM -0700, Britt Green wrote: > > I have a little problem thats been vexing me for the past week. If I > > have a class, how do you name the instances of that class? In all the > > code I've seen its always been hardcoded like this: > > > > class Employee: pass > > > > john = Employee() > > > > Instead of hardcoding it, how can I make my program automatically give > > a unique name or number to a new class? > > How are you going to refer to it if you don't give it a name? You can put it into a Python list --- the list itself would have a name, but the contents could be indexed by number: employees = [] for i in range(10): employees.append(Employee()) would create a list of 10 employees. I'm not sure if this is what you want, though. Good luck to you. From rick@niof.net Mon Apr 9 04:20:07 2001 From: rick@niof.net (Rick Pasotto) Date: Sun, 8 Apr 2001 23:20:07 -0400 Subject: [Tutor] Naming Instances of Classes In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Sun, Apr 08, 2001 at 07:29:35PM -0700 References: <20010408205611.A554@tc.niof.net> Message-ID: <20010408232007.B554@tc.niof.net> On Sun, Apr 08, 2001 at 07:29:35PM -0700, Daniel Yoo wrote: > On Sun, 8 Apr 2001, Rick Pasotto wrote: > > > On Sun, Apr 08, 2001 at 05:28:31PM -0700, Britt Green wrote: > > > I have a little problem thats been vexing me for the past week. If > > > I have a class, how do you name the instances of that class? In > > > all the code I've seen its always been hardcoded like this: > > > > > > class Employee: pass > > > > > > john = Employee() > > > > > > Instead of hardcoding it, how can I make my program automatically > > > give a unique name or number to a new class? > > > > How are you going to refer to it if you don't give it a name? > > You can put it into a Python list --- the list itself would have a > name, but the contents could be indexed by number: > > employees = [] > for i in range(10): > employees.append(Employee()) > > would create a list of 10 employees. I'm not sure if this is what you > want, though. Precisely. The names would then be employees[0], employees[1], etc. What the original poster was asking for doesn't make any sense. -- "Moderation in temper is always a virtue; but moderation in principle is always a vice." -- Thomas Paine, _The Rights of Man_ (1791) Rick Pasotto email: rickp@telocity.com From glingl@aon.at Mon Apr 9 07:50:51 2001 From: glingl@aon.at (Gregor Lingl) Date: Mon, 09 Apr 2001 08:50:51 +0200 Subject: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral References: Message-ID: <3AD15BCB.CB1E1B5E@aon.at> Julieta schrieb: > The primes, 2,3,4,5,7, . . . can be arranged on a two-dimensional > plane in the form of a rectangular spiral.<-represents left -> > represents right ^represents up | represents down 59 <- 53 <- > 47 <- 43 <- 41 > ^ 11 <- 7 <- 5 <- 37 | > ^ ^ 13 2 -> 3 31 > | ^ 17 -> 19 -> 23 -> > 29 How could I write a program which inputs integers M and N and > outputs the value of the number at location (M, N) on the plane? The > initial 2 is stored at position (0,0). This means that an input of > ( 0, 0 ) should output 2. An input of, say, ( -1, 1) should output > 11; an input of (-1,2) should output 53, and so on. I don't have any > programming experience nor have I ever taken a computer programming > class, however, I would like to start learning. I've written very > small programs (20 lines long) in my TI - 92 calculator and in Python, > and I'm trying to build on that. Right now I'm trying to learn some > Python, so any kind of input on this problem would help > tremendously. Dear Julieta! I assume, that 'any kind of input' doesn't mean a complete solution to the problem. So I'll provide some hints: Befor beginning to code you have to know clearly how to solve the problem by hand. I think it could be helpful to break up the problem in two smaller ones: 1. Calculate an n so that the the location (M,N) ist the n-th 'point' on your spiral, for instance: (0/0) ->1 (1/0) ->2 (1/1) ->3 ... (1/-1) -> 9 (2/-1) -> 10 (2/0) -> 11 ... and so on. 2. Calculate the n-th prime. For this a simple (although probably not very efficient) way would be to use the Sieve of Eratosthenes: Write down all natural numbers from 1 to a certain maximum z (yet to determine). Cancel 1. Next uncancelled number is 2 It's a prime: mark it and cancel all the multiples of two. Next uncancelled number is 3. It's a prime: mark it and cancel all the multiples of three, ... Repeat this until the square of the next uncacelled number ( = found prime) surpasses z. Only primes remain in the list and now you can determine the n-th one. As z use a number which will be securely big enough. Remark: If you have an algorithm to determine if a given natural number is prime, an even simpler but less efficient way would be to go through the natural numbers, determine for each one, if it is a prime and count it ... until you arrive at the n-th prime. 3. Combine those two parts of the solution. 4. If you need more help on specific parts of the solution, try to formulate clear questions and put them into the tutor-newsgroup. 5. If you arrive at a solution post it at Useless Python , the best place where it belongs to. Have fun, Gregor Lingl P.S.: Interesting would be a (more or less) simple and efficient way to calculate from a given prime p next_prime(p). Perhaps someone else knows one .... From sheila@thinkspot.net Mon Apr 9 07:57:40 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 08 Apr 2001 23:57:40 -0700 Subject: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral In-Reply-To: <3AD15BCB.CB1E1B5E@aon.at> References: <3AD15BCB.CB1E1B5E@aon.at> Message-ID: <14CE6196C60@kserver.org> On Mon, 09 Apr 2001 08:50:51 +0200, Gregor Lingl wrote about Re: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral: :P.S.: Interesting would be a (more or less) simple and efficient way to :calculate from a given prime p next_prime(p). Perhaps someone else :knows one .... I believe that the algorithm that is generally considered the quickest for calculating primes, is called the "Sieve of Erasthones". (sp?) However, this algorithm requires that you start from the number "two" and work your way on up. I don't believe there is any way to start at an arbitrary prime number and find the next prime without knowing the preceding primes. So, you'd have to implement the Sieve of Erasthones in any case, even though you were only interested in finding a single number. I'm always willing to find out I'm wrong, if someone else knows better... -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From scarblac@pino.selwerd.nl Mon Apr 9 08:16:06 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 9 Apr 2001 09:16:06 +0200 Subject: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral In-Reply-To: ; from julieta_rangel@hotmail.com on Sun, Apr 08, 2001 at 05:12:08PM -0500 References: Message-ID: <20010409091606.A24574@pino.selwerd.nl> On 0, Julieta wrote: > The primes, 2,3,4,5,7, . . . can be arranged on a two-dimensional plane in the form of a rectangular spiral. > <-represents left -> represents right ^represents up | represents down > > 59 <- 53 <- 47 <- 43 <- 41 > ^ > 11 <- 7 <- 5 <- 37 > | ^ ^ > 13 2 -> 3 31 > | ^ > 17 -> 19 -> 23 -> 29 > > How could I write a program which inputs integers M and N and outputs the > value of the number at location (M, N) on the plane? The initial 2 is > stored at position (0,0). This means that an input of ( 0, 0 ) should > output 2. An input of, say, ( -1, 1) should output 11; an input of (-1,2) > should output 53, and so on. What an odd problem. Is this a homework assignment? At first it looks like the way to do this is a) Find out from the position you get which prime you need b) Find that prime On a closer look, the way to find prime n is to build up a list of them, growing it until you've found the nth one. It would be easy to keep track of the position of that prime as well, stopping when we arrive at the right point. If you have the Python source distribution, there is a prime number program in Demos/scripts/primes.py. Change the primes function to primes(x, y) for the position and let it always start at min=2. Initialize cur_x and cur_y to 0, 0, for the start position. Change the loop into something like "while (x,y) != (cur_x, cur_y)" and put some code after primes.append(i) that moves the position (cur_x, cur_y) around appropriately. In the end, primes[-1] has the answer. -- Remco Gerlich From skandel07@hotmail.com Mon Apr 9 10:07:03 2001 From: skandel07@hotmail.com (Derek White) Date: Mon, 09 Apr 2001 05:07:03 -0400 Subject: [Tutor] Message persistence Message-ID: Hello all, If I were wanting to write a web based message board system with CGI with replies in threads what would be some of the ways to consider for message persistence in Python? Thanks, Derek White _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Mon Apr 9 10:21:32 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Apr 2001 02:21:32 -0700 (PDT) Subject: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral In-Reply-To: Message-ID: On Sun, 8 Apr 2001, Julieta wrote: > The primes, 2,3,4,5,7, . . . can be arranged on a two-dimensional > plane in the form of a rectangular spiral. > <-represents left -> represents right ^represents up | represents down > > 59 <- 53 <- 47 <- 43 <- 41 > ^ > 11 <- 7 <- 5 <- 37 > | ^ ^ > 13 2 -> 3 31 > | ^ > 17 -> 19 -> 23 -> 29 > > How could I write a program which inputs integers M and N and outputs > the value of the number at location (M, N) on the plane? The initial > 2 is stored at position (0,0). This means that an input of ( 0, 0 ) > should output 2. An input of, say, ( -1, 1) should output 11; an > input of (-1,2) should output 53, and so on. Wow! This looks like a really interesting problem. The problem with the primes doesn't seem as interesting as trying to get the cycle thing going. The cycle problem seems rife with patterns; it'd be nice to get it working. The first problem that I'm seeing is trying to figure out a function that, given a location, tells us which prime we're looking for. Let's see if there are patterns... nth location --- ------ 0 (0, 0) 1 (1, 0) 2 (1, 1) 3 (0, 1) 4 (-1, 1) 5 (-1, 0) 6 (-1, -1) ... The numbers that are catching my eye, at the moment, are the ones on the diagonal in Quadrant three: nth location --- ------ 0 (0, 0) 6 (-1, -1) 20 (-2, -2) 42 (-3, -3) ... ... The reason that these numbers seem interesting to me is that if we start taking the differences between them, there's an interesting pattern that occurs: 0 6 20 42 # Position numbers on the diagonal 6 14 22 # Difference level 1 8 8 # Difference level 2 As a prediction, I suspect that at position (-4, -4), we are trying to print out the 72th number. I haven't testing this yet. The reason for this guess is because there's a way to consistantly extend this pattern: 0 6 20 42 72 6 14 22 30 8 8 8 But I'd have to draw it out to manually verify this. Testing it now... verified! Yes: the number at position (-4, -4) should be the 72th prime. Cool, so that's one pattern we might be able to exploit here, that if we take the difference between two diagonal positions, the gap between the appears to expand at a rate of 8. This might not help, but it's a pattern, and there might be a very cute way of writing a function that can quickly find, given a position, the nth number. I'll take a closer look at this when I have time --- this looks really interesting! Skip below if you want to listen to me ramble about discrete math while I'm working at this... *grin* (note: yes, there is a cute way. >>> def a(n): return 2*n*(1+2*n) ... >>> a(0), a(1), a(2), a(3), a(4) (0, 6, 20, 42, 72) The method for deriving this is below.) --- [Math mode on. Warning!] Hmmm... I'd like to label those three sequences I was looking at earlier: 0 6 20 42 72 # Let's call this sequence (a) 6 14 22 30 # Let's call this sequence (b) 8 8 8 # Let's call this sequence (c) The problem that I'd like to solve is to find a nice formula for sequence (a) --- that would solve the problem of finding which nth prime should go on the diagonals. Sequence (c) isn't that interesting, because it's just all 8s. Let's look at sequence (b). Sequence (b) isn't that much harder, because every time we go up the sequence, we just need to add 8 to what we had before. This translates, in math, to: b(n) = 6 + 8 * n With this done, we might be able to handle sequence (a), which looks a little weirder. In order to get from one part of the sequence to the next, we need to add a corresponding element from (b). More formally: a(0) = 0 a(n) = a(n-1) + b(n-1) Let's see if this works in Python. ### >>> def b(n): return 6 + 8*n ... >>> def a(n): ... if n == 0: return 0 ... else: return a(n-1) + b(n-1) ... >>> a(0), a(1), a(2), a(3), a(4) (0, 6, 20, 42, 72) ### Very cool. So this is a perfectly good way of solving the problem of finding which prime numbers should go on the diagonal. But we can go even further, if we're perverse enough. It's also very true that: a(n) = a(n-1) + 8*(n-1) + 6 = a(n-1) + 8*n - 2 if we substitute the value of b(n-1) into the equation. If I were to do this by hand, I'd use a math technique called generating functions that can take something like: a(0) = 0 a(n) = a(n-1) + 8*n - 2 and transform it into something nicer. But I'm cheap and ignorant about generating functions still, so I'll use Mathematica instead. According to Mathematica's RSolve function, a(n) = 2n(1+2n) Does this work? ### >>> def a(n): return 2*n*(1+2*n) ... >>> a(0), a(1), a(2), a(3), a(4) (0, 6, 20, 42, 72) ### My gosh. I must learn how generating functions work, so that I can see how in the world that worked. *grin* From alan.gauld@bt.com Mon Apr 9 11:15:09 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Apr 2001 11:15:09 +0100 Subject: Subject: [Tutor] Tkinter topic completed Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6CD@mbtlipnt02.btlabs.bt.co.uk> > The layout scheme using absolute coordinates in wxWindows is > wastfull and produces code which is difficult to port. Indeed, its the big thing I don't like about wxPython so far. I hate coordinate based layouts. > It is better to use wxWindows layput classes. Aha! I didn't notice those, all the examles/tutors I had seen used coordinates. I will go look at the layout objects, thanks. Thanks for the comments, Alan G From alan.gauld@bt.com Mon Apr 9 11:43:23 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Apr 2001 11:43:23 +0100 Subject: [Tutor] Primes on a two-dimensional plane in the form of a re ctangular spiral Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6D0@mbtlipnt02.btlabs.bt.co.uk> ---Interesting discourse on pattern generayion snipped---- > But I'm cheap and ignorant about generating functions still, > so I'll use Mathematica instead. According to > Mathematica's RSolve function, > > a(n) = 2n(1+2n) > .... > My gosh. I must learn how generating functions work, so that > I can see how in the world that worked. *grin* You do that Danny, me I'm off to buy a copy of Mathematica :-) I didn't know it could do that kind of thing, cool! Alan G. From alan.gauld@bt.com Mon Apr 9 11:31:12 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Apr 2001 11:31:12 +0100 Subject: [Tutor] Naming Instances of Classes Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6CE@mbtlipnt02.btlabs.bt.co.uk> > class, how do you name the instances of that class? > john = Employee() > > Instead of hardcoding it, how can I make my program > automatically give a unique name or number to a new class? Thee are several ways including using sequence numbers and generating unique strings, then use eval() to do the assignment. But since the only real need for this that I can think of is to create collections of objects why not just usea list and append the classes: myBigNumber = 1000000 class myClass: pass myInstances = [] for i in range(aBigNumber): myInstances.append(myClass()) You can then operate on all of your classes using map, filter etc or just a for loop. Or you can find the instance you want (maybe with filter) and assign that to a hard coded name: def selectAnInstance(inst,val = "spam"): return inst.meat == val thisInstance = filter(selectAnInstance, myInstances)[0] #1 only HTH, Alan G From alan.gauld@bt.com Mon Apr 9 11:35:59 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 9 Apr 2001 11:35:59 +0100 Subject: [Tutor] Message persistence Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6CF@mbtlipnt02.btlabs.bt.co.uk> > to write a web based message board system with CGI with > replies in threads what would be some of the ways to consider > for message persistence in Python? Same as any other kind of persistence: 1) Store in memory - valid for life of process 2) Store in flat files - fine oif not too many - maybe OK if a file per thread? 3) pickle/shelve - save the thread object as above but less work :-) 4) Use a database - best if any real volumes involved. Pick any database that runs on your platform and has a Python data driver module Alan G From lha2@columbia.edu Mon Apr 9 15:23:52 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Mon, 09 Apr 2001 10:23:52 -0400 Subject: [Tutor] Re: [Python] Primes on a two-dimensional plane in the form of a rectangular spiral References: Message-ID: <3AD1C5F8.DA562B35@mail.verizon.net> Because the original post (from Julieta) was encoded by MIME, the formatting got all messed up and I won't be quoting from it. See the bottom of for how to create a matrix, which can be thought of as a two-dimensional list; the problem is that negative indices won't work the way you want them to. A negative index will count from the end of the list; so matrix=[[1,2,3],[4,5,6],[7,8,9]] is thought of by people as looking like [1,2,3] [4,5,6] [7,8,9] and matrix[-1][-1] should return <9>. You could use a matrix implementation, and keep track of where the origin is, but that could get ugly. Because you have negative indices, it may be easier for you to pretend that you have a sparse matrix (even though you will have zero entries with value zero) and use a dictionary with key-values that are tuples: for the above matrix, with <5> as the "origin", matrixdict = {(0,0):5, (0,1):6} #you can set initial values matrixdict[(-1,1)] = 1 #and you can add values as you go matrixdict[(-1,0)] = 4 matrixdict {(0, 1): 6, (0, 0): 5, (-1, 1): 1, (-1, 0): 4} matrixdict[(0,1)] 6 This implementation looks easier and more appropriate for your project. From st_hickey@hotmail.com Mon Apr 9 15:56:54 2001 From: st_hickey@hotmail.com (Stevenson Hickey) Date: Mon, 9 Apr 2001 07:56:54 -0700 Subject: [Tutor] WxPython Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0014_01C0C0CA.A4FACAC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I downloaded WxPython for Python 2.0 and installed it from the download = just by clicking on it. It seemed to install properly, but when I went = to do the demo as instructed, I could not get it from Windows. I went = into Cygwin and went to the directory and typed "python demo.py". This = is the error message I got: stevenson hickey@HICKEY BOX /c/python21/s $ python demo.py Traceback (most recent call last): File "demo.py", line 3, in ? import Main File "Main.py", line 15, in ? from wxPython.wx import * ImportError: No module named wxPython.wx When I did a search of my whole Python directory, I found no file named = wxpython.wx. =20 I understand that this may mean that I have to compile wxpython from = source code, but I don't understand why? =20 I am running Windows 98 on a 400 Mhz PC with 64 Megs Ram. Thanks for any help, Stevenson Hickey --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.247 / Virus Database: 120 - Release Date: 4/6/2001 ------=_NextPart_000_0014_01C0C0CA.A4FACAC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I downloaded WxPython for Python 2.0 and installed it from the = download=20 just by clicking on it.  It seemed to install properly, but when I = went to=20 do the demo as instructed, I could not get it from Windows.  I went = into=20 Cygwin and went to the directory and typed "python demo.py".  This = is the=20 error message I got:
 
stevenson  hickey@HICKEY = BOX=20 /c/python21/s
$ python demo.py
Traceback (most recent call=20 last):
  File "demo.py", line 3, in ?
    = import=20 Main
  File "Main.py", line 15, in ?
   =20 from   wxPython.wx import *
ImportError: No module named=20 wxPython.wx
 
When I did a search of my whole Python directory, I found no file = named=20 wxpython.wx. 
 
I understand that this may mean that I have to compile wxpython = from source=20 code, but I don't understand why? 
I am running Windows 98 = on  a=20 400 Mhz PC with 64 Megs Ram.
 
Thanks for any help,
 
Stevenson Hickey
 

---
Outgoing mail is certified Virus Free.
Checked by AVG = anti-virus system (http://www.grisoft.com).
Version: = 6.0.247 /=20 Virus Database: 120 - Release Date: 4/6/2001
------=_NextPart_000_0014_01C0C0CA.A4FACAC0-- From dsh8290@rit.edu Mon Apr 9 16:17:26 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 9 Apr 2001 11:17:26 -0400 Subject: [Tutor] WxPython In-Reply-To: ; from st_hickey@hotmail.com on Mon, Apr 09, 2001 at 07:56:54AM -0700 References: Message-ID: <20010409111725.A24784@harmony.cs.rit.edu> On Mon, Apr 09, 2001 at 07:56:54AM -0700, Stevenson Hickey wrote: | | I downloaded WxPython for Python 2.0 and installed it from the | download just by clicking on it. It seemed to install properly, but | when I went to do the demo as instructed, I could not get it from | Windows. I went into Cygwin and went to the directory and typed | "python demo.py". This is the error message I got: | | stevenson [1]hickey@HICKEY BOX /c/python21/s | $ python demo.py | Traceback (most recent call last): | File "demo.py", line 3, in ? | import Main | File "Main.py", line 15, in ? | from wxPython.wx import * | ImportError: No module named wxPython.wx | | When I did a search of my whole Python directory, I found no file | named wxpython.wx. Where did you install wxPython to? When I installed it I put it in d:\lib\python_packages\wxPython. I needed to add d:\lib\python_packages to my PYTHONPATH environment variable. The reason is python will look in it's install directory and PYTHONPATH to find all modules/packages. If you installed wxPython to a different directory, it won't be able to find it. You need to either include that directory in PYTHONPATH or install it under the python directory. The other solution is to create a .pth file in the python install directory. It can be named anything. For example : ------ d:\apps\Python20\packages.pth ------ d:\lib\python_packages That pth file will add that path to sys.path, and python will recognize all packages in that directory (such as wxPython). HTH, -D From hailan@thing.radiant-media.com Mon Apr 9 16:33:31 2001 From: hailan@thing.radiant-media.com (Hailan Yu) Date: Mon, 9 Apr 2001 11:33:31 -0400 (EDT) Subject: [Tutor] how to change PYTHONPATH in WinPython 2.0 Message-ID: <20010409153331.9F65E1382@thing.radiant-media.com> In win python 2.0 IDLE, you can browse path using path browser, but how you can change path? If you want to install a python app, what you have to do, so it can find all the packages, likw wxpython, XML, etc. Hailan Thanks From dsh8290@rit.edu Mon Apr 9 17:17:51 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 9 Apr 2001 12:17:51 -0400 Subject: [Tutor] how to change PYTHONPATH in WinPython 2.0 In-Reply-To: <20010409153331.9F65E1382@thing.radiant-media.com>; from hailan@thing.radiant-media.com on Mon, Apr 09, 2001 at 11:33:31AM -0400 References: <20010409153331.9F65E1382@thing.radiant-media.com> Message-ID: <20010409121751.A24917@harmony.cs.rit.edu> In Windows 9x you can set PYTHONPATH : o open c:\autoexec.bat with your favorite text editor (notepad or edit will suffice) o add this line at the bottom : set PYTHONPATH c:\path\to\packages o save o reboot ( ?-p ) In WinNT or 2K you can set PYTHONPATH : o click on Start->Settings->Control Panel->System o click on the "Advanced" tab o click on the "Environment Variables" button o click on the "New" button (pick whether you want this change for the current user only, or all users, for all users you must have admin privilegs) o type "PYTHONPATH" (without quotes) for the variable name o type the value (ie c:\path\to\packages) for the value o click the "Ok" button o click the "Ok" button o click the "Ok" button (once again -- all on different dialogs) o logout o login In both situations, if a setting for PYTHONPATH already exists, just append the additional paths you want separated by a ';'. (In the first case, executing 'set PYTHONPATH ...' will override the preexisting value. This can be overcome by using 'set PYTHONPATH %PYTHONPATH%;c:\apath' to include the old value in the new value.) By setting the system's environment, you will affect all programs that don't ignore it. I suppose it's possible that PythonWin ignores the system PYTHONPATH setting, but I would consider that to be broken and should be reported as a bug. (I don't use PythonWin so I don't know what it actually does). -D From lsloan@umich.edu Mon Apr 9 17:33:14 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Mon, 09 Apr 2001 12:33:14 -0400 Subject: [Tutor] converting CGI's FieldStorage to dictionary? Message-ID: <200104091633.MAA11149@birds.us.itd.umich.edu> I'm writing a series of CGIs in Python and I'm using the standard cgi module and I've also copied DocumentTemplate out of Zope. The problem I'm running into is that DocumentTemplate uses dictionaries as arguments to hold template values, but cgi's FieldStorage is not quite a dictionary. So, this doesn't work: import cgi import DocumentTemplate form = cgi.FieldStorage() tmpl = DocumentTemplate.HTMLFile('path/to/file') print tmpl(mapping = form) How can I write a function that takes my FieldStorage form as an argument and returns a dictionary of field names to field values? I think I may have to worry about multiple values for a field (checkboxes), but if somebody could help me get on the right track, I can probably account for that. My CGIs won't be accepting files as input, so I'm glad I don't have to worry about that, too. Thanks in advance! -- Lance E Sloan - lsloan@umich.edu Univ. of Michigan, ITCS From NHYTRO@compuserve.com Mon Apr 9 17:50:03 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Mon, 9 Apr 2001 12:50:03 -0400 Subject: [Tutor] ODBC->CGI results Message-ID: <200104091250_MC2-CBCD-E9FF@compuserve.com> I am accessing an Access database with a CGI script, everything works but= for the problem that the results are in Tuple format when I "print" them = as an output to a browser client, could someone show me a better way to do this or a work around? ##### My script### #!C:/Python/python.exe -u print "Content-Type: text/html\n\n" import dbi, odbc connection =3D odbc.odbc('minicms') cur =3D connection.cursor() cur.execute('select * from benutzer') allrows =3D cur.fetchall() print '' print "" print "" print "blank" print "" print '' for dbfields in allrows: print "
", print dbfields print "
" print "" print "" ################ end code ######## and the results look like this: ('Michael',) ('johnny',) and so on... any ideas? Thank you very much for your anticipated help Sharriff Aina From glingl@aon.at Mon Apr 9 18:30:15 2001 From: glingl@aon.at (Gregor Lingl) Date: Mon, 09 Apr 2001 19:30:15 +0200 Subject: [Tutor] Primes on a two-dimensional plane in the form of arectangular spiral References: Message-ID: <3AD1F1A6.9F0A80C6@aon.at> --------------A10B7D9871003B18E15DEEBB Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Daniel Yoo wrote: ... but it's a pattern, and there might be a very cute way of writing a function that can quickly find, given a position, the nth number. I'll take a closer look at this when I have time --- this looks really interesting! Skip below if you want to listen to me ramble about discrete math while I'm working at this... *grin* (note: yes, there is a cute way. >>> def a(n): return 2*n*(1+2*n) ... >>> a(0), a(1), a(2), a(3), a(4) (0, 6, 20, 42, 72) The method for deriving this is below.) --- [Math mode on. Warning!] Hmmm... Here I propose a different derivation of this formula: [Geometry mode on. No warnings!] n n n n n n n n x x x x x n n x ... x n n x . O x n n x .. x n n A x x x x n B In this pattern A is at location ( -(n-1), -(n-1) ) an B is at location (-n, -n) There a (2*n-1)**2 points in the inner square, consuming indices from 0 to (2*n-1)**2 - 1, and 6*n points at the rim of the outer square, so (2*n-1)**2 - 1 + 6*n = 4*n**2 -4*n + 1 - 1 + 6*n = 4*n**2+2*n = 2*n*(2*n+2) as was our desire! I've continued to follow this quasi-pythagorean approach of simple counting (beginning with the index 1 for the point (0/0)) and arrived at the following code: def loc_number(M,N): if M==0 and N==0: return 1 maxabs = max(abs(M),abs(N)) innersquare = (2 * maxabs-1)**2 if M == maxabs and N > -maxabs: rest = maxabs + N elif N == maxabs: rest = 3 * maxabs - M elif M == -maxabs: rest = 5 * maxabs - N else: rest = 7 * maxabs + M return innersquare + rest # which can be accompanied by def dannies_loc_number(M,N): return loc_number(M,N) - 1 Of course I'm curious, if someone else (who has already or is off to buy a copy of Mathematica) finds a more elegant or more concise solution. Always interested in useless problems Gregor L. Here follow - for reference - Daniels complete reply to Julieta: > On Sun, 8 Apr 2001, Julieta wrote: > > > The primes, 2,3,4,5,7, . . . can be arranged on a two-dimensional > > plane in the form of a rectangular spiral. > > > <-represents left -> represents right ^represents up | represents down > > > > 59 <- 53 <- 47 <- 43 <- 41 > > ^ > > 11 <- 7 <- 5 <- 37 > > | ^ ^ > > 13 2 -> 3 31 > > | ^ > > 17 -> 19 -> 23 -> 29 > > > > How could I write a program which inputs integers M and N and outputs > > the value of the number at location (M, N) on the plane? The initial > > 2 is stored at position (0,0). This means that an input of ( 0, 0 ) > > should output 2. An input of, say, ( -1, 1) should output 11; an > > input of (-1,2) should output 53, and so on. > > Wow! This looks like a really interesting problem. The problem with the > primes doesn't seem as interesting as trying to get the cycle thing > going. The cycle problem seems rife with patterns; it'd be nice to get it > working. > > > The first problem that I'm seeing is trying to figure out a function that, > given a location, tells us which prime we're looking for. Let's see if > there are patterns... > > nth location > --- ------ > 0 (0, 0) > 1 (1, 0) > 2 (1, 1) > 3 (0, 1) > 4 (-1, 1) > 5 (-1, 0) > 6 (-1, -1) > ... > > The numbers that are catching my eye, at the moment, are the ones on the > diagonal in Quadrant three: > > nth location > --- ------ > 0 (0, 0) > 6 (-1, -1) > 20 (-2, -2) > 42 (-3, -3) > ... ... > > The reason that these numbers seem interesting to me is that if we start > taking the differences between them, there's an interesting pattern that > occurs: > > 0 6 20 42 # Position numbers on the diagonal > 6 14 22 # Difference level 1 > 8 8 # Difference level 2 > > As a prediction, I suspect that at position (-4, -4), we are trying to > print out the 72th number. I haven't testing this yet. The reason for > this guess is because there's a way to consistantly extend this pattern: > > 0 6 20 42 72 > 6 14 22 30 > 8 8 8 > > But I'd have to draw it out to manually verify this. Testing it now... > verified! Yes: the number at position (-4, -4) should be the 72th prime. > Cool, so that's one pattern we might be able to exploit here, that if we > take the difference between two diagonal positions, the gap between the > appears to expand at a rate of 8. > > This might not help, but it's a pattern, and there might be a very cute > way of writing a function that can quickly find, given a position, the nth > number. I'll take a closer look at this when I have time --- this looks > really interesting! > > Skip below if you want to listen to me ramble about discrete math while > I'm working at this... *grin* > > (note: yes, there is a cute way. > > >>> def a(n): return 2*n*(1+2*n) > ... > >>> a(0), a(1), a(2), a(3), a(4) > (0, 6, 20, 42, 72) > > The method for deriving this is below.) > > --- > > [Math mode on. Warning!] > > Hmmm... I'd like to label those three sequences I was looking at earlier: > > 0 6 20 42 72 # Let's call this sequence (a) > 6 14 22 30 # Let's call this sequence (b) > 8 8 8 # Let's call this sequence (c) > > The problem that I'd like to solve is to find a nice formula for sequence > (a) --- that would solve the problem of finding which nth prime should go > on the diagonals. Sequence (c) isn't that interesting, because it's just > all 8s. > > Let's look at sequence (b). Sequence (b) isn't that much harder, because > every time we go up the sequence, we just need to add 8 to what we had > before. This translates, in math, to: > > b(n) = 6 + 8 * n > > With this done, we might be able to handle sequence (a), which looks a > little weirder. In order to get from one part of the sequence to the > next, we need to add a corresponding element from (b). More formally: > > a(0) = 0 > a(n) = a(n-1) + b(n-1) > > Let's see if this works in Python. > > ### > >>> def b(n): return 6 + 8*n > ... > >>> def a(n): > ... if n == 0: return 0 > ... else: return a(n-1) + b(n-1) > ... > >>> a(0), a(1), a(2), a(3), a(4) > (0, 6, 20, 42, 72) > ### > > Very cool. So this is a perfectly good way of solving the problem of > finding which prime numbers should go on the diagonal. But we can go even > further, if we're perverse enough. It's also very true that: > > a(n) = a(n-1) + 8*(n-1) + 6 > = a(n-1) + 8*n - 2 > > if we substitute the value of b(n-1) into the equation. If I were to do > this by hand, I'd use a math technique called generating functions that > can take something like: > > a(0) = 0 > a(n) = a(n-1) + 8*n - 2 > > and transform it into something nicer. > > But I'm cheap and ignorant about generating functions still, so I'll use > Mathematica instead. According to Mathematica's RSolve function, > > a(n) = 2n(1+2n) > > Does this work? > > ### > >>> def a(n): return 2*n*(1+2*n) > ... > >>> a(0), a(1), a(2), a(3), a(4) > (0, 6, 20, 42, 72) > ### > > My gosh. I must learn how generating functions work, so that I can see > how in the world that worked. *grin* > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor --------------A10B7D9871003B18E15DEEBB Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit  

Daniel Yoo wrote:

... but it's a pattern, and there might be a very cute
way of writing a function that can quickly find, given a position, the nth
number.  I'll take a closer look at this when I have time --- this looks
really interesting!

Skip below if you want to listen to me ramble about discrete math while
I'm working at this...  *grin*

(note: yes, there is a cute way.

>>> def a(n): return 2*n*(1+2*n)
...
>>> a(0), a(1), a(2), a(3), a(4)
(0, 6, 20, 42, 72)

The method for deriving this is below.)

---

[Math mode on.  Warning!]

Hmmm...

Here I propose a different derivation of this formula:

[Geometry mode on. No warnings!]

      n n n n n n n
      n x x x x x n
      n x ...   x n
      n x . O   x n
      n x ..    x n
      n A x x x x n
      B

In this pattern A is at location ( -(n-1), -(n-1) )
an B is at location (-n, -n)

There a (2*n-1)**2 points in the inner square,
consuming indices from 0 to (2*n-1)**2 - 1,
and 6*n points at the rim of the outer square, so
(2*n-1)**2 - 1 + 6*n = 4*n**2 -4*n + 1 - 1 + 6*n =
4*n**2+2*n = 2*n*(2*n+2) as was our desire!

I've continued to follow this quasi-pythagorean
approach of simple counting (beginning with the
index 1 for the point (0/0)) and arrived at the
following code:
 

def loc_number(M,N):
    if M==0 and N==0:
        return 1
    maxabs = max(abs(M),abs(N))
    innersquare = (2 * maxabs-1)**2
    if M == maxabs and N > -maxabs:
        rest = maxabs + N
    elif N == maxabs:
        rest = 3 * maxabs - M
    elif M == -maxabs:
        rest = 5 * maxabs - N
    else:
        rest = 7 * maxabs + M
    return innersquare + rest

# which can be accompanied by

def dannies_loc_number(M,N):
    return loc_number(M,N) - 1

Of course I'm curious, if someone else
(who has already or is off to buy a copy
of Mathematica) finds a more elegant or
more concise solution.

Always interested in useless problems
Gregor L.
 
 

Here follow - for reference - Daniels complete reply to Julieta:

On Sun, 8 Apr 2001, Julieta wrote:

> The primes, 2,3,4,5,7, . . . can be arranged on a two-dimensional
> plane in the form of a rectangular spiral.

> <-represents left   -> represents right    ^represents up     | represents down
>
> 59 <-  53 <-  47  <-  43    <-    41
>                                              ^
>         11 <-   7    <-   5   <-     37
>           |                    ^            ^
>         13        2   ->   3           31
>           |                                 ^
>         17  ->  19  ->  23   ->    29
>
> How could I write a program which inputs integers M and N and outputs
> the value of the number at location (M, N) on the plane?  The initial
> 2 is stored at position (0,0).  This means that an input of ( 0, 0 )
> should output 2.  An input of, say, ( -1, 1) should output 11; an
> input of (-1,2) should output 53, and so on.

Wow!  This looks like a really interesting problem.  The problem with the
primes doesn't seem as interesting as trying to get the cycle thing
going.  The cycle problem seems rife with patterns; it'd be nice to get it
working.
 

The first problem that I'm seeing is trying to figure out a function that,
given a location, tells us which prime we're looking for.  Let's see if
there are patterns...

nth  location
---  ------
0    (0, 0)
1    (1, 0)
2    (1, 1)
3    (0, 1)
4    (-1, 1)
5    (-1, 0)
6    (-1, -1)
...

The numbers that are catching my eye, at the moment, are the ones on the
diagonal in Quadrant three:

nth  location
---  ------
0    (0, 0)
6    (-1, -1)
20   (-2, -2)
42   (-3, -3)
...  ...

The reason that these numbers seem interesting to me is that if we start
taking the differences between them, there's an interesting pattern that
occurs:

0   6      20    42            # Position numbers on the diagonal
  6    14     22               # Difference level 1
    8      8                   # Difference level 2

As a prediction, I suspect that at position (-4, -4), we are trying to
print out the 72th number.  I haven't testing this yet.  The reason for
this guess is because there's a way to consistantly extend this pattern:

0   6    20    42    72
  6   14    22    30
    8    8     8

But I'd have to draw it out to manually verify this.  Testing it now...
verified!  Yes: the number at position (-4, -4) should be the 72th prime.
Cool, so that's one pattern we might be able to exploit here, that if we
take the difference between two diagonal positions, the gap between the
appears to expand at a rate of 8.

This might not help, but it's a pattern, and there might be a very cute
way of writing a function that can quickly find, given a position, the nth
number.  I'll take a closer look at this when I have time --- this looks
really interesting!

Skip below if you want to listen to me ramble about discrete math while
I'm working at this...  *grin*

(note: yes, there is a cute way.

>>> def a(n): return 2*n*(1+2*n)
...
>>> a(0), a(1), a(2), a(3), a(4)
(0, 6, 20, 42, 72)

The method for deriving this is below.)

---

[Math mode on.  Warning!]

Hmmm...  I'd like to label those three sequences I was looking at earlier:

0   6    20    42    72           # Let's call this sequence (a)
  6   14    22    30              # Let's call this sequence (b)
    8    8     8                  # Let's call this sequence (c)

The problem that I'd like to solve is to find a nice formula for sequence
(a) --- that would solve the problem of finding which nth prime should go
on the diagonals.  Sequence (c) isn't that interesting, because it's just
all 8s.

Let's look at sequence (b).  Sequence (b) isn't that much harder, because
every time we go up the sequence, we just need to add 8 to what we had
before.  This translates, in math, to:

    b(n) = 6 + 8 * n

With this done, we might be able to handle sequence (a), which looks a
little weirder.  In order to get from one part of the sequence to the
next, we need to add a corresponding element from (b).  More formally:

    a(0) = 0
    a(n) = a(n-1) + b(n-1)

Let's see if this works in Python.

###
>>> def b(n): return 6 + 8*n
...
>>> def a(n):
...     if n == 0: return 0
...     else: return a(n-1) + b(n-1)
...
>>> a(0), a(1), a(2), a(3), a(4)
(0, 6, 20, 42, 72)
###

Very cool.  So this is a perfectly good way of solving the problem of
finding which prime numbers should go on the diagonal.  But we can go even
further, if we're perverse enough.  It's also very true that:

    a(n) = a(n-1) + 8*(n-1) + 6
         = a(n-1) + 8*n - 2

if we substitute the value of b(n-1) into the equation.  If I were to do
this by hand, I'd use a math technique called generating functions that
can take something like:

    a(0) = 0
    a(n) = a(n-1) + 8*n - 2

and transform it into something nicer.

But I'm cheap and ignorant about generating functions still, so I'll use
Mathematica instead.  According to Mathematica's RSolve function,

    a(n) = 2n(1+2n)

Does this work?

###
>>> def a(n): return 2*n*(1+2*n)
...
>>> a(0), a(1), a(2), a(3), a(4)
(0, 6, 20, 42, 72)
###

My gosh.  I must learn how generating functions work, so that I can see
how in the world that worked.  *grin*

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

--------------A10B7D9871003B18E15DEEBB-- From mbc2@netdoor.com Mon Apr 9 18:50:38 2001 From: mbc2@netdoor.com (Brad Chandler) Date: Mon, 9 Apr 2001 12:50:38 -0500 Subject: [Tutor] ODBC->CGI results References: <200104091250_MC2-CBCD-E9FF@compuserve.com> Message-ID: <001201c0c11d$96e6e2e0$111c0d0a@spb.state.ms.us> When you loop through your result, allrows, each row is returned as a tuple. What you want is the first element (in this case, the only element) of that tuple. Which is dbfields[0]. Try 'print dbfields[0]'. Brad ----- Original Message ----- From: "Sharriff Aina" To: Sent: Monday, April 09, 2001 11:50 AM Subject: [Tutor] ODBC->CGI results I am accessing an Access database with a CGI script, everything works but for the problem that the results are in Tuple format when I "print" them as an output to a browser client, could someone show me a better way to do this or a work around? ##### My script### #!C:/Python/python.exe -u print "Content-Type: text/html\n\n" import dbi, odbc connection = odbc.odbc('minicms') cur = connection.cursor() cur.execute('select * from benutzer') allrows = cur.fetchall() print '' print "" print "" print "blank" print "" print '' for dbfields in allrows: print "
", print dbfields print "
" print "" print "" ################ end code ######## and the results look like this: ('Michael',) ('johnny',) and so on... any ideas? Thank you very much for your anticipated help Sharriff Aina _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From syrinx@simplecom.net Mon Apr 9 16:57:55 2001 From: syrinx@simplecom.net (Scott) Date: Mon, 09 Apr 2001 10:57:55 -0500 Subject: [Tutor] for each dictionary key... Message-ID: This post wasn't meant for public consumption. :) I was just trying to put my problem into words, when I had company. I meant to save this message for later, but managed to send it instead. I don't remember where I was really going with it either. Sorry. >I've been doing this: > > keys =3D self.someclass.keys() > for key in keys: > ( do something ) > >What's the shorter way? From rick@niof.net Mon Apr 9 21:34:52 2001 From: rick@niof.net (Rick Pasotto) Date: Mon, 9 Apr 2001 16:34:52 -0400 Subject: [Tutor] user defined compare for sorting Message-ID: <20010409163452.D554@tc.niof.net> I have a list of dictionaries. How can I specify at runtime the key to use for sorting the list? lst[ [ 'A':'a', 'B':'2', 'C':'z' ] [ 'A':'b', 'B':'3', 'C':'x' ] [ 'A':'c', 'B':'1', 'C':'y' ] ] How can I pass 'A', 'B', or 'C' to 'key' in the compare function? def mycmp(a,b): cmp(a[key],b[key]) -- "Capitalism is a social system based on the recognition of individual rights, including property rights, in which all property is privately owned." -- Ayn Rand Rick Pasotto email: rickp@telocity.com From dyoo@hkn.eecs.berkeley.edu Mon Apr 9 21:56:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 9 Apr 2001 13:56:16 -0700 (PDT) Subject: [Tutor] Primes on a two-dimensional plane in the form of arectangular spiral In-Reply-To: <3AD1F1A6.9F0A80C6@aon.at> Message-ID: Here's one more experiment after I played around with the spiraling function. Take a look! ### >>> def a(n): return 2 * n * (1+2*n) ... >>> def getNum(x, y): ... if abs(x) <= abs(y): return a(-y) + abs(y-x) ... else: return a(-x) - abs(y-x) ... >>> for y in range(5, -5, -1): ... for x in range(-5, 5): ... print "%5d" % getNum(x, y), ... print ... 100 99 98 97 96 95 94 93 92 91 101 64 63 62 61 60 59 58 57 56 102 65 36 35 34 33 32 31 30 55 103 66 37 16 15 14 13 12 29 54 104 67 38 17 4 3 2 11 28 53 105 68 39 18 5 0 1 10 27 52 106 69 40 19 6 7 8 9 26 51 107 70 41 20 21 22 23 24 25 50 108 71 42 43 44 45 46 47 48 49 109 72 73 74 75 76 77 78 79 80 ### There is a Mathgod, after all. *grin* Actually, I finally did the generating function way of deriving the function a(n). If anyone's interested, I'll be glad to post a .pdf to the math. Ok, this was overkill, but I had fun doing it. From glingl@aon.at Mon Apr 9 23:04:56 2001 From: glingl@aon.at (Gregor Lingl) Date: Tue, 10 Apr 2001 00:04:56 +0200 Subject: [Tutor] Primes on a two-dimensional plane in the form of arectangular spiral References: Message-ID: <3AD23208.48F3E4E3@aon.at> Dies ist eine mehrteilige Nachricht im MIME-Format. --------------5EA0C941FE15032E318423AD Content-Type: multipart/alternative; boundary="------------B18CC9CDB79AB7DAD05C9D6F" --------------B18CC9CDB79AB7DAD05C9D6F Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Very well done! After all, we can have a script with 20 lines of code, as Julieta wanted: def a(n): return 2 * n * (1+2*n) def getNum(x, y): if abs(x) <= abs(y): return a(-y) + abs(y-x) else: return a(-x) - abs(y-x) def primes(n): primes = [2] i = 3 while len(primes) < n: for p in primes: if i%p == 0 or p*p > i: break if i%p <> 0: primes.append(i) i = i+2 return primes primelist = primes(11*11) for y in range(5, -5, -1): for x in range(-5, 5): print "%5d" % primelist[getNum(x, y)], print which ouputs: 547 541 523 521 509 503 499 491 487 479 557 313 311 307 293 283 281 277 271 269 563 317 157 151 149 139 137 131 127 263 569 331 163 59 53 47 43 41 113 257 571 337 167 61 11 7 5 37 109 251 577 347 173 67 13 2 3 31 107 241 587 349 179 71 17 19 23 29 103 239 593 353 181 73 79 83 89 97 101 233 599 359 191 193 197 199 211 223 227 229 601 367 373 379 383 389 397 401 409 419 Thanks for your ideas Gregor L. P.S.: concerning the math: post it! Daniel Yoo schrieb: > Here's one more experiment after I played around with the spiraling > function. Take a look! > > ### > >>> def a(n): return 2 * n * (1+2*n) > ... > >>> def getNum(x, y): > ... if abs(x) <= abs(y): return a(-y) + abs(y-x) > ... else: return a(-x) - abs(y-x) > ... > >>> for y in range(5, -5, -1): > ... for x in range(-5, 5): > ... print "%5d" % getNum(x, y), > ... print > ... > 100 99 98 97 96 95 94 93 92 91 > 101 64 63 62 61 60 59 58 57 56 > 102 65 36 35 34 33 32 31 30 55 > 103 66 37 16 15 14 13 12 29 54 > 104 67 38 17 4 3 2 11 28 53 > 105 68 39 18 5 0 1 10 27 52 > 106 69 40 19 6 7 8 9 26 51 > 107 70 41 20 21 22 23 24 25 50 > 108 71 42 43 44 45 46 47 48 49 > 109 72 73 74 75 76 77 78 79 80 > ### > > There is a Mathgod, after all. *grin* > > Actually, I finally did the generating function way of deriving the > function a(n). If anyone's interested, I'll be glad to post a .pdf to the > math. > > Ok, this was overkill, but I had fun doing it. --------------B18CC9CDB79AB7DAD05C9D6F Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Very well done!
After all, we can have a script with 20 lines of code,
as Julieta wanted:

def a(n):
    return 2 * n * (1+2*n)

def getNum(x, y):
    if abs(x) <= abs(y): return a(-y) + abs(y-x)
    else: return a(-x) - abs(y-x)
 
def primes(n):
    primes = [2]
    i = 3
    while len(primes) < n:
        for p in primes:
            if i%p == 0 or p*p > i: break
        if i%p <> 0:
            primes.append(i)
        i = i+2
    return primes

primelist = primes(11*11)
for y in range(5, -5, -1):
    for x in range(-5, 5):
        print "%5d" % primelist[getNum(x, y)],
    print

which ouputs:

  547   541   523   521   509   503   499   491   487   479
  557   313   311   307   293   283   281   277   271   269
  563   317   157   151   149   139   137   131   127   263
  569   331   163    59    53    47    43    41   113   257
  571   337   167    61    11     7     5    37   109   251
  577   347   173    67    13     2     3    31   107   241
  587   349   179    71    17    19    23    29   103   239
  593   353   181    73    79    83    89    97   101   233
  599   359   191   193   197   199   211   223   227   229
  601   367   373   379   383   389   397   401   409   419

Thanks for your ideas

Gregor L.

P.S.: concerning the math: post it!

Daniel Yoo schrieb:

Here's one more experiment after I played around with the spiraling
function.  Take a look!

###
>>> def a(n): return 2 * n * (1+2*n)
...
>>> def getNum(x, y):
...     if abs(x) <= abs(y): return a(-y) + abs(y-x)
...     else: return a(-x) - abs(y-x)
...
>>> for y in range(5, -5, -1):
...     for x in range(-5, 5):
...         print "%5d" % getNum(x, y),
...     print
...
  100    99    98    97    96    95    94    93    92    91
  101    64    63    62    61    60    59    58    57    56
  102    65    36    35    34    33    32    31    30    55
  103    66    37    16    15    14    13    12    29    54
  104    67    38    17     4     3     2    11    28    53
  105    68    39    18     5     0     1    10    27    52
  106    69    40    19     6     7     8     9    26    51
  107    70    41    20    21    22    23    24    25    50
  108    71    42    43    44    45    46    47    48    49
  109    72    73    74    75    76    77    78    79    80
###

There is a Mathgod, after all.  *grin*

Actually, I finally did the generating function way of deriving the
function a(n).  If anyone's interested, I'll be glad to post a .pdf to the
math.

Ok, this was overkill, but I had fun doing it.

--------------B18CC9CDB79AB7DAD05C9D6F-- --------------5EA0C941FE15032E318423AD Content-Type: text/plain; charset=us-ascii; name="primespiral.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="primespiral.py" def a(n): return 2 * n * (1+2*n) def getNum(x, y): if abs(x) <= abs(y): return a(-y) + abs(y-x) else: return a(-x) - abs(y-x) def primes(n): primes = [2] i = 3 while len(primes) < n: for p in primes: if i%p == 0 or p*p > i: break if i%p <> 0: primes.append(i) i = i+2 return primes primelist = primes(11*11) for y in range(5, -5, -1): for x in range(-5, 5): print "%5d" % primelist[getNum(x, y)], print --------------5EA0C941FE15032E318423AD-- From glingl@aon.at Mon Apr 9 23:16:03 2001 From: glingl@aon.at (Gregor Lingl) Date: Tue, 10 Apr 2001 00:16:03 +0200 Subject: [Tutor] or better ... References: Message-ID: <3AD234A2.815FB56A@aon.at> --------------BEA9CD40CEA971B83AF0BCEF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Very well done! After all, we can have a script with 20 lines of code, as Julieta wanted: def a(n): return 2 * n * (1+2*n) def getNum(x, y): if abs(x) <= abs(y): return a(-y) + abs(y-x) else: return a(-x) - abs(y-x) def primes(n): primes = [2] i = 3 while len(primes) < n: for p in primes: if i%p == 0 or p*p > i: break if i%p <> 0: primes.append(i) i = i+2 return primes primelist = primes(11*11) for y in range(5, -6, -1): for x in range(-5, 6): print "%5d" % primelist[getNum(x, y)], print which ouputs all the first 121 primes: (Note the changes in the ranges above, sorry) 547 541 523 521 509 503 499 491 487 479 467 557 313 311 307 293 283 281 277 271 269 463 563 317 157 151 149 139 137 131 127 263 461 569 331 163 59 53 47 43 41 113 257 457 571 337 167 61 11 7 5 37 109 251 449 577 347 173 67 13 2 3 31 107 241 443 587 349 179 71 17 19 23 29 103 239 439 593 353 181 73 79 83 89 97 101 233 433 599 359 191 193 197 199 211 223 227 229 431 601 367 373 379 383 389 397 401 409 419 421 607 613 617 619 631 641 643 647 653 659 661 Daniel Yoo schrieb: > Here's one more experiment after I played around with the spiraling > function. Take a look! > > ### > >>> def a(n): return 2 * n * (1+2*n) > ... > >>> def getNum(x, y): > ... if abs(x) <= abs(y): return a(-y) + abs(y-x) > ... else: return a(-x) - abs(y-x) > ... > >>> for y in range(5, -5, -1): > ... for x in range(-5, 5): > ... print "%5d" % getNum(x, y), > ... print > ... > 100 99 98 97 96 95 94 93 92 91 > 101 64 63 62 61 60 59 58 57 56 > 102 65 36 35 34 33 32 31 30 55 > 103 66 37 16 15 14 13 12 29 54 > 104 67 38 17 4 3 2 11 28 53 > 105 68 39 18 5 0 1 10 27 52 > 106 69 40 19 6 7 8 9 26 51 > 107 70 41 20 21 22 23 24 25 50 > 108 71 42 43 44 45 46 47 48 49 > 109 72 73 74 75 76 77 78 79 80 > ### > > There is a Mathgod, after all. *grin* > > Actually, I finally did the generating function way of deriving the > function a(n). If anyone's interested, I'll be glad to post a .pdf to the > math. > > Ok, this was overkill, but I had fun doing it. --------------BEA9CD40CEA971B83AF0BCEF Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Very well done!
After all, we can have a script with 20 lines of code,
as Julieta wanted:

def a(n):
    return 2 * n * (1+2*n)

def getNum(x, y):
    if abs(x) <= abs(y): return a(-y) + abs(y-x)
    else: return a(-x) - abs(y-x)
 
def primes(n):
    primes = [2]
    i = 3
    while len(primes) < n:
        for p in primes:
            if i%p == 0 or p*p > i: break
        if i%p <> 0:
            primes.append(i)
        i = i+2
    return primes

primelist = primes(11*11)
for y in range(5, -6, -1):
    for x in range(-5, 6):
        print "%5d" % primelist[getNum(x, y)],
    print

which ouputs all the first 121 primes: (Note the changes in the ranges above, sorry)

  547   541   523   521   509   503   499   491   487   479   467
  557   313   311   307   293   283   281   277   271   269   463
  563   317   157   151   149   139   137   131   127   263   461
  569   331   163    59    53    47    43    41   113   257   457
  571   337   167    61    11     7     5    37   109   251   449
  577   347   173    67    13     2     3    31   107   241   443
  587   349   179    71    17    19    23    29   103   239   439
  593   353   181    73    79    83    89    97   101   233   433
  599   359   191   193   197   199   211   223   227   229   431
  601   367   373   379   383   389   397   401   409   419   421
  607   613   617   619   631   641   643   647   653   659   661
 

Daniel Yoo schrieb:

Here's one more experiment after I played around with the spiraling
function.  Take a look!

###
>>> def a(n): return 2 * n * (1+2*n)
...
>>> def getNum(x, y):
...     if abs(x) <= abs(y): return a(-y) + abs(y-x)
...     else: return a(-x) - abs(y-x)
...
>>> for y in range(5, -5, -1):
...     for x in range(-5, 5):
...         print "%5d" % getNum(x, y),
...     print
...
  100    99    98    97    96    95    94    93    92    91
  101    64    63    62    61    60    59    58    57    56
  102    65    36    35    34    33    32    31    30    55
  103    66    37    16    15    14    13    12    29    54
  104    67    38    17     4     3     2    11    28    53
  105    68    39    18     5     0     1    10    27    52
  106    69    40    19     6     7     8     9    26    51
  107    70    41    20    21    22    23    24    25    50
  108    71    42    43    44    45    46    47    48    49
  109    72    73    74    75    76    77    78    79    80
###

There is a Mathgod, after all.  *grin*

Actually, I finally did the generating function way of deriving the
function a(n).  If anyone's interested, I'll be glad to post a .pdf to the
math.

Ok, this was overkill, but I had fun doing it.

--------------BEA9CD40CEA971B83AF0BCEF-- From scarblac@pino.selwerd.nl Mon Apr 9 23:49:57 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 10 Apr 2001 00:49:57 +0200 Subject: [Tutor] user defined compare for sorting In-Reply-To: <20010409163452.D554@tc.niof.net>; from rick@niof.net on Mon, Apr 09, 2001 at 04:34:52PM -0400 References: <20010409163452.D554@tc.niof.net> Message-ID: <20010410004957.A1185@pino.selwerd.nl> On 0, Rick Pasotto wrote: > I have a list of dictionaries. How can I specify at runtime the key to > use for sorting the list? > > lst[ [ 'A':'a', 'B':'2', 'C':'z' ] > [ 'A':'b', 'B':'3', 'C':'x' ] > [ 'A':'c', 'B':'1', 'C':'y' ] ] > > How can I pass 'A', 'B', or 'C' to 'key' in the compare function? > > def mycmp(a,b): cmp(a[key],b[key]) (The above isn't correct, I assume you meant { curly braces } around the dicts, and the mycmp needs a "return"). I understand you want to be able to sort the list on different keys. Make a function that returns a function that sorts on some key: def make_sort_function(key): def sort_func(a, b, key=key): return cmp(a[key], b[key]) return sort_func cmp_func works as we want it to work because it gets key as a default argument. Now you can do, say, lst.sort(make_sort_function('A')) 'lambda' is a way to make functions on the fly. The same thing could like like this: lst.sort(lambda a,b,key='A': cmp(a[key],b[key])) It's up to you to choose the one you find easier to understand. If you don't understand how this works, play around with make_sort_function in the interpreter... -- Remco Gerlich From dsh8290@rit.edu Mon Apr 9 23:53:21 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 9 Apr 2001 18:53:21 -0400 Subject: [Tutor] user defined compare for sorting In-Reply-To: <20010409163452.D554@tc.niof.net>; from rick@niof.net on Mon, Apr 09, 2001 at 04:34:52PM -0400 References: <20010409163452.D554@tc.niof.net> Message-ID: <20010409185321.A26585@harmony.cs.rit.edu> On Mon, Apr 09, 2001 at 04:34:52PM -0400, Rick Pasotto wrote: | I have a list of dictionaries. How can I specify at runtime the key to | use for sorting the list? | | lst[ [ 'A':'a', 'B':'2', 'C':'z' ] | [ 'A':'b', 'B':'3', 'C':'x' ] | [ 'A':'c', 'B':'1', 'C':'y' ] ] minor correction : lst = [ { 'A':'a', 'B':'2', 'C':'z' } , { 'A':'b', 'B':'3', 'C':'x' } , { 'A':'c', 'B':'1', 'C':'y' } ] | How can I pass 'A', 'B', or 'C' to 'key' in the compare function? | | def mycmp(a,b): cmp(a[key],b[key]) Perhaps something like this would help : def make_cmp( key ) : return lambda a , b , key=key : cmp( a[key] , b[key] ) this_key = 'B' # figure out the key to use lst.sort( make_cmp( this_key ) ) The function make_cmp returns a comparison function that uses the particular key you specify as its argument. >>> def make_cmp( key ) : return lambda a , b, key=key : cmp( a[key] , b[key] ) ... >>> lst = [ { 'A':'a', 'B':'2', 'C':'z' } ,{ 'A':'b', 'B':'3', 'C':'x' } , { 'A':'c', 'B':'1', 'C':'y' } ] >>> lst [{'B': '2', 'C': 'z', 'A': 'a'}, {'B': '3', 'C': 'x', 'A': 'b'}, {'B': '1', 'C': 'y', 'A': 'c'}] >>> f = make_cmp( 'B' ) >>> print f at 007A843C> >>> lst.sort( f ) >>> print lst [{'B': '1', 'C': 'y', 'A': 'c'}, {'B': '2', 'C': 'z', 'A': 'a'}, {'B': '3', 'C': 'x', 'A': 'b'}] >>> Now try and do that as quickly in Java! (on second thought, don't hurt yourself ) (sorry, I am a little annoyed with java right now) -D From vlindberg@verio.net Tue Apr 10 00:11:26 2001 From: vlindberg@verio.net (VanL) Date: Mon, 09 Apr 2001 17:11:26 -0600 Subject: [Tutor] pyopengl name error Message-ID: <3AD2419E.BB5FBB1E@verio.net> Hello, If this is too pyopengl-specific, I'll take this question there. However, it seems to actually be a problem with namespaces, so I decided to try this group first. I installed pyOpenGL. I can import it, get a listing of available functions from dir(), etc. However, When I try to run the example code drawcube.py, I get the following error: Traceback (most recent call last): File "glut.py", line 69, in OnDraw drawCube() File "drawcube.py", line 3, in drawCube OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); NameError: There is no variable named 'OpenGL' Traceback (most recent call last): File "glut.py", line 69, in OnDraw drawCube() File "drawcube.py", line 3, in drawCube OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); NameError: There is no variable named 'OpenGL' Traceback (most recent call last): File "glut.py", line 69, in OnDraw drawCube() File "drawcube.py", line 3, in drawCube OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); NameError: There is no variable named 'OpenGL' Here is the code throwing the exception: '''GLUT rendering context sample ''' from OpenGL.GL import * from OpenGL.GLUT import * from drawcube import drawCube class GLUTContext: def __init__ ( self, title= "GLUT Render Context", size = (300,300), mode = GLUT_DOUBLE | GLUT_RGB ): ### Context parameter setup glutInitDisplayMode( mode ) ### Instantiation # Note: GLUT does this strangely, # most windowing libraries wrap the size # of the context into the creation call... apply ( glutInitWindowSize, size) # create a new rendering window self.windowID = glutCreateWindow( title ) ### Callback setup # so GLUT knows the target window glutSetWindow( self.windowID ) glutSetReshapeFuncCallback(self.OnResize) glutReshapeFunc() glutSetDisplayFuncCallback(self.OnDraw) glutDisplayFunc() def OnResize(self, width, height): ### Size callback glutSetWindow( self.windowID ) glViewport(0, 0, width, height) def OnDraw(self, *arguments): ### Draw callback ### Capture rendering context glutSetWindow( self.windowID ) ### Create projection matrix glMatrixMode(GL_PROJECTION); # load the identity matrix (reset the view) glLoadIdentity() # calculate a 3D perspective view glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0); ### Setup model view matrix # move the object-creation matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity() ### Setup global rendering "environment" # Enable occlusion testing for the depth buffer glEnable(GL_DEPTH_TEST); # Enable lighting calculations glEnable(GL_LIGHTING); # Enable the default light zero (shining forward on the y axis) glEnable(GL_LIGHT0); # Setup buffers # blank the background to a single colour, # also clear the depth-buffer to all 0 glClearColor(1.0,1.0,1.0,1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ### Render drawCube() ### Swap buffers glutSwapBuffers() if __name__ == "__main__": # initialize GLUT windowing system glutInit('foo') context = GLUTContext( ) glutMainLoop() Any help? Thanks, Van From dsh8290@rit.edu Tue Apr 10 00:13:05 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 9 Apr 2001 19:13:05 -0400 Subject: [Tutor] pyopengl name error In-Reply-To: <3AD2419E.BB5FBB1E@verio.net>; from vlindberg@verio.net on Mon, Apr 09, 2001 at 05:11:26PM -0600 References: <3AD2419E.BB5FBB1E@verio.net> Message-ID: <20010409191305.A26683@harmony.cs.rit.edu> On Mon, Apr 09, 2001 at 05:11:26PM -0600, VanL wrote: | | Traceback (most recent call last): | File "glut.py", line 69, in OnDraw | drawCube() | File "drawcube.py", line 3, in drawCube | OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is the line of code causing the exception. This line doesn't occur anywhere in the code you posted. Can you post the first few lines of 'drawcube.py' instead? Something to note : I noticed that the package name uses mixed case. On Windows systems the filesystem is case-insensitive so sometimes there are problems relating to the case not matching. Also, BTW, even though semicolons are allowed for line termination, it isn't exactly encouraged. (not a big deal, though) -D From jsc@rock-tnsc.com Wed Apr 11 01:34:02 2001 From: jsc@rock-tnsc.com (Jethro Cramp) Date: Tue, 10 Apr 2001 16:34:02 -0800 Subject: [Tutor] Problem Moving Python Program From WIndows to Linux Message-ID: <3AD3A67A.5090208@rock-tnsc.com> I have hit upon a thorny little problem. I had started building a program on Windows ME and then I moved over to Linux and want to keep working on it. I have hit a number of problems where my python files won't run on Linux. On Windows there is no problem. On both systems I am using Python 2.0. My Linux system is SuSE7.1 The problem is to do with reading files and then splitting the fields. So I have a text file of the following format: Imperial Black =3.01 Mountain White =2.7 Canton Green =2.8 etc.etc These are names of different types of stone and their mass in MT. The format is a couple of tabs for legibility "=" then The code I use is like this: def Get_Materials_List(): materialsfile = open(rkpaths.material_specs, "r") materials = {} for material in materialsfile.readlines(): #Ignores blank lines, comments, and currency demarcation if not material=="\n" and not material[:1] == "#" and not material[:1] =="[": #Get the material name and the mass stripping white spaces print material mat, mass = map(string.strip, string.split(material, "=")) materials[string.upper(mat)] = (mat,mass) The error I get when I run this code is: Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.0/rk/rkcalc.py", line 172, in Get_Materials_List mat, mass = map(string.strip, string.split(material, "=")) ValueError: unpack list of wrong size Are the tab stops being treated differently in Linux from Windows? Also when I open a file in idle that I wrote under windows there is a "\r" at the end of each line. Is this some kind of windows specific end of line character. If I read the file manually like so: >>> file = open(rkpaths.material_specs, "r") >>> x = file.readlines() for entry in x: print entry # This file contains a list of materials and their mass in MT/m3\r \r Imperial Black = 3.01\r Chinese Tarn = 2.7\r Mongolian Red = 2.7\r Mountain White = 2.7\r Dragon Beige = 2.7\r etc.etc. Then I try: >>> for entry in x: x,y = string.split(entry,"=") Traceback (innermost last): File "", line 2, in ? x,y = string.split(entry,"=") ValueError: unpack list of wrong size Notice all the '\r' entries. Anyone know what's going on and what I have to do. Do I have to convert all my scripts using dos2unix? TIA, Jethro From NHYTRO@compuserve.com Tue Apr 10 10:11:31 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Tue, 10 Apr 2001 05:11:31 -0400 Subject: [Tutor] CGI, HTML checkbox extraction Message-ID: <200104100511_MC2-CBD8-8257@compuserve.com> Message text written by INTERNET:tutor@python.org >< Hi! Could someone show me how to extract data per CGI from Checkboxes and Radiobuttons I=B4ve done a search on "Pythonlist", the python homepage and "Pythontut= or" and came up with nothing,. Thanks for your anticipated help. Sharriff From dyoo@hkn.eecs.berkeley.edu Tue Apr 10 10:39:55 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 10 Apr 2001 02:39:55 -0700 (PDT) Subject: [Tutor] Problem Moving Python Program From WIndows to Linux In-Reply-To: <3AD3A67A.5090208@rock-tnsc.com> Message-ID: On Tue, 10 Apr 2001, Jethro Cramp wrote: > The error I get when I run this code is: > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.0/rk/rkcalc.py", line 172, in Get_Materials_List > mat, mass = map(string.strip, string.split(material, "=")) > ValueError: unpack list of wrong size > > Are the tab stops being treated differently in Linux from Windows? > Also when I open a file in idle that I wrote under windows there is a > "\r" at the end of each line. Is this some kind of windows specific end > of line character. About the tab stops: not that I can tell. However, you're right about the "\r" stuff: it's the carriage return character that Windows/DOS systems use in conjunction with "\n". > >>> file = open(rkpaths.material_specs, "r") > >>> x = file.readlines() > for entry in x: > print entry > > # This file contains a list of materials and their mass in MT/m3\r > > \r Ah, here's something. If your first line contains a '\r', it's still a line, so the command x,y = string.split(entry,"=") will try doing the string split across this line --- that's what's causing the problem when we tuple-unpack later on. Same sort of thing happens if there are blank lines in your file. One way to fix this is to tell your loop to "skip over" blank lines: ### for entry in x: if string.strip(entry) == "": continue # ... the rest is the same ### "continue" will tell Python to skip this element, and consider the next element in x. For example: ### >>> for x in range(10): ... if x % 2 == 0: continue ... print x ... 1 3 5 7 9 ### Another, more robust way to fix this problem is to use exception handling. Can someone give a good explanation about this? > Notice all the '\r' entries. Use string.strip() to get rid of that trailing whitespace stuff. strip() will help you clean up a string from both the left and right side. It's probably better to do it after unpacking the tuple, just to get rid of all that whitespace at once. Hope this helps! From jsc@rock-tnsc.com Wed Apr 11 03:15:44 2001 From: jsc@rock-tnsc.com (Jethro Cramp) Date: Tue, 10 Apr 2001 18:15:44 -0800 Subject: [Tutor] Problem Moving Python Program From WIndows to Linux References: Message-ID: <3AD3BE50.6020905@rock-tnsc.com> Dear Daniel, Thanks alot for the suggestions. Given me several ideas and introduced me to the "continue" function. Can you recommend any utilities to strip "\r" from files. I tried doing search and replace in idle but that failed. Also if I do strip all the "\r" will that render the scripts inoperable under windows? Jethro From kalle@gnupung.net Tue Apr 10 11:59:56 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 10 Apr 2001 12:59:56 +0200 Subject: [Tutor] Problem Moving Python Program From WIndows to Linux In-Reply-To: <3AD3BE50.6020905@rock-tnsc.com>; from jsc@rock-tnsc.com on Tue, Apr 10, 2001 at 06:15:44PM -0800 References: <3AD3BE50.6020905@rock-tnsc.com> Message-ID: <20010410125955.A30323@father> Sez Jethro Cramp: > Can you recommend any utilities to strip "\r" from files. I tried doing > search and replace in idle but that failed. s = open("afile").read() s = s.replace("\r", "") open("afile", "w").write(s) Will remove all "\r"s from "afile". > Also if I do strip all the "\r" will that render the scripts inoperable > under windows? I don't think so, but haven't tested. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From moshez@zadka.site.co.il Tue Apr 10 12:04:31 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Tue, 10 Apr 2001 14:04:31 +0300 Subject: [Tutor] Message persistence In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D6CF@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20751D6CF@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Mon, 9 Apr 2001 11:35:59 +0100, alan.gauld@bt.com wrote: > Same as any other kind of persistence: > > 1) Store in memory - valid for life of process > 2) Store in flat files - fine oif not too many > - maybe OK if a file per thread? > 3) pickle/shelve - save the thread object as above > but less work :-) > 4) Use a database - best if any real volumes involved. > Pick any database that runs on your platform and > has a Python data driver module Alan was a bit vague re 4), one important option is ZODB, which now has a project all to itself, without Zope. www.amk.ca links to it. Which of course brings up the question, why not use Zope? -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org From moshez@zadka.site.co.il Tue Apr 10 12:08:01 2001 From: moshez@zadka.site.co.il (Moshe Zadka) Date: Tue, 10 Apr 2001 14:08:01 +0300 Subject: [Tutor] Primes on a two-dimensional plane in the form of a rectangular spiral In-Reply-To: <14CE6196C60@kserver.org> References: <14CE6196C60@kserver.org>, <3AD15BCB.CB1E1B5E@aon.at> Message-ID: On Sun, 08 Apr 2001, Sheila King wrote: > However, this algorithm requires that you start from the number "two" and work > your way on up. I don't believe there is any way to start at an arbitrary > prime number and find the next prime without knowing the preceding primes. So, > you'd have to implement the Sieve of Erasthones in any case, even though you > were only interested in finding a single number. > > I'm always willing to find out I'm wrong, if someone else knows better... Dead wrong! The quicket algorithm would be to use Rabin's Criterion for primality, starting at p, and moving up. It is guranteed to stop before 2*p. -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org From rick@niof.net Tue Apr 10 14:13:41 2001 From: rick@niof.net (Rick Pasotto) Date: Tue, 10 Apr 2001 09:13:41 -0400 Subject: [Tutor] pyopengl name error In-Reply-To: <3AD2419E.BB5FBB1E@verio.net>; from vlindberg@verio.net on Mon, Apr 09, 2001 at 05:11:26PM -0600 References: <3AD2419E.BB5FBB1E@verio.net> Message-ID: <20010410091341.E554@tc.niof.net> On Mon, Apr 09, 2001 at 05:11:26PM -0600, VanL wrote: > Hello, > > If this is too pyopengl-specific, I'll take this question there. > However, it seems to actually be a problem with namespaces, so I decided > to try this group first. > > I installed pyOpenGL. I can import it, get a listing of available > functions from dir(), etc. However, When I try to run the example code > drawcube.py, I get the following error: > > Traceback (most recent call last): > File "glut.py", line 69, in OnDraw > drawCube() > File "drawcube.py", line 3, in drawCube > OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); > NameError: There is no variable named 'OpenGL' > Traceback (most recent call last): > File "glut.py", line 69, in OnDraw > drawCube() > File "drawcube.py", line 3, in drawCube > OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); > NameError: There is no variable named 'OpenGL' > Traceback (most recent call last): > File "glut.py", line 69, in OnDraw > drawCube() > File "drawcube.py", line 3, in drawCube > OpenGL.GL.glTranslatef(0.0, 0.0, -2.0); > NameError: There is no variable named 'OpenGL' > > > Here is the code throwing the exception: > > > '''GLUT rendering context sample > ''' > from OpenGL.GL import * > from OpenGL.GLUT import * You haven't imported OpenGL. Instead you have imported some of the *contents* of OpenGL. Change your line to glTranslatef(0.0, 0.0, -2.0) and I suspect it will work. -- "Being an elected Libertarian is like being a designated driver in a bar." --- Michael Emerling Cloud Rick Pasotto email: rickp@telocity.com From dsh8290@rit.edu Tue Apr 10 15:00:06 2001 From: dsh8290@rit.edu (D-Man) Date: Tue, 10 Apr 2001 10:00:06 -0400 Subject: [Tutor] Problem Moving Python Program From WIndows to Linux In-Reply-To: <3AD3BE50.6020905@rock-tnsc.com>; from jsc@rock-tnsc.com on Tue, Apr 10, 2001 at 06:15:44PM -0800 References: <3AD3BE50.6020905@rock-tnsc.com> Message-ID: <20010410100006.B1942@harmony.cs.rit.edu> On Tue, Apr 10, 2001 at 06:15:44PM -0800, Jethro Cramp wrote: | Dear Daniel, | | Thanks alot for the suggestions. Given me several ideas and introduced | me to the "continue" function. it's a keyword, not a function | Can you recommend any utilities to strip "\r" from files. I tried doing | search and replace in idle but that failed. In vim : :%s/^V^M// or you can use the python script Kalle suggested. | Also if I do strip all the "\r" will that render the scripts inoperable | under windows? No. I use windows at work and in (g)vim (my favorite editor) I set it to not include the extra, useless, \r characters on each line. Where you will run into trouble is if you write the file on a windows system it will normally translate \n to \r\n in the write operation. If you treat the file as a text file and look for empty lines rather than \n expicitly it will work fine across systems. The other alternative is to open the (data) file in 'binary' mode. Then you will have full control over the contents. Operating systems really shouldn't be mangling your files like that anyways (IMO); it's the job of the library to handle that filetype to do any necessary mangling. -D From kromag@nsacom.net Tue Apr 10 18:23:52 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Tue, 10 Apr 2001 10:23:52 -0700 (PDT) Subject: [Tutor] Compilation of python on win95b using bcc 5.5 Message-ID: <200104101723.f3AHNqk07382@pop.nsacom.net> Help the windows newbie please. I have learned to use configure and make and have become addicted: Since my company uses a standardized windows image based on win95b (for the time being...) and the only compiler available to me is the Borland C++ v. 5.5, I fear I have become a little lost. Is there a Win32 compilation howto anywhere? I have not been able to find one on the python site. Thanks! From ium@micromuse.com Tue Apr 10 16:27:39 2001 From: ium@micromuse.com (ibraheem umaru-mohammed) Date: Tue, 10 Apr 2001 16:27:39 +0100 Subject: [Tutor] Problem Moving Python Program From WIndows to Linux In-Reply-To: <20010410100006.B1942@harmony.cs.rit.edu>; from dsh8290@rit.edu on Tue, Apr 10, 2001 at 10:00:06AM -0400 References: <3AD3BE50.6020905@rock-tnsc.com> <20010410100006.B1942@harmony.cs.rit.edu> Message-ID: <20010410162738.A2738@ignoramus> [D-Man wrote...] -| | Can you recommend any utilities to strip "\r" from files. I tried doing -| | search and replace in idle but that failed. -| -| In vim : -| -| :%s/^V^M// -| You could also just use the fileformat command under Vim. :help ff and then just do something like :set ff=dos or :set ff=unix This will automatically handle fileformat issues. Hope that helps, Kindest regards, --ibs. -- The best you get is an even break. -- Franklin Adams From Glen@ihello-inc.com Tue Apr 10 20:54:06 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Tue, 10 Apr 2001 12:54:06 -0700 Subject: [Tutor] tkinter displaying results? Message-ID: Hi , I am trying to write a program that will diplay my bandwidth speed. I have the program basically written, however I want it to disply the results in a gui. I am trying to use Tkinter, but I keep getting NameErrors in regards to the variable that I have the result stored in. Does anyone have any ideas? Thanks Glen From Glen@ihello-inc.com Tue Apr 10 21:34:59 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Tue, 10 Apr 2001 13:34:59 -0700 Subject: [Tutor] tkinter displaying results? Message-ID: Please ignore the previous message, I figured it out. Glen -----Original Message----- From: Glen Bunting [mailto:Glen@ihello-inc.com] Sent: Tuesday, April 10, 2001 12:54 PM To: 'tutor@python.org' Subject: [Tutor] tkinter displaying results? Hi , I am trying to write a program that will diplay my bandwidth speed. I have the program basically written, however I want it to disply the results in a gui. I am trying to use Tkinter, but I keep getting NameErrors in regards to the variable that I have the result stored in. Does anyone have any ideas? Thanks Glen _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From Glen@ihello-inc.com Tue Apr 10 23:27:09 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Tue, 10 Apr 2001 15:27:09 -0700 Subject: [Tutor] (no subject) Message-ID: Below is a simple script I wrote to download a file, time how long it takes to download and display the bandwidth usage in Tkinter. It works initially. But the while loop does not work. After the initial run, the program just hangs there and I cannot even exit out of the Tkinter that pops up. What am I doing wrong? Thanks #!/usr/bin/env python import os, urllib, time, Tkinter from Tkinter import * while 1: urllib.urlopen('http://www.esynch.com') first = time.time() urllib.urlretrieve('http://www.esynch.com/mw_test.dat', 'test') second = time.time() speed1 = second - first print speed1 speed = round(speed1, 1) top = Tkinter.Tk() label = Tkinter.Label(top, text = 'Kilobytes/sec:') label.pack() bandwidth = Tkinter.Label(top, text = speed) bandwidth.pack() quit = Tkinter.Button(top, text = 'QUIT', command=top.quit, bg='red', fg='white') quit.pack() Tkinter.mainloop() time.sleep(500) Glen From Kishore.Prayaga@li.csiro.au Wed Apr 11 04:31:16 2001 From: Kishore.Prayaga@li.csiro.au (Kishore Prayaga) Date: Wed, 11 Apr 2001 13:31:16 +1000 Subject: [Tutor] help Message-ID: <4.2.2.20010411131240.00ba6470@mailhost> Hi Here is a small example of a data file and the script I want write in python to do the job. Please let me know the solution for this data file model: A 62 35.0 A 96 47.0 A 107 56.0 B 42 38.0 B 147 46.0 B 183 52.0 C 34 26.0 C 86 43.0 C 108 52.0 ........................ and so on My idea is to count second column with in the first column serially (which i could do) and then calculate the increment in the third column for every increae in the second column with in the first column. i.e for A 62 35.0 the result would be 35.0 - 35.0 =0 for A 96 47.0 the result would be 47.0 - 35.0 =12.0 for A 107 56.0 the result would be 56.0 - 47.0 =9.0 ...............so on with the following script I could do upto counting and to calculate the differences part I need help #!/usr/bin/python import string, sys infile = open('litint.out') outputfile=open('litint1.out', "w") data = {} for line in infile.readlines(): line = line[0:-1] fields = string.split(line,' ') dam_id = fields[0] age = string.atoi(fields[1]) litter = string.atoi(fields[2]) if data.has_key(dam_id): pass else: data[dam_id] ={} data[dam_id][litter] = fields dkeys= data.keys() dkeys.sort() for dam in dkeys: lkeys = data[dam].keys() lkeys.sort() n = 0 for litter in lkeys: n = n+1 total =data[dam][litter] outputfile.write('%s' % n) for i in range(0, len(total)): outputfile.write(' %s' % (total[i])) outputfile.write('\n') ********************************************************* Dr.Kishore C. Prayaga CSIRO Livestock Industries Locked bag 1 Armidale NSW 2350 Australia Ph: (02) 6776 1379 / (02) 6776 1420 Fax: (02) 6776 1371 e-mail: Kishore.Prayaga@li.csiro.au ********************************************************* From kromag@nsacom.net Wed Apr 11 06:42:59 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Tue, 10 Apr 2001 22:42:59 -0700 (PDT) Subject: [Tutor] _pg module and the insertion of random numbers... Message-ID: <200104110542.f3B5gxk07448@pop.nsacom.net> I am attempting to insert random numbers into a PostGreSQL database using _pg and random. I am unsure as to syntax when adding variables. I have attempted the following: import _pg import random db.connect('test', 'localhost') db.query("insert into pork values(`random.randint(1,1000)`+ 'stuff' +'1-2- 1999')") which returns a parse error at the second opening parenthesis. I have also attempted: db.query("insert into pork values('`random.randint(1,1000)`', 'stuff', '1-2- 1999')") which inserts random.randint() as a literal string. What am I doing wrong? From jsc_lists@rock-tnsc.com Wed Apr 11 20:47:05 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Wed, 11 Apr 2001 11:47:05 -0800 Subject: [Tutor] Configuring Xemacs highlighting for Python Message-ID: <3AD4B4B9.4000200@rock-tnsc.com> Can anyone give me some pointers on how to configure the colour highlighting in python mode in XEmacs? Presumably I have to edit the python-mode.el file and then re-compile it. I have looked at this file but can't see what, if anything, I should change. Thanks in advance. Jethro From jsc@rock-tnsc.com Wed Apr 11 21:08:23 2001 From: jsc@rock-tnsc.com (Jethro Cramp) Date: Wed, 11 Apr 2001 12:08:23 -0800 Subject: [Tutor] Problem Moving Python Program From WIndows to Linux References: <3AD3BE50.6020905@rock-tnsc.com> <20010410125955.A30323@father> Message-ID: <3AD4B9B7.1070605@rock-tnsc.com> Kalle Svensson wrote: > Sez Jethro Cramp: > >> Can you recommend any utilities to strip "\r" from files. I tried doing >> search and replace in idle but that failed. > > > s = open("afile").read() > s = s.replace("\r", "") > open("afile", "w").write(s) > > Will remove all "\r"s from "afile". > > >> Also if I do strip all the "\r" will that render the scripts inoperable >> under windows? > > > I don't think so, but haven't tested. > > Peace, > Kalle Thanks. Worked a treat. Jethro From kromag@nsacom.net Wed Apr 11 07:48:26 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Tue, 10 Apr 2001 23:48:26 -0700 (PDT) Subject: [Tutor] Idle/PyGreSQL weirditude. Message-ID: <200104110648.f3B6mQk32144@pop.nsacom.net> I have a rather strange (maybe) bug occouring in IDLE (2.1b2) when attempting to query a PostGreSQL database using the _pg module When attempting the following: import _pg db=_pg.connect('test','localhost') db.query("select * from pork") I get instead of the actual data from the query. Is there something I am missing? From NHYTRO@compuserve.com Wed Apr 11 09:54:37 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Wed, 11 Apr 2001 04:54:37 -0400 Subject: [Tutor] Python variable in SQL statement Message-ID: <200104110454_MC2-CC0C-FC98@compuserve.com> Message text written by INTERNET:tutor@python.org >< I=B4m trying to generate dynamic web pages by reading chunks of HTML from= a database, my prob is, my SQL statements using the Python ODBC module does= not recognize my python container: ###### my code ## print "Content-Type: text/html\n\n" import cgi, dbi, odbc, time # # # my HTML container # template0 =3D """ blah adkasdkadkadjakdjakdjakdjadjada, adadadad dadadadada,dadadad dadadad adada dad adada adad """ #database access connection =3D odbc.odbc('minicms') cur =3D connection.cursor() cur.execute('select * from dummy') for a in range(3): cur.execute("insert into dummy(fieldtwo, fieldthree) values('foonav',= template0)") connection.commit() cur.close() connection.close() ###### end code ### The ODBC driver states that only one value has been given, it just overlooks the "template0" big string container that I declared. Thanks for your anticipated help in advance Sharriff From dyoo@hkn.eecs.berkeley.edu Wed Apr 11 10:09:30 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 02:09:30 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Tue, 10 Apr 2001, Glen Bunting wrote: > Below is a simple script I wrote to download a file, time how long it takes > to download and display the bandwidth usage in Tkinter. It works initially. > But the while loop does not work. After the initial run, the program just > hangs there and I cannot even exit out of the Tkinter that pops up. What am > I doing wrong? When we hit the mainloop() command, Tkinter takes control, and doesn't exit the mainloop() function until we shut down the gui by closing all windows (or calling quit()). It's meant to be the last command in a program, so that's what's causing the while loop to "hang". It looks like you want to update your display every once in a while: try using the after() method: it tells Tkinter to call a function "after" a certain period of time. For example: ### from Tkinter import * root = Tk() def addLabelContinuously(): Label(root, text='hola').pack() root.after(1000, addLabelContinuously) addLabelContinuously() mainloop() ### is a funny little program that, after every second, pack()s in a new label into our main window. Not very useful, but it illustrates how to use after() a little bit. I hope you don't mind, but I wanted to try converting your code with OOP. As a result, I've mutilated your code somewhat beyond recognition. ### from Tkinter import * import os, urllib, time class GUI(Frame): def __init__(self, root): Frame.__init__(self, root) self.speedvar = StringVar() self.updateSpeedvar() Label(self, text='Kilobytes/sec:').pack() Label(self, textvariable=self.speedvar).pack() Button(self, text='QUIT', command=self.quit, bg='red', fg='white').pack() def updateSpeedvar(self): first = time.time() urllib.urlretrieve('http://www.esynch.com/mw_test.dat', 'test') second = time.time() speed1 = second - first print speed1 speed = round(speed1, 1) self.speedvar.set(speed) self.after(500, self.updateSpeedvar) if __name__ == '__main__': root = Tk() gui = GUI(root) gui.pack() mainloop() ### From danny@intuitivemedia.com Wed Apr 11 10:13:46 2001 From: danny@intuitivemedia.com (Danny Ruttle) Date: Wed, 11 Apr 2001 10:13:46 +0100 Subject: [Tutor] Cursors as Dictionaries Message-ID: <5.0.2.1.0.20010411100042.00a0caa0@mail.moonshine.co.uk> I understand that the Python DB2 API allows the results of a database query to be returned as a dictionary. I have tried the following: >>> import PgSQL >>> import libpq >>> >>> db_init = PgSQL.connect(database="testdb3") >>> my_cursor = db_init.cursor() >>> my_cursor.execute("select user_id, first_name from ruser") >>> dict = {} >>> dict = my_cursor.fetchall() but when I try to access the dictionary I get the following error: >>> h = dict.keys() Traceback (most recent call last): File "", line 1, in ? AttributeError: keys On further investigation I discovered that the type of dict is now a list!! >>> dir(dict) ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> print dict[0] ['abf1tu', 'Amy'] This isn't what I want - I need the field names as well as the data in the result set. regards Danny From dyoo@hkn.eecs.berkeley.edu Wed Apr 11 10:17:06 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 02:17:06 -0700 (PDT) Subject: [Tutor] Compilation of python on win95b using bcc 5.5 In-Reply-To: <200104101723.f3AHNqk07382@pop.nsacom.net> Message-ID: On Tue, 10 Apr 2001 kromag@nsacom.net wrote: > Help the windows newbie please. > > I have learned to use configure and make and have become addicted: > > Since my company uses a standardized windows image based on win95b (for the > time being...) and the only compiler available to me is the Borland C++ v. > 5.5, I fear I have become a little lost. > > Is there a Win32 compilation howto anywhere? I have not been able to find one > on the python site. I believe that the compilation environment is optimized for Visual C++. However, Guido van Rossum has written some notes about doing Borland stuff: http://www.cwi.nl/www.python.org/search/hypermail/python-1994q1/0415.html Unfortunately, this is from WAY back in 1994, so the situation now might be so different that the material above might not apply. Furthermore, on the Python web site, the webmaster has written the following warning: "The build process is explained clearly in the file PC/readme.txt contained in the distribution. Only MSVC++ is supported. (Although the source presumably still compiles with the Borland compilers, and there is support for it in config.h, there are currently no Borland project or Makefiles. We lack the personnel to spend time supporting alternate compilers, and nobody has volunteered yet.)" So you're probably going to need to do some work to get Python compiled. I get the feeling that many of us haven't compiled our own Python interpreter, so we might not be able to help with this. Do you really need to compile your own Python interpreter, or are the prebuilt binaries ok for your purposes? Try asking your question in comp.lang.python instead, and you should get better responses. Good luck! From wong_chow_cheok@hotmail.com Wed Apr 11 11:03:14 2001 From: wong_chow_cheok@hotmail.com (wong chow cheok) Date: Wed, 11 Apr 2001 18:03:14 +0800 Subject: [Tutor] (no subject) Message-ID: hai this is chow cheok again. got another problem here. this is what i have so far f=open('you','w') html=urllib.urlopen("http://www.guardian.co.uk/Distribution/Artifact_Trail_Block/0,5184,179821-0-,00.html").read() f.write(html) but when i read it i don't get the file from the website. all i get is rubbish. why is that. even when i try to write a line ex:"i am a boy' i get rubbish too. the only thing i can write to the file is '12345abcd' and other strings similar to it. how do i write the information i got from the website into the file. it can print out fine when i type print html. but it won't enter my file. any help is appreciated. thank you ps. thanks for all the advise you all have given in the past. it has been very helpful. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From dyoo@hkn.eecs.berkeley.edu Wed Apr 11 11:03:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 03:03:33 -0700 (PDT) Subject: [Tutor] Cursors as Dictionaries In-Reply-To: <5.0.2.1.0.20010411100042.00a0caa0@mail.moonshine.co.uk> Message-ID: On Wed, 11 Apr 2001, Danny Ruttle wrote: > I understand that the Python DB2 API allows the > results of a database query to be returned as a > dictionary. Can you point out where you saw this? > I have tried the following: > > >>> import PgSQL > >>> import libpq > >>> > >>> db_init = PgSQL.connect(database="testdb3") > >>> my_cursor = db_init.cursor() > >>> my_cursor.execute("select user_id, first_name from ruser") > >>> dict = {} > >>> dict = my_cursor.fetchall() > > but when I try to access the dictionary I get the following error: > > >>> h = dict.keys() > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: keys > > On further investigation I discovered that the type of > dict is now a list!! SQL fetchall()'s should return back a list of results. More formally, they return a sequence of sequences, not a dictionary. > This isn't what I want - I need the field names as well as the data in the > result set. You'll probably need to look at the "description" attribute of your cursor object, after you do the execute. According to: http://python.org/topics/database/DatabaseAPI-2.0.html after doing the execute, the database module should automagically fill in that information so you can take a look at it. By the way, have you tried working with SQLDict? This might be a useful module for you: http://dustman.net/andy/python/SQLDict Dunno how well it works with Postgres, but I hope it comes in handy. From dyoo@hkn.eecs.berkeley.edu Wed Apr 11 11:14:07 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 03:14:07 -0700 (PDT) Subject: [Tutor] _pg module and the insertion of random numbers... In-Reply-To: <200104110542.f3B5gxk07448@pop.nsacom.net> Message-ID: On Tue, 10 Apr 2001 kromag@nsacom.net wrote: > I am attempting to insert random numbers into a PostGreSQL database using _pg > and random. I am unsure as to syntax when adding variables. > > I have attempted the following: > > import _pg > import random > db.connect('test', 'localhost') > db.query("insert into pork values(`random.randint(1,1000)`+ 'stuff' +'1-2- > 1999')") Python doesn't do string interpolation within strings until you actually trigger it. That is, as far as Python is concerned, both the single and double quotes have the same meaning: there's no difference between them, and no "interpolative context" as in Perl. What you passed to the query was probably the literal string: insert into pork values(`random.randint(1,1000)`+ 'stuff'+'1-2-1999') Instead, you'll probably want to use the string interpolation operator '%'. There's a brief explanation about it here: http://python.org/doc/current/tut/node9.html#SECTION009100000000000000000 The main idea is to tell Python to "fill in the blanks" --- wherever it sees a '%s' within the string, it'll replace it with something useful when we actually do the interpolation: db.query("insert into pork values(%s, stuff, 1-2-1999)" % random.randint(1, 1000)) Try some examples from the tutorial, and if it's still a little unclear, feel free to ask us questions about it. Good luck! From dyoo@hkn.eecs.berkeley.edu Wed Apr 11 11:25:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 03:25:33 -0700 (PDT) Subject: [Tutor] Python variable in SQL statement [String interpolation] In-Reply-To: <200104110454_MC2-CC0C-FC98@compuserve.com> Message-ID: On Wed, 11 Apr 2001, Sharriff Aina wrote: > #database access > connection = odbc.odbc('minicms') > cur = connection.cursor() > cur.execute('select * from dummy') > for a in range(3): > cur.execute("insert into dummy(fieldtwo, fieldthree) values('foonav', > template0)") > connection.commit() > cur.close() > connection.close() > ###### end code ### > > > The ODBC driver states that only one value has been given, it just > overlooks the "template0" big string container that I declared. (I'm starting to sound like a broken record! *grin*) The reason why template0 isn't being substituted into your SQL string is because Python doesn't know when do do this sort of substitution. For example, if we did something like the following: a = 100 s = "Hello, this is the letter 'a'". should our string s contain: "Hello, this is the letter 'a'", or "Hello, this is the letter '100'" How would Python know? Because of the ambiguity of such situations, Python design dictates less guesswork --- it will not "interpolate" or fill in a string with variable values, until we actually tell it to do it explicitly. That's where string interpolation comes in. Take a look at: http://python.org/doc/current/tut/node9.html#SECTION009100000000000000000 which shows some brief examples about this topic. Also, the page: http://python.sourceforge.net/devel-docs/lib/typesseq-strings.html gives a much drier explanation of string interpolation. From dyoo@hkn.eecs.berkeley.edu Wed Apr 11 11:34:21 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 03:34:21 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Wed, 11 Apr 2001, wong chow cheok wrote: > hai this is chow cheok again. got another problem here. > this is what i have so far > > f=open('you','w') > html=urllib.urlopen("http://www.guardian.co.uk/Distribution/Artifact_Trail_Block/0,5184,179821-0-,00.html").read() > f.write(html) > > but when i read it i don't get the file from the website. all i get is > rubbish. why is that. even when i try to write a line ex:"i am a boy' What kind of contents are you getting? When I visit that link with my Netscape browser, it spits out the "Sorry, the page you requested is not available at this moment." Could you check the URL again? Also, it's usually helpful to show us what a small portion of the file looks like: although it might not be understandable, it might contain clues about why it's not doing the right thing. > i get rubbish too. the only thing i can write to the file is '12345abcd' and > other strings similar to it. how do i write the information i got from the > website into the file. it can print out fine when i type > print html. Your program looks ok; I'm guessing either the web site is down, or the url needs to be corrected. By the way, try the following program, and see if it works ok for you: ### f = open('evens.txt', 'w') f.write("This is a file that contains even numbers.\n\n") for i in range(20, 2): f.write(i) f.write(' ') f.close() ### It does enough file writing to help you see if file output is working well. From kalle@gnupung.net Wed Apr 11 12:14:13 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 11 Apr 2001 13:14:13 +0200 Subject: [Tutor] _pg module and the insertion of random numbers... In-Reply-To: <200104110542.f3B5gxk07448@pop.nsacom.net>; from kromag@nsacom.net on Tue, Apr 10, 2001 at 10:42:59PM -0700 References: <200104110542.f3B5gxk07448@pop.nsacom.net> Message-ID: <20010411131413.A10701@father> Sez kromag@nsacom.net: > I am attempting to insert random numbers into a PostGreSQL database using _pg > and random. I am unsure as to syntax when adding variables. > > I have attempted the following: > > import _pg > import random > db.connect('test', 'localhost') > db.query("insert into pork values(`random.randint(1,1000)`+ 'stuff' +'1-2- > 1999')") db.query("insert into pork values(" + `random.randint(1,1000)` + ", 'stuff', '1-2-1999')") should work, but I haven't tested. Also note that use of backticks for stringification is quite uncommon. Using the builtin functions str() or repr() (which is equivalent to backticks) is far more common. repr(123) == `123` # this is always true str(123) == `123` # this isn't always true, but works for integers. Another way to do it is to use the % operator: "insert into pork values(%d, 'stuff', '1-2-1999')" % random.randint(1,1000)) > What am I doing wrong? I think you got lost in a maze of twisty little quotes, all alike. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From NHYTRO@compuserve.com Wed Apr 11 13:30:12 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Wed, 11 Apr 2001 08:30:12 -0400 Subject: [Tutor] Interpolative content Message-ID: <200104110830_MC2-CBFA-D759@compuserve.com> Thanks Mr. Yoo, Mr, Coughlin! I=B4m not gonna get chewed up by my boss after all... did I ever mention how much I=B4m enjoying Python...I=B4ll never open tho= se Java books of mine again.. Best regards and thanks Sharriff From shaleh@valinux.com Wed Apr 11 17:56:34 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 11 Apr 2001 09:56:34 -0700 (PDT) Subject: [Tutor] Configuring Xemacs highlighting for Python In-Reply-To: <3AD4B4B9.4000200@rock-tnsc.com> Message-ID: On 11-Apr-2001 Jethro Cramp wrote: > Can anyone give me some pointers on how to configure the colour > highlighting in python mode in XEmacs? > > Presumably I have to edit the python-mode.el file and then re-compile > it. I have looked at this file but can't see what, if anything, I should > change. > ;; figure out which face is being used (defun describe-face-at-point () "Return face used at point." (interactive) (hyper-describe-face (get-char-property (point) 'face))) I have this in my .emacs file. I put the pointer on the item I want to change, type M-X describe-face-at-point and it opens a second frame which shows me all of the attributes. From Glen@ihello-inc.com Wed Apr 11 18:27:42 2001 From: Glen@ihello-inc.com (Glen Bunting) Date: Wed, 11 Apr 2001 10:27:42 -0700 Subject: [Tutor] (no subject) Message-ID: Daniel, Your version works perfectly except for one thing, when I click on the quit button, nothing happens. I will continue to use the program the way you wrote it, but I have a few questions about the way I was trying to write it. 1: The after() method does not redraw or refresh the speed variable, all it does is reprint the variable below the original after the time specified. 2: As long as Tkinter.mainloop() remains in the while loop, the while loop does not continue until after I quit Tkinter. Once I do that the loop continues. If I take Tkinter.mainloop out of the while loop, the loop continues like it should , but the gui never pops up. Any suggestions? The next thing I might be interested in doing is to graph the results. Is that the next logical step, or would that be a little to advanced for a newbie? Thanks Glen -----Original Message----- From: Daniel Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] Sent: Wednesday, April 11, 2001 2:10 AM To: Glen Bunting Cc: 'tutor@python.org' Subject: Re: [Tutor] (no subject) On Tue, 10 Apr 2001, Glen Bunting wrote: > Below is a simple script I wrote to download a file, time how long it takes > to download and display the bandwidth usage in Tkinter. It works initially. > But the while loop does not work. After the initial run, the program just > hangs there and I cannot even exit out of the Tkinter that pops up. What am > I doing wrong? When we hit the mainloop() command, Tkinter takes control, and doesn't exit the mainloop() function until we shut down the gui by closing all windows (or calling quit()). It's meant to be the last command in a program, so that's what's causing the while loop to "hang". It looks like you want to update your display every once in a while: try using the after() method: it tells Tkinter to call a function "after" a certain period of time. For example: ### from Tkinter import * root = Tk() def addLabelContinuously(): Label(root, text='hola').pack() root.after(1000, addLabelContinuously) addLabelContinuously() mainloop() ### is a funny little program that, after every second, pack()s in a new label into our main window. Not very useful, but it illustrates how to use after() a little bit. I hope you don't mind, but I wanted to try converting your code with OOP. As a result, I've mutilated your code somewhat beyond recognition. ### from Tkinter import * import os, urllib, time class GUI(Frame): def __init__(self, root): Frame.__init__(self, root) self.speedvar = StringVar() self.updateSpeedvar() Label(self, text='Kilobytes/sec:').pack() Label(self, textvariable=self.speedvar).pack() Button(self, text='QUIT', command=self.quit, bg='red', fg='white').pack() def updateSpeedvar(self): first = time.time() urllib.urlretrieve('http://www.esynch.com/mw_test.dat', 'test') second = time.time() speed1 = second - first print speed1 speed = round(speed1, 1) self.speedvar.set(speed) self.after(500, self.updateSpeedvar) if __name__ == '__main__': root = Tk() gui = GUI(root) gui.pack() mainloop() ### From m_konermann@gmx.de Wed Apr 11 22:45:20 2001 From: m_konermann@gmx.de (Marcus Konermann) Date: Wed, 11 Apr 2001 23:45:20 +0200 Subject: [Tutor] Need help on a simple problem (i think) Message-ID: <3AD4D070.2CE8C5DE@gmx.de> --------------F02AE80BD61521123CF7363D Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hello ! I´ve got two moduls. The first one is mainko.py and the second one functions.py and i only want to call a method from the mainko.py modul named test, wich is declared in the modul functions.py. This is mainko.py : import string,re,sys,glob,operator from functions import * import os #print os.getcwd() #print os.listdir(os.getcwd()) #ausgabe=[] print 'test()=',test() #abweichung('soll.out',(((3,5),1),((7,9),1)),'ist.out',(((3,5),1),((7,9),1)),r'\d+\.\d+[E][+-]\d+',r'[ ]+') #print 'ausgabe=',ausgabe #((3,5),1),(4,(1,3)),(5,1))) and this is the modul functions.py : import string,sys from math import * from types import * from identify import identification class operation(identification): def __init__(self,srchfiles,pattfile,splitfile): identification.__init__(self,srchfiles,pattfile,splitfile) def test(self): print'it is ok' and the ERROR Output from Python is the following: test()=Traceback (innermost last): File "C:\Arbeit_Studienarbeit\PythonPROG\Pythonwin\pywin\framework\scriptutils.py", line 237, in RunScript exec codeObject in __main__.__dict__ File "C:\Arbeit_Studienarbeit\Arbeit\Marcus\aktuell\mainko.py", line 8, in ? print 'test()=',test() NameError: test and I don´t know why there´s a NameError. I´m using Pythonwin under Win98 and a few days before i put my working directory in another destination, probably there could be an answer of my problem. I already put the following PATH Command in my autoexec.bat: SET PYTHONPATH=c:\arbeit_studienarbeit\arbeit\marcus\aktuell;c:\arbeit_studienarbeit\pythonprog\lib but nothing happend. So ,can anyone help me ??? Thanks a lot Marcus --------------F02AE80BD61521123CF7363D Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hello !

I´ve got two moduls. The first one is mainko.py and the second one functions.py and i only want to call a method from the mainko.py modul named test, wich is declared in the modul functions.py.
This is mainko.py :

import string,re,sys,glob,operator
from functions import *
import os

#print os.getcwd()
#print os.listdir(os.getcwd())
#ausgabe=[]
print 'test()=',test()
#abweichung('soll.out',(((3,5),1),((7,9),1)),'ist.out',(((3,5),1),((7,9),1)),r'\d+\.\d+[E][+-]\d+',r'[ ]+')
#print 'ausgabe=',ausgabe

#((3,5),1),(4,(1,3)),(5,1)))

and this is the modul functions.py :

import string,sys
from math import *
from types import *
from identify import  identification

class operation(identification):

 def __init__(self,srchfiles,pattfile,splitfile):
  identification.__init__(self,srchfiles,pattfile,splitfile)

 def test(self):
  print'it is ok'

and the ERROR Output from Python is the following:

test()=Traceback (innermost last):
  File "C:\Arbeit_Studienarbeit\PythonPROG\Pythonwin\pywin\framework\scriptutils.py", line 237, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Arbeit_Studienarbeit\Arbeit\Marcus\aktuell\mainko.py", line 8, in ?
    print 'test()=',test()
NameError: test

and I don´t know why there´s a NameError. I´m using Pythonwin under Win98 and a few days before i put my working directory in another destination, probably there could be an answer of my problem.
I already put the following PATH Command in my autoexec.bat:

SET PYTHONPATH=c:\arbeit_studienarbeit\arbeit\marcus\aktuell;c:\arbeit_studienarbeit\pythonprog\lib

but nothing happend.
So ,can anyone help me ???

Thanks a lot
Marcus --------------F02AE80BD61521123CF7363D-- From kalle@gnupung.net Wed Apr 11 23:06:45 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 12 Apr 2001 00:06:45 +0200 Subject: [Tutor] Need help on a simple problem (i think) In-Reply-To: <3AD4D070.2CE8C5DE@gmx.de>; from m_konermann@gmx.de on Wed, Apr 11, 2001 at 11:45:20PM +0200 References: <3AD4D070.2CE8C5DE@gmx.de> Message-ID: <20010412000645.C375@apone.network.loc> Sez Marcus Konermann: [snip problem description, basically a NameError] > class operation(identification): > > def __init__(self,srchfiles,pattfile,splitfile): > identification.__init__(self,srchfiles,pattfile,splitfile) > > def test(self): > print'it is ok' The problem seems to be here. test() is defined as a method of the class operation, but you try to call it as a function. Either move the test() function out of the class, or create a class instance in mainko.py: op = operation("f","g","h") print op.test() Also note that "from xxx import *" is generally considered bad practice. A little more obvious indentation, four or eight spaces, wouldn't hurt either, IMHO. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From DOUGS@oceanic.com Thu Apr 12 00:03:06 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Wed, 11 Apr 2001 13:03:06 -1000 Subject: [Tutor] Need help on a simple problem (i think) Message-ID: <8457258D741DD411BD3D0050DA62365907A762@huina.oceanic.com> [Marcus Konermann asked:] > I=B4ve got two moduls. The first one is mainko.py and the=20 > second one functions.py and i only want to call a method from=20 > the mainko.py modul named test, wich is declared in the modul=20 > functions.py.=20 > This is mainko.py :=20 > import string,re,sys,glob,operator=20 > from functions import *=20 > import os=20 > #print os.getcwd()=20 > #print os.listdir(os.getcwd())=20 > #ausgabe=3D[]=20 > print 'test()=3D',test()=20 > #abweichung('soll.out',(((3,5),1),((7,9),1)),'ist.out',(((3,5) > ,1),((7,9),1)),r'\d+\.\d+[E][+-]\d+',r'[ ]+')=20 > #print 'ausgabe=3D',ausgabe=20 > #((3,5),1),(4,(1,3)),(5,1)))=20 > and this is the modul functions.py :=20 > import string,sys=20 > from math import *=20 > from types import *=20 > from identify import identification=20 > class operation(identification):=20 > def __init__(self,srchfiles,pattfile,splitfile):=20 > identification.__init__(self,srchfiles,pattfile,splitfile)=20 > def test(self):=20 > print'it is ok'=20 > and the ERROR Output from Python is the following:=20 > test()=3DTraceback (innermost last):=20 > File=20 > "C:\Arbeit_Studienarbeit\PythonPROG\Pythonwin\pywin\framework\ > scriptutils.py", line 237, in RunScript=20 > exec codeObject in __main__.__dict__=20 > File=20 > "C:\Arbeit_Studienarbeit\Arbeit\Marcus\aktuell\mainko.py",=20 > line 8, in ?=20 > print 'test()=3D',test()=20 > NameError: test=20 Python is telling you that you didn't do what you thought you would = when you imported the 'functions' module. What it wanted to see in order to = believe 'test' was a real name was that name defined in the first level of the module. In other words if the fifth line in functions.py was 'test =3D = 27' then it would have known what the name was. In your case you've defined 'test' as a function of a class = 'operation'. That function can't be available simply from a module import. You need = to have something like the following to instantiate an instance of the = class which would have a 'test' function available: spam =3D operation(eggs) print 'test()=3D', spam.test() One comment on style here. To use 'from module import *' as you do = several places here, is considered a "VERY BAD IDEA" (tm), unless you are quite clear what you are doing. It is almost always better to use 'import = module' and then use the module.name format to address the module contents. In = your case this should equate to: import functions spam =3D functions.operation(eggs) HTH -Doug- From cdwom@mpinet.net Wed Apr 11 21:52:55 2001 From: cdwom@mpinet.net (Corey Woodworth) Date: Wed, 11 Apr 2001 16:52:55 -0400 Subject: [Tutor] Newsgroup Message-ID: <000001c0c2de$6e27bc40$dcdd35d8@KellyJoW> I've heard that this mailing list is also posted to a newsgroup? What newsgroup is it? I'm filling up my mailbox with tons of posts i never read, it would be much better If i could read 'em in a newsreaded. thanks Corey From dyoo@hkn.eecs.berkeley.edu Thu Apr 12 00:39:39 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 16:39:39 -0700 (PDT) Subject: [Tutor] Newsgroup In-Reply-To: <000001c0c2de$6e27bc40$dcdd35d8@KellyJoW> Message-ID: On Wed, 11 Apr 2001, Corey Woodworth wrote: > I've heard that this mailing list is also posted to a newsgroup? What > newsgroup is it? I'm filling up my mailbox with tons of posts i never > read, it would be much better If i could read 'em in a newsreaded. > thanks What you probably mean is the main Python newsgroup (comp.lang.python). That particular newsgroup is available as a mailing list: http://mail.python.org/mailman/listinfo/python-list/ and as the newsgroup comp.lang.python. However, this mailing list is tutor@python.org. For good or for evil, we don't have our own dedicated newsgroup. Still, all the messages on tutor are archived through a nice web interface: http://mail.python.org/pipermail/tutor so if you want to see what we've been chatting about recently, you can browse messages there. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Thu Apr 12 00:58:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 16:58:05 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Wed, 11 Apr 2001, Glen Bunting wrote: > Your version works perfectly except for one thing, when I click on the quit > button, nothing happens. I will continue to use the program the way you > wrote it, but I have a few questions about the way I was trying to write it. Hmmm... strange! What might be happening is that the updating action is taking a long time. At the moment, the program is written to only be able to do one task at a time. The call to: urllib.urlretrieve('http://www.esynch.com/mw_test.dat', 'test') takes a heck of a lot of time, precisely because the file is HUGE, even with a broadband connection. *grin*. That's probably why the GUI isn't as responsive as it should be: it's only doing one thing at a time. Try your program on a less stressful URL, and see if this is the case. > 2: As long as Tkinter.mainloop() remains in the while loop, the while > loop does not continue until after I quit Tkinter. Once I do that the > loop continues. If I take Tkinter.mainloop out of the while loop, the > loop continues like it should , but the gui never pops up. The role of the mainloop() call is to pass control of your program off to Tkinter --- after caling mainloop(), it's all "hands-off". I believe this is called "event-driven programming", because anything that happens afterwards is a response to what the user does with the GUI. The control flow of our GUI programs, then, looks like: start ----> initialize stuff ---> initialize GUI -+ | +------------------<-------------------+ | +----> do GUI stuff ---+---> turn off GUI ---> done! | | +----------<-----------+ handle an "event" The "do GUI stuff" loopiness is what the mainloop() is doing: it keeps on looping until we can't look at any more "events", and then we finish the program. It's a different style of programming than what you might be used to. > The next thing I might be interested in doing is to graph the results. Is > that the next logical step, or would that be a little to advanced for a > newbie? Graphing sounds like a great idea. You'll want to play around with the Canvas widget. If you want, I can take a look at Grayson's "Python and Tkinter Programming" to review how Canvases work. There's supposedly a really good module that works with Tkinter to make really nice widgets. It's called Python Mega Widgets, and I think it has a graphing widget that might be useful. If you're interested, take a look: http://pmw.sourceforge.net Lots of good stuff. Anyway, good luck to you. From dyoo@hkn.eecs.berkeley.edu Thu Apr 12 01:10:54 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 11 Apr 2001 17:10:54 -0700 (PDT) Subject: [Tutor] converting CGI's FieldStorage to dictionary? In-Reply-To: <200104091633.MAA11149@birds.us.itd.umich.edu> Message-ID: On Mon, 9 Apr 2001, Lance E Sloan wrote: > The problem I'm running into is that DocumentTemplate uses > dictionaries as arguments to hold template values, but cgi's > FieldStorage is not quite a dictionary. So, this doesn't work: > > import cgi > import DocumentTemplate > > form = cgi.FieldStorage() > tmpl = DocumentTemplate.HTMLFile('path/to/file') > print tmpl(mapping = form) > > How can I write a function that takes my FieldStorage form as an > argument and returns a dictionary of field names to field values? Let's write a function that takes a FieldStorage, and returns back an equivalent dictionary: ### def fieldStorageToDictionary(fs): mydict = {} for k, v in fs.items(): mydict[k] = v.value return mydict ### To tell the truth, I haven't tested this code yet, but hopefully this is close enough that it'll help you write that function. Good luck! From bwgolling@home.com Wed Apr 11 21:55:38 2001 From: bwgolling@home.com (Bruce Golling) Date: Wed, 11 Apr 2001 20:55:38 +0000 Subject: [Tutor] Idle vs PythonWin Env Message-ID: <3AD4C4C9.1026CCA6@home.com> I wonder if anyone can tell me why PythonWin and Idle behave so differently on my win98 box. F'rinstance if I run the turle.demo on Idle, it performs the whole routine. Whereas on PythonWin only the 3 boxes come up and the prog stops. The reason I bring this up is that I gave up on Perl because I had such hard time interfacing with windows. As everyone here knows that problem does not exist with Python. Pythonwin seems to be a little more intuitive for me (I need all the help I can get), but it seems to more buggy than Idle. Do I not have my env set up correctly, or something. Mainly I want to spend more time fooling around with the lang rather than the ide. tks Bruce From spi" Hi, I'm messing around with win32com and IE, I grabbed this sample code from some messge groups, it works fine in the pythonwin interactive window, I can control IE and browse .. import win32com import win32com.client ie = win32com.client.Dispatch("InternetExplorer.Application") ie.Navigate("www.yahoo.com") doc = ie.Document print doc.url The problem is that when I put the exact same code in a python script and run it from the command line I get this error D:\data\product\workingDB\py>test.py Traceback (most recent call last): File "D:\data\product\workingDB\py\test.py", line 6, in ? doc = ie.Document File "d:\python20\win32com\client\dynamic.py", line 431, in __getattr__ raise pythoncom.com_error, details pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147467259), None) It's the exact same code that I enter into pythonwin, and it works there I don't understand what the problem is.. From mosleh@corpotech.com Thu Apr 12 04:26:09 2001 From: mosleh@corpotech.com (Mosleh Uddin) Date: Thu, 12 Apr 2001 13:26:09 +1000 Subject: [Tutor] Can't find FtServer. Message-ID: <3AD52051.8F83F9C3@corpotech.com> Hi I was trying to run a program but it can't find "FtServer". Can you please give me idea how can I can get "FtServer". Thank you. Mosleh From kalle@gnupung.net Thu Apr 12 14:48:29 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 12 Apr 2001 15:48:29 +0200 Subject: [Tutor] Can't find FtServer. In-Reply-To: <3AD52051.8F83F9C3@corpotech.com>; from mosleh@corpotech.com on Thu, Apr 12, 2001 at 01:26:09PM +1000 References: <3AD52051.8F83F9C3@corpotech.com> Message-ID: <20010412154829.A16549@father> Sez Mosleh Uddin: > I was trying to run a program but it can't find "FtServer". > Can you please give me idea how can I can get "FtServer". Sorry, but I have no idea. What program is it you're trying to run? Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From alan.gauld@bt.com Thu Apr 12 17:24:17 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 12 Apr 2001 17:24:17 +0100 Subject: [Tutor] Idle vs PythonWin Env Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6E8@mbtlipnt02.btlabs.bt.co.uk> > if I run the turle.demo on Idle, it performs the whole routine. > Whereas on PythonWin only the 3 boxes come up and the prog stops. Works OK for me on both. BUT being a Tkinter program its probably not a good idea to run it from within IDLE - which is also a Tkinter program. IDLE (Tkinrter) usually gets confused about who owns the app mainloop... > Pythonwin seems to be a little more intuitive for me > but it seems to more buggy than Idle. I agree, but for some things the extra function outweighs the occasional hangup etc. > Mainly I want to spend more time fooling around with > the lang rather than the ide. Always a good idea :-) Alan G From alan.gauld@bt.com Thu Apr 12 17:16:05 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 12 Apr 2001 17:16:05 +0100 Subject: [Tutor] Newsgroup Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6E7@mbtlipnt02.btlabs.bt.co.uk> > > I've heard that this mailing list is also posted to a newsgroup? > However, this mailing list is tutor@python.org. > are archived through a nice web interface: > > http://mail.python.org/pipermail/tutor Also you can elect to get a digest of the messages which means you only see betwen 1 and 4 messaages per day in your mailbox - thats a lot more manageable. Alan g From van@lindbergs.org Thu Apr 12 19:08:05 2001 From: van@lindbergs.org (VanL) Date: Thu, 12 Apr 2001 12:08:05 -0600 Subject: [Tutor] Idle vs PythonWin Env References: <3AD4C4C9.1026CCA6@home.com> Message-ID: <3AD5EF05.A789FF9B@lindbergs.org> Try ActiveState's Komodo IDE. It is free for educational or home use if you sign up for their ASPN. (I'm not sure exactly what ASPN stands for.) It has a couple things that I haven't seen other places: A regular expression editor/checker, project management, and it does other languages too. VanL Bruce Golling wrote: > I wonder if anyone can tell me why PythonWin and Idle behave so > differently on my win98 box. F'rinstance if I run the turle.demo on > Idle, it performs the whole routine. Whereas on PythonWin only the 3 > boxes come up and the prog stops. > The reason I bring this up is that I gave up on Perl because I had such > hard time interfacing with windows. As everyone here knows that problem > does not exist with Python. > Pythonwin seems to be a little more intuitive for me (I need all the > help I can get), but it seems to more buggy than Idle. > Do I not have my env set up correctly, or something. > Mainly I want to spend more time fooling around with the lang rather > than the ide. > tks > Bruce > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From pythoperson@yahoo.com Thu Apr 12 21:47:36 2001 From: pythoperson@yahoo.com (folklore hopeful) Date: Thu, 12 Apr 2001 13:47:36 -0700 (PDT) Subject: [Tutor] Possible problems using a windows .bat file to run a program? Message-ID: <20010412204736.42896.qmail@web12405.mail.yahoo.com> I was wondering if there are any potential problems in using a windows desktop shortcut to run a batch file which runs a python program. Basically, I have a nifty little program that is useful in the office, but the people using the program are computer-challanged and the word "DOS" sounds confusing to them. So, currently, I am having them double click on a batchfile which runs: c:\python20\python 216.py I've had reports of the program giving error messages and etc. and that computers had to be rebooted so that the program would work. Any ideas what the problem might be? How can I avoid this? Thanks for all your help! __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From dsh8290@rit.edu Thu Apr 12 22:16:44 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 12 Apr 2001 17:16:44 -0400 Subject: [Tutor] Possible problems using a windows .bat file to run a program? In-Reply-To: <20010412204736.42896.qmail@web12405.mail.yahoo.com>; from pythoperson@yahoo.com on Thu, Apr 12, 2001 at 01:47:36PM -0700 References: <20010412204736.42896.qmail@web12405.mail.yahoo.com> Message-ID: <20010412171644.A15266@harmony.cs.rit.edu> On Thu, Apr 12, 2001 at 01:47:36PM -0700, folklore hopeful wrote: | I was wondering if there are any potential problems in using a | windows desktop shortcut to run a batch file which runs a python | program. Basically, I have a nifty little program that is useful in | the office, but the people using the program are computer-challanged | and the word "DOS" sounds confusing to them. So, currently, I am | having them double click on a batchfile which runs: The python installer sets the file associations so that they can double click on a .py or .pyw file and it will run in python. The biggest problem with that is getting a traceback, and windows closing the DOS-box before the message can be read. | I've had reports of the program giving error messages and etc. and | that computers had to be rebooted so that the program would work. | Any ideas what the problem might be? Windows | How can I avoid this? Use Debian . apt-get rules. No rebooting necessary except for power outages, new kernels, or testing boot loaders and init sequence . Seriously, though, windows is _very_ reboot-happy. (Ever try to set up networking? Each change requires a reboot! =p) After installing anything (apps, drivers, you name it) windows must be rebooted to work semi-reliably. (IMO windows doesn't work any better than semi-reliably) Another potential solution would be to put a raw_input( "Press [enter] to quit this app" ) at the end of your program so that error messages (the DOS-box) will stay on-screen until you can read them. Without knowing the actual error message it is hard to guess what the real problem is. Is your program a console or gui app? If it is a gui app then you might want to rename the main .py file to .pyw to eliminate the DOS box. -D From info@webb2e.com Fri Apr 13 01:13:37 2001 From: info@webb2e.com (info@webb2e.com) Date: Thu, 12 Apr 2001 17:13:37 -0700 Subject: [Tutor] Free register of online company's profile Message-ID: <0aa973713000d41MAIL@mail3.chinainfoland.com> This is a multi-part message in MIME format. ------=_NextPart_000_389C_01C0C373.E9855A60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit How much are you paying to advertise your business to the world? Expose Your service to the world with bold register of online business profile. Sign up today! Introducing WebB2E.com -- your direct link to global information; source of business, products, education/research, social/culture, entertainment and travel... Additionally you can BUY, SELL or PROMOTE your products and services At www.webb2e.com you'll get: --Message center (open to the public). --Employment center. --Sponsorship center. --Bulletin board (business and service issue). --Flexible Online Office (Business Online Report). --Economic news. --View thousands of trade leads. --Post business propositions. --Merchandise marketing (Vast advertising at a low cost). --World shopping center. .. and much more. Please visit www.webb2e.com If you do not want to recieve any more e-mails from WebB2E.com and wish to be removed from e-mail list please click here . ------=_NextPart_000_389C_01C0C373.E9855A60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable www.webb2e.comHow much are you = paying to advertise your business to the world?

Expose Your = service to the world with bold register of online business profile. Sign = up today!

Introducing WebB2E.com -- your direct link to global = information; source of business, products, education/research, = social/culture, entertainment and travel...
Additionally you can = BUY, SELL or PROMOTE your products and services
At www.webb2e.com you'll get: =

--Message center (open to the public).
--Employment center. =
--Sponsorship center.
--Bulletin board (business and service = issue).
--Flexible Online Office (Business Online Report). =
--Economic news.
--View thousands of trade leads.
--Post = business propositions.
--Merchandise marketing (Vast advertising at = a low cost).
--World shopping center.

... and much more. = Please visit www.webb2e.com =

If you do not want to recieve any more e-mails from WebB2E.com = and wish to be removed from e-mail list please click = here.

------=_NextPart_000_389C_01C0C373.E9855A60-- From wong_chow_cheok@hotmail.com Fri Apr 13 04:31:36 2001 From: wong_chow_cheok@hotmail.com (wong chow cheok) Date: Fri, 13 Apr 2001 11:31:36 +0800 Subject: [Tutor] (no subject) Message-ID: i was wondering how do you extract a url using reg expressions. i mean just say i want my program to extract any url beginning with 'http://......'. is there any way to do that? i tried using 'http:(.*?).com' and some other variations but it is not doing the trick. i can only get those url ending with .com ir other endings that i have tried. thanks for your help. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From van@lindbergs.org Fri Apr 13 05:13:33 2001 From: van@lindbergs.org (VanL) Date: Thu, 12 Apr 2001 22:13:33 -0600 Subject: [Tutor] Recursive search and replace Message-ID: <3AD67CED.17CFAA34@lindbergs.org> Hello, I have written a script to do two things: 1. Copy a set of textfiles into every directory in a directory tree. 2. Edit every htmlfile in the directory tree such that "../(../../)textfile.txt" becomes "textfile.txt" This script does the first, but not the second. I successfully open each htmlfile, but my regex does not to the matching and substitution. However, when I test the same regex in the interpreter, it works perfectly. Can anyone spot the problem? Thanks, Van SCRIPT: import re, string, os, os.path from shutil import copy txtfilematch = re.compile(r'txt') htmlfilematch = re.compile(r'html') includematch = re.compile(r'(include file=")(\.\./)+') def walk(includes, dirname, names): for obj in names: if os.path.isfile(obj): if re.search(htmlfilematch, obj): linelist = open(obj).readlines() print "Opened:", os.path.join(dirname, obj) newfile = open(obj, 'w') for line in linelist: if re.search(includematch, line): print "Found include:", line line = includematch.sub(r'include file="', line) print "New line:", line newfile.write(line) else: newfile.write(line) newfile.flush() newfile.close() for file in includes: filename = os.path.split(file)[1] newloc = os.path.join(dirname, filename) copy(file, newloc) #print "Copied:", filename, newloc includefiles = [] for file in os.listdir(os.getcwd()): if re.search(txtfilematch, file): includefiles.append(file) os.path.walk('.', walk, includefiles) From dyoo@hkn.eecs.berkeley.edu Fri Apr 13 08:58:36 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 13 Apr 2001 00:58:36 -0700 (PDT) Subject: [Tutor] Message persistence In-Reply-To: Message-ID: On Mon, 9 Apr 2001, Derek White wrote: > Hello all, > > If I were wanting to write a web based message board system with CGI with > replies in threads what would be some of the ways to consider for message > persistence in Python? If there's going to be a lot of messages, you'll probably want to store your data within some sort of SQL database. The reason for this is because databases are equipped to handle large amounts of heirarchical stuff. There are a few free (free speech and free beer) systems out there, including mysql and postgresql: http://www.mysql.com http://www.pgsql.com (Strangely enough, www.pgsql.com seems to be down at the time of this writing. Check back on it later.) There's a nice web site that talks a lot about mysql called devshed: http://devshed.com/Server_Side/MySQL/ which might give you ideas on how to plan out the structure of your web message board. Something tells me, though, that all this might be overkill. Is this what you're looking for, or something else? From dyoo@hkn.eecs.berkeley.edu Fri Apr 13 10:46:14 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 13 Apr 2001 02:46:14 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Fri, 13 Apr 2001, wong chow cheok wrote: > i was wondering how do you extract a url using reg expressions. > > i mean just say i want my program to extract any url beginning with > 'http://......'. is there any way to do that? i tried using > 'http:(.*?).com' and some other variations but it is not doing the trick. i > can only get those url ending with .com ir other endings that i have tried. Here ya go: ### abs_http_url = r''' # one of the main protocols (http | https | ftp | telnet | gopher | file | wais | ftp | mailto) : # followed by a colon [\w.#@&=\-_~/;:\n]+? # a bunch of stuff that can span lines, # nongreedily, (?=([,:\-.!?;]? # that shouldn't contain any # trailing punctutation, (\s+|$))) # spaces, or eol character. ''' abs_http_url_re = re.compile(abs_http_url, re.VERBOSE) ### Let's see it in action: ### >>> result = abs_http_url_re.search("this is a test with an url\ http://python.org embedded in it.") >>> result >>> result.group(0) 'http://python.org' ### It might not be perfect, but it's commented heavily, so you can see where to fix it up. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Fri Apr 13 11:01:17 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 13 Apr 2001 03:01:17 -0700 (PDT) Subject: [Tutor] Recursive search and replace In-Reply-To: <3AD67CED.17CFAA34@lindbergs.org> Message-ID: On Thu, 12 Apr 2001, VanL wrote: > Hello, > > I have written a script to do two things: > 1. Copy a set of textfiles into every directory in a directory > tree. > 2. Edit every htmlfile in the directory tree such that > "../(../../)textfile.txt" becomes "textfile.txt" > > This script does the first, but not the second. I successfully open > each htmlfile, but my regex does not to the matching and > substitution. However, when I test the same regex in the > interpreter, it works perfectly. Can anyone spot the problem? You might want to make sure that it's not interfering with case sensitivity by using the IGNORECASE flag: txtfilematch = re.compile(r'txt', re.IGNORECASE) That's the only think I can think of so far; otherwise, I don't see an obvious bug in the code. As a style comment: it might be better to separate the code: > linelist = open(obj).readlines() > print "Opened:", > os.path.join(dirname, obj) > newfile = open(obj, 'w') > > for line in linelist: > if re.search(includematch, > line): > print "Found > include:", line > line = > includematch.sub(r'include file="', line) > print "New line:", > line > newfile.write(line) > > else: > newfile.write(line) > > newfile.flush() > newfile.close() off into a separate function, just to reduce the amount of nested blocks in the program. Conceptually, it's doing a large task: it's taking in a file, fiddling it's contents, and writing it back to disk. We could call the function something like fixupFile(f). By doing this, we can independently test to see if the string replacement is the bug, or if it's something else. From cruciatuz Fri Apr 13 13:28:48 2001 From: cruciatuz (cruciatuz) Date: Fri, 13 Apr 2001 14:28:48 +0200 Subject: [Tutor] wxPyhton installation Message-ID: <12211033629.20010413142848@gmx.de> Hello tutorlist, I installed wxPython for Python 2 on my windows 98 machine but i have the problem that i am using Python 2.1b1, so i get the following error msg: Traceback (most recent call last): File "", line 1, in ? from wxPython import * File "c:\python21\lib\wxPython\__init__.py", line 20, in ? import wxc ImportError: Module use of python20.dll conflicts with this version of Python. After that i set the sys.version variable from Python 2.1b to Python 2.0, but that didn't help. Is there a solution? + ---------------------------------- + | Stefan Antoni | + ---------------------------------- + | ICQ: 72292815 | | PGP-Key: AVAILABLE | + ---------------------------------- + 14:13 / Freitag, 13. April 2001 From dsh8290@rit.edu Fri Apr 13 15:16:02 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 13 Apr 2001 10:16:02 -0400 Subject: [Tutor] Message persistence In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Fri, Apr 13, 2001 at 12:58:36AM -0700 References: Message-ID: <20010413101602.F16516@harmony.cs.rit.edu> On Fri, Apr 13, 2001 at 12:58:36AM -0700, Daniel Yoo wrote: | http://www.pgsql.com | | (Strangely enough, www.pgsql.com seems to be down at the time of this | writing. Check back on it later.) It's up now. There is also http://www.postgresql.org -D From rdsteph@earthlink.net Thu Apr 12 18:58:41 2001 From: rdsteph@earthlink.net (Ron Stephens) Date: Thu, 12 Apr 2001 13:58:41 -0400 Subject: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) Message-ID: <3AD5ECD1.8B050A84@earthlink.net> Sacrilege, I know. ;-))) But sometimesIi wonder why no modern language will let me have a simple goto statement when nothing else will do as well...this is a rhetorical statement only... I have written and am writing a series of similar small programs to help a user choose amongst several different alternatives. The programs mostly use simple weighted averages based on several appropriate criteria with weights, or importance levels. Maybe later, Bayes;-))) On such program is general in nature and lets the user input the options to be decided amongst, and then input the criteria to be used to decide and then the weights for each criteria and then the scores for each option on each criteria. Other options are sort of mini expert systems in which the programmer pre inputs the options and criteria and the scores for each option on each criteria, then the user only enters his individual weights amongst the criteria. These programlets can cover any field in which the programmer is "expert". Now, my problem. I want to create a sort of simple menu to offer the user a choice between the various mini-decisonanalysis programs. So, the user can choose the general program, or else a specific program. Once the user chooses, the appropriate mini-progran should launch. If I had goto statements available, my job would be finished. Just create a simple choice, say 1-10 and when the user inputs 10 the program launches its program. I first considered using a Tkinter menu, but I am still struggling with gui event-driven programs. Also, if I use Tkinter, how would I solve my basic problem to jump to each a specific program when the user chooses its menu item? In other words, I would have to launch a procedural program from a gui event-driven menu program. So, now I consider procedural menu program using raw_input. Still, how do I go to the appropriate sub-program when the user chooses one? With goto's this would be trivial. Now, I consider a nested set of "if " statements that determines which number was chosen, but still how do I "jump" to the correct sub-program??? Even if I define the subprograms as functions even, how do I jump to them??? Any help for hopelessly confused newbie will be greatly appreciated... Ron Stephens From Rob Andrews" Message-ID: <004c01c0c445$3e086920$9600a8c0@Planhouse5> On Useless Python, I have an example script that uses a GOTO-like structure, as well as an example of the next revision which does it without any GOTO behavior. The URL for Useless Python is http://www.lowerstandard.com/python/pythonsource.html and the two scripts are slotmachine.py (the one that acts like it has a GOTO) and zippy.py. Not menu-driven, but the behavior is there. Hope this helps some at all, Rob ----- Original Message ----- From: "Ron Stephens" To: Sent: Thursday, April 12, 2001 12:58 PM Subject: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) > Sacrilege, I know. ;-))) But sometimesIi wonder why no modern language > will let me have a simple goto statement when nothing else will do as > well...this is a rhetorical statement only... > > I have written and am writing a series of similar small programs to help > a user choose amongst several different alternatives. The programs > mostly use simple weighted averages based on several appropriate > criteria with weights, or importance levels. Maybe later, Bayes;-))) > > On such program is general in nature and lets the user input the options > to be decided amongst, and then input the criteria to be used to decide > and then the weights for each criteria and then the scores for each > option on each criteria. Other options are sort of mini expert systems > in which the programmer pre inputs the options and criteria and the > scores for each option on each criteria, then the user only enters his > individual weights amongst the criteria. These programlets can cover any > field in which the programmer is "expert". > > Now, my problem. I want to create a sort of simple menu to offer the > user a choice between the various mini-decisonanalysis programs. So, the > user can choose the general program, or else a specific program. Once > the user chooses, the appropriate mini-progran should launch. > > If I had goto statements available, my job would be finished. Just > create a simple choice, say 1-10 and when the user inputs 10 the program > launches its program. > > I first considered using a Tkinter menu, but I am still struggling with > gui event-driven programs. Also, if I use Tkinter, how would I solve my > basic problem to jump to each a specific program when the user chooses > its menu item? In other words, I would have to launch a procedural > program from a gui event-driven menu program. > > So, now I consider procedural menu program using raw_input. Still, how > do I go to the appropriate sub-program when the user chooses one? With > goto's this would be trivial. Now, I consider a nested set of "if " > statements that determines which number was chosen, but still how do I > "jump" to the correct sub-program??? Even if I define the subprograms as > functions even, how do I jump to them??? > > Any help for hopelessly confused newbie will be greatly appreciated... > > Ron Stephens > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From rdsteph@earthlink.net Thu Apr 12 22:12:03 2001 From: rdsteph@earthlink.net (Ronald D Stephens) Date: Thu, 12 Apr 2001 17:12:03 -0400 Subject: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) References: <3AD5ECD1.8B050A84@earthlink.net> <004c01c0c445$3e086920$9600a8c0@Planhouse5> Message-ID: <001d01c0c395$39f561e0$dc75e9d0@cerf.net> Thanks tremendously!!! I am on my way to your web site right now...! Ron Stephens ----- Original Message ----- From: "Rob Andrews" To: "Ron Stephens" Cc: Sent: Friday, April 13, 2001 2:12 PM Subject: Re: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) > On Useless Python, I have an example script that uses a GOTO-like structure, > as well as an example of the next revision which does it without any GOTO > behavior. The URL for Useless Python is > http://www.lowerstandard.com/python/pythonsource.html and the two scripts > are slotmachine.py (the one that acts like it has a GOTO) and zippy.py. Not > menu-driven, but the behavior is there. > > Hope this helps some at all, > Rob > > ----- Original Message ----- > From: "Ron Stephens" > To: > Sent: Thursday, April 12, 2001 12:58 PM > Subject: [Tutor] Menu to choose programlets: if only python had a GoTO > statement ;-)))) > > > > Sacrilege, I know. ;-))) But sometimesIi wonder why no modern language > > will let me have a simple goto statement when nothing else will do as > > well...this is a rhetorical statement only... > > > > I have written and am writing a series of similar small programs to help > > a user choose amongst several different alternatives. The programs > > mostly use simple weighted averages based on several appropriate > > criteria with weights, or importance levels. Maybe later, Bayes;-))) > > > > On such program is general in nature and lets the user input the options > > to be decided amongst, and then input the criteria to be used to decide > > and then the weights for each criteria and then the scores for each > > option on each criteria. Other options are sort of mini expert systems > > in which the programmer pre inputs the options and criteria and the > > scores for each option on each criteria, then the user only enters his > > individual weights amongst the criteria. These programlets can cover any > > field in which the programmer is "expert". > > > > Now, my problem. I want to create a sort of simple menu to offer the > > user a choice between the various mini-decisonanalysis programs. So, the > > user can choose the general program, or else a specific program. Once > > the user chooses, the appropriate mini-progran should launch. > > > > If I had goto statements available, my job would be finished. Just > > create a simple choice, say 1-10 and when the user inputs 10 the program > > launches its program. > > > > I first considered using a Tkinter menu, but I am still struggling with > > gui event-driven programs. Also, if I use Tkinter, how would I solve my > > basic problem to jump to each a specific program when the user chooses > > its menu item? In other words, I would have to launch a procedural > > program from a gui event-driven menu program. > > > > So, now I consider procedural menu program using raw_input. Still, how > > do I go to the appropriate sub-program when the user chooses one? With > > goto's this would be trivial. Now, I consider a nested set of "if " > > statements that determines which number was chosen, but still how do I > > "jump" to the correct sub-program??? Even if I define the subprograms as > > functions even, how do I jump to them??? > > > > Any help for hopelessly confused newbie will be greatly appreciated... > > > > Ron Stephens > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > From bsass@freenet.edmonton.ab.ca Fri Apr 13 23:05:35 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 13 Apr 2001 16:05:35 -0600 (MDT) Subject: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) In-Reply-To: <3AD5ECD1.8B050A84@earthlink.net> Message-ID: On Thu, 12 Apr 2001, Ron Stephens wrote: <...> > "jump" to the correct sub-program??? Even if I define the subprograms as > functions even, how do I jump to them??? >>> def hi(): ... print "Hi!" ... >>> a = {1:hi} >>> a[1] >>> a[1]() Hi! >>> n=1 >>> a[n]() Hi! >>> so... "goto n" --> a[n]() and... "n rem some code" --> "def fn... ; a[n]=fn" These... menuitems = dict.keys() validmenuitem = dict.has_key(key) ...are handy identities. > Any help for hopelessly confused newbie will be greatly appreciated... Is that the piece you were missing? - Bruce From rdsteph@earthlink.net Fri Apr 13 01:16:58 2001 From: rdsteph@earthlink.net (Ronald D Stephens) Date: Thu, 12 Apr 2001 20:16:58 -0400 Subject: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) References: Message-ID: <000f01c0c3af$0ea40fe0$dc75e9d0@cerf.net> Thanks!!! ----- Original Message ----- From: "Bruce Sass" To: "Ron Stephens" Cc: Sent: Friday, April 13, 2001 6:05 PM Subject: Re: [Tutor] Menu to choose programlets: if only python had a GoTO statement ;-)))) > On Thu, 12 Apr 2001, Ron Stephens wrote: > <...> > > "jump" to the correct sub-program??? Even if I define the subprograms as > > functions even, how do I jump to them??? > > >>> def hi(): > ... print "Hi!" > ... > >>> a = {1:hi} > >>> a[1] > > >>> a[1]() > Hi! > >>> n=1 > >>> a[n]() > Hi! > >>> > > so... "goto n" --> a[n]() > > and... "n rem some code" --> "def fn... ; a[n]=fn" > > These... > menuitems = dict.keys() > validmenuitem = dict.has_key(key) > > ...are handy identities. > > > > Any help for hopelessly confused newbie will be greatly appreciated... > > Is that the piece you were missing? > > > - Bruce > > From pdiaz88@terra.es Sat Apr 14 04:23:50 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 14 Apr 2001 05:23:50 +0200 Subject: [Tutor] FYI Message-ID: <01041405235005.00327@debian> --------------Boundary-00=_QRIRU6T1DIUEDCBG1FDA Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Wow, I didn't know this: Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> a=[1,2,3,4,5,6] >>> b=a >>> a.remove(3) >>> a [1, 2, 4, 5, 6] >>> b [1, 2, 4, 5, 6] >>> c=a[:] >>> a.remove(1) >>> a [2, 4, 5, 6] >>> b [2, 4, 5, 6] >>> c [1, 2, 4, 5, 6] >>> a={} >>> b=a >>> a[1]='1' >>> a {1: '1'} >>> b {1: '1'} >>> c=a[:] Maybe I'm not the only that missed that part on the tutorial, so thats why I post this ;D Moral: lists, dictionaries (and all other objects???) are copies by reference, be careful when you pass them to functions Cheers Pedro - -- /* * Pedro Diaz Jimenez * pdiaz88@terra.es * pdiaz@acm.asoc.fi.upm.es * * La sabiduria me persigue, pero yo soy mas rapido */ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE618LGnu53feEYxlERAmbVAJ91ROLA1sgNnLUeA/1KBeMXGtW32ACg4RiQ GrwS/csYskS7OZ5rMIbxXGc= =RXKv -----END PGP SIGNATURE----- --------------Boundary-00=_QRIRU6T1DIUEDCBG1FDA Content-Type: application/pgp-keys; name="my pgp key" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=public_key.asc LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tClZlcnNpb246IEdudVBHIHYxLjAu NCAoR05VL0xpbnV4KQpDb21tZW50OiBGb3IgaW5mbyBzZWUgaHR0cDovL3d3dy5nbnVwZy5vcmcK Cm1RR2lCRHFjR1pzUkJBREZJYWhOUExrOHN1TWxTMzltOFJxYXRMZ1g0ZE83UFUyRjVwMW9Wdmt5 QjdQYUxRQ3YKRlJFV3dmcmpHcHhBalJueHlaNFRkYUZpMW9DUDQ5NXQ1UjJDZGpQWnUwRWZqc0Vx b3NkTFhrakRzS2wybjRXbwpBZmI2QmFITUpTNVBBREVJMFFmcFpPa0I4T3J1QVpqYS9vR21uNXJU aHlqZ0N4V0hVdUsxQXJtZUd3Q2c3KzlhCm93Zzl3UDFSb2hlUEhKU0RCOWQySFlNRC9pN3oxWDRl ditLOTBMdW1nSndTV2xTY0o3TUVpcDVydzR3cUdPa0sKbEYvQzJuVFlzb1g1Q1ZFbi9wdTdoUk9M L0JXSVl0QmdrTkRhRWpzVnN5Yis0S2pRWGNaVVc1bDNBRGlwV1l4MgpyOXM0c0ZmZVo5bmZoRGNH MGFOWVJjQ05rWVNaL1d4VWtYUzhValZFQUVoa0Z1MUJBKzZVWm1lcTNwS3RKWlRSCitIcUtBLzl6 Um1nVG9uMzZ6dDJxZTllaVI2RHlZMEVwR0VJMGlZK0tZWDZHQy93eGl6ZUhCdzBGVzFlT0VveEYK R2p0eGRCdi9VOXZpN1ZnYXY2YVkrcHI0bGE1cTZqVmFiZTAzWTh5R0RGZUw4ak0rbHF3dzFyenBB QmlHckYrVwpxZ2U2NXpDVWpMM2pKRTUrNXlpK0tjUnlsbGIxT0E3dVhRVHRzUncrVEdxOUR2YWF6 N1F3VUdWa2NtOGdSR2xoCmVpQkthVzFsYm1WNklDaENMazh1Umk1SUxpa2dQSEJrYVdGNk9EaEFk R1Z5Y21FdVpYTStpRllFRXhFQ0FCWUYKQWpxY0dac0VDd29FQXdNVkF3SURGZ0lCQWhlQUFBb0pF Sjd1ZDMzaEdNWlJqMjBBbjJDZTRTL3ZCVHVaRHhuTApXRkJySlJuYzNVZGFBS0RuSVBOUmJ6N3I0 ZGg5QXVCY3BiQ0UxcFEvU0xrQkRRUTZuQm1xRUFRQXI3TzA3RHdzCjV6QWJRdm0xaHdHdGhYS0NI dElJdVdDUGRYL1hrTkc2WnhWL2NYZ3M0TEk0b0FnM0dodHREMkpJRWsyU29WWEUKRk9mL3dJZGRJ RHo3MC85bUlaYXZNdnBSMzFMeEJGU0prMFVwM2NhT3ZUaE05MHdNdHRSaTd0ZzdjZjA0cnJNTQpQ aHk4VDViT0lXL3E1U013WmZmYkpYRDdiQTAvakRMZFE2TUFBd1lELzFlbVN3TlR6T09tTUNaYWRv RUJwS0lFCkhBMzVQMi9tL1NzQ0krcFEvT0tYS1B2dnJRS1RRcVJDY0RhNWFxMzFvU2lUOU01V1E5 NkJsSUdLSFJQV0dwdm0KMDgyMlY3TTlSRjJtWVpQSWZnS2ZUU3ZacFlIemp6K1JNN1B2QkJpQmM5 bDk1dnk3MFNoN1N5d0lGODZIODBBZwpEMGRVSUR0R2xyU0FOaFhqeDRFSmlFWUVHQkVDQUFZRkFq cWNHYW9BQ2drUW51NTNmZUVZeGxIZFZBQ2dqVmhVClk4Q0tmNk1ZWmdRT1I5ZUlETnZUWDBBQW4z ZHdiVzFITHhFRjVPUUtKSXNuZ2wwQlVsWUsKPWQ0UzMKLS0tLS1FTkQgUEdQIFBVQkxJQyBLRVkg QkxPQ0stLS0tLQo= --------------Boundary-00=_QRIRU6T1DIUEDCBG1FDA-- From pdiaz88@terra.es Sat Apr 14 04:32:38 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Sat, 14 Apr 2001 05:32:38 +0200 Subject: [Tutor] FYI In-Reply-To: <01041405235005.00327@debian> References: <01041405235005.00327@debian> Message-ID: <01041405323806.00327@debian> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just a note On Saturday 14 April 2001 05:23, Pedro Diaz Jimenez wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Wow, I didn't know this: > > Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian > GNU/Linux)] on linux2 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > > >>> a=[1,2,3,4,5,6] > >>> b=a > >>> a.remove(3) > >>> a > > [1, 2, 4, 5, 6] > > >>> b > > [1, 2, 4, 5, 6] > > >>> c=a[:] > >>> a.remove(1) > >>> a > > [2, 4, 5, 6] > > >>> b > > [2, 4, 5, 6] > > >>> c > > [1, 2, 4, 5, 6] > > >>> a={} > >>> b=a > >>> a[1]='1' > >>> a > > {1: '1'} > > >>> b > > {1: '1'} > > >>> c=a[:] ^^^^^^^^^^ THIS WONT WORK (hey, they are dictionaries after all, but I had to try it :) > > Maybe I'm not the only that missed that part on the tutorial, so thats why > I post this ;D > > Moral: lists, dictionaries (and all other objects???) are copies by > reference, be careful when you pass them to functions > > Cheers > Pedro > - -- > > /* > * Pedro Diaz Jimenez > * pdiaz88@terra.es > * pdiaz@acm.asoc.fi.upm.es > * > * La sabiduria me persigue, pero yo soy mas rapido > */ > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.4 (GNU/Linux) > Comment: For info see http://www.gnupg.org > > iD8DBQE618LGnu53feEYxlERAmbVAJ91ROLA1sgNnLUeA/1KBeMXGtW32ACg4RiQ > GrwS/csYskS7OZ5rMIbxXGc= > =RXKv > -----END PGP SIGNATURE----- - ---------------------------------------- Content-Type: application/pgp-keys; charset="iso-8859-1"; name="my pgp key" Content-Transfer-Encoding: base64 Content-Description: - ---------------------------------------- - -- /* * Pedro Diaz Jimenez * pdiaz88@terra.es * pdiaz@acm.asoc.fi.upm.es * * La sabiduria me persigue, pero yo soy mas rapido */ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE618TWnu53feEYxlERAr6NAJ9OgQoRtdFhPTBchmfL2MGDbwRj2ACfYJwD CN/IUTHHtv/oIYLK7/I5bXM= =izjV -----END PGP SIGNATURE----- From sheila@thinkspot.net Sat Apr 14 06:55:27 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 13 Apr 2001 22:55:27 -0700 Subject: [Tutor] Python Advocacy Message-ID: <3B02ED26B9@kserver.org> [this was also posted to comp.lang.python earlier this evening.] OK, I apologize for posting questions of this type, YET AGAIN, to this group. But I don't really have the background to answer them (being only a newbie Python programmer), so I'm hoping someone will help me out, here. (I searched at Google Groups and Python.org, but don't feel like I'm finding the essence of the answers...) Basically: The sysadmin/tech at the company where I host my website is thinking of *possibly* dipping his toes into Python. He is considering using it for some upcoming projects, instead of Perl. (I've got an entire Python Advocacy thread, which I started on their web board, here: http://www.aota.net/ubb/Forum3/HTML/001567-1.html ) Anyhow, the sysadmin is still skeptical, and asks the following questions: ------------------(begin quoted questions)------------------------------------ Python does have it's 'methods of programming' benefits over Perl, and a much cleaner syntax... I can write ugly-ugly perl code that does beautiful things - and vice versa... I have a couple questions about Python: 1) It's speed in relation to perl... If figure this will be subjective to the task at hand - but hopefully there is an average overall performance increase/decrease... I would assume lugging around the OOP methodologies will impose overhead which would be pretty much unavoidable... 2) How does it stack up against Perl's regex capabilities, which I rely __heavily__ on for massive processing duties... 3) How well does it perform auto-vivication of complex data structures: e.g.: http://www.perl.com/pub/doc/manual/html/pod/perldsc.html **yes, I know that perl's dereferencing syntax is for masochists, but once mastered - the sadistic side shines through... I have some projects that might fit better into an object oriented way of thinking - however I must be careful of time spent learning 'Yet Another Programming Language' since deadlines could quickly slip... I don't think anyone can argue that Perl is **extremely** powerful and runs the full gamut of simple one-shot scripts - to system level capabilities via syscall()/POSIX interface... Thoughts on the above? ------------------(end quoted questions)------------------------------------ What should I tell him? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From deirdre@deirdre.net Sat Apr 14 07:02:58 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 13 Apr 2001 23:02:58 -0700 (PDT) Subject: [Tutor] Python Advocacy In-Reply-To: <3B02ED26B9@kserver.org> Message-ID: On Fri, 13 Apr 2001, Sheila King wrote: > I have a couple questions about Python: 1) It's speed in relation to > perl... If figure this will be subjective to the task at hand - but > hopefully there is an average overall performance increase/decrease... > I would assume lugging around the OOP methodologies will impose > overhead which would be pretty much unavoidable... OOP is not inherently slower. Late binding is slower than early, no question. However, python is byte compiled, which may offer speed advantages. However, in general, if you're looking for speed, you wouldn't be using perl either. > 2) How does it stack up against Perl's regex capabilities, which I rely > __heavily__ on for massive processing duties... The python regex is modeled after perl. http://www.python.org/doc/current/lib/module-re.html > 3) How well does it perform auto-vivication of complex data structures: e.g.: > http://www.perl.com/pub/doc/manual/html/pod/perldsc.html > **yes, I know that perl's dereferencing syntax is for masochists, but once > mastered - the sadistic side shines through... It's also like flying in bad weather without instruments. :) Python has lists and lists of lists and classes (which can contain their own members). But it doesn't have hashes, nor does it need them. > I have some projects that might fit better into an object oriented way of > thinking - however I must be careful of time spent learning 'Yet Another > Programming Language' since deadlines could quickly slip... Well, here's the thing: perl is essentially awk on steroids. Python is a general-purpose programming language. Do you intend on sysadminning forever? Because shell scripting will limit your career options more than learning a more traditional-style language. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From sheila@thinkspot.net Sat Apr 14 07:20:20 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 13 Apr 2001 23:20:20 -0700 Subject: [Tutor] Python Advocacy In-Reply-To: References: <3B02ED26B9@kserver.org> Message-ID: <51C1D43A9F@kserver.org> On Fri, 13 Apr 2001 23:02:58 -0700 (PDT), Deirdre Saoirse wrote about Re: [Tutor] Python Advocacy: :Python has lists and lists of lists and classes (which can contain their :own members). But it doesn't have hashes, nor does it need them. Wouldn't you consider the Python dictionaries to be like hashes? (OK, I admit it, I really don't know what Perl hashes are...) : FQ sysadmin asked: :> I have some projects that might fit better into an object oriented way of :> thinking - however I must be careful of time spent learning 'Yet Another :> Programming Language' since deadlines could quickly slip... : :Well, here's the thing: perl is essentially awk on steroids. Python is a :general-purpose programming language. Do you intend on sysadminning :forever? Because shell scripting will limit your career options more than :learning a more traditional-style language. Just a note: The sysadmin in question is the OWNER of the web hosting company. He works for himself. FutureQuest, http://www.futurequest.net , is a small web hosting company that has grown, in about three years time, from one community server, to twelve. They offer superlative support, integrity and honesty, and a personal relationship with your hosting company. (Um, did I mention that I like them?) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From deirdre@deirdre.net Sat Apr 14 07:21:14 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Fri, 13 Apr 2001 23:21:14 -0700 (PDT) Subject: [Tutor] Python Advocacy In-Reply-To: <51C1D43A9F@kserver.org> Message-ID: On Fri, 13 Apr 2001, Sheila King wrote: > Wouldn't you consider the Python dictionaries to be like hashes? (OK, > I admit it, I really don't know what Perl hashes are...) No, not really. I mean, you can use them like the simple form of the hash, but perl hashes get intensely evil. > Just a note: The sysadmin in question is the OWNER of the web hosting > company. He works for himself. Yes, but how successful is it if the owner IS the sysadmin? :) I like small companies, don't get me wrong. In a different economy, I'd start one (I was just laid off). > FutureQuest, http://www.futurequest.net , is a small web hosting > company that has grown, in about three years time, from one community > server, to twelve. They offer superlative support, integrity and > honesty, and a personal relationship with your hosting company. (Um, > did I mention that I like them?) Sounds like a great place. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From alan.gauld@freenet.co.uk Sat Apr 14 09:44:22 2001 From: alan.gauld@freenet.co.uk (Alan Gauld) Date: Sat, 14 Apr 2001 08:44:22 +0000 Subject: [Tutor] Functional Programming tutor Message-ID: <3.0.1.32.20010414084422.015de55c@mail.freenet.co.uk> For anyone interested I have uploaded a bnew topic to my tutor: Functional Programming. Its only a brief overview of FP and how Python supports it but covers: map(), reduce(), filter(), lambda and short circuit evaluation as a replacement for if/else I haven't covered the new v2.0 features, partly coz I haven't really used them myself yet! It's at: http://www.crosswinds.net/~agauld Under advanced topics. Feedback, as ever, is welcomed. Alan G From scarblac@pino.selwerd.nl Sat Apr 14 20:54:17 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sat, 14 Apr 2001 21:54:17 +0200 Subject: [Tutor] FYI In-Reply-To: <01041405235005.00327@debian>; from pdiaz88@terra.es on Sat, Apr 14, 2001 at 05:23:50AM +0200 References: <01041405235005.00327@debian> Message-ID: <20010414215417.A5995@pino.selwerd.nl> On 0, Pedro Diaz Jimenez wrote: > Moral: lists, dictionaries (and all other objects???) are copies by > reference, be careful when you pass them to functions Yes, all other objects as well. Assignment is by reference. Python never copies things "by itself". If the object is immutable, like a string or an integer, you'll never notice the difference, of course (except it's faster this way). -- Remco Gerlich From sheila@thinkspot.net Sat Apr 14 21:29:58 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 14 Apr 2001 13:29:58 -0700 Subject: [Tutor] Python Advocacy In-Reply-To: References: <3B02ED26B9@kserver.org> Message-ID: <356116929B2@kserver.org> On Fri, 13 Apr 2001 23:02:58 -0700 (PDT), Deirdre Saoirse wrote about Re: [Tutor] Python Advocacy: :However, python is byte compiled, which may offer speed :advantages. However, in general, if you're looking for speed, you wouldn't :be using perl either. I've been sharing the comments I've received to this post (some were sent by private e-mail, some came from comp.lang.python). In response to Deidre's remarks above, someone responded: PK> How Python being compiled to bytecodes would give it a speed advantage over Perl, which is PK> also compiled to "bytecodes" which are then interpreted, is beyond me. I just am not qualified to respond to these types of remarks. Is anyone here game? He further states: PK> Speed is often not a BIG issue: if a script in Perl takes 1 minute and in Python PK>it took 1 and a half minutes, that's really not going to be an issue most of the time. If a Perl PK> script that runs in 1 minute takes 20 minutes in Python, that may well be an issue: and it's a PK> possibility too. http://home.hiwaay.net/~gbacon/py-vs-pl.html (It's from 1995: I assume Python PK> has gotten considerably faster since then. The point is that it most certainly COULD be that PK> scale of difference, not that it IS.) Then he proposes a challenge: Some task, where the Perl fans will write their idiomatic solution, and the Python fans (me? I don't know that there is anyone else there), will write their solution. And then they'll benchmark it. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From rob@jam.rr.com Sat Apr 14 23:06:59 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Sat, 14 Apr 2001 17:06:59 -0500 Subject: [Tutor] Python Advocacy References: <3B02ED26B9@kserver.org> <356116929B2@kserver.org> Message-ID: <3AD8CA03.CC2E5B39@jam.rr.com> I've just composed two scripts that count from 2 to 10,000. One is in Perl, freshly downloaded from ActiveState, and the other in Python 2.0. Each ran in just about exactly 5 seconds from the command prompt on a Win98 PII-266. Here are the scripts: Python: i = 0 while i <= 10000: i = i+1 print i Perl: $i = 0; while ($i <= 10000){ $i = $i + 1; print "$i\n"; } If anyone feels like an adventure (and knows how to do it), we could devise a number of fair challenges for a Script Olympics of sorts. I've only seen limited and somewhat dated comparisons between languages out there as a general rule, so I'm tempted to come up with a few similar scripts like this and put them head-to-head. (Kinda like *Junkyard Wars*, only digital. 3;-> ) Uselessly yours, Rob Sheila King wrote: > > On Fri, 13 Apr 2001 23:02:58 -0700 (PDT), Deirdre Saoirse > wrote about Re: [Tutor] Python Advocacy: > > :However, python is byte compiled, which may offer speed > :advantages. However, in general, if you're looking for speed, you wouldn't > :be using perl either. > > I've been sharing the comments I've received to this post (some were sent by > private e-mail, some came from comp.lang.python). > > In response to Deidre's remarks above, someone responded: > > PK> How Python being compiled to bytecodes would give it a speed advantage > over Perl, which is > PK> also compiled to "bytecodes" which are then interpreted, is beyond me. > > I just am not qualified to respond to these types of remarks. Is anyone here > game? > > He further states: > > PK> Speed is often not a BIG issue: if a script in Perl takes 1 minute and in > Python > PK>it took 1 and a half minutes, that's really not going to be an issue most > of the time. If a Perl > PK> script that runs in 1 minute takes 20 minutes in Python, that may well be > an issue: and it's a > PK> possibility too. http://home.hiwaay.net/~gbacon/py-vs-pl.html (It's from > 1995: I assume Python > PK> has gotten considerably faster since then. The point is that it most > certainly COULD be that > PK> scale of difference, not that it IS.) > > Then he proposes a challenge: Some task, where the Perl fans will write their > idiomatic solution, and the Python fans (me? I don't know that there is anyone > else there), will write their solution. And then they'll benchmark it. > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From arcege@speakeasy.net Sat Apr 14 23:28:38 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Sat, 14 Apr 2001 18:28:38 -0400 (EDT) Subject: [Tutor] Python Advocacy In-Reply-To: <356116929B2@kserver.org> from "Sheila King" at Apr 14, 2001 01:29:58 PM Message-ID: <200104142228.f3EMSdp03147@dsl254-114-246.nyc1.dsl.speakeasy.net> Sheila King wrote > In response to Deidre's remarks above, someone responded: > > PK> How Python being compiled to bytecodes would give it a speed advantage > over Perl, which is > PK> also compiled to "bytecodes" which are then interpreted, is beyond me. > > I just am not qualified to respond to these types of remarks. Is anyone here > game? Perl is compiled into bytecode as well... but every time the program runs. Python has the ability, like Java, to save the bytecode to a file (.pyc) and use the bytecode files instead (if up-to-date). Beyond that, there will be little that has to be done. But it used to be a big gotcha in the Perl world that all files had to be compiled when loaded. >From what I can tell, newer version of Perl have a "backend bytecode compiler". You need to run a different program, "byteperl", to use the resulting files (which they called "plc" and "pmc" files, taking from Python's "pyc" extension - like they did with most of Perl 5). This is a seperate, developer-initiated step. Since the bytecode needs to be recompiled in Perl every execution, and Python can use already compiled files. Recompiling can be a fairly expensive processes, slowing the program's startup down. But, there is one overriding reason for using Python over Perl. It is summed up well in an excerpt from _Programming Python, 2nd Edition_ by Mark Lutz. ----------------- A Morality Tale of Perl Versus Python (The following was posted recently to the rec.humor.funny Usenet newsgroup by Larry Hastings, and is reprinted here with the original author's permission. I don't necessarily condone language wars; okay?) This has been percolating in the back of my mind for a while. It's a scene from "The Empire Strikes Back," reinterpreted to serve a valuable moral lesson for aspiring programmers. EXTERIOR: DAGOBAH-DAY With Yoda strapped to his back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises - grepping, installing new packages, logging in as root, and writing replacements for two-year- old shell scripts in Python. YODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax.. more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will. LUKE: Is Perl better than Python? YODA: No... no... no. Quicker, easier, more seductive. LUKE: But how will I know why Python is better than Perl? YODA: You will know. When your code you try to read six months from now. ----------------- As someone who has a web hosting company, where his customers require him to maintain his systems, he should be more than just conscious of code maintainability. If he had Perl as his system language, I'd be looking elsewhere for such services. -Arcege FYI: Interestingly, the Perl byte-compile makes a HUGE file relative to the source code: $ echo 'print "Hi there"' > foo.py $ python -c 'import pycompile; pycompile.compile_file("foo.py")' Traceback (innermost last): File "", line 1, in ? ImportError: No module named pycompile $ python -c 'import py_compile; py_compile.compile("foo.py")' $ echo 'print "Hi there\n";' > foo.pl $ perl -MO=Bytecode foo.pl > foo.plc foo.pl syntax OK $ ls -l foo.* -rw-rw-r-- 1 arcege arcege 20 Apr 14 17:59 foo.pl -rw-rw-r-- 1 arcege arcege 159127 Apr 14 17:59 foo.plc -rw-rw-r-- 1 arcege arcege 17 Apr 14 17:58 foo.py -rw-rw-r-- 1 arcege arcege 90 Apr 14 17:58 foo.pyc The Python bytecode is five times the source code, but Perl's is nearly 2000 times larger. Hmmm.... efficient? Don't know. -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From scarblac@pino.selwerd.nl Sun Apr 15 02:55:30 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 15 Apr 2001 03:55:30 +0200 Subject: [Tutor] Python Advocacy In-Reply-To: <356116929B2@kserver.org>; from sheila@thinkspot.net on Sat, Apr 14, 2001 at 01:29:58PM -0700 References: <3B02ED26B9@kserver.org> <356116929B2@kserver.org> Message-ID: <20010415035530.A6272@pino.selwerd.nl> On 0, Sheila King wrote: > PK> How Python being compiled to bytecodes would give it a speed advantage > over Perl, which is > PK> also compiled to "bytecodes" which are then interpreted, is beyond me. > > I just am not qualified to respond to these types of remarks. Is anyone here > game? "PK" is being clever. His point is that Perl is byte-compiled as well. Saying "How this is a difference is beyond me" is c.l.perl.misc talk for "I'm sorry, but you were inaccurate there, there is no difference." > He further states: > > PK> Speed is often not a BIG issue: if a script in Perl takes 1 minute and in > Python > PK>it took 1 and a half minutes, that's really not going to be an issue most > of the time. If a Perl > PK> script that runs in 1 minute takes 20 minutes in Python, that may well be > an issue: and it's a > PK> possibility too. http://home.hiwaay.net/~gbacon/py-vs-pl.html (It's from > 1995: I assume Python > PK> has gotten considerably faster since then. The point is that it most > certainly COULD be that > PK> scale of difference, not that it IS.) > > Then he proposes a challenge: Some task, where the Perl fans will write their > idiomatic solution, and the Python fans (me? I don't know that there is anyone > else there), will write their solution. And then they'll benchmark it. His first point is good. Perl and Python are both slow compared to typically fast languages (say, C). So if you're going to use one, it's not going to matter if one is slightly slower than the other. If one is going to be substantially slower (like a factor 20) then it matters, for that application. >From what I've seen, most huge differences between Perl and Python were caused by incompetence in the slower language. Some idiom in Perl was translated too directly to Python or vice versa. There's often a better way. Still, such a challenge would be reasonable, if it were to use a lot of different problems. I don't know what his challenge was about, url? -- Remco Gerlich From sheila@thinkspot.net Sun Apr 15 03:58:54 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 14 Apr 2001 19:58:54 -0700 Subject: [Tutor] Python Advocacy In-Reply-To: <20010415035530.A6272@pino.selwerd.nl> References: <3B02ED26B9@kserver.org> <356116929B2@kserver.org> <20010415035530.A6272@pino.selwerd.nl> Message-ID: <4B5AC8B0320@kserver.org> On Sun, 15 Apr 2001 03:55:30 +0200, Remco Gerlich wrote about Re: [Tutor] Python Advocacy: :On 0, Sheila King wrote: ...... :"PK" is being clever. His point is that Perl is byte-compiled as well. : :Saying "How this is a difference is beyond me" is c.l.perl.misc talk for :"I'm sorry, but you were inaccurate there, there is no difference." : :> He further states: ...... :> Then he proposes a challenge: Some task, where the Perl fans will write their :> idiomatic solution, and the Python fans (me? I don't know that there is anyone :> else there), will write their solution. And then they'll benchmark it. : :His first point is good. Perl and Python are both slow compared to typically :fast languages (say, C). So if you're going to use one, it's not going to :matter if one is slightly slower than the other. If one is going to be :substantially slower (like a factor 20) then it matters, for that application. : :From what I've seen, most huge differences between Perl and Python were :caused by incompetence in the slower language. Some idiom in Perl was :translated too directly to Python or vice versa. There's often a better way. Yes, this is what I figured. However, it's one thing to say to someone else, "Well, it is my understanding that there isn't that much difference in speed between the two languages." And have them just accept my statement at face value. It is another thing, entirely, to convince them of that. :Still, such a challenge would be reasonable, if it were to use a lot of :different problems. I don't know what his challenge was about, url? Yes, well, I'm warming up to the idea of a good challenge. If the Pythoners from this list want to team up, I think I can find an opposing team of Perl Monks who'd want to take up the challenge. PK didn't suggest any specific task. More like, he was casting about for someone to propose one. Here is the URL where this discussion is taking place: http://www.aota.net/ubb/Forum3/HTML/001567-3.html -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From tbrauch@mindless.com Sun Apr 15 07:02:35 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Sun, 15 Apr 2001 02:02:35 -0400 (EDT) Subject: [Tutor] Python Advocacy In-Reply-To: <20010415035530.A6272@pino.selwerd.nl> References: <20010415035530.A6272@pino.selwerd.nl> Message-ID: <1079.216.68.187.116.987314555.squirrel@titan.centre.edu> Here's my two cents on the subject. A long time ago I learned programming on my Apple IIe based on DOS 3.0 (or was it 3.1?). I learned by looking at the code other people had already written. Then, I changed things to see what the difference was. And, there were never any comments in these programs. Nothing was better than starting a stock market game I had with one million dollars instead of one thousand. Now, I know Python decent enough to be able to accomplish just about anything I want to do with it. I have some knowledge of C/C++ and very little of Perl. I think that I know Python best now because I can look at the code and understand what is happening and what happens if I change something. Even ugly, uncommented code I can usually decipher (although I am still a little fuzzy on pickling and lamda functions). On tests for my Comp Sci class on Python, there were even always questions such as "What is the output of the following code?" That is why I think Python is better, at least to learn, than Perl. Someday I thought I might actually make an attempt at learning Perl for real, but if I can't just look at code and figure things out, it will make learning it a little harder for me. I'm sure Perl has a good quality and if I look hard enough, one day I might find it. However, right now I am spending my time learning some good ol' assembly language. Tim Brauch From cooler12001@yahoo.com Sun Apr 15 10:09:42 2001 From: cooler12001@yahoo.com (Matthews James) Date: Sun, 15 Apr 2001 02:09:42 -0700 (PDT) Subject: [Tutor] To anyone that understands python or tkinter....... Message-ID: <20010415090942.63266.qmail@web11405.mail.yahoo.com> Does anyone have any useless programs that i might beable to mess around with to help me understand this. i can understand most of python but i would like some tkinter programs also __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From Daniel.Kinnaer@Advalvas.be Sun Apr 15 10:47:20 2001 From: Daniel.Kinnaer@Advalvas.be (Daniel Kinnaer) Date: Sun, 15 Apr 2001 11:47:20 +0200 Subject: [Tutor] Python Advocacy In-Reply-To: <4B5AC8B0320@kserver.org> Message-ID: When it comes to testing a language, one has to be very careful. If I remember well, in the "old days" Basic was often compared to Turbo Pascal and Turbo C and the testers used a.o. the Sieve of Erastothenes to make those comparisons. Now, what is interesting in this story is that at some time, there were very optimized Basic-subroutines for the Sieve, which they were running on faster/better PCs as well, thus making Basic "as fast as" Pascal or C ! Let us come up with something honest: - note what a language can do and what a language can't do - test the the common parts (like SMTP, the Sieve, database,...) - use the same hardware and OS for the tests - test with equivalent knowledge (newbie, intermediate, expert) - test the ease of changing the code after a few weeks/months This little list can be extended in many ways, but I guess I summed up the important points, though. Hope to read about these tests pretty soon! Best regards, Daniel From scarblac@pino.selwerd.nl Sun Apr 15 11:02:31 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 15 Apr 2001 12:02:31 +0200 Subject: [Tutor] To anyone that understands python or tkinter....... In-Reply-To: <20010415090942.63266.qmail@web11405.mail.yahoo.com>; from cooler12001@yahoo.com on Sun, Apr 15, 2001 at 02:09:42AM -0700 References: <20010415090942.63266.qmail@web11405.mail.yahoo.com> Message-ID: <20010415120231.A6585@pino.selwerd.nl> On 0, Matthews James wrote: > Does anyone have any useless programs that i might > beable to mess around with to help me understand this. We have a collection of them, at Useless Python, http://www.lowerstandard.com/python/pythonsource.html No guarantees whatsoever about the code, but there is a lot to look at :). You can also search for Python related stuff at Parnassus, http://www.vex.net/parnassus/ Loads of stuff there. And if you get the Python source distribution, there is a directory called "Demos" in it with some good things. -- Remco Gerlich From kstoner@netins.net Sun Apr 15 14:03:58 2001 From: kstoner@netins.net (Katharine Stoner) Date: Sun, 15 Apr 2001 08:03:58 -0500 Subject: [Tutor] ool Message-ID: <000a01c0c5ac$89092aa0$ab52b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0C582.9F92EB00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Is python a completely object orientated language or is it a hybrid? -Cameron ------=_NextPart_000_0007_01C0C582.9F92EB00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi all,
 
Is python a completely object = orientated language=20 or is it a hybrid?
 
-Cameron
 
------=_NextPart_000_0007_01C0C582.9F92EB00-- From rob@jam.rr.com Sun Apr 15 15:28:28 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Sun, 15 Apr 2001 09:28:28 -0500 Subject: [Tutor] ool References: <000a01c0c5ac$89092aa0$ab52b1cf@oemcomputer> Message-ID: <3AD9B00C.F054104D@jam.rr.com> One of the Old Wise Ones may be able to answer in more detail than this, but I can say that while Python is OOP, it is possible to write simple procedural scripts such as: >>> n = 0 >>> while n < 3: print n n = n +1 0 1 2 This is great, because it enables morons such as m'self to draft simple scripts that do stuff until we begin to get the gist of OOP. But OOP runs deep in Python, such that by the time I started to think of coding in OOP I discovered that Python had snuck it in on me in some of the built-in parts. The short story is that you don't have to use OOP to code "hello world", but merely to do this: >>> print "hello world" hello world Hope this helps, Rob > Katharine Stoner wrote: > > Hi all, > > Is python a completely object orientated language or is it a hybrid? > > -Cameron > -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From scarblac@pino.selwerd.nl Sun Apr 15 17:00:34 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 15 Apr 2001 18:00:34 +0200 Subject: [Tutor] ool In-Reply-To: <000a01c0c5ac$89092aa0$ab52b1cf@oemcomputer>; from kstoner@netins.net on Sun, Apr 15, 2001 at 08:03:58AM -0500 References: <000a01c0c5ac$89092aa0$ab52b1cf@oemcomputer> Message-ID: <20010415180034.A7122@pino.selwerd.nl> On 0, Katharine Stoner wrote: > Is python a completely object orientated language or is it a hybrid? I don't think that's a very useful question. Whatever answer we give will immediately wander off into a discussion of what "completely object oriented language" is supposed to mean. And it doesn't actually matter for anything, does it? Everything is an object in Python, including functions, classes, and the module you run things in. But some people insist that to be "completely object oriented", you must be forced to put everything inside class definitions, and that's not the case in Python. So although it uses objects everywhere, you can write lots of Python without ever defining a class. It's not "completely class-oriented". Deciding whether this means "yes", "no" or "maybe" is left as an excercise for the reader. Regardless of that, in my opinion the way Python does it is the Right Thing, and that does matter :-). Putting a main() function inside some dummy class, supposedly for being more OO, is just stupid. -- Remco Gerlich From britt_green@hotmail.com Mon Apr 16 02:03:05 2001 From: britt_green@hotmail.com (Britt Green) Date: Sun, 15 Apr 2001 18:03:05 -0700 Subject: [Tutor] Name Error? Message-ID: Hello All, Whenever I run this code, I get a Name Error: import string class Parser: def __init__(self): pass def isVerb(self, firstWord): verbs = ['go', 'get', 'drop', 'open', 'close', 'look', 'throw', 'lock', 'unlock'] if firstWord in verbs: return 1 else: return 0 def parseWords(self): phrase = raw_input("-->") splitPhrase = string.split(phrase) if isVerb(splitPhrase[0]): print splitPhrase[0] + " is a verb!" else: print splitPhrase[0] + " is not a verb!" if __name__ == "__main__": myParser = Parser() myParser.parseWords() And the error I'm getting is this: Traceback (innermost last): File "C:/Python20/Code/parser.py", line 25, in ? myParser.parseWords() File "C:/Python20/Code/parser.py", line 18, in parseWords if isVerb(splitPhrase[0]) == 1: NameError: There is no variable named 'isVerb' What am I doing wrong? _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From rick@niof.net Mon Apr 16 02:15:51 2001 From: rick@niof.net (Rick Pasotto) Date: Sun, 15 Apr 2001 21:15:51 -0400 Subject: [Tutor] Name Error? In-Reply-To: ; from britt_green@hotmail.com on Sun, Apr 15, 2001 at 06:03:05PM -0700 References: Message-ID: <20010415211551.A26067@tc.niof.net> On Sun, Apr 15, 2001 at 06:03:05PM -0700, Britt Green wrote: > Hello All, > > Whenever I run this code, I get a Name Error: > > import string > > class Parser: > def __init__(self): > pass > > def isVerb(self, firstWord): > verbs = ['go', 'get', 'drop', 'open', 'close', 'look', 'throw', > 'lock', > 'unlock'] > if firstWord in verbs: > return 1 > else: > return 0 > > def parseWords(self): > phrase = raw_input("-->") > splitPhrase = string.split(phrase) > if isVerb(splitPhrase[0]) if self.isVerb(splitPhrase[0]): > print splitPhrase[0] + " is a verb!" > else: > print splitPhrase[0] + " is not a verb!" > > if __name__ == "__main__": > myParser = Parser() > myParser.parseWords() > > And the error I'm getting is this: > > Traceback (innermost last): > File "C:/Python20/Code/parser.py", line 25, in ? > myParser.parseWords() > File "C:/Python20/Code/parser.py", line 18, in parseWords > if isVerb(splitPhrase[0]) == 1: > NameError: There is no variable named 'isVerb' > > What am I doing wrong? Two things. There was no colon after your if (possibly a typo in the email) and since the function is defined within a class you need to qualify it with either the class name or the instance. -- "A moral code impossible to practice, a code that demands imperfection or death, has taught you to dissolve all ideas in fog, to permit no firm definitions, to regard any concept as approximate & any rule of conduct as elastic, to hedge on any principle, to compromise on any value, to take the middle of any road." -- Ayn Rand Rick Pasotto email: rickp@telocity.com From cooler12001@yahoo.com Mon Apr 16 05:38:17 2001 From: cooler12001@yahoo.com (Matthews James) Date: Sun, 15 Apr 2001 21:38:17 -0700 (PDT) Subject: [Tutor] Help with Tkinter's Entry or whatever else im wrong about Message-ID: <20010416043817.23322.qmail@web11407.mail.yahoo.com> This is what i have. I just started really learning Tkinter so beware it might not be pretty. ####################################################### from Tkinter import * def do(): entry.get() for times in range(0,13): label = Label(root,text=times+'X'+entry) label.pack() root = Tk() entry = Entry(root,input) entry.pack() button = Button(root,text='Times',command=do) button.pack() ###################################################### I'm wanting to know how to get entry to get a number or text but it always says that entry is .027483 and that number is always different each time i run the program Thanks Very Much James Matthews __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From sheila@thinkspot.net Mon Apr 16 06:50:23 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 15 Apr 2001 22:50:23 -0700 Subject: [Tutor] Listing files in directories recursively Message-ID: <42313A62FE@kserver.org> OK, so I'm practicing a bit using os and os.path modules. I think I will try to list all the files under a given root directory, recursively going through all of its subdirectories and listing their contents, too. Shouldn't be too hard? OK, here's my script in its current version: ----------------------------------------------------- import sys, os '''print all the files in a directory and recursively in all directories below the given starting directory''' def listFiles(dir): basedir = dir print "Files in ", os.path.abspath(dir), ": " subdirlist = [] for item in os.listdir(dir): if os.path.isfile(item): print item else: subdirlist.append(os.path.join(basedir, item)) for subdir in subdirlist: listFiles(subdir) startdir = sys.argv[1] #starting dir passed as argument to script print "startdir is ", startdir listFiles(startdir) ----------------------------------------------------- Here is the command line call to the script: ----------------------------------------------------- E:>python E:\programs\LearningPython\recursfilelist.py C:\temp\ ----------------------------------------------------- Here is the output: ----------------------------------------------------- startdir is C:\temp\ Files in C:\temp : Files in C:\temp\Courses : Files in C:\temp\Courses\APCS : Files in C:\temp\Courses\APCS\KARELWIN : Files in C:\temp\Courses\APCS\KARELWIN\BC450RTL.DLL : Traceback (most recent call last): File "E:\programs\LearningPython\recursfilelist.py", line 20, in ? listFiles(startdir) File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles listFiles(subdir) File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles listFiles(subdir) File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles listFiles(subdir) File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles listFiles(subdir) File "E:\programs\LearningPython\recursfilelist.py", line 10, in listFiles for item in os.listdir(dir): WindowsError: [Errno 3] The system cannot find the path specified: 'C:\\temp\\Courses\\APCS\\KARELWIN\\BC450RTL.DLL' ----------------------------------------------------- Now, I don't know why it isn't listing any of the files. The listFiles function clearly tests if item is a file, using os.path.isfile, and if so, should list the file before calling the recursion to the next directory level below. But it isn't listing any of the files. Moreover, it's considering a .dll file to be a directory? I've been playing with this for two days, now. (Actually, my original idea was to add up the sizes of all the files, but I've put the file sizes on hold, until I can just list the blasted files.) I must be doing something simple wrong. Does anyone see what it is? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Mon Apr 16 06:59:54 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 15 Apr 2001 22:59:54 -0700 Subject: [Tutor] Listing files in directories recursively In-Reply-To: <42313A62FE@kserver.org> References: <42313A62FE@kserver.org> Message-ID: <4ACB4746F6@kserver.org> OK, I solved my problem already. Here is what I changed: def listFiles(dir): basedir = dir print "Files in ", os.path.abspath(dir), ": " subdirlist = [] for item in os.listdir(dir): if os.path.isfile(item): print item else: subdirlist.append(os.path.join(basedir, item)) for subdir in subdirlist: listFiles(subdir) Changed the line above: print "Files in ", os.path.abspath(dir), ": " To print "Files in ", dir, ": " I don't figure that had anything to do with the error, but putting abspath on it wouldn't really help. Plus, I've found that abspath just really tacks on the path for the current working directory, which isn't really what I want, here. The key change, was changing this line: if os.path.isfile(item): To this: if os.path.isfile(os.path.join(basedir,item)): The files systems are kind of tricky to work with, because the files must be clearly indicated, by full path. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sun, 15 Apr 2001 22:50:23 -0700, Sheila King wrote about [Tutor] Listing files in directories recursively: :OK, so I'm practicing a bit using os and os.path modules. I think I will try :to list all the files under a given root directory, recursively going through :all of its subdirectories and listing their contents, too. Shouldn't be too :hard? : :OK, here's my script in its current version: : :----------------------------------------------------- :import sys, os : :'''print all the files in a directory and recursively :in all directories below the given starting directory''' : :def listFiles(dir): : basedir = dir : print "Files in ", os.path.abspath(dir), ": " : subdirlist = [] : for item in os.listdir(dir): : if os.path.isfile(item): : print item : else: : subdirlist.append(os.path.join(basedir, item)) : for subdir in subdirlist: : listFiles(subdir) : :startdir = sys.argv[1] #starting dir passed as argument to script :print "startdir is ", startdir :listFiles(startdir) :----------------------------------------------------- : :Here is the command line call to the script: : :----------------------------------------------------- :E:>python E:\programs\LearningPython\recursfilelist.py C:\temp\ :----------------------------------------------------- : : :Here is the output: :----------------------------------------------------- :startdir is C:\temp\ :Files in C:\temp : :Files in C:\temp\Courses : :Files in C:\temp\Courses\APCS : :Files in C:\temp\Courses\APCS\KARELWIN : :Files in C:\temp\Courses\APCS\KARELWIN\BC450RTL.DLL : :Traceback (most recent call last): : File "E:\programs\LearningPython\recursfilelist.py", line 20, in ? : listFiles(startdir) : File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles : listFiles(subdir) : File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles : listFiles(subdir) : File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles : listFiles(subdir) : File "E:\programs\LearningPython\recursfilelist.py", line 16, in listFiles : listFiles(subdir) : File "E:\programs\LearningPython\recursfilelist.py", line 10, in listFiles : for item in os.listdir(dir): :WindowsError: [Errno 3] The system cannot find the path specified: :'C:\\temp\\Courses\\APCS\\KARELWIN\\BC450RTL.DLL' :----------------------------------------------------- : :Now, I don't know why it isn't listing any of the files. The listFiles :function clearly tests if item is a file, using os.path.isfile, and if so, :should list the file before calling the recursion to the next directory level :below. But it isn't listing any of the files. Moreover, it's considering a :.dll file to be a directory? : :I've been playing with this for two days, now. (Actually, my original idea was :to add up the sizes of all the files, but I've put the file sizes on hold, :until I can just list the blasted files.) : :I must be doing something simple wrong. Does anyone see what it is? From parth.malwankar@wipro.com Mon Apr 16 07:11:24 2001 From: parth.malwankar@wipro.com (Parth Malwankar) Date: Mon, 16 Apr 2001 11:41:24 +0530 Subject: [Tutor] unicode support in 're' Message-ID: <20010416114124.A19244@wipro.wipsys.sequent.com> Hello, I wish to find the occurance of a pattern in a unicode text file. I tried using re for this purpose. ##### expr = re.compile(u'^\.', re.UNICODE|re.M) x = expr.split(textfromfile) ##### but this doesnt seem to split on the character specified. Am I doing something wrong. It is possible to convert the read lines into ascii and then run the match. But I was wondering if there is any direct way to do this. Thanks in advance, Parth From van@lindbergs.org Mon Apr 16 07:37:32 2001 From: van@lindbergs.org (VanL) Date: Mon, 16 Apr 2001 00:37:32 -0600 Subject: [Tutor] Listing files in directories recursively References: <42313A62FE@kserver.org> <4ACB4746F6@kserver.org> Message-ID: <3ADA932C.B99EAC62@lindbergs.org> For what its worth, there is already a builtin that will do most of the work for you: >>> import os >>> >>> def walker(arg, dirname, names): ... print arg, dirname, names ... >>> os.path.walk('.', walker, 'Please show me:') Please show: . ['Addons'] Please show: .\Addons ['avl-2.0.tar.gz', 'egenix-mx-base-2.0.0.win32-py2.0.exe', 'egenix-mx-commercial-2.0.0.win32-py2.0.exe', 'eopl.tar.gz', 'HTMLgen', 'HTMLge n.tar', 'NumPy', 'PyOpenGL-1.5.6.win32-py2.0.exe', 'win32all-138.exe', 'wxPython -2.2.1-Py20b1.EXE'] hth, VanL From dyoo@hkn.eecs.berkeley.edu Mon Apr 16 09:42:23 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 16 Apr 2001 01:42:23 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Mon, 16 Apr 2001, wong chow cheok wrote: > hai daniel. sorry to bother you like this. but i cannot seem to grasp what > you did. i know it works but i do not know how to edit it as i cannot > understand all the signs you used. it has really confused me. > > [\w.#@&=\-_~/;:\n]+? # a bunch of stuff that can span > >lines, > > # nongreedily, > > (?=([,:\-.!?;]? # that shouldn't contain any > > # trailing punctutation, > > (\s+|$))) # spaces, or eol character. > > ''' > > i cannot seem to get all the lines here. i know that the first line after > the colon(:) is the rest of the url after the HTTP but what is the others > for and what is the function of the ?. sorry for being a bore but your help > is really appreciated. thanks a lot. Let's take a closer look at some of those lines: [\w.#@&=\-_~/;:\n]+? # a bunch of stuff that can span lines, This particular regular expression says a few things. It's defining a "character class" between the two brackets '[' and ']'. A character class says that all of the enclosed "characters" should be considered the same --- the reason this is useful is because the plus sign character afterwards means that we want to have at least one or more of those characters. For example: [abcd]+ will match "aabbcc" "dabbac", "cad", but will reject "raccoon", "wizard", or anything that doesn't consist of the letters 'a', 'b', 'c', or 'd'. Let's take a closer look at the characters within the class. There's a "metacharacter" called '\w' that stands for all word-like characters. By this, we're telling Python to recognize the letters "A" through "Z" and digits "0" through "9" as perfectly good characters. Also, I need to say that the symbols '.', '#', '&', and the rest could be part of an URL. So, for example: python.org/doc/Intros.html will match with the above, because each character will match with something within our character class. The question mark '?' is a little harder to explain. It's called the "nongreedy" modifier, and it takes a few examples to see why it's necessary. Take a look: ### >>> re.search('begin.*end', 'let us begin and end this.').group(0) 'begin and end' >>> re.search('begin.*end', 'begin and end this, and end it.').group(0) 'begin and end this, and end' ### Notice that when we try matching with this regular expression, that it tries to grab as many characters as it can. Intuitively, we can see that the search is "greedy". To make it nongreedy, we need to give our regular expression some doubt, which is symbolized by the question mark: ### >>> re.search('begin.*?end', 'let us begin and end this, and end it now').group(0) 'begin and end' ### The question mark modifies the matching to tell Python to try matching without so much greediness, to try matching as quickly as possible. I actually adapted the code from Tom Christensen's nice "Far More than Everything You Wanted To Know About Regexps" article on perl.org. He explains regular expressions a lot better than me; take a look at his article: http://language.perl.com/all_about/regexps.html Hope this helps! From cooler12001@yahoo.com Mon Apr 16 10:07:37 2001 From: cooler12001@yahoo.com (Matthews James) Date: Mon, 16 Apr 2001 02:07:37 -0700 (PDT) Subject: [Tutor] Need help with Tkinter Entry() Message-ID: <20010416090737.48228.qmail@web11405.mail.yahoo.com> This is what i have ####################################################### from Tkinter import * def do(): ENTRY = entry.get() for times in range(0,13): E = '%d X %d = %d' % (ENTRY,times,ENTRY*times) label = Label(root,text=E) label.pack() root = Tk() entry = Entry(root) entry.pack() button = Button(root,text='Times',command=do) button.pack() ###################################################### I dont know how to get the entry to get the number or text it always say that it needs a integer. but when i call it in the python shell it says that it is .274467 or something like that and this number is always different when i run the program James __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ From cooler12001@hotmail.com Mon Apr 16 10:22:02 2001 From: cooler12001@hotmail.com (James Matthews) Date: Mon, 16 Apr 2001 09:22:02 -0000 Subject: [Tutor] Need help with Tkinter Entry().. Message-ID: ####################################################### from Tkinter import * def do(): ENTRY = entry.get() for times in range(0,13): E = '%d X %d = %d' % (ENTRY,times,ENTRY*times) label = Label(root,text=E) label.pack() root = Tk() entry = Entry(root) entry.pack() button = Button(root,text='Times',command=do) button.pack() ###################################################### I dont know how to get the entry to get the number or text it always say that it needs a integer. but when i call it in the python shell it says that it is .274467 or something like that and this number is always different when i run the program James _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Mon Apr 16 17:31:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 16 Apr 2001 09:31:33 -0700 (PDT) Subject: [Tutor] Need help with Tkinter Entry().. In-Reply-To: Message-ID: On Mon, 16 Apr 2001, James Matthews wrote: > > ####################################################### > from Tkinter import * > > def do(): > ENTRY = entry.get() > for times in range(0,13): > E = '%d X %d = %d' % (ENTRY,times,ENTRY*times) > label = Label(root,text=E) > label.pack() > > root = Tk() > entry = Entry(root) > entry.pack() > button = Button(root,text='Times',command=do) > button.pack() > ###################################################### > > I dont know how to get the entry to get the number or > text it always say that it needs a integer. but > when i call it in the python shell it says that it is > .274467 or something like that and this number is > always different when i run the program On the whole, your program looks ok. There are a few nitpicky things we'll need to fix to get things working: 1. The Entry doesn't have an initial value --- it starts off empty by default --- so let's check within your do() to see if the entry has a good value in there. There are a few ways to do this (some with exception handling), but for now, let's just check that the user's not putting in an empty string. 2. Also, the value that you get out of entry.get() is a string, so you'll want to coerce it into an integer form, because arithmetic on strings doesn't work. For example: ### >>> "3" + "4" ## "Addition" between two strings is concatenation '34' >>> "3" * "4" Traceback (innermost last): File "", line 1, in ? TypeError: can't multiply sequence with non-int >>> int("3") * int("4") ## Converting strings to ints first 12 ### 3. Don't forget to do a mainloop() at the end of your program, to tell Python that the gui's constructed and we're ready to listen to the user. The reason this is necessary is because, if we get to the bottom of the program, Python assumes that we're done with everything, and quits too prematurely. Here's a version of the code with the corrections: ### from Tkinter import * def do(): ENTRY = entry.get().strip() if ENTRY == "": return ## Do nothing if we don't have a string NUMENTRY = int(ENTRY) for times in range(0,13): E = '%d X %d = %d' % (NUMENTRY, times, NUMENTRY*times) label = Label(root,text=E) label.pack() root = Tk() entry = Entry(root) entry.pack() button = Button(root, text='Times', command=do) button.pack() mainloop() ### Hope this helps! From alan.gauld@bt.com Mon Apr 16 22:57:21 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Apr 2001 22:57:21 +0100 Subject: [Tutor] Python Advocacy Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F2@mbtlipnt02.btlabs.bt.co.uk> > own members). But it doesn't have hashes, nor does it need them. Umm, I think a dictionary is a hash? It may not be identical to a Perl hash but it is a hash none the less. In particular Python can do associative arrays - Vital to any Perler and would wipe Python out of consideration if you suggest otherwise! Otherwise I agree :-) Alan G From deirdre@deirdre.net Mon Apr 16 23:06:08 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 16 Apr 2001 15:06:08 -0700 (PDT) Subject: [Tutor] Python Advocacy In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F2@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Mon, 16 Apr 2001 alan.gauld@bt.com wrote: > > > own members). But it doesn't have hashes, nor does it need them. > > Umm, I think a dictionary is a hash? In the simple form, yes. There are peculiar things you can do with perl hashes that are not so easily replicated in Python. > It may not be identical to a Perl hash but it is a hash none the less. > In particular Python can do associative arrays - Vital to any Perler > and would wipe Python out of consideration if you suggest otherwise! -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From alan.gauld@bt.com Mon Apr 16 23:12:52 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Apr 2001 23:12:52 +0100 Subject: [Tutor] To anyone that understands python or tkinter....... Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F3@mbtlipnt02.btlabs.bt.co.uk> > Does anyone have any useless programs that i might > beable to mess around with to help me understand this. > > i can understand most of python but i would like some > tkinter programs also Try starting with my event driven programming tutor: http://www.crosswinds.net/~agauld/tutevent.htm Then move to the next topic: GUI Programming with Tkinter http://www.crosswinds.net/~agauld/tutgui.htm Then try the Case Study http://www.crosswinds.net/~agauld/tutcase.htm which concludes with a Tkinter version of the grammar counter. Finally there is an OO Games Framework and a GUI implementation of hangman on the Useless Python site. There is a link to it on this page: http://www.crosswinds.net/~agauld/tutintro.htm HTH, Alan G PS If you find lamdas difficult you could also look at the explanation here: http://www.crosswinds.net/~agauld/tutfctnl.htm From arthur.watts@gbst.com Mon Apr 16 23:11:15 2001 From: arthur.watts@gbst.com (Arthur Watts) Date: Tue, 17 Apr 2001 08:11:15 +1000 Subject: [Tutor] Python and Speed Message-ID: <1CDB101F0CB6D311882F0000F8063924033A786A@aquarius.bne.star.com.au> Guys, I noticed that the Advocacy thread contained reference to the question of Perl's assumed speed advantage over Python. As someone who championed Python's acceptance for use in implementing a replacement for the shell scripts which support our bread-and-butter application, I was keen to quantify the difference. I was particularly keen to see how well Python went with a common shell operation - reading in a file, sorting it and then writing the new file. Lets assume we have two text files, each containing variable length strings (I think I used Linux HOW-TO's, from memory). We want to merge the files and sorted the merged result by ASCII collating sequence. The resulting 'newmaster' contained over 70,000 lines of text. Trivial stuff for a shell script : cat master.txt > /tmp/temp.txt cat trans.txt >> /tmp/temp.txt cat /tmp/temp.txt | sort | uniq > newmaster.txt I wrote code in C, Perl and Python (each using the default 'quicksort' algorithm to sort the data), and ran tests on a Celeron 566 (SuSe Linux), SPARC Enterprise 65000 (Solaris 2.6) and Compaq Alphaserver 4100. Under Solaris and Linux, Python actually outperformed Perl on each machine, with the Sun machine (much bigger than the Alpha..) achieving the best overall result. The C implementation took a total of 1.10 , Python 2.07 and Perl 2.21 secs. I'd like to make the following points : 1. These are just numbers - I'm sure that better programmers than myself could achieve better numbers for their chosen language. I doubt whether the Perl or Python code would ever begin to approach the C execution times without some sort of C extension. 2. The vast majority of the elapsed time, in each case, was spent in the performing file ops ('User'), whilst 'System' times are what the serious benchmarkers seem to focus on. For the record, they were .05, .11 and .15 respectively. 3. I tried to use the same algorithmic approach for each language, and relied on the default 'quicksort' approach. 4. If you read almost any treatise on sorting, you will see that different sort algorithms suit different patterns of data. I believe that Perl uses deep recursion in its version of the quicksort algorithm, which would give it an advantage with smaller text files. I think I prefer the approach taken by the C and Python guys. For me, the big win was not in any perceived speed advantage : it was the fact that I achieved my goal with 32 lines of Python (over 45 linees of Perl and way too many lines of C...). Here are the comparisons between the Perl sort code and the Python sort code : Perl : sub quicksort ($) { my ($arrayref) = @_; @$arrayref = sort { $a cmp $b } @$arrayref; return $arrayref; } Python list1.sort() # sort the list of strings In defence of Perl, we also use it for a variety of purposes, and it is a fantastically powerful language with a wealth of available modules. However, after mucking around for a while with the C and Perl solutions, I was stunned by how quickly the Python solution fell into my lap. Debugging it would also be a lot more bearable at 3am ... And, yes, we are now using Python as part of our revenue raiser ! Finally, I would like this to provide the catalyst for the Perl and Python communities to each agree on a set of common tasks which we could use for benchmark testing each new release of these interpreters. I know that Guido has never denied that Python is slower, but I'd like to be able to quantify it against something a little less trivial than my own manufactured example. Enjoy, Arthur Arthur Watts Software Engineer GBST Automation Global Banking & Securities Transactions Telephone + 61 7 3331 5555 mailto: arthur.watts@gbst.com www.gbst.com From alan.gauld@bt.com Mon Apr 16 23:17:39 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Apr 2001 23:17:39 +0100 Subject: [Tutor] ool Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F4@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0C6C3.0C709100 Content-type: text/plain; charset="iso-8859-1" Is python a completely object orientated language or is it a hybrid? Does a completely OO language exist? I've never seen one. If one did exist would it be a good thing? Why? I think Smalltalk comes closest to completely OO but you can still write what is effectively non OO code in it. Python is a hybrid that allows you to use imperative, OO or functional styles of programming as appropriate. Alan G ------_=_NextPart_001_01C0C6C3.0C709100 Content-type: text/html; charset="iso-8859-1"
Is python a completely object orientated language or is it a hybrid?
Does a completely OO language exist? I've never seen one.
If one did exist would it be a good thing? Why?
 
I think Smalltalk comes closest to completely OO but you
can still write what is effectively non OO code in it.
 
Python is a hybrid that allows you to use imperative, OO or
functional styles of programming as appropriate.
 
Alan G
------_=_NextPart_001_01C0C6C3.0C709100-- From alan.gauld@bt.com Mon Apr 16 23:21:50 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Apr 2001 23:21:50 +0100 Subject: [Tutor] ool Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F5@mbtlipnt02.btlabs.bt.co.uk> > ...It's not "completely class-oriented". Amen to that. I have taken to calling Java a class oriented language rather than on object oriented because it relies so heavily on static class functions. This annoys my Java programming colleagues enormously ;-) Alan G > From alan.gauld@bt.com Mon Apr 16 23:27:29 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Apr 2001 23:27:29 +0100 Subject: [Tutor] Help with Tkinter's Entry or whatever else im wrong a bout Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F6@mbtlipnt02.btlabs.bt.co.uk> > def do(): > entry.get() multiplier = int(entry.get()) # need a variable > for times in range(0,13): > label = Label(root,text=times+'X'+entry) label = Label(root,text=str(times)+'X'+multipler) Alternatively delete the entry.get() line and just do: label = Label(root,text=str(times)+'X'+entry.get()) HTH, Alan G From deirdre@deirdre.net Mon Apr 16 23:26:34 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 16 Apr 2001 15:26:34 -0700 (PDT) Subject: [Tutor] ool In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F5@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Mon, 16 Apr 2001 alan.gauld@bt.com wrote: > > ...It's not "completely class-oriented". > > Amen to that. I have taken to calling Java a class > oriented language rather than on object oriented > because it relies so heavily on static class functions. I don't like Java, but mostly because it's a language designed for beginners (ostensibly) that doesn't really seem to encourage good programming practices. > This annoys my Java programming colleagues enormously You mean like my claim that Java is "C++ with training wheels"? :) -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From alan.gauld@bt.com Mon Apr 16 23:34:33 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 16 Apr 2001 23:34:33 +0100 Subject: [Tutor] Need help with Tkinter Entry() Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F7@mbtlipnt02.btlabs.bt.co.uk> Further to my earlier reply... > def do(): > ENTRY = entry.get() Better but you are reading a string not a number - it just looks like a number! > for times in range(0,13): > E = '%d X %d = %d' % (ENTRY,times,ENTRY*times) Much better once you make ENTRY into a number > when i call it in the python shell it says that it is > .274467 or something like that and this number is Thats the underlying Tcl/Tk represntation of your widget. The number is basically the memory address and the '.' is the root widget. If you had put your entry within a frame youd have gotten something like: .274467.123456 You don't need to know about any of that except to recognise it as Tcl/Tk internals... Alan G From dsh8290@rit.edu Mon Apr 16 23:48:16 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 16 Apr 2001 18:48:16 -0400 Subject: [Tutor] Python and Speed In-Reply-To: <1CDB101F0CB6D311882F0000F8063924033A786A@aquarius.bne.star.com.au>; from arthur.watts@gbst.com on Tue, Apr 17, 2001 at 08:11:15AM +1000 References: <1CDB101F0CB6D311882F0000F8063924033A786A@aquarius.bne.star.com.au> Message-ID: <20010416184816.C16@harmony.cs.rit.edu> On Tue, Apr 17, 2001 at 08:11:15AM +1000, Arthur Watts wrote: | Guys, | | I noticed that the Advocacy thread contained reference to the | question of Perl's assumed speed advantage over Python. As someone who | championed Python's acceptance for use in implementing a replacement for the | shell scripts which support our bread-and-butter application, I was keen to | quantify the difference. I was particularly keen to see how well Python went | with a common shell operation - reading in a file, sorting it and then | writing the new file. ... | 3. I tried to use the same algorithmic approach for each language, | and relied on the default 'quicksort' approach. I think that this is a 'defect' in your benchmark. I have seen several examples of perl (or other) programmers on c.l.py saying that Python is horribly slow in comparison to the other language. Then the gurus on c.l.py reworked their python code using more pythonic idioms and data structures and the speed became comparable. I think that for the benchmark to be "better" (by some definition of better ) the most natural approach (algorithm, data structures) for each language must be used, even those approaches are almost certainly quite different. ... | For me, the big win was not in any perceived speed advantage : it | was the fact that I achieved my goal with 32 lines of Python (over 45 linees | of Perl and way too many lines of C...). Here are the comparisons between | the Perl sort code and the Python sort code : That's the goal and the win. ... | Finally, I would like this to provide the catalyst for the Perl and | Python communities to each agree on a set of common tasks which we could use | for benchmark testing each new release of these interpreters. I know that | Guido has never denied that Python is slower, but I'd like to be able to | quantify it against something a little less trivial than my own manufactured | example. I don't really agree that a "standard" benchmark would be a real advantage because developers have a tendency to optimize to the benchmark then. Sure, the numbers on the benchmark may look great, but what about the rest of the uses? The following perl is faster than the python below it : (barring any careless mistakes; yes I know the python version will add an extra newline to every line , I'm not sure about the perl version) for () { print ; } for line in sys.stdin.readlines() : print line because (according to Tim Peters, and others) perl heavily optimizes file io at the cost of portability (supposedly they toy with the C FILE structs directly rather than use the C API) while python focuses more on being portable and thread-safe. Other differences include readlines sucks everything into RAM at once, xreadlines (in >=2.1 would be better). For another example, see the archives regarding counting words in a file. I posted a perl sample (didn't make it to the list) that I wrote for a class, then later translated to python. The perl version was (insignificantly, IMO) faster than the python version. Both produced identical results. I posted several observations about the testbed and the python code. The python version is on the Useless pages. I did have ~3 bugs in the perl version, but I don't remember what they are (the prof said so when I got my grade). The python version probably has the same 3 errors . I rewrote that script and measured the times in response to someone having trouble with performance of his solution to a similar problem. The original post used several classes and nested linear traversals of lists. He said it took over 15 minutes (or so) for his version to count a 2M (or something) file. The version I posted used different data structures and took less than 2 minutes (at most, I don't remember exactly now). -D From dsh8290@rit.edu Mon Apr 16 23:52:37 2001 From: dsh8290@rit.edu (D-Man) Date: Mon, 16 Apr 2001 18:52:37 -0400 Subject: [Tutor] ool In-Reply-To: ; from deirdre@deirdre.net on Mon, Apr 16, 2001 at 03:26:34PM -0700 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F5@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010416185237.D16@harmony.cs.rit.edu> On Mon, Apr 16, 2001 at 03:26:34PM -0700, Deirdre Saoirse wrote: | On Mon, 16 Apr 2001 alan.gauld@bt.com wrote: | | > > ...It's not "completely class-oriented". | > | > Amen to that. I have taken to calling Java a class | > oriented language rather than on object oriented | > because it relies so heavily on static class functions. | | I don't like Java, but mostly because it's a language designed for | beginners (ostensibly) that doesn't really seem to encourage good | programming practices. I didn't think Java was really designed (s/designed/suited/) for beginners. I think a 'beginner' language wouldn't make the beginner learn how to deal with exceptions to do IO. I have a friend who recently started studying CS in college. He has a bad professor (or so he describes) who is teaching java and awt. This is a beginning course. According to my friend they haven't learned a whole lot and always struggle through the projects. The only thing he really knows about exceptions is that putting "throws Exception" on the end of 'main' will let the prog compile and run. | > This annoys my Java programming colleagues enormously | | You mean like my claim that Java is "C++ with training wheels"? :) :-) There are a few conveniences Java has over C++, but I don't see a huge advantage; especially not compared to python. -D From scarblac@pino.selwerd.nl Tue Apr 17 00:13:04 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 17 Apr 2001 01:13:04 +0200 Subject: [Tutor] Python Advocacy In-Reply-To: ; from deirdre@deirdre.net on Mon, Apr 16, 2001 at 03:06:08PM -0700 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D6F2@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010417011304.A9337@pino.selwerd.nl> On 0, Deirdre Saoirse wrote: > On Mon, 16 Apr 2001 alan.gauld@bt.com wrote: > > > > > > own members). But it doesn't have hashes, nor does it need them. > > > > Umm, I think a dictionary is a hash? > > In the simple form, yes. There are peculiar things you can do with perl > hashes that are not so easily replicated in Python. Ooh, didn't know that. Examples? -- Remco Gerlich From deirdre@deirdre.net Tue Apr 17 00:21:45 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 16 Apr 2001 16:21:45 -0700 (PDT) Subject: [Tutor] Python Advocacy In-Reply-To: <20010417011304.A9337@pino.selwerd.nl> Message-ID: On Tue, 17 Apr 2001, Remco Gerlich wrote: > > In the simple form, yes. There are peculiar things you can do with perl > > hashes that are not so easily replicated in Python. > > Ooh, didn't know that. Examples? You know, I knew someone was going to ask that and I knew I wouldn't have an example handy. I remember someone showing me some clever (and unreadable) Perl code a couple years ago. Unfortunately, I'm not enough of a Perl masochist to try and replicate it. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From deirdre@deirdre.net Tue Apr 17 00:27:59 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Mon, 16 Apr 2001 16:27:59 -0700 (PDT) Subject: [Tutor] ool In-Reply-To: <20010416185237.D16@harmony.cs.rit.edu> Message-ID: On Mon, 16 Apr 2001, D-Man wrote: > | I don't like Java, but mostly because it's a language designed for > | beginners (ostensibly) that doesn't really seem to encourage good > | programming practices. > > I didn't think Java was really designed (s/designed/suited/) for > beginners. I think a 'beginner' language wouldn't make the beginner > learn how to deal with exceptions to do IO. Oh, I agree -- but it's being touted as though it was. Other examples: try "hello world" as standardly taught in Java. > I have a friend who recently started studying CS in college. He has a > bad professor (or so he describes) who is teaching java and awt. > This is a beginning course. According to my friend they haven't > learned a whole lot and always struggle through the projects. The > only thing he really knows about exceptions is that putting "throws > Exception" on the end of 'main' will let the prog compile and run. ::snort:: That's really useful. I really think my older statement really was spot-on: "Java is Cobol 2.0." > There are a few conveniences Java has over C++, but I don't see a huge > advantage; especially not compared to python. I agree, which is why I use Python. The biggest advantage Java seems to have over C++ is database access and multilanguage support (esp. 2-byte characters). The downside is that JVMs are, on average, as stable as the high elements of the periodic table. Not to mention the arguing over GUI libraries and so on. Which means that Java is uniquely suited for cron and batch jobs that access databases -- which is pretty much what Cobol has been historically used for. -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From kojo@hal-pc.org Tue Apr 17 01:40:25 2001 From: kojo@hal-pc.org (Kojo) Date: Mon, 16 Apr 2001 19:40:25 -0500 Subject: [Tutor] ool In-Reply-To: References: <20010416185237.D16@harmony.cs.rit.edu> Message-ID: <5.0.2.1.0.20010416192831.01f13fc8@Pop3.norton.antivirus> At 04:27 PM 4/16/2001 -0700, you wrote: >I really think my older statement really was spot-on: "Java is Cobol 2.0." Ouch!! I'm no great lover of Java, but man, that even hurts MY feelings. :-) As a recovering Accounting PhD student who has always been interested in Computers (I'm leaving the Accounting PhD program to start work on a Comp Sci BS in the fall) , someone's always trying to talk to be about COBOL. Puh-Leaze!! Didn't we learn anything from Y2K? My research area was Accounting Info Systems, and when people found that out, too many of them wanted to dazzle me with the fact that they'd heard of COBOL, not knowing that it was like telling a neurosurgeon that they knew what leeches were... Ok, maybe that's a bit extreme, but I think you get my drift. "Java is Cobol 2.0." I may have to use that Deirdre. I've already used your sig about "deadlines swooshing by" in a conversation You (and Douglas Adams)were cited, or course. :-) **************************** Kojo Idrissa kojo@hal-pc.org **************************** From van@lindbergs.org Tue Apr 17 02:15:58 2001 From: van@lindbergs.org (VanL) Date: Mon, 16 Apr 2001 19:15:58 -0600 Subject: [Tutor] Python and Speed References: <1CDB101F0CB6D311882F0000F8063924033A786A@aquarius.bne.star.com.au> <20010416184816.C16@harmony.cs.rit.edu> Message-ID: <3ADB994E.A608D978@lindbergs.org> > D-Man said: > I think that this is a 'defect' in your benchmark. I have seen > several examples of perl (or other) programmers on c.l.py saying that > Python is horribly slow in comparison to the other language. > > Then the gurus on c.l.py reworked their python code using more > pythonic idioms and data structures and the speed became comparable. > I think that for the benchmark to be "better" (by some definition of > better ) the most natural approach (algorithm, data structures) > for each language must be used, even those approaches are almost > certainly quite different. > > ...... > | Finally, I would like this to provide the catalyst for the Perl and > | Python communities to each agree on a set of common tasks which we could use > | for benchmark testing each new release of these interpreters. I know that > | Guido has never denied that Python is slower, but I'd like to be able to > | quantify it against something a little less trivial than my own manufactured > | example. I would be very interested in this sort of test. You mention that using identical data structures would be detrimental to the integrity of the test -- definately so. What about a standard set of tasks, running the gamut from system administration tasks to database to algorithms and scientific computing. May the best implementation in each language win. Then a weighted average of all the scores could determine (both within task groups, and overall) a "fastest" language. Moreover, if the set of tests were broad enough, the temptation for the language writers to "write to the test" would be diminished, in favor of better overall efficiency. Scores could be weighted, for example, to count consistent scores more heavily. I think this sort of idea would be interesting for another reason, as well: the scripts themselves would be very instructive for aspiring programmers as a example "best" implementation of a particular task. Hmmmm..... From sheila@thinkspot.net Tue Apr 17 02:59:25 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 16 Apr 2001 18:59:25 -0700 Subject: [Tutor] Python and Speed In-Reply-To: <3ADB994E.A608D978@lindbergs.org> References: <1CDB101F0CB6D311882F0000F8063924033A786A@aquarius.bne.star.com.au> <20010416184816.C16@harmony.cs.rit.edu> <3ADB994E.A608D978@lindbergs.org> Message-ID: <6487B72077@kserver.org> On Mon, 16 Apr 2001 19:15:58 -0600, VanL wrote about Re: [Tutor] Python and Speed: :I think this sort of idea would be interesting for another reason, as well: the :scripts themselves would be very instructive for aspiring programmers as a example :"best" implementation of a particular task. : :Hmmmm..... This is a good point, as well. I'm restricted in my available time, but I'm the one who started this whole thing (at least on this Tutor list), and I'm willing to do organizational type stuff, and put up a web page with results and all of the code afterwards. I'm also willing to help write code, but as a Python newbie, don't know how helpful that will be. Maybe I could write code for one or two of the suggested tests, and then post it for critiquing. Should we take this off-list to some other forum/discussion area? I'm afraid it may not be on-topic for this list. I'm willing to host a temporary mailing list, for the duration of such a project. If enough people respond, indicating interest, I'll start working on this, and try to drum up some Perl programmers to write the other code. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From alan.gauld@bt.com Tue Apr 17 17:10:29 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 17 Apr 2001 17:10:29 +0100 Subject: [Tutor] Python and Speed Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D6FC@mbtlipnt02.btlabs.bt.co.uk> > :I think this sort of idea would be interesting for another > reason, as well: the :scripts themselves would be > very instructive for aspiring programmers as a example > :"best" implementation of a particular task. I'm not sure that's true. The problem with these kinds of tasks is that the rapidly degenerate to a performance fine tuning exercise. Finely tuned code is rarely typical of what you write day to day, nor is it usually very maintainable. So proving that "tweaked till it squeaks" Python is as fast as "tweaked till it squeaks" Perl just doesn't say a lot about day to day tasks. Maybe a better idea is to point to the production code that is written in each language - Majordomo vv Mailman for example. Zope vv ??? A fastCGI site using modPerl and one using modPython. Or compare both top Java - in most cases either Perl or Python will be faster than Java on a JVM! FWIW THe Ruby web site carries a comment somewhere that their code falls about midway between Perl and Python in speed, but retains the readability of Python. Alan G. From bobhicks@adelphia.net Tue Apr 17 17:41:16 2001 From: bobhicks@adelphia.net (Robert Hicks) Date: Tue, 17 Apr 2001 12:41:16 -0400 Subject: [Tutor] Python and Speed In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D6FC@mbtlipnt02.btlabs.bt.co.uk> Message-ID: > FWIW THe Ruby web site carries a comment somewhere that > their code falls about midway between Perl and Python > in speed, but retains the readability of Python. Personally, I would say the Ruby site is wrong. Ruby is NOT a readable as Python for a newbie. I looked into it as an Admin that wanted to bridge the gap. From Ruby Central FAQ: "Ruby's syntax and design philosophy are heavily influenced by Perl." "If you like Perl, you will like Ruby and be right at home with its syntax." "Ruby is much more complex than Python but its features, for the most part, hang together well." From van@lindbergs.org Tue Apr 17 18:00:02 2001 From: van@lindbergs.org (Van Edward Lindberg) Date: Tue, 17 Apr 2001 11:00:02 -0600 Subject: [Tutor] Ruby v. Python? Message-ID: <3ADC7692.49FE734E@lindbergs.org> Sorry if this is slilghtly OT... I just read the Ruby send-up on slashdot. I checked out the Ruby website, it looks all right. Someone made the comment that Ruby looks like the mythical April Fool's Day "Parrot" language. From an initial perusal, that appears to be so. Has anyone had any direct experience with Ruby? How does it compare v. Python? VanL From st_hickey@hotmail.com Wed Apr 18 09:22:19 2001 From: st_hickey@hotmail.com (Stevenson Hickey) Date: Wed, 18 Apr 2001 01:22:19 -0700 Subject: [Tutor] Win98 appears as NT Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0C7A6.038329C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable There are certain inconsistencies that I have come across in running = Py21.b. I don't know if these are in earlier versions. Apparently my Windows 98 system is identified by Python as an 'NT' = system. Below is some of the data: import sys >>> print sys.builtin_module_names ('__builtin__', '__main__', '_codecs', '_locale', '_weakref', 'array', = 'audioop', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'errno', = 'exceptions', 'gc', 'imageop', 'imp', 'marshal', 'math', 'md5', = 'msvcrt', 'new', 'nt', 'operator', 'pcre', 'regex', 'rgbimg', 'rotor', = 'sha', 'signal', 'strop', 'struct', 'sys', 'thread', 'time', = 'xreadlines') (notice that 'nt' appears, but not 'dos') I also got this: >>> os.path.__name__ 'ntpath' And also: >>> os.path (I do have a dospath.py file in my library.) In the Faqw of 1998, it says: "There are (at least) three kinds of = modules in Python: 1) modules written in Python (.py); 2) modules = written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc); 3) = modules written in C and linked with the interpreter; to get a list of = these, type:=20 import sys print sys.builtin_module_names" This came about when I was investigating os.py in relationship to the = os.path.walk method. =20 Any clues as to why my system seems to be referred to as 'nt'? Is it possible that I made some mistake upon installation of py21? If = so, where would I look to make changes? Stevenson Hickey --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.248 / Virus Database: 121 - Release Date: 4/11/2001 ------=_NextPart_000_0007_01C0C7A6.038329C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
There are certain inconsistencies that I have come across in = running=20 Py21.b.  I don't know if these are in earlier versions.
 
Apparently my Windows 98 system is identified by Python as an 'NT'=20 system.  Below is some of the data:
 
import sys
>>> print=20 sys.builtin_module_names
('__builtin__', '__main__', '_codecs', = '_locale',=20 '_weakref', 'array', 'audioop', 'binascii', 'cPickle', 'cStringIO', = 'cmath',=20 'errno', 'exceptions', 'gc', 'imageop', 'imp', 'marshal', 'math', 'md5', = 'msvcrt', 'new', 'nt', 'operator', 'pcre', 'regex', 'rgbimg', 'rotor', = 'sha',=20 'signal', 'strop', 'struct', 'sys', 'thread', 'time', = 'xreadlines')

(notice that 'nt' appears, but not 'dos')
 
I also got this:
 
>>> os.path.__name__
'ntpath'
 
And also:
 
>>> os.path
<module 'ntpath' from=20 'c:\python21\lib\ntpath.pyc'>
 
(I do have a dospath.py file in my library.)
 
In the Faqw of 1998, it says: "There are (at least) three kinds of = modules=20 in Python: 1) modules written in Python (.py); 2) modules written in C = and=20 dynamically loaded (.dll, .pyd, .so, .sl, etc); 3) modules written in C = and=20 linked with the interpreter; to get a list of these, type:=20
    import sys
    print=20 sys.builtin_module_names"
 
This came about when I was investigating os.py in relationship to = the=20 os.path.walk method. 
 
Any clues as to why my system seems to be referred to as = 'nt'?
 
Is it possible that I made some mistake upon installation of = py21?  If=20 so, where would I look to make changes?
 
Stevenson Hickey
 

---
Outgoing mail is certified Virus Free.
Checked by AVG = anti-virus system (http://www.grisoft.com).
Version: = 6.0.248 /=20 Virus Database: 121 - Release Date: 4/11/2001
------=_NextPart_000_0007_01C0C7A6.038329C0-- From wong_chow_cheok@hotmail.com Wed Apr 18 10:31:19 2001 From: wong_chow_cheok@hotmail.com (wong chow cheok) Date: Wed, 18 Apr 2001 17:31:19 +0800 Subject: [Tutor] (no subject) Message-ID: hello ya all. i have a problem again. still trying to extract url from the web. but now i need to extract multiple url and not just one. i ahve tried using findall() but all i get is the 'http' and nothing else. http_url=r''' (http|https|ftp|wais|telnet|mailto|gopher|file) : [\w.#@&=\,-_~/;:\n]+ (?=([,.:;\-?!\s])) ''' http_re=re.compile(http_url, re.X) p=http_re.findall("http:\\www.hotmial.com abnd http:\\www.my.com") print p this was very helpful and very confusing. after reading more on it i am only more confused with all the simbols. (?=...) what does this mean. i read it up but still am having trouble using it and underdtanding how it works. and i still cannot extract more than one url. tried many other ways but this is the only one with a bit of progress(the 'http') well sorry for being so muxh trouble but your help is appreciated. thank you _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From tim.one@home.com Wed Apr 18 11:10:55 2001 From: tim.one@home.com (Tim Peters) Date: Wed, 18 Apr 2001 06:10:55 -0400 Subject: [Tutor] Win98 appears as NT In-Reply-To: Message-ID: [Stevenson Hickey] > There are certain inconsistencies that I have come across in running > Py21.b. I don't know if these are in earlier versions. > > Apparently my Windows 98 system is identified by Python as an 'NT' > system. Below is some of the data: Na, if you do >>> import sys >>> sys.platform I bet it displays 'win32' And it should do that on Win95, Win98, ME, NT, *and* Win2000. The sys.nt module you're seeing is an internal implementation detail. You should never import it directly! The os module (which you should import instead) tries to provide (as far as possible) the same functions across operating systems, and it's an internal implementation detail that, on Win32 systems, the os module happens to be largely *implemented*, under the covers, by a module named "nt". Under other operating systems the os module is implemented by modules with names other than nt. It would have been better had the nt module been named, say, win32 instead -- but it wasn't, and it's too late to change now. Don't get discouraged by it! This is a very hairy part of the implementation, because cross-platform portability is difficult for us to provide, and the details are both complicated and not at all worth *your* time to learn. > ... > I also got this: > > >>> os.path.__name__ > 'ntpath' > > And also: > > >>> os.path > Sure. Those are expected on all Win32 platforms -- you're just confusing yourself by looking at stuff nobody else ever looks at . > (I do have a dospath.py file in my library.) And if you were running a pure DOS (*not* Windows!) system, os.path would be implemented via dospath.py instead. > Is it possible that I made some mistake upon installation of py21? I don't think it's possible for you to make a mistake when running the installer we ship . click-on-'next'-until-it-stops-ly y'rs - tim From alan.gauld@bt.com Wed Apr 18 18:29:10 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 18 Apr 2001 18:29:10 +0100 Subject: [Tutor] Python and Speed Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D703@mbtlipnt02.btlabs.bt.co.uk> > > their code falls about midway between Perl and Python > > in speed, but retains the readability of Python. > Personally, I would say the Ruby site is wrong. Ruby is NOT a > readable as Python for a newbie. Its not far off. I'd I looked into it as an Admin that wanted to > bridge the gap. > > From Ruby Central FAQ: > > "Ruby's syntax and design philosophy are heavily influenced by Perl." > "If you like Perl, you will like Ruby and be right at home with its > syntax." > "Ruby is much more complex than Python but its features, for the most > part, hang together well." > > From alan.gauld@bt.com Wed Apr 18 18:39:49 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 18 Apr 2001 18:39:49 +0100 Subject: [Tutor] Python and Speed Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D704@mbtlipnt02.btlabs.bt.co.uk> Sorry for the false send, I'll try again :-( > > their code falls about midway between Perl and Python > > in speed, but retains the readability of Python. > > Personally, I would say the Ruby site is wrong. Ruby is NOT a > readable as Python for a newbie. I don't think it's far off. Ruby is certainly much closer to Python than it is to Perl syntactically - despite the comments you cited. I think those are designed to attract Perl programmers! What Ruby does have is, like Perl, builtin regular expressions. That makes most regex activities noticably faster than Python. Otherwise I don't honestly see any difference in general programming between Ruby and Python. I do find Perl is usually slightly faster than either, but only a few percent. Certainly not the hundreds of percent claimed by the Perl zealots. > "Ruby's syntax and design philosophy are heavily > influenced by Perl." I don't understand this comment, other than as sales pitch. Ruby is readable, Perl isn't. In fact about the only Perl like syntax I've seen is the addition of '@' in front of instance variables class Foo def initialize(i) .... @var = i end ... end f = Foo.new(42) Doesn't look much like Perl to me! In fact it looks rather a lot like Python... :-) > "Ruby is much more complex than Python but its > features, for the most part, hang together well." It has a more complete and consistent object model but otherwise I wouldn't say it was much more "complex". Alan g From alan.gauld@bt.com Wed Apr 18 18:44:00 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 18 Apr 2001 18:44:00 +0100 Subject: [Tutor] Ruby v. Python? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D705@mbtlipnt02.btlabs.bt.co.uk> > Has anyone had any direct experience with Ruby? How does it > compare v. Python? See my previous post. My editor wanted me to do a version of my book in Ruby so I downloaded it and had a play. Theres a big potential market for Ruby books but I decided that Ruby just takes the OOP concept too far to make it suitable as a first language. You can't do hardly anything in Ruby without running into objects, and to try to explain those without any prior knowledge is too hard for a simple soul like me! But as a general purpose scripting language it has promise. If I hadn't already seen Python I would probably be a Ruby programmer by now... I'll probably continue playing with it for a while yet. Its infinitely better than perl! Alan G. From bobhicks@adelphia.net Wed Apr 18 18:53:05 2001 From: bobhicks@adelphia.net (Robert Hicks) Date: Wed, 18 Apr 2001 13:53:05 -0400 Subject: [Tutor] Python and Speed In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D704@mbtlipnt02.btlabs.bt.co.uk> Message-ID: Well if I had to choose between Ruby and Perl...I would take Ruby for readability. Python is the first VHL that I can look at the code and say "hey, I know where that is going". Hmmm...maybe I could write "Learn to program using Ruby".... : ) Just kidding! I use the language I like...Python. - Bob - the comments quoted about Ruby were from a Ruby site...not my opinion. From shaleh@valinux.com Wed Apr 18 18:58:42 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 18 Apr 2001 10:58:42 -0700 (PDT) Subject: [Tutor] flatten a tuple Message-ID: So I have a tuple: ((0, 1, 2), (3,4,5), (6,7,8)) and I want to get: (6,7,8,3,4,5,0,1,2) i.e. reverse the container, then get the contents in order. The tuple in question happens to be a 3x3, but this need not affect the answer. From alan.gauld@bt.com Wed Apr 18 18:53:43 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 18 Apr 2001 18:53:43 +0100 Subject: [Tutor] (no subject) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D706@mbtlipnt02.btlabs.bt.co.uk> > more confused with all the simbols. (?=...) what does this > mean. Its a regular expression. There are several web sites that explain how they work. The one you have is a fairly complex one but the principles are straightforward. If you can, goo to informIT.com (you';ll need to register), and do a searchh for my name and you should find an article on regular expressions that explains their use. [ Or you could buy my book which contains the same info in a chapter :-) ] > the only one with a bit of progress(the 'http') Not sure but the fact you used \\ instead of // after the http might have confused things? Alan G. From scarblac@pino.selwerd.nl Wed Apr 18 19:11:11 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 18 Apr 2001 20:11:11 +0200 Subject: [Tutor] flatten a tuple In-Reply-To: ; from shaleh@valinux.com on Wed, Apr 18, 2001 at 10:58:42AM -0700 References: Message-ID: <20010418201111.A22891@pino.selwerd.nl> On 0, Sean 'Shaleh' Perry wrote: > So I have a tuple: > > ((0, 1, 2), (3,4,5), (6,7,8)) > > and I want to get: > > (6,7,8,3,4,5,0,1,2) > > i.e. reverse the container, then get the contents in order. > > The tuple in question happens to be a 3x3, but this need not affect the answer. In general it's easier to convert tuples to lists for this sort of thing, then convert them back at the end. That's because it's easier to build things if they're mutable. def flatten_reverse_tuple(tuples_tuple): result = [] tuples_list = list(tuples_tuple) tuples_list.reverse() for tup in tuples_list: result.extend(tup) return tuple(result) It doesn't completely flatten it, so that you won't get a big flat tuple if you have a tuple of tuples of tuples (I love saying that) but you didn't define what should happen in that case anyway. -- Remco Gerlich From deirdre@deirdre.net Wed Apr 18 19:13:22 2001 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Wed, 18 Apr 2001 11:13:22 -0700 (PDT) Subject: [Tutor] flatten a tuple In-Reply-To: Message-ID: On Wed, 18 Apr 2001, Sean 'Shaleh' Perry wrote: > So I have a tuple: > > ((0, 1, 2), (3,4,5), (6,7,8)) > > and I want to get: > > (6,7,8,3,4,5,0,1,2) > > i.e. reverse the container, then get the contents in order. > > The tuple in question happens to be a 3x3, but this need not affect the answer. Well, tuples being immutable, use an intermediary list. I was in the middle of typing a longer answer, but Remco's clearly more awake than I am.... -- _Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From shaleh@valinux.com Wed Apr 18 19:25:13 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 18 Apr 2001 11:25:13 -0700 (PDT) Subject: [Tutor] flatten a tuple In-Reply-To: <20010418201111.A22891@pino.selwerd.nl> Message-ID: > > In general it's easier to convert tuples to lists for this sort of thing, > then convert them back at the end. That's because it's easier to build > things if they're mutable. > > def flatten_reverse_tuple(tuples_tuple): > result = [] > tuples_list = list(tuples_tuple) > tuples_list.reverse() > for tup in tuples_list: > result.extend(tup) > return tuple(result) > > It doesn't completely flatten it, so that you won't get a big flat tuple if > you have a tuple of tuples of tuples (I love saying that) but you didn't > define what should happen in that case anyway. > hmm, so much list conversion )-: guess I will store them as lists. BTW, list.extend() requires a list too, so it should have been result.extend(list(tup)). From scarblac@pino.selwerd.nl Wed Apr 18 19:35:35 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Wed, 18 Apr 2001 20:35:35 +0200 Subject: [Tutor] flatten a tuple In-Reply-To: ; from shaleh@valinux.com on Wed, Apr 18, 2001 at 11:25:13AM -0700 References: <20010418201111.A22891@pino.selwerd.nl> Message-ID: <20010418203535.A22934@pino.selwerd.nl> On 0, Sean 'Shaleh' Perry wrote: > BTW, list.extend() requires a list too, so it should have been > result.extend(list(tup)). It can take a sequence, I tested that. >>> x=[] >>> x.extend((1,2,3)) >>> x [1, 2, 3] Hmm. Grumble. Writing *this* post, I dug into the actual docs. http://www.python.org/doc/current/lib/typesseq-mutable.html s.extend(x) Same as s[len(s):len(s)] = x (2) (2) Raises an exception when x is not a list object. The extend() method is experimental and not supported by mutable sequence types other than lists. Well, it does not raise an exception when used with a tuple! But since the lib ref says it's illegal, it may disappear at any point :-(. I *hate* things that work although it is by accident. When you're coding Python and suspect that something works, you're going to test it in the interpreter. You're not going to dig into the references :-(. And s[len(s):len(s)] = x does give the exception. Ah well. Just another reason to use lists in the first place :-). -- Remco Gerlich From arcege@speakeasy.net Wed Apr 18 19:36:19 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Wed, 18 Apr 2001 14:36:19 -0400 (EDT) Subject: [Tutor] flatten a tuple In-Reply-To: from "Sean 'Shaleh' Perry" at Apr 18, 2001 10:58:42 AM Message-ID: <200104181836.f3IIaJ101424@dsl254-114-246.nyc1.dsl.speakeasy.net> Sean 'Shaleh' Perry wrote > > So I have a tuple: > > ((0, 1, 2), (3,4,5), (6,7,8)) > > and I want to get: > > (6,7,8,3,4,5,0,1,2) > > i.e. reverse the container, then get the contents in order. > > The tuple in question happens to be a 3x3, but this need not affect the answer. How about: def reverse_flatten(a): if not a: return () # force to a tuple, just to make sure return tuple(a[-1]) + reverse_flatten(a[:-1]) The function will take any sequence and return a tuple. It will not completely flatten the given sequence, just the top level. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From dsh8290@rit.edu Wed Apr 18 19:39:42 2001 From: dsh8290@rit.edu (D-Man) Date: Wed, 18 Apr 2001 14:39:42 -0400 Subject: [Tutor] flatten a tuple In-Reply-To: ; from shaleh@valinux.com on Wed, Apr 18, 2001 at 10:58:42AM -0700 References: Message-ID: <20010418143942.A17879@harmony.cs.rit.edu> On Wed, Apr 18, 2001 at 10:58:42AM -0700, Sean 'Shaleh' Perry wrote: | So I have a tuple: | | ((0, 1, 2), (3,4,5), (6,7,8)) | | and I want to get: | | (6,7,8,3,4,5,0,1,2) | | i.e. reverse the container, then get the contents in order. | | The tuple in question happens to be a 3x3, but this need not affect | the answer. Reversing is easy : def reverse_tuple( t ) : l = list( t ) l.reverse() return tuple( l ) maybe you could save (execution) time and leave it as a list? import types def flatten( coll ) : """ Take a linear collection (currently only handles tuple and list properly) and return a tuple containing all the elements. Any sub-tuple/list will be "flattened". """ # the result, as a list res_l = [] for item in col : # here is where Lisp is a bit better, or the new adapter stuff # would be _really_ useful # # # If the item is a list/tuple, recursively flatten it, then # add all that stuff to the result list. # # Otherwise it is an "atom" (see Lisp for a definition), # append it to the result list. # if type( item ) == types.ListType or type( item ) == types.TupleType : res_l.extend( flatten( item ) ) else : res_l.append( item ) return tuple( res_l ) print flatten( reverse( ((0, 1, 2), (3,4,5), (6,7,8)) ) ) Double check, then thoroughly test this :-). -D From shaleh@valinux.com Wed Apr 18 21:21:37 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Wed, 18 Apr 2001 13:21:37 -0700 (PDT) Subject: [Tutor] flatten a tuple In-Reply-To: <20010418203535.A22934@pino.selwerd.nl> Message-ID: On 18-Apr-2001 Remco Gerlich wrote: > On 0, Sean 'Shaleh' Perry wrote: >> BTW, list.extend() requires a list too, so it should have been >> result.extend(list(tup)). > > It can take a sequence, I tested that. > >>>> x=[] >>>> x.extend((1,2,3)) >>>> x > [1, 2, 3] > > Hmm. Grumble. Writing *this* post, I dug into the actual docs. > http://www.python.org/doc/current/lib/typesseq-mutable.html > > s.extend(x) Same as s[len(s):len(s)] = x (2) > > (2) Raises an exception when x is not a list object. The extend() method is > experimental and not supported by mutable sequence types other than > lists. > > Well, it does not raise an exception when used with a tuple! But since the > lib ref says it's illegal, it may disappear at any point :-(. > it did raise an exception under 1.5.2. From Hans.Beernink@UCHSC.edu Wed Apr 18 21:58:03 2001 From: Hans.Beernink@UCHSC.edu (Hans.Beernink@UCHSC.edu) Date: Wed, 18 Apr 2001 14:58:03 -0600 Subject: [Tutor] python on OS-X Message-ID: has anyone successfully compiled py2.1 on MacOS-X? and while we're on the topic, why didnt python come preinstalled like pearl/java/tcl/etc.etc.etc.???? seems like some lobbying needs to be done with apple! thanks, htb ___________________________________________ Hans T.H. Beernink, Ph.D. Department of Biochemistry and Molecular Genetics University of Colorado Health Science Center 4200 E. 9th Ave Campus Box B121 Denver CO 80262 tel. 303.315.7547 FAX 303.315.8215 Hans.Beernink@UCHSC.edu From dyoo@hkn.eecs.berkeley.edu Wed Apr 18 22:34:21 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 18 Apr 2001 14:34:21 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Wed, 18 Apr 2001, wong chow cheok wrote: > hello ya all. i have a problem again. still trying to extract url from the > web. but now i need to extract multiple url and not just one. i ahve tried > using findall() but all i get is the 'http' and nothing else. Hmm... I have to take a look at the findall() documentation... (http://python.org/doc/current/lib/Contents_of_Module_re.html) "findall(pattern, string) Return a list of all non-overlapping matches of pattern in string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result." Ah, ok. What they mean by "group" is anything surrounded by parentheses. In regular expressions, a pair of parentheses form a group that can be treated as a single thing. If we look at the regular expression, we can see that there's parentheses around the "http|https|ftp|..." stuff. findall() is a bit sensitive towards groups: if it sees them, it will think that the groups are all we are interested it, which explains why we're getting only the "http" part of an url. We'll need to put the whole url regular expression in one large group, to get findall() to work properly: ### http_url=r''' ( (http|https|ftp|wais|telnet|mailto|gopher|file) : [\w.#@&=\,-_~/;:\n]+ ) (?=([,.:;\-?!\s])) ''' ### Just to clarify: the url above has three groups: the first is the one that encloses the whole regular expression. The second surrounds all the protocol types (http/https...). Finally, the last is called the lookahead group, which I'll have to skip: I need to think about it a little more. (Also, there's some bugs in the regular expression itself that doesn't let it find urls perfectly... whoops!) Let's see if this sorta works: ### >>> http_re.findall("http://www.hotmail.com abnd http://www.my.com") [('http://www.hotmail.com', 'http', ' '), ('http://www.my', 'http', '.')] ### So it almost works, but there's bugs in the regular expression that need to be fixed. I'm not quite as certain that the lookahead (?=...) is doing the right thing; I'll need to look at it later. > this was very helpful and very confusing. after reading more on it i am only > more confused with all the simbols. (?=...) what does this mean. i read it Regular expressions are meant to be useful for computers --- they're not really meant for humans, so don't worry if the symbols are confusing: they take a bit of practice to figure out what's happening. OReilly publishes a book called "Mastering Regular Expressions" which I've heard is really good if you're trying to learn regular expressions. Take a look to see if it's useful for you. Good luck! From dyoo@hkn.eecs.berkeley.edu Wed Apr 18 22:51:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 18 Apr 2001 14:51:37 -0700 (PDT) Subject: [Tutor] flatten a tuple In-Reply-To: Message-ID: On Wed, 18 Apr 2001, Sean 'Shaleh' Perry wrote: > So I have a tuple: > > ((0, 1, 2), (3,4,5), (6,7,8)) > > and I want to get: > > (6,7,8,3,4,5,0,1,2) > > i.e. reverse the container, then get the contents in order. Reversal isn't too bad; I think that flattening is the more interesting problem. One way to do this flattening is with a recursive definition: To flatten a thing: 1. Trying to flatten a non-tuple should return that thing in a flat tuple. For example, flatten(42) should give us the tuple (42,). If we're at this point, the thing must be a tuple: 2. If the tuple's empty, let's return it without any changes. That is, flatten(()) should return (). 3. Otherwise, let's flatten the first element of the tuple, and concatenate it with the flattening of the rest of the tuple. What we get back should be altogether flattened. ### >>> def isTuple(x): return type(x) == types.TupleType ... >>> def flatten(T): ... if not isTuple(T): return (T,) ... elif len(T) == 0: return () ... else: return flatten(T[0]) + flatten(T[1:]) ... >>> flatten( ((0, 1, 2), (3, 4, 5), (6, 7, 8)) ) (0, 1, 2, 3, 4, 5, 6, 7, 8) ### What's nice is that the flattening is "deep", that is, it can handle any amount of nesting: >>> flatten( ( ((0,), (1, 2)), (3, (((4,))), 5), (6, 7, 8) ) ) (0, 1, 2, 3, 4, 5, 6, 7, 8) Hope this helps! From dyoo@hkn.eecs.berkeley.edu Wed Apr 18 23:01:11 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 18 Apr 2001 15:01:11 -0700 (PDT) Subject: [Tutor] python on OS-X In-Reply-To: Message-ID: On Wed, 18 Apr 2001 Hans.Beernink@UCHSC.edu wrote: > has anyone successfully compiled py2.1 on MacOS-X? and while we're on the > topic, why didnt python come preinstalled like > pearl/java/tcl/etc.etc.etc.???? seems like some lobbying needs to be done > with apple! Ouch! You'll want to talk with the people who built Python. Try asking on comp.lang.python: I'm sure that someone there knows what's happening. About Python being preinstalled with MacOS-X... um... good point. *grin* According to the documentation, they're working at it: http://python.sourceforge.net/devel-docs/mac/node23.html Give it a few days: Python 2.1 just came out on Tuesday, and the implementors are probably still a little dizzy. If you're looking for any version of Python 2.x for Mac OS X, here's one for 2.0: http://tony.lownds.com/macosx/ and on Jack's MacPython page, they have a prebuilt Python 2.1 beta: http://www.cwi.nl/~jack/macpython.html Good luck to you. From arthur.watts@gbst.com Thu Apr 19 00:31:13 2001 From: arthur.watts@gbst.com (Arthur Watts) Date: Thu, 19 Apr 2001 09:31:13 +1000 Subject: [Tutor] Python as a superior teaching language Message-ID: <1CDB101F0CB6D311882F0000F8063924033A7897@aquarius.bne.star.com.au> Guys, One of our developers had me build the GNU readline library, then 'activate' the module for Python 2.0 on our Alpha. I initially thought that being able to scroll thru one's command history in the interative interpreter was pretty good, but that's nothing compared to the info he just sent me : Here's some of the cool stuff you can do with Readline in Python. As well as providing a command history, the Readline module allows you to do auto-completion. This can be very handy when you are just learning the language and/or its objects. (NOTE Readline is installed on Taurus, but is not yet on Jupiter). Run the following lines when you run the Python Interactive Shell (or better still, put them in your $PYTHONSTARTUP program) >>> import rlcompleter >>> import readline >>> readline.parse_and_bind("tab: complete") And you now have AutoCompleting on. To use it, type part of a variable and press "". If there is only one variable matching, it will be filled in automatically, as in >>> readline.i Line will become >>> readline.insert_text because the readline module on has one attribute beginning with the letter 'i'. If there are more than one, nothing will happen after the first . Press again to see a list of variables that match, as in >>> import sys >>> sys. sys.__doc__ sys.exec_prefix sys.ps1 sys.__name__ sys.executable sys.ps2 sys.__stderr__ sys.exit sys.setcheckinterval sys.__stdin__ sys.exitfunc sys.setprofile sys.__stdout__ sys.getdefaultencoding sys.setrecursionlimit sys.argv sys.getrecursionlimit sys.settrace sys.builtin_module_names sys.getrefcount sys.stderr sys.byteorder sys.hexversion sys.stdin sys.copyright sys.maxint sys.stdout sys.exc_info sys.modules sys.version sys.exc_traceback sys.path sys.version_info sys.exc_type sys.platform sys.exc_value sys.prefix gem> sys. Very handy if you don't know what methods/attributes are available (or how to spell them). Like I said earlier, the main purpose of Readline is to provide a command-line history. By default, it is emacs style. Use your arrow keys to go through your previous commands. I however, prefer the 'vi' style line editing. To do this, put a '.inputrc' file in your home directory with the following line set editing-mode vi Now you can use all your 'vi' commands (, search with '/", etc). Also, if you want to save your command history between sessions, get Python to save it to file when you exit and re-reading it when you go back in. Here's my complete $PYTHONSTARTUP script (That is, I have written this to '/u/stephenb/python.py' and pointed the PYTHONSTARTUP Shell variable to it) try: import readline except ImportError: pass else: import rlcompleter import os import atexit # Allow auto-complete stuff readline.parse_and_bind("tab: complete") # Save the history file for next session histfile = os.path.join(os.environ["HOME"], ".pyhist") try: readline.read_history_file(histfile) except IOError: pass atexit.register(readline.write_history_file, histfile) # Cleanup del os, histfile, readline, atexit, rlcompleter I know that many commercial IDE's contain handy online references, but I find this particularly valuable when you want to work your way thru a module's namespace to find what you need. Enjoy, Arthur Arthur Watts Software Engineer GBST Automation Global Banking & Securities Transactions Telephone + 61 7 3331 5555 mailto: arthur.watts@gbst.com www.gbst.com From sheila@thinkspot.net Thu Apr 19 01:00:17 2001 From: sheila@thinkspot.net (Sheila King) Date: Wed, 18 Apr 2001 17:00:17 -0700 Subject: [Tutor] Python as a superior teaching language In-Reply-To: <1CDB101F0CB6D311882F0000F8063924033A7897@aquarius.bne.star.com.au> References: <1CDB101F0CB6D311882F0000F8063924033A7897@aquarius.bne.star.com.au> Message-ID: <135D3C5413F@kserver.org> On Thu, 19 Apr 2001 09:31:13 +1000, Arthur Watts wrote about [Tutor] Python as a superior teaching language: : I know that many commercial IDE's contain handy online references, :but I find this particularly valuable when you want to work your way thru a :module's namespace to find what you need. PythonWin has a popup scroll menu, that lists the modules namespace, and can autocomplete on a TAB. (For those on a Windows system...and PythonWin is free.) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From bobhicks@adelphia.net Thu Apr 19 02:37:32 2001 From: bobhicks@adelphia.net (Robert Hicks) Date: Wed, 18 Apr 2001 21:37:32 -0400 Subject: [Tutor] PYTHON ON OSX Message-ID: http://www.zope.org/Members/jshell/ZopeOnOSX This pretty much explains it all. I did NOT have to do the FCNTL I DID have to edit the Makefile I did NOT have to do "cp Python/python ./python.exe" - Bob From dyoo@hkn.eecs.berkeley.edu Thu Apr 19 03:46:50 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 18 Apr 2001 19:46:50 -0700 (PDT) Subject: [Tutor] PYTHON ON OSX In-Reply-To: Message-ID: On Wed, 18 Apr 2001, Robert Hicks wrote: > http://www.zope.org/Members/jshell/ZopeOnOSX > > This pretty much explains it all. > > I did NOT have to do the FCNTL > I DID have to edit the Makefile > I did NOT have to do "cp Python/python ./python.exe" Thanks for the info; there was a LOT of people asking about this on python-help as well. From NHYTRO@compuserve.com Thu Apr 19 07:04:01 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Thu, 19 Apr 2001 02:04:01 -0400 Subject: [Tutor] Client redirect? Message-ID: <200104190204_MC2-CCFC-995C@compuserve.com> Hello! I would like to use a CGI script to redirect a clients browser to a HTML page on the server, could someone tell me how I should accomplish this? I= did not find anything similar in the CGI module Best regards Sharriff From sheila@thinkspot.net Thu Apr 19 07:22:51 2001 From: sheila@thinkspot.net (Sheila King) Date: Wed, 18 Apr 2001 23:22:51 -0700 Subject: [Tutor] Client redirect? In-Reply-To: <200104190204_MC2-CCFC-995C@compuserve.com> References: <200104190204_MC2-CCFC-995C@compuserve.com> Message-ID: <290B82F7F44@kserver.org> On Thu, 19 Apr 2001 02:04:01 -0400, Sharriff Aina wrote about [Tutor] Client redirect?: :Hello! : :I would like to use a CGI script to redirect a clients browser to a HTML :page on the server, could someone tell me how I should accomplish this? I :did not find anything similar in the CGI module The entire output of your script should be print "Location: http://www.yourdomain.com/redirect/URL.html\n\n" -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sburr@mac.com Thu Apr 19 08:07:53 2001 From: sburr@mac.com (Steven Burr) Date: Thu, 19 Apr 2001 00:07:53 -0700 Subject: [Tutor] PYTHON ON OSX In-Reply-To: Message-ID: <20010419070729.MNKI26880.mail1.rdc1.az.home.com@localhost> On Wednesday, April 18, 2001, at 07:46 PM, Daniel Yoo wrote: > On Wed, 18 Apr 2001, Robert Hicks wrote: > >> http://www.zope.org/Members/jshell/ZopeOnOSX >> >> This pretty much explains it all. >> >> I did NOT have to do the FCNTL >> I DID have to edit the Makefile >> I did NOT have to do "cp Python/python ./python.exe" > > Thanks for the info; there was a LOT of people asking about this on > python-help as well. > I think the instructions on the Zope web site may be a bit dated. The Unix version of Python 2.1 now compiles "out of the box" on OS X. The README file in the Python-2.1/ directory that you get after untarring the tarball includes specific instructions for running the configure script in OS X. If you follow those instructions, you can do the usual make, make install routine afterwards. There's no longer any need to edit the Makefile manually. I just compiled and installed the final release this way, and it worked without a hitch. One caveat, OS X users may need to add /usr/local/bin, where the python binary is installed by default, to their paths. There's a lot more information on what people have been up to with python on OS X in the archives for the python-mac SIG. From NHYTRO@compuserve.com Thu Apr 19 13:22:47 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Thu, 19 Apr 2001 08:22:47 -0400 Subject: [Tutor] testing for "None" Message-ID: <200104190823_MC2-CCF3-4EAE@compuserve.com> Hi guys! ## code start ## templinks =3D [("aa,None,cc,dd")] # from databse links =3D string.split(templinks[0],",") for x in links: if x !=3D None: counter =3D counter + 1 print "%d. " %(counter) print "", print x print """    """ else: pass ## code end ## can someone tell me why this code fails? I=B4m trying to print values tha= t are not " None" From scarblac@pino.selwerd.nl Thu Apr 19 13:35:00 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 19 Apr 2001 14:35:00 +0200 Subject: [Tutor] testing for "None" In-Reply-To: <200104190823_MC2-CCF3-4EAE@compuserve.com>; from NHYTRO@compuserve.com on Thu, Apr 19, 2001 at 08:22:47AM -0400 References: <200104190823_MC2-CCF3-4EAE@compuserve.com> Message-ID: <20010419143500.A24074@pino.selwerd.nl> On 0, Sharriff Aina wrote: > Hi guys! > > ## code start ## > templinks = [("aa,None,cc,dd")] # from databse > links = string.split(templinks[0],",") > for x in links: > if x != None: > counter = counter + 1 > print "%d. " %(counter) > print "", > print x > print """ >    > > > > """ > else: > pass > ## code end ## > > can someone tell me why this code fails? I´m trying to print values that > are not " None" None of the values are None, they're all strings - "aa", "None", "cc" and "dd". You should be testing for the string "None", not the object None (if x != "None": ...). -- Remco Gerlich From dsh8290@rit.edu Thu Apr 19 15:26:19 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 19 Apr 2001 10:26:19 -0400 Subject: [Tutor] Python as a superior teaching language In-Reply-To: <1CDB101F0CB6D311882F0000F8063924033A7897@aquarius.bne.star.com.au>; from arthur.watts@gbst.com on Thu, Apr 19, 2001 at 09:31:13AM +1000 References: <1CDB101F0CB6D311882F0000F8063924033A7897@aquarius.bne.star.com.au> Message-ID: <20010419102619.D28426@harmony.cs.rit.edu> On Thu, Apr 19, 2001 at 09:31:13AM +1000, Arthur Watts wrote: | Guys, | | >>> import rlcompleter | >>> import readline | >>> readline.parse_and_bind("tab: complete") | | And you now have AutoCompleting on. To use it, type part of a variable and | press "". If there is only one variable matching, it will be filled in | automatically, as in ... | provide a command-line history. By default, it is emacs style. Use your | arrow keys to go through your previous commands. I however, prefer the 'vi' | style line editing. To do this, put a '.inputrc' file in your home | directory with the following line | set editing-mode vi It is very cool. Thanks for sharing. It works with Python 2.1 under cygwin as well. Except for the history stuff, you can get the same setup by putting the line "\t": complete in the .inputrc file. -D PS, for all you *nix fans stuck with windo~1 out there : 2.1 with cygwin is _very_ cool. It handles EOF properly (^D) and works with readline, as it is supposed to. It also handles job control from bash properly (^Z suspends it and returns your shell prompt) From bobhicks@adelphia.net Thu Apr 19 15:35:09 2001 From: bobhicks@adelphia.net (Robert Hicks) Date: Thu, 19 Apr 2001 10:35:09 -0400 Subject: [Tutor] How I got Python on OSX Message-ID: Get the source... I usually do all my stuff from /usr/local/src but you can do it anywhere. So open a Terminal and go to where you want to start.... type: wget http://www.python.org/ftp/python/2.1/python-2.1.tgz This will download the TGZ to your current folder/directory type: gnutar -xzf python-2.1.tgz cd python-2.1/ ./configure --program-suffix=.exe --with-dyld We need to take care of a case sensitive issue on OSX: Edit the Makefile...find the line that says EXE= and make sure it says EXE=.exe type: make OPT="-traditional-cpp" make install After it is installed you want to go to /usr/local/bin and... type: cp python.exe python cp python2.1.exe python2.1 You can remove the .exe ones if you like. Type: python Your interpreter should fire up... Hope this helps someone. The README from the TGZ states the steps as well. You cannot do a simple ./configure make make install unfortunately(or at least I couldn't). - Bob From alan.gauld@bt.com Thu Apr 19 16:38:25 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 19 Apr 2001 16:38:25 +0100 Subject: [Tutor] flatten a tuple Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D70B@mbtlipnt02.btlabs.bt.co.uk> > So I have a tuple: > > ((0, 1, 2), (3,4,5), (6,7,8)) > > and I want to get: > > (6,7,8,3,4,5,0,1,2) Go to my web tutor, look thru' the topic on recursion. In there, there is a recursive function for printing a list of arbitrary complexity in a flattened format. Convert the tuples to lists and change the print statements to result.append() and you should have most of your solution. HTH Alan G From dsh8290@rit.edu Thu Apr 19 17:10:11 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 19 Apr 2001 12:10:11 -0400 Subject: [Tutor] flatten a tuple In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D70B@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Thu, Apr 19, 2001 at 04:38:25PM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D70B@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010419121011.E28582@harmony.cs.rit.edu> On Thu, Apr 19, 2001 at 04:38:25PM +0100, alan.gauld@bt.com wrote: | > So I have a tuple: | > | > ((0, 1, 2), (3,4,5), (6,7,8)) | > | > and I want to get: | > | > (6,7,8,3,4,5,0,1,2) | | Go to my web tutor, look thru' the topic on recursion. | In there, there is a recursive function for printing | a list of arbitrary complexity in a flattened format. | | Convert the tuples to lists and change the print | statements to result.append() and you should have | most of your solution. A slight subltety here : >>> result = [] >>> result.append( [ 6 , 7 , 8 ] ) >>> print result [[6, 7, 8]] >>> What you really want is 'extend', the subtleties of which (taking only a list as the argument) have already been discussed. -D From winanss@earthlink.net Thu Apr 19 17:49:35 2001 From: winanss@earthlink.net (Sean M Winans) Date: Thu, 19 Apr 2001 12:49:35 -0400 (EDT) Subject: [Tutor] reload a module Message-ID: <385465291.987698975484.JavaMail.root@web443-wrb> Hi all, I'm picking Python up again after a few months off... I can't remember how to reload a module after making changes. Thanks in advance, Sean. From kalle@gnupung.net Thu Apr 19 17:58:50 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Thu, 19 Apr 2001 18:58:50 +0200 Subject: [Tutor] reload a module In-Reply-To: <385465291.987698975484.JavaMail.root@web443-wrb>; from winanss@earthlink.net on Thu, Apr 19, 2001 at 12:49:35PM -0400 References: <385465291.987698975484.JavaMail.root@web443-wrb> Message-ID: <20010419185850.D379@apone.network.loc> Sez Sean M Winans: > Hi all, > > I'm picking Python up again after a few months off... > > I can't remember how to reload a module after making changes. reload(module) Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From bdupire@seatech.fau.edu Thu Apr 19 18:12:16 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 19 Apr 2001 13:12:16 -0400 Subject: [Tutor] weird python code Message-ID: <3ADF1C70.F3CF7026@seatech.fau.edu> I found this on a Python website (i don' t remember where exactly).. but did not figure out why this does not work.... can someone explain it to me? thanks... def f(): global path from sys import * print path >>> f() Traceback (innermost last): File "", line 1, in ? f() File "", line 4, in f print path NameError: path -- Benoit Dupire Graduate Student Systems Engineering - FAU ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From curtis.larsen@Covance.Com Thu Apr 19 18:52:03 2001 From: curtis.larsen@Covance.Com (Curtis Larsen) Date: Thu, 19 Apr 2001 12:52:03 -0500 Subject: [Tutor] Python NNTP Scripts? Message-ID: Does anyone know where I could find some Python NNTP scripts to study? I'm especially interested in a Python-based news-searcher: how one would grab a collection of headers, then look through them using regex, then getting more if what you're looking for isn't there. If it is there, then downloading the messages) for later perusal. (What does the NNTP communications ebb and flow look like, etc.) In my case attachments aren't a real issue -- and would probably blow my teeny little mind trying to figure out how to collect, put together, then decode anyway. Maybe after I understand the textual part of the deal I can work on the binary parts. (A MIME is such a terrible thing to waste.) Yes, I know there's things like Deja out there, but: 1. I _wanna_ do it in Python (the power! The SHEER POWER! Muwahahahahaa!), and 2. Deja kinda sorta sucks anymore Thanks! Curtis ----------------------------------------------------- Confidentiality Notice: This e-mail transmission may contain confidential or legally privileged information that is intended only for the individual or entity named in the e-mail address. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or reliance upon the contents of this e-mail is strictly prohibited. If you have received this e-mail transmission in error, please reply to the sender, so that we can arrange for proper delivery, and then please delete the message from your inbox. Thank you. From dsh8290@rit.edu Thu Apr 19 19:01:13 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 19 Apr 2001 14:01:13 -0400 Subject: [Tutor] weird python code In-Reply-To: <3ADF1C70.F3CF7026@seatech.fau.edu>; from bdupire@seatech.fau.edu on Thu, Apr 19, 2001 at 01:12:16PM -0400 References: <3ADF1C70.F3CF7026@seatech.fau.edu> Message-ID: <20010419140113.D29633@harmony.cs.rit.edu> On Thu, Apr 19, 2001 at 01:12:16PM -0400, Benoit Dupire wrote: | | I found this on a Python website (i don' t remember where exactly).. | but did not figure out why this does not work.... | | can someone explain it to me? | thanks... | | def f(): | global path | from sys import * | print path | | | >>> f() | Traceback (innermost last): | File "", line 1, in ? | f() | File "", line 4, in f | print path | NameError: path The global statement says that 'path' should be found in the global namespace, not the local one. The from-import-* creates a local name 'path', I guess. from-import-* is bad to do, except _maybe_ at module scope (ie not inside a function). AFAIK the Ref Man says it's behavior is undefined (implementation specific) except at module-level. If you use from sys import path instead and leave out the 'global' statement it will work. Or better yet use import sys print sys.path (BTW, it gives the same error in 2.0 and 2.1, but tells a little more: NameError: global name 'path' is not defined) HTH, -D From dsh8290@rit.edu Thu Apr 19 19:03:18 2001 From: dsh8290@rit.edu (D-Man) Date: Thu, 19 Apr 2001 14:03:18 -0400 Subject: [Tutor] Python as a superior teaching language In-Reply-To: <20010419102619.D28426@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Apr 19, 2001 at 10:26:19AM -0400 References: <1CDB101F0CB6D311882F0000F8063924033A7897@aquarius.bne.star.com.au> <"from arthur.watts"@gbst.com> <20010419102619.D28426@harmony.cs.rit.edu> Message-ID: <20010419140318.E29633@harmony.cs.rit.edu> On Thu, Apr 19, 2001 at 10:26:19AM -0400, D-Man wrote: | Putting | "\t": complete | in the .inputrc file. A side-effect I just discovered : >>> def func() : ... doesn't work as before -- rather than indenting, readline asks if you want to see all possible completions. Can't have everything I guess ;-). -D From scarblac@pino.selwerd.nl Thu Apr 19 19:18:27 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 19 Apr 2001 20:18:27 +0200 Subject: [Tutor] Python NNTP Scripts? In-Reply-To: ; from curtis.larsen@Covance.Com on Thu, Apr 19, 2001 at 12:52:03PM -0500 References: Message-ID: <20010419201827.A24611@pino.selwerd.nl> On 0, Curtis Larsen wrote: > Does anyone know where I could find some Python NNTP scripts to study? I'll add to this post part of a late night hack that I did about a year ago. I was having a few beers and wanted to know which newsreaders people were using in nl.*. (Outlook 49.7%, Forte Agent 15.2%, Netscape 12.3%, Forte Free Agent 4.8%, 33 other newsreaders). I must say I'm rather surprised how easy to understand the code is now - I don't want to see the Perl I produce when slightly drunk... This is the function for downloading the posts; the bit for getting the bodies is commented out, and the posts are stored by Message-ID in a shelf in a directory per group: import nntplib, string, time, shelve, os def get_posts(grouplistfile, server='news.rug.nl', filename_func=default_file): nntp = nntplib.NNTP('news.rug.nl') groups = map(string.strip, grouplistfile.readlines()) for group in groups: filename = ("/home/scarblac/python/nntphack/groups/%s/%s.dat" % (time.strftime("%Y%m%d",time.localtime(time.time())), group)) if os.path.exists(filename): continue try: # This gets info about the list of articles in this group resp, count, first, last, name = nntp.group(group) except nntplib.NNTPError: continue db = shelve.open(filename) for i in xrange(int(first), int(last)+1): article = Article() try: resp, nr, id, list = nntp.head(str(i)) article.set_headers(list) # resp, nr, id, list = nntp.body(str(i)) # article.set_body(list) db[article.get_header("Message-ID")] = article except nntplib.NNTPError: pass And the Article class: class Article: def __init__(self, headers=None, body=None): self.headers = {} if headers: self.set_headers(headers) self.body = body def set_headers(self, header_list): """Internal. Header_list is a list of header strings from nntplib.""" for line in header_list: i = string.find(line, ": ") if i == -1: continue self.headers[line[:i]] = string.strip(line[i+1:]) def set_body(self, body): self.body = body def get_headers(self): return self.headers def get_header(self, header): return self.headers.get(header, "") def get_body(self): return self.body > I'm especially interested in a Python-based news-searcher: how one > would grab a collection of headers, then look through them using regex, > then getting more if what you're looking for isn't there. If it is > there, then downloading the messages) for later perusal. (What does the > NNTP communications ebb and flow look like, etc.) What you see above should be enough. The sad thing is that in order to get all the headers in NNTP, you have to download the whole article. There are but a few that you can get with an XOVER command (From:, Xref:, Subject: and two others I think) but I can't remember how that's done with Python's nntplib. -- Remco Gerlich From Daniel.Kinnaer@Advalvas.be Thu Apr 19 21:42:26 2001 From: Daniel.Kinnaer@Advalvas.be (Daniel Kinnaer) Date: Thu, 19 Apr 2001 22:42:26 +0200 Subject: [Tutor] Python NNTP Scripts? In-Reply-To: Message-ID: Below is a very straightforward script I tried to write which scans for a single word in the NNTP-Headers and only downloads the MessageBody to disk if the specific word is found in the Headers. I must admit that I copied much from the EffBot Guide: The Standard Python Library by /F :) It is my first 'real' Python program, so don't be too hard on me :) ############################################################## # script : NNTP_ScanHeaders_GetBody_on_found.py # author : Daniel Kinnaer # ref : The EffBot Guide: The Standard Python Library by /F # start : 26 December 2000 # finish : 28 December 2000 # updates: # # purpose: connect to an NNTP Server # check all de messages kept on the server for # authors named "Daniel". If found, download # that message and save it on disk # ############################################################## #get libraries from nntplib import * import string, StringIO, rfc822 #name variables SERVER="news.skynet.be" GROUP="comp.lang.python" KEYWORD="Daniel" THEPATH="C:/Data/Py/AProject/NNTP/NNTPBodies/" #Slash, not BackSlash! print " " #connect to server server=NNTP(SERVER) print "### Connecting to " + SERVER + "..." #select a newsgroup print "### reading group " + GROUP + "..." resp,count,first,last,name=server.group(GROUP) print "count=%s first=%s last=%s " %(count,first,last) #get every item from id=first to id=last resp, items = server.xover(first,last) #search every item for the KEYWORD print "### now searching for keyword " + KEYWORD + " in each article from group " + name for id,subject,author,date,message_id,references,size,lines in items: if string.find(author,KEYWORD)>=0: resp,id,message_id,text=server.article(id) #save body artikellijnen =str(len(text)) FileNaam=THEPATH + str(id)+'.txt' f=open(FileNaam,'w') print "writing %s lines to file %s " %(artikellijnen,FileNaam) author=author+'\n' f.write(author) subject=subject+'\n' artikellijnen=artikellijnen + "\n" f.write(artikellijnen) text=string.join(text,"\n") file=StringIO.StringIO(text) message=rfc822.Message(file) for k,v in message.items(): lijn=k,"=",v+'\n' f.writelines(lijn) lijnen=message.fp.read() f.writelines(lijnen) f.write( "\r\n") f.close() print "End of Script..." How can this be improved with 'regex'? I'd like to scan on several parts of the header (like must contain A and B or C). What is the best way to improve this? Hope to read you soon. Best regards, Daniel... From tbrauch@mindless.com Thu Apr 19 23:39:26 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Thu, 19 Apr 2001 18:39:26 -0400 Subject: [Tutor] COM Ports Message-ID: <3ADF691E.74775B5F@mindless.com> I have a project that I would greatly appreciate some help with getting started. I think it can be done in Python, and would love it if it can be. I have an infrared receiver for a remote control hooked up to my Win98 computer's COM2. What I would like to do is be able to use the remote to fun functions inside a Python program, depending on what button is pushed. The receiver also can pick up signals from any remote, but the program that came with the remote will only operate with this remote. I would really like to eventually write a program that can be changed fairly easily depending on what remote I have on hand (no need to worry about losing the remote). The problem is I don't know how (or even if it is possible) to use Python to "get" the buttons from COM2. Also, I'm not even sure what COM2 sends when I do push a button. If someone can just point me in the right direction, I would be very greatful. Of course, any other help you might want to provide would be great as well. - Tim From jonsoons@telocity.com Fri Apr 20 00:05:56 2001 From: jonsoons@telocity.com (jonsoons@telocity.com) Date: 19 Apr 2001 16:05:56 -0700 Subject: [Tutor] trouble reading Programming Python Message-ID: <20010419230556.1296.cpmta@c007.snv.cp.net> I am on page 47 of "Programming Python" 2nd Edition and 3/4 of the way down the page there are a couple of lines with three double quotes within: print 'Got this" "%s"' % raw_input() and Got this" "Help! Help! I'm being repressed!" It all makes sense apart from the first " in each line. Are these characters protected from interpretation in some way that the %s is not? Why is this not a syntax error? To quote the manual: "...r"\" is a valid string literal, r"\"" is not..." From rob@jam.rr.com Fri Apr 20 03:20:13 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Thu, 19 Apr 2001 21:20:13 -0500 Subject: [Tutor] trouble reading Programming Python References: <20010419230556.1296.cpmta@c007.snv.cp.net> Message-ID: <3ADF9CDD.C5DCA2C7@jam.rr.com> Although I'm not sure why that first " is in there, it's as protected as it needs to be due to the fact that it appears between two single quotes. Everything between those single quotes is to be printed, including each double quote sign, such as in the following: >>> print '"""""' """"" If you place single quotes inside a pair of double quotes, the same thing happens: >>> print "'''''" ''''' You can use either single or double quotes for containment, and sometimes it doesn't matter which you choose. However, there are circumstances in which one will work but the other will not, such as in these examples: >>> print 'quoth the Raven "nevermore"' quoth the Raven "nevermore" >>> print "quoth the Raven "nevermore"" Traceback ( File "", line 1 print "quoth the Raven "nevermore"" ^ SyntaxError: invalid syntax >>> print "I can't see!" I can't see! >>> print 'I can't see!' Traceback ( File "", line 1 print 'I can't see!' ^ SyntaxError: invalid syntax I hope this helps, Rob jonsoons@telocity.com wrote: > > I am on page 47 of "Programming Python" 2nd Edition > and 3/4 of the way down the page there are a couple > of lines with three double quotes within: > > print 'Got this" "%s"' % raw_input() > > and > > Got this" "Help! Help! I'm being repressed!" > > It all makes sense apart from the first " in > each line. Are these characters protected from > interpretation in some way that the %s is not? > Why is this not a syntax error? > > To quote the manual: "...r"\" is a valid string > literal, r"\"" is not..." > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From kstoner@netins.net Fri Apr 20 03:24:20 2001 From: kstoner@netins.net (Katharine Stoner) Date: Thu, 19 Apr 2001 21:24:20 -0500 Subject: [Tutor] inverse Message-ID: <000a01c0c941$0914f700$8352b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0C917.18D029A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, How do you get the inverse of tan using python? -Cameron ------=_NextPart_000_0007_01C0C917.18D029A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
How do you get the inverse of tan using = python?
 
-Cameron
 
------=_NextPart_000_0007_01C0C917.18D029A0-- From python tutor" Message-ID: [Katharine Stoner] > How do you get the inverse of tan using python? Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import math >>> math.atan(1) 0.78539816339744828 >>> _ * 4 3.1415926535897931 >>> Note that, as in most computer languages, Python's trigonometric functions measure angles in radians (pi radians == 180 degrees). Also see the docs for the math module. From tbrauch@mindless.com Fri Apr 20 04:53:10 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Thu, 19 Apr 2001 23:53:10 -0400 Subject: [Tutor] COM Ports Message-ID: <3ADFB2A6.9242E68@mindless.com> I have a program I want to write and I would greatly appreciate some help with getting started. I think it can be done in Python, and would love it if it can be. I have an infrared receiver for a remote control hooked up to my Win98 computer's COM2. What I would like to do is be able to use the remote to fun functions inside a Python program, depending on what button is pushed. The receiver also can pick up signals from any remote, but the program that came with the remote will only operate with this remote. I would really like to eventually write a program that can be changed fairly easily depending on what remote I have on hand (no need to worry about losing the remote). The problem is I don't know how (or even if it is possible) to use Python to "get" the buttons from COM2. Also, I'm not even sure what COM2 sends when I do push a button. If someone can just point me in the right direction, I would be very greatful. Of course, any other help you might want to provide would be great as well. - Tim **I tried sending this earlier, but I don't know if it went through. If so, please ignore my double posting.** From ash@zyx.net Fri Apr 20 05:44:30 2001 From: ash@zyx.net (Aaron Mathews) Date: Thu, 19 Apr 2001 22:44:30 -0600 Subject: [Tutor] COM Ports References: <3ADF691E.74775B5F@mindless.com> Message-ID: <002a01c0c954$97bc4db0$7800000a@gandalf> Unless you can find a published spec for the communication mode the IR receiver uses, you will be in for some reverse engineering if you want full functionality (generally). You might try contacting the manufacturer of the device and see if they have any developer kits, etc. You might try watching COM2 from a terminal, and capturing the output from the IR receiver when you press buttons- you could watch for that output (per button) and execute a function when you see the command for '5', for example. Oh, and I don't know anything about accessing serial ports on windows... I'm used to just opening the serial device as a filehandle under BSD. Sorry :) -Aaron ----- Original Message ----- From: "Timothy M. Brauch" To: "Python Tutor" Sent: Thursday, April 19, 2001 4:39 PM Subject: [Tutor] COM Ports > I have a project that I would greatly appreciate some help with getting > started. I think it can be done in Python, and would love it if it can > be. > I have an infrared receiver for a remote control hooked up to my Win98 > computer's COM2. What I would like to do is be able to use the remote > to fun functions inside a Python program, depending on what button is > pushed. The receiver also can pick up signals from any remote, but the > program that came with the remote will only operate with this remote. I > would really like to eventually write a program that can be changed > fairly easily depending on what remote I have on hand (no need to worry > about losing the remote). > > The problem is I don't know how (or even if it is possible) to use > Python to "get" the buttons from COM2. Also, I'm not even sure what > COM2 sends when I do push a button. > > If someone can just point me in the right direction, I would be very > greatful. Of course, any other help you might want to provide would be > great as well. > > - Tim > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From baris@gelecek.com.tr Fri Apr 20 08:09:58 2001 From: baris@gelecek.com.tr (Baris Metin) Date: Fri, 20 Apr 2001 10:09:58 +0300 (EEST) Subject: [Tutor] tail -f Message-ID: Hello, How can I read a file continuously, like the command "tail -f" on unix systems ? Do I have to open and close file ? -- Baris Metin From kalle@gnupung.net Fri Apr 20 11:49:14 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 20 Apr 2001 12:49:14 +0200 Subject: [Tutor] tail -f In-Reply-To: ; from baris@gelecek.com.tr on Fri, Apr 20, 2001 at 10:09:58AM +0300 References: Message-ID: <20010420124914.C372@apone.network.loc> Sez Baris Metin: > How can I read a file continuously, like the command "tail -f" on unix > systems ? > > Do I have to open and close file ? No, just reading from it should work: f = open("fisk") import time while 1: print f.read() time.sleep(1) f.close() will print all new text in the file every time through the loop. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From bdupire@seatech.fau.edu Fri Apr 20 14:34:43 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Fri, 20 Apr 2001 09:34:43 -0400 Subject: [Tutor] COM Ports References: <3ADFB2A6.9242E68@mindless.com> Message-ID: <3AE03AF3.997D1B3E@seatech.fau.edu> In electronics, like in CE, the communication between a transmitter and a receiver uses a particular 'protocol' to be sure that the message the receiver receives is being caused by the transmitter, and not by any noise..... For instance, if you press the button '5', the remote can send '01100101' 10 times in a row, and the receiver aknowledge the signal when it receives 3 of them.... this protocol is often 'hardware', therefore can't be changed, and depends of the product... so make sure before beginning your project that you can substitute your first remote by another one....(Maybe there exists a 'universal' remote out there or maybe you can buy several remotes for this product from the constructor). Then, what you want to know is the output of the receiver, when it deciphers '01100101'...... you have to get the spec...otherwise you have to do it yourself and to look at the output for each event of the remote... Then, you can ask yourself whether the rest of the project can be done in Python... -- Benoit Dupire Graduate Student Systems Engineering ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From alan.gauld@bt.com Fri Apr 20 15:14:41 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 20 Apr 2001 15:14:41 +0100 Subject: [Tutor] flatten a tuple Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D717@mbtlipnt02.btlabs.bt.co.uk> | Convert the tuples to lists and change the print > | statements to result.append() and you should have > > What you really want is 'extend' Nope, I want append. The recursive routine reduces the list to elements before printing thus you never attempt to print a list... Here it is: def printList(L): if not L: return if type(L[0]) == type([]): # extend for other sequences? printList(L[0]) else: #no list so just print element print L[0] # now process the rest of L printList(L[1:]) I think it was Danny posted something similar already, that also did the reversal by using -1 instead of 0, a neat twist :-) Alan G. PS Is there a better way of testing the type? For example something that could check for any sequence? if L.hasMethod(__getitems__) or whatever? From dsh8290@rit.edu Fri Apr 20 15:41:12 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 20 Apr 2001 10:41:12 -0400 Subject: [Tutor] flatten a tuple In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D717@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Fri, Apr 20, 2001 at 03:14:41PM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20751D717@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010420104112.A2753@harmony.cs.rit.edu> On Fri, Apr 20, 2001 at 03:14:41PM +0100, alan.gauld@bt.com wrote: | | Convert the tuples to lists and change the print | > | statements to result.append() and you should have | > | > What you really want is 'extend' | | Nope, I want append. The recursive routine reduces | the list to elements before printing thus you never | attempt to print a list... Oh ok. You have a nested list (only 1 level) , then you strip that level when you print. I was trying to get rid of all levels of nesting, then the print would simply be 'print'. Same result, different perspective :-). | PS Is there a better way of testing the type? | For example something that could check for any | sequence? if L.hasMethod(__getitems__) or whatever? It really depends on what you expect to be in the list. If you want to allow the list to contain strings, and consider those strings as "atoms", then that technique won't work. I think the adapter PEP or the interfaces PEP (I haven't read the interfaces one yet) might address this situation, but I don't know that it would consider a string to be an atom (after all, you can iterate over a string a character at a time ...). If you want the code to be slightly faster and use a little less memory make the following change : - if type( L ) == type( [] ) : + import types + if type( L ) == types.ListType : The difference is the first line creates a new list, calls a function to get its type, then frees the list each time it is executed. The second one creates a list, gets its type, frees it only on the import. OTOH the second form does the same thing for every other type, so it really depends on where you want the time to be spent. If you check the type of other stuff or if you run through the loop a lot it is a good tradeoff. -D From jsoons@juilliard.edu Fri Apr 20 16:05:23 2001 From: jsoons@juilliard.edu (Jonathan Soons) Date: Fri, 20 Apr 2001 11:05:23 -0400 Subject: [Tutor] readline recompile fails Message-ID: I cannot make Python2.0 recompile with readline enabled in Modules/Setup. I have installed GNU readline in /usr/local/lib (same place as tcl and tk libs). I am on a SPARC with Solaris7. gcc2.8.0. Do I need ncurses also? The Setup file seems to say this is optional. From kalle@gnupung.net Fri Apr 20 16:37:12 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 20 Apr 2001 17:37:12 +0200 Subject: [Tutor] readline recompile fails In-Reply-To: ; from jsoons@juilliard.edu on Fri, Apr 20, 2001 at 11:05:23AM -0400 References: Message-ID: <20010420173712.A6905@apone.network.loc> Sez Jonathan Soons: > I cannot make Python2.0 recompile with readline enabled in Modules/Setup. I > have installed GNU readline in /usr/local/lib (same place as tcl and tk > libs). > I am on a SPARC with Solaris7. > gcc2.8.0. How does it fail? Could you post an error message, and perhaps the relevant part of Setup? > Do I need ncurses also? The Setup file seems to say this is optional. ncurses is optional. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From alan.gauld@bt.com Fri Apr 20 17:05:05 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 20 Apr 2001 17:05:05 +0100 Subject: [Tutor] flatten a tuple Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D71C@mbtlipnt02.btlabs.bt.co.uk> > | PS Is there a better way of testing the type? > It really depends on what you expect to be in the list. If you want > to allow the list to contain strings, and consider those strings as > "atoms", No, I think I'd treat strings as sequences. > If you want the code to be slightly faster and use a little less > memory make the following change : > > - if type( L ) == type( [] ) : > + import types > + if type( L ) == types.ListType : True, Good catch. Alan G. From jsoons@juilliard.edu Fri Apr 20 18:24:12 2001 From: jsoons@juilliard.edu (Jonathan Soons) Date: Fri, 20 Apr 2001 13:24:12 -0400 Subject: [Tutor] RE: recompiling with readline Message-ID: I cannot make Python2.0 recompile with readline enabled in Modules/Setup. It may have been a mistake to install readline if the source comes with Python2.0. Maybe that's the conflict??? Here is the line from Setup: readline readline.c -lreadline -ltermcap Here is the error: make[1]: Leaving directory `/usr/share/src/Python-2.0/Python' cd Modules ; make OPT="-g -O2 -Wall -Wstrict-prototypes" VERSION="2.0" \ prefix="/usr/local" exec_prefix="/usr/local" all make[1]: Entering directory `/usr/share/src/Python-2.0/Modules' gcc -g -O2 -Wall -Wstrict-prototypes -I./../Include -I.. -DHAVE_CONFIG_H -c ./readline.c ./readline.c:31: conflicting types for `rl_read_init_file' /usr/local/include/readline/readline.h:303: previous declaration of `rl_read_init_file' ./readline.c:32: conflicting types for `rl_insert_text' /usr/local/include/readline/readline.h:363: previous declaration of `rl_insert_text' ./readline.c: In function `set_completer_delims': ./readline.c:227: warning: passing arg 1 of `free' discards `const' from pointer target type ./readline.c: In function `flex_complete': ./readline.c:399: warning: implicit declaration of function `completion_matches' ./readline.c:399: warning: return makes pointer from integer without a cast make[1]: *** [readline.o] Error 1 make[1]: Leaving directory `/usr/share/src/Python-2.0/Modules' make: *** [Modules] Error 2 From kalle@gnupung.net Fri Apr 20 19:09:04 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 20 Apr 2001 20:09:04 +0200 Subject: [Tutor] RE: recompiling with readline In-Reply-To: ; from jsoons@juilliard.edu on Fri, Apr 20, 2001 at 01:24:12PM -0400 References: Message-ID: <20010420200904.B7649@apone.network.loc> Sez Jonathan Soons: > > I cannot make Python2.0 recompile with readline enabled in Modules/Setup. > It may have been a mistake to install readline if the source comes with > Python2.0. > Maybe that's the conflict??? No, I don't think there is any readline code in the Python dist. > Here is the line from Setup: > readline readline.c -lreadline -ltermcap > > Here is the error: > > make[1]: Leaving directory `/usr/share/src/Python-2.0/Python' > cd Modules ; make OPT="-g -O2 -Wall -Wstrict-prototypes" VERSION="2.0" \ > prefix="/usr/local" exec_prefix="/usr/local" all > make[1]: Entering directory `/usr/share/src/Python-2.0/Modules' > gcc -g -O2 -Wall -Wstrict-prototypes -I./../Include -I.. -DHAVE_CONFIG_H -c > ./readline.c > ./readline.c:31: conflicting types for `rl_read_init_file' > /usr/local/include/readline/readline.h:303: previous declaration of > `rl_read_init_file' > ./readline.c:32: conflicting types for `rl_insert_text' > /usr/local/include/readline/readline.h:363: previous declaration of > `rl_insert_text' [snip] Aha! You use readline 4.2, right? A CVS commit on Fri Apr 13 18:14:27 2001 UTC has the following log entry: """ Clean up the unsightly mess around the readline header files. We now always: - #undef HAVE_CONFIG_H (because otherwise chardefs.h tries to include strings.h) - #include readline.h and history.h and we never declare any readline function prototypes ourselves. This makes it compile with readline 4.2, albeit with a few warnings. Some of the remaining warnings are about completion_matches(), which is renamed to rl_completion_matches(). I've tested it with various other versions, from 2.0 up, and they all seem to work (some with warnings) -- but only on Red Hat Linux 6.2. Fixing the warnings for readline 4.2 would break compatibility with 3.0 (and maybe even earlier versions), and readline doesn't seem to have a way to test for its version at compile time, so I'd rather leave the warnings in than break compilation with older versions. """ This probably means you have to downgrade readline to 3.x or upgrade Python to 2.1. I suggest upgrading Python... Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From bsass@freenet.edmonton.ab.ca Fri Apr 20 19:22:47 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 20 Apr 2001 12:22:47 -0600 (MDT) Subject: [Tutor] flatten a tuple In-Reply-To: <20010420104112.A2753@harmony.cs.rit.edu> Message-ID: On Fri, 20 Apr 2001, D-Man wrote: <...> > - if type( L ) == type( [] ) : > + import types > + if type( L ) == types.ListType : > > The difference is the first line creates a new list, calls a function > to get its type, then frees the list each time it is executed. The > second one creates a list, gets its type, frees it only on the import. > OTOH the second form does the same thing for every other type, so it > really depends on where you want the time to be spent. If you check > the type of other stuff or if you run through the loop a lot it is a > good tradeoff. I'd say the best way is to do... ListType = type([]) ... if type(L) == ListType The first line is what "import types" does; doing it manually will always be faster because there is no "import" or attribute access (".") overhead. - Bruce From dyoo@hkn.eecs.berkeley.edu Fri Apr 20 19:45:07 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 20 Apr 2001 11:45:07 -0700 (PDT) Subject: [Tutor] flatten a tuple In-Reply-To: Message-ID: On Fri, 20 Apr 2001, Bruce Sass wrote: > On Fri, 20 Apr 2001, D-Man wrote: > <...> > > - if type( L ) == type( [] ) : > > + import types > > + if type( L ) == types.ListType : > > > > The difference is the first line creates a new list, calls a function > > to get its type, then frees the list each time it is executed. The > > second one creates a list, gets its type, frees it only on the import. > > OTOH the second form does the same thing for every other type, so it > > really depends on where you want the time to be spent. If you check > > the type of other stuff or if you run through the loop a lot it is a > > good tradeoff. > > I'd say the best way is to do... > > ListType = type([]) > ... > if type(L) == ListType > > The first line is what "import types" does; doing it manually will > always be faster because there is no "import" or attribute access > (".") overhead. Deja vu! *grin* http://mail.python.org/pipermail/tutor/2001-March/003911.html From pt00aar@student.bth.se Fri Apr 20 20:00:12 2001 From: pt00aar@student.bth.se (Anders Arvidsson) Date: Fri, 20 Apr 2001 21:00:12 +0200 Subject: [Tutor] please help and I will be so happy Message-ID: <001c01c0c9cc$20b63fa0$998f2fc2@rsn.hkr.se> This is a multi-part message in MIME format. ------=_NextPart_000_0019_01C0C9DC.E42E46C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I would like to know how to recive and print information from a certain = webpage by using sockets in Python.=20 ------=_NextPart_000_0019_01C0C9DC.E42E46C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I would like to know how to recive and = print=20 information from a certain webpage by using sockets in Python.=20
------=_NextPart_000_0019_01C0C9DC.E42E46C0-- From dsh8290@rit.edu Fri Apr 20 20:08:02 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 20 Apr 2001 15:08:02 -0400 Subject: [Tutor] please help and I will be so happy In-Reply-To: <001c01c0c9cc$20b63fa0$998f2fc2@rsn.hkr.se>; from pt00aar@student.bth.se on Fri, Apr 20, 2001 at 09:00:12PM +0200 References: <001c01c0c9cc$20b63fa0$998f2fc2@rsn.hkr.se> Message-ID: <20010420150802.A3673@harmony.cs.rit.edu> On Fri, Apr 20, 2001 at 09:00:12PM +0200, Anders Arvidsson wrote: | I would like to know how to recive and print information from a certain webpage by using sockets in Python. Don't use sockets. Sockets are very low level, and you would have to implement the HTTP protocol on top of them. Instead use the "httplib" module that is in the standard distribution. http://www.python.org/doc/lib/lib.html HTH, -D From randrews@planhouse.com Fri Apr 20 20:17:05 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 20 Apr 2001 14:17:05 -0500 Subject: [Tutor] please help and I will be so happy In-Reply-To: <001c01c0c9cc$20b63fa0$998f2fc2@rsn.hkr.se> Message-ID: <000701c0c9ce$7d6e4b00$1e00a8c0@planhouse5> You can find info on sockets with Python at this URL: http://www.python.org/doc/current/lib/module-socket.html If you can tell us a bit more detail about what you'd like to do, it'll be easier to give more specific feedback. Rob -----Original Message----- I would like to know how to recive and print information from a certain webpage by using sockets in Python. From arcege@speakeasy.net Fri Apr 20 20:21:41 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Fri, 20 Apr 2001 15:21:41 -0400 (EDT) Subject: [Tutor] flatten a tuple In-Reply-To: from "Bruce Sass" at Apr 20, 2001 12:22:47 PM Message-ID: <200104201921.f3KJLfv04312@dsl254-114-246.nyc1.dsl.speakeasy.net> Bruce Sass wrote > I'd say the best way is to do... > > ListType = type([]) > ... > if type(L) == ListType > > The first line is what "import types" does; doing it manually will > always be faster because there is no "import" or attribute access > (".") overhead. Folks, If you are concerned with this level of efficiency, then it is very likely that you have a decent sized application, and that you are doing this in a number of places. Creating all these *Type values in a lot of different modules is going to be far more wasteful (memory and speed) than importing the types module. And if you are so concerned with the attribute references, you can use the "from types import ListType" form. The time to load an already compiled standard module is not all that much. Except for small, pedantic scripts, defining your own ListType global isn't more efficient at all, and probably the worst way to do this (at least the `type([])' method frees the memory). -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From kromag@nsacom.net Fri Apr 20 23:59:42 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Fri, 20 Apr 2001 15:59:42 -0700 (PDT) Subject: [Tutor] COM Ports Message-ID: <200104202259.f3KMxgm07111@pop.nsacom.net> > > Oh, and I don't know anything about accessing serial ports on windows... > I'm used to just opening the serial device as a filehandle under BSD. > Sorry :) But never let a chance like this go to waste..... I have a project in the works that requires me to read data from a multi-port serial card (which I don't have yet - it should arrive in the mail soon) and squirt the data into a database. I am using (at this moment) linux for this particular job, but would have no problem switching to Free/NetBSD (I don't think PostGreSQL will run on OpenBSD yet...). As I understand it, one has to create a C module to read from the serial port in python under unix. I have read the Linux-Serial- Programming-HOWTO and the C Extentions Overview in Programming Python and am beginning to get some idea of how creating such a mawnstah might work, but would really like to see some example code that is a little less generic. Can you or any of the other clueful post some examples or url's for same? Thanks! d From vijay.kumar@cqsl.com Wed Apr 11 18:18:31 2001 From: vijay.kumar@cqsl.com (Vijay Kumar) Date: Wed, 11 Apr 2001 13:18:31 -0400 (EDT) Subject: [Tutor] Help Message-ID: Hi, I am beginner in Python & working on Linux. I have set the PYTHONSTARTUP variable to some file in the .bash_profile. When I start python Interactively this script is not being executed alothough the PYTHONSTARTUP variable has the value which is specified in the .bash_profile. How do I set the Value in the PYTHONSTARTUP variable ??? Please Help Thank You, Vijay. From dsh8290@rit.edu Fri Apr 20 22:15:29 2001 From: dsh8290@rit.edu (D-Man) Date: Fri, 20 Apr 2001 17:15:29 -0400 Subject: [Tutor] COM Ports In-Reply-To: <200104202259.f3KMxgm07111@pop.nsacom.net>; from kromag@nsacom.net on Fri, Apr 20, 2001 at 03:59:42PM -0700 References: <200104202259.f3KMxgm07111@pop.nsacom.net> Message-ID: <20010420171529.B3917@harmony.cs.rit.edu> On Fri, Apr 20, 2001 at 03:59:42PM -0700, kromag@nsacom.net wrote: | > | > Oh, and I don't know anything about accessing serial ports on windows... | > I'm used to just opening the serial device as a filehandle under BSD. | > Sorry :) | | But never let a chance like this go to waste..... | | I have a project in the works that requires me to read data from a multi-port | serial card (which I don't have yet - it should arrive in the mail soon) and | squirt the data into a database. | | I am using (at this moment) linux for this particular job, but would have no | problem switching to Free/NetBSD (I don't think PostGreSQL will run on | OpenBSD yet...). As I understand it, one has to create a C module to read | from the serial port in python under unix. I have read the Linux-Serial- | Programming-HOWTO and the C Extentions Overview in Programming Python and am | beginning to get some idea of how creating such a mawnstah might work, but | would really like to see some example code that is a little less generic. | | Can you or any of the other clueful post some examples or url's for same? To toy with your modem, on COM3 (under linux) : modem = open( "/dev/ttyS2" , "r+" ) modem.write( "ATZ" ) modem.write( "ATDT*80,4272000" ) print modem.readline() print modem.readline() print modem.readline() . Unix is rather orthogonal when it comes to device access. It treats everything as a file -- terminals, ttys, serial ports, actual files. The serial ports under Linux >= 2.2.x are /dev/ttySn where n is a single digit integer (I suppose you could have more serial ports, but I only have at most 3 on my systems). Simply open the device file and read/write to your heart's content. The main thing to be careful of is knowing how the device will react and interacting appropriately. If instead I tried to print modem.read() the interpreter will "hang" waiting for an EOF signal from the modem. Of course, that isn't about to happen anytime soon. I must confess that I too don't know how to open a Windows serial port for reading/writing. The following DOS command will copy a disk file directly to a port: copy /b Linux-Advocacy.ps LPT1 This is useful if you have, say, a postscript file and a postscript printer on LPT1. -D PS. Disclaimer : Even though I did use the interactive interpreter some when I was trying to get my modem to work, I haven't done any serious serial (or parallel, or USB, etc) programming and haven't read that HOWTO you referred to. From bsass@freenet.edmonton.ab.ca Fri Apr 20 22:26:52 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 20 Apr 2001 15:26:52 -0600 (MDT) Subject: [Tutor] flatten a tuple In-Reply-To: <200104201921.f3KJLfv04312@dsl254-114-246.nyc1.dsl.speakeasy.net> Message-ID: On Fri, 20 Apr 2001, Michael P. Reilly wrote: > If you are concerned with this level of efficiency, then it is very > likely that you have a decent sized application, and that you are doing > this in a number of places. Creating all these *Type values in a lot of > different modules is going to be far more wasteful (memory and speed) > than importing the types module. > > And if you are so concerned with the attribute references, you can > use the "from types import ListType" form. The time to load an already > compiled standard module is not all that much. Ya, there is no "best way" in the general case... > Except for small, pedantic scripts, defining your own ListType global > isn't more efficient at all, and probably the worst way to do this > (at least the `type([])' method frees the memory). ...this was for a standalone script with a single check inside a loop. Thanks for the reality check though, it is easy to get hooked on one way of doing things. Two questions come to mind: Why isn't this a FAQ? Anyone have any idea of how many manual someType=type(something)-s are in an "import types". ``grep "Type = type(" types.py | wc -l'' -> 28 with py-2.1, so does that mean you could do it manually >28 times before using "import types" is more efficient? - Bruce From arcege@speakeasy.net Fri Apr 20 22:35:13 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Fri, 20 Apr 2001 17:35:13 -0400 (EDT) Subject: [Tutor] COM Ports In-Reply-To: <200104202259.f3KMxgm07111@pop.nsacom.net> from "kromag@nsacom.net" at Apr 20, 2001 03:59:42 PM Message-ID: <200104202135.f3KLZDw04474@dsl254-114-246.nyc1.dsl.speakeasy.net> kromag@nsacom.net wrote > I am using (at this moment) linux for this particular job, but would have no > problem switching to Free/NetBSD (I don't think PostGreSQL will run on > OpenBSD yet...). As I understand it, one has to create a C module to read > from the serial port in python under unix. I have read the Linux-Serial- > Programming-HOWTO and the C Extentions Overview in Programming Python and am > beginning to get some idea of how creating such a mawnstah might work, but > would really like to see some example code that is a little less generic. You don't need to create a new C module just to access the serial lines, open the device file for the serial line (eg. /dev/ttyS0), configure the line as needed with the termios/TERMIOS modules and read and write the data as needed. The select module can help you for when data is ready. >>> import termios, TERMIOS >>> f= open('/dev/ttyS2', 'r+') >>> settings = termios.tcgetattr(f.fileno()) >>> settings[3] = settings[3] & ~TERMIOS.ICANON >>> settings[4] = settings[5] = TERMIOS.B9600 >>> termios.tcsetattr(f.fileno(), settings, TERMIOS.TCSAFLUSH) >>> f.write('AT\r') # Hayes modem protocol >>> f.read(10) 'AT\n' # this is contrived, it might return 'AT\r\n' >>> There are other packages out there that will do this for you as well. [Shameless self-promotion] Such as ExpectPy, which is a C module interface to the Expect library (usually associated with Tcl); it doesn't sound like you need ExpectPy though. Definately look into termios. Myself, as a developer of FreeBSD products, I'd stay with Linux. There are a lot of problems that FreeBSD creates (and if you were to use FreeBSD, do NOT use the canned Python 1.5.2 in the distributions, build it yourself). -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From pt00aar@student.bth.se Sat Apr 21 00:27:45 2001 From: pt00aar@student.bth.se (Anders Arvidsson) Date: Sat, 21 Apr 2001 01:27:45 +0200 Subject: [Tutor] please help me and I will be so happy again Message-ID: <006b01c0c9f1$811f7e40$998f2fc2@rsn.hkr.se> This is a multi-part message in MIME format. ------=_NextPart_000_0068_01C0CA02.448FE440 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable People are very nice here on this mailing list.... My problem is that I shall create a program that get's stock values from = a website and then saves it in a textfile, and I dont know how to recive = the stock numbers from the website... ------=_NextPart_000_0068_01C0CA02.448FE440 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
People are very nice here on this = mailing=20 list....
My problem is that I shall create = a program=20 that get's stock values from a website and then saves it in a=20 textfile, and I dont know how to recive the stock numbers from the=20 website...
------=_NextPart_000_0068_01C0CA02.448FE440-- From parth.malwankar@wipro.com Sat Apr 21 01:23:46 2001 From: parth.malwankar@wipro.com (Parth Malwankar) Date: Sat, 21 Apr 2001 05:53:46 +0530 Subject: [Tutor] COM Ports In-Reply-To: <3ADFB2A6.9242E68@mindless.com>; from Timothy M. Brauch on Thu, Apr 19, 2001 at 11:53:10PM -0400 References: <3ADFB2A6.9242E68@mindless.com> Message-ID: <20010421055346.A8996@wipro.wipsys.sequent.com> Though I am very new to python, incase you are considering writing a wrapper to C code for accessing the serial port, functions _inp() and _outp() declared in c onio.h under windows provide access to i/o ports for reading and writing bytes. Regards, Parth On Thu, Apr 19, 2001 at 11:53:10PM -0400, Timothy M. Brauch wrote: |I have a program I want to write and I would greatly appreciate some |help with getting started. I think it can be done in Python, and would |love it if it can be. | |I have an infrared receiver for a remote control hooked up to my Win98 |computer's COM2. What I would like to do is be able to use the remote |to fun functions inside a Python program, depending on what button is |pushed. The receiver also can pick up signals from any remote, but the |program that came with the remote will only operate with this remote. I |would really like to eventually write a program that can be changed |fairly easily depending on what remote I have on hand (no need to worry |about losing the remote). | |The problem is I don't know how (or even if it is possible) to use |Python to "get" the buttons from COM2. Also, I'm not even sure what |COM2 sends when I do push a button. | |If someone can just point me in the right direction, I would be very |greatful. Of course, any other help you might want to provide would be |great as well. | | - Tim | |**I tried sending this earlier, but I don't know if it went through. If |so, please ignore my double posting.** | |_______________________________________________ |Tutor maillist - Tutor@python.org |http://mail.python.org/mailman/listinfo/tutor From rick@niof.net Sat Apr 21 03:29:18 2001 From: rick@niof.net (Rick Pasotto) Date: Fri, 20 Apr 2001 22:29:18 -0400 Subject: [Tutor] Help In-Reply-To: ; from vijay.kumar@cqsl.com on Wed, Apr 11, 2001 at 01:18:31PM -0400 References: Message-ID: <20010420222918.O15213@tc.niof.net> On Wed, Apr 11, 2001 at 01:18:31PM -0400, Vijay Kumar wrote: > > Hi, > > I am beginner in Python & working on Linux. > > I have set the PYTHONSTARTUP variable to some file in the .bash_profile. Are you sure? You need to post *exactly* what you have. Little things mean a lot. > When I start python Interactively this script is not being executed > alothough the PYTHONSTARTUP variable has the value which is specified in > the .bash_profile. > > How do I set the Value in the PYTHONSTARTUP variable ??? What are you trying to accomplish? -- "The financial policy of the welfare state requires that there be no way for the owners of wealth to protect themselves. This is the shabby secret of the welfare statists' tirades against gold. Deficit spending is simply a scheme for the 'hidden' confiscation of wealth. Gold stands in the way of this insidious process. It stands as a protector of property rights." -- Alan Greenspan Rick Pasotto email: rickp@telocity.com From joejava@dragoncat.net Sat Apr 21 05:31:15 2001 From: joejava@dragoncat.net (JRicker) Date: Sat, 21 Apr 2001 00:31:15 -0400 Subject: [Tutor] Regex troubles References: Message-ID: <003801c0ca1b$e9cfa080$d4a1d6d1@ceo> Ok I'm at wits end here and would love to hear some ideas on what I'm doing wrong here. I'm trying to match all occurances of this text in a web page: Some Text I want to be able to search for that text plus match certain keywords, and return the text between the two tags if the keyword appears anywhere in the text. Some code: keywords = "[Foobar|Some]" keyword_re = re.compile("(.*?" + keywords + ".*?)", re.I | re.DOTALL) for x in re.findall(keyword_re, apage): print x where apage is a web page .read() in. Now this is returning everything between each appearance of whether the keywords match or not. Something else that struck me as odd. I tried making keywords a single word to search for (ie keywords = "Some") and my script crashed giving me an error of maximum recursion level reached. Any ideas what caused this? Thanks Joel From not@my.house Sat Apr 21 07:56:41 2001 From: not@my.house (N/A) Date: Sat, 21 Apr 2001 01:56:41 -0500 Subject: [Tutor] newbie needs simple file handling help Message-ID: <000a01c0ca30$5d603140$824643cf@devious> This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0CA06.4F0DE8A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, i'm trying to write a program for creating and managing LARP = character sheets for a friend, I understand most of the basic syntax and = data handling needed, but I can't figure out how to open and write = strings to a text file. If it's possible could you send me the commands = and attributes for this, unfortunatley I don't have the code I have = written here and my linux box isn't online. any help is appreciated, Aaron ------=_NextPart_000_0007_01C0CA06.4F0DE8A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi, i'm trying to write a program for = creating and=20 managing LARP character sheets for a friend, I understand most of the = basic=20 syntax and data handling needed, but I can't figure out how to open and = write=20 strings to a text file. If it's possible could you send me the commands = and=20 attributes for this, unfortunatley I don't have the code I have written = here and=20 my linux box isn't online.
 
any help is appreciated,
Aaron
------=_NextPart_000_0007_01C0CA06.4F0DE8A0-- From dyoo@hkn.eecs.berkeley.edu Sat Apr 21 10:36:55 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 21 Apr 2001 02:36:55 -0700 (PDT) Subject: [Tutor] please help me and I will be so happy again In-Reply-To: <006b01c0c9f1$811f7e40$998f2fc2@rsn.hkr.se> Message-ID: On Sat, 21 Apr 2001, Anders Arvidsson wrote: > My problem is that I shall create a program that get's stock values > from a website and then saves it in a textfile, and I dont know how to > recive the stock numbers from the website... In this case, it might be easier not to work with the raw sockets, but to work with the urllib module: urllib lets us open network resources easily. For example, to read the contents of python.org's main page, we could do this: ### >>> import urllib >>> myfile = urllib.urlopen('http://www.python.org') >>> contents = myfile.read() >>> print contents[0:200] trunc (a) = 1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 13 fract(a) = 0101 --> fract (a) = 0 * 2^(-1) + 1 * 2^(-2) + 0 * 2^(-3) + 1* 2^(-4) = 0 * 1/2 + 1 * 1/4 + 0 * 1/8 + 1 * 1/16 As you can see, the precision obtained is 1/16. a = 13.3125 Tne number just prior to 'a' is 1101 0100, which is 13.25 in decimal. You can see that 13.3 has no correct representation, but it's not related to Python, just to the way numbers are represented by the computer. Benoit Remco Gerlich wrote: > On 0, Pijus Virketis wrote: > > Hi, > > > > not that this is very significant, but perhaps someone can explain this > > curious bit of output? > > > > Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 > > Type "copyright", "credits" or "license" for more information. > > IDLE 0.8 -- press F1 for help > > >>> 4.2-2.5 > > 1.7000000000000002 <-- ?!? Where do we get this miraculous digit? > > > > >>># just for comparison ... > > >>> 7.0-4.0 > > 3.0 <-- All's well ... > > >>> > > This has to do with the inherent inaccuracy of floating points that are > represented by a fixed number of binary digits. '4.2' has no precise > representation, neither has '1.7'. > > I finally got tired of answering this question so I added an explanation to > the FAQ, some other people should review it too since it's early morning and > I'm sure it could be worded better, but it's really time an explanation > for this is in there: > http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp > > -- > Remco Gerlich > From me@mboffin.com Thu Apr 26 17:57:06 2001 From: me@mboffin.com (Dylan Bennett) Date: Thu, 26 Apr 2001 09:57:06 -0700 Subject: [Tutor] Newbie question Message-ID: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> Hello, everyone. I just joined this list. I'm an instructor at a private boarding school and I'm looking at implementing Python as the introductory computer language for the students in the computer classes. (Right now we use QuickBASIC, which is rather out-dated.) I am new to Python myself. Since I'm exploring different ways of teaching Python to someone who has zero programming experience, I have been looking through some of the online resources. I am currently following a tutorial that was linked on the python.org site. If any of you happen to know of excellent resources for teaching Python to students with zero programming experience, please let me know. Now to my question. :) So I'm going through this tutorial and it says to do the following: s = raw_input("Who are you? ") That should pass what the user inputs to the variable s. However, when I run the program it gets to where I can input data, but then after I hit enter, it doesn't do anything. I just goes to the next line. Nothing I try will actually end it accepting input. It just keeps accepting input no matter how many times I hit enter. I even tried ctrl-enter, shift-enter, etc. Oh yeah, and I'm using IDLE in a Windows environment. Anyone have any ideas on why this isn't working? --Dylan From deirdre@deirdre.net Thu Apr 26 18:01:20 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Thu, 26 Apr 2001 10:01:20 -0700 Subject: [Tutor] Newbie question In-Reply-To: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> Message-ID: >Now to my question. :) So I'm going through this tutorial and it says to do >the following: > >s = raw_input("Who are you? ") > >That should pass what the user inputs to the variable s. However, when I run >the program it gets to where I can input data, but then after I hit enter, >it doesn't do anything. I just goes to the next line. Nothing I try will >actually end it accepting input. It just keeps accepting input no matter how >many times I hit enter. I even tried ctrl-enter, shift-enter, etc. Oh yeah, >and I'm using IDLE in a Windows environment. Anyone have any ideas on why >this isn't working? What's the rest of the program after that line? -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From wheelege@tsn.cc Thu Apr 26 18:02:38 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Fri, 27 Apr 2001 03:02:38 +1000 Subject: [Tutor] Newbie question References: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> Message-ID: <047a01c0ce72$b3002a60$0200a8c0@ACE> > Hello, everyone. I just joined this list. I'm an instructor at a private > boarding school and I'm looking at implementing Python as the introductory > computer language for the students in the computer classes. (Right now we > use QuickBASIC, which is rather out-dated.) I am new to Python myself. Since > I'm exploring different ways of teaching Python to someone who has zero > programming experience, I have been looking through some of the online > resources. I am currently following a tutorial that was linked on the > python.org site. If any of you happen to know of excellent resources for > teaching Python to students with zero programming experience, please let me > know. > Alan Gauld's tutorial is great - you can find it at http://www.crosswinds.net/~agauld > Now to my question. :) So I'm going through this tutorial and it says to do > the following: > > s = raw_input("Who are you? ") > > That should pass what the user inputs to the variable s. However, when I run > the program it gets to where I can input data, but then after I hit enter, > it doesn't do anything. I just goes to the next line. Nothing I try will > actually end it accepting input. It just keeps accepting input no matter how > many times I hit enter. I even tried ctrl-enter, shift-enter, etc. Oh yeah, > and I'm using IDLE in a Windows environment. Anyone have any ideas on why > this isn't working? > Alright, first off, are you at the interactive window? If so, then it will just keep accepting input - that's its job. If your not in the interactive window then try altering your script to say something like... s = raw_input("Who are you? ") print s Then save and run. If your going to go onto tkinter (the standard GUI toolkit for python) then I suggest you grab the Activestate IDE - it is not written IN tk (as opposed to IDLE) and handles such things alot better. Also, I have had bad experiences with threads in IDLE. I'm still relatively new myself, so don't just go on what I say :) Glen. > --Dylan > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From arcege@speakeasy.net Thu Apr 26 19:10:02 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 26 Apr 2001 14:10:02 -0400 (EDT) Subject: [Tutor] Newbie questiony In-Reply-To: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> from "Dylan Bennett" at Apr 26, 2001 09:57:06 AM Message-ID: <200104261810.f3QIA2x01236@dsl092-074-184.bos1.dsl.speakeasy.net> Dylan Bennett wrote > Now to my question. :) So I'm going through this tutorial and it says to do > the following: > > s = raw_input("Who are you? ") > > That should pass what the user inputs to the variable s. However, when I run > the program it gets to where I can input data, but then after I hit enter, > it doesn't do anything. I just goes to the next line. Nothing I try will > actually end it accepting input. It just keeps accepting input no matter how > many times I hit enter. I even tried ctrl-enter, shift-enter, etc. Oh yeah, > and I'm using IDLE in a Windows environment. Anyone have any ideas on why > this isn't working? This shouldn't be a problem with newer versions of IDLE (version 0.4 and later), but once upon a time it was indeed a problem. You might want to try Ctrl-D and Ctrl-Z (although I think both would end IDLE). Check which version you are using (select "About IDLE..." from the Help menu). And you might also want to see which version of Python you are running while you are at it. :) -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From pythoperson@yahoo.com Thu Apr 26 20:56:01 2001 From: pythoperson@yahoo.com (folklore hopeful) Date: Thu, 26 Apr 2001 12:56:01 -0700 (PDT) Subject: [Tutor] One more time: weird python windows batch file error Message-ID: <20010426195601.57704.qmail@web12405.mail.yahoo.com> Hello all, I posted about this before but perhaps I did not word it correctly. I have written a nifty python program and have burned it, along with py20, onto a CD-ROM so that it can be easily used on Win95 computers without installing Python. To make it easier for my non-dos savvy audience, I am trying to use a batch file to start the python program. That way I can say to everyone "click on My Computer. Click on the D drive. Click on the file call FOO.BAT" and we're away. My FOO.BAT contains this: @echo off pythonw FOO.PY It works just fine, but pops up an error message every time my users exit the program. It's the basic windows error message which says, in a nutshel "Pythonw.exe has done something illegal, tell it stop." Any suggestions what the problem might be? I know there are solutions other than a batch file, but I am now curious about this particular problem, regardless of whether there's a better way. What is causing the problem? Is it python? My batch file? Or windows? I appreciate any advice. Thanks to everyone for their help so far. __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From phil.bertram@clear.net.nz Thu Apr 26 21:17:09 2001 From: phil.bertram@clear.net.nz (Phil Bertram) Date: Fri, 27 Apr 2001 08:17:09 +1200 Subject: [Tutor] How to inspect variables in a module from the command line Message-ID: <003901c0ce8d$f7aaa440$723661cb@pf05nt.bayernz.co.nz> This is a multi-part message in MIME format. ------=_NextPart_000_0036_01C0CEF2.742197E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I often develop my programs by writing a class in a module class MyClass: stuff here if __name__ =3D=3D '__main__' : klass=3DMyClass() klass.mutate() print klass.attribute to run and test scripts written in a module. With print statements for = debugging. (I press f5 in PythonWin). Is there a way to switch to the interpreter and inspect the variables in = the module I've tried thinds like=20 >>> __main__.klass.anotherAttribute but can't seem to work it out. Any ideas ? Phil B ------=_NextPart_000_0036_01C0CEF2.742197E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
I often develop my programs by writing a class in a=20 module
 
class MyClass:
    stuff here
 
if __name__ =3D=3D '__main__' :
    klass=3DMyClass()
    klass.mutate()
    print = klass.attribute
 
to run and test scripts written in a module. With = print=20 statements for debugging. (I press f5 in PythonWin).
 
Is there a way to switch to the interpreter and = inspect the=20 variables in the module
I've tried thinds like
 
>>> = __main__.klass.anotherAttribute
 
but can't seem to work it out.
 
Any ideas ?
 
Phil B
------=_NextPart_000_0036_01C0CEF2.742197E0-- From me@mboffin.com Thu Apr 26 22:04:37 2001 From: me@mboffin.com (Dylan Bennett) Date: Thu, 26 Apr 2001 14:04:37 -0700 Subject: [Tutor] Newbie question References: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> <047a01c0ce72$b3002a60$0200a8c0@ACE> Message-ID: <001201c0ce94$8116a340$2101a8c0@delphian.org> Ok, I feel like kind of a putz. Some other things weren't working, so I checked some stuff out. Turns out I downloaded 1.52, not the latest version of 2.1. Hehe. Thanks for the help, anyway. I take it as a good sign of a close-knit, active community that within 15 minutes of posting I had gotten something like 5 replies. :) --Dylan From Desai.Dinakar@mayo.edu Thu Apr 26 22:16:48 2001 From: Desai.Dinakar@mayo.edu (Dinakar Desai) Date: Thu, 26 Apr 2001 16:16:48 -0500 Subject: [Tutor] command line syntax References: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> <047a01c0ce72$b3002a60$0200a8c0@ACE> <001201c0ce94$8116a340$2101a8c0@delphian.org> Message-ID: <3AE89040.AD39F5FB@mayo.edu> This is a multi-part message in MIME format. --------------92077563F41A7664805DA842 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello Everyone: I was wondering is there any way one can write command line script like that done in perl or shell. I tried FAQ and could not find what I was looking for. I look forward to hear from you. Dinakar --------------92077563F41A7664805DA842 Content-Type: text/x-vcard; charset=us-ascii; name="desai.dinakar.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Dinakar Desai Content-Disposition: attachment; filename="desai.dinakar.vcf" begin:vcard n:Desai;Dinakar tel;fax:507-284-0615 tel;home:507-289-3972 tel;work:507-266-2831 x-mozilla-html:FALSE adr:;;;;;; version:2.1 email;internet:desai.dinakar@mayo.edu note;quoted-printable:Restrictive tools designed to prevent the worst programmers from failing often prevent the best=0D=0Aprogrammers from succeeding. Conversely, unsupportive languages and tools can make average=0D=0Aprogrammers unproductive. fn:Dinakar end:vcard --------------92077563F41A7664805DA842-- From scarblac@pino.selwerd.nl Thu Apr 26 22:31:36 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 26 Apr 2001 23:31:36 +0200 Subject: [Tutor] command line syntax In-Reply-To: <3AE89040.AD39F5FB@mayo.edu>; from Desai.Dinakar@mayo.edu on Thu, Apr 26, 2001 at 04:16:48PM -0500 References: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> <047a01c0ce72$b3002a60$0200a8c0@ACE> <001201c0ce94$8116a340$2101a8c0@delphian.org> <3AE89040.AD39F5FB@mayo.edu> Message-ID: <20010426233136.A4669@pino.selwerd.nl> On 0, Dinakar Desai wrote: > I was wondering is there any way one can write command line script like > that done in perl or shell. > I tried FAQ and could not find what I was looking for. > > > I look forward to hear from you. I'm not sure what you mean. Is the -c option what you're looking for? bash$ python -c 'print "whee"' whee bash$ python -c ' > from time import * > print ctime() > ' Thu Apr 26 23:29:58 2001 If you want a script that you can start from the command line, just put in the appropriate #! line (#!/usr/bin/env python) just like you would with sh, perl, tcl, expect or whatever... -- Remco Gerlich From scarblac@pino.selwerd.nl Thu Apr 26 22:42:42 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 26 Apr 2001 23:42:42 +0200 Subject: [Tutor] How to inspect variables in a module from the command line In-Reply-To: <003901c0ce8d$f7aaa440$723661cb@pf05nt.bayernz.co.nz>; from phil.bertram@clear.net.nz on Fri, Apr 27, 2001 at 08:17:09AM +1200 References: <003901c0ce8d$f7aaa440$723661cb@pf05nt.bayernz.co.nz> Message-ID: <20010426234242.B4669@pino.selwerd.nl> On 0, Phil Bertram wrote: > I often develop my programs by writing a class in a module > > class MyClass: > stuff here > > if __name__ == '__main__' : > klass=MyClass() > klass.mutate() > print klass.attribute > > to run and test scripts written in a module. With print statements for debugging. (I press f5 in PythonWin). > > Is there a way to switch to the interpreter and inspect the variables in the module > I've tried thinds like > > >>> __main__.klass.anotherAttribute > > but can't seem to work it out. > > Any ideas ? I'm not sure what you mean so I'll just put some suggestions here. The current module's name is in __name__ (in the interactive interpreter, it's usually '__main__'). You can use that name to look up the module, in the dictionary sys.modules. The dir() function shows a list attributes of a module (or class, or other object). With getattr(object, name) you can get the value of some object So something like this is possible: import sys mod = sys.modules[__name__] # Get current module for attr in dir(mod): print attr, "=", repr(getattr(mod, attr)) This is what we call neat introspection abilities :) Similarly, mod.klass is the class klass in the module mod, and you can look at its attributes with dir() and getattr(), exactly the same way. Instead of mod, you can also use some module you just imported, like your script. With the command line option -i you can run a script first, then go into the interactive interpreter to inspect things (I don't have much Idle experience). Hmm, I hope I've written down enough random thoughts now to get to something useful :-) -- Remco Gerlich From aichele@mindspring.com Thu Apr 26 22:52:42 2001 From: aichele@mindspring.com (Stephen Aichele) Date: Thu, 26 Apr 2001 17:52:42 -0400 (EDT) Subject: [Tutor] id() In-Reply-To: Message-ID: <200104262152.RAA16267@mclean.mail.mindspring.net> I have a question regarding the use of id(): basically, I'd like to find a way to reverse this process- in otherwords, is there a way to access a specific instance's attributes from the id # alone? I need to do this because in my app, I may have several instances of the same class up concurrently - all with the same variable name... (I'm using wxPython) - I know that by reusing the variable name, I won't have access to any but the last instance created; however, I'm wondering if the previous instance IDs will still exist and if so, how to use them to access previous instances/windows... sorry to be so confusing (and confused), but if anyone has an idea of my problem and how to deal with it, I'd love to hear it. thanks! -Stephen From scarblac@pino.selwerd.nl Thu Apr 26 22:59:48 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 26 Apr 2001 23:59:48 +0200 Subject: [Tutor] id() In-Reply-To: <200104262152.RAA16267@mclean.mail.mindspring.net>; from aichele@mindspring.com on Thu, Apr 26, 2001 at 05:52:42PM -0400 References: <200104262152.RAA16267@mclean.mail.mindspring.net> Message-ID: <20010426235948.A4750@pino.selwerd.nl> On 0, Stephen Aichele wrote: > I have a question regarding the use of id(): basically, I'd like to find a > way to reverse this process- in otherwords, is there a way to access a > specific instance's attributes from the id # alone? No. > I need to do this because in my app, I may have several instances of the > same class up concurrently - all with the same variable name... (I'm using > wxPython) - I know that by reusing the variable name, I won't have access to > any but the last instance created; however, I'm wondering if the previous > instance IDs will still exist and if so, how to use them to access previous > instances/windows... An object ceases to exist when the last reference to it is gone. So if nothing else keeps a reference to your class instance, it will be gone the moment you assign something else to the variable. If something else does keep a reference (see, you've attached it to the GUI or so) there may be a way to get it back from there, who knows. > sorry to be so confusing (and confused), but if anyone has an idea of my > problem and how to deal with it, I'd love to hear it. Um, don't do that then? :) You could keep an index to them. Append them to a list when you create them, or something like that. Then you can keep referring to them through the list. Apparently you do keep the objects' id(). Why don't you keep the object itself there instead? Without more information about what you're doing I don't think I can give more advice. Time to sleep now, then I'll be gone for two days... -- Remco Gerlich From bdupire@seatech.fau.edu Thu Apr 26 23:04:24 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 26 Apr 2001 18:04:24 -0400 Subject: [Tutor] id() References: <200104262152.RAA16267@mclean.mail.mindspring.net> Message-ID: <3AE89B68.34789314@seatech.fau.edu> Stephen Aichele wrote: > I have a question regarding the use of id(): basically, I'd like to find a way to reverse this process- in otherwords, is there a way to access a specific instance's attributes from the id # alone? > > I need to do this because in my app, I may have several instances of the same class up concurrently - all with the same variable name... (I'm using wxPython) - I know that by reusing the variable name, I won't have access to any but the last instance created; however, I'm wondering if the previous instance IDs will still exist and if so, how to use them to access previous instances/windows... if you don't keep track of the old objects, they are deleted by the garbage collector. You can't access them anymore. I am not sure what you are referring to about wxPython.... To keep track of all your objects, just add them to a list... my_list = [] for i in range(1,5): my_list.append( MyClass() ) Then you can access the last object: my_list[-1] and the previous ones... If you want to refer an object by its id, you have to keep a table (dictionary) key= id, value = reference to the object... I don't think there is another way to do it... my_list = [] reverse_id_dict={} for i in range(1,5): obj = MyClass() my_list.append( obj) reverse_id_dict[id(obj)] = obj hope it helps benoit > > > sorry to be so confusing (and confused), but if anyone has an idea of my problem and how to deal with it, I'd love to hear it. > > thanks! > > -Stephen > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From bdupire@seatech.fau.edu Thu Apr 26 23:10:52 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 26 Apr 2001 18:10:52 -0400 Subject: [Tutor] id() References: <200104262152.RAA16267@mclean.mail.mindspring.net> <3AE89B68.34789314@seatech.fau.edu> Message-ID: <3AE89CEC.E950307B@seatech.fau.edu> Benoit Dupire wrote: > > I don't think there is another way to do it... > > my_list = [] > reverse_id_dict={} > for i in range(1,5): > obj = MyClass() > my_list.append( obj) > reverse_id_dict[id(obj)] = obj > actually i realize my_list is no use if you store the references in a dictionary. this is better : reverse_id_dict{} for i in range(1,5): obj = MyClass() reverse_id_dict[id(obj)] = obj From arcege@speakeasy.net Thu Apr 26 23:40:00 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 26 Apr 2001 18:40:00 -0400 (EDT) Subject: [Tutor] id() In-Reply-To: <200104262152.RAA16267@mclean.mail.mindspring.net> from "Stephen Aichele" at Apr 26, 2001 05:52:42 PM Message-ID: <200104262240.f3QMe0O01509@dsl092-074-184.bos1.dsl.speakeasy.net> Stephen Aichele wrote > > I have a question regarding the use of id(): basically, I'd like to find a way to reverse this process- in otherwords, is there a way to access a specific instance's attributes from the id # alone? > > I need to do this because in my app, I may have several instances of the same class up concurrently - all with the same variable name... (I'm using wxPython) - I know that by reusing the variable name, I won't have access to any but the last instance created; however, I'm wondering if the previous instance IDs will still exist and if so, how to use them to access previous instances/windows... > The short answer is: you won't be able to do what you are trying to do, at all (if it is what I'm gathering). Objects are areas of memory, yes, but dynamic memory (read malloc() with references counts to free up the memory. Variables are just bindings to objects, if you reassign, you decrement the reference to an object and increment the reference count to the new value. The 'sys' module has a nice function called getrefcount() which returns the number of references and object has, plus one for the function argument itself. >>> import sys >>> class A: ... pass ... >>> a = A() >>> sys.getrefcount(a) 2 - one for the binding to 'a', and one for the function call >>> b = a >>> id(a), id(b) (135094016, 135094016) >>> sys.getrefcount(a) 3 >>> a = A() # create a new instance and bind it to 'a' >>> sys.getrefcount(a), sys.getrefcount(b) (2, 2) >>> id(a), id(b) (135094192, 135094016) >>> Now when the reference count gets to 0 (no references to the object), the memory is freed, and therefore the memory is usable for another object. Basically, reusing variables won't give you access to old values because those old values may be gone and overwritten. In any event, Python does not have a mechanism for taking a "id" of an object and getting back the object itself. You might want to go thru past discussions on this in the Python newsgroup archives on the website. What you might want to do instead is place the objects in a list (maybe as a class member) to keep track of them. Just beware of "circular references" - you will need to remove the object from the list as well before the memory can be freed. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From csima@spidynamics.com Fri Apr 27 01:43:52 2001 From: csima@spidynamics.com (csima) Date: Thu, 26 Apr 2001 20:43:52 -0400 Subject: [Tutor] Python and DLL's Message-ID: <005101c0ceb3$220c4070$0201a8c0@gate> Does anyone have any information on being able to make a python script an activex dll? I want to be able to create a dll that will be accessible by a VB program From dyoo@hkn.eecs.berkeley.edu Fri Apr 27 03:10:26 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 26 Apr 2001 19:10:26 -0700 (PDT) Subject: [Tutor] % function In-Reply-To: <20010426164855.A3505@pino.selwerd.nl> Message-ID: On Thu, 26 Apr 2001, Remco Gerlich wrote: > On 0, Liana Wiehahn wrote: > > Can somebody please explain to me when you are using the % function and > > explain it to me? > > There are two different % operators, one for numbers and one for strings. > The number one computes the remainder of a division: > >>> 4 % 3 > 1 # Because if you do 4/3, the remainder is 1 > > You probably meant the string operator :). By the way, I finally found out where the documentation mentions string interpolation: http://python.org/doc/current/lib/typesseq-strings.html#l2h-68 and http://python.org/doc/current/tut/node9.html#SECTION009100000000000000000 so you can take a look at the documentation if you're a details-oriented person. From dyoo@hkn.eecs.berkeley.edu Fri Apr 27 03:19:11 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 26 Apr 2001 19:19:11 -0700 (PDT) Subject: [Tutor] One more time: weird python windows batch file error In-Reply-To: <20010426195601.57704.qmail@web12405.mail.yahoo.com> Message-ID: On Thu, 26 Apr 2001, folklore hopeful wrote: > Hello all, I posted about this before but perhaps I did not word > it correctly. I have written a nifty python program and have > burned it, along with py20, onto a CD-ROM so that it can be > easily used on Win95 computers without installing Python. To make > it easier for my non-dos savvy audience, I am trying to use > a batch file to start the python program. That way I can say > to everyone "click on My Computer. Click on the D drive. Click > on the file call FOO.BAT" and we're away. My FOO.BAT contains this: > > @echo off > pythonw FOO.PY > > It works just fine, but pops up an error message every time > my users exit the program. It's the basic windows error message > which says, in a nutshel "Pythonw.exe has done something illegal, > tell it stop." Ouch! pythonw.exe should never return an error message like this. Hmmm... have you tried using your program with Python 2.1? Let's make sure this isn't a bug that's been fixed recently. If the same thing happens with 2.1, then you'll probably want to talk with some people at comp.lang.python; they might be better able to help diagnose what's going on. Your batch file looks ok, so it's either Python or Windows. Personally, I'd put suspicion on Windows. *grin* Good luck to you. From dyoo@hkn.eecs.berkeley.edu Fri Apr 27 03:21:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 26 Apr 2001 19:21:33 -0700 (PDT) Subject: [Tutor] How to inspect variables in a module from the command line In-Reply-To: <003901c0ce8d$f7aaa440$723661cb@pf05nt.bayernz.co.nz> Message-ID: On Fri, 27 Apr 2001, Phil Bertram wrote: > I often develop my programs by writing a class in a module > > class MyClass: > stuff here > > if __name__ == '__main__' : > klass=MyClass() > klass.mutate() > print klass.attribute > > to run and test scripts written in a module. With print statements for > debugging. (I press f5 in PythonWin). > > Is there a way to switch to the interpreter and inspect the variables in the module > I've tried thinds like > > >>> __main__.klass.anotherAttribute > > but can't seem to work it out. It sounds like you might want to try out the debugger that comes with PythonWin. However, I have to profess total ignorance about it. *grin* Does anyone have any experience with PythonWin's debugger? From dyoo@hkn.eecs.berkeley.edu Fri Apr 27 03:30:32 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 26 Apr 2001 19:30:32 -0700 (PDT) Subject: [Tutor] Python and DLL's In-Reply-To: <005101c0ceb3$220c4070$0201a8c0@gate> Message-ID: On Thu, 26 Apr 2001, csima wrote: > Does anyone have any information on being able to make a python script an > activex dll? I want to be able to create a dll that will be accessible by a > VB program Hmmm... I haven't played with Windows in a while, but I've seen a few links that might be useful: There's some information on making DLL's here: http://python.org/doc/current/ext/building-on-windows.html There's also ways of writing COM objects in Python, which you should be able to access from VB. There's some information on doing this here: http://starship.python.net/crew/mhammond/ and the book "Python and Win32 Programming", by Mark Hammond and Andy Robinson: http://www.ora.com/catalog/pythonwin32/ gives more details about doing this sort of stuff. Good luck to you. From rfalck@home.com Fri Apr 27 06:34:54 2001 From: rfalck@home.com (Rick Falck) Date: Thu, 26 Apr 2001 22:34:54 -0700 Subject: [Tutor] Python problem... Message-ID: <3AE904FE.5F8D149@home.com> Hi, I tried to create a python extension dll but when I import it into python it gives an error message that says initExtest() si not defined - even though it is. It is a very simple example so I copied it into this email. Could you tell me what is wrong with this? Any help would be appreciated.... Code follows: ================================== #include #include #include int fac(int n) { if (n < 2) return(1); return ((n)*fac(n-1)); } char *reverse(char *s) { register char t, *p = s, *q = (s + (strlen(s) - 1)); while (s && (p < q)) { t = *p; *p++ = *q; *q-- = t; } return(s); } void test() { char s[BUFSIZ]; printf("4! == %d\n", fac(4)); printf("8! == %d\n", fac(8)); printf("12! == %d\n", fac(12)); strcpy(s, "abcdef"); printf("reversing 'abcdef', we get '%s'\n", \ reverse(s)); strcpy(s, "madam"); printf("reversing 'madam', we get '%s'\n", \ reverse(s)); } #include "Python.h" static PyObject * Extest_fac(PyObject *self, PyObject *args) { int num; if (!PyArg_ParseTuple(args, "i", &num)) return NULL; return (PyObject*)Py_BuildValue("i", fac(num)); } static PyObject * Extest_doppel(PyObject *self, PyObject *args) { char *orig_str; char *dupe_str; PyObject* retval; if (!PyArg_ParseTuple(args, "s", &orig_str)) return NULL; retval = (PyObject*)Py_BuildValue("ss", orig_str, dupe_str=reverse(strdup(orig_str))); free(dupe_str); return retval; } static PyObject * Extest_test(PyObject *self, PyObject *args) { test(); return (PyObject*)Py_BuildValue(""); } static PyMethodDef ExtestMethods[] = { { "fac", Extest_fac, METH_VARARGS }, { "doppel", Extest_doppel, METH_VARARGS }, { "test", Extest_test, METH_VARARGS }, { NULL, NULL }, }; DL_EXPORT(void) initExtest() { (void) Py_InitModule("Extest", ExtestMethods); } From rick@niof.net Thu Apr 26 22:26:29 2001 From: rick@niof.net (Rick Pasotto) Date: Thu, 26 Apr 2001 17:26:29 -0400 Subject: [Tutor] command line syntax In-Reply-To: <3AE89040.AD39F5FB@mayo.edu>; from Desai.Dinakar@mayo.edu on Thu, Apr 26, 2001 at 04:16:48PM -0500 References: <001e01c0ce71$ed6ace40$2101a8c0@delphian.org> <047a01c0ce72$b3002a60$0200a8c0@ACE> <001201c0ce94$8116a340$2101a8c0@delphian.org> <3AE89040.AD39F5FB@mayo.edu> Message-ID: <20010426172629.A23289@tc.niof.net> On Thu, Apr 26, 2001 at 04:16:48PM -0500, Dinakar Desai wrote: > Hello Everyone: > > I was wondering is there any way one can write command line script like > that done in perl or shell. > I tried FAQ and could not find what I was looking for. That would be rather difficult since white space *is* significant in python. -- "The means of defense against foreign danger historically have become the instruments of tyranny at home." -- James Madison Rick Pasotto email: rickp@telocity.com From rob@jam.rr.com Fri Apr 27 12:37:54 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Fri, 27 Apr 2001 06:37:54 -0500 Subject: [Tutor] ActiveState Python Cookbook Message-ID: <3AE95A12.69D5243C@jam.rr.com> ActiveState and O'Reilly, in a clear attempt to copy Useless Python, have set up the on-line Python Cookbook. I just pass this on because I figure it might turn into a useful resource for some of us, and we just might stumble across contributions from some of the Elder pythonistas on the tutor list there. http://www.activestate.com/ASPN/Python/Cookbook/ -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From Mark A. Tobin" Message-ID: <001d01c0cf1d$6674b660$4bbcc28e@anonymous> Hi there, I've been playing around with Python for a while now as my first real foray into programming. I've just started looking at creating classes as they seem to be the more "mature" way to structure one's programming. I can now implement instances and what not, thanks to some of the great tutorials out there, however I can't figure out what the "self" argument is all about. It is used throughout the program to refer to something, but I don't really "get it". As I said, I can use it (i.e.. repeat the structure I've seen in the tutorials by rote), but I don't really know why or how I'm using it. An explanation or a point to an explanation would be helpful, Mark From kalle@gnupung.net Fri Apr 27 15:04:27 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 27 Apr 2001 16:04:27 +0200 Subject: [Tutor] Classes and "Self" In-Reply-To: <001d01c0cf1d$6674b660$4bbcc28e@anonymous>; from mtobin@attcanada.net on Fri, Apr 27, 2001 at 09:24:32AM -0400 References: <001d01c0cf1d$6674b660$4bbcc28e@anonymous> Message-ID: <20010427160427.A980@father> Sez Mark A. Tobin: > Hi there, > I've been playing around with Python for a while now as my first real foray > into programming. I've just started looking at creating classes as they > seem to be the more "mature" way to structure one's programming. I can now > implement instances and what not, thanks to some of the great tutorials out > there, however I can't figure out what the "self" argument is all about. Well, it is a reference to the instance that the method is run with. An example: >>> class C: ... def f(self): ... global i, j # don't do this at home, kids... ... if i is self: ... print "self is i!" ... elif j is self: ... print "self is j!" ... else: ... print "self is not i or j!" ... >>> i = C(); j = C(); k = C() # create three instances of C >>> i.f() self is i! >>> j.f() self is j! >>> k.f() self is not i or j! >>> C.f(i) # check this one out... self is i! self is used to access the methods and data of the instance from inside its own methods. It is automatically passed as the first argument when a method is sccessed from a class instace. When the method is accessed from the class, as in the last example, it's called an unbound method and the first argument must be an instance of the class or a subclass. I don't know if that helped at all, but it's a try. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From wheelege@tsn.cc Fri Apr 27 15:23:02 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sat, 28 Apr 2001 00:23:02 +1000 Subject: [Tutor] X11 Bitmaps in windows... Message-ID: <04e101c0cf25$922c72e0$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_04DE_01C0CF79.63290900 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I'm looking for some way to make a bitmap in windows. I have been = looking on the 'net for any tool - but all I find are = unix/linux/not-windows utilities. The reason I'd like an X11 bitmap is so I can use it for my icon in a = tkinter program I'm making. I am sure that I can make a normal bitmap = with colours as my icon - because I have seen other tcl/tk programs do = it. However, I cannot find any mention of it in the docs or the book = 'Python and Tkinter Programming'. Specifically, this is what I'm trying to do... from tkinter import * root =3D TK() myicon =3D BitmapImage(file=3Dr'C:\icon.bmp') root.iconbitmap(icon) Seems it only wants a monochrome bitmap in that case. Thanks for any help, Glen. ------=_NextPart_000_04DE_01C0CF79.63290900 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hi all,
 
  I'm looking for some way to make a bitmap in windows.  = I have=20 been looking on the 'net for any tool - but all I find are=20 unix/linux/not-windows utilities.
  The reason I'd like an X11 bitmap is so I can use it for my = icon in=20 a tkinter program I'm making.  I am sure that I can make a normal = bitmap=20 with colours as my icon - because I have seen other tcl/tk programs do = it. =20 However, I cannot find any mention of it in the docs or the book 'Python = and=20 Tkinter Programming'.
  Specifically, this is what I'm trying to do...
 
from tkinter import *
root =3D TK()
myicon =3D BitmapImage(file=3Dr'C:\icon.bmp')
root.iconbitmap(icon)
 
  Seems it only wants a monochrome bitmap in that case.
 
  Thanks for any help,
  Glen.
------=_NextPart_000_04DE_01C0CF79.63290900-- From bdupire@seatech.fau.edu Fri Apr 27 16:05:35 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Fri, 27 Apr 2001 11:05:35 -0400 Subject: [Tutor] Classes and "Self" References: <001d01c0cf1d$6674b660$4bbcc28e@anonymous> Message-ID: <3AE98ABF.17B53991@seatech.fau.edu> Here's my try: ;o) Correct me if i am wrong >>> class Foo: def __init__(self, value): i = 8 self.name = value >>> dir(Foo) ['__doc__', '__init__', '__module__'] >>> a=Foo(12) >>> dir(a) ['name'] Why self ? Namespace issue! >From within __init__, the local namespace consists of all the variables defined within __init__ (ie i can access 'i') The global namespace is the module (ie. i can access a). and there is the built in namespace.... I can't access 'name' directly from __init__ because it is in the object namespace (somewhat nested), and thus it's not local to __init__ or global to the module I can access 'name' from the global namespace, using 'a.name'. So i can access 'name' from __init__ only if i have got a reference to 'a', so that i can use 'a.name' As the problem occurs for every instance variables, we need this ref every time and to pass it, and the convention is to call it self. When you call __init__(a, 12) then you create 2 variable in the __init__ namespace self, and i. "Mark A. Tobin" wrote: > Hi there, > I've been playing around with Python for a while now as my first real foray > into programming. I've just started looking at creating classes as they > seem to be the more "mature" way to structure one's programming. I can now > implement instances and what not, thanks to some of the great tutorials out > there, however I can't figure out what the "self" argument is all about. It > is used throughout the program to refer to something, but I don't really > "get it". As I said, I can use it (i.e.. repeat the structure I've seen in > the tutorials by rote), but I don't really know why or how I'm using it. > An explanation or a point to an explanation would be helpful, > > Mark > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From Christopher Bemis" This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C0CF16.2B444B20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Does anyone know how I can fix this problem? I can run my programs from = IDLE, and from Start/Run, but when I type: Python Helloworld.py ,e.g. = into a command prompt, I keep getting "Bad Command or File Name". I'm = still kinda new at this, but is there any way for me to fix this? The Great One ------=_NextPart_000_0009_01C0CF16.2B444B20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Does = anyone know=20 how I can fix this problem? I can run my programs from IDLE, and from = Start/Run,=20 but when I type: Python Helloworld.py ,e.g.   into a command = prompt, I=20 keep getting "Bad Command or File Name". I'm still kinda new at this, = but is=20 there any way for me to fix this?
The = Great=20 One
------=_NextPart_000_0009_01C0CF16.2B444B20-- From vlindberg@verio.net Fri Apr 27 20:32:31 2001 From: vlindberg@verio.net (VanL) Date: Fri, 27 Apr 2001 13:32:31 -0600 Subject: [Tutor] Classes and "Self" References: <001d01c0cf1d$6674b660$4bbcc28e@anonymous> Message-ID: <3AE9C94F.FA919CCD@verio.net> I'll try too. This may be a bit long-winded, but I'll get to your question. The concept of object-oriented programming (OOP) was invented, in part, to help make software contructs that mirrored their real-world counterparts. Previous imperative programs worked more like a recipe -- take the ingredients, follow a procedure, produce an output. While this worked well for a lot of problems, there were certain problems that didn't match well to this style of solving a problem. Take, for instance, a software model that would drive a (virtual) car. In an imperative program, the program would need to know a lot about how all of the different parts of the car worked -- after all, the same 'recipe' would control everything from steering to the drivetrain to the electrical system. In an important sense, though, that isn't how we drive a car. We don't have to worry about the drivetrain or the electrical system while we are steering -- we have a couple of well-defined controls (the steering wheel, pedals, etc) to tell the car what we want to do and we don't worry about the underlying mechanics of how it all works. Thus, this problem could be modeled more closely by imagining a set of interacting players, each of which did one particular thing. The 'driver' object steered, the 'drivetrain' object transmitted power, etc. These objects worked with each other via defined interfaces. Furthermore, an interacting collection of objects could itself be considered an object, just like we take a bunch of parts, put them together, and call them a car. Now when we think of a physical object with controls, it is sort of hard to imagine the steering wheel of one car actually controlling some other car down the street. With software, though, it was possible to do just that. Hence, it was necessary to define which object went with which set of controls. Now when you declare an instance of an class, you are actually doing two things: 1. creating the instance (the object) and 2. naming it uniquely. This enables the computer to keep track of which set of controls goes with each object. The 'self' parameter is the object's internal name -- it lets the computer know which object you actually want to do stuff with. HTH, VanL From doc_pepin@yahoo.com Fri Apr 27 20:29:50 2001 From: doc_pepin@yahoo.com (doc pepin) Date: Fri, 27 Apr 2001 12:29:50 -0700 (PDT) Subject: [Tutor] tkinter or python Message-ID: <20010427192950.85590.qmail@web13903.mail.yahoo.com> for a newbie programmer which is easier learn tkinter or wxpython __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From bdupire@seatech.fau.edu Fri Apr 27 22:38:13 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Fri, 27 Apr 2001 17:38:13 -0400 Subject: [Tutor] DOS Prompt .. changing PATH envir. var References: <000c01c0cf37$b6b8f720$2008683f@laser151> <3AE9C386.1310809E@seatech.fau.edu> <000e01c0cf5d$8188aca0$3f08683f@laser151> Message-ID: <3AE9E6C5.A9DA1868@seatech.fau.edu> If C:\Python20 is the name of the directory in which Python is installed type: set PATH=C:\Python20;%PATH% If you don't want to type this command each time you reboot your PC (win 98 :o) !!! ), you can edit the autoexec.bat file at the root of the file system...and add PATH=C:\Python20;%PATH% (i don't think you need the 'set', but i have NT , i do this another way , not sure about this) Christopher Bemis wrote: > I have Python 1.5, on a Windows98SE machine, How do I change the > path?It comes from DOS...The Great One From cooler12001@yahoo.com Sat Apr 28 07:22:45 2001 From: cooler12001@yahoo.com (Matthews James) Date: Fri, 27 Apr 2001 23:22:45 -0700 (PDT) Subject: [Tutor] how do i get one of my program to open when i open a folder or something. Message-ID: <20010428062245.2289.qmail@web11401.mail.yahoo.com> i am want a program of mine to open when i open a folder sort of like a password protecting thingamabob Thanks James __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From deirdre@deirdre.net Sat Apr 28 07:38:17 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Fri, 27 Apr 2001 23:38:17 -0700 Subject: [Tutor] how do i get one of my program to open when i open a folder or something. In-Reply-To: <20010428062245.2289.qmail@web11401.mail.yahoo.com> References: <20010428062245.2289.qmail@web11401.mail.yahoo.com> Message-ID: >i am want a program of mine to open when i open a >folder sort of like a password protecting thingamabob It would help significantly if you mentioned what operating system you were programming on. In any case, it probably involves more interaction with the operating system than you might prefer to code. -- -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From wheelege@tsn.cc Sat Apr 28 08:09:17 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sat, 28 Apr 2001 17:09:17 +1000 Subject: [Tutor] tkinter or python References: <20010427192950.85590.qmail@web13903.mail.yahoo.com> Message-ID: <00d801c0cfb2$24ba6ea0$0200a8c0@ACE> > for a newbie programmer which is easier learn tkinter > or wxpython > Tkinter is definitely easier to learn for a newbie programer - as to which one is 'better' to learn, that is still up for debate. You will *need* to get some understanding of Object Oriented programming before you start with tkinter. I recommend going through Alan Gaulds tutorial (here : http://www.crosswinds.net/~agauld) with particular regard to the Object Oriented Programming section and the tkinter section. Glen. From brett42@flex.com Sat Apr 28 08:32:16 2001 From: brett42@flex.com (Brett) Date: Fri, 27 Apr 2001 21:32:16 -1000 Subject: [Tutor] A couple questions about lists Message-ID: <4.3.2.7.0.20010427211821.00ab3230@mail.flex.com> I had some variables I wanted to do similar operations on, so i put them in a list and sent them through a for loop:
for x in [a,b,c,d,e]:
        if x<10:
                x=x+10
 After running this the list and the variables all had the same values, but x was equal to 15(the value of e). Is there a way to change part of a list with using it's index?  Either way, I figured out that I could use
list=[a,b,c,d,e]
for x in range(0,4):
        if list[x]<10:
                list[x]=list[x]+10
But it only changed the values in the list, and didn't change the variables.  Is there a way to make a list, or some other object, that keeps a reference to the variable instead of just taking it's value?


When Schrodinger's cat's away,
the mice may or may not play,
no one can tell.
From wheelege@tsn.cc Sat Apr 28 08:46:38 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sat, 28 Apr 2001 17:46:38 +1000 Subject: [Tutor] A couple questions about lists Message-ID: <00f801c0cfb7$5da91220$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_00F5_01C0D00B.2CD750E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I had some variables I wanted to do similar operations on, so i put = them in a list and sent them through a for loop: for x in [a,b,c,d,e]: if x<10: x=3Dx+10 After running this the list and the variables all had the same = values, but x was equal to 15(the value of e). Is there a way to change = part of a list with using it's index? Either way, I figured out that I = could use list=3D[a,b,c,d,e] for x in range(0,4): if list[x]<10: list[x]=3Dlist[x]+10 But it only changed the values in the list, and didn't change the = variables. Is there a way to make a list, or some other object, that = keeps a reference to the variable instead of just taking it's value? Okay, so you want to get some variables, put them in a list and make a = change to a member of the list change the variable that was its model? First off, I've got to ask why you don't just use lists and give up on = the single variables? For example... >>> x =3D 1 >>> y =3D 2 >>> z =3D 3 >>> l =3D [x, y, z] >>> l [1, 2, 3] >>> l[0] 1 >>> l[1] 2 >>> l[2] 3 Now, how is writing l[0] different to writing x? Except for the two = extra key presses, I don't see any disadvantages to storing it this way. = Then something like... >>> for index in range(len(l)): ... l[index] =3D l[index] + 5 ...=20 >>> l [6, 7, 8] >>> l[0] 6 >>> l[1] 7 >>> l[2] 8 Will work fine, and you don't need to worry about it. I only say this = because the only way I can see to get back to the x,y,z variables is by = direct assignment - ie x =3D l[0], y =3D l[1], z =3D l[2]. Which just = adds another step when you can directly reference them by just writing = l[0] etc. Food for thought, Glen. ------=_NextPart_000_00F5_01C0D00B.2CD750E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I had some variables I wanted to do similar operations on, so i = put them=20 in a list and sent them through a for loop:
for x in=20 = [a,b,c,d,e]:
        if=20 = x<10:
                x=3Dx+10=

 After running this the list and the variables all had = the same=20 values, but x was equal to 15(the value of e). Is there a way to = change=20 part of a list with using it's index?  Either way, I figured = out that=20 I could use
list=3D[a,b,c,d,e]
for x in=20 = range(0,4):
        if=20 = list[x]<10:
        =         li= st[x]=3Dlist[x]+10
But=20 it only changed the values in the list, and didn't change the = variables. =20 Is there a way to make a list, or some other object, that keeps a = reference=20 to the variable instead of just taking it's = value?
  Okay, so you want to get some variables, put them in a list = and make=20 a change to a member of the list change the variable that was its = model?
  First off, I've got to ask why you don't just use lists and = give up=20 on the single variables?  For example...
 
>>> x =3D 1
>>> y =3D 2
>>> z =3D=20 3
>>> l =3D [x, y, z]
>>> l
[1, 2, = 3]
>>>=20 l[0]
1
>>> l[1]
2
>>> l[2]
3
  Now, how is writing l[0] different to writing x?  = Except for=20 the two extra key presses, I don't see any disadvantages to storing it = this=20 way.  Then something like...
 
>>> for index in range(len(l)):
...  l[index] =3D = l[index] +=20 5
...
>>> l
[6, 7, 8]
>>>=20 l[0]
6
>>> l[1]
7
>>> l[2]
8
 
  Will work fine, and you don't need to worry about it.  = I only=20 say this because the only way I can see to get back to the x,y,z = variables=20 is by direct assignment - ie x =3D l[0], y =3D l[1], z =3D l[2].  = Which just adds=20 another step when you can directly reference them by just writing l[0]=20 etc.
 
  Food for thought,
  Glen.
------=_NextPart_000_00F5_01C0D00B.2CD750E0-- From wheelege@tsn.cc Sat Apr 28 10:55:24 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Sat, 28 Apr 2001 19:55:24 +1000 Subject: [Tutor] Not-so Quick Question References: <03b401c0ce62$c380f820$0200a8c0@ACE> <20010426173216.A3593@pino.selwerd.nl> Message-ID: <011a01c0cfc9$5a81b540$0200a8c0@ACE> > > > Try to make your problem as small as possible, ie make the smallest program > that still has the problem. This may well be a Tcl/Tk bug, if you're sure > the 'expected' string doesn't occur in your program. > I now think it is a Pythonwin problem - I run the program under pythonwin and now it gets to the point where even ignoring the error through tr: except: will not work - it still stops inside that function. So I thought it might be similar to my problem with IDLE and ran it through the command line - not even one error. Whereas when running under pythonwin I would get about 10 messages inside a minute, and then wouldn't be able to continue. So, perhaps a bug report to Activestate? Glen. > -- > Remco Gerlich > > From renegade_65535@hotmail.com Sat Apr 28 16:09:36 2001 From: renegade_65535@hotmail.com (JJk k) Date: Sat, 28 Apr 2001 16:09:36 +0100 Subject: [Tutor] Help: Python GUI Message-ID: Hi, How do I use the GUI? Say if I wanted to say: >>>print "None Shall Pass!" >>>"\n" >>>print "Fight or Die" Thats just an example, but when I type the first line in (print "None Shall Pass") when I press enter to carry on typing, it just prints out None Shall Pass How do I use this correctly? I'd really appreciate help :) Thanks very much :) Jake. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From rob@jam.rr.com Sat Apr 28 16:28:37 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Sat, 28 Apr 2001 10:28:37 -0500 Subject: [Tutor] Help: Python GUI References: Message-ID: <3AEAE1A5.BEAA0460@jam.rr.com> Were you looking for something like this? >>> print "None Shall Pass!\nFight or Die!" None Shall Pass! Fight or Die! Rob JJk k wrote: > > Hi, > How do I use the GUI? > Say if I wanted to say: > >>>print "None Shall Pass!" > >>>"\n" > >>>print "Fight or Die" > > Thats just an example, but when I type the first line in (print "None Shall > Pass") when I press enter to carry on typing, it just prints out > None Shall Pass > How do I use this correctly? I'd really appreciate help :) > Thanks very much :) > Jake. > _________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From rob@jam.rr.com Sat Apr 28 16:44:18 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Sat, 28 Apr 2001 10:44:18 -0500 Subject: [Tutor] Help: Python GUI References: Message-ID: <3AEAE552.92D6D2F9@jam.rr.com> Well, you do have options. I assume you're using IDLE, PythonWin, or something similar, where you type in a line of code, press [Enter], and get prompted for another line of code with >>>. You can also use your favorite text editor (such as notepad if you're using Windows) to just type the entire script in a document. Then save it as a document ending in .py (fightordie.py, for example). It often doesn't matter where you save the file, but since it *sometimes* matters, you can safely save the file in the folder/directory containing your Python install, such as (again, assuming Windows) C:\Python21. You can then run the program in one of several different ways, but try doing this within IDLE: >>>import fightordie Notice that you can leave off the .py when running the script in this manner. Or from the command prompt (which some Windows users call the DOS prompt): C:\Python21>python fightordie.py Which operating system are you running, by the way? And does this help any? Rob JJk k wrote: > > Thank you very much! That's a great help, > but say I wanted a large script using the "print" function, if I pressed > enter to start a new line, it says "syntac error" or something like that, so > how would I write multiple lines on sepatate lines without using "\n"? > Thank you again :) > _________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From deirdre@deirdre.net Sat Apr 28 18:30:52 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Sat, 28 Apr 2001 10:30:52 -0700 Subject: [Tutor] Help: Python GUI In-Reply-To: References: Message-ID: >Hi, >How do I use the GUI? This question is platform-dependent to some extent, so it's helpful to state what platform you're on and what your ultimate aims are so we can help you. (I know, I sound like a broken record....) -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From deirdre@deirdre.net Sat Apr 28 18:38:31 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Sat, 28 Apr 2001 10:38:31 -0700 Subject: [Tutor] Help: Python GUI In-Reply-To: References: Message-ID: >Erm..i nto actually sure myself! lol! >What do u want to do with it?? I think you're confused -- I was trying to help answer your question, but I need more information. Recognize that the GUI toolkits are not a part of the language proper and that only some subset of people on a list will be able to answer questions about any specific one. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From jko@andover.edu Sat Apr 28 20:41:30 2001 From: jko@andover.edu (Justin Ko) Date: Sat, 28 Apr 2001 15:41:30 -0400 Subject: [Tutor] Low Level Reads Message-ID: <5.0.0.25.2.20010428153001.0232dd60@mail.andover.edu> Hey everyone, I've got a question about reading from files. I'm working on a module to read ID3v2 tags off of mp3 files. When I read data from the mp3 file, the data is returned as a string of hex. For instance... >>> file = open("some.mp3") >>> file.seek(0, 0) >>> header = file.read(11) >>> header 'ID3\x03\x00\x00\x00\x00\x0ejT' >>> How can i perform the conversion from hex to base 10? More specifically, I need to obtain base 10 values for header[3:5]. int() doesn't seem to like hexadecimal values. Neither does str() or float()... _justin Ko From dyoo@hkn.eecs.berkeley.edu Sat Apr 28 21:59:49 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Apr 2001 13:59:49 -0700 (PDT) Subject: [Tutor] Low Level Reads In-Reply-To: <5.0.0.25.2.20010428153001.0232dd60@mail.andover.edu> Message-ID: On Sat, 28 Apr 2001, Justin Ko wrote: > Hey everyone, > I've got a question about reading from files. I'm working on a > module to read ID3v2 tags off of mp3 files. When I read data from the mp3 > file, the data is returned as a string of hex. For instance... > > > >>> file = open("some.mp3") > >>> file.seek(0, 0) > >>> header = file.read(11) > >>> header > 'ID3\x03\x00\x00\x00\x00\x0ejT' > >>> > > How can i perform the conversion from hex to base 10? More > specifically, I need to obtain base 10 values for header[3:5]. int() > doesn't seem to like hexadecimal values. Neither does str() or float()... I thought that int() would be fairly happy with hexidecimal numbers. Let's check: ### >>> int("0x03") Traceback (innermost last): File "", line 1, in ? ValueError: invalid literal for int(): 0x03 ### You're right; int() doesn't appear to know how to work with hexidecimal. However, there's a more robust version of int() within the string module called atoi() ("ascii to integer"): ### >>> import string >>> print string.atoi.__doc__ atoi(s [,base]) -> int Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. ### Let's try this out: ### >>> string.atoi("0x03", 0) 3 ### Ok, so string.atoi() looks like it will be more useful for you: it can convert strings in a particular base, like hexidecimal, to integers. Try using string.atoi() instead. Good luck! From rick@niof.net Sat Apr 28 23:35:09 2001 From: rick@niof.net (Rick Pasotto) Date: Sat, 28 Apr 2001 18:35:09 -0400 Subject: [Tutor] Low Level Reads In-Reply-To: <5.0.0.25.2.20010428153001.0232dd60@mail.andover.edu>; from jko@andover.edu on Sat, Apr 28, 2001 at 03:41:30PM -0400 References: <5.0.0.25.2.20010428153001.0232dd60@mail.andover.edu> Message-ID: <20010428183509.B23289@tc.niof.net> On Sat, Apr 28, 2001 at 03:41:30PM -0400, Justin Ko wrote: > > > Hey everyone, > I've got a question about reading from files. I'm working on a > module to read ID3v2 tags off of mp3 files. When I read data from the mp3 > file, the data is returned as a string of hex. For instance... > > > >>> file = open("some.mp3") > >>> file.seek(0, 0) > >>> header = file.read(11) > >>> header > 'ID3\x03\x00\x00\x00\x00\x0ejT' > >>> > > How can i perform the conversion from hex to base 10? More > specifically, I need to obtain base 10 values for header[3:5]. int() > doesn't seem to like hexadecimal values. Neither does str() or float()... The start of an ID3v2 header is 'ID\x33'. 0x33 *is* decimal 3. -- "I would remind you that extremism in the defense of liberty is no vice. And let me remind you also that moderation in the pursuit of liberty is no virtue." -- Barry Goldwater Rick Pasotto email: rickp@telocity.com From netsspike@hotmail.com Sun Apr 29 00:55:59 2001 From: netsspike@hotmail.com (net spike) Date: Sat, 28 Apr 2001 23:55:59 -0000 Subject: [Tutor] how can i Message-ID: how do i set my system up so if i open a command promp and type python it will start the python prompt? i run windows 2000pro if thats any help thank you for any help you can provide Brian _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From julieta_rangel@hotmail.com Sun Apr 29 02:31:59 2001 From: julieta_rangel@hotmail.com (Julieta) Date: Sat, 28 Apr 2001 20:31:59 -0500 Subject: [Tutor] 15 puzzle Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0D022.467F7EC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi! My name is Maritza and I am trying to learn how to program with the = python language. I'm interested in a computer version of the 15 puzzle. = I've seen how it works and used it as well, but I am curious about how = the program was set up. Just to make sure that we all know which puzzle = I'm refering to, it is the one that you can get at toy stores and is = essentially a 4 x 4 matrix with the numbers 1-15 on tiles placed in the = matrix. There is one blank space where tiles adjacent to the blank = space may be moved into the blank space. The object of the game is to = arrange the numbers 1-15 in order. They are initially scrambled, of = course. If you have this program or can help me put it together, please = e-mail me at maritza_rodz.hotmail.com ------=_NextPart_000_0005_01C0D022.467F7EC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi! My name is Maritza and I am trying = to learn how=20 to program with the python language.  I'm interested in a computer = version=20 of the 15 puzzle.  I've seen how it works and used it as well, but = I am=20 curious about how the program was set up.  Just to make sure that = we all=20 know which puzzle I'm refering to, it is the one that you can get at toy = stores=20 and is essentially a 4 x 4 matrix with the numbers 1-15 on tiles placed = in the=20 matrix.  There is one blank space where tiles adjacent to the blank = space=20 may be moved into the blank space.  The object of the game is to = arrange=20 the numbers 1-15 in order.  They are initially scrambled, of = course. =20 If you have this program or can help me put it together, = please e-mail=20 me at maritza_rodz.hotmail.com
------=_NextPart_000_0005_01C0D022.467F7EC0-- From kalle@gnupung.net Sun Apr 29 02:51:36 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sun, 29 Apr 2001 03:51:36 +0200 Subject: [Tutor] Low Level Reads In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Sat, Apr 28, 2001 at 01:59:49PM -0700 References: <5.0.0.25.2.20010428153001.0232dd60@mail.andover.edu> Message-ID: <20010429035136.A368@apone.network.loc> Sez Daniel Yoo: > On Sat, 28 Apr 2001, Justin Ko wrote: > > > Hey everyone, > > I've got a question about reading from files. I'm working on a > > module to read ID3v2 tags off of mp3 files. When I read data from the mp3 > > file, the data is returned as a string of hex. For instance... > > > > > > >>> file = open("some.mp3") > > >>> file.seek(0, 0) > > >>> header = file.read(11) > > >>> header > > 'ID3\x03\x00\x00\x00\x00\x0ejT' > > >>> > > > > How can i perform the conversion from hex to base 10? More > > specifically, I need to obtain base 10 values for header[3:5]. int() > > doesn't seem to like hexadecimal values. Neither does str() or float()... The thing is, the data is not returned hex-encoded, it is returned raw. You want to take a look at the struct module. >>> import struct >>> file = open("some.mp3") >>> file.seek(0, 0) # this is not necessary if you just opened the file. >>> header = file.read(11) >>> header 'ID3\x03\x00\x00\x00\x00\x0ejT' >>> struct.unpack("h", header[3:5]) (3,) >>> > I thought that int() would be fairly happy with hexidecimal numbers. > Let's check: > > ### > >>> int("0x03") > Traceback (innermost last): > File "", line 1, in ? > ValueError: invalid literal for int(): 0x03 > ### > > You're right; int() doesn't appear to know how to work with hexidecimal. You need to supply a second argument: >>> int("0x03") Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): 0x03 >>> int("0x03", 16) 3 > However, there's a more robust version of int() within the string module > called atoi() ("ascii to integer"): [snip] > Ok, so string.atoi() looks like it will be more useful for you: it can > convert strings in a particular base, like hexidecimal, to integers. Try > using string.atoi() instead. string.atoi is deprecated, IIRC. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From bdupire@seatech.fau.edu Sun Apr 29 02:54:54 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Sat, 28 Apr 2001 21:54:54 -0400 Subject: [Tutor] how can i References: Message-ID: <3AEB746E.FC59D556@seatech.fau.edu> You need to change the PATH variable which designates the default directories in which the OS looks into to find your programs...... If C:\Python20 is the name of the directory in which Python is installed type: set PATH=C:\Python20;%PATH% If you don't want to type this command each time you reboot your PC you can edit the autoexec.bat file at the root of the file system...and add PATH=C:\Python20;%PATH% I don't know at all Windows 2000.... In NT you can do START > Settings > Control Panel > System > environment and there you can set the PATH environment variable check if this works with Win2000.... hope it helps... Benoit net spike wrote: > how do i set my system up so if i open a command promp and type python > it will start the python prompt? i run windows 2000pro if thats any help > thank you for any help you can provide > > Brian > _________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From dyoo@hkn.eecs.berkeley.edu Sun Apr 29 03:01:57 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Apr 2001 19:01:57 -0700 (PDT) Subject: [Tutor] 15 puzzle In-Reply-To: Message-ID: On Sat, 28 Apr 2001, Julieta wrote: > Hi! My name is Maritza and I am trying to learn how to program with > the python language. I'm interested in a computer version of the 15 > puzzle. I've seen how it works and used it as well, but I am curious > about how the program was set up. Just to make sure that we all know If you're trying to write a game to play the 15 puzzle, it sounds like a fun problem. How far have you gotten in Python? We can help give you pointers on writing the game. However, if you're trying to write a program to get the computer to try _solving_ the problem, that's a whole different story. Solving the 15 puzzle is a HARD problem --- it's something that even beginning computer scientists have trouble writing. *grin* > which puzzle I'm refering to, it is the one that you can get at toy > stores and is essentially a 4 x 4 matrix with the numbers 1-15 on > tiles placed in the matrix. There is one blank space where tiles > adjacent to the blank space may be moved into the blank space. The > object of the game is to arrange the numbers 1-15 in order. They are ### [You might want to ignore the message below; now that I think about it, this is probably not what you're looking for.] If you'd like an example on how to get the computer to solve 15 puzzles, take a look at: http://hkn.eecs.berkeley.edu/~dyoo/python/ Check under the heading "A* Search", which has a solution to the 8-puzzle. Modifying it to do the 15 puzzle shouldn't be too bad... (However, if you're just starting out in Python, I'm not quite sure if my code will be readable for you.) From toodles@yifan.net Sun Apr 29 06:28:16 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Sun, 29 Apr 2001 13:28:16 +0800 Subject: [Tutor] popen Message-ID: Hi tutors! I want my program to do the following: In main.py, in an infinity loop (temporarily) it continually runs an update command. I want to open up a new python window for input, for an administrator to punch in commands using input() or raw_input(). input.py looks like this: while 1: x=input('>') print x #print to the main process Now I tried using os.popen: input_process=os.popen('python input.py') This works, but the window doesn't show up! It's probably not meant to, but is there a way around this? Because otherwise I can not input at all... Is there another function that does this better? TIA, Andrew From julieta_rangel@hotmail.com Sun Apr 29 06:57:06 2001 From: julieta_rangel@hotmail.com (Julieta) Date: Sun, 29 Apr 2001 00:57:06 -0500 Subject: [Tutor] determining whether a set is a group Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0D047.4FEC1020 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello everyone! I took a modern abstract algebra class this semester = and there is something that caught my attention, and which I think would = make a neat program. I would like to have a program in which given any = set and the table accompaning the set, the computer would display a = message stating whether the set is a group or not. I guess I would have = to get the computer to ask for the amount of elements in the set, say 6, = and then have the computer generate a 6 by 6 matrix, in which the user = would enter the corresponding table, so the computer can figure out, = after testing for the required properties, whether the set is a group or = not. You might think that I'm very lazy to want the computer to do this = for me, and I guess you are right, this is probably the reason why = computer programming is becoming more interesting by the minute. You do = the work only once and then the computer does it for you. It is = beautiful! I have so many little projects that could make my life much = much easier, that I don't know where to start. My only and biggest = problem is that I'm a computer illiterate and have no clue as to where = to start, however, I'm willing to do what it takes to learn. I know = that some help over the internet might not do miracles for me, but I = guess it would be a start. I have the book Teach Yourself Python in 24 = Hours and I'm reading it, but I guess I need more help. Can you help = me. Julieta =20 ------=_NextPart_000_0005_01C0D047.4FEC1020 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello everyone!  I took a modern = abstract=20 algebra class this semester and there is something that caught my = attention, and=20 which I think would make a neat program.  I would like to have a = program in=20 which given any set and the table accompaning the set, the computer = would=20 display a message stating whether the set is a group or not.  I = guess I=20 would have to get the computer to ask for the amount of elements in the = set, say=20 6, and then have the computer generate a 6 by 6 matrix, in which the = user would=20 enter the corresponding table, so the computer can figure out, after = testing for=20 the required properties, whether the set is a group or not.  You = might=20 think that I'm very lazy to want the computer to do this for me, and I = guess you=20 are right, this is probably the reason why computer programming is = becoming more=20 interesting by the minute.  You do the work only once and then the = computer=20 does it for you.  It is beautiful!  I have so many little = projects=20 that could make my life much much easier, that I don't know where to=20 start.  My only and biggest problem is that I'm a computer = illiterate and=20 have no clue as to where to start, however, I'm willing to do what it = takes to=20 learn.  I know that some help over the internet might not do = miracles for=20 me, but I guess it would be a start.  I have the book Teach = Yourself=20 Python in 24 Hours and I'm reading it, but I guess I need more = help. =20 Can you help me.
 
Julieta  =
------=_NextPart_000_0005_01C0D047.4FEC1020-- From deirdre@deirdre.net Sun Apr 29 06:57:56 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Sat, 28 Apr 2001 22:57:56 -0700 Subject: [Tutor] 15 puzzle In-Reply-To: References: Message-ID: --============_-1223598608==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" >Hi! My name is Maritza and I am trying to learn how to program with >the python language. I'm interested in a computer version of the 15 >puzzle. I've seen how it works and used it as well, but I am >curious about how the program was set up. Just to make sure that we >all know which puzzle I'm refering to, it is the one that you can >get at toy stores and is essentially a 4 x 4 matrix with the numbers >1-15 on tiles placed in the matrix. There is one blank space where >tiles adjacent to the blank space may be moved into the blank space. >The object of the game is to arrange the numbers 1-15 in order. >They are initially scrambled, of course. If you have this >program or can help me put it together, please e-mail me at >maritza_rodz.hotmail.com The best way to set it up would be as a 4 x 4 matrix. That way, it's easy to know whether or not any given spot was "next to" the hole -- as only something that's up, down, left or right of the hole can move there. Then, you'd swap the space and the number that was there. As Daniel said, it's an interesting problem and it could be designed either with a command-line interface or a gui one (or done as a command-line at first and developed into a GUI program). -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams --============_-1223598608==_ma============ Content-Type: text/html; charset="us-ascii" Re: [Tutor] 15 puzzle
Hi! My name is Maritza and I am trying to learn how to program with the python language.  I'm interested in a computer version of the 15 puzzle.  I've seen how it works and used it as well, but I am curious about how the program was set up.  Just to make sure that we all know which puzzle I'm refering to, it is the one that you can get at toy stores and is essentially a 4 x 4 matrix with the numbers 1-15 on tiles placed in the matrix.  There is one blank space where tiles adjacent to the blank space may be moved into the blank space.  The object of the game is to arrange the numbers 1-15 in order.  They are initially scrambled, of course.  If you have this program or can help me put it together, please e-mail me at maritza_rodz.hotmail.com


The best way to set it up would be as a 4  x 4 matrix. That way, it's easy to know whether or not any given spot was "next to" the hole -- as only something that's up, down, left or right of the hole can move there.

Then, you'd swap the space and the number that was there. As Daniel said, it's an interesting problem and it could be designed either with a command-line interface or a gui one (or done as a command-line at first and developed into a GUI program).
--============_-1223598608==_ma============-- From deirdre@deirdre.net Sun Apr 29 07:10:28 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Sat, 28 Apr 2001 23:10:28 -0700 Subject: [Tutor] determining whether a set is a group In-Reply-To: References: Message-ID: --============_-1223597837==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" The hardest part about learning to program, and the reason why so many people give up on it is exactly what you said below: knowing where to start. That's why we're here. :) And you're right -- a lot of people learn to program for the same reason you do: because they want to do something and they are lazy. In fact, I think there's a Linus Torvalds quote about why that makes him a good programmer. The first thing to ask about any project is: "what do I know about it?" You'll realize that you know more than you think you do, you just may not have broken it down into the little baby steps computers want. Most programming isn't hard really, just time-consuming. The next thing is to start with what you can program in the project. The overall problem may seem too huge, but right now, you probably can start with something. In other words, start somewhere. This is counter to advice you may get later on (on how to design) but you know enough to do *something* most likely (like ask the user how many elements are in the set). Then, when you knock off all the things you know how to do, then there's a few things you don't know. As much as you can, break each one down into pieces and write what you can. Yell for help when you need it. Most of the expertise gained in the first few years of programming for a living isn't anything you learn, you just learn how to go through this process more efficiently. >Hello everyone! I took a modern abstract algebra class this >semester and there is something that caught my attention, and which >I think would make a neat program. I would like to have a program >in which given any set and the table accompaning the set, the >computer would display a message stating whether the set is a group >or not. I guess I would have to get the computer to ask for the >amount of elements in the set, say 6, and then have the computer >generate a 6 by 6 matrix, in which the user would enter the >corresponding table, so the computer can figure out, after testing >for the required properties, whether the set is a group or not. You >might think that I'm very lazy to want the computer to do this for >me, and I guess you are right, this is probably the reason why >computer programming is becoming more interesting by the minute. >You do the work only once and then the computer does it for you. It >is beautiful! I have so many little projects that could make my >life much much easier, that I don't know where to start. My only >and biggest problem is that I'm a computer illiterate and have no >clue as to where to start, however, I'm willing to do what it takes >to learn. I know that some help over the internet might not do >miracles for me, but I guess it would be a start. I have the book >Teach Yourself Python in 24 Hours and I'm reading it, but I guess I >need more help. Can you help me. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams --============_-1223597837==_ma============ Content-Type: text/html; charset="us-ascii" Re: [Tutor] determining whether a set is a group
The hardest part about learning to program, and the reason why so many people give up on it is exactly what you said below: knowing where to start. That's why we're here. :)

And you're right -- a lot of people learn to program for the same reason you do: because they want to do something and they are lazy. In fact, I think there's a Linus Torvalds quote about why that makes him a good programmer.

The first thing to ask about any project is: "what do I know about it?" You'll realize that you know more than you think you do, you just may not have broken it down into the little baby steps computers want. Most programming isn't hard really, just time-consuming.

The next thing is to start with what you can program in the project. The overall problem may seem too huge, but right now, you probably can start with something. In other words, start somewhere. This is counter to advice you may get later on (on how to design) but you know enough to do *something* most likely (like ask the user how many elements are in the set).

Then, when you knock off all the things you know how to do, then there's a few things you don't know. As much as you can, break each one down into pieces and write what you can. Yell for help when you need it.

Most of the expertise gained in the first few years of programming for a living isn't anything you learn, you just learn how to go through this process more efficiently.

Hello everyone!  I took a modern abstract algebra class this semester and there is something that caught my attention, and which I think would make a neat program.  I would like to have a program in which given any set and the table accompaning the set, the computer would display a message stating whether the set is a group or not.  I guess I would have to get the computer to ask for the amount of elements in the set, say 6, and then have the computer generate a 6 by 6 matrix, in which the user would enter the corresponding table, so the computer can figure out, after testing for the required properties, whether the set is a group or not.  You might think that I'm very lazy to want the computer to do this for me, and I guess you are right, this is probably the reason why computer programming is becoming more interesting by the minute.  You do the work only once and then the computer does it for you.  It is beautiful!  I have so many little projects that could make my life much much easier, that I don't know where to start.  My only and biggest problem is that I'm a computer illiterate and have no clue as to where to start, however, I'm willing to do what it takes to learn.  I know that some help over the internet might not do miracles for me, but I guess it would be a start.  I have the book Teach Yourself Python in 24 Hours and I'm reading it, but I guess I need more help.  Can you help me.
--============_-1223597837==_ma============-- From sheila@thinkspot.net Sun Apr 29 07:31:42 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 28 Apr 2001 23:31:42 -0700 Subject: [Tutor] determining whether a set is a group In-Reply-To: References: Message-ID: <1B89315070E@kserver.org> On Sun, 29 Apr 2001 00:57:06 -0500, "Julieta" wrote about [Tutor] determining whether a set is a group: :Hello everyone! I took a modern abstract algebra class this semester and there is something that caught my attention, and which I think would make a neat program. I would like to have a program in which given any set and the table accompaning the set, the computer would display a message stating whether the set is a group or not. OK, you made me go look up what a group is. (I couldn't remember for sure...and couldn't find my abstract algebra text.) For the benefit of others, who may not know, I found this definition on the web: The axioms (basic rules) for a group are: ( where the dot (•) symbolizes some operation...) 1.CLOSURE: If a and b are in the group then a • b is also in the group. 2.ASSOCIATIVITY: If a, b and c are in the group then (a • b) • c = a • (b • c). 3.IDENTITY: There is an element e of the group such that for any element a of the group a • e = e • a = a. 4.INVERSES: For any element a of the group there is an element a^(-1) such that a • a^(-1) = e and a^(-1) • a = e : I guess I would have to get the computer to ask for the amount of elements in the set, say 6, and then have the computer generate a 6 by 6 matrix, in which the user would enter the corresponding table, so the computer can figure out, after testing for the required properties, whether the set is a group or not. Well, it sounds like an interesting project. It only would work for discrete sets, with a finite number of elements. But writing the program would help you learn a number of things. You'd have to define your operation, symbolized by the dot (•). I suppose you'd have to write a function to handle checking (1)Closure, and another to handle checking (2) Associativity. As far as checking for an identity element and inverses, though...I can't think how you'd get the computer to do that, except (possibly), by exhaustion (try all possible combinations until you find one that works?). I don't know that a matrix would be necessary. A simple list of the elements, and then iterate through the list, checking each element of the list against all others (so a nested loop). :You might think that I'm very lazy to want the computer to do this for me, and I guess you are right, this is probably the reason why computer programming is becoming more interesting by the minute. You do the work only once and then the computer does it for you. It is beautiful! I have so many little projects that could make my life much much :easier, that I don't know where to start. My only and biggest problem is that I'm a computer illiterate and have no clue as to where to start, however, I'm willing to do what it takes to learn. I know that some help over the internet might not do mira cles for me, but I guess it would be a start. I have the book Teach Yourself Python in 24 Hours and I'm reading it, but I guess I need more help. Can you help me. Yep, I've got a list of projects, too. Computer programming can be great. Here are some websites that have Python tutorials aimed at non-programmers: For non-programmers: Non-programmer's tutorial for Python http://www.honors.montana.edu/~jjc/easytut/easytut/ Learning To Program http://www.crosswinds.net/~agauld/ Python Baby-steps Tutorial (crashed my NS but viewable in IE) http://www.coolnamehere.com/z/programming/python/pythontut.asp How To Think Like a Computer Scientist http://www.ibiblio.org/obp/ Instant Hacking http://www.hetland.org/python/instant-hacking.php -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dyoo@hkn.eecs.berkeley.edu Sun Apr 29 07:32:44 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Apr 2001 23:32:44 -0700 (PDT) Subject: [Tutor] 15 puzzle (fwd) Message-ID: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. ------=_NextPart_000_53dd_1d84_16c4 Content-Type: TEXT/PLAIN; FORMAT=flowed; charset=US-ASCII Content-ID: Dear Maritza, Unfortunately, I'm unable to read word documents, so I'm forwarding this to the other python tutors, in hopes that someone out there has Windows. *grin* By the way, when you're replying to messages from tutor, make sure you're doing a reply-to-all, so that other people can volunteer their insight to the problem. We can translate much of the meaning of the Java applet into a Python program. However, it's not going to be a line-by-line translation: there are certain things that are easier to do in Python than Java, and vice versa. Python makes working with lists very convenient, and it's this versetility that encourages idioms that might not translate well without some effort. Just to give an example, when we're trying to represent something two-dimensionally in Java, the language offers a structure called the array, which is something analogous to a Python list. Let's talk about how we can possible represent a board position in Java and Python. As a warning, my Java's very rusty, so some of this code may offend Java purists. At the same time, I threaten to offend Python programmers with what must look like an eyesore. Either way, I apologize in advance. *grin* Here's a snippet of code that explores one possible way we can represent the 15-puzzle board, as a 2-dimensional array: /// public class test { static String[][] makeBoard() { String[][] board = new String[4][4]; int counter = 1; for(int row = 0; row < board.length; row++) { for(int col = 0; col < board[row].length; col++) { board[row][col] = (counter++)+""; } } board[3][3] = " "; return board; } static public void main(String[] args) { String[][] board = makeBoard(); for(int i = 0; i < board.length; i++) { for(int j = 0; j < board[i].length; j++) { System.out.print(board[i][j] + " "); } System.out.println(); } } } /// Here's a bit of Python code that does a similar task: ### def makeBoard(): board = [None] * 4 for i in range(len(board)): board[i] = map(str, range(4*i+1, 4*i + 5)) board[3][3] = ' ' return board if __name__ == '__main__': board = makeBoard(); for row in range(len(board)): print board[row] ### As you can see, there are a lot of concepts that transfer cleanly between both languages, but there are also substantial differences. Some of these owe to the fact that I haven't played around enough with Java to feel casual with it; at the same time, Java isn't really meant for casual use anyway. *grin* I guess I'm trying to say that, yes, you can borrow some ideas from the Java applet, but to really learn Python, you'll want to experiment with the "Pythonic" way of doing things, and this you'll learn as you play with examples and programs. I hope that we can talk more about your program. Feel free to email us your progress as you learn Python. Good luck! ---------- Forwarded message ---------- Date: Sat, 28 Apr 2001 23:08:03 -0500 From: Maritza Rodriguez To: dyoo@hkn.eecs.berkeley.edu Subject: 15 puzzle I found this information on the internet. It appears to be the actual program generating the game, but it is in another language. Is it possible to translate it to python? Please help. Maritza _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com ------=_NextPart_000_53dd_1d84_16c4 Content-Type: APPLICATION/OCTET-STREAM; NAME="The 15 Applet.doc" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: ATTACHMENT; FILENAME="The 15 Applet.doc" 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAAB AAAAKgAAAAAAAAAAEAAALAAAAAEAAAD+////AAAAACkAAAD///////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// ///////////////////////spcEANyAJBAAA8BK/AAAAAAAAEAAAAAAABAAA iQwAAA4AYmpialUWVRYAAAAAAAAAAAAAAAAAAAAAAAAJBBYAIiAAADd8AAA3 fAAAiQgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAAAAAA AAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAGwAAAAAACoBAAAA AAAAKgEAACoBAAAAAAAAKgEAAAAAAAAqAQAAAAAAACoBAAAAAAAAKgEAABQA AAAAAAAAAAAAAD4BAAAAAAAARgcAAAAAAABGBwAAAAAAAEYHAAAAAAAARgcA AAwAAABSBwAAHAAAAD4BAAAAAAAA5QsAAPYAAAB6BwAAAAAAAHoHAAAAAAAA egcAAAAAAAB6BwAAAAAAAHoHAAAAAAAAegcAAAAAAAB6BwAAAAAAAHoHAAAA AAAAZAsAAAIAAABmCwAAAAAAAGYLAAAAAAAAZgsAAAAAAABmCwAAAAAAAGYL AAAAAAAAZgsAACQAAADbDAAAIAIAAPsOAACaAAAAigsAABUAAAAAAAAAAAAA AAAAAAAAAAAAKgEAAAAAAAB6BwAAAAAAAAAAAAAAAAAAAAAAAAAAAAB6BwAA AAAAAHoHAAAAAAAAegcAAAAAAAB6BwAAAAAAAIoLAAAAAAAA4goAAAAAAAAq AQAAAAAAACoBAAAAAAAAegcAAAAAAAAAAAAAAAAAAHoHAAAAAAAAnwsAABYA AADiCgAAAAAAAOIKAAAAAAAA4goAAAAAAAB6BwAATgEAACoBAAAAAAAAegcA AAAAAAAqAQAAAAAAAHoHAAAAAAAAZAsAAAAAAAAAAAAAAAAAAOIKAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAegcAAAAAAABkCwAAAAAAAOIKAACCAAAA4goAAAAAAAAAAAAAAAAAAGQL AAAAAAAAKgEAAAAAAAAqAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAsAAAAAAAB6BwAA AAAAAG4HAAAMAAAAAHD4u2HQwAE+AQAACAYAAEYHAAAAAAAAyAgAABoCAABk CwAAAAAAAAAAAAAAAAAAZAsAAAAAAAC1CwAAMAAAAOULAAAAAAAAZAsAAAAA AACVDwAAAAAAAOIKAAAAAAAAlQ8AAAAAAABkCwAAAAAAAOIKAAAAAAAAPgEA AAAAAAA+AQAAAAAAACoBAAAAAAAAKgEAAAAAAAAqAQAAAAAAACoBAAAAAAAA AgDZAAAALyoNICBUaGUgMTUgQXBwbGV0Lg0gIFlvdSBjYW4gZG8gd2hhdGV2 ZXIgeW91IHdhbnQgd2l0aCB0aGUgY29kZS4gWW91IGNhbiB1c2UgaXQsIG1v ZGlmeSBpdCwNICBkZWxldGUgaXQuIFlvdSBjYW4gZXZlbiBwcmludCBpdCBv dXQgYW5kIGJ1cm4gaXQsIG9yIHlvdSBjYW4gYnVybiBpdA0gIHdpdGhvdXQg cHJpbnRpbmcgaXQgb3V0LCBidXQgdGhlbiBwbGVhc2UgZG8gYmUgdmVyeSBj YXJlZnVsbCwgZm9yIEkgDSAgaGVhcmQgdGhhdCBtb25pdG9ycywgaGFyZCBk cml2ZXMgYW5kIGNvbXB1dGVycyBpbiBnZW5lcmFsIGRvbid0IGJlaGF2ZQ0g IHdlbGwgdW5kZXIgaGlnaCB0ZW1wZXJhdHVyZXMuIEp1c3QgZG9uJ3QgaG9s ZCBtZSByZXNwb25zaWJsZSBpZiBpdCBkb2VzDSAgYW55dGhpbmcsIHVtLCBu b3Qgc28gZ29vZCB0byB5b3VyIGNvbXB1dGVyLg0NICBUaGVyZSBpcyBvbmUg dGhpbmcgSSBkbyBhc2s6DSAgVGhpcyBpcyBteSBmaXJzdCBKYXZhIGVmZm9y dCwgc28gSSBkb24ndCBrbm93IHRoZSBsYW5ndWFnZSB2ZXJ5IHdlbGwuDSAg SSdtIGFsbW9zdCBzdXJlIHRoYXQgc29tZSB0aGluZ3MgaGVyZSBhcmUgcXVp dGUgaW5jb3JyZWN0LCBldmVuIHRob3VnaA0gIHRoZXkgZG8gd29yay4gTmV2 ZXIgbWluZCB0aGUgYWxnb3JpdGhtcyB0aGVtc2VsdmVzLCBidXQgaWYgeW91 IGRvIGZpbmQNICBhbnl0aGluZyB0aGF0IG5lZWRzIHRvIGJlIGNoYW5nZWQs IHBsZWFzZSBzZW5kIG1lIGEgbWVzc2FnZSBhdA0gIGV1Z2VuZUBpbnRlcmxv Zy5jb20gVGhhbmsgeW91Lg0qLw1pbXBvcnQgamF2YS5hcHBsZXQuKjsNaW1w b3J0IGphdmEuYXd0Lio7DS8vLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0NcHVibGljIGNsYXNzIGZpZnRlZW4gZXh0ZW5kcyBBcHBsZXQNew0gICBw cml2YXRlIFNldmVuU2VnbWVudERpZ2l0W10gZGlzcGxheSA9IG5ldyBTZXZl blNlZ21lbnREaWdpdFszXTsNICAgcHJpdmF0ZSBCdXR0b25bXSBCdXR0b25z ID0gbmV3IEJ1dHRvblsxNl07IC8vVGhpcyBhcnJheSBpcyBhbiBhY3R1YWxs IHBsYXlmaWVsZC4NICAgcHJpdmF0ZSBCdXR0b24gc2h1ZmZsZUJ0biA9IG5l dyBCdXR0b24gKCImU2h1ZmZsZSIpOw0gICBwcml2YXRlIGludCBzY29yZT0w Ow0gICBwcml2YXRlIGludCBzaHVmZmxpbmc9MDsJCQkJCQkgIA0gICBwcml2 YXRlIEZvbnQgZjsNLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0qLw0JcHVibGljIFN0 cmluZyBnZXRBcHBsZXRJbmZvKCkgLy9EbyBJIG5lZWQgdGhpcyBmdW5jdGlv bj8NCXsNCQlyZXR1cm4gIk5hbWU6IGZpZnRlZW5cclxuIiArDQkJICAgICAg ICJBdXRob3I6IEV1Z2VuZVxyXG4iICsNCQkgICAgICAgIkNyZWF0ZWQgd2l0 aCBNaWNyb3NvZnQgVmlzdWFsIEorKyBWZXJzaW9uIDEuMCI7DQl9DQ0vKi0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLSovDQlwdWJsaWMgdm9pZCBpbml0KCkNCXsNCQlp bnQgaT0wOw0JCVN0cmluZyBzdHI9bmV3IFN0cmluZygpOw0NCQlyZXNpemUo MjAwLCAzMDApOw0JCXNldExheW91dChudWxsKTsgLy9XaHkgZG8gdGhleSBi b3RoZXIgc28gaGFyZCB3aXRoIGxheW91dHM/DQkJc2V0QmFja2dyb3VuZChD b2xvci5ibGFjayk7DQ0JCWZvcihpPTA7IGkzKQ0JCQkJCSAgbW92ZUJ0bihl bXB0eS00KTsNCQkJCSAgcmV0dXJuIHRydWU7DQkJDQkJY2FzZSBFdmVudC5M RUZUOiBpZihlbXB0eSAlIDQgIT0zKQ0JCQkJCSAgbW92ZUJ0bihlbXB0eSsx KTsNCQkJICAgICAgcmV0dXJuIHRydWU7DQ0JCWNhc2UgRXZlbnQuUklHSFQ6 IGlmKGVtcHR5ICUgNCAhPSAwKQ0JCQkJCSAgbW92ZUJ0bihlbXB0eS0xKTsN CQkJICAgICAgcmV0dXJuIHRydWU7DQ0gICAgICAgIGNhc2UgJ3MnOg0JCWNh c2UgJ1MnOiBzaHVmZmxlKCk7DQkJCSAgICAgIHJldHVybiB0cnVlOw0JCX0N CSAgcmV0dXJuIGZhbHNlOw0JfQ0vKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSovDQlw dWJsaWMgYm9vbGVhbiBhY3Rpb24oRXZlbnQgZXZ0LCBPYmplY3Qgd2hhdCkN CXsNCQlpbnQgaT0wOw0JIA0JCQlmb3IoaT0wO2kNDQAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAIgMAACJDAAA/QAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEXkoDAAIABAAA AwQAABQEAABdBAAApAQAAOsEAAA0BQAAfgUAAKwFAACtBQAAzAUAABQGAABd BgAApgYAAOcGAAAIBwAACwcAACEHAAA0BwAAgQcAAKUHAACnBwAA6gcAAD4I AAB2CAAAjggAALIIAADFCAAACQkAAEMJAAD9AAAAAAAAAAAAAAAA/QAAAAAA AAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAA AP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAA AAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAA AAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAA AAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAA AAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAA AAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAA AAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAAAA AAAAAAAAAAABDwAAHQAEAACJDAAA/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAQEBQwkAAEYJAABlCQAAhQkA AL8JAADCCQAAwwkAAAcKAAAbCgAAHgoAACkKAABECgAARQoAAFkKAACXCgAA tQoAALYKAADFCgAA3goAAPEKAAD0CgAAGQsAADILAABICwAASQsAAHALAACJ CwAAnwsAAKALAACyCwAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAA AAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAA AAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAA AAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAA AAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0A AAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAA AAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9 AAAAAAAAAAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAA AAAAAAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ8A AB2yCwAAyQsAAN8LAADjCwAA9AsAAPcLAAA7DAAAagwAAG0MAAB4DAAAewwA AIgMAACJDAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAA AAAA/QAAAAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAA AAAAAAAAAAAAAP0AAAAAAAAAAAAAAAD9AAAAAAAAAAAAAAAA/QAAAAAAAAAA AAAAAP0AAAAAAAAAAAAAAAD7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAEAAAABDwAADCAAMZBoAR+w0C8gsOA9IbAIByKwCAcjkKAF JJCgBSWwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAQAAoAAQBp AA8AAwAAAAAAAAAAADgAAEDx/wIAOAAMAAYATgBvAHIAbQBhAGwAAAACAAAA GABDShgAX0gBBGFKGABtSAkEc0gJBHRICQQAAAAAAAAAAAAAAAAAAAAAAAA8 AEFA8v+hADwADAAWAEQAZQBmAGEAdQBsAHQAIABQAGEAcgBhAGcAcgBhAHAA aAAgAEYAbwBuAHQAAAAAAAAAAAAAAAAAgABlYAEA8gCAAAwAEQBIAFQATQBM ACAAUAByAGUAZgBvAHIAbQBhAHQAdABlAGQAAAA3AA8ADcYyABCUAygHvApQ DuQReBUMGaAcNCDII1wn8CqELhgyrDVAOQAAAAAAAAAAAAAAAAAAAAAAFABD ShQAT0oDAFBKAwBRSgMAYUoUAAAAAACJCAAABAAAIAAAAAD/////AAAAAAMA AAAUAAAAXQAAAKQAAADrAAAANAEAAH4BAACsAQAArQEAAMwBAAAUAgAAXQIA AKYCAADnAgAACAMAAAsDAAAhAwAANAMAAIEDAAClAwAApwMAAOoDAAA+BAAA dgQAAI4EAACyBAAAxQQAAAkFAABDBQAARgUAAGUFAACFBQAAvwUAAMIFAADD BQAABwYAABsGAAAeBgAAKQYAAEQGAABFBgAAWQYAAJcGAAC1BgAAtgYAAMUG AADeBgAA8QYAAPQGAAAZBwAAMgcAAEgHAABJBwAAcAcAAIkHAACfBwAAoAcA ALIHAADJBwAA3wcAAOMHAAD0BwAA9wcAADsIAABqCAAAbQgAAHgIAAB7CAAA iAgAAIsIAACYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAA AAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICY AAAADzAAAAAAAAAAgAAAAICYAAAADzAAAAAAAAAAgAAAAICYAAAAADAAAAAA AAAAgAAAAIAABAAAiQwAAAsAAAAABAAAQwkAALILAACJDAAADAAAAA4AAAAP AAAAAAQAAIkMAAANAAAAAAAAANoAAADiAAAAEgMAAB0DAAAoAwAAMAMAALID AADDAwAA1AMAAOUDAAArBAAAMgQAAFAEAABaBAAAgQQAAIQEAACZBAAAnAQA ABgFAAAlBQAAIAYAACMGAAAkBgAAJQYAADIGAAA1BgAAWwYAAGQGAACZBgAA pgYAAKcGAACyBgAAvAYAAL0GAADMBgAA0wYAAPsGAAAFBwAAIAcAACcHAABQ BwAAWwcAAHcHAAB+BwAAQwgAAEoIAABYCAAAWwgAAG8IAAByCAAAcwgAAHQI AACCCAAAgwgAAIsIAAAHABwABwAcAAcAHAAHABwABwAcAAcAHAAHABwABwAc AAcAHAAHABwABwAcAAcAHAAHABwABwAcAAcAHAAHABwABwAcAAcAHAAHABwA BwAcAAcAHAAHABwABwAcAAcAHAAHABwABwAcAAcAHAAHAAAAAAAMAAAAEgAA AEoAAABQAAAAUgAAAFwAAABfAAAAZQAAAKYAAACtAAAA7QAAAPIAAAA2AQAA OgEAAIABAACIAQAAXwIAAGMCAACoAgAAsAIAAOkCAAD8AgAACwMAABEDAAAh AwAAJwMAAIEDAACHAwAAqgMAALEDAADtAwAA9AMAAEEEAABIBAAAeQQAAIAE AACRBAAAmAQAALUEAAC8BAAACgUAABAFAABIBQAATgUAAAgGAAAOBgAAIAYA ACMGAAA6BgAAQQYAAEcGAABNBgAAWwYAAGQGAACZBgAApgYAALgGAAC7BgAA zAYAANMGAADkBgAA6gYAAPYGAAD6BgAAIAcAACcHAAA7BwAAQQcAAEsHAABP BwAAdwcAAH4HAACSBwAAmAcAAKgHAACsBwAAtAcAALgHAADSBwAA2AcAAOYH AADsBwAAPAgAAEIIAABvCAAAcggAAH4IAACBCAAAiwgAAAcAMwAHADMABwAz AAcAMwAHADMABwAzAAcAMwAHADMABwAzAAcAMwAHADMABwAzAAcAMwAHADMA BwAzAAcAMwAHADMABwAzAAcAMwAHADMABwAzAAcAMwAHADMABwAzAAcAMwAH ADMABwAzAAcAMwAHADMABwAzAAcAMwAHADMABwAzAAcAMwAHADMABwAzAAcA MwAHADMABwAzAAcAMwAHADMABwAzAAcAMwAHADMABwD//wIAAAAbAEwAbwBy AGUAbgB6AG8AIABhAG4AZAAgAEoAdQBsAGkAZQB0AGEAIABNAGkAcgBhAG4A ZABhACEAQwA6AFwATQB5ACAARABvAGMAdQBtAGUAbgB0AHMAXABUAGgAZQAg ADEANQAgAEEAcABwAGwAZQB0AC4AZABvAGMA/0ABgAEAxwYAAMcGAACMjWQA egB6AMcGAAAAAAAAxwYAAAAAAAACEAAAAAAAAACJCAAAQAAACABAAAD//wEA AAAHAFUAbgBrAG4AbwB3AG4A//8BAAgAAAAAAAAAAAAAAP//AQAAAAAA//8A AAIA//8AAAAA//8AAAIA//8AAAAABAAAAEcWkAEAAAICBgMFBAUCAwSHOgAA AAAAAAAAAAAAAAAA/wAAAAAAAABUAGkAbQBlAHMAIABOAGUAdwAgAFIAbwBt AGEAbgAAADUWkAECAAUFAQIBBwYCBQcAAAAAAAAAEAAAAAAAAAAAAAAAgAAA AABTAHkAbQBiAG8AbAAAADMmkAEAAAILBgQCAgICAgSHOgAAAAAAAAAAAAAA AAAA/wAAAAAAAABBAHIAaQBhAGwAAAA/NZABAAACBwMJAgIFAgQEhzoAAAAA AAAAAAAAAAAAAP8AAAAAAAAAQwBvAHUAcgBpAGUAcgAgAE4AZQB3AAAAIgAE AHEIiBgA8NACAABoAQAAAADF5VTGxuVUxgAAAAABAAEAAAA7AQAACQcAAAEA AwAAAAQAAxAPAAAAAAAAAAAAAAABAAEAAAABAAAAAAAAACQDAPAQAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKUGwAe0ALQA gYEyMAAAAAAAAAAAAAAAAAAAowgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAA AAAAAAAAADKDEQDwEAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AP//EgAAAAAAAAACAC8AKgAAAAAAAAAbAEwAbwByAGUAbgB6AG8AIABhAG4A ZAAgAEoAdQBsAGkAZQB0AGEAIABNAGkAcgBhAG4AZABhABsATABvAHIAZQBu AHoAbwAgAGEAbgBkACAASgB1AGwAaQBlAHQAYQAgAE0AaQByAGEAbgBkAGEA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP7/AAAECgIA AAAAAAAAAAAAAAAAAAAAAAEAAADghZ/y+U9oEKuRCAArJ7PZMAAAAIwBAAAR AAAAAQAAAJAAAAACAAAAmAAAAAMAAACkAAAABAAAALAAAAAFAAAA1AAAAAYA AADgAAAABwAAAOwAAAAIAAAA/AAAAAkAAAAgAQAAEgAAACwBAAAKAAAASAEA AAwAAABUAQAADQAAAGABAAAOAAAAbAEAAA8AAAB0AQAAEAAAAHwBAAATAAAA hAEAAAIAAADkBAAAHgAAAAMAAAAvKgAAHgAAAAEAAAAAKgAAHgAAABwAAABM b3JlbnpvIGFuZCBKdWxpZXRhIE1pcmFuZGEAHgAAAAEAAAAAb3JlHgAAAAEA AAAAb3JlHgAAAAcAAABOb3JtYWwAIB4AAAAcAAAATG9yZW56byBhbmQgSnVs aWV0YSBNaXJhbmRhAB4AAAACAAAAMQByZR4AAAATAAAATWljcm9zb2Z0IFdv cmQgOS4wACBAAAAAAEbDIwAAAABAAAAAAD4+j2HQwAFAAAAAAIQBs2HQwAED AAAAAQAAAAMAAAA7AQAAAwAAAAkHAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD+/wAABAoC AAAAAAAAAAAAAAAAAAAAAAABAAAAAtXN1ZwuGxCTlwgAKyz5rjAAAADsAAAA DAAAAAEAAABoAAAADwAAAHAAAAAFAAAAfAAAAAYAAACEAAAAEQAAAIwAAAAX AAAAlAAAAAsAAACcAAAAEAAAAKQAAAATAAAArAAAABYAAAC0AAAADQAAALwA AAAMAAAAywAAAAIAAADkBAAAHgAAAAEAAAAAAAAAAwAAAA8AAAADAAAAAwAA AAMAAACjCAAAAwAAAKAKCQALAAAAAAAAAAsAAAAAAAAACwAAAAAAAAALAAAA AAAAAB4QAAABAAAAAwAAAC8qAAwQAAACAAAAHgAAAAYAAABUaXRsZQADAAAA AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAIA AAADAAAABAAAAAUAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAA AA4AAAAPAAAAEAAAAP7///8SAAAAEwAAABQAAAAVAAAAFgAAABcAAAAYAAAA /v///xoAAAAbAAAAHAAAAB0AAAAeAAAAHwAAACAAAAD+////IgAAACMAAAAk AAAAJQAAACYAAAAnAAAAKAAAAP7////9////KwAAAP7////+/////v////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////9SAG8AbwB0ACAARQBuAHQAcgB5AAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFgAFAf//////////AwAA AAYJAgAAAAAAwAAAAAAAAEYAAAAAAAAAAAAAAAAAcPi7YdDAAS0AAACAAAAA AAAAADEAVABhAGIAbABlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAIA////////////////AAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAAAAQAAAAAAAAVwBv AHIAZABEAG8AYwB1AG0AZQBuAHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAABoAAgEFAAAA//////////8AAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIiAAAAAAAAAFAFMAdQBtAG0A YQByAHkASQBuAGYAbwByAG0AYQB0AGkAbwBuAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAKAACAQIAAAAEAAAA/////wAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAABkAAAAAEAAAAAAAAAUARABvAGMAdQBtAGUAbgB0 AFMAdQBtAG0AYQByAHkASQBuAGYAbwByAG0AYQB0AGkAbwBuAAAAAAAAAAAA AAA4AAIB////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAIQAAAAAQAAAAAAAAAQBDAG8AbQBwAE8AYgBqAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAgEB AAAABgAAAP////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAagAAAAAAAABPAGIAagBlAGMAdABQAG8AbwBsAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFgABAP////////// /////wAAAAAAAAAAAAAAAAAAAAAAAAAAAHD4u2HQwAEAcPi7YdDAAQAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////////////////AAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AQAAAP7///////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////8BAP7/AwoAAP////8GCQIAAAAAAMAAAAAAAABG GAAAAE1pY3Jvc29mdCBXb3JkIERvY3VtZW50AAoAAABNU1dvcmREb2MAEAAA AFdvcmQuRG9jdW1lbnQuOAD0ObJxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== ------=_NextPart_000_53dd_1d84_16c4-- From dyoo@hkn.eecs.berkeley.edu Sun Apr 29 07:43:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 28 Apr 2001 23:43:28 -0700 (PDT) Subject: [Tutor] determining whether a set is a group In-Reply-To: Message-ID: Hiya Julieta, Could you tell us some facts about groups? I do have my abstract algebra book with me, but it might have different definitions than what your books have. *grin* Let's talk about what it means for something to be a group. We might find ways to express these ideas in Python syntax. > And you're right -- a lot of people learn to program for the same > reason you do: because they want to do something and they are lazy. > In fact, I think there's a Linus Torvalds quote about why that makes > him a good programmer. The Perl people understand this as the Three Virtues of a Programmer: "Laziness, impatience, and hubris". http://www.netropolis.org/hash/perl/virtue.html > >and biggest problem is that I'm a computer illiterate and have no > >clue as to where to start, however, I'm willing to do what it takes > >to learn. I know that some help over the internet might not do > >miracles for me, but I guess it would be a start. I have the book > >Teach Yourself Python in 24 Hours and I'm reading it, but I guess I > >need more help. Can you help me. We'll do our best to help. Good luck! From sheila@thinkspot.net Sun Apr 29 07:51:04 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 28 Apr 2001 23:51:04 -0700 Subject: [Tutor] 15 puzzle (fwd) In-Reply-To: References: Message-ID: <1CA350D3FC8@kserver.org> On Sat, 28 Apr 2001 23:32:44 -0700 (PDT), Daniel Yoo wrote about [Tutor] 15 puzzle (fwd): Here are the contents of the MS Word document: /* The 15 Applet. You can do whatever you want with the code. You can use it, modify it, delete it. You can even print it out and burn it, or you can burn it without printing it out, but then please do be very carefull, for I heard that monitors, hard drives and computers in general don't behave well under high temperatures. Just don't hold me responsible if it does anything, um, not so good to your computer. There is one thing I do ask: This is my first Java effort, so I don't know the language very well. I'm almost sure that some things here are quite incorrect, even though they do work. Never mind the algorithms themselves, but if you do find anything that needs to be changed, please send me a message at eugene@interlog.com Thank you. */ import java.applet.*; import java.awt.*; //-------------------------------------------------------------------------- public class fifteen extends Applet { private SevenSegmentDigit[] display = new SevenSegmentDigit[3]; private Button[] Buttons = new Button[16]; //This array is an actuall playfield. private Button shuffleBtn = new Button ("&Shuffle"); private int score=0; private int shuffling=0; private Font f; /*---------------------------------------------------------------*/ public String getAppletInfo() //Do I need this function? { return "Name: fifteen\r\n" + "Author: Eugene\r\n" + "Created with Microsoft Visual J++ Version 1.0"; } /*---------------------------------------------------------------*/ public void init() { int i=0; String str=new String(); resize(200, 300); setLayout(null); //Why do they bother so hard with layouts? setBackground(Color.black); for(i=0; i3) moveBtn(empty-4); return true; case Event.LEFT: if(empty % 4 !=3) moveBtn(empty+1); return true; case Event.RIGHT: if(empty % 4 != 0) moveBtn(empty-1); return true; case 's': case 'S': shuffle(); return true; } return false; } /*---------------------------------------------------------------*/ public boolean action(Event evt, Object what) { int i=0; for(i=0;i -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dyoo@hkn.eecs.berkeley.edu Sun Apr 29 08:05:50 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 29 Apr 2001 00:05:50 -0700 (PDT) Subject: [Tutor] determining whether a set is a group In-Reply-To: <1B89315070E@kserver.org> Message-ID: On Sat, 28 Apr 2001, Sheila King wrote: > The axioms (basic rules) for a group are:=20 > ( where the dot (=95) symbolizes some operation...) >=20 > 1.CLOSURE: If a and b are in the group then a =95 b is also in the gro= up.=20 > 2.ASSOCIATIVITY: If a, b and c are in the group then (a =95 b) =95 c = =3D a =95 (b =95 > c).=20 > 3.IDENTITY: There is an element e of the group such that for any eleme= nt a > of the group > a =95 e =3D e =95 a =3D a.=20 > 4.INVERSES: For any element a of the group there is an element a^(-1) = such > that=20 > a =95 a^(-1) =3D e=20 > and=20 > a^(-1) =95 a =3D e=20 Doing stuff with infinite sets looks messy, so let's try working with finite groups for now. It appears that a group is a combination of: 1. a set of elements. 2. some operation that combines any two elements. There's no built-in that perfectly represents a set in Python, but in a pinch, the list structure works very well. Also, Python functions seem like a great way to represent a group operator. For example, we can say that: ### def addModFour(x, y): return (x + y) % 4 mygroup =3D ([0, 1, 2, 3], addModFour) ### would be one way to represent a group in Python, as a 2-tuple. What's nice is that this representation allows us to test for all four cases fairly nicely. Here's a little snippet that hints at a possible way to test for closure: ### elements, operator =3D mygroup if operator(elements[0], elements[1]) in elements: print "Our group might not be closed," print "but at least %s dotted with %s is in our set" % (elements[0], elements[1]") else: print "There's no way this is a group, because it's not closed!" ### Once you get through the for-loops and lists chapter in Teach Yourself Python, try writing the closure checking function; I think you'll be pleasantly surprised. Hope this helps! From juno@gamefire.com Sun Apr 29 09:30:33 2001 From: juno@gamefire.com (juno@gamefire.com) Date: Sun, 29 Apr 2001 01:30:33 -0700 Subject: [Tutor] Help with the technique "Menu Processing" Message-ID: Hi Everyone, I was wondering if I might be able to get some help with "Menu Processing". What I'm looking for is an example of how it might be done within an object. I've been trying myself, but I keep getting an error. Here's an example of what I'm trying to do: Class msg: def __init__(self): self.msgtype = {"priv":send_priv_msg, "pub":send_pub_msg, "action":send_action_msg, "notice":send_notice_msg, "ctcp":send_ctcp_msg} ...more stuff... def send_priv_msg(connection, nick, text): ... send code .. def send_pub_msg(connection, nick, text): ... send code .. def send_action_msg(connection, nick, text): ... send code .. def send_notice_msg(connection, nick, text): ... send code .. def send_ctcp_msg(connection, nick, text): ... send code .. def send_msg_by(connection, nick, text, type): self.msgtype[type](connection, nick, text) Thanks, Juno From toodles@yifan.net Sun Apr 29 14:05:54 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Sun, 29 Apr 2001 21:05:54 +0800 Subject: [Tutor] Help with the technique "Menu Processing" In-Reply-To: Message-ID: Hi Juno, What you need to do is set up the class so... 1) Each method's first argument is self. self refers to the instance itself, if you don't know. eg. > def send_priv_msg(connection, nick, text): > ... send code .. should be: def send_priv_msg(self,connection,nick,text): blah blah blah 2) The msgtype dictionary's values should have self before the variables, to tell python to look in the instance's own namespace. eg. > self.msgtype = {"priv":send_priv_msg, should be: self.msgtype={"priv":self.send_priv_msg, #and so on... Now when you call them, it should be fine and dandy! def send_msg_by(connection, nick, text, type): > self.msgtype[type](connection, nick, text) *looks puzzled* You had it right in that one! =) Hope you can understand my badly written attempt at helping... Andrew > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > juno@gamefire.com > Sent: Sunday, 29 April 2001 4:31 PM > To: tutor@python.org > Subject: [Tutor] Help with the technique "Menu Processing" > > > Hi Everyone, > I was wondering if I might be able to get some help with "Menu > Processing". > What I'm looking for is an example of how it might be done within > an object. > I've been trying myself, but I keep getting an error. > > Here's an example of what I'm trying to do: > > Class msg: > def __init__(self): > self.msgtype = {"priv":send_priv_msg, > "pub":send_pub_msg, > "action":send_action_msg, > "notice":send_notice_msg, > "ctcp":send_ctcp_msg} > ...more stuff... > > def send_priv_msg(connection, nick, text): > ... send code .. > def send_pub_msg(connection, nick, text): > ... send code .. > def send_action_msg(connection, nick, text): > ... send code .. > def send_notice_msg(connection, nick, text): > ... send code .. > def send_ctcp_msg(connection, nick, text): > ... send code .. > > def send_msg_by(connection, nick, text, type): > self.msgtype[type](connection, nick, text) > > > Thanks, > > Juno > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From bdupire@seatech.fau.edu Sun Apr 29 16:59:58 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Sun, 29 Apr 2001 11:59:58 -0400 Subject: [Tutor] determining whether a set is a group References: Message-ID: <3AEC3A7E.1868590F@seatech.fau.edu> Daniel Yoo wrote: > On Sat, 28 Apr 2001, Sheila King wrote: > > > The axioms (basic rules) for a group are: > > ( where the dot (=95) symbolizes some operation...) > > > > 1.CLOSURE: If a and b are in the group then a =95 b is also in the= group. > > 2.ASSOCIATIVITY: If a, b and c are in the group then (a =95 b) =95= c =3D a =95 (b =95 > > c). > > 3.IDENTITY: There is an element e of the group such that for any e= lement a > > of the group > > a =95 e =3D e =95 a =3D a. > > 4.INVERSES: For any element a of the group there is an element a^(= -1) such > > that > > a =95 a^(-1) =3D e > > and > > a^(-1) =95 a =3D e > The pb is that my computer can't handle very well infinite sets... how do= es a program like Mapple handle this kind of things ? How can i implement something whose cardinal is Cantor something (ie. inf= inite) ? Although i remember what a group is , i don't remember what groups are us= eful for....... any math teachers? Benoit From sheila@thinkspot.net Sun Apr 29 17:40:06 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 29 Apr 2001 09:40:06 -0700 Subject: [Tutor] determining whether a set is a group In-Reply-To: <3AEC3A7E.1868590F@seatech.fau.edu> References: <3AEC3A7E.1868590F@seatech.fau.edu> Message-ID: <3E369671789@kserver.org> On Sun, 29 Apr 2001 11:59:58 -0400, Benoit Dupire wrote about Re: [Tutor] determining whether a set is a group: :Although i remember what a group is , i don't remember what groups are us= :eful :for....... any math teachers? Uh, I am a math teacher. Sorry to say, I don't work much with groups. I took one required course in Abstract Algebra, and then went on to do probability and analysis, and a small bit of numerical methods. Abstract algebra is more for the theorists and purists. I'm more interested in the practical application of math (although I enjoy the theory and beauty of it, as well). Here is a nice page with a lot of Algebra definitions and theorems on it: http://www.math.niu.edu/~beachy/aaol/ If I get a better answer to "What are groups good for?", I will share. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Sun Apr 29 18:03:18 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 29 Apr 2001 10:03:18 -0700 Subject: [Tutor] determining whether a set is a group In-Reply-To: <3E369671789@kserver.org> References: <3AEC3A7E.1868590F@seatech.fau.edu> <3E369671789@kserver.org> Message-ID: <3F8364E13E9@kserver.org> On Sun, 29 Apr 2001 09:40:06 -0700, Sheila King wrote about Re: [Tutor] determining whether a set is a group: :If I get a better answer to "What are groups good for?", I will share. OK, from a Britannica.com article on Fourier Analysis (which we all know is extremely important for engineering, right?) here: http://www.britannica.com/eb/article?eu=120670 I quote: """ Since their formal introduction in the early 19th century, groups have been one of the principal objects of mathematical attention (see algebra: Groups). Their widespread and profound applications to such physical subjects as crystallography, quantum mechanics, and hydrodynamics and to such other mathematical regimes as number theory, harmonic analysis, and geometry have demonstrated their importance. """ And from this article at Britannica.com on Groups: http://www.britannica.com/eb/article?eu=120647 I quote: """ In studying the solution of polynomial equations, a Norwegian mathematician, Niels Henrik Abel, showed that in general the equation of fifth degree cannot be solved by radicals. Then the French mathematician Évariste Galois, using groups systematically, showed that the solution of an equation by radicals is possible only if a group associated with the equation has certain specific properties; these groups are now called solvable groups. The group concept is now recognized as one of the most fundamental in all of mathematics and in many of its applications. The German mathematician Felix Klein considered geometry to be those properties of a space left unchanged by a certain specific group of transformations. In topology geometric entities are considered equivalent if one can be transformed into another by an element of a continuous group. """ If you're interested, you will find much more on the importance and usefulness of groups at the links listed above. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From julieta_rangel@hotmail.com Sun Apr 29 19:48:34 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 29 Apr 2001 13:48:34 -0500 Subject: [Tutor] Multiplication of polynomials Message-ID:
If I want to write a program that multiplies polynomials, just to show you how illiterate I am at computer programming, this is what I would do: I would need the user to enter the amount of polynomials that will be multiplying.  Lets say the user wants to multiply two polynomials.  Once the user enters the amount of polynomials that will be multiplying, the computer would have to ask the degree of the polynomials, say the first polynomial is of third degree and the second is a second degree polynomial (2x^3 + x^2 + 3x + 2) * (x^2 + 1)Once the person enters the degree of the polynomials, the computer would have to ask the coefficient of each of the terms of the polynomials,  in this case the computer would have to ask the user to enter the coefficient of  x^3, x^2, x, and c and then the coefficients of the second polynomial.  Should I have the computer create two lists for each polynomial?  In one list I would store all the coefficients and in another the exponents of the expression.  I'm assuming that if I have two lists for each polynomial, I could do the operations required.  Based on the polynomials I have, the lists of coefficients would look like (L1) [2,1,3,2] and (L2)[1,0,1] and my lists of exponents would look like (L 3) [3,2,1,0] and (L 4)[2,1,0]. I would then have the first element in L1 times each element in L2, so that I get list 5 [2,0,2]
and 1st element in L3 + each element in L4, so that I get list 6 [5,4,3].  Then I would have the 2nd element in L1 times each element in L2 so that I get another list [1,0,1] and also have the 2nd element in L3 + each element in L4, so that I get [4,3,2].  This would go on for each element and I would end up with 4 more lists [3,0,3], [3,2,1], [2,0,2], [2,1,0].  I would then take the numbers from my lists and have the computer write the coefficients along with the exponents:  2x^5 + 0x^4 + 2x^3 + x^4 +0x^3+x^2+3x^3+0x^2 +3x+ 2x^2+0x+2.    I would then have to get rid of those terms with zero coefficients and combine like terms.  Is this crazy or what?  How could I accomplish this?  Like I told you before, this is all new to me, but I'm really interested in finding out how this complex task can be accomplished in Python.  Can you help?
 
Julieta


Get your FREE download of MSN Explorer at http://explorer.msn.com

From sheila@thinkspot.net Sun Apr 29 20:26:46 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 29 Apr 2001 12:26:46 -0700 Subject: [Tutor] Multiplication of polynomials In-Reply-To: References: Message-ID: <47A4FFB472F@kserver.org> Juliet, PLEASE set your mail settings, to compose in plain text. On Sun, 29 Apr 2001 13:48:34 -0500, "Julieta Rangel" wrote about [Tutor] Multiplication of polynomials: :
If I want to write a program that multiplies polynomials, just to show you how illiterate I am at computer programming, this is what I would do: I would need the user to enter the amount of polynomials that will be multiplying.  Let s say the user wants to multiply two polynomials.  Once the user enters the amount of polynomials that will be multiplying, the computer would have to ask the degree of the polynomials, say the first polynomial is of third degree and the second is a second degree polynomial (2x^3 + x^2 + 3x + 2) * (x^2 + 1)Once the person enters the degree of the polynomials, the computer would have to ask the coefficient of each of the terms of the polynomials,  in this case the computer would have to ask the user to enter the coefficient of  x^3, x^2, x, and c and then the coefficients of the second polynomial.  Should I have the computer create two lists for each polynomial?  In one list I would store all the coefficients :and in another the exponents of the expression. This is a worthy problem. I might suggest, first implementing polynomial addition, rather than multiplication. Do the addition first, and once you've got that, try multiplication. Another worthy problem, is evaluating a single polynomial for a given value of x. Well, maybe that one is a bit easy. Still, worthy trying for a new, non-programmer. As to your problem, you really don't need to store the exponents of the polynomial in a second list. You could infer the exponent from the placement of the polynomial's coefficient in the list. For example, you could store 2x^4+x^2-3x+5 as [2, 0, 1, -3, 5] or, you might want to store it in reverse order, as [5, -3, 1, 0, 2] The advantage of the second representation is that, if coeff = [5, -3, 1, 0, 2] then coeff[4] refers to the coefficient of the x^4 term, and coeff[1] refers to the coefficient of the x^1 term, and so on. You should store zeros for the coefficients equal to zero. Really, you might want to make a class called Polynomial and give it methods like ValueAtX and Add and Multiply. :  I'm assuming that if I have two lists for each polynomial, I could do the operations required.  Based on the polynomials I have, the lists of coefficients would look like (L1) [2,1,3,2] and (L2)[1,0,1] and my lists of exponents would look li ke (L 3) [3,2,1,0] and (L 4)[2,1,0]. I would then have the first element in L1 times each element in L2, so that I get list 5 [2,0,2]
:
and 1st element in L3 + each element in L4, so that I get list 6 [5,4,3].  Then I would have the 2nd element in L1 times each element in L2 so that I get another list [1,0,1] and also have the 2nd element in L3 + each element in L4, so that I get [4,3,2].  This would go on for each element and I would end up with 4 more lists [3,0,3], [3,2,1], [2,0,2], [2,1,0].  I would then take the numbers from my lists and have the computer write the coefficients along with the exponents:  2x^5 + 0x^4 + 2x^3 + x^4 +0x^3+x^2+3x^3+0x^2 +3x+ 2x^2+0x+2.    I would then have to get rid of those terms with zero coefficients and combine like terms.  Is this crazy or what?  How could I accomplish this?  Like I told yo u before, this is all new to me, but I'm really interested in finding out how this complex task can be accomplished in Python.  Can you help?
In order to multiply two polynomials, you would need to take each coefficient in the one list and multiply it be each coefficient in the other list. So, your suggested problem (2x^3 + x^2 + 3x + 2) * (x^2 + 1) might look like this: p1 = [2, 3, 1, 2] p2 = [1, 0, 1] I would note, that since you are multiplying a 3rd degree polynomial by a 2nd degree one, that your result should be fifth degree. You could find this out by doing len(p1)-1 added to len(p2)-1 then create a new list to store the results of your multiplication. Give it length of 5 and initialize all spots to zero. Let's call this new list for the result, p3. Now create a loop to go through each element of p1. Start with p1[0] and multiply it by p2[0] and add the result to p3[0]. Now multiply p1[0] with p2[1] and add the result to p3[1]. Now multiply p1[0] with p2[2] and add the result to p3[2]. All done with p1[0]. Now the loop moves to p1[1]. Multiply p1[1] with p2[0] and add the result to p3[1]. Now multiply p1[1] with p2[1] and add the result to p3[2]. Now multiply p1[1] with p2[2] and add the result to p3[3]. Note, that the indices indicate the exponent on your variable. So, p1[1] is an x^1 coefficient and p2[2] is an x^2 coefficient, so the result needs to be an x^3 coefficient, so add that result to p3[3]. Proceed on to p1[2] and p1[3] in the same manner. So, you have a loop on p1, and inside that loop is another loop that iterates over all the indices in p2. I hope this is helpful. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From bdupire@seatech.fau.edu Sun Apr 29 20:39:15 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Sun, 29 Apr 2001 15:39:15 -0400 Subject: [Tutor] Multiplication of polynomials References: Message-ID: <3AEC6DE2.E438AFD@seatech.fau.edu> you would want to have several functions one to define a polynom as a name one to add 2 polynoms one to multiply 2 polynoms and it would be nice to propose a menu to the user, so that he can choose what he wants to do A frame for your program could be ( i did not debug it...) polynome= {} def initPolynom(): global polynome name= raw_input('Polynom name ?') degree=raw_input('degree ?') coeff=[] for i in range (0, degree+1): coefficient = raw_input('coeff for x^ %i' %i) coeff.append(coefficient) polynome[name]=coeff def multiply(): global polynome name1= raw_input('Polynom name 1?') name2= raw_input('Polynom name 2?') pol1= polynome[name1] pol2 =polynome[name2] # perform here the multiplication logic. pol3 = pol1 * pol2 print pol3 name3 = raw_input('Give a name for the result..') polynome[name3]=pol3 def add(): pass # and now ... the menu menu=['init': initPolynom, 'multiply': multiply, 'add': add] for item in menu.keys(): print item choice = raw_input('your choice') if menu.has_key(choice): menu[choice]() Julieta Rangel wrote: > If I want to write a program that multiplies polynomials, just to show > you how illiterate I am at computer programming, this is what I would > do: I would need the user to enter the amount of polynomials that will > be multiplying. Lets say the user wants to multiply two polynomials. > Once the user enters the amount of polynomials that will be > multiplying, the computer would have to ask the degree of the > polynomials, say the first polynomial is of third degree and the > second is a second degree polynomial (2x^3 + x^2 + 3x + 2) * (x^2 + > 1)Once the person enters the degree of the polynomials, the computer > would have to ask the coefficient of each of the terms of the > polynomials, in this case the computer would have to ask the user to > enter the coefficient of x^3, x^2, x, and c and then the coefficients > of the second polynomial. Should I have the computer create two lists > for each polynomial? In one list I would store all the coefficients > and in another the exponents of the expression. > > > One list is enough (just the coeff): coeff[0] is coeff for exp. 0, > etc... > > > I'm assuming that if I have two lists for each polynomial, I could do > the operations required. Based on the polynomials I have, the lists > of coefficients would look like (L1) [2,1,3,2] and (L2)[1,0,1] and my > lists of exponents would look like (L 3) [3,2,1,0] and (L 4)[2,1,0]. I > would then have the first element in L1 times each element in L2, so > that I get list 5 [2,0,2]and 1st element in L3 + each element in L4, > so that I get list 6 [5,4,3]. Then I would have the 2nd element in L1 > times each element in L2 so that I get another list [1,0,1] and also > have the 2nd element in L3 + each element in L4, so that I get > [4,3,2]. This would go on for each element and I would end up with 4 > more lists [3,0,3], [3,2,1], [2,0,2], [2,1,0]. I would then take the > numbers from my lists and have the computer write the coefficients > along with the exponents: 2x^5 + 0x^4 + 2x^3 + x^4 > +0x^3+x^2+3x^3+0x^2 +3x+ 2x^2+0x+2. I would then have to get rid of > those terms with zero coefficients and combine like terms. Is this > crazy or what? How could I accomplish this? Like I told you before, > this is all new to me, but I'm really interested in finding out how > this complex task can be accomplished in Python. Can you > help? Julieta > > > ----------------------------------------------------------------------- > Get your FREE download of MSN Explorer at http://explorer.msn.com > _______________________________________________ Tutor maillist - > Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From scarblac@pino.selwerd.nl Sun Apr 29 22:46:58 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sun, 29 Apr 2001 23:46:58 +0200 Subject: [Tutor] Multiplication of polynomials In-Reply-To: ; from julieta_rangel@hotmail.com on Sun, Apr 29, 2001 at 01:48:34PM -0500 References: Message-ID: <20010429234658.A10233@pino.selwerd.nl> On 0, Julieta Rangel wrote: *Please* set your email to sending plain text. I have to jump through some hoops to get html mail into readable form. Not everyone uses Microsoft products, even though they want you to believe so. >
If I want to write a program that multiplies > polynomials, just to show you how illiterate I am at computer > programming, this is what I would do: I would need the user to enter the > amount of polynomials that will be multiplying.  Lets say the user > wants to multiply two polynomials.  Once the user enters the amount of > polynomials that will be multiplying, the computer would have to ask the > degree of the polynomials, say the first polynomial is of third degree and > the second is a second degree polynomial (2x^3 + x^2 + 3x + 2) * (x^2 + > 1)Once the person enters the degree of the polynomials, the computer would > have to ask the coefficient of each of the terms of the polynomials,  > in this case the computer would have to ask the user to enter the > coefficient of  x^3, x^2, x, and c and then the coefficients of the > second polynomial.  Should I have the computer create two lists for > each polynomial?  In one list I would store all the coeffici! ents and > in another the exponents of the expression.  Let's ignore the way the user gives his input at first. It's relatively trivial, and there are many ways to do it. No, two lists aren't necessary. Keep one list for the coefficients, and you'll know from the length of that list which exponents the numbers belong to. If you have a list, say, L=[1,2,3,4], then that should be for a 3rd degree polynomial (len(L)-1), where L[0] is the coefficient of the 0-degree term, ie the constant. It stands for 4x^3+3x^2+2x+1. > I'm assuming that if I > have two lists for each polynomial, I could do the operations > required.  Based on the polynomials I have, the lists of coefficients > would look like (L1) [2,1,3,2] and (L2)[1,0,1] and my lists of exponents > would look like (L 3) [3,2,1,0] and (L 4)[2,1,0]. I would then have the > first element in L1 times each element in L2, so that I get list > 5 [2,0,2]
>
and 1st element in L3 + each element in L4, so that I get list 6 > [5,4,3].  Then I would have the 2nd element in L1 times each element in > L2 so that I get another list [1,0,1] and also have the 2nd element in L3 + > each element in L4, so that I get [4,3,2].  This would go on for each > element and I would end up with 4 more lists [3,0,3], [3,2,1], [2,0,2], > [2,1,0].  I would then take the numbers from my lists and have the > computer write the coefficients along with the exponents:  2x^5 + 0x^4 > + 2x^3 + x^4 +0x^3+x^2+3x^3+0x^2 +3x+ 2x^2+0x+2.    I would > then have to get rid of those terms with zero coefficients and combine like > terms.  Is this crazy or what? Make one function that adds two functions, by adding together their coefficients. Then you can have the multiplication function generate the polynomials that have to be added together. >   How could I accomplish this?  > Like I told you before, this is all new to me, but I'm really interested in > finding out how this complex task can be accomplished in Python.  Can > you help?
I'm going to explain how I would do this with OO (Object Oriented) programming. You see, a polynomial here is a bit of data, with a nontrivial representation (like your lists, but there may be other ways), and a bunch of related functions (for adding them together, evaluating them, printing them as a string, and so on). This kind of "rich data" usually means that making an object is a good idea. This is the first version: class Polynomial: def __init__(self, coefficients): self.coefficients = coefficients def degree(self): return len(self.coefficients)-1 def coefficient(self, n): # n is the degree of the term of which we need the coefficient # it has to be an integer >= 0 if (type(n) != type(1)) or n < 0: raise ValueError, "n has to be an integer >= 0" if n >= len(self.coefficients): # All coefficients greater than the ones in the list are 0 return 0 else: return self.coefficients[n] That's a simple first version. You could use it like this (suppose it is in a file polynomial.py): >>> import polynomial >>> p = polynomial.Polynomial([1,2,3,4]) >>> p.degree() 3 # It's a third degree polynomial >>> p.coefficient(3) 4 # coefficient of x^3 is 4 You'd want to add methods for turning it into a string, evaluating it, adding them together and multiplying: def __str__(self): terms = [] for i in range(len(self.coefficients)): if i == 0: # If i == 0, the term is a constant terms.append(str(self.coefficients[0])) elif i == 1: # If i == 1, it's simply coefficient*x terms.append(str(self.coefficients[0])+"x") else: # Otherwise use the ^ thing terms.append(str(self.coefficients[0])+"x^"+str(i)) terms.reverse() # Customary to list highest degree first return "+".join(terms) # Put '+' between the terms def eval(self, x): result = 0L for i in range(len(self.coefficients)): result += self.coefficients[i]*(x**i) return result def add(self, other): """Return a new polynomial that is the sum of self and other""" # The length of the needed list is the maximum of their two degrees, # plus one. length = max(self.degree(), other.degree()) + 1 # Initialize a list that length result = [0] * length # Fill it with the sums for i in range(len(result)): result[i] = self.coefficient(i) + other.coefficient(i) # Construct new polynomial and return it return Polynomial(result) def multiply_single_term(self, coefficient, degree): # First the simple form of multiplication: by a single term. # If the polynomial is multiplied by, say, 4x^3, we added three # zeroes to the beginning of the list of coefficients, and multiply # the rest by 4. # Construct a new polynomial that is a copy of this one result = Polynomial(self.coefficients[:]) # Add zeroes result.coefficients[0:0] = [0]*degree # Multiply by coefficient for i in range(len(result.coefficients)): result.coefficients *= coefficient return result def multiply(self, other): # Start with a zero polynomial, add to it self multiplied by each # term of other. Return the result. result = Polynomial([]) for term in range(other.degree()+1): result=result.add(self.multiply_single_term(other.coefficient(term), term)) return result Hmm, this has become rather longer than I expected. No time left to explain the details, argh. Ask about whatever is unclear, like what OO is and how to use this.... (of course, nothing tested, as usual) -- Remco Gerlich From juno@gamefire.com Mon Apr 30 00:35:35 2001 From: juno@gamefire.com (juno@gamefire.com) Date: Sun, 29 Apr 2001 16:35:35 -0700 Subject: [Tutor] Help with saving data Message-ID: Hello, Can someone tell me the best way to save an object to disk? It the object uses a list of dictionaries for storing its data. Thanks, Juno PS. Andrew, your email helped, thx! From jaime@hilcos01.hilconet.com Mon Apr 30 00:36:28 2001 From: jaime@hilcos01.hilconet.com (JAIME'S MAIL) Date: Sun, 29 Apr 2001 18:36:28 -0500 Subject: [Tutor] 15 puzzle Message-ID: <000901c0d105$37f63d60$38178440@oemcomputer> I would like to make a program for the 15-puzzle in python language. I have this program for it, but it is in another language. Could you help me translate it to python? import java.applet.*; import java.awt.*; //-------------------------------------------------------------------------- public class fifteen extends Applet { private SevenSegmentDigit[] display = new SevenSegmentDigit[3]; private Button[] Buttons = new Button[16]; //This array is an actuall playfield. private Button shuffleBtn = new Button ("&Shuffle"); private int score=0; private int shuffling=0; private Font f; /*---------------------------------------------------------------*/ public String getAppletInfo() //Do I need this function? { return "Name: fifteen\r\n" + "Author: Eugene\r\n" + "Created with Microsoft Visual J++ Version 1.0"; } /*---------------------------------------------------------------*/ public void init() { int i=0; String str=new String(); resize(200, 300); setLayout(null); //Why do they bother so hard with layouts? setBackground(Color.black); for(i=0; i3) moveBtn(empty-4); return true; case Event.LEFT: if(empty % 4 !=3) moveBtn(empty+1); return true; case Event.RIGHT: if(empty % 4 != 0) moveBtn(empty-1); return true; case 's': case 'S': shuffle(); return true; } return false; } /*---------------------------------------------------------------*/ public boolean action(Event evt, Object what) { int i=0; for(i=0;i _____________________________________________________________ I would appreciate any help! Maritza From rob@jam.rr.com Mon Apr 30 00:30:25 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Sun, 29 Apr 2001 18:30:25 -0500 Subject: [Tutor] Help with saving data References: Message-ID: <3AECA411.A16AE528@jam.rr.com> If I understand your question correctly, you might want to look into the pickle module. Rob juno@gamefire.com wrote: > > Hello, > Can someone tell me the best way to save an object to disk? It the object > uses a list of dictionaries for storing its data. > > Thanks, > > Juno > > PS. Andrew, your email helped, thx! > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From dyoo@hkn.eecs.berkeley.edu Mon Apr 30 05:43:28 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 29 Apr 2001 21:43:28 -0700 (PDT) Subject: [Tutor] 15 puzzle In-Reply-To: <000901c0d105$37f63d60$38178440@oemcomputer> Message-ID: On Sun, 29 Apr 2001, JAIME'S MAIL wrote: > I would like to make a program for the 15-puzzle in python language. > I have this program for it, but it is in another language. Could you > help me translate it to python? Almost all of the code included in the message deals with GUI stuff: building buttons and displaying the game as a window. As much as it pains me to say this, I'd recommend not using this as a base for your own code for now, because Java's model for doing GUI's is a bit different from Python. (We can help you to write a graphical program later on with the Tkinter module a little later though.) Can you try writing a program that does the 15-puzzle in plain text? It might sound a little less exciting than graphics, but it's easier to work with, and with some imagination, it's still a fun problem. Once we have something that, at the heart of it, represents the 15-puzzle, we should be able to slap a nice GUI on top of that. It looks like the author of the code uses an array of length 16 to represent a particular "state" or situation of the board. This sounds like a nice idea. Try to work on getting the 15-puzzle working as a text game first, and we can help convert it to something that uses the gui stuff. If you're getting really stuck on starting, I've typed up a small skeleton framework that might be useful for you; you don't need to use it though.: [spoiler space ahead] ### winning_board = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '.'] def printBoard(board): for i in range(0, 16, 4): print board[i:i+4] def moveHole(board, direction): # Fix me! Nowhere near done yet. if direction == 'up': pass elif direction == 'down': pass elif direction == 'left' : pass elif direction == 'right' : pass def didWeWin(board): if board == winning_board: return 1 else: return 0 def playGame(): # let's start it off with some board. board = ['2', '1', '3', '4', '1', '.', '7', '8', '5', '10', '11', '12', '9', '13', '14', '15'] while not didWeWin(board): pass # Fix me! We should probably add stuff to ask # the user where to move, and modify our board # accordingly. Also, it might be nice to show # what the board looks like as we play the # game. if __name__ == '__main__': playGame() ### Good luck to you! From toodles@yifan.net Mon Apr 30 10:32:14 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Mon, 30 Apr 2001 17:32:14 +0800 Subject: [Tutor] Help with saving data In-Reply-To: Message-ID: Using pickle (or cPickle for an improvement in speed) should be sufficient. example: import cPickle my_dict={'example':'123'} #dictionary for saving file_path='c:\\file.tmp' file=open(file_path,'w') #open the file for reading cPickle.dump(my_dict,file) #save to file file.close() file=open(file_path) #open for reading cPickle.dump(my_dict,file) #read from file file.close() The pickle module also supports other types, as well as user defined classes. I don't know a lot about the module, I've only just started using it...I'm about part way through making a MUD system...I'll put it up on Useless once I'm done...sound good Rob? =) > PS. Andrew, your email helped, thx! No worries, that's what I'm here for...apart from lurking of course heh heh Andrew > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From toodles@yifan.net Mon Apr 30 11:12:42 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Mon, 30 Apr 2001 18:12:42 +0800 Subject: [Tutor] Help with saving data In-Reply-To: Message-ID: in the loading bit it's meant to be cPickle.load() not cPickle.dump() sorry for that...ahh the perils of cut and paste =) Andrew > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Andrew Wilkins > Sent: Monday, 30 April 2001 5:32 PM > To: tutor@python.org > Subject: RE: [Tutor] Help with saving data > > > Using pickle (or cPickle for an improvement in speed) should be > sufficient. > > example: > > import cPickle > > my_dict={'example':'123'} #dictionary for saving > file_path='c:\\file.tmp' > > file=open(file_path,'w') #open the file for reading > cPickle.dump(my_dict,file) #save to file > file.close() > > file=open(file_path) #open for reading > cPickle.dump(my_dict,file) #read from file > file.close() > > The pickle module also supports other types, as well as user defined > classes. I don't know a lot about the module, I've only just started using > it...I'm about part way through making a MUD system...I'll put it up on > Useless once I'm done...sound good Rob? =) > > > PS. Andrew, your email helped, thx! > > No worries, that's what I'm here for...apart from lurking of > course heh heh > > Andrew > > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From alan.gauld@bt.com Mon Apr 30 15:28:40 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 30 Apr 2001 15:28:40 +0100 Subject: [Tutor] 15 puzzle Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D726@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0D181.DA0A2C20 Content-type: text/plain; charset="iso-8859-1" This may well have been answered already - I'm catching up from a week's vacation... Here is a skeleton for a 3x3 game and lacks any input validation - ie it's easily broken but it should form a basis for something... Alan G class Grid: grid = [(0,1),(1,2),(2,5), (3,3),(4,7),(5,6), (6,0),(7,4),(8,8)] def findBlock(self,val): for item in self.grid: if item[1] == val: return item def printIt(self): for i in self.grid: if (i[0]+1)%3 != 0: print i[1], else: print i[1] def isSorted(self): for i in range(7): if self.grid[i][1] > self.grid[i+1][1]: return 0 return 1 def swap(self,pos): gap = self.findBlock(0) self.grid[gap[0]] = (gap[0],pos[1]) self.grid[pos[0]] = (pos[0],0) g = Grid() g.printIt() while not g.isSorted(): block = input("Item to move?") item = g.findBlock(block) g.swap(item) g.printIt() if g.isSorted(): print "Game over" break ------_=_NextPart_001_01C0D181.DA0A2C20 Content-type: text/html; charset="iso-8859-1"
This may well have been answered already - I'm catching up from a week's vacation...
 
Here is a skeleton for a 3x3 game and lacks any input validation
- ie it's easily broken but it should form a basis for something...
 
Alan G

class Grid:
   grid = [(0,1),(1,2),(2,5),
            (3,3),(4,7),(5,6),
            (6,0),(7,4),(8,8)]
 
   def findBlock(self,val):
      for item in self.grid:
        if item[1] == val:
            return item
   
   def printIt(self):
      for i in self.grid:
        if (i[0]+1)%3 != 0:
          print i[1],
        else: print i[1]
 
   def isSorted(self):
       for i in range(7):
            if self.grid[i][1] > self.grid[i+1][1]:
              return 0
       return 1
 
   def swap(self,pos):
       gap = self.findBlock(0)
       self.grid[gap[0]] = (gap[0],pos[1])
       self.grid[pos[0]] = (pos[0],0)
           
g = Grid()
g.printIt()
while not g.isSorted():
    block = input("Item to move?")
    item = g.findBlock(block)
    g.swap(item)
    g.printIt()
    if g.isSorted():
        print "Game over"
        break
------_=_NextPart_001_01C0D181.DA0A2C20-- From alan.gauld@bt.com Mon Apr 30 16:18:31 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 30 Apr 2001 16:18:31 +0100 Subject: [Tutor] Multiplication of polynomials Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D727@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0D188.D0F1F850 Content-type: text/plain; charset="iso-8859-1" how illiterate I am at computer programming, this is what I would do: I Pretty much correct. But instead of using lists try using dictionaries. Thus the dictionary vcan be keyed by the order of the polynomial and you can assign the coefficients to the value part. This makes rationalising the final expression a bit easier IMHO. (In fact you could do it 'on the fly') Alan G. ------_=_NextPart_001_01C0D188.D0F1F850 Content-type: text/html; charset="iso-8859-1"
how illiterate I am at computer programming, this is what I would do: I  
 
Pretty much correct.
 
But instead of using lists try using dictionaries.
Thus the dictionary vcan be keyed by the order of
the polynomial and you can assign the coefficients to the
value part. This makes rationalising the final expression
a bit easier IMHO. (In fact you could do it 'on the fly')
 
Alan G.

------_=_NextPart_001_01C0D188.D0F1F850-- From kromag@nsacom.net Mon Apr 30 18:40:38 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Mon, 30 Apr 2001 10:40:38 -0700 (PDT) Subject: [Tutor] Displaying image in scrolled canvas Message-ID: <200104301740.f3UHec821609@pop.nsacom.net> I am attempting to place a large .gif file into a scrolled canvas. I am working from the examples in programming python (in case the code looked slightly familiar :-) To wit: from Tkinter import * class ScrolledCanvas(Frame): def __init__(self, parent=None, color='white'): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) photo=PhotoImage(file='\windows\desktop\wacky3.gif') canv = Canvas(self, bg=color, relief=SUNKEN) canv.config(width=1010, height=745) canv.config(scrollregion=(0,0,300, 1000)) canv.create_image(10,10, image=photo, anchor=NW) sbar = Scrollbar(self) sbar.config(command=canv.yview) canv.config(yscrollcommand=sbar.set) sbar.pack(side=RIGHT, fill=Y) canv.pack(side=LEFT, expand=YES, fill=BOTH) if __name__ == '__main__': ScrolledCanvas().mainloop() results in the properly-sized frame and scrollbar, but for some reason the image does not pop to life. What am I missing here? d From alan.gauld@bt.com Mon Apr 30 17:13:24 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 30 Apr 2001 17:13:24 +0100 Subject: [Tutor] 15 puzzle Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D72A@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0D190.7BB06EF0 Content-type: text/plain; charset="iso-8859-1" This may well have been answered already - I'm catching up from a week's vacation... It appears not yet... Here is a skeleton for a 3x3 game and lacks any input validation - ie it's easily broken but it should form a basis for something... Here it is in full 4x4 size with minimal error detection... class Grid: size = 4 grid = [(0,1),(1,2),(2,5),(3,9), (4,3),(5,7),(6,6),(7,10), (8,0),(9,4),(10,8),(11,11), (12,15),(13,14),(14,13),(15,12) ] def findBlock(self,val): if val in range(self.size**2): for item in self.grid: if item[1] == val: return item else: print "invalid item" return self.findBlock(0) def printIt(self): for i in self.grid: if (i[0]+1)%self.size != 0: print i[1], else: print i[1] def isSorted(self): limit = (self.size**2)-2 for i in range(limit): if (self.grid[i+1][1] - self.grid[i][1]) != 1: return 0 return 1 def swap(self,pos): gap = self.findBlock(0) self.grid[gap[0]] = (gap[0],pos[1]) self.grid[pos[0]] = (pos[0],0) g = Grid() g.printIt() while not g.isSorted(): block = input("Item to move?") item = g.findBlock(block) g.swap(item) g.printIt() if g.isSorted(): print "Game over" break ------_=_NextPart_001_01C0D190.7BB06EF0 Content-type: text/html; charset="iso-8859-1"
This may well have been answered already - I'm catching up from a week's vacation...
It appears not yet... 
Here is a skeleton for a 3x3 game and lacks any input validation
- ie it's easily broken but it should form a basis for something...
 Here it is in full 4x4 size with minimal error detection...
 

class Grid:
   size = 4
   grid = [(0,1),(1,2),(2,5),(3,9),
           (4,3),(5,7),(6,6),(7,10),
           (8,0),(9,4),(10,8),(11,11),
           (12,15),(13,14),(14,13),(15,12)
           ]
 
   def findBlock(self,val):
      if val in range(self.size**2):
        for item in self.grid:
          if item[1] == val:
            return item
      else:
          print "invalid item"
          return self.findBlock(0)
   
   def printIt(self):
      for i in self.grid:
        if (i[0]+1)%self.size != 0:
          print i[1],
        else: print i[1]
 
   def isSorted(self):
       limit = (self.size**2)-2
       for i in range(limit):
            if (self.grid[i+1][1] - self.grid[i][1]) != 1:
              return 0
       return 1
 
   def swap(self,pos):
       gap = self.findBlock(0)
       self.grid[gap[0]] = (gap[0],pos[1])
       self.grid[pos[0]] = (pos[0],0)
           
g = Grid()
g.printIt()
while not g.isSorted():
    block = input("Item to move?")
    item = g.findBlock(block)
    g.swap(item)
    g.printIt()
    if g.isSorted():
        print "Game over"
        break
------_=_NextPart_001_01C0D190.7BB06EF0-- From dyoo@hkn.eecs.berkeley.edu Mon Apr 30 22:41:05 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 30 Apr 2001 14:41:05 -0700 (PDT) Subject: [Tutor] Displaying image in scrolled canvas [PhotoImage weirdness] In-Reply-To: <200104301740.f3UHec821609@pop.nsacom.net> Message-ID: On Mon, 30 Apr 2001 kromag@nsacom.net wrote: > I am attempting to place a large .gif file into a scrolled canvas. I am > working from the examples in programming python (in case the code looked > slightly familiar :-) > > To wit: > > from Tkinter import * > class ScrolledCanvas(Frame): > def __init__(self, parent=None, color='white'): > Frame.__init__(self, parent) > self.pack(expand=YES, fill=BOTH) > photo=PhotoImage(file='\windows\desktop\wacky3.gif') > canv = Canvas(self, bg=color, relief=SUNKEN) > canv.config(width=1010, height=745) > canv.config(scrollregion=(0,0,300, 1000)) > canv.create_image(10,10, image=photo, anchor=NW) > sbar = Scrollbar(self) > sbar.config(command=canv.yview) > canv.config(yscrollcommand=sbar.set) > sbar.pack(side=RIGHT, fill=Y) > canv.pack(side=LEFT, expand=YES, fill=BOTH) > if __name__ == '__main__': ScrolledCanvas().mainloop() > > results in the properly-sized frame and scrollbar, but for some reason the > image does not pop to life. What am I missing here? The same question popped up last year too! http://mail.python.org/pipermail/tutor/2000-February/001002.html You're right; it's not popping up. For the life of me, I have no idea why this isn't working. What's weird is that: ### root = Tk() photo = PhotoImage(file="test.gif") canv = Canvas(root) canv.pack() canv.create_image(0, 0, image=photo, anchor=NW) mainloop() ### works, but: ### class MyFrame(Frame): def __init__(self, root): Frame.__init__(self, root) photo = PhotoImage(file="test.gif") canvas = Canvas(self) canvas.pack() canvas.create_image(0, 0, image=photo, anchor=NW) root = Tk() f = MyFrame(root) f.pack() mainloop() ### doesn't! I'm looking into this right now; in the meantime, has anyone else run into the same thing? From dyoo@hkn.eecs.berkeley.edu Mon Apr 30 23:04:31 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 30 Apr 2001 15:04:31 -0700 (PDT) Subject: [Tutor] Breaking threads In-Reply-To: <200104302306.f3UN6r802577@pop.nsacom.net> Message-ID: On Mon, 30 Apr 2001 kromag@nsacom.net wrote: > I am working my way through "Programming Python" from the begining (I have > asked too many silly questions! :-). Here is a non-silly question: No problem. > import thread, time > > glarf=open('\windows\desktop\goat.txt', 'w') > > def counter(myId, count): > for i in range(count): > mutex.acquire() > # time.sleep(1) > glarf.write('[%s]=> %s' % (myId, i)) > mutex.release() > > mutex = thread.allocate_lock() > for i in range(10000): > thread.start_new_thread(counter, (i, 3)) > It starts to write 10,000 counts to goat.txt, then dies with the following: > > > Traceback (most recent call last): > File "cornfedbeef.py", line 14, in ? > thread.start_new_thread(counter, (i, 3)) > thread.error: can't start new thread > > It works fine in iterations of 10, 100 and 1000. Why does it puke at the > 10000 mark? Python's thread support is based on what the system underneath provides us. Unfortunately, not all platforms support a threaded model well. What probably happened was that the system got flooded by too many threads. Many systems have a hard time supporting even 1000 threads. According to one group: "It has been our experience that in real world use, Windows NT is incapable of running more than 1000 simultaneous threads at a time" http://www.lyris.com/about/company/whitepapers/lm_extreme/secondgen.html On the Linux side, the story is even more grim: you're limited to 256 threads at a time: http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html So this is something that will probably need to be fixed. At the moment though, try to avoid writing programs that abuse the threading system. *grin* From wildchild07770@yahoo.com Mon Apr 30 21:54:42 2001 From: wildchild07770@yahoo.com (Aaron) Date: Mon, 30 Apr 2001 15:54:42 -0500 Subject: [Tutor] Program not accessing while loops Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C0D18D.DEF0F0A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I wrote this out last night on a different computer and I had the = script running fine but now that I rewrote it doesn't seem to be = accesing the second group of while loops, the main menu will load and = keep running and asking for input, but it won't call on the loop. #character managment program totop =3D 1 while totop =3D=3D 1: print print "Main Menu" print "---------" print mainmenu =3D ["1 for to create a new character", "2 to manage an = existing character", "3 to exit the program"] for x in mainmenu: print "Enter", x mainmen =3D raw_input(">") while mainmen =3D=3D 1: print "This function is under construction" while mainmen =3D=3D 2: print "This function is under construction" while mainmen =3D=3D 3: exit =3D raw_input("are you sure? ") if exit =3D=3D r"yes": totop =3D=3D 2 break elif exit =3D=3D r"no": totop =3D=3D 1 break while mainmen < 3: print "Invalid choice, choose again" for x in mainmenu: print "Enter", x mainmen =3D raw_input(">") Thanks, aaron ------=_NextPart_000_0007_01C0D18D.DEF0F0A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi, I wrote this out last night on = a different=20 computer and I had the script running fine but now that I rewrote = it=20 doesn't seem to be accesing the second group of while loops, the main = menu will=20 load and keep running and asking for input, but it won't call on the=20 loop.
 
#character managment program
totop = =3D 1
while=20 totop =3D=3D 1:
    print
    print = "Main=20 Menu"
    print "---------"
   =20 print
    mainmenu =3D ["1 for to create a new = character", "2 to=20 manage an existing character", "3 to exit the = program"]
   =20 for x in mainmenu:
        print = "Enter",=20 x
    mainmen =3D = raw_input(">")
    while=20 mainmen =3D=3D 1:
        print = "This function=20 is under construction"
    while mainmen =3D=3D=20 2:
        print "This function is = under=20 construction"
    while mainmen =3D=3D=20 3:
        exit =3D raw_input("are = you sure?=20 ")
        if exit =3D=3D=20 r"yes":
          &n= bsp;=20 totop =3D=3D = 2
           =20 break
        elif exit =3D=3D=20 r"no":
          &nb= sp;=20 totop =3D=3D = 1
           =20 break
    while mainmen <=20 3:
        print "Invalid choice, = choose=20 again"
        for x in=20 mainmenu:
          =  =20 print "Enter", x
        mainmen = =3D=20 raw_input(">")
 
Thanks, = aaron
------=_NextPart_000_0007_01C0D18D.DEF0F0A0--