From cyberdiction@hotmail.com Sun Sep 1 00:09:21 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Sat, 31 Aug 2002 16:09:21 -0700 Subject: [Tutor] Re: q about method(self) Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0021_01C25108.C47FE720 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable "Emile van Sebille" wrote in message = news:akqqpg$obt$1@main.gmane.org... > Erik: > > A class method generally takes "self" as its first argument. >=20 > It is named self by convention only. You can call it 'this' if you = want. >=20 > > I had > > been wondering for some time why this is, since it seems redundant = if > > it's there for all class methods. But I just realized -- you can = call > > an object's method without using dot notation in Python, like this: > > > > method(instance_reference, args) >=20 > This might also be seen as function(inst_ref, args) which serves to = show > that a class method is not really much different from any function. = In this > case, the instance being passed could come from any class. >=20 > > > > rather than only like this: > > > > instance_reference.method(args) > > > > I didn't realize that until just now. But what I'm wondering is, > > why/when would you want to use this form? Since I was just reading about this in the Sams Teach yourself Python in 24 Hours, which is introductory, obviously, I post: "Although you can call a function or method and use the return value to = assign to or create a variable, the function itself cannot create = something outside its box=97unless the function uses the self parameter. = We see how that's done in Listing 10.1. The way to create variables = (members in OOP talk) in an object is the same way Python creates all = variables=97by assigning a value to them. That's what is going on = Listing 10.1; self.t, self.year, self.month, and so on are variables = being created as members of class now. The localtime() function returns = a 9-tuple; an assignment such as that shown in the previous listing = unpacks the tuple, placing the values into the variables on the left = side of the =3D sign, exactly the way you would expect. Dow stands for = ''day of the week," doy indicates "day number of the year," and dst is 1 = if daylight savings time is being observed, 0 if not. =20 =20 After you create an instance of class now, you can, outside the box, = look inside the instance and see that the __init__() method has created = variables. You can inspect the variables, you can modify them, you can = add new methods, and you can call any methods that are inside the class; = you can even modify the methods and variables after creating an = instance. However, if you do that, when you create another instance, = your added methods and variables won't show up in the new instance. = (There is a way to do this, but it's not something you'll be wanting to = do for a long time, and it won't be covered in this book.) =20 =20 As you saw in the original listing for class now, which was presented = in the preceding chapter (see Listing 9.2), creating an instance of a = class is easy: =20 n =3D now() print "The year is", n.year =20 =20 You may notice that creating an instance of a class looks very much like = calling a function. That's because it is; Python does a few magic tricks = behind the scenes, by fabricating a generic object and then passing that = as the self argument to a function call that effectively looks like =20 =20 n =3D now.__init__(object) =20 =20 After you've created an instance of a class, you might think that you = could call the class's __init__() method directly, like this: =20 =20 n =3D now() o =3D now.__init__(n) print "year", o.year, n is o =20 =20 If you run the preceding code, you'll see that you get an = AttributeError that tells you that the object o is not an instance of = class now, but a None object. That's because the self argument you = provided to __init__() was not really a reference to itself. Only Python = can construct a generic object that will really work in such a call. = Chalk it up to magic." SH: I'm not sure what that last paragraph means. Regards, Stephen=20 ------=_NextPart_000_0021_01C25108.C47FE720 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
 
"Emile van Sebille" <emile@fenx.com> wrote in message = news:akqqpg$obt$1@main.gmane.or= g...
> Erik:
> > A class method generally takes "self" as = its first=20 argument.
>
> It is named self by convention only.  = You can=20 call it 'this' if you want.
>
> > I had
> > = been=20 wondering for some time why this is, since it seems redundant if
> = >=20 it's there for all class methods.  But I just realized -- you can=20 call
> > an object's method without using dot notation in = Python, like=20 this:
> >
> > method(instance_reference, args)
> =
> This might also be seen as function(inst_ref, args) which = serves to=20 show
> that a class method is not really much different from any=20 function.  In this
> case, the instance being passed could = come from=20 any class.
>
> >
> > rather than only like=20 this:
> >
> > instance_reference.method(args)
>=20 >
> > I didn't realize that until just now.  But what = I'm=20 wondering is,
> > why/when would you want to use this = form?
 
Since I was just reading about this in the Sams Teach = yourself
Python in 24 Hours, which is introductory, obviously, I post:
 
"Although you can call a function or method and use the return = value to=20 assign to or create a variable, the function itself cannot create = something=20 outside its box=97unless the function uses the self parameter. We see = how that's=20 done in Listing 10.1. The way to create variables (members in OOP talk) = in an=20 object is the same way Python creates all variables=97by assigning a = value to=20 them. That's what is going on Listing 10.1; self.t, self.year, = self.month, and=20 so on are variables being created as members of class now. The = localtime()=20 function returns a 9-tuple; an assignment such as that shown in the = previous=20 listing unpacks the tuple, placing the values into the variables on the = left=20 side of the =3D sign, exactly the way you would expect. Dow stands for = ''day of=20 the week," doy indicates "day number of the year," and dst is 1 if = daylight=20 savings time is being observed, 0 if = not.  
 
 After=20 you create an instance of class now, you can, outside the box, look = inside the=20 instance and see that the __init__() method has created variables. You = can=20 inspect the variables, you can modify them, you can add new methods, and = you can=20 call any methods that are inside the class; you can even modify the = methods and=20 variables after creating an instance. However, if you do that, when you = create=20 another instance, your added methods and variables won't show up in the = new=20 instance. (There is a way to do this, but it's not something you'll be = wanting=20 to do for a long time, and it won't be covered in this=20 book.)  
 
 As you saw in the original listing = for=20 class now, which was presented in the preceding chapter (see Listing = 9.2),=20 creating an instance of a class is easy:  

 n =3D now()
print "The year is",=20 n.year  
 
You may notice that creating an instance of a class looks very much = like=20 calling a function. That's because it is; Python does a few magic tricks = behind=20 the scenes, by fabricating a generic object and then passing that as the = self=20 argument to a function call that effectively looks=20 like  
 
 n =3D=20 now.__init__(object)  
 
 After you've created = an=20 instance of a class, you might think that you could call the class's = __init__()=20 method directly, like this:  
 
 n =3D = now()
o =3D=20 now.__init__(n)
print "year", o.year, n is=20 o  
 
 If you run the preceding code, you'll = see that=20 you get an AttributeError that tells you that the object o is not an = instance of=20 class now, but a None object. That's because the self argument you = provided to=20 __init__() was not really a reference to itself. Only Python can = construct a=20 generic object that will really work in such a call. Chalk it up to=20 magic."
 
SH: I'm not sure what that last paragraph means.
 
Regards,
Stephen 

------=_NextPart_000_0021_01C25108.C47FE720-- From iumarumo@eidosnet.co.uk Sun Sep 1 01:56:56 2002 From: iumarumo@eidosnet.co.uk (Ibraheem Umaru-Mohammed) Date: Sun, 1 Sep 2002 01:56:56 +0100 Subject: Iterators (was: Re: [Tutor] text module) In-Reply-To: <3F86314E-BCDE-11D6-9B69-00039351FE6A@mac.com> References: <200208310141.30176.scot@possum.in-berlin.de> <3F86314E-BCDE-11D6-9B69-00039351FE6A@mac.com> Message-ID: <20020901005656.GA5950@micromuse.com> ["Erik Price"="Erik"] Erik >> On Friday, August 30, 2002, at 07:41 PM, Scot W. Stevenson wrote: Erik >> Erik >> >This is okay if you know that the file is going to be small and you Erik >> >machine Erik >> >is big, but for large files on small machines, it could be a problem: Erik >> >readlines loads the whole file into memory in one big gulp. xreadlines Erik >> >was Erik >> >created in Python 2.1 (I think) to avoid this problem, but if you have Erik >> >Python 2.2 or later, the really cool thing to do is to use iterators Erik >> >and Erik >> >simply create a loop such as: Erik >> > Erik >> >for line in subj: Erik >> > (etc) Erik >> Erik >> Not having any idea what iterators are, I went to the docs Erik >> (http://python.org/doc/current/whatsnew/node4.html) and read about Erik >> them. But as always I am not sure of everything. Erik >> A good article on iterators and generators is: ,---- [ url ] | http://www-106.ibm.com/developerworks/library/l-pycon.html?t=gr,lnxw10=PyIntro `---- Erik >> I understand the construction that Scot uses above, because the docs Erik >> explain that file objects incorporate the __iter__() method, and "for" Erik >> loops now act upon this method for all sequence objects (and file Erik >> objects too). Erik >> Erik >> It's the first part of the explanation of iterators that I'm not Erik >> totally clear on, the part that explains how you can incorporate your Erik >> own iterators into your own class definitions. Erik >> Erik >> Erik >> Is it that you specify an "__iter__()" method, and then you implement Erik >> the code that would go about returning a "next" item each time the Erik >> __iter__() method is called? How do you store the state of the object Erik >> such that it knows which item to return next time the __iter__() method Erik >> is called? Am I correct in assuming that you must implement the Erik >> StopIterator exception yourself in the code for situations in which Erik >> there are no more items to be iterated over? And finally, do you write Erik >> a separate class definition for an iterator, and then have your Erik >> original class definition use the iterator object, or is this something Erik >> that can be entirely kept within the class definition for the object in Erik >> question? Erik >> Erik >> It's a confusing document IMHO. I would appreciate any discussion and Erik >> thoughts that anyone cares to contribute. Erik >> I agree, that the document probably could have done with some examples or something added to the tutorial. I haven't played much with iterators myself, nor simple generators, but the code below might help, as it is an example that uses both the __iter__() and next() methods required of user-defined classes that adhere to the iterator protocol. ,---- [ myrange.py => Iterators ] | #!/usr/bin/env python | | class MyRange: | def __init__(self,step=1): | self.zeroToTen = ["zero", "one", "two","three","four","five","six","seven","eight","nine","ten" ] | self.index = 0 | self.step = step | | def __iter__(self): | return self | | def next(self): | if self.index >= len(self.zeroToTen): | raise StopIteration | index = self.index | self.index += self.step | return self.zeroToTen[index] | | if __name__ == "__main__": | myrange = MyRange(1) | for item in myrange: | print item | | myrange = MyRange(3) | for item in myrange: | print item `---- It basically has functionality similar to range(), but instead returns the name of the number as a string as opposed to returning numbers. It is limited to the range, zero to ten. The key here is the use of the "step", to specify the stride through the 11 elements. In the function next(), we have to save the value of the current index before we increment the index counter (in preparation for the "next" value) - we need to do this before we return the value for the next() method. If the step was always "1", the "++" that some other languages provied would have been useful here (e.g return self.zeroToTen[self.index++]). Maybe someone else can shed some more light on using iterators and generators. Anyway, I hope this helps a little. --ibz. -- Ibraheem Umaru-Mohammed "ibz" umarumohammed (at) btinternet (dot) com From iumarumo@eidosnet.co.uk Sun Sep 1 02:03:04 2002 From: iumarumo@eidosnet.co.uk (Ibraheem Umaru-Mohammed) Date: Sun, 1 Sep 2002 02:03:04 +0100 Subject: Iterators (was: Re: [Tutor] text module) In-Reply-To: <20020901005656.GA5950@micromuse.com> References: <200208310141.30176.scot@possum.in-berlin.de> <3F86314E-BCDE-11D6-9B69-00039351FE6A@mac.com> <20020901005656.GA5950@micromuse.com> Message-ID: <20020901010304.GB5950@micromuse.com> ["Ibraheem Umaru-Mohammed"="Ibraheem"] Ibraheem >> ,---- [ myrange.py => Iterators ] Ibraheem >> | #!/usr/bin/env python Ibraheem >> | Ibraheem >> | class MyRange: Ibraheem >> | def __init__(self,step=1): Ibraheem >> | self.zeroToTen = ["zero", "one", "two","three","four","five","six","seven","eight","nine","ten" ] Ibraheem >> | self.index = 0 Ibraheem >> | self.step = step Ibraheem >> | Ibraheem >> | def __iter__(self): Ibraheem >> | return self Ibraheem >> | Ibraheem >> | def next(self): Ibraheem >> | if self.index >= len(self.zeroToTen): Ibraheem >> | raise StopIteration Ibraheem >> | index = self.index Ibraheem >> | self.index += self.step Ibraheem >> | return self.zeroToTen[index] Ibraheem >> | Ibraheem >> | if __name__ == "__main__": Ibraheem >> | myrange = MyRange(1) Ibraheem >> | for item in myrange: Ibraheem >> | print item Ibraheem >> | Ibraheem >> | myrange = MyRange(3) Ibraheem >> | for item in myrange: Ibraheem >> | print item Ibraheem >> `---- Ibraheem >> Don't know what happened there, but take care with the tabs/spaces above. Kindest regards, --ibz. -- Ibraheem Umaru-Mohammed "ibz" umarumohammed (at) btinternet (dot) com From shalehperry@attbi.com Sun Sep 1 02:37:03 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Sat, 31 Aug 2002 18:37:03 -0700 Subject: [Tutor] Re: q about method(self) In-Reply-To: References: Message-ID: <200208311837.03822.shalehperry@attbi.com> On Saturday 31 August 2002 16:09, Stephen Harris wrote: > After you've created an instance of a class, you might think that you > could call the class's __init__() method directly, like this: > > n =3D now() > o =3D now.__init__(n) > print "year", o.year, n is o > > If you run the preceding code, you'll see that you get an AttributeErr= or > that tells you that the object o is not an instance of class now, but a > None object. That's because the self argument you provided to __init__(= ) > was not really a reference to itself. Only Python can construct a gener= ic > object that will really work in such a call. Chalk it up to magic." > > SH: I'm not sure what that last paragraph means. > > Regards, > Stephen __init__ is special (like the other __foo__() methods) and you should not= call=20 it directly. It exists for the interpreter. An object is created by the= =20 first line 'n =3D now()' calling __init__ is just another function call w= hen=20 done by hand. From idiot1@netzero.net Sun Sep 1 04:17:22 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 31 Aug 2002 23:17:22 -0400 Subject: [Tutor] returning to my memberlister script References: <3D6DA598.AC3E0B8@netzero.net> Message-ID: <3D7186C2.19A0A185@netzero.net> OK, this is getting frustrating. I am reading the actual source text for cgi.py, and sure enough, the damn thing returns a dictionary. This script should be working, and it howls like a wolf with a full moon. Which means I am doing something wrong, but I am not catching it. Anyone want to look at this and adjust my headspace and timing please? This apprentice requests correction. Kirk Bailey wrote: > > Well, I have been busy, but finally got to return to my memberlister script. > > It gets this result in the www.errorlog: > SyntaxError: invalid syntax > [Thu Aug 29 00:26:38 2002] [error] [client 63.208.207.252] Premature end of script headers: /www/www.tinylist.org/cgi-bin/TLmemberlister.py > Traceback (innermost last): > File "/www/www.tinylist.org/cgi-bin/TLmemberlister.py", line 126, in ? > print 'listname='+mylist+'

' > TypeError: __add__ nor __radd__ defined for these operands > > Here is the script ( I will omit the text headers): > login as: howlermo > Sent username "howlermo" > howlermo@howlermonkey.net's password: > Last login: Wed Aug 28 00:04:44 2002 from dialup-65.59.82. > Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994 > The Regents of the University of California. All rights reserved. > > FreeBSD 3.4-RELEASE (HOWLER) #0: Thu Jun 21 22:13:44 EDT 2001 > > Welcome to the Monkey! > Please, enjoy your stay... now get to work! > > You have new mail. > $ /www/www.howlermonkey.net > > print "Key 'owner' not found!" #120 > if not (form.has_key("password")): > print "key 'password' not found!" > if not (form.has_key("listname")): > print "key 'listname' not found!" > mylist = form["listname"] # listname, > print 'listname='+mylist+'

' > myowner = form["Owner"] # owner, > print 'owner='+myowner+'

' > mypassword = form["password"] # and password. > print 'password='+mypassword+'

' #130 > f1=open('/lists/' + listname + '.owner','r') # read the (listname).owner fil$ > trueowner=string.srip(f1.readline()) # read the owner id > trueword=string.strip(f1.readline()) # read THE PASSWORD > f1.close() # Close the file. > if myowner == trueowner : # if the owner matches up, test$ > if mypassword==trueword: # if the password also $ > f1=open('/lists/'+ mylist,'r') #proceed to access the member ro$ > members=f1.readlines() # read them in, > [ Wrote 151 lines ] > > ns# list TLmemberlister.py > Listing of file TLmemberlister.py in directory:/www/www.tinylist.org/cgi-bin > > #!/usr/local/bin/python > # > # This is TLmemberviewer V:1.3.0 COPYRIGHT 2002 by Kirk D Bailey > # > # It is part of the TinyList MLM suite, released under the GNU GPL. > # which suite is also COPYRIGHT 2002 by Kirk D Bailey. > # Please referr to enclosed GNU license in a seperate file. > # > # Being modular makes for MORE CHOICES AVAILABLE TO YOU! > #10############################################################################# > ### > # Python can be studied and aquired at http://www.python.org/ !!! > #########1#########2#########3#########4#########5#########6#########7#########8 > # that line is 80 char across, try to stay within it if you can. > # > # ADMIN AND LEGAL STUFF: > # This program is free software; you can redistribute it and/or > # modify it under the terms of the GNU General Public License > # as published by the Free Software Foundation; either version 2 > # of the License, or (at your option) any later version. > #20 > # This program is distributed in the hope that it will be useful, > # but WITHOUT ANY WARRANTY; without even the implied warranty of > # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > # GNU General Public License for more details. > # > # You should have received a copy of the GNU General Public License > # along with this program; if not, write to the Free Software > # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. > # You should have received a copy of the GNU General Public License > #30 along with this program; if not, write to: > # > # Free Software Foundation, Inc. > # 59 Temple Place - Suite 330 > # Boston, MA 02111-1307 USA. > # > # and request one; be cool and include a business sized SASE. > # > # Also, the GNU GPL may be viewed online at > # http://www.gnu.org/licenses/gpl.html > #40############################################################################ > # > # "The tyrant's foe, the people's friend, a free press." -Dr Benjamin Franklin. > # > # Think about that last line- this software is your Ezine engine. > ############################################################################### > # > # OWNERSHIP AND PERMISSION ISSUES > # make sure this script runs as a TRUSTED USER- > # and NOT as root!!! You set that up in the Sendmail Config file (sendmail.cf). > #50 Make sure that a NON-priviliged user OWNS > # this script, and that it runs as that identity! > # Generally, this is accomplished by making sure it is owned by that user. > # Permission on all scripts must be 755, files as 666, and listdir as 744. > # The image files must NOT be placed in the cgi-bin, but in the web directory! > ############################################################################### > # > # SPAM > # Spam SUCKS. It also ROBS everyone it touches, each system it passes through. > # Fight spam. DO NOT host open lists all the world may post to. > #60 TinyList CANNOT do so as written, PLEASE do not defeat this. > # > ############################################################################### > # > # > import os, sys, string, cgi # MUST be invoked! > # > # CONFIGURATION SECTION > # ===================== > #number in the next line is a line number to help locate sections of code. > #70 > # NOTE that this script is SUPPOSED to be installed in the web cgi-bin! > # and the lists dir is immediately under this dir! > # > # ok, where am I? I just woke up! > fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0])) > # > # ok, now my config file is supposed to be RIGHT HERE with me! > # So let's read the thing! > f1=open("tinylist.cf",'r') > #80 > # Tell me little file, who am I? > webdomain=string.strip(f1.readline()) > f1.close() > # > # knowing where I am, I know that my lists are ONE FLOOR DOWN! > path=fullpathtoscript[0] > # ALL TinyList scripts MUST live in the web cgi-bin, and > # ALL global and list files are directly off the web cgi-bin dir in '/lists'. > # that dir should be owned by the same owner and group as this script, and > #90 should be chmod 766. DIR 'list' must be 766, with all Scripts 755. > # > # > # > # > # > # > # > # > # data arrives as 'QUERY_STRING'=(listname value) using > #100 the GET method, but cgi module handles this nicely, > # parsing it out into keywords and vlaues in a dictionary! > # > # > # > print "Content-type: text/html\n\n" # HTML is following > print '' > print '' > print 'TinyList membership listing Utility.' > print '' > print "" > print '

' > print '


  TinyList

' > print '


' > # > form=cgi.FieldStorage() # recover the form's data, > if not (form.has_key("Owner")): > print "Key 'owner' not found!" #120 > if not (form.has_key("password")): > print "key 'password' not found!" > if not (form.has_key("listname")): > print "key 'listname' not found!" > mylist = form["listname"] # listname, > print 'listname='+mylist+'

' # > myowner = form["Owner"] # owner, > print 'owner='+myowner+'

' # > mypassword = form["password"] # and password. > print 'password='+mypassword+'

' #130 > f1=open('/lists/' + listname + '.owner','r') # read the (listname).owner file, > trueowner=string.srip(f1.readline()) # read the owner id > trueword=string.strip(f1.readline()) # read THE PASSWORD > f1.close() # Close the file. > if myowner == trueowner : # if the owner matches up, test the password; > if mypassword==trueword: # if the password also matches, > f1=open('/lists/'+ mylist,'r') #proceed to access the member roster. > members=f1.readlines() # read them in, > f1.close # and close the file. > for i in members: #130 > print i + '
' > else: > print 'Sorry, wrong password.' > else: > print 'Sorry, wrong owner id.' > # > print '


' # close the page, and end. > # > # > #140 > # > > ns# > > Note I am using 1.5.2 python, and an upgrade is not practical at this time. > > I invite suggestions, advice, evil humor, and dead parrot sketch sequals. > > -- > > end > > Respectfully, > Kirk D Bailey > > +---------------------"Thou Art Free." -Eris-----------------------+ > | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | > | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | > | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | > +------------------Thinking| NORMAL |Thinking----------------------+ > +--------+ > ------------------------------------------- > Introducing NetZero Long Distance > Unlimited Long Distance only $29.95/ month! > Sign Up Today! www.netzerolongdistance.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 1 04:34:19 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 31 Aug 2002 23:34:19 -0400 Subject: [Tutor] returning to my memberlister script Message-ID: <3D718ABB.29DA32F0@netzero.net> TLmembershipform.py listing- it generates the form for you, inserting the site relevant information. Offered just in case anyone wants to see what the receiving script is being babbled at by. The big idea here is the newbie user does not have to go in and edit the page for site relevant information, the script includes it automatically. Goal is to make it as easy as possible for marginal users- and them folk in a hurry to get something turned on simple and easy. ns# list TLmembershipform.py Listing of file TLmembershipform.py in directory:/www/www.tinylist.org/cgi-bin #!/usr/local/bin/python # # This is TLmemberviewer V:1.4.0 COPYRIGHT 2002 by Kirk D Bailey # # It is part of the TinyList MLM suite, released under the GNU GPL. # which suite is also COPYRIGHT 2002 by Kirk D Bailey. # Please referr to enclosed GNU license in a seperate file. # # Being modular makes for MORE CHOICES AVAILABLE TO YOU! ################################################################################ # Python can be studied and acquired at http://www.python.org/ !!! #########1#########2#########3#########4#########5#########6#########7#########8 # that line is 80 char across, try to stay within it if you can. # # ADMIN AND LEGAL STUFF: # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. #20 # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # You should have received a copy of the GNU General Public License #30 along with this program; if not, write to: # # Free Software Foundation, Inc. # 59 Temple Place - Suite 330 # Boston, MA 02111-1307 USA. # # and request one; be cool and include a business sized SASE. # # Also, the GNU GPL may be viewed online at # http://www.gnu.org/licenses/gpl.html #40############################################################################ # # "The tyrant's foe, the people's friend, a free press." -Dr Benjamin Franklin. # # Think about that last line- this software is your Ezine engine. ############################################################################### # # OWNERSHIP AND PERMISSION ISSUES # make sure this script runs as a TRUSTED USER- # and NOT as root!!! You set that up in the Sendmail Config file (sendmail.cf). #50 Make sure that a NON-priviliged user OWNS # this script, and that it runs as that identity! # Generally, this is accomplished by making sure it is owned by that user. # Permission on all scripts must be 755, files as 666, and listdir as 744. # The image files must NOT be placed in the cgi-bin, but in the web directory! ############################################################################### # # SPAM # Spam SUCKS. It also ROBS everyone it touches, each system it passes through. # Fight spam. DO NOT host open lists all the world may post to. #60 TinyList CANNOT do so as written, PLEASE do not defeat this. # #end of preamble ############################################################## # # import os, string # MUST be invoked! # # # CONFIGURATION SECTION # ===================== #70 we don' need no stinkin configuration, this is a pretty stupid file. # # # # # # # # f1=open("tinylist.cf",'r') # we hope this simple version will work. #80 # Tell me little file, who am I? localhost=string.strip(f1.readline()) f1.close() # # # # print "Content-type: text/html \n\n" # to prim e the server print "TinyList ListOwner's Membership display form" print '

' #90 print '


   TinyList

List Membership display request Form

' print '' print '
' print '' print '' print '' print '' print '' print '' print '' # 100 print '' print '
Owner:
Owner\'s Password
ListName:
' print '

' print 'To inspect your list\'s membership roster, just fill in your pure email address
' print '("me@here.org" for instance, not "me@here.org <"BoB Dobbs">")
' print "this list's PASSWORD, ('foo')
" print "and the LISTNAME you want to inspect ('mylist')

" print " -->DO NOT<-- INCLUDE THE DOMAIN OF THIS SITE in that list name " print "('mylist@here.org')!" print '


Powered by TinyList!


' # 110promoteme! print "" # end of script. ns# The above script generates this page: TinyList ListOwner's Membership display form


  TinyList

List Membership display request Form

Owner:
Owner's Password
ListName:

To inspect your list's membership roster, just fill in your pure email address
("me@here.org" for instance, not "me@here.org <"BoB Dobbs">")
this list's PASSWORD, ('foo')
and the LISTNAME you want to inspect ('mylist')

-->DO NOT<-- INCLUDE THE DOMAIN OF THIS SITE in that list name ('mylist@here.org')!


Powered by TinyList!


-- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 1 04:42:41 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 31 Aug 2002 23:42:41 -0400 Subject: [Tutor] returning to my memberlister script Message-ID: <3D718CB1.748E2F39@netzero.net> OK, I added this line: print form and the web page displayed THIS: FieldStorage(None, None, [MiniFieldStorage('Submit', 'SUBMIT'), MiniFieldStorage('password', 'fubar'), MiniFieldStorage('listname', 'testlist3'), MiniFieldStorage('Owner', 'idiot1@netzero.net')]) Any ideas what is going on here? This is Python 1.5.2 please note. Yes, I double checked. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 1 05:18:34 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 01 Sep 2002 00:18:34 -0400 Subject: [Tutor] returning to my memberlister script Message-ID: <3D71951A.3A7B4132@netzero.net> Here is my latest version of the script (with preamble text deleted): ns# list TLmemberlister.py Listing of file TLmemberlister.py in directory:/www/www.tinylist.org/cgi-bin #!/usr/local/bin/python # # This is TLmemberviewer V:1.3.0 COPYRIGHT 2002 by Kirk D Bailey # # It is part of the TinyList MLM suite, released under the GNU GPL. # which suite is also COPYRIGHT 2002 by Kirk D Bailey. # Please referr to enclosed GNU license in a seperate file. # # Being modular makes for MORE CHOICES AVAILABLE TO YOU! #10################################################################################ # Python can be studied and aquired at http://www.python.org/ !!! #########1#########2#########3#########4#########5#########6#########7#########8 # that line is 80 char across, try to stay within it if you can. # # ADMIN AND LEGAL STUFF: # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. #20 # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # You should have received a copy of the GNU General Public License #30 along with this program; if not, write to: # # Free Software Foundation, Inc. # 59 Temple Place - Suite 330 # Boston, MA 02111-1307 USA. # # and request one; be cool and include a business sized SASE. # # Also, the GNU GPL may be viewed online at # http://www.gnu.org/licenses/gpl.html #40############################################################################ # # "The tyrant's foe, the people's friend, a free press." -Dr Benjamin Franklin. # # Think about that last line- this software is your Ezine engine. ############################################################################### # # OWNERSHIP AND PERMISSION ISSUES # make sure this script runs as a TRUSTED USER- # and NOT as root!!! You set that up in the Sendmail Config file (sendmail.cf). #50 Make sure that a NON-priviliged user OWNS # this script, and that it runs as that identity! # Generally, this is accomplished by making sure it is owned by that user. # Permission on all scripts must be 755, files as 666, and listdir as 744. # The image files must NOT be placed in the cgi-bin, but in the web directory! ############################################################################### # # SPAM # Spam SUCKS. It also ROBS everyone it touches, each system it passes through. # Fight spam. DO NOT host open lists all the world may post to. #60 TinyList CANNOT do so as written, PLEASE do not defeat this. # ############################################################################### # # import os, sys, string, cgi # MUST be invoked! # # CONFIGURATION SECTION # ===================== # #70 # NOTE that this script is SUPPOSED to be installed in the web cgi-bin! # and the lists dir is immediately under this dir! # # ok, where am I? I just woke up! fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0])) # # ok, now my config file is supposed to be RIGHT HERE with me! # So let's read the thing! f1=open("tinylist.cf",'r') #80 # Tell me little file, who am I? webdomain=string.strip(f1.readline()) f1.close() # # knowing where I am, I know that my lists are ONE FLOOR DOWN! path=fullpathtoscript[0] # ALL TinyList scripts MUST live in the web cgi-bin, and # ALL global and list files are directly off the web cgi-bin dir in '/lists'. # that dir should be owned by the same owner and group as this script, and #90 should be chmod 766. DIR 'list' must be 766, with all Scripts 755. # # # # # # # # # data arrives as 'QUERY_STRING'=(listname value) using #100 the GET method, but cgi module handles this nicely, # parsing it out into keywords and vlaues in a dictionary! # footer='



' # close the page, and end it. print "Content-type: text/html\n\n" # HTML is following print '' print '' print 'TinyList membership listing Utility.' print '' print "" print '

' print '


   TinyList

' print '


' # form=cgi.FieldStorage() # recover the form's data, print form,'

' if not (form.has_key("Owner")): print "ERROR: 'owner' field invalid, please click BACK and correct." #120 print footer sys.exit(1) if not (form.has_key("password")): print "ERROR: 'password' field invalid; please click BACK and correct!" print footer sys.exit(1) if not (form.has_key("listname")): print "ERROR: 'listname' field invalid; please click BACK and correct!" print footer sys.exit(1) mylist = form["listname"] # listname, print 'listname='+mylist+'

' myowner = form["Owner"] #130 owner, print 'owner='+myowner+'

' mypassword = form["password"] # and password. print 'password='+mypassword+'

' # f1=open('/lists/' + listname + '.owner','r') # read the (listname).owner file, trueowner=string.srip(f1.readline()) # read the owner id trueword=string.strip(f1.readline()) # read THE PASSWORD f1.close() # Close the file. if myowner == trueowner : # if the owner matches up, test the password; if mypassword==trueword: # if the password also matches, f1=open('/lists/'+ mylist,'r') #140proceed to access the member roster. members=f1.readlines() # read them in, f1.close # and close the file. for i in members: # print i + '
' else: print 'Sorry, wrong password.' else: print 'Sorry, wrong owner id.' # # # # ns# ns# -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 1 05:45:38 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 01 Sep 2002 00:45:38 -0400 Subject: [Tutor] returning to my memberlister script Message-ID: <3D719B72.2D81D44F@netzero.net> Well, Iwent into the form script, and changed the method from Get to Post. NO DIFFERENCE IN RESULTS WHATSOEVER. It is 12:44 am EDST, and I am tired. Goodnight. Feel free to email, I will work on this more tomorrow evening. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 1 06:35:04 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 01 Sep 2002 01:35:04 -0400 Subject: [Tutor] returning to my memberlister script Message-ID: <3D71A708.7CD35BEB@netzero.net> Making progress, although I still do not understand why it did not work before when I used the x=foo.value method. got it talking to the thing, and almost working. Got a slight problem with it barking about formatting output and such, but that's for tomorrow to wrestle with, me tired. ZZZZzzzz..... -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 1 06:42:46 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 01 Sep 2002 01:42:46 -0400 Subject: [Tutor] returning to my memberlister script Message-ID: <3D71A8D6.13F26A74@netzero.net> Well, I stayed up a little longer. Here it is: http://www.tinylist.org/cgi-bin/TLmemberlister.py owner: idiot1@netzero.net pw:fubar listname:testlist3 All these subscribers are non existant except for me. worthless computers is a friends, and he agreed to never have such a identity so I can test how bad addressses outside the LAN perform. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From magnus@thinkware.se Sun Sep 1 07:05:04 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 01 Sep 2002 08:05:04 +0200 Subject: [Tutor] Re: q about method(self) In-Reply-To: References: <45388CCA-BCF0-11D6-9B69-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020901080019.02a15cf8@www.thinkware.se> At 09:28 2002-08-31 -0700, Emile van Sebille wrote: >Erik: > > > instance_reference.method(args) > > > > I didn't realize that until just now. But what I'm wondering is, > > why/when would you want to use this form? > >Normally, you probably wouldn't. Certainly with inheritence. For instance: class A: def __init__(self, name): self.name =3D name class B(A): def __init__(self, name, address): A.__init__(self, name) self.address This is a silly, simplistic example of cource, but there are certainly a lot of cases where subclasses want to call methods in superclasses. Very recent python versions has "super()" but so maybe this use won't be as common in the future. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sun Sep 1 07:09:10 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 01 Sep 2002 08:09:10 +0200 Subject: [Tutor] q about method(self) In-Reply-To: <45388CCA-BCF0-11D6-9B69-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020901080823.02a2d950@www.thinkware.se> At 10:45 2002-08-31 -0400, Erik Price wrote: >One other quickie question -- not that I would ever need to do this, but=20 >could a different identifier other than "self" ever be used? (such as=20 >"this") It -appears- that "self" is just a reference within a class, but= =20 >perhaps there's magic going on that I don't know about. No magic. You are free to confuse yourself and your fellow programmers if you wish. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sun Sep 1 07:17:15 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 01 Sep 2002 08:17:15 +0200 Subject: [Tutor] help required In-Reply-To: Message-ID: <5.1.0.14.0.20020901080941.02a36f40@www.thinkware.se> At 16:31 2002-08-31 +0100, hotmail wrote: >i was wondering if it is possible to make a gui for python programs to=20 >make the use of them easier and also i was wondering if it si possible to= =20 >out put images as well as text in programs. Certainly. See: http://www.thinkware.se/cgi-bin/thinki.cgi/PythonGuis http://www.wxpython.org/ http://www.pythonware.com/library/an-introduction-to-tkinter.htm --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sun Sep 1 07:34:30 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 01 Sep 2002 08:34:30 +0200 Subject: [Tutor] importing variable contents, and variable naming problms In-Reply-To: <20020831124958.753233ac.thomi@thomi.imail.net.nz> References: <5.1.0.14.0.20020830105519.02b69bc0@www.thinkware.se> <20020830195452.45774dff.thomi@thomi.imail.net.nz> <5.1.0.14.0.20020830105519.02b69bc0@www.thinkware.se> Message-ID: <5.1.0.14.0.20020901074755.02a012c0@www.thinkware.se> At 12:49 2002-08-31 +1200, Thomi Richards wrote: >ok, I'll explain.. I have a program, which has a directory under it >called species/. under this dir the END USER creates some modules, which >define the species behavior. however, i don't know what they are going >to call their species, they could call it 'lion', or they could call it >'blahblahlongname', however, no matter what it is called, i need to >import it. using os.listdir, i can add the correct directories to the >sys.path list, but i now need to import the species/lion/lion.py file. >of course, i don't know that it will be called 'lion.py' before the >program starts , so i cannot hard code this in.. does that make any >sense?? Sure. But you know the contents of each module, right? I.e. what variables, classes, functions etc it contains? You have two big problems, name-clashes and incorporating unpredictable variable names. You don't want any of that. And what happens if someone would create a species called sys, os or sockets? I think you need to use some kind of prefix to your filenames to be certain--even if you avoid all other name clashes. Then you place all your modules in a list or dict. Untested code follows: import os directory =3D '/some/path/' prefix =3D 'species_' moduleNames =3D [fileName for fileName in os.listdir(directory) if fileName.startswith(prefix)] speciesModules =3D {} for modName in moduleNames: speciesName =3D modName[len(prefix):] exec("import %s as speciesModules[%s]" % (modName, speciesName)) Now you have a dictionary of modules, keyed by animal name. If they all have the attribute "maxWeight" you can list the max weights in alphabetical order for the species as: speciesNames =3D speciesModules.keys() speciesNames.sort() print "%15s|%8s" % ('Species', 'Weight') for name in speciesNames: print "%15s|%8i" % (name, speciesModules[name].maxWeight) --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From glingl@aon.at Sun Sep 1 08:38:02 2002 From: glingl@aon.at (Gregor Lingl) Date: Sun, 01 Sep 2002 09:38:02 +0200 Subject: [Tutor] q about method(self) References: <45388CCA-BCF0-11D6-9B69-00039351FE6A@mac.com> Message-ID: <3D71C3DA.2060900@aon.at> Erik Price schrieb: > A class method generally takes "self" as its first argument. I had > been wondering for some time why this is, since it seems redundant if > it's there for all class methods. But I just realized -- you can call > an object's method without using dot notation in Python, like this: > > method(instance_reference, args) > > rather than only like this: > > instance_reference.method(args) > > I didn't realize that until just now. But what I'm wondering is, > why/when would you want to use this form? Is it just an aesthetic > thing, or is it something that is required b/c of the way that Python > handles user-defined classes and objects? Or something else? > > One other quickie question -- not that I would ever need to do this, > but could a different identifier other than "self" ever be used? > (such as "this") It -appears- that "self" is just a reference within > a class, but perhaps there's magic going on that I don't know about. > some weeks ago I posted a message, which adresses several aspects of your question. You may find it here: http://mail.python.org/pipermail/tutor/2002-August/016395.html Regards, Gregor > > > Thanks, > > Erik > > > > > > -- > Erik Price > > email: erikprice@mac.com > jabber: erikprice@jabber.org > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > From thomi@thomi.imail.net.nz Sun Sep 1 09:20:14 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Sun, 1 Sep 2002 20:20:14 +1200 Subject: [Tutor] bitmap or not? Message-ID: <20020901202014.4594f71e.thomi@thomi.imail.net.nz> hi yet again:-) I have a series of cells, 256 wide by 256 high. each cell has a "state number", which can range between 0 and 24. I need to read and write these cells very quickly. to start with, the cells are stored in memory, but I'd like to keep them in a 256 colour bitmap file, so that each cell is a pixel, and each colour represents a different colour. Originally i thought of using the python-allegro module being developed at http://pyallegro.sourceforge.net/ but it's not really stable enough for me, or complete enough. Can anyone suggest an alternative?? thanks. -- "Avoid the Gates of Hell. Use Linux" Thomi Richards, thomi@imail.net.nz From slime@vsnl.net Sun Sep 1 10:50:19 2002 From: slime@vsnl.net (Prahlad Vaidyanathan) Date: Sun, 1 Sep 2002 15:20:19 +0530 Subject: [Tutor] Re: A simple RPN calculator In-Reply-To: <200208280650.39225.scot@possum.in-berlin.de> References: <200208280650.39225.scot@possum.in-berlin.de> Message-ID: <20020901095019.GA1179@localhost.localdomain> Hi, On Wed, 28 Aug 2002 Scot W. Stevenson spewed into the ether: > Hello there, > > I had started a thread about Reverse Polish Notation calculators a while > ago, and Gregor actually wrote one, and I did that smart-ass thing of > coming back and saying, hey, really neat, Gregor, but how about the > following functions...So I guess I owe him some code =8). Well, I just thought I'd implement one myself, using a couple of stacks, so here it is : http://www.symonds.net/~prahladv/files/rpn_calc.py This also requires this module : http://www.symonds.net/~prahladv/files/stack.py HTH, pv. -- Prahlad Vaidyanathan Ducks? What ducks?? From erikprice@mac.com Sun Sep 1 15:31:02 2002 From: erikprice@mac.com (Erik Price) Date: Sun, 1 Sep 2002 10:31:02 -0400 Subject: Python for RAD (was: [Tutor] Re: q about method(self)) In-Reply-To: Message-ID: <711233DC-BDB7-11D6-8A4A-00039351FE6A@mac.com> On Saturday, August 31, 2002, at 12:28 PM, Emile van Sebille wrote: > ISTM that when you > get to the point of having a class method that turns out to be more > useful > as a function, you'd want to refactor it that way. In regards to this very notion, I have had a question burning in the back of my mind for a few weeks now: Many people prefer Python over a language such as Java because you are not forced to use the OO methodology, and in many cases (especially smaller scripts) this lets you write your program more quickly. For instance, it's much easier IMHO to write a function to do some work than it is to incorporate a special class into the design of the program overall (thus possibly changing the entire design) simply to provide this feature. Similarly useful features of Python are the dynamic typing and the fact that vars don't need to be predeclared. Yet, at the same time Python is often described as a useful environment for rapid application design, so that a model can be tested quickly without dealing with these sorts of inconveniences, even though in the end the final application will be implemented in one of the more cumbersome languages. I've never done anything like write a program in a scripting language to test a design model which is to be later implemented in another language. I've never even seen code like this, either. So here is my question: If you are eventually planning to migrate code to, say Java (since that is the only other OO language I am familiar with), is it unwise to take the easier route of writing functions to do some work that would normally be implemented [more tediously] using a class? I would think so, since this would violate the very thing which is being tested -- the design/model of the application. Obviously the design should have accounted for the need for this feature and there should be a class to represent it (or it should be handled somehow without the need for a separate function, since this won't be possible in the final implementation language [Java]). At least, that is what I would assume. But if you're staying within the Python language then a pure object-oriented methodology of using only classes might be more trouble than it's worth, it would seem. Thank you, Erik PS: I know that there are some strong feelings about different methodologies (including one guy on Slashdot who apparently devotes his life to combating the popularity of OO: http://slashdot.org/~tablizer) and languages so I'm not trying to be controversial. Rather, I am asking as someone who is studying Java in addition to Python so the "pure" OO methodology is something that I have to consider in my designs. -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From erikprice@mac.com Sun Sep 1 15:39:57 2002 From: erikprice@mac.com (Erik Price) Date: Sun, 1 Sep 2002 10:39:57 -0400 Subject: Iterators (was: Re: [Tutor] text module) In-Reply-To: <20020901005656.GA5950@micromuse.com> Message-ID: On Saturday, August 31, 2002, at 08:56 PM, Ibraheem Umaru-Mohammed wrote: > A good article on iterators and generators is: > > ,---- [ url ] > | > http://www-106.ibm.com/developerworks/library/l- > pycon.html?t=gr,lnxw10=PyIntro > `---- Thanks Ibz, I will read that article. > I haven't played much with iterators myself, nor simple generators, > but the code > below might help, as it is an example that uses both the __iter__() > and next() methods > required of user-defined classes that adhere to the iterator protocol. "iterator protocol" makes me wonder if iterators are found in other programming languages other than Python. Obviously it wouldn't use the double-underscore convention for the method to be subclassed, but is this something that's found in C++, Java, or Obj-C (etc)? Thank you, Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From pobrien@orbtech.com Sun Sep 1 16:01:20 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Sun, 1 Sep 2002 10:01:20 -0500 Subject: Python for RAD (was: [Tutor] Re: q about method(self)) In-Reply-To: <711233DC-BDB7-11D6-8A4A-00039351FE6A@mac.com> Message-ID: [Erik Price] > > I've never done anything like write a program in a scripting language > to test a design model which is to be later implemented in another > language. I've never even seen code like this, either. So here is my > question: If you are eventually planning to migrate code to, say Java > (since that is the only other OO language I am familiar with), is it > unwise to take the easier route of writing functions to do some work > that would normally be implemented [more tediously] using a class? > > I would think so, since this would violate the very thing which is > being tested -- the design/model of the application. Obviously the > design should have accounted for the need for this feature and there > should be a class to represent it (or it should be handled somehow > without the need for a separate function, since this won't be possible > in the final implementation language [Java]). At least, that is what I > would assume. > > But if you're staying within the Python language then a pure > object-oriented methodology of using only classes might be more trouble > than it's worth, it would seem. Fortunately, Python makes it easy to take either of these paths. Defining all actions as methods instead of functions only requires a trivial amount of extra code. So the overhead in Python is minimal. Here is a (necessarily oversimplified) example of something coded as both a function and then as a method of a class: >>> def p(text): ... return '

%s

' % text ... >>> p("This is a paragraph.") '

This is a paragraph.

' >>> class Html: ... def p(self, text): ... return '

%s

' % text ... >>> html = Html() >>> html.p("This is another paragraph.") '

This is another paragraph.

' >>> >From a pure design point of view, I actually think Python's use of functions and modules is a more practical reflection of reality than forcing everything to be a method of a class. It also does a better job of supporting code reuse. One way to look at this is to see a function as a kind of method that has no need for any state associated with its own class instance, and therefore should be able to stand on its own. A function doesn't have a compelling *need* to *be* a method. If it did, then it should be coded as a method. Forcing it to be a method of a class is easy enough to do in Python, it just doesn't buy you anything if there is no need. But if you know that this is a prototype for another language, then I would go ahead and code it as a method in Python as well. That way you'll get the experience of actually using the code as a method call, rather than a function call, and you'll get a better sense of whether the organization of these function/method hybrids is elegant and useful. Hope that helps. -- Patrick K. O'Brien Orbtech ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- Web: http://www.orbtech.com/web/pobrien/ Blog: http://www.orbtech.com/blog/pobrien/ Wiki: http://www.orbtech.com/wiki/PatrickOBrien ----------------------------------------------- From erikprice@mac.com Sun Sep 1 16:17:44 2002 From: erikprice@mac.com (Erik Price) Date: Sun, 1 Sep 2002 11:17:44 -0400 Subject: Python for RAD (was: [Tutor] Re: q about method(self)) In-Reply-To: Message-ID: On Sunday, September 1, 2002, at 11:01 AM, Patrick K. O'Brien wrote: > From a pure design point of view, I actually think Python's use of > functions > and modules is a more practical reflection of reality than forcing > everything to be a method of a class. Agreed. The alternative could be to write a class with a static method that does the same thing (or a class with a couple of static methods called "UtilityClass" or something), but like you said -- a function definition is more straightforward and practical. > But if you know that this is a prototype for another language, then I > would > go ahead and code it as a method in Python as well. That way you'll > get the > experience of actually using the code as a method call, rather than a > function call, and you'll get a better sense of whether the > organization of > these function/method hybrids is elegant and useful. That's what I was thinking too. Thanks for responding, I hope that anyone else who has used python for prototyping for another language (especially an OO language like Java) will comment as well. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From emile@fenx.com Sun Sep 1 16:20:11 2002 From: emile@fenx.com (Emile van Sebille) Date: Sun, 1 Sep 2002 08:20:11 -0700 Subject: [Tutor] Re: Python for RAD (was: Re: q about method(self)) References: Message-ID: Erik: > That's what I was thinking too. Thanks for responding, I hope that > anyone else who has used python for prototyping for another language > (especially an OO language like Java) will comment as well. > I'd like to know as well if python is actually being used this way. I half expect that this notion of 'python as prototyping tool' is a myth designed to get python into the 'approved language only' shops. Once the 'prototype' is written in a fraction of the time and shown to perform acceptably well, no re-write is performed and python becomes accepted. Emile van Sebille emile@fenx.com From pobrien@orbtech.com Sun Sep 1 16:31:40 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Sun, 1 Sep 2002 10:31:40 -0500 Subject: [Tutor] Re: Python for RAD (was: Re: q about method(self)) In-Reply-To: Message-ID: [Emile van Sebille] > > Erik: > > That's what I was thinking too. Thanks for responding, I hope that > > anyone else who has used python for prototyping for another language > > (especially an OO language like Java) will comment as well. > > > > I'd like to know as well if python is actually being used this > way. I half > expect that this notion of 'python as prototyping tool' is a myth designed > to get python into the 'approved language only' shops. Once the > 'prototype' > is written in a fraction of the time and shown to perform acceptably well, > no re-write is performed and python becomes accepted. Ssssssshhhhhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!! -- Patrick K. O'Brien Orbtech ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- Web: http://www.orbtech.com/web/pobrien/ Blog: http://www.orbtech.com/blog/pobrien/ Wiki: http://www.orbtech.com/wiki/PatrickOBrien ----------------------------------------------- From lists@shrestha.net.np Sun Sep 1 17:39:21 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Sun, 01 Sep 2002 22:24:21 +0545 Subject: Python for RAD (was: [Tutor] Re: q about method(self)) References: Message-ID: <3D7242B9.3070503@shrestha.net.np> we use jython to "prototype" our java apps. actually we start writing the apps in jython and then look at the parts that need to be "optimised" and move that part to java. when you actually write and test it the portion we need to move to java is like 5 to 10 percent. we once wrote an xmlrpc client server in jython using the xmlrpc library from pythonware. just for measuring performance we rewrote the jython app to use the apache xmlrpc library in java (not as compact and easy as in pure python). sure there were quite a difference. server client timing in milliseconds python python 22362 java python 5837 python java 3209 java java 681 java = apache xmlrpc library python = pythonware xmlrpc library well looks quite an improvement. guess what! we didn't really bother to move the one that we had deployed at the client's system to java. it was good enough for them. frankly, we prototype in jython and then it is usually good enough to be deployed. ashish shrestha http://www.nyatapol.com.np jid: axhixh@jabber.org blog: http://axhixh.blogspot.com From dyoo@hkn.eecs.berkeley.edu Sun Sep 1 21:49:49 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 1 Sep 2002 13:49:49 -0700 (PDT) Subject: [Tutor] returning to my memberlister script In-Reply-To: <3D7186C2.19A0A185@netzero.net> Message-ID: On Sat, 31 Aug 2002, Kirk Bailey wrote: > OK, this is getting frustrating. I am reading the actual source text for > cgi.py, and sure enough, the damn thing returns a dictionary. This > script should be working, and it howls like a wolf with a full moon. > Which means I am doing something wrong, but I am not catching it. Anyone > want to look at this and adjust my headspace and timing please? This > apprentice requests correction. Hi Kirk, Let's look at the error message and see if it can give us clues as to what's going on: > > SyntaxError: invalid syntax > > [Thu Aug 29 00:26:38 2002] [error] [client 63.208.207.252] Premature end of script headers: /www/www.tinylist.org/cgi-bin/TLmemberlister.py > > Traceback (innermost last): > > File "/www/www.tinylist.org/cgi-bin/TLmemberlister.py", line 126, in ? > > print 'listname='+mylist+'

' > > TypeError: __add__ nor __radd__ defined for these operands Hmmm... It looks like the statement: print 'listname='+mylist+'

' has a bug in it; Python is complaining that something on this line doesn't like to be added together. My assumption right now is that 'mylist' is not a string: that's the only thing I can think of that will cause Python to make that TypeError complaint. What is 'mylist'? mylist = form["listname"] # listname, Ah! This needs to be replaced with: mylist = form['listname'].value The reason is because the FieldStorage object isn't quite a dictionary: although it provides a dictionary-like interface, we need to go through an extra step to get the 'value' of a parameter. Why is FieldStorage designed in this way? Isn't it horribly indirect? Yes, but that's because the values returned by FieldStorage are a bit chunky: we can get either a single value, multiple values, or even a file-like object! Think of uploading a huge file in a CGI script: if someone sends us a HUGE file, we may want to read through it a line at a time, rather than all at once. The FieldStorage module allows us to check for this situation like this: ### if form['data'].file: f = form['data'].file for line in f.xreadlines(): ... ### We may want to be able to detect these different situations, so that's why there's a bit of indirectness in the FieldStorage object. The documentation does try to explain this, but it takes a while to see what it's actually talking about. *grin* See: http://www.python.org/doc/lib/node295.html for more details. Good luck! From dyoo@hkn.eecs.berkeley.edu Sun Sep 1 22:04:38 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 1 Sep 2002 14:04:38 -0700 (PDT) Subject: Iterators (was: Re: [Tutor] text module) In-Reply-To: Message-ID: On Sun, 1 Sep 2002, Erik Price wrote: > "iterator protocol" makes me wonder if iterators are found in other > programming languages other than Python. Obviously it wouldn't use the > double-underscore convention for the method to be subclassed, but is > this something that's found in C++, Java, or Obj-C (etc)? Java does have an Iterator protocol, but it's somewhat clunky. If you're really interested, take a look at: http://developer.java.sun.com/developer/onlineTraining/collections/index.html (In Java, using an iterator is considered an advanced topic. *cough*) Python's for loop is nice because it handles the iteration concept for us: ### names = ['demonthenes', 'locke', 'antigone', 'socrates', 'plato'] for n in names: print n ### Java, on the other hand, has no explicit support for the interface; and all things need be done explicitely, using the methods of the Iteration interface: /*** Java ***/ // assume that 'import java.util.*;' has been written. List names = new List(Arrays.asList (new String[] { "demonthenes", "locke", "antigone", "socrates", "plato" })); Iterator iter = names.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } /******/ (I have not tested the above code; I hope I haven't made a typo!) So, in Java, using the Iterator concept involves a little bit more work: the idea is the same, but the execution is just a bit... well, it just seems like explicit array indicing would be easier. *grin* Hope this helps! From iumarumo@eidosnet.co.uk Sun Sep 1 22:41:06 2002 From: iumarumo@eidosnet.co.uk (Ibraheem Umaru-Mohammed) Date: Sun, 1 Sep 2002 22:41:06 +0100 Subject: Iterators (was: Re: [Tutor] text module) In-Reply-To: References: <20020901005656.GA5950@micromuse.com> Message-ID: <20020901214106.GC5950@micromuse.com> ["Erik Price"="Erik"] Erik >> On Saturday, August 31, 2002, at 08:56 PM, Ibraheem Umaru-Mohammed Erik >> wrote: Erik >> Erik >> >A good article on iterators and generators is: Erik >> > Erik >> > ,---- [ url ] Erik >> > | Erik >> >http://www-106.ibm.com/developerworks/library/l- Erik >> >pycon.html?t=gr,lnxw10=PyIntro Erik >> > `---- Erik >> Erik >> Thanks Ibz, I will read that article. Erik >> Erik >> >I haven't played much with iterators myself, nor simple generators, Erik >> >but the code Erik >> >below might help, as it is an example that uses both the __iter__() Erik >> >and next() methods Erik >> >required of user-defined classes that adhere to the iterator protocol. Erik >> Erik >> "iterator protocol" makes me wonder if iterators are found in other Erik >> programming languages other than Python. Obviously it wouldn't use the Erik >> double-underscore convention for the method to be subclassed, but is Erik >> this something that's found in C++, Java, or Obj-C (etc)? Erik >> Iterators are definitely found in languages outside of python. From my understanding of iterators, they are fundamentally extensions of the basic looping constructs that operate on sequences (e.g for, while, repeat, until etc), in order to operate on arbitrary objects that adhere to the protocol. C++, Java, Smalltalk, Ruby for example have iterators... Having played with Ruby recently, I have realised that the way Ruby objects do iteration is very different to the way Python does it. In Ruby, you can quite comfortable code away without having to use for, while or other looping constructs because the objects themselves provide multiple iterable methods. For example, you could do this in Ruby: ,-----[ Ruby loop ] | 0.upto(9) { |i| puts i } `--- which would be the equivalent of the following in python: ¸------[ Python loop ] | for i in xrange(10): | print i `--- You can see that the loop is passed "in" to the iterator object in Ruby, whereas in Python, the iterator (xrange) passes objects to the looping construct. In fact, I think the "each" method is equivalent to a "for" loop in Ruby. For example, ¸------[ Ruby loop ] | (0..9).each { |i| puts i } `--- Basically, the block passed to the iterator object in Ruby cannot end the loop, only the iterator itself can end the loop. That is, there is no way to break out of the iteration from within the block. I think the same rule applies in Python, in that iterators either return the next item when called upon, or raise StopIteration when there are no more items to return. There is no other clean way to break out of the iteration. Hope that helps a little. Kindest regards, --ibz. -- Ibraheem Umaru-Mohammed "ibz" umarumohammed (at) btinternet (dot) com From glingl@aon.at Sun Sep 1 23:01:29 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 02 Sep 2002 00:01:29 +0200 Subject: [Tutor] Help concerning raw_input urgently needed! References: <20020901005656.GA5950@micromuse.com> <20020901214106.GC5950@micromuse.com> Message-ID: <3D728E39.9010204@aon.at> Some ten days ago I posted the following to idle-dev, but the message went into a wrong thread and was consequently ignored. So I try it again, this time also at tutor. Several colleagues asked me already, why this Error occurs - I still can only reply: I don't know. By the way: does this Error also occur when working with IDLE on a Linux-machine? (Aren't there people with happy little Linux-Systems in Berlin, who could check this easily?) -------------- Some month ago I copied sitecustomize.py with appropriate locale-setting to C:\Python22\Lib thanks to an advice of someone on this list. This worked well until today I made the observation, that raw_input doesn't work correctly: >>> a = raw_input("Hä? ") Hä? Tschüs Traceback (most recent call last): File "", line 1, in ? a = raw_input("Hä? ") TypeError: object.readline() returned non-string >>> Consequently I cannot execute programs with raw_input from IDLE, if the expected answers (inputs) may contain "Umlaute". Those same programs, however, can be executed from the commandline. And also the interactive Python interpreter can execute raw_input statements even when Umlaute are input. So I think, this must be a problem of IDLE. I must confess, I do not understand the error message. Hope this can be corrected somehow. Thanks Gregor Lingl From kyle@sent.com Sun Sep 1 23:51:20 2002 From: kyle@sent.com (Kyle Babich) Date: Sun, 1 Sep 2002 22:51:20 UT Subject: [Tutor] Help concerning raw_input urgently needed! Message-ID: <20020901225120.D9FA19370B@server2.fastmail.fm> On Mon, 02 Sep 2002 00:01:29 +0200, "Gregor Lingl" said: > Some ten days ago I posted the following to idle-dev, but > the message went into a wrong thread and was consequently > ignored. So I try it again, this time also at tutor. Several colleagues > asked me already, why this Error occurs - I still can only reply: > I don't know. > By the way: does this Error also occur when working with IDLE on > a Linux-machine? (Aren't there people with happy little Linux-Systems > in Berlin, who could check this easily?) > -------------- >=20 > Some month ago I copied sitecustomize.py with > appropriate locale-setting to C:\Python22\Lib > thanks to an advice of someone on this list. >=20 > This worked well until today I made the observation, > that raw_input doesn't work correctly: >=20 > >>> a =3D raw_input("H=E4? ") > H=E4? Tsch=FCs > Traceback (most recent call last): > File "", line 1, in ? > a =3D raw_input("H=E4? ") > TypeError: object.readline() returned non-string > >>> >=20 The program expects the raw_input to return a string, but Tsch=FCs according to python doesn't qualify. >>> type("Tsch=FCs") UnicodeError: ASCII encoding error: ordinal not in range(128) A better idea might be to use sys.stdin.readline(). >>> import sys >>> a =3D sys.stdin.readline() Tsch=FCs >>> print a Tsch=FCs > Consequently I cannot execute programs with > raw_input from IDLE, if the expected answers (inputs) > may contain "Umlaute". Those same programs, > however, can be executed from the commandline. > And also the interactive Python interpreter can execute > raw_input statements even when Umlaute are input. >=20 > So I think, this must be a problem of IDLE. > I must confess, I do not understand the error message. >=20 > Hope this can be corrected somehow. > Thanks >=20 > Gregor Lingl >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor >=20 From guillermo.fernandez@epfl.ch Mon Sep 2 01:06:21 2002 From: guillermo.fernandez@epfl.ch (Guillermo Fernandez) Date: Mon, 02 Sep 2002 09:36:21 +0930 Subject: [Tutor] Help concerning raw_input urgently needed! References: <20020901005656.GA5950@micromuse.com> <20020901214106.GC5950@micromuse.com> <3D728E39.9010204@aon.at> Message-ID: <3D72AB7D.12847680@epfl.ch> > Some month ago I copied sitecustomize.py with > appropriate locale-setting to C:\Python22\Lib > thanks to an advice of someone on this list. > = > This worked well until today I made the observation, > that raw_input doesn't work correctly: > = > >>> a =3D raw_input("H=E4? ") > H=E4? Tsch=FCs > Traceback (most recent call last): > File "", line 1, in ? > a =3D raw_input("H=E4? ") > TypeError: object.readline() returned non-string > >>> > By the way: does this Error also occur when working with IDLE on > a Linux-machine? (Aren't there people with happy little Linux-Systems > in Berlin, who could check this easily?) I'm in Australia, not in Berlin, but hope this helps :-) I'm using linux SuSE 7.3 with Python 2.2 and this is the result: >>> a =3D raw_input("H=E4? ") UnicodeError: ASCII encoding error: ordinal not in range(128) >>> = >>> Regards, Guille From erikprice@mac.com Mon Sep 2 04:49:17 2002 From: erikprice@mac.com (Erik Price) Date: Sun, 1 Sep 2002 23:49:17 -0400 Subject: Iterators (was: Re: [Tutor] text module) In-Reply-To: Message-ID: On Sunday, September 1, 2002, at 05:04 PM, Danny Yoo wrote: > Java, on the other hand, has no explicit support for the interface; and > all things need be done explicitely, using the methods of the Iteration > interface: > > /*** Java ***/ > // assume that 'import java.util.*;' has been written. > > List names = new List(Arrays.asList > (new String[] { "demonthenes", > "locke", > "antigone", > "socrates", > "plato" })); > Iterator iter = names.iterator(); > while (iter.hasNext()) { > System.out.println(iter.next()); > } > /******/ I see -- so you first take an array of strings, and transform it into a List (with Arrays.asList()). Then you use the iterator() method [of List?] to instantiate an Iterator object, and you use this Iterator object's hasNext() and next() methods to do the work. Interesting. Although it's certainly more work than in Python, it does seem a little bit more straightforward. This is probably just because you are forced to look at the implementation, whereas in Python I can't really see the difference between using iterators and a simple for loop. Thanks for this comparison, Danny. Erik PS: thanks for the correction too! -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From hsteiger@comcast.net Mon Sep 2 07:10:03 2002 From: hsteiger@comcast.net (Henry Steigerwaldt) Date: Mon, 02 Sep 2002 01:10:03 -0500 Subject: [Tutor] Displaying .GIF file on a canvas Message-ID: <000801c25247$614f7c70$0201a8c0@eagle> This is a multi-part message in MIME format. --Boundary_(ID_S58WlvxoZciU2hQLq9cQqg) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT To All: Can anyone tell me what is wrong with this code? I am simply trying to display a .GIF file on a canvas. The canvas is placed on a toplevel window (root). No errors occur, but yet the .GIF file never appears on the canvas. I have played around with this thing for probably 30 minutes or longer without any success. Below is the code snipet: _________________________________ root = Tk() root.geometry('1024x768+125+100') canvas = Canvas(root, width=950, height=700) img = PhotoImage(file = '\\python_pgms\\plot_guidance\\guid_map.gif') canvas.create_image(600,400, image=img, anchor=CENTER) canvas.pack() ______________________ Thanks for any help provided. Henry Steigerwaldt Hermitage, TN --Boundary_(ID_S58WlvxoZciU2hQLq9cQqg) Content-type: text/html; charset=iso-8859-1 Content-transfer-encoding: 7BIT

To All:
 
Can anyone tell me what is wrong with this code? I am
simply trying to display a .GIF file on a canvas. The canvas
is placed on a toplevel window (root). 
 
No errors occur, but yet the .GIF file never appears on the
canvas.
 
I have played around with this thing for probably 30
minutes or longer without any success.
 
Below is the code snipet:
_________________________________

root = Tk()

root.geometry('1024x768+125+100')

canvas = Canvas(root, width=950, height=700)

img = PhotoImage(file = '\\python_pgms\\plot_guidance\\guid_map.gif')

canvas.create_image(600,400, image=img, anchor=CENTER)

canvas.pack()

______________________

Thanks for any help provided.

Henry Steigerwaldt

Hermitage, TN

 

--Boundary_(ID_S58WlvxoZciU2hQLq9cQqg)-- From glingl@aon.at Mon Sep 2 07:54:32 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 02 Sep 2002 08:54:32 +0200 Subject: [Tutor] Help concerning raw_input urgently needed! References: <20020901225120.D9FA19370B@server2.fastmail.fm> Message-ID: <3D730B28.4030402@aon.at> Kyle Babich schrieb: >On Mon, 02 Sep 2002 00:01:29 +0200, "Gregor Lingl" >said: > > >>... >>Some month ago I copied sitecustomize.py with >>appropriate locale-setting to C:\Python22\Lib >>thanks to an advice of someone on this list. >> >>This worked well until today I made the observation, >>that raw_input doesn't work correctly: >> >> >>> a = raw_input("Hä? ") >>Hä? Tschüs >>Traceback (most recent call last): >> File "", line 1, in ? >> a = raw_input("Hä? ") >>TypeError: object.readline() returned non-string >> >>> >> >> >> > >The program expects the raw_input to return a string, but Tschüs >according to python doesn't qualify. > > > >>>>type("Tschüs") >>>> >>>> >UnicodeError: ASCII encoding error: ordinal not in range(128) > > That's what Python does, if not "sitecustomized". If I put the lines import sys, locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if encoding != "ascii": sys.setdefaultencoding(encoding) into the file sitecustomize.py this is repaired and type("Tschüs") as well as ather output with öäßÜ and so on works well. Nevertheless there remains the fact that - as shown above - raw_input("Hä? ") does write Hä!, does wait for input, but does NOT accept Tschüs as input. Moreover this occurs only within IDLE, not when using the python-interactive-interpreter. >A better idea might be to use sys.stdin.readline(). > > >>>>import sys >>>>a = sys.stdin.readline() >>>> >>>> >Tschüs > > >>>>print a >>>> >>>> >Tschüs > > > This works also on my machine - so it's a possible solution. Nevertheless I'd prefer much if the IDLE-bug could be repaired, e.g. by some other sort of customizing, because in the lessons for beginning programmers, where I use it, the introduction and explanation of sys.stdin.readline() would distract from the main themes covered there. Moreover it doesn't look fine, if - on a very introductory level - you have to learn how to work around bugs. Nevertheless: thanks so far, it constitutes some progress - better this way than no way. With kind regards Gregor P.S.: To have to use something successfully or to have to explain something to others successfully makes a *big* difference. From magnus@thinkware.se Mon Sep 2 09:11:13 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 02 Sep 2002 10:11:13 +0200 Subject: [Tutor] Re: Python for RAD (was: Re: q about method(self)) In-Reply-To: References: Message-ID: <5.1.0.14.0.20020902100551.02b542e8@www.thinkware.se> At 08:20 2002-09-01 -0700, Emile van Sebille wrote: >Erik: > > That's what I was thinking too. Thanks for responding, I hope that > > anyone else who has used python for prototyping for another language > > (especially an OO language like Java) will comment as well. > > > >I'd like to know as well if python is actually being used this way. I half >expect that this notion of 'python as prototyping tool' is a myth designed >to get python into the 'approved language only' shops. Once the= 'prototype' >is written in a fraction of the time and shown to perform acceptably well, >no re-write is performed and python becomes accepted. eShop was written in Python and I think it was rewritten in C++ once Microsoft had bought it. I don't think Greg Stein and his friends had bothered rewiting it if they had kept it. But it was probably better this way. Not because of the C++ code, but because Greg was paid enough by MS to be able to code as much Python as he likes... In general I think it's more common that only bottlenecks are rewritten in C or C++. It's certainly very common that Python is used in systems where several programming languages are used. Typically with C, C++, Java or Fortran. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From scot@possum.in-berlin.de Mon Sep 2 09:06:48 2002 From: scot@possum.in-berlin.de (Scot Stevenson) Date: Mon, 2 Sep 2002 10:06:48 +0200 (CEST) Subject: [Tutor] Java and Python (was: Iterators) In-Reply-To: Message-ID: Hello Danny, > So, in Java, using the Iterator concept involves a little bit more work: > the idea is the same, but the execution is just a bit... well, it just > seems like explicit array indicing would be easier. *grin* With no intention of starting a language war (fat chance with this crowd anyway): I had actually started out to learn Java when I first got the idea it would be fun to start programming again, because - well, basically I believed Sun's sales pitch. I still have the book by Bruce Eckel here that I started to learn the language with. But after about a half a year or so, I gave up [no fault of Bruce's, I really liked his style]. Your cranial capacity may vary, but Java simply doesn't fit my brain, given that programming is not my day job and I can only do it in fits and bursts. And what is worse, Java doesn't seem to /stay/ in my brain for very long (but maybe that's because I don't drink coffee). Python does. Looking at your Java iterator example brought back that "Huh?" feeling that I kept having while trying to learn Java. By now, it is simply beyond me why anybody would bother with the language, unless it's in a Fortranesque we-got-sixty-million-lines-of-the-stuff-that's-why-buddy situation. To me as an amateur, the choices seem clear: If you don't care about speed, use Python, if you do need speed, use C++ or C, and if you need the bytecode, use Jython. Java would seem to be caught between something that rocks and a hard case. Or am I missing something? Again, I am simply not qualified to judge one language above the other, so I'm not running around doing one of those Slashdot "Python is better than Java - so there!" things here. This is just an amateur's personal experience... Y, Scot -- Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany From magnus@thinkware.se Mon Sep 2 09:31:42 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 02 Sep 2002 10:31:42 +0200 Subject: [Tutor] Re: q about method(self) In-Reply-To: <919FDB66-BDB8-11D6-8A4A-00039351FE6A@mac.com> References: <5.1.0.14.0.20020901080019.02a15cf8@www.thinkware.se> Message-ID: <5.1.0.14.0.20020902094521.02b40e00@www.thinkware.se> At 10:39 2002-09-01 -0400, Erik Price wrote: >On Sunday, September 1, 2002, at 02:05 AM, Magnus Lycka wrote: > >>At 09:28 2002-08-31 -0700, Emile van Sebille wrote: >>>Normally, you probably wouldn't. >> >>Certainly with inheritence. For instance: >> >>class A: >> def __init__(self, name): >> self.name = name >> >>class B(A): >> def __init__(self, name, address): >> A.__init__(self, name) ^^^^^^^^^^^^^^^^^^^^^^ >> self.address >> >>This is a silly, simplistic example of cource, but there are >>certainly a lot of cases where subclasses want to call methods >>in superclasses. > >I'm sorry, I should have been more explicit. I meant to say "But what I'm >wondering is, why/when would you want to use the method(inst_ref, args) >form rather than the more traditional inst_ref.method(args) form?" See above. When you are in an instance of one class, and call a method of a base class, i.e. another class this class inherited from. Let's imagine a system with objects where an attribute is automatically updated with a timestamp and a user identity whenever an attribute is changed. *Some* objects also have a policy that only the owner of the object must change it. ... class ChangeLoggedObjects: def __setattr__(self, attr, value): self.__dict__['changeTimeStamp'] = time.time() self.__dict__['changedBy'] = getCurrentUser() self.__dict__['attr'] = value ... class ChangeRestrictedObjects(ChangeLoggedObjects): def __setattr__(self, attr, value): if getCurrentUser() != self.owner: raise PermissionError ChangeLoggedObjects.__setattr__(self, attr, value) If ChangeRestrictedObjects.__setattr__ wouldn't call ChangeLoggedObjects.__setattr__ you wouldn't update change parameters for change restricted objects. -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Mon Sep 2 10:08:11 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 02 Sep 2002 11:08:11 +0200 Subject: [Tutor] Help concerning raw_input urgently needed! In-Reply-To: <3D730B28.4030402@aon.at> References: <20020901225120.D9FA19370B@server2.fastmail.fm> Message-ID: <5.1.0.14.0.20020902101532.02b438b8@www.thinkware.se> At 08:54 2002-09-02 +0200, Gregor Lingl wrote: >Moreover this occurs only within IDLE, not when using the=20 >python-interactive-interpreter. I think the problem is that Tcl/Tk use Unicode these days, and Python defaults to ISO8859-1. Thus your umlaut is ok for raw_input in python proper. In IDLE, the characters are recieved by Tk, and translated from Unicode. That fails on any non-ASCII value, since these are ambiguous unless a code page is supplied. I've stumbled over similar Unicode/ASCII problems before with IDLE. There has also been bugs previously that made it impossible to enter floats such as "pi =3D 3.14" if the national settings in Windows assumed decimal comma, such as in Swedish settings etc. I didn't get a lot of response reagarding those problems. (That was before IDLE was a "project".) Maybe there were good and simple solutions for these things, but I sure didn't manage to find them, and I didn't manage to get any attention. It's seems the idle-dev mailing list is equally uninterested now. In general I find it difficult to find good information about internationalization and localization issues for Python. Neither in books, on the net, nor in mailing lists. Maybe it would work better if I was fluent in German or Japanese... ;) After all most of those who write in English don't need to worry about it... My advice would be to avoid IDLE. I prefer PythonWin in Windows, and there are several other environments that are better than IDLE in my opinion. I think Tcl/Tk makes life harder for us. In general I also suggest using wxPython rather than Tkinter. One good reason for that is the rapid development and response to bugs from Robin Dunn and others in the wxPython mailing list. wxWindows and wxPython are not without flaws, but they both have dynamic and responsive development communities that work well, and are helpful for all levels of users. I expect there to be a free IDLE killer in the wxPython package eventually. PyCrust is a beginning. I haven't used IDLE or Tkinter a lot in quite some time, so maybe things changed and I didn't notice, but I feel confident in the growth and development of wxPython. I also miss a "Tkinter development community". Fredrik Lundh doesn't count as a community. ;-) In the long run, I guess we will see a unicodification of our entire computer platforms, and hopefully some of these problems will disappear, but it seems we are in a looong phase of transition, and that certainly makes life a bit complicated for us with more the 26 letters. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From thomi@thomi.imail.net.nz Mon Sep 2 13:10:29 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Tue, 3 Sep 2002 00:10:29 +1200 Subject: [Tutor] PIL import module problems Message-ID: <20020903001029.1168fc87.thomi@thomi.imail.net.nz> Hey! I just downloaded the python imaging library module on my debian (sarge) box ('sudo apt-get install python2.2-imaging'). It installed OK, but when i go 'import Image', it says it cannot find the module "Image'. HOWEVER, i am using python2.1. can someone explain why the imaging library for 2.2 will not work with 2.1?? are there features in 2.2 which PIL needs?? I'll download the 2.1 version, but i did find this a little interesting... -- This message was brought to you by one bored guy, with nothing better to do, And the letter Q. Thomi Richards, thomi@imail.net.nz From ajs@ix.netcom.com Mon Sep 2 13:42:27 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 2 Sep 2002 08:42:27 -0400 Subject: [Tutor] Java and Python (was: Iterators) References: Message-ID: <001201c2527e$3295cbf0$9865fea9@arthur> Scot writes - > I had actually started out to learn Java when I first got the idea it would > be fun to start programming again, because Me too. > But after about a half a year or so, I gave up Me too. > And what is worse, Java doesn't seem to /stay/ in my brain > for very long (but maybe that's because I don't drink coffee). Python does. Me too. Though I drink *lots* of coffee. > Looking at your Java iterator example brought back that "Huh?" feeling that > I kept having while trying to learn Java. By now, it is simply beyond me > why anybody would bother with the language, unless it's in a Fortranesque > we-got-sixty-million-lines-of-the-stuff-that's-why-buddy situation. To me > as an amateur, the choices seem clear: If you don't care about speed, use > Python, if you do need speed, use C++ or C, and if you need the bytecode, > use Jython. Java would seem to be caught between something that rocks and a > hard case. Here's where our experience diverges. After learning some Python, I went on to Jython (it was then JPython), and began getting a feel for Java itself, until I was eventually able to write Java code directly. a) I think Java is more accesssible than C, C++. Particularly for someone whose main experience is Python - I think there is less (but still plenty) in Java that feels unfamilair than with C,C++. I *really* don't want to think about memory management issues, for example. b) Writing stuff that runs over the Web is sometimes what one wants. To that extent, at least, Java isn't hype. It seems the best alternative - and it's this aspect of Java that seems to account for its take-off. > Or am I missing something? > > Again, I am simply not qualified to judge one language above the other, so > I'm not running around doing one of those Slashdot "Python is better than > Java - so there!" things here. This is just an amateur's personal > experience... Well, if anything we are warring on Java v. C++. On the other hand, would I love to get a enough of a handle on C, C++ to at least be able to extend Python where that is the best alternative to relieve performance bottlenecks. - and Webization is not an issue. Absolutely. Which is why I am watching the development of Boost Python - hoping that it will become a defacto standard for doing so in Python, and provide something of a roadmap for this kind of effort. Art From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_0027_01C25298.5586CF00 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0028_01C25298.5586CF00" ------=_NextPart_001_0028_01C25298.5586CF00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Morne here again, could someone have a look at this and help me . Just to see if Im on the right track.THANX This is what I want to do . I want to write a program that can read the attached ppp.log file and = give me the following type of report: PPP Log file summary for 5 Jul 2002 ----------------------------------- Jul 5 18:15:01 Connected to internet (IP 155.239.150.146) Jul 5 18:18:08 Closed connection. ( Connect time: 197 secs: 5091 octets = in, 1864 octets out ) ----------------------------------- Successful connections: 5 Failed connections: 2 Total time online: 456 seconds Total data in: 66576 octets Total Data out: 66349 octets The lines in the file that you will use look like this: Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 hisaddr =3D 155.239.150.254 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: 5091 octets in, 1864 octets out Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed HERE IS WHAT I HAVE import string def getStuff(file): ppplist =3D file.readlines() for line in ppplist: closeline =3D 0 error.count =3D 0 second.count =3D 0 connect.count =3D 0 data_out.count =3D 0 data_in.count =3D 0 =20 if string.find("IPCP",line) > 0: connectline =3D split(line) connect.count =3D connect.count + 1 elif string.find("ERROR",line) > 0: error.count =3D error.count + 1 =20 elif string.find("connect time",line) > 0: closeline =3D split(line) print connectline[1],"", connectline[2] =20 seconds.count =3D seconds.count + atoi(closeline[9]) print summary ------=_NextPart_001_0028_01C25298.5586CF00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
 

Hi Morne here again, = could someone have a=20 look at this and help me .
Just to see if Im on the right=20 track.THANX
 
This is what I want to do = .
 
I want to write a program that can read = the=20 attached ppp.log file and give me the
following type of=20 report:


PPP Log file summary for 5 Jul=20 2002
-----------------------------------
Jul  5 18:15:01 = Connected to=20 internet (IP 155.239.150.146)
Jul  5 18:18:08 Closed connection. = (=20 Connect time: 197 secs: 5091 octets in,
1864 octets out=20 )
-----------------------------------
Successful connections: = 5
Failed=20 connections: 2
Total time online: 456 seconds
Total data in: 66576 = octets
Total Data out: 66349 octets
The lines in the file that you will use = look like=20 this:

Jul  5 18:45:31 maxigate ppp[34607]: tun0: IPCP: = myaddr=20 155.239.150.146
hisaddr =3D 155.239.150.254
Jul  5 18:48:48 = maxigate=20 ppp[34607]: tun0: IPCP: Connect time: 197 secs:
5091 octets in, 1864 = octets=20 out
Jul  6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat = script=20 failed

 HERE IS WHAT I=20 HAVE
 
 import string
def=20 getStuff(file):
    ppplist =3D=20 file.readlines()
    for line in=20 ppplist:
        closeline =3D=20 0
        error.count =3D=20 0
        second.count =3D=20 0
        connect.count =3D=20 0
        data_out.count =3D=20 0
        data_in.count =3D=20 0
       
    = if=20 string.find("IPCP",line) > = 0:
       =20 connectline =3D = split(line)
       =20 connect.count =3D connect.count + 1
 
    elif = string.find("ERROR",line)=20 > 0:
       error.count =3D = error.count +=20 1
      
    elif=20 string.find("connect time",line) > = 0:
      =20 closeline =3D split(line)
       print=20 connectline[1],"", = connectline[2]
      =20
       seconds.count =3D seconds.count = +=20 atoi(closeline[9])
 
       = print=20 summary
------=_NextPart_001_0028_01C25298.5586CF00-- ------=_NextPart_000_0027_01C25298.5586CF00 Content-Type: application/octet-stream; name="ppp.log" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ppp.log" Jul 5 18:00:00 maxigate newsyslog[87300]: logfile turned over Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:15:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 40 secs: 0 octets in, 265 octets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: : 1079435 = packets in, 231579 packets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: total 6 bytes/sec, = peak 21 bytes/sec on Fri Jul 5 18:15:40 2002=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:45:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(180) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(103) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(9) state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(103) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(181) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 = hisaddr =3D 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 5 18:46:33 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: Idle timer expired=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerDown: = 155.239.150.146=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Command: maxigate: iface = clear=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = SendTerminateReq(106) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvTerminateAck(106) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerFinish.=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: = 5091 octets in, 1864 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: : 234569 packets in, = 230304 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: total 35 bytes/sec, = peak 815 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Terminate=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerDown=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = SendTerminateReq(180) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: open -> lcp=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = RecvTerminateAck(180) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 228 secs: 6795 octets in, 2567 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: total 41 bytes/sec, = peak 840 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 06:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Chat: Expect timeout=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = hangup=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 43 secs: 0 octets in, 0 octets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: total 0 bytes/sec, = peak 0 bytes/sec on Sat Jul 6 06:30:44 2002=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^MAT^M^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 08:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(182) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(107) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(206) state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(107) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(183) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.26 = hisaddr =3D 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 6 08:31:32 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 ------=_NextPart_000_0027_01C25298.5586CF00-- From rickp@telocity.com Mon Sep 2 14:50:23 2002 From: rickp@telocity.com (Rick Pasotto) Date: Mon, 2 Sep 2002 09:50:23 -0400 Subject: [Tutor] PIL import module problems In-Reply-To: <20020903001029.1168fc87.thomi@thomi.imail.net.nz> References: <20020903001029.1168fc87.thomi@thomi.imail.net.nz> Message-ID: <20020902135023.GC4840@tc.niof.net> On Tue, Sep 03, 2002 at 12:10:29AM +1200, Thomi Richards wrote: > > Hey! > > I just downloaded the python imaging library module on my debian (sarge) > box ('sudo apt-get install python2.2-imaging'). It installed OK, but > when i go 'import Image', it says it cannot find the module "Image'. > HOWEVER, i am using python2.1. > > can someone explain why the imaging library for 2.2 will not work with > 2.1?? are there features in 2.2 which PIL needs?? I'll download the 2.1 > version, but i did find this a little interesting... Because /usr/lib/python2.1/site-packages/PIL is a different directory than /usr/lib/python2.2/site-packages/PIL. Debian is set up so that you can have multiple versions of python on the machine at the same time and then choose which one you want to work with. -- "Every time I try to define a perfectly stable person, I am appalled by the dullness of that person." -- J. D. Griffin Rick Pasotto rickp@telocity.com http://www.niof.net From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_0041_01C2529E.EE7439E0 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0042_01C2529E.EE7439E0" ------=_NextPart_001_0042_01C2529E.EE7439E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Please help Hi Morne here again, could someone have a look at this and help me . Just to see if Im on the right track.THANX This is what I want to do . I want to write a program that can read the attached ppp.log file and = give me the following type of report: PPP Log file summary for 5 Jul 2002 ----------------------------------- Jul 5 18:15:01 Connected to internet (IP 155.239.150.146) Jul 5 18:18:08 Closed connection. ( Connect time: 197 secs: 5091 octets = in, 1864 octets out ) ----------------------------------- Successful connections: 5 Failed connections: 2 Total time online: 456 seconds Total data in: 66576 octets Total Data out: 66349 octets The lines in the file that you will use look like this: Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 hisaddr =3D 155.239.150.254 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: 5091 octets in, 1864 octets out Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed HERE IS WHAT I HAVE import string def getStuff(file): ppplist =3D file.readlines() for line in ppplist: closeline =3D 0 error.count =3D 0 second.count =3D 0 connect.count =3D 0 data_out.count =3D 0 data_in.count =3D 0 =20 if string.find("IPCP",line) > 0: connectline =3D split(line) connect.count =3D connect.count + 1 elif string.find("ERROR",line) > 0: error.count =3D error.count + 1 =20 elif string.find("connect time",line) > 0: closeline =3D split(line) print connectline[1],"", connectline[2] =20 seconds.count =3D seconds.count + atoi(closeline[9]) print summary ------=_NextPart_001_0042_01C2529E.EE7439E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Please help

Hi Morne here again, = could someone=20 have a look at this and help me .
Just to see if Im on the right=20 track.THANX
 
This is what I want to do = .
 
I want to write a program that can read = the=20 attached ppp.log file and give me the
following type of=20 report:


PPP Log file summary for 5 Jul=20 2002
-----------------------------------
Jul  5 18:15:01 = Connected to=20 internet (IP 155.239.150.146)
Jul  5 18:18:08 Closed connection. = (=20 Connect time: 197 secs: 5091 octets in,
1864 octets out=20 )
-----------------------------------
Successful connections: = 5
Failed=20 connections: 2
Total time online: 456 seconds
Total data in: 66576 = octets
Total Data out: 66349 octets
The lines in the file that you will use = look like=20 this:

Jul  5 18:45:31 maxigate ppp[34607]: tun0: IPCP: = myaddr=20 155.239.150.146
hisaddr =3D 155.239.150.254
Jul  5 18:48:48 = maxigate=20 ppp[34607]: tun0: IPCP: Connect time: 197 secs:
5091 octets in, 1864 = octets=20 out
Jul  6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat = script=20 failed

 HERE IS WHAT I=20 HAVE
 
 import string
def=20 getStuff(file):
    ppplist =3D=20 file.readlines()
    for line in=20 ppplist:
        closeline =3D=20 0
        error.count =3D=20 0
        second.count =3D=20 0
        connect.count =3D=20 0
        data_out.count =3D=20 0
        data_in.count =3D=20 0
       
    = if=20 string.find("IPCP",line) > = 0:
       =20 connectline =3D = split(line)
       =20 connect.count =3D connect.count + 1
 
    elif = string.find("ERROR",line)=20 > 0:
       error.count =3D = error.count +=20 1
      
    elif=20 string.find("connect time",line) > = 0:
      =20 closeline =3D split(line)
       print=20 connectline[1],"", = connectline[2]
      =20
       seconds.count =3D seconds.count = +=20 atoi(closeline[9])
 
       = print=20 summary
------=_NextPart_001_0042_01C2529E.EE7439E0-- ------=_NextPart_000_0041_01C2529E.EE7439E0 Content-Type: application/octet-stream; name="ppp.log" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ppp.log" Jul 5 18:00:00 maxigate newsyslog[87300]: logfile turned over Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:15:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 40 secs: 0 octets in, 265 octets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: : 1079435 = packets in, 231579 packets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: total 6 bytes/sec, = peak 21 bytes/sec on Fri Jul 5 18:15:40 2002=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:45:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(180) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(103) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(9) state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(103) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(181) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 = hisaddr =3D 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 5 18:46:33 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: Idle timer expired=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerDown: = 155.239.150.146=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Command: maxigate: iface = clear=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = SendTerminateReq(106) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvTerminateAck(106) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerFinish.=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: = 5091 octets in, 1864 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: : 234569 packets in, = 230304 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: total 35 bytes/sec, = peak 815 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Terminate=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerDown=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = SendTerminateReq(180) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: open -> lcp=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = RecvTerminateAck(180) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 228 secs: 6795 octets in, 2567 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: total 41 bytes/sec, = peak 840 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 06:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Chat: Expect timeout=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = hangup=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 43 secs: 0 octets in, 0 octets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: total 0 bytes/sec, = peak 0 bytes/sec on Sat Jul 6 06:30:44 2002=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^MAT^M^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 08:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(182) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(107) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(206) state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(107) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(183) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.26 = hisaddr =3D 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 6 08:31:32 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 ------=_NextPart_000_0041_01C2529E.EE7439E0-- From pobrien@orbtech.com Mon Sep 2 15:26:08 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Mon, 2 Sep 2002 09:26:08 -0500 Subject: [Idle-dev] Re: [Tutor] Help concerning raw_input urgently needed! In-Reply-To: <5.1.0.14.0.20020902101532.02b438b8@www.thinkware.se> Message-ID: [Magnus Lycka] > > PyCrust is a beginning. Thanks for the plug and the opportunity to jump in here and mention that PyCrust has several non-English users who have helped me make PyCrust international language friendly. The PyCrust that is currently in CVS, and that will ship with the next release of wxPython (version 2.3.3), does support your original example: Welcome To PyCrust 0.7.2 - The Flakiest Python Shell Sponsored by Orbtech - Your source for Python programming expertise. Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. Startup script executed: C:\Code\.pythonrc.py >>> a = raw_input("Hä? ") Hä? Tschüs >>> a 'Tsch\xfcs' >>> print a Tschüs >>> Also, I did *not* need to create a sitecustomize.py file for this to work. That said, IDLE is still getting worked on and hopefully this issue will be addressed. -- Patrick K. O'Brien Orbtech ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- Web: http://www.orbtech.com/web/pobrien/ Blog: http://www.orbtech.com/blog/pobrien/ Wiki: http://www.orbtech.com/wiki/PatrickOBrien ----------------------------------------------- From pobrien@orbtech.com Mon Sep 2 15:30:20 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Mon, 2 Sep 2002 09:30:20 -0500 Subject: [Idle-dev] Re: [Tutor] Help concerning raw_input urgently needed! In-Reply-To: <200209021409.g82E9uZ30689@pcp02138704pcs.reston01.va.comcast.net> Message-ID: [Guido van Rossum] > > Try the IDLE from current CVS. AFAIK the Unicode issues have been > fixed there. I just updated from CVS and gave it a try. :-( Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. GRPC IDLE Fork 0.8.2 >>> a = raw_input("Hä? ") UnicodeError: ASCII encoding error: ordinal not in range(128) -- Patrick K. O'Brien Orbtech ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- Web: http://www.orbtech.com/web/pobrien/ Blog: http://www.orbtech.com/blog/pobrien/ Wiki: http://www.orbtech.com/wiki/PatrickOBrien ----------------------------------------------- From buc40@bemail.org Mon Sep 2 15:54:00 2002 From: buc40@bemail.org (S A) Date: Mon, 2 Sep 2002 07:54:00 -0700 Subject: [Tutor] newbie text parsing question Message-ID: <200209021454.g82Es0T07609@mail15.bigmailbox.com> Try re module. You could use re to search and remove everything before the colon and the colon itself. You can then "slice" the spaces before the data and then save each piece of data to a comma seperated file. This file can easily be imported into a spreadsheet. Good Luck. SA > Ron Nixon tutor@python.org [Tutor] newbie text parsing questionDate: Wed, 28 Aug 2002 08:57:22 -0700 (PDT) > > >Ive got a file that looks like this: > > Case Number: 076-2000 Recall Notification Report: RNR076-2000 > Date Opened: 12/20/2000 Date Closed: 04/20/2001 > Recall Class: 1 Press Release (Y/N): Y > Domestic Est. Number: 02040 M Name: Harper's Country Ham > Imported Product (Y/N): Y Foreign Estab. Number: N/A > City: Clinton State: KY Country: USA > Product: Country Ham > Problem: BACTERIA Description: LISTERIA > Total Pounds Recalled: 10,400 Pounds Recovered: 7,561 > > > >I'd like to be able to read all of the file in a extract the data following the Title and ":" to produce some like this: > >076-2000, RNR076-2000,04/20/2001,04/20/2001,1,Y,02040 M, Harper's Country Ham, etc > >that I can then import into a spreadsheet or database. I found nothing at the Python.org site nor in the Text Processing using Python book. Any ideas? thanks in advance > > > >Ron > > > >--------------------------------- >Do You Yahoo!? >Yahoo! Finance - Get real-time stock quotes ><< msg2.html >> "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From erikprice@mac.com Mon Sep 2 16:10:13 2002 From: erikprice@mac.com (Erik Price) Date: Mon, 2 Sep 2002 11:10:13 -0400 Subject: [Tutor] time-scheduling application Message-ID: <148B35F2-BE86-11D6-A6EB-00039351FE6A@mac.com> I have an idea for a program that I'm considering, and I was wondering if anyone has any suggestions on how to go about one aspect of it. I work in a restaurant, and my boss has lamented the trouble of trying to schedule each shift based on each employee's availability. It's like a jigsaw puzzle, since person A can work on Fridays but not on Wednesdays before 5:00pm, whereas Person B can work any day of the week before 4:00pm, etc. You get the idea. I haven't written out a requirements description yet (I'll probably do that later on tonight), but obviously the crux of the program will be to determine who is available within certain time frames. But I'm wondering if anyone has any advice on this part of the program. It seems like a good idea to make each employee represented by an object, and store the employees' availability within attributes of the Employee object. Methods of the Employee can be used to determine availability, assign shifts, etc. There could also be a Shift object (whose hours are stored as attributes) that represents a given shift (a real-world "shift" is something like "4:45pm to 11:30pm, bartending"). Some employees, for instance, are not qualified to work certain Shifts (i.e. not all waiters can work as bartenders). So the Shift object would have its own information. The part of the program that I'm soliciting advice on, however, is the part that actually determines the availability. Here is some pseudocode: for Shift in WorkDay: for Employee in EmployeeList: if Employee.available(Shift.startTime(), Shift.stopTime()): assign Shift to Employee Obviously this is really crude, but the idea is that a WorkDay is a list or collection of Shift objects, and for each Shift object in that list, check all employees to see if they are available. The methods would be coded to be able to send these messages (so that the Employee.available() method would accept a start time and an end time argument, and determine whether the Employee was able to work for that whole time period). What do you think of this -- I have never written something like this before. Is there a better paradigm that I should be using to think about the relationship between Employees and Shifts? I'd like to use Python for obvious reasons (it's cool), but also because it's cross-platform (my boss uses Windows and I use MacOSX). I will write it as a command-line app, and then if the model works well I may try to come up with a simple GUI wrapper. Even though there are probably shrinkwrapped software packages that do this kind of thing much better than what I could write, I thought that this would be a good exercise. Any thoughts? Thanks, Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From arodrigo@genasys.com Mon Sep 2 17:06:16 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: Mon, 2 Sep 2002 18:06:16 +0200 Subject: [Tutor] Parsing iptables log files Message-ID: <20020902160616.GA16558@onix> Dear tutors, I am a sysadmin fairly new to Python and to programming in general. I have been asked to code a script that, using iptables, tells how long an http request takes to be completed in a cluster enviroment with load balancing and high availability. My data is collected issuing these commands: # iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix "--logtrack-- " --log-tcp-sequence # iptables -A OUTPUT -p tcp -j LOG --log-prefix "--logtrack-- " --log-tcp-sequence # grep "\-\-logtrack\-\-" /var/log/syslog > amaya The script and sample log can be found at: http://www.amayita.com/~amaya/python/ and are not being posted to this list because of their size: amaya@aenima>du * 96K amaya.bz2 8.0K amaya.py I am getting errors I don't fully understand, and I will appreciate any comments. I love python, but I still don't seem to be proficient enough. I also am not sure if I am taking the right approach to this issue. I am using python 2.2. Thanks in advance. -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From alan.gauld@bt.com Mon Sep 2 17:58:44 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Sep 2002 17:58:44 +0100 Subject: Python for RAD (was: [Tutor] Re: q about method(self)) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8CE@mbtlipnt02.btlabs.bt.co.uk> > Yet, at the same time Python is often described as a useful > environment for rapid application design, RAD = Rapid Application Development. Design is a mental process and rarely rapid! :-) > so that a model can be tested quickly > without dealing with these sorts of inconveniences, This is my only use for Python at work. I test out design ideas aimed at Java or C++(and occasionally COBOL!) in Python. If its JAVA it will entail classes - sometimes objects too! If its C++ it could be classes, objects or neither - just like Python! If its COBOL its definitely not OO in any shape or form. > question: If you are eventually planning to migrate code to, > say Java is it unwise to take the easier route of writing > functions to do some work that would normally be implemented > [more tediously] using a class? It depends. The prototyping may be more interested in how an integration technology works (Microsoft COM or CORBA say) than in prototyping the structure of the design. So writing a few quick n' dirty functions to create a COM interface and communicatecwith it, examining return values is all you need - I sometimes get all I need from the >>> prompt.... If you want to compare class heirarchies - flat vv wide etc - then obviously you use the proposed designs for the low level language. Its not usual (for me at least) to implement a whole Java application in Python, its usually just the tricky bits I'm interested in. > I would think so, since this would violate the very thing which is > being tested -- the design/model of the application. If thats what you are prototyping. But IME its more likely to be a mechanism used in the design - a technoique for storing data - dictionary vv file vv array etc. Or an integration technique. Or maybe a foreign object model - like an XML DOM say. You can play with these ideas in Python till you understand how they really work then tackle the much more time consuming Java/C++ code with confidence. > PS: I know that there are some strong feelings about different > methodologies (including one guy on Slashdot who apparently > devotes his life to combating the popularity of OO: Anyone who can't argue both for and against any concept doesn't really understand it! OO is great for some things. FP is good for others. Hardcore assembler is best for still others. The mark of a true craftsman is knowing how to use a variety of tools - and when to use which.... Alan g. Author of the 'Learning to Program' web site http://www.freenetpages.co.uk/hp/alan.gauld From alan.gauld@bt.com Mon Sep 2 18:07:31 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Sep 2002 18:07:31 +0100 Subject: [Tutor] Re: Python for RAD (was: Re: q about method(self)) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8CF@mbtlipnt02.btlabs.bt.co.uk> > I'd like to know as well if python is actually being used > this way. I definitely do use Python as a prototyping language for Java/C++ and COBOL at work. I occasionally use it for Delphi at home too - I can throw a GUI together faster in Tkinter than I can using Delphi's GUI builder... But as I said in my response to Erik I rarely prototype the entire application, I just throw a demostrator of the key technologies together. Or implement a few of the harder bits to show its possible. > the 'prototype' is written in a fraction of the time > and shown to perform acceptably well, > no re-write is performed and python becomes accepted. Nah. The other languages are used for sound commercial reasons. C++ uses far fewer resources than Python. To get the same performance requires a bigger box. Bigger boxes cost bigger money - and higher maintenance charges - which soon pay for the development cost many times over. On a typical project we spend 5-10% of the budget actually writing code, the rest (requirement capture, analysis, design, test, deployment, training, procurement) is pretty much constant regardless of language. If a C++ box costs $250K and a Python box costs 500K then I can afford to spend $250K writing the extra code.... Two man years at least! Alan g. Author of the 'Learning to Program' web site http://www.freenetpages.co.uk/hp/alan.gauld From alan.gauld@bt.com Mon Sep 2 18:17:31 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Sep 2002 18:17:31 +0100 Subject: [Tutor] Java and Python (was: Iterators) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D0@mbtlipnt02.btlabs.bt.co.uk> > use Jython. Java would seem to be caught between something > that rocks and a hard case. > > Or am I missing something? Nope. Java is an overhyped phenomenon that is winning hearts for some extremely nebulous reasons. Its significantly slower than C++ but aside from garbage collection offers few advantages. It certainly does NOT save on lines of code - almost all the real world conversions I've seen have had more code in Java than in C++! Its slightly faster than Python but I have seen cases of Perl beating it. Frankly the choice of programming in either Java or Perl is not one I'd like to make but I'd probably choose Perl coz the pain would last for less time! The other big advantage of Java over C++ is it does have a pretty vast class library. The C++ STL is miniscule in comparison to the Java classes but OTOH thats a big API to learn.... Alan g From alan.gauld@bt.com Mon Sep 2 18:26:04 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Sep 2002 18:26:04 +0100 Subject: [Tutor] Fw: Hi Alan Morne here Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D2@mbtlipnt02.btlabs.bt.co.uk> 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_01C252A5.D0E44EE0 Content-Type: text/plain; charset="iso-8859-1" Hi Morne here again, could someone have a look at this and help me . You are still putting your if statements too far out. (And initialising the values to zero for each line thus losing your changes!) def foo(): for n in seq: x = y if x == y: #etc The if only gets executed after the for loop completes. What you want looks like this: def foo(): x = y # only initialise once before the loop for n in seq: if x == y: # notice the indentation. # do it elif x == z: # do another # now report the end values - again, note indentation HTH Alan g. Author of the 'Learning to Program' web site http://www.freenetpages.co.uk/hp/alan.gauld ------_=_NextPart_001_01C252A5.D0E44EE0 Content-Type: text/html; charset="iso-8859-1"
Hi Morne here again, could someone have a look at this and help me . 
 
You are still putting your if statements too far out.
(And initialising the values to zero for each line thus losing your changes!)
 
def foo():
   for n in seq:
      x = y
   if x == y:
      #etc
 
The if only gets executed after the for loop completes.
What you want looks like this:
 
def foo():
   x = y  # only initialise once before the loop
   for n in seq:
      if x == y:  # notice the indentation.
        # do it 
      elif x == z:
        # do another
    # now report the end values - again, note indentation
 
HTH

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld

------_=_NextPart_001_01C252A5.D0E44EE0-- From glingl@aon.at Mon Sep 2 18:19:29 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 02 Sep 2002 19:19:29 +0200 Subject: [Idle-dev] Re: [Tutor] Help concerning raw_input urgently needed! References: <20020901225120.D9FA19370B@server2.fastmail.fm> <5.1.0.14.0.20020902101532.02b438b8@www.thinkware.se> <200209021409.g82E9uZ30689@pcp02138704pcs.reston01.va.comcast.net> Message-ID: <3D739DA1.5050106@aon.at> Guido van Rossum schrieb: >>I think the problem is that Tcl/Tk use Unicode these days, >>and Python defaults to ISO8859-1. >> >> > >That's not true. > > > >>Thus your umlaut is ok for raw_input in python proper. In IDLE, the >>characters are recieved by Tk, and translated from Unicode. That >>fails on any non-ASCII value, since these are ambiguous unless a >>code page is supplied. >> >> > >Try the IDLE from current CVS. AFAIK the Unicode issues have been >fixed there. > >--Guido van Rossum (home page: http://www.python.org/~guido/) > > No, the problem addressed has not been fixed there. I don't know, if Unicode issues are involved, but anyway we find: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE Fork 0.8 -- press F1 for help >>> a = raw_input("Hä? ") Hä? Tschüs Traceback (most recent call last): File "", line 1, in ? a = raw_input("Hä? ") TypeError: object.readline() returned non-string >>> Gregor From alan.gauld@bt.com Mon Sep 2 18:21:12 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 2 Sep 2002 18:21:12 +0100 Subject: [Tutor] Java and Python (was: Iterators) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D1@mbtlipnt02.btlabs.bt.co.uk> > b) Writing stuff that runs over the Web is sometimes what one > wants. Good point, I forgot about applets. They are the one good selling point for Java and in that capacity I like it. Othewise C++ just seems to much easier to use(*), even with memory management overheads - I guess I'm used to them having been weaned on C... Alan g. (*)But I don't like C++ much either, its just the lesser of the two evils IMHO! From shalehperry@attbi.com Mon Sep 2 19:07:39 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Mon, 2 Sep 2002 11:07:39 -0700 Subject: [Tutor] Parsing iptables log files In-Reply-To: <20020902160616.GA16558@onix> References: <20020902160616.GA16558@onix> Message-ID: <200209021107.39433.shalehperry@attbi.com> On Monday 02 September 2002 09:06, Amaya Rodrigo Sastre wrote: > > The script and sample log can be found at: > http://www.amayita.com/~amaya/python/ and are not being posted to this > list because of their size: > amaya@aenima>du * > 96K=09amaya.bz2 > 8.0K=09amaya.py > > I am getting errors I don't fully understand, and I will appreciate any > comments. I love python, but I still don't seem to be proficient enough= =2E > I also am not sure if I am taking the right approach to this issue. > > I am using python 2.2. > > Thanks in advance. You didn't actually give us permission for those files ...... Could you just post the python errors and the offending section of code? From ajs@ix.netcom.com Mon Sep 2 20:15:24 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 2 Sep 2002 15:15:24 -0400 Subject: [Tutor] Java and Python (was: Iterators) References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D0@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <004f01c252b5$17b8a410$9865fea9@arthur> Alan writes - > Nope. Java is an overhyped phenomenon that is winning hearts > for some extremely nebulous reasons. Unfortunately, one of those reasons came from decent instincts. Java seemed to have the center-piece of an UnMicrosoft campaign - or at least was marketed (implicitly, at least) as such. Isn't there something to a claim that Java has been a decent alternative where cross or multiple platform issues exist. In the business world in which I interact, the AS400, for example, is a powerful presence. Java seems to have the potential of opening up that black box to a much wider development community. It is true, I think, that more recently things have gone in a direction where there are more alternatives for true cross-platform deveopment - good choice of crossplatform GUI's for example. But that wasn't nearly as true during Java's take-off. And in the interim Java seems to have achieved enough of a critical mass of support from major players like IBM and Oracle, to expect that it is a juggernaut not likely to recede for the foreseeable future. Or so it seems to me. Art From mufuboy2002@yahoo.com Mon Sep 2 20:30:13 2002 From: mufuboy2002@yahoo.com (dirk pitt) Date: Mon, 2 Sep 2002 12:30:13 -0700 (PDT) Subject: [Tutor] need help(urgent) Message-ID: <20020902193013.59775.qmail@web20107.mail.yahoo.com> --0-1939215898-1030995013=:59409 Content-Type: text/plain; charset=us-ascii hi guys, for a start, i have just one question to ask. i am a new person in the programing world. a friend gave me an advice to start with phyton. i just downloaded the software but before i could install it, i also saw that the computer i was using has java on it. i want to know if the two programs can work well on one machine or should i delete the java b4 i can install the phyton. i also want to know if the two programs wont affect one another if installed on the same machine. thanks a lot for doing this online training. best regars mufuboy --------------------------------- Do You Yahoo!? Yahoo! Autos - Get free new car price quotes --0-1939215898-1030995013=:59409 Content-Type: text/html; charset=us-ascii

hi guys,

for a start, i have just one question to ask. i am a new person in the programing world. a friend gave me an advice to start with phyton. i just downloaded the software but before i could install it, i also saw that the computer i was using has java on it. i want to know if the two programs can work well on one machine or should i delete the java b4 i can install the phyton. i also want to know if the two programs wont affect one another if installed on the same machine.

thanks a lot for doing this online training.

best regars mufuboy



Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes --0-1939215898-1030995013=:59409-- From pobrien@orbtech.com Mon Sep 2 20:55:09 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Mon, 2 Sep 2002 14:55:09 -0500 Subject: [Tutor] need help(urgent) In-Reply-To: <20020902193013.59775.qmail@web20107.mail.yahoo.com> Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_003E_01C25290.BB70DF20 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit Not only can they be installed together, they can actually work together. There is a version of Python implemented in Java, called Jython. Jython allows Python programs to work with Java classes and vice versa. So there is no need to delete Java before you install Python. -- Patrick K. O'Brien Orbtech ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- Web: http://www.orbtech.com/web/pobrien/ Blog: http://www.orbtech.com/blog/pobrien/ Wiki: http://www.orbtech.com/wiki/PatrickOBrien ----------------------------------------------- -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of dirk pitt Sent: Monday, September 02, 2002 2:30 PM To: tutor@python.org Subject: [Tutor] need help(urgent) hi guys, for a start, i have just one question to ask. i am a new person in the programing world. a friend gave me an advice to start with phyton. i just downloaded the software but before i could install it, i also saw that the computer i was using has java on it. i want to know if the two programs can work well on one machine or should i delete the java b4 i can install the phyton. i also want to know if the two programs wont affect one another if installed on the same machine. thanks a lot for doing this online training. best regars mufuboy ---------------------------------------------------------------------------- -- Do You Yahoo!? Yahoo! Autos - Get free new car price quotes ------=_NextPart_000_003E_01C25290.BB70DF20 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
Not=20 only can they be installed together, they can actually work together. = There is a=20 version of Python implemented in Java, called Jython. Jython allows = Python=20 programs to work with Java classes and vice versa. So there is no need = to delete=20 Java before you install Python.
 

--
Patrick K.=20 O'Brien
Orbtech
-----------------------------------------------
= "Your=20 source for Python programming=20 expertise."
-----------------------------------------------
Web:&nb= sp; http://www.orbtech.com/web/pobrien/
Blog: http://www.orbtech.com/blog/pobrien/
Wiki: http://www.orbtech.com/wiki/PatrickOBrien
--------= ---------------------------------------

-----Original Message-----
From: = tutor-admin@python.org=20 [mailto:tutor-admin@python.org]On Behalf Of dirk = pitt
Sent:=20 Monday, September 02, 2002 2:30 PM
To:=20 tutor@python.org
Subject: [Tutor] need=20 help(urgent)

hi guys,

for a start, i have just one question to ask. i am a new person in = the=20 programing world. a friend gave me an advice to start with phyton. i = just=20 downloaded the software but before i could install it, i also saw that = the=20 computer i was using has java on it. i want to know if the two = programs can=20 work well on one machine or should i delete the java b4 i can install = the=20 phyton. i also want to know if the two programs wont affect one = another if=20 installed on the same machine.

thanks a lot for doing this online training.

best regars mufuboy



Do You Yahoo!?
Yahoo! = Autos -=20 Get free new car price quotes
------=_NextPart_000_003E_01C25290.BB70DF20-- From dyoo@hkn.eecs.berkeley.edu Mon Sep 2 23:11:52 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 2 Sep 2002 15:11:52 -0700 (PDT) Subject: [Tutor] need help(urgent) In-Reply-To: Message-ID: On Mon, 2 Sep 2002, Patrick K. O'Brien wrote: > Not only can they be installed together, they can actually work > together. There is a version of Python implemented in Java, called > Jython. Jython allows Python programs to work with Java classes and vice > versa. So there is no need to delete Java before you install Python. Hi mufuboy, For more information on Jython, you can look at: http://jython.org/ There's some examples on using Java with Python there. Rob Andrews has also written a quicky tutorial on getting into Jython here: http://uselesspython.com/Jython_Swing_Basics.html Please feel free to ask more questions, and we'll be happy to help! From dyoo@hkn.eecs.berkeley.edu Mon Sep 2 23:25:44 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 2 Sep 2002 15:25:44 -0700 (PDT) Subject: [Tutor] PIL import module problems In-Reply-To: <20020903001029.1168fc87.thomi@thomi.imail.net.nz> Message-ID: On Tue, 3 Sep 2002, Thomi Richards wrote: > I just downloaded the python imaging library module on my debian (sarge) > box ('sudo apt-get install python2.2-imaging'). It installed OK, but > when i go 'import Image', it says it cannot find the module "Image'. > HOWEVER, i am using python2.1. > > can someone explain why the imaging library for 2.2 will not work with > 2.1?? are there features in 2.2 which PIL needs?? I'll download the 2.1 > version, but i did find this a little interesting... Hi Thomi, The Python Imaging Library is a C extension module, and is tightly bound to Python's dynamic library. As a result, C extension modules are really dependent on the version of Python it's compiled against, and so Python2.2-imaging package will only work with Python 2.2. So modules that work with 2.1 need to be recompiled to work with 2.2. (It's a bit of a hassle; I wonder if it's possible to make C extension modules less version dependent!) But anyway, since you're running Debian Linux, you should be able to do an 'apt-get install python2.1-imaging' command to get things running. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Mon Sep 2 23:31:21 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 2 Sep 2002 15:31:21 -0700 (PDT) Subject: [Tutor] Fw: Hi Alan Morne here In-Reply-To: <002b01c25287$9ae5a8c0$2500a8c0@maxitec.co.za> Message-ID: On Mon, 2 Sep 2002, Morne wrote: > The lines in the file that you will use look like this: > > Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 > hisaddr = 155.239.150.254 > Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: > 5091 octets in, 1864 octets out > Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed > > > if string.find("IPCP",line) > 0: > connectline = split(line) > connect.count = connect.count + 1 > > elif string.find("ERROR",line) > 0: > error.count = error.count + 1 > > elif string.find("connect time",line) > 0: Hi Morne, One note: if you're looking to see if yolur string contains a certain substring, be aware that string.find() can also return '0' if it finds that string at the very beginning. For example: ### >>> 'hello world'.find('hello') 0 ### So zero is also a perfectly good value as far as find() is concerned. It's that '-1' value that you want to watch out for: ### >>> 'hello world'.find('goodbye') -1 ### Hope this helps! From guido@python.org Mon Sep 2 15:09:56 2002 From: guido@python.org (Guido van Rossum) Date: Mon, 02 Sep 2002 10:09:56 -0400 Subject: [Idle-dev] Re: [Tutor] Help concerning raw_input urgently needed! In-Reply-To: Your message of "Mon, 02 Sep 2002 11:08:11 +0200." <5.1.0.14.0.20020902101532.02b438b8@www.thinkware.se> References: <20020901225120.D9FA19370B@server2.fastmail.fm> <5.1.0.14.0.20020902101532.02b438b8@www.thinkware.se> Message-ID: <200209021409.g82E9uZ30689@pcp02138704pcs.reston01.va.comcast.net> > I think the problem is that Tcl/Tk use Unicode these days, > and Python defaults to ISO8859-1. That's not true. > Thus your umlaut is ok for raw_input in python proper. In IDLE, the > characters are recieved by Tk, and translated from Unicode. That > fails on any non-ASCII value, since these are ambiguous unless a > code page is supplied. Try the IDLE from current CVS. AFAIK the Unicode issues have been fixed there. --Guido van Rossum (home page: http://www.python.org/~guido/) From guido@python.org Mon Sep 2 20:02:47 2002 From: guido@python.org (Guido van Rossum) Date: Mon, 02 Sep 2002 15:02:47 -0400 Subject: [Idle-dev] Re: [Tutor] Help concerning raw_input urgently needed! In-Reply-To: Your message of "Mon, 02 Sep 2002 09:30:20 CDT." References: Message-ID: <200209021902.g82J2lN31121@pcp02138704pcs.reston01.va.comcast.net> > [Guido van Rossum] > > > > Try the IDLE from current CVS. AFAIK the Unicode issues have been > > fixed there. > > I just updated from CVS and gave it a try. :-( > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > GRPC IDLE Fork 0.8.2 > >>> a = raw_input("Hä? ") > UnicodeError: ASCII encoding error: ordinal not in range(128) Sorry, that's the idlefork IDLE. I meant the core Python CVS. --Guido van Rossum (home page: http://www.python.org/~guido/) From lists@shrestha.net.np Tue Sep 3 03:26:36 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Tue, 03 Sep 2002 08:11:36 +0545 Subject: Iterators (was: Re: [Tutor] text module) References: Message-ID: <3D741DDC.3090909@shrestha.net.np> Actually, in Java arrays are really accessed using iterators. The iterators are used for subclasses of List which are already lists so all we need to do is use the iterator() method to get an iterator! Since arrays in Java cannot grow dynamically like Python a subclass of List is generally used when the list needs to grow. The nice thing in Python is that there is just list, in Java we have arrays and whole bunch of implementations of List! Ashish From dylan.belsey@baesystems.com Tue Sep 3 05:51:24 2002 From: dylan.belsey@baesystems.com (BELSEY, Dylan) Date: Tue, 3 Sep 2002 14:21:24 +0930 Subject: [Tutor] Article !!! Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2A8C@wtntex1.baea.com.au> >From an earlier posting.. www.python.org/doc/tut/node10.html www.python.org/doc/lib/module-exceptions.html -----Original Message----- From: Arthur [mailto:ajs@ix.netcom.com] Sent: Thursday, 22 August 2002 23:41 To: tutor@python.org Subject: [Tutor] Error handling resource needed I am looking for some tutorial level, but hopefully fairly thorough resource on exception handling in Python. Surprisingly hard to dig up. Have the 1200 page book Programming Python, e.g., which surprisingly has next to nothing on the subject -=20 at least that I can locate. Tips appreciated. Art _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -----Original Message----- From: Aur=E9lio Magalh=E3es Dias [mailto:amd@atlas.ucpel.tche.br] Sent: Saturday, 31 August 2002 10:06 To: B. M. Ericsson Cc: tutor@python.org Subject: Re: [Tutor] Article !!! Sorry, It is exceptions handling, in a very general view! ----------------------------------------- Aur=E9lio Magalh=E3es Dias Ci=EAncia da Computa=E7=E3o UCPel - RS - Brasil ----------------------------------------- On Fri, 30 Aug 2002, B. M. Ericsson wrote: > exceptions abound. > > =3D=3D=3D=3D=3D > www.geocities.com/bmericsson > > Check out my website, sign > the Guestbook, look around. > > __________________________________________________ > Do You Yahoo!? > Yahoo! Finance - Get real-time stock quotes > http://finance.yahoo.com > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From arodrigo@genasys.com Tue Sep 3 08:47:23 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: Tue, 3 Sep 2002 09:47:23 +0200 Subject: [Tutor] Parsing iptables log files In-Reply-To: <200209021107.39433.shalehperry@attbi.com> References: <20020902160616.GA16558@onix> <200209021107.39433.shalehperry@attbi.com> Message-ID: <20020903074722.GA22515@onix> Sean 'Shaleh' Perry dijo: > You didn't actually give us permission for those files ...... Sorry, fixed now... > Could you just post the python errors and the offending section of > code? The problem is that it's not really a piece of code that's giving me trouble. Right now it is just not going inside the loop: IndexError: list index out of range But my main concern if is my approach is right, and I wanted a more experienced programmer's advice. I'll explain what I am trying to do. My iptables gives me a log line like this (this is what my regex seems to be obtaining) for a complete request and its answers: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ------------------------------------------------------------------------------ num | date | time | src_addr | dst_addr | s_p | d_p | seq | ack ------------------------------------------------------------------------------ 0 Aug 22 09:35:23 192.168.3.9 192.168.3.1 37192 80 1899023795 0 1 Aug 22 09:35:33 192.168.3.1 192.168.3.9 80 37192 1906765896 1899023795 2 Aug 22 09:35:43 192.168.3.9 192.168.3.1 37192 80 1899023795 1906765896 3 Aug 22 09:35:53 192.168.3.1 192.168.3.9 80 37192 1906765896 1899023795 The thing is that I know that a request is being answered beacuse: - a request's source port equals it's answer's destination port and it's always higher than 1024. - the request's ACK equals its answer SEQ. Each http request has several lines, and I have to get the first request's time, and the last answer's and then know how long it took the request to be over. And then of course make statistics with the data, but that is the easiest part, I think. Thanks for your time... -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_0099_01C25337.6E98A780 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi ,OK Here I have done somthing else but it seems not to work when I = copy and then paste it to the Python "eddit" It gives me this error ,can = some one help me please. Just say I want to open the file ppp.log "path: C:\my documents\ppp.log = would that work" Not that Im very new to python and dont know my way around but am going = to know in some time. Thanx from Morne import re import string secondsMatcher=3Dre.compile("Connect time: (\d+) secs") def getStuff(file): closeline =3D 0 errorcount =3D 0 secondscount =3D 0 connectcount =3D 0 data_outcount =3D 0 data_incount =3D 0 ppplist =3D file.readlines() for line in ppplist: if string.find(line,"LayerUp") >=3D 0: print "found connect" connectline =3D string.split(line) connectcount =3D connectcount + 1 elif string.find(line,"ERROR") >=3D 0: print "found error" errorcount =3D errorcount + 1 elif string.find(line,"Connect time") >=3D 0: print "found close" connectSecs=3DsecondsMatcher.search(line).group(1) print "Connected for",connectSecs closeline =3D string.split(line) secondscount =3D secondscount + string.atoi(connectSecs) def main(): f=3Dopen("ppp.log","r") getStuff(f) return None if __name__=3D=3D"__main__": main() ------=_NextPart_000_0099_01C25337.6E98A780 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi ,OK Here I have done somthing else = but it seems=20 not to work when I copy and then paste it to the Python "eddit" It gives = me this=20 error ,can some one help me please.
 
Just say I want to open the file = ppp.log "path:=20 C:\my documents\ppp.log would that work"
Not that Im very new to python and dont = know my way=20 around but am going to know in some time.
 
Thanx from Morne
 
import re
import string
 
secondsMatcher=3Dre.compile("Connect = time: (\d+)=20 secs")
 
def = getStuff(file):
    closeline=20 =3D 0
    errorcount =3D 0
    = secondscount =3D=20 0
    connectcount =3D 0
    = data_outcount =3D=20 0
    data_incount =3D 0
    ppplist = =3D=20 file.readlines()
 
    for line in=20 ppplist:
 
      if=20 string.find(line,"LayerUp") >=3D=20 0:
          print = "found=20 connect"
          = connectline =3D=20 string.split(line)
        &nb= sp;=20 connectcount =3D connectcount + 1
 
      elif=20 string.find(line,"ERROR") >=3D=20 0:
          print = "found=20 error"
          = errorcount =3D=20 errorcount + 1
 
      elif=20 string.find(line,"Connect time") >=3D=20 0:
          print = "found=20 close"
         =20 connectSecs=3DsecondsMatcher.search(line).group(1)
   &= nbsp;     =20 print "Connected=20 for",connectSecs
         = ;=20 closeline =3D=20 string.split(line)
        &nb= sp;=20 secondscount =3D secondscount + string.atoi(connectSecs)
 
def main():
   =20 f=3Dopen("ppp.log","r")
    = getStuff(f)
   =20 return None
 
if = __name__=3D=3D"__main__":
   =20 main()
------=_NextPart_000_0099_01C25337.6E98A780-- From thomi@thomi.imail.net.nz Tue Sep 3 08:59:07 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Tue, 3 Sep 2002 19:59:07 +1200 Subject: [Tutor] PIL import module problems In-Reply-To: <20020902135023.GC4840@tc.niof.net> References: <20020903001029.1168fc87.thomi@thomi.imail.net.nz> <20020902135023.GC4840@tc.niof.net> Message-ID: <20020903195907.5efc021d.thomi@thomi.imail.net.nz> of couse!! sorry bout that guys (stupid question) On Mon, 2 Sep 2002 09:50:23 -0400 Thus said Rick Pasotto : > On Tue, Sep 03, 2002 at 12:10:29AM +1200, Thomi Richards wrote: > > > > Hey! > > > > I just downloaded the python imaging library module on my debian > > (sarge) box ('sudo apt-get install python2.2-imaging'). It installed > > OK, but when i go 'import Image', it says it cannot find the module > > "Image'. HOWEVER, i am using python2.1. > > > > can someone explain why the imaging library for 2.2 will not work > > with 2.1?? are there features in 2.2 which PIL needs?? I'll download > > the 2.1 version, but i did find this a little interesting... > > Because /usr/lib/python2.1/site-packages/PIL is a different directory > than /usr/lib/python2.2/site-packages/PIL. > > Debian is set up so that you can have multiple versions of python on > the machine at the same time and then choose which one you want to > work with. > > -- > "Every time I try to define a perfectly stable person, I am appalled > by the dullness of that person." > -- J. D. Griffin > Rick Pasotto rickp@telocity.com http://www.niof.net > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- "Avoid the Gates of Hell. Use Linux" Thomi Richards, thomi@imail.net.nz From thomi@thomi.imail.net.nz Tue Sep 3 09:33:23 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Tue, 3 Sep 2002 20:33:23 +1200 Subject: [Tutor] windows clipboard problems with python. Message-ID: <20020903203323.7b7e42e1.thomi@thomi.imail.net.nz> does anyonme know of a way to get python to recognise when something has been copied (using CTRL+C), and take whatever has been copied, and then paste it to a file?? sort of like a 'paste board'. this would be really usefull when getting links for research for colledge projects etc. etc. etc. also, has anyon ever managed to make windows app which site in the system tray, and has functins available when you right click its icon? -- This message was brought to you by one bored guy, with nothing better to do, And the letter Q. Thomi Richards, thomi@imail.net.nz From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_00FE_01C2533A.F4996F60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ----- Original Message -----=20 From: Morne=20 To: python tutor=20 Sent: Tuesday, September 03, 2002 10:48 AM Subject: Clipin ERROR IT GIVES ME with and without disk in A: drive >>>=20 Traceback (most recent call last): File "A:/mess", line 39, in ? main() File "A:/mess", line 34, in main f=3Dopen("ppp.log","r") IOError: [Errno 2] No such file or directory: 'ppp.log' Exception in Tkinter callback Traceback (most recent call last): File "C:\PYTHON22\lib\lib-tk\Tkinter.py", line 1292, in __call__ return apply(self.func, args) File "C:\PYTHON22\Tools\idle\ScriptBinding.py", line 148, in = run_script_event interp.execfile(filename) File "C:\PYTHON22\Tools\idle\PyShell.py", line 175, in execfile source =3D open(filename, "r").read() IOError: [Errno 13] Permission denied: 'A:/mess' Hi ,OK Here I have done somthing else but it seems not to work when I = copy and then paste it to the Python "eddit" It gives me this error ,can = some one help me please. Just say I want to open the file ppp.log "path: C:\my documents\ppp.log = would that work" Not that Im very new to python and dont know my way around but am going = to know in some time. Thanx from Morne =20 import re import string secondsMatcher=3Dre.compile("Connect time: (\d+) secs") def getStuff(file): closeline =3D 0 errorcount =3D 0 secondscount =3D 0 connectcount =3D 0 data_outcount =3D 0 data_incount =3D 0 ppplist =3D file.readlines() for line in ppplist: if string.find(line,"LayerUp") >=3D 0: print "found connect" connectline =3D string.split(line) connectcount =3D connectcount + 1 elif string.find(line,"ERROR") >=3D 0: print "found error" errorcount =3D errorcount + 1 elif string.find(line,"Connect time") >=3D 0: print "found close" connectSecs=3DsecondsMatcher.search(line).group(1) print "Connected for",connectSecs closeline =3D string.split(line) secondscount =3D secondscount + string.atoi(connectSecs) def main(): f=3Dopen("ppp.log","r") getStuff(f) return None if __name__=3D=3D"__main__": main() ------=_NextPart_000_00FE_01C2533A.F4996F60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
----- Original Message -----=20
From: Morne=20
Sent: Tuesday, September 03, 2002 10:48 AM
Subject: Clipin
 
ERROR IT GIVES ME with and without disk in A: drive
>>>
Traceback (most recent call last):
  File=20 "A:/mess", line 39, in ?
    main()
  File = "A:/mess",=20 line 34, in main
    = f=3Dopen("ppp.log","r")
IOError: [Errno=20 2] No such file or directory: 'ppp.log'
Exception in Tkinter=20 callback
Traceback (most recent call last):
  File=20 "C:\PYTHON22\lib\lib-tk\Tkinter.py", line 1292, in=20 __call__
    return apply(self.func, args)
  = File=20 "C:\PYTHON22\Tools\idle\ScriptBinding.py", line 148, in=20 run_script_event
    = interp.execfile(filename)
  File=20 "C:\PYTHON22\Tools\idle\PyShell.py", line 175, in = execfile
   =20 source =3D open(filename, "r").read()
IOError: [Errno 13] Permission = denied:=20 'A:/mess'
 
 
 

Hi ,OK Here I have done somthing else = but it seems=20 not to work when I copy and then paste it to the Python "eddit" It gives = me this=20 error ,can some one help me please.
 
Just say I want to open the file = ppp.log "path:=20 C:\my documents\ppp.log would that work"
Not that Im very new to python and dont = know my way=20 around but am going to know in some time.
 
Thanx from Morne
 
import re
import string
 
secondsMatcher=3Dre.compile("Connect = time: (\d+)=20 secs")
 
def = getStuff(file):
    closeline=20 =3D 0
    errorcount =3D 0
    = secondscount =3D=20 0
    connectcount =3D 0
    = data_outcount =3D=20 0
    data_incount =3D 0
    ppplist = =3D=20 file.readlines()
 
    for line in=20 ppplist:
 
      if=20 string.find(line,"LayerUp") >=3D=20 0:
          print = "found=20 connect"
          = connectline =3D=20 string.split(line)
        &nb= sp;=20 connectcount =3D connectcount + 1
 
      elif=20 string.find(line,"ERROR") >=3D=20 0:
          print = "found=20 error"
          = errorcount =3D=20 errorcount + 1
 
      elif=20 string.find(line,"Connect time") >=3D=20 0:
          print = "found=20 close"
         =20 connectSecs=3DsecondsMatcher.search(line).group(1)
   &= nbsp;     =20 print "Connected=20 for",connectSecs
         = ;=20 closeline =3D=20 string.split(line)
        &nb= sp;=20 secondscount =3D secondscount + string.atoi(connectSecs)
 
def main():
   =20 f=3Dopen("ppp.log","r")
    = getStuff(f)
   =20 return None
 
if = __name__=3D=3D"__main__":
   =20 main()
------=_NextPart_000_00FE_01C2533A.F4996F60-- From arodrigo@genasys.com Tue Sep 3 10:52:26 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: Tue, 3 Sep 2002 11:52:26 +0200 Subject: [Tutor] Clipin In-Reply-To: <009c01c25326$ad9549e0$2500a8c0@maxitec.co.za> References: <009c01c25326$ad9549e0$2500a8c0@maxitec.co.za> Message-ID: <20020903095226.GH22577@onix> Morne dijo: > Hi ,OK Here I have done somthing else but it seems not to work when I > copy and then paste it to the Python "eddit" It gives me this error > ,can some one help me please. This version of the script works well with the logfile you sent me (no errors): ~arodrigo@onix>python ppp.py found close Connected for 40 found connect found connect found close Connected for 197 found close Connected for 228 found close Connected for 43 found connect found connect What exactly is giving you trouble? -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_0028_01C25344.81A5BF40 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0029_01C25344.81A5BF40" ------=_NextPart_001_0029_01C25344.81A5BF40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ok my log file is saved in C:\my documents\ppp.log Can you run the program on you python and see where i went wrong. import re import string secondsMatcher=3Dre.compile("Connect time: (\d+) secs") def getStuff(file): closeline =3D 0 errorcount =3D 0 secondscount =3D 0 connectcount =3D 0 data_outcount =3D 0 data_incount =3D 0 ppplist =3D file.readlines() for line in ppplist: if string.find(line,"LayerUp") >=3D 0: connectline =3D string.split(line) connectcount =3D connectcount + 1 elif string.find(line,"ERROR") >=3D 0: print "found error" errorcount =3D errorcount + 1 elif string.find(line,"Connect time") >=3D 0: print "found close" connectSecs=3DsecondsMatcher.search(line).group(1) print "Connected for",connectSecs closeline =3D string.split(line) secondscount =3D secondscount + string.atoi(connectSecs) def main(): f=3Dopen("C:\my documents\ppp.log","r") getStuff(f) return None if __name__=3D=3D"__main__": main() ------=_NextPart_001_0029_01C25344.81A5BF40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
ok my log file is saved in C:\my=20 documents\ppp.log
 
Can you run the program on you python = and see where=20 i went wrong.
 
 
 
import re
import string
 
secondsMatcher=3Dre.compile("Connect = time: (\d+)=20 secs")
 
def = getStuff(file):
    closeline=20 =3D 0
    errorcount =3D 0
    = secondscount =3D=20 0
    connectcount =3D 0
    = data_outcount =3D=20 0
    data_incount =3D 0
    ppplist = =3D=20 file.readlines()
 
    for line in=20 ppplist:
 
      if=20 string.find(line,"LayerUp") >=3D=20 0:
          connectline = =3D=20 string.split(line)
        &nb= sp;=20 connectcount =3D connectcount + 1
 
      elif=20 string.find(line,"ERROR") >=3D=20 0:
          print = "found=20 error"
          = errorcount =3D=20 errorcount + 1
 
      elif=20 string.find(line,"Connect time") >=3D=20 0:
          print = "found=20 close"
         =20 connectSecs=3DsecondsMatcher.search(line).group(1)
   &= nbsp;     =20 print "Connected=20 for",connectSecs
         = ;=20 closeline =3D=20 string.split(line)
        &nb= sp;=20 secondscount =3D secondscount + string.atoi(connectSecs)
 
def main():
    = f=3Dopen("C:\my=20 documents\ppp.log","r")
    = getStuff(f)
   =20 return None
 
if = __name__=3D=3D"__main__":
   =20 main()
------=_NextPart_001_0029_01C25344.81A5BF40-- ------=_NextPart_000_0028_01C25344.81A5BF40 Content-Type: application/octet-stream; name="ppp.log" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ppp.log" Jul 5 18:00:00 maxigate newsyslog[87300]: logfile turned over Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:15:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 40 secs: 0 octets in, 265 octets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: : 1079435 = packets in, 231579 packets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: total 6 bytes/sec, = peak 21 bytes/sec on Fri Jul 5 18:15:40 2002=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:45:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(180) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(103) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(9) state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(103) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(181) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 = hisaddr =3D 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 5 18:46:33 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: Idle timer expired=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerDown: = 155.239.150.146=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Command: maxigate: iface = clear=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = SendTerminateReq(106) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvTerminateAck(106) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerFinish.=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: = 5091 octets in, 1864 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: : 234569 packets in, = 230304 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: total 35 bytes/sec, = peak 815 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Terminate=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerDown=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = SendTerminateReq(180) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: open -> lcp=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = RecvTerminateAck(180) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 228 secs: 6795 octets in, 2567 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: total 41 bytes/sec, = peak 840 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 06:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Chat: Expect timeout=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = hangup=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 43 secs: 0 octets in, 0 octets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: total 0 bytes/sec, = peak 0 bytes/sec on Sat Jul 6 06:30:44 2002=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^MAT^M^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 08:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(182) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(107) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(206) state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(107) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(183) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.26 = hisaddr =3D 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 6 08:31:32 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 ------=_NextPart_000_0028_01C25344.81A5BF40-- From alan.gauld@bt.com Tue Sep 3 11:13:14 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 3 Sep 2002 11:13:14 +0100 Subject: [Tutor] Java and Python (was: Iterators) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D4@mbtlipnt02.btlabs.bt.co.uk> > > Nope. Java is an overhyped phenomenon that is winning hearts > > for some extremely nebulous reasons. > Java seemed to have the center-piece of an UnMicrosoft campaign - > or at least was marketed (implicitly, at least) as such. Yes, thats what I meant :-) > Isn't there something to a claim that Java has been a decent > alternative where cross or multiple platform issues exist. In practice no. Java is no more cross platform than well written C. In practice GNU software has been (and is!) available on many platforms without being written in Java. Just look at Python for that matter - all in C.... Java's portability is largely hype, in practice there is a lot of incompatibilities between JVMs and even between the same JVM on diffeent platforms. > In the business world in which I interact, the AS400, for example, is > a powerful presence. Java seems to have the potential of opening > up that black box to a much wider development community. Yes, but its largely misconception. AS/4000's have had a full Posix library layer for years - at least 1992 - ie before Java came to town.... > crossplatform GUI's for example. But that wasn't nearly as > true during Java's take-off. Again, I'm not sure that's true. Visix did a cross platform GUI toolkit. And Bristol allowed you to write Windows C code on X windows. There were several X windows ports for Windows and even DOS(DeskView X anyone?) There were other options too XVT, TeleUse etc... The big difference was they all cost (lots of) money! > And in the interim Java seems to have achieved > enough of a critical mass of support from major > players like IBM and Oracle Absolutely. At work we have gone (for server apps) from 80% C++ about 5 years ago to 80% Java now. To pick up another point. I said in another mail that the cost of hardware could justify a rewrite in C++ that doesn't apply for Java since its generally a bigger resource hog than Python! But the maintenance bill does have some bearing since the maintenance teams are only trained in Java and C++ (and the mainframers in COBOL). Alan G. From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_0083_01C2534E.9421E900 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi there ; here is what I have and then what I need the program to do . import re import string secondsMatcher=3Dre.compile("Connect time: (\d+) secs") def getStuff(file): closeline =3D 0 errorcount =3D 0 secondscount =3D 0 connectcount =3D 0 data_outcount =3D 0 data_incount =3D 0 ppplist =3D file.readlines() for line in ppplist: if string.find(line,"LayerUp") >=3D 0: print "found connect" connectline =3D string.split(line) connectcount =3D connectcount + 1 =20 elif string.find(line,"ERROR") >=3D 0: print "found error" errorcount =3D errorcount + 1 elif string.find(line,"Connect time") >=3D 0: print "found close" connectSecs=3DsecondsMatcher.search(line).group(1) print "Connected for",connectSecs closeline =3D string.split(line) secondscount =3D secondscount + string.atoi(connectSecs) def main(): f=3Dopen("C:/my documents/ppp.log","r") getStuff(f) return None if __name__=3D=3D"__main__": main() WHEN I RUN THE PROGRAM: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>>=20 found close Connected for 40 found connect found connect found close Connected for 197 found close Connected for 228 found close Connected for 43 found connect found connect KNOW what IT SHOULD DO: I want this program to read a .log file and give me the following type of report: PPP Log file summary for 5 Jul 2002 ----------------------------------- Jul 5 18:15:01 Connected to internet (IP 155.239.150.146) Jul 5 18:18:08 Closed connection. ( Connect time: 197 secs: 5091 octets = in, 1864 octets out ) ----------------------------------- Successful connections: 5 Failed connections: 2 Total time online: 456 seconds Total data in: 66576 octets Total Data out: 66349 octets HOW WOULD I DO THAT ? wpuld you please help me . ------=_NextPart_000_0083_01C2534E.9421E900 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi there ; here is what I have and then = what I need=20 the program to do .
 
import re
import string
 
secondsMatcher=3Dre.compile("Connect = time: (\d+)=20 secs")
 
def = getStuff(file):
    closeline=20 =3D 0
    errorcount =3D 0
    = secondscount =3D=20 0
    connectcount =3D 0
    = data_outcount =3D=20 0
    data_incount =3D 0
    ppplist = =3D=20 file.readlines()
 
    for line in=20 ppplist:
 
      if=20 string.find(line,"LayerUp") >=3D=20 0:
          print = "found=20 connect"
          = connectline =3D=20 string.split(line)
        &nb= sp;=20 connectcount =3D connectcount +=20 1
        =20
      elif string.find(line,"ERROR") = >=3D=20 0:
          print = "found=20 error"
          = errorcount =3D=20 errorcount + 1
 
      elif=20 string.find(line,"Connect time") >=3D=20 0:
          print = "found=20 close"
         =20 connectSecs=3DsecondsMatcher.search(line).group(1)
   &= nbsp;     =20 print "Connected=20 for",connectSecs
         = ;=20 closeline =3D=20 string.split(line)
        &nb= sp;=20 secondscount =3D secondscount + string.atoi(connectSecs)
 
def main():
    = f=3Dopen("C:/my=20 documents/ppp.log","r")
    = getStuff(f)
   =20 return None
 
if = __name__=3D=3D"__main__":
   =20 main()
 
WHEN I RUN THE PROGRAM:
 
Python 2.2.1 (#34, Apr  9 2002, = 19:34:33) [MSC=20 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for = more=20 information.
IDLE 0.8 -- press F1 for help
>>>
found=20 close
Connected for 40
found connect
found connect
found=20 close
Connected for 197
found close
Connected for 228
found=20 close
Connected for 43
found connect
found = connect
KNOW what IT SHOULD DO:
 
I want this program to read a = .log file=20 and give me the
following type of report:


PPP Log file = summary for=20 5 Jul 2002
-----------------------------------
Jul  5 = 18:15:01=20 Connected to internet (IP 155.239.150.146)
Jul  5 18:18:08 = Closed=20 connection. ( Connect time: 197 secs: 5091 octets in,
1864 octets out = )
-----------------------------------
Successful connections: = 5
Failed=20 connections: 2
Total time online: 456 seconds
Total data in: 66576 = octets
Total Data out: 66349 octets
HOW WOULD I DO THAT ?
 
wpuld you please help me=20 .








------=_NextPart_000_0083_01C2534E.9421E900-- From ajs@ix.netcom.com Tue Sep 3 15:08:40 2002 From: ajs@ix.netcom.com (Arthur) Date: Tue, 3 Sep 2002 10:08:40 -0400 Subject: [Tutor] Java and Python (was: Iterators) References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D4@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <001601c25353$98752440$9865fea9@arthur> > > > Nope. Java is an overhyped phenomenon that is winning hearts > > > for some extremely nebulous reasons. > > Java seemed to have the center-piece of an UnMicrosoft campaign - > > or at least was marketed (implicitly, at least) as such. > > Yes, thats what I meant :-) and your other comments.. Well, I accept that you are talking from a deeper experience than I. The issue is timely to me, because I am at a bit of a crossroads - feeling the need to further explore one of C++ or Java - again mostly to have a better understanding of options to extend, complement Python. The impetus: At the moment the lack of method overloading in Python has become a focus. PyGeo in pure Python has maybe 40 classes of geometric "primitives". I could probably cut that to 15 to 20 if I had the ability to distinguish by constructor signature. I think that would make PyGeo much more useable and better simulate geometric thinking. First choice is probably just to find a way to simulate method overloading behavior in Python; second is to explore whether I can achieve the result by porting the classes to Java or C++ and expose them to Python. As to choice one - I have gotten fairly close, but no cigar yet. Essentially my approach is trying to find is a function/algorythm to which I can send a list of lists of classes that are acceptable constructor signatures for a class, together with the instance arguments actually sent to the class, and receive back a message as to which signature the arguments match, or that there is no match. The further complications being that I would like to make argument order irrelevant. That is, if I send a (line instance, plane instance) it should find a match with a signature of [Plane, Line], *and* return the arguments in (plane instance, line instance) order. And, of course, the [Plane, Line] signature should find a match for instances which are subclasses of Plane and/or Line. Interesting and fun to try to work this out. Probably quite doable, but I haven't been able to nail it yet. If I do work it out, I *think* I can take it from there by, among other things, referencing (to the function name called during update cycles) the function appropriate to the signature returned as valid. (If that makes any sense, as stated). And I am thinking since this is all accomplished at initialization, there will be no performance hit after start-up. And a second or two of start-up overhead does not concern me. On the other hand I fear that if this is in fact doable, there would be a more publicly discussed Python Pattern for handling this issue - so that maybe I am off on a goose chase. Ideas welcome. Art From arodrigo@genasys.com Tue Sep 3 15:34:03 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: Tue, 3 Sep 2002 16:34:03 +0200 Subject: [Tutor] Parsing iptables log files In-Reply-To: <20020903074722.GA22515@onix> References: <20020902160616.GA16558@onix> <200209021107.39433.shalehperry@attbi.com> <20020903074722.GA22515@onix> Message-ID: <20020903143403.GD23594@onix> I see my web server is giving timeouts, so I moved the log and script to http://www.lared.es/~amayita/python/ in case you want to take a look at it. Sorry for all the noise. -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From alan.gauld@bt.com Tue Sep 3 15:35:59 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 3 Sep 2002 15:35:59 +0100 Subject: [Tutor] Java and Python (was: Iterators) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D8@mbtlipnt02.btlabs.bt.co.uk> > Well, I accept that you are talking from a deeper experience than I. Not necessarily, just different experience perhaps. My background is in corporate IS on large (and by the standards of most folks, very large) projects. Typical budgets are >$10 million. It is interesting to me toi see the opposite end of the spectrum discussed on these lists. Most folks seem to be on smaller projects <$100K say which have a different set of challenges and different "right" answers. > At the moment the lack of method overloading in Python has > become a focus. PyGeo in pure Python has maybe 40 classes > of geometric "primitives". I could probably cut that > to 15 to 20 if I had the ability to distinguish by > constructor signature. Could. Doesn't mean you should. I'm curious because although the ability to have multiple constructors(al la Delphi) is something I'd like in Python, overloading of constructors is rarely an issue since in Python everything is an object so I can pass in whatever I like. Combined with default args its just not an issue for me. Why can't you just define say 6 or 7 parameters, give them defaults and then check the types of the arguments at runtime calling out to the rquired init function as appropriate? class C: def __init__(self,p1=None,p2=None,p3=None,p4=None) if type(p1) == type(1) and type(p2) == type("string") \ and type(p3 == type(7) and type(p4) == type(0.5): self.initISIF(p1,p2,p3,p4) elif type(p1) == type("str"): self.initSNNN(p1) etc... def initISIF(anInt,aString,anotherInt,aFloat): pass def initSNNN(aString): pass Its a bit clunky but works for me... its like what you do in C++ when the automatic type promotion system breaks the overloading mechanism.... However that kind of constructor overloading should be used with great care or you wind up with class methods that are full of type conditionals: def aMethod(self,p1): if self.type = something: #do something stuff elif self.type == somethingelse # do something else Which is the antithesis of OOP and a maintenance nightmare. Usiakly the way to deal with class explosions is to define a function (or factory class) which takes the parameters in, figures out which kind of class you really need and hands you a pointer to it: class ShapeFactory: def __init__(....) def makeInstance(self,p1,p2,p3...): if type(p1) == type(2) and.... blah blah: return Rectangle(p1,p2,p3,p4) elif type.....: return Circle(p1,p2) elif.... And so on. Users then create a factory and request it to give them instances... Of course I may be misunderstanding the issues totally, like I said I have no experience of PyGeo... HTH, Alan g. Author of the 'Learning to Program' web site http://www.freenetpages.co.uk/hp/alan.gauld From shalehperry@attbi.com Tue Sep 3 16:33:15 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 08:33:15 -0700 Subject: [Tutor] Parsing iptables log files In-Reply-To: <20020903143403.GD23594@onix> References: <20020902160616.GA16558@onix> <20020903074722.GA22515@onix> <20020903143403.GD23594@onix> Message-ID: <200209030833.15433.shalehperry@attbi.com> On Tuesday 03 September 2002 07:34, Amaya Rodrigo Sastre wrote: > I see my web server is giving timeouts, so I moved the log and script t= o > http://www.lared.es/~amayita/python/ in case you want to take a look at > it. Sorry for all the noise. >>> already_read =3D [] >>> already_read [] >>> already_read.append(0) >>> already_read [0] as you can see .append(0) made already_read[0] =3D 0, no reason to do it = by hand=20 again. You are getting: Traceback (most recent call last): File "./amaya.py", line 103, in ? if (already_read[j] =3D=3D 0): IndexError: list index out of range because you are accessing already_read[1] which does not exist, your scri= pt=20 only creates the [0] entry. I see nothing obviously wrong with the commented out regex section it is=20 actually failing later in the script. From arodrigo@genasys.com Tue Sep 3 16:43:09 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: 03 Sep 2002 17:43:09 +0200 Subject: [Tutor] Parsing iptables log files In-Reply-To: <200209030833.15433.shalehperry@attbi.com> References: <20020902160616.GA16558@onix> <20020903074722.GA22515@onix> <20020903143403.GD23594@onix> <200209030833.15433.shalehperry@attbi.com> Message-ID: <1031067790.24098.6.camel@onix.genasys> On Tue, 2002-09-03 at 17:33, Sean 'Shaleh' Perry wrote: > as you can see .append(0) made already_read[0] = 0, no reason to do it by hand > again. Good, I was doing that to force it to get in the loop, oh God :-) > because you are accessing already_read[1] which does not exist, your script > only creates the [0] entry. Thank you, that's exactly what it was hard for me to see... > I see nothing obviously wrong with the commented out regex section it is > actually failing later in the script. Well, it also helps that I realized that the log file was wrong and uploaded a better file. And it's still Tuesday ;-) Thanks for your time... -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From ajs@ix.netcom.com Tue Sep 3 16:42:17 2002 From: ajs@ix.netcom.com (Arthur) Date: Tue, 3 Sep 2002 11:42:17 -0400 Subject: [Tutor] Java and Python (was: Iterators) References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D8@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <000f01c25360$7c2599c0$9865fea9@arthur> > Could. Doesn't mean you should. > I'm curious because although the ability to have multiple > constructors(al la Delphi) is something I'd like in Python, > overloading of constructors is rarely an issue since in > Python everything is an object so I can pass in whatever > I like. Combined with default args its just not an issue > for me. > Why can't you just define say 6 or 7 parameters, give them > defaults and then check the types of the arguments at runtime > calling out to the rquired init function as appropriate? > > class C: > def __init__(self,p1=None,p2=None,p3=None,p4=None) > if type(p1) == type(1) and type(p2) == type("string") \ > and type(p3 == type(7) and type(p4) == type(0.5): > self.initISIF(p1,p2,p3,p4) > elif type(p1) == type("str"): > self.initSNNN(p1) > etc... > def initISIF(anInt,aString,anotherInt,aFloat): > pass > def initSNNN(aString): > pass > > Its a bit clunky but works for me... its like what you do > in C++ when the automatic type promotion system breaks > the overloading mechanism.... Well, for one thing, I'm trying to come up with something I can consider to be modular, in that what I am doing is in a constant state of refactoring and flux. Ideally, I add to or amend the list of signature lists, and am largely home. Also, I am in the land of new style classes, so type testing doens't seem to be the way - but I guess your point works as well with issinstance and issubclass. > However that kind of constructor overloading should be > used with great care or you wind up with class methods > that are full of type conditionals: > > def aMethod(self,p1): > if self.type = something: > #do something stuff > elif self.type == somethingelse > # do something else > > Which is the antithesis of OOP and a maintenance nightmare. > > Usiakly the way to deal with class explosions is to define a > function (or factory class) which takes the parameters in, > figures out which kind of class you really need and hands > you a pointer to it: > > class ShapeFactory: > def __init__(....) > def makeInstance(self,p1,p2,p3...): > if type(p1) == type(2) and.... blah blah: > return Rectangle(p1,p2,p3,p4) > elif type.....: > return Circle(p1,p2) > elif.... > > And so on. > > Users then create a factory and request it to give > them instances... Aah, I've heard talk of "factory functions". Now I have a clue what we are talking about. > > Of course I may be misunderstanding the issues totally, > like I said I have no experience of PyGeo... > Or more likely, I'm misunderstanding what my options might be. Thanks for some clues. Art From erikprice@mac.com Tue Sep 3 17:04:45 2002 From: erikprice@mac.com (Erik Price) Date: Tue, 3 Sep 2002 12:04:45 -0400 Subject: Factory classes (was: Re: [Tutor] Java and Python (was: Iterators)) In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8D8@mbtlipnt02.btlabs.bt.co.uk> Message-ID: On Tuesday, September 3, 2002, at 10:35 AM, alan.gauld@bt.com wrote: > Usiakly the way to deal with class explosions is to define a > function (or factory class) which takes the parameters in, > figures out which kind of class you really need and hands > you a pointer to it: What is a factory class? I have seen this term before, but I'm not sure how it is different from any other class. Don't all class definitions create instances for you (handing you a reference to the instance)? Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From shalehperry@attbi.com Tue Sep 3 17:13:57 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 09:13:57 -0700 Subject: [Tutor] Parsing iptables log files In-Reply-To: <1031067790.24098.6.camel@onix.genasys> References: <20020902160616.GA16558@onix> <200209030833.15433.shalehperry@attbi.com> <1031067790.24098.6.camel@onix.genasys> Message-ID: <200209030913.57569.shalehperry@attbi.com> On Tuesday 03 September 2002 08:43, Amaya Rodrigo Sastre wrote: > > And it's still Tuesday ;-) > > Thanks for your time... Another suggestion: Why not extend your regex slightly instead of using both a regex and spli= t? match_pat =3D re.compile(r'(SRC=3D[0-9.]+)[\t ](DST=3D[0-9.]+)[\t ](.*TCP= |UDP)[\t=20 ](SPT=3D[0-9]+)[\t ](DPT=3D[0-9]+)[\t ](SEQ=3D[0-9]+)[\t ](ACK=3D[0-9]+)'= ) is your current regex. if you add '(\w{3}\s\d{1,2}\s\d{1,2}:\d{2}:\d{2}).+' to the front of your= =20 regex you can catch the date/time as well in one group. The {} syntax specifies a number of repititions. So {3} means '3 of thes= e'=20 and {1,2} means at least 1 up to 2. So {1,7} would mean at least one but= no=20 more than 7. \s means 'whitespace' and is generally better than [\t ]. \d means a number and is better than [0-9]. From shalehperry@attbi.com Tue Sep 3 17:15:05 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 09:15:05 -0700 Subject: Factory classes (was: Re: [Tutor] Java and Python (was: Iterators)) In-Reply-To: References: Message-ID: <200209030915.05184.shalehperry@attbi.com> On Tuesday 03 September 2002 09:04, Erik Price wrote: > On Tuesday, September 3, 2002, at 10:35 AM, alan.gauld@bt.com wrote: > > Usiakly the way to deal with class explosions is to define a > > function (or factory class) which takes the parameters in, > > figures out which kind of class you really need and hands > > you a pointer to it: > > What is a factory class? I have seen this term before, but I'm not > sure how it is different from any other class. Don't all class > definitions create instances for you (handing you a reference to the > instance)? > A factory makes something other than itself. A car factory is a place wh= ere=20 cars are made, not more car factories. From arodrigo@genasys.com Tue Sep 3 17:42:20 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: 03 Sep 2002 18:42:20 +0200 Subject: [Tutor] Parsing iptables log files In-Reply-To: <200209030913.57569.shalehperry@attbi.com> References: <20020902160616.GA16558@onix> <200209030833.15433.shalehperry@attbi.com> <1031067790.24098.6.camel@onix.genasys> <200209030913.57569.shalehperry@attbi.com> Message-ID: <1031071341.24057.9.camel@onix.genasys> On Tue, 2002-09-03 at 18:13, Sean 'Shaleh' Perry wrote: > Why not extend your regex slightly instead of using both a regex and split? Thanks so much! On the other hand I can't still make my already_read get in the loop, no matter what I try... How can I? -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From dyoo@hkn.eecs.berkeley.edu Tue Sep 3 18:28:40 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 3 Sep 2002 10:28:40 -0700 (PDT) Subject: [Tutor] Parsing iptables log files [regular expressions] In-Reply-To: <200209030913.57569.shalehperry@attbi.com> Message-ID: On Tue, 3 Sep 2002, Sean 'Shaleh' Perry wrote: > On Tuesday 03 September 2002 08:43, Amaya Rodrigo Sastre wrote: > > > > And it's still Tuesday ;-) > > > > Thanks for your time... > > Another suggestion: > > Why not extend your regex slightly instead of using both a regex and split? > > match_pat = re.compile(r'(SRC=[0-9.]+)[\t ](DST=[0-9.]+)[\t ](.*TCP|UDP)[\t > ](SPT=[0-9]+)[\t ](DPT=[0-9]+)[\t ](SEQ=[0-9]+)[\t ](ACK=[0-9]+)') Hi Amaya, By the way, Python and Perl both support a "verbose" form of regular expressions that might help make your regular expression a little easier to look at. In Python, we can turn on verbosity by sending in the re.VERBOSE flag when we prepare the regular expression: ### match_pat = re.compile(r'''(SRC=[0-9.]+) [\t ] (DST=[0-9.]+) [\t ] (.*TCP|UDP) [\t ] (SPT=[0-9]+) [\t ] (DPT=[0-9]+) [\t ] (SEQ=[0-9]+) [\t ] (ACK=[0-9]+)''', re.VERBOSE) ### It doesn't directly fix your program, but it may make it easier to debug or improve your regular expression in the future. Good luck! From shalehperry@attbi.com Tue Sep 3 18:30:22 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 10:30:22 -0700 Subject: [Tutor] Parsing iptables log files In-Reply-To: <1031071341.24057.9.camel@onix.genasys> References: <20020902160616.GA16558@onix> <200209030913.57569.shalehperry@attbi.com> <1031071341.24057.9.camel@onix.genasys> Message-ID: <200209031030.22494.shalehperry@attbi.com> --------------Boundary-00=_MYHV1E123P8FS7XBPY37 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On Tuesday 03 September 2002 09:42, Amaya Rodrigo Sastre wrote: > On Tue, 2002-09-03 at 18:13, Sean 'Shaleh' Perry wrote: > > Why not extend your regex slightly instead of using both a regex and > > split? > > Thanks so much! > > On the other hand I can't still make my already_read get in the loop, n= o > matter what I try... How can I? Here is a rough take at a different approach to your script. You should = be=20 able to make it work from here. --------------Boundary-00=_MYHV1E123P8FS7XBPY37 Content-Type: text/x-python; charset="iso-8859-1"; name="shaleh.py" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="shaleh.py" #!/usr/bin/python import re ## # note the different approach to various parts of your regex ## pattern = re.compile(r'(\w+\s\d+\s\d+:\d+:\d+).+SRC=([\d.]+)\s+DST=([\d.]+)\s+(?:.*?TCP|UDP)\s+SPT=(\d+)\s+DPT=(\d+)\s+SEQ=(\d+)\s+ACK=(\d+)') def time2sec(my_time): my_time = my_time.split(":") return int(my_time[2]) + int(my_time[1]) * 60 + \ int(my_time[0]) * 360 # let's use a dictionary of requests requests = {} my_file = open('amaya') for line in my_file.xreadlines(): match = pattern.search(line) if not match: continue date = match.group(1) src_addr = match.group(2) dst_addr = match.group(3) src_port = int(match.group(4)) dst_port = int(match.group(5)) seq = match.group(6) # seq and ack are too big for int, they ack = match.group(7) # need long, so i left them as strings print match.groups() # for debugging if src_port > 1024 and long(ack) == 0: # the final zero will be used to keep a running tally of time spent # which is why I use a list and not a tuple here requests[seq] = [date, src_addr, dst_addr, src_port, dst_port, 0] elif requests.has_key(ack) and \ dst_port == requests[ack][3] and src_port == requests[ack][4] and \ dst_addr == requests[ack][1] and src_addr == requests[ack][2]: # the above check is very pedantic to ensure we are using the # correct request t1 = time2sec(requests[ack][0]) t2 = time2sec(date) requests[ack][5] += t2 - t1 # needs an else to catch what the above to miss, I do not understand # the problem well enough to write it my_file.close() for key in requests.keys(): print requests[key][1], requests[key][5] --------------Boundary-00=_MYHV1E123P8FS7XBPY37-- From buc40@bemail.org Tue Sep 3 19:00:24 2002 From: buc40@bemail.org (S A) Date: Tue, 3 Sep 2002 11:00:24 -0700 Subject: [Tutor] ok Message-ID: <200209031800.g83I0Ou16757@mail15.bigmailbox.com> I get the following when I run the program: found close Connected for 40 found close Connected for 197 found close Connected for 228 found close Connected for 43 Is this what you are looking for? What problems are you having? A little more data and we will see if we can help you some. Thanks. SA >Reply-To: "Morne" > "Morne" "python tutor" [Tutor] okDate: Tue, 3 Sep 2002 12:22:01 +0200 > >ok my log file is saved in C:\my documents\ppp.log > >Can you run the program on you python and see where i went wrong. > > > >import re >import string > >secondsMatcher=re.compile("Connect time: (\d+) secs") > >def getStuff(file): > closeline = 0 > errorcount = 0 > secondscount = 0 > connectcount = 0 > data_outcount = 0 > data_incount = 0 > ppplist = file.readlines() > > for line in ppplist: > > if string.find(line,"LayerUp") >= 0: > connectline = string.split(line) > connectcount = connectcount + 1 > > elif string.find(line,"ERROR") >= 0: > print "found error" > errorcount = errorcount + 1 > > elif string.find(line,"Connect time") >= 0: > print "found close" > connectSecs=secondsMatcher.search(line).group(1) > print "Connected for",connectSecs > closeline = string.split(line) > secondscount = secondscount + string.atoi(connectSecs) > >def main(): > f=open("C:\my documents\ppp.log","r") > getStuff(f) > return None > >if __name__=="__main__": > main() > > ><< msg2.html >> ><< ppp.log >> "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From smith@rfa.org Tue Sep 3 21:06:37 2002 From: smith@rfa.org (smith@rfa.org) Date: Tue, 3 Sep 2002 16:06:37 -0400 Subject: [Tutor] python xml entity problem Message-ID: <20020903160637.B26435@jeve.org> I'm interested in parsing a xml file using the python tools in debian woody. Everything seems to be ok until I reach a "&MAN;" My python script just passes over it. My guess is that I have a external entity resolver problem. I've been reading the Python XML book on O'reilly and I believe I'm doing the right things. At least in terms of non external entities. Does anybody have any examples or how can I make the program recognize external entity. I'm still very new to python and xml so maybe it's something I don't understand. The xml file starts off with something like this: http://something/MAN/2000/02/test.mp3 2000/02/02 16:00 &MAN; 00:70:00 archive AW AW XZ The dtd looks something like this: oh yeah, this is what I'm calling in the beginning of the python script: from xml.dom.ext.reader.Sax2 import FromXmlStream from xml.sax import xmlreader import sys Your input is appreciated thanks. -Smith From willis@oxy.edu Tue Sep 3 21:16:26 2002 From: willis@oxy.edu (Jason Willis) Date: Tue, 3 Sep 2002 13:16:26 -0700 Subject: [Tutor] Python Books Message-ID: <20020903131626.74a71a21.willis@oxy.edu> Hello, I was wondering which books anyone would recommend for a beginner in Python programming? I've browsed through some of the books -- but I'm not sure which might carry me through beginner to intermediate (or so) levels. Thanks for the help. (Sorry if this question has been asked and answered so many times already) Jason W. From buc40@bemail.org Tue Sep 3 21:29:58 2002 From: buc40@bemail.org (S A) Date: Tue, 3 Sep 2002 13:29:58 -0700 Subject: [Tutor] Python Books Message-ID: <200209032029.g83KTwX17873@mail17.bigmailbox.com> "Learning Python". Another wonderful Oreily Book. Good Luck. SA > Jason Willis tutor@python.org [Tutor] Python BooksDate: Tue, 3 Sep 2002 13:16:26 -0700 > >Hello, > > I was wondering which books anyone would recommend for a beginner in Python programming? I've browsed through some of the books -- but I'm not sure which might carry me through beginner to intermediate (or so) levels. Thanks for the help. (Sorry if this question has been asked and answered so many times already) > > Jason W. > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From aicolburn@yahoo.com Tue Sep 3 23:22:27 2002 From: aicolburn@yahoo.com (Alan Colburn) Date: Tue, 3 Sep 2002 15:22:27 -0700 Subject: [Tutor] A Book for People Like Me Message-ID: <00e601c25398$63274e90$cae68b86@fo5132> I know it's fairly common, and understandable, for folks to ask this list for suggestions about books. I guess it's my turn :-) Rather than asking for a general "good" book, I'm looking for suggestions for particular types of books. At this stage I'd call myself an advanced beginner--I need help with things like understanding OOP concepts, creating GUIs, Python on the web, etc. Here's the important part, though: My learning style is such that the best books, for me personally, have a couple common attributes. Language is key. I understand concepts, but I have a lot of difficulty with the specialized vocabulary of programming. It's a major stumbling block, for me, with some of the Python documentation for example. It's also a reason I've had such difficulty with OOP. So, I hope to find a text that uses a minimum of jargon, whose author carefully explains the specialized terms (s)he uses. In addition, I find exercises helpful. Hands-on exercises help me learn, and turn passive reading into a more active process. It doesn't matter whether the exercises are at the end of a chapter or interspersed within. (As a side point, for complete beginners looking for exercises, I recommend http://bembry.org/tech/python/index.shtml It's a great resource that I haven't seen discussed on this list in the month or two I've been a member.) Sorry for talking about me so much . . . I'm hoping there's others out there who are similar who'll also benefit by folks suggestions :-) Thanks, as always -- Al From magnus@thinkware.se Tue Sep 3 23:34:27 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 04 Sep 2002 00:34:27 +0200 Subject: [Tutor] Python Books In-Reply-To: <20020903131626.74a71a21.willis@oxy.edu> Message-ID: <5.1.0.14.0.20020904003243.02b65e90@www.thinkware.se> At 13:16 2002-09-03 -0700, Jason Willis wrote: >Hello, > > I was wondering which books anyone would recommend for a beginner= =20 > in Python programming? I've browsed through some of the books -- but I'm= =20 > not sure which might carry me through beginner to intermediate (or so)=20 > levels. Thanks for the help. (Sorry if this question has been asked and= =20 > answered so many times already) Are you experienced in programming in any other language? Besides browsing some books (which btw) how much have you actually programmed in Python? --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From dyoo@hkn.eecs.berkeley.edu Wed Sep 4 00:21:41 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 3 Sep 2002 16:21:41 -0700 (PDT) Subject: [Tutor] python xml entity problem [xml parsing and DTD handling] In-Reply-To: <20020903160637.B26435@jeve.org> Message-ID: On Tue, 3 Sep 2002 smith@rfa.org wrote: > I'm interested in parsing a xml file using the python tools in debian > woody. Everything seems to be ok until I reach a "&MAN;" My python > script just passes over it. My guess is that I have a external entity > resolver problem. I've been reading the Python XML book on O'reilly and > I believe I'm doing the right things. At least in terms of non external > entities. Does anybody have any examples or how can I make the program > recognize external entity. I'm still very new to python and xml so maybe > it's something I don't understand. Hi Smith, Yikes. The documentation on Python and XML, in my opinion, is just absolutely hideous; most of the documentation assumes that you want to write this stuff in Java, which is just, well, lazy! Even the 'Python & XML' book minimally touches external references. Forgive me for the rant; I'm just so frustrated by the lack of documentation in this area. It just seems that the documentation and examples could be greatly improved. Perhaps we can do an xml-parsing thing this week and send our examples over to the PyXML folks... Hmmmm.) For XML processing with DTD's to work well, it appears that you need to give the address of a real DTD --- otherwise, I think the system will just ignore external references outright! The line: should be changed to point to a real url that your system can find --- xml.sax will use the 'urllib' module to grab DTD information from this, so it's not enough to put a fill-me-in sort of thing: the DTD url has to be real. Also, there's a bug on line 3 of your DTD: You need a space between the element name and the open parenthesis character. Doh! *grin* Once we make those fixes, then everything should be ok. I've written an example that uses a DTD that's embedded in the xml, so that the system doesn't have to try looking for it online. ###### import xml.sax xml_text = \ """ ]> http://something/MAN/2000/02/test.mp3 2000/02/02 16:00 &MAN; 00:70:00 archive AW AW XZ """ class MyContentHandler(xml.sax.handler.ContentHandler): def __init__(self): xml.sax.handler.ContentHandler.__init__(self) self.indent = 0 def startElement(self, name, attrs): self.printIndent() print "I see the start of", name self.indent += 4 def endElement(self, name): self.indent -= 4 self.printIndent() print "I see the end of", name def characters(self, text): if text.strip(): self.printIndent() print "I see characters", repr(text) pass def printIndent(self): print " " * self.indent, if __name__ == '__main__': parser = xml.sax.make_parser() handler = MyContentHandler() parser.setContentHandler(handler) parser.feed(xml_text) parser.close() ####### I hope this helps! If you have more questions, please feel free to ask. From scot@possum.in-berlin.de Wed Sep 4 00:32:31 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Wed, 4 Sep 2002 01:32:31 +0200 Subject: [Tutor] Re: Factory classes In-Reply-To: References: Message-ID: <200209040132.31219.scot@possum.in-berlin.de> Hi, > What is a factory class? I have seen this term before, but I'm not > sure how it is different from any other class. Don't all class > definitions create instances for you (handing you a reference to the > instance)? Let's see if I understand factories by trying to explain them [note to Erik and others: Before you believe _any_ of this, wait and see what the real programmers say ]: A factory function or class produces objects depending on the parameters given to it, the same way a real factory will produce different kinds of, say, bicycles, depending on what color, size, or type you want. You use a factory function when you know that you are going to need an object of a certain type - but not of which subtype - when you write the program. This is sort of like building a bicycle factory, but not knowing if red or green will be the favorite color next year. So you give the factory the ability to retool on the fly, that is, produce either a green or red bicycle depending on the demand. My attempt at writing a factory function would be something like this (Python 2.2, I am not sure about older versions because I'm subclassing "object" here): ============================================= class spraycan_factory(object): """Produce spraycan objects that paint walls""" class spraycan(object): """This is what we build in the factory""" # Fill me up with a color when I am manufactured def __init__(self, color): self.color = color # Spray my color all over when I am called def __call__(self): print 'Psssss! Your wall is now %s' % self.color # Return a spraycan of the color required def __call__(self, color='white'): new_can = self.spraycan(color) return new_can =============================================== With this behaviour (file is "factory.py"): =============================================== Python 2.2 (#1, Mar 26 2002, 15:46:04) [GCC 2.95.3 20010315 (SuSE)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import factory >>> can_plant = factory.spraycan_factory() >>> can_plant >>> can1 = can_plant('blue') >>> can1 >>> can1() Psssss! Your wall is now blue >>> can2 = can_plant('red') >>> can2() Psssss! Your wall is now red >>> can3 = can_plant() >>> can3() Psssss! Your wall is now white =============================================== The term itself is out of a book called "Design Patterns: Elements of Reusuable Object-Orientated Software" by four gentlemen named Gamma, Helm, Johnson and Vlissides. It seems to be required reading for Real Computer Scientists: Stand next to one at a cocktail party for long enough, and sooner or later, they'll start talking about "the gang of four"... Well, at least that's how I understand factories. Now if somebody could tell me if any of this is actually correct, I'd feel much better =8). Y, Scot -- Scot W. Stevenson wrote me on Wednesday, 4. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1869 hours and has a CPU that is falling asleep at a system load of 0.00. From shalehperry@attbi.com Wed Sep 4 00:37:06 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 16:37:06 -0700 Subject: [Tutor] Re: Factory classes In-Reply-To: <200209040132.31219.scot@possum.in-berlin.de> References: <200209040132.31219.scot@possum.in-berlin.de> Message-ID: <200209031637.06332.shalehperry@attbi.com> On Tuesday 03 September 2002 16:32, Scot W. Stevenson wrote: > > Well, at least that's how I understand factories. Now if somebody could > tell me if any of this is actually correct, I'd feel much better =3D8). > > Y, Scot yeah, you got it pretty much right. One side comment. def foo(): result =3D computation() return result is a little silly just write 'return computation()'. In several language= s=20 (not sure about python) writing the code this way allows the compiler to=20 optimize the function call so that the return result is written directly = into=20 the caller's stack so no actual return is executed which means faster, mo= re=20 efficient function calls. From shalehperry@attbi.com Wed Sep 4 00:41:25 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 16:41:25 -0700 Subject: [Tutor] A Book for People Like Me In-Reply-To: <00e601c25398$63274e90$cae68b86@fo5132> References: <00e601c25398$63274e90$cae68b86@fo5132> Message-ID: <200209031641.26001.shalehperry@attbi.com> On Tuesday 03 September 2002 15:22, Alan Colburn wrote: > I know it's fairly common, and understandable, for folks to ask this li= st > for suggestions about books. I guess it's my turn :-) Rather than askin= g > for a general "good" book, I'm looking for suggestions for particular t= ypes > of books. At this stage I'd call myself an advanced beginner--I need he= lp > with things like understanding OOP concepts, creating GUIs, Python on t= he > web, etc. > > Here's the important part, though: My learning style is such that the b= est > books, for me personally, have a couple common attributes. Language is = key. > I understand concepts, but I have a lot of difficulty with the speciali= zed > vocabulary of programming. It's a major stumbling block, for me, with s= ome > of the Python documentation for example. It's also a reason I've had su= ch > difficulty with OOP. So, I hope to find a text that uses a minimum of > jargon, whose author carefully explains the specialized terms (s)he use= s. > Find an OOP book or two which are language neutral. As mentioned in the=20 factory class thread the book "Design Patterns: Elements of=20 Reusuable Object-Orientated Software" by Gamma, Helm, Johnson and Vlissid= es is an important one to read because it helps build the vocabulary required t= o=20 talk about OO programming. It has smalltalk, c++ and other examples in i= t=20 but largely it talks about the thought process of coding. After that I liked the book "Pragmatic Programmer". Just an all around "= I=20 have been there and done that for 20 years, learn from my experience" typ= e=20 book. From erikprice@mac.com Wed Sep 4 05:45:16 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 00:45:16 -0400 Subject: [Tutor] Python Books In-Reply-To: <20020903131626.74a71a21.willis@oxy.edu> Message-ID: <1BB5D794-BFC1-11D6-B926-00039351FE6A@mac.com> On Tuesday, September 3, 2002, at 04:16 PM, Jason Willis wrote: > I was wondering which books anyone would recommend for a beginner in > Python programming? I've browsed through some of the books -- but I'm > not sure which might carry me through beginner to intermediate (or so) > levels. Thanks for the help. (Sorry if this question has been asked > and answered so many times already) I like the Python Essential Reference. It is not a tutorial, but rather a reference book, but if you read it straight through you will learn a lot about Python and it's not too long. Mind you it does not teach you how to write programs, you need to know this already. But it's easier on the eyes than the docs online. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From erikprice@mac.com Wed Sep 4 05:46:57 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 00:46:57 -0400 Subject: [Tutor] A Book for People Like Me In-Reply-To: <00e601c25398$63274e90$cae68b86@fo5132> Message-ID: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> On Tuesday, September 3, 2002, at 06:22 PM, Alan Colburn wrote: > Here's the important part, though: My learning style is such that the > best > books, for me personally, have a couple common attributes. Language is > key. > I understand concepts, but I have a lot of difficulty with the > specialized > vocabulary of programming. It's a major stumbling block, for me, with > some > of the Python documentation for example. It's also a reason I've had > such > difficulty with OOP. So, I hope to find a text that uses a minimum of > jargon, whose author carefully explains the specialized terms (s)he > uses. The best book I have seen for complete beginners on OOP is unquestionably "Beginning Java Objects" by Jackie Barker (published by Wrox). I always recommend it to anyone who wants to learn about object oriented programming fundamentals. First, and most importantly, you can forget that it has the word "Java" in its title. Really, read this book. It provides a platform- and language-independent introduction to the fundamental concepts of OOP, explaining each of these terms carefully and then using them so that soon terms like "implementation", "subclass", "aggregation", and "method" become second nature to you. The book is divided into thirds. The first third of the book is a (language-independent) introduction to OOP concepts. There is one chapter that is specific to Java, just skip over it since you are using Python. Then the second third of the book is an introduction to object oriented design and modelling. Again, don't worry that you aren't learning Java -- it isn't used in this section either. Only the final third of the book actually involves Java. If you read the first two thirds of this book, you will be ready to tackle more advanced books that assume familiarity with OOP. But it is definitely aimed at beginners -- if you are already comfortable with the concepts of OOP and are just looking for books that teach how to be a better modeller, I don't know of any yet (that "Design Patterns" book by Gamma and the others seems to come up all the time, too bad it's so expensive). Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From shalehperry@attbi.com Wed Sep 4 05:59:47 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 3 Sep 2002 21:59:47 -0700 Subject: [Tutor] A Book for People Like Me In-Reply-To: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> References: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> Message-ID: <200209032159.47782.shalehperry@attbi.com> On Tuesday 03 September 2002 21:46, Erik Price wrote: > > If you read the first two thirds of this book, you will be ready to > tackle more advanced books that assume familiarity with OOP. But it is > definitely aimed at beginners -- if you are already comfortable with > the concepts of OOP and are just looking for books that teach how to be > a better modeller, I don't know of any yet (that "Design Patterns" book > by Gamma and the others seems to come up all the time, too bad it's so > expensive). > > Yeah, it is expensive and so are all of the Addison Wesley books. The ma= in=20 selling point is that almost all of them are good enough that numerous=20 colleges use them as required texts for classes. And as we all know coll= ege=20 texts are not cheap either. "Today's book about tomorrow's language" is only good today. A decent bo= ok on=20 OO will last at least until the next paradigm is deeply entrenched (-: =20 Besides you can sell it back to a used book salesman. They love addison=20 wesley books. In fact try to find a copy of "Design Patterns" or any of = W.=20 Richard Stevens's books used. Erik this is less aimed at you and more at the newer readers of the list.= =20 Don't want to scare them off with cost. From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_002E_01C253F2.E51D7820 Content-Type: multipart/alternative; boundary="----=_NextPart_001_002F_01C253F2.E51D7820" ------=_NextPart_001_002F_01C253F2.E51D7820 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Could someone please help me with this? Im really new to any kind of programming and the people at python.org return my messages in some other code :not python(lol)The people there = are cool I just dont seem to understand there answers.If posible would you = be able to answer in detail. is it wrong of me to send the ppp.log file to just anyone? HERE IS WHAT I HAVE: import re import string secondsMatcher=3Dre.compile("Connect time: (\d+) secs") def getStuff(file): closeline =3D 0 errorcount =3D 0 secondscount =3D 0 connectcount =3D 0 data_outcount =3D 0 data_incount =3D 0 ppplist =3D file.readlines() for line in ppplist: if string.find(line,"LayerUp") >=3D 0: print "found connect" connectline =3D string.split(line) connectcount =3D connectcount + 1 elif string.find(line,"ERROR") >=3D 0: print "found error" errorcount =3D errorcount + 1 elif string.find(line,"Connect time") >=3D 0: print "found close" connectSecs=3DsecondsMatcher.search(line).group(1) print "Connected for",connectSecs closeline =3D string.split(line) secondscount =3D secondscount + string.atoi(connectSecs) def main(): f=3Dopen("C:/my documents/ppp.log","r") getStuff(f) return None if __name__=3D=3D"__main__": main() THIS IS WHAT I NEED THE PROGRAM TO DO: I want the program to read the attached ppp.log file and give me the following type of report: PPP Log file summary for 5 Jul 2002 ----------------------------------- Jul 5 18:15:01 Connected to internet (IP 155.239.150.146) Jul 5 18:18:08 Closed connection. ( Connect time: 197 secs: 5091 octets = in, 1864 octets out ) ----------------------------------- Successful connections: 5 Failed connections: 2 Total time online: 456 seconds Total data in: 66576 octets Total Data out: 66349 octets ------=_NextPart_001_002F_01C253F2.E51D7820 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Could someone please help me with=20 this?

Im really new to any kind of = programming and=20 the people at python.org
return my messages in some other code :not=20 python(lol)The people there are
cool I just dont seem to understand = there=20 answers.If posible would you be
able to answer in detail.

is = it wrong=20 of me to send the ppp.log file to just anyone?

HERE IS WHAT I=20 HAVE:

import re
import=20 string

secondsMatcher=3Dre.compile("Connect time: (\d+) = secs")

def=20 getStuff(file):
    closeline =3D = 0
   =20 errorcount =3D 0
    secondscount =3D = 0
   =20 connectcount =3D 0
    data_outcount =3D = 0
   =20 data_incount =3D 0
    ppplist =3D=20 file.readlines()

    for line in=20 ppplist:

      if = string.find(line,"LayerUp")=20 >=3D 0:
          = print "found=20 connect"
          = connectline =3D=20 string.split(line)
        &nb= sp;=20 connectcount =3D connectcount + 1

      = elif=20 string.find(line,"ERROR") >=3D=20 0:
          print = "found=20 error"
          = errorcount =3D=20 errorcount + 1

      elif=20 string.find(line,"Connect time") >=3D=20 0:
          print = "found=20 close"
         =20 connectSecs=3DsecondsMatcher.search(line).group(1)
   &= nbsp;     =20 print "Connected=20 for",connectSecs
         = ;=20 closeline =3D=20 string.split(line)
        &nb= sp;=20 secondscount =3D secondscount + string.atoi(connectSecs)

def=20 main():
    f=3Dopen("C:/my=20 documents/ppp.log","r")
    = getStuff(f)
   =20 return None

if __name__=3D=3D"__main__":
   =20 main()

THIS IS WHAT I NEED THE PROGRAM TO DO:

I want the = program=20 to read the attached ppp.log file and give me the
following type of=20 report:


PPP Log file summary for 5 Jul=20 2002
-----------------------------------
Jul  5 18:15:01 = Connected to=20 internet (IP 155.239.150.146)
Jul  5 18:18:08 Closed connection. = (=20 Connect time: 197 secs: 5091 octets in,
1864 octets out=20 )
-----------------------------------
Successful connections: = 5
Failed=20 connections: 2
Total time online: 456 seconds
Total data in: 66576 = octets
Total Data out: 66349 octets




------=_NextPart_001_002F_01C253F2.E51D7820-- ------=_NextPart_000_002E_01C253F2.E51D7820 Content-Type: application/octet-stream; name="ppp.log" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ppp.log" Jul 5 18:00:00 maxigate newsyslog[87300]: logfile turned over Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:15:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:15:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:34 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Req-Sent=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:15:37 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xfead050c=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 40 secs: 0 octets in, 265 octets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: : 1079435 = packets in, 231579 packets out=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: total 6 bytes/sec, = peak 21 bytes/sec on Fri Jul 5 18:15:40 2002=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:15:40 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 5 18:45:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 5 18:45:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 5 18:45:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 5 18:45:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Stopped=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(7) state =3D Req-Sent=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf83ad=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0xd52c5683=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(8) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x58cf933e=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(179) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(180) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(103) state =3D Closed=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(188) state =3D Req-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(9) state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(103) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = d52c5683 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(181) = state =3D Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(104) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.146=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(105) state =3D Ack-Sent=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.146 = hisaddr =3D 155.239.150.254=20 Jul 5 18:45:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 5 18:46:33 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: Idle timer expired=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerDown: = 155.239.150.146=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Command: maxigate: iface = clear=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = SendTerminateReq(106) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvTerminateAck(106) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: LayerFinish.=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: Connect time: 197 secs: = 5091 octets in, 1864 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: : 234569 packets in, = 230304 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: total 35 bytes/sec, = peak 815 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Terminate=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Stopped --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerDown=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = SendTerminateReq(180) state =3D Opened=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Opened --> Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: open -> lcp=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: = RecvTerminateAck(180) state =3D Closing=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: LayerFinish=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closing --> Closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Initial=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> logout = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: logout -> = hangup=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 228 secs: 6795 octets in, 2567 octets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: total 41 bytes/sec, = peak 840 bytes/sec on Fri Jul 5 18:48:48 2002=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 5 18:48:48 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 06:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 06:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Chat: Expect timeout=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Warning: Chat script failed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = hangup=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Disconnected! = Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: Connect time: = 43 secs: 0 octets in, 0 octets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: : 1079551 = packets in, 231625 packets out=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: total 0 bytes/sec, = peak 0 bytes/sec on Sat Jul 6 06:30:44 2002=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: deflink: hangup -> = closed=20 Jul 6 06:30:44 maxigate ppp[34607]: tun0: Phase: bundle: Dead=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = quit=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection dropped.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: Connected to local = client.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = set timeout 180=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> = opening=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> = dial=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 1 = of 1=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: = Client connection closed.=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^MAT^M^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M=20 Jul 6 08:30:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M=20 Jul 6 08:30:01 maxigate ppp[34607]: tun0: Chat: Send: = ATx1DT0860007249^M=20 Jul 6 08:30:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: = ATx1DT0860007249^M^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT = 33600/ARQ/V34/LAPM/V42BIS^M=20 Jul 6 08:30:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> = carrier=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: = CD detected=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> = login=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:23 maxigate ppp[34607]: tun0: LCP: deflink: State change = Closed --> Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Stopped=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:24 maxigate ppp[34607]: tun0: LCP: deflink: State change = Stopped --> Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc3012a=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:27 maxigate ppp[34607]: tun0: LCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:28 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigReq(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x00000000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MRU[4] 1500=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x0cd05494=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigReq(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = SendConfigAck(205) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACCMAP[6] 0x000a0000=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: AUTHPROTO[4] 0xc023 = (PAP)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: MAGICNUM[6] 0x5bc310bd=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: PROTOCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: ACFCOMP[2]=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvConfigAck(181) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: LayerUp=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(182) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Authenticate=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: his =3D PAP, = mine =3D none=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Output: itec79 = ********=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: Pap Input: SUCCESS ()=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: Using trigger address = 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: MPPE: Not usable without = CHAP81=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: = SendConfigReq(1) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: DEFLATE[4] win 15=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: PRED1[2] =20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: deflink: lcp -> open=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Phase: bundle: Network=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: FSM: Using "deflink" as = a transport=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Initial --> Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerStart.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(107) state =3D Closed=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Closed --> Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigReq(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigAck(204) state =3D Req-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Req-Sent --> Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: = RecvProtocolRej(206) state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: -- Protocol = 0x80fd (Compression Control Protocol) was rejected!=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: CCP: deflink: State change = Req-Sent --> Stopped=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigRej(107) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: Sending ident magic = 0cd05494 text user-ppp 2.3 (built Apr 26 2001)=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: LCP: deflink: SendIdent(183) = state =3D Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: COMPPROTO[6] 16 VJ = slots with slot compression=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] 0.0.0.0=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigNak(108) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] changing = address: 0.0.0.0 --> 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = SendConfigReq(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: IPADDR[6] = 155.239.150.26=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: PRIDNS[6] = 196.25.240.94=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: SECDNS[6] 196.25.1.9=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: = RecvConfigAck(109) state =3D Ack-Sent=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: State change = Ack-Sent --> Opened=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: deflink: LayerUp.=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: IPCP: myaddr 155.239.150.26 = hisaddr =3D 155.239.150.254=20 Jul 6 08:30:31 maxigate ppp[34607]: tun0: Command: maxigate: !bg = /usr/local/sys/linkup=20 Jul 6 08:31:32 maxigate ppp[34607]: tun0: Phase: deflink: HDLC errors = -> FCS: 2, ADDR: 0, COMD: 0, PROTO: 0=20 ------=_NextPart_000_002E_01C253F2.E51D7820-- From dyoo@hkn.eecs.berkeley.edu Wed Sep 4 09:14:16 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 4 Sep 2002 01:14:16 -0700 (PDT) Subject: [Tutor] My last In-Reply-To: <003301c253e2$26c11ea0$2500a8c0@maxitec.co.za> Message-ID: On Wed, 4 Sep 2002, Morne wrote: > Could someone please help me with this? > > Im really new to any kind of programming and the people at python.org > return my messages in some other code :not python(lol)The people there > are cool I just dont seem to understand there answers. If posible would > you be able to answer in detail. When we learn from each other, things have to go in two directions: you need to tell us exactly where we start sounding ludicrous. Many of us have done programming so long that things are beginning to look "obvious" to us. Beware us when that happens. *grin* We know that, all too easily, things that seem "obvious" aren't obvious at all. The thing is that we can't tell when we start sounding crazy, so you've got to wave your hands a bit wildly to bring us back down to Earth. When you hear a confusing answer, bring it up; perhaps someone here can put a light on it to make it less mysterious. > is it wrong of me to send the ppp.log file to just anyone? It's not "wrong" at all, and it's often really helpful. If it is a bit long, then it might be better to post it somewhere on the web and send us an url instead, to save bandwidth. An alternative is to just take a few lines of log that cover all the cases that are being tested for (connections, layers, errors, etc.) Maybe around 12 lines or so is good. It also helps because a smaller case is easier to check by hand. I've taken a look at your program: I don't see anything obviously wrong yet, but you may find it easier if you try for a slightly simpler program that works, before going after the whole problem. How about something like this? ### def getStuff(file): ppplist = file.readlines() for line in ppplist: print "I am looking at line", line if string.file(line, "connect time") >= 0: print "found close" connectSecs = secondsMatcher.search(line).group(1) print "Connected for", connectSecs def main(): f = open("C:/my documents/ppp.log", "r") getStuff(f) ### That is, just pay attention to 'connect time' lines in your program for now. I've also added a small "I am looking at blah" print statement, so you can trace out what's happening in the program. Does this do anything useful with your log? Do you get any errors, or does it skip all your log lines without doing anything? Let's get something working first: we can always add more to a working program. It's much harder to get a whole, fully-working program at first go: we often need to build toward it. From lep@aber.ac.uk Wed Sep 4 09:14:31 2002 From: lep@aber.ac.uk (Leighton Pritchard) Date: Wed, 04 Sep 2002 09:14:31 +0100 Subject: [Tutor] A Book for People Like Me Message-ID: <5.1.0.14.0.20020904090745.03aefdd8@pophost.aber.ac.uk> Erik wrote: >The best book I have seen for complete beginners on OOP is unquestionably >"Beginning Java Objects" by Jackie Barker (published by Wrox). I always >recommend it to anyone who wants to learn about object oriented >programming fundamentals. Absolutely. I was going to recommend this straight off, but Erik got there first... This book was suggested to me (as a beginner in OOP) by a colleague, and I found it fantastically easy to follow and understand, and it took me to a level where more jargon-filled OOP texts made sense. I have since recommended it to others, who've had similar good experiences with it. One major advantage of this book is that it doesn't just teach OOP, but gives an involved and understandable overview of the whole OOP design process, working from requirements. Although based around a specific example, the generalities are well-flagged. Those chapters continue to help me a great deal :) It's a great book. -- Dr Leighton Pritchard AMRSC T44, Cledwyn Building Institute of Biological Sciences University of Wales, Aberystwyth, SY23 3DD Tel 01970 622353 ext. 2353 PGP public key - http://www.keyserver.net (0x47B4A485) From charlie@begeistert.org Wed Sep 4 11:23:53 2002 From: charlie@begeistert.org (Charlie Clark) Date: Wed, 04 Sep 2002 10:23:53 +0000 Subject: [Tutor] Re: Python Books In-Reply-To: <20020903232606.14056.83679.Mailman@mail.python.org> References: <20020903232606.14056.83679.Mailman@mail.python.org> Message-ID: <20020904102353.770.2@gormenghast.1031133490.fake> On 2002-09-03 at 23:26:06 [+0000], you wrote: > Hello, > > I was wondering which books anyone would recommend for a beginner in > Python programming? I've browsed through some of the books -- but I'm > not sure which might carry me through beginner to intermediate (or so) > levels. Thanks for the help. (Sorry if this question has been asked a= nd > answered so many times already) > Hi Jason, I came to Python as complete beginner myself and can sympathise with you. I= think I should make a plug for Alan Gauld's online/offline resource which i= s listed with several others including Danny Yoo's introduction to IDLE http://www.python.org/doc/Newbies.html Both Alan and Danny are regulars on the list so you can ask them specific questions. I very much enjoyed "Learning Python" by Mark Lutz & David Ascher. It's a great introduction to programming in general and explains the Python way ve= ry well. There are exercises at the end of each chapter which is a good way to= get started. I've also just picked up "The Python Cookbook" which I've really enjoyed delving into because it discusses various approaches which helps one gain a= n understanding of why people like to program in Python. I think I now nearly= understand list comprehensions as a result! Charlie -- Charlie Clark Helmholtzstr. 20 D=1Asseldorf D- 40215 Tel: +49-211-938-5360 GSM: +49-178-782-6226 From dyoo@hkn.eecs.berkeley.edu Wed Sep 4 09:41:27 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 4 Sep 2002 01:41:27 -0700 (PDT) Subject: Factory classes (was: Re: [Tutor] Java and Python (was: Iterators)) In-Reply-To: Message-ID: On Tue, 3 Sep 2002, Erik Price wrote: > > On Tuesday, September 3, 2002, at 10:35 AM, alan.gauld@bt.com wrote: > > > Usiakly the way to deal with class explosions is to define a > > function (or factory class) which takes the parameters in, > > figures out which kind of class you really need and hands > > you a pointer to it: > > What is a factory class? I have seen this term before, but I'm not sure > how it is different from any other class. Don't all class definitions > create instances for you (handing you a reference to the instance)? Hi Erik, The Portland Patterns Repository collects descriptions of these nebulous design patterns. I did a quick search and found: http://c2.com/cgi/wiki?ClassFactory Admittedly, it's a little dense, and doesn't have enough Python. *grin* What may be even better for Python programmers might be Bruce Eckel's "Thinking In Python", which is an online book on exploring design patterns in Python: http://www.mindview.net/Books/TIPython In particular, Chapter 5 in Eckel's book talks about factories, and looks really nice. There are a few examples of factories in Python's standard library. One notorious one includes the xml.sax.make_parser() function that manufactures XML parser objects for us. make_parser() is a "factory function", http://c2.com/cgi/wiki?FactoryFunction http://www.python.org/doc/lib/module-xml.sax.html that will try its best to give us back a parser object. It's only purpose in life is to pick among several potential choices and give us something reasonable to work with. (But by default, I think it's only choice is the 'pyexpat' parser based on a C extension module. What makes make_parser() notorious is that, when people install Python on their own systems, they often forget to install expat, which means that make_parser() has no way of making an xml parser object for us.) The 'pyxml' project provides a few more implementations of XML parsers, as well as the '4suite' XML modules. As far as we're concerned, though, xml.sax.make_parser() manufactures us an xml parser object, and we usually shouldn't care exactly where it comes from or how it got constructed. Hope this helps! From magnus@thinkware.se Wed Sep 4 11:15:36 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 04 Sep 2002 12:15:36 +0200 Subject: [Tutor] Re: Factory classes (etc) In-Reply-To: <200209040132.31219.scot@possum.in-berlin.de> References: Message-ID: <5.1.0.14.0.20020904094606.02ae4690@www.thinkware.se> At 01:32 2002-09-04 +0200, Scot W. Stevenson wrote: >The term itself is out of a book called "Design Patterns: Elements of >Reusuable Object-Orientated Software" by four gentlemen named Gamma, Helm, >Johnson and Vlissides. Actually, the book "Design Patterns" (also called "the Gang of Four book" or GoF) describes the patterns "Abstract Factory" (or Kit) and "Factory Method" (Virtual Constructor). Not Factory Class. Googling for "factory pattern" will yield plenty of hits. The term "Factory Pattern" also floats around. See for instance http://java.sun.com/products/jdk/1.2/docs/guide/rmi/Factory.html . Sun writes: ``A factory, in this context, is a piece of software that implements one of the "factory" design patterns introduced in the book, Design Patterns, Elements of Reusable Object-Oriented Software.=B4=B4 Then they fail miserably in describing either pattern. :( Their "real world" examples describe the concept of any function or subroutine. It has nothing to do with any factory pattern. Sigh. I guess the problem is that the Factory patterns aren't based on any real world problem, but on a pure consequence of how object oriented programming languages are typically implemented: You typically get hold of an object by invoking a constructor method in a class object. If you want to be able to get instances of different classes depending on context, this won't work. You can't write: myVehicle =3D Car() or AirPlane() or Boat() or Rocket() depending on how and where I travel; Neither Java nor C++ accepts that. Syntax error! So you write: myVehicle =3D getVehicle() and the Factory Method getVehicle has to figure out what vehicle you need, depending on some kind of state. Maybe you pass an origin and a destination as parameters. (Maybe budget too. :) Your spray can example is neither an "Abstract Factory" nor a "Factory Method" I'm afraid. Both the "Abstract Factory" and "Factory Method" patterns return instances of _different_classes_ depending on the situation. The issue is not to pass parameters, but rather to instantiate different stuff depending on the situation. In your case you might as well call spraycan's constructor directly. The point is that if instances of different classes might be returned, you can't call a constructor directly. # Factory function for symmetrical shapes def getSymmetricalShape(x, y, size, corners=3D0, angle=3D0): assert type(corners) =3D=3D type(1) and (corners =3D=3D 0 or corners >= 1) if corners =3D=3D 0: return Circle(x, y, size) elif corners =3D=3D 2: return Line(x, y, size, angle) elif corners =3D=3D 3: return Triangle(x, y, size, angle) elif corners =3D=3D 4: return Square(x, y, size, angle) else: return RegularPolygon(x, y, size, sides, angle) for i in range(7): if i =3D=3D 1: continue shape =3D getSymmetricalShape(i*5, i*10, i*3+5, i) shape.fill(red) shape.paint() GoFs Factory Method Pattern goes beyond this factory function in that it wraps it in a class. Then you can subclass that class and have a slightly different factory method there. But that is of less relevance in Python than in C++ or Java. Inheriting is not as important in Python. An Abstract Factory provides an interface for creating families of related or dependent objects without specifying their concrete classes. For= instance, this might be useful in cross platform GUI toolkits. You write some code which works "everywhere" and "under the hood" different classes are=20 instantiated depending on what underlying GUI toolkit you use on a particular platform. A Factory Method is similar, but it only deals with one "product" which can be of different classes, not a whole "family" such as in the GUI toolkit case. An Abstract Factory might will use Factory Methods, but Factory= Methods can also be useful in other contexts. See http://www.c2.com/cgi/wiki?search=3DFactory for more info. (BTW, the Portland Pattern Repository Wiki http://www.c2.com/cgi/wiki is a great place to learn about programming.) See also http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86900 etc. >It seems to be required reading for Real Computer >Scientists: Stand next to one at a cocktail party for long enough, and >sooner or later, they'll start talking about "the gang of four"... Oh no. Real Computer Scientists don't go to cocktail parties! ;) It's not a bad book, but since Python is so dynamic, you can often solve the problems they try to solve with their pattern in a simpler way. To some extent GoF can be read as an example of how difficult life gets when you code in C++ or Java. This is a bit strange, since the Pattern movement (in software design) started among SmallTalkers, and SmallTalk is dynamically typed--I don't know enough SmallTalk to explain this. You typically use inheritance less to achieve polymorphism in python than in static languages such as Java and C++. In python, polymorphism doesn't require use of inheritance, and inheritance is no guarantee that= polymorphism will work since there is no static type checking. In python inheritance is used more to avoid duplication of code. An example: class Blue: def whatAmI(self): print "I'm cool blue" class Red: def whatAmI(self): print "I'm hot red" b =3D Blue() r =3D Red() for c in [b, r]: c.whatAmI() This will work, but if you change to: for c in [b, r, "Woops!"]: c.whatAmI() you will get a run time error. If we imagine that Python had static type checking similar to C++ or Java, you would have to do something strange like this: class Color: virtual def whatAmI(self) class Blue(Color): def whatAmI(self): print "I'm cool blue" class Red(Color): def whatAmI(self): print "I'm hot red" Blue b =3D Blue() Blue r =3D Red() for Color c in (Color)[b, r]: c.whatAmI() The compiler would like to check at compile time that nothing bad like the "Woops!" above would occur. It does this by making sure that c is of a class that provides the method whatAmI, that all objects that might be referred to by the variable c are instantiated by Color or a Color subclass (must be a subclass in this case since color is virtual) and by checking that the concrete Color subclasses actually implement whatAmI. It would also check that parameter lists for the method calls are compatible in the inheritance chain. In this simple example it's fairly obvious that it's easier for the programmer to check the validity of the program himself than write all the extra code that will make it possible for a compiler to check it. In larger systems this is disputed. Maybe most people favour static type checking. It eliminated a lot of simple (but possibly dangerous) errors, and it restrains programmers. (Whether that is good or bad depends on your perspective.) But it also makes the code bloated and makes some types of convenient operations very difficult. It will lead to duplication of code, extra concepts such as templates, interfaces and more complex inheritance structures. I'm not saying that the ideas in GoF are overly complex, but I think it would have been a much thinner book if the Gang of Four had used Python... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From erikprice@mac.com Wed Sep 4 13:37:01 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 08:37:01 -0400 Subject: [Tutor] Re: Factory classes In-Reply-To: Message-ID: <0294A6BC-C003-11D6-BB50-00039351FE6A@mac.com> On Wednesday, September 4, 2002, at 04:41 AM, Danny Yoo wrote: > Admittedly, it's a little dense, and doesn't have enough Python. > *grin* I agree. > What may be even better for Python programmers might be Bruce Eckel's > "Thinking In Python", which is an online book on exploring design > patterns > in Python: > > http://www.mindview.net/Books/TIPython > > In particular, Chapter 5 in Eckel's book talks about factories, and > looks > really nice. I had forgotten about this book. I was going to read it a while ago but I put it off to learn the basics of Python first. I am going to start reading it now. > There are a few examples of factories in Python's standard library. > One > notorious one includes the xml.sax.make_parser() function that > manufactures XML parser objects for us. make_parser() is a "factory > function", > > http://c2.com/cgi/wiki?FactoryFunction > http://www.python.org/doc/lib/module-xml.sax.html > > that will try its best to give us back a parser object. It's only > purpose > in life is to pick among several potential choices and give us > something > reasonable to work with. From all of the input on this list (thanks everyone), I think I've put together what a factory class is. It's a kind of tool which dynamically (at runtime) makes a decision and based on that decision instantiates a certain kind of class, which depends on the decision. But what I'm not entirely sure of is the why. When I first grokked the concept of OO it was from a script that Kirby Urner posted to this list, and then Alan Gauld explained polymorphism to me (I read that part of his tutor). Eventually I came to understand that one of the reasons that polymorphism is considered important is that you don't need to write code like this: if (object is this): do this else if (object is that): do that else if (object is another thing): do the other thing else: do yet some other thing Pardon me for saying it but it sounds like a Factory Class does something similar to the above! Is there something that I'm missing, or does the functionality of a Factory Class contradict the point of having similarly-named methods in different classes and subclasses so that we can use different kinds of objects in the same chunk of client code? popcorn.eat() apple.eat() sushi.eat() (Different objects altogether but all have an "eat()" method which can be called, ie in a loop.) Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From jostein.berntsen@sensewave.com Wed Sep 4 13:32:14 2002 From: jostein.berntsen@sensewave.com (Jostein Berntsen) Date: Wed, 4 Sep 2002 14:32:14 +0200 (CEST) Subject: [Fwd: Re: [Tutor] Python Books] Message-ID: <43737.136.164.222.31.1031142734.squirrel@to.server.sensewave.com> -------- Opprinnelig melding -------- Emne: Re: [Tutor] Python Books Fra: "Jostein Berntsen" Til: Hi, My three suggestions are: Practical Python - Magnus Lie Hetland Quick Python Book - D.Harms, Kenneth McDonald Visual Quickstart guide - Chris Fehily They are quite organized, and easy to follow step by step to get an understanding of the language. Regards, Jostein > Hello, > > I was wondering which books anyone would recommend for a beginner in > Python programming? I've browsed through some of the books -- but I'm > not sure which might carry me through beginner to intermediate (or so) > levels. Thanks for the help. (Sorry if this question has been asked > and answered so many times already) > > Jason W. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From magnus@thinkware.se Wed Sep 4 14:06:47 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 04 Sep 2002 15:06:47 +0200 Subject: [Tutor] Re: Factory classes In-Reply-To: <0294A6BC-C003-11D6-BB50-00039351FE6A@mac.com> References: Message-ID: <5.1.0.14.0.20020904144917.00be6ec0@www.thinkware.se> At 08:37 2002-09-04 -0400, Erik Price wrote: >When I first grokked the concept of OO it was from a script that Kirby=20 >Urner posted to this list, and then Alan Gauld explained polymorphism to=20 >me (I read that part of his tutor). Eventually I came to understand that= =20 >one of the reasons that polymorphism is considered important is that you=20 >don't need to write code like this: > >if (object is this): > do this >else if (object is that): > do that >else if (object is another thing): > do the other thing >else: > do yet some other thing > >Pardon me for saying it but it sounds like a Factory Class does something= =20 >similar to the above! We still use if-statements on object-oriented programming. In this case we create a slightly convoluted Factory so that the code will be simpler in the places where the Factory will be _used_. As I'm sure you know, polymorphism allows you to treat objects the same even if they belong to different classes. shape.paint() or shape.move(5, 6) regardless of if the variable "shape" might be an instance of the class Rectangle or Polygon or ShadowedSphere. You can say that factory functions and factory methods extend polymorphism to the creation phase of the variable which makes use of polymophism. Look at shape above. Where did that variable come from? If it can be of several different classes, how did that happen? It might have been passed in as a function or method parameter, but if it isn't it's likely that there is something like: if XXX: shape =3D Rectangle(...) elif XXX: shape =3D Circle(...) ... With a factory function you can avoid this. shape =3D getMyShape(...) Sure, there will be some if-statements in the definition of the factory function, but I don't think it will be so hairy. The main thing here is that the interesting thing where you actually do something substantial with your shape isn't littered with a lot of irrelevant object creation logic. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From ajs@ix.netcom.com Wed Sep 4 14:19:12 2002 From: ajs@ix.netcom.com (Arthur) Date: Wed, 4 Sep 2002 09:19:12 -0400 Subject: [Tutor] Re: Factory classes (etc) References: <5.1.0.14.0.20020904094606.02ae4690@www.thinkware.se> Message-ID: <002001c25415$a9cd5dd0$9865fea9@arthur> Magnus writes - >I guess the problem is that the Factory patterns aren't based on any >real world problem, but on a pure consequence of how object oriented >programming languages are typically implemented: You typically get hold >of an object by invoking a constructor method in a class object. If you >want to be able to get instances of different classes depending on >context, this won't work. Quite glad the discussion came up. Rightly or wrongly, I am convinced that the standard Python approaches to class constructors don't quite work in my situation and I need to go further. But it seems I can leave my 40 odd classes intact, and create "consolidating" Factory classes with which the user interacts, and which will (hopefully, eventually) create the appropriate instances based on argument signature. Whereas Factory classes do not directly solve my problem, which I am calling a mothod overloading issue, I think it does point to a significantly better approach than the path down which I had been going. Art From erikprice@mac.com Wed Sep 4 14:47:23 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 09:47:23 -0400 Subject: [Tutor] Re: Factory classes In-Reply-To: <5.1.0.14.0.20020904144917.00be6ec0@www.thinkware.se> Message-ID: On Wednesday, September 4, 2002, at 09:06 AM, Magnus Lycka wrote: > You can say that factory functions and factory methods extend > polymorphism to the creation phase of the variable which makes > use of polymophism. Look at shape above. Where did that variable > come from? If it can be of several different classes, how did > that happen? > > It might have been passed in as a function or method parameter, [...] > The main > thing here is that the interesting thing where you actually do > something substantial with your shape isn't littered with a lot > of irrelevant object creation logic. Ah, now that makes total sense. You're right, somewhere along the line there had to be code to make the determination of which kind of object to instantiate -- in that sense, then Factory classes do exactly that (extend polymorphism to include the actual creation of object instances). I've just had one of those "Got it!" moments. Thanks Magnus! Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From pobrien@orbtech.com Wed Sep 4 14:45:40 2002 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Wed, 4 Sep 2002 08:45:40 -0500 Subject: [Tutor] Re: Factory classes (etc) In-Reply-To: <002001c25415$a9cd5dd0$9865fea9@arthur> Message-ID: [Arthur] > > Quite glad the discussion came up. > > Rightly or wrongly, I am convinced that the standard Python approaches to > class constructors don't quite work in my situation and I need to > go further. > > But it seems I can leave my 40 odd classes intact, and create > "consolidating" > Factory classes with which the user interacts, and which will > (hopefully, eventually) create the appropriate instances based on argument > signature. > > Whereas Factory classes do not directly solve my problem, which I am > calling a mothod overloading issue, I think it does point to a > significantly > better > approach than the path down which I had been going. Take a look at Bruce Eckel's Thinking in Python book (http://www.mindview.net/Books/TIPython). Chapter 11 has a couple of nice examples of Multiple Dispatching. In particular, the second example uses a dictionary to hold tuples of class combinations that map to certain values. You should be able to do something like this combined with a Factory pattern to determine what class to instantiate based on the class/type of your arguments. -- Patrick K. O'Brien Orbtech ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- Web: http://www.orbtech.com/web/pobrien/ Blog: http://www.orbtech.com/blog/pobrien/ Wiki: http://www.orbtech.com/wiki/PatrickOBrien ----------------------------------------------- From erikprice@mac.com Wed Sep 4 14:52:17 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 09:52:17 -0400 Subject: [Tutor] Re: Factory classes (etc) In-Reply-To: <002001c25415$a9cd5dd0$9865fea9@arthur> Message-ID: <8644D037-C00D-11D6-BB50-00039351FE6A@mac.com> On Wednesday, September 4, 2002, at 09:19 AM, Arthur wrote: > But it seems I can leave my 40 odd classes intact, and create > "consolidating" > Factory classes with which the user interacts, and which will > (hopefully, eventually) create the appropriate instances based on > argument > signature. > > Whereas Factory classes do not directly solve my problem, which I am > calling a mothod overloading issue, I think it does point to a > significantly > better > approach than the path down which I had been going. Python doesn't let you do method overloading? On second thought, that makes sense since it's not strictly typed (how is Python going to know the difference between Constructor(String a, int b) and Constructor(int a, String b)). I hadn't considered this before. :( Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From emile@fenx.com Wed Sep 4 16:09:32 2002 From: emile@fenx.com (Emile van Sebille) Date: Wed, 4 Sep 2002 08:09:32 -0700 Subject: [Tutor] Re: Re: Factory classes (etc) References: <002001c25415$a9cd5dd0$9865fea9@arthur> <8644D037-C00D-11D6-BB50-00039351FE6A@mac.com> Message-ID: Erik > Python doesn't let you do method overloading? On second thought, that > makes sense since it's not strictly typed (how is Python going to know > the difference between Constructor(String a, int b) and Constructor(int > a, String b)). I hadn't considered this before. > Python isn't going to do it for you, but you can. def test(a,b): try: return a*1., b+"" except: try: return a+"", b*1. except: raise 'invalid args' test() accepts string,int or int,string, or any pair that allows for floating point multiplication and string addition. -- Emile van Sebille emile@fenx.com --------- From arodrigo@genasys.com Wed Sep 4 15:34:26 2002 From: arodrigo@genasys.com (Amaya Rodrigo Sastre) Date: Wed, 4 Sep 2002 16:34:26 +0200 Subject: [Tutor] RegEx [Was: Parsing iptables log files] In-Reply-To: <20020903143403.GD23594@onix> References: <20020902160616.GA16558@onix> <200209021107.39433.shalehperry@attbi.com> <20020903074722.GA22515@onix> <20020903143403.GD23594@onix> Message-ID: <20020904143426.GA17342@onix> I am now struggling with the regex: One sample line in my logs looks like this: Aug 17 20:41:55 martinika kernel: --logtrack-- IN= OUT=lo SRC=192.168.100.10 DST=192.168.100.10 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=43085 DPT=80 SEQ=307515611 ACK=0 WINDOW=32767 RES=0x00 SYN URGP=0 And my regex is: #!/usr/bin/python import re my_re = "(\w+\s\d+\s\d+:\d+:\d+).+SRC=([\d.]+)\s+DST=([\d.]+)\s(.*TTL=([\d]))+ID=([\d.]+)\s+(.*TCP|UDP)\s+SPT=(\d+)\s+DPT=(\d+)\s+SEQ=(\d+)\s+ACK=(\d+)" # This one works, but doesn't match ID: # my_re = "(\w+\s\d+\s\d+:\d+:\d+).+SRC=([\d.]+)\s+DST=([\d.]+)\s(.*TTL=([\d]))+ID=([\d.]+)\s+(.*TCP|UDP)\s+SPT=(\d+)\s+DPT=(\d+)\s+SEQ=(\d+)\s+ACK=(\d+)')" pattern = re.compile(r'(my_re)') requests = {} my_line=0 my_file = open('amaya') for line in my_file.xreadlines(): print line match = pattern.search(line) #if not match: continue #if not match: # print "No" # continue date = match.group(1) src_addr = match.group(2) dst_addr = match.group(3) p_id = match.group(5) src_port = int(match.group(7)) dst_port = int(match.group(8)) seq = match.group(9) # seq and ack are too big for int, they ack = match.group(10) # need long, so i left them as strings print match.groups() # for debugging my_line = my_line + 1 my_file.close() The first, uncommented regex finds nothing. The commented one finds this: [0, 'Aug 17', '20:41:55', '192.168.100.10', '192.168.100.10', 43085, 80, '307515611', '0'] I now want to match find the ID= field, but I don't seem to be able. I have gone through http://py-howto.sourceforge.net/regex/ and couldn't find a reason for my regex not to work... -- Amaya M. Rodrigo Sastre Genasys II Spain, S.A.U. MLS Sysadmin Ventura de la Vega, 5. Phone: +34.91.3649100 28014 Madrid. Spain From erikprice@mac.com Wed Sep 4 16:20:01 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 11:20:01 -0400 Subject: [Tutor] RegEx [Was: Parsing iptables log files] In-Reply-To: <20020904143426.GA17342@onix> Message-ID: On Wednesday, September 4, 2002, at 10:34 AM, Amaya Rodrigo Sastre wrote: > # This one works, but doesn't match ID: > # my_re = > "(\w+\s\d+\s\d+:\d+:\d+).+SRC=([\d.]+)\s+DST=([\d.]+)\s(.*TTL=([\d]))+I > D=([\d.]+)\s+(.*TCP|UDP)\s+SPT=(\d+)\s+DPT=(\d+)\s+SEQ=(\d+)\s+ACK=(\d+ > )')" [...] > for line in my_file.xreadlines(): > print line > match = pattern.search(line) > #if not match: continue > #if not match: > # print "No" > # continue > date = match.group(1) > src_addr = match.group(2) > dst_addr = match.group(3) > p_id = match.group(5) > src_port = int(match.group(7)) > dst_port = int(match.group(8)) > seq = match.group(9) # seq and ack are too big for > int, they > ack = match.group(10) # need long, so i left them as > strings [...] > The commented one finds this: > [0, 'Aug 17', '20:41:55', '192.168.100.10', '192.168.100.10', 43085, > 80, '307515611', '0'] > > I now want to match find the ID= field, but I don't seem to be able. > I have gone through http://py-howto.sourceforge.net/regex/ and > couldn't find a > reason for my regex not to work... The ID looks like the sixth group. I don't see you assigning the sixth group to anything in your for loop. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From erikprice@mac.com Wed Sep 4 16:48:15 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 11:48:15 -0400 Subject: [Tutor] attn Morne: text processing in Python Message-ID: I just found this online book by David Mertz, it deals specifically with what you are trying to do: "Text Processing in Python" http://gnosis.cx/TPiP/ -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From emil@lysator.liu.se Wed Sep 4 17:33:59 2002 From: emil@lysator.liu.se (Emil Styrke) Date: 04 Sep 2002 18:33:59 +0200 Subject: [Tutor] ok In-Reply-To: <002c01c25333$c18bd740$2500a8c0@maxitec.co.za> References: <002c01c25333$c18bd740$2500a8c0@maxitec.co.za> Message-ID: <87ptvtd894.fsf@i110.ryd.student.liu.se> "Morne" writes: > ok my log file is saved in C:\my documents\ppp.log ... > def main(): > f=open("C:\my documents\ppp.log","r") ^ ^ Here is the error. Backslashes act as special "escape" characters inside python strings. There are several escape sequences you can put in your strings to produce characters that are hard or impossible to write explicitly. For example, "\n" inserts a newline into your string, and "\t" inserts a tab character. You have two options here: 1. Double all the backslashes ("C:\\my documents\\ppp.log"). "\\" is the escape sequence to insert a backslash into the string. 2. Put an "r" before the string, like this: >>> r"C:\my documents\ppp.log" This will make python interpret the string as a "raw" string, thus ignoring any escape sequences. HTH /Emil From dyoo@hkn.eecs.berkeley.edu Wed Sep 4 18:29:04 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 4 Sep 2002 10:29:04 -0700 (PDT) Subject: [Tutor] My last (fwd) Message-ID: Hi Morne, Instead of sending just to me, it's often better to send to the tutor@python.org address. This is not because I don't like getting email, but because I personally cannot guarantee a quick or good answer! By sending to 'tutor@python.org', all of the tutors here can help you. You need to give us more details about what doesn't work. Does Python give an error "traceback"? A traceback is something that Python prints out as a debugging aid. For example, if we tried something like this: ### Type "help", "copyright", "credits" or "license" for more information. >>> 41 + "one" Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand types for +: 'int' and 'str' ### Those three last lines would be considered the "traceback"; they often give us enough hints to figure out why a program isn't working. Do you get anything like this? ---------- Forwarded message ---------- Date: Wed, 4 Sep 2002 10:50:14 +0200 From: Morne To: Danny Yoo Subject: Re: [Tutor] My last Danny thanx for relpying. Ok so I took your code and copy paste it to the Python shell and it does not work ? ----- Original Message ----- From: Danny Yoo To: Morne Cc: python tutor Sent: Wednesday, September 04, 2002 10:14 AM Subject: Re: [Tutor] My last ### > def getStuff(file): > ppplist = file.readlines() > for line in ppplist: > print "I am looking at line", line > if string.file(line, "connect time") >= 0: > print "found close" > connectSecs = secondsMatcher.search(line).group(1) > print "Connected for", connectSecs > > def main(): > f = open("C:/my documents/ppp.log", "r") > getStuff(f) > ### > From dyoo@hkn.eecs.berkeley.edu Wed Sep 4 18:44:57 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 4 Sep 2002 10:44:57 -0700 (PDT) Subject: [Tutor] RegEx [Was: Parsing iptables log files] In-Reply-To: <20020904143426.GA17342@onix> Message-ID: On Wed, 4 Sep 2002, Amaya Rodrigo Sastre wrote: > I am now struggling with the regex: > > One sample line in my logs looks like this: > > Aug 17 20:41:55 martinika kernel: --logtrack-- IN= OUT=lo > SRC=192.168.100.10 DST=192.168.100.10 LEN=60 TOS=0x00 PREC=0x00 TTL=64 > ID=0 DF PROTO=TCP SPT=43085 DPT=80 SEQ=307515611 ACK=0 WINDOW=32767 > RES=0x00 SYN URGP=0 I'd actually approach this in a slightly different way: the log file has enough structure to make it possible to just do this without regular expressions: ### sample_line = """Aug 17 20:41:55 martinika kernel: --logtrack-- IN= OUT=lo SRC=192.168.100.10 DST=192.168.100.10 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=43085 DPT=80 SEQ=307515611 ACK=0 WINDOW=32767 RES=0x00 SYN URGP=0""" def getNameValuePairs(log_line): anchor = '--logtrack--' name_values_line = log_line[log_line.find(anchor) + len(anchor) + 1 :] pairs = name_values_line.split() return pairs if __name__ == '__main__': print getNameValuePairs(sample_line) ### It's wimpy, but it works. *grin* In any case, this may make it easier to parse out those values that you're looking for. Hope this helps! From buc40@bemail.org Wed Sep 4 18:34:50 2002 From: buc40@bemail.org (S A) Date: Wed, 4 Sep 2002 10:34:50 -0700 Subject: [Tutor] My last Message-ID: <200209041734.g84HYok11803@mail19.bigmailbox.com> I would like to add, please stay with one thread. You are making things a little more confusing for everyone by jumping to different threads. Reply only to the list and the authors of the email you are responding to. This will ensure that everyone on the list can follow the same thread and see what has been developed so far. What you have so far in your program is doing exactly what you have written. It is not however doing what you wish to accomplish for a couple of different reasons, the first being that your programming logic is wrong here. To begin solving the problem let's look at the issues: 1. You want a script that runs through a PPP.log file and extracts info. 2. One piece of info you want is connection time for an IP address.(I assume it is tha IP address you are assigned?) 3. You want to know how many octets are passed in/out during this connection. 4. You then wish to take this extracted info and print it out in a formatted print? Are these correct? Is there anything else you wish to extract from the file? Danny is correct here. Start with something that works and then build on it. Answer my two questions and I will continue to direct you to the solution. Everyone else please jump in and correct my mistakes also, since I'm not an expert. Thanks. SA > Danny Yoo Morne cc: python tutor > Re: [Tutor] My lastDate: Wed, 4 Sep 2002 01:14:16 -0700 (PDT) > > > >On Wed, 4 Sep 2002, Morne wrote: > >> Could someone please help me with this? >> >> Im really new to any kind of programming and the people at python.org >> return my messages in some other code :not python(lol)The people there >> are cool I just dont seem to understand there answers. If posible would >> you be able to answer in detail. > >When we learn from each other, things have to go in two directions: you >need to tell us exactly where we start sounding ludicrous. Many of us >have done programming so long that things are beginning to look "obvious" >to us. Beware us when that happens. *grin* > >We know that, all too easily, things that seem "obvious" aren't obvious at >all. The thing is that we can't tell when we start sounding crazy, so >you've got to wave your hands a bit wildly to bring us back down to Earth. > >When you hear a confusing answer, bring it up; perhaps someone here can >put a light on it to make it less mysterious. > > > >> is it wrong of me to send the ppp.log file to just anyone? > >It's not "wrong" at all, and it's often really helpful. If it is a bit >long, then it might be better to post it somewhere on the web and send us >an url instead, to save bandwidth. > >An alternative is to just take a few lines of log that cover all the cases >that are being tested for (connections, layers, errors, etc.) Maybe >around 12 lines or so is good. It also helps because a smaller case is >easier to check by hand. > > >I've taken a look at your program: I don't see anything obviously wrong >yet, but you may find it easier if you try for a slightly simpler program >that works, before going after the whole problem. How about something >like this? > >### >def getStuff(file): > ppplist = file.readlines() > for line in ppplist: > print "I am looking at line", line > if string.file(line, "connect time") >= 0: > print "found close" > connectSecs = secondsMatcher.search(line).group(1) > print "Connected for", connectSecs > >def main(): > f = open("C:/my documents/ppp.log", "r") > getStuff(f) >### > >That is, just pay attention to 'connect time' lines in your program for >now. I've also added a small "I am looking at blah" print statement, so >you can trace out what's happening in the program. > > >Does this do anything useful with your log? Do you get any errors, or >does it skip all your log lines without doing anything? Let's get >something working first: we can always add more to a working program. >It's much harder to get a whole, fully-working program at first go: we >often need to build toward it. > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From buc40@bemail.org Wed Sep 4 18:53:38 2002 From: buc40@bemail.org (S A) Date: Wed, 4 Sep 2002 10:53:38 -0700 Subject: [Tutor] RegEx [Was: Parsing iptables log files] Message-ID: <200209041753.g84Hrc712935@mail19.bigmailbox.com> > Danny Yoo Amaya Rodrigo Sastre cc: tutor@python.org > Re: [Tutor] RegEx [Was: Parsing iptables log files]Date: Wed, 4 Sep 2002 10:44:57 -0700 (PDT) >### >sample_line = """Aug 17 20:41:55 martinika kernel: --logtrack-- IN= >OUT=lo SRC=192.168.100.10 DST=192.168.100.10 LEN=60 TOS=0x00 PREC=0x00 >TTL=64 ID=0 DF PROTO=TCP SPT=43085 DPT=80 SEQ=307515611 ACK=0 >WINDOW=32767 RES=0x00 SYN URGP=0""" > >def getNameValuePairs(log_line): > anchor = '--logtrack--' > name_values_line = log_line[log_line.find(anchor) > + len(anchor) + 1 :] > pairs = name_values_line.split() > return pairs > >if __name__ == '__main__': > print getNameValuePairs(sample_line) >### > So this just slices everything past the anchor "--logtrack--" and then splits the string into a list at every whitespace? Thanks. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From jcosby@mindspring.com Wed Sep 4 20:35:56 2002 From: jcosby@mindspring.com (Jon Cosby) Date: Wed, 4 Sep 2002 12:35:56 -0700 Subject: [Tutor] Referencing global variables Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0000_01C2540F.9DAD2D10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Why does this not work: >>> count = 0 >>> def increment(n): ... for i in range(n): ... count = count + 1 ... return count ... >>> increment(5) UnboundLocalError: local variable 'count' referenced before assignment "count" is global, isn't it? It would seem I should be able to reference it in the function. I don't want to initialize it each time the function runs, I'm actually trying to count instances in a recursive function. Jon Cosby jcosby@mindspring.com www.jcosby.com ------=_NextPart_000_0000_01C2540F.9DAD2D10 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Why does this not work:
 
>>> count =3D = 0
>>> def=20 increment(n):
...     for i in=20 range(n):
...         &nb= sp;  =20 count =3D count + 1
...     return=20 count
...
>>> increment(5)
UnboundLocalError: local = variable=20 'count' referenced before assignment
 
"count" is global, isn't it? It would = seem I should=20 be able to reference it in the function. I don't want to initialize it = each time=20 the function runs, I'm actually trying to count instances in a recursive = function.

Jon Cosby

jcosby@mindspring.com
www.jcosby.com

 
------=_NextPart_000_0000_01C2540F.9DAD2D10-- From shalehperry@attbi.com Wed Sep 4 20:41:06 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Wed, 4 Sep 2002 12:41:06 -0700 Subject: [Tutor] Referencing global variables In-Reply-To: References: Message-ID: <200209041241.06698.shalehperry@attbi.com> On Wednesday 04 September 2002 12:35, Jon Cosby wrote: > Why does this not work: > >>> count =3D 0 > >>> def increment(n): > > ... for i in range(n): > ... count =3D count + 1 > ... return count > ... > > >>> increment(5) > > UnboundLocalError: local variable 'count' referenced before assignment > > "count" is global, isn't it? It would seem I should be able to referenc= e it > in the function. I don't want to initialize it each time the function r= uns, > I'm actually trying to count instances in a recursive function. > if you want to *change* a global you need to declare it global. def increment(n): global count for i in range(n): count =3D count + 1 # or count +=3D 1 return count From buc40@bemail.org Wed Sep 4 20:01:48 2002 From: buc40@bemail.org (S A) Date: Wed, 4 Sep 2002 12:01:48 -0700 Subject: [Tutor] Referencing global variables Message-ID: <200209041901.g84J1mO07149@mail22.bigmailbox.com> > jcosby@mindspring.com buc40@bemail.orgDate: Wed, 04 Sep 2002 11:58:06 > RE: [Tutor] Referencing global variables >>Reply-To: >> "Jon Cosby" [Tutor] Referencing global variablesDate: Wed, 4 Sep 2002 12:35:56 -0700 >> >>Why does this not work: >> >>>>> count = 0 >>>>> def increment(n): >>... for i in range(n): >>... count = count + 1 >>... return count >>... >>>>> increment(5) >>UnboundLocalError: local variable 'count' referenced before assignment >> >>"count" is global, isn't it? It would seem I should be able to reference it >>in the function. I don't want to initialize it each time the function runs, >>I'm actually trying to count instances in a recursive function. >> >>Jon Cosby > > >I think this is not so. Someone else correct me if I'm wrong. But the only value passed to the function is 5. Therefore increment does not know what the value of count is. One correction is as follows: > >>>> def increment(n): >... count = 0 >... for i in range(n): >... count = count + 1 >... return count >... >>>> increment(5) >5 > >However, this may not be the solution for you. Maybe you want count to be defined outside of the function? You can then try the following: >>>> count = 0 >>>> def increment(n, count): >... for i in range(n): >... count = count + 1 >... return count >... >>>> increment(5, count) >5 > >Maybe this is what you are looking for. Anybody else? > >Good Luck. >SA > > > >"I can do everything on my Mac that I used to do on my PC, plus alot more ..." > >-Me "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From jeff@ccvcorp.com Wed Sep 4 21:51:43 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Wed, 04 Sep 2002 13:51:43 -0700 Subject: [Tutor] Referencing global variables References: Message-ID: <3D76725F.B04B4886@ccvcorp.com> Jon Cosby wrote: > Why does this not work: >>> count = 0 > >>> def increment(n): > ... for i in range(n): > ... count = count + 1 > ... return count > ... > >>> increment(5) > UnboundLocalError: local variable 'count' referenced before > assignment "count" is global, isn't it? Actually, it's not. Well, technically, there's a global count *and* a local count. Assignment to a variable, within the scope of a function, creates a local variable regardless of the existence of a similarly-named global. Since locals are determined at compile-time (when the interpreter loads the function) rather than run-time, any usage of 'count' within the function applies to the local variable, even *before* that local has been assigned to. Thus, 'count = count + 1' tries to access the value of the local 'count', add one to it, and then assign the results back to (the local version of) 'count'. The first time this happens, there *is* no value for the local 'count', thus the exception you see. The simple solution, as Sean pointed out, is to declare that 'count' is a global before you use it in the function. This will get exactly the behavior you're expecting. The not-so-simple solution would be to find some other way of counting whatever it is that you're counting, but doing that would require more knowledge of what you're trying to do. ;) In particular, I wonder why you're not using this: def increment(n): global count return count + n which seems much more sensible than the for-loop that you're using, but perhaps there's some reason in the details that you've left out. (For that matter, I wonder why you wouldn't use 'count += n' instead of 'increment(n)' ... but I suppose you probably have a reason that wasn't germane to the specific problem you're asking about.) Jeff Shannon Technician/Programmer Credit International From shalehperry@attbi.com Wed Sep 4 22:02:21 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Wed, 4 Sep 2002 14:02:21 -0700 Subject: [Tutor] Referencing global variables In-Reply-To: <3D76725F.B04B4886@ccvcorp.com> References: <3D76725F.B04B4886@ccvcorp.com> Message-ID: <200209041402.21673.shalehperry@attbi.com> On Wednesday 04 September 2002 13:51, Jeff Shannon wrote: > The simple solution, as Sean pointed out, is to declare that 'count' > is a global before you use it in the function. This will get exactly > the behavior you're expecting. The not-so-simple solution would be to > find some other way of counting whatever it is that you're counting, > but doing that would require more knowledge of what you're trying to > do. ;) In particular, I wonder why you're not using this: > I made the assumption that the example was simply meant to illustrate his= =20 point and was not really his code. I hope I was right (-: From smith@jeve.org Wed Sep 4 22:40:34 2002 From: smith@jeve.org (smith@jeve.org) Date: Wed, 4 Sep 2002 17:40:34 -0400 Subject: [Tutor] python xml entity problem [xml parsing and DTD handling] In-Reply-To: References: <20020903160637.B26435@jeve.org> Message-ID: <20020904214034.GA2377@fete.jeve.org> On Tue, Sep 03, 2002 at 04:21:41PM -0700, Danny Yoo wrote: > > > On Tue, 3 Sep 2002 smith@rfa.org wrote: > > > I'm interested in parsing a xml file using the python tools in debian > > woody. Everything seems to be ok until I reach a "&MAN;" My python > > script just passes over it. My guess is that I have a external entity > > resolver problem. I've been reading the Python XML book on O'reilly and > > I believe I'm doing the right things. At least in terms of non external > > entities. Does anybody have any examples or how can I make the program > > recognize external entity. I'm still very new to python and xml so maybe > > it's something I don't understand. > > Hi Smith, > > Yikes. The documentation on Python and XML, in my opinion, is just > absolutely hideous; most of the documentation assumes that you want to > write this stuff in Java, which is just, well, lazy! Even the 'Python & > XML' book minimally touches external references. > > > Forgive me for the rant; I'm just so frustrated by the lack of > documentation in this area. It just seems that the documentation and > examples could be greatly improved. Perhaps we can do an xml-parsing > thing this week and send our examples over to the PyXML folks... Hmmmm.) I agree, the documentation is pretty weak for external references. Thanks for your input on this. I responded to your message last night, but it looks like you didn't it get. I've learned many things from the list, so if I could some how give back, by sending my(ours) examples to the PyXML folks, Cool. The only problem is I'm still very new to python and xml, so I'm not sure how much I could contribute. > For XML processing with DTD's to work well, it appears that you need to > give the address of a real DTD --- otherwise, I think the system will just > ignore external references outright! The line: > > > > > > should be changed to point to a real url that your system can find --- > xml.sax will use the 'urllib' module to grab DTD information from this, so > it's not enough to put a fill-me-in sort of thing: the DTD url has to be > real. Of coarse, I wasn't sure if it was ok to put the real one out there. The real one is: ftp://techweb.rfa.org/pub/r-boss/xml_files/schedule.dtd > Also, there's a bug on line 3 of your DTD: > > > > > You need a space between the element name and the open parenthesis > character. Doh! *grin* Yeah, when I copied those lines from the original dtd, the space between "pgm_block" and "(id?,arch?,air_date?,air_time?, ..." got deleted. > Once we make those fixes, then everything should be ok. I've written an > example that uses a DTD that's embedded in the xml, so that the system > doesn't have to try looking for it online. Now I'm really confused. I've gone over the documentation many times and my program still it passes over the external entity. Thanks, for your sample. It works great. I appreciate the time you put into that, the xml files I'm working with are generated form another program, so I'm not sure If I would be able to use it. regards, SA > > > ###### > import xml.sax > > xml_text = \ > """ > > block_time?,sch_status,mc,produce)> > > > > > > > > > > > > > > > ]> > type="text/xsl"href="ftp://something.org/pub/xml_files/program.xsl"?> > > > > http://something/MAN/2000/02/test.mp3 > 2000/02/02 > 16:00 > &MAN; > 00:70:00 > archive > AW > AW > XZ > > """ > > > class MyContentHandler(xml.sax.handler.ContentHandler): > def __init__(self): > xml.sax.handler.ContentHandler.__init__(self) > self.indent = 0 > > def startElement(self, name, attrs): > self.printIndent() > print "I see the start of", name > self.indent += 4 > > def endElement(self, name): > self.indent -= 4 > self.printIndent() > print "I see the end of", name > > > def characters(self, text): > if text.strip(): > self.printIndent() > print "I see characters", repr(text) > pass > > def printIndent(self): > print " " * self.indent, > > > if __name__ == '__main__': > parser = xml.sax.make_parser() > handler = MyContentHandler() > parser.setContentHandler(handler) > parser.feed(xml_text) > parser.close() > ####### > > > > I hope this helps! If you have more questions, please feel free to ask. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From scot@possum.in-berlin.de Wed Sep 4 10:48:32 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Wed, 4 Sep 2002 11:48:32 +0200 Subject: [Tutor] The Gang of Four (was: A Book for You and Me) In-Reply-To: <200209032159.47782.shalehperry@attbi.com> References: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> <200209032159.47782.shalehperry@attbi.com> Message-ID: <200209041148.32380.scot@possum.in-berlin.de> Hello Sean, > Yeah, it is expensive and so are all of the Addison Wesley books. The > main selling point is that almost all of them are good enough that > numerous colleges use them as required texts for classes. And "Design Patterns" is written like a college book, in a terrible, deadly, dehumanized, and completely humorless prose that is the exact opposite of the clear, friendly style of writing that has helped make English the international language of science and technology. In fact, if you were to capitalize the nouns, make the sentences a bit longer and move the verbs to the end, "Design Patterns" could pass as a German college text. This is not a compliment: A lot of Germans in my biochemistry class were using American textbooks instead of German ones simply because of the style of writing. As well structured as "Design Patterns" is and as great the insights might be (I don't claim to even understand a third of it yet), it is very much a book where you get the feeling that the people who wrote it are very, very serious, don't have much fun in life, and don't think their thoughts should be generally accessable. Also, the book is from 1995, and still in the first edition. I would expect OOP has progressed somewhat since then, so somebody should sit down and rewrite the whole thing to a) bring it up to date with current developments, b) humanize the prose, and c) replace the Smalltalk examples with Python. My suggestion to other amateur newbies is to wait with this book until you keep running up against terms like "Flywheel" and "Factory" and "Mediator" all the time - this book is far more in the science section of computer science, and you're probably going to want to read a whole lot of other stuff before you get to it. I occassionally take down my copy and am amazed how, say, it can take 15 pages of robotic prose to explain in very abstract terms what an iterator does, and how amazingly complicated they seem to be to implement in C++. Simply put, this book is far too advanced for me, and I wish I had bought "Code Complete" by McConnell first and "Design Patterns" sometime in the future when I am able (and willing) to think about objects on that level of abstraction - and can stomach the prose. For Python beginners, this is definitely a "We read Knuth so you don't have to" (Tim Peters in the "Python Cookbook") kind of book. Y, Scot -- Scot W. Stevenson wrote me on Wednesday, 4. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1880 hours and has a CPU that is falling asleep at a system load of 0.08. From dyoo@hkn.eecs.berkeley.edu Thu Sep 5 02:12:35 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 4 Sep 2002 18:12:35 -0700 (PDT) Subject: [Tutor] python xml entity problem [xml parsing and DTD handling] In-Reply-To: <20020904214034.GA2377@fete.jeve.org> Message-ID: > my program still it passes over the external entity. Thanks, for your > sample. It works great. I appreciate the time you put into that, the xml > files I'm working with are generated form another program, so I'm not > sure If I would be able to use it. Hmmm... but do the generated files set up the correct DOCTYPE element? If I do something like this, I also get good results: ### import xml.sax xml_text = \ """ http://something/MAN/2000/02/test.mp3 2000/02/02 16:00 &MAN; 00:70:00 archive AW AW XZ """ class MyContentHandler(xml.sax.handler.ContentHandler): def __init__(self): xml.sax.handler.ContentHandler.__init__(self) self.indent = 0 def startElement(self, name, attrs): self.printIndent() print "I see the start of", name self.indent += 4 def endElement(self, name): self.indent -= 4 self.printIndent() print "I see the end of", name def characters(self, text): if text.strip(): self.printIndent() print "I see characters", repr(text) pass def printIndent(self): print " " * self.indent, if __name__ == '__main__': parser = xml.sax.make_parser() handler = MyContentHandler() parser.setContentHandler(handler) parser.feed(xml_text) parser.close() ### So this test case should handle external references properly too. Perhaps there's something fishy with the generated XML that you're getting? Best of wishes! From idiot1@netzero.net Thu Sep 5 04:59:06 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Wed, 04 Sep 2002 23:59:06 -0400 Subject: [Tutor] Python Books References: <200209032029.g83KTwX17873@mail17.bigmailbox.com> Message-ID: <3D76D68A.CD3AE3B2@netzero.net> I am groking it each day, and it is for me scripture. I also dare read Python Web Programming, but for a beginner this is not such a hot idea. S A wrote: > > "Learning Python". > > Another wonderful Oreily Book. > > Good Luck. > SA > > > Jason Willis tutor@python.org [Tutor] Python BooksDate: Tue, 3 Sep 2002 13:16:26 -0700 > > > >Hello, > > > > I was wondering which books anyone would recommend for a beginner in Python programming? I've browsed through some of the books -- but I'm not sure which might carry me through beginner to intermediate (or so) levels. Thanks for the help. (Sorry if this question has been asked and answered so many times already) > > > > Jason W. > > > >_______________________________________________ > >Tutor maillist - Tutor@python.org > >http://mail.python.org/mailman/listinfo/tutor > > "I can do everything on my Mac that I used to do on my PC, plus alot more ..." > > -Me > > ------------------------------------------------------------ > Free, BeOS-friendly email accounts: http://BeMail.org/ > BeOS News and Community: http://www.BeGroovy.com/ > > --------------------------------------------------------------------- > Express yourself with a super cool email address from BigMailBox.com. > Hundreds of choices. It's free! > http://www.bigmailbox.com > --------------------------------------------------------------------- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From kojo@hal-pc.org Thu Sep 5 03:35:45 2002 From: kojo@hal-pc.org (Kojo Idrissa) Date: Wed, 04 Sep 2002 21:35:45 -0500 Subject: [Tutor] Addison-Wesley Sale (was: A Book for People Like Me) In-Reply-To: <200209032159.47782.shalehperry@attbi.com> References: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020904213009.02ca34c0@mail.hal-pc.org> At 09:59 PM 9/3/2002 -0700, Sean 'Shaleh' Perry wrote: >On Tuesday 03 September 2002 21:46, Erik Price wrote: > >(that "Design Patterns" book > > by Gamma and the others seems to come up all the time, too bad it's so > > expensive). > > > > > >Yeah, it is expensive and so are all of the Addison Wesley books. The main >selling point is that almost all of them are good Well, as I was reading these posts at work today, I got an email for the good folks at . Looks like they've got the A-W books (along with some others) on sale for 41, 28 and 21% off, depending on the "series", Trade, Pro or Pro Reference. The Gamma book is a Pro, so it's 28% off. Sorry to post what seems to be a commercial (I am not affiliated with Bookpool...I've just bought some books from them), but it seemed rather appropos... Returning to Lurk Mode... **************************** Kojo Idrissa kojo@hal-pc.org http://www.hal-pc.org/~kojo/ **************************** From magnus@thinkware.se Thu Sep 5 14:12:29 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Thu, 05 Sep 2002 15:12:29 +0200 Subject: [Tutor] ok In-Reply-To: <87ptvtd894.fsf@i110.ryd.student.liu.se> References: <002c01c25333$c18bd740$2500a8c0@maxitec.co.za> <002c01c25333$c18bd740$2500a8c0@maxitec.co.za> Message-ID: <5.1.0.14.0.20020905150458.029b6368@www.thinkware.se> >"Morne" writes: > > You have two options here: > >1. Double all the backslashes ("C:\\my documents\\ppp.log"). "\\" is > the escape sequence to insert a backslash into the string. > >2. Put an "r" before the string, like this: > > >>> r"C:\my documents\ppp.log" A third (and more convenient) solution is to use forward slashes in paths as God intended. "C:/my documents/ppp.log" --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From erikprice@mac.com Thu Sep 5 14:36:05 2002 From: erikprice@mac.com (Erik Price) Date: Thu, 5 Sep 2002 09:36:05 -0400 Subject: [Tutor] Python Books In-Reply-To: <3D76D68A.CD3AE3B2@netzero.net> Message-ID: <6D5037E1-C0D4-11D6-984F-00039351FE6A@mac.com> On Wednesday, September 4, 2002, at 11:59 PM, Kirk Bailey wrote: > I also dare read Python Web Programming, but for a beginner this is > not such a > hot idea. This book is not very complicated, in my opinion. If you already know Python, skip over Chapters 1, 2, and 3 because this is all review (not bad to review though if you're coming back to the language after a break). Chapter 4 is a great overview of the concepts used in networking, it doesn't even deal with Python per se. Chapter 5 is pretty much an explanation and tutorial of the client libraries like httplib and urllib -- good to read if you have no experience with them but you could probably get away with the online docs and be fine. I haven't read Chapters 6 (Server Framework Libraries) or 7 (Asynchronous services) yet. Chapters 8 through 11 deal with database programming (not too tricky; it's harder to install and design a decent database than it is to write client code to access it IMHO) and 12 through 15 deal with XML processing (a very high-level inspection, really only discusses XML principles and SAX). The last couple chapters integrate a lot of the earlier discussion into "Integrated Web Applications in Python" which I must say I haven't read yet. I'd give this book a try, though if you're looking for something more general-purpose then perhaps "Programming Python" is a favorite (one that I've been meaning to read). Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From wesc@deirdre.org Thu Sep 5 07:25:35 2002 From: wesc@deirdre.org (wesc@deirdre.org) Date: Wed, 4 Sep 2002 23:25:35 -0700 (PDT) Subject: [Tutor] ANN: BayPIGgies mtg Wed 9/11 7:30pm Message-ID: <200209050625.g856PZx20521@alpha.ece.ucsb.edu> BayPIGgies: Silicon Valley-San Francisco Bay Area Python Users Group Agenda: Using a New MVC Architecture to Create a Pythonic XML-based Web Application Framework When: September 11, 2002 @ 7:30pm Where: Stanford University, Palo Alto, CA Speakers: Paul McGavin, Donovan Preston, Sam Penrose from InterSight We will discuss how we are applying a new Python-based MVC architecture to create an efficient, Pythonic web application framework that separates presentation templates from the Python source code with DOMTemplate. The framework componentizes behavior into reusable objects with DOMWidgets and DOMHandlers. After creating web applications in three separate Python frameworks -- Webware for Python, Zope and Apache/Python cgi -- InterSight decided to create its own MVC framework, based on some of the ideas from IBM and Lutris Enhydra's Barracuda project, to power their automated publishing applications. Their applications enable scalable content: the ability to produce, from a single set of managed data and images, many different marketing communication pieces: press- ready Adobe InDesign and QuarkXPress files, web pages, order sheets, sample stickers, price tags and more. We are actively seeking speakers for BayPIGgies, esp. October 9th! If you would like to give a talk at one of our meetings (any Python- related topic), please contact us! more info including directions: http://www.baypiggies.net hope to see some of you on Wednesday! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, © 2001 http://starship.python.net/crew/wesc/cpp/ Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies) http://www.baypiggies.net wesley.j.chun :: wesc at deirdre.org cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com http://roadkill.com/~wesc/cyberweb/ From idiot1@netzero.net Thu Sep 5 04:34:15 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Wed, 04 Sep 2002 23:34:15 -0400 Subject: [Tutor] cgi poison detection kit Message-ID: <3D76D0B7.BA0A98F@netzero.net> WELL, I was thinking about how evil data can trip up the unwary cgi script author by means of an evil hacker sending in assorted escapes and other datum in a form's input. shell scripts are NOTORIOUSLY susceptible to this, but python is not immune. So I decided to build a function to detect evil data and abort the program if found. But what is evil data? Well, let's try the paranoia express approach; any data which is not KNOWN to be safe should be considered potentially dangerous and discarded. def snifftest(couldbeshit): # we pass a string for testing to the function, for lump in couldbeshit: # examine EACH char in the string passed to the function, if lump not in """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_- """: sys.exit("Bullshit!") # this line executes if we smell a whiff... # else we simply return and execution continues. Alas, I have an uninhibited mind, forgive me. Might this be a candidate for useless python? -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From magnus@thinkware.se Thu Sep 5 15:19:22 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Thu, 05 Sep 2002 16:19:22 +0200 Subject: [Tutor] Re: Factory classes (etc) In-Reply-To: <200209051020.25303.scot@possum.in-berlin.de> References: <5.1.0.14.0.20020904094606.02ae4690@www.thinkware.se> <5.1.0.14.0.20020904094606.02ae4690@www.thinkware.se> Message-ID: <5.1.0.14.0.20020905151836.029b64b0@www.thinkware.se> At 10:20 2002-09-05 +0200, Scot W. Stevenson wrote: >Ah, now I understand. Just as an aside, if I were to really programm >something like this (which is certainly the best way to understand the >principle), would I want to use a if-elif-else construct like above, or >rather a dictionary such as: > >shapes =3D {0: Circle, 2: Line, 3: Triangle, [...]} > >and then do a > >shapes[corners](x, y, size, angle) > >which would assume that Circle doesn't go balistic if it is suddenly handed >an angle. Again, I'm glad you did it this way here, because it is easier >to understand. Well, if it was easier for you to understand with the if statement, then that is probably a better way of coding it... The dictionary construct is not unknown among python programmers, but it's probably more likely to confuse, and you need to handle both Circle (which in my imagined implementation didn't take angle) and Polygons that want the number of sides as a parameter. If it had been 20 choices or so, I might have preferred the dictionary approach since it's less verbose. >Does anybody actually _use_ SmallTalk for production code, or is it one of >those teaching languages that revolutionized various concepts but never >made it in the market (sort of like Multics [sp] vs. Unix, or the League >of Nations vs. the United Nations, or for that matter, "Buffy" the Film >vs. "Buffy" the TV series)? Certainly, although it seems some of them are forced over to Java. Since GemStone, the favourite database of SmallTalkers is now ported to Java, they seem to be able to live with that. Check out Portland again: http://www.c2.com/cgi/wiki?search=3Dsmalltalk Perhaps you should look at= http://www.c2.com/cgi/wiki?SmalltalkInsteadOfPython >Are there any common patterns that are missing by today's standards? I'm >thinking about the Borg "non-pattern" described in the "Python Cookbook" - >I can't believe that seven years later, the GoF is still state of the >art... GoF might be state of art, or at least still considered a good first book about patterns, but it's certainly not intending to be a catalog of _all_ software design patterns. I'm sure the authors had no such ambition. There are a few more books here: http://c2.com/cgi/wiki?PatternRelatedBookList I have some stuff about Patterns and Python here: http://www.thinkware.se/cgi-bin/thinki.cgi/PythonPatterns http://www.thinkware.se/cgi-bin/thinki.cgi/PatternCatalog --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From abarker@xminc.com Thu Sep 5 15:39:00 2002 From: abarker@xminc.com (Anthony Barker) Date: Thu, 5 Sep 2002 10:39:00 -0400 (EDT) Subject: [Tutor] Addison-Wesley Sale In-Reply-To: <5.1.0.14.0.20020904213009.02ca34c0@mail.hal-pc.org> References: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> <5.1.0.14.0.20020904213009.02ca34c0@mail.hal-pc.org> Message-ID: <1499.65.95.68.242.1031236740.squirrel@www.xminc.com> Seems like all the books I want are "pro" according to bookpool. I noticed programming python (first edition mind you). on sale at www.bookcloseouts.com for $6 - they seem to have 100 copies. Another method I use is to scan the local universities reused textbooks - I got a few books at 30-40% off that way. Anthony >> Erik Price wrote: >> >(that "Design Patterns" book >> > by Gamma and the others seems to come up all the time, too bad it's > so >> > expensive). >> > >> > ... > Well, as I was reading these posts at work today, I got an email for the > good folks at . Looks like they've got the A-W books > (along with some others) on sale for 41, 28 and 21% off, depending on the > "series", Trade, Pro or Pro Reference. From magnus@thinkware.se Thu Sep 5 15:40:23 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Thu, 05 Sep 2002 16:40:23 +0200 Subject: [Tutor] Re: Re: Factory classes (etc) In-Reply-To: References: <002001c25415$a9cd5dd0$9865fea9@arthur> <8644D037-C00D-11D6-BB50-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020905162256.02af8448@www.thinkware.se> At 08:09 2002-09-04 -0700, Emile van Sebille wrote: > > Python doesn't let you do method overloading? > >Python isn't going to do it for you, but you can. > >def test(a,b): > try: return a*1., b+"" > except: > try: return a+"", b*1. > except: > raise 'invalid args' In general it's a bad idea to use exceptions for other things than error handling. They cost a lot of performance. This might be a better solution (assuming that you don't use keyword arguments): def typesAreSame(recievedArgs, expectedArgs): if len(recievedArgs) !=3D len(expectedArgs): return 0 for recievedArg, expectedArg in zip(recievedArgs, expectedArgs): if type(recievedArg) !=3D type(expectedArg): return 0 return 1 (You might want to extent that a bit to check that instances are of correct class.) class X: def needsOverloading(self, *args): if typesAreSame(args, (1,1,1)): self.___threeIntegersMethod(self, *args) elif typesAreSame(args, ("")): self.___oneStringMethod(self, *args) ... else: raise ValueError, 'Bad parameters: %s' % args But in most cases where you use overloading or templates in C++ etc, you just write one method in Python, and that's it! :) Perhaps you need an extra if-statement in the method, but I have never missed method overloading in Python during the six years I used it. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From erikprice@mac.com Thu Sep 5 16:17:10 2002 From: erikprice@mac.com (Erik Price) Date: Thu, 5 Sep 2002 11:17:10 -0400 Subject: [Tutor] cgi poison detection kit In-Reply-To: <3D76D0B7.BA0A98F@netzero.net> Message-ID: <8C5CC2F8-C0E2-11D6-984F-00039351FE6A@mac.com> On Wednesday, September 4, 2002, at 11:34 PM, Kirk Bailey wrote: > But what is evil data? > I think that the concept of evil data really depends on the context. For instance, in a home banking web application, the dollar sign might be used -- do you really want to be sending error messages to users who innocently prepended their input with a dollar sign? It might be hard to write a "universal function" for this "sniffing" task. But you could probably come up with some good general-purpose functions and put them in a module. Some functions could be moneyOnly() # only allows digits, currency symbols, and an # appropriately-placed dot (use regular expressions # for this). Perhaps optional commas too. datesOnly() # only allows dates, in various formats such as # YYYY-MM-DD; MM/DD/YYYY; YYMMDD; # MM/DD/YY; Mon DD, YYYY etc # you could really get fancy and provide logic to # only accept dates within a range, specified by # arguments htmlentities() # There is a PHP function by this name that # automatically turns any HTML code into the # appropriate entity, which is good for discussion- # forum scripts, so that users can't plant things like # # into your guestbook applications. Even though you might # appreciate such generosity. Just some ideas. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From erikprice@mac.com Thu Sep 5 04:54:37 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 4 Sep 2002 23:54:37 -0400 Subject: [Tutor] The Gang of Four (was: A Book for You and Me) In-Reply-To: <200209041148.32380.scot@possum.in-berlin.de> Message-ID: <327A1F9B-C083-11D6-B21E-00039351FE6A@mac.com> On Wednesday, September 4, 2002, at 05:48 AM, Scot W. Stevenson wrote: > Simply put, this book is far too advanced for me, and I wish I had > bought > "Code Complete" by McConnell first and "Design Patterns" sometime in > the > future when I am able (and willing) to think about objects on that > level > of abstraction - and can stomach the prose. For Python beginners, this > is > definitely a "We read Knuth so you don't have to" (Tim Peters in the > "Python Cookbook") kind of book. I'm glad I'm not the only one who was daunted when he picked up the book in the store and tried reading it for an hour or so. Perhaps it's only to those of us who haven't formal training in comp sci (like myself and Scot). Speaking of "Code Complete", that's another highly recommended book from people whose opinions I regard highly (you know who you are), and when I read a little bit of that one in the store, I discovered that it didn't seem to discuss the OO methodology at all. I was somewhat surprised by this, and hopefully I'm wrong. Also, this one's even older than "Design Patterns"! It looks like a good book, though. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From llazarre@yahoo.com Thu Sep 5 17:46:31 2002 From: llazarre@yahoo.com (Levy Lazarre) Date: Thu, 5 Sep 2002 09:46:31 -0700 (PDT) Subject: [Tutor] Perl to Python code migration Message-ID: <20020905164631.42180.qmail@web40403.mail.yahoo.com> Good afternoon all, In Python what is the fastest way to break a file into records according to a fixed string delimiter? I have a file that looks like this: (ID 1) IBC NOCHG - Test Code Does Not Exist In STAR PATIENT CARE...Data Discarded! 0307 PID;00100869^^^A;ZTEST^PATIENT^ONE^^^;19591127;F;221500187^^^A;261-71-0192 FT1|1|20020803.1208|LAB|20020804|20020804|CH|NOCHG|||1|||WLB||||||||||| (ID 1) IBC 11849 - Test Code Does Not Exist In STAR PATIENT CARE...Data Discarded! 0354 PID;00026891^^^A;ZTEST^PATIENT^TWO^^^;;;0221500122^^^A; FT1||409782||20020803133427|20020804|CH|11849|DILTIAZEM HCL||1|0||WPH|||^EDS^^^|||^^^^^|^Zdog^Shaggy^^^^^|^^^^^^^||^| The string "(ID 1)" marks the beginning of a new record. In Perl, I simply do: local $/ = "(ID 1)"; # change the default input # record separator Since Python doesn't have similar constructs, I wonder what would be the most efficient approach. I do not want to load the whole file in memory at once. The purpose is to extract fields from the PID and FT1 segments. I used Perl regular expressions to do this, but I would like to do it in Python without regexes. Thanks in advance for any suggestion. Levy Lazarre __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com From jeff@ccvcorp.com Thu Sep 5 19:01:07 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Thu, 05 Sep 2002 11:01:07 -0700 Subject: [Tutor] Perl to Python code migration References: <20020905164631.42180.qmail@web40403.mail.yahoo.com> Message-ID: <3D779BE3.A154E3A1@ccvcorp.com> Levy Lazarre wrote: > Good afternoon all, > > In Python what is the fastest way to break a file into > records according to a fixed string delimiter? [...] > > The string "(ID 1)" marks the beginning of a new > record. [...] Try using the split() string method. infile = open('myfile.txt', 'r') data = infile.read() infile.close() records = data.split( "(ID 1)" ) Now 'records' holds a list. Each element of that list is a block that was delimited by the argument to split() (in this case, "(ID 1)"). Note that if your file starts with the delimiter, then records[0] will be an empty string. You can similarly use split() on each of the records to break those down further. Or, you could use find() to locate a particular substring (such as "PID") and then grab whatever follows that. You *could* also use Python regexes to find your fields, though they're probably overkill. The best approach here depends a bit on what fields you're actually interested in, and what demarkation you expect on them. Jeff Shannon Technician/Programmer Credit International From anthonypolis@hotmail.com Thu Sep 5 19:32:03 2002 From: anthonypolis@hotmail.com (anthony polis) Date: Thu, 05 Sep 2002 18:32:03 +0000 Subject: [Tutor] searching for a value in an array Message-ID: How do you search for a value in an array? For example: I need to check to see if the string "bob" is in the array "people". Thanks, Anthony _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com From dyoo@hkn.eecs.berkeley.edu Thu Sep 5 20:03:56 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 5 Sep 2002 12:03:56 -0700 (PDT) Subject: [Tutor] python xml entity problem [xml parsing and DTD handling] In-Reply-To: <20020905173004.GA4174@fete.jeve.org> Message-ID: On Thu, 5 Sep 2002 smith@jeve.org wrote: > Hey Danny, I want to thank you once again, but it still doesn't work. > Can you email me the list of python/xml packages you are using ? I feel > like we are close, and I want to rule out everything. This is what mine > looks like. > > ii python2.1-xml 0.7-1 XML tools for Python (2.1.x) > ii python2.1-xmlb 2.1.3-3 XML support included in Python (v2.1) > > regards > > SA Hello, I tried this in Python-2.2 --- I haven't tried it in 2.1 yet. Does anyone know if this makes a difference? From dyoo@hkn.eecs.berkeley.edu Thu Sep 5 20:10:41 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 5 Sep 2002 12:10:41 -0700 (PDT) Subject: [Tutor] searching for a value in an array In-Reply-To: Message-ID: On Thu, 5 Sep 2002, anthony polis wrote: > How do you search for a value in an array? For example: > > I need to check to see if the string "bob" is in the array "people". I think you'll like this one: it's basically what you just said: ### >>> print 'bob' in ['jane', 'hector', 'alissa', 'john', 'lisa', 'bob', ... 'iris'] 1 ### The 'in' operator returns true if it can find our item in a list, and false otherwise. What Python does here is a "linear" scan: it'll march through our list until it either runs out of list, or if it finds 'bob'. There are faster ways of seeing if someone is present in a group of people: we can use a dictionary: ### >>> people = { 'jane' : 1, 'hector' : 1, 'alissa' : 1 } >>> 'jane' in people 1 >>> 'bob' in people 0 ### Hope this helps! From smith@jeve.org Thu Sep 5 18:30:05 2002 From: smith@jeve.org (smith@jeve.org) Date: Thu, 5 Sep 2002 13:30:05 -0400 Subject: [Tutor] python xml entity problem [xml parsing and DTD handling] In-Reply-To: References: <20020904214034.GA2377@fete.jeve.org> Message-ID: <20020905173004.GA4174@fete.jeve.org> Hey Danny, I want to thank you once again, but it still doesn't work. Can you email me the list of python/xml packages you are using ? I feel like we are close, and I want to rule out everything. This is what mine looks like. ii python2.1-xml 0.7-1 XML tools for Python (2.1.x) ii python2.1-xmlb 2.1.3-3 XML support included in Python (v2.1) regards SA On Wed, Sep 04, 2002 at 06:12:35PM -0700, Danny Yoo wrote: > > > > my program still it passes over the external entity. Thanks, for your > > sample. It works great. I appreciate the time you put into that, the xml > > files I'm working with are generated form another program, so I'm not > > sure If I would be able to use it. > > Hmmm... but do the generated files set up the correct DOCTYPE element? > If I do something like this, I also get good results: > > > ### > import xml.sax > > xml_text = \ > """ > "ftp://techweb.rfa.org/pub/r-boss/xml_files/schedule.dtd"> > type="text/xsl"href="ftp://something.org/pub/xml_files/program.xsl"?> > > > > http://something/MAN/2000/02/test.mp3 > 2000/02/02 > 16:00 > &MAN; > 00:70:00 > archive > AW > AW > XZ > > """ > > > class MyContentHandler(xml.sax.handler.ContentHandler): > def __init__(self): > xml.sax.handler.ContentHandler.__init__(self) > self.indent = 0 > > def startElement(self, name, attrs): > self.printIndent() > print "I see the start of", name > self.indent += 4 > > def endElement(self, name): > self.indent -= 4 > self.printIndent() > print "I see the end of", name > > > def characters(self, text): > if text.strip(): > self.printIndent() > print "I see characters", repr(text) > pass > > def printIndent(self): > print " " * self.indent, > > > if __name__ == '__main__': > parser = xml.sax.make_parser() > handler = MyContentHandler() > parser.setContentHandler(handler) > parser.feed(xml_text) > parser.close() > ### > > > So this test case should handle external references properly too. > Perhaps there's something fishy with the generated XML that you're > getting? > > > Best of wishes! From rob@uselesspython.com Thu Sep 5 20:17:03 2002 From: rob@uselesspython.com (Rob) Date: Thu, 5 Sep 2002 14:17:03 -0500 Subject: [Tutor] searching for a value in an array In-Reply-To: Message-ID: There are different answers to your question, depending on just what you have in mind. Just for fun, here's a list of names: >>> people = ['kenny', 'stan', 'kyle', 'cartman', 'bob'] And here's an example of how to iterate through the items of the list, checking each one to see if the item is 'bob'. >>> for i in people: if i == 'bob': print "'bob' is in the list" 'bob' is in the list >>> This is case-sensitive, so 'Bob' is not the same as 'bob'. >>> for i in people: if i == 'Bob': print "'bob' is in the list" Nada from this. One fiat to this method is the multiple-bob paradigm: >>> people = ['kenny', 'stan', 'kyle', 'cartman', 'bob', 'bob', 'bob'] >>> for i in people: if i == 'bob': print "'bob' is in the list" 'bob' is in the list 'bob' is in the list 'bob' is in the list >>> Of course, you may have had something entirely different in mind when you asked your question. I just thought this would be a good excuse to show a few interesting things to any newb's who might like it. Rob http://uselesspython.com > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > anthony polis > Sent: Thursday, September 05, 2002 1:32 PM > To: tutor@python.org > Subject: [Tutor] searching for a value in an array > > > How do you search for a value in an array? For example: > > I need to check to see if the string "bob" is in the array "people". > > Thanks, > Anthony > > > > _________________________________________________________________ > Send and receive Hotmail on your mobile device: http://mobile.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From erikprice@mac.com Thu Sep 5 20:26:28 2002 From: erikprice@mac.com (Erik Price) Date: Thu, 5 Sep 2002 15:26:28 -0400 Subject: [Tutor] searching for a value in an array In-Reply-To: Message-ID: <5FDE665E-C105-11D6-984F-00039351FE6A@mac.com> On Thursday, September 5, 2002, at 02:32 PM, anthony polis wrote: > How do you search for a value in an array? For example: > > I need to check to see if the string "bob" is in the array "people". To pick nits, Python doesn't have arrays -- it has List objects. >>> strings = ['one', 'two', 'three'] >>> if ('one' in strings): print "Yes" ... else: print "No" ... Yes >>> if ('four' in strings): print "Yes" ... else: print "No" ... No Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From terjeja@hotmail.com Thu Sep 5 20:35:42 2002 From: terjeja@hotmail.com (Terje Johan Abrahamsen) Date: Thu, 05 Sep 2002 19:35:42 +0000 Subject: [Tutor] Database content Message-ID: I would like to make a program that has the possibility to get info from a list of data. Eg. I would like to have a dropdown box where I can write for example a few letters of a persons last name. Then I can use the dropdown box to select which individual I want. When I have selected the person, I get up the phonenumber, adress and so forth. How should I store this info the best? A list? al_bundy = ["chicago", "555-5433", "Dodge"] A dictionary? Other suggestions? The list of names is rather large, but the program should hopefully be used on different computers, so a link to Excel, Access or a SQL database is not possible. Everything has to be run in Python. Thanks.. _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com From glingl@aon.at Thu Sep 5 20:39:20 2002 From: glingl@aon.at (Gregor Lingl) Date: Thu, 05 Sep 2002 21:39:20 +0200 Subject: [Tutor] searching for a value in an array References: Message-ID: <3D77B2E8.4010107@aon.at> Danny Yoo schrieb: >I think you'll like this one: it's basically what you just said: > >### > > >>>>print 'bob' in ['jane', 'hector', 'alissa', 'john', 'lisa', 'bob', >>>> >>>> >... 'iris'] >1 >### > >The 'in' operator returns true if it can find our item in a list, and >false otherwise. What Python does here is a "linear" scan: it'll march >through our list until it either runs out of list, or if it finds 'bob'. > > >There are faster ways of seeing if someone is present in a group of >people: we can use a dictionary: > >### > > >>>>people = { 'jane' : 1, 'hector' : 1, 'alissa' : 1 } >>>>'jane' in people >>>> >>>> >1 > > >>>>'bob' in people >>>> >>>> >0 >### > > Faster ways? >>> txt = """The 'in' operator returns true if it can find our item in a list, and false otherwise. What Python does here is a "linear" scan: it'll march through our list until it either runs out of list, or if it finds 'bob'. There are faster ways of seeing if someone is present in a group of people: we can use a dictionary: ### >>> people = { 'jane' : 1, 'hector' : 1, 'alissa' : 1 } >>> 'jane' in people 1 >>> 'bob' in people 0""".split() >>> txt ['The', "'in'", 'operator', 'returns', 'true', 'if', 'it', 'can', 'find', 'our', 'item', 'in', 'a', 'list,', 'and', 'false', 'otherwise.', 'What', 'Python', 'does', 'here', 'is', 'a', '"linear"', 'scan:', "it'll", 'march', 'through', 'our', 'list', 'until', 'it', 'either', 'runs', 'out', 'of', 'list,', 'or', 'if', 'it', 'finds', "'bob'.", 'There', 'are', 'faster', 'ways', 'of', 'seeing', 'if', 'someone', 'is', 'present', 'in', 'a', 'group', 'of', 'people:', 'we', 'can', 'use', 'a', 'dictionary:', '###', '>>>', 'people', '=', '{', "'jane'", ':', '1,', "'hector'", ':', '1,', "'alissa'", ':', '1', '}', '>>>', "'jane'", 'in', 'people', '1', '>>>', "'bob'", 'in', 'people', '0'] >>> txtdict={} >>> for item in txt: txtdict[item]=1 >>> txtdict {'and': 1, 'seeing': 1, 'What': 1, '"linear"': 1, 'false': 1, '0': 1, 'people': 1, 'is': 1, 'There': 1, 'it': 1, 'list,': 1, 'through': 1, 'are': 1, 'in': 1, 'operator': 1, 'our': 1, 'find': 1, 'if': 1, "'jane'": 1, '1,': 1, 'use': 1, 'group': 1, 'item': 1, 'ways': 1, "'hector'": 1, '1': 1, "'bob'.": 1, 'returns': 1, 'does': 1, 'out': 1, '=': 1, 'until': 1, '###': 1, 'can': 1, 'we': 1, 'someone': 1, 'march': 1, "'bob'": 1, 'otherwise.': 1, "'in'": 1, 'here': 1, 'dictionary:': 1, '>>>': 1, 'The': 1, 'true': 1, 'present': 1, 'a': 1, 'runs': 1, ':': 1, 'faster': 1, 'of': 1, 'list': 1, 'or': 1, 'Python': 1, 'either': 1, 'scan:': 1, '{': 1, "'alissa'": 1, '}': 1, 'finds': 1, 'people:': 1, "it'll": 1} >>> import time >>> def checktime(value, collection, reps=100000): t = time.time() i = 0 while i < reps: i+=1 value in collection print time.time()-t >>> checktime("bob",txt) 2.98500001431 >>> checktime("The",txt) 0.360999941826 >>> checktime("Python",txt) 0.900999903679 >>> checktime("'bob'",txt) 2.8939999342 >>> checktime("0",txt) 3.08400011063 >>> checktime("bob",txtdict) 0.320999979973 >>> checktime("The",txtdict) 0.340000033379 >>> checktime("Python",txtdict) 0.340999960899 >>> checktime("0",txtdict) 0.330999970436 >>> checktime("'bob'",txtdict) 0.330999970436 >>> Indeed! Gregor From shalehperry@attbi.com Thu Sep 5 20:41:38 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Thu, 5 Sep 2002 12:41:38 -0700 Subject: [Tutor] Perl to Python code migration In-Reply-To: <3D779BE3.A154E3A1@ccvcorp.com> References: <20020905164631.42180.qmail@web40403.mail.yahoo.com> <3D779BE3.A154E3A1@ccvcorp.com> Message-ID: <200209051241.38167.shalehperry@attbi.com> On Thursday 05 September 2002 11:01, Jeff Shannon wrote: > Levy Lazarre wrote: > > Good afternoon all, > > > > In Python what is the fastest way to break a file into > > records according to a fixed string delimiter? [...] > > > > The string "(ID 1)" marks the beginning of a new > > record. [...] > > Try using the split() string method. > > infile =3D open('myfile.txt', 'r') > data =3D infile.read() > infile.close() > records =3D data.split( "(ID 1)" ) > > Now 'records' holds a list. Each element of that list is a block that = was > delimited by the argument to split() (in this case, "(ID 1)"). Note th= at > if your file starts with the delimiter, then records[0] will be an empt= y > string. > and you just violated his request that the whole file not be read in at o= nce. I am not aware of a clean method that mimics the perl code directly. My = usual=20 tactic is to read the file line by line looking for the tags I am interes= ted=20 in (like 'ID 1') and use something like a state variable to control furth= er=20 reading. From buc40@bemail.org Thu Sep 5 21:15:11 2002 From: buc40@bemail.org (S A) Date: Thu, 5 Sep 2002 13:15:11 -0700 Subject: [Tutor] searching for a value in an array Message-ID: <200209052015.g85KFB728924@mail24.bigmailbox.com> This is a multi-part message in MIME format... --RyPi5XhfkmOmkCQj5HFxg5Rya Content-Type: text/plain Content-Transfer-Encoding: 8bit > Re: [Tutor] searching for a value in an arrayCc: tutor@python.org > "anthony polis" Erik Price Date: Thu, 5 Sep 2002 15:26:28 -0400 > > >To pick nits, Python doesn't have arrays -- it has List objects. Umm... I think this is not entirely true. A list is a mutable sequence type. Python has another mutable sequence type in the array module. http://www.python.org/doc/current/ref/types.html I'm not sure about this array module since I have not messed with it. However, the built-in type "lists" should do the trick for you. Good Luck. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- --RyPi5XhfkmOmkCQj5HFxg5Rya Content-Type: text/html Content-Transfer-Encoding: 8bit

> Re: [Tutor] searching for a value in an arrayCc: tutor@python.org
> "anthony polis"  Erik Price Date: Thu, 5 Sep 2002 15:26:28 -0400
>
>
>To pick nits, Python doesn't have arrays -- it has List objects.

Umm...
I think this is not entirely true. A list is a mutable sequence type. Python has 
another mutable sequence type in the array module.

http://www.python.org/doc/current/ref/types.html

I'm not sure about this array module since I have not messed with it. However, 
the built-in type "lists" should do the trick for you.


Good Luck.
SA




"I can do everything on my Mac that I used to do on my PC, plus alot more ..."

-Me

------------------------------------------------------------
Free, BeOS-friendly email accounts: http://BeMail.org/
BeOS News and Community: http://www.BeGroovy.com/


---------------------------------------------------------------------
Express yourself with a super cool email address from BigMailBox.com.
Hundreds of choices. It's free!
http://www.bigmailbox.com
---------------------------------------------------------------------
--RyPi5XhfkmOmkCQj5HFxg5Rya-- From dyoo@hkn.eecs.berkeley.edu Thu Sep 5 21:20:41 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 5 Sep 2002 13:20:41 -0700 (PDT) Subject: [Tutor] searching for a value in an array (fwd) Message-ID: Hi Anthony, Let's keep the discussion on Tutor, so that other people have the opportunity to help you. Also, there may be people who'd like to know how to do this value-removing as well, so I'll forward your question to Tutor. ---------- Forwarded message ---------- Date: Thu, 05 Sep 2002 19:21:40 +0000 From: anthony polis To: dyoo@hkn.eecs.berkeley.edu Subject: Re: [Tutor] searching for a value in an array Danny, Now I know how to search a list. But how do you pop() a list item without knowing it's location in the list? The Python tutorial told me I have to provide an integer in order to pop() an item out. How do I pop() an item out when I only know it's value? _________________________________________________________________ Join the world=92s largest e-mail service with MSN Hotmail. http://www.hotmail.com From scot@possum.in-berlin.de Thu Sep 5 09:20:25 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Thu, 5 Sep 2002 10:20:25 +0200 Subject: [Tutor] Re: Factory classes (etc) In-Reply-To: <5.1.0.14.0.20020904094606.02ae4690@www.thinkware.se> References: <5.1.0.14.0.20020904094606.02ae4690@www.thinkware.se> Message-ID: <200209051020.25303.scot@possum.in-berlin.de> Hello Magnus, Thank you for the long answer! > Your spray can example is neither an "Abstract Factory" nor a "Factory > Method" I'm afraid. Both the "Abstract Factory" and "Factory Method" > patterns return instances of _different_classes_ depending on the > situation. I knew it was too good to be true =8). > # Factory function for symmetrical shapes > def getSymmetricalShape(x, y, size, corners=0, angle=0): > assert type(corners) == type(1) and (corners == 0 or corners > 1) > if corners == 0: > return Circle(x, y, size) > elif corners == 2: > return Line(x, y, size, angle) > elif corners == 3: > return Triangle(x, y, size, angle) > elif corners == 4: > return Square(x, y, size, angle) > else: > return RegularPolygon(x, y, size, sides, angle) Ah, now I understand. Just as an aside, if I were to really programm something like this (which is certainly the best way to understand the principle), would I want to use a if-elif-else construct like above, or rather a dictionary such as: shapes = {0: Circle, 2: Line, 3: Triangle, [...]} and then do a shapes[corners](x, y, size, angle) which would assume that Circle doesn't go balistic if it is suddenly handed an angle. Again, I'm glad you did it this way here, because it is easier to understand. > This is a bit strange, since the Pattern > movement (in software design) started among SmallTalkers, and SmallTalk > is dynamically typed--I don't know enough SmallTalk to explain this. Does anybody actually _use_ SmallTalk for production code, or is it one of those teaching languages that revolutionized various concepts but never made it in the market (sort of like Multics [sp] vs. Unix, or the League of Nations vs. the United Nations, or for that matter, "Buffy" the Film vs. "Buffy" the TV series)? > I'm not saying that the ideas in GoF are overly complex, but I think > it would have been a much thinner book if the Gang of Four had used > Python... Are there any common patterns that are missing by today's standards? I'm thinking about the Borg "non-pattern" described in the "Python Cookbook" - I can't believe that seven years later, the GoF is still state of the art... Thanks again, Y, Scot -- Scot W. Stevenson wrote me on Thursday, 5. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1903 hours and has a CPU that is falling asleep at a system load of 0.08. From printers@sendme.cz Thu Sep 5 14:20:31 2002 From: printers@sendme.cz (A) Date: Thu, 05 Sep 2002 15:20:31 +0200 Subject: [Tutor] What database should I use Message-ID: <3D77763F.23080.BFAFA3@localhost> Hello, I am going to program a small application (in Python and wxPython) which consists about 2000 - 3000 records . Can you please recommend which database is the best for that. I use Windows. Maybe MS Access or FoxPro or MySQL or better? I want to keep the program as small as possible. Thanks Ladislav From buc40@bemail.org Thu Sep 5 21:48:13 2002 From: buc40@bemail.org (S A) Date: Thu, 5 Sep 2002 13:48:13 -0700 Subject: [Tutor] How does Shelve work? Message-ID: <200209052048.g85KmDA14667@mail6.bigmailbox.com> Can someone please explain how the Shelve module works? I tried to use a shelve.open (filename) command on a blank flat file and got an error saying that it could not determine the database type? Traceback (most recent call last): File "", line 1, in ? File "/sw/lib/python2.2/shelve.py", line 158, in open return DbfilenameShelf(filename, flag) File "/sw/lib/python2.2/shelve.py", line 148, in __init__ Shelf.__init__(self, anydbm.open(filename, flag)) File "/sw/lib/python2.2/anydbm.py", line 83, in open raise error, "db type could not be determined" anydbm.error: db type could not be determined >>> d = shelve.open('test2') Traceback (most recent call last): File "", line 1, in ? File "/sw/lib/python2.2/shelve.py", line 158, in open return DbfilenameShelf(filename, flag) File "/sw/lib/python2.2/shelve.py", line 148, in __init__ Shelf.__init__(self, anydbm.open(filename, flag)) File "/sw/lib/python2.2/anydbm.py", line 83, in open raise error, "db type could not be determined" anydbm.error: db type could not be determined Is this saying that it can not find a database to run on my computer or that the file is not of a database type? Please excuse the ignorance, I'm just now dabbling in databases. Thanks. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From erikprice@mac.com Thu Sep 5 22:18:17 2002 From: erikprice@mac.com (Erik Price) Date: Thu, 5 Sep 2002 17:18:17 -0400 Subject: [Tutor] searching for a value in an array (fwd) In-Reply-To: Message-ID: On Thursday, September 5, 2002, at 04:20 PM, Danny Yoo wrote: > ---------- Forwarded message ---------- > Date: Thu, 05 Sep 2002 19:21:40 +0000 > From: anthony polis > To: dyoo@hkn.eecs.berkeley.edu > Subject: Re: [Tutor] searching for a value in an array > > Danny, > > Now I know how to search a list. But how do you pop() a list item > without > knowing it's location in the list? The Python tutorial told me I have > to > provide an integer in order to pop() an item out. How do I pop() an > item > out when I only know it's value? This one's easy. You want the index() method of List objects: >>> somelist = ['he-man', 'man-at-arms', 'skeletor', 'zoar'] >>> badguy = 'skeletor' >>> num = somelist.index(badguy) >>> popped = somelist.pop(num) >>> popped 'skeletor' >>> somelist ['he-man', 'man-at-arms', 'zoar'] >>> I'm not sure what happens if there's more than one element in the list that matches the argument to index. Let's find out: >>> somelist ['he-man', 'man-at-arms', 'zoar'] >>> somelist.insert(2, badguy) >>> somelist ['he-man', 'man-at-arms', 'skeletor', 'zoar'] >>> somelist.append('skeletor') >>> somelist ['he-man', 'man-at-arms', 'skeletor', 'zoar', 'skeletor'] >>> somelist.pop(somelist.index(badguy)) 'skeletor' >>> somelist ['he-man', 'man-at-arms', 'zoar', 'skeletor'] >>> Looks like it goes for the lowest-indexed element matching the argument to index() but you might want to research this more. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From buc40@bemail.org Thu Sep 5 22:15:18 2002 From: buc40@bemail.org (S A) Date: Thu, 5 Sep 2002 14:15:18 -0700 Subject: [Tutor] Dictionary Question. Message-ID: <200209052115.g85LFIW08441@mail12.bigmailbox.com> Let me first setup the scenario: I have a dictionary that contains keys that are names of people. Each one of these keys contains three items: 1.phone number 2.address 3.email The program is set up to first ask the user to input a new key(name). Then the user is asked to enter first the phone number, followed by the address, and finally the email. This of course is repeated for many keys(names). (kinda of like an addressbook) I want to ensure first that each item for the key is listed in the same order of input: {key:('phone number', 'address', 'email')} Will this be the case for every key? Or will the list for every key place the values in random order? Next is there a way to sort the keys, say alphabetically, without disturbing the key:value relationship? (In case you have not yet noticed, I'm trying to build a simple database using dictionaries and I need to be able to enter/retrieve fields for specific relational keys) Thanks in advance. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From buc40@bemail.org Thu Sep 5 22:18:24 2002 From: buc40@bemail.org (S A) Date: Thu, 5 Sep 2002 14:18:24 -0700 Subject: [Tutor] GUI question Message-ID: <200209052118.g85LIOU08562@mail12.bigmailbox.com> With the plethora of GUI's that support python (Tkinter, QT, wxPython, ...), would HTML better serve as a gui for platform independent data entry into a python scripted db? I ask this since some of the platforms this data will goto supports HTML but not the others. Actually HTML is the only interface that is supported on all platforms the script will run on.(like portable devices for example) Thanks in advance. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From shalehperry@attbi.com Thu Sep 5 22:22:01 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Thu, 5 Sep 2002 14:22:01 -0700 Subject: [Tutor] Dictionary Question. In-Reply-To: <200209052115.g85LFIW08441@mail12.bigmailbox.com> References: <200209052115.g85LFIW08441@mail12.bigmailbox.com> Message-ID: <200209051422.01667.shalehperry@attbi.com> On Thursday 05 September 2002 14:15, S A wrote: > > I want to ensure first that each item for the key is listed in the same > order of input: > > {key:('phone number', 'address', 'email')} > > Will this be the case for every key? Or will the list for every key pla= ce > the values in random order? > a list is always in the order of creation. So: my_list.append(phone) my_list.append(address) my_list.append(email) will result in a list in the order you want. A dictionary does not touch= its=20 data, it just holds it. > Next is there a way to sort the keys, say alphabetically, without > disturbing the key:value relationship? (In case you have not yet notice= d, > I'm trying to build a simple database using dictionaries and I need to = be > able to enter/retrieve fields for specific relational keys) > you can not directly control how a dictionary stores its key or the order= they=20 are in. The usual solution to what you want is: keys =3D my_dict.keys() keys.sort() # remember, you can pass a function to sort to help # control the order From steve_lewis@openiso.com Thu Sep 5 23:39:36 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Thu, 5 Sep 2002 17:39:36 -0500 (CDT) Subject: [Tutor] First script project... Message-ID: <6539.199.66.1.5.1031265576.squirrel@www.absolutenettech.com> Hello, This is my first post to tutor list and am just starting to learn Pyton. I work in a very busy Helpdesk at the nations largest poultry producer. As my first learning project I would like to automate the opening of the many tools, apps, that we use. We are standardized on W2K pro. I have a folder on my Desktop that contains Shortcuts to all of my tools. I open the apps one at a time using the shortcuts. What I thought may be a good and useful Python learning project is creating a script that will open all of my apps with the one script. A gentle nudge in the correct direction would be great. I am using online tutorials, papers and "The Quick Python BooK" to learn with. I am learning alone so I hoped this list and all of the fine folks here would help fill the void. Thank you for any and all advice, pointers and gentle nudges. Steve Lewis From israel@lith.com Thu Sep 5 23:50:37 2002 From: israel@lith.com (Israel Evans) Date: Thu, 5 Sep 2002 15:50:37 -0700 Subject: [Tutor] First script project... Message-ID: In order to start a bunch of my webdev programs, I did something along the lines of: ### #!python import os #start Webware's Webkit os.chdir('c:/proj/webware/WebKit') os.system('start AppServer.bat') #start Apache http server os.system('start C:\proj\apacheGroup\Apache\Apache.exe -w -f "C:\proj\ApacheGroup\Apache\conf\httpd.conf" -d "C:\proj\ApacheGroup\Apache\"') #start the mySQL server and the Admin Tool os.system('start c:/proj/mysql/bin/winmysqladmin.exe') ### So really what I was doing here was making python pass strings to the system in much the same way that you would start a program from the dos prompt or the command program. I just double click the script on my desktop and all these programs are launched. -----Original Message----- From: Steve Lewis [mailto:steve@openiso.com] Sent: Thursday, September 05, 2002 3:40 PM To: tutor@python.org Subject: [Tutor] First script project... Hello, This is my first post to tutor list and am just starting to learn Pyton. I work in a very busy Helpdesk at the nations largest poultry producer. As my first learning project I would like to automate the opening of the many tools, apps, that we use. We are standardized on W2K pro. I have a folder on my Desktop that contains Shortcuts to all of my tools. I open the apps one at a time using the shortcuts. What I thought may be a good and useful Python learning project is creating a script that will open all of my apps with the one script. A gentle nudge in the correct direction would be great. I am using online tutorials, papers and "The Quick Python BooK" to learn with. I am learning alone so I hoped this list and all of the fine folks here would help fill the void. Thank you for any and all advice, pointers and gentle nudges. Steve Lewis _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From scot@possum.in-berlin.de Fri Sep 6 00:35:15 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Fri, 6 Sep 2002 01:35:15 +0200 Subject: [Tutor] Different idioms for making lists of strings Message-ID: <200209060135.15945.scot@possum.in-berlin.de> Hello there, While working my way thru the "Python Cookbook", I have come across a couple of examples where lists of strings are created not the "normal" way alist = ['From', 'To', 'Subject'] but by splitting up a string alist = 'From To Subject'.split() which of course is a lot easier to type, the computation involved should be trivial, and the days when you would have had to import the string module to do stuff like this are long over. So I thought I'd point it out to the rest of the crowd here. Y, Scot -- Scot W. Stevenson wrote me on Friday, 6. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1918 hours and has a CPU that is falling asleep at a system load of 0.05. From python Fri Sep 6 00:55:32 2002 From: python (python) Date: Thu, 5 Sep 2002 16:55:32 -0700 Subject: [Tutor] Different idioms for making lists of strings In-Reply-To: <200209060135.15945.scot@possum.in-berlin.de> References: <200209060135.15945.scot@possum.in-berlin.de> Message-ID: <6059556010.20020905165532@inkedmn.net> Scot, you can also create lists using loops: >>> oldlist [1, 2, 3, 4, 5] >>> newlist [] >>> for item in oldlist: ... newlist.append(item) ... >>> newlist [1, 2, 3, 4, 5] brett SWS> Hello there, SWS> While working my way thru the "Python Cookbook", I have come across a SWS> couple of examples where lists of strings are created not the "normal" way SWS> alist = ['From', 'To', 'Subject'] SWS> but by splitting up a string SWS> alist = 'From To Subject'.split() SWS> which of course is a lot easier to type, the computation involved should be SWS> trivial, and the days when you would have had to import the string module SWS> to do stuff like this are long over. So I thought I'd point it out to the SWS> rest of the crowd here. SWS> Y, Scot From shalehperry@attbi.com Fri Sep 6 00:50:52 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Thu, 5 Sep 2002 16:50:52 -0700 Subject: [Tutor] Different idioms for making lists of strings In-Reply-To: <200209060135.15945.scot@possum.in-berlin.de> References: <200209060135.15945.scot@possum.in-berlin.de> Message-ID: <200209051650.52447.shalehperry@attbi.com> On Thursday 05 September 2002 16:35, Scot W. Stevenson wrote: > Hello there, > > While working my way thru the "Python Cookbook", I have come across a > couple of examples where lists of strings are created not the "normal" = way > > alist =3D ['From', 'To', 'Subject'] > > but by splitting up a string > > alist =3D 'From To Subject'.split() > > which of course is a lot easier to type, the computation involved shoul= d be > trivial, and the days when you would have had to import the string modu= le > to do stuff like this are long over. So I thought I'd point it out to t= he > rest of the crowd here. > > Y, Scot My only problem with this is it masks the intent of the code. 'From To=20 Subject' is now a magic constant. Why do I have it? What does it mean? = =20 Will it change? When I do alist =3D [....] it is obvious I am constructi= ng a=20 list from known strings. Using the .split() methods gives the impression= the=20 string itself is important. From mufuboy2002@yahoo.com Thu Sep 5 20:20:09 2002 From: mufuboy2002@yahoo.com (dirk pitt) Date: Thu, 5 Sep 2002 12:20:09 -0700 (PDT) Subject: [Tutor] confused! Message-ID: <20020905192009.96186.qmail@web20101.mail.yahoo.com> --0-2063017906-1031253609=:95735 Content-Type: text/plain; charset=us-ascii hi there. i just want to if TCL is another type of programing language or a program inside phyton and for example, when u type >>>print "hello world" and run it what should u expect the computer to do. bye --------------------------------- Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes --0-2063017906-1031253609=:95735 Content-Type: text/html; charset=us-ascii

hi there. i just want to if TCL is another type of programing language or a program inside phyton and for example, when u type >>>print "hello world" and run it what should u expect the computer to do.

bye



Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes --0-2063017906-1031253609=:95735-- From ckasso@sprynet.com Fri Sep 6 03:22:36 2002 From: ckasso@sprynet.com (Chris Kassopulo) Date: Thu, 5 Sep 2002 22:22:36 -0400 Subject: [Tutor] function vs module Message-ID: <20020905222236.4fc87f32.ckasso@sprynet.com> This is a multi-part message in MIME format. --Multipart_Thu__5_Sep_2002_22:22:36_-0400_0827b9d8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Greetings, I'm working on some scripts that output stuff to the screen. For example, the attached script, list_modules.py formats and outputs a list of builtin modules. When I convert it to ListModules.py to use a module, ListColumns.py I get: $ /home/ckasso/python/scripts/AsciiChart.py Traceback (most recent call last): File "/home/ckasso/python/scripts/AsciiChart.py", line 50, in ? ListColumns.ListColumns(AsciiList) File "/home/ckasso/python/scripts/ListColumns.py", line 18, in ListColumns if ReturnFlag == 0: NameError: global name 'ReturnFlag' is not defined ReturnFlag = 0 at the beginning of ListColumns gets around the error, but I can't set it there. The intention is that scripts that use ListColumns will set the flag and ListColumns just reads it. I thought that making ReturnFlag global in ListColumns would work, but it doesn't. Could someone shed some light on this please. Thanks, Chris Kassopulo Python 2.2.1 (#1, Apr 11 2002, 15:27:15) --Multipart_Thu__5_Sep_2002_22:22:36_-0400_0827b9d8 Content-Type: application/octet-stream; name="list_modules.py" Content-Disposition: attachment; filename="list_modules.py" Content-Transfer-Encoding: base64 IyEgL3Vzci9iaW4vZW52IHB5dGhvbgoKZGVmIExpc3RDb2x1bW5zKE1lbnVJdGVtcyxOdW1iZXJv ZkNvbHVtbnM9NCk6CgoJIyBKdXN0aWZ5IGFuZCBvdXRwdXQgYSBsaXN0IG9mIHN0cmluZ3MgaW4g Y29sdW1ucyBmcm9tIGxlZnQgdG8gcmlnaHQKCQoJaW1wb3J0IHN0cmluZwoJCgkjIGluaXRpYWxp emUKCVJldHVybkZsYWcgPSAwCglDdXJyZW50Q29sdW1uID0gMQoKCSMgbGVuZ3RoIG9mIGxvbmdl c3Qgc3RyaW5nIGZvciBjb2x1bW4gd2lkdGgKCUxvbmdlc3RMZW5ndGggPSBtYXgoW2xlbihpdGVt KSBmb3IgaXRlbSBpbiBNZW51SXRlbXNdKQoKCSMgb3V0cHV0IHRoZSBsaXN0Cglmb3IgaXRlbSBp biBNZW51SXRlbXM6CgkKCQkjIG91dHB1dCBpcyB0byBiZSBwcmludGVkCgkJaWYgUmV0dXJuRmxh ZyA9PSAwOgoJCQoJCQkjIGp1c3RpZnkgYW5kIG91dHB1dCB0aGUgbGlzdCB0byBjb25zb2xlCgkJ CWlmIEN1cnJlbnRDb2x1bW4gPCBOdW1iZXJvZkNvbHVtbnM6CgkJCQlwcmludCBzdHJpbmcubGp1 c3QoaXRlbSxMb25nZXN0TGVuZ3RoKSwnfCcsCgkJCQlDdXJyZW50Q29sdW1uICs9IDEKCQkJZWxz ZToKCQkJCXByaW50IHN0cmluZy5sanVzdChpdGVtLExvbmdlc3RMZW5ndGggKyAxKQoJCQkJQ3Vy cmVudENvbHVtbiA9IDEKCQkJCQoJCSMgYnVpbGQgYSBuZXcgbGlzdCB3aXRoIGp1c3RpZmllZCBh bmQgcGFkZGVkIHN0cmluZ3MKCQllbHNlOiBSZXR1cm5MaXN0LmFwcGVuZChzdHJpbmcubGp1c3Qo aXRlbSxMb25nZXN0TGVuZ3RoICsgMSkpCgkJCQoJIyByZXR1cm4gdGhlIG5ldyBsaXN0CglpZiBS ZXR1cm5GbGFnID09IDE6CXJldHVybiBSZXR1cm5MaXN0CgojIGxpc3RfbW9kdWxlcy5weQojIGZv cm1hdCBhbmQgbGlzdCBidWlsdGluIG1vZHVsZXMKCmltcG9ydCBzeXMKCiMgZ2V0IHRoZSBsaXN0 Ck1vZHVsZU5hbWVzID0gKHN5cy5idWlsdGluX21vZHVsZV9uYW1lcykKCiMgcGFzcyBmb3IgcHJv Y2Vzc2luZwpMaXN0Q29sdW1ucyhNb2R1bGVOYW1lcykK --Multipart_Thu__5_Sep_2002_22:22:36_-0400_0827b9d8 Content-Type: application/octet-stream; name="ListModules.py" Content-Disposition: attachment; filename="ListModules.py" Content-Transfer-Encoding: base64 IyEgL3Vzci9iaW4vZW52IHB5dGhvbgoKIyBMaXN0TW9kdWxlcy5weQojIGZvcm1hdCBhbmQgbGlz dCBidWlsdGluIG1vZHVsZXMKCmltcG9ydCBzeXMKaW1wb3J0IExpc3RDb2x1bW5zCgojIGdldCB0 aGUgbGlzdApNb2R1bGVOYW1lcyA9IChzeXMuYnVpbHRpbl9tb2R1bGVfbmFtZXMpCgojIHBhc3Mg Zm9yIHByb2Nlc3NpbmcKTGlzdENvbHVtbnMuTGlzdENvbHVtbnMoTW9kdWxlTmFtZXMpCg== --Multipart_Thu__5_Sep_2002_22:22:36_-0400_0827b9d8 Content-Type: application/octet-stream; name="ListColumns.py" Content-Disposition: attachment; filename="ListColumns.py" Content-Transfer-Encoding: base64 ZGVmIExpc3RDb2x1bW5zKE1lbnVJdGVtcyxOdW1iZXJvZkNvbHVtbnM9NCk6CgoJIyBMaXN0Q29s dW1ucy5weQoJIyBqdXN0aWZ5IGFuZCBvdXRwdXQgYSBsaXN0IG9mIHN0cmluZ3MgaW4gY29sdW1u cyBmcm9tIGxlZnQgdG8gcmlnaHQKCQoJaW1wb3J0IHN0cmluZwoJCgkjIGluaXRpYWxpemUKCUN1 cnJlbnRDb2x1bW4gPSAxCgoJIyBsZW5ndGggb2YgbG9uZ2VzdCBzdHJpbmcgZm9yIGNvbHVtbiB3 aWR0aAoJTG9uZ2VzdExlbmd0aCA9IG1heChbbGVuKGl0ZW0pIGZvciBpdGVtIGluIE1lbnVJdGVt c10pCgoJIyBvdXRwdXQgdGhlIGxpc3QKCWZvciBpdGVtIGluIE1lbnVJdGVtczoKCQoJCSMgb3V0 cHV0IGlzIHRvIGJlIHByaW50ZWQKCQlpZiBSZXR1cm5GbGFnID09IDA6CgkJCgkJCSMganVzdGlm eSBhbmQgb3V0cHV0IHRoZSBsaXN0IHRvIGNvbnNvbGUKCQkJaWYgQ3VycmVudENvbHVtbiA8IE51 bWJlcm9mQ29sdW1uczoKCQkJCXByaW50IHN0cmluZy5sanVzdChpdGVtLExvbmdlc3RMZW5ndGgp LCd8JywKCQkJCUN1cnJlbnRDb2x1bW4gKz0gMQoJCQllbHNlOgoJCQkJcHJpbnQgc3RyaW5nLmxq dXN0KGl0ZW0sTG9uZ2VzdExlbmd0aCArIDEpCgkJCQlDdXJyZW50Q29sdW1uID0gMQoJCQkJCgkJ IyBidWlsZCBhIG5ldyBsaXN0IHdpdGgganVzdGlmaWVkIGFuZCBwYWRkZWQgc3RyaW5ncwoJCWVs c2U6IFJldHVybkxpc3QuYXBwZW5kKHN0cmluZy5sanVzdChpdGVtLExvbmdlc3RMZW5ndGggKyAx KSkKCQkJCgkjIHJldHVybiB0aGUgbmV3IGxpc3QKCWlmIFJldHVybkZsYWcgPT0gMToJcmV0dXJu IFJldHVybkxpc3QK --Multipart_Thu__5_Sep_2002_22:22:36_-0400_0827b9d8-- From shalehperry@attbi.com Fri Sep 6 03:20:45 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Thu, 5 Sep 2002 19:20:45 -0700 Subject: [Tutor] confused! In-Reply-To: <20020905192009.96186.qmail@web20101.mail.yahoo.com> References: <20020905192009.96186.qmail@web20101.mail.yahoo.com> Message-ID: <200209051920.45640.shalehperry@attbi.com> On Thursday 05 September 2002 12:20, dirk pitt wrote: > hi there. i just want to if TCL is another type of programing language = or a > program inside phyton and for example, when u type >>>print "hello worl= d" > and run it what should u expect the computer to do. > TCL is another programming language and has nothing to do with python. T= k is=20 a GUI toolkit that was originally written for TCL and is now used by seve= ral=20 programming languages including python, perl and ruby. The python program: print "Hello, World!" Will cause the text "Hello, World!" to appear in the text window the prog= ram=20 is run in. From jeff@ccvcorp.com Fri Sep 6 03:24:27 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Thu, 05 Sep 2002 19:24:27 -0700 Subject: [Tutor] Perl to Python code migration References: <20020905164631.42180.qmail@web40403.mail.yahoo.com> <3D779BE3.A154E3A1@ccvcorp.com> <200209051241.38167.shalehperry@attbi.com> Message-ID: <3D7811DA.68479730@ccvcorp.com> Sean 'Shaleh' Perry wrote: > On Thursday 05 September 2002 11:01, Jeff Shannon wrote: > > > > Try using the split() string method. > > > > and you just violated his request that the whole file not be read in at once. I didn't see any explicit specification along those lines... though perhaps it was implied by the Perl idiom. I don't know Perl, so I'd miss that. Given that restriction, then the best solution probably would be to read in small chunks of the file (possibly using xreadlines() if it's broken into lines) until the delimiter is found, and accumulating those chunks manually. Jeff Shannon Technician/Programmer Credit International From erikprice@mac.com Fri Sep 6 05:21:36 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 6 Sep 2002 00:21:36 -0400 Subject: [Tutor] Different idioms for making lists of strings In-Reply-To: <200209060135.15945.scot@possum.in-berlin.de> Message-ID: <22122B71-C150-11D6-BDA3-00039351FE6A@mac.com> On Thursday, September 5, 2002, at 07:35 PM, Scot W. Stevenson wrote: > which of course is a lot easier to type, the computation involved > should be > trivial, and the days when you would have had to import the string > module > to do stuff like this are long over. So I thought I'd point it out to > the > rest of the crowd here. That never would have occurred to me. And it is a quicker way to do it. It doesn't feel as "right" (canonical?) as the traditional List literal, but there's really nothing wrong with it. I guess the only thing is that it's not as obvious as using a List literal (assuming that obviousness is something that should be praised in the Python approach), but it's hardly obfuscated. Thanks Scot. Erik (PS: it reminds me of Perl's qw() function) -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From scot@possum.in-berlin.de Fri Sep 6 00:58:59 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Fri, 6 Sep 2002 01:58:59 +0200 Subject: [Tutor] GUI question In-Reply-To: <200209052118.g85LIOU08562@mail12.bigmailbox.com> References: <200209052118.g85LIOU08562@mail12.bigmailbox.com> Message-ID: <200209060158.59591.scot@possum.in-berlin.de> Hi there, > With the plethora of GUI's that support python (Tkinter, QT, wxPython, > ...), would HTML better serve as a gui for platform independent data > entry into a python scripted db? You might want to take a look at the "anygui" project that lets your code work with anything from Tkinter to Swing, or so it claims. The "Python Cookbook" has one pretty cool looking example, and gives the web page as http://www.anygui.org - note that I haven't tried this myself, and it says here that the code is still beta. But that was probably _weeks_ ago =8). Y, Scot -- Scot W. Stevenson wrote me on Friday, 6. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1919 hours and has a CPU that is falling asleep at a system load of 0.03. From scot@possum.in-berlin.de Fri Sep 6 00:50:49 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Fri, 6 Sep 2002 01:50:49 +0200 Subject: [Tutor] searching for a value in an array In-Reply-To: References: Message-ID: <200209060150.49128.scot@possum.in-berlin.de> Hello Danny, > There are faster ways of seeing if someone is present in a group of > people: we can use a dictionary: And, just in case anybody is getting funny ideas about Python becoming stable any time soon, in Python 2.3, you will be able to use "sets" instead. If I understand the concept, these unordered collections would be even better here, because they are "hashable" (which seems to be computerspeak for "the Python Elves can access them really, really quickly, and their speed doesn't depend on the number of elements") so you don't have to use those dummy 1's as values of a dictionary like you did in your example. What will they ever think of next =8). Y, Scot -- Scot W. Stevenson wrote me on Friday, 6. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1919 hours and has a CPU that is falling asleep at a system load of 0.00. From erikprice@mac.com Fri Sep 6 05:29:45 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 6 Sep 2002 00:29:45 -0400 Subject: [Tutor] Perl to Python code migration In-Reply-To: <3D7811DA.68479730@ccvcorp.com> Message-ID: <45520544-C151-11D6-BDA3-00039351FE6A@mac.com> On Thursday, September 5, 2002, at 10:24 PM, Jeff Shannon wrote: >> and you just violated his request that the whole file not be read in >> at once. > > I didn't see any explicit specification along those lines... though > perhaps it > was implied by the Perl idiom. I don't know Perl, so I'd miss that. Surrounded by the question itself and the code, it was pretty easy to miss, but Levy did say that: Since Python doesn't have similar constructs, I wonder what would be the most efficient approach. I do not want to load the whole file in memory at once. > Given that restriction, then the best solution probably would be to > read in small > chunks of the file (possibly using xreadlines() if it's broken into > lines) until > the delimiter is found, and accumulating those chunks manually. I was thinking about this earlier today, but it's a hard one. xreadlines() seems like the best solution, except that the data is not separated into separate lines (it's multi-line). Really the best thing to do I think would be to write an event handler (like those used in SAX processing) and parse over the data, setting flags at certain points and being careful to "grab" the chunks when they are detected. xreadlines() will work for this as long as the code that does this parsing is able to "remember" a previous line (i.e. store it in a temporary variable or something) while it continues to parse the next lines up to the next delimiter text. This is one case for XML -- easier to parse than raw data. (Yes I know, harder to produce than raw data too.) Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From magnus@thinkware.se Fri Sep 6 10:00:35 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 06 Sep 2002 11:00:35 +0200 Subject: [Tutor] GUI question In-Reply-To: <200209052118.g85LIOU08562@mail12.bigmailbox.com> Message-ID: <5.1.0.14.0.20020906102606.02a6fa30@www.thinkware.se> At 14:18 2002-09-05 -0700, S A wrote: >With the plethora of GUI's that support python (Tkinter, QT, wxPython,=20 >...), would HTML better serve as a gui for platform independent data entry= =20 >into a python scripted db? I ask this since some of the platforms this=20 >data will goto supports HTML but not the others. Actually HTML is the only= =20 >interface that is supported on all platforms the script will run on.(like= =20 >portable devices for example) I don't see why the multitude of GUIs should be a reason to throw in one more player... Standard HTML is a very limited GUI environment. If it is sufficient for your needs, it's obviously an option. But if you want more GUI bells and whistles you'll probably use DHTML or various IE extensions etc that will destroy the platform independence. Also, I haven't seen any good tool kits for building HTML forms in Python. Sure there are some support for constructing HTML tags, such as forms, and there is support for extracting posted variables, but for a GUI-like application, one would like to be able to work on a slightly higher level of abstraction, where one can somehow see the HTML form ans the code handling that data as some kind of unit. As a side note, it IS possible to use python for client side scripting in web applications for Windows, but this is hardly recommented from a security point of view, and it's not cross platform. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Fri Sep 6 11:07:08 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 06 Sep 2002 12:07:08 +0200 Subject: [Tutor] Dictionary Question. In-Reply-To: <200209052115.g85LFIW08441@mail12.bigmailbox.com> Message-ID: <5.1.0.14.0.20020906110700.02b96ea8@www.thinkware.se> At 14:15 2002-09-05 -0700, S A wrote: >Let me first setup the scenario: > >I have a dictionary that contains keys that are names of people. Each one >of these keys contains three items: >1.phone number >2.address >3.email My mail at http://mail.python.org/pipermail/tutor/2002-August/016173.html relates to this. Sorry for the MIME garbage in the text. (Can't someone fix the mail archive to encode MIME?) Replace =3D with = and =20 with space and it shold be fairly understandable. >The program is set up to first ask the user to input a new key(name). Then >the user is asked to enter first the phone number, followed by the >address, and finally the email. This of course is repeated for many >keys(names). (kinda of like an addressbook) > >I want to ensure first that each item for the key is listed in the same >order of input: > >{key:('phone number', 'address', 'email')} Do you mean that phone number comes first, address next and email last? Sure, if you put those in a tuple as you suggest here, it's given. Like this: ... name = raw_input('Name: ') phone = raw_input('Phone: ') address = raw_input('Address: ') email = raw_input('Email: ') dictionary[name] = (phone, address, email) ... Another option is to use a list instead of a tuple: ... name = raw_input('Name: ') dictionary[name] = raw_input('Phone: ') dictionary[name].append(raw_input('Address: ')) dictionary[name].append(raw_input('Email: ')) ... But I would use the first version with the tuples. >Will this be the case for every key? Or will the list for every key place >the values in random order? > >Next is there a way to sort the keys, say alphabetically, without >disturbing the key:value relationship? (In case you have not yet noticed, >I'm trying to build a simple database using dictionaries and I need to be >able to enter/retrieve fields for specific relational keys) A dictionary is never sorted. You can have no influence over this without fixing the hash-values for your keys, and that might be little to close to magic for this list. You can extract your keys to a list, and sort that list, and finally use the sorted list to extract your data: dict = format = "Name: %s, Phone: %s, Address: %s, Email: %s" keys = dict.keys() keys.sort() for name in keys: print format % (name,) + dict[name] But if you just loop over the dictionary items as below, you can't influence the order. for entry in dict.items(): ... That would be against the nature of a dictionary... -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Fri Sep 6 11:14:32 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 06 Sep 2002 12:14:32 +0200 Subject: [Tutor] First script project... In-Reply-To: Message-ID: <5.1.0.14.0.20020906120946.02a9edc8@www.thinkware.se> At 15:50 2002-09-05 -0700, Israel Evans wrote: >In order to start a bunch of my webdev programs, I did something along the >lines of: [snip] I think you missed the part with "gentle nudge"... To let Steve be at least a little creative, I'd like to hint that a list and a loop might make the script easier to maintain, and less boring to read. One might even imagine creating the list by splitting a multiline string... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Fri Sep 6 11:35:55 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 06 Sep 2002 12:35:55 +0200 Subject: [Tutor] function vs module In-Reply-To: <20020905222236.4fc87f32.ckasso@sprynet.com> Message-ID: <5.1.0.14.0.20020906122311.02a66d88@www.thinkware.se> At 22:22 2002-09-05 -0400, Chris Kassopulo wrote: >Greetings, > >I'm working on some scripts that output stuff to the screen. For >example, the attached script, list_modules.py formats and outputs >a list of builtin modules. When I convert it to ListModules.py >to use a module, ListColumns.py I get: ... >NameError: global name 'ReturnFlag' is not defined > >ReturnFlag = 0 at the beginning of ListColumns gets around the >error, but I can't set it there. The intention is that scripts >that use ListColumns will set the flag and ListColumns just reads >it. I thought that making ReturnFlag global in ListColumns would >work, but it doesn't. > >Could someone shed some light on this please. Sure. The "global scope" refers to the module. An imported module should not know the context where it's used. If we had modules changing their behaviour due to variables outside of their own scope, it would both be much more difficult to both write and use modules. Thus 'import' in python is not like the preprocessor directive "#include" in C, where source-files are copied into your code and your own scope before compiling. Import is also a lot less problematic than #include... We might assume that this difference is one of the reasons why people use a linker in C instead of just using #include to compile all source code at once... There are several options here. You can set a variable in the global scope of your module from an importing module. import ListColumns ListColumns.ReturnFlag = 1 ListColumns.ListColumns(...) You can obviously send "ReturnFlag" as a parameter to your function call. You can use a class with a method instead of a module with a function. Then you just set an approriate value to ReturnFlag at initialization, or at any other point before calling the method. But if you only need one instance of this class, the first approach with the module global variable is enough. -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Fri Sep 6 11:53:27 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 06 Sep 2002 12:53:27 +0200 Subject: [Tutor] Different idioms for making lists of strings In-Reply-To: <200209051650.52447.shalehperry@attbi.com> References: <200209060135.15945.scot@possum.in-berlin.de> <200209060135.15945.scot@possum.in-berlin.de> Message-ID: <5.1.0.14.0.20020906123845.029b8830@www.thinkware.se> At 16:50 2002-09-05 -0700, Sean 'Shaleh' Perry wrote: >On Thursday 05 September 2002 16:35, Scot W. Stevenson wrote: > > alist =3D 'From To Subject'.split() > >My only problem with this is it masks the intent of the code. Your second problem will occur the day you realize that you need a space in one of the strings in your list... I don't think this is in general a good idea, but something along those lines might be useful in some occations. Like this: (For Steve Lewis who just wanted a gentle hint...sorry ;) programs =3D ''' # Std Windows stuff notepad.exe winword.exe excel.exe # To make it feel more like Unix g:/cygwin/bin/bash.exe ''' import os for program in programs.split('\n'): if program and program[0] !=3D '#': os.system('start %s' % program) Writing the script like that will probably make it easier for a non-programmer to maintain the list of programs. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From tjenkins@devis.com Fri Sep 6 15:41:56 2002 From: tjenkins@devis.com (Tom Jenkins) Date: 06 Sep 2002 10:41:56 -0400 Subject: [Tutor] Re: [DB-SIG] Re: What database should I use In-Reply-To: References: Message-ID: <1031323316.6785.9.camel@asimov> On Fri, 2002-09-06 at 10:29, Leif Jensen wrote: > > PostgreSQL, no doubt, if you use Linux, WinNT or possible WinXP ! > > Leif > I disagree. Don't get me wrong, we use PostgreSQL EXTENSIVELY. But for 2-3k records? These "requirements" don't require anything that powerful. I'd look at Access, pySQLite (which intrigues me), Gadfly. > > > On Thu, 5 Sep 2002, A wrote: > > > Hello, > > I am going to program a small application (in Python and wxPython) which consists about > > 2000 - 3000 records . Can you please recommend which database is the best for that. I > > use Windows. > > Maybe MS Access or FoxPro or MySQL or better? > > I want to keep the program as small as possible. > > Thanks > > Ladislav > > > > > > _______________________________________________ > > wx-users mailing list > > wx-users@lists.wxwindows.org > > http://lists.wxwindows.org/mailman/listinfo/wx-users > > > > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig -- Tom Jenkins Development InfoStructure http://www.devis.com From alan.gauld@bt.com Fri Sep 6 17:19:55 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:19:55 +0100 Subject: [Tutor] The Gang of Four (was: A Book for You and Me) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F6@mbtlipnt02.btlabs.bt.co.uk> > And "Design Patterns" is written like a college book, It is primarily a reference book not a tutorial. It is a very easy book to use in day to day work when you want to look up the details of a pattern. Its not a fun book, however... > book where you get the feeling that the people who wrote it > are very, very serious, don't have much fun in life ...when the book came out I went to a seminar on patterns by Ralph Johnston one of the GoF. He was charming, witty and very informative. I can assure you they ain't stiffs! :-) > Also, the book is from 1995, and still in > the first edition. I would expect OOP has progressed somewhat > since then, The book isn't about OOP its about design patterns. The patterns they list are still the most commonly used patterns by a long way and nothing has changed. Some new patterns have been discovered and the patterns web site describes them in the same manner as the book. > so somebody should sit down and rewrite the whole thing > to a) bring it up to date with current developments, It already is. b) humanize the prose, That might make it readable but they need to keep it concise and precise for referemnce purposes too. > c) replace the Smalltalk examples with Python. Hmmm, a tad biased there methinks :-) > My suggestion to other amateur newbies is to wait with this > book until you keep running up against terms like > "Flywheel" and "Factory" and "Mediator" Absolutely. This bnook is absolutely NOT for OO beginners. It assumes a very good grounding in OO and is aimed at designers first not programmers. If you fit the right profile then its a must have and you should approach it by reading one chapter per day - Johnston's recommendation and I agree its a good approach. > this book is far more in the science section > of computer science, Nope, its very much in the mainstream of software engineering and design in particular. I use it at least once a week. > going to want to read a whole lot of other > stuff before you get to it. Absolutely, it's a niche book but fills its niche well. > it can take 15 pages of robotic prose to > explain in very abstract terms what an iterator does, Becase they are describing a very abstract concept. It may or may not be implemented in an OOP language and it may or may not be in a similar scenario to the example they give. > and how amazingly complicated they > seem to be to implement in C++. Their C++ tends to be almost copy book perfect. Its one of the things I was very impresssed with, they write code that could actually be copied into real projects. It takes account of all the special cases (consts, references etc etc). Very few books provide as well written C++ as found there(Herb Sutter's books being notable exceptions(sic!)) > "Code Complete" by McConnell first Ah, now there is an outstanding book. Everyone who writes code owes it to themselves to buy and read this book. > definitely a "We read Knuth so you don't have to" (Tim Peters in the > "Python Cookbook") kind of book. I'd probably agree. Its a book aimed at professional software engineers grappling with complex problems that require complex solutions. It is like the meta classes book - if you understand it then you can be fairly that you really finally understand OO! Alan G. From alan.gauld@bt.com Fri Sep 6 17:26:09 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:26:09 +0100 Subject: [Tutor] Re: Re: Factory classes (etc) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F7@mbtlipnt02.btlabs.bt.co.uk> > But in most cases where you use overloading or templates in > C++ etc, you just write one method in Python, and that's it! :) > Perhaps you need an extra if-statement in the method, but I > have never missed method overloading in Python during the six > years I used it. I agree. Although I posted a solution a few days ago, mostly you just write the code such that you don't care what types get passed in. When you combine that with default arguments and keyword arguments there is hardly ever a real need for overloading. Controlling a class explosion (which was Arthurs problem) is better handled by one or more class factories operating at the appropriate level of abstraction - shape say in his case... Alan g. From alan.gauld@bt.com Fri Sep 6 17:29:42 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:29:42 +0100 Subject: [Tutor] The Gang of Four (was: A Book for You and Me) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F8@mbtlipnt02.btlabs.bt.co.uk> > Speaking of "Code Complete", that's another highly recommended book > didn't seem to discuss the OO methodology at all. I was somewhat > surprised by this, and hopefully I'm wrong. It is about writing code. OO code is very little different to non OO code. The principles - variable naming, code structure, commenting ewtc etc - stay the same. OO is diffeerent at the design level not the code level (apart from some minor syntax changes). Again, code complete could have ben written any time after about 1985 and not require any alteration. CS hasn't changed much at that level since then. Alan G. From alan.gauld@bt.com Fri Sep 6 17:42:28 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:42:28 +0100 Subject: [Tutor] GUI question Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FA@mbtlipnt02.btlabs.bt.co.uk> > but not the others. Actually HTML is the only interface that > is supported on all platforms the script will run on. I think you just answered your own question. If it's the only common option then it's the right answer... Alan g From alan.gauld@bt.com Fri Sep 6 17:44:40 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:44:40 +0100 Subject: [Tutor] First script project... Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FB@mbtlipnt02.btlabs.bt.co.uk> > We are standardized on W2K pro. I have a folder on my Desktop that > contains Shortcuts to all of my tools. I open the apps one at > a time using the shortcuts. Run, don't walk, to a bookstore and buy Mark Hammonds book on Programming Python on Win32. It may be a wee bit advanceed in some places but its essential for any serious work on a Windows platform. Alan G. From alan.gauld@bt.com Fri Sep 6 17:41:00 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:41:00 +0100 Subject: [Tutor] Re: Factory classes (etc) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F9@mbtlipnt02.btlabs.bt.co.uk> > Does anybody actually _use_ SmallTalk for production code, Yes, its heavily used in the financial sector. Also at least two airlines that I know of use it internally. I also know of an electronic test gear company who produce all their control software in it. One of Smalltalks big advantages for them is its portability. The same image file can be run on any system supporting the interpreter - like Javas JVM but much more reliable! > those teaching languages that revolutionized various concepts > but never made it in the market Oddly enough I don't think Smalltalk really caught on as a teaching language, it has been more a research and prototyping tool in my experience. > Are there any common patterns that are missing by today's > standards? There are a few new ones on the patterns web site but the most common by far are those in the book. > I can't believe that seven years later, the GoF is still state of the > art... Pretty much. Its one of the testaments to the quality that they pretty much got it right. It hasn't needed to change. Alan g. Author of the 'Learning to Program' web site http://www.freenetpages.co.uk/hp/alan.gauld From alan.gauld@bt.com Fri Sep 6 17:47:52 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 6 Sep 2002 17:47:52 +0100 Subject: [Tutor] confused! Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FC@mbtlipnt02.btlabs.bt.co.uk> > i just want to if TCL is another type of programing language Yes. > or a program inside phyton No, although Pythons GUI toolkit Tkinter is built on Tcl. So occasionally you see Tcl error messages when using Tkinter. > and for example, when u type >>>print "hello world" and > run it what should u expect the computer to do. print "hello world" on the screen. What does it do for you? Alan g. Author of the 'Learning to Program' web site http://www.freenetpages.co.uk/hp/alan.gauld From jeff@ccvcorp.com Fri Sep 6 17:56:58 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Fri, 06 Sep 2002 09:56:58 -0700 Subject: [Tutor] Perl to Python code migration References: <45520544-C151-11D6-BDA3-00039351FE6A@mac.com> Message-ID: <3D78DE5A.DEF1711C@ccvcorp.com> Erik Price wrote: > On Thursday, September 5, 2002, at 10:24 PM, Jeff Shannon wrote: > > > I didn't see any explicit specification along those lines... > > Surrounded by the question itself and the code, it was pretty easy to > miss, but Levy did say that: Whoops, guess I need to read a bit more closely before spouting off. ;) (What makes this even more embarrassing is that I went back and re-read the original before sending that reply, so I missed it *twice*.) > > Given that restriction, then the best solution probably would be to > > read in small > > chunks of the file (possibly using xreadlines() if it's broken into > > lines) until > > the delimiter is found, and accumulating those chunks manually. > > I was thinking about this earlier today, but it's a hard one. > xreadlines() seems like the best solution, except that the data is not > separated into separate lines (it's multi-line). Well, multiline data can still be handled by xreadlines(), though it's a bit more complicated. If we can assume that a record always starts at the beginning of a line (the delimiter will always be the first group of characters on any line that it appears on), then we can use code that looks something like this: block = [] for line in infile.xreadlines(): if line.startswith( "(ID 1)" ) and block != []: process_data(block) block = [] block.append(line) process_data(block) This could doubtless be made a bit cleaner, but it should work. It starts by reading a line at a time, and adding that line to a block. When we find the line that starts the next record, we process the block that's already accumulated, and then start a new block with that new line. Since the final record won't have anything following it to trigger processing, we have to add another call to process it after the for-loop finishes. The process_data() function could perhaps join() the list of lines into a single string for easier processing. This is, in principle, somewhat similar to the event-based sax parsing that you mentioned, but in a very rough quick-and-dirty form. Of course, as noted, this assumes that the delimiter always starts a line. If that assumption isn't valid, or if there are no line breaks in the file, then you'd need to use find() to determine if the delimiter is present, add any data before the delimiter to the block before you send it, and start the new block with only data from after the delimiter. (If there aren't line breaks, you'd need to use, say, file.read(1024) instead of file.xreadlines(), but the principle is the same.) You might also need to check each line (or newly read chunk) to ensure that it doesn't contain more than one delimiter. Jeff Shannon Technician/Programmer Credit International From shalehperry@attbi.com Fri Sep 6 17:59:17 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 6 Sep 2002 09:59:17 -0700 Subject: [Tutor] confused! In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FC@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FC@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <200209060959.17149.shalehperry@attbi.com> On Friday 06 September 2002 09:47, alan.gauld@bt.com wrote: > > and for example, when u type >>>print "hello world" and > > run it what should u expect the computer to do. > > print "hello world" on the screen. > > What does it do for you? > I half believe the original poster expected his printer to spit out a pag= e=20 with "hello world" on it. We programmers take it for granted but I can see how a newbie would be=20 confused by it. From shalehperry@attbi.com Fri Sep 6 18:04:21 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 6 Sep 2002 10:04:21 -0700 Subject: [Tutor] Perl to Python code migration In-Reply-To: <3D78DE5A.DEF1711C@ccvcorp.com> References: <45520544-C151-11D6-BDA3-00039351FE6A@mac.com> <3D78DE5A.DEF1711C@ccvcorp.com> Message-ID: <200209061004.21469.shalehperry@attbi.com> On Friday 06 September 2002 09:56, Jeff Shannon wrote: > > Well, multiline data can still be handled by xreadlines(), though it's = a > bit more complicated. If we can assume that a record always starts at = the > beginning of a line (the delimiter will always be the first group of > characters on any line that it appears on), then we can use code that l= ooks > something like this: > > block =3D [] > for line in infile.xreadlines(): > if line.startswith( "(ID 1)" ) and block !=3D []: > process_data(block) > block =3D [] > block.append(line) > process_data(block) > > I wonder how hard it would be to add something like perl's delimiter hack= to=20 the file interface. fp =3D open(my_file) fp.set_record_delimiter('(ID 1)') for line in fp.xreadlines(): ....... Which gives you the equivalent of the perl code. From jeff@ccvcorp.com Fri Sep 6 18:07:04 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Fri, 06 Sep 2002 10:07:04 -0700 Subject: [Tutor] confused! References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FC@mbtlipnt02.btlabs.bt.co.uk> <200209060959.17149.shalehperry@attbi.com> Message-ID: <3D78E0B8.AC1A9B2E@ccvcorp.com> Sean 'Shaleh' Perry wrote: > On Friday 06 September 2002 09:47, alan.gauld@bt.com wrote: > > > and for example, when u type >>>print "hello world" and > > > run it what should u expect the computer to do. > > > > print "hello world" on the screen. > > > > What does it do for you? > > > > I half believe the original poster expected his printer to spit out a page > with "hello world" on it. Either that, or they may have taken the prompt a bit too literally... >>> print "hello world" hello world >>> >>>print "hello world" File "", line 1 >>>print "hello world" ^ SyntaxError: invalid syntax >>> Jeff Shannon Technician/Programmer Credit International From steve_lewis@openiso.com Fri Sep 6 18:56:14 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Fri, 6 Sep 2002 12:56:14 -0500 (CDT) Subject: [Tutor] First script project... In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FB@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8FB@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <5634.199.66.1.5.1031334974.squirrel@www.absolutenettech.com> >> We are standardized on W2K pro. I have a folder on my Desktop that >> contains Shortcuts to all of my tools. I open the apps one at >> a time using the shortcuts. > > Run, don't walk, to a bookstore and buy Mark Hammonds book > on Programming Python on Win32. It may be a wee bit advanceed > in some places but its essential for any serious work on > a Windows platform. > > Alan G. Thank you, I have my running shoes on. I already have some questions that I am sure are covered in the book. I created some scripts on my Win ME box to open apps, worked great. I also use Linux so that is a dev platform too. #example script import os os.system('start c:\\windows\\programfiles\\cdex\\cdex.exe') I had to use double slashes, but worked. Now in W2k I am encountering some file path errors with spaces etc. But, that is what learning is all about. Also, thanks for all of the other help. I was able to get a fast start getting a script going, also the hint about Lists and Loops is exactly what I need to progress from simple scripts to more advanced programs, thank you. I will get back as this moves along. Thanks again, Steve Lewis Fayetteville,AR,USA. From ckasso@sprynet.com Fri Sep 6 20:18:21 2002 From: ckasso@sprynet.com (Chris Kassopulo) Date: Fri, 6 Sep 2002 15:18:21 -0400 Subject: [Tutor] function vs module In-Reply-To: <5.1.0.14.0.20020906122311.02a66d88@www.thinkware.se> References: <20020905222236.4fc87f32.ckasso@sprynet.com> <5.1.0.14.0.20020906122311.02a66d88@www.thinkware.se> Message-ID: <20020906151821.7f15a754.ckasso@sprynet.com> On Fri, 06 Sep 2002 12:35:55 +0200 Magnus Lycka wrote: > > There are several options here. > > You can set a variable in the global scope of your module > from an importing module. > > import ListColumns > ListColumns.ReturnFlag = 1 > ListColumns.ListColumns(...) Thanks for your reply. I used this option and it works beautifully. It sheds much light on referring to modules for me. > You can obviously send "ReturnFlag" as a parameter to > your function call. I had a working version using this method at some point, but had changed it because the global way seemed more appropriate. > You can use a class with a method instead of a module > with a function. Then you just set an approriate value > to ReturnFlag at initialization, or at any other point > before calling the method. But if you only need one > instance of this class, the first approach with the > module global variable is enough. This one is above my head for the moment. Thanks again Chris Kassopulo From jchilders@smartITservices.com Thu Sep 5 14:06:11 2002 From: jchilders@smartITservices.com (Jeff Childers) Date: Thu, 5 Sep 2002 09:06:11 -0400 Subject: [Tutor] CGI, Apache (and ODBC?) Message-ID: <9C067B997594D3118BF50050DA24EA1097D3A1@CCG2> Hi all, got a wierd one. When I run my python routine from the command line, it works properly. I can pipe the output to a temporary html file and open it in the browser, works fine. But when I try to run it as a CGI, it returns the following (apache's error log): "mxODBC.OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified', 5998)" I've pasted the code that handles the ODBC below if it helps. Does anyone have any idea where I should start looking? I thought the CGI process ran the same Python.EXE that I get from the command line? Thanks, Jeff #!python.exe # showitems.py # CGI Program to display Inventory Items in HTML Table import os import cgi import pro_ODBC class doIt: def printheader(self, title): print """Content-type: text/html %s """ % title def main(self): rowNumber = 0 backgroundColor = "white" items = pro_ODBC.proItems() items.getItems() self.printheader("Item List") print """""" #print table of CGI vars for item in items.itemList.keys(): rowNumber += 1 if rowNumber % 2 == 0: backgroundColor = "white" else: backgroundColor = "lightgrey" print """""" % backgroundColor, #table2 = """""" % ("foo", "bar") table2 = """""" % (cgi.escape(item), cgi.escape( items.itemList[item])) print table2 print """
%s%s
%s%s
""" def startup(): o = doIt() o.main() if __name__ == "__main__": startup() # PRO_ODBC.PY # Connect to SQL, make dictionary for output import mx.ODBC.Windows import time class proItems: def __init__(self): self.db = mx.ODBC.Windows.DriverConnect("DSN=Pro Series 6.5") self.itemList = {} def getItems(self): # Start Querying cur = self.db.cursor() # Get items cur.execute("SELECT * FROM ICITEM99") counter = 1 while (1): item = cur.fetchone() if item == None: break self.itemList[item[0]] = item[1] counter += 1 cur.close() def closeDB(self): self.db.close() print "Closed." From umarumohammed@btinternet.com Fri Sep 6 12:18:06 2002 From: umarumohammed@btinternet.com (Ibraheem Umaru-Mohammed) Date: Fri, 6 Sep 2002 12:18:06 +0100 Subject: [Tutor] How does Shelve work? In-Reply-To: <200209052048.g85KmDA14667@mail6.bigmailbox.com> References: <200209052048.g85KmDA14667@mail6.bigmailbox.com> Message-ID: <20020906111806.GA27998@micromuse.com> >>>> S == "S A " writes: S>> Can someone please explain how the Shelve module works? S>> S>> I tried to use a shelve.open (filename) command on a blank flat S>> file and got an error saying that it could not determine the database S>> type? S>> S>> Traceback (most recent call last): S>> File "", line 1, in ? S>> File "/sw/lib/python2.2/shelve.py", line 158, in open S>> return DbfilenameShelf(filename, flag) S>> File "/sw/lib/python2.2/shelve.py", line 148, in __init__ S>> Shelf.__init__(self, anydbm.open(filename, flag)) S>> File "/sw/lib/python2.2/anydbm.py", line 83, in open S>> raise error, "db type could not be determined" S>> anydbm.error: db type could not be determined S>> >>> d = shelve.open('test2') S>> Traceback (most recent call last): S>> File "", line 1, in ? S>> File "/sw/lib/python2.2/shelve.py", line 158, in open S>> return DbfilenameShelf(filename, flag) S>> File "/sw/lib/python2.2/shelve.py", line 148, in __init__ S>> Shelf.__init__(self, anydbm.open(filename, flag)) S>> File "/sw/lib/python2.2/anydbm.py", line 83, in open S>> raise error, "db type could not be determined" S>> anydbm.error: db type could not be determined S>> S>> Is this saying that it can not find a database to run on my computer or S>> that the file is not of a database type? Please excuse the ignorance, I'm S>> just now dabbling in databases. S>> S>> Thanks. S>> SA S>> Does the following help at all? ,---- [ shelve module example - foo.py ] | #!/usr/bin/env python | import shelve | | handle = shelve.open("mydb") | # save objects | handle[1]="one" | handle[2]="two" | handle[3]="three" | handle[4]="four" | handle[5]="five" | | # retrieve objects | print "Stored the following to database: " | for item in handle.keys(): | print item, "=>", handle[item] | handle.close() `---- You may also want to look at the following, although it wasn't all that helpful: ,---- [ shelve module URL ] | http://www.python.org/doc/current/lib/module-shelve.html `---- Kindest regards, --ibz. -- Ibraheem Umaru-Mohammed "ibz" umarumohammed (at) btinternet (dot) com From ajs@ix.netcom.com Sat Sep 7 02:21:52 2002 From: ajs@ix.netcom.com (Arthur) Date: Fri, 6 Sep 2002 21:21:52 -0400 Subject: [Tutor] Re: Re: Factory classes (etc) References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F7@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <000901c2560c$f3c4c330$9865fea9@arthur> Magnus - > > But in most cases where you use overloading or templates in > > C++ etc, you just write one method in Python, and that's it! :) > > Perhaps you need an extra if-statement in the method, but I > > have never missed method overloading in Python during the six > > years I used it. Alan - > I agree Being that this is the 5th or 6th time I've heard exactly the same take from folks with deeper programming experience than myself, I kind of feel the need for a reality check. I am not "missing" method overloading in the sense that I feel Python is somehow deficient by not having it built-in. Because in fact I don't see anything very deep about method overloading at all. It's just about what things are called, not what they do. There is the simple option of giving 2 classes that take different arguments different names, and having an API defined accordingly. As well as numbers of other options. The irony of all this being that if I was working in Java, or C++ I would be much happier with that kind of solution, because a true API for a Java or C++ library is a neccessity, or at least expected, in any case, and if there were not method overloading it would be easy enough to compensate by an appropriately documented API. But for what I am doing I want to build as much as I can a scripting interface that follows geometric intuitive logic, not programmers logic. And at the scripting interface level what things are called *is* to the essence of things. If a point is instantiated as an Intersection, if might be the intersection of a number of other possible elements. It is absolutely redundant both to have the Intersection classes named in accordance with what elements they take as arguments, and then to give them those arguments - because in fact the arguments themselves define the kind of intersection we are trying to create. Given lets say 20 classes which could take anywhere from one to five different sets of arguments, and thats a hell of a lot of if type(arg[0]): xxx else: yyyy to try to get right and keep straight. And forcng the scripter to name all arguments is not an acceptable solution, from my point of view. So, I actually feel I am on quite the right track by trying to come up with an algorythmic solution - which I am comfortable is doable. Probably cake for someone with more algorythmic experience and intuition than I have. And, yes, the concepts of running it all through Factory Classes is not something I understood to consider. Brought tio my attention, it seems the obviously best way to go - but I still need my algorythms. So I am both supremely confident, and horribly insecure - about being on a sensible track. Art From buc40@bemail.org Sat Sep 7 03:41:29 2002 From: buc40@bemail.org (S A) Date: Fri, 6 Sep 2002 19:41:29 -0700 Subject: [Tutor] How does Shelve work? Message-ID: <200209070241.g872fTd12946@mail24.bigmailbox.com> This is a multi-part message in MIME format... --oMTJpMNmSdfKIvBP55bemGKwA Content-Type: text/plain Content-Transfer-Encoding: 8bit > Ibraheem Umaru-Mohammed S A Cc: tutor@python.org > Re: [Tutor] How does Shelve work?Date: Fri, 6 Sep 2002 12:18:06 +0100 > >Does the following help at all? > >,---- [ shelve module example - foo.py ] >| #!/usr/bin/env python >| import shelve >| >| handle = shelve.open("mydb") >| # save objects >| handle[1]="one" >| handle[2]="two" >| handle[3]="three" >| handle[4]="four" >| handle[5]="five" >| >| # retrieve objects >| print "Stored the following to database: " >| for item in handle.keys(): >| print item, "=>", handle[item] >| handle.close() >`---- > >You may also want to look at the following, although it wasn't all that helpful: > >,---- [ shelve module URL ] >| http://www.python.org/doc/current/lib/module-shelve.html >`---- Yes. That is a foot in the right direction. However: handle[1]="one" needs to be changed to: handle['1']= "one" Otherwise I get the following error: Traceback (most recent call last): File "", line 1, in ? File "/sw/lib/python2.1/shelve.py", line 77, in __setitem__ self.dict[key] = f.getvalue() TypeError: gdbm mappings have string indices only I gather from the error that the key must be a string item. I wish there was better info on the shelve module. It looks to be very useful for small flat db files. Unfortunately, I had already tried the link you suggested, and you are correct, it was not very informative. But with your help, I was able to figure out how to work this module. Thank you very much. Does anyone else on the list have anything to add to this discussion? Thanks. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- --oMTJpMNmSdfKIvBP55bemGKwA Content-Type: text/html Content-Transfer-Encoding: 8bit

> Ibraheem Umaru-Mohammed  S A Cc: tutor@python.org
> Re: [Tutor] How does Shelve work?Date: Fri, 6 Sep 2002 12:18:06 +0100
>
>Does the following help at all?
>
>,---- [ shelve module example - foo.py ]
>| #!/usr/bin/env python
>| import shelve
>|
>| handle = shelve.open("mydb")
>| # save objects
>| handle[1]="one"
>| handle[2]="two"
>| handle[3]="three"
>| handle[4]="four"
>| handle[5]="five"
>|
>| # retrieve objects
>| print "Stored the following to database: "
>| for item in handle.keys():
>|   print item, "=>", handle[item]
>| handle.close()
>`----
>
>You may also want to look at the following, although it wasn't all that 
helpful:
>
>,---- [ shelve module URL ]
>| http://www.python.org/doc/current/lib/module-shelve.html
>`----

Yes. That is a foot in the right direction. However:
handle[1]="one"

needs to be changed to:
handle['1']= "one"

Otherwise I get the following error:
Traceback (most recent call last):
  File "", line 1, in ?
  File "/sw/lib/python2.1/shelve.py", line 77, in __setitem__
    self.dict[key] = f.getvalue()
TypeError: gdbm mappings have string indices only

I gather from the error that the key must be a string item.

I wish there was better info on the shelve module. It looks to be very useful 
for small flat db files. Unfortunately, I had already tried the link you 
suggested, and you are correct, it was not very informative. But with your help, 
I was able to figure out how to work this module. Thank you very much.

Does anyone else on the list have anything to add to this discussion?

Thanks.
SA




"I can do everything on my Mac that I used to do on my PC, plus alot more ..."

-Me

------------------------------------------------------------
Free, BeOS-friendly email accounts: http://BeMail.org/
BeOS News and Community: http://www.BeGroovy.com/


---------------------------------------------------------------------
Express yourself with a super cool email address from BigMailBox.com.
Hundreds of choices. It's free!
http://www.bigmailbox.com
---------------------------------------------------------------------
--oMTJpMNmSdfKIvBP55bemGKwA-- From allyn.@tardigrade.net Sat Sep 7 03:55:20 2002 From: allyn.@tardigrade.net (Allyn Weaks) Date: Fri, 6 Sep 2002 19:55:20 -0700 Subject: [Tutor] The Gang of Four (was: A Book for You and Me) In-Reply-To: <200209041148.32380.scot@possum.in-berlin.de> References: <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> <200209032159.47782.shalehperry@attbi.com> <200209041148.32380.scot@possum.in-berlin.de> Message-ID: On 4/9/02, Scot W. Stevenson wrote: >"We read Knuth so you don't have to" (Tim Peters in the >"Python Cookbook") kind of book. But, but, but, Knuth is quite readable and even funny. If you have a sufficiently warped sense of humor :-). -- Allyn Weaks allyn@tardigrade.net Seattle, WA Sunset zone 5 Pacific NW Native Wildlife Gardening: http://www.tardigrade.org/natives/ "The benefit of even limited monopolies is too doubtful, to be opposed to that of their general suppression." Thomas Jefferson From buc40@bemail.org Sat Sep 7 04:04:02 2002 From: buc40@bemail.org (S A) Date: Fri, 6 Sep 2002 20:04:02 -0700 Subject: [Tutor] Is there a file creator? Message-ID: <200209070304.g87342W13581@mail21.bigmailbox.com> Is there a function or module that creates an empty file like the unix command "touch" does? Thanks. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- From thomi@thomi.imail.net.nz Sat Sep 7 08:08:10 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Sat, 7 Sep 2002 19:08:10 +1200 Subject: [Tutor] Is there a file creator? In-Reply-To: References: <200209070304.g87342W13581@mail21.bigmailbox.com> Message-ID: <20020907190810.15194ed8.thomi@thomi.imail.net.nz> appen mode?? file = open('test.txt','a') works... On Sat, 6 Sep 2003 00:17:27 -0400 (EDT) Thus said Gus Tabares : > SA, > > I think when you open a file in write mode, if the file doesn't > already exists, it will be created, hence, it will start empty. Hope > this helps... > > > Gus > > On Fri, 6 Sep 2002, S A wrote: > > > Is there a function or module that creates an empty file like the > > unix command "touch" does? > > > > > > Thanks. > > SA > > > > > > > > "I can do everything on my Mac that I used to do on my PC, plus alot > > more ..." > > > > -Me > > > > ------------------------------------------------------------ > > Free, BeOS-friendly email accounts: http://BeMail.org/ > > BeOS News and Community: http://www.BeGroovy.com/ > > > > > > ------------------------------------------------------------------- > > -- Express yourself with a super cool email address from > > BigMailBox.com. Hundreds of choices. It's free! > > http://www.bigmailbox.com > > ------------------------------------------------------------------- > > -- > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- DOS: n., A small annoying boot virus that causes random spontaneous system crashes, usually just before saving a massive project. Easily cured by UNIX. See also MS-DOS, IBM-DOS, DR-DOS. (from David Vicker's .plan) Thomi Richards, thomi@imail.net.nz From erikprice@mac.com Sat Sep 7 14:47:24 2002 From: erikprice@mac.com (Erik Price) Date: Sat, 7 Sep 2002 09:47:24 -0400 Subject: [Tutor] Re: Re: Factory classes (etc) In-Reply-To: <000901c2560c$f3c4c330$9865fea9@arthur> Message-ID: <56F514D4-C268-11D6-85DA-00039351FE6A@mac.com> On Friday, September 6, 2002, at 09:21 PM, Arthur wrote: > I am not "missing" method overloading in the sense that I feel Python > is > somehow deficient by not having it built-in. Because in fact I don't > see > anything > very deep about method overloading at all. It's just about what > things are > called, not what they do. There is the simple option of giving 2 > classes > that take different arguments different names, and having an API > defined > accordingly. As well as numbers of other options. I was under the impression that method overloading becomes important when you are using late binding at runtime (I think that's what it's called). In other words, if you aren't certain exactly what data will be handed to an object so you take into account multiple kinds of messages and write methods for each situation that you believe will be encountered in your program. You might have no idea what some kind of data will be, you just want to be prepared for whatever is likely so you code methods to handle these situations. This lets your class be truly encapsulated (you do not depend on the structure of the rest of the program to determine what messages the object can and cannot receive because you might even use this class in another program!). In other words it becomes crucial (for strongly typed languages) when you want to use things like polymorphism. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From buc40@bemail.org Sat Sep 7 16:14:26 2002 From: buc40@bemail.org (S A) Date: Sat, 7 Sep 2002 08:14:26 -0700 Subject: [Tutor] Slightly off topic for whomever is monitoring this list. Message-ID: <200209071514.g87FEQx25077@mail24.bigmailbox.com> This is a multi-part message in MIME format... --Vut5nMAlEkc7ndnFWIlNwits4 Content-Type: text/plain Content-Transfer-Encoding: 8bit I do mot mean to be rude. but a just deleted a bunch of mail that just flooded the list from: ctp@ctpdesign.com Apparently his "anti-spam" software has gone ballistic on the list. I've sent him an email, can the list admin maybe filter this junk until the issue is resolved? Thanks. SA "I can do everything on my Mac that I used to do on my PC, plus alot more ..." -Me ------------------------------------------------------------ Free, BeOS-friendly email accounts: http://BeMail.org/ BeOS News and Community: http://www.BeGroovy.com/ --------------------------------------------------------------------- Express yourself with a super cool email address from BigMailBox.com. Hundreds of choices. It's free! http://www.bigmailbox.com --------------------------------------------------------------------- --Vut5nMAlEkc7ndnFWIlNwits4 Content-Type: text/html Content-Transfer-Encoding: 8bit
I do mot mean to be rude. but a just deleted a bunch of mail that just flooded 
the list from:

ctp@ctpdesign.com

Apparently his "anti-spam" software has gone ballistic on the list. I've sent 
him an email, can the list admin maybe filter this junk until the issue is 
resolved?

Thanks.
SA



"I can do everything on my Mac that I used to do on my PC, plus alot more ..."

-Me

------------------------------------------------------------
Free, BeOS-friendly email accounts: http://BeMail.org/
BeOS News and Community: http://www.BeGroovy.com/


---------------------------------------------------------------------
Express yourself with a super cool email address from BigMailBox.com.
Hundreds of choices. It's free!
http://www.bigmailbox.com
---------------------------------------------------------------------
--Vut5nMAlEkc7ndnFWIlNwits4-- From martin.klaffenboeck@gmx.at Sat Sep 7 21:49:19 2002 From: martin.klaffenboeck@gmx.at (Martin Klaffenboeck) Date: 07 Sep 2002 22:49:19 +0200 Subject: [Tutor] question on lists Message-ID: <1031431760.818.118.camel@martin.kleinerdrache.org> Hello, I have got a list with 4 columns. This 4 columns are: string1 string2 id timestamp So how do I store the data? As a list or as an array: What I want to do with this data: Sort the list alphabetically (if possible _not_ case sensitive). Add new entries at the right alphabetic position. Randomize the list (or a copy of it) and sort it back alphabetically after modifying the id and the timestamp. Whats the best way to store data for this in python? Thanks, Martin (a newbie) PS. Sorry for my bad english. -- From shalehperry@attbi.com Sat Sep 7 22:33:35 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Sat, 7 Sep 2002 14:33:35 -0700 Subject: [Tutor] question on lists In-Reply-To: <1031431760.818.118.camel@martin.kleinerdrache.org> References: <1031431760.818.118.camel@martin.kleinerdrache.org> Message-ID: <200209071433.35580.shalehperry@attbi.com> On Saturday 07 September 2002 13:49, Martin Klaffenboeck wrote: > Hello, > > I have got a list with 4 columns. This 4 columns are: > > string1 string2 id timestamp > > So how do I store the data? As a list or as an array: > a list is for all intents and purposes an array in python. There are 3=20 grouping structures in core python -- tuple, list, dictionary. A tuple i= s a=20 list which can not be changed once created a dictionary is equivalent to=20 perl's hash or C++'s map. > What I want to do with this data: > > Sort the list alphabetically (if possible _not_ case sensitive). > Add new entries at the right alphabetic position. > > Randomize the list (or a copy of it) and sort it back alphabetically > after modifying the id and the timestamp. > > list.sort() takes a function to determine sort order. There is a handy=20 function called cmp() which is often used for this. Your add function is not too hard to write and the random module may give= you=20 what you want for the random stuff. Read through the python docs on lists and the builtin functions it should= get=20 you started. From magnus@thinkware.se Sat Sep 7 23:04:53 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 08 Sep 2002 00:04:53 +0200 Subject: [Tutor] The Gang of Four (was: A Book for You and Me) In-Reply-To: References: <200209041148.32380.scot@possum.in-berlin.de> <577C58CC-BFC1-11D6-B926-00039351FE6A@mac.com> <200209032159.47782.shalehperry@attbi.com> <200209041148.32380.scot@possum.in-berlin.de> Message-ID: <5.1.0.14.0.20020908000134.02ade5a0@www.thinkware.se> At 19:55 2002-09-06 -0700, Allyn Weaks wrote: >On 4/9/02, Scot W. Stevenson wrote: > >"We read Knuth so you don't have to" (Tim Peters in the > >"Python Cookbook") kind of book. > >But, but, but, Knuth is quite readable and even funny. If you have a >sufficiently warped sense of humor :-). And plenty of time... I tend to get tired before he gets to the point. He is ... different. See also: http://www.thinkware.se/cgi-bin/thinki.cgi/DiscussTheArtOfComputerProgrammin= g (Look at the end for example of warped humour.) --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From kyle@sent.com Sat Sep 7 23:42:45 2002 From: kyle@sent.com (Kyle Babich) Date: Sat, 7 Sep 2002 22:42:45 UT Subject: [Tutor] Individual Character Count Message-ID: <20020907224245.E830C93768@server2.fastmail.fm> I'm trying (with little luck) to create a function to count how many time an individual character appears in a file. What I have so far I have written on patterns I've noticed but it is still extremely buggy depending on whether the character being searched for appears as the first character in the file, the last, both, or neither. Here it is: #################### def InCharCount(location, character): subj =3D file(location, "r") body =3D subj.read() body =3D body.split("\n") body =3D string.join(body, "") body =3D body.split(character) last =3D len(body) last =3D last - 1 char =3D 0 for each in body: char =3D char + 1 if body[0] in [""]: char =3D char - 1 elif body[last] in [""]: char =3D char - 1 =20 else: pass return char #################### Could someone please help me work the bugs out of this? I have a feeling that I'm making this harder than I need to for myself again. Thank you, -- Kyle From dyoo@hkn.eecs.berkeley.edu Sun Sep 8 00:17:20 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 7 Sep 2002 16:17:20 -0700 (PDT) Subject: [Tutor] Individual Character Count In-Reply-To: <20020907224245.E830C93768@server2.fastmail.fm> Message-ID: On Sat, 7 Sep 2002, Kyle Babich wrote: > I'm trying (with little luck) to create a function to count how many > time an individual character appears in a file. What I have so far I > have written on patterns I've noticed but it is still extremely buggy > depending on whether the character being searched for appears as the > first character in the file, the last, both, or neither. Here it is: Hi Kyle, Let's take a look at the program. > #################### > def InCharCount(location, character): > subj = file(location, "r") > body = subj.read() > > body = body.split("\n") > body = string.join(body, "") > body = body.split(character) Hmmm... Ok, so if our file's contents has something like "aaabbabba", then if we wanted to count all the "a"'s, we could split against 'a' and see how many pieces come up: ### >>> s = "aaabbabba" >>> l = s.split('a') >>> l ['', '', '', 'bb', 'bb', ''] ### As a result, our list won't contain any more "a"'s once we split by 'a'. But it will have a bunch of empty strings, which might look silly. ... But those empty strings are there for a very good reason: we should be able to rehydrate our string, and reverse the process by using join(): ### >>> 'a'.join(l) 'aaabbabba' ### Your approach seems reasonable. Once you've split the 'body' up, you already have enough information to count how many of that 'character' is in there: the number of 'character's should just be the number of in-betweens we have in our split-up body: ['', '', '', 'bb', 'bb', ''] That is, if we have a list of six elements, the number of "in-between" places is just the number of commas we see in our list: 5. join ==> '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + '' So all you need now is to count "in-between" places. I'll let you figure out how to do that. *grin* Your approach works even if our string is initially empty: ### >>> mystring = "" >>> l = mystring.split("a") >>> l [''] >>> "a".join(l) '' ### because when our split-up list is only one element long, there are no "in-between" spots in our list, which is exactly right. Let's look at the rest of your code: > last = len(body) > last = last - 1 > > char = 0 > for each in body: > char = char + 1 > > if body[0] in [""]: > char = char - 1 > > elif body[last] in [""]: > char = char - 1 > > else: > pass > > return char I'd remove this part of the code because it's making the problem too complicated. *grin* I don't think you need to do more cases based on empty strings. Empty strings in your split-up list are perfectly good: you don't need to do additional case analysis on them. Good luck to you! From dyoo@hkn.eecs.berkeley.edu Sun Sep 8 00:24:58 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 7 Sep 2002 16:24:58 -0700 (PDT) Subject: [Tutor] Individual Character Count In-Reply-To: Message-ID: > Your approach seems reasonable. Once you've split the 'body' up, you > already have enough information to count how many of that 'character' is > in there: the number of 'character's should just be the number of > in-betweens we have in our split-up body: > > ['', '', '', 'bb', 'bb', ''] > > That is, if we have a list of six elements, the number of "in-between" > places is just the number of commas we see in our list: 5. > > join ==> > > '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + '' Hi Kyle, Doh. I messed up here in the diagram. Forget those pictures above. I meant to write: l = ['', '', '', 'bb', 'bb', ''] 'a'.join(l) ==> '' + 'a' + '' + 'a' + '' + 'a' + 'bb' + 'a' + 'bb' + 'a' + '' instead, which tries to show better the relationship that join() has with split(). My apologies for being sloppy about this. From scot@possum.in-berlin.de Sun Sep 8 01:10:31 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sun, 8 Sep 2002 02:10:31 +0200 Subject: [Tutor] Individual Character Count In-Reply-To: <20020907224245.E830C93768@server2.fastmail.fm> References: <20020907224245.E830C93768@server2.fastmail.fm> Message-ID: <200209080210.31575.scot@possum.in-berlin.de> Hello Kyle, > I'm trying (with little luck) to create a function to count how many > time an individual character appears in a file. One thing I have learned in the past few months about Python is to always consult the Module Library before even considering writing new code. This is the "batteries included" principle that people keep talking about with Python, and it works. In this case, there is actually a "count" method in the string module. I'm assuming you have a new version of Python such as 2.2, where you don't have to import the string module anymore (if not, we'll try again with one of the older forms), so you get: =============================== >>> mystring = 'Spam! Spam! Spam!' >>> mystring.count('S') 3 =============================== Or, even shorter, though it looks strange the first time you see it: =============================== >>> 'Spam! Spam! Spam!'.count('S') 3 =============================== So the short version of your function could be: =============================== def InCharCount(location, character): subj = file(location, "r") body = subj.read() subj.close() return body.count(character) =============================== [I just love that last line: It sounds like something out of a Python version of "Apocalypse Now". And I bet you didn't even see it coming.] You don't really need the close(), because the Python Elves will do it for you after the program is over, but it is considered good form because it shows attention to detail and moral fiber. Note that count() will also accept strings (such as 'word') and not only single characters ('w'), so you get more fun for same price. There is one problem with this version, though: read() gives you the whole file as one big string. Usually, this should be fine, but if you import a very, very large file (say, some DNA sequencing data from your secret T-Rex project) on a very, very small machine, this might cause trouble. So you might be better off reading the file line by line after all. You could try this (in Python 2.2): ================================ def InCharCount(location, character): subj = file(location, "r") nbr_of_char = 0 for line in subj: nbr_of_char = nbr_of_char + line.count(character) return nbr_of_char ================================ The "for line in subj" goes thru the file one line at a time very quickly, and you simply add up all the times the char occurs in each line. This takes care of any memory problems you might have with large files, but does take longer. Hope this helps, Y, Scot -- Scot W. Stevenson wrote me on Sunday, 8. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 1966 hours and has a CPU that is falling asleep at a system load of 0.00. From Gil Tucker [ateliermobile]" Greetings, I am trying to make a program that can generate random ascii art forms or designs. I have tried a few but they dont work.Any tip or tips. Or warnings? gil tucker From magnus@thinkware.se Sun Sep 8 09:57:15 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 08 Sep 2002 10:57:15 +0200 Subject: [Tutor] Re: Re: Factory classes (etc) In-Reply-To: <000901c2560c$f3c4c330$9865fea9@arthur> References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F7@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <5.1.0.14.0.20020908000534.02ad8818@www.thinkware.se> At 21:21 2002-09-06 -0400, Arthur wrote: >I am not "missing" method overloading in the sense that I feel Python is >somehow deficient by not having it built-in. ... >But for what I am doing I want to build as much as I can a scripting >interface that follows geometric intuitive logic, not programmers logic. >And at the scripting interface level what things are called *is* to the >essence >of things. If a point is instantiated as an Intersection, if might be the >intersection of a number of other possible elements. It is absolutely >redundant >both to have the Intersection classes named in accordance with what= elements >they take as arguments, and then to give them those arguments - because in >fact the arguments themselves define the kind of intersection we are >trying to create. It's really difficult to help you when you are so abstract. To be honest, I don't really understand what you are trying to do. I think it would be easier if you showed a sample of code. The thing is, that if you have the same name, you should basically do the same thing. In Java or C++ you can't to the same thing just once if the types or number of params differ, but in Python you usually can. import math, cmath, operator # This handles any number of ints, floats or complex numbers. def RootSumSquared(*args): if type(1j) in map(type, args): sqrt =3D cmath.sqrt else: sqrt =3D math.sqrt return sqrt(reduce(operator.add, map(lambda x: x*x, args))) RSS =3D RootSumSquared print RSS(3,4) print RSS(0.3, 0.4) print RSS(3j, 4) print RSS(0.3, 4, 5j) print apply(RSS, (1, )*100) Of cource the simple solution in Java or C++ would be to cast all arguments to Complex, but note that I don't use the slower complex sqrt unless I have a complex parameter. Would your overloaded method look very different from one another? Maybe you can warp your thinking into making them much more similar, and then further into being the same thing? >Given lets say 20 classes which could take anywhere from one to >five different sets of arguments, and thats a hell of a lot of >if type(arg[0]): > xxx >else: > yyyy > >to try to get right and keep straight. I bet it will still be much shorter than Java if you use the kind of signature recognition function that I mentioned previously... BTW, would it be possible to write a base class Overloader such that: class X(Overloader): def add_int_int(self, a, b): return a + b def add_string_int(self, a, b): return a + str(b) a =3D X() a.add(1, 3) =3D> 4 a.add('a', 5) =3D> 'a5' a.add('d', 'd') =3D> AttributeError __getattr__ will catch the calls to the undefined 'add' method, but I don't know how to figure out what the argument list looked like. Can that be found from the Python introspection magic? >>> class X: ... def x(self): ... print "Hello" ... def __getattr__(self, value): ... return self.x ... >>> a =3D X() >>> a.hello() Hello >>> a.bitMap() Hello This is a little bit on the way, it the __getattr__ is in the base class. There are seemingly useful functions in the inspect module, but they aren't so easy to figure out... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sun Sep 8 10:00:26 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 08 Sep 2002 11:00:26 +0200 Subject: [Tutor] Individual Character Count In-Reply-To: <200209080210.31575.scot@possum.in-berlin.de> References: <20020907224245.E830C93768@server2.fastmail.fm> <20020907224245.E830C93768@server2.fastmail.fm> Message-ID: <5.1.0.14.0.20020908105918.02aec7c8@www.thinkware.se> At 02:10 2002-09-08 +0200, Scot W. Stevenson wrote: >You don't really need the close(), because the Python Elves will do it for >you after the program is over, but it is considered good form because it >shows attention to detail and moral fiber. Also, you don't know when the elves will take action if you are using Jython. Jython uses the Java garbage collection, which is not based on reference counting. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From martin.klaffenboeck@gmx.at Sun Sep 8 12:27:09 2002 From: martin.klaffenboeck@gmx.at (Martin Klaffenboeck) Date: 08 Sep 2002 13:27:09 +0200 Subject: [Tutor] question on lists In-Reply-To: <200209071433.35580.shalehperry@attbi.com> References: <1031431760.818.118.camel@martin.kleinerdrache.org> <200209071433.35580.shalehperry@attbi.com> Message-ID: <1031484430.689.5.camel@martin.kleinerdrache.org> Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry: > > list.sort() takes a function to determine sort order. There is a handy > function called cmp() which is often used for this. > > Your add function is not too hard to write and the random module may give you > what you want for the random stuff. Ok, that works good with for x in words: if x[0] < newword: continue if x[0] > newword: break pos = words.index(x) But what can I do that the words are sorted case insensitive. (No matter about upper and lower case letters)? And how can I tell words.sort() that it should only sort the first column of my 4 column list? Martin -- From thomi@thomi.imail.net.nz Sun Sep 8 12:41:07 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Sun, 8 Sep 2002 23:41:07 +1200 Subject: [Tutor] list sorting problem (help!) Message-ID: <20020908234107.00522172.thomi@thomi.imail.net.nz> ok, i have a problem. i have a list, like this: ['email me','My programs','Web Design','Web Hosting'] and i want to sort them, so i can say something like "the link 'My programs' should ALWAYS appear at the top". i thought I'd use a weighting system, so the 'My programs' list item would be weighted 0, and so always appear at the top. the next one would be '1', then '2', etc. etc. etc. i could give 'contact me' a weighting of 999, so it would always appear at the bottom. could i ask some of you python experts to make me a simple procedure which would do this?? It's for a CGI, which has to load every page, so the emphasis should be on minimal size and speed.. thanks. -- The software required Win95 or better, so I installed Linux. Thomi Richards, thomi@imail.net.nz From glingl@aon.at Sun Sep 8 13:06:08 2002 From: glingl@aon.at (Gregor Lingl) Date: Sun, 08 Sep 2002 14:06:08 +0200 Subject: [Tutor] question on lists References: <1031431760.818.118.camel@martin.kleinerdrache.org> <200209071433.35580.shalehperry@attbi.com> <1031484430.689.5.camel@martin.kleinerdrache.org> Message-ID: <3D7B3D30.4000501@aon.at> Martin Klaffenboeck schrieb: >Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry: > > > >>list.sort() takes a function to determine sort order. There is a handy >>function called cmp() which is often used for this. >> >>Your add function is not too hard to write and the random module may give you >>what you want for the random stuff. >> >> > >Ok, that works good with > >for x in words: > if x[0] < newword: > continue > if x[0] > newword: > break > > pos = words.index(x) > >But what can I do that the words are sorted case insensitive. (No matter >about upper and lower case letters)? > >>> l = [["Hans",1,2,3], ["fritz",4,5,6], ["Adam",7,8,9]] >>> t = l[:] >>> t.sort() >>> t [['Adam', 7, 8, 9], ['Hans', 1, 2, 3], ['fritz', 4, 5, 6]] >>> cmp("Adam","Hans") -1 >>> cmp("Hans","fritz") -1 >>> cmp("Hans".upper(),"fritz".upper()) 1 >>> def vgl(a,b): return cmp(a[0].upper(), b[0].upper()) >>> t = l[:] >>> t [['Hans', 1, 2, 3], ['fritz', 4, 5, 6], ['Adam', 7, 8, 9]] >>> t.sort(vgl) >>> t [['Adam', 7, 8, 9], ['fritz', 4, 5, 6], ['Hans', 1, 2, 3]] >>> > >And how can I tell words.sort() that it should only sort the first >column of my 4 column list? > > What do you mean exactly. Do you want the result for the list used above to be: [['Adam', 1, 2, 3], ['fritz', 4, 5, 6], ['Hans', 7, 8, 9]] ??? Gregor >Martin > > > From ajs@ix.netcom.com Sun Sep 8 15:08:53 2002 From: ajs@ix.netcom.com (Arthur) Date: Sun, 8 Sep 2002 10:08:53 -0400 Subject: [Tutor] Re: Re: Factory classes (etc) References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C8F7@mbtlipnt02.btlabs.bt.co.uk> <5.1.0.14.0.20020908000534.02ad8818@www.thinkware.se> Message-ID: <005d01c25741$43c65f80$9865fea9@arthur> >It's really difficult to help you when you are so abstract. >To be honest, I don't really understand what you are trying >to do. I think it would be easier if you showed a sample of >code. Well actually at this point I am not so much asking for specific help. More trying to get a better overview of certain OO concepts that are inherently abstract, at least to me. >The thing is, that if you have the same name, you should >basically do the same thing. Now this seems to be somewhere near the gist of my issue. I want things to have the same name for objects if they end up as objects with the same essential attributes. How they get to have those attributes may be totally different. A Chord, for example, might be derived as the intersection of a line and a circle, the intersection of 2 circles, the intersection of a line and a sphere. The key attributes of a Chord are its endpoints. Depending on the the kinds of geometric objects fed in as input, the routines to determine those endpoints differ fundamently, but at the end I have the precisely same kind of an object - whose essential attributes are its two endpoints. They are precisely the same kinds of objects because if I give a Chord as an argument to the creation of another geometric object, it is of no relevance whether that Chord was orginally created by 2 circles, or a sphere and a line. Now in my mind Java method overloading addresses this need head-on. But maybe that is where I am confused and creating confusion - because though I had done some Java, I much prefer Python - and my Java understanding is actually much more vague than my Python. At any rate, the algorythm I keep referring to, would be an absolutely generic function to which I could feed lists of acceptable arguments for a Class, and get, as a return, information sufficient to inform the Class which specific routine it needs to call to create its essential attributes - in the case of a Chord, its endpoints. My tutorial need, I guess, is some ratification that my understanding and goals and approach are sensible. Art From emile@fenx.com Sun Sep 8 15:58:10 2002 From: emile@fenx.com (Emile van Sebille) Date: Sun, 8 Sep 2002 07:58:10 -0700 Subject: [Tutor] Re: list sorting problem (help!) References: <20020908234107.00522172.thomi@thomi.imail.net.nz> Message-ID: Thomi: > ok, i have a problem. i have a list, like this: > > ['email me','My programs','Web Design','Web Hosting'] > > and i want to sort them, so i can say something like "the link 'My > programs' should ALWAYS appear at the top". i thought I'd use a > weighting system, so the 'My programs' list item would be weighted 0, > and so always appear at the top. the next one would be '1', then '2', > etc. etc. etc. i could give 'contact me' a weighting of 999, so it would > always appear at the bottom. > thisset = ['email me','My programs','Web Design','Web Hosting'] sortwghts = {'email me':999,'My programs':0,'Web Design':40,'Web Hosting':200} thisset.sort(lambda this, other: cmp (sortwghts[this], sortwghts[other])) print thisset ## -> ['My programs', 'Web Design', 'Web Hosting', 'email me'] sortwghts = {'email me':999,'My programs':2000,'Web Design':2040,'Web Hosting':2200} thisset.sort(lambda this, other: cmp (sortwghts[this], sortwghts[other])) print thisset ## -> ['email me', 'My programs', 'Web Design', 'Web Hosting'] Note: Depending on your python version, the lambda may need to start: lambda this, other, sortwghts=sortwghts: cmp HTH, -- Emile van Sebille emile@fenx.com --------- From rob@uselesspython.com Sun Sep 8 18:24:12 2002 From: rob@uselesspython.com (Rob) Date: Sun, 8 Sep 2002 12:24:12 -0500 Subject: [Tutor] ascii art In-Reply-To: <001e01c25702$e7034ee0$6400a8c0@privat> Message-ID: What sort of ideas have you tried, and what kind of results did you get? There's randomness, and then there's randomness! heh, Rob http://uselesspython.com > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Gil Tucker [ateliermobile] > Sent: Sunday, September 08, 2002 1:16 AM > To: tutor@python.org > Subject: [Tutor] ascii art > > > > > > Greetings, > I am trying to make a program that can > generate random ascii art forms or designs. I have tried a few > but they dont work.Any tip or tips. Or warnings? > gil tucker > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From rob@uselesspython.com Sun Sep 8 20:28:59 2002 From: rob@uselesspython.com (Rob) Date: Sun, 8 Sep 2002 14:28:59 -0500 Subject: [Tutor] linux/unix-friendly python Message-ID: I'm working on putting together a quick overhead view of python for my local linux users group, and figured I'd hit the list for ideas on making a zippy presentation. What I don't have in mind is to teach people "how to program", but instead to show some of the nifty built-in features that demonstrate python's suitability for system administration and other tasks. So I thought it might be a good idea to hit up the tutor list for thoughts on what might be ideal to mention in a situation like this, in which I'll have only one session to make a good pitch. Several members of this group have already embraced or at least flirted with python, and I expect a warm reception. So far I'm jotting down notes from the Library Reference and from personal experience. But since a lot of python people seem to use linux a lot more than I do, I'd bet some can point out better ideas than those I would think of personally. Rob http://uselesspython.com From magnus@thinkware.se Mon Sep 9 00:18:01 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 09 Sep 2002 01:18:01 +0200 Subject: [Tutor] list sorting problem (help!) In-Reply-To: <20020908234107.00522172.thomi@thomi.imail.net.nz> Message-ID: <5.1.0.14.0.20020909010533.02ac22d8@www.thinkware.se> At 23:41 2002-09-08 +1200, Thomi Richards wrote: >ok, i have a problem. i have a list, like this: > >['email me','My programs','Web Design','Web Hosting'] > >and i want to sort them, so i can say something like "the link 'My >programs' should ALWAYS appear at the top". i thought I'd use a >weighting system, so the 'My programs' list item would be weighted 0, >and so always appear at the top. the next one would be '1', then '2', >etc. etc. etc. i could give 'contact me' a weighting of 999, so it would >always appear at the bottom. > >could i ask some of you python experts to make me a simple procedure >which would do this?? It's for a CGI, which has to load every page, so >the emphasis should be on minimal size and speed.. thanks. Sure thing, thingsToSort = ['email me','My programs','Web Design','Web Hosting'] sortWeights = [(999,'email me'), (0, 'My programs'), (6, 'Web Design'), (5, 'My rtyrty'), (4, 'Web fghfgh'), (3, 'My cvbcvb'), (2, 'Web ertert'), (1, 'Web Hosting'), ] usedWithWeights = [x for x in sortWeights if x[1] in thingsToSort] usedWithWeights.sort() sortedThings = [x[1] for x in usedWithWeights] print sortedThings This is a variant of the Schwartzian transform (sp?). That's a Perl thingie, but since .sort() is much slower with a sort function supplied in Python, this is typically faster than to supply a function to the sort() method. -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From Gil Tucker [ateliermobile]" Message-ID: <002901c257ce$a2372e40$6400a8c0@privat> Hi, I wonder why no one replied to my question about doing art with ascii types? I opnly got a reply about hacking. If you create stuff with ascii does that mean you are a "HACKER" in the negative category. Come on! Gil tucker ----- Original Message ----- From: To: Sent: Sunday, September 08, 2002 4:11 PM Subject: Tutor digest, Vol 1 #1916 - 14 msgs > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-request@python.org > > You can reach the person managing the list at > tutor-admin@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. question on lists (Martin Klaffenboeck) > 2. Re: question on lists (Sean 'Shaleh' Perry) > 3. Re: The Gang of Four (was: A Book for You and Me) (Magnus Lycka) > 4. Individual Character Count (Kyle Babich) > 5. Re: Individual Character Count (Danny Yoo) > 6. Re: Individual Character Count (Danny Yoo) > 7. Re: Individual Character Count (Scot W. Stevenson) > 8. ascii art (Gil Tucker [ateliermobile]) > 9. Re: Re: Re: Factory classes (etc) (Magnus Lycka) > 10. Re: Individual Character Count (Magnus Lycka) > 11. Re: question on lists (Martin Klaffenboeck) > 12. list sorting problem (help!) (Thomi Richards) > 13. Re: question on lists (Gregor Lingl) > 14. Re: Re: Re: Factory classes (etc) (Arthur) > > --__--__-- > > Message: 1 > From: Martin Klaffenboeck > To: tutor@python.org > Date: 07 Sep 2002 22:49:19 +0200 > Subject: [Tutor] question on lists > > Hello, > > I have got a list with 4 columns. This 4 columns are: > > string1 string2 id timestamp > > So how do I store the data? As a list or as an array: > > What I want to do with this data: > > Sort the list alphabetically (if possible _not_ case sensitive). > Add new entries at the right alphabetic position. > > Randomize the list (or a copy of it) and sort it back alphabetically > after modifying the id and the timestamp. > > > Whats the best way to store data for this in python? > > Thanks, > Martin (a newbie) > > PS. Sorry for my bad english. > > -- > > > > --__--__-- > > Message: 2 > From: Sean 'Shaleh' Perry > To: tutor@python.org > Subject: Re: [Tutor] question on lists > Date: Sat, 7 Sep 2002 14:33:35 -0700 > > On Saturday 07 September 2002 13:49, Martin Klaffenboeck wrote: > > Hello, > > > > I have got a list with 4 columns. This 4 columns are: > > > > string1 string2 id timestamp > > > > So how do I store the data? As a list or as an array: > > > > a list is for all intents and purposes an array in python. There are 3=20 > grouping structures in core python -- tuple, list, dictionary. A tuple i= > s a=20 > list which can not be changed once created a dictionary is equivalent to=20 > perl's hash or C++'s map. > > > What I want to do with this data: > > > > Sort the list alphabetically (if possible _not_ case sensitive). > > Add new entries at the right alphabetic position. > > > > Randomize the list (or a copy of it) and sort it back alphabetically > > after modifying the id and the timestamp. > > > > > > list.sort() takes a function to determine sort order. There is a handy=20 > function called cmp() which is often used for this. > > Your add function is not too hard to write and the random module may give= > you=20 > what you want for the random stuff. > > Read through the python docs on lists and the builtin functions it should= > get=20 > you started. > > > --__--__-- > > Message: 3 > Date: Sun, 08 Sep 2002 00:04:53 +0200 > To: Allyn Weaks , tutor@python.org > From: Magnus Lycka > Subject: Re: [Tutor] The Gang of Four (was: A Book for You and Me) > > At 19:55 2002-09-06 -0700, Allyn Weaks wrote: > >On 4/9/02, Scot W. Stevenson wrote: > > >"We read Knuth so you don't have to" (Tim Peters in the > > >"Python Cookbook") kind of book. > > > >But, but, but, Knuth is quite readable and even funny. If you have a > >sufficiently warped sense of humor :-). > > And plenty of time... I tend to get tired before he > gets to the point. He is ... different. See also: > http://www.thinkware.se/cgi-bin/thinki.cgi/DiscussTheArtOfComputerProgrammin= > g > (Look at the end for example of warped humour.) > > > --=20 > Magnus Lyck=E5, Thinkware AB > =C4lvans v=E4g 99, SE-907 50 UME=C5 > tel: 070-582 80 65, fax: 070-612 80 65 > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > > --__--__-- > > Message: 4 > Date: Sat, 7 Sep 2002 22:42:45 UT > From: "Kyle Babich" > To: "Tutor" > Subject: [Tutor] Individual Character Count > > I'm trying (with little luck) to create a function to count how many > time an individual character appears in a file. What I have so far I > have written on patterns I've noticed but it is still extremely buggy > depending on whether the character being searched for appears as the > first character in the file, the last, both, or neither. Here it is: > > #################### > def InCharCount(location, character): > subj =3D file(location, "r") > body =3D subj.read() > > body =3D body.split("\n") > body =3D string.join(body, "") > body =3D body.split(character) > > last =3D len(body) > last =3D last - 1 > > char =3D 0 > for each in body: > char =3D char + 1 > > if body[0] in [""]: > char =3D char - 1 > > elif body[last] in [""]: > char =3D char - 1 > =20 > else: > pass > > return char > #################### > > Could someone please help me work the bugs out of this? I have a > feeling that I'm making this harder than I need to for myself again. > > Thank you, > -- > Kyle > > > --__--__-- > > Message: 5 > Date: Sat, 7 Sep 2002 16:17:20 -0700 (PDT) > From: Danny Yoo > To: Kyle Babich > cc: Tutor > Subject: Re: [Tutor] Individual Character Count > > > > On Sat, 7 Sep 2002, Kyle Babich wrote: > > > I'm trying (with little luck) to create a function to count how many > > time an individual character appears in a file. What I have so far I > > have written on patterns I've noticed but it is still extremely buggy > > depending on whether the character being searched for appears as the > > first character in the file, the last, both, or neither. Here it is: > > Hi Kyle, > > > Let's take a look at the program. > > > #################### > > def InCharCount(location, character): > > subj = file(location, "r") > > body = subj.read() > > > > body = body.split("\n") > > body = string.join(body, "") > > body = body.split(character) > > Hmmm... Ok, so if our file's contents has something like "aaabbabba", > then if we wanted to count all the "a"'s, we could split against 'a' and > see how many pieces come up: > > ### > >>> s = "aaabbabba" > >>> l = s.split('a') > >>> l > ['', '', '', 'bb', 'bb', ''] > ### > > As a result, our list won't contain any more "a"'s once we split by 'a'. > But it will have a bunch of empty strings, which might look silly. > > ... But those empty strings are there for a very good reason: we should be > able to rehydrate our string, and reverse the process by using join(): > > ### > >>> 'a'.join(l) > 'aaabbabba' > ### > > > Your approach seems reasonable. Once you've split the 'body' up, you > already have enough information to count how many of that 'character' is > in there: the number of 'character's should just be the number of > in-betweens we have in our split-up body: > > ['', '', '', 'bb', 'bb', ''] > > That is, if we have a list of six elements, the number of "in-between" > places is just the number of commas we see in our list: 5. > > join ==> > > '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + '' > > So all you need now is to count "in-between" places. I'll let you figure > out how to do that. *grin* > > > Your approach works even if our string is initially empty: > > ### > >>> mystring = "" > >>> l = mystring.split("a") > >>> l > [''] > >>> "a".join(l) > '' > ### > > because when our split-up list is only one element long, there are no > "in-between" spots in our list, which is exactly right. > > > > Let's look at the rest of your code: > > > last = len(body) > > last = last - 1 > > > > char = 0 > > for each in body: > > char = char + 1 > > > > if body[0] in [""]: > > char = char - 1 > > > > elif body[last] in [""]: > > char = char - 1 > > > > else: > > pass > > > > return char > > I'd remove this part of the code because it's making the problem too > complicated. *grin* I don't think you need to do more cases based on > empty strings. Empty strings in your split-up list are perfectly good: > you don't need to do additional case analysis on them. > > > Good luck to you! > > > > --__--__-- > > Message: 6 > Date: Sat, 7 Sep 2002 16:24:58 -0700 (PDT) > From: Danny Yoo > To: Kyle Babich > cc: Tutor > Subject: Re: [Tutor] Individual Character Count > > > > Your approach seems reasonable. Once you've split the 'body' up, you > > already have enough information to count how many of that 'character' is > > in there: the number of 'character's should just be the number of > > in-betweens we have in our split-up body: > > > > ['', '', '', 'bb', 'bb', ''] > > > > That is, if we have a list of six elements, the number of "in-between" > > places is just the number of commas we see in our list: 5. > > > > join ==> > > > > '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + '' > > > Hi Kyle, > > Doh. I messed up here in the diagram. Forget those pictures above. I > meant to write: > > > l = ['', '', '', 'bb', 'bb', ''] > > 'a'.join(l) ==> > > '' + 'a' + '' + 'a' + '' + 'a' + 'bb' + 'a' + 'bb' + 'a' + '' > > > instead, which tries to show better the relationship that join() has with > split(). My apologies for being sloppy about this. > > > > --__--__-- > > Message: 7 > From: "Scot W. Stevenson" > Organization: Hexenhaus Zepernick > To: "Kyle Babich" > Subject: Re: [Tutor] Individual Character Count > Date: Sun, 8 Sep 2002 02:10:31 +0200 > Cc: tutor@python.org > > Hello Kyle, > > > I'm trying (with little luck) to create a function to count how many > > time an individual character appears in a file. > > One thing I have learned in the past few months about Python is to always > consult the Module Library before even considering writing new code. This > is the "batteries included" principle that people keep talking about with > Python, and it works. > > In this case, there is actually a "count" method in the string module. I'm > assuming you have a new version of Python such as 2.2, where you don't > have to import the string module anymore (if not, we'll try again with one > of the older forms), so you get: > > =============================== > >>> mystring = 'Spam! Spam! Spam!' > >>> mystring.count('S') > 3 > =============================== > > Or, even shorter, though it looks strange the first time you see it: > > =============================== > >>> 'Spam! Spam! Spam!'.count('S') > 3 > =============================== > > So the short version of your function could be: > > =============================== > def InCharCount(location, character): > subj = file(location, "r") > body = subj.read() > subj.close() > return body.count(character) > =============================== > > [I just love that last line: It sounds like something out of a Python > version of "Apocalypse Now". And I bet you didn't even see it coming.] > > You don't really need the close(), because the Python Elves will do it for > you after the program is over, but it is considered good form because it > shows attention to detail and moral fiber. Note that count() will also > accept strings (such as 'word') and not only single characters ('w'), so > you get more fun for same price. > > There is one problem with this version, though: read() gives you the whole > file as one big string. Usually, this should be fine, but if you import a > very, very large file (say, some DNA sequencing data from your secret > T-Rex project) on a very, very small machine, this might cause trouble. > > So you might be better off reading the file line by line after all. You > could try this (in Python 2.2): > > ================================ > def InCharCount(location, character): > subj = file(location, "r") > > nbr_of_char = 0 > for line in subj: > nbr_of_char = nbr_of_char + line.count(character) > > return nbr_of_char > ================================ > > The "for line in subj" goes thru the file one line at a time very quickly, > and you simply add up all the times the char occurs in each line. This > takes care of any memory problems you might have with large files, but > does take longer. > > Hope this helps, > Y, Scot > > -- > Scot W. Stevenson wrote me on Sunday, 8. Sep 2002 in Zepernick, Germany > on his happy little Linux system that has been up for 1966 hours > and has a CPU that is falling asleep at a system load of 0.00. > > > > --__--__-- > > Message: 8 > Reply-To: "Gil Tucker [ateliermobile]" > From: "Gil Tucker [ateliermobile]" > To: > Date: Sun, 8 Sep 2002 08:16:11 +0200 > Subject: [Tutor] ascii art > > > > > Greetings, > I am trying to make a program that can > generate random ascii art forms or designs. I have tried a few > but they dont work.Any tip or tips. Or warnings? > gil tucker > > > > > --__--__-- > > Message: 9 > Date: Sun, 08 Sep 2002 10:57:15 +0200 > To: "Arthur" , > From: Magnus Lycka > Subject: Re: [Tutor] Re: Re: Factory classes (etc) > > At 21:21 2002-09-06 -0400, Arthur wrote: > >I am not "missing" method overloading in the sense that I feel Python is > >somehow deficient by not having it built-in. > ... > >But for what I am doing I want to build as much as I can a scripting > >interface that follows geometric intuitive logic, not programmers logic. > >And at the scripting interface level what things are called *is* to the > >essence > >of things. If a point is instantiated as an Intersection, if might be the > >intersection of a number of other possible elements. It is absolutely > >redundant > >both to have the Intersection classes named in accordance with what= > elements > >they take as arguments, and then to give them those arguments - because in > >fact the arguments themselves define the kind of intersection we are > >trying to create. > > It's really difficult to help you when you are so abstract. > To be honest, I don't really understand what you are trying > to do. I think it would be easier if you showed a sample of > code. > > The thing is, that if you have the same name, you should > basically do the same thing. In Java or C++ you can't to > the same thing just once if the types or number of params > differ, but in Python you usually can. > > import math, cmath, operator > > # This handles any number of ints, floats or complex numbers. > def RootSumSquared(*args): > if type(1j) in map(type, args): sqrt =3D cmath.sqrt > else: sqrt =3D math.sqrt > return sqrt(reduce(operator.add, map(lambda x: x*x, args))) > > RSS =3D RootSumSquared > > print RSS(3,4) > print RSS(0.3, 0.4) > print RSS(3j, 4) > print RSS(0.3, 4, 5j) > print apply(RSS, (1, )*100) > > Of cource the simple solution in Java or C++ would be to > cast all arguments to Complex, but note that I don't use > the slower complex sqrt unless I have a complex parameter. > > Would your overloaded method look very different from one > another? Maybe you can warp your thinking into making them > much more similar, and then further into being the same > thing? > > >Given lets say 20 classes which could take anywhere from one to > >five different sets of arguments, and thats a hell of a lot of > >if type(arg[0]): > > xxx > >else: > > yyyy > > > >to try to get right and keep straight. > > I bet it will still be much shorter than Java if you use > the kind of signature recognition function that I mentioned > previously... > > BTW, would it be possible to write a base class Overloader > such that: > > class X(Overloader): > def add_int_int(self, a, b): > return a + b > def add_string_int(self, a, b): > return a + str(b) > > a =3D X() > > a.add(1, 3) =3D> 4 > a.add('a', 5) =3D> 'a5' > a.add('d', 'd') =3D> AttributeError > > __getattr__ will catch the calls to the undefined > 'add' method, but I don't know how to figure out > what the argument list looked like. Can that be > found from the Python introspection magic? > > >>> class X: > ... def x(self): > ... print "Hello" > ... def __getattr__(self, value): > ... return self.x > ... > >>> a =3D X() > >>> a.hello() > Hello > >>> a.bitMap() > Hello > > This is a little bit on the way, it the __getattr__ > is in the base class. There are seemingly useful > functions in the inspect module, but they aren't so > easy to figure out... > > > > --=20 > Magnus Lyck=E5, Thinkware AB > =C4lvans v=E4g 99, SE-907 50 UME=C5 > tel: 070-582 80 65, fax: 070-612 80 65 > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > > --__--__-- > > Message: 10 > Date: Sun, 08 Sep 2002 11:00:26 +0200 > To: "Scot W. Stevenson" , > "Kyle Babich" > From: Magnus Lycka > Subject: Re: [Tutor] Individual Character Count > Cc: tutor@python.org > > At 02:10 2002-09-08 +0200, Scot W. Stevenson wrote: > >You don't really need the close(), because the Python Elves will do it for > >you after the program is over, but it is considered good form because it > >shows attention to detail and moral fiber. > > Also, you don't know when the elves will take action > if you are using Jython. Jython uses the Java garbage > collection, which is not based on reference counting. > > > --=20 > Magnus Lyck=E5, Thinkware AB > =C4lvans v=E4g 99, SE-907 50 UME=C5 > tel: 070-582 80 65, fax: 070-612 80 65 > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > > --__--__-- > > Message: 11 > Subject: Re: [Tutor] question on lists > From: Martin Klaffenboeck > To: tutor@python.org > Date: 08 Sep 2002 13:27:09 +0200 > > Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry: > > > > > list.sort() takes a function to determine sort order. There is a handy > > function called cmp() which is often used for this. > > > > Your add function is not too hard to write and the random module may give you > > what you want for the random stuff. > > Ok, that works good with > > for x in words: > if x[0] < newword: > continue > if x[0] > newword: > break > > pos = words.index(x) > > But what can I do that the words are sorted case insensitive. (No matter > about upper and lower case letters)? > > And how can I tell words.sort() that it should only sort the first > column of my 4 column list? > > Martin > > -- > > > > --__--__-- > > Message: 12 > Date: Sun, 8 Sep 2002 23:41:07 +1200 > From: Thomi Richards > To: tutor@python.org > Subject: [Tutor] list sorting problem (help!) > > ok, i have a problem. i have a list, like this: > > ['email me','My programs','Web Design','Web Hosting'] > > and i want to sort them, so i can say something like "the link 'My > programs' should ALWAYS appear at the top". i thought I'd use a > weighting system, so the 'My programs' list item would be weighted 0, > and so always appear at the top. the next one would be '1', then '2', > etc. etc. etc. i could give 'contact me' a weighting of 999, so it would > always appear at the bottom. > > could i ask some of you python experts to make me a simple procedure > which would do this?? It's for a CGI, which has to load every page, so > the emphasis should be on minimal size and speed.. thanks. > > -- > The software required Win95 or better, so I installed Linux. > Thomi Richards, > thomi@imail.net.nz > > > --__--__-- > > Message: 13 > Date: Sun, 08 Sep 2002 14:06:08 +0200 > From: Gregor Lingl > To: Martin Klaffenboeck > CC: tutor@python.org > Subject: Re: [Tutor] question on lists > > Martin Klaffenboeck schrieb: > > >Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry: > > > > > > > >>list.sort() takes a function to determine sort order. There is a handy > >>function called cmp() which is often used for this. > >> > >>Your add function is not too hard to write and the random module may give you > >>what you want for the random stuff. > >> > >> > > > >Ok, that works good with > > > >for x in words: > > if x[0] < newword: > > continue > > if x[0] > newword: > > break > > > > pos = words.index(x) > > > >But what can I do that the words are sorted case insensitive. (No matter > >about upper and lower case letters)? > > > >>> l = [["Hans",1,2,3], > ["fritz",4,5,6], > ["Adam",7,8,9]] > >>> t = l[:] > >>> t.sort() > >>> t > [['Adam', 7, 8, 9], ['Hans', 1, 2, 3], ['fritz', 4, 5, 6]] > >>> cmp("Adam","Hans") > -1 > >>> cmp("Hans","fritz") > -1 > >>> cmp("Hans".upper(),"fritz".upper()) > 1 > >>> def vgl(a,b): > return cmp(a[0].upper(), b[0].upper()) > > >>> t = l[:] > >>> t > [['Hans', 1, 2, 3], ['fritz', 4, 5, 6], ['Adam', 7, 8, 9]] > >>> t.sort(vgl) > >>> t > [['Adam', 7, 8, 9], ['fritz', 4, 5, 6], ['Hans', 1, 2, 3]] > >>> > > > > >And how can I tell words.sort() that it should only sort the first > >column of my 4 column list? > > > > > What do you mean exactly. Do you want the result for the list > used above to be: > [['Adam', 1, 2, 3], ['fritz', 4, 5, 6], ['Hans', 7, 8, 9]] > ??? > > Gregor > > >Martin > > > > > > > > > > > > > --__--__-- > > Message: 14 > From: "Arthur" > To: , "Magnus Lycka" > Subject: Re: [Tutor] Re: Re: Factory classes (etc) > Date: Sun, 8 Sep 2002 10:08:53 -0400 > > >It's really difficult to help you when you are so abstract. > >To be honest, I don't really understand what you are trying > >to do. I think it would be easier if you showed a sample of > >code. > > Well actually at this point I am not so much asking for specific help. More > trying to get a better overview of certain OO concepts that are inherently > abstract, at least to me. > > >The thing is, that if you have the same name, you should > >basically do the same thing. > > Now this seems to be somewhere near the gist of my issue. I want things to > have the same name for objects if they end up as objects with the same > essential attributes. How they get to have those attributes may be totally > different. A Chord, for example, might be derived as the intersection of a > line and a circle, the intersection of 2 circles, the intersection of a line > and a sphere. The key attributes of a Chord are its endpoints. Depending > on the the kinds of geometric objects fed in as input, the routines to > determine those endpoints differ fundamently, but at the end I have the > precisely same kind of an object - whose essential attributes are its two > endpoints. They are precisely the same kinds of objects because if I give a > Chord as an argument to the creation of another geometric object, it is of > no relevance whether that Chord was orginally created by 2 circles, or a > sphere and a line. > > Now in my mind Java method overloading addresses this need head-on. But > maybe that is where I am confused and creating confusion - because though I > had done some Java, I much prefer Python - and my Java understanding is > actually much more vague than my Python. > > At any rate, the algorythm I keep referring to, would be an absolutely > generic function to which I could feed lists of acceptable arguments for a > Class, and get, as a return, information sufficient to inform the Class > which specific routine it needs to call to create its essential attributes - > in the case of a Chord, its endpoints. > > My tutorial need, I guess, is some ratification that my understanding and > goals and approach are sensible. > > Art > > > > > > > --__--__-- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest > > From shalehperry@attbi.com Mon Sep 9 12:05:02 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Mon, 9 Sep 2002 04:05:02 -0700 Subject: [Tutor] Re: Tutor digest, Vol 1 #1916 - msg 8 In-Reply-To: <002901c257ce$a2372e40$6400a8c0@privat> References: <20020908141113.2298.18670.Mailman@mail.python.org> <002901c257ce$a2372e40$6400a8c0@privat> Message-ID: <200209090405.02620.shalehperry@attbi.com> On Sunday 08 September 2002 23:37, Gil Tucker [ateliermobile] wrote: > Hi, > I wonder why no one replied to my question about > doing art with ascii types? I opnly got a reply about hacking. > If you create stuff with ascii does that mean you are a "HACKER" > in the negative category. Come on! > Gil tucker > No one replied because you did not actually ask a question or present any= =20 information to help you with. We got the equivalent of "my car makes thi= s=20 noise, what's wrong with it". Show us some code that you thought would w= ork,=20 an error message, the corrupt output, something. Remember we are working= on=20 only what you give us, even if we could read minds e-mail does not give u= s a=20 sufficiently strong connection. "ascii art" is a wide range of things. Are you trying to draw boxes? fox= es?=20 entrances to bbs'? each letter of the alphabet? From erikprice@mac.com Mon Sep 9 13:39:52 2002 From: erikprice@mac.com (Erik Price) Date: Mon, 9 Sep 2002 08:39:52 -0400 Subject: [Tutor] streamlining a return statement Message-ID: <3C8F6165-C3F1-11D6-85DA-00039351FE6A@mac.com> I have a function in a chunk of code that detects the presence of HTML attributes in a string. If successful, the function returns a tuple (containing 3 elements: the whitespace preceding the tag, the tag element name itself, and a string containing all of the attributes of the element). It works fine. But I'm wondering whether returning an empty tuple is a good idea. It feels like I should make use of Python's exception facilities. (Right now the client code which uses this function works by calling len() on the return value of the function, but I could modify that to handle some kind of IndexError exception or whichever exception is appropriate.) Can someone criticize my code please? Specifically the "return" statements -- the first part of the function is just the way I want it. Also, using "if matchobj" works but is that the preferred way to detect whether a re.search() was successful? (Testing for successful assignment, "if matchobj = re.search()", which I admit is a Perlish way of looking at it, doesn't work.) def atts_detect(line): """searches a line for a tag with attributes and returns a tuple of info about the tag if attributes are found""" import re # this regex ensures that the tag the kind we want needle = r'(\s*)<(\w+)(\s+[-\w]+=[\'"].+[\'"])+(\s*/?>)' regex = re.compile(needle) # a match object is only returned if search is successful matchobj = regex.search(line) if matchobj: return matchobj.groups() # return an empty tuple if no matches found else: return () Thanks, Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From erikprice@mac.com Mon Sep 9 13:47:43 2002 From: erikprice@mac.com (Erik Price) Date: Mon, 9 Sep 2002 08:47:43 -0400 Subject: [Tutor] list sorting problem (help!) In-Reply-To: <20020908234107.00522172.thomi@thomi.imail.net.nz> Message-ID: <556798A8-C3F2-11D6-85DA-00039351FE6A@mac.com> On Sunday, September 8, 2002, at 07:41 AM, Thomi Richards wrote: > ok, i have a problem. i have a list, like this: > > ['email me','My programs','Web Design','Web Hosting'] > > and i want to sort them, so i can say something like "the link 'My > programs' should ALWAYS appear at the top". i thought I'd use a > weighting system, so the 'My programs' list item would be weighted 0, > and so always appear at the top. the next one would be '1', then '2', > etc. etc. etc. i could give 'contact me' a weighting of 999, so it > would > always appear at the bottom. > > could i ask some of you python experts to make me a simple procedure > which would do this?? It's for a CGI, which has to load every page, so > the emphasis should be on minimal size and speed.. thanks. If you are using a weighting system, then a Dictionary would seem to be a good choice. I think it was on this list a few months back that one or more of the resident gurus pronounced: "When you find yourself thinking in terms of associations between values, such as name and definition or item and ranking (etc), you probably want a Dictionary." (not an exact quote but something like that) Dictionary lookups are supposedly pretty fast too. Erik -- Erik Price email: erikprice@mac.com jabber: erikprice@jabber.org From rob@uselesspython.com Mon Sep 9 14:14:35 2002 From: rob@uselesspython.com (Rob) Date: Mon, 9 Sep 2002 08:14:35 -0500 Subject: [Tutor] Re: Tutor digest, Vol 1 #1916 - msg 8 In-Reply-To: <002901c257ce$a2372e40$6400a8c0@privat> Message-ID: I feel certain that I replied asking you for more information about what you had tried and had in mind. Rob > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Gil Tucker [ateliermobile] > Sent: Monday, September 09, 2002 1:38 AM > To: tutor@python.org > Subject: [Tutor] Re: Tutor digest, Vol 1 #1916 - msg 8 > > > > Hi, > I wonder why no one replied to my question about > doing art with ascii types? I opnly got a reply about hacking. > If you create stuff with ascii does that mean you are a "HACKER" > in the negative category. Come on! > Gil tucker > > > > > > > > > ----- Original Message ----- > From: > To: > Sent: Sunday, September 08, 2002 4:11 PM > Subject: Tutor digest, Vol 1 #1916 - 14 msgs > > > > Send Tutor mailing list submissions to > > tutor@python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://mail.python.org/mailman/listinfo/tutor > > or, via email, send a message with subject or body 'help' to > > tutor-request@python.org > > > > You can reach the person managing the list at > > tutor-admin@python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Tutor digest..." > > > > > > Today's Topics: > > > > 1. question on lists (Martin Klaffenboeck) > > 2. Re: question on lists (Sean 'Shaleh' Perry) > > 3. Re: The Gang of Four (was: A Book for You and Me) (Magnus Lycka) > > 4. Individual Character Count (Kyle Babich) > > 5. Re: Individual Character Count (Danny Yoo) > > 6. Re: Individual Character Count (Danny Yoo) > > 7. Re: Individual Character Count (Scot W. Stevenson) > > 8. ascii art (Gil Tucker [ateliermobile]) > > 9. Re: Re: Re: Factory classes (etc) (Magnus Lycka) > > 10. Re: Individual Character Count (Magnus Lycka) > > 11. Re: question on lists (Martin Klaffenboeck) > > 12. list sorting problem (help!) (Thomi Richards) > > 13. Re: question on lists (Gregor Lingl) > > 14. Re: Re: Re: Factory classes (etc) (Arthur) > > > > --__--__-- > > > > Message: 1 > > From: Martin Klaffenboeck > > To: tutor@python.org > > Date: 07 Sep 2002 22:49:19 +0200 > > Subject: [Tutor] question on lists > > > > Hello, > > > > I have got a list with 4 columns. This 4 columns are: > > > > string1 string2 id timestamp > > > > So how do I store the data? As a list or as an array: > > > > What I want to do with this data: > > > > Sort the list alphabetically (if possible _not_ case sensitive). > > Add new entries at the right alphabetic position. > > > > Randomize the list (or a copy of it) and sort it back alphabetically > > after modifying the id and the timestamp. > > > > > > Whats the best way to store data for this in python? > > > > Thanks, > > Martin (a newbie) > > > > PS. Sorry for my bad english. > > > > -- > > > > > > > > --__--__-- > > > > Message: 2 > > From: Sean 'Shaleh' Perry > > To: tutor@python.org > > Subject: Re: [Tutor] question on lists > > Date: Sat, 7 Sep 2002 14:33:35 -0700 > > > > On Saturday 07 September 2002 13:49, Martin Klaffenboeck wrote: > > > Hello, > > > > > > I have got a list with 4 columns. This 4 columns are: > > > > > > string1 string2 id timestamp > > > > > > So how do I store the data? As a list or as an array: > > > > > > > a list is for all intents and purposes an array in python. > There are 3=20 > > grouping structures in core python -- tuple, list, dictionary. > A tuple i= > > s a=20 > > list which can not be changed once created a dictionary is > equivalent to=20 > > perl's hash or C++'s map. > > > > > What I want to do with this data: > > > > > > Sort the list alphabetically (if possible _not_ case sensitive). > > > Add new entries at the right alphabetic position. > > > > > > Randomize the list (or a copy of it) and sort it back alphabetically > > > after modifying the id and the timestamp. > > > > > > > > > > list.sort() takes a function to determine sort order. There is > a handy=20 > > function called cmp() which is often used for this. > > > > Your add function is not too hard to write and the random > module may give= > > you=20 > > what you want for the random stuff. > > > > Read through the python docs on lists and the builtin functions > it should= > > get=20 > > you started. > > > > > > --__--__-- > > > > Message: 3 > > Date: Sun, 08 Sep 2002 00:04:53 +0200 > > To: Allyn Weaks , tutor@python.org > > From: Magnus Lycka > > Subject: Re: [Tutor] The Gang of Four (was: A Book for You and Me) > > > > At 19:55 2002-09-06 -0700, Allyn Weaks wrote: > > >On 4/9/02, Scot W. Stevenson wrote: > > > >"We read Knuth so you don't have to" (Tim Peters in the > > > >"Python Cookbook") kind of book. > > > > > >But, but, but, Knuth is quite readable and even funny. If you have a > > >sufficiently warped sense of humor :-). > > > > And plenty of time... I tend to get tired before he > > gets to the point. He is ... different. See also: > > > http://www.thinkware.se/cgi-bin/thinki.cgi/DiscussTheArtOfComputer > Programmin= > > g > > (Look at the end for example of warped humour.) > > > > > > --=20 > > Magnus Lyck=E5, Thinkware AB > > =C4lvans v=E4g 99, SE-907 50 UME=C5 > > tel: 070-582 80 65, fax: 070-612 80 65 > > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > > > > > > --__--__-- > > > > Message: 4 > > Date: Sat, 7 Sep 2002 22:42:45 UT > > From: "Kyle Babich" > > To: "Tutor" > > Subject: [Tutor] Individual Character Count > > > > I'm trying (with little luck) to create a function to count how many > > time an individual character appears in a file. What I have so far I > > have written on patterns I've noticed but it is still extremely buggy > > depending on whether the character being searched for appears as the > > first character in the file, the last, both, or neither. Here it is: > > > > #################### > > def InCharCount(location, character): > > subj =3D file(location, "r") > > body =3D subj.read() > > > > body =3D body.split("\n") > > body =3D string.join(body, "") > > body =3D body.split(character) > > > > last =3D len(body) > > last =3D last - 1 > > > > char =3D 0 > > for each in body: > > char =3D char + 1 > > > > if body[0] in [""]: > > char =3D char - 1 > > > > elif body[last] in [""]: > > char =3D char - 1 > > =20 > > else: > > pass > > > > return char > > #################### > > > > Could someone please help me work the bugs out of this? I have a > > feeling that I'm making this harder than I need to for myself again. > > > > Thank you, > > -- > > Kyle > > > > > > --__--__-- > > > > Message: 5 > > Date: Sat, 7 Sep 2002 16:17:20 -0700 (PDT) > > From: Danny Yoo > > To: Kyle Babich > > cc: Tutor > > Subject: Re: [Tutor] Individual Character Count > > > > > > > > On Sat, 7 Sep 2002, Kyle Babich wrote: > > > > > I'm trying (with little luck) to create a function to count how many > > > time an individual character appears in a file. What I have so far I > > > have written on patterns I've noticed but it is still extremely buggy > > > depending on whether the character being searched for appears as the > > > first character in the file, the last, both, or neither. Here it is: > > > > Hi Kyle, > > > > > > Let's take a look at the program. > > > > > #################### > > > def InCharCount(location, character): > > > subj = file(location, "r") > > > body = subj.read() > > > > > > body = body.split("\n") > > > body = string.join(body, "") > > > body = body.split(character) > > > > Hmmm... Ok, so if our file's contents has something like "aaabbabba", > > then if we wanted to count all the "a"'s, we could split against 'a' and > > see how many pieces come up: > > > > ### > > >>> s = "aaabbabba" > > >>> l = s.split('a') > > >>> l > > ['', '', '', 'bb', 'bb', ''] > > ### > > > > As a result, our list won't contain any more "a"'s once we split by 'a'. > > But it will have a bunch of empty strings, which might look silly. > > > > ... But those empty strings are there for a very good reason: > we should be > > able to rehydrate our string, and reverse the process by using join(): > > > > ### > > >>> 'a'.join(l) > > 'aaabbabba' > > ### > > > > > > Your approach seems reasonable. Once you've split the 'body' up, you > > already have enough information to count how many of that 'character' is > > in there: the number of 'character's should just be the number of > > in-betweens we have in our split-up body: > > > > ['', '', '', 'bb', 'bb', ''] > > > > That is, if we have a list of six elements, the number of "in-between" > > places is just the number of commas we see in our list: 5. > > > > join ==> > > > > '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + '' > > > > So all you need now is to count "in-between" places. I'll let > you figure > > out how to do that. *grin* > > > > > > Your approach works even if our string is initially empty: > > > > ### > > >>> mystring = "" > > >>> l = mystring.split("a") > > >>> l > > [''] > > >>> "a".join(l) > > '' > > ### > > > > because when our split-up list is only one element long, there are no > > "in-between" spots in our list, which is exactly right. > > > > > > > > Let's look at the rest of your code: > > > > > last = len(body) > > > last = last - 1 > > > > > > char = 0 > > > for each in body: > > > char = char + 1 > > > > > > if body[0] in [""]: > > > char = char - 1 > > > > > > elif body[last] in [""]: > > > char = char - 1 > > > > > > else: > > > pass > > > > > > return char > > > > I'd remove this part of the code because it's making the problem too > > complicated. *grin* I don't think you need to do more cases based on > > empty strings. Empty strings in your split-up list are perfectly good: > > you don't need to do additional case analysis on them. > > > > > > Good luck to you! > > > > > > > > --__--__-- > > > > Message: 6 > > Date: Sat, 7 Sep 2002 16:24:58 -0700 (PDT) > > From: Danny Yoo > > To: Kyle Babich > > cc: Tutor > > Subject: Re: [Tutor] Individual Character Count > > > > > > > Your approach seems reasonable. Once you've split the 'body' up, you > > > already have enough information to count how many of that > 'character' is > > > in there: the number of 'character's should just be the number of > > > in-betweens we have in our split-up body: > > > > > > ['', '', '', 'bb', 'bb', ''] > > > > > > That is, if we have a list of six elements, the number of "in-between" > > > places is just the number of commas we see in our list: 5. > > > > > > join ==> > > > > > > '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + '' > > > > > > Hi Kyle, > > > > Doh. I messed up here in the diagram. Forget those pictures above. I > > meant to write: > > > > > > l = ['', '', '', 'bb', 'bb', ''] > > > > 'a'.join(l) ==> > > > > '' + 'a' + '' + 'a' + '' + 'a' + 'bb' + 'a' + 'bb' + 'a' + '' > > > > > > instead, which tries to show better the relationship that > join() has with > > split(). My apologies for being sloppy about this. > > > > > > > > --__--__-- > > > > Message: 7 > > From: "Scot W. Stevenson" > > Organization: Hexenhaus Zepernick > > To: "Kyle Babich" > > Subject: Re: [Tutor] Individual Character Count > > Date: Sun, 8 Sep 2002 02:10:31 +0200 > > Cc: tutor@python.org > > > > Hello Kyle, > > > > > I'm trying (with little luck) to create a function to count how many > > > time an individual character appears in a file. > > > > One thing I have learned in the past few months about Python is > to always > > consult the Module Library before even considering writing new > code. This > > is the "batteries included" principle that people keep talking > about with > > Python, and it works. > > > > In this case, there is actually a "count" method in the string > module. I'm > > assuming you have a new version of Python such as 2.2, where you don't > > have to import the string module anymore (if not, we'll try > again with one > > of the older forms), so you get: > > > > =============================== > > >>> mystring = 'Spam! Spam! Spam!' > > >>> mystring.count('S') > > 3 > > =============================== > > > > Or, even shorter, though it looks strange the first time you see it: > > > > =============================== > > >>> 'Spam! Spam! Spam!'.count('S') > > 3 > > =============================== > > > > So the short version of your function could be: > > > > =============================== > > def InCharCount(location, character): > > subj = file(location, "r") > > body = subj.read() > > subj.close() > > return body.count(character) > > =============================== > > > > [I just love that last line: It sounds like something out of a Python > > version of "Apocalypse Now". And I bet you didn't even see it coming.] > > > > You don't really need the close(), because the Python Elves > will do it for > > you after the program is over, but it is considered good form because it > > shows attention to detail and moral fiber. Note that count() will also > > accept strings (such as 'word') and not only single characters ('w'), so > > you get more fun for same price. > > > > There is one problem with this version, though: read() gives > you the whole > > file as one big string. Usually, this should be fine, but if > you import a > > very, very large file (say, some DNA sequencing data from your secret > > T-Rex project) on a very, very small machine, this might cause trouble. > > > > So you might be better off reading the file line by line after all. You > > could try this (in Python 2.2): > > > > ================================ > > def InCharCount(location, character): > > subj = file(location, "r") > > > > nbr_of_char = 0 > > for line in subj: > > nbr_of_char = nbr_of_char + line.count(character) > > > > return nbr_of_char > > ================================ > > > > The "for line in subj" goes thru the file one line at a time > very quickly, > > and you simply add up all the times the char occurs in each line. This > > takes care of any memory problems you might have with large files, but > > does take longer. > > > > Hope this helps, > > Y, Scot > > > > -- > > Scot W. Stevenson wrote me on Sunday, 8. Sep 2002 in > Zepernick, Germany > > on his happy little Linux system that has been up for 1966 hours > > and has a CPU that is falling asleep at a system load of 0.00. > > > > > > > > --__--__-- > > > > Message: 8 > > Reply-To: "Gil Tucker [ateliermobile]" > > From: "Gil Tucker [ateliermobile]" > > To: > > Date: Sun, 8 Sep 2002 08:16:11 +0200 > > Subject: [Tutor] ascii art > > > > > > > > > > Greetings, > > I am trying to make a program that can > > generate random ascii art forms or designs. I have tried a few > > but they dont work.Any tip or tips. Or warnings? > > gil tucker > > > > > > > > > > --__--__-- > > > > Message: 9 > > Date: Sun, 08 Sep 2002 10:57:15 +0200 > > To: "Arthur" , > > From: Magnus Lycka > > Subject: Re: [Tutor] Re: Re: Factory classes (etc) > > > > At 21:21 2002-09-06 -0400, Arthur wrote: > > >I am not "missing" method overloading in the sense that I feel > Python is > > >somehow deficient by not having it built-in. > > ... > > >But for what I am doing I want to build as much as I can a scripting > > >interface that follows geometric intuitive logic, not > programmers logic. > > >And at the scripting interface level what things are called *is* to the > > >essence > > >of things. If a point is instantiated as an Intersection, if > might be the > > >intersection of a number of other possible elements. It is absolutely > > >redundant > > >both to have the Intersection classes named in accordance with what= > > elements > > >they take as arguments, and then to give them those arguments > - because in > > >fact the arguments themselves define the kind of intersection we are > > >trying to create. > > > > It's really difficult to help you when you are so abstract. > > To be honest, I don't really understand what you are trying > > to do. I think it would be easier if you showed a sample of > > code. > > > > The thing is, that if you have the same name, you should > > basically do the same thing. In Java or C++ you can't to > > the same thing just once if the types or number of params > > differ, but in Python you usually can. > > > > import math, cmath, operator > > > > # This handles any number of ints, floats or complex numbers. > > def RootSumSquared(*args): > > if type(1j) in map(type, args): sqrt =3D cmath.sqrt > > else: sqrt =3D math.sqrt > > return sqrt(reduce(operator.add, map(lambda x: x*x, args))) > > > > RSS =3D RootSumSquared > > > > print RSS(3,4) > > print RSS(0.3, 0.4) > > print RSS(3j, 4) > > print RSS(0.3, 4, 5j) > > print apply(RSS, (1, )*100) > > > > Of cource the simple solution in Java or C++ would be to > > cast all arguments to Complex, but note that I don't use > > the slower complex sqrt unless I have a complex parameter. > > > > Would your overloaded method look very different from one > > another? Maybe you can warp your thinking into making them > > much more similar, and then further into being the same > > thing? > > > > >Given lets say 20 classes which could take anywhere from one to > > >five different sets of arguments, and thats a hell of a lot of > > >if type(arg[0]): > > > xxx > > >else: > > > yyyy > > > > > >to try to get right and keep straight. > > > > I bet it will still be much shorter than Java if you use > > the kind of signature recognition function that I mentioned > > previously... > > > > BTW, would it be possible to write a base class Overloader > > such that: > > > > class X(Overloader): > > def add_int_int(self, a, b): > > return a + b > > def add_string_int(self, a, b): > > return a + str(b) > > > > a =3D X() > > > > a.add(1, 3) =3D> 4 > > a.add('a', 5) =3D> 'a5' > > a.add('d', 'd') =3D> AttributeError > > > > __getattr__ will catch the calls to the undefined > > 'add' method, but I don't know how to figure out > > what the argument list looked like. Can that be > > found from the Python introspection magic? > > > > >>> class X: > > ... def x(self): > > ... print "Hello" > > ... def __getattr__(self, value): > > ... return self.x > > ... > > >>> a =3D X() > > >>> a.hello() > > Hello > > >>> a.bitMap() > > Hello > > > > This is a little bit on the way, it the __getattr__ > > is in the base class. There are seemingly useful > > functions in the inspect module, but they aren't so > > easy to figure out... > > > > > > > > --=20 > > Magnus Lyck=E5, Thinkware AB > > =C4lvans v=E4g 99, SE-907 50 UME=C5 > > tel: 070-582 80 65, fax: 070-612 80 65 > > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > > > > > > --__--__-- > > > > Message: 10 > > Date: Sun, 08 Sep 2002 11:00:26 +0200 > > To: "Scot W. Stevenson" , > > "Kyle Babich" > > From: Magnus Lycka > > Subject: Re: [Tutor] Individual Character Count > > Cc: tutor@python.org > > > > At 02:10 2002-09-08 +0200, Scot W. Stevenson wrote: > > >You don't really need the close(), because the Python Elves > will do it for > > >you after the program is over, but it is considered good form > because it > > >shows attention to detail and moral fiber. > > > > Also, you don't know when the elves will take action > > if you are using Jython. Jython uses the Java garbage > > collection, which is not based on reference counting. > > > > > > --=20 > > Magnus Lyck=E5, Thinkware AB > > =C4lvans v=E4g 99, SE-907 50 UME=C5 > > tel: 070-582 80 65, fax: 070-612 80 65 > > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > > > > > > --__--__-- > > > > Message: 11 > > Subject: Re: [Tutor] question on lists > > From: Martin Klaffenboeck > > To: tutor@python.org > > Date: 08 Sep 2002 13:27:09 +0200 > > > > Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry: > > > > > > > > list.sort() takes a function to determine sort order. There > is a handy > > > function called cmp() which is often used for this. > > > > > > Your add function is not too hard to write and the random > module may give > you > > > what you want for the random stuff. > > > > Ok, that works good with > > > > for x in words: > > if x[0] < newword: > > continue > > if x[0] > newword: > > break > > > > pos = words.index(x) > > > > But what can I do that the words are sorted case insensitive. (No matter > > about upper and lower case letters)? > > > > And how can I tell words.sort() that it should only sort the first > > column of my 4 column list? > > > > Martin > > > > -- > > > > > > > > --__--__-- > > > > Message: 12 > > Date: Sun, 8 Sep 2002 23:41:07 +1200 > > From: Thomi Richards > > To: tutor@python.org > > Subject: [Tutor] list sorting problem (help!) > > > > ok, i have a problem. i have a list, like this: > > > > ['email me','My programs','Web Design','Web Hosting'] > > > > and i want to sort them, so i can say something like "the link 'My > > programs' should ALWAYS appear at the top". i thought I'd use a > > weighting system, so the 'My programs' list item would be weighted 0, > > and so always appear at the top. the next one would be '1', then '2', > > etc. etc. etc. i could give 'contact me' a weighting of 999, so it would > > always appear at the bottom. > > > > could i ask some of you python experts to make me a simple procedure > > which would do this?? It's for a CGI, which has to load every page, so > > the emphasis should be on minimal size and speed.. thanks. > > > > -- > > The software required Win95 or better, so I installed Linux. > > Thomi Richards, > > thomi@imail.net.nz > > > > > > --__--__-- > > > > Message: 13 > > Date: Sun, 08 Sep 2002 14:06:08 +0200 > > From: Gregor Lingl > > To: Martin Klaffenboeck > > CC: tutor@python.org > > Subject: Re: [Tutor] question on lists > > > > Martin Klaffenboeck schrieb: > > > > >Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry: > > > > > > > > > > > >>list.sort() takes a function to determine sort order. There > is a handy > > >>function called cmp() which is often used for this. > > >> > > >>Your add function is not too hard to write and the random > module may give > you > > >>what you want for the random stuff. > > >> > > >> > > > > > >Ok, that works good with > > > > > >for x in words: > > > if x[0] < newword: > > > continue > > > if x[0] > newword: > > > break > > > > > > pos = words.index(x) > > > > > >But what can I do that the words are sorted case insensitive. > (No matter > > >about upper and lower case letters)? > > > > > >>> l = [["Hans",1,2,3], > > ["fritz",4,5,6], > > ["Adam",7,8,9]] > > >>> t = l[:] > > >>> t.sort() > > >>> t > > [['Adam', 7, 8, 9], ['Hans', 1, 2, 3], ['fritz', 4, 5, 6]] > > >>> cmp("Adam","Hans") > > -1 > > >>> cmp("Hans","fritz") > > -1 > > >>> cmp("Hans".upper(),"fritz".upper()) > > 1 > > >>> def vgl(a,b): > > return cmp(a[0].upper(), b[0].upper()) > > > > >>> t = l[:] > > >>> t > > [['Hans', 1, 2, 3], ['fritz', 4, 5, 6], ['Adam', 7, 8, 9]] > > >>> t.sort(vgl) > > >>> t > > [['Adam', 7, 8, 9], ['fritz', 4, 5, 6], ['Hans', 1, 2, 3]] > > >>> > > > > > > > >And how can I tell words.sort() that it should only sort the first > > >column of my 4 column list? > > > > > > > > What do you mean exactly. Do you want the result for the list > > used above to be: > > [['Adam', 1, 2, 3], ['fritz', 4, 5, 6], ['Hans', 7, 8, 9]] > > ??? > > > > Gregor > > > > >Martin > > > > > > > > > > > > > > > > > > > > > > > --__--__-- > > > > Message: 14 > > From: "Arthur" > > To: , "Magnus Lycka" > > Subject: Re: [Tutor] Re: Re: Factory classes (etc) > > Date: Sun, 8 Sep 2002 10:08:53 -0400 > > > > >It's really difficult to help you when you are so abstract. > > >To be honest, I don't really understand what you are trying > > >to do. I think it would be easier if you showed a sample of > > >code. > > > > Well actually at this point I am not so much asking for > specific help. More > > trying to get a better overview of certain OO concepts that are > inherently > > abstract, at least to me. > > > > >The thing is, that if you have the same name, you should > > >basically do the same thing. > > > > Now this seems to be somewhere near the gist of my issue. I > want things to > > have the same name for objects if they end up as objects with the same > > essential attributes. How they get to have those attributes > may be totally > > different. A Chord, for example, might be derived as the > intersection of a > > line and a circle, the intersection of 2 circles, the > intersection of a line > > and a sphere. The key attributes of a Chord are its endpoints. > Depending > > on the the kinds of geometric objects fed in as input, the routines to > > determine those endpoints differ fundamently, but at the end I have the > > precisely same kind of an object - whose essential attributes > are its two > > endpoints. They are precisely the same kinds of objects because > if I give a > > Chord as an argument to the creation of another geometric > object, it is of > > no relevance whether that Chord was orginally created by 2 circles, or a > > sphere and a line. > > > > Now in my mind Java method overloading addresses this need head-on. But > > maybe that is where I am confused and creating confusion - > because though I > > had done some Java, I much prefer Python - and my Java understanding is > > actually much more vague than my Python. > > > > At any rate, the algorythm I keep referring to, would be an absolutely > > generic function to which I could feed lists of acceptable > arguments for a > > Class, and get, as a return, information sufficient to inform the Class > > which specific routine it needs to call to create its essential > attributes - > > in the case of a Chord, its endpoints. > > > > My tutorial need, I guess, is some ratification that my > understanding and > > goals and approach are sensible. > > > > Art > > > > > > > > > > > > > > --__--__-- > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > End of Tutor Digest > > > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From dana@pixelenvy.ca Mon Sep 9 16:27:19 2002 From: dana@pixelenvy.ca (Dana Larose) Date: Mon, 9 Sep 2002 10:27:19 -0500 (CDT) Subject: [Tutor] Scoping question Message-ID: Hello, (Hope this is the right mailing list for this question!) I've been using Python for several months now, and I've run across a scoping issue involving global variables. Consider this program scrap: blah = 0 list = [0] def foo(): blah += 1 def bar(): list[0] += 1 Now, bar would compile and execute fine, but foo is illegal because: 'UnboundLocalError: local variable 'blah' referenced before assignment' Now, I'll guess that my problem is that Python is treating blah as though it were local and the assignment fails because the variable hasn't been created yet. But why doesn't Python search up the scoping chain when the local assignment fails? Also, if foo had been defined as just being: def foo(): print blah It executes just fine and can find blah. Why can it find the global in this context but not the other? And finally, why does the assignment to a list element execute successfully? Dana. dana@pixelenvy.ca From charlie@begeistert.org Mon Sep 9 19:16:37 2002 From: charlie@begeistert.org (Charlie Clark) Date: Mon, 09 Sep 2002 18:16:37 +0000 Subject: [Tutor] re: Scoping question In-Reply-To: <20020909160006.3492.59952.Mailman@mail.python.org> References: <20020909160006.3492.59952.Mailman@mail.python.org> Message-ID: <20020909181637.528.1@gormenghast.1031594840.fake> On 2002-09-09 at 16:00:06 [+0000], you wrote: > (Hope this is the right mailing list for this question!) yes, it is > > I've been using Python for several months now, and I've run across a > scoping issue involving global variables. Consider this program scrap: > > blah =3D 0 > list =3D [0] ^^^^^^ list is a key word in Python for turning other objects into lists so it's a= good idea to use another name, although Python will let you reassign it without complaining. > def foo(): > blah +=3D 1 > > def bar(): > list[0] +=3D 1 > > Now, bar would compile and execute fine, but foo is illegal because: > > 'UnboundLocalError: local variable 'blah' referenced before assignment' You can read 'blah' from the global scope but can't rewrite it. This is for= safety reasons, I think because you have to consider the convenience of rewriting global variables from within functions against the possible damage this can cause when several functions use this variable. Maybe some of the gurus can give more authoritative explanations but I think that is the gist. The way around this is to pass in the variable you want and return it. def foo(blah=3Dblah): return blah+1 > Now, I'll guess that my problem is that Python is treating blah as though > it were local and the assignment fails because the variable hasn't been > created yet. But why doesn't Python search up the scoping chain when the > local assignment fails? Also, if foo had been defined as just being: > > def foo(): > print blah > > It executes just fine and can find blah. Why can it find the global in > this context but not the other? > > And finally, why does the assignment to a list element execute > successfully? It doesn't for me. Maybe it's your choice of keyword. Charlie Clark -- Charlie Clark Helmholtzstr. 20 D=1Asseldorf D- 40215 Tel: +49-211-938-5360 GSM: +49-178-782-6226 From op73418@mail.telepac.pt Mon Sep 9 18:00:48 2002 From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=) Date: Mon, 9 Sep 2002 18:00:48 +0100 Subject: [Tutor] Scoping question References: Message-ID: <001101c25822$71ec2930$641b0dd5@violante> ----- Original Message ----- From: "Dana Larose" To: Sent: Monday, September 09, 2002 4:27 PM Subject: [Tutor] Scoping question > Hello, Hello > > (Hope this is the right mailing list for this question!) > It is. > I've been using Python for several months now, and I've run across a > scoping issue involving global variables. Consider this program scrap: > > blah = 0 > list = [0] > > def foo(): > blah += 1 > > def bar(): > list[0] += 1 > > Now, bar would compile and execute fine, but foo is illegal because: > > 'UnboundLocalError: local variable 'blah' referenced before assignment' > > Now, I'll guess that my problem is that Python is treating blah as though > it were local and the assignment fails because the variable hasn't been > created yet. But why doesn't Python search up the scoping chain when the > local assignment fails? Also, if foo had been defined as just being: > > def foo(): > print blah > > It executes just fine and can find blah. Why can it find the global in > this context but not the other? > > And finally, why does the assignment to a list element execute > successfully? > > Dana. > dana@pixelenvy.ca > The problem is the difference between local variables and global ones. Consider the scrap >>> blah = 1 >>> def foo(): ... print blah ... >>> foo() 1 Here Python knows that I wanted to acess the global blah because blah is a free name inside foo (i.e. there is no assignment to it). Now consider >>> def foo2(): ... blah = 2 ... print blah ... >>> foo2() 2 >>> print blah 1 Here Python has created a *local* blah inside foo, which, when foo is done, is discarded - and that is why print blah gives the global blah, e.g. 1. Now consider >>> def foo3(): ... blah += 1 ... >>> foo3() Traceback (most recent call last): File "", line 1, in ? File "", line 2, in foo3 UnboundLocalError: local variable 'blah' referenced before assignment According to the first case, the name blah is local and you are rebinding it. But blah += 1 is a shortcut for blah = blah + 1 so you are trying to acess something that it is not defined. *IF* you want to acess the global blah inside foo you have to explicitly order Python to do so, e.g. >>> def foo4(): ... global blah ... blah += 1 ... >>> foo4() >>> print blah 2 Hope it helps, Gonçalo Rodrigues From jeff@ccvcorp.com Mon Sep 9 18:32:50 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Mon, 09 Sep 2002 10:32:50 -0700 Subject: [Tutor] Scoping question References: Message-ID: <3D7CDB42.BD0DE21F@ccvcorp.com> Dana Larose wrote: > And finally, why does the assignment to a list element execute > successfully? Gongalo has already pretty much explained your first question, so I'll tackle this one. The difference is that, in the first case, you're re-binding the name, whereas with the list element, you're mutating an existing object. When you execute an assignment like "blah = 5", Python creates an integer object with the value of 5, and binds that to the name blah. It really doesn't matter whether blah had already existed or not -- if there was a previous blah in the same scope, it's pretty much blindly overwritten. (If there was a blah in a containing scope, such as the global blah in your example, then the new local blah masks the global but doesn't overwrite it.) In either case, the object being pointed to by 'blah' is a *new* object, regardless of whether blah existed before or not. Specifically, in the case of "blah += 1", Python will retrieve the value of blah and add one to it, creating a new integer object, and then will point blah at that new object. Things are a bit more complicated in the list case. There, you are not re-binding a name. Let's look at it as "list[0] = list[0] + 1" -- this is essentially equivalent to your code, but a bit easier to break down into steps. Python first finds the value of element 0 of the list, and adds one to that, creating a new integer object just as before. However, you then assign that object to list[0] -- this means that you're not re-binding the name 'list', or creating a new name. You're telling Python that the first slot in this already-existing object is now pointing to something different... but the object itself still exists, and still has the same name attached to it. I find it easier to understand name-binding if you think of names as little Post-it notes that are attached to objects. The statement 'blah = blah + 1' finds the note that says 'blah', creates a new object that's one greater than the original object, and moves the note to that new object. The statement 'list[0] = list[0] + 1', on the other hand, finds the note that says 'list', which is a set of drawers. It opens the first drawer, adds one to the object that it finds there, and puts the new object back in that first drawer, but it does *not* move the sticky note to a new object -- it's still the same set of drawers. Hope that this makes things a bit clearer for you... Jeff Shannon Technician/Programmer Credit International From tzirnsack@web.de Mon Sep 9 19:15:39 2002 From: tzirnsack@web.de (Thomas Zirnsack) Date: Mon, 9 Sep 2002 20:15:39 +0200 Subject: [Tutor] re: Scoping question In-Reply-To: <20020909181637.528.1@gormenghast.1031594840.fake> References: <20020909160006.3492.59952.Mailman@mail.python.org> <20020909181637.528.1@gormenghast.1031594840.fake> Message-ID: <200209092015.39116.tzirnsack@web.de> > > And finally, why does the assignment to a list element execute > > successfully? > > It doesn't for me. Maybe it's your choice of keyword. Well, as I tested: ----->8----- l =3D [0,2,3] def foo() l[0] +=3D 1 foo() print l ----->8----- Will print -> [1,2,3] I assume this works by design and not accidently by choosing a var name like 'list' (python 2.2 here). just my 5 cents, tom From ajs@ix.netcom.com Mon Sep 9 19:39:03 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 9 Sep 2002 14:39:03 -0400 Subject: [Tutor] MyFactoryClass Message-ID: <00bb01c25830$2c13ba00$9865fea9@arthur> Realize that I'm off on my own track (for a change) but I hoped there might be some interest in this, in continuation of the FactoryClass disscussion. Needs a *lot* more testing, but illustrates what I am after. And I think it is a generic enough pattern (should work with built_ins and created classes) to be useful in many circumstances. I'm particularly concerned about the usae of a list.remove(x) on a list over which I am iterating, which I know is a no-no but it doesn't seem to be getting in the way here, and I haven't yet come up with plan 2. # saved as ClassFactory.py from __future__ import generators def method_get(sigs,given_args): def gen(test_sigs): for sig in test_sigs: yield sig def order(sig,given_args): return_args=[] if len(sig) == len(given_args): test_args=list(given_args) for S in sig: for A in test_args: if issubclass(S,A.__class__): test_args.remove(A) return_args.append(A) return return_args try: sig=gen(sigs) for S in sig: final_args = order(S,given_args) if len(final_args) == len(S): raise StopIteration except: return final_args,sigs.index(S) return None, None class ClassFactory(object): def __new__(self,*args): __sigs__ = [[type(2.),type(1),type("A")],[type(1.), type(2.), type("A")]] t,i = method_get(__sigs__,args) if t is None: raise TypeError else: if i==0: return ClassOne(t[0],t[1],t[2]) else: return ClassTwo(t[0],t[1],t[2]) class ClassOne: def __init__(self,f,i,s): self.f = f self.i = i self.s = s def get_args(self): return self.f,self.i,self.s class ClassTwo: def __init__(self,f1,f2,s): self.f1 = f1 self.f2 = f2 self.s = s def get_args(self): return self.f1,self.f2,self.s Now some interactive testing Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> from ClassFactory import ClassFactory >>> t1=ClassFactory(7.,7.,"d") >>> print t1,t1.get_args() (7.0, 7.0, 'd') >>> t2=ClassFactory("e", 9, 4.) >>> print t2,t2.get_args() (4.0, 9, 'e') >>> t3=ClassFactory("e", 2, 2) Traceback (most recent call last): File "", line 1, in ? t3=ClassFactory("e", 2, 2) File "C:\Python22\PyGeo\ClassFactory.py", line 35, in __new__ raise TypeError TypeError From terjeja@hotmail.com Tue Sep 10 18:50:44 2002 From: terjeja@hotmail.com (Terje Johan Abrahamsen) Date: Tue, 10 Sep 2002 17:50:44 +0000 Subject: [Tutor] Finding an URL Message-ID: Is there some easy way to identify an URL in a file? I would like to send some sourcecode in as a file, get Python to read thru it and spit out the URLS. I found a module, robotparser that might work? I didn't really understand exactly what it did. Is there another module that might work, or is my best bet to read line by line, and look for eg www, by moving character by character? Thanks, Terje _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com From sarmxiii@knology.net Tue Sep 10 19:32:50 2002 From: sarmxiii@knology.net (montana) Date: Tue, 10 Sep 2002 13:32:50 -0500 Subject: [Tutor] Here is a completed script for everyones perusal. Message-ID: Hi Everyone- I've attached a script to this email for everyone to check out. Please feel free to make comments or suggestions. This script is a basic new retriever from the FoxNews site. It downloads the articles into easily readable html that I then transfer over to my Zaurus for reading. The script is as follows: #!/usr/bin/env python # A simple Python script that downloads new stories from FoxNews # Sean Armstrong, 06 September 2002 import re import urllib, urllister import sys import os import string import time class Html: def __init__(self, address): self.address = address #connection and parsing def connect(self): sock = urllib.urlopen("http://" + self.address) parser = urllister.URLLister() parser.feed(sock.read()) parser.close() sock.close() parser = parser.urls return parser #search main doc for story links def linkSearch(self): source = self.connect() link = r'''\/story\/0,\d+,6\d+,00\.html''' sch = re.findall(link, string.join(source)) sch = string.join(sch) return sch #compare old source file with new def compare(self): t = time.strftime("%j_%H%M%S_%Y", time.localtime()) folder_contents = os.listdir("/Users/montana/News/Fox/") l = len(folder_contents) for i in folder_contents: if i[-3:] == "fox": oldnews = i newsin = open("/Users/montana/News/Fox/"+oldnews, "rb") newsfile = newsin.read() if self.linkSearch() != newsin: newsin.close() print "News is being updated ..." newsout = open("/Users/montana/News/Fox/news"+t+".fox", "wb") newsout.write(self.linkSearch()) newsout.close() os.remove("/Users/montana/News/Fox/"+oldnews) else: print "Nothing to update. Bye." exit #download desired html links def download(self): sch = string.split(self.linkSearch()) l = len(sch) for i in range(l): file = sch[i] os.system("touch /Users/montana/News/Fox/"+file[7:]) sock = urllib.urlopen("http://www.foxnews.com" + sch[i]) links = sock.read() output = open("/Users/montana/News/Fox/"+file[7:], "wb") output.write(links) output.close() sock.close() class StoryExtractor: def __init__(self, html): self.html = html #search and crop headers from html def cropHeader(self): f = open(self.html, "r") file = f.read() headline = "%s.+%s" % ("", "") headline = re.findall(headline, file) headline = string.join(headline) f.close() return headline #search and crop text from html def crop(self): f = open(self.html, "r") file = f.read() story = "(?sx)%s.+%s" % ("", "") newhtml = re.findall(story, file) newhtml = string.join(newhtml) f.close() # start = "") body = re.sub(middle, " ", newhtml) return body if __name__ == "__main__": start = Html("www.foxnews.com") start.compare() start.download() list = os.listdir("/Users/montana/News/Fox/") l = len(list) t = time.strftime("%j_%H%M%S_%Y", time.localtime()) os.mkdir("/Users/montana/News/Fox/"+t) savedir = "/Users/montana/News/Fox/"+t+"/" count = 0 headera = ''' ''' headerb = ''' ''' footer = ''' ''' for i in range(l): count += 1 item = list[i] if item[-4:] == "html": story = StoryExtractor("/Users/montana/News/Fox/"+item) headline = story.cropHeader() body = story.crop() newstory = headera + "Story" + headerb + "

" + headline + "

" + body + footer number = str(count) outfile = open(savedir+"story"+number+".html", "w") outfile.write(newstory) outfile.close() os.chdir(savedir) newlist = os.listdir(savedir) f = open("index"+t+".html", "a") l = len(newlist) f.write(headera + "FoxNews" + headerb) for i in range(l): item = newlist[i] html = open(item, "r") file = html.read() html.close() headline = "%s(.+)%s" % ("", "") headline = re.findall(headline, file) f.write(''''''+headline[0]+"

") f.write(footer) os.chdir("/Users/montana/News/Fox/") os.system("rm -rf *.html") Let me know of any bugs you come across please. Thanks. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me From dsimco@optonline.net Thu Sep 5 22:12:43 2002 From: dsimco@optonline.net (Dan Simco) Date: Thu, 05 Sep 2002 17:12:43 -0400 Subject: [Tutor] hello Message-ID: <000001c256d6$a28b6670$6701a8c0@ibmav8jk6vcief> This is a multi-part message in MIME format. --Boundary_(ID_nqbf1KfhATiX33oBTwQ/iw) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Hello i am trying to learn programming and i am wondering if it is possible to program videogames using python. Please respond. Thank you very much. Dan Simco --Boundary_(ID_nqbf1KfhATiX33oBTwQ/iw) Content-type: text/html; charset=iso-8859-1 Content-transfer-encoding: 7BIT
Hello i am trying to learn programming and i am wondering if it is possible to program videogames using python. Please respond. Thank you very much.
 
                                                    Dan Simco
--Boundary_(ID_nqbf1KfhATiX33oBTwQ/iw)-- From mustard1@optonline.net Sun Sep 8 17:20:27 2002 From: mustard1@optonline.net (Eric S.) Date: Sun, 08 Sep 2002 12:20:27 -0400 Subject: [Tutor] python lessons Message-ID: <003601c25753$a4918ee0$d8a52e18@computername> This is a multi-part message in MIME format. --Boundary_(ID_pM3mFdIiRlHPaeugpfT2Kg) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Hi, my name is Eric and I'm 15 years old and I was wondering if there were any python or just programming classes in my area. I live in westchester NY. thanks, Eric --Boundary_(ID_pM3mFdIiRlHPaeugpfT2Kg) Content-type: text/html; charset=iso-8859-1 Content-transfer-encoding: 7BIT
Hi, my name is Eric and I'm 15 years old and I was wondering if there were any python or just programming classes in my area. I live in westchester NY.
 
thanks,
Eric
--Boundary_(ID_pM3mFdIiRlHPaeugpfT2Kg)-- From mcherm@destiny.com Mon Sep 9 17:49:17 2002 From: mcherm@destiny.com (Michael Chermside) Date: Mon, 09 Sep 2002 12:49:17 -0400 Subject: [Tutor] Re: streamlining a return statement References: <3C8F6165-C3F1-11D6-85DA-00039351FE6A@mac.com> Message-ID: <3D7CD10D.7060806@destiny.com> Erik Price wrote: > I have a function in a chunk of code... > > It works fine. But I'm wondering whether returning an empty tuple is a > good idea... > > Can someone criticize my code please? Sure. But it's just my opinion... don't be afraid to trust your own instincts too: they seem pretty good. > Specifically the "return" > statements -- the first part of the function is just the way I want it. > Also, using "if matchobj" works but is that the preferred way to detect > whether a re.search() was successful? Yes, it is. > (Testing for successful > assignment, "if matchobj = re.search()", which I admit is a Perlish way > of looking at it, doesn't work.) > > def atts_detect(line): > """searches a line for a tag with attributes and > returns a tuple of info about the tag if attributes are found""" > > import re > > # this regex ensures that the tag the kind we want > needle = r'(\s*)<(\w+)(\s+[-\w]+=[\'"].+[\'"])+(\s*/?>)' > regex = re.compile(needle) > > # a match object is only returned if search is successful > matchobj = regex.search(line) > if matchobj: return matchobj.groups() > # return an empty tuple if no matches found > else: return () I can see two approaches here, both of which are pretty good style. The first approach would be to use your code as is... making two changes. The first (and perhaps this is already how you do it) would be to use the truth value of the tuple returned as the indicator of whether a tag was found or not. So I mean something like this: def outer_program(line): atts = atts_detect(line): if atts: handle_a_tag( atts[0], atts[1], atts[2] ) else: handle_no_tag() The other approach would be, as you suggest, to use an exception: def outer_program(line): try: atts = atts_detect(line) handle_a_tag( atts[0], atts[1], atts[2] ) except NoTagFoundException: handle_no_tag() It's probably fairly easy to get a big debate going about the advantages of each, but I think the best answer has to do with how you think about the results. If there is supposed to be a tag on each line, and a missing tag indicates that the file is corrupt, then the exception approach definitely makes more sense. If you expect no tag found to be fairly common, then some people would say "never use an exception to handle a non-error condition". (I am not one of them -- the overhead of exceptions is larger than most normal statements, but not overwhelming in Python, even "for" loops use exceptions for termination.) But in EITHER case, there's one thing missing. Your docstring should specify what happens in the unusual case. Go with one of these: """Searches a line for a tag with attributes. Returns a 4-element tuple (, , , ) if found, and an empty tuple if not found.""" """Finds the first tag with attributes on the line. Returns a 4-element tuple (, , , ). If no tag with attributes is found, it raises NoTagFoundException.""" Notice that my documentation of the tuple that is returned matches what is implemented in the code, but does NOT match your description. Was that a bug? -- Michael Chermside From Midnit3408@aol.com Tue Sep 10 07:08:57 2002 From: Midnit3408@aol.com (Midnit3408@aol.com) Date: Tue, 10 Sep 2002 02:08:57 EDT Subject: [Tutor] Question Message-ID: <12e.1739605c.2aaee679@aol.com> --part1_12e.1739605c.2aaee679_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Sir or Madam, I was curious about the use of Python. Ive been wanting to learn how to write a program similar to a search engine That would be capable of pulling up and opening documents within itself. Is that possible with Python or should I try another program for that use? If so which one would you suggest? Thank you for your time. Sincerly, Joshua --part1_12e.1739605c.2aaee679_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit Sir or Madam,

I was curious about the use of Python. Ive been wanting to learn how to write a program similar to a search engine That would be capable of pulling up and opening documents within itself. Is that possible with Python or should I try another program for that use? If so which one would you suggest?

Thank you for your time.

Sincerly,
Joshua
--part1_12e.1739605c.2aaee679_boundary-- From mcherm@destiny.com Tue Sep 10 18:12:46 2002 From: mcherm@destiny.com (Michael Chermside) Date: Tue, 10 Sep 2002 13:12:46 -0400 Subject: [Tutor] Re: Perl to Python code migration References: <45520544-C151-11D6-BDA3-00039351FE6A@mac.com> <3D78DE5A.DEF1711C@ccvcorp.com> <200209061004.21469.shalehperry@attbi.com> Message-ID: Sean 'Shaleh' Perry wrote: > I wonder how hard it would be to add something like perl's delimiter hack to > the file interface. > > fp = open(my_file) > fp.set_record_delimiter('(ID 1)') > for line in fp.xreadlines(): > ....... > > Which gives you the equivalent of the perl code. Rather than adding it to the built-in "file" object, build it (along with appropriate buffering) into the "DelimitedFile" object you create by subclassing file. Isn't it nice to be able to subclass built-in objects? -- Michael Chermside WARNING: Untested and almost certainly incorrect psudocode follows: class DelimitedFile( file ): __slots__ = (delimiter, read_chunk_size, buffer) def readline(self): while not self.buffer.contains(delimiter): buffer += self.read(self.read_chunk_size) result, self.buffer = buffer.split(delimiter, 1) return result def set_record_delimiter(self, delimiter): self.delimiter = delimiter From dyoo@acoma.Stanford.EDU Tue Sep 10 21:56:32 2002 From: dyoo@acoma.Stanford.EDU (Danny Yoo) Date: Tue, 10 Sep 2002 13:56:32 -0700 (PDT) Subject: [Tutor] re: Finding an URL Message-ID: Hi Terje, This parsing of URL's in text seems like something that is reinvented quite a bit. Perhaps it might be nice for someone to do a review of the code out there and package it nicely into the Standard library? The MoinMoin project, I remember, did a bunch of automatic highlighting of URLs in any page, using its parser.wiki.Parser module: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/moin/MoinMoin/parser/wiki.py?rev=1.91&content-type=text/vnd.viewcvs-markup Mailman, too, has its own regular expression for urls, though I can't remember exactly where it is (I think it's somewhere in its "Pipermail" archive displayer). I ported over Tom Christiansen's URL regular expression here: http://mail.python.org/pipermail/tutor/2002-February/012481.html Best of wishes to you! From dyoo@acoma.Stanford.EDU Tue Sep 10 22:30:46 2002 From: dyoo@acoma.Stanford.EDU (Danny Yoo) Date: Tue, 10 Sep 2002 14:30:46 -0700 (PDT) Subject: [Tutor] re: Finding an URL In-Reply-To: Message-ID: On Tue, 10 Sep 2002, Danny Yoo wrote: > Hi Terje, > > This parsing of URL's in text seems like something that is reinvented > quite a bit. Perhaps it might be nice for someone to do a review of the > code out there and package it nicely into the Standard library? > [some text cut] > > I ported over Tom Christiansen's URL regular expression here: > > http://mail.python.org/pipermail/tutor/2002-February/012481.html Hmmm... I actually tried a silly test on the original program: ### >>> url_re.findall('http://python.org...') [('http://python.org...', 'http')] ### and that's not right! It should realize that the trailing dots aren't a part of the url. So I took a closer look at tchrist's original Perl regular expression, and it appears to have a bug. Doh. Serves me right for directly porting the regex... *grin* The following version should work better for you: ### """parseUrls.py A regular expression that detects HTTP urls. Danny Yoo (dyoo@hkn.eecs.berkeley.edu) This is only a small sample of tchrist's very nice tutorial on regular expressions. See: http://www.perl.com/doc/FMTEYEWTK/regexps.html for more details. Note: this properly detects strings like "http://python.org.", with a period at the end of the string.""" import re def grabUrls(text): """Given a text string, returns all the urls we can find in it.""" return url_re.findall(text) urls = '(?: %s)' % '|'.join("""http telnet gopher file wais ftp""".split()) ltrs = r'\w' gunk = r'/#~:.?+=&%@!\-' punc = r'.:?\-' any = "%(ltrs)s%(gunk)s%(punc)s" % { 'ltrs' : ltrs, 'gunk' : gunk, 'punc' : punc } url = r""" \b # start at word boundary %(urls)s : # need resource and a colon [%(any)s] +? # followed by one or more # of any valid character, but # be conservative and take only # what you need to.... (?= # look-ahead non-consumptive assertion [%(punc)s]* # either 0 or more punctuation (?: [^%(any)s] # followed by a non-url char | # or end of the string $ ) ) """ % {'urls' : urls, 'any' : any, 'punc' : punc } url_re = re.compile(url, re.VERBOSE | re.MULTILINE) def _test(): sample = """hello world, this is an url: http://python.org. Can you find it?""" match = url_re.search(sample) print "Here's what we found: '%s'" % match.group(0) if __name__ == '__main__': _test() ### Here's a small demonstration on one way to use this code: ### >>> grabUrls(urllib.urlopen('http://python.org').read())[:5] ['http://ht2html.sf.net', 'http://sourceforge.net/bugs/?group_id=5470', 'http://sourceforge.net/patch/?group_id=5470', 'http://sourceforge.net/cvs/?group_id=5470', 'http://www.jython.org/'] >>> grabUrls("this is a test") [] >>> grabUrls("http://python.org.....") ['http://python.org'] >>> grabUrls("In a hole in the ground there lived a hobbit. " ... + "See: http://www.coldal.org/hobbit.htm") ['http://www.coldal.org/hobbit.htm'] ### Hope this helps! From sarmxiii@knology.net Wed Sep 11 00:02:06 2002 From: sarmxiii@knology.net (montana) Date: Tue, 10 Sep 2002 18:02:06 -0500 Subject: [Tutor] Question In-Reply-To: <12e.1739605c.2aaee679@aol.com> Message-ID: <5403B18A-C511-11D6-8995-00039315F4DA@knology.net> --Apple-Mail-6--295364309 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Yes. Python is a very versatile scripting language. Please check www.python.org to get you started. Good Luck. SA On Tuesday, September 10, 2002, at 01:08 AM, Midnit3408@aol.com wrote: > Sir or Madam, > > I was curious about the use of Python. Ive been wanting to learn how > to write a program similar to a search engine That would be capable of > pulling up and opening documents within itself. Is that possible with > Python or should I try another program for that use? If so which one > would you suggest? > > Thank you for your time. > > Sincerly, > Joshua > > "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me --Apple-Mail-6--295364309 Content-Transfer-Encoding: 7bit Content-Type: text/enriched; charset=US-ASCII Yes. Python is a very versatile scripting language. Please check www.python.org to get you started. Good Luck. SA On Tuesday, September 10, 2002, at 01:08 AM, Midnit3408@aol.com wrote: Comic Sans MS0000,0000,FFFFSir or Madam, I was curious about the use of Python. Ive been wanting to learn how to write a program similar to a search engine That would be capable of pulling up and opening documents within itself. Is that possible with Python or should I try another program for that use? If so which one would you suggest? Thank you for your time. Sincerly, Joshua "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me --Apple-Mail-6--295364309-- From sarmstrong@shearwatercorp.com Wed Sep 11 00:03:41 2002 From: sarmstrong@shearwatercorp.com (SA) Date: Tue, 10 Sep 2002 18:03:41 -0500 Subject: [Tutor] hello In-Reply-To: <000001c256d6$a28b6670$6701a8c0@ibmav8jk6vcief> Message-ID: <8CAC4B70-C511-11D6-8995-00039315F4DA@shearwatercorp.com> --Apple-Mail-8--295269252 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; format=flowed Yes. Check out pygame. Good Luck. SA On Thursday, September 5, 2002, at 04:12 PM, Dan Simco wrote: > Hello i am trying to learn=A0programming and i am wondering if it is=20= > possible to program videogames using python. Please respond. Thank you=20= > very much. > =A0 > =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Dan Simco > "I can do everything on my Mac I used to do on my PC, plus alot more=20 ..." --Me --Apple-Mail-8--295269252 Content-Transfer-Encoding: quoted-printable Content-Type: text/enriched; charset=ISO-8859-1 Yes. Check out pygame. Good Luck. SA On Thursday, September 5, 2002, at 04:12 PM, Dan Simco wrote: ArialHello i am trying to learn=A0programming and i am wondering if it is possible to program videogames using python. Please respond. Thank you very = much. =A0 Arial=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Dan = Simco "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me --Apple-Mail-8--295269252-- From sarmstrong@shearwatercorp.com Wed Sep 11 00:05:27 2002 From: sarmstrong@shearwatercorp.com (SA) Date: Tue, 10 Sep 2002 18:05:27 -0500 Subject: [Tutor] python lessons In-Reply-To: <003601c25753$a4918ee0$d8a52e18@computername> Message-ID: --Apple-Mail-10--295163463 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; format=flowed I do not know about your area. But check out www.python.org to get you=20= started. If you feel the need to spend some money, go grab the book=20 "Learning Python". It is a great book for begining programmers that=20 teaches the fundamentals of Python. Good Luck. SA On Sunday, September 8, 2002, at 11:20 AM, Eric S. wrote: > Hi, my name is Eric and I'm 15 years old and I was wondering if there=20= > were any python or just programming classes in my area. I live in=20 > westchester NY. > =A0 > thanks, > Eric > "I can do everything on my Mac I used to do on my PC, plus alot more=20 ..." --Me --Apple-Mail-10--295163463 Content-Transfer-Encoding: quoted-printable Content-Type: text/enriched; charset=ISO-8859-1 I do not know about your area. But check out www.python.org to get you started. If you feel the need to spend some money, go grab the book "Learning Python". It is a great book for begining programmers that teaches the fundamentals of Python. Good Luck. SA On Sunday, September 8, 2002, at 11:20 AM, Eric S. wrote: ArialHi, my name is Eric and I'm 15 years old and I was wondering if there were any python or just programming classes in my area. I live in westchester = NY. =A0 Arialthanks, ArialEric "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me --Apple-Mail-10--295163463-- From printers@sendme.cz Wed Sep 11 14:14:30 2002 From: printers@sendme.cz (A) Date: Wed, 11 Sep 2002 15:14:30 +0200 Subject: [Tutor] Re: Paradox table Message-ID: <3D7F5DD6.8814.1363983@localhost> Hi, Is there a module for reading Paradox database (.DB) files with Python? I need to run the script under Linux, so I can not use ODBC. Any suggestion would be appreciated Thanks for help Ladislav I look forward to hearing from you soon. Best regards, Ladislav Blazek( Mr.) BMA TRADING Ltd. email: export@sendme.cz email2: export@bmatrading.com Fax:/Tel +420 506 447921 Tel:+420 506 447920, +420 602 849309 From jamesallen@softhome.net Wed Sep 11 19:13:36 2002 From: jamesallen@softhome.net (James Allen) Date: Wed, 11 Sep 2002 13:13:36 -0500 Subject: [Tutor] python lessons In-Reply-To: References: Message-ID: Since you are a beginner to programming I would recommend: http://www.ibiblio.org/obp/thinkCS.php/ How to Think Like a Computer Scientist Teaches programming using python or their are Java or C++ versions available. http://www.freenetpages.co.uk/hp/alan.gauld/ Learning to Program Using Python Both available to download. James On Tuesday 10 September 2002 18:05, you wrote: > I do not know about your area. But check out www.python.org to get you > started. If you feel the need to spend some money, go grab the book > "Learning Python". It is a great book for begining programmers that > teaches the fundamentals of Python. > On Sunday, September 8, 2002, at 11:20 AM, Eric S. wrote: > > Hi, my name is Eric and I'm 15 years old and I was wondering if there > > were any python or just programming classes in my area. I live in > > westchester NY. From dman@dman.ddts.net Thu Sep 12 15:35:32 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Thu, 12 Sep 2002 10:35:32 -0400 Subject: [Tutor] Paradox table In-Reply-To: <3D7F5DD6.8814.1363983@localhost> References: <3D7F5DD6.8814.1363983@localhost> Message-ID: <20020912143532.GA17566@dman.ddts.net> --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 11, 2002 at 03:14:30PM +0200, A wrote: | Hi, | Is there a module for reading Paradox database (.DB) files with Python? | I need to run the script under Linux, so I can not use ODBC. | Any suggestion would be appreciated One way to access the data is to export it from paradox in CSV format. CSV is an open standard and several (python) parsers exist for it. However, using this method won't allow you to easily access the data from both paradox and from your script, instead you would need to re-export it every time you modified it in paradox and you would not be able to modify it using your script. If you can, it would probably be easiest to migrate to a different db such as postgresql. Postgres databases are much more accessible than paradox is (at least with the paradox version I've seen, 3.5). -D --=20 Dishonest money dwindles away, but he who gathers money little by little makes it grow. Proverbs 13:11 =20 http://dman.ddts.net/~dman/ --NzB8fVQJ5HfG6fxh Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2ApjQACgkQO8l8XBKTpRTx3gCffJpmKdlJQRAY9CGoEcoF5SAq eEoAmwTscJwQ242oQzdIrTWij2gaADES =UTTW -----END PGP SIGNATURE----- --NzB8fVQJ5HfG6fxh-- From sarmxiii@knology.net Thu Sep 12 17:43:24 2002 From: sarmxiii@knology.net (montana) Date: Thu, 12 Sep 2002 11:43:24 -0500 Subject: [Tutor] Paradox table In-Reply-To: <20020912143532.GA17566@dman.ddts.net> Message-ID: Is there a good example on how to use a CSV parser in Python? So you have this comma seperated file, does the CSV parser break data up into groups based upon where they are positioned in the file or does it just generate a list of data or both? Is there any good sites out there that deal with CSV parsing and python that have some good examples or can someone on this list give some? Thanks. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me On Thursday, September 12, 2002, at 09:35 AM, Derrick 'dman' Hudson wrote: > On Wed, Sep 11, 2002 at 03:14:30PM +0200, A wrote: > | Hi, > | Is there a module for reading Paradox database (.DB) files with > Python? > | I need to run the script under Linux, so I can not use ODBC. > | Any suggestion would be appreciated > > One way to access the data is to export it from paradox in CSV format. > CSV is an open standard and several (python) parsers exist for it. > However, using this method won't allow you to easily access the data > from both paradox and from your script, instead you would need to > re-export it every time you modified it in paradox and you would not > be able to modify it using your script. If you can, it would probably > be easiest to migrate to a different db such as postgresql. Postgres > databases are much more accessible than paradox is (at least with the > paradox version I've seen, 3.5). > > -D > > -- > Dishonest money dwindles away, > but he who gathers money little by little makes it grow. > Proverbs 13:11 > > http://dman.ddts.net/~dman/ > From dyoo@CSUA.Berkeley.EDU Thu Sep 12 17:54:00 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Thu, 12 Sep 2002 09:54:00 -0700 (PDT) Subject: [Tutor] Paradox table In-Reply-To: Message-ID: <20020912095200.Q61947-100000@soda.CSUA.Berkeley.EDU> On Thu, 12 Sep 2002, montana wrote: > Is there a good example on how to use a CSV parser in Python? So you > have this comma seperated file, does the CSV parser break data up into > groups based upon where they are positioned in the file or does it just > generate a list of data or both? > > Is there any good sites out there that deal with CSV parsing and python > that have some good examples or can someone on this list give some? [I'm taking python-list out of CC] Yes, there's a nice CSV module that the Object Craft folks have worked on: http://www.object-craft.com.au/projects/csv/ The parser returns a list of elements, and acts almost like string.split(), but smarter. Good luck! From charlie@begeistert.org Thu Sep 12 23:13:51 2002 From: charlie@begeistert.org (Charlie Clark) Date: Thu, 12 Sep 2002 22:13:51 +0000 Subject: [Tutor] Paradox (DB) & Python In-Reply-To: <20020912160004.2283.36690.Mailman@mail.python.org> References: <20020912160004.2283.36690.Mailman@mail.python.org> Message-ID: <20020912221351.531.2@gormenghast.1031868492.fake> On 2002-09-12 at 16:00:04 [+0000], you wrote: > On Wed, Sep 11, 2002 at 03:14:30PM +0200, A wrote: > | Hi, > | Is there a module for reading Paradox database (.DB) files with Python= ? > | I need to run the script under Linux, so I can not use ODBC. > | Any suggestion would be appreciated Rumour would have it that there is an ODBC driver for Linux. mxODBC certainly works. Charlie -- Charlie Clark Helmholtzstr. 20 D=1Asseldorf D- 40215 Tel: +49-211-938-5360 GSM: +49-178-782-6226 From jccoellar@yahoo.es Fri Sep 13 00:13:07 2002 From: jccoellar@yahoo.es (=?iso-8859-1?q?Juan=20Carlos=20Coellar?=) Date: Fri, 13 Sep 2002 01:13:07 +0200 (CEST) Subject: [Tutor] need info Message-ID: <20020912231307.52594.qmail@web12705.mail.yahoo.com> hello all! i am brand new to this mailing list i don’t know none about PYTHON I enjoy build a simple project electronics from computer ibm ,through the printer port lpt1 from BASIC , it’s outdate language ......ugh! This is a simple function in BASIC: OUT& h378, # ?How i do ,to control through printer port (IBM or compatible PC) from PYTHON ?Is it possible that replace the sentences : OUT&h378,# any suggestion would be appreciate Thanks in advance sincerely JCCN _______________________________________________________________ Yahoo! Messenger Nueva versión: Webcam, voz, y mucho más ¡Gratis! Descárgalo ya desde http://messenger.yahoo.es From dyoo@CSUA.Berkeley.EDU Fri Sep 13 00:34:54 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Thu, 12 Sep 2002 16:34:54 -0700 (PDT) Subject: [Tutor] need info In-Reply-To: <20020912231307.52594.qmail@web12705.mail.yahoo.com> Message-ID: <20020912163036.S39038-100000@soda.CSUA.Berkeley.EDU> On Fri, 13 Sep 2002, [iso-8859-1] Juan Carlos Coellar wrote: > > hello all! i am brand new to this mailing list > i don=92t know none about PYTHON > I enjoy build a simple project electronics from > computer ibm ,through the printer port lpt1 > from BASIC , it=92s outdate language ......ugh! > This is a simple function in BASIC: > OUT& h378, # > ?How i do ,to control through printer port > (IBM or compatible PC) from PYTHON > ?Is it possible that replace the sentences : > OUT&h378,# > any suggestion would be appreciate Hello! There is a module called "winioport" that you can probably use to control your printer port. You can find the module here: http://www.geocities.com/dinceraydin/python/indexeng.html This windows module should allow you to control the printer port. I'm not on a Windows machine at the moment, so I can't test this module out yet, but other people on the list might be able to help you. If you're running Linux, the Linux Gazette magazine wrote an example about controlling the printer port with Python: http://www.linuxgazette.com/issue49/pramode.html Please feel free to ask more questions. Good luck to you! From slime@vsnl.net Thu Sep 12 11:00:29 2002 From: slime@vsnl.net (Prahlad Vaidyanathan) Date: Thu, 12 Sep 2002 15:30:29 +0530 Subject: [Tutor] Re: Here is a completed script for everyones perusal. In-Reply-To: References: Message-ID: <20020912100028.GA862@localhost.localdomain> Hi, Just noticed one little thing ... On Tue, 10 Sep 2002 montana spewed into the ether: [-- snip --] > import urllib, urllister Is urllister part of the standard library ? I don't seem to have it on my setup here. pv. -- Prahlad Vaidyanathan Is a tattoo real, like a curb or a battleship? Or are we suffering in Safeway? From slime@vsnl.net Fri Sep 13 07:23:19 2002 From: slime@vsnl.net (Prahlad Vaidyanathan) Date: Fri, 13 Sep 2002 11:53:19 +0530 Subject: [Tutor] more precision/predictability in calculations Message-ID: <20020913062319.GA983@localhost.localdomain> Hi, [ Note: This mail contains quite a bit of Math, so if you don't like math, please ignore it ] I have just written some code that looks like this : """ def diff2 (fn, var, x0, y0, epsilon=0.0001) : """ Given a 2 variable function, differentiates it partially w.r.t 'var', at the point (x0, y0) """ if var == "x" : return (fn(x0+epsilon, y0) - fn(x0, y0))/epsilon elif var == "y" : return (fn(x0, y0+epsilon) - fn(x0, y0))/epsilon def satisfies_cr_eqns (u, v, z0) : """Checks if the 2 real-valued functions 'u' and 'v' satisfy the Cauchy-Reimann equations at z0""" ux = diff2(u, "x", z0.real, z0.imag) ##; print ux uy = diff2(u, "y", z0.real, z0.imag) ##; print uy vx = diff2(v, "x", z0.real, z0.imag) ##; print vx vy = diff2(v, "y", z0.real, z0.imag) ##; print vy ## return ux == vy and uy == -vx return (ux - vy) < pow(10,-3) and (uy + vx) < pow(10, -3) """ Now, I construct 2 functions like so : """ def f1(a, b) : return pow(math.e, a) * math.cos(b) def f2(a, b) : return pow(math.e, a) * math.sin(b) """ These 2 functions do satisfy the c-r equations for any point in the complex plane. But, when I run satisfy_cr_eqns(), it returns true for some points and false for others. I presumed that the higher the value of the complex number, the lower the precision would be. But, the function turns out to be true for complex(99,99), and false for complex(3,3) !! I know this may be asking too much of Python, but is there any way I can make these calculations more precise ? or, at least more predictable ? :-) Do let me know. Thanks. pv. -- Prahlad Vaidyanathan If all the world's a stage, I want to operate the trap door. -- Paul Beatty From dyoo@CSUA.Berkeley.EDU Fri Sep 13 08:36:48 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Fri, 13 Sep 2002 00:36:48 -0700 (PDT) Subject: [Tutor] more precision/predictability in calculations [gmpy module] In-Reply-To: <20020913062319.GA983@localhost.localdomain> Message-ID: <20020913000715.D89094-100000@soda.CSUA.Berkeley.EDU> On Fri, 13 Sep 2002, Prahlad Vaidyanathan wrote: > def diff2 (fn, var, x0, y0, epsilon=0.0001) : > """ Given a 2 variable function, differentiates it partially > w.r.t 'var', at the point (x0, y0) """ > if var == "x" : > return (fn(x0+epsilon, y0) - fn(x0, y0))/epsilon > elif var == "y" : > return (fn(x0, y0+epsilon) - fn(x0, y0))/epsilon > > def satisfies_cr_eqns (u, v, z0) : > """Checks if the 2 real-valued functions 'u' and 'v' satisfy > the Cauchy-Reimann equations at z0""" > ux = diff2(u, "x", z0.real, z0.imag) ##; print ux > uy = diff2(u, "y", z0.real, z0.imag) ##; print uy > vx = diff2(v, "x", z0.real, z0.imag) ##; print vx > vy = diff2(v, "y", z0.real, z0.imag) ##; print vy > ## return ux == vy and uy == -vx > return (ux - vy) < pow(10,-3) and (uy + vx) < pow(10, -3) > > """ > > Now, I construct 2 functions like so : > > """ > > def f1(a, b) : > return pow(math.e, a) * math.cos(b) > > def f2(a, b) : > return pow(math.e, a) * math.sin(b) > > """ > > These 2 functions do satisfy the c-r equations for any point in the > complex plane. ?!? Waaaa.... *grin* > But, when I run satisfy_cr_eqns(), it returns true for some points and > false for others. I presumed that the higher the value of the complex > number, the lower the precision would be. But, the function turns out to > be true for complex(99,99), and false for complex(3,3) !! > > I know this may be asking too much of Python, but is there any way I > can make these calculations more precise ? or, at least more predictable > ? :-) Python uses floating point to represent these numbers, so that's where we're losing precision. We can probably do a bit better by using the 'gmp' General MultiPrecision library --- it's made to handle hardcore arbitrary precision arithmetic: http://www.swox.com/gmp/ There's are a few Python wrappers around portions of the GMP library, and we can find a good one in the 'gmpy' module: http://gmpy.sourceforge.net/ The gmpy module provides a function called 'mpf()', which constructs multi-precision floats. The documentation is a little terse, so here's a small example: ### >>> import gmpy >>> mpf = gmpy.mpf >>> mpf('3.1415926') mpf('3.1415926e0') >>> pi = mpf('3.1415926') >>> pi / mpf(10**100000) mpf('3.1415926e-100000') ### The last example is somewhat neat, considering that it doesn't work (at least, not easily) in standard Python: ### >>> 3.1415926 / 10**100000 Traceback (most recent call last): File "", line 1, in ? OverflowError: long int too large to convert to float ### The gmpy module should come with a test file called 'gmpy_test_08_mpf.py' that showcases the sort of precision we can expect from these numbers. Best of wishes to you! From Morne" This is a multi-part message in MIME format. ------=_NextPart_000_0018_01C25B11.BC5BCE20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi=20 Can you help me=20 I need the code to print out the info in any .txt file im using python = 2.2 with the IDLE (GUI) import string def getStuff(file): info =3D open(file,'r') infolines =3D info.readlines() =20 avg =3D wordcount/len(infolines) print"Average words per line %f" %(avg) =20 file =3D raw_input("Enter filename:") getStuff(file) Thanx =20 ------=_NextPart_000_0018_01C25B11.BC5BCE20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi
Can you help me
I need the code to print out the info = in any .txt=20 file im using python 2.2 with the IDLE (GUI)
 
 
 
import string
def = getStuff(file):
 info=20 =3D open(file,'r')
 infolines =3D = info.readlines()
 
 avg =3D=20 wordcount/len(infolines)
       =20 print"Average words per line %f" %(avg)
  
file =3D=20 raw_input("Enter filename:")
getStuff(file)
 
 
Thanx

  
 
 
------=_NextPart_000_0018_01C25B11.BC5BCE20-- From erikprice@mac.com Fri Sep 13 14:24:38 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 13 Sep 2002 09:24:38 -0400 Subject: [Tutor] .txt file out put In-Reply-To: <001b01c25b00$fc5bd6c0$2500a8c0@maxitec.co.za> Message-ID: <27065279-C71C-11D6-8F52-00039351FE6A@mac.com> On Friday, September 13, 2002, at 04:38 AM, Morne wrote: > I need the code to print out the info in any .txt file im using python=20= > 2.2 with the IDLE (GUI) > =A0 > =A0 > =A0 > import string > def getStuff(file): > =A0info =3D open(file,'r') > =A0infolines =3D info.readlines() > =A0 > =A0avg =3D wordcount/len(infolines) > =A0=A0=A0=A0=A0=A0=A0 print"Average words per line %f" %(avg) > =A0=A0 > file =3D raw_input("Enter filename:") > getStuff(file) If you're using Python2.2, I don't think you have to import the String=20= module. You can, if you prefer to use functions, but Python2.2 treats=20= string literals as Objects with the String methods. So whereas before=20= you might use "split(string, sep)", in Python2.2, you can use=20 "string.split(sep)". So the first thing that you have done (and it's a good idea) is defined=20= a function to open your file and read the lines in the file. Here's=20 how I would do that a little differently: def getStuff(file): # initialize some variables wordcount =3D 0 linecount =3D 0 words_per_line_list =3D [] # get the file's contents filehandle =3D open(file, 'r') infolines =3D filehandle.readlines() linecount =3D len(infolines) filehandle.close() # loop through the "infolines" list to get the wordcount of each line for line in infolines: num_words =3D len(line.split(' ')) words_per_line_list.append(num_words) # do some math to determine the average words per line for words in words_per_line_list: wordcount =3D words + wordcount avg =3D wordcount / len(words_per_line_list) # return the results return avg So that's your function. It can be optimized to fewer lines of code,=20 but I thought that it would be more helpful to make it verbose so you=20 can look at it and read from the first line down to the last line and=20 see how it works. Here's the plain-English breakdown of what happens=20 in this function in ten easy steps: (1) The function is called with one argument -- "file". "file" is a=20 variable containing the path to a file. (2) Some variables are initialized, wordcount and linecount are set to=20= zero and words_per_line_list is set to an empty list. It's a good idea=20= to declare your variables in function definitions, although Python=20 doesn't always require that you do this. (3) The file is opened. Note that I use the variable name "filehandle"=20= instead of "info". The names you give a variable are important for=20 understanding that code later. Remember that open() doesn't return any=20= human-readable information, rather it returns a "handle" to a file=20 object. So the name "filehandle" is pretty helpful to remind us of=20 this. (4) The file is read, using the readlines() method of the filehandle=20 object. There are other ways to do this (such as xreadlines()), but=20 this one works for your purposes. Just don't try to open any 30 MB=20 files with this script. Each line read from the file is stored in an=20 element of a list, in this case the list is called "infolines". (5) The "linecount" variable, which was originally initialized to zero=20= (at the beginning of the function), is then set to the result of=20 "len(infolines)". The len() function counts the number of elements in=20= a list if a List is handed to it. So that means that "linecount" is=20 now set to the number of lines in the file. (6) The file handle is closed, using the close() method of filehandle=20 objects. Not required in Python, but like initializing variables, it's=20= a good idea. (7) Using a "for" loop, we loop through each element in the "infolines"=20= list and temporarily assign the element's value to the variable named=20 "line". During this "for" loop, we do a couple of things. First, we=20 split the line (which is temporarily stored in "line") into a list,=20 separated by whitespace. This is a fairly primitive way to get a list=20= of words in the line. Then we call the len() function on this list of=20= words to find the number of words in the line. This value is assigned=20= to the temporary variable "num_words". I didn't initialize "num_words"=20= at the top of the function (though i could have) since it is a=20 temporary variable, only used within this loop. (8) The other thing that we do in the "for" loop is store the number of=20= words found in that line into a new list, the list we initialized at=20 the top named "words_per_line_list". The append() method is used to do=20= this, append() adds a value to the end of a list. (9) Now that we have a list of words per line, we can go through that=20 list and add each element together to get the total number of words in=20= the file. That's what we do in the second "for" loop. For each=20 element in the "words_per_line_list" list, we add its value to the=20 "wordcount" variable. This gives us a total number of words. Then,=20 using the number of lines as a divisor, we determine the average number=20= of words per line. (By dividing the total number of words by the total=20= number of lines.) It looks like you had this in your original code,=20 but you had no way of getting the total number of words. (10) Finally, we return the average from the function. In your=20 original function, you used a "print" statement. This works fine, but=20= your code is more reuseable if you use a "return" and then deal with=20 the returned value in your code. In other words, you can use this=20 function in another script that might not want to print out "Avg words=20= per line: ", by simply returning the average number of words per line=20 and printing the return value of the function. So the rest of your=20 script could look like this (after the function definition): if __name__ =3D=3D "__main__": import sys filename =3D sys.argv[1] average =3D getStuff(filename) print "Average words per line: %f" % (average) Now you have a truly reuseable module that you can use by itself to=20 print the average number of words per line, or you could import into=20 another script and just use the function. (The above chunk of code=20 will only execute if the script is itself directly executed, it won't=20 happen if you import it into another script.) To use this script, save=20= it as "getstuff.py", then go to your command prompt and type: python getstuff.py NAME_OF_FILE Where NAME_OF_FILE is the name of the file that you want to get the=20 average number of words per line. HTH, Erik -- Erik Price (zombies=20 roam) email: erikprice@mac.com jabber: erikprice@jabber.org From dyoo@CSUA.Berkeley.EDU Fri Sep 13 18:19:05 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Fri, 13 Sep 2002 10:19:05 -0700 (PDT) Subject: [Tutor] .txt file out put In-Reply-To: <001b01c25b00$fc5bd6c0$2500a8c0@maxitec.co.za> Message-ID: <20020913101603.S40747-100000@soda.CSUA.Berkeley.EDU> On Fri, 13 Sep 2002, Morne wrote: > Can you help me I need the code to print out the info in any .txt file > im using python 2.2 with the IDLE (GUI) > > > > import string > def getStuff(file): > info = open(file,'r') > infolines = info.readlines() > > avg = wordcount/len(infolines) > print"Average words per line %f" %(avg) > > file = raw_input("Enter filename:") > getStuff(file) There are some small indentation problems in this code. If you're using IDLE, you can take advantage of the 'Tab' button: it should jump 4 spaces forward, so that you don't have to manually press the space bar all the time. Your reindented code may look something like this: ### import string def getStuff(file): info = open(file,'r') infolines = info.readlines() avg = wordcount/len(infolines) print "Average words per line %f" %(avg) file = raw_input("Enter filename:") getStuff(file) ### Can you explain to us what this code does right now, and what kind of additional information you'd like to print out. From Jmllr891@cs.com Fri Sep 13 18:51:03 2002 From: Jmllr891@cs.com (Jmllr891@cs.com) Date: Fri, 13 Sep 2002 13:51:03 EDT Subject: [Tutor] Passing Arguments to a Remote CGI Script Message-ID: <19b.8965187.2ab37f87@cs.com> --part1_19b.8965187.2ab37f87_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I've been fooling around with Python and the web lately. I need to know, how would you pass arguments (such as a username and password) to a remote CGI script directly from within Python? --part1_19b.8965187.2ab37f87_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit I've been fooling around with Python and the web lately. I need to know, how would you pass arguments (such as a username and password) to a remote CGI script directly from within Python? --part1_19b.8965187.2ab37f87_boundary-- From aicolburn@yahoo.com Fri Sep 13 22:05:53 2002 From: aicolburn@yahoo.com (Alan Colburn) Date: Fri, 13 Sep 2002 14:05:53 -0700 Subject: [Tutor] GUIs and Classes Message-ID: <01e701c25b69$589e2c90$cae68b86@fo5132> As a beginner to the world of GUI toolkits, I've noticed that most of the tutorials I've seen (regardless of the toolkit being taught) follow a similar pattern. There's an aspect to the examples that I don't really understand. Perhaps someone can clarify for me. I'll use Tkinter for this message. A typical program might look like this (I'm borrowing this from the 'Thinking in Tkinter' site): from Tkinter import * class MyApp: def __init__(self, myParent): self.myContainer1 = Frame(myParent) self.myContainer1.pack() ##various other widgets are added here root = Tk() myapp = MyApp(root) root.mainloop() The part I don't understand relates to the reason the GUI is set up within its own class. It doesn't have to be. In addition, I'm not quite sure of the difference between the root and the frame. If I simply bound all the widgets to the root object the GUI would look the same. Thoughts? Thanks, as always -- Al p.s. My thanks to those of you who recommended 'Beginning Java Objects' to me as a way to better understand OOP. I'm enjoying the book very much. From hall@nhn.ou.edu Fri Sep 13 22:40:34 2002 From: hall@nhn.ou.edu (Isaac Hall) Date: Fri, 13 Sep 2002 16:40:34 -0500 Subject: [Tutor] GUIs and Classes In-Reply-To: <01e701c25b69$589e2c90$cae68b86@fo5132>; from aicolburn@yahoo.com on Fri, Sep 13, 2002 at 16:05:53 -0500 References: <01e701c25b69$589e2c90$cae68b86@fo5132> Message-ID: <20020913164034.A15908@ouhep1.nhn.ou.edu> As someone who was once a beginner to both GUI's AND class structures at the same time, I think I may be able to help. (it should be noted here that in no way do I consider myself a programmer or computer expert, but merely someone who has to use a computer as a tool in my work) I have found that while you never actually have to use class structures in creating GUI applications/programs, the real benefit of doing so comes out when you must modify/update any GUI code you have written. I began writing my GUI programs in python in strict linear fashion. I did this because I was being forced to learn python, Tkinter, and class structures all at the same time. I had never written an object oriented program in my life, so needless to say, I was a bit intimidated by doing so. By writing my programs in the linear fashion (and with some function declarations too) I found that I could make my programs work just fine and dandy, however they eventually became super-large files that were a mess to modify. So I looked into trying to follow examples in books for putting GUI stuff into classes. I found that suddenly my code became much clearer and more concise, and to boot, I was no longer intimidated by making object oriented code. As far as making a frame to hold stuff, that is a bit redundant. It is not always nessecary, but for instance if you want to put several things in the window that are not of the same widget type, sometimes it is useful in dividing up the window in whatever way you want with frames, and then putting your widgets in the frames. The benefit here is that all size considerations can be made with the frames, leaving you free to not worry about that with all of your other widgets. I hope this helps a little. putting GUI objects in classes is not particularly nessecary, but doing so makes it easier on your blood pressure when you must modify your program after having not looked at it in 6 months. Ike On 2002.09.13 16:05 Alan Colburn wrote: > As a beginner to the world of GUI toolkits, I've noticed that most of > the > tutorials I've seen (regardless of the toolkit being taught) follow a > similar pattern. There's an aspect to the examples that I don't really > understand. Perhaps someone can clarify for me. I'll use Tkinter for > this > message. > > A typical program might look like this (I'm borrowing this from the > 'Thinking in Tkinter' site): > > from Tkinter import * > > class MyApp: > def __init__(self, myParent): > self.myContainer1 = Frame(myParent) > self.myContainer1.pack() > ##various other widgets are added here > > root = Tk() > myapp = MyApp(root) > root.mainloop() > > The part I don't understand relates to the reason the GUI is set up > within > its own class. It doesn't have to be. In addition, I'm not quite sure > of the > difference between the root and the frame. If I simply bound all the > widgets > to the root object the GUI would look the same. > > Thoughts? Thanks, as always -- Al > > p.s. My thanks to those of you who recommended 'Beginning Java > Objects' to > me as a way to better understand OOP. I'm enjoying the book very much. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From shalehperry@attbi.com Fri Sep 13 22:49:22 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 13 Sep 2002 14:49:22 -0700 Subject: [Tutor] GUIs and Classes In-Reply-To: <01e701c25b69$589e2c90$cae68b86@fo5132> References: <01e701c25b69$589e2c90$cae68b86@fo5132> Message-ID: <200209131449.22682.shalehperry@attbi.com> On Friday 13 September 2002 14:05, Alan Colburn wrote: > > The part I don't understand relates to the reason the GUI is set up wit= hin > its own class. It doesn't have to be. In addition, I'm not quite sure o= f > the difference between the root and the frame. If I simply bound all th= e > widgets to the root object the GUI would look the same. > GUIs are one of those places where Object Oriented coding is an obvious=20 choice. Each visible item gets a class and things just kind of fall in=20 place. Part of this is also most people who are taught GUIs are taught t= hem=20 while being taught OO obviously they have been made in purely functional=20 code. Many of us who know both styles just find that the objects make th= e=20 problem easier to deal with. From erikprice@mac.com Sat Sep 14 00:13:57 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 13 Sep 2002 19:13:57 -0400 Subject: [Tutor] GUIs and Classes In-Reply-To: <20020913164034.A15908@ouhep1.nhn.ou.edu> Message-ID: <7AA0FC41-C76E-11D6-AC9D-00039351FE6A@mac.com> On Friday, September 13, 2002, at 05:40 PM, Isaac Hall wrote: > I began writing my GUI programs in python in strict linear fashion. I > did this > because I was being forced to learn python, Tkinter, and class > structures > all at the same time. I had never written an object oriented program > in my life, > so needless to say, I was a bit intimidated by doing so. By writing > my programs > in the linear fashion (and with some function declarations too) I > found that I > could make my programs work just fine and dandy, however they > eventually became > super-large files that were a mess to modify. So I looked into trying > to follow > examples in books for putting GUI stuff into classes. I found that > suddenly my code > became much clearer and more concise, and to boot, I was no longer > intimidated by > making object oriented code. I wonder if this is how most people come to OO programming. I also was writing some large, ugly PHP scripts, and as I learned how to use objects (from Python no less) I basically rewrote my entire PHP application to use them too, and made it a lot easier to work with. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From sarmxiii@knology.net Sat Sep 14 00:37:58 2002 From: sarmxiii@knology.net (montana) Date: Fri, 13 Sep 2002 18:37:58 -0500 Subject: [Tutor] Re: Here is a completed script for everyones perusal. In-Reply-To: <20020912100028.GA862@localhost.localdomain> Message-ID: --Apple-Mail-3--34013122 Content-Type: multipart/alternative; boundary=Apple-Mail-4--34013122 --Apple-Mail-4--34013122 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed No. I got it from a download of modules from: http://diveintopython.org/fr/dialect_extract.html I've attached it to this email in case it can't be found. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me On Thursday, September 12, 2002, at 05:00 AM, Prahlad Vaidyanathan wrote: > Hi, > > Just noticed one little thing ... > > On Tue, 10 Sep 2002 montana spewed into the ether: > [-- snip --] >> import urllib, urllister > > Is urllister part of the standard library ? I don't seem to > have it on my setup here. --Apple-Mail-4--34013122 Content-Transfer-Encoding: 7bit Content-Type: text/enriched; charset=US-ASCII No. I got it from a download of modules from: Lucida Grandehttp://diveintopython.org/fr/dialect_extract.html I've attached it to this email in case it can't be found. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me On Thursday, September 12, 2002, at 05:00 AM, Prahlad Vaidyanathan wrote: Hi, Just noticed one little thing ... On Tue, 10 Sep 2002 montana spewed into the ether: [-- snip --] import urllib, urllister Is urllister part of the standard library ? I don't seem to have it on my setup here. --Apple-Mail-4--34013122-- --Apple-Mail-3--34013122 Content-Disposition: attachment; filename=urllister.py Content-Transfer-Encoding: quoted-printable Content-Type: application/octet-stream; x-unix-mode=0755; name="urllister.py" """Extract=20list=20of=20URLs=20in=20a=20web=20page=0D=0A=0D=0AThis=20= program=20is=20part=20of=20"Dive=20Into=20Python",=20a=20free=20Python=20= book=20for=0D=0Aexperienced=20programmers.=20=20Visit=20= http://diveintopython.org/=20for=20the=0D=0Alatest=20version.=0D=0A"""=0D= =0A=0D=0A__author__=20=3D=20"Mark=20Pilgrim=20(f8dy@diveintopython.org)"=0D= =0A__version__=20=3D=20"$Revision:=201.1.1.1=20$"=0D=0A__date__=20=3D=20= "$Date:=202002/02/21=2018:45:44=20$"=0D=0A__copyright__=20=3D=20= "Copyright=20(c)=202001=20Mark=20Pilgrim"=0D=0A__license__=20=3D=20= "Python"=0D=0A=0D=0Afrom=20sgmllib=20import=20SGMLParser=0D=0A=0D=0A= class=20URLLister(SGMLParser):=0D=0A=09def=20reset(self):=0D=0A=09=09= SGMLParser.reset(self)=0D=0A=09=09self.urls=20=3D=20[]=0D=0A=0D=0A=09def=20= start_a(self,=20attrs):=0D=0A=09=09href=20=3D=20[v=20for=20k,=20v=20in=20= attrs=20if=20k=3D=3D'href']=0D=0A=09=09if=20href:=0D=0A=09=09=09= self.urls.extend(href)=0D=0A=0D=0Aif=20__name__=20=3D=3D=20"__main__":=0D= =0A=09import=20urllib=0D=0A=09usock=20=3D=20= urllib.urlopen("http://diveintopython.org/")=0D=0A=09parser=20=3D=20= URLLister()=0D=0A=09parser.feed(usock.read())=0D=0A=09parser.close()=0D=0A= =09usock.close()=0D=0A=09for=20url=20in=20parser.urls:=20print=20url=0D=0A= --Apple-Mail-3--34013122-- From idiot1@netzero.net Fri Sep 13 16:21:21 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Fri, 13 Sep 2002 11:21:21 -0400 Subject: [Tutor] Planning out your program References: Message-ID: <3D820271.3636B2ED@netzero.net> I tend to program in a top down approach, which is proceeding from most abstracte and generalized to most specific. 1. conceive of a program to do something. 2. Rough out the details of what it is going to do, without lapsing into extreme detail. 3. outline the steps it has to go through to accomplish this. Flow charting may be useful here. 4. build a skeleton program, and import a few modules you know you will need. 5. Run it. See if it bombs. Fix it. COMMENT it! 6. Start fleshing out the program. Write functions to accomplish specific tasks, or import them from code you already have written. COMMENT IT! 7. Run it again, and pay attention to the error reports. COMMENT IT! Once it works, and is satisfactory, set it aside for a while and then go back, look at it, and RE WRITE IT. you can probably refactor it and come up with a major improvement or three to efficiency and factoring. THOSE COMMENTS ARE A LIFESAVER, do not omit them. Sean 'Shaleh' Perry wrote: > > On 12-Jul-2002 Britt A. Green wrote: > > I made a very crude little text adventure in Python a few months ago. > > However, as I began to add on functionality to it, it became apparent that a > > lot of the underlying code wasn't capable of being improved. The original > > code basically let one player walk amongst a dozen rooms and pick things up. > > To get it to do much more would mean a huge rewrite of what I'd already > > done. > > > > So I'm going to have a lot of free time this summer and want to write > > something a bit more complex. What would be the best way to plan out my code > > before I start writing? > > > > There are many schools of thought and approaches. Flow charts, UML, object > analysis, the magic eight ball, alcohol, the list goes on and on. > > Many times our first draft of a program exposes a flaw in how we thought it > would work. The key is to learn from these types of mistakes. > > Go to your local library or bookstore and wander their computer section. > There are many, many books about the act of programming and design. Much of > what they say is language neutral. > > Afterwards, sit down, ponder the way you would like to work it out. Code in > pieces, examine the parts, then continue. Many programming failures come from > someone trying to do everything in one pass. > > One of my favorite analogies is programming is like cooking, sure you can just > throw all of the ingredients in the pot, add heat, and cook until it is done. > But you have no idea what it will taste like or how long it will take. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From dyoo@hkn.eecs.berkeley.edu Sat Sep 14 07:23:08 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 13 Sep 2002 23:23:08 -0700 (PDT) Subject: [Tutor] python lessons In-Reply-To: Message-ID: Hi Eric, Also, there's also some great worksheets from the "Livewires" project; you might like them: http://www.livewires.org.uk/python/ These sheets print out pretty nicely, and they have this sort of "let's experiment and see what happens" sort of attitude to them; I like this. *grin* > > > I was wondering if there were any python or just programming classes > > > in my area. I live in westchester NY. You're always welcome to chat here about Python; we may not be next door, but we'll still be happy to listen. Good luck! From dyoo@hkn.eecs.berkeley.edu Sat Sep 14 07:38:15 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 13 Sep 2002 23:38:15 -0700 (PDT) Subject: [Tutor] Planning out your program In-Reply-To: <3D820271.3636B2ED@netzero.net> Message-ID: On Fri, 13 Sep 2002, Kirk Bailey wrote: > I tend to program in a top down approach, which is proceeding from most > abstracte and generalized to most specific. > > 1. conceive of a program to do something. > 2. Rough out the details of what it is going to do, without lapsing into > extreme detail. > 3. outline the steps it has to go through to accomplish this. Flow charting > may be useful here. > 4. build a skeleton program, and import a few modules you know you will need. > 5. Run it. See if it bombs. Fix it. COMMENT it! > 6. Start fleshing out the program. Write functions to accomplish specific > tasks, or import them from code you already have written. COMMENT IT! > 7. Run it again, and pay attention to the error reports. COMMENT IT! At the same time, the counterpoint needs to be offered: if the code is complicated enough that every line needs annotation, that's a possible sign that the code really is doing too much work. *grin* But seriously, like all things taken to extremes, overcommenting can be detrimental: comments can discourage people from simplifying code. > > > I made a very crude little text adventure in Python a few months > > > ago. However, as I began to add on functionality to it, it became > > > apparent that a lot of the underlying code wasn't capable of being > > > improved. Hmmm... if you don't mind, would it be ok to show us what the program looks like? It might not be necessary to toss the whole thing in the fire: it may be salvagable. And it would help a lot of us here on the Tutor list because it would give us an opportunity to practice the Art of Revising. Gotta go to sleep now. Talk to you later! From dyoo@hkn.eecs.berkeley.edu Sat Sep 14 07:52:59 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 13 Sep 2002 23:52:59 -0700 (PDT) Subject: [Tutor] Passing Arguments to a Remote CGI Script In-Reply-To: <19b.8965187.2ab37f87@cs.com> Message-ID: On Fri, 13 Sep 2002 Jmllr891@cs.com wrote: > I've been fooling around with Python and the web lately. I need to know, > how would you pass arguments (such as a username and password) to a > remote CGI script directly from within Python? Hello! We can pass information into a CGI in a few ways. The easiest would probably be to pass it in as part of the "query string" --- as part of the URL that starts off with a question mark. For example, let's say that we had a CGI running on a server, like this: ### """test.cgi --- a small CGI program to show how one can pass parameters. """ import cgi fs = cgi.FieldStorage() print "Content-type: text/plain\n" for key in fs.keys(): print "%s = %s" % (key, fs[key].value) ### Simple enough --- this should just echo off any parameters we send to it. Ok, with this, we can experiment a bit with passing parameters. If you have a browser ready, try putting in the url of the cgi, and add to the end of it... something like this: ?name=jmllr891&password=python For example, the following url: http://www.decrem.com/~dyoo/test.cgi?name=dyoo&password=tutor runs the 'test.cgi' CGI script and passes those two parameters into the CGI. (If you'ved noticed, lots of dynamic web sites, like amazon.com, have weird URLs like this: that's the passing of parameters between your browser and the CGI's on a server.) So all our Python program needs to do is pack all our parameter arguments in a string, and then use the 'urllib' url-handling module to send them off. The urllib module has a fucntion called 'urllib.urlencode()' that does most of the hard work: ### import urllib params = { 'language' : 'Python', 'url': 'http://python.org' } encoded_params = urllib.urlencode(params) response = urllib.urlopen('http://www.decrem.com/~dyoo/test.cgi?%s' % encoded_params) print "here's what the CGI sent back to us: ", response.read() ### Please feel free to ask more questions; I think I rushed certain things, so if anything's fuzzy, we can try concentrating on those things. I hope this helps! From dyoo@hkn.eecs.berkeley.edu Sat Sep 14 08:20:32 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 14 Sep 2002 00:20:32 -0700 (PDT) Subject: [Tutor] ascii art In-Reply-To: <001e01c25702$e7034ee0$6400a8c0@privat> Message-ID: On Sun, 8 Sep 2002, Gil Tucker [ateliermobile] wrote: > I am trying to make a program that can generate > random ascii art forms or designs. I have tried a few but they dont > work.Any tip or tips. Or warnings? Hi Gil, Can you show us some of the programs you've tried writing? By not working, do you mean that you're just getting uninteresting pictures, or are there syntax errors? Steven Wolfram's book, "A new Kind of Science", has many examples of simple programs that produce random-but-pretty pictures. For example: http://www.wolframscience.com/preview/nks_pages/?NKS0032.gif shows a neat triangle picture sort of thing. *grin* Here's a Python program that generates this image: ###### """A small ascii-art program in Python. Danny Yoo (dyoo@hkn.eecs.berkeley.edu) See: http://www.wolframscience.com/preview/nks_pages/?NKS0032.gif and Wolfram's "A New Kind of Science" for more information about this fascinating topic. """ import sys """Wolfram's automaton uses eight rules for generating the next row of output. Let's take a look at them.""" RULE_100 = { (1, 1, 1) : 0, (1, 1, 0) : 1, (1, 0, 1) : 1, (1, 0, 0) : 0, (0, 1, 1) : 1, (0, 1, 0) : 1, (0, 0, 1) : 1, (0, 0, 0) : 0 } def drawRow(row): for character in row: if character: sys.stdout.write('O') else: sys.stdout.write('.') sys.stdout.write('\n') STARTING_ROW = [0]*2 + [0]*70 + [1] + [0]*2 def applyRuleOnRow(rule, row): new_row = [0] for i in range(1, len(row)-1): triple = (row[i-1], row[i], row[i+1]) new_row.append(rule[triple]) new_row.append(0) return new_row if __name__ == '__main__': row = STARTING_ROW for i in range(70): drawRow(row) row = applyRuleOnRow(RULE_100, row) ###### I hope this sparks some interest! Good luck to you! From thomi@thomi.imail.net.nz Sat Sep 14 10:16:25 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Sat, 14 Sep 2002 21:16:25 +1200 Subject: [Tutor] ascii art In-Reply-To: References: <001e01c25702$e7034ee0$6400a8c0@privat> Message-ID: <20020914211625.2e50a6ab.thomi@thomi.imail.net.nz> wasn't Steven wolfram the guy who did a bit of research into cellular automaton in the late eighties? -- This message was brought to you by one bored guy, with nothing better to do, And the letter Q. Thomi Richards, thomi@imail.net.nz From magnus@thinkware.se Sat Sep 14 14:18:46 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 14 Sep 2002 15:18:46 +0200 Subject: [Tutor] re: Scoping question In-Reply-To: <20020909181637.528.1@gormenghast.1031594840.fake> References: <20020909160006.3492.59952.Mailman@mail.python.org> <20020909160006.3492.59952.Mailman@mail.python.org> Message-ID: <5.1.0.14.0.20020914145205.02b0c458@www.thinkware.se> At 18:16 2002-09-09 +0000, Charlie Clark wrote: >list is a key word in Python for turning other objects into lists so it's a >good idea to use another name, although Python will let you reassign it >without complaining. To be picky, list() is a built-in function, not a keyword. Using a keyword (such as "in", "for" or "print") as a vaiable name is a syntax error. > > And finally, why does the assignment to a list element execute > > successfully? If you write l =3D 5 you let go of whatever object l might have pointed at before, and refer to the integer object 5 instead. If you write l[0] =3D 5 you don't. 'l' still points to the same object as it did -- a list, and you change the content of the first item of this list. It's not at all the same thing. Maybe it's unfortunate that Python uses that syntax for assignment to slices and list elements. I guess you wouldn't have asked that question if the syntax had been: l.updateElement(0,5) Besides, if you think about it, you realize that it really has to be like this. a =3D "m" def x(): a =3D 5 print a Here, it's certainly clear to me that a in x() should be a local variable. If we turn it around: a =3D "m" def x(): print a a =3D 5 In this case it seems reasonable that 'a' in x() is still local, and that the code is in error. def x(): a =3D a + 1 or def x(): a +=3D 1 are just variations of that. But with something like a =3D [] def x(): a[0] =3D 5 it's a completely different thing. First of all, we don't reassign 'a' to a different object. We fill this mutable object with data. Secondly, if we would have imagined that 'a' in x() was local here, the code above would have been incorrect. If 'a' is local, it's so-far not defined, and then it's not a list or anything else that you can make an element assignment to. It would be as incorrect as writing 'a[0] =3D 5' in the global scope without assigning 'a' to a list or other mutable sequence first. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From scot@possum.in-berlin.de Sat Sep 14 16:50:28 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sat, 14 Sep 2002 17:50:28 +0200 Subject: [Tutor] Planning out your program In-Reply-To: <3D820271.3636B2ED@netzero.net> References: <3D820271.3636B2ED@netzero.net> Message-ID: <200209141750.28434.scot@possum.in-berlin.de> Hi there, > I tend to program in a top down approach, which is proceeding from most > abstracte and generalized to most specific. I would second Kirk's approach, and add that a good book on these things is "Code Complete" by Steve McConnell. Note that it is a Microsoft Press book, which means that they are helping to train the next generation of open source coders here - unless, of course, you are actually working for Microsoft =8). > 3. outline the steps it has to go through to accomplish this. Flow > charting may be useful here. I have found sitting down with pencil and paper and making a rough list of objects I think I need very useful, as well as lists of what they are supposed to do to each other. Nothing fancy like UML, just a bunch of boxes and arrows. > 4. build a skeleton program, and import a few modules you know you will > need. The skeleton version usually includes all of the functions I think I'll need, but as dummies: def something(stuff): pass so that I have a "viable" program very quickly, and can then code function after function, testing the whole thing after each move. Y, Scot -- Scot W. Stevenson wrote me on Saturday, 14. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 2127 hours and has a CPU that is falling asleep at a system load of 0.03. From cyberdiction@hotmail.com Sat Sep 14 18:46:24 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Sat, 14 Sep 2002 10:46:24 -0700 Subject: [Tutor] ascii art References: Message-ID: ----- Original Message ----- From: "Danny Yoo" To: "Gil Tucker [ateliermobile]" Cc: "Tutor" Sent: Saturday, September 14, 2002 12:20 AM Subject: Re: [Tutor] ascii art > > > On Sun, 8 Sep 2002, Gil Tucker [ateliermobile] wrote: > > > I am trying to make a program that can generate > > random ascii art forms or designs. I have tried a few but they dont > > work.Any tip or tips. Or warnings? > > Hi Gil, > > Can you show us some of the programs you've tried writing? By not > working, do you mean that you're just getting uninteresting pictures, or > are there syntax errors? > > > Steven Wolfram's book, "A new Kind of Science", has many examples of > simple programs that produce random-but-pretty pictures. For example: > > http://www.wolframscience.com/preview/nks_pages/?NKS0032.gif > > shows a neat triangle picture sort of thing. *grin* > > Here's a Python program that generates this image: > > > ###### > """A small ascii-art program in Python. > > Danny Yoo (dyoo@hkn.eecs.berkeley.edu) > > See: > > http://www.wolframscience.com/preview/nks_pages/?NKS0032.gif > > and Wolfram's "A New Kind of Science" for more information about this > fascinating topic. > > """ > > import sys > > > """Wolfram's automaton uses eight rules for generating the next row of > output. Let's take a look at them.""" > RULE_100 = { (1, 1, 1) : 0, > (1, 1, 0) : 1, > (1, 0, 1) : 1, > (1, 0, 0) : 0, > (0, 1, 1) : 1, > (0, 1, 0) : 1, > (0, 0, 1) : 1, > (0, 0, 0) : 0 } > > > def drawRow(row): > for character in row: > if character: sys.stdout.write('O') > else: sys.stdout.write('.') > sys.stdout.write('\n') > > > STARTING_ROW = [0]*2 + [0]*70 + [1] + [0]*2 > > def applyRuleOnRow(rule, row): > new_row = [0] > for i in range(1, len(row)-1): > triple = (row[i-1], row[i], row[i+1]) > new_row.append(rule[triple]) > new_row.append(0) > return new_row > > > if __name__ == '__main__': > row = STARTING_ROW > for i in range(70): > drawRow(row) > row = applyRuleOnRow(RULE_100, row) > ###### > > > > I hope this sparks some interest! Good luck to you! > I like it! I just cut and pasted the code and it worked. There has been discussion about the proof of universality for rule 110 (the code above) and how best to run .nb if you dont want to pay for Mathematica. I guess you convert it. Regards, Stephen From magnus@thinkware.se Sat Sep 14 20:49:44 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 14 Sep 2002 21:49:44 +0200 Subject: [Tutor] Question In-Reply-To: <12e.1739605c.2aaee679@aol.com> Message-ID: <5.1.0.14.0.20020914153131.02b15078@www.thinkware.se> At 02:08 2002-09-10 -0400, Midnit3408@aol.com wrote: >I was curious about the use of Python. Ive been wanting to learn how to=20 >write a program similar to a search engine That would be capable of=20 >pulling up and opening documents within itself. Is that possible with=20 >Python or should I try another program for that use? If so which one would= =20 >you suggest? Sure, several of the major search engines and crawlers use Python. If you look through the python standard library http://www.python.org/doc/current/lib/lib.html you will find a number of relevant modules. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From idiot1@netzero.net Sun Sep 15 07:13:13 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 15 Sep 2002 02:13:13 -0400 Subject: [Tutor] A NOVEL IDEA- no more spam! Message-ID: <3D8424F9.73E9507C@netzero.net> OK, recently I saw a site with an intresting idea. SPAM PROOFING. Idea is, it maintains a list of people who may send email to you. Anyone else sends in a email, they get one back, explaining it is in storage for 7 days, they have to go there, put in their address and a brief explanation of why they should be allowed to email you, then click submit on the form. This unlocks their identity and they can send email to you. After 7 days, any message is deleted. Almost all spam is robotic, this process will never happen. The owner of such email account is spamproof. This can be somewhat simplified. No 7 day stuff, you're not in the list, you get /dev/nul in your face. You want on the list, you go to a form and ask to be placed there, or even simpler, click a url in a person's sig block and go to a form to do so yourself. Again, no robot will be doing this. Local delivery is handed off by sendmail to a program called mail, usually located in '/bin' (ok, in my FreeBSD setup, it is in '/usr/bin/' Now, of we wrap a shell around it, we could look at the message and examine it's From: field and TO: field, open the user's OK.2mail file (just made the name up, DON'T PANIC!), and IF THE SENDER IS IN THERE we run mail and hand off the message, OTHERWISE we send off a terse email explaining the situation with the correct link included- and toss away the email. The FROM field is to an alias which feeds directly into /dev/nul so bounces from fraudulent and cancelled accounts just go away. Gee, I wonder what language to write the scripts in... ;-) This is the roughing out the concept stage, hacking at a large pad with my box of crayons and wishing I had a beer. Anyone else want to toss a cinderblock in the wading pool along side mine? If the list does not think this is the palace to kick this around, we can take it off list- and I know a place that provides great free list service... -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 15 07:45:42 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 15 Sep 2002 02:45:42 -0400 Subject: [Tutor] Re: [your list here] A NOVEL IDEA- no more spam! References: <3D8424F9.73E9507C@netzero.net> Message-ID: <3D842C96.44AFAF93@netzero.net> Hey, ya wanna look at the site sparkplugging the idea? http://spamarrest.com/ Kirk Bailey wrote: > > OK, recently I saw a site with an intresting idea. SPAM PROOFING. > > Idea is, it maintains a list of people who may send email to you. Anyone else > sends in a email, they get one back, explaining it is in storage for 7 days, > they have to go there, put in their address and a brief explanation of why they > should be allowed to email you, then click submit on the form. This unlocks > their identity and they can send email to you. After 7 days, any message is > deleted. > > Almost all spam is robotic, this process will never happen. The owner of such > email account is spamproof. > > This can be somewhat simplified. No 7 day stuff, you're not in the list, you get > /dev/nul in your face. You want on the list, you go to a form and ask to be > placed there, or even simpler, click a url in a person's sig block and go to a > form to do so yourself. Again, no robot will be doing this. > > Local delivery is handed off by sendmail to a program called mail, usually > located in '/bin' (ok, in my FreeBSD setup, it is in '/usr/bin/' Now, of we > wrap a shell around it, we could look at the message and examine it's From: > field and TO: field, open the user's OK.2mail file (just made the name up, DON'T > PANIC!), and IF THE SENDER IS IN THERE we run mail and hand off the message, > OTHERWISE we send off a terse email explaining the situation with the correct > link included- and toss away the email. The FROM field is to an alias which > feeds directly into /dev/nul so bounces from fraudulent and cancelled accounts > just go away. > > Gee, I wonder what language to write the scripts in... ;-) > > This is the roughing out the concept stage, hacking at a large pad with my box > of crayons and wishing I had a beer. Anyone else want to toss a cinderblock in > the wading pool along side mine? If the list does not think this is the palace > to kick this around, we can take it off list- and I know a place that provides > great free list service... > > -- > > end > > Respectfully, > Kirk D Bailey > > +---------------------"Thou Art Free." -Eris-----------------------+ > | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | > | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | > | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | > +------------------Thinking| NORMAL |Thinking----------------------+ > +--------+ > ------------------------------------------- > Introducing NetZero Long Distance > Unlimited Long Distance only $29.95/ month! > Sign Up Today! www.netzerolongdistance.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From Tom Churm" Hi, I finally decided to get serious and install some kind of CVS system locally on the Windows machines where I write my Python Scripts (Win98 SE & Win2000). At first I decided to try WinCVS. Even though I'd invested quite a lot of time trying to find documentation for it & install it, WinCVS never worked for me. Afterwards I discovered that, in order for it to work properly, I'd have to install some kind of additional server program on my machine?? I have to say that the docs for WinCVS are the worst I've ever seen: what little documentation there is seems all geared up for using CVS on Linux; and, although I'm not stupid, it doesn't look so easy trying to figure out how to use WinCVS--once you've managed to get it installed and working, that is! Because I wanted to get some kind of CVS system up and running without investing hours and hours in trying to tweak WinCVS so that it works for me, I just installed MS Visual Source Safe. Regardless of any disadvantages of MS VSS, at least the program's easy to install and intuitive to use. So, finally...my concrete questions: 1) What's the best CVS System to use for Python programming on Win32? 2) If your answer is WinCVS, where can I find decent documentation (for CVS newbies) on installing it and using it for the first time? Remember, I'm still frustrated over my first attempt at installing it, so I need it simple, please. 3) Are there disadvantages/limitations to using MS VSS, and what are they? 4) Or is there some CVS program written solely in Python that I should be using? Muchos gracias, Tom churmtom@hotmail.com From allyn.@tardigrade.net Sun Sep 15 10:49:22 2002 From: allyn.@tardigrade.net (Allyn Weaks) Date: Sun, 15 Sep 2002 02:49:22 -0700 Subject: [Tutor] A NOVEL IDEA- no more spam! In-Reply-To: <3D8424F9.73E9507C@netzero.net> References: <3D8424F9.73E9507C@netzero.net> Message-ID: On 15/9/02, Kirk Bailey wrote: >OK, recently I saw a site with an intresting idea. SPAM PROOFING. > >Idea is, it maintains a list of people who may send email to you. Anyone else >sends in a email, they get one back, explaining it is in storage for 7 days, It's not all that novel; there are several commercial services (sic) that do this. In practice, it turns out to be a bad idea, except perhaps as a programming exercise. It will prevent you from getting a variety of real mail, such as receipts and shipping notices when you buy things from web sites. It will stop you from being able to register at many web sites, or to buy software on line when they email you the registration key. And I'm far from the only person who refuses to jump through hoops such as this. Ah, you say, you can periodically check the rejected mail to make sure you aren't missing anything good! At which point, why bother with it? Use a simple set of mail client filters or procmail and you're better off--same number of spam subject lines to scan for false positives, and you won't have confused or ticked off any real people. This scheme is also guaranteed to keep you off of a lot of mailing lists, and you may never know why, because no one can tell you without jumping through hoops. The list server won't be able to send you a confirmation request. If you do manage to zubscribe somehow, it's downright rude to send such messages to the people who post to the list, and just as bad to direct them to the listowner. You've already explicitly agreed to accept list mail by zubscribing. As a listowner, I'd never allow a member to punish contributers that way. This topic has come up on several lists for listowners in the last couple of weeks, and the opinion has been unanimous against the technique. It's considered so annoying that there are discussions for the best way to preemptively block anyone using such things before they manage to harass anyone. Not long ago someone on this list was using this scheme, and maybe still is (I guess I'll find out when this message goes out). The 'jump through hoops' message I got back from a post I sent was just the nudge I needed to auto-reject anyone using the servers that specialize in this. >Almost all spam is robotic, this process will never happen. The owner of such >email account is spamproof. Possibly, but the 'jump through hoops' message sent out to legit correspondents is even more annoying than spam is. Dealing with your spam directly is a nuisance, but missing out on real mail is the pits. Do you expect a prospective employer to jump through hoops to send you a job offer? What if your great-uncle gets confused about the process, and you miss an invitation to a family reunion? What if your wife who's out of town has to send you an urgent message, but can only do it from a borrowed account before she catches a plane? The bayesian probability algorithm has a *much* better chance of being successful at blocking spam with few or even no false positives. There's been a lot of discussion about it all over the net in the last month including on c.l.p. There are active projects going on in nearly all languages. One in python (there may be more): -- Allyn Weaks allyn@tardigrade.net Seattle, WA Sunset zone 5 Pacific NW Native Wildlife Gardening: http://www.tardigrade.org/natives/ "The benefit of even limited monopolies is too doubtful, to be opposed to that of their general suppression." Thomas Jefferson From thomi@thomi.imail.net.nz Sun Sep 15 10:55:59 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Sun, 15 Sep 2002 21:55:59 +1200 Subject: [Tutor] A NOVEL IDEA- no more spam! In-Reply-To: References: <3D8424F9.73E9507C@netzero.net> Message-ID: <20020915215559.271e98bd.thomi@thomi.imail.net.nz> well said :-) On Sun, 15 Sep 2002 02:49:22 -0700 Thus said Allyn Weaks : > On 15/9/02, Kirk Bailey wrote: > >OK, recently I saw a site with an intresting idea. SPAM PROOFING. > > > >Idea is, it maintains a list of people who may send email to you. > >Anyone else sends in a email, they get one back, explaining it is in > >storage for 7 days, > > It's not all that novel; there are several commercial services (sic) > that do this. In practice, it turns out to be a bad idea, except > perhaps as a programming exercise. > > It will prevent you from getting a variety of real mail, such as > receipts and shipping notices when you buy things from web sites. It > will stop you from being able to register at many web sites, or to buy > software on line when they email you the registration key. And I'm > far from the only person who refuses to jump through hoops such as > this. Ah, you say, you can periodically check the rejected mail to > make sure you aren't missing anything good! At which point, why > bother with it? Use a simple set of mail client filters or procmail > and you're better off--same number of spam subject lines to scan for > false positives, and you won't have confused or ticked off any real > people. > > This scheme is also guaranteed to keep you off of a lot of mailing > lists, and you may never know why, because no one can tell you without > jumping through hoops. The list server won't be able to send you a > confirmation request. If you do manage to zubscribe somehow, it's > downright rude to send such messages to the people who post to the > list, and just as bad to direct them to the listowner. You've already > explicitly agreed to accept list mail by zubscribing. As a listowner, > I'd never allow a member to punish contributers that way. This topic > has come up on several lists for listowners in the last couple of > weeks, and the opinion has been unanimous against the technique. It's > considered so annoying that there are discussions for the best way to > preemptively block anyone using such things before they manage to > harass anyone. Not long ago someone on this list was using this > scheme, and maybe still is (I guess I'll find out when this message > goes out). The 'jump through hoops' message I got back from a post I > sent was just the nudge I needed to auto-reject anyone using the > servers that specialize in this. > > >Almost all spam is robotic, this process will never happen. The owner > >of such email account is spamproof. > > Possibly, but the 'jump through hoops' message sent out to legit > correspondents is even more annoying than spam is. Dealing with your > spam directly is a nuisance, but missing out on real mail is the pits. > Do you expect a prospective employer to jump through hoops to send you > a job offer? What if your great-uncle gets confused about the > process, and you miss an invitation to a family reunion? What if your > wife who's out of town has to send you an urgent message, but can only > do it from a borrowed account before she catches a plane? > > The bayesian probability algorithm has a *much* better chance of being > successful at blocking spam with few or even no false positives. > There's been a lot of discussion about it all over the net in the last > month including on c.l.p. There are active projects going on in > nearly all languages. One in python (there may be more): > > > -- > Allyn Weaks allyn@tardigrade.net Seattle, WA Sunset zone 5 > Pacific NW Native Wildlife Gardening: > http://www.tardigrade.org/natives/ > "The benefit of even limited monopolies is too doubtful, to be opposed > to that of their general suppression." Thomas Jefferson > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- The software required Win95 or better, so I installed Linux. Thomi Richards, thomi@imail.net.nz From magnus@thinkware.se Sun Sep 15 11:34:31 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 15 Sep 2002 12:34:31 +0200 Subject: [Tutor] A NOVEL IDEA- no more spam! In-Reply-To: References: <3D8424F9.73E9507C@netzero.net> <3D8424F9.73E9507C@netzero.net> Message-ID: <5.1.0.14.0.20020915123154.02addd40@www.thinkware.se> At 02:49 2002-09-15 -0700, Allyn Weaks wrote: >The bayesian probability algorithm has a *much* better chance of being >successful at blocking spam with few or even no false positives. >There's been a lot of discussion about it all over the net in the last >month including on c.l.p. There are active projects going on in nearly >all languages. One in python (there may be more): > > I don't think we need more if there is one being written by Barry and Timbot. I suppose it will be in the standard library soon. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sun Sep 15 11:50:14 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 15 Sep 2002 12:50:14 +0200 Subject: [Tutor] Best CVS System for Python Programming on Win 32? In-Reply-To: Message-ID: <5.1.0.14.0.20020915123520.02ad1a10@www.thinkware.se> At 09:16 2002-09-15 +0200, Tom Churm wrote: >I finally decided to get serious and install some kind of CVS system= locally >on the Windows machines where I write my Python Scripts (Win98 SE & >Win2000). At first I decided to try WinCVS. It seems you did too little research. WinCVS is one of serveral GUI *clients* for CVS, which is a client/server based configuration management system. AFAIK CVS servers only run on Unix/Linux/BSD. >Because I wanted to get some kind of CVS system up and running without >investing hours and hours in trying to tweak WinCVS so that it works for= me, >I just installed MS Visual Source Safe. Regardless of any disadvantages of >MS VSS, at least the program's easy to install and intuitive to use. Stick with VSS. >3) Are there disadvantages/limitations to using MS VSS, and what are they? It only runs on Windows. If you are happy with it, develop alone or in a small group and don't plan to work outside Microsofts OS, I think VSS will suit you well. If you plan on hosting a global, internet based open soure development project like the ones on www.sf.net, VSS won't do. >4) Or is there some CVS program written solely in Python that I should be >using? CVS =3D Concurrent Versions System, is a specific product, not some kind of category of products which you seem to think. As far as I can see, the programming language used to build the SCM system is of no consequence unless you plan to customize it, and I can't imagine why you would need that. (The large, customizable SCM systems such as ClearCase can easily be customized with Python anyway.) There are tons of configuration management systems, free as well as proprietary. All have strengths and weaknesses of course. If you don't like VSS have a look here: http://www.cmtoday.com/yp/configuration_management.html http://www.loria.fr/~molli/cm-index.html --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From kyle@sent.com Sun Sep 15 12:50:09 2002 From: kyle@sent.com (Kyle Babich) Date: Sun, 15 Sep 2002 11:50:09 UT Subject: [Tutor] imaplib append() question Message-ID: <20020915115009.7487B93703@server2.fastmail.fm> I'm trying to use imaplib's append() to upload messages locally to an IMAP server. The files are .eml's and .txt's. The guy who runs the server told me that it seperates the header from the body with two newlines, but no matter how I go about this I still get the same response from the server: ('NO', ['Message has no header/body separator']). I think my problem is that I am representing the two newlines incorrectly and that is where I need help. I've tried opening the files in notepad and hitting the enter twice where the header of the mails meets the body and I've tried using \n\n but I still get the same message. What am I doing wrong? Thank you, -- Kyle From magnus@thinkware.se Sun Sep 15 16:28:24 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 15 Sep 2002 17:28:24 +0200 Subject: [Tutor] imaplib append() question In-Reply-To: <20020915115009.7487B93703@server2.fastmail.fm> Message-ID: <5.1.0.14.0.20020915170054.02b02378@www.thinkware.se> At 11:50 2002-09-15 +0000, Kyle Babich wrote: >I'm trying to use imaplib's append() to upload messages locally to an >IMAP server. The files are .eml's and .txt's. The guy who runs the >server told me that it seperates the header from the body with two >newlines, but no matter how I go about this I still get the same >response from the server: ('NO', ['Message has no header/body >separator']). I think my problem is that I am representing the two >newlines incorrectly and that is where I need help. I've tried opening >the files in notepad and hitting the enter twice where the header of >the mails meets the body and I've tried using \n\n but I still get the >same message. What am I doing wrong? \r\n\r\n perhaps? From RFC 1730: "All interactions transmitted by client and server are in the form of lines; that is, strings that end with a CRLF." See: http://www.ietf.org/rfc/rfc1730.txt IMAP 4 http://www.ietf.org/rfc/rfc2822.txt Internet Message Format -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From fleet@teachout.org Sun Sep 15 17:20:48 2002 From: fleet@teachout.org (fleet@teachout.org) Date: Sun, 15 Sep 2002 12:20:48 -0400 (EDT) Subject: [Tutor] RPMs Message-ID: I've finally decided to upgrade from 1.5 to 2.2. I've found the RPMs. There's an RPM for RH7.3 and one for RH7.2. My system is RH7.1 (of course!). Can I use either of the RH7.+ RPMs or should I use the RH6.2 binary? The pointer in the digest this morning to SpamHam precipitated this sudden desire to be up-to-date. I'm assuming Python 1.5 won't hack it when SpamHam is ready. Is there any discussion about the project? - fleet - From cyberdiction@hotmail.com Sun Sep 15 17:56:42 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Sun, 15 Sep 2002 09:56:42 -0700 Subject: [Tutor] RPMs References: Message-ID: ----- Original Message ----- From: To: "python tutor list" Sent: Sunday, September 15, 2002 9:20 AM Subject: [Tutor] RPMs > I've finally decided to upgrade from 1.5 to 2.2. I've found the RPMs. > There's an RPM for RH7.3 and one for RH7.2. My system is RH7.1 (of > course!). Can I use either of the RH7.+ RPMs or should I use the RH6.2 > binary? > > The pointer in the digest this morning to SpamHam precipitated this sudden > desire to be up-to-date. I'm assuming Python 1.5 won't hack it when > SpamHam is ready. Is there any discussion about the project? > > - fleet - > I think the directions indicate that you download the file "Python-2.2.1.tgz" and make a .rpm file with "rpm -ta .tgz". My habit is to erase or uninstall the old package first. Then install with with: `rpm -U` or the equivalent. IIRC, this would be rpm -i or -udf 'packagename', read the Man page. I also think it works to do the "make" routine described below. Details in Man page. http://www.python.org/2.2.1/ All others should download Python-2.2.1.tgz, the source tarball, and do the usual "gunzip; tar; configure; make" dance. http://www.python.org/2.2.1/rpms.html Building RPMs Shy of RPMs because of library or other dependency problems with most of the RPMs you pick up? The cure may be to use an SRPM (Source RPM). The benefit is that you will have a binary RPM built against exactly the libraries on your system. To build a binary tailored to your system, download the source RPM and run: rpm --rebuild .src.rpm or download the original tar file and run: rpm -ta .tgz ^^^^^^^^^^^^^^^^^^^^^^^^ Note: this does not actually install . The end products (.rpm files as indicated by the "Wrote:" stdout lines) must be subsequently installed with `rpm -U` or the equivalent. SH: Libraries have those fat Linux books which explain the "make" procedure also. I am also interested in SpamHam or alternative but dont know the details. Easier than it looks, Stephen From scot@possum.in-berlin.de Sun Sep 15 18:32:25 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sun, 15 Sep 2002 19:32:25 +0200 Subject: [Tutor] A NOVEL IDEA- no more spam! (Offtopic) In-Reply-To: <3D8424F9.73E9507C@netzero.net> References: <3D8424F9.73E9507C@netzero.net> Message-ID: <200209151932.25355.scot@possum.in-berlin.de> Hello Kirk, > OK, recently I saw a site with an interesting idea. SPAM PROOFING. You will not be able to stop spam with any technical means, however clever, ever: Spam is not a technical problem, it is a legal (social) problem caused by the inability or rather the unwillingness of the United States government to pass laws that protect its citizens' interests in the face of business pressure. This is how you /really/ stop spam: In Germany and other parts of Europe, using other people's resources (fax paper, computer hardware, metered phone time, etc) for your own business purposes without their permission is /verboten/, because it is basically a form of theft. In the last year, I received one (yes, one) piece of spam from a German source, and I sent back an email citing the appropriate federal laws and asking the originator: - To inform me which data concerning my person he is in possession of - To delete all said data from his data base - To confirm, in writing, that he has done so - To give me the name of the person who gave him my data - To do all this inside a certain time frame and to smile when he does it, or else I'll send his address to the state agency for data protection (or whatever /Datenschutz/ would be in English) and sue his ass from here to the French border for violating my right under German federal law to determine what happens to my personal data. I also sent a copy of the mail CC to his provider's postmaster address. Worked like a charm, works every time. So if you really want to do something against spam, stop wasting your time coding something they're just going to outsmart anyway and write a letter to your congressperson, pointing out three things: 1. That spam is degrading productivity in U.S. companies, because U.S. employees have to wade thru tons of spam in their email boxes, while their European counterparts don't, at least not to that extent; 2. That storing, relaying, and filtering spam is costing the U.S. billions of dollars in hardware and manhours; 3. That spam is destroying email as a communication form in the U.S. the same way that it has almost destroyed newsgroups. You'll have to write an actual letter, tho, since your congressperson probably doesn't read his or her email anymore - too much spam, you see. On this note, I would like to point out that the amount of spam from the U.S. that I have received to this address has dropped to almost zero in the last year, hopefully because somebody in the address selling business (which, I should point out, is illegal here, too) finally has realized that if somebody in Hamburg, Germany is going to get a penis enlargement, he's probably not going to fly to Dorktown, Idaho for it. Or maybe American companies finally realized that they are getting ripped off when they pay for addresses with a .de (or .uk, .fr, .nl, .it, .es, .no, etc) at the end. Or, of course, my provider might just have brilliant spam filters installed. It would be nice, you know, if the U.S. finally made the .us domain mandatory: That way you would help spammers make sure they only reach their target audience (which is good for whatever reasons they're telling you spam as such is supposed to be good for you) and the rest of the world doesn't have to suffer thru what is basically an Internet disease transmitted by American providers. Now _that_ is a technical solution that would solve spam problems for millions and millions of people... Y, Scot -- Scot W. Stevenson wrote me on Sunday, 15. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 2152 hours and has a CPU that is falling asleep at a system load of 0.08. From scot@possum.in-berlin.de Sun Sep 15 18:36:37 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sun, 15 Sep 2002 19:36:37 +0200 Subject: [Tutor] RPMs In-Reply-To: References: Message-ID: <200209151936.37458.scot@possum.in-berlin.de> Hi, > Easier than it looks, Jikes. So it is really true true that RedHat is still shipping 7.3 with Python 1.5.3? I find that somewhat hard to believe, since SuSE 8.0 comes out of the box with Python 2.2, and it is so old that 8.1 is planned for release in September already... Y, Scot -- Scot W. Stevenson wrote me on Sunday, 15. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 2152 hours and has a CPU that is falling asleep at a system load of 0.00. From idiot1@netzero.net Mon Sep 16 01:14:55 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 15 Sep 2002 20:14:55 -0400 Subject: [Tutor] spamguard is cooking in the kitchen Message-ID: <3D85227F.A1F2E5DB@netzero.net> Hey gang, anyone tired of getting spam? OK, calm down, stop yelling, stop swearing, stop throwing printouts. Me too. How about a Local Delivery Agent that blocks out any email identity you do not have on your approved poster list for your account? with web forms to let you or them add them easy, and an overriding persona non grata only you can access which prevents naughty people from posting or adding themselves, even if they try? Here is a untested and very buggy first approximation at SPAMGUARD, the local delivery agent with antispam provisions. I invite discussion. #!/usr/local/bin/python # # This is spamguard V:1.0.0 COPYRIGHT 2002 by Kirk D Bailey # # It is part of the SPAMGUARD suite, # which suite is also COPYRIGHT 2002 by Kirk D Bailey. # This program is a local delivery agent, with refusal features. # it is invoked by sendmail for local delivery of mail. ################################################################################ # Python can be studied and aquired at http://www.python.org/ !!! #########1#########2#########3#########4#########5#########6#########7#########8 # that line is 80 char across, try to stay within it if you can. # # ADMIN. AND LEGAL STUFF: # This program is SHAREWARE; you can try it for 30 days from the date of # installation for free. Continued use will require paying a fee of $25 one time; # this gets you a license for one computer. A site wide license costs $50, # allowing unlimited installs for a single site. It is FREE for hobby use. # #20 # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. In addition, you may have # to modify it to work properly on your server's setup. # You should contact Mr. Kirk Bailey for licensing this suite. # # Kirk D Bailey # 10163 115 ave n # Largo FL 33773 # highprimate@howlermonkey.net #30 727-393-2161 (10am-3pm EST m-f, 3-8pm sat, 12-6 pm sundays. # ############################################################################### # OWNERSHIP AND PERMISSION ISSUES # make sure this script runs as a TRUSTED USER- # and NOT as root!!! You set that up in the Sendmail Config file (sendmail.cf). # Make sure that a NON-priviliged user OWNS # this script, and that it runs as that identity! # Generally, this is accomplished by making sure it is owned by that user. #40 Permission on all scripts must be 755, files as 666, and dirs as 744. # ############################################################################### # RESERVED FOR FUTURE TECHNOBABBLE # # # # # ############################################################################### #50 LISTS WILL BOUNCE! Users must add them to the ok2post file with the web form. # ############################################################################### # # import os, os.path, sys, string, smtp, rfc822 # MUST be invoked! # # CONFIGURATION SECTION # ===================== # NOTE that this script is SUPPOSED to be installed in the web cgi-bin! #60 # ok, where am I? I just woke up! fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0])) print fullpathtoscript # debug code, delete later. # # ok, now my config file is supposed to be RIGHT HERE with me! # So let's read the thing! f1=open(fullpathtoscript[0]+"/spamguard.cf",'r') # # Tell me little file, who am I? webdomain=string.strip(f1.readline()) #70 read the domain name pathtopop=string.strip(f1.readline()) # read the pathto the user pop files f1.close() # note the path to pop files MUST end in '/'!!!!! # # and who is this email to? username=sys.argv[1] # # receive the message and eat it alive and digest it. fullmessage=sys.stdin #80 # # digest it, Message = rfc822.Message(fullmessage) # read the incoming message in. # # then extract the From: field contents from = string.strip(Message['From']) # Extract the sender's from field. # # each *local* user has a file which email is appended to, and a dir where # personal files are stored, which in FreeBSD is /usr/home/(username). #90 that dir is where their ok2post and nongrata files are stored. # # open the ok2post file f1=open("/usr/home/"+ username+'/'+'ok2post','r') # open the approved posters, ok2post=f1.readlines() # read in the complete file, f1.close() # and close the file # # same thing now for the nongrata persona file. f1=open("usr/home/"+username+'/'+nongrata',r,) # open the unwelcome poster file, nongrata=f1.readlines() # read in all the banned persons, f1.close() #100 and close the file # if from in nongrata: sys.exit() # don't even bother with it, just exit. They are an unperson. # No replys, no bounces, no more mess or wasted clock cycles, BOOM, they're gone. # if from in ok2post: # if they are authorized, just deliver the mail! f1=open(pathtopopfile+username,'a') # open the user's mailbox file, f1.write(fullmessage) # write the entire message to it, f1.close() # then close the mailbox sys.exit() #110 and go back to sleep. else: # we do this block for not yet authorized posters msg=msg+"To: "+ from+"\n" # Reply to the professed sender, msg=msg+'From: critter@'+localhost+"\n" # with a from which will EAT bounces. msg=msg + "Subject: Unauthorized posting to account:" + + "\n" # by feeding them to /dev/nul ! msg=msg + "X-Loop: postmaster@"+ domainname + "\n" # Breaks mail loops, good idea really msg=msg + "X-spamfilter: SPAMGUARD V:1.0.0" + CRLF # Shameless self promotion msg=msg + "Reply-To: postmaster@"+ localhost +"\n" # to help REAL senders. msg=msg + """ To whom it may concern; Recently, someone using this account tried to send a message to \" """ + username + "@" + localhost + """. It was never delivered, and has been destroyed. Here is why. This site uses SPAMGUARD to intercept unauthorized messages. The INTENT is to stop spam from ever landing in the mailbox. ANY message not coming from an approved source is deleted. An unknown sender is simply replied to with this letter. PERSONA NON GRATA don't even get this much, their letter is simply destroyed, with no reply. As you got this letter, your email address does not currently appear on the persona non grata list. WHY SPAMGUARD? SPAM is Unsolicited Bulk Email (UBE, or junk Email), and is a growing problem for the internet. It is generally dishonest to some degree, unsubscribe features in it not only often do not work, but the submitted email address being unsubscribed tends to be sold to others later! Worse, the accounts used to send these things are usually throwaway accounts, and are often already deleted by the time you get around to firing off a testy complaint letter to the source. Worst of all, it is tying up bandwidth, mailbox storage, and processor time all across the net- spam is a form of distributed theft of service. Therefore, we are forced in self defense to resort to strong measures to resist this tidal wave of unpermissioned advertising. The management here has chosen to employ spamguard to block unauthorized transmissions to this account. We apologize for any inconvience this causes you. HOW DOES IT WORK? Most spam is sent by a computer program in a mass mailing, and replies like this are almost never seen by a real person, let alone acted upon. Spamguard feeds unauthorized mail to the trash heap, and sends off this letter explaining what is happening and what to do about it. The letter goes to the address shown in the letter someone tried to send here. If the sending address declared in the mail is bogus, it bounces back to us at a specially prepared alias, which feeds directly into that trash heap- we call it '/dev/nul'. Less processor time, and NO human time. We considered using a bogus top level domain name (the part after the '.', such as yahoo.foo, but as we are critical of fraud, it is somewhat hypocritical to employ it, even for a good cause). This would have caused it to stay in the sending network and not tie up bandwidth, but we like to stay above the spammer's moral level. Therefore, this feature locks out 99% of all spam. With our persona non grata features, a user may place a real person who is annoying on a refuse list, and that should handle the other 1%; Goodbye spam! :-) HOW DO I BECOME AUTHORIZED? To become authorized to post to this account, either the account owner must go to a web page and place your address on the list, or you must go to that page and place your address on the list. SPAMBOTS currently cannot do this. When the rats CAN, we will invent a better raptrap. To become authorized to send to this account, please click on this link: """ + 'http://www.'+localhost+'/cgi-bin/spamguard1.py?' + username + """ fill in your email address EXACTLY AS IT APPEARS HERE: """ + from + """ a mouse copy would be a good idea. Then click [SUBMIT]. Unless you are on the persona non grata list, you will be added to the ok2post list, and thereafter your may send email to this account normally. IF YOU ARE on that non grata list, all hope is lost, but at least the results page will declare this fact to you. Respectfully, The Postmaster at """+ localhost + "\n\n" #190 # # # # # # to_addr=from # set up the envlope data TO: from_addr='critter@'+localhost # and FROM: server = smtplib.SMTP('localhost') # you MIGHT want to comment this out; Your Milage May Vary. server.sendmail(from_addr, to_addr, msg) #200 send envlope and msg! server.quit() # then close the connection. # # end of program. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From magnus@thinkware.se Mon Sep 16 01:38:50 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 16 Sep 2002 02:38:50 +0200 Subject: [Tutor] RPMs In-Reply-To: Message-ID: <5.1.0.14.0.20020916023219.02b02008@www.thinkware.se> At 12:20 2002-09-15 -0400, fleet@teachout.org wrote: >I've finally decided to upgrade from 1.5 to 2.2. I've found the RPMs. >There's an RPM for RH7.3 and one for RH7.2. My system is RH7.1 (of >course!). Can I use either of the RH7.+ RPMs or should I use the RH6.2 >binary? Please note that most of the administration tools in Red Hat rely on Python 1.5.2. You can't upgrade from 1.5.2 to 2.2 without breaking a lot of things. For that reason Python 2.x is a separate package in Red Hat, and the python 2.2 executable will be /usr/bin/python2, and /usr/bin/python will still be 1.5.2. This will be a bit problematic if you have a lot of programs with #!/usr/bin/python or #/usr/bin/env python. In the second case I suppose you can somehow trick env to find the python2 binary for the normal users, and python 1.5.2 for root... See http://www.python.org/2.2.1/rpms.html --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From dyoo@CSUA.Berkeley.EDU Mon Sep 16 03:49:16 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Sun, 15 Sep 2002 19:49:16 -0700 (PDT) Subject: [Tutor] spamguard is cooking in the kitchen [using templated strings] In-Reply-To: <3D85227F.A1F2E5DB@netzero.net> Message-ID: <20020915192330.J9764-100000@soda.CSUA.Berkeley.EDU> Hi Kirk, Some comments on the code: > # ok, where am I? I just woke up! > fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0])) > print fullpathtoscript # debug code, delete later. > # > # ok, now my config file is supposed to be RIGHT HERE with me! > # So let's read the thing! > f1 = open(fullpathtoscript[0]+"/spamguard.cf",'r') I'd recommend using the os.path.join() function here, just for symmetry's sake. We had just used the os.path.split() a few lines back; we're rebuilding a new path string, so our operations should reflect that: ### f1 = open(os.path.join(fullpathtoscript[0], "spamguard.cf")) ### Ideally, this should make your program more portable. (But since Sendmail is not a common component on Windows systems, portability may not be too important here. *grin*) I've also removed the second parameter to the open() call, because read mode "r" is the default that open() expects to use. > webdomain=string.strip(f1.readline()) #70 read the domain name > pathtopop=string.strip(f1.readline()) # read the pathto the user pop files > f1.close() Good, so the webdomain and pathtopop are defined in a separate configuration file called 'sendmail.cf'. We can take this one step further: we may want to keep some of the program's long string messages in there too! This way, people who want to change the program's notification messages won't need to hunt through source code. In particular, we can yank this chunk of code here: > msg=msg+"To: "+ from+"\n" > msg=msg+'From: critter@'+localhost+"\n" > msg=msg + "Subject: Unauthorized posting to account:" + + "\n" > msg=msg + "X-Loop: postmaster@"+ domainname + "\n" > msg=msg + "X-spamfilter: SPAMGUARD V:1.0.0" + CRLF > msg=msg + "Reply-To: postmaster@"+ localhost +"\n" > msg=msg + """ > To whom it may concern; > Recently, someone using this account tried to send a message to \" """ + > username + "@" + localhost + """. > It was never delivered, and has been destroyed. Here is why. [text cut] And once this is out of the code, we can relocate it into some kind of "template" in your configuration file. ### """ To: %(from)s From: critter@%(localhost) Subject: Unauthorized posting to account: X-Loop: postmaster@%(domainname)s X-spamfilter: SPAMGUARD V:1.0.0 Reply-To: postmaster@%(localhost)s To whom it may concern; Recently, someone using this account tried to send a message to %(username)s@%(localhost)s. It was never delivered, and has been destroyed. Here is why... """ ### Think of this template as a form letter, to be filled in when we really want to use it. When we want to print this out, we can use string formatting to fill in the blanks: ### error_notification = get_error_message_from_cf_file(f1) print error_notification % { 'from' : from, 'localhost' : localhost, 'domainname' : domainname, 'username' : username } ### (I haven't defined get_error_message_from_cf_file() --- you'll want to think about how to do this.) These changes shouldn't add any new functionality to your program, but they do make it nicer to read and edit. I hope this helps! From idiot1@netzero.net Mon Sep 16 04:21:28 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 15 Sep 2002 23:21:28 -0400 Subject: [Tutor] spamguard is cooking in the kitchen [using templatedstrings] References: <20020915192330.J9764-100000@soda.CSUA.Berkeley.EDU> Message-ID: <3D854E38.D5F408C1@netzero.net> Why thank you! But with the feedback I have received, I am seriously reconsidering the issue altogether. In fact, given the tone of some of it, I am considering coming out in favor of the assassination of spammers instead, and look what good it will do for the gun and ammunition industries! If I DO proceed with spamguard, I will be sure to implement your suggestions- I may just read in the body of the letter from a second file, allowing for easy changing and customizing of it. Daniel Yoo wrote: > > Hi Kirk, > > Some comments on the code: > > > # ok, where am I? I just woke up! > > fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0])) > > print fullpathtoscript # debug code, delete later. > > # > > # ok, now my config file is supposed to be RIGHT HERE with me! > > # So let's read the thing! > > f1 = open(fullpathtoscript[0]+"/spamguard.cf",'r') > > I'd recommend using the os.path.join() function here, just for symmetry's > sake. We had just used the os.path.split() a few lines back; we're > rebuilding a new path string, so our operations should reflect that: > > ### > f1 = open(os.path.join(fullpathtoscript[0], "spamguard.cf")) > ### > > Ideally, this should make your program more portable. (But since Sendmail > is not a common component on Windows systems, portability may not be too > important here. *grin*) > > I've also removed the second parameter to the open() call, because read > mode "r" is the default that open() expects to use. > > > webdomain=string.strip(f1.readline()) #70 read the domain name > > pathtopop=string.strip(f1.readline()) # read the pathto the user pop files > > f1.close() > > Good, so the webdomain and pathtopop are defined in a separate > configuration file called 'sendmail.cf'. We can take this one step > further: we may want to keep some of the program's long string messages in > there too! This way, people who want to change the program's notification > messages won't need to hunt through source code. > > In particular, we can yank this chunk of code here: > > > msg=msg+"To: "+ from+"\n" > > msg=msg+'From: critter@'+localhost+"\n" > > msg=msg + "Subject: Unauthorized posting to account:" + + "\n" > > msg=msg + "X-Loop: postmaster@"+ domainname + "\n" > > msg=msg + "X-spamfilter: SPAMGUARD V:1.0.0" + CRLF > > msg=msg + "Reply-To: postmaster@"+ localhost +"\n" > > msg=msg + """ > > To whom it may concern; > > Recently, someone using this account tried to send a message to \" """ + > > username + "@" + localhost + """. > > It was never delivered, and has been destroyed. Here is why. > [text cut] > > And once this is out of the code, we can relocate it into some kind of > "template" in your configuration file. > > ### > """ > To: %(from)s > From: critter@%(localhost) > Subject: Unauthorized posting to account: > X-Loop: postmaster@%(domainname)s > X-spamfilter: SPAMGUARD V:1.0.0 > Reply-To: postmaster@%(localhost)s > To whom it may concern; > Recently, someone using this account tried to send a message to > %(username)s@%(localhost)s. It was never delivered, and has been > destroyed. Here is why... > """ > ### > > Think of this template as a form letter, to be filled in when we really > want to use it. When we want to print this out, we can use string > formatting to fill in the blanks: > > ### > error_notification = get_error_message_from_cf_file(f1) > print error_notification % { 'from' : from, > 'localhost' : localhost, > 'domainname' : domainname, > 'username' : username } > ### > > (I haven't defined get_error_message_from_cf_file() --- you'll want to > think about how to do this.) > > These changes shouldn't add any new functionality to your program, but > they do make it nicer to read and edit. > > I hope this helps! > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From kowk@mac.com Mon Sep 16 05:24:10 2002 From: kowk@mac.com (Kow K) Date: Sun, 15 Sep 2002 21:24:10 -0700 Subject: [Tutor] RPMs In-Reply-To: <200209151936.37458.scot@possum.in-berlin.de> Message-ID: <25F93586-C92C-11D6-8D7A-00050287C0A6@mac.com> On Sunday, September 15, 2002, at 10:36 AM, Scot W. Stevenson wrote: > > Jikes. So it is really true true that RedHat is still shipping 7.3 with > Python 1.5.3? I find that somewhat hard to believe, since SuSE 8.0 comes > out of the box with Python 2.2, and it is so old that 8.1 is planned for > release in September already... Yes, that's true. The reason is just that a lot of Red Hat installation and adminitration tasks are done with scripts written in Python 1.5.2. Actually, you can optionally install Python 2.x as "python2" in addition to Python 1.5.2. So, it's possible to say that 'python' is captivated by the system until RHL 7.3, for better or worse.. From 7.3 on, however, some programs seemt to depend on scripts written in Python 2.x. This means that 'python2' is also gonna be captivated by the system, for better or worse. Kow From somboon@asianet.co.th Mon Sep 16 13:04:23 2002 From: somboon@asianet.co.th (somboon v.) Date: Mon, 16 Sep 2002 19:04:23 +0700 Subject: [Tutor] echo asterisk string for password Message-ID: <002501c25d79$32cb3780$0a0110ac@ksk.com> This is a multi-part message in MIME format. ------=_NextPart_000_0022_01C25DB3.DE9C2760 Content-Type: text/plain; charset="windows-874" Content-Transfer-Encoding: quoted-printable Hi, Are there any import module or function to echo the string input as = ******** (asterisk string) for password input. somboon ------=_NextPart_000_0022_01C25DB3.DE9C2760 Content-Type: text/html; charset="windows-874" Content-Transfer-Encoding: quoted-printable
Hi,
Are there any import module or = function to=20 echo the string input as ******** (asterisk string) for password=20 input.
 
somboon
------=_NextPart_000_0022_01C25DB3.DE9C2760-- From emile@fenx.com Mon Sep 16 14:34:08 2002 From: emile@fenx.com (Emile van Sebille) Date: Mon, 16 Sep 2002 06:34:08 -0700 Subject: [Tutor] Re: echo asterisk string for password References: <002501c25d79$32cb3780$0a0110ac@ksk.com> Message-ID: somboon: > Are there any import module or function to echo the > string input as ******** (asterisk string) for password input. getpass doesn't echo at all by default, but can easily be made to do so. -- Emile van Sebille emile@fenx.com --------- From magnus@thinkware.se Mon Sep 16 15:25:41 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 16 Sep 2002 16:25:41 +0200 Subject: [Tutor] Re: echo asterisk string for password In-Reply-To: References: <002501c25d79$32cb3780$0a0110ac@ksk.com> Message-ID: <5.1.0.14.0.20020916161826.02afd590@www.thinkware.se> At 06:34 2002-09-16 -0700, Emile van Sebille wrote: >somboon: > > Are there any import module or function to echo the > > string input as ******** (asterisk string) for password input. > >getpass doesn't echo at all by default, but can easily be made to do so. Are you suggesting that he modifies the standard library, or are you implying something else here? It's obviously not difficult to read the code in getpass.py, and to see how to echo a '*' when we get a character. I would suggest that you copy the code and call it something else than getpass.getpass though. It's a bit boring if your changes disappear next time you upgrade python, or if some other code which expects a certain behaviour from a standard module won't work since the standard module is hacked. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From glingl@mail.rg16.asn-wien.ac.at Mon Sep 16 15:39:50 2002 From: glingl@mail.rg16.asn-wien.ac.at (glingl) Date: Mon, 16 Sep 2002 16:39:50 +0200 Subject: [Tutor] Re: [Edu-sig] Getting Started Message-ID: <200209161439.g8GEdwU04286@ada.rg16.asn-wien.ac.at> --- Randy Latimer schrieb: > 1. Simple Question > > I want to load a python program and "run" it. For instance, from the > tutorial: > def countdown(n): > if n == 0: > print "Blastoff!" > else: > print n > countdown(n-1) > > I save this as count.py. Go into python. Then what do I do? > > Here's the error message I'm getting: > > >>> import countdown > >>> countdown(3) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object of type 'module' is not callable > >>> > There are two ways to solve this problem, which partially arises giving to your function the same name as to your module. 1. way: call countdown.countdown(3) which means: execute the function countdown (with argument 3) from module countdown 2. way: change the import statement to from countdown import countdown (or: from countdown import * (i. e. everything)) then countdown(3) should work. Regards, Gregor > 2. What's the best way to do GUI in python? PyGTK? > > There is no best way, only a best way for you. Depends on your needs, I think. > Thanks, > Randy L > > > > > _______________________________________________ > Edu-sig mailing list > Edu-sig@python.org > http://mail.python.org/mailman/listinfo/edu-sig > From jeff@ccvcorp.com Mon Sep 16 16:57:55 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Mon, 16 Sep 2002 08:57:55 -0700 Subject: [Tutor] Best CVS System for Python Programming on Win 32? References: Message-ID: <3D85FF82.7B6F94E6@ccvcorp.com> Tom Churm wrote: > Hi, > > I finally decided to get serious and install some kind of CVS system locally > on the Windows machines where I write my Python Scripts (Win98 SE & > Win2000). At first I decided to try WinCVS. [...] You're correct that CVS requires a client/server setup, and that the documentation about it is... well, like many unix manpages, it seems to assume that one is already more-or-less familiar with the process and just need pointers on specific details. I've had fairly good luck running the CVSNT server (www.cvsnt.org) and using TortoiseCVS (www.tortoisecvs.org) as my client. Most of the documentation I've seen assumes that you'll be running the server on Unix/Linux, but for my (limited) purposes CVSNT's server seems to work the same. However, it does require an NT-based box to work from (presumably, Win2k or WinXP would work as well). The server can run on your workstation or over the network. TortoiseCVS is an Explorer-plugin frontend for the CVS client, meaning that you can handle all the basic CVS operations from within Windows Explorer. It uses icon overlays to identify the status of files under CVS management. I don't remember where exactly I found it, but there is a "daily use guide" for CVS that did a fair job of explaining the how and why of CVS in a way that a novice (like myself) could make sense of. It's really a lot simpler than you'd expect from looking through the standard documentation. Jeff Shannon Technician/Programmer Credit International From jpaish@freenet.edmonton.ab.ca Mon Sep 16 17:23:07 2002 From: jpaish@freenet.edmonton.ab.ca (Joseph Paish) Date: Mon, 16 Sep 2002 10:23:07 -0600 Subject: [Tutor] assigning portions of list to another Message-ID: <02091610230709.01026@localhost.localdomain> i am trying to copy certain elements from a list into individual variables without writing one line of code for each assignment of value to variable. i am missing something that is probably very obvious. i have tried numerous different combinations of things, and this is the latest: this is what i have so far: >>> first_record = [1, 2, 3] >>> second_rec = [4, 5, 6] >>> merged_rec = first_record + second_rec >>> print merged_rec [1, 2, 3, 4, 5, 6] (okay so far) (now to assign certain elements to variable names) >>> nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] Traceback (innermost last): File "", line 1, in ? nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] TypeError: sequence index must be integer suggestions? pointers to documentation? any help would be appreciated thanks joe From Michael Montagne Mon Sep 16 18:15:22 2002 From: Michael Montagne (Michael Montagne) Date: Mon, 16 Sep 2002 10:15:22 -0700 Subject: [Tutor] xselection Message-ID: <20020916171522.GB17057@boora.com> How can I access the current xselection to pass to my browser as a string? I want to open URLs that way to simulate the klipper functionality found in KDE. -- Michael Montagne [montagne@boora.com] 503.226.1575 -- From dyoo@CSUA.Berkeley.EDU Mon Sep 16 18:38:51 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Mon, 16 Sep 2002 10:38:51 -0700 (PDT) Subject: [Tutor] assigning portions of list to another In-Reply-To: <02091610230709.01026@localhost.localdomain> Message-ID: <20020916103012.N92499-100000@soda.CSUA.Berkeley.EDU> On Mon, 16 Sep 2002, Joseph Paish wrote: > i am trying to copy certain elements from a list into individual > variables without writing one line of code for each assignment of value > to variable. i am missing something that is probably very obvious. i > have tried numerous different combinations of things, and this is the > latest: > > this is what i have so far: > > >>> first_record = [1, 2, 3] > >>> second_rec = [4, 5, 6] > >>> merged_rec = first_record + second_rec > >>> print merged_rec > [1, 2, 3, 4, 5, 6] > > (okay so far) > > (now to assign certain elements to variable names) > > >>> nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] > Traceback (innermost last): > File "", line 1, in ? > nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] > TypeError: sequence index must be integer Unfortunately, Python doesn't support the exact same array slicing mechanisms that a language like Perl does. To pull out those three elements, we can do something like this: ### nbr1, nbr2, nbr3 = merged_rec[0], merged_rec[3], merged_rec[4] ### but this is a little... well... dull! *grin* We can improve this by writing a function that slices the list for us: ### def slice(sequence, indices): """Returns a sequence 'slice', given a list of indices.""" portions = [] for i in indices: portions.append(sequence[i]) return portions ### Once we have this, we can use this slice() function like this: ### >>> merged_rec = [1, 2, 3, 4, 5, 6] >>> nbr1, nbr2, nbr3 = slice(merged_rec, [0, 3, 4]) >>> nbr1 1 >>> nbr2 4 >>> nbr3 5 >>> slice("this is a test of the emergency broadcast system", ... [0, 2, 7, 15]) ['t', 'i', ' ', 'o'] ### The last example shows that this slice()ing should work on any sequence-like object, including strings. I hope this helps! From dman@dman.ddts.net Mon Sep 16 18:54:32 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 16 Sep 2002 13:54:32 -0400 Subject: [Tutor] Re: A NOVEL IDEA- no more spam! In-Reply-To: <3D8424F9.73E9507C@netzero.net> References: <3D8424F9.73E9507C@netzero.net> Message-ID: <20020916175432.GA29275@dman.ddts.net> --ibTvN161/egqYuK8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 15, 2002 at 02:13:13AM -0400, Kirk Bailey wrote: | Idea is, it maintains a list of people who may send email to you. [...] That's called "TMDA". Look on sourceforge. Some people (for example me) won't be bothered to jump through those hoops just to send you a message. Other solutions include spamassassin and spambayes. If you don't yet know about SA, what internet are you connected to? Spambayes is a new implementation from the python team. It is based on the theory explained at http://www.paulgraham.com/spam.html You can reinvent another wheel if you want. Personally I don't have the time for that. -D --=20 "Open Source Software - Sometimes you get more than you paid for..." =20 http://dman.ddts.net/~dman/ --ibTvN161/egqYuK8 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2GGtgACgkQO8l8XBKTpRR/YACeK8npOT6D44+HHr0DyoFCEKAt l+8AoLYqy2ETK/8+zF82QGvR38c3bfMY =t1sw -----END PGP SIGNATURE----- --ibTvN161/egqYuK8-- From dyoo@CSUA.Berkeley.EDU Mon Sep 16 18:45:42 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Mon, 16 Sep 2002 10:45:42 -0700 (PDT) Subject: [Tutor] xselection In-Reply-To: <20020916171522.GB17057@boora.com> Message-ID: <20020916103927.J92499-100000@soda.CSUA.Berkeley.EDU> On Mon, 16 Sep 2002, Michael Montagne wrote: > How can I access the current xselection to pass to my browser as a > string? I want to open URLs that way to simulate the klipper > functionality found in KDE. Alan Cox wrote a program called "googlizer" to pull stuff from X's selection buffer: http://www.linux.org.uk/~telsa/GDP/ Based on that code, I had written something in PyGTK that might be useful for you: http://hkn.eecs.berkeley.edu/~dyoo/python/Selection.py Good luck! From dman@dman.ddts.net Mon Sep 16 19:03:14 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 16 Sep 2002 14:03:14 -0400 Subject: [Tutor] Re: Best CVS System for Python Programming on Win 32? In-Reply-To: <5.1.0.14.0.20020915123520.02ad1a10@www.thinkware.se> References: <5.1.0.14.0.20020915123520.02ad1a10@www.thinkware.se> Message-ID: <20020916180314.GB29275@dman.ddts.net> --Y7xTucakfITjPcLV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 15, 2002 at 12:50:14PM +0200, Magnus Lycka wrote: | At 09:16 2002-09-15 +0200, Tom Churm wrote: | >I finally decided to get serious and install some kind of CVS | >system locally on the Windows machines where I write my Python | >Scripts (Win98 SE & Win2000). At first I decided to try WinCVS. |=20 | It seems you did too little research. WinCVS is one of serveral | GUI *clients* for CVS, which is a client/server based configuration | management system. This is only partly true. CVS doesn't strictly require a client/server architecture. If I use a CVSROOT of, say, /var/cvs/dman, then the 'cvs' command handles everything itself on local files. If I use, eg dman.ddts.net:/var/cvs/dman then it will use $CVS_RSH (which I set to 'ssh') to connect to the remote host and run the 'cvs' command as in the first example. You only use a client/server architecture if you use the "pserver" method of connecting and authenticating. Nonetheless WinCVS won't do what you want unless you have a server somewhere. (at school I never managed to figure out wincvs so I learned the 'cvs' command line interface instead) | AFAIK CVS servers only run on Unix/Linux/BSD. The cygwin package includes 'cvs'. Go to www.cygwin.com and download the installer for cygwin. I highly recommend using cygwin on any windows system. | >Because I wanted to get some kind of CVS system up and running without | >investing hours and hours in trying to tweak WinCVS so that it works for= =20 | >me, | >I just installed MS Visual Source Safe. Regardless of any disadvantages= of | >MS VSS, at least the program's easy to install and intuitive to use. |=20 | Stick with VSS. | | >3) Are there disadvantages/limitations to using MS VSS, and what are th= ey? I've used VSS at work. IMO it sucks. It is not very convenient to use, and recently I came across this article, which you really should read before using VSS : http://www.highprogrammer.com/alan/windev/sourcesafe.html HTH, -D --=20 Many are the plans in a man's heart, but it is the Lord's purpose that prevails. Proverbs 19:21 =20 http://dman.ddts.net/~dman/ --Y7xTucakfITjPcLV Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2GHOIACgkQO8l8XBKTpRQQhACfV/SUGbUNFCQ3oIoQ3/bBz+kv vXIAn0k+i7/nnaaV0/eBR7OJ3C10cumC =CetD -----END PGP SIGNATURE----- --Y7xTucakfITjPcLV-- From Michael Montagne Mon Sep 16 19:01:29 2002 From: Michael Montagne (Michael Montagne) Date: Mon, 16 Sep 2002 11:01:29 -0700 Subject: [Tutor] xselection In-Reply-To: <20020916103927.J92499-100000@soda.CSUA.Berkeley.EDU> References: <20020916171522.GB17057@boora.com> <20020916103927.J92499-100000@soda.CSUA.Berkeley.EDU> Message-ID: <20020916180129.GA18082@boora.com> >On 16/09/02, from the brain of Daniel Yoo tumbled: > > > On Mon, 16 Sep 2002, Michael Montagne wrote: > > > How can I access the current xselection to pass to my browser as a > > string? I want to open URLs that way to simulate the klipper > > functionality found in KDE. > > Alan Cox wrote a program called "googlizer" to pull stuff from X's > selection buffer: > > http://www.linux.org.uk/~telsa/GDP/ > > > Based on that code, I had written something in PyGTK that might be useful > for you: > > http://hkn.eecs.berkeley.edu/~dyoo/python/Selection.py > > > Good luck! Oh man!! Perfect. Thank you. I'm still learning but I'll pass back what I've figured out. I'm trying to add some functionality to rox. -- Michael Montagne [montagne@boora.com] 503.226.1575 -- From praveen.patil@silver-software.com Mon Sep 16 16:56:43 2002 From: praveen.patil@silver-software.com (Praveen Patil) Date: Mon, 16 Sep 2002 16:56:43 +0100 Subject: [Tutor] Please help solving the problem In-Reply-To: Message-ID: Hi , Please help me in solving the problem below. step 1: I have written three dlls : a.dll , b.dll , c.dll. a.dll contains funct_A(); b.dll contains funct_B(); c.dll contains funct_C(); step 2: I am copying a.dll to directory C:\Program Files\Python\DLLs and renaming as a.pyd similarly I am copying b.dll to directory C:\Program Files\Python\DLLs. I am not renaming as b.pyd I am copying c.dll to directory C:\Program Files\Python\DLLs and renaming as c.pyd So my C:\Program Files\Python\DLLs directory contain a.pyd , b.dll , c.pyd step 3: a)Python function func_pyA() calls funct_A() b)funct_A() call funct_B() c)funct_B() call funct_C() d)funct_C() call python fuction func_pyC() step 4: I am importing a.pyd and c.pyd in python program. import a import c step 5: I am having problem in importing 'a' because 'a' need to load b.dll and c.dll. But I copied c.dll as c.pyd. Please suggest me some solution. here is my code : 1)a.c (a.dll) ---------- void func_A(); 2)b.c (b.dll) ----------- void func_B(); 3)c.c( c.dll) ----------- void func_C(); 4) example.py --------- import a import c G_Logfile = None def TestFunction(): G_Logfile = open('Pytestfile.txt', 'w') G_Logfile.write("%s \n"%'I am writing python created text file') G_Logfile.close G_Logfile = None if __name__ == "__main__": a.func_A(); ..... ..... Please help me in solving the problem. Cheers, Praveen. [ The information contained in this e-mail is confidential and is intended for the named recipient only. If you are not the named recipient, please notify us by telephone on +44 (0)1249 442 430 immediately, destroy the message and delete it from your computer. Silver Software has taken every reasonable precaution to ensure that any attachment to this e-mail has been checked for viruses. However, we cannot accept liability for any damage sustained as a result of any such software viruses and advise you to carry out your own virus check before opening any attachment. Furthermore, we do not accept responsibility for any change made to this message after it was sent by the sender.] From mcherm@destiny.com Mon Sep 16 17:32:27 2002 From: mcherm@destiny.com (Michael Chermside) Date: Mon, 16 Sep 2002 12:32:27 -0400 Subject: [Tutor] Re: Best CVS System for Python Programming on Win 32? References: Message-ID: Tom Churm wrote: > 1) What's the best CVS System to use for Python programming on Win32? The best CVS *client* is (IMNSHO) "Tortoise CVS". It uses the underlying libraries from WinCVS, but integrates VERY NICELY with the Win32 shell. You simply use Windows Explorer or file view to see your files, and they are labled (green for unchanged, red for modified, etc), and can be checked in / checked out / diffed / etc by right-clicking. It can be obtained from http://www.tortoisecvs.org/ . Depending on what you are doing, you may or may not need a CVS *server*. If you are simply keeping versioning on your own machine, you can use a file as your repository, and it will handle the versioning without a server. If you want to be able to obtain the files remotely or back up to another machine, then you will need a CVS server. I have used cvsnt (from http://www.cvsnt.org ), but it wasn't the same wonderful experience I've had from Tortoise CVS. -- Michael Chermside From richert@upb.de Mon Sep 16 18:07:29 2002 From: richert@upb.de (Willi Richert) Date: Mon, 16 Sep 2002 19:07:29 +0200 Subject: [Tutor] assigning portions of list to another In-Reply-To: <02091610230709.01026@localhost.localdomain> References: <02091610230709.01026@localhost.localdomain> Message-ID: <200209161707.g8GH7TU25271@mailserver.c-lab.de> On Monday, 16. September 2002 18:23, Joseph Paish wrote: > nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] You would have to write nbr1, nbr2, nbr3 = merged_rec[0], merged_rec[3], merged_rec[4] as you are only allowed to specify integers or ranges like [2:6] as an index to lists. Have fun, willi From shalehperry@attbi.com Mon Sep 16 19:37:48 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Mon, 16 Sep 2002 11:37:48 -0700 Subject: [Tutor] xselection In-Reply-To: <20020916180129.GA18082@boora.com> References: <20020916171522.GB17057@boora.com> <20020916103927.J92499-100000@soda.CSUA.Berkeley.EDU> <20020916180129.GA18082@boora.com> Message-ID: <200209161137.48506.shalehperry@attbi.com> --------------Boundary-00=_0RNJMDR4Q8EFC91N1JL7 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On Monday 16 September 2002 11:01, Michael Montagne wrote: > > Oh man!! Perfect. Thank you. I'm still learning but I'll pass back > what I've figured out. I'm trying to add some functionality to rox. Enclosed is a program I wrote shortly after googlizer came out. It is 10= 0%=20 pure Xlib and C code. The license is basically BSD, so do with it as you= =20 wish. --------------Boundary-00=_0RNJMDR4Q8EFC91N1JL7 Content-Type: application/x-tgz; name="opener-0.3.tar.gz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="opener-0.3.tar.gz" H4sIAAHyfTkAA+0aa3PaSDJf0a/ocJsYHPGyY/vOPucWA46pw+ACnJDKplJCGkAXoWGlEdh7m/vt 1z0zEgKTTfYq66urU1dSSD3TPd09/Zqx+IL5LChVy4eVJ38UVKsvqydHR/hbrZ0cVem3Wnv5Uv5q eFI9qR2eHJ7UcORJtXZQPTx4Akd/mEQpiEJhBQBPwpnlsdlvzWNB+BgCPS7w9f6rx7L93deo4q4e q/3esf+1g5Pjo639P3x5cvwEqt9dkh3wf77/lX1o8MV94E5nAgp2EQ5wS2DALB/2BtIke3DDguAe /qos9KPDxq7ll3kwfWXAPv6j8bkbhi73wQ1hxgI2vodpYPmCOSZMAsaAT8CeWcGUmSA4WP49LNCc SMDHwnJ915+CRaxslIUmixlyCvlErKyA4XwHrDDktmshS3C4Hc2ZLyxBS05cj4VQEDMG+YGmyBdN 4oZLOczywPWBhuNRWLlixiMBAQtF4NrExsRJthc5JEk87LlzVy0imSEHaaaQ+KI7mFJaE+bccSf0 y6R+i2jsueHMBMcl7uNIIDIkpM18pCJeqFCFBxAyzyMmLioglV7LaEqlcaEFGVdoc8mlVzM+p7nE KFEJzTWJAh8XZpLM4Wg+ue4/mC0IQ9wn3PP4inS0ue+4pFp4qndxiOPWmC+ZVEs5hM8FSq1EoR1Z rHdaD5FTeDBm2ny4uCutZaU0C0gMDDNfuLgZCx7Idbc1LsdyXLVg0Lscvq33W9AewE2/96bdbDUh Xx/ge96Et+3hVe92CDijX+8O30HvEurdd/D3drdpQmt0028NBtDrE7f29U2n3UJ0u9vo3Dbb3ddw gaTd3hA67ev2EPkOe3JNza3dGhC/61a/cYWv9Yt2pz18J3ftsj3sEufLXh/qcFPvD9uN2069Dze3 /ZveoIVCNJFzt9297ONCretWd1gGXBmR0HqDbzC4qnc6sZb1W9SjT5JCo3fzrt9+fTWEq16n2ULk RQsFrF90Wmo5VK/RqbevTWjWr+uvW5Kqh1ykljRTyQlvr1qEpVXr+K8xbPe6pFCj1x328dVEffvD hPpte9Ayod5vD1BiqWS/h4uQeZGoJ/kgabelGJHpN3cIp9D77aC1IVGzVe8gxwHRp+fTLu9XDONP 2l8wrQjH5eXZq02U5463cQH67SYuQn8XziZuVKtVRjtQluDzHegH60gsJgYeBTajIQNTZMAsJ1Te OqSthUWA1TIQ95jdVDBi0vAdvopTDVtifgKUObJFhOGJKiObbvmiDPc8Ap+pKKXcWChKCqUfroTz fRxFipCSjy0TJ+xPmfiI+YLJbFUYDeLHllpJvhbhn4YBCHVUFkjjM/nq4owJD+aWUO+RH7pTWsTj uKTvCjYPd42M7wULP3pssk2nREqMcA7d205n5xwxXyTDSpZJQQlbXpPjBO4zkj6n9E/x+6zIRq+Z eCtNfKPJYjaYZheehflXvwfs5wjzOg8STLyQaeRyoKDaMaFWPXiJP8Mgwmw7qn9UW2vCczIc/iiL pYieK0vh0Now+IIqFs9i3YgWnp6v+RV36LSaYc0qrJnAK6hK7ZHBhlWQAumJJGXrOeZWbhfQYTzm Fwpk5/0iCQEvUjuGLzUUK4fTbEuoabBfTGwBMUaJnxtdki/GL9/J2iS6NnPaZN9g8ty32PtzbPV4 TWnE/0RjyQ2YFzLikDI2Dm/4od7LbeZnBo7reF1y18GKeMfsAlbZUOhIsPl8joWURFRSI5M1Kkfv TylKPxWKEkGTQiZC1ymQtPRKPL1CvjJ2/Uo4w0qYfizZeepIJEdTuU5C5opCld4+a1W2hL0NrSkr UJZQ6n20ucNiQScLTEwCo1Y42AeaRl7OPgV1XID3pfDDT37eyAOUwlOU2ArsGbZHlMxkXpNegflg xQMnlDP1dM1g5WKr4FmRj2REYM94yHxYsTGMA77CtttMsVtaXsR066D5jCDJi9glylm3/Q4O6n2V 6qcVk5tF2s6x9ZRqY2dqm3qf8Hn5/kOSSpvK4WFfe77iqYJDJ32FGgXzpiWssYU+FNePj844GXwj JZfyK5xaTiI+ivvFBhZbPLaRVhUajaJtsmMwCryHWL0f51Bd51/SFlPOgXQztfel2kZIyUCIZ2Ii OoizE8XWfFGQNqp9IK8L80WaUS3GHqvXq6G7xWweUs02qZQQ0kWJJo1MSRbLX9BbgauMeuhEeosK 0ueLSeIkkbecF/K3vjX2GNVecj/QnJSz5KSnbC+IddvG+i+wDY6LPNZmmcbVG0rRkBMG7nzhMeUa sYwyl+Wgz7nYGoAmm1iRJwbIHfO4RheLmqJq0r9a/F9jLzzL/nTj3jHvW/n8DoriWaKxNA46LTjj WFsyvHZL7EWYvyzkr3rXrTxa/GnK4soX74I5ncseVCtiQHXqL7I06c3Rk3F3noWVskoLmMvk3DPp doVUQJG9gzkWqEukiSMu5rEljNaG2jedOTDBplMLKZfTAYos+3qZ9Hoolr4Z0TSUbHsKcxFj4oq1 jmZTv8RJGLWQ72XLcYJYSHj+XMlVDt1fGMbkSwyI3EaUo+GcaJGiTTFUwRYn6jR8Xenct2isFkgp PNAIrS98Wefc71BY9o0ye31R289UvHKyX463eqsHSFstaZ12mTJPRRKPDtgkoF1KAZtzDO49Uhnr RuFZaPpsVVLBXdzLaxeU8iV8N6TNz4RYnFYqq9WqPOV86rEyLlFRxvvbz+fPwnwqtDB4NkqWDq9R g/tLbCWSxn4drtgo3fTb1/X+u42maf2YtKhKaBMaURDgsWDoygiKV1aHEo/zRZLBZCNak7EyUicJ tqTWqMvuhHxfS/GcLWNemt8MOw2M8UTiLhfu5F56V7hyhT0rsGWZ/EIlBiqMW3NP4yDVpVdZJC5i qZG1uWT2SZ2EcIm75G0jNhKKVEJ4WBBaQYBeQMFCLUZCpStCqiTk1t6WsoFuXNLRRddHmy0JulWS aJKwJbmU5XXOxF53QUsmJyjqTFzC0MiDVLpWGvOpxqFbFuPGP4dRX3Bl5V9L8979QKG491N17wxe vHDV+tsmo1ko3R7sUXTmNvGw92KP2GM4JhmcBDQphE3Y2AsVsCSVVEwGjVZTWjPpuOOAionXUZ9T T4lrbBpBK6zf1tFejDcsltDSt3zrKVJe8mh9vpLTsALhzpt6uZiJauY3cbpsyDPEA/8bNelmkd9v l3ydVOJZDQ9b3bh7icvwjqY9N0b//ISPjircpzo0uC9cn9rJpLGPQ93n1Mtb9kzdJGww/Gyk7n9T 9//X1idGifW73zH/9v0/jh4fPrj/Pz7J7v8fAxqXnfrrwXnpLV3YlhbMoVtaG0pTo9O+QHynEoVB ZVSr9Y8rnjuGkofPxhu0Bbr7ObqNcdnutAbn8R+PIPYi9DeL2mHdz0EDq8WUdfgUhr1mzzAUOj5G lm0jN7Vt+KGgBCriEwlQTMahxPWzYQQYb1hNTuUVu43PvpH7EQ/Q76Hk6EmlHwpayCJ8OKNDoQ/Y zpaCycMJZzBxkcH8k+MGD0dxxF6gOFLP4s5x8iD7l+UO1mUcKk9/2Un1JXFwiOEhGPJ9pSash/KG IdU91eQxdULSoFGclRjmFGL7yPlYZv61w0Jfkjvhi0lKKE554+tOlcH/DKTy/2bAfsc1vpL/qwe1 4638j+n/MMv/jwFP1R/26M+H2AYvVfhDtXxg6ts72aryhdB/3cWjkbF5HD6F4G4poMRgdTiHZ6Gx cXY8hdThyPKEtcRMYsnzkT11S3R9+XPEgnt5TMpSy6NDKv6TCv291/ha/B/Xatv939FJ1v89CtDn HqXqSan27R99GLl9bJju8GQxjqawou894rt8O7DkBwgrard8DoEtP8+AFR6CFwELmS/o6BIyNg/l jQ8N0FklZMIwYlmqf/52Wehks5/OWxoTRgv60EBmtVK4mcf0FNxRfbIrasyUlLDowwWHgeXoDyTk 5w+y93H9aUrK498rpeu78gsI3b6aKbFr/63Ul4p/6sv/kDW+Wv8fnP8Ojg6qWfw/BshPF6x7aKtv dFwRCYZFXMYNXVvJv85x37unL3r4SuK5T5/70Ac9tvxTHE53fbAM9QmDCSHHaZzQv/4KY7QuPkk+ Mj3IvsJaLAxjzITApCGvEenyTX8QJC8KVVqh1EAHU8cSFnUfdE2XNQkZZJBBBhlkkEEGGWSQQQYZ ZJBBBhlkkEEGGWSQQQYZZJBBBhlkkEEGGWSQQQYE/wb0JS6MAFAAAA== --------------Boundary-00=_0RNJMDR4Q8EFC91N1JL7-- From rob@zoism.org Tue Sep 17 00:00:14 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 17 Sep 2002 11:00:14 +1200 Subject: [Tutor] Socket server and threads Message-ID: <1032217212.2735.21.camel@caspian.everglade> Hi, I am trying to write an app. it Has a gui, and I am using xmlrpc via socket server to communicate with other apps on other machines. I currently have the socket server running as a thread like so: args = (('', 48002), BHH_Communication.BHH_DMHandler, self) self.server = None self.tserver = thread.start_new_thread(BHH_Communication.BHH_TCPServer, args) while (self.server == None): pass where BHH_TPCServer is: class BHH_TCPServer(SocketServer.TCPServer): def __init__(self, server_address, RequestHandlerClass, parent): SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) self.BHH = parent self.BHH.server = self # so handlers have access to # GUI app self.in_comms = [] self.in_comms.append(self) self.out_comms = [] while 1: rtoread, rtowrite, err = select.select(self.in_comms , self.out_comms, [], 5.0) if (len(rtoread) != 0): rtoread[0].handle_request() So with this my handler class can call functions in the main app via self.server.BHH.some_function() My question is what do I need to do to make sure it is safe, what happens if the thread and the parent app are trying to call the same function at the same time? What about if two or more request handlers are running and want the same function at the same time (via a threaded TCP handler class? Thanks -- * * Rob Brown-Bayliss * From ajs@ix.netcom.com Mon Sep 16 23:55:28 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 16 Sep 2002 18:55:28 -0400 Subject: [Tutor] Not sure how to phrase this question Message-ID: <000501c25dd4$38711460$9865fea9@arthur> Hoping I can get some help digesting the following behavior. ************************************ class returnClassic(object): def __new__(self): return Classic() class callClassic(object): def __new__(self): Classic() class returnNewStyle(object): def __new__(self): return NewStyle() class callNewStyle(object): def __new__(self): NewStyle() class returnNewStyle(object): def __new__(self): return NewStyle() class Classic: def __init__(self): print "Classic class init" class NewStyle(object): def __init__(self): print "NewStyle class init" if __name__ == "__main__": print "call to callClassic()" cc=callClassic() print cc.__class__ print "*************" print "call to returnClassic()" rc=returnClassic() print rc.__class__ print "*************" print "call to callNewStyle()" cns=callNewStyle() print cns.__class__ print "*************" print "call to returnNewStyle()" rns=returnNewStyle() print rns.__class__ Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> call to callClassic() Classic class init ************* call to returnClassic() Classic class init __main__.Classic ************* call to callNewStyle() NewStyle class init ************* call to returnNewStyle() NewStyle class init NewStyle class init Message-ID: Arthur: > Would hate to have to resort to truely understanding > this stuff to get to where I am hoping to get. > It would help to know where that is... ;-) -- Emile van Sebille emile@fenx.com --------- From rob@uselesspython.com Tue Sep 17 01:13:21 2002 From: rob@uselesspython.com (Rob) Date: Mon, 16 Sep 2002 19:13:21 -0500 Subject: [Tutor] A NOVEL IDEA- no more spam! In-Reply-To: <3D8424F9.73E9507C@netzero.net> Message-ID: Interestingly enough, every message in this thread was filtered by a rule I have set up that deletes email messages with an exclamation point in the subject line. I just noticed them all sitting in the trash awaiting my judgment. heh, Rob > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Kirk Bailey > Sent: Sunday, September 15, 2002 1:13 AM > To: tutor@python.org > Cc: monkeyshines@howlermonkey.net; tinylist-devlopers@tinylist.org; > freebsd-questions@freebsd.org > Subject: [Tutor] A NOVEL IDEA- no more spam! > > > OK, recently I saw a site with an intresting idea. SPAM PROOFING. > > Idea is, it maintains a list of people who may send email to you. > Anyone else > sends in a email, they get one back, explaining it is in storage > for 7 days, > they have to go there, put in their address and a brief > explanation of why they > should be allowed to email you, then click submit on the form. > This unlocks > their identity and they can send email to you. After 7 days, any > message is > deleted. > > Almost all spam is robotic, this process will never happen. The > owner of such > email account is spamproof. > > This can be somewhat simplified. No 7 day stuff, you're not in > the list, you get > /dev/nul in your face. You want on the list, you go to a form > and ask to be > placed there, or even simpler, click a url in a person's sig > block and go to a > form to do so yourself. Again, no robot will be doing this. > > Local delivery is handed off by sendmail to a program called mail, usually > located in '/bin' (ok, in my FreeBSD setup, it is in '/usr/bin/' > Now, of we > wrap a shell around it, we could look at the message and examine > it's From: > field and TO: field, open the user's OK.2mail file (just made the > name up, DON'T > PANIC!), and IF THE SENDER IS IN THERE we run mail and hand off > the message, > OTHERWISE we send off a terse email explaining the situation with > the correct > link included- and toss away the email. The FROM field is to an > alias which > feeds directly into /dev/nul so bounces from fraudulent and > cancelled accounts > just go away. > > Gee, I wonder what language to write the scripts in... ;-) > > This is the roughing out the concept stage, hacking at a large > pad with my box > of crayons and wishing I had a beer. Anyone else want to toss a > cinderblock in > the wading pool along side mine? If the list does not think this > is the palace > to kick this around, we can take it off list- and I know a place > that provides > great free list service... > > -- > > end > > Respectfully, > Kirk D Bailey > > > +---------------------"Thou Art Free." -Eris-----------------------+ > | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | > | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | > | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | > +------------------Thinking| NORMAL |Thinking----------------------+ > +--------+ > ------------------------------------------- > Introducing NetZero Long Distance > Unlimited Long Distance only $29.95/ month! > Sign Up Today! www.netzerolongdistance.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From ajs@ix.netcom.com Tue Sep 17 01:08:55 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 16 Sep 2002 20:08:55 -0400 Subject: [Tutor] Re: Not sure how to phrase this question Message-ID: <000501c25dde$79a8be60$9865fea9@arthur> Arthur: > Would hate to have to resort to truely understanding > this stuff to get to where I am hoping to get. > Emille: >It would help to know where that is... ;-) Something that I guess can be called a simple class factory. I have a routine that will analyze *args sufficiently to provide information as to which class to be called from the ClassFactory to which *args is passed. In the end I want to create an instance of the called/returned class, not of the ClassFactory class. Ran into the behavior of my original post while playing around with alternative ways to go. I'll certainly take a simple solution to my problem - though I think some elucidation of the behavior in my original post might be of some interest to folks other than just myself, in any case. I have posted some other questions/comments as to what I am trying to accomplish, mostly on tutor. Seem to be getting alot of blank stares. Suffice it to say that what I think I am doing is designing a user friendly interface for scripting, geared to the famous non-programmer. In short, I want to avoid a lot of named arguments, want to have the user interface with "argument smart" classes (in the manner of how I think method overloading generally works), going so far as wanting positional arguments that are in effect order insensitive. Give a Intersection class a plane and a line in any order and it will know what you are trying to get at. No Intersection(plane=planeinstance, line=lineinstance). No error on Intersection(planeinstance,lineinstance) because the class has be set up to receive only (lineinstance, planeinstance). Like most things with Python, its all quite doable. In fact its pretty much done in a way that I am satisfied is modular and maintainable. But for this one last area of confusion. Sorry you asked? Art From ajs@ix.netcom.com Tue Sep 17 01:20:18 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 16 Sep 2002 20:20:18 -0400 Subject: [Tutor] Re: Not sure how to phrase this question Message-ID: <000b01c25de0$010816c0$9865fea9@arthur> I wrote - >I'll certainly take a simple solution to my problem - though I think some elucidation of the behavior in my original post might >be of some interest to folks other than just myself, in any case. Is the simple solution that the factory should be a function, not a class? Art From dyoo@hkn.eecs.berkeley.edu Tue Sep 17 01:31:42 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 16 Sep 2002 17:31:42 -0700 (PDT) Subject: [Tutor] Re: Not sure how to phrase this question In-Reply-To: <000501c25dde$79a8be60$9865fea9@arthur> Message-ID: > In short, I want to avoid a lot of named arguments, want to have the > user interface with "argument smart" classes (in the manner of how I > think method overloading generally works), going so far as wanting > positional arguments that are in effect order insensitive. Give a > Intersection class a plane and a line in any order and it will know what > you are trying to get at. No Intersection(plane=planeinstance, > line=lineinstance). No error on Intersection(planeinstance,lineinstance) > because the class has be set up to receive only (lineinstance, > planeinstance). Hi Arthur, This link might give some more ideas on doing this kind of generalized operations. The code is in Scheme, but the ideas should transfer over gracefully: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-18.html#%_sec_2.5 Can you give a list of operations that you want to provide as well as "Intersection"? Will order always not matter, or are there operations like 'subtract', where order does matter? Perhaps your program might be amendable to a generic-operations approach. What you're doing sounds reasonable: I think the main problem here is that it's out of the experience of most mortals! *grin* Best of wishes to you! From emile@fenx.com Tue Sep 17 03:58:48 2002 From: emile@fenx.com (Emile van Sebille) Date: Mon, 16 Sep 2002 19:58:48 -0700 Subject: [Tutor] Re: Not sure how to phrase this question References: <000501c25dde$79a8be60$9865fea9@arthur> Message-ID: Arthur: > Something that I guess can be called a simple class factory. I have a > routine that will analyze *args sufficiently to provide information as to > which class to be called from the ClassFactory to which *args is > passed. > > In the end I want to create an instance of the called/returned class, not of > the ClassFactory class. I don't think you need __new__, or if you do, you'll want to read up on the existing documentation and prior discussions. Oh... I couldn't find the docs. There are some usage examples in the demo/newmetaclasses, but they only seem to exist in cvs. All this probably has a bit to do with the lack of response you mention. Anyway, it sounds like you want to create an interface to, eg, allow students to experiment with geometric properties. To support this, you want to create class instances that provide a flexible interface and do not require arguments passed in an expected sequence. ISTM a wrapper class could do this trick. class _Intersection: def __init__(self, plane=None, line=None): self.line = line self.plane = plane class Plane: def __init__(self): self.ima = 'plane' class Line: def __init__(self): self.ima = 'line' class Intersection(_Intersection): def __init__(self, *args, **kwargs): for ii in args: kwargs[ii.ima] = ii _Intersection.__init__(self, **kwargs) #test l = Line() p = Plane() ii = Intersection(l,p) jj = Intersection(p,l) print ii.line print jj.plane HTH, and if you keep trying metaclass stuff, keep us up on your progress and findings. ;-) -- Emile van Sebille emile@fenx.com --------- From ajs@ix.netcom.com Tue Sep 17 04:44:41 2002 From: ajs@ix.netcom.com (Arthur) Date: Mon, 16 Sep 2002 23:44:41 -0400 Subject: [Tutor] Re: Not sure how to phrase this question Message-ID: <001501c25dfc$8e7b6b30$9865fea9@arthur> Emille writes - >I don't think you need __new__, or if you do, you'll want to read up on >the existing documentation and prior discussions. Oh... I couldn't find >the docs. There are some usage examples in the demo/newmetaclasses, but >they only seem to exist in cvs. All this probably has a bit to do with >the lack of response you mention Yeah, if *I* need __new__ I know there is going to problems. Seems there is indeed a simple solution which works with the infrastructure I had already created - the obvious one that dawned on me after having made my original post. My "factories" work simply as functions. def Intersection(*args,**kw): dowhatigottodo if its the right thing to do under the circumstances: return PlaneIntersetion(args[0],args[1] else: do what makes more sense based on args. class PlaneIntersection(new or old,shouldn't matter): def __init__(self,plane,line): self.plane = plane self.line = line takeitfromthere i=Intersection(planeinstance, lineinstance) #or Intersection(lineinstance,planeinstance ) the dowhatigottodo routine handles the ordering issues print i.__class__ >>class '__main__.PlaneIntersection' As you suggest, this is probably just one of a number of ways to go, but seems to work most simply for picking up from where I happen to be right now. There is something to be said, though, for sort of discovering this stuff, rather than learning it in the textbook sense. As Terry posts suggests, this is probably mundane standard procedure. But, at least I have a pretty good sense now of why. Art From joel@prettyhipprogramming.com Tue Sep 17 05:55:00 2002 From: joel@prettyhipprogramming.com (Joel Ricker) Date: 17 Sep 2002 00:55:00 -0400 Subject: [Tutor] Question about socket connections Message-ID: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> My recent project in python has been to write two programs, one is a server for playing card games, while the other will be a client for playing the game with other connected clients. I'm at the point now that I'm trying to decide exactly what messages should be passed between the server/client and how they should be passed. I figure that there'll will probably be two types of messages: either a message is sent by the client and a response is immediately needed (as in client: "is it ok to play this card?", server: "yes") and those that are generated by either the server itself or another connected client (maybe an instant message or a response to the opponent's move). Since reading from a socket will block until a message is read, my thinking is that I can start a thread that does nothing but read off messages from the server and sticks them into a priority queue. Then when the client has time, it can process those messages. That sounds good for the messages that originate from outside of the client, but what about messages that the client sends itself and needs a response too? Maybe a I can establish a unique key for the request and then have the client look through the priority queue for a response? This seems a little complex for what I'm doing and Python has taught me to be suspicious of complex scripts :) Any other ideas for this sort of thing or am I on the right track? Thanks Joel From idiot1@netzero.net Tue Sep 17 06:51:43 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Tue, 17 Sep 2002 01:51:43 -0400 Subject: [Tutor] 1.5.2 to 2.x.x upgrade question Message-ID: <3D86C2EF.4DB0F2B7@netzero.net> If I can upgrade critter to2.foo, will I have to rewrite a bunch of scripts, or will all the scripts working now continue to operate correctly under the new version? -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From rob@zoism.org Tue Sep 17 07:12:38 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 17 Sep 2002 18:12:38 +1200 Subject: [Tutor] Question about socket connections In-Reply-To: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> Message-ID: <1032243156.4428.9.camel@caspian.everglade> On Tue, 2002-09-17 at 16:55, Joel Ricker wrote: I am in a similar position at the moment, my app has a main or control app and a user running it and one or more clients. I have been experimenting with the socketserver module, and looked at the threaded handler classes. I have the socket server running as a thread to get around the blocking problem you mention, but lie you find the setup looks a bit to complex or ugly in design (my setup, not the socket server module) and this suggests my approach is wrong. Another problem I think we both might face is thread safety, more than one thread accessing a function. What thoughts have you there? -- * * Rob Brown-Bayliss * From emile@fenx.com Tue Sep 17 07:23:12 2002 From: emile@fenx.com (Emile van Sebille) Date: Mon, 16 Sep 2002 23:23:12 -0700 Subject: [Tutor] Re: 1.5.2 to 2.x.x upgrade question References: <3D86C2EF.4DB0F2B7@netzero.net> Message-ID: Kirk Bailey > If I can upgrade critter to2.foo, will I have to rewrite a bunch of scripts, or > will all the scripts working now continue to operate correctly under the new > version? You'll want to review these: http://www.python.org/1.6.1/#news http://www.amk.ca/python/2.0/ http://www.amk.ca/python/2.1/ http://www.python.org/2.2.1/NEWS.txt But, IIRC, the major changes that hit code had to do with usage contrary to documented usage, eg sockets that were documneted to require a tuple, but would work just fine if two parameters were passed in. All in all I'd anticipate an easy transition. HTH, -- Emile van Sebille emile@fenx.com --------- From dyoo@hkn.eecs.berkeley.edu Tue Sep 17 07:29:39 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 16 Sep 2002 23:29:39 -0700 (PDT) Subject: [Tutor] 1.5.2 to 2.x.x upgrade question In-Reply-To: <3D86C2EF.4DB0F2B7@netzero.net> Message-ID: On Tue, 17 Sep 2002, Kirk Bailey wrote: > If I can upgrade critter to2.foo, will I have to rewrite a bunch of > scripts, or will all the scripts working now continue to operate > correctly under the new version? Ideally, the code should be portable from 1.52 to 2.2.1. Realistically, you might run into a small snag or two, but nothing too major. *grin* One of the "major" changes was to the list.append() method, where in old version of Python, if we gave append() multiple arguments, it would work with it: ### bash-2.04$ python Python 1.5.2 (#1, Apr 13 2000, 18:18:10) [GCC 2.95.1 19990816 (release)] on sunos5 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> l = [] >>> l.append(1,2,3) >>> l [(1, 2, 3)] >>> This example shows that Python 1.52 would append the tuple object (1,2,3) into our list. But this is a little weird, because then we have two ways of doing the same thing: l.append( (1, 2, 3) ) or: l.append(1, 2, 3) To fix what appears to be a bug, Python 2 opts to make the second form of append() here obsolete with an error message: ### dyoo@coffeetable:~$ python Python 2.2.1 (#2, Sep 7 2002, 15:35:22) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> l = [] >>> l.append(1,2,3) Traceback (most recent call last): File "", line 1, in ? TypeError: append() takes exactly one argument (3 given) ### I think that was the major compatibility change there; the majority of the other changes have been additional features (like list comprehenions), or improvements in the standard library (like the addition of the 'difflib' difference-seeking module). For the most part, code written for 1.52 should be upwards compatible to the Python 2 series. But, of course, this is reality, so something's bound to go awry. *grin* If you run into any weirdness while switching over to the new version of Python, post your script, and we can see what version-specific problems there are. Good luck! From magnus@thinkware.se Tue Sep 17 09:53:48 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Tue, 17 Sep 2002 10:53:48 +0200 Subject: [Tutor] Not sure how to phrase this question In-Reply-To: <000501c25dd4$38711460$9865fea9@arthur> Message-ID: <5.1.0.14.0.20020917104233.02ac6000@www.thinkware.se> At 18:55 2002-09-16 -0400, Arthur wrote: >Would hate to have to resort to truely understanding >this stuff to get to where I am hoping to get. ;) Don't you think it would be simpler to make a factory function, instead of trying to mess with the constructors? def returnClassic... rather than class returnClassic... The interface would look just the same, and I think implementation would be trivial. What you are doing now certainly seems to defy the intentions of __new__, since what you are returning is not in the inheritence chain of the class. If my channeling is successful, you are neither doing what Guido intended, nor what the Gang of 4 intended with the Factory patterns. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Tue Sep 17 10:07:25 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Tue, 17 Sep 2002 11:07:25 +0200 Subject: [Tutor] 1.5.2 to 2.x.x upgrade question In-Reply-To: <3D86C2EF.4DB0F2B7@netzero.net> Message-ID: <5.1.0.14.0.20020917105736.029c9fb0@www.thinkware.se> At 01:51 2002-09-17 -0400, Kirk Bailey wrote: >If I can upgrade critter to2.foo, will I have to rewrite a bunch of=20 >scripts, or >will all the scripts working now continue to operate correctly under the= new >version? Apart from sockets and list.append now being more strict and enforcing what the documentation always said, I think some modules have become deprecated, regex for instance. It seems the problems involved has stopped Red Hat from upgrading, and made them fiddle with parallel installations of both 1.5.2 and 2.x.x. Also remember that all python libraries using the Python C-API will have to be upgraded. Things like database drivers, wxPython, mxDateTime etc has to be updated with Python. For pure python scripts I doubt there will be any major problems. It's simple to write a script to scan your file system for the append, socket and regex problems. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From mennosimons@gmx.net Tue Sep 17 10:54:09 2002 From: mennosimons@gmx.net (Menno Simons) Date: Tue, 17 Sep 2002 11:54:09 +0200 Subject: [Tutor] faster way for adding many strings Message-ID: <200209171154.09053.mennosimons@gmx.net> Hi, what is the faster way: appending many strings to a list and then joining= =20 them, or writing to StringIO and then getvalue()? willi From kalle@lysator.liu.se Tue Sep 17 11:47:41 2002 From: kalle@lysator.liu.se (Kalle Svensson) Date: Tue, 17 Sep 2002 12:47:41 +0200 Subject: [Tutor] faster way for adding many strings In-Reply-To: <200209171154.09053.mennosimons@gmx.net> References: <200209171154.09053.mennosimons@gmx.net> Message-ID: <20020917104741.GB1547@i92.ryd.student.liu.se> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [Menno Simons] > what is the faster way: appending many strings to a list and then joining > them, or writing to StringIO and then getvalue()? Try it. Here's an example test program using the profile module: - --------- 8< --------- import profile, cStringIO def test1(): l = [] for x in xrange(1000000): l.append("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n") return "".join(l) def test2(): i = cStringIO.StringIO() for x in xrange(1000000): i.write("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n") return i.getvalue() def test3(): i = "" for x in xrange(10000): i += "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" return i def dotest(): print len(test1()) print len(test2()) print len(test3()) print len(test2()) print len(test3()) print len(test1()) profile.run("dotest()") - --------- >8 --------- and the output on my machine: - --------- 8< --------- 33000000 33000000 330000 33000000 330000 33000000 9 function calls in 24.960 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 24.940 24.940 :1(?) 1 0.020 0.020 24.960 24.960 profile:0(dotest()) 0 0.000 0.000 profile:0(profiler) 2 14.210 7.105 14.210 7.105 test.py:15(test3) 1 0.070 0.070 24.940 24.940 test.py:21(dotest) 2 5.680 2.840 5.680 2.840 test.py:3(test1) 2 4.980 2.490 4.980 2.490 test.py:9(test2) - --------- >8 --------- This would indicate that cStringIO is a bit faster than list.append + join. Note that test3 produces a string that is 100 times smaller than the other tests, and it's still the slowest of the tests. Peace, Kalle - -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 iD8DBQE9hwhJdNeA1787sd0RAlzKAKDMcWZKntl2SQ1NVD1L+WELlu1tVwCgvmM/ GqLaJkO7Z+BxQAb6YeNQ6c8= =N+1L -----END PGP SIGNATURE----- From slime@vsnl.net Tue Sep 17 11:49:56 2002 From: slime@vsnl.net (Prahlad Vaidyanathan) Date: Tue, 17 Sep 2002 16:19:56 +0530 Subject: [Tutor] more precision/predictability in calculations [gmpy module] In-Reply-To: <20020913000715.D89094-100000@soda.CSUA.Berkeley.EDU> References: <20020913062319.GA983@localhost.localdomain> <20020913000715.D89094-100000@soda.CSUA.Berkeley.EDU> Message-ID: <20020917104956.GA1047@localhost.localdomain> Hi, On Fri, 13 Sep 2002 Daniel Yoo spewed into the ether: [-- snip --] > Python uses floating point to represent these numbers, so that's where > we're losing precision. We can probably do a bit better by using the > 'gmp' General MultiPrecision library --- it's made to handle hardcore > arbitrary precision arithmetic: > > http://www.swox.com/gmp/ [-- snip --] > http://gmpy.sourceforge.net/ Thanks ! That should be what I need. Will have a look. pv. -- Prahlad Vaidyanathan Never trust a child farther than you can throw it. From jpaish@freenet.edmonton.ab.ca Tue Sep 17 16:47:41 2002 From: jpaish@freenet.edmonton.ab.ca (Joseph Paish) Date: Tue, 17 Sep 2002 09:47:41 -0600 Subject: Fwd: [Tutor] assigning portions of list to another ... thanks Message-ID: <0209170947410C.01026@localhost.localdomain> thanks for all the replies. it's working now. instead of passing one large merged list to a function, i kept it as the original several smaller ones and named the variables (using bogus names for the variables i wouldn't be using) for each individual element in each of the passed lists. for example : nbr1, nbr2, nbr3 = first_record[:] that way, there was only one line of code for each short list. actually, a very workable solution. joe ps. i am in the process of converting a perl script to python and this is just the first of what will probably be several "python newbie" questions. ---------- Forwarded Message ---------- Subject: [Tutor] assigning portions of list to another Date: Mon, 16 Sep 2002 10:23:07 -0600 From: Joseph Paish To: tutor@python.org i am trying to copy certain elements from a list into individual variables without writing one line of code for each assignment of value to variable. i am missing something that is probably very obvious. i have tried numerous different combinations of things, and this is the latest: this is what i have so far: >>> first_record = [1, 2, 3] >>> second_rec = [4, 5, 6] >>> merged_rec = first_record + second_rec >>> print merged_rec [1, 2, 3, 4, 5, 6] (okay so far) (now to assign certain elements to variable names) >>> nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] Traceback (innermost last): File "", line 1, in ? nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] TypeError: sequence index must be integer suggestions? pointers to documentation? any help would be appreciated thanks joe _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ------------------------------------------------------- From dyoo@hkn.eecs.berkeley.edu Tue Sep 17 17:02:30 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 17 Sep 2002 09:02:30 -0700 (PDT) Subject: [Tutor] 1.5.2 to 2.x.x upgrade question (fwd) Message-ID: Hi James, You probably meant to reply to the whole Tutor list. I'll forward your message for you. (Side note: you probably want to turn off HTML mode on your mail program; the HTML in your message is obscuring your message for potentially many people.) ---------- Forwarded message ---------- Date: Tue, 17 Sep 2002 05:20:56 -0700 (PDT) From: James Clare To: Danny Yoo Subject: Re: [Tutor] 1.5.2 to 2.x.x upgrade question

If you upgrade, do it in another directory and point the shebang line to the new directory. If you have problems with an old program just use the older version.

 Danny Yoo wrote:



On Tue, 17 Sep 2002, Kirk Bailey wrote:

> If I can upgrade critter to2.foo, will I have to rewrite a bunch of
> scripts, or will all the scripts working now continue to operate
> correctly under the new version?

Ideally, the code should be portable from 1.52 to 2.2.1. Realistically,
you might run into a small snag or two, but nothing too major. *grin*



One of the "major" changes was to the list.append() method, where in old
version of Python, if we gave append() multiple arguments, it would work
with it:

###
bash-2.04$ python
Python 1.5.2 (#1, Apr 13 2000, 18:18:10) [GCC 2.95.1 19990816 (release)]
on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> l =3D []
>>> l.append(1,2,3)
>>> l
[(1, 2, 3)]
>>>

This example shows that Python 1.52 would append the tuple object (1,2,3)
into our list. But this is a little weird, because then we have two ways
of doing the same thing:

l.append( (1, 2, 3) )

or:

l.append(1, 2, 3)

To fix what appears to be a bug, Python 2 opts to make the second form of
append() here obsolete with an error message:

###
dyoo@coffeetable:~$ python
Python 2.2.1 (#2, Sep 7 2002, 15:35:22)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l =3D []
>>> l.append(1,2,3)
Traceback (most recent call last):
File "", line 1, in ?
TypeError: append() takes exactly one argument (3 given)
###

I think that was the major compatibility change there; the majority of
the other changes have been additional features (like list comprehenions),
or improvements in the standard library %=10=10_=06=F8=0F_=06=02 From jeff@ccvcorp.com Tue Sep 17 18:15:39 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Tue, 17 Sep 2002 10:15:39 -0700 Subject: [Tutor] assigning portions of list to another References: <02091610230709.01026@localhost.localdomain> Message-ID: <3D87633B.2DA71DF3@ccvcorp.com> Joseph Paish wrote: > i am trying to copy certain elements from a list into individual variables > without writing one line of code for each assignment of value to variable. > [...] > >>> nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] > Traceback (innermost last): > File "", line 1, in ? > nbr1, nbr2, nbr3 = merged_rec[0, 3, 4] > TypeError: sequence index must be integer One thing that you might consider doing is using a class and class attributes, instead of individual variables or list references. For instance... class record: def __init__(self, *args): argnumber = 1 for arg in args: try: for item in arg: setattr(self, 'nbr%d' % argnumber, item) argnumber += 1 except IndexError: setattr(self, 'nbr%d' % argnumber, arg) argnumber += 1 >>> rec1 = [1, 2, 3] >>> rec2 = [4, 5, 6] >>> merged = record(rec1, rec2) >>> merged.nbr1 1 >>> merged.nbr5 5 >>> This gives you the understandablity of named variables, while still allowing you to keep track of everything as a group. You could doubtless come up with some attribute-naming scheme that's more useful than 'nbr1', 'nbr2', etc, that could still be automatically generated. If you wanted to get really fancy, you could write a __setattr__() that would generate attribute names for you. Or, if there is a specific set of fields in this record which will always appear in the same order, you could give them more descriptive names. This would still involve one line for each field, but you'd only have to do so once, in the class definition, and not each time that you want to use a record. class record: def __init__(self, firstname, lastname, address, zip, phone): self.firstname = firstname self.lastname = lastname self.address = address self.zip = zip self.phone = phone >>> r = record('john', 'smith', '123 main', '98104', '555-1212') >>> r.zip '98104' >>> Either of these approaches seems to me to be preferable to your plan of actually using individual, unconnected variables, though admittedly this is to some degree a matter of taste. Jeff Shannon Technician/Programmer Credit International From python Tue Sep 17 20:37:20 2002 From: python (python) Date: Tue, 17 Sep 2002 12:37:20 -0700 Subject: Re[2]: [Tutor] Question about socket connections In-Reply-To: <1032243156.4428.9.camel@caspian.everglade> References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> <1032243156.4428.9.camel@caspian.everglade> Message-ID: <3370587306.20020917123720@inkedmn.net> you guys might have a look at the asyncore module, as well as this tutorial on asynchronous sockets... http://squirl.nightmare.com/medusa/async_sockets.html good luck RBB> On Tue, 2002-09-17 at 16:55, Joel Ricker wrote: RBB> I am in a similar position at the moment, my app has a main or control RBB> app and a user running it and one or more clients. RBB> I have been experimenting with the socketserver module, and looked at RBB> the threaded handler classes. RBB> I have the socket server running as a thread to get around the blocking RBB> problem you mention, but lie you find the setup looks a bit to complex RBB> or ugly in design (my setup, not the socket server module) and this RBB> suggests my approach is wrong. RBB> Another problem I think we both might face is thread safety, more than RBB> one thread accessing a function. What thoughts have you there? From dyoo@hkn.eecs.berkeley.edu Tue Sep 17 21:44:17 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 17 Sep 2002 13:44:17 -0700 (PDT) Subject: Re[2]: [Tutor] Question about socket connections In-Reply-To: <3370587306.20020917123720@inkedmn.net> Message-ID: On Tue, 17 Sep 2002, python wrote: > you guys might have a look at the asyncore module, as well as this > tutorial on asynchronous sockets... > > http://squirl.nightmare.com/medusa/async_sockets.html Medusa, however, is a bit antiquated, from what I've heard, and hasn't been developed on for years. Thankfully, there is an alternative: the 'Twisted' framework appears to be the spiritual successor to Medusa: http://twistedmatrix.com/ http://twistedmatrix.com/documents/dev Good luck! From joel@prettyhipprogramming.com Tue Sep 17 22:04:20 2002 From: joel@prettyhipprogramming.com (Joel Ricker) Date: 17 Sep 2002 17:04:20 -0400 Subject: [Tutor] Question about socket connections In-Reply-To: <1032243156.4428.9.camel@caspian.everglade> References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> <1032243156.4428.9.camel@caspian.everglade> Message-ID: <1032296660.2076.8.camel@rdu57-231-033.nc.rr.com> On Tue, 2002-09-17 at 02:12, Rob Brown-Bayliss wrote: > Another problem I think we both might face is thread safety, more than > one thread accessing a function. What thoughts have you there? My thinking is that each of my server threads will have access to an "Inbox" and an "Outbox" of their own that connects to an overall MessageHandler. Each thread will wait for messages to be received by the client and stick anything it gets into its Inbox. The MessageHandler is watching the Inboxes of all the current threads and then processes them in turn and at some point puts a new outgoing message into the right Outbox. Then the thread will pick up on that and pass it back out. It looks pretty safe to me but then again, this is all pretty theoretical at the moment and would love to hear any ideas. If it helps you any, this is what I have so far for my server. import SocketServer import threading class MessageObject: def pack(self, str): return "Blah" def unpack(self, str): return "Blah" class MyHandler(SocketServer.BaseRequestHandler): def setup(self): self.peer = self.request.getpeername() print "New Connection From %s:%d" % self.peer def handle(self): while 1: dataReceived, (addr, port) = self.request.recvfrom(1024) if not dataReceived: break print MessageObject().unpack(dataReceived) self.request.send(MessageObject().pack("OK")) def finish(self): print "Connection closed." myServer = SocketServer.ThreadingTCPServer(('', 8881), MyHandler) myServer.serve_forever() HTH Joel From Michael Montagne Tue Sep 17 23:13:12 2002 From: Michael Montagne (Michael Montagne) Date: Tue, 17 Sep 2002 15:13:12 -0700 Subject: [Tutor] Is it a weekend Message-ID: <20020917221312.GB30884@boora.com> Can python tell me if it is a weekend or not? Holiday? -- Michael Montagne [montagne@boora.com] 503.226.1575 -- From emile@fenx.com Tue Sep 17 23:32:33 2002 From: emile@fenx.com (Emile van Sebille) Date: Tue, 17 Sep 2002 15:32:33 -0700 Subject: [Tutor] Re: Re[2]: Question about socket connections References: <3370587306.20020917123720@inkedmn.net> Message-ID: Danny Yoo: > Medusa, however, is a bit antiquated, from what I've heard, and hasn't > been developed on for years. > Medusa, IIRC, is the core of ZServer in Zope and can be found there. However, I'm not sure if it plays nicely by itself. -- Emile van Sebille emile@fenx.com --------- From emile@fenx.com Tue Sep 17 23:44:15 2002 From: emile@fenx.com (Emile van Sebille) Date: Tue, 17 Sep 2002 15:44:15 -0700 Subject: [Tutor] Re: Is it a weekend References: <20020917221312.GB30884@boora.com> Message-ID: "Michael Montagne" wrote in message news:20020917221312.GB30884@boora.com... > Can python tell me if it is a weekend or not? Holiday? >>> import time >>> time.localtime(time.time()) (2002, 9, 17, 15, 33, 11, 1, 260, 1) >>> print time.localtime.__doc__ localtime([seconds]) -> (tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_ yday,tm_isdst) Convert seconds since the Epoch to a time tuple expressing local time. When 'seconds' is not passed in, convert the current time instead. >>> mxDateTime has Feasts, which covers some of the additional holidays, but as there are different observances everywhere, you're not likely to find any one module that covers them all the right way. HTH, -- Emile van Sebille emile@fenx.com --------- From danny@i4.net Wed Sep 18 01:40:20 2002 From: danny@i4.net (Danny) Date: Tue, 17 Sep 2002 18:40:20 -0600 Subject: [Tutor] ( the reply's additional "Re:" is ok) confirm 507249 Message-ID: <000801c25eab$f7defd80$d0e76741@hewlett5k1589j> From magnus@thinkware.se Wed Sep 18 02:24:47 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 18 Sep 2002 03:24:47 +0200 Subject: [Tutor] Re: Is it a weekend In-Reply-To: References: <20020917221312.GB30884@boora.com> Message-ID: <5.1.0.14.0.20020918025659.00be26e0@www.thinkware.se> At 15:44 2002-09-17 -0700, Emile van Sebille wrote: >"Michael Montagne" wrote in message >news:20020917221312.GB30884@boora.com... > > Can python tell me if it is a weekend or not? Holiday? > > >>> import time > >>> time.localtime(time.time()) >(2002, 9, 17, 15, 33, 11, 1, 260, 1) > >>> print time.localtime.__doc__ >localtime([seconds]) -> >(tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_ >yday,tm_isdst) To make it a bit more specific: import time, types def weekend(when=None): if when == None: # Use present when = time.localtime() elif type(when) == types.FloatType: # Seconds since epoch when = time.localtime(when) elif type(when) != type(time.localtime()): print type(when) raise TypeError, "Bad input, expected float or time-struct" iDayOfWeek = 6 friday = 4 # monday = 0, sunday = 6 return when[iDayOfWeek] > friday #test print weekend() daylength = 24 * 60 * 60 # seconds ourTime = time.time() for d in range(7): print weekend(ourTime) print weekend(time.localtime(ourTime)) ourTime += daylength I'd recommend keeping a dictionary with year and a tuple of julian day numbers for holidays for each year. Then you just need something like... def holiday(when): # Assuming time-struct. iYear, iJulianDay = 0, 7 return when[iJulianDay] in holidays[when[iYear]] ...to catch the remaining red days. Of course things like easter can be calculated, but I wouldn't bother to do that in run-time. >Convert seconds since the Epoch to a time tuple expressing local time. >When 'seconds' is not passed in, convert the current time instead. > >>> > >mxDateTime has Feasts, which covers some of the additional holidays, but >as there are different observances everywhere, you're not likely to find >any one module that covers them all the right way. -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From lists@shrestha.net.np Tue Sep 17 18:10:14 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Tue, 17 Sep 2002 22:55:14 +0545 Subject: [Tutor] Question about socket connections References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> <1032243156.4428.9.camel@caspian.everglade> Message-ID: <3D8761F6.9040108@shrestha.net.np> why don't you check out xmlrpc at http://www.xmlrpc.com get a python implementation from http://www.pythonware.com ashish Rob Brown-Bayliss wrote: > On Tue, 2002-09-17 at 16:55, Joel Ricker wrote: > > I am in a similar position at the moment, my app has a main or control > app and a user running it and one or more clients. > > I have been experimenting with the socketserver module, and looked at > the threaded handler classes. > > I have the socket server running as a thread to get around the blocking > problem you mention, but lie you find the setup looks a bit to complex > or ugly in design (my setup, not the socket server module) and this > suggests my approach is wrong. > > Another problem I think we both might face is thread safety, more than > one thread accessing a function. What thoughts have you there? > From abarker@xminc.com Wed Sep 18 05:06:02 2002 From: abarker@xminc.com (Anthony Barker) Date: Wed, 18 Sep 2002 00:06:02 -0400 (EDT) Subject: [Tutor] refactoring book and function size Message-ID: <33175.65.95.67.39.1032321962.squirrel@www.xminc.com> I have been reading the book "Refactoring: Improving the Design of Existing Code" it makes for a good read - particularly if you have refactored before on a medium sized project. One thing I found odd is how they pull out very small bits of code and add them to new routines. I am reading "Code Complete", by Steve McConnell in parallel. - he mentions some research that larger subroutines statistically have fewer bugs than very small ones. The research shows that routines of up to 200 lines are not bad. Personally I find readability drops if you have subroutines for less than 2-3 statements. Larger routines, with purpose, clean names and simple interfaces make understanding a program or module easier. Anthony http://xminc.com/anthony/ From dyoo@hkn.eecs.berkeley.edu Wed Sep 18 06:52:40 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 17 Sep 2002 22:52:40 -0700 (PDT) Subject: [Tutor] Learning natural language processing and Python? [learning about "stemming" words] Message-ID: Hi everyone, I'm starting to learn "Natural Language Processing", which tries to use a computer to tease meaning out of natural language. I was wondering if anyone was interested in this sort of thing? I've started to find some resources out there. One big one is the "NLTK" toolkit, which acts as an umbrella for a lot of NLP software: http://nltk.sourceforge.net/ One task that appears to be fairly well understood is getting the "stem" of a word. http://www.comp.lancs.ac.uk/computing/research/stemming/general/index.htm Stemming is used to toss out most of the variation in word endings, to get at the very "stem" of a word. There's an algorithm called the "Porter Stemming Algorithm" that does interesting things to English words: http://www.tartarus.org/~martin/PorterStemmer/index.html It tries to remove the inflectional endings of English text, so it's similar to the root-word function that's in WordNet. The page above gives a Python implementation of the algorithm! Here's an example of what it does: ### >>> import porter >>> p = porter.PorterStemmer() >>> def stem(word): return p.stem(word, 0, len(word)-1) ... >>> stem('superfly') 'superfli' >>> stem('learning') 'learn' >>> stem('pythonic') 'python' >> stem('programmer') 'programm' >>> stem('elbereth') 'elbereth' ### So I think it's something of a super-plural remover. I'm glad to see that 'Elbereth' came out untainted. Anyway, sorry for posting about a random topic; I'm hoping that someone else will be interested enough to help me learn this stuff... *grin* From marcolinux@linuxbr.com.br Mon Sep 16 02:39:56 2002 From: marcolinux@linuxbr.com.br (Marc) Date: Sun, 15 Sep 2002 22:39:56 -0300 Subject: [Tutor] RPMs In-Reply-To: References: Message-ID: <20020915223956.A1270@marcolab.net> Stephen Harris (cyberdiction@hotmail.com) wrote: > http://www.python.org/2.2.1/ > All others should download Python-2.2.1.tgz, the source tarball, and do the > usual "gunzip; tar; configure; make" dance. > You may like a new step in this dance: the checkinstall program. http://freshmeat.net/projects/checkinstall/ It not only makes possible to unistall most programs you install from source, but also allow one to generate RPM, DEB, or slackware TGZ. Suppose you have checkinstall installed. Download python-2.2.1.tgz, unpack then do: # ./configure --prefix=/usr #I dont like things in /usr/local # checkinstall Follow the instructions and generate the package that makes you happy. Most of the programs I install are RPMfied now, makes easier to keep the system sane from an administrative perspective. Hope it's not offtopic since we are installing python :) . -- .:: MarcoLinux ::. From erikprice@mac.com Wed Sep 18 13:51:41 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 18 Sep 2002 08:51:41 -0400 Subject: [Tutor] Learning natural language processing and Python? [learning about "stemming" words] In-Reply-To: Message-ID: <610D03F2-CB05-11D6-B699-00039351FE6A@mac.com> On Wednesday, September 18, 2002, at 01:52 AM, Danny Yoo wrote: > Stemming is used to toss out most of the variation in word endings, to > get > at the very "stem" of a word. There's an algorithm called the "Porter > Stemming Algorithm" that does interesting things to English words: > > http://www.tartarus.org/~martin/PorterStemmer/index.html > > It tries to remove the inflectional endings of English text, so it's > similar to the root-word function that's in WordNet. The page above > gives Yes, but isn't that ending needed to make sense of the word (in most cases)? NLP sounds interesting. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From magnus@thinkware.se Wed Sep 18 15:29:13 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 18 Sep 2002 16:29:13 +0200 Subject: [Tutor] refactoring book and function size In-Reply-To: <33175.65.95.67.39.1032321962.squirrel@www.xminc.com> Message-ID: <5.1.0.14.0.20020918152017.02a81958@www.thinkware.se> At 00:06 2002-09-18 -0400, Anthony Barker wrote: >I have been reading the book "Refactoring: Improving the Design of >Existing Code" it makes for a good read - particularly if you have >refactored before on a medium sized project. > >One thing I found odd is how they pull out very small bits of code and add >them to new routines. > >I am reading "Code Complete", by Steve McConnell in parallel. - he >mentions some research that larger subroutines statistically have fewer >bugs than very small ones. The research shows that routines of up to 200 >lines are not bad. > >Personally I find readability drops if you have subroutines for less than >2-3 statements. Larger routines, with purpose, clean names and simple >interfaces make understanding a program or module easier. There is a big span between 2-3 statements and 200 lines... You should realize that these people come from different backgrounds. McConnell and Code Complete refers mainly to C, and I think his research refers to typical procedural languages as well. The XP people have their roots in Smalltalk to a large degree (although I'm not sure about Martin Fowler). Both Smalltalk syntax and Object-Oriented programming in general leads to different optima. Some friends of mine listened to Fowler talking about this in Bergen two years ago, and the thing they mentioned, and that he himself even seemed a little puzzled over, was that he typically made very small methods in Java these days. On one hand, it makes each method trivial, but on the other hand, it might lead to a situation where you are a bit lost with all these methods. In Python there is also the time involved in function call overhead to consider. I suppose it might be a bit like with mathematical proofs, that you can disect a problem until each piece is trivial, solve each trivial piece, assemble the pieces, and the problem is solved without you really understanding the whole code. You're still confident in the result as you are sure that each piece is correct in itself, and correctly used. I'm sure detailed unit testing plays a big part here as well. If you are capable of simplifying the problems very much, you will probably end up with shorter routines, and a smaller program in all. You will also get fewer bugs. If you try to split large coherent functions in an artificial way without reducing complexity, just to get down line-count, I'm guessing things will just get worse. I'm sure you understand that optimal routine sizes differ differ with language. Obviously, you must be able to make some kind of point in a routine, and a very verbose language is going to require larger routines to be coherent. I've never programmed a lot in functional languages, but as far as I understand, functions in ML are typically much smaller than functions in C for instance. Actually, I had a look at an O'Caml application called GeneWeb, and out of almost 1500 routines, about 40% were no more than 10 lines, and 2.5% were more than 100 lines, the largest being 263 lines. Median lenght was 13 lines, and average was 22 LoC. (Disclaimer: I don't know O'Caml. What I did was too look at a few files, decide that the routines in these files always seems to start with a line beginning with "value", and end with a ';' in the first column of a line. Then I made a quick Python hack to count lines based on that presumption. I might be wrong, but it looks like it fits.) Actually, on closer inspection, it seems I missed 265 one line functions with my scan... Here we go again: number of functions = 1729 LoCmin = 1 LoCmax = 263 LoCmedian = 10 LoCaverage = 19 LoC<10 = 50% Loc>100 = 2.1% I would also like to claim that the kind of problem you are solving will lead to different routine sizes. I guess that advanced cryptography might be more complicated, and for that reason require larger routines, than say a business administration package. -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From erikprice@mac.com Wed Sep 18 15:44:12 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 18 Sep 2002 10:44:12 -0400 Subject: [Tutor] refactoring book and function size In-Reply-To: <5.1.0.14.0.20020918152017.02a81958@www.thinkware.se> Message-ID: <191B89D9-CB15-11D6-B699-00039351FE6A@mac.com> On Wednesday, September 18, 2002, at 10:29 AM, Magnus Lycka wrote: > On one hand, it makes each method trivial, but on the other > hand, it might lead to a situation where you are a bit lost > with all these methods. In Python there is also the time > involved in function call overhead to consider. I have often wondered about this. Are classes considered "bloated" if they feature a ton of methods to do various things with the data contained within the object? If so, is that true even if it wouldn't make sense to move some of these methods to a separate class (say, these methods are inherent behaviors that would seem best to go with the original object)? I find it easier to have a single method that does what I need than to have four methods that can be combined to do what I need (unless of course I ever have need for one of those four methods individually). It's less information about the class's interface that I need to remember. But that might not be the best approach to be taking. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From op73418@mail.telepac.pt Wed Sep 18 17:02:21 2002 From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=) Date: Wed, 18 Sep 2002 17:02:21 +0100 Subject: [Tutor] refactoring book and function size References: <5.1.0.14.0.20020918152017.02a81958@www.thinkware.se> Message-ID: <001201c25f2c$c58199c0$04150dd5@violante> > At 00:06 2002-09-18 -0400, Anthony Barker wrote: > >I have been reading the book "Refactoring: Improving the Design of > >Existing Code" it makes for a good read - particularly if you have > >refactored before on a medium sized project. > > > >One thing I found odd is how they pull out very small bits of code and add > >them to new routines. > > > >I am reading "Code Complete", by Steve McConnell in parallel. - he > >mentions some research that larger subroutines statistically have fewer > >bugs than very small ones. The research shows that routines of up to 200 > >lines are not bad. > > > >Personally I find readability drops if you have subroutines for less than > >2-3 statements. Larger routines, with purpose, clean names and simple > >interfaces make understanding a program or module easier. > > There is a big span between 2-3 statements and 200 lines... > > You should realize that these people come from different > backgrounds. McConnell and Code Complete refers mainly to > C, and I think his research refers to typical procedural > languages as well. > > The XP people have their roots in Smalltalk to a large > degree (although I'm not sure about Martin Fowler). Both > Smalltalk syntax and Object-Oriented programming in general > leads to different optima. > > Some friends of mine listened to Fowler talking about this > in Bergen two years ago, and the thing they mentioned, and > that he himself even seemed a little puzzled over, was that > he typically made very small methods in Java these days. > > On one hand, it makes each method trivial, but on the other > hand, it might lead to a situation where you are a bit lost > with all these methods. In Python there is also the time > involved in function call overhead to consider. > > I suppose it might be a bit like with mathematical proofs, > that you can disect a problem until each piece is trivial, > solve each trivial piece, assemble the pieces, and the > problem is solved without you really understanding the > whole code. You're still confident in the result as you > are sure that each piece is correct in itself, and correctly > used. I'm sure detailed unit testing plays a big part here > as well. > > If you are capable of simplifying the problems very much, > you will probably end up with shorter routines, and a > smaller program in all. You will also get fewer bugs. > > If you try to split large coherent functions in an > artificial way without reducing complexity, just to get > down line-count, I'm guessing things will just get worse. > Since my experience is in mathematics let me add here the quip of a mathematician: "Make the definitions complex and the proofs trivial" The parallel of this in programming would be something I have read somewhere, sometime long ago: "Make the data complex and the code trivial" Shift as much complexity to the data as possible seems to me a very good thumb rule. But of course, I may be way out my depth here since my largest Python program is (and although I knew a few more languages I have never done anything worth its salt with them), with all modules counted together, a little more than a measly 2 kLocs. Best regards, Gonçalo Rodrigues From jeff@ccvcorp.com Wed Sep 18 17:26:33 2002 From: jeff@ccvcorp.com (Jeff Shannon) Date: Wed, 18 Sep 2002 09:26:33 -0700 Subject: [Tutor] refactoring book and function size References: <191B89D9-CB15-11D6-B699-00039351FE6A@mac.com> Message-ID: <3D88A939.451039EA@ccvcorp.com> Erik Price wrote: > On Wednesday, September 18, 2002, at 10:29 AM, Magnus Lycka wrote: > > > On one hand, it makes each method trivial, but on the other > > hand, it might lead to a situation where you are a bit lost > > with all these methods. In Python there is also the time > > involved in function call overhead to consider. > > I have often wondered about this. Are classes considered "bloated" if > they feature a ton of methods to do various things with the data > contained within the object? If so, is that true even if it wouldn't > make sense to move some of these methods to a separate class (say, > these methods are inherent behaviors that would seem best to go with > the original object)? I would agree that it's best to organize classes according to what logically belongs together. If that ends up with a few classes being exceptionally large, then it might make sense to see if there's a different approach that would logically decompose those large classes. But it does *not* seem like a good idea to artificially separate a class that makes logical sense, strictly on the basis of code size. (If you look at GUI toolkits, the class for "window object" is invariably large and complex -- but this is such an important and complex role that it would be hard to make a case to do otherwise.) > I find it easier to have a single method that does what I need than to > have four methods that can be combined to do what I need (unless of > course I ever have need for one of those four methods individually). > It's less information about the class's interface that I need to > remember. But that might not be the best approach to be taking. One possible approach to this is to have those four methods be "private", and then have a single public method that calls them in the proper combination. That way, you have the simple interface that you desire, and yet each method implementation is small, simple, and easy to understand. In Python, the distinction between public and private methods is blurred, but still exists to some extent -- if nothing else, method names beginning with a single underscore are recognized by convention as being private, and method names beginning with two underscores are mangled with the classname to "enforce" privacy. I find it very helpful to be able to designate some methods as being "for internal use only", and some methods as "external interface". Jeff Shannon Technician/Programmer Credit International From magnus@thinkware.se Wed Sep 18 18:13:58 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 18 Sep 2002 19:13:58 +0200 Subject: [Tutor] refactoring book and function size In-Reply-To: <191B89D9-CB15-11D6-B699-00039351FE6A@mac.com> References: <5.1.0.14.0.20020918152017.02a81958@www.thinkware.se> Message-ID: <5.1.0.14.0.20020918173939.02ab5d20@www.thinkware.se> >On Wednesday, September 18, 2002, at 10:29 AM, Magnus Lycka wrote: >>On one hand, it makes each method trivial, but on the other >>hand, it might lead to a situation where you are a bit lost >>with all these methods. In Python there is also the time >>involved in function call overhead to consider. At 10:44 2002-09-18 -0400, Erik Price wrote: >I have often wondered about this. Are classes considered "bloated" if >they feature a ton of methods to do various things with the data contained >within the object? If so, is that true even if it wouldn't make sense to >move some of these methods to a separate class (say, these methods are >inherent behaviors that would seem best to go with the original object)? > >I find it easier to have a single method that does what I need than to >have four methods that can be combined to do what I need (unless of course >I ever have need for one of those four methods individually). >It's less information about the class's interface that I need to >remember. But that might not be the best approach to be taking. Short answer: It depends. Long answer: If you only need one method in the public interface of the class, please stay with one public method. You can still implement the code through several private methods. If the need arises, you can make these methods public later. You can always extend the public interface of a class, but once you have offered an interface, it's very difficult to revoke it. This is what Bertrand Meyer calls the Open-Closed principle. Arthur Riel writes in "Object-Oriented Design Heuristics" that the protocol of a class should have as few messages (i.e. methods) as possible. But again, that's the public interface, and no reason to try to do more than one thing in one implementation routine. Of cource you can distribute the implementation of your one public operation to several private or protected methods. And his counter example is a linked list class with 4000 methods... (That's more than tons, right?) Bertrand Meyer's "Object-Oriented Software Construction" ( http://www.eiffel.com/doc/manuals/technology/oosc/ ) is one of the main works on OOP. Discussing "the road to object orientation" Meyer writes about five criteria: * Decomposability * Composability * Understandability * Continuity (* Protection) "A software construction method satisfies Modular Decomposability if it helps in the task of decomposing a software problem into a small number of less complex subproblems, connected by a simple structure, and independent enough to allow further work to proceed separately on each of them." "A method satisfies Modular Composability if it favors the production of software elements which may then be freely combined with each other to produce new systems, possibly in an environment quite different from the one in which they were initially developed." "A method favors Modular Understandability if it helps produce software in which a human reader can understand each module without having to know the others, or, at worst, by having to examine only a few of the others." "A method satisfies Modular Continuity if, in the software architectures that it yields, a small change in a problem specification will trigger a change of just one module, or a small number of modules." Taken together, this means that if we have a number of tasks that are bundled into one big method since we typically perform them together, we are locked to just this behaviour. On the other hand, if we have turned every task into an independent method, a programmer utilizing our class can come up with uses we didn't ever think of. This is closely related to the Unix Philosophy: http://www.thinkware.se/cgi-bin/thinki.cgi/UnixPhilosophy B.M. continues with five rules and five principles, of which the Open-Closed principle is one. The book is roughly 1250 pages, so he says a lot more (obviously). But for instance he is very clear in stating that if a method both changes the state of the system (a procedure) and retrieves information to the caller (a function) it should be split, so that it is for instance possible to retrieve the state without changing anything in the object. The idea here is based on something else he states. I don't remember the exact wording, but he roughly writes that just as in movies that end when the hero and the pretty girl marry, some people consider the software development to end when the program is delivered. In fact, claims Meyer, this is when the fun begins... In other word, classes evolve over the life time of a program. A class should match some kind of real world object--concrete or abstract--and with time it will contain more and more features, that really match what the real world object is like. In other words, a class will (at least eventually) have a lot of generic classes that don't exactly match any distinct parts of any Use Cases that was written during the design phase (if there was one ;). Let me say that B.M. (and Riel) seems to have a very different view on OOP than for instance Ivar Jacobson, and I tent to side with B.M. See http://www.thinkware.se/cgi-bin/thinki.cgi/TheDarkSideOfUseCases and http://www.eiffel.com/doc/manuals/technology/oosc/finding/page.html#sources Returning to Refactoring, which is an XP practice, the relevant design rule in XP is "Make the simplest thing that could possibly work!" The advantage with refactoring is that we don't need to anticipate all needs in advance. Do we need to reuse part of a methods? Well, then it's time to refactor that into a separate method. I'd say that the XP approach of making the simplest thing that could possibly work is a reasonable approach for classes in a monolithic application, developed by a small number of people. It doesn't work at all in a library which is thought of as a separate product with an API used by others, for instance an OODBMS or something like PIL or ReportLab. Particularly if it's a proprietary project, but even with open source, you can't expect the application developers to redesign their underlying libraries. In these cases you need to work out a full featured interface, so that the people who use the library can make full use of it's features in ways we never imagined. XP seems to be a non-optimal methodology for such products. But I think it's a bigger problem to build the right classes, and to determine how they correlate, than to build the right methods. Let's take that another day... -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Wed Sep 18 18:25:17 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 18 Sep 2002 19:25:17 +0200 Subject: [Tutor] refactoring book and function size In-Reply-To: <3D88A939.451039EA@ccvcorp.com> References: <191B89D9-CB15-11D6-B699-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020918191609.02b1e808@www.thinkware.se> At 09:26 2002-09-18 -0700, Jeff Shannon wrote: >In Python, the distinction between public and private methods is blurred, >but still exists to some extent -- if nothing else, method names beginning >with a single underscore are recognized by convention as being private, >and method names beginning with two underscores are mangled with the >classname to "enforce" privacy. I find it very helpful to be able to >designate some methods as being "for internal use only", and some methods >as "external interface". I use the naming conventions of no leading underscore for public, one leading underscore for *protected* and double underscores for private. I use the words public, protected and private in the sense of C++, i.e. public methods are available to all, protected methods are available to sub-classes, and private methods are only available inside the defining class. I know others do this as well. On the other hand, it's rumoured that Stroustrup himself felt that private, protected and public was one protection category too many... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From darksyyyde@earthlink.net Wed Sep 18 20:46:23 2002 From: darksyyyde@earthlink.net (darksyyyde) Date: Wed, 18 Sep 2002 13:46:23 -0600 Subject: [Tutor] Tkinter + OSX Message-ID: <4FC1B33A-CB3F-11D6-87FF-000A2792FECC@earthlink.net> Im running OSX 10.1.3, and i have 'fink' installed. Under Python help, it show TKinter as one of the modules, but the module is not present apparently. >>> import _tkinter Traceback (most recent call last): File "", line 1, in ? ImportError: No module named _tkinter When trying to install python with fink, i got... The following package will be installed or updated: python The following 5 additional packages will be installed: db3 expat gdbm gmp readline Do you want to continue? [Y/n] y rm -rf db3-3.3.11-2 mkdir -p /macunix/src/db3-3.3.11-2 tar -xvzf /macunix/src/db-3.3.11.tar.gz gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error exit delayed from previous errors ### tar failed, exit code 2 Unpacking the tarball db-3.3.11.tar.gz of package db3-3.3.11-2 failed. The most likely cause for this is a corrupted or incomplete download. Do you want to delete the tarball and download it again? [Y/n] y This would just happen over and over, no matter how many times i entered 'y'. I pulled the tar.gz file out of the fink subdirectory ( or copied it ) to the local directory that i made for python. I then unpacked it with stufit expander. As you can see, i was able to setup and make python this way, but theres no TKinter. I suppose i should ask if TKinter is even operable under MacOSX... is it? /me scratches head. From dyoo@hkn.eecs.berkeley.edu Wed Sep 18 21:38:56 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 18 Sep 2002 13:38:56 -0700 (PDT) Subject: [Tutor] Tkinter + OSX In-Reply-To: <4FC1B33A-CB3F-11D6-87FF-000A2792FECC@earthlink.net> Message-ID: On Wed, 18 Sep 2002, darksyyyde wrote: > Im running OSX 10.1.3, and i have 'fink' installed. Under Python help, > it show TKinter as one of the modules, but the module is not present > apparently. Hello! This looks like a fink-specific packaging problem; I'm not sure if anyone here can help with that. There is a page here: http://people.ucsc.edu/~jacobkm/tkinter_osx_howto.html that appears to apply to OS X; it looks like you may need to update Fink's configuration to pull "unstable/main" into Fink's package tree. The instructions on the page are fairly unambiguous, but doesn't say what to do if things go horribly wrong. For that, you may want to ask on the pythonmac-sig mailing list; I'm sure someone there can help you: http://www.python.org/sigs/pythonmac-sig/ >From reading the archives, it sounds like Tkinter is still somewhat experimental: http://mail.python.org/pipermail/pythonmac-sig/2002-August/005955.html so you definitely should get in touch with the pythonmac-sig for more authoritative answers. I hope that this helps! From cyberdiction@hotmail.com Wed Sep 18 21:49:26 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Wed, 18 Sep 2002 13:49:26 -0700 Subject: [Tutor] Learning natural language processing and Python? [learning about "stemming" words] References: Message-ID: ----- Original Message ----- From: "Danny Yoo" To: "Tutor" Sent: Tuesday, September 17, 2002 10:52 PM Subject: [Tutor] Learning natural language processing and Python? [learning about "stemming" words] > Hi everyone, > > I'm starting to learn "Natural Language Processing", which tries to use a > computer to tease meaning out of natural language. I was wondering if > anyone was interested in this sort of thing? > I have been interested in Artificial Intelligence (AI). Natural language translation is almost the same challenge as a Turing test passing AI program. The CyC project took about 18 years to get to its present level of success. http://www.cyc.com/nl.html The Cyc NL Subsystem The Cyc-NL system can be described in terms of its three primary components, although in truth there are many other utilities that contribute to its success. The three main components are the lexicon, the syntactic parser, and the semantic interpreter. There is speech dictation software. Let us suppose we want to check some text we have dictated for spelling and grammar errors. There are words which sound alike but are spelled differently which will not be highligted by the spelling and grammar checkers. This is where an AI type meaning checker with associated correct spelling enters the picture. These work fairly well for concrete levels of thinking; they require apprehending the meaning but not necessarily creating a sense of identity or personhood required of the Turing test passing program. As meaning becomes more abstract, there is a corresponding increase in ambiguity which means the filter tree of inference rules can become confused. So poetry that is translated from English to Russian and then back, is pretty garbled. I think it would be worse from English to Russian to French. The metaphors become quite complex and the common-sense rules of analogy require a lot of relational sophistication working on a very large set of facts. I'm speaking about why some translations of The Illiad are recognized as "gifted" and other translators are too literal or dont quite grasp the meaning of the author. For instance when Homer writes about some wisdom that old age brings, that idea will be better translated by the translator who has experienced that realization. So how does one write rules that represent a mature point of view in varying contexts?! Phrases like "which way does the wind blow" have layers of meaning depending on context. There are some phrases in every natural language which do not have literal translation into another language. So the meaning has to be captured before it can be rendered appropriately. Like altavista translation just works well enough so that you can usually fill in the %$#$ words. Anyway, I wrote because you seemed to have a mildly dabbling attitude about a project that I think would take a lot of time to create anything useful. The CyC webpage has more on theory. Best regards, Stephen From sarmstrong@shearwatercorp.com Wed Sep 18 23:00:08 2002 From: sarmstrong@shearwatercorp.com (SA) Date: Wed, 18 Sep 2002 17:00:08 -0500 Subject: [Tutor] Tkinter + OSX In-Reply-To: Message-ID: First try this at the command line: %which python If your reply is /sw/bin/python or something dimilar from the /sw directory then fink screwed up. If the reply is /usr/bin/python then you do not have you environment setup properly because it is not recognizing apps from /sw/bin. Once /sw/bin is in your path you should remove any trace of python from usr/bin and usr/lib then you can setup the default python to be from /sw/bin instead of /usr/bin. This is the issue you will encounter when using fink. All your apps are installed under /sw/bin. I wish the fink developers would come up with a way to add this to your PATH automatically. But alas ... Anyways. 10.2 has python installed natively and I heard it has Tk and Tcl installed by default also but I get the same error. What this error is saying is that Tk is not installed properly because python cant find it? There are some sites out there that explain how to install TK/Tcl and there is a MacOSX release for this, but I never got it to work right under 10.1 so I had to resort to the fink method also. It works if you are running under XDarwin so it really is not native. Hopefully the mac-python group will get it together and switch to OSX so that some progress can be made in this direction. They are still the python with Tkinter support for OS9. Oh well, one can wish... You could always use jython and use the built in java on OSX. Other than that it is still a PC world for Pythoneers. Unless you feel like hacking it together. Good Luck. SA On Wednesday, September 18, 2002, at 03:38 PM, Danny Yoo wrote: > > > On Wed, 18 Sep 2002, darksyyyde wrote: > >> Im running OSX 10.1.3, and i have 'fink' installed. Under Python help, >> it show TKinter as one of the modules, but the module is not present >> apparently. > > Hello! This looks like a fink-specific packaging problem; I'm not > sure if > anyone here can help with that. There is a page here: > > http://people.ucsc.edu/~jacobkm/tkinter_osx_howto.html > > that appears to apply to OS X; it looks like you may need to update > Fink's > configuration to pull "unstable/main" into Fink's package tree. The > instructions on the page are fairly unambiguous, but doesn't say what > to > do if things go horribly wrong. > > > > For that, you may want to ask on the pythonmac-sig mailing list; I'm > sure > someone there can help you: > > http://www.python.org/sigs/pythonmac-sig/ > > From reading the archives, it sounds like Tkinter is still somewhat > experimental: > > > http://mail.python.org/pipermail/pythonmac-sig/2002-August/005955.html > > so you definitely should get in touch with the pythonmac-sig for more > authoritative answers. > > > I hope that this helps! > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From dyoo@hkn.eecs.berkeley.edu Wed Sep 18 23:04:51 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 18 Sep 2002 15:04:51 -0700 (PDT) Subject: [Tutor] Learning natural language processing and Python? [why NLP?] In-Reply-To: Message-ID: On Wed, 18 Sep 2002, Stephen Harris wrote: > As meaning becomes more abstract, there is a corresponding increase in > ambiguity which means the filter tree of inference rules can become > confused. So poetry that is translated from English to Russian and then > back, is pretty garbled. I think it would be worse from English to > Russian to French. > [some text cut] Thankfully, the text documents I'm thinking about processing have very little poetry. *grin* The problem that I really want to work on is to automatically "categorize" technical documents, where the language is hopefully less ambiguous than free verse. Automatic document classification appears to be slightly less hard than AI. A few posts back, someone mentioned the 'spambayes' classifer as a program that detects spam. Spam has a specific "scent" that we can pick out. But why stop at spam? Ultimately, the idea I have is to put automatic classification to a more constructive use: I'd like to categorize Python-Tutor postings so that messages can be searched by topic. > Anyway, I wrote because you seemed to have a mildly dabbling attitude > about a project that I think would take a lot of time to create anything > useful. The CyC webpage has more on theory. Yes, I do dabble a lot. *grin* Don't worry: I know I should try to avoid reinventing the wheel. I'm just trying to build up my own general knowledge, just enough so I can understand 'spambayes' and other classification systems. I don't plan to do anything serious. (Perhaps the easiest thing to try is to run multiple copies of spambayes, and just give each copy different training sets! Hmmm...) Good luck to you! From cyberdiction@hotmail.com Thu Sep 19 02:38:14 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Wed, 18 Sep 2002 18:38:14 -0700 Subject: [Tutor] Learning natural language processing and Python? [why NLP?] References: Message-ID: ----- Original Message ----- From: "Danny Yoo" To: "Stephen Harris" Cc: "Tutor" Sent: Wednesday, September 18, 2002 3:04 PM Subject: Re: [Tutor] Learning natural language processing and Python? [why NLP?] > > > On Wed, 18 Sep 2002, Stephen Harris wrote: > > > As meaning becomes more abstract, there is a corresponding increase in > > ambiguity which means the filter tree of inference rules can become > > confused. So poetry that is translated from English to Russian and then > > back, is pretty garbled. I think it would be worse from English to > > Russian to French. > > > [some text cut] > > Thankfully, the text documents I'm thinking about processing have very > little poetry. *grin* > > The problem that I really want to work on is to automatically "categorize" > technical documents, where the language is hopefully less ambiguous than > free verse. Automatic document classification appears to be slightly less > hard than AI. > > > A few posts back, someone mentioned the 'spambayes' classifer as a program > that detects spam. Spam has a specific "scent" that we can pick out. > > But why stop at spam? Ultimately, the idea I have is to put automatic > classification to a more constructive use: I'd like to categorize > Python-Tutor postings so that messages can be searched by topic. > > > > Anyway, I wrote because you seemed to have a mildly dabbling attitude > > about a project that I think would take a lot of time to create anything > > useful. The CyC webpage has more on theory. > > Yes, I do dabble a lot. *grin* > > Don't worry: I know I should try to avoid reinventing the wheel. I'm just > trying to build up my own general knowledge, just enough so I can > understand 'spambayes' and other classification systems. I don't plan to > do anything serious. > > (Perhaps the easiest thing to try is to run multiple copies of spambayes, > and just give each copy different training sets! Hmmm...) > > > > Good luck to you! > I think CyC has maybe a million common sense rules, whereas other NL translators are more statistical. I noticed that they have an open source project also. OpenCyC http://www.opencyc.org/doc/#OpenCyc_Intro PyWordNet (for Wordnet in Python) provides some kind of conceptual intersection with the CyC Wordnet Interface(also SourceForge sponsee): "WordNet is very large English lexical database in which words are organized into synonym sets, or "synsets". Many existing natural language processing systems make use of the WordNet database. The Cyc-WordNet Linking Tool allows users to state links between WordNet synsets and Cyc constants. The interface also allows the user to browse WordNet, and to see existing Cyc-WordNet links." SH: And in reference to your remark: > "I'd like to categorize Python-Tutor > postings so that messages can be searched by topic." http://www.cyc.com/cycdoc/ref/nl.html Lexical Ambiguity and Polysemy The majority of the most common words in English have multiple meanings: "bat", "bank", "table", "can", "will", etc. In applications such as machine translation and document indexing/retrieval, it is crucial to be able to figure out which meaning of an ambiguous word is intended. For example, if a user queries a text database for "bats and other small mammals", a standard Boolean search engine will also deliver documents about baseball bats, even though it is obvious to any reasonable human that this is not what the querier intended. The background knowledge in Cyc can be used in attempting to choose the most appropriate meaning of a word in context. (SH: Google "I feel lucky") Syntactic Ambiguity Syntactic ambiguity occurs when an input string has more than one possible syntactic structure. Coreference Resolution In interpreting text, new pieces of information must be integrated with what has been mentioned before. A pronoun may be used to refer back to something already in the universe of discourse. SH: I certainly agree that a search engine identifying what information is wanted from surrounding text context is like identifying spam from surrounding context! Unfortunately, though the OpenCyc download is free, I think it makes use of Lisp. SubL Reference SubL is a computer language built by members of Cycorp. SubL was written to support the CYC application, allowing it to run both under Lisp environments and as a C application generated by a SubL-to-C translator. The OpenCyc Knowledge Server comes with a built-in SubL interpreter, and SubL is also available through an API port, supporting server-side scripting. This describes the primitive functions of SubL.(SH: I think translating between programming languages is similar too.) This commercial product is still under development: CycAnswers CycAnswers is an integrated knowledge management and question-answering application that has the ability to handle large volumes of questions automatically and intelligently. CycAnswers responds to questions with precise and complete answers, by actually reasoning about them, drawing on formally represented knowledge from disparate sources. CycAnswers monitors the state of its knowledge base to spot inconsistencies or incompleteness before they become a cause of customer dissatisfaction. Highlights of the CycAnswers product include: Seamlessly integrates knowledge and data bases Supports user profiles Automatically analyzes unanswered questions and recommends appropriate repairs and/or extensions Supports sophisticated information retrieval when questions cannot be directly answered Each CycAnswers solution is constructed from a modular set of components, including: Danny, I truly believe that the title "Ontological Engineer" would adorn your resume with prestige. As a Sanitation Engineer, the OE title fills me with puissant intellectual/olfactory envy! Best regards, Stinky Stevie From darksyyyde@earthlink.net Thu Sep 19 06:51:02 2002 From: darksyyyde@earthlink.net (darksyyyde) Date: Wed, 18 Sep 2002 23:51:02 -0600 Subject: [Tutor] Tkinter + OSX In-Reply-To: <20020919014101.20410.60778.Mailman@mail.python.org> Message-ID: On Wednesday, September 18, 2002, at 07:41 PM, tutor-request@python.org wrote: > > > > > --__--__-- > > --__--__-- > > Message: 7 > Date: Wed, 18 Sep 2002 17:00:08 -0500 > Subject: Re: [Tutor] Tkinter + OSX > From: SA > To: Tutor > > First try this at the command line: > %which python > > If your reply is /sw/bin/python or something dimilar from the /sw > directory then fink screwed up. > No, i made a /usr/local/bin before config and make %wich python -- reflects it correctly. > If the reply is /usr/bin/python then you do not have you environment > setup properly because it is not recognizing apps from /sw/bin. Once > /sw/bin is in your path you should remove any trace of python from > usr/bin and usr/lib then you can setup the default python to be from > /sw/bin instead of /usr/bin. This is the issue you will encounter when > using fink. All your apps are installed under /sw/bin. I wish the fink > developers would come up with a way to add this to your PATH > automatically. But alas ... > The thing is, the fink/gzip wouldnt work. so i pulled the tar.gz via gui out of fink and into my /usr/local/bin. Then just unzipped it with stufit expander. Then opened terminal and set up the directory. Then ./configure. Then %sudo make install. Ill see what the mac pythoneers have to say about it. I appreciate the responses here though. > Anyways. 10.2 has python installed natively and I heard it has Tk and > Tcl installed by default also but I get the same error. What this error > is saying is that Tk is not installed properly because python cant find > it? > > There are some sites out there that explain how to install TK/Tcl and > there is a MacOSX release for this, but I never got it to work right > under 10.1 so I had to resort to the fink method also. It works if you > are running under XDarwin so it really is not native. Hopefully the > mac-python group will get it together and switch to OSX so that some > progress can be made in this direction. They are still the python with > Tkinter support for OS9. Oh well, one can wish... > fink installed tcl/tk just fine. However its not in the same directory as python. > You could always use jython and use the built in java on OSX. That would be kind of cool. I know very little about it though. Is it a half breed between java and python, or just python that can import/ use java classes etc. ? > > Other than that it is still a PC world for Pythoneers. Unless you feel > like hacking it together. > Why couldnt python use/import the project builder files used for templates of cocoa(objective C) applications? Then mac people wouldnt even have to worry about tkinter. > Good Luck. > SA > > On Wednesday, September 18, 2002, at 03:38 PM, Danny Yoo wrote: > >> >> >> On Wed, 18 Sep 2002, darksyyyde wrote: >> >>> Im running OSX 10.1.3, and i have 'fink' installed. Under Python help, >>> it show TKinter as one of the modules, but the module is not present >>> apparently. >> >> Hello! This looks like a fink-specific packaging problem; I'm not >> sure if >> anyone here can help with that. There is a page here: >> >> http://people.ucsc.edu/~jacobkm/tkinter_osx_howto.html >> >> that appears to apply to OS X; it looks like you may need to update >> Fink's >> configuration to pull "unstable/main" into Fink's package tree. The >> instructions on the page are fairly unambiguous, but doesn't say what >> to >> do if things go horribly wrong. >> >> >> >> For that, you may want to ask on the pythonmac-sig mailing list; I'm >> sure >> someone there can help you: >> >> http://www.python.org/sigs/pythonmac-sig/ >> >> From reading the archives, it sounds like Tkinter is still somewhat >> experimental: >> >> >> http://mail.python.org/pipermail/pythonmac-sig/2002-August/005955.html >> >> so you definitely should get in touch with the pythonmac-sig for more >> authoritative answers. >> >> >> I hope that this helps! >> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor >> > > > > --__--__-- > > Message: 8 > Date: Wed, 18 Sep 2002 15:04:51 -0700 (PDT) > From: Danny Yoo > To: Stephen Harris > cc: Tutor > Subject: Re: [Tutor] Learning natural language processing and Python? > [why > NLP?] > > > > On Wed, 18 Sep 2002, Stephen Harris wrote: > >> As meaning becomes more abstract, there is a corresponding increase in >> ambiguity which means the filter tree of inference rules can become >> confused. So poetry that is translated from English to Russian and then >> back, is pretty garbled. I think it would be worse from English to >> Russian to French. >> > [some text cut] > > Thankfully, the text documents I'm thinking about processing have very > little poetry. *grin* > > The problem that I really want to work on is to automatically "categorize" > technical documents, where the language is hopefully less ambiguous than > free verse. Automatic document classification appears to be slightly less > hard than AI. > > > A few posts back, someone mentioned the 'spambayes' classifer as a program > that detects spam. Spam has a specific "scent" that we can pick out. > > But why stop at spam? Ultimately, the idea I have is to put automatic > classification to a more constructive use: I'd like to categorize > Python-Tutor postings so that messages can be searched by topic. > > >> Anyway, I wrote because you seemed to have a mildly dabbling attitude >> about a project that I think would take a lot of time to create anything >> useful. The CyC webpage has more on theory. > > Yes, I do dabble a lot. *grin* > > Don't worry: I know I should try to avoid reinventing the wheel. I'm just > trying to build up my own general knowledge, just enough so I can > understand 'spambayes' and other classification systems. I don't plan to > do anything serious. > > (Perhaps the easiest thing to try is to run multiple copies of spambayes, > and just give each copy different training sets! Hmmm...) > > > > Good luck to you! > > > > --__--__-- > > Message: 9 > From: "Stephen Harris" > To: "Danny Yoo" > Cc: "Tutor" > Subject: Re: [Tutor] Learning natural language processing and Python? > [why NLP?] > Date: Wed, 18 Sep 2002 18:38:14 -0700 > > > ----- Original Message ----- > From: "Danny Yoo" > To: "Stephen Harris" > Cc: "Tutor" > Sent: Wednesday, September 18, 2002 3:04 PM > Subject: Re: [Tutor] Learning natural language processing and Python? [why > NLP?] > > >> >> >> On Wed, 18 Sep 2002, Stephen Harris wrote: >> >>> As meaning becomes more abstract, there is a corresponding increase in >>> ambiguity which means the filter tree of inference rules can become >>> confused. So poetry that is translated from English to Russian and then >>> back, is pretty garbled. I think it would be worse from English to >>> Russian to French. >>> >> [some text cut] >> >> Thankfully, the text documents I'm thinking about processing have very >> little poetry. *grin* >> >> The problem that I really want to work on is to automatically >> "categorize" >> technical documents, where the language is hopefully less ambiguous than >> free verse. Automatic document classification appears to be slightly >> less >> hard than AI. >> >> >> A few posts back, someone mentioned the 'spambayes' classifer as a >> program >> that detects spam. Spam has a specific "scent" that we can pick out. >> >> But why stop at spam? Ultimately, the idea I have is to put automatic >> classification to a more constructive use: I'd like to categorize >> Python-Tutor postings so that messages can be searched by topic. >> >> >>> Anyway, I wrote because you seemed to have a mildly dabbling attitude >>> about a project that I think would take a lot of time to create anything >>> useful. The CyC webpage has more on theory. >> >> Yes, I do dabble a lot. *grin* >> >> Don't worry: I know I should try to avoid reinventing the wheel. I'm >> just >> trying to build up my own general knowledge, just enough so I can >> understand 'spambayes' and other classification systems. I don't plan to >> do anything serious. >> >> (Perhaps the easiest thing to try is to run multiple copies of spambayes, >> and just give each copy different training sets! Hmmm...) >> >> >> >> Good luck to you! >> > > I think CyC has maybe a million common sense rules, whereas other NL > translators are more statistical. I noticed that they have an open source > project also. OpenCyC http://www.opencyc.org/doc/#OpenCyc_Intro > > PyWordNet (for Wordnet in Python) provides some kind of conceptual > intersection with the CyC Wordnet Interface(also SourceForge sponsee): > > "WordNet is very large English lexical database in which words are > organized > into synonym sets, or "synsets". Many existing natural language processing > systems make use of the WordNet database. The Cyc-WordNet Linking > Tool allows users to state links between WordNet synsets and Cyc > constants. > The interface also allows the user to browse WordNet, and to see existing > Cyc-WordNet links." > > SH: And in reference to your remark: > "I'd like to categorize > Python-Tutor >> postings so that messages can be searched by topic." > > http://www.cyc.com/cycdoc/ref/nl.html > Lexical Ambiguity and Polysemy > The majority of the most common words in English have multiple meanings: > "bat", "bank", "table", "can", "will", etc. In applications such as > machine > translation and document indexing/retrieval, it is crucial to be able to > figure > out which meaning of an ambiguous word is intended. For example, if a user > queries a text database for "bats and other small mammals", a standard > Boolean > search engine will also deliver documents about baseball bats, even though > it is > obvious to any reasonable human that this is not what the querier > intended. > The background knowledge in Cyc can be used in attempting to choose the > most appropriate meaning of a word in context. (SH: Google "I feel lucky" > ) > > Syntactic Ambiguity > Syntactic ambiguity occurs when an input string has more than one possible > syntactic structure. > > Coreference Resolution > In interpreting text, new pieces of information must be integrated with > what > has been mentioned before. A pronoun may be used to refer back to > something > already in the universe of discourse. > > SH: I certainly agree that a search engine identifying what information is > wanted > from surrounding text context is like identifying spam from surrounding > context! > Unfortunately, though the OpenCyc download is free, I think it makes use > of > Lisp. > > SubL Reference > SubL is a computer language built by members of Cycorp. SubL was written > to > support the CYC application, allowing it to run both under Lisp > environments > and > as a C application generated by a SubL-to-C translator. The OpenCyc > Knowledge > Server comes with a built-in SubL interpreter, and SubL is also available > through an > API port, supporting server-side scripting. This describes the > primitive > functions of SubL.(SH: I think translating between programming languages > is > similar too.) > > This commercial product is still under development: > > CycAnswers > > CycAnswers is an integrated knowledge management and question-answering > application > that has the ability to handle large volumes of questions automatically > and > intelligently. > CycAnswers responds to questions with precise and complete answers, by > actually > reasoning about them, drawing on formally represented knowledge from > disparate sources. > > CycAnswers monitors the state of its knowledge base to spot > inconsistencies > or > incompleteness before they become a cause of customer dissatisfaction. > > Highlights of the CycAnswers product include: > > Seamlessly integrates knowledge and data bases > Supports user profiles > Automatically analyzes unanswered questions and recommends appropriate > repairs > and/or extensions > Supports sophisticated information retrieval when questions cannot be > directly answered > Each CycAnswers solution is constructed from a modular set of components, > including: > > Danny, I truly believe that the title "Ontological Engineer" would adorn > your resume with > prestige. As a Sanitation Engineer, the OE title fills me with puissant > intellectual/olfactory envy! > > Best regards, > Stinky Stevie > > > > --__--__-- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest > From dyoo@hkn.eecs.berkeley.edu Thu Sep 19 08:48:52 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 19 Sep 2002 00:48:52 -0700 (PDT) Subject: [Tutor] Tkinter + OSX In-Reply-To: Message-ID: On Wed, 18 Sep 2002, darksyyyde wrote: > > using fink. All your apps are installed under /sw/bin. I wish the fink > > developers would come up with a way to add this to your PATH > > automatically. But alas ... > > > > The thing is, the fink/gzip wouldnt work. > so i pulled the tar.gz via gui out of fink and into my /usr/local/bin. > Then just unzipped it with stufit expander. Ah! I think this may be a problem: stuffit expander, according to the Fink folks, is not a good thing to use because it doesn't understand long file names: """It is important that you don't use StuffIt Expander to extract the tar archive. For some reason StuffIt still can't handle long file names. If StuffIt Expander already extracted the archive, throw away the folder it created...""" http://fink.sourceforge.net/doc/users-guide/install.php And discussion on pythonmac-sig appears to echo the warning: http://mail.python.org/pipermail/pythonmac-sig/2002-January/004911.html http://redivi.com/~bob/ Someone feels very strongly about this, as the second link uses a honking huge H1 header with a stuffit warning. *grin* > Then opened terminal and set up the directory. Then ./configure. > Then %sudo make install. > Ill see what the mac pythoneers have to say about it. > I appreciate the responses here though. When you do get it working, can you send all of us a followup so that we can better help the next person with OS X / Tkinter problems? I wish you the best of luck on this; installation problems always stink. From erikprice@mac.com Thu Sep 19 12:56:47 2002 From: erikprice@mac.com (Erik Price) Date: Thu, 19 Sep 2002 07:56:47 -0400 Subject: [Tutor] Tkinter + OSX In-Reply-To: Message-ID: On Wednesday, September 18, 2002, at 06:00 PM, SA wrote: > Anyways. 10.2 has python installed natively and I heard it has Tk and > Tcl installed by default also but I get the same error. What this > error is saying is that Tk is not installed properly because python > cant find it? I haven't tried it yet myself, but from what I understand, the Tk libraries are not yet ready for Aqua. So, there are two things you can do: 1. [Use Fink to] install the X11 Window System (use xfree86-base package from Fink, I think) and then install the Tk libraries to use X11 2. Do your homework on the Aqua Tk libraries and find out how to install them. I read that Apple was helping with the development, so you might want to search http://developer.apple.com/ Good luck, and let us know if you get it going. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From s.nelick@verizon.net Thu Sep 19 14:33:36 2002 From: s.nelick@verizon.net (Steve Nelick) Date: Thu, 19 Sep 2002 09:33:36 -0400 Subject: [Tutor] Python and Messaging Message-ID: <000e01c25fe1$28854c60$6401a8c0@pc933> This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C25FBF.A0F50680 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Can you use Python for voice messaging? I was using a PC and Microsoft Flight Simulator (multiplayer mode), and = Microsoft Net Meeting (with a microphone) . When I upgraded my computer = to Microsoft XP, the Flight Simulator and Net Meeting could not be used = together. So, I need software that I can use for the voice messaging, = while the Flight Simulator is running. Has anybody seen a book with a Python sample program that does voice = messaging? ------=_NextPart_000_000B_01C25FBF.A0F50680 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Can you use Python for voice=20 messaging?
 
I was using a PC and Microsoft Flight = Simulator=20 (multiplayer mode), and Microsoft Net Meeting (with a microphone) . = When I=20 upgraded my computer to Microsoft XP, the Flight Simulator and Net = Meeting could=20 not be used together. So, I need software that I can use for the voice=20 messaging, while the Flight Simulator is running.
 
Has anybody seen a book with a Python = sample=20 program that does voice messaging?
------=_NextPart_000_000B_01C25FBF.A0F50680-- From lsloan@umich.edu Thu Sep 19 14:43:51 2002 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 19 Sep 2002 09:43:51 -0400 Subject: [Tutor] Tkinter + OSX In-Reply-To: References: Message-ID: <1322517.1032428631@[10.0.1.2]> --On Wednesday, September 18, 2002 17:00 -0500 SA wrote: > Anyways. 10.2 has python installed natively and I heard it has Tk and Tcl > installed by default also but I get the same error. What this error is > saying is that Tk is not installed properly because python cant find it? Yes, MOSX 10.2 (AKA Jaguar) has Python and Tcl installed. But I can't tell if Tk is installed. I'm no Tcl/Tk expert, but I think it's not. But even if it were, Python wasn't compiled with the Tk libs, so Tkinter *still* isn't available. IMNSHO, Apple should make some X11 caompatibility libraries that just map X11 function calls to the appropriate Aqua ones. But then, I don't know all about the differences between X11 and Aqua. It may be a lot harder than I think. > There are some sites out there that explain how to install TK/Tcl and > there is a MacOSX release for this, but I never got it to work right > under 10.1 so I had to resort to the fink method also. It works if you > are running under XDarwin so it really is not native. Hopefully the I've almost succumbed to Fink and XDarwin. But I've recently come across some new (new to me, anyway) web pages about Tkinter and OSX, so I'm going to give them a look soon. If I ever get it working on my machine, I'm going to be so happy that I'll probably tell everybody on this list about it. :) -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From steve_lewis@openiso.com Thu Sep 19 17:02:57 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Thu, 19 Sep 2002 11:02:57 -0500 (CDT) Subject: [Tutor] Bayespam...questions? Message-ID: <4129.199.66.1.5.1032451377.squirrel@www.absolutenettech.com> Hello list, I have downloaded the bayespam from sourceforge, when unzipped it leaves a file with the extension .pik. For the life of me, i cant find a reference to that extension in any of my online sources. Need help. What is the extension and a pointer or two on how to use it for spam protection. thanks Steve Lewis From dyoo@CSUA.Berkeley.EDU Thu Sep 19 17:41:50 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Thu, 19 Sep 2002 09:41:50 -0700 (PDT) Subject: [Tutor] Bayespam...questions? In-Reply-To: <4129.199.66.1.5.1032451377.squirrel@www.absolutenettech.com> Message-ID: <20020919093702.R22180-100000@soda.csua.berkeley.edu> On Thu, 19 Sep 2002, Steve Lewis wrote: > I have downloaded the bayespam from sourceforge, when unzipped it leaves > a file with the extension .pik. For the life of me, i cant find a > reference to that extension in any of my online sources. Need help. What > is the extension and a pointer or two on how to use it for spam > protection. thanks Hi Steve, Bayespam is a spam filter for Qmail: http://sourceforge.net/projects/bayespam/ But it's written in Perl, not Python! You may be confusing this with 'spambayes', which is the Python spam filter mentioned a few days ago. http://sourceforge.net/projects/spambayes Your best bet for an answer to that 'pik' file is to contact the Bayespam people instead: http://sourceforge.net/forum/?group_id=61862 From erikprice@mac.com Thu Sep 19 18:04:20 2002 From: erikprice@mac.com (Erik Price) Date: Thu, 19 Sep 2002 13:04:20 -0400 Subject: [Tutor] Bayespam...questions? In-Reply-To: <20020919093702.R22180-100000@soda.csua.berkeley.edu> Message-ID: On Thursday, September 19, 2002, at 12:41 PM, Daniel Yoo wrote: > Your best bet for an answer to that 'pik' file is to contact the > Bayespam > people instead: > > http://sourceforge.net/forum/?group_id=61862 I thought that ".pik" files were (generally) files written to by the pickle module. The "spambayes" sourceforge project consists of a single file (which is a Python pickled dictionary). I think. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From dyoo@CSUA.Berkeley.EDU Thu Sep 19 18:07:20 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Thu, 19 Sep 2002 10:07:20 -0700 (PDT) Subject: [Tutor] Learning natural language processing and Python? [learning about "stemming" words] In-Reply-To: <610D03F2-CB05-11D6-B699-00039351FE6A@mac.com> Message-ID: <20020919094853.P23312-100000@soda.csua.berkeley.edu> On Wed, 18 Sep 2002, Erik Price wrote: > > On Wednesday, September 18, 2002, at 01:52 AM, Danny Yoo wrote: > > > Stemming is used to toss out most of the variation in word endings, to > > get > > at the very "stem" of a word. There's an algorithm called the "Porter > > Stemming Algorithm" that does interesting things to English words: > > > > http://www.tartarus.org/~martin/PorterStemmer/index.html > > > > It tries to remove the inflectional endings of English text, so it's > > similar to the root-word function that's in WordNet. The page above > > gives > > Yes, but isn't that ending needed to make sense of the word (in most > cases)? In English, the suffix might not be so important. We many want to say that the following words are related to each other: ### >>> import porter >>> p = porter.PorterStemmer() >>> def stem(word): return p.stem(word, 0, len(word) - 1) ... >>> map(stem, ['processed', 'procession', 'processing']) ['process', 'process', 'process'] ### So a stemmer isn't meant to preserve information: it is meant to throw away word endings. For certain purposes, dropping this information is good: for example, if we were to index a document for searching, stemming the whole document makes it easier to account for English variation. If we had a whole collection of scientific documents, and we were to look for the term 'proteasome regulatory particle', we want to make sure we can still retrieve results if we type 'proteasome regulation'. At least, that's how I'm understanding stemming at the moment... *grin* From dyoo@CSUA.Berkeley.EDU Thu Sep 19 18:14:44 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Thu, 19 Sep 2002 10:14:44 -0700 (PDT) Subject: [Tutor] Bayespam...questions? (fwd) Message-ID: <20020919101055.J27658-100000@soda.csua.berkeley.edu> Hi Steve, I haven't had the opportunity to work with bayesian filters yet. spambayes is being actively developed, but hasn't been nicely packaged or documented yet. Let me forward your question to the other Tutors; perhaps someone there can better answer your questions! ---------- Forwarded message ---------- Date: Thu, 19 Sep 2002 12:08:06 -0500 (CDT) From: Steve Lewis Reply-To: steve_lewis@openiso.com To: dyoo@CSUA.Berkeley.EDU Subject: Re: [Tutor] Bayespam...questions? sorry daniel, sorry, my goof. apparently spambayes does not have any downloadable code yet, am i correct? have you used or done any work with this. i am very intrigued with the concept of bayesian type probabilty filters. thanks, steve lewis > > > On Thu, 19 Sep 2002, Steve Lewis wrote: > >> I have downloaded the bayespam from sourceforge, when unzipped it >> leaves a file with the extension .pik. For the life of me, i cant find >> a reference to that extension in any of my online sources. Need help. >> What is the extension and a pointer or two on how to use it for spam >> protection. thanks > > > Hi Steve, > > Bayespam is a spam filter for Qmail: > > http://sourceforge.net/projects/bayespam/ > > But it's written in Perl, not Python! You may be confusing this with > 'spambayes', which is the Python spam filter mentioned a few days ago. > > http://sourceforge.net/projects/spambayes > > > Your best bet for an answer to that 'pik' file is to contact the > Bayespam people instead: > > http://sourceforge.net/forum/?group_id=61862 From rob@zoism.org Thu Sep 19 21:16:19 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 20 Sep 2002 08:16:19 +1200 Subject: [Tutor] Question about socket connections In-Reply-To: <3D8761F6.9040108@shrestha.net.np> References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> <1032243156.4428.9.camel@caspian.everglade> <3D8761F6.9040108@shrestha.net.np> Message-ID: <1032466576.1946.11.camel@caspian.everglade> On Wed, 2002-09-18 at 05:10, Ashish Shrestha wrote: > why don't you check out xmlrpc at http://www.xmlrpc.com > > get a python implementation from http://www.pythonware.com I have looked at xmlrpc, and it works fine for a server but being based on the socket server module is not really suitable for communication between gui apps, at least in my opinion. The problem comes from it spawning a new instance of the handler calls for each request. So the handler needs to then talk to the app, to do that it needs to have the app reference passed to it, and this has to be passed to the server object to pass to the handler object and it just starts to look messy which to me means it's not a good solution. And then there is the triplicate problem, the client needs a routine to ask the server, which needs a routine to ask the app which needs a routine to do the task for every thing, and then to the clients the clients need their own server and so on, I havent done anything about it for over a week, but I am planning on looking at spread which some one mentiond here, -- * * Rob Brown-Bayliss * From tutor@python.org Thu Sep 19 21:36:28 2002 From: tutor@python.org (Tim Peters) Date: Thu, 19 Sep 2002 16:36:28 -0400 Subject: [Tutor] Bayespam...questions? In-Reply-To: <4129.199.66.1.5.1032451377.squirrel@www.absolutenettech.com> Message-ID: [Steve Lewis] > I have downloaded the bayespam from sourceforge, when unzipped it leaves a > file with the extension .pik. For the life of me, i cant find a reference > to that extension in any of my online sources. Need help. What is the > extension and a pointer or two on how to use it for spam protection. The file is a binary pickle of a classifier instance. If that didn't make any sense, you're doing fine : the file was there just to make it easy for developers on the project to share it. I've removed it now, so nobody else falls into this trap. There's really nothing useful you can do with it! The spambayes project is in a research phase now, and has nothing to offer that's useful to users. think-of-it-as-a-cocktail-napkin-with-scribbled-notes-ly y'rs - tim From steve_lewis@openiso.com Thu Sep 19 22:22:09 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Thu, 19 Sep 2002 16:22:09 -0500 (CDT) Subject: [Tutor] Bayespam...questions? In-Reply-To: References: <4129.199.66.1.5.1032451377.squirrel@www.absolutenettech.com> Message-ID: <9201.199.66.1.5.1032470529.squirrel@www.absolutenettech.com> thank you tim, i am very new to python, but learning fast. as your project progesses i would love to beta test and/or utilize your software. thanks again, steve > [Steve Lewis] >> I have downloaded the bayespam from sourceforge, when unzipped it >> leaves a file with the extension .pik. For the life of me, i cant find >> a reference to that extension in any of my online sources. Need help. >> What is the extension and a pointer or two on how to use it for spam >> protection. > > The file is a binary pickle of a classifier instance. If that didn't > make any sense, you're doing fine : the file was there just to > make it easy for developers on the project to share it. I've removed > it now, so nobody else falls into this trap. There's really nothing > useful you can do with it! The spambayes project is in a research > phase now, and has nothing to offer that's useful to users. > > think-of-it-as-a-cocktail-napkin-with-scribbled-notes-ly y'rs - tim From sarmxiii@knology.net Thu Sep 19 23:00:37 2002 From: sarmxiii@knology.net (montana) Date: Thu, 19 Sep 2002 17:00:37 -0500 Subject: [Tutor] Tkinter + OSX In-Reply-To: Message-ID: <3A733D1A-CC1B-11D6-AC58-00039315F4DA@knology.net> On Thursday, September 19, 2002, at 12:51 AM, darksyyyde wrote: > > On Wednesday, September 18, 2002, at 07:41 PM, > tutor-request@python.org wrote: >> >> >> First try this at the command line: >> %which python >> >> If your reply is /sw/bin/python or something dimilar from the /sw >> directory then fink screwed up. >> > No, i made a /usr/local/bin before config and make > > %wich python -- reflects it correctly. > No that is not exactly what I'm talking about. If you built it from source, python would be installed in the correct directories and this will not matter. Did you build it from source, or did you install using the Mac installer. Big difference. As someone else has already pointed out, you have to build Python from source with Tk this is what the fink install does. Huge difference. What you have here is probably no different than the OSX default Python in 10.2, this is why I have this problem also. Of course I have not yet put fink on this install. > >> If the reply is /usr/bin/python then you do not have you environment >> setup properly because it is not recognizing apps from /sw/bin. Once >> /sw/bin is in your path you should remove any trace of python from >> usr/bin and usr/lib then you can setup the default python to be from >> /sw/bin instead of /usr/bin. This is the issue you will encounter when >> using fink. All your apps are installed under /sw/bin. I wish the fink >> developers would come up with a way to add this to your PATH >> automatically. But alas ... >> > > The thing is, the fink/gzip wouldnt work. > so i pulled the tar.gz via gui out of fink and into my /usr/local/bin. > Then just unzipped it with stufit expander. > Then opened terminal and set up the directory. Then ./configure. > Then %sudo make install. > Ill see what the mac pythoneers have to say about it. > I appreciate the responses here though. > >> Anyways. 10.2 has python installed natively and I heard it has Tk and >> Tcl installed by default also but I get the same error. What this >> error >> is saying is that Tk is not installed properly because python cant >> find >> it? >> >> There are some sites out there that explain how to install TK/Tcl and >> there is a MacOSX release for this, but I never got it to work right >> under 10.1 so I had to resort to the fink method also. It works if you >> are running under XDarwin so it really is not native. Hopefully the >> mac-python group will get it together and switch to OSX so that some >> progress can be made in this direction. They are still the python with >> Tkinter support for OS9. Oh well, one can wish... >> > fink installed tcl/tk just fine. However its not in the same directory > as python. > Try same: % wish tclsh and see what response you get. You should have something like /sw/bin/tclsh if fink installed ok. Fink installs Tcl and Tk libraries in /sw/lib so there is no way to build python from scratch with Tk support unlees this directory is in your lib PATH. (I have no idea how to do this so you will need to ask someone else) Fink gets around this by it's own special installer that looks for Tcl/Tk Libraries as far as I know. As a matter of fact, you have to get the fink version of python that is built for Tk. This is different than you run of the mill python or the other python installs off of fink. Try: %fink list And scroll down till you get to all of the different python installs. >> You could always use jython and use the built in java on OSX. > > That would be kind of cool. I know very little about it though. > Is it a half breed between java and python, or just python that can > import/ > use java classes etc. ? > Somewhat from what I can gather. Seems to import java classes or you can write java programs with pyhton code embedded from what I can gather. >> >> Other than that it is still a PC world for Pythoneers. Unless you feel >> like hacking it together. >> > > Why couldnt python use/import the project builder files used for > templates > of cocoa(objective C) applications? > Then mac people wouldnt even have to worry about tkinter. > Apple already has cocoa set up to run with Java code as well as C, I wonder how hard it would be for them to set it up to run with python, perl, or ruby scripts also? > > I think there is someone named Tony Lownds (or something like that) that has a site describing how to get Aqua Tk working. I have had limited success with this but you may do better. If you get it to work Ok (if you decide to go this route), let us all know how it is set up. Hope some of this helps SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me From cyberdiction@hotmail.com Fri Sep 20 00:20:59 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Thu, 19 Sep 2002 16:20:59 -0700 Subject: [Tutor] Bayespam...questions? References: <4129.199.66.1.5.1032451377.squirrel@www.absolutenettech.com> Message-ID: ----- Original Message ----- From: "Steve Lewis" To: Sent: Thursday, September 19, 2002 9:02 AM Subject: [Tutor] Bayespam...questions? > Hello list, > > I have downloaded the bayespam from sourceforge, when unzipped it leaves a > file with the extension .pik. For the life of me, i cant find a reference > to that extension in any of my online sources. > Need help. What is the extension and a pointer or two on how to use it for > spam protection. > thanks > > > Steve Lewis > > I did that too. On comp.lang.python I found the answer using google. .pik stands for pickle and it is not ready for end-user consumption. From magnus@thinkware.se Fri Sep 20 00:35:32 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 20 Sep 2002 01:35:32 +0200 Subject: [Tutor] Learning natural language processing and Python? [why NLP?] In-Reply-To: References: Message-ID: <5.1.0.14.0.20020920013230.02b3a460@www.thinkware.se> At 15:04 2002-09-18 -0700, Danny Yoo wrote: >But why stop at spam? Ultimately, the idea I have is to put automatic >classification to a more constructive use: I'd like to categorize >Python-Tutor postings so that messages can be searched by topic. Or why not make a web portal that will search the web and present information that seems to be interesting to people based on what they thought was interesting before. Although I guess the big AI trick there would be to avoid presenting a lot of redundant information. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From pythonpython@hotmail.com Fri Sep 20 02:53:45 2002 From: pythonpython@hotmail.com (Hy Python) Date: Fri, 20 Sep 2002 01:53:45 +0000 Subject: [Tutor] How to execute other python program within a python program? Message-ID: Hello, Could you please tell me: How to execute other python program within a python program? I mean that: if have script1.py and script2, how can I execute "python script1.py para1 para2" in script2? Thanks a lot for your help. Hy _________________________________________________________________ Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com From lists@shrestha.net.np Fri Sep 20 03:36:33 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Fri, 20 Sep 2002 08:21:33 +0545 Subject: [Tutor] Question about socket connections References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> <1032243156.4428.9.camel@caspian.everglade> <3D8761F6.9040108@shrestha.net.np> <1032466576.1946.11.camel@caspian.everglade> Message-ID: <3D8A89B1.40707@shrestha.net.np> Rob Brown-Bayliss wrote: > I have looked at xmlrpc, and it works fine for a server but being based > on the socket server module is not really suitable for communication > between gui apps, at least in my opinion. I have done Gui apps with xmlrpc. Here's my logic. I implement xmlrpc client and xmlrpc server in both side (client and server) so client has a xmlrpc server + client and server has xmlrpc server+client when the client starts it registers with the server with its url (address and port) i then have a two way channel for communication. ashish jabberid: axhixh@jabber.org From bapolis@email.msn.com Mon Sep 16 22:01:24 2002 From: bapolis@email.msn.com (Anthony Polis) Date: Mon, 16 Sep 2002 14:01:24 -0700 Subject: [Tutor] MySQL module for windows Message-ID: <000801c25dc4$37f15050$79bc6641@voyd> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C25D89.8AEBD810 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, I don't have a C compiler. Does anyone know where I can find a installer = for the Windows MySQL module? Thanks, Anthony ------=_NextPart_000_0005_01C25D89.8AEBD810 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello,
 
I don't have a C compiler. Does anyone = know where I=20 can find a installer for the Windows MySQL module?
 
Thanks,
Anthony
------=_NextPart_000_0005_01C25D89.8AEBD810-- From james2dope@yahoo.com Wed Sep 18 20:12:09 2002 From: james2dope@yahoo.com (james middendorff) Date: Wed, 18 Sep 2002 12:12:09 -0700 (PDT) Subject: [Tutor] help Message-ID: <20020918191209.80801.qmail@web13903.mail.yahoo.com> I am wondering if there is any way I can write a program to run and say I type yahoo and it will run Internet Explorer and bring it to yahoo.com? __________________________________________________ Do you Yahoo!? Yahoo! News - Today's headlines http://news.yahoo.com From phil@river-bank.demon.co.uk Thu Sep 19 13:27:27 2002 From: phil@river-bank.demon.co.uk (Phil Thompson) Date: Thu, 19 Sep 2002 13:27:27 +0100 Subject: [Tutor] Re: Is there a widget or program for a database browsing In-Reply-To: <3D89DA60.8878.8D30C74@localhost> References: <3D89DA60.8878.8D30C74@localhost> Message-ID: <200209191327.27196.phil@river-bank.demon.co.uk> On Thursday 19 September 2002 1:08 pm, A wrote: > Hi, > In my program users will search a database and I need to display choosen > record(s ) in a nice graphical way. Is there a module( program), that I > could use together with Python, that could easily show the database > record(s) and take care of all thinks during browsing? Thanks for help. > Ladislav PyQt - check out the examples in the examples3/SQL directory. Phil From tdf@camoes.rnl.ist.utl.pt Thu Sep 19 19:27:44 2002 From: tdf@camoes.rnl.ist.utl.pt (TIAGO DUARTE FELIX) Date: Thu, 19 Sep 2002 19:27:44 +0100 (WET DST) Subject: [Tutor] Tkinter Windows! Message-ID: I need to build a GUI with python... the problem is that in my GUI i need 1 master window and then all the other windows open inside this master window! Is it possible to do this with python? If yes... how? Thanks! From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 04:04:36 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 19 Sep 2002 20:04:36 -0700 (PDT) Subject: [Tutor] MySQL module for windows In-Reply-To: <000801c25dc4$37f15050$79bc6641@voyd> Message-ID: On Mon, 16 Sep 2002, Anthony Polis wrote: > I don't have a C compiler. Does anyone know where I can find a installer > for the Windows MySQL module? Hi Anthony, If you have MySQL already installed, you can use the MySQLdb Python module here: http://sourceforge.net/project/showfiles.php?group_id=22307&release_id=102893 No one's had the time or resources to package up the 0.9.2 release yet, but there are binaries for 0.9.1 that should work ok for you. Best of wishes! From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 04:06:55 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 19 Sep 2002 20:06:55 -0700 (PDT) Subject: [Tutor] help In-Reply-To: <20020918191209.80801.qmail@web13903.mail.yahoo.com> Message-ID: On Wed, 18 Sep 2002, james middendorff wrote: > I am wondering if there is any way I can write a program to run and say > I type yahoo and it will run Internet Explorer and bring it to > yahoo.com? Yes: we'll want to check out the 'webbrowser' module, which should allow us to bring up a new web browser window in Python. Here's a link to some documentation about it: http://www.python.org/doc/lib/module-webbrowser.html If you run into problems while using it, give a holler on the Tutor list, and we can work together to fix it. Talk to you later! From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 04:09:39 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 19 Sep 2002 20:09:39 -0700 (PDT) Subject: [Tutor] MySQL module for windows In-Reply-To: <000801c25dc4$37f15050$79bc6641@voyd> Message-ID: On Mon, 16 Sep 2002, Anthony Polis wrote: > I don't have a C compiler. By the way, there IS a free C compiler for Windows made by the nice folks at Cygnus: http://www.cygwin.com/ I've heard that it's quite good, though I haven't had too much opportunity to play with it yet. Does anyone know if it integrates well with Python and building Python extensions? From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 04:23:20 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 19 Sep 2002 20:23:20 -0700 (PDT) Subject: [Tutor] How to execute other python program within a python program? [using modules] In-Reply-To: Message-ID: On Fri, 20 Sep 2002, Hy Python wrote: > Could you please tell me: > > How to execute other python program within a python program? > > I mean that: > if have script1.py and script2, > how can I execute "python script1.py para1 para2" in script2? > > Thanks a lot for your help. Hi Hy, Hmmm... My, my. *grin* Please forgive me --- I just couldn't resist. If you want to run the whole other program, you can use the os.system() function. Here's an example of how it might work: ### import os print "I will call this other program called hello.py" os.system("python hello.py") ### and if everything works the way we expect, this should get Python to run the other command. However, if both programs are Python, there's a way of being able to take individual pieces of one file, and use them in another. We can do this by by first 'importing' a file --- once we do this, then we can call the functions that are defined in the imported program. For example, let's say we have two files. Let's call the first one 'myutils.py': ### myutils.py def sqrt(x): return x ** 0.5 def double(x): return x + x ### What we'll do, in the second file, is use stuff from the myutils file. Let's call this file 'main.py': ### main.py import myutils print "Hey, this is something from the myutils file:", myutils.sqrt print "Let's use it! The square root of forty-two is", print myutils.sqrt(42) print "Let's try the other function:", print myutils.double("double") ### This is one way to use parts of one program within another, and we'd usually call the utility program a "module" because it contains a bunch of pieces that we can mix and match. The Useless Python website has a good tutorial on using modules; you can take a look at it here: http://uselesspython.com/BatteriesIncluded.html I think I rushed the explanation a bit; I think I drank too much coffee today. *grin* Please feel free to ask more questions where things are fuzzy, and one of us here can help explain it better. Talk to you later! From idiot1@netzero.net Fri Sep 20 06:00:12 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Fri, 20 Sep 2002 01:00:12 -0400 Subject: [Tutor] I don't get it Message-ID: <3D8AAB5B.4BF851BF@netzero.net> Folks, in the course of learning I have found that I trip over some key concept, and the lights go on; I get an illumination experience, and things go better after that. I have not yet had that with Python. There is some critical concept, some understanding about python I do not possess which helps make sense of everything. There is a conceptual linchpin which I have not tripped over, which is essential to the language, and which helps make sense of everything else. Any idea what this magic cookie is? -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 06:35:17 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 19 Sep 2002 22:35:17 -0700 (PDT) Subject: [Tutor] I don't get it In-Reply-To: <3D8AAB5B.4BF851BF@netzero.net> Message-ID: On Fri, 20 Sep 2002, Kirk Bailey wrote: > Folks, in the course of learning I have found that I trip over some key > concept, and the lights go on; I get an illumination experience, and > things go better after that. I have not yet had that with Python. > > There is some critical concept, some understanding about python I do not > possess which helps make sense of everything. There is a conceptual > linchpin which I have not tripped over, which is essential to the > language, and which helps make sense of everything else. Any idea what > this magic cookie is? Hi Kirk, >From reading samples of your code, I believe that you have a good grasp on using modules and variables, as well as conditionals. However, I think your programs are also very monolithic. My opinion is that your programming will become better if you define more utility functions. I hope this critique sounds reasonable, if prosaic. Function writing is not a magic bullet nor a magic cookie, but it does encourage one to think about design. But much more importantly, it gives you the freedom to make our own "verbs" in a programming langauge. I remember your excitement when you had first mentioned Forth as a language where one can extend the language. I suspect that if you get more comfortable writing Python functions in your own code, that a big lightbulb will suddenly emerge over your head. Best of wishes! From kowk@mac.com Fri Sep 20 06:35:52 2002 From: kowk@mac.com (Kow K) Date: Thu, 19 Sep 2002 22:35:52 -0700 Subject: [Tutor] Tkinter + OSX Message-ID: Hi, With python version 2.2 that fink installed, Tkinter was working very fine on Mac OS 10.1.x. (Now, I'm running python 2.2.1 under CVS with Tkinter enabled.) By the way, find developers recommend keeping /usr/local and /sw separate. Actually, setting a binding, say by symlink, between them sometimes causes a big mess, especially when you install GNU packages (*.pkg files) from Aqua environment. Kow On Wednesday, September 18, 2002, at 12:46 PM, darksyyyde wrote: > Im running OSX 10.1.3, and i have 'fink' installed. > Under Python help, it show TKinter as one of the modules, > but the module is not present apparently. > > >>> import _tkinter > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named _tkinter > > > When trying to install python with fink, i got... > > The following package will be installed or updated: > python > The following 5 additional packages will be installed: > db3 expat gdbm gmp readline > Do you want to continue? [Y/n] y > rm -rf db3-3.3.11-2 > mkdir -p /macunix/src/db3-3.3.11-2 > tar -xvzf /macunix/src/db-3.3.11.tar.gz > > gzip: stdin: not in gzip format > tar: Child returned status 1 > tar: Error exit delayed from previous errors > ### tar failed, exit code 2 > Unpacking the tarball db-3.3.11.tar.gz of package db3-3.3.11-2 failed. The > most likely cause for this is a corrupted or incomplete download. Do you > want > to delete the tarball and download it again? [Y/n] y > > > This would just happen over and over, no matter how many times i > entered 'y'. > I pulled the tar.gz file out of the fink subdirectory ( or copied it ) > to the local directory that i made for python. > I then unpacked it with stufit expander. > > As you can see, i was able to setup and make python this way, but theres > no TKinter. > I suppose i should ask if TKinter is even operable under MacOSX... > is it? > /me scratches head. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From printers@sendme.cz Fri Sep 20 09:24:54 2002 From: printers@sendme.cz (A) Date: Fri, 20 Sep 2002 10:24:54 +0200 Subject: [Tutor] Is there a widget or program for a database browsing Message-ID: <3D8AF776.22712.D2CB4CD@localhost> Hi, In my program users will search a database and I need to display choosen record(s ) in a nice graphical way. Is there a module( program), that I could use together with Python, that could easily show the database record(s) and take care of all thinks during browsing? Thanks for help. Ladislav From erikprice@mac.com Fri Sep 20 13:15:45 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 20 Sep 2002 08:15:45 -0400 Subject: [Tutor] I don't get it In-Reply-To: Message-ID: On Friday, September 20, 2002, at 01:35 AM, Danny Yoo wrote: > However, I think your programs are also very monolithic. My opinion is > that your programming will become better if you define more utility > functions. if __name__ == '__main__': Was really a lightbulb-turner-onner for me. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From nixonron@yahoo.com Fri Sep 20 15:17:28 2002 From: nixonron@yahoo.com (Ron Nixon) Date: Fri, 20 Sep 2002 07:17:28 -0700 (PDT) Subject: [Tutor] basic python question In-Reply-To: <200209021454.g82Es0T07609@mail15.bigmailbox.com> Message-ID: <20020920141728.17922.qmail@web20310.mail.yahoo.com> --0-1167826968-1032531448=:17914 Content-Type: text/plain; charset=us-ascii I'm playing around with the "How to Think Like A Computer Scientist" book and trying one of the examples and I keep getting syntax errors even though I'm typing word for word. if X%2==0: print x, "Is even" else: print x, "is odd" but I get a syntax error on the "else:" as shown below. Can I not do this with IDLE? SyntaxError: invalid syntax >>> if x%2==0: print x, "is even" else: SyntaxError: invalid syntax >>> --------------------------------- Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! --0-1167826968-1032531448=:17914 Content-Type: text/html; charset=us-ascii

I'm playing around with the "How to Think Like A Computer Scientist" book and trying one of the examples and I keep getting syntax errors even though I'm typing word for word.

 

if X%2==0:

print x, "Is even"

else:

print x, "is odd"

 

but I get a syntax error on the "else:" as shown below. Can I not do this with IDLE?

 

SyntaxError: invalid syntax
>>> if x%2==0:
 print x, "is even"
 else:
  
SyntaxError: invalid syntax
>>>

 

 



Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo! --0-1167826968-1032531448=:17914-- From ATrautman@perryjudds.com Fri Sep 20 15:22:55 2002 From: ATrautman@perryjudds.com (Alan Trautman) Date: Fri, 20 Sep 2002 09:22:55 -0500 Subject: [Tutor] basic python question Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B5878@mail.pjinet.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_01C260B1.361774E0 Content-Type: text/plain; charset="iso-8859-1" Ron, Python is totally dependant on indentation for program flow. To make your program work type if x%2 = 0: print x,"is even" else: print x,"is odd" The indentations tell Python that these are the steps to perform when the condition is true (ie.. even) or what to do in all other cases (odd). -----Original Message----- From: Ron Nixon [mailto:nixonron@yahoo.com] Sent: Friday, September 20, 2002 9:17 AM To: tutor@python.org Subject: [Tutor] basic python question I'm playing around with the "How to Think Like A Computer Scientist" book and trying one of the examples and I keep getting syntax errors even though I'm typing word for word. if X%2==0: print x, "Is even" else: print x, "is odd" but I get a syntax error on the "else:" as shown below. Can I not do this with IDLE? SyntaxError: invalid syntax >>> if x%2==0: print x, "is even" else: SyntaxError: invalid syntax >>> _____ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! ------_=_NextPart_001_01C260B1.361774E0 Content-Type: text/html; charset="iso-8859-1"
Ron,
 
Python is totally dependant on indentation for program flow.
 
To make your program work type
 
if x%2 = 0:
    print x,"is even"
else:
    print x,"is odd"
 
The indentations tell Python that these are the steps to perform when the condition is true (ie.. even) or what to do in all other cases (odd).
 
 
-----Original Message-----
From: Ron Nixon [mailto:nixonron@yahoo.com]
Sent: Friday, September 20, 2002 9:17 AM
To: tutor@python.org
Subject: [Tutor] basic python question

I'm playing around with the "How to Think Like A Computer Scientist" book and trying one of the examples and I keep getting syntax errors even though I'm typing word for word.

if X%2==0:

print x, "Is even"

else:

print x, "is odd"

but I get a syntax error on the "else:" as shown below. Can I not do this with IDLE?

SyntaxError: invalid syntax
>>> if x%2==0:
 print x, "is even"
 else:
  
SyntaxError: invalid syntax
>>>

 



Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
------_=_NextPart_001_01C260B1.361774E0-- From shalehperry@attbi.com Fri Sep 20 16:03:52 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 20 Sep 2002 08:03:52 -0700 Subject: [Tutor] I don't get it In-Reply-To: References: Message-ID: <200209200803.52687.shalehperry@attbi.com> On Friday 20 September 2002 05:15, Erik Price wrote: > On Friday, September 20, 2002, at 01:35 AM, Danny Yoo wrote: > > However, I think your programs are also very monolithic. My opinion = is > > that your programming will become better if you define more utility > > functions. > > if __name__ =3D=3D '__main__': > > Was really a lightbulb-turner-onner for me. > Indeed. It leads to unit testing and testing is not possible if you have= all=20 of your code in one, big jumble. I find that forcing myself to write tes= ts=20 also forces me to design my code better. From magnus@thinkware.se Fri Sep 20 17:19:25 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 20 Sep 2002 18:19:25 +0200 Subject: [Tutor] Tkinter Windows! In-Reply-To: Message-ID: <5.1.0.14.0.20020920180400.02aca4f0@www.thinkware.se> At 19:27 2002-09-19 +0100, TIAGO DUARTE FELIX wrote: >I need to build a GUI with python... the problem is that in my GUI >i need 1 master window and then all the other windows open inside this >master window! Hm... MDI-applications. I thought they were all gone by now. Do you need to use Tkinter? Someone asked that in May and got no reply. You could try mailing adi.clepcea@sysrom.ro to hear if he solved it. But as far as I understand, Tcl/Tk has no native MDI support. There are add-ons but I doubt that Tkinter can use them. Both Mark Hammonds PythonWin extensions and the ever popular wxPython (new version today) can handle MDI. I thought noone used MDI any longer. It seems MS dropped it at least... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From erikprice@mac.com Fri Sep 20 17:36:14 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 20 Sep 2002 12:36:14 -0400 Subject: [Tutor] I don't get it In-Reply-To: <200209200803.52687.shalehperry@attbi.com> Message-ID: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> On Friday, September 20, 2002, at 11:03 AM, Sean 'Shaleh' Perry wrote: > On Friday 20 September 2002 05:15, Erik Price wrote: >> On Friday, September 20, 2002, at 01:35 AM, Danny Yoo wrote: >>> However, I think your programs are also very monolithic. My opinion >>> is >>> that your programming will become better if you define more utility >>> functions. >> >> if __name__ == '__main__': >> >> Was really a lightbulb-turner-onner for me. >> > > Indeed. It leads to unit testing and testing is not possible if you > have all > of your code in one, big jumble. I find that forcing myself to write > tests > also forces me to design my code better. I have heard of unit-testing. But I'm not sure exactly what it is. My best guess is that it's when you provide sample data in the "if __name__ == '__main__' " block so that you can execute this class individually to make sure it works. But I don't know the methodology of unit testing. (OT question: Does anyone know, is the Java version of "if __name__ == '__main__' " a simple matter of using the main() method?) Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From shalehperry@attbi.com Fri Sep 20 17:34:47 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 20 Sep 2002 09:34:47 -0700 Subject: [Tutor] I don't get it In-Reply-To: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> References: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> Message-ID: <200209200934.47967.shalehperry@attbi.com> On Friday 20 September 2002 09:36, Erik Price wrote: > > I have heard of unit-testing. But I'm not sure exactly what it is. My > best guess is that it's when you provide sample data in the "if > __name__ =3D=3D '__main__' " block so that you can execute this class > individually to make sure it works. > > But I don't know the methodology of unit testing. > breaking the name down it means testing in small units of functionality. = Each=20 function/class/whatever in a module would have one or more test functions= =20 written which verify proper behavior. As you said the main block provide= s a=20 way to run these tests in an elegant manner. From cyberdiction@hotmail.com Fri Sep 20 18:21:29 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Fri, 20 Sep 2002 10:21:29 -0700 Subject: [Tutor] Learning natural language processing and Python? [why NLP?] Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0019_01C2608F.7C3C1F60 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hello, Along the lines of searching the tutor archives I found Norvig's project and he is asking for volunteers. AIMA PYTHON CODE This file gives an overview of the Python code for the algorithms in the = textbook=20 AI: A Modern Approach. The code is Copyright (c) 2002 by Peter Norvig = and=20 is offered free of charge for your use. As you may know, the textbook = presents=20 algorithms in pseudo-code format; as a supplement we provide this Python = code=20 as well as Lisp code. The intent is to implement all the algorithms in = both languages,=20 so that you can choose whichever language you prefer. As yet neither = implementation=20 is complete, but the Lisp version is closer.=20 So I downloaded the files and below is the very start of the nlp.py = code. The copyright=20 for the code is very open. The book is done and will be published in DEC = 2002. """Will be a chartparser and related NLP tools. Not at all working yet. = (Chapter 22)""" from utils import * import random, search # [Fig. 22.4] Naive-Communicating-Agent #________________________________________________________________________= ______ # Grammars and Lexicons def Rules(**rules):=20 """Create a dictionary mapping symbols to alternatives.""" for k in rules.keys(): rules[k] =3D [alt.strip().split(' ') for alt in = rules[k].split('|')] return rules Norvig: "If you'd like to contribute to this project, we could really use the = help. Read the=20 guidelines and then let me know what you'd like to contribute."=20 http://www.norvig.com/python/guidelines.html Norvig wrote: We already have a body of existing Lisp code; why do we need a Python = version=20 (especially when the Lisp version is not yet complete)? Several reasons: = .... Of all the established languages in the world, Python is closest to the=20 pseudo-code that we developed (independently) for the book.=20 SH: Anyway, at the least I think this will provide an example of Python = nlp code. Best regards, Stephen ------=_NextPart_000_0019_01C2608F.7C3C1F60 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
Hello,
 
Along the lines of searching the tutor = archives I=20 found
Norvig's project and he is asking for=20 volunteers.
 
AIMA PYTHON CODE
This file gives an overview of the Python code for the algorithms = in the=20 textbook
AI: A = Modern=20 Approach. The code is Copyright (c) 2002 by Peter Norvig and
is offered free of charge for=20 your use. As you may know, the textbook presents
algorithms in pseudo-code format; as a supplement we provide this = Python=20 code
as well as Lisp = code.=20 The intent is to implement all the algorithms in both languages,
so that you can choose whichever language you prefer. As yet = neither=20 implementation
is complete, but the Lisp version is closer.
 
 
So I downloaded the files and below is = the very=20 start of the nlp.py code. The = copyright=20
for the code is very open. The book is = done and=20 will be published in DEC 2002.
 
"""Will be a chartparser and related = NLP=20 tools.  Not at all working yet. (Chapter 22)"""
 
from utils import *
import random,=20 search
 
# [Fig. 22.4]=20 Naive-Communicating-Agent
 
#_______________________________________________________________= _______________
#=20 Grammars and Lexicons
 
def Rules(**rules): =
   =20 """Create a dictionary mapping symbols to = alternatives."""
   =20 for k in rules.keys():
        = rules[k] =3D=20 [alt.strip().split(' ') for alt in = rules[k].split('|')]
   =20 return rules
 
Norvig:
"If you'd like to contribute to this project, we could really use = the help.=20 Read the
guidelines and = then let me know what you'd like = to=20 contribute."
http://www.norvig.c= om/python/guidelines.html
Norvig wrote:
We already have a body of exist= ing Lisp=20 code; why do we need a Python version
(especially when the Lisp version is not yet complete)? Several = reasons:=20 ....
 
Of all the established languages in the world, Python is closest to = the=20
pseudo-code that we developed (independently) for the book.
 
SH: Anyway, at the least I think this = will provide=20 an example of Python nlp code.
 
Best regards,
Stephen
 
------=_NextPart_000_0019_01C2608F.7C3C1F60-- From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 18:48:16 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 20 Sep 2002 10:48:16 -0700 (PDT) Subject: [Tutor] I don't get it In-Reply-To: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> Message-ID: On Fri, 20 Sep 2002, Erik Price wrote: > > On Friday 20 September 2002 05:15, Erik Price wrote: > >> On Friday, September 20, 2002, at 01:35 AM, Danny Yoo wrote: > >>> However, I think your programs are also very monolithic. My opinion > >>> is that your programming will become better if you define more > >>> utility functions. > >> > >> if __name__ == '__main__': > >> > >> Was really a lightbulb-turner-onner for me. > >> > > > > Indeed. It leads to unit testing and testing is not possible if you > > have all of your code in one, big jumble. I find that forcing myself > > to write tests also forces me to design my code better. > > I have heard of unit-testing. But I'm not sure exactly what it is. My > best guess is that it's when you provide sample data in the "if __name__ > == '__main__' " block so that you can execute this class individually to > make sure it works. > > But I don't know the methodology of unit testing. Dive into Python has an awesome chapter on showing what Unit Testing is: http://diveintopython.org/roman_divein.html > (OT question: Does anyone know, is the Java version of "if __name__ == > '__main__' " a simple matter of using the main() method?) Yes, it's the same... well, except that the Java version's main static method is explicitely named, so that we can actually call it from other places if we wanted to. In Python, on the other hand, we'd need to add a layer of indirection for the exact same effect. That is, instead of: ### if __name__ == '__main__': print "hello, this is a test" ### we can yank out the body of the main into a separate function: ### def _main(): print "hello, this is a test" if __name__ == '__main__': _main() ### This would be closer to a Java/C style main function. Good luck! From magnus@thinkware.se Fri Sep 20 18:53:34 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 20 Sep 2002 19:53:34 +0200 Subject: [Tutor] I don't get it In-Reply-To: <200209200934.47967.shalehperry@attbi.com> References: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020920190751.02b76ce0@www.thinkware.se> At 09:34 2002-09-20 -0700, Sean 'Shaleh' Perry wrote: >breaking the name down it means testing in small units of=20 >functionality. Each >function/class/whatever in a module would have one or more test functions >written which verify proper behavior. As you said the main block provides= a >way to run these tests in an elegant manner. Every public *method* in every class should have a unit test. There is an excellent module called "unittest" in the python standard library. See http://www.thinkware.se/cgi-bin/thinki.cgi/PyUnitExample and http://www.python.org/doc/current/lib/module-unittest.html and http://pyunit.sourceforge.net/ According to Extreme Programming you should always write tests before writing the code you try to test. When your code passes all your tests you stop coding, since then you are done. See http://www.thinkware.se/cgi-bin/thinki.cgi/ExtremeProgramming A complimentary Extreme Programming practice is refactoring, which means that you continually fix your program structure when you find flaws. (Adding/changing functionality and refactoring code are separate processes in XP. When you add or change functionality you always add or change unit tests. When you refactor you *never* change your tests. They should all run both before and after each refactoring.) A development session using unit testing and refactoring is sescribed here: http://www.xprogramming.com/xpmag/refactoringisntrework.htm These development practices are very useful even if you don't run a full extreme programming project. Writing test first mean that: * You have to think through requirements before coding. * You avoid goldplating code since you get a signal to stop coding. "All test are OK. I'm done coding." * The test cases can be used as examples on how to use your classes and functions. Useful for other coders. * Obviously, the unit tests will warn you when you make coding mistakes. * You don't have to worry about breaking functionality when you refactor your code, since you make changes in small steps and continually check that all tests are OK. This requires that you learn how to refactor, i.e. how to change the design of your code in small evolutionary steps without breaking functionality. It's a very Darwinistic approach to programming. Just like with the evolution of organisms, big leaps in developemnt can't happen. Each generation (successful test run) can only be slightly different from the previous. Regarding use of "if __name__ =3D=3D '__main__':" I usually place my test code in separate files. For moduleX.py I will have a moduleX_ut.py. I then have a small script that will run all the test scripts in a project directory. Another way of doing unit testing in Python is the doctest module, that will let you specify tests in the documentation strings for functions, methods etc. See http://www.python.org/doc/current/lib/module-doctest.html --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From erikprice@mac.com Fri Sep 20 19:39:18 2002 From: erikprice@mac.com (Erik Price) Date: Fri, 20 Sep 2002 14:39:18 -0400 Subject: [Tutor] I don't get it In-Reply-To: <5.1.0.14.0.20020920190751.02b76ce0@www.thinkware.se> Message-ID: <45A7BF26-CCC8-11D6-BB7E-00039351FE6A@mac.com> On Friday, September 20, 2002, at 01:53 PM, Magnus Lycka wrote: > Regarding use of "if __name__ == '__main__':" I usually > place my test code in separate files. For moduleX.py > I will have a moduleX_ut.py. I then have a small script > that will run all the test scripts in a project directory. So... assuming I place each class in a different file, then I should have a complementary file that imports the class and runs through the gauntlet of methods, making sure each one does what it's supposed to do? Excellent. I will implement this in my current project. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From shalehperry@attbi.com Fri Sep 20 19:47:32 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 20 Sep 2002 11:47:32 -0700 Subject: [Tutor] I don't get it In-Reply-To: <45A7BF26-CCC8-11D6-BB7E-00039351FE6A@mac.com> References: <45A7BF26-CCC8-11D6-BB7E-00039351FE6A@mac.com> Message-ID: <200209201147.32173.shalehperry@attbi.com> On Friday 20 September 2002 11:39, Erik Price wrote: > On Friday, September 20, 2002, at 01:53 PM, Magnus Lycka wrote: > > Regarding use of "if __name__ =3D=3D '__main__':" I usually > > place my test code in separate files. For moduleX.py > > I will have a moduleX_ut.py. I then have a small script > > that will run all the test scripts in a project directory. > > So... assuming I place each class in a different file, then I should > have a complementary file that imports the class and runs through the > gauntlet of methods, making sure each one does what it's supposed to do= ? > > Excellent. I will implement this in my current project. > right for a trivial case: def div(top, bottom): return top / bottom def test_div(): ret =3D div(0,1) assert(ret =3D=3D 0) try: ret =3D div(1,0) except: pass else: assert(0) # should have thrown an exception ret =3D div(4,2) assert(ret =3D=3D 2) #end test_div In other words try a few boundary conditions and then a few real cases. From magnus@thinkware.se Fri Sep 20 21:12:48 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 20 Sep 2002 22:12:48 +0200 Subject: [Tutor] I don't get it In-Reply-To: <200209201147.32173.shalehperry@attbi.com> References: <45A7BF26-CCC8-11D6-BB7E-00039351FE6A@mac.com> <45A7BF26-CCC8-11D6-BB7E-00039351FE6A@mac.com> Message-ID: <5.1.0.14.0.20020920220511.02b5b908@www.thinkware.se> At 11:47 2002-09-20 -0700, Sean 'Shaleh' Perry wrote: >def div(top, bottom): > return top / bottom > >def test_div(): > ret =3D div(0,1) > assert(ret =3D=3D 0) > > try: > ret =3D div(1,0) > except: > pass > else: > assert(0) # should have thrown an exception > > ret =3D div(4,2) > assert(ret =3D=3D 2) >#end test_div But with the unittest module you get some nice methods that makes at least the exception test a bit shorter. You can do things like ... self.assertRaises(ZeroDivisionError, div(1,0)) ... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From rob@zoism.org Fri Sep 20 21:14:58 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 21 Sep 2002 08:14:58 +1200 Subject: [Tutor] Question about socket connections In-Reply-To: <3D8A89B1.40707@shrestha.net.np> References: <1032238500.2265.25.camel@rdu57-231-033.nc.rr.com> <1032243156.4428.9.camel@caspian.everglade> <3D8761F6.9040108@shrestha.net.np> <1032466576.1946.11.camel@caspian.everglade> <3D8A89B1.40707@shrestha.net.np> Message-ID: <1032552885.2224.4.camel@caspian.everglade> On Fri, 2002-09-20 at 14:36, Ashish Shrestha wrote: > I have done Gui apps with xmlrpc. Here's my logic. > > I implement xmlrpc client and xmlrpc server in both side (client and server) > > so client has a xmlrpc server + client and server has xmlrpc server+client > > when the client starts it registers with the server with its url > (address and port) > > i then have a two way channel for communication. Thats essentially what I had started, except that I had the client ask the server for a port number, that way allowing more than one client to operate on the same machine. How were you handling the actual server class in your apps? -- * * Rob Brown-Bayliss * From bergelin@cs.utwente.nl Fri Sep 20 16:22:01 2002 From: bergelin@cs.utwente.nl (Carlos Bergelin) Date: Fri, 20 Sep 2002 17:22:01 +0200 Subject: [Tutor] Calling C from Python Message-ID: <003f01c260b9$77d1f560$2f0c5982@dynamic.cs.utwente.nl> Hi everybody! I just want to know how can I do to call a C function from python? Thanks, Carlos From dyoo@hkn.eecs.berkeley.edu Fri Sep 20 21:58:22 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 20 Sep 2002 13:58:22 -0700 (PDT) Subject: [Tutor] Calling C from Python In-Reply-To: <003f01c260b9$77d1f560$2f0c5982@dynamic.cs.utwente.nl> Message-ID: On Fri, 20 Sep 2002, Carlos Bergelin wrote: > Hi everybody! > I just want to know how can I do to call a C function from python? Hi Carlos, You can write a "wrapper" to make C functions look like Python functions. There' s a good utility called SWIG that makes wrapper writing fairly easy: http://www.swig.org/ It usually involves telling SWIG what the function interface looks like. >From there, SWIG will generate the necessary code in C to make it accessible to Python. If you're curious about how all this actually works, you can take a look at the Extending and Embedding Document: http://python.org/doc/current/ext/ext.html If you have more questions, please feel free to ask. Good luck! From dyoo@CSUA.Berkeley.EDU Fri Sep 20 23:05:54 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Fri, 20 Sep 2002 15:05:54 -0700 (PDT) Subject: [Tutor] Calling C from Python [C wrapper writing] In-Reply-To: Message-ID: <20020920142820.R97539-100000@soda.csua.berkeley.edu> On Fri, 20 Sep 2002, Danny Yoo wrote: > > > On Fri, 20 Sep 2002, Carlos Bergelin wrote: > > > Hi everybody! > > I just want to know how can I do to call a C function from python? > > Hi Carlos, > > You can write a "wrapper" to make C functions look like Python > functions. There' s a good utility called SWIG that makes wrapper > writing fairly easy: > > http://www.swig.org/ > > It usually involves telling SWIG what the function interface looks like. > >From there, SWIG will generate the necessary code in C to make it > accessible to Python. > > If you're curious about how all this actually works, you can take a look > at the Extending and Embedding Document: > > http://python.org/doc/current/ext/ext.html The key part in writing a wrapper is translating things from C values to Python values. If you want to see what a wrapper might look like if we don't use SWIG, you can take a good below: I'm starting to polish up my wrapper on a "Lovin-style" string stemmer: http://hkn.eecs.berkeley.edu/~dyoo/python/lovin_stemmer/ The original source code I took provides a 'stem()' function that reads in a char* and does an in-place modification of the string. Python strings, however, are immutable --- they're not supposed to be modified in place! The wrapper tries to reconcile these two views of strings by using a temporary holding variable. /******/ static PyObject* LovinStemmer_stem(PyObject *module, PyObject *args) { char *word; PyObject *stemmed_word; unsigned char *temp_str; if (! PyArg_ParseTuple(args, "s", &word)) { return NULL; } temp_str = malloc(sizeof(char) * (strlen(word) + 1 + 1)); /* Explanation for the "+ 1 + 1" part of the malloc: +1 for the first character, which actually stores the string length, and +1 for NULL termination. */ strncpy(temp_str+1, word, strlen(word)); temp_str[0] = strlen(word); _stem(temp_str); stemmed_word = PyString_FromStringAndSize(temp_str+1, temp_str[0]); free(temp_str); return stemmed_word; } /******/ Here, my wrapper does a string copy before calling the real stem() function. Once the original C function is done, I go back and then create a new Python string. So my rough wrapper for the C stem() function is simple, but a little tedious. And that's where SWIG comes in: it does most of the tedium for us. Anyway, hope this helps! From fgranger@altern.org Fri Sep 20 23:11:43 2002 From: fgranger@altern.org (Francois Granger) Date: Sat, 21 Sep 2002 00:11:43 +0200 Subject: [Tutor] I don't get it In-Reply-To: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> References: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> Message-ID: At 12:36 -0400 20/09/02, in message Re: [Tutor] I don't get it, Erik Price wrote: > >I have heard of unit-testing. But I'm not sure exactly what it is. >My best guess is that it's when you provide sample data in the "if >__name__ == '__main__' " block so that you can execute this class >individually to make sure it works. > >But I don't know the methodology of unit testing. Have a look there: http://diveintopython.org/ There is a good chapter and a good exemple on this matter. From steve_lewis@openiso.com Fri Sep 20 23:57:21 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Fri, 20 Sep 2002 17:57:21 -0500 (CDT) Subject: [Tutor] simple question... Message-ID: <6921.199.66.1.5.1032562641.squirrel@www.absolutenettech.com> hello, i am just learning and doing simple scripts to open Windows apps. snip os.system('start C:\Program Files\NoteTab Light\NoteTab.exe') /snip the spaces are causing problems. any pointers? steve lewis u.s.a From dyoo@hkn.eecs.berkeley.edu Sat Sep 21 00:21:22 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 20 Sep 2002 16:21:22 -0700 (PDT) Subject: [Tutor] Timing calculation (fwd) Message-ID: Hi Ali, You probably meant to send mail to Tutor, so let me forward your question there. Good luck to you! ---------- Forwarded message ---------- Date: Fri, 20 Sep 2002 15:40:17 -0700 From: Ali Soleymanzadeh To: dyoo@hkn.eecs.berkeley.edu Subject: Timing calculation Hi, Could someone please show me how to calculate the time, which is running by a test. My program is doing: ... os.system( "make deja %s 2>&1 | tee %s" % (makeopts,spoolfile) ) data = open( spoolfile ).read() ... I need to get the time before and after running "make deja", then calculate the time between. Thanks in advance for your help. Regards, -Ali From fgranger@altern.org Sat Sep 21 00:31:00 2002 From: fgranger@altern.org (Francois Granger) Date: Sat, 21 Sep 2002 01:31:00 +0200 Subject: [Tutor] simple question... In-Reply-To: <6921.199.66.1.5.1032562641.squirrel@www.absolutenettech.com> References: <6921.199.66.1.5.1032562641.squirrel@www.absolutenettech.com> Message-ID: At 17:57 -0500 20/09/02, in message [Tutor] simple question..., Steve Lewis wrote: >hello, > >i am just learning and doing simple scripts to open Windows apps. > >snip > >os.system('start C:\Program Files\NoteTab Light\NoteTab.exe') Try this: os.system('start "C:\Program Files\NoteTab Light\NoteTab.exe"') From emile@fenx.com Sat Sep 21 00:33:46 2002 From: emile@fenx.com (Emile van Sebille) Date: Fri, 20 Sep 2002 16:33:46 -0700 Subject: [Tutor] Re: simple question... References: <6921.199.66.1.5.1032562641.squirrel@www.absolutenettech.com> Message-ID: "Steve Lewis" wrote in message news:6921.199.66.1.5.1032562641.squirrel@www.absolutenettech.com... > hello, > > i am just learning and doing simple scripts to open Windows apps. > > snip > > os.system('start C:\Program Files\NoteTab Light\NoteTab.exe') > > /snip > > the spaces are causing problems. any pointers? > You need to put the program name in quotes for the os. Try: os.system('start "C:\Program Files\NoteTab Light\NoteTab.exe"') -- Emile van Sebille emile@fenx.com --------- From fgranger@altern.org Sat Sep 21 00:36:23 2002 From: fgranger@altern.org (Francois Granger) Date: Sat, 21 Sep 2002 01:36:23 +0200 Subject: [Tutor] Timing calculation (fwd) In-Reply-To: References: Message-ID: >From: Ali Soleymanzadeh > >I need to get the time before and after running "make deja", then calculate >the time between. for exemple, have a look there: http://tinylink.com/?CiNJirKOZu From danny@i4.net Sat Sep 21 00:57:15 2002 From: danny@i4.net (Danny) Date: Fri, 20 Sep 2002 17:57:15 -0600 Subject: [Tutor] Does any know of a code that I can look at that will not allow the Programs to shut dos down after I run them In-Reply-To: <1032317994.47.1350@sake.mondoinfo.com> Message-ID: <000001c26101$72973950$4ee76741@hewlett5k1589j> Hi Does anyone out there know of a code that will not allow windows do shut the dos prompt after I run a program so I can see what the program has done or at least pause it for a specified amount of time anyone with any information please email me back soon as u can thanks for everyone help and support I hope that actually I know one day I will be answering questions for newbiews like myself thanks for all your help and support oh one more quick question does anyone know after I have downloaded SuSE i386 8.0 if there is anything else I need before I start to play with it thanks for everything everyone Sincerely Danny D From yduppen@xs4all.nl Sat Sep 21 01:16:30 2002 From: yduppen@xs4all.nl (Yigal Duppen) Date: Sat, 21 Sep 2002 02:16:30 +0200 Subject: [Tutor] Does any know of a code that I can look at that will not allow the Programs to shut dos down after I run them In-Reply-To: <000001c26101$72973950$4ee76741@hewlett5k1589j> References: <000001c26101$72973950$4ee76741@hewlett5k1589j> Message-ID: <200209210216.33533.yduppen@xs4all.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey Danny, The usual way to prevent Dosboxes from closing after a script is as follows: #!/usr/bin/env python # Just a silly script print "Hello world" raw_input("Press enter to continue...") # <- this is the trick ! This script will print hello world and will pause until you've pressed enter; at which point, the Dosbox will close. As for SuSE 8.0; I just installed it and everything seemed to be present. At least for my purposes. YDD - -- http://www.xs4all.nl/~yduppen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9i7phLsKMuCf5EdwRAvp5AKDbNHCAmZr/JyltTtyobeR7UbcxTwCgtGIg 6ciSxZviNb2t0iPbkJPXOPI= =yuyG -----END PGP SIGNATURE----- From yduppen@xs4all.nl Sat Sep 21 01:22:00 2002 From: yduppen@xs4all.nl (Yigal Duppen) Date: Sat, 21 Sep 2002 02:22:00 +0200 Subject: [Tutor] Is there a widget or program for a database browsing In-Reply-To: <3D8AF776.22712.D2CB4CD@localhost> References: <3D8AF776.22712.D2CB4CD@localhost> Message-ID: <200209210222.00709.yduppen@xs4all.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > Hi, > In my program users will search a database and I need to display choosen > record(s ) in a nice graphical way. Is there a module( program), that I > could use together with Python, that could easily show the database > record(s) and take care of all thinks during browsing? Thanks for help. Have a look at PyQt: http://www.riverbankcomputing.co.uk/pyqt/ Especially the qtsql module. I haven't used it yet, but programming Qt is very nice & easy. (Especially when using B.Rempt's book: http://www.opendocspublishing.com/pyqt/) BTW, please try to limit your crossposting... YDD - -- http://www.xs4all.nl/~yduppen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9i7uoLsKMuCf5EdwRAkyBAKDO5/ShmdZifLnFALik0Nm3hztLWgCggDiM kOFpCqEegvoR6He7OjeTGpg= =WRCw -----END PGP SIGNATURE----- From yduppen@xs4all.nl Sat Sep 21 01:49:38 2002 From: yduppen@xs4all.nl (Yigal Duppen) Date: Sat, 21 Sep 2002 02:49:38 +0200 Subject: [Tutor] I don't get it In-Reply-To: <5.1.0.14.0.20020920190751.02b76ce0@www.thinkware.se> References: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> <5.1.0.14.0.20020920190751.02b76ce0@www.thinkware.se> Message-ID: <200209210249.38341.yduppen@xs4all.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > According to Extreme Programming you should always write tests > before writing the code you try to test. When your code passes > all your tests you stop coding, since then you are done. See > http://www.thinkware.se/cgi-bin/thinki.cgi/ExtremeProgramming Hmm. Talking about lightbulbs erupting over heads... I never got the idea of 'test first, code later' until I read Chapter 14 of "Extreme Programming Explained". By semi-transcribing an imaginary chat between to developers testing and coding, the authors managed to have the equivalent of 10 100Watt bulbs over my head ;-) Since that time, I'm quite a strict follower of the test->code paradigm. > When you refactor you *never* change your tests. They should > all run both before and after each refactoring.) This is of course a slightly optimistic view. For example, one of the simplest refactorings is Rename Method. I can guarantee that after applying this refactoring, at least one of your tests will fail :) When you get to the more elaborate refactorings that modify your code structure, this gets even worse. That's why the refactorings in the Book are all presented as algorithms with very simple steps -- you are allowed to adjust your tests, as long as you _only_ change tests as a direct result of applying one of the refactoring-steps. > A development session using unit testing and refactoring is > sescribed here: > http://www.xprogramming.com/xpmag/refactoringisntrework.htm It's a bit like the chapter 14 mentioned above. But the nice thing about XP Explained is that their test case is far from trivial; yet-another-stack example just doesn't seem to thrill me... > I then have a small script > that will run all the test scripts in a project directory. Ahhh. No greater joy than running such a script and seeing the 'OK's scroll over your screen (verbose=2 setting in unittest.TestRunner). Sometimes when I'm stuck I just hit it over and over again, to have something soothing to stare at... I know... I need a life :) YDD - -- http://www.xs4all.nl/~yduppen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9i8IiLsKMuCf5EdwRAiyaAKC1qrohdDzOLOEq5ZR3kBmuwqX7+ACeILCS TA59kiWGiNbnUy71fdvGEDs= =kCUc -----END PGP SIGNATURE----- From python Sat Sep 21 02:03:58 2002 From: python (python) Date: Fri, 20 Sep 2002 18:03:58 -0700 Subject: [Tutor] Does any know of a code that I can look at that will not allow the Programs to shut dos down after I run them In-Reply-To: <000001c26101$72973950$4ee76741@hewlett5k1589j> References: <000001c26101$72973950$4ee76741@hewlett5k1589j> Message-ID: <19183928983.20020920180358@inkedmn.net> If you want to make the prompt hang for a few seconds, just add these lines: import time ... sleep(5) # replace 5 with the number of seconds you want it to wait good luck brett D> Hi Does anyone out there know of a code that will not allow windows do shut D> the dos prompt after I run a program so I can see what the program has done D> or at least pause it for a specified amount of time anyone with any D> information please email me back soon as u can thanks for everyone help and D> support I hope that actually I know one day I will be answering questions D> for newbiews like myself thanks for all your help and support oh one more D> quick question does anyone know after I have downloaded SuSE i386 8.0 if D> there is anything else I need before I start to play with it thanks for D> everything everyone D> Sincerely Danny D D> _______________________________________________ D> Tutor maillist - Tutor@python.org D> http://mail.python.org/mailman/listinfo/tutor From wilson@visi.com Sat Sep 21 04:37:29 2002 From: wilson@visi.com (Tim Wilson) Date: Fri, 20 Sep 2002 22:37:29 -0500 Subject: [Tutor] sorting into lists Message-ID: <20020921033729.GA8491@isis.visi.com> Hey everyone, Let's say I've got a list like the following: l = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] I'm trying to figure out a good way to turn this list into [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] Any ideas? -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | | http://linux.com From darnold02@sprynet.com Sat Sep 21 04:59:15 2002 From: darnold02@sprynet.com (Don Arnold) Date: Fri, 20 Sep 2002 22:59:15 -0500 Subject: [Tutor] sorting into lists References: <20020921033729.GA8491@isis.visi.com> Message-ID: <017a01c26123$45270550$c009ba3f@defaultcomp> I'm sure there are slicker ways to do what you want, but this works: origList = [1,1,1,2,2,3,3,3,3,4,4] finalList = [] currList = [] lastItem = origList[0] for item in origList: if item == lastItem: currList.append(item) else: finalList.append(currList) lastItem = item currList = [item] finalList.append(currList) print 'original list:', origList print 'final list: ', finalList >>> original list: [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] final list: [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] Don ----- Original Message ----- From: "Tim Wilson" To: Sent: Friday, September 20, 2002 10:37 PM Subject: [Tutor] sorting into lists > Hey everyone, > > Let's say I've got a list like the following: > > l = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] > > I'm trying to figure out a good way to turn this list into > > [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] > > Any ideas? > > -Tim > > -- > Tim Wilson | Visit Sibley online: | Check out: > Henry Sibley HS | http://www.isd197.org | http://www.zope.com > W. St. Paul, MN | | http://slashdot.org > wilson@visi.com | | http://linux.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Sat Sep 21 05:22:51 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 20 Sep 2002 21:22:51 -0700 (PDT) Subject: [Tutor] sorting into lists In-Reply-To: <20020921033729.GA8491@isis.visi.com> Message-ID: On Fri, 20 Sep 2002, Tim Wilson wrote: > Hey everyone, > > Let's say I've got a list like the following: > > l = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] > > I'm trying to figure out a good way to turn this list into > > [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] Hi Tim, Is this grouping identical elements? Do we have to worry about what happens when the list isn't in order? More information on the problem might allow us to write more appropriate programs. Here's one approach that uses dictionaries: ### def formGroups(L): groups = {} for item in L: groups.setdefault(item, []).append(item) return groups.values() ### Here's the formGroups() function in action: ### >>> formGroups([1, 2, 3, 3, 1, 2, 1, 3, 5]) [[1, 1, 1], [2, 2], [3, 3, 3], [5]] ### Good luck to you! From wilson@visi.com Sat Sep 21 05:32:41 2002 From: wilson@visi.com (Tim Wilson) Date: Fri, 20 Sep 2002 23:32:41 -0500 Subject: [Tutor] sorting into lists In-Reply-To: References: <20020921033729.GA8491@isis.visi.com> Message-ID: <20020921043241.GB12985@isis.visi.com> On Fri, Sep 20, 2002 at 09:22:51PM -0700, Danny Yoo wrote: > > On Fri, 20 Sep 2002, Tim Wilson wrote: > > > Hey everyone, > > > > Let's say I've got a list like the following: > > > > l = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] > > > > I'm trying to figure out a good way to turn this list into > > > > [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] > > Hi Tim, > > Is this grouping identical elements? Do we have to worry about what > happens when the list isn't in order? More information on the problem > might allow us to write more appropriate programs. Danny, Thanks for the quick response. You were right to suspect that my real problem is not quite as straight-forward as the example I provided. Actually, I've got a list of objects that are returned from a SQL query in Zope. Each of those objects contains a DateTime field and is already sorted on that field by the SQL query. (In other words, I can assume that the original list is sorted.) The query results correspond to events in a larger database of events. My goal is to produce an "Upcoming events" table on my Web site with the events grouped by day. For example, "Today," "Tomorrow," "Mon. 9/23," etc. The reason I need the list of lists is because it's the most obvious way I can think of to iterate over the events and print the date at the beginning of each inner loop. (Think nested for loops.) Does that help or are you sorry you asked? :-) -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | | http://linux.com From idiot1@netzero.net Sat Sep 21 05:53:41 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 21 Sep 2002 00:53:41 -0400 Subject: [Tutor] I don't get it References: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> <5.1.0.14.0.20020920190751.02b76ce0@www.thinkware.se> <200209210249.38341.yduppen@xs4all.nl> Message-ID: <3D8BFB55.E0F57C15@netzero.net> OK, I think I detected a burned out light bulb. See, I absorbed all this the eclectic way, no schooling. There's probably holes all through my brain regarding computing. Tell me about factoring please? Um, well, I'm not totally ignorant. Just ALMOST ignorant. It's the idea of breaking some task down logically into component steps, then coding those, and building up a program with all these steps. You need to clearly outline the process it must perform. This also seems to have a secret love affair with the idea of algorithms, processes not defined in any programming language, to accomplish some task. Maybe I should go steal a few introductory computer science books? Yigal Duppen wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > According to Extreme Programming you should always write tests > > before writing the code you try to test. When your code passes > > all your tests you stop coding, since then you are done. See > > http://www.thinkware.se/cgi-bin/thinki.cgi/ExtremeProgramming > > Hmm. Talking about lightbulbs erupting over heads... I never got the idea of > 'test first, code later' until I read Chapter 14 of "Extreme Programming > Explained". By semi-transcribing an imaginary chat between to developers > testing and coding, the authors managed to have the equivalent of 10 100Watt > bulbs over my head ;-) > Since that time, I'm quite a strict follower of the test->code paradigm. > > > When you refactor you *never* change your tests. They should > > all run both before and after each refactoring.) > > This is of course a slightly optimistic view. > > For example, one of the simplest refactorings is Rename Method. I can > guarantee that after applying this refactoring, at least one of your tests > will fail :) > > When you get to the more elaborate refactorings that modify your code > structure, this gets even worse. That's why the refactorings in the Book are > all presented as algorithms with very simple steps -- you are allowed to > adjust your tests, as long as you _only_ change tests as a direct result of > applying one of the refactoring-steps. > > > A development session using unit testing and refactoring is > > sescribed here: > > http://www.xprogramming.com/xpmag/refactoringisntrework.htm > > It's a bit like the chapter 14 mentioned above. But the nice thing about XP > Explained is that their test case is far from trivial; yet-another-stack > example just doesn't seem to thrill me... > > > I then have a small script > > that will run all the test scripts in a project directory. > > Ahhh. No greater joy than running such a script and seeing the 'OK's scroll > over your screen (verbose=2 setting in unittest.TestRunner). Sometimes when > I'm stuck I just hit it over and over again, to have something soothing to > stare at... I know... I need a life :) > > YDD > - -- > http://www.xs4all.nl/~yduppen > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.7 (GNU/Linux) > > iD8DBQE9i8IiLsKMuCf5EdwRAiyaAKC1qrohdDzOLOEq5ZR3kBmuwqX7+ACeILCS > TA59kiWGiNbnUy71fdvGEDs= > =kCUc > -----END PGP SIGNATURE----- > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sat Sep 21 05:57:03 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 21 Sep 2002 00:57:03 -0400 Subject: [Tutor] sorting into lists References: <20020921033729.GA8491@isis.visi.com> Message-ID: <3D8BFC1F.A7FD0E30@netzero.net> HINT? ok. At the reach of overreaching myself, here goes: HINT: the address is the information. HINT: All processes of physics are reversible. HINT: sorting functions, and module. Sometimes I manage to trip over some interesting ideas in my grazing of the public library. Tim Wilson wrote: > > Hey everyone, > > Let's say I've got a list like the following: > > l = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] > > I'm trying to figure out a good way to turn this list into > > [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] > > Any ideas? > > -Tim > > -- > Tim Wilson | Visit Sibley online: | Check out: > Henry Sibley HS | http://www.isd197.org | http://www.zope.com > W. St. Paul, MN | | http://slashdot.org > wilson@visi.com | | http://linux.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From dyoo@hkn.eecs.berkeley.edu Sat Sep 21 06:07:37 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 20 Sep 2002 22:07:37 -0700 (PDT) Subject: [Tutor] sorting into lists In-Reply-To: <20020921043241.GB12985@isis.visi.com> Message-ID: On Fri, 20 Sep 2002, Tim Wilson wrote: > > Is this grouping identical elements? Do we have to worry about what > > happens when the list isn't in order? More information on the problem > > might allow us to write more appropriate programs. > > Danny, > > Thanks for the quick response. You were right to suspect that my real > problem is not quite as straight-forward as the example I provided. > Actually, I've got a list of objects that are returned from a SQL query > in Zope. Each of those objects contains a DateTime field and is already > sorted on that field by the SQL query. (In other words, I can assume > that the original list is sorted.) > > The query results correspond to events in a larger database of events. > My goal is to produce an "Upcoming events" table on my Web site with the > events grouped by day. For example, "Today," "Tomorrow," "Mon. 9/23," > etc. The reason I need the list of lists is because it's the most > obvious way I can think of to iterate over the events and print the date > at the beginning of each inner loop. (Think nested for loops.) Hmmm... Let's assume, for the moment, that our list of events has a method named "date()". (If they don't, perhaps we can add it in as a method.) Then we can adjust the dictionary approach we used earlier so that it groups the events by date --- we can use the date as keys into the dictionary: ### def formGroups(events): groups = {} for event in events: groups.setdefault(event.date(), []).append(event) return groups.values() ### If you notice, this is almost exactly like the approach with the integers. In fact, the only difference here is the way that we consider element items "equivalent". In the first case, we assumed they were in the same group if they were the same number. In the second, they're in the same group if they have the same date. We can apply this generalization if we modify formGroups() to take in a definition of sameness as a second parameter! ### def identity(x): return x def formGroups(elements, signature_function=identity): groups = {} for item in elements: groups.setdefault(signature_function(item), []).append(item) return groups.values() ### This version of formGroups() is just slightly more complex now, but with the advantage that we can reuse it to form many different types of groups: ### >>> formGroups([1, 1, 2, 3, 2, 42]) [[1, 1], [2, 2], [3], [42]] >>> def parity(x): ... if x % 2 == 0: return "even" ... else: return "odd" ... >>> formGroups([1, 1, 2, 3, 2, 42], parity) [[2, 2, 42], [1, 1, 3]] ### Hmmm.... wait a sec... ### >>> import lovin_stemmer >>> >>> ## see http://hkn.eecs.berkeley.edu/~dyoo/python/lovin_stemmer >>> ## for this module. It's still a bit experimental. >>> >>> stem = lovin_stemmer.stem >>> words = [x.strip() for x in open("/usr/share/dict/words").readlines()] >>> word_groups = formGroups(words, stem) >>> word_groups[0] ['fawn', 'fawned', 'fawning', 'fawns'] >>> word_groups[1] ['orthogonal', 'orthogonality', 'orthogonally'] >>> len(word_groups) 21364 ### Very cool! *grin* I like this formGroups() function. > Does that help or are you sorry you asked? :-) Are you kidding? *grin* I'm glad you asked; this was a fun problem. I hope this helps! From idiot1@netzero.net Sat Sep 21 06:13:58 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 21 Sep 2002 01:13:58 -0400 Subject: [Tutor] I don't get it Message-ID: <3D8C0016.8DAF7DE@netzero.net> I understand factoring is normally taught in the course of a course of instruction in some language- C, the popular bondage and discipline language Pascal, Visual Basic,, whatever. Is there a good on line article about factoring? -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From dyoo@hkn.eecs.berkeley.edu Sat Sep 21 06:29:09 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 20 Sep 2002 22:29:09 -0700 (PDT) Subject: [Tutor] I don't get it In-Reply-To: <3D8BFB55.E0F57C15@netzero.net> Message-ID: On Sat, 21 Sep 2002, Kirk Bailey wrote: > OK, I think I detected a burned out light bulb. > > See, I absorbed all this the eclectic way, no schooling. There's > probably holes all through my brain regarding computing. > > Tell me about factoring please? Hi Kirk, "Factoring" as a programming technique isn't too hard to understand: it's just the teasing out of a chunk of code from a program and giving it a good name as a function. For example, if we saw something like this: ### print "Hey, what's your name? ", name = raw_input() print "And what's your age? ", age = raw_input() ### we could look at both blocks, and try making a function that takes the best of the common elements: ### def askAQuestion(question): print question, " ", return raw_input() name = askAQuestion("Hey, what's your name?") age = askAQuestion("And what's your age?") ### Programmers who want to sound learned and wise by call this "factoring", but this amazing technique is just moving code around. Or is it? The "Refactoring" folks say that this grouping and regrouping of code is really important if we want to make good programs. There's an initial cost into making this function --- what we have now is a little bit longer. However, any new questions that we want to ask can use our askQuestion() function, so instead of writing those two print/raw_input() statements again, we can askAQuestion(). Do you have the latest version of your mail list program? Perhaps we can kill two birds with one stone, and do a concrete factoring of your program into functions. Talk to you later! From wilson@visi.com Sat Sep 21 06:44:34 2002 From: wilson@visi.com (Tim Wilson) Date: Sat, 21 Sep 2002 00:44:34 -0500 Subject: [Tutor] sorting into lists In-Reply-To: References: <20020921043241.GB12985@isis.visi.com> Message-ID: <20020921054434.GA20808@isis.visi.com> On Fri, Sep 20, 2002 at 10:07:37PM -0700, Danny Yoo wrote: > > Hmmm... Let's assume, for the moment, that our list of events has a method > named "date()". (If they don't, perhaps we can add it in as a method.) > Then we can adjust the dictionary approach we used earlier so that it > groups the events by date --- we can use the date as keys into the > dictionary: > > ### > def formGroups(events): > groups = {} > for event in events: > groups.setdefault(event.date(), []).append(event) > return groups.values() > ### OK, this function works very well! I knew there was a nice and clean solution. You can see a proof of concept at http://isd197.org/sibley/displayEvents if you're interested. This page is generated on the fly from the SQL database and will rotate to show about a week's worth of events. > We can apply this generalization if we modify formGroups() to take in a > definition of sameness as a second parameter! Very cool! This is one to tuck away for future reference. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | | http://linux.com From danny@i4.net Sat Sep 21 07:31:12 2002 From: danny@i4.net (Danny) Date: Sat, 21 Sep 2002 00:31:12 -0600 Subject: [Tutor] Redid the last code "fixhash" with a couple of changes and I keep getting this syntax error I can't figure out Message-ID: <000001c26138$7bd5d7b0$5ce96741@hewlett5k1589j> Thankyou everyone for your continued help here is the error SyntaxError: invalid syntax Traceback (most recent call last): File "", line 1, in ? File "C:\Python21\fiinalfixhash.py", line 44 def fixdirectory ( arg, d, dlist ) : ^ SyntaxError: invalid syntax and here is the code #!/usr/local/bin/python import os import sys import fileinput from stat import * pbang = "#!" + sys.executable nfiles = 0 nm = " " def initial ( y = 0 ) : global nm if v != 0 : if sys.platform == "win32" : sys.stderr.write ( "Python Version " + sys.version + \ " Running on Windows\n" ) elif sys.platform == "linux2" : sys.stderr.write ( "Python Version " + sys.version + \ " Running on Lynux\n" ) else : sys.stderr.write ( "Python Version " + sys.version + \ " Running on " + sys.platform + "\n" ) nm = os.path.split ( sys.argv[ 0 ] )[ 1 ] def getnfiles ( ) : return nfiles def rewritefile ( flp ): global pbang mode = os.stat ( fip )[ ST_MODE ] for line in fileinput.input ( fip, inplace = 1 ): if fileinput.isfirstline ( ) : if line [ : 2 ] == "#!" : sys.stdout.write ( pbang + "\n" ) else: sys.stdout.write ( pbang + "\n" ) sys.stdout.write ( line ) else: sys.stdout.write ( line ) fileinput.close ( ) os.chmod ( fip, mode def fixdirectory ( arg, d, dlist ) : global nfiles nfiles > 0 for i in dlist : if i == nm : continue if len ( i ) > 4 : fname = os.path.join (d, i) if fname[ -3 : ] == ".py" : sys.stderr.write ( "Checking " + fname + "...\n" ) for line in fileinput.input ( fname, os.W_OK ) : if fileinput.isfirstline ( ) : if line[ : -1 ] != pbang : fileinput.close ( ) t = os.access ( fname, os.W_OK ) if t == 0 : sys.stderr.write ( fname + \ " is not writable; skipping,\n" ) else: sys.stderr.write ( \ "Modifing " + fname + "...\n" ) rewritefile ( fname ) nfiles = nfiles + 1 break else: fileinput.close ( ) break return n.files def fixhash ( d, r, v ) : nmod = 0 if type ( d ) != type ( [] ) : dl = list ( d ) else: dl = d initial ( y ) for i in dl : if not r : dlist = os.listdir ( i ) fixdirectory ( v, i, dlist ) else: os.path.walk ( i, fixdirectory, v ) nmod = nmod + getnfiles ( ) return nmod if __name__ == "__main__" : nmod = 0 recurse = 0 if len ( sys.argv ) > 1 : if sys.argv[1] == '-r' : recurse = 1 if recurse and len ( sys.argv ) > 2 : dirnames = sys.argv[ 2 : ] elif recurse and len ( sys.argv ) <= 2 : dirnames = [ "." ] else: dirnames = sys.argv[ 1 : ] else: dirnames = [ "." ] for s in dirnames : if not recurse : dlist = os.listdir ( s ) fixdirectory ( 0, s, dlist ) else: os.path.walk ( s, fixdirectory, 0 ) nmod = nmod + getfiles ( ) sys.stderr.write ( "Files modifed: " + `nmod` + "\n" ) Thanks again for all you all do have a great night and a great weekend Danny D From scot@possum.in-berlin.de Sat Sep 21 10:41:33 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sat, 21 Sep 2002 11:41:33 +0200 Subject: [Tutor] Qt book by Rempt In-Reply-To: <200209210222.00709.yduppen@xs4all.nl> References: <3D8AF776.22712.D2CB4CD@localhost> <200209210222.00709.yduppen@xs4all.nl> Message-ID: <200209211141.33253.scot@possum.in-berlin.de> Hello Yigal, > Especially the qtsql module. I haven't used it yet, but programming Qt > is very nice & easy. (Especially when using B.Rempt's book: > http://www.opendocspublishing.com/pyqt/) Wasn't this the book that is marred by its heavy reliance on the commercial BlackAdder IDE? I remember that the whole first chapter was devoted to gushing about, installing and using BlackAdder... A shame, actually, because I keep hearing a lot of good stuff about Qt and am slowly getting fed up with Tkinter... Y, Scot -- Scot W. Stevenson wrote me on Saturday, 21. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 2288 hours and has a CPU that is falling asleep at a system load of 0.53. From scot@possum.in-berlin.de Sat Sep 21 10:20:51 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sat, 21 Sep 2002 11:20:51 +0200 Subject: [Tutor] Redid the last code "fixhash" with a couple of changes and I keep getting this syntax error I can't figure out In-Reply-To: <000001c26138$7bd5d7b0$5ce96741@hewlett5k1589j> References: <000001c26138$7bd5d7b0$5ce96741@hewlett5k1589j> Message-ID: <200209211120.51141.scot@possum.in-berlin.de> Hello Danny, Looks to me like you are missing a ")" in the line above the one that is causing the error: > fileinput.close ( ) > os.chmod ( fip, mode > def fixdirectory ( arg, d, dlist ) : Do you use an editor such as vim that will automatically show you matching braces, brackets and such? Y, Scot -- Scot W. Stevenson wrote me on Saturday, 21. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 2288 hours and has a CPU that is falling asleep at a system load of 0.02. From magnus@thinkware.se Sat Sep 21 10:44:14 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 21 Sep 2002 11:44:14 +0200 Subject: [Tutor] Timing calculation (fwd) In-Reply-To: Message-ID: <5.1.0.14.0.20020921093149.02b94ea0@www.thinkware.se> >Could someone please show me how to calculate the time, which is running by >a test. My program is doing: >... >os.system( "make deja %s 2>&1 | tee %s" % (makeopts,spoolfile) ) >data =3D open( spoolfile ).read() >... > >I need to get the time before and after running "make deja", then calculate >the time between. Well, it seems like you are running a unix of some sort. Then you can always time things on the os level with "time make ..." By using os.popen() instead of os.system(), the output of your os command will end up in a file handle that you can read. Look at the os.popen family of commands in the library manual. With os.popen4, you will get two file handles back, one with stdin, and another with both stdout and stderr. So if you don't need the spoolfile for anything else: import os stin, stouterr =3D os.popen4('time make deja %s' % makeopts) stin.close() # Don't pipe anything into the command dump =3D stouterr.readlines() # but get the output and errors stouterr.close() # Two last lines should be timing info data =3D "".join(dump[:-2]) timing =3D "".join(dump[-2:]) Naturally, you can also use python for the timing, but it will give you less information, and include some time actually spent in python. The time module contains a time.time() function that returns the number of seconds since midnight Jan 1 1970, and time.clock() that returns the number of seconds since...well it depends on the OS. You can use it as a timer anyway. time.clock() will sometimes reach a maximum value and start over from zero if your machine or program is running for long. time.time() should never do that (before Jan 19 2038). Python gets these times from different sources depending on OS, and they have different resolution. With a quick measurement I get these results on two AMD machines: OS |time.time()|time.clock() =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 Windows 2000 | 10 ms | ~0.010 ms Linux 2.4.3 | ~0.020 ms | 10 ms Strange, huh? The Windows machine is a 700MHz Duron, and the Linux box is a 233MHz K-6, which might explain the difference in Linux time.time() and Windows time.clock(). I don't know if the short times are limited by the OS or by Python delays. But as you notice, apart from avoiding rollover, you get a much better resolution with time.time() in Linux. In Windows you get a much better resolution with time.clock(), and should choose that when milli second resolution is needed, and time.time() otherwise to avoid rollover problems. So, finally, your code with the python timer: import time timer =3D time.time # or time.clock cmd =3D "make deja %s 2>&1 | tee %s" % (makeopts,spoolfile) start =3D timer() os.system( cmd ) stop =3D timer() print cmd, "took", stop-start, "seconds" data =3D open( spoolfile ).read() To check the resolution on the different platforms I did: >>> def x(f): ... r =3D f() ... while 1: ... r1 =3D f() ... if r1 !=3D r: ... print r1 - r ... break ... >>> import time >>> x(time.time) 0.00999999046326 >>> x(time.clock) 1.03365092343e-005 (This is obviously Windows.) --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sat Sep 21 11:02:32 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 21 Sep 2002 12:02:32 +0200 Subject: [Tutor] sorting into lists In-Reply-To: <20020921043241.GB12985@isis.visi.com> References: <20020921033729.GA8491@isis.visi.com> Message-ID: <5.1.0.14.0.20020921115834.02b70250@www.thinkware.se> At 23:32 2002-09-20 -0500, Tim Wilson wrote: >etc. The reason I need the list of lists is because it's the most >obvious way I can think of to iterate over the events and print the date >at the beginning of each inner loop. (Think nested for loops.) Think again! :) oldDate =3D None for element in straightList: date =3D getDate(element) # you figure it out if date !=3D oldDate: print date oldDate =3D date print detailsToPrint(element) Why make it more complicated than that? --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sat Sep 21 11:09:10 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 21 Sep 2002 12:09:10 +0200 Subject: [Tutor] I don't get it In-Reply-To: <3D8BFB55.E0F57C15@netzero.net> References: <1470DFB1-CCB7-11D6-BB4B-00039351FE6A@mac.com> <5.1.0.14.0.20020920190751.02b76ce0@www.thinkware.se> <200209210249.38341.yduppen@xs4all.nl> Message-ID: <5.1.0.14.0.20020921120406.0363a640@www.thinkware.se> At 00:53 2002-09-21 -0400, Kirk Bailey wrote: >Maybe I should go steal a few introductory computer science books? Or wade around in Cunningham's Wiki. Perhaps you should start with http://c2.com/cgi/wiki?XpFaq or http://c2.com/cgi/wiki?WhatIsRefactoring -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From yduppen@xs4all.nl Sat Sep 21 11:54:10 2002 From: yduppen@xs4all.nl (Yigal Duppen) Date: Sat, 21 Sep 2002 12:54:10 +0200 Subject: [Tutor] Qt book by Rempt In-Reply-To: <200209211141.33253.scot@possum.in-berlin.de> References: <3D8AF776.22712.D2CB4CD@localhost> <200209210222.00709.yduppen@xs4all.nl> <200209211141.33253.scot@possum.in-berlin.de> Message-ID: <200209211254.12985.yduppen@xs4all.nl> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > Wasn't this the book that is marred by its heavy reliance on the commercial > BlackAdder IDE? I remember that the whole first chapter was devoted to > gushing about, installing and using BlackAdder... Not really. It is true that the first five chapters are typical required 'introduction' stuff (python basics, blackadder installation etc) , but the interesting part of the book doesn't mention BlackAdder at all... Just using Qt Designer (great tool!) and emacs (ditto!) you can do everything the author does. Even funnier, Chapter 11 (Qt Designer, BlackAdder and uic) is very careful; all the BlackAdder features that are used are also explained using only Qt Designer and pyuic. As of Chapter 12, it is actually one of the best books on GUI programming I ever read. Instead of showing a window with a button, then showing a window with an input, then showing etc etc, Rempt uses the next 10 chapters to create a cool editor from scratch, explaining nice Qt concepts on the way. These 10 chapters are great fun to read and they really tie it all together. Without mentioning BlackAdder at all. > A shame, actually, because I keep hearing a lot of good stuff about Qt and > am slowly getting fed up with Tkinter... In my opinion, Qt is really nice, Qt Designer is a really good UI tool and Rempt's book is a really good book on PyQt. Hope this convinces you :) YDD - -- http://www.xs4all.nl/~yduppen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9jE/ULsKMuCf5EdwRAriiAJ9kBiUfxEdLhHRxbdUZJQCNvFnLVwCePbEk 78orlJXGKQmkVvbeYdLOQzg= =500h -----END PGP SIGNATURE----- From lists@shrestha.net.np Sat Sep 21 07:33:49 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Sat, 21 Sep 2002 12:18:49 +0545 Subject: [Tutor] Question about socket connections Message-ID: <3D8C12CD.4020307@shrestha.net.np> Rob Brown-Bayliss wrote: > On Fri, 2002-09-20 at 14:36, Ashish Shrestha wrote: > > >>I have done Gui apps with xmlrpc. Here's my logic. >> >>I implement xmlrpc client and xmlrpc server in both side (client and server) >> >>so client has a xmlrpc server + client and server has xmlrpc server+client >> >>when the client starts it registers with the server with its url >>(address and port) >> >>i then have a two way channel for communication. > > > Thats essentially what I had started, except that I had the client ask > the server for a port number, that way allowing more than one client to > operate on the same machine. > > How were you handling the actual server class in your apps? > i had the client try to start the its xmlrpc server at say port 9000 if there is a bind exception i then try 9001 and so on till 9050 (another arbitary limit) when it is successful it registers with the server with ip:port! by the way i am using multicast to locate the server instead of giving the server address in client! so my clients are autoconfiguring. ashish From thorsten@thorstenkampe.de Sat Sep 21 15:30:56 2002 From: thorsten@thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 Sep 2002 16:30:56 +0200 Subject: [Tutor] Re: sorting into lists In-Reply-To: <20020921050302.11376.57917.Mailman@mail.python.org> References: <20020921050302.11376.57917.Mailman@mail.python.org> Message-ID: <154157961877.20020921163056@thorstenkampe.de> * Tim Wilson > l = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4] > > I'm trying to figure out a good way to turn this list into > [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]] Mathematically spoken you want a "quotient set" that is the original list partitioned into "equivalence classes". In your case the function defining "equivalence" is the identity 'f(x) = x' #v+ def quotient_set(seq, func): """ partition seq into equivalence classes """ quotient_set = {} for item in seq: quotient_set.setdefault(repr(func(item)),[]).append(item) return quotient_set #v- "quotient_set" keeps the class representatives ("keys") for further processing, so you have to get rid of them: quotient_set(l, lambda x: x).values() Equivalence classes are *very* useful. Two examples: You want to write a dictionary of words where all words starting with the same character should be in a separate chapter. 'func' is 'word[0]'. You want to group numbers into bins where each 0 < x < 10 goes in bin1, 10 <= x < 100 goes in bin2, 100 <= x < 1000 goes in bin3, etc. 'func' is modf(log10(x))[1] Thorsten From sarmxiii@knology.net Sat Sep 21 16:30:43 2002 From: sarmxiii@knology.net (montana) Date: Sat, 21 Sep 2002 10:30:43 -0500 Subject: [Tutor] Compiling Python on MacOSX. Message-ID: <17724E5C-CD77-11D6-B05D-00039315F4DA@knology.net> Hi Everyone- I'm following the directions from: http://tony.lownds.com/macosx/tkinter.html I'm trying to compile Python 2.2 with aqua Tk support for my computer. I'm running 10.2.1 on a G4 Powerbook. When I run 'make' it barfs on the followign error: Modules/_tkinter.c: In function `Sleep': Modules/_tkinter.c:252: warning: implicit declaration of function `select' make: *** [Modules/_tkinter.o] Error 1 Here is the guilty piece of code: static void Sleep(int milli) { /* XXX Too bad if you don't have select(). */ struct timeval t; t.tv_sec = milli/1000; t.tv_usec = (milli%1000) * 1000; select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); } Any ideas how to get around this? Is this an issues with the new gcc 3 on 10.2 versus the old gcc from 10.1? Thanks. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me From danny@i4.net Sat Sep 21 21:25:32 2002 From: danny@i4.net (Danny) Date: Sat, 21 Sep 2002 14:25:32 -0600 Subject: [Tutor] What would you say is the best way to continue learning python Message-ID: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> Hello and good afternoon everyone. I have now just about completed the book learn python in 24 hours although I have learned a lot I still feel very lost I have also read through the tutor and some of the doc's included in python and even downloaded them all in PDF format I still feel lost even considering that what else can I read or do to continue my learning process so I can be as good as most of you in very good time of course. Thanks for you time and consideration in my learning process Oh before I forget I have bought a lot of C++ books I want to learn that as well could those help me any in python. Thanks again and talk to you all again soon thanks Sincerely Danny D From glingl@aon.at Sat Sep 21 21:42:42 2002 From: glingl@aon.at (Gregor Lingl) Date: Sat, 21 Sep 2002 22:42:42 +0200 Subject: [Tutor] What would you say is the best way to continue learning python References: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> Message-ID: <3D8CD9C2.9070406@aon.at> Danny schrieb: >Hello and good afternoon everyone. > >I have now just about completed the book learn python in 24 hours although I >have learned a lot I still feel very lost I have also read through the tutor >and some of the doc's included in python and even downloaded them all in PDF >format I still feel lost even considering that what else can I read or do to >continue my learning process so I can be as good as most of you in very good >time of course. Thanks for you time and consideration in my learning >process Oh before I forget I have bought a lot of C++ books I want to learn >that as well could those help me any in python. > Of course! Look for some examples in those C++ books you like and recode them in Python. That would be learning by doing. Very rewarding. Gregor You also may have a look at: http://www.norvig.com/21-days.html >Thanks again and talk to you >all again soon thanks > >Sincerely Danny D > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > > From steve_lewis@openiso.com Sun Sep 22 00:24:56 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Sat, 21 Sep 2002 18:24:56 -0500 (CDT) Subject: [Tutor] What IDE do you prefer? Message-ID: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> Just curious. What are some of your favorite IDEs and/or text editors? Steve Lewis From magnus@thinkware.se Sun Sep 22 00:45:02 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 22 Sep 2002 01:45:02 +0200 Subject: [Tutor] What would you say is the best way to continue learning python In-Reply-To: <3D8CD9C2.9070406@aon.at> References: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> Message-ID: <5.1.0.14.0.20020922004855.036340e8@www.thinkware.se> At 22:42 2002-09-21 +0200, Gregor Lingl wrote: >Danny schrieb: > >>I have now just about completed the book learn python in 24 hours although= I >>have learned a lot I still feel very lost I have also read through the= tutor Read through? Did you experiment with all the things the Tutorial mentions? You won't learn how to program with your eyes. You can only learn that with your fingers! Try it out properly. Experiment. Test the limits of python and your own knowledge. The python environment is excellent to experiment in. >>and some of the doc's included in python and even downloaded them all in= PDF >>format I still feel lost even considering that what else can I read or do= to >>continue my learning process so I can be as good as most of you in very= good >>time of course. Thanks for you time and consideration in my learning >>process Oh before I forget I have bought a lot of C++ books I want to= learn >>that as well could those help me any in python. >Of course! Look for some examples in those C++ books you like and recode=20 >them in Python. >That would be learning by doing. Very rewarding. >Gregor > >You also may have a look at: >http://www.norvig.com/21-days.html Regarding Norvigs notice that it might take 10 years to learn things, I could mention the yearly programming tests referred to in DeMarco & Lister's excellent book "Peopleware". In their measurements, people with ten years of experience was not better than those with two years of experience. People with less than half a year of experience was clearly less productive though. So, perhaps it takes around a year of practice to become proficient in a programming laguage? Either way, I also suggest learning by doing. All people are different, and I don't think there is one method that fits all, but I'd try to make something practical, and then get back to this mailing list when I get stuck. A few possible assignments follow: 1. Make a program that will start programs listed in a text file. For example, a user could edit a text file so that it looked as the lines between the dashes below, and invoking the program you write, the programs would all be started. Hint: os.system() ---- excel.exe winword.exe c:\python22\python.exe ---- 2. The factorial of a number n is 1 * 2 * 3 ... (n-1) * n. E.g. the factorial of 5 is 1 * 2 * 3 * 4 * 5 =3D 120. Write a program that will calculate the factorial of a given positive number. Try a few different solutions. 3. The first fibonacci numbers are 0 and 1. The following fibonacci numbers are the sum of the two preceding fibonacci numbers. I.e. 0, 1, 1, 2, 3, 5, 8, 13 ... Write a program that will calculate the n:th fibonacci number. Try a few different solutions. 4. Write a program that will count the frequency of words in a text file. (You can run it on an archive of this mailing list and see what we talk about most! :) 5. Write a program that will print the current date and time for a location if you enter the name of a major city. (Ignore daylight savings time in the first version.) Hint: import time 6. Write a program that will ask for an activity when invoked, and store that activity with a timestamp in a text file. Having used the program for a while your text file might look like this: ---- 2002-09-22 09:15:12 program 2002-09-22 11:17:23 read email 2002-09-22 13:01:51 lunch 2002-09-22 13:47:12 program 2002-09-22 17:42:00 stop ---- 7. Write a program that reads the file in assignment 5 and summarizes the amount of time for each activity. 8. Write a program that proves that when n is an integer, n > 2, the equation x**n + y**n =3D z**n has no solution in positive integers x,y,z. (x**n is the Python notation for x to the power of n, i.e. 4**3 =3D 4*4*4.) /Magnus P.S. Assignment number 8 is not trivial. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sun Sep 22 00:54:05 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 22 Sep 2002 01:54:05 +0200 Subject: [Tutor] What IDE do you prefer? In-Reply-To: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> Message-ID: <5.1.0.14.0.20020922015344.03641418@www.thinkware.se> At 18:24 2002-09-21 -0500, Steve Lewis wrote: >Just curious. What are some of your favorite IDEs and/or text editors? I've mainly used PythonWin, SciTE, vim and emacs. They all have syntax highlighting for Python, allow programs to be executed from the editor, and at least PythonWin and SciTE are folding editors, which I like. Vim is certainly a bit difficult to get used to... Many people seem to like WingIDE. Be aware that for instance IDLE and PythonWin execute python programs in the same process as the editor/IDE is running. This makes it impossible to run GUI applications from within those. At least if they are written with a different GUI toolkit such as wxPython. But it's not a big problem to edit files in PythonWin and start them from a command prompt. If you want to try out a few, look at: http://www.thinkware.se/cgi-bin/thinki.cgi/PythonEditing and http://www.python.org/cgi-bin/moinmoin/PythonEditors -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From dyoo@hkn.eecs.berkeley.edu Sun Sep 22 01:48:00 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 21 Sep 2002 17:48:00 -0700 (PDT) Subject: [Python-Help] Re: [Tutor] What would you say is the best way to continue learning python In-Reply-To: <5.1.0.14.0.20020922004855.036340e8@www.thinkware.se> Message-ID: On Sun, 22 Sep 2002, Magnus Lycka wrote: > Regarding Norvigs notice that it might take 10 years to learn things, I > could mention the yearly programming tests referred to in DeMarco & > Lister's excellent book "Peopleware". In their measurements, people with > ten years of experience was not better than those with two years of > experience. Gerald Weinberg has written an article called "How Long Does it Take to Make a Programmer?" in his book, "Understanding the Professional Programmer". I hope he doesn't mind if I quote extensively from his book. Weinberg says: """... Programming is another subject with no shortage of experts. Six weeks of ``training'' is typically considered all that is necessary to elevate one to the ``expert'' level, beyond the need for learning anything new and qualified to design online life-support systems. When you see an advertisement for ``experienced'' programmers, it often means about one year or perhaps two years of experience... ... Yet before we go too far in ridiculing those who hold this view, we ought to acknowledge that fifteen years of experience, in and of itself, need not teach you anything about programming...""" One problem with people who do too much programming is that they risk losing perspective. To demonstrate the need for flexibility, Weinberg mentions the "Manhattan Problem": """The problem is to determine how much the $24 supposedly paid for Manhattan island in 1627 would be worth today if it had been placed in a savings account at 4.5 percent annual interest.""" One program that could do this might look like: ### year = 1627 amount = 24 while year != 2002: amount = amount * 1.045 year = year + 1 print amount ### And this works. But Weinberg mentions that there is an alternative way of solving this problem: ### amount = 24.00 * (1.045 ** (2002 - 1627)) print amount ### Weinberg continues: "If the most trivial problem imaginable can be programmed in two ways that differ in cost by factors of 5 or 100, what must the difference be between a professional and an amature job of programming an operating system?" My point is that it's not the language syntax itself that takes years to learn: it's the things we try to express as code that takes practice to get right. And not just by practicing writing code in isolation, but by looking and and understanding the programs that other people have written. > Either way, I also suggest learning by doing. All people are different, > and I don't think there is one method that fits all, but I'd try to make > something practical, and then get back to this mailing list when I get > stuck. Yes, I agree; learning by doing works, and it's my feeling that it's a lot more effective if it's done with other people. In this sense, I believe we learn any language more effectively through practice and exposure. Talk to you later! From abarker@xminc.com Sun Sep 22 01:59:57 2002 From: abarker@xminc.com (Anthony Barker) Date: Sat, 21 Sep 2002 20:59:57 -0400 Subject: [Tutor] What IDE do you prefer? References: <5.1.0.14.0.20020922015344.03641418@www.thinkware.se> Message-ID: <3D8D160D.4030109@xminc.com> Magnus Lycka wrote: > At 18:24 2002-09-21 -0500, Steve Lewis wrote: > >> Just curious. What are some of your favorite IDEs and/or text editors? > > > I've mainly used PythonWin, SciTE, vim and emacs. They all have > syntax highlighting for Python, allow programs to be executed > from the editor, and at least PythonWin and SciTE are folding > editors, which I like. emacs has a folding add-in module- have you tried it? fte has folding - but I am not crazy about it. David Mertz has a review of a dozen or so text editors http://gnosis.cx/publish/ > Vim is certainly a bit difficult to get > used to... Unless you administer unix machines in which case its necessary. Personally I try to use emacs / nedit /vim in linux and editplus in windows(with python syntax support). Anthony From rlegge@tc3net.com Sun Sep 22 02:37:16 2002 From: rlegge@tc3net.com (Ray Leggett) Date: Sat, 21 Sep 2002 21:37:16 -0400 Subject: [Tutor] 2 quick questions on python/tkinter Message-ID: <200209212137.16853.rlegge@tc3net.com> Ok, i wrote this little demo app on windows, but included the #!/bin/pyth= on=20 line so i could work on it under linux, too: -------------------------------------------------------------------------= ----------------------------- #!/usr/bin/python # File: widgets.pyw # gives basic examples of tkinter widgets from Tkinter import * # create a class to handle the gui class Application(Frame): =09def __init__(self, master=3DNone): # creates the root window =09=09Frame.__init__(self, master) =09=09self.grid() =09=09self.createWidgets() =09def createWidgets(self):=09# creates the child widgets =09=09self.label =3D Label( self, text =3D "Label!") =09=09self.label.grid() =09=09self.chkbox =3D Checkbutton(self, text =3D "Check Button") =09=09self.chkbox.grid() =09=09self.entry =3D Entry(self) =09=09self.entry.grid() =09=09self.message =3D Message(self, text =3D "Message!") =09=09self.message.grid() =09=09self.quitButton =3D Button ( self, text=3D"Quit",command=3Dself.qui= t ) =09=09self.quitButton.grid() =09=09 app =3D Application() # Instantiate the application class app.master.title("Widget Examples") app.mainloop() # Wait for events -------------------------------------------------------------------------= ----------------------------- It runs fine under windows, but under linux it gave the following error: bash: ./widgets2.py: bad interpreter: No such file or directory Oddly, it runs fine when i type python widgets2.py. Whats going on? My second question - you see the self.widget.grid() line repeated sever= al=20 times in the Application class. Is there some way i can apply the grid()= =20 function once to to all of the widgets? From sarmxiii@knology.net Sun Sep 22 02:51:27 2002 From: sarmxiii@knology.net (montana) Date: Sat, 21 Sep 2002 20:51:27 -0500 Subject: [Tutor] 2 quick questions on python/tkinter In-Reply-To: <200209212137.16853.rlegge@tc3net.com> Message-ID: Did you make the file executable?: chmod +x widgets2.py ./widget2.py will only work if it is an executable file. If it is not executable it can still be run by: python widgets2.py Hope this helps. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me On Saturday, September 21, 2002, at 08:37 PM, Ray Leggett wrote: > Ok, i wrote this little demo app on windows, but included the > #!/bin/python > line so i could work on it under linux, too: > > ----------------------------------------------------------------------- > ------------------------------- > #!/usr/bin/python > > # File: widgets.pyw > > # gives basic examples of tkinter widgets > > from Tkinter import * > > # create a class to handle the gui > > class Application(Frame): > def __init__(self, master=None): # creates the root window > Frame.__init__(self, master) > self.grid() > self.createWidgets() > def createWidgets(self): # creates the child widgets > self.label = Label( self, text = "Label!") > self.label.grid() > self.chkbox = Checkbutton(self, text = "Check Button") > self.chkbox.grid() > self.entry = Entry(self) > self.entry.grid() > self.message = Message(self, text = "Message!") > self.message.grid() > self.quitButton = Button ( self, text="Quit",command=self.quit ) > self.quitButton.grid() > > > app = Application() # Instantiate the application class > app.master.title("Widget Examples") > app.mainloop() # Wait for events > > ----------------------------------------------------------------------- > ------------------------------- > > It runs fine under windows, but under linux it gave the following > error: > > bash: ./widgets2.py: bad interpreter: No such file or directory > > Oddly, it runs fine when i type python widgets2.py. Whats going on? > > My second question - you see the self.widget.grid() line repeated > several > times in the Application class. Is there some way i can apply the > grid() > function once to to all of the widgets? > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > From dyoo@hkn.eecs.berkeley.edu Sun Sep 22 03:10:05 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 21 Sep 2002 19:10:05 -0700 (PDT) Subject: [Tutor] 2 quick questions on python/tkinter In-Reply-To: <200209212137.16853.rlegge@tc3net.com> Message-ID: > It runs fine under windows, but under linux it gave the following error: > > bash: ./widgets2.py: bad interpreter: No such file or directory > > Oddly, it runs fine when i type python widgets2.py. Whats going on? It sounds like the magic line: > #!/usr/bin/python isn't doing the right thing; let's double check to see where the Python executable is really located. What happens when you try: ### $ which python ### at your shell prompt? Also, the following alternative magic line: ### #!/usr/bin/env python ### might work better for you; this will search your path for the first available Python interpreter it can find, and the run with that, so you won't have to hardcode the path that Python lives in. > My second question - you see the self.widget.grid() line repeated > several times in the Application class. Is there some way i can apply > the grid() function once to to all of the widgets? Yes, it does look a bit repetitive. Hmmmm.. perhaps something like: ### for widget in [self, self.label, self.chkbox, self.entry, self.message, self.quitbutton]: widget.grid() ### might work? What this loop does is allow us to apply the grid() method to each widget that's in that list above. It does still feel a little weird having to write out the widgets manually. Since an object's attributes live in a special attribute dictionary named '__dict__', we can restate the above and take advantage of __dict__: ### for widget in self.__dict__.values(): widget.grid() #### This assumes, though, that all the object's attributes will be widgets. But something like this should be better than having to manually type out 'foo.grid()' all the time... *grin* Good luck! From dyoo@CSUA.Berkeley.EDU Sun Sep 22 03:21:27 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Sat, 21 Sep 2002 19:21:27 -0700 (PDT) Subject: [Tutor] sorting into lists In-Reply-To: <5.1.0.14.0.20020921115834.02b70250@www.thinkware.se> Message-ID: <20020921191644.I88373-100000@soda.csua.berkeley.edu> On Sat, 21 Sep 2002, Magnus Lycka wrote: > At 23:32 2002-09-20 -0500, Tim Wilson wrote: > >etc. The reason I need the list of lists is because it's the most > >obvious way I can think of to iterate over the events and print the date > >at the beginning of each inner loop. (Think nested for loops.) > > Think again! :) > > oldDate = None > > for element in straightList: > date = getDate(element) # you figure it out > if date != oldDate: > print date > oldDate = date > print detailsToPrint(element) > > Why make it more complicated than that? This looks much better for Tim's task. At least, this approach is simpler than forming mathematical equivalence classes. *grin* We need to make sure that our straightList is sorted by date, so that common elements are grouped together sequentially, but Tim has to do that anyway to display his events in chronological order. From idiot1@netzero.net Sun Sep 22 05:38:06 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 22 Sep 2002 00:38:06 -0400 Subject: [Tutor] guess the error cause time! Message-ID: <3D8D492E.90AAE329@netzero.net> OK, here is the error: File "/www/www.tinylist.org/cgi-bin/TLcommander.py", line 155, in bullshit if data not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_": TypeError: string member test needs char left operand A char left operand??? pardon, but WTF? and here is the code: def bullshit(data): # this detects evil data (we HOPE)... for i in data: # slice the data nicely if data not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_": print "ERROR: input invalid. Please click [BACK] on the browser and modify input." footer() #160 close the page out sys.exit() # and abort execution. I$ # -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From dyoo@CSUA.Berkeley.EDU Sun Sep 22 05:51:23 2002 From: dyoo@CSUA.Berkeley.EDU (Daniel Yoo) Date: Sat, 21 Sep 2002 21:51:23 -0700 (PDT) Subject: [Tutor] guess the error cause time! In-Reply-To: <3D8D492E.90AAE329@netzero.net> Message-ID: <20020921214350.Q1088-100000@soda.csua.berkeley.edu> On Sun, 22 Sep 2002, Kirk Bailey wrote: > OK, here is the error: > > File "/www/www.tinylist.org/cgi-bin/TLcommander.py", line 155, in bullshit > if data not in > "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_": > TypeError: string member test needs char left operand What it's saying is that 'data' itself is not a single character. It's a good thing that it's saying that because it's pointing out a bug in the code: ### def bull(data): for i in data: if data not in ("abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"): ## [rest of body cut] ### In particular, the variable 'i' is not being used anywhere in this loop, but I think you really do mean to use it... somewhere... *grin* A regular-expression approach to your problem might be to use a "negative" character class: ### def bull(data): good_chars = ("abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_") evil_pattern = re.compile('[^%s]' % good_chars) if evil_pattern.search(data): pass # ... we've detected evil characters in the string. ### Good luck! From idiot1@netzero.net Sun Sep 22 06:04:13 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 22 Sep 2002 01:04:13 -0400 Subject: [Tutor] hairpull but making progress Message-ID: <3D8D4F4D.7162E543@netzero.net> Well, there's good news and bad news. GOOD: TL1.4.0 is almost ready. TLpost now honors a persona non grata file on a per list basis, and has better footer logic- smaller, and the link to the manager aims you right at the menu for THAT list. Also, the menu system now supports the offering of UNREVEALED lists- right, unpublished lists. All along the menu page simply ignored lists that had no info file for them; the problem was the script that would (try to) read the info file and place it's contents on the page with the form- it would explode into random numbers when trying to handle a secret list. Now, TLwebform2.py (the one generating the form and listing the info file), does not balk if there is no info file; The list simply does not show up on the menu TLwebmgr generates, but IF YOU KNOW THE LINK, you can still bring up the form to manage subscriptions. No info of course, but it simply says as much and drives on. This means if you want a private list, you TELL someone about it and give them the link- which appears in every footer generated on the fly by TLpost, along with a link to click to post a new message to the list. This in no way hampers any other function. TLmembershiproster some people want to be sure everyone really is in the list that should be there- managers, a fire department, the local masonic lodge, whatever, they want to be sure in an instant that all people who SHOULD be members ARE members. OK, easy to do with ssi, but insecure as all hell- ANYONE tripping over the link can read all those email addresses! So script 1 offers a form, all preformatted automagically; you fill in YOUR email as listowner (new concept), password, and the list's name. All is well, out comes the list data. It works fine, but it has GOT to be hacker resistant, so the BS repellent in the next section has GOT to be resolved. BAD: working on making it even more hack resistant, but the BS detector is giving me twitches. Seems to refuse to scan strings passed to it, demanding something I don't recognize, which I described on tutor list in previous postings. Will have this licked in 3 days or less, and then 1.4.0 will be on the download area. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 22 06:09:35 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 22 Sep 2002 01:09:35 -0400 Subject: [Tutor] demo link for commander Message-ID: <3D8D508F.E6778781@netzero.net> if you want to look at commander, here is a SSI include of the current script in the server undergoing beta testing. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From shiska@swbell.net Sun Sep 22 06:12:36 2002 From: shiska@swbell.net (Bob Roher) Date: Sun, 22 Sep 2002 00:12:36 -0500 Subject: [Tutor] newbie looking for code suggestions Message-ID: <004101c261f6$abf367a0$6401a8c0@swbell.net> This is a multi-part message in MIME format. --Boundary_(ID_98i9W9TVP61EExAtuef3Fg) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Hi all. I was wondering if anyone could look over the following code and give me any suggestions or criticisms? I just started learning Python a few days ago, so I'm sure there's a lot that can be done to make it look and run better. #This program was written in response to following question: #How many numbers between 1 and 999999 have 21 as the total of #their digits? #For example: 902,550 is 9+0+2+5+5+0 = 21 #After finding the answer, I wanted to expand it to find any total #in an integer range. #This function will take an integer as input and return the sum of #its digits. def sum_of_digits(in_string): sum = 0 t = 0 for n in in_string: t = int(n) sum = sum + t return sum print """This program finds all the integers in a user-specified range that have a user-specified digit total.""" max_possible = 0 run_again = "y" #User enters parameters for min, max, and what I call digit total for #lack of a better word. while run_again == "y": min_number = raw_input("Enter a start integer: ") max_number = raw_input("Enter a stop integer: ") digit_total = raw_input("What digit total would you like: ") x = "" p = 0 running_total = 0 #Passes each number in the range to sum_of_digits function as a string. for y in range (int(min_number), int(max_number)+1): x = str(y) p = sum_of_digits(x) #Checks to see if condition is met; if so, counter is incremented. if p == int(digit_total): running_total = running_total + 1 #Checks to make sure the user digit total wasn't too big. if p > max_possible: max_possible = p if int(digit_total)>max_possible: print "No possible way to get that digit total in that number range." print "The highest total possible is: ",max_possible run_again = raw_input("Would you like to run this program again? y/n: ") if run_again == "y": pass #Shows the number of integers that meet the criteria and allows user to run #program again if desired. else: print "Total number of integers with a digit total of",digit_total,"is: ",running_total run_again = raw_input("Would you like to run this program again? y/n: ") One thing I would like to do is be able to have the user re-enter digit_total if they enter one that is too big without re-running the program. I tried a few things, but am having trouble passing control back to the main while loop if I add another prompt in there. I would also like to compute max_possible independently so that I could run all possible digit_totals for a range, but I think it would have to run through the entire range to compute that first. Sorry if I am confusing you, I know what I want it to do, but I'm finding it hard to describe. --Boundary_(ID_98i9W9TVP61EExAtuef3Fg) Content-type: text/html; charset=iso-8859-1 Content-transfer-encoding: 7BIT
Hi all.  I was wondering if anyone could look over the following code and give me any suggestions or criticisms?  I just started learning Python a few days ago, so I'm sure there's a lot that can be done to make it look and run better.
 
#This program was written in response to following question:
#How many numbers between 1 and 999999 have 21 as the total of
#their digits?
#For example: 902,550 is 9+0+2+5+5+0 = 21
#After finding the answer, I wanted to expand it to find any total
#in an integer range.
 

#This function will take an integer as input and return the sum of
#its digits.
def sum_of_digits(in_string):
    sum = 0
    t = 0
    for n in in_string:
        t = int(n)
        sum = sum + t
    return sum
 
print """This program finds all the integers in a user-specified range
that have a user-specified digit total."""
 
max_possible = 0
run_again = "y"
 
#User enters parameters for min, max, and what I call digit total for
#lack of a better word.
while run_again == "y": 
    min_number = raw_input("Enter a start integer: ")
    max_number = raw_input("Enter a stop integer: ")
    digit_total = raw_input("What digit total would you like: ")
   
    x = ""
    p = 0
    running_total = 0
 
#Passes each number in the range to sum_of_digits function as a string.
    for y in range (int(min_number), int(max_number)+1):
        x = str(y)
        p = sum_of_digits(x)
 
#Checks to see if condition is met; if so, counter is incremented.
        if p == int(digit_total):
            running_total = running_total + 1
 
#Checks to make sure the user digit total wasn't too big. 
        if p > max_possible:
            max_possible = p
    if int(digit_total)>max_possible:
        print "No possible way to get that digit total in that number range."
        print "The highest total possible is: ",max_possible
        run_again = raw_input("Would you like to run this program again?  y/n: ")
        if run_again == "y":
            pass
 
#Shows the number of integers that meet the criteria and allows user to run
#program again if desired.           
    else:
        print "Total number of integers with a digit total of",digit_total,"is: ",running_total
        run_again = raw_input("Would you like to run this program again?  y/n: ")
 
One thing I would like to do is be able to have the user re-enter digit_total if they enter one that is too big without re-running the program.  I tried a few things, but am having trouble passing control back to the main while loop if I add another prompt in there.  I would also like to compute max_possible independently so that I could run all possible digit_totals for a range, but I think it would have to run through the entire range to compute that first.  Sorry if I am confusing you, I know what I want it to do, but I'm finding it hard to describe.
--Boundary_(ID_98i9W9TVP61EExAtuef3Fg)-- From shalehperry@attbi.com Sun Sep 22 06:24:42 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Sat, 21 Sep 2002 22:24:42 -0700 Subject: [Tutor] newbie looking for code suggestions In-Reply-To: <004101c261f6$abf367a0$6401a8c0@swbell.net> References: <004101c261f6$abf367a0$6401a8c0@swbell.net> Message-ID: <200209212224.42765.shalehperry@attbi.com> On Saturday 21 September 2002 22:12, Bob Roher wrote: > > #This function will take an integer as input and return the sum of > #its digits. > def sum_of_digits(in_string): > sum =3D 0 > t =3D 0 > for n in in_string: > t =3D int(n) > sum =3D sum + t > return sum > def sum_of_digits(in_string): return reduce(lambda x,y: int(x) + int(y), in_string) is another approach. Here's another without the lambda: def sum_of_digits(in_string): import operator return reduce(operator.add, map(int, in_string)) What this does is call 'map(int, in_string)' which call the function 'int= ' on=20 each char in the string and put it in a new list: >>> s =3D '1024' >>> map(int, s) [1, 0, 2, 4] reduce then walks this new list and calls operator.add on it. > > One thing I would like to do is be able to have the user re-enter > digit_total if they enter one that is too big without re-running the > program. I tried a few things, but am having trouble passing control b= ack > to the main while loop if I add another prompt in there. I would also = like > to compute max_possible independently so that I could run all possible > digit_totals for a range, but I think it would have to run through the > entire range to compute that first. Sorry if I am confusing you, I kno= w > what I want it to do, but I'm finding it hard to describe. I often find that if I sit down away from the computer and sketch out the= plan=20 things make more sense. Do not write in python code, just ideas or psued= o=20 fragments. Any time we learn something new we also have to learn a vocabulary. =20 Mechanics, doctors, knitting circles, etc all have their jargons. This is actually a pretty good program that has several places for you to= =20 learn new things. From idiot1@netzero.net Sun Sep 22 06:33:57 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 22 Sep 2002 01:33:57 -0400 Subject: [Tutor] this is even stranger Message-ID: <3D8D5645.76A8470B@netzero.net> ok, I tried a sample in idle, worked fine. apple='123456789' for i in apple: print i >>> 1 2 3 4 5 6 7 8 9 >>> OK, I spotted a type, glaring really, must be tired, was referring 'data', not 'i' in the loop. ok, fixed. Still barks. http://www.tinylist.org/TLcommander.shtml is the ssi page linking to the script that is in there RIGHT NOW. also, try this: http://www.tinylist.org/cgi-bin/TLwebform2.py?secret and up comes the form page with everything for a demonstration SECRET LIST (shhh...) Last, here is the membership roster form. http://www.tinylist.org/cgi-bin/TLmembershipform.py owner id: highprimate@howlermonkey.net (that's me) owner pw: fubar Feel free to try it out. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From shalehperry@attbi.com Sun Sep 22 06:46:21 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Sat, 21 Sep 2002 22:46:21 -0700 Subject: [Tutor] this is even stranger In-Reply-To: <3D8D5645.76A8470B@netzero.net> References: <3D8D5645.76A8470B@netzero.net> Message-ID: <200209212246.21857.shalehperry@attbi.com> On Saturday 21 September 2002 22:33, Kirk Bailey wrote: > > OK, I spotted a type, glaring really, must be tired, was referring 'dat= a', > not 'i' in the loop. ok, fixed. Still barks. > if you are still getting the same error message try adding a 'print type(= i)'=20 to the code. Also, loading the code in a browser it came up rather odd, could you post= the=20 relevant section of code when you respond to the list next. From idiot1@netzero.net Sun Sep 22 07:34:33 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sun, 22 Sep 2002 02:34:33 -0400 Subject: [Tutor] ok Message-ID: <3D8D6479.8FDE2ACD@netzero.net> ok, I chased all them bugs, it APPEARS to be working, now come the cold cruel FUN part. Beat on it. I mean, HACK the thing. can you make it open up, unzip, and bend over? if so, stop, write a letter, and tell me how you did it. -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From glingl@aon.at Sun Sep 22 08:50:41 2002 From: glingl@aon.at (Gregor Lingl) Date: Sun, 22 Sep 2002 09:50:41 +0200 Subject: [Tutor] What would you say is the best way to continue learning python References: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> <5.1.0.14.0.20020922004855.036340e8@www.thinkware.se> Message-ID: <3D8D7651.4030102@aon.at> Magnus Lycka schrieb: > 8. Write a program that proves that when n is an integer, > n > 2, the equation x**n + y**n = z**n has no solution in > positive integers x,y,z. (x**n is the Python notation for > x to the power of n, i.e. 4**3 = 4*4*4.) > > > /Magnus > > P.S. Assignment number 8 is not trivial. > 1. Python (version >=2.2) certainly is especially well suited for this problem, because of its automatic type conversion between int and long. 2. Moreover this problem has the advantage, that speed of execution doesn't play any role. Python would solve it in exactly the same time as for instance C. 3. This assignment is especially rewarding, if you decide not to use your computer any more (for anything else) ;-) 4. If not, a less ressource-consuming problem would be to determine all triples (x,y,z) within e given range, with no common divisor, that solve the equation x**2+y**2=z**2. Gregor From dyoo@hkn.eecs.berkeley.edu Sun Sep 22 09:05:09 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 22 Sep 2002 01:05:09 -0700 (PDT) Subject: [Tutor] newbie looking for code suggestions In-Reply-To: <200209212224.42765.shalehperry@attbi.com> Message-ID: > > One thing I would like to do is be able to have the user re-enter > > digit_total if they enter one that is too big without re-running the > > program. I tried a few things, but am having trouble passing control back > > to the main while loop if I add another prompt in there. I would also like > > to compute max_possible independently so that I could run all possible > > digit_totals for a range, but I think it would have to run through the > > entire range to compute that first. Sorry if I am confusing you, I know > > what I want it to do, but I'm finding it hard to describe. > > I often find that if I sit down away from the computer and sketch out the plan > things make more sense. Do not write in python code, just ideas or psuedo > fragments. > > Any time we learn something new we also have to learn a vocabulary. > Mechanics, doctors, knitting circles, etc all have their jargons. > > This is actually a pretty good program that has several places for you > to learn new things. I'm sorry, Bob: I just couldn't help myself. This problem was so interesting to me that I wrote up a completely warped way of solving it. *grin* Here's another approach to the problem for anyone's who's interested: *** spoiler space ahead! *** *** We're in! *** """How many numbers between 1 and 999999 have 21 as the total of their digits? For example: 902,550 is 9+0+2+5+5+0 = 21. This is a sample solution to the problem using some combinatorial math. Danny Yoo (dyoo@hkn.eecs.berkeley.edu) (See 'http://mail.python.org/pipermail/tutor/2002-September/017436.html' for the origins of this code.) Here's the weird approach I'm taking for this problem. We can first check to see what distinct digits will add up to 21. For example, the following digits all add up to 21: [9, 9, 1, 1, 1, 0], [9, 7, 2, 1, 1, 1], [6, 6, 3, 3, 3, 0], [4, 4, 4, 3, 3, 3]] Let me call each one of these a "partition" of 21. One property of these partitions is that we can just jumble each one, and if we account for all possible permutations of each digit list, we should be able to generate all the possible numbers in the problem. All we need to do, then is, is generate all the possible partitions of 21 that use 9 digits. Once we have that, we count all the possible permutation of each partition, and we have our answer.""" def partition(n): """Given a number n > 0, returns all possible partitions of that number. For example: partition(1) = [[1]] partition(2) = [[2], [1, 1]] partition(3) = [[3], [2, 1], [1, 1, 1]] partition(4) = [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]] By the way, this is a generalization of the "change-making" problem that every CS student reads about at least three times... *grin*""" return _partition(n, n) def _partition(n, max): """Returns all partitions of n, if each partition is restricted to using numbers less than max.""" if n < 0: return [] elif n == 0: return [[]] else: parts = [] for x in range(max, 0, -1): mini_parts = _partition(n-x, x) if mini_parts: parts.extend([[x] + p for p in mini_parts]) return parts """Here are the possible set of digits we can use to sum up to 21:""" POSSIBLE_DIGITS = [part for part in _partition(21, 9) if len(part) <= 6] ## I need a few more functions to do permutation counting: def count_perms_with_repeats(L): """Returns the number of permutations of L exist, if not all of the elements in L are distinct. For example, [9, 9, 3] has: 3! / (2!) = 3 permutations ([9, 9, 3], [9, 3, 9], [3, 9, 9]) """ return (factorial(len(L)) / product([factorial(count) for count in histogram(L).values()])) def pad_with_zero(digits, n): return digits + [0]*(n-len(digits)) def factorial(n): result = 1 for i in range(1, n+1): result = result * i return result def histogram(l): dict = {} for x in l: dict[x] = dict.get(x, 0) + 1 return dict def product(L): """Returns the product of all the numbers in L""" return reduce(lambda x, y: x*y, L) def sum(L): """Returns the product of all the numbers in L""" return reduce(lambda x, y: x+y, L) """Now that we have this, all we need to do is go through each digit set and count all the ways we can mix the digits around.""" ANSWER = sum([count_perms_with_repeats(pad_with_zero(digits, 6)) for digits in POSSIBLE_DIGITS]) print ANSWER From dyoo@hkn.eecs.berkeley.edu Sun Sep 22 09:09:24 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 22 Sep 2002 01:09:24 -0700 (PDT) Subject: [Tutor] newbie looking for code suggestions In-Reply-To: Message-ID: Doh. There's an error in the comment I have in my source code: > 21 that use 9 digits. Once we have that, we count all the possible ^ I meant to say 6. I don't know why I have such a hard time distinguishing between 2*3 and 3*3. *grin* From thorsten@thorstenkampe.de Sun Sep 22 13:13:15 2002 From: thorsten@thorstenkampe.de (Thorsten Kampe) Date: Sun, 22 Sep 2002 14:13:15 +0200 Subject: [Tutor] Re: newbie looking for code suggestions In-Reply-To: <20020922081002.28057.51973.Mailman@mail.python.org> References: <20020922081002.28057.51973.Mailman@mail.python.org> Message-ID: <11464707464.20020922141315@thorstenkampe.de> * Bob Roher > Hi all. I was wondering if anyone could look over the following code and give me any suggestions or criticisms? I just started learning Python a few days ago, so I'm sure there's a lot that can > be done to make it look and run better. Please insert line breaks at about column 70 so your readers do not have to scroll horizontally. > #This program was written in response to following question: > #How many numbers between 1 and 999999 have 21 as the total of > #their digits? > #For example: 902,550 is 9+0+2+5+5+0 = 21 > #After finding the answer, I wanted to expand it to find any total > #in an integer range. First you should separate the core code (algorithm) from the input/output/error checking stuff. The "total of their digits" is the "cross sum" of a number. I've written three variations to demonstrate different techniques: #v+ def cross_sum(integer): if integer: return integer % 10 + cross_sum(integer / 10) else: return 0 def cross_sum(integer): sum = 0 while integer: sum += integer % 10 integer /= 10 return sum def cross_sum(integer): sum = 0 for digit in str(integer): sum += int(digit) return sum #v- The iterative version ("while") performs best. Okay, so mathematically spoken, you want the size of a certain list where each item is equivalent to the others by it's cross sum (sorry Magnus). This is the code for the "equivalent lists": #v+ def quotient_set(seq, func): """ partition seq into equivalence classes """ quotient_set = {} for item in seq: quotient_set.setdefault(repr(func(item)),[]).append(item) return quotient_set #v- That's all: >>> min_number, max_number, digit_total = 1, 999999, 21 >>> len(quotient_set(range(min_number, max_number+1), cross_sum)[str(digit_total)]) 39962 cpu: 28.121, total: 29.832 > > > > > > > >
Hi all.  I was wondering if anyone could look > over the following code and give me any suggestions or criticisms?  I just > started learning Python a few days ago, so I'm sure there's a lot that can be > done to make it look and run better.
Please omit the HTML part. Thanks! Thorsten From wolf_binary@hotmail.com Sun Sep 22 16:50:59 2002 From: wolf_binary@hotmail.com (CameronStoner) Date: Sun, 22 Sep 2002 08:50:59 -0700 Subject: [Tutor] publishing programs Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C26215.2C781E20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, How do programs get published and people make money from them? Thanks, Cameron Stoner ------=_NextPart_000_0007_01C26215.2C781E20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
How do programs get published and = people make money=20 from them?
 
Thanks,
 
Cameron = Stoner
------=_NextPart_000_0007_01C26215.2C781E20-- From lsloan@umich.edu Sun Sep 22 15:02:49 2002 From: lsloan@umich.edu (Lance E Sloan) Date: Sun, 22 Sep 2002 10:02:49 -0400 Subject: [Tutor] Compiling Python on MacOSX. In-Reply-To: References: Message-ID: <4147140.1032688969@[192.168.2.201]> --On Saturday, September 21, 2002 10:30 -0500 montana wrote: > I'm following the directions from: > http://tony.lownds.com/macosx/tkinter.html > > I'm trying to compile Python 2.2 with aqua Tk support for my computer. > I'm running 10.2.1 on a G4 Powerbook. Hey! I'm trying to do the exact same thing with the same setup. > When I run 'make' it barfs on the > followign error: > > Modules/_tkinter.c: In function `Sleep': > Modules/_tkinter.c:252: warning: implicit declaration of function `select' > make: *** [Modules/_tkinter.o] Error 1 Sorry to hear that. I had no problem with that at all. Where did you get Python from? Was it CVS or the latest tar file? I used the tar file. The problem I ran into was from step 5, where Tony recommeded adding "-I/usr/X11R6/include/". I ended up emailing Tony and asked him if that was really necessary because I don't want to install X11. I also just tried removing that line and I found it would all compile, but Tkinter and Tk didn't play well together. It produced all kinds of errors. I received Tony's response later that I should use Tk 8.4.0 (the final release?) rather than 8.4a4 (the alpha/beta?). The problem is, it is only available as source. I'm having trouble figuring out how to build and install it using Project Builder. Apparently it has to be built that way, because just using make didn't work. Tony has AquaTk available as part of a 41 MB IDLE_snapshot, but that's too big for me to download over my slow-ish cable/AirPort connection. I've emailed Tony again this morning to see if he knows of any instructions to guide me through building AquaTk with Project Builder. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From grimmtooth@softhome.net Sun Sep 22 15:52:39 2002 From: grimmtooth@softhome.net (Jeff Grimmett) Date: Sun, 22 Sep 2002 10:52:39 -0400 Subject: [Tutor] What IDE do you prefer? In-Reply-To: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> Message-ID: > Just curious. What are some of your favorite IDEs and/or text editors? Oh, goody, I haven't been in a text editor flamewar in years :-) Seriously: I've been using CodeWright on Win. But just until something better comes along. Which hasn't yet. From scot@possum.in-berlin.de Sun Sep 22 11:29:07 2002 From: scot@possum.in-berlin.de (Scot W. Stevenson) Date: Sun, 22 Sep 2002 12:29:07 +0200 Subject: [Tutor] What IDE do you prefer? In-Reply-To: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> References: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> Message-ID: <200209221229.07784.scot@possum.in-berlin.de> Hello Steve, > Just curious. What are some of your favorite IDEs and/or text editors? If you use all ten fingers to type, definitely take the time to learn vim for both. It has wonderful Python support (including automatically continuing comments), there is a version for every platform, and you will only have to learn how to use one editor for the rest of you life. Y, Scot -- Scot W. Stevenson wrote me on Sunday, 22. Sep 2002 in Zepernick, Germany on his happy little Linux system that has been up for 2313 hours and has a CPU that is falling asleep at a system load of 0.05. From abarker@xminc.com Sun Sep 22 16:37:38 2002 From: abarker@xminc.com (Anthony Barker) Date: Sun, 22 Sep 2002 11:37:38 -0400 Subject: [Tutor] Stackless Python vs pyco vs OS? References: <004101c261f6$abf367a0$6401a8c0@swbell.net> Message-ID: <3D8DE3C2.9070502@xminc.com> I still don't 100% understand stackless python OK it doesn't use the C stack It is faster for doing recursion and a bit faster overall Why else would someone use it? Async I/0 Microthreads Wouldn't this be better in the OS level? The 2.5x linux kernel contains support for both those things. What about psyco - wouldn't that have much of the same effect? Anthony From sarmxiii@knology.net Sun Sep 22 21:40:44 2002 From: sarmxiii@knology.net (montana) Date: Sun, 22 Sep 2002 15:40:44 -0500 Subject: [Tutor] Compiling Python on MacOSX. In-Reply-To: <4147140.1032688969@[192.168.2.201]> Message-ID: <91204C79-CE6B-11D6-B94D-00039315F4DA@knology.net> --Apple-Mail-2-732953390 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; format=flowed Here was Tony's response to my problem: I believe you are using latest snapshot from Tcl.sf.net, 8.4a4 - thats=20= pretty old at this point. Either find some X11 headers or compile from=20= Tk 8.4.0 source using these commands (I am just copying from a post in=20= the tcl-mac@lists.sourceforge.net mailing list - it worked great for me=20= but YMMV, ask there if you have troubles). =A0=A0=A0=A0=A0=A0=A0curl -O=20 http://telia.dl.sourceforge.net/sourceforge/tcl/tcl8.4.0-src.tar.gz =A0=A0=A0=A0curl -O=20 http://telia.dl.sourceforge.net/sourceforge/tcl/tk8.4.0-src.tar.gz =A0=A0=A0=A0=A0tar zxf tcl8.4.0-src.tar.gz; ln -fs tcl8.4.0 tcl =A0=A0=A0=A0=A0=A0=A0tar zxf tk8.4.0-src.tar.gz; ln -fs tk8.4.0 tk =A0=A0pushd tcl/macosx =A0=A0=A0=A0=A0=A0=A0make =A0=A0=A0sudo make install =A0=A0=A0=A0=A0=A0popd =A0=A0=A0cp tk/generic/prolog.ps tk/library =A0=A0=A0=A0=A0pushd tk/macosx make =A0=A0=A0sudo make install =A0=A0=A0=A0=A0=A0popd -Tony I'm trying this now. I will let you know how it goes. Thanks. SA "I can do everything on my Mac I used to do on my PC, plus alot more=20 ..." --Me On Sunday, September 22, 2002, at 09:02 AM, Lance E Sloan wrote: > --On Saturday, September 21, 2002 10:30 -0500 montana=20 > wrote: >> I'm following the directions from: >> http://tony.lownds.com/macosx/tkinter.html >> >> I'm trying to compile Python 2.2 with aqua Tk support for my=20 >> computer. >> I'm running 10.2.1 on a G4 Powerbook. > > Hey! I'm trying to do the exact same thing with the same setup. > >> When I run 'make' it barfs on the >> followign error: >> >> Modules/_tkinter.c: In function `Sleep': >> Modules/_tkinter.c:252: warning: implicit declaration of function=20 >> `select' >> make: *** [Modules/_tkinter.o] Error 1 > > Sorry to hear that. I had no problem with that at all. Where did you=20= > get Python from? Was it CVS or the latest tar file? I used the tar=20= > file. > > The problem I ran into was from step 5, where Tony recommeded adding=20= > "-I/usr/X11R6/include/". I ended up emailing Tony and asked him if=20 > that was really necessary because I don't want to install X11. I also=20= > just tried removing that line and I found it would all compile, but=20 > Tkinter and Tk didn't play well together. It produced all kinds of=20 > errors. > > I received Tony's response later that I should use Tk 8.4.0 (the final=20= > release?) rather than 8.4a4 (the alpha/beta?). The problem is, it is=20= > only available as source. I'm having trouble figuring out how to=20 > build and install it using Project Builder. Apparently it has to be=20= > built that way, because just using make didn't work. Tony has AquaTk=20= > available as part of a 41 MB IDLE_snapshot, but that's too big for me=20= > to download over my slow-ish cable/AirPort connection. > > I've emailed Tony again this morning to see if he knows of any=20 > instructions to guide me through building AquaTk with Project Builder. > > --Apple-Mail-2-732953390 Content-Transfer-Encoding: quoted-printable Content-Type: text/enriched; charset=ISO-8859-1 Here was Tony's response to my problem: I believe you are using latest snapshot from Tcl.sf.net, 8.4a4 - thats pretty old at this point. Either find some X11 headers or compile from Tk 8.4.0 source using these commands (I am just copying from a post in the tcl-mac@lists.sourceforge.net mailing list - it worked great for me but YMMV, ask there if you have troubles). =A0=A0=A0=A0=A0=A0=A0curl -O http://telia.dl.sourceforge.net/sourceforge/tcl/tcl8.4.0-src.tar.gz =A0=A0=A0=A0curl -O http://telia.dl.sourceforge.net/sourceforge/tcl/tk8.4.0-src.tar.gz =A0=A0=A0=A0=A0tar zxf tcl8.4.0-src.tar.gz; ln -fs tcl8.4.0 tcl =A0=A0=A0=A0=A0=A0=A0tar zxf tk8.4.0-src.tar.gz; ln -fs tk8.4.0 tk =A0=A0pushd tcl/macosx =A0=A0=A0=A0=A0=A0=A0make =A0=A0=A0sudo make install =A0=A0=A0=A0=A0=A0popd =A0=A0=A0cp tk/generic/prolog.ps tk/library =A0=A0=A0=A0=A0pushd tk/macosx make =A0=A0=A0sudo make install =A0=A0=A0=A0=A0=A0popd -Tony I'm trying this now. I will let you know how it goes. Thanks. SA "I can do everything on my Mac I used to do on my PC, plus alot more ..." --Me On Sunday, September 22, 2002, at 09:02 AM, Lance E Sloan wrote: --On Saturday, September 21, 2002 10:30 -0500 montana < wrote: I'm following the directions from: http://tony.lownds.com/macosx/tkinter.html I'm trying to compile Python 2.2 with aqua Tk support for my computer. I'm running 10.2.1 on a G4 Powerbook. Hey! I'm trying to do the exact same thing with the same setup. When I run 'make' it barfs on the followign error: Modules/_tkinter.c: In function `Sleep': Modules/_tkinter.c:252: warning: implicit declaration of function `select' make: *** [Modules/_tkinter.o] Error 1 Sorry to hear that. I had no problem with that at all. Where did you get Python from? Was it CVS or the latest tar file? I used the tar file. The problem I ran into was from step 5, where Tony recommeded adding "-I/usr/X11R6/include/". I ended up emailing Tony and asked him if that was really necessary because I don't want to install X11. I also just tried removing that line and I found it would all compile, but Tkinter and Tk didn't play well together. It produced all kinds of errors. I received Tony's response later that I should use Tk 8.4.0 (the final release?) rather than 8.4a4 (the alpha/beta?). The problem is, it is only available as source. I'm having trouble figuring out how to build and install it using Project Builder. Apparently it has to be built that way, because just using make didn't work. Tony has AquaTk available as part of a 41 MB IDLE_snapshot, but that's too big for me to download over my slow-ish cable/AirPort connection. I've emailed Tony again this morning to see if he knows of any instructions to guide me through building AquaTk with Project Builder. = --Apple-Mail-2-732953390-- From lsloan@umich.edu Sun Sep 22 21:45:04 2002 From: lsloan@umich.edu (Lance E Sloan) Date: Sun, 22 Sep 2002 16:45:04 -0400 Subject: [Tutor] Compiling Python on MacOSX. In-Reply-To: <91204C79-CE6B-11D6-B94D-00039315F4DA@knology.net> References: <91204C79-CE6B-11D6-B94D-00039315F4DA@knology.net> Message-ID: <5150112.1032713104@[192.168.2.201]> --On Sunday, September 22, 2002 15:40 -0500 montana =20 wrote: > =A0=A0=A0=A0=A0=A0=A0curl -O > http://telia.dl.sourceforge.net/sourceforge/tcl/tcl8.4.0-src.tar.gz = =A0=A0=A0 > =A0curl -O > http://telia.dl.sourceforge.net/sourceforge/tcl/tk8.4.0-src.tar.gz = =A0=A0=A0=A0 > =A0tar zxf tcl8.4.0-src.tar.gz; ln -fs tcl8.4.0 tcl > =A0=A0=A0=A0=A0=A0=A0tar zxf tk8.4.0-src.tar.gz; ln -fs tk8.4.0 tk [...] Yup. I just got the same instructions from Tony, too. After I emailed him = this morning about building Tcl/Tk, I did a web search and found some=20 instructions at . I followed those and it=20 worked, but I like these instructions Tony forwarded, they're easier to cut = & paste into a terminal. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From magnus@thinkware.se Sun Sep 22 23:15:12 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 23 Sep 2002 00:15:12 +0200 Subject: [Tutor] What would you say is the best way to continue learning python In-Reply-To: <3D8D7651.4030102@aon.at> References: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> <5.1.0.14.0.20020922004855.036340e8@www.thinkware.se> Message-ID: <5.1.0.14.0.20020922234840.036412d0@www.thinkware.se> At 09:50 2002-09-22 +0200, Gregor Lingl wrote: >Magnus Lycka schrieb: > >>8. Write a program that proves that when n is an integer, >>n > 2, the equation x**n + y**n =3D z**n has no solution in >>positive integers x,y,z. (x**n is the Python notation for >>x to the power of n, i.e. 4**3 =3D 4*4*4.) >2. Moreover this problem has the advantage, that speed of >execution doesn't play any role. Python would solve it in >exactly the same time as for instance C. Never? (Regardless of computer speed you won't find any such numbers, and regardless of how many you test, you can't be certain that an untested combination of the unlimited amount of integers won't satisfy the equation... But then you assume a brute-force attack. Maybe there is a smarter way that still involves computer calculations?) >3. This assignment is especially rewarding, if you decide not to use >your computer any more (for anything else) ;-) In case there is someone who didn't notice what it was, this problem was discussed in ancient Greece. A lawyer in Toulouse, France, Pierre de Fermat, made a margin note in his copy of Diophantos "Arithmetika" more that 350 years ago, that he had found an elegant proof for this, but it didn't quite fit in the margin. A mathematician claimed to have solved it at last, just a few years ago. His first version turned out to contain a flaw, but he came back with a new proof, and noone has found any hole in that. As far as I understand, it's just a handful of people in the world that are able to understand it though... In the previous attempts to solve this problem over the centuries, a number of important discoveries on the nature of mathematics have been made, so even if we don't reach the final goal, there is no reason not to try... ;) Donald Knuth included this as an exercise in "The Art of Computer Programming", grading it in the middle between a term paper and a research project. It has been more of a life time project for many generations of mathematicians, so Knuth was either very optimistic, or slightly playful... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From dyoo@hkn.eecs.berkeley.edu Mon Sep 23 04:05:13 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 22 Sep 2002 20:05:13 -0700 (PDT) Subject: [Tutor] Stackless Python vs pyco vs OS? In-Reply-To: <3D8DE3C2.9070502@xminc.com> Message-ID: On Sun, 22 Sep 2002, Anthony Barker wrote: > I still don't 100% understand stackless python > > OK it doesn't use the C stack It is faster for doing recursion and a bit > faster overall > > Why else would someone use it? Hmmm... you may actually want to ask this on comp.lang.python. Many of us here on Tutor haven't followed this extension to the Python language, so we may not be the best people to ask about the advantages of Stackless. My understanding is that the main purpose of Stackless is to give programmers the ability to fiddle around with "continutations", to hold the scales of life and death over program flow. Cameron Laird has organized lots of notes about Stackless, and most of them concentrate on applying continuations to great effect: http://phaseit.net/claird/comp.lang.python/stackless.html Continuations allow one to write one's own control structures. For example, Tismer originally implemented generators using continuations. Not only generators, but other things like coroutines and microthreads. So coroutines are extraordinarily powerful, if weird. *grin* I think the other advantages of Stackless (speed, infinite recursion, not using C stack) are just icing on the cake. > Wouldn't this be better in the OS level? The 2.5x linux kernel contains > support for both those things. There's one counterpoint: Python does run on more than Linux. And another of the big things about Stackless is that it should allow Python to get around the stack limitations on the Palm platform. > What about psyco - wouldn't that have much of the same effect? Psyco, the specializing compiler, is entirely different: it aims to apply JIT-like compilation of Python into machine code, so it's definitely aimed for optimization. If you'd like to learn more about psyco, you can take a look at: http://psyco.sourceforge.net/ Good luck to you! From dyoo@hkn.eecs.berkeley.edu Mon Sep 23 04:21:29 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 22 Sep 2002 20:21:29 -0700 (PDT) Subject: [Tutor] newbie looking for code suggestions In-Reply-To: <004101c261f6$abf367a0$6401a8c0@swbell.net> Message-ID: On Sun, 22 Sep 2002, Bob Roher wrote: > Hi all. I was wondering if anyone could look over the following code > and give me any suggestions or criticisms? I just started learning > Python a few days ago, so I'm sure there's a lot that can be done to > make it look and run better. No problem; let's take a look at parts of your code. > #User enters parameters for min, max, and what I call digit total for > #lack of a better word. > while run_again == "y": > min_number = raw_input("Enter a start integer: ") > max_number = raw_input("Enter a stop integer: ") > digit_total = raw_input("What digit total would you like: ") Since the comment says what this code will do, perhaps it might be nice to package it up into a function. Let's call it "get_user_input()": ### def get_user_input(): min_number = raw_input("Enter a start integer: ") max_number = raw_input("Enter a stop integer: ") digit_total = raw_input("What digit total would you like: ") return min_number, max_number, digit_total ### Once we have something like this, the previous code will look like: ### while run_again == "y": min_number, max_number, digit_total = get_user_input() ### > One thing I would like to do is be able to have the user re-enter > digit_total if they enter one that is too big without re-running the > program. Hmmm... ok, since get_user_input() is now separate from the rest of the program, we can just focus on getting get_user_input() to know about this restriction. How do we know what the largest possible digit total there is? I see that you're calculating it by finding the maximum number out of the number range; it might just be easier to take the maximum outright and use that. Let's pretend we had a function that, given the lower and upper ranges, tells us what the highest possible digit total can be: ### def maximum_digit_total(min_number, max_number): ## fix me! We should really look at min_number and max_number here. return 9*6 ### Ok, I'm wussing out there. *grin* I haven't written a real definition that takes max_number and min_number into account, but at least it'll work for now. Ok, say we now have this maximum_digit_total() function: we can go back to get_user_input() and use it! ### def get_user_input(): min_number = raw_input("Enter a start integer: ") max_number = raw_input("Enter a stop integer: ") while 1: digit_total = raw_input("What digit total would you like: ") if it's a good digit_total: ## <--- pseudocode break else: print "That's a bad number. Shame on you." return min_number, max_number, digit_total ### Since get_user_input() is in a function, that's the only piece you'll need to concentrate on to get that digit_total checking logic to work. I hope some of this made sense! Please feel free to ask more questions about the fuzzy parts, and we can talk more about the problem. Good luck! From shiska@swbell.net Mon Sep 23 05:58:39 2002 From: shiska@swbell.net (Bob Roher) Date: Sun, 22 Sep 2002 23:58:39 -0500 Subject: [Tutor] newbie looking for code suggestions References: <004101c261f6$abf367a0$6401a8c0@swbell.net> <200209212224.42765.shalehperry@attbi.com> Message-ID: <001b01c262bd$e38ffa80$6401a8c0@swbell.net> > #This function will take an integer as input and return the sum of > #its digits. > def sum_of_digits(in_string): > sum = 0 > t = 0 > for n in in_string: > t = int(n) > sum = sum + t > return sum > def sum_of_digits(in_string): return reduce(lambda x,y: int(x) + int(y), in_string) is another approach. Here's another without the lambda: def sum_of_digits(in_string): import operator return reduce(operator.add, map(int, in_string)) What this does is call 'map(int, in_string)' which call the function 'int' on each char in the string and put it in a new list: >>> s = '1024' >>> map(int, s) [1, 0, 2, 4] reduce then walks this new list and calls operator.add on it. Thanks for the intro to reduce, lamda, and map. I did a little reading on those today, but it will take me a while to fully understand them. I want to do some testing to see which function will execute the fastest when I get time. From shiska@swbell.net Mon Sep 23 06:12:38 2002 From: shiska@swbell.net (Bob Roher) Date: Mon, 23 Sep 2002 00:12:38 -0500 Subject: [Tutor] Re: newbie looking for code suggestions References: <20020922081002.28057.51973.Mailman@mail.python.org> <11464707464.20020922141315@thorstenkampe.de> Message-ID: <002f01c262bf$d8225740$6401a8c0@swbell.net> > Please insert line breaks at about column 70 so your readers do not > have to scroll horizontally. Sorry. > The "total of their digits" is the "cross sum" of a number. I've > written three variations to demonstrate different techniques: > > #v+ > def cross_sum(integer): > if integer: > return integer % 10 + cross_sum(integer / 10) > else: > return 0 > > def cross_sum(integer): > sum = 0 > while integer: > sum += integer % 10 > integer /= 10 > return sum > > def cross_sum(integer): > sum = 0 > for digit in str(integer): > sum += int(digit) > return sum > #v- Thanks, I've gotten the chance to look at the first one so far. I'll check the other two out when I get a chance tomorrow. > The iterative version ("while") performs best. > > Okay, so mathematically spoken, you want the size of a certain list > where each item is equivalent to the others by it's cross sum (sorry > Magnus). This is the code for the "equivalent lists": > > #v+ > def quotient_set(seq, func): > """ partition seq into equivalence classes """ > quotient_set = {} > for item in seq: > quotient_set.setdefault(repr(func(item)),[]).append(item) > return quotient_set > #v- > > >>> min_number, max_number, digit_total = 1, 999999, 21 > >>> len(quotient_set(range(min_number, max_number+1), cross_sum)[str(digit_total)]) > 39962 Is that a typo on that output, or is that what you actually got? I got 39662 when I ran it... > cpu: 28.121, total: 29.832 Neat. How do you get the cpu and total time to show up? > Please omit the HTML part. Thanks! Sorry again. I thought it was set to plain text. Is this better? From shiska@swbell.net Mon Sep 23 06:24:09 2002 From: shiska@swbell.net (Bob Roher) Date: Mon, 23 Sep 2002 00:24:09 -0500 Subject: [Tutor] newbie looking for code suggestions References: Message-ID: <003501c262c1$73ae2d00$6401a8c0@swbell.net> > Since the comment says what this code will do, perhaps it might be nice to > package it up into a function. Let's call it "get_user_input()": > > ### > def get_user_input(): > min_number = raw_input("Enter a start integer: ") > max_number = raw_input("Enter a stop integer: ") > digit_total = raw_input("What digit total would you like: ") > return min_number, max_number, digit_total > ### > > > > Once we have something like this, the previous code will look like: > > ### > while run_again == "y": > min_number, max_number, digit_total = get_user_input() > ### > > > > One thing I would like to do is be able to have the user re-enter > > digit_total if they enter one that is too big without re-running the > > program. > > Hmmm... ok, since get_user_input() is now separate from the rest of the > program, we can just focus on getting get_user_input() to know about this > restriction. How do we know what the largest possible digit total there > is? > > > I see that you're calculating it by finding the maximum number out of the > number range; it might just be easier to take the maximum outright and use > that. Let's pretend we had a function that, given the lower and upper > ranges, tells us what the highest possible digit total can be: > > ### > def maximum_digit_total(min_number, max_number): > ## fix me! We should really look at min_number and max_number here. > return 9*6 > ### > > > Ok, say we now have this maximum_digit_total() function: we can go back to > get_user_input() and use it! > > ### > def get_user_input(): > min_number = raw_input("Enter a start integer: ") > max_number = raw_input("Enter a stop integer: ") > while 1: > digit_total = raw_input("What digit total would you like: ") > if it's a good digit_total: ## <--- pseudocode > break > else: > print "That's a bad number. Shame on you." > return min_number, max_number, digit_total > ### > > > Since get_user_input() is in a function, that's the only piece you'll need > to concentrate on to get that digit_total checking logic to work. > > > I hope some of this made sense! Please feel free to ask more questions > about the fuzzy parts, and we can talk more about the problem. > Thanks Danny, that helps some. I still have a problem with that maximum_digit_total, though. Can you explain what you meant for that? I thought I was being pretty slick when I put in a function that would add all the digits for the upper limit and use that as a digit total, but my wife tested the program for me and put in a range from 1 to 200. Of course, you can have a higher digit total than 2 in that range. So, that's why I put it in the loop, since the only way I could think to calculate it was a simple compare and replace type of deal and I didn't want to have to run through a million number sequence twice. As for your version using statistics, that was pretty nice, too. I considered going that route, but I really hated statistics in school and pretty much worked my rear off for an A and tried to forget the semester ever happened. It would have taken me a month to relearn it enough to write the program that way. (Please tell me if this text isn't wrapping correctly, I'm having fits with my email program.) From dyoo@hkn.eecs.berkeley.edu Mon Sep 23 06:20:16 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 22 Sep 2002 22:20:16 -0700 (PDT) Subject: [Tutor] Re: newbie looking for code suggestions In-Reply-To: <002f01c262bf$d8225740$6401a8c0@swbell.net> Message-ID: > > Okay, so mathematically spoken, you want the size of a certain list > > where each item is equivalent to the others by it's cross sum (sorry > > Magnus). This is the code for the "equivalent lists": > > > > #v+ > > def quotient_set(seq, func): > > """ partition seq into equivalence classes """ > > quotient_set = {} > > for item in seq: > > quotient_set.setdefault(repr(func(item)),[]).append(item) > > return quotient_set > > #v- > > > > >>> min_number, max_number, digit_total = 1, 999999, 21 > > >>> len(quotient_set(range(min_number, max_number+1), > cross_sum)[str(digit_total)]) > > 39962 Wow, very cool. That quotient_set() function is appearing everywhere! *grin* I hadn't thought about applying quotient_set() this way to solve the problem. > Is that a typo on that output, or is that what you actually got? I got > 39662 when I ran it... I'm also getting 39662 on my solution. ### dyoo@coffeetable:~$ python bobs_puzzle.py 39662 ### > > cpu: 28.121, total: 29.832 > > Neat. How do you get the cpu and total time to show up? Unix comes with a 'time' command, so if we have a program called 'count_quotient_set.py' we can do: ### $ time ./count_quotient_set.py ### which should give us timing statistics after the program is finished. > > Please omit the HTML part. Thanks! > > Sorry again. I thought it was set to plain text. Is this better? Looks good now! Bob, thanks for asking this problem; lots of interesting stuff is coming out of this. From linux1011@HotPOP.com Mon Sep 23 06:27:44 2002 From: linux1011@HotPOP.com (David Mccowan) Date: Mon, 23 Sep 2002 00:27:44 -0500 Subject: [Tutor] clist in tkinter and pmw Message-ID: <20020923002744.3b8cc20c.linux1011@HotPOP.com> Is there a widget in tkinter or pmw that has simular functionality to the clist widget in gtk? From shiska@swbell.net Mon Sep 23 06:35:39 2002 From: shiska@swbell.net (Bob Roher) Date: Mon, 23 Sep 2002 00:35:39 -0500 Subject: [Tutor] Tutor] Re: newbie looking for code suggestions References: Message-ID: <003d01c262c3$0f19f7a0$6401a8c0@swbell.net> Sorry for the spam everyone, I wanted to reply to everyone in one message, but it was too messy. :( > I'm also getting 39662 on my solution. That's a relief, I thought I had another problem to sort through. > > > cpu: 28.121, total: 29.832 > > > > Neat. How do you get the cpu and total time to show up? > > Unix comes with a 'time' command, so if we have a program called > 'count_quotient_set.py' we can do: > > > ### > $ time ./count_quotient_set.py > ### > > which should give us timing statistics after the program is finished. > Ah, yet another reason I'm starting to feel cheated by running Windows. Is there a way to import time into the program, say before the loop starts and have it compare start and stop times to give some idea of cpu time? I would like to have some idea of time used when I try some of the ideas I've seen here. From glingl@aon.at Mon Sep 23 09:01:52 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 23 Sep 2002 10:01:52 +0200 Subject: [Tutor] Tutor] Re: newbie looking for code suggestions References: <003d01c262c3$0f19f7a0$6401a8c0@swbell.net> Message-ID: <3D8ECA70.8030408@aon.at> Bob Roher schrieb: >Is there a way to import time into the program, say >before the loop starts and have it compare start and stop times >to give some idea of cpu time? I would like to have some idea of >time used when I try some of the ideas I've seen here. > > > You may use this function: from time import clock def gettime(repetitions, function, *arguments): start = clock() for i in range(repetitions): function(*arguments) end = clock() return end - start which measures the time used for repetitions repetitions of the function function with an arbitrary number of arguments. Regards Gregor > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > > From thorsten@thorstenkampe.de Mon Sep 23 10:25:25 2002 From: thorsten@thorstenkampe.de (Thorsten Kampe) Date: Mon, 23 Sep 2002 11:25:25 +0200 Subject: [Tutor] [OT] Outlook Express (was: newbie looking for code suggestions) In-Reply-To: <20020923053202.20872.44014.Mailman@mail.python.org> References: <20020923053202.20872.44014.Mailman@mail.python.org> Message-ID: <193141031973.20020923112525@thorstenkampe.de> * Bob Roher >> Since get_user_input() is in a function, that's the only piece > you'll need >> to concentrate on to get that digit_total checking logic to > work. >> >> I hope some of this made sense! Please feel free to ask more > questions >> about the fuzzy parts, and we can talk more about the problem. > [...] > (Please tell me if this text isn't wrapping correctly, I'm having > fits with my email program.) It's badly broken and hard to read (especially for those who colourize the text to distinguish different quoting levels): "If you use Outlook Express as your mail/news client, you will have noticed that OE doesn't exactly feature the most intelligent quoting algorithm; in fact, it's the silliest one imaginable." -- http://home.in.tum.de/~jain/software/quotefix.php#description Thorsten From magnus@thinkware.se Mon Sep 23 11:06:38 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 23 Sep 2002 12:06:38 +0200 Subject: [Tutor] newbie looking for code suggestions In-Reply-To: <004101c261f6$abf367a0$6401a8c0@swbell.net> Message-ID: <5.1.0.14.0.20020923115844.02c05e08@www.thinkware.se> I'll just make two notes about the first function: At 00:12 2002-09-22 -0500, Bob Roher wrote: >#This function will take an integer as input and return the sum of >#its digits. >def sum_of_digits(in_string): I'd change this to def sum_of_digits(number): in_string = str(number) to make the function more resilient. Then it will work if people call it with sum_of_digits(123) as well. It might not matter a lot in this small program, but in general, I think that it's better (in a dynamic language such as Python, where it's possible) to let the function which is actually concerned with calculating digits to make this conversion, since it's a pure technicality. From the point of the caller, you typically have an integer that you want to sum up digits in. I mean, this is a matematical exercise rather than a string exercise. You just happen to use some string functions to implement it. > sum = 0 > t = 0 t=0 is pointless. Remove that line. > for n in in_string: > t = int(n) > sum = sum + t > return sum -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From glingl@aon.at Mon Sep 23 11:56:07 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 23 Sep 2002 12:56:07 +0200 Subject: [Tutor] What would you say is the best way to continue learning python References: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> <5.1.0.14.0.20020922004855.036340e8@www.thinkware.se> <5.1.0.14.0.20020922234840.036412d0@www.thinkware.se> Message-ID: <3D8EF347.10509@aon.at> Magnus Lycka schrieb: > At 09:50 2002-09-22 +0200, Gregor Lingl wrote: > >> Magnus Lycka schrieb: >> >>> 8. Write a program that proves that when n is an integer, >>> n > 2, the equation x**n + y**n = z**n has no solution in >>> positive integers x,y,z. (x**n is the Python notation for >>> x to the power of n, i.e. 4**3 = 4*4*4.) >> > >> 2. Moreover this problem has the advantage, that speed of >> execution doesn't play any role. Python would solve it in >> exactly the same time as for instance C. > > > Never? (Regardless of computer speed you won't find > any such numbers, and regardless of how many you test, > you can't be certain that an untested combination of > the unlimited amount of integers won't satisfy the > equation... But then you assume a brute-force attack. > Maybe there is a smarter way that still involves > computer calculations?) Maybe you are right. But certainly you could find this only I you were an expert in Fermat'sTheorem-topics. (And see your own remark below). There is another famous computer aided proof of a problem that resisted all efforts to proof it "by hand" for a long time: the so called four color -problem. See for instance: http://www.math.gatech.edu/~thomas/FC/fourcolor.html Yet this proof consists of the exhaustive search of a finite (albeit *very* large) set of "cases" - would you call it some sort of "intelligent brute force"?. What I wanted to point out: you cannot prove by computer that something is *impossible* for an infinite set of data unless you know, that it can be reduced to finite set of cases. To expect this to be done by a student just beginning to program was recently described as a proof of D. Knuth's somewhat weird sense of humour. > >> 3. This assignment is especially rewarding, if you decide not to use >> your computer any more (for anything else) ;-) > > > In case there is someone who didn't notice what it > was, this problem was discussed in ancient Greece. > A lawyer in Toulouse, France, Pierre de Fermat, made > a margin note in his copy of Diophantos "Arithmetika" > more that 350 years ago, that he had found an elegant > proof for this, but it didn't quite fit in the margin. See also: http://www-gap.dcs.st-and.ac.uk/~history/HistTopics/Fermat's_last_theorem.html > > A mathematician Andrew Wiles > claimed to have solved it at last, just > a few years ago. His first version turned out to contain > a flaw, but he came back with a new proof, and noone has > found any hole in that. As far as I understand, it's just > a handful of people in the world that are able to > understand it though... > > In the previous attempts to solve this problem over > the centuries, a number of important discoveries on > the nature of mathematics have been made, so even if > we don't reach the final goal, there is no reason not > to try... ;) > > Donald Knuth included this as an exercise in "The Art of > Computer Programming", grading it in the middle between > a term paper and a research project. It has been more of > a life time project for many generations of mathematicians, > so Knuth was either very optimistic, or slightly playful... > > Regards, Gregor From thorsten@thorstenkampe.de Mon Sep 23 12:37:36 2002 From: thorsten@thorstenkampe.de (Thorsten Kampe) Date: Mon, 23 Sep 2002 13:37:36 +0200 Subject: [Tutor] Re: newbie looking for code suggestions In-Reply-To: References: Message-ID: <140148963107.20020923133736@thorstenkampe.de> * Danny Yoo >>> Okay, so mathematically spoken, you want the size of a certain >>> list where each item is equivalent to the others by it's cross sum >>> (sorry Magnus). This is the code for the "equivalent lists": >>> [...] >>> >>> min_number, max_number, digit_total = 1, 999999, 21 >>> >>> len(quotient_set(range(min_number, max_number+1), cross_sum)[str(digit_total)]) >>> 39962 > Wow, very cool. That quotient_set() function is appearing > everywhere! *grin* I hadn't thought about applying quotient_set() > this way to solve the problem. I didn't someday think to myself: "I'm so bored, let's code something /really/ weird: why not ... equivalence classes?!" But I was noticing that a lot of day-to-day problems were - at least partially - solved by grouping related ("equivalent") elements. The one thing I do not like about the algorithm is that I had to write "repr(func(item)" because some func(item) (list or dictionary) might not be hashable. So other programs that process the quotient set further have to do "eval(key)"/"eval(repr(func(item)))". One possible solution is to pass a flag to quotient_set() meaning: "I guarantee all func(item) are hashable, so omit 'repr(func(item))', just hash func(item)" Here are two functions demonstrating the use of quotient_set(): #v+ def set(seq): """ make seq a true set by removing duplicates """ return [item[0] for item in quotient_set(seq, lambda x: x).values()] def extr(seq, func): """ return [(min(func(seq)), min_func_seq), (max(func(seq)), max_func_seq)] """ equiv_classes = [(eval(key), value) for key, value in quotient_set(seq, func).items()] return [(min(equiv_classes)), (max(equiv_classes))] #v- The first one is pretty self explanatory and the second is related to the fact that in math you're often not interested in maximum or minimum but in "the extrema", for instance: * here's a bunch of reals, give me those with the smallest fractional part: extr(list_of_reals, lambda x: math.modf(x)[0])[0][1] sorry, I meant the /biggest/: extr(list_of_reals, lambda x: math.modf(x)[0])[1][1] yes, but I need to know the fractional part, too: extr(list_of_reals, lambda x: math.modf(x)[0])[1] * here's a list of words. I want the longest words, please: extr(list_of_words, len)[1][1] sorry, I meant: just the size of the longest word(s): extr(list_of_words, len)[1][0] Thorsten From lbrannma@cablespeed.com Mon Sep 23 12:48:51 2002 From: lbrannma@cablespeed.com (Lance) Date: Mon, 23 Sep 2002 04:48:51 -0700 Subject: [Tutor] Tutor] Re: newbie looking for code suggestions References: <003d01c262c3$0f19f7a0$6401a8c0@swbell.net> <3D8ECA70.8030408@aon.at> Message-ID: <000f01c262f7$2fe2c4b0$3212eb42@MYNEWBOX> I wonder how often the clock tics.... It seems to tic only every second on our Solaris box. Lance ----- Original Message ----- From: "Gregor Lingl" To: "Bob Roher" Cc: "Tutor" Sent: Monday, September 23, 2002 1:01 AM Subject: Re: [Tutor] Tutor] Re: newbie looking for code suggestions > Bob Roher schrieb: > > >Is there a way to import time into the program, say > >before the loop starts and have it compare start and stop times > >to give some idea of cpu time? I would like to have some idea of > >time used when I try some of the ideas I've seen here. > > > > > > > You may use this function: > > from time import clock > > def gettime(repetitions, function, *arguments): > start = clock() > for i in range(repetitions): > function(*arguments) > end = clock() > return end - start > > > which measures the time used for repetitions repetitions > of the function function with an arbitrary number of arguments. > Regards > Gregor > > > > >_______________________________________________ > >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 glingl@aon.at Mon Sep 23 12:56:27 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 23 Sep 2002 13:56:27 +0200 Subject: [Tutor] Tutor] Re: newbie looking for code suggestions References: <003d01c262c3$0f19f7a0$6401a8c0@swbell.net> <3D8ECA70.8030408@aon.at> <000f01c262f7$2fe2c4b0$3212eb42@MYNEWBOX> Message-ID: <3D8F016B.2030501@aon.at> Lance schrieb: >I wonder how often the clock tics.... It seems to tic only every second on >our Solaris box. > >Lance > > I think Magnus posted not long ago, that you may use alternatively the function time() from modul time. from time import time .... start = time() ... end = time() And he showed that on some machines with somo os's time() has the better resolution, on others clock() You may check the resolution by calling something like def testtimefun(fun): s = e = fun() while s == e: e = fun() return e - s with clock and time respectively as argument. Regards, Gregor >----- Original Message ----- >From: "Gregor Lingl" >To: "Bob Roher" >Cc: "Tutor" >Sent: Monday, September 23, 2002 1:01 AM >Subject: Re: [Tutor] Tutor] Re: newbie looking for code suggestions > > > > >>Bob Roher schrieb: >> >> >> >>>Is there a way to import time into the program, say >>>before the loop starts and have it compare start and stop times >>>to give some idea of cpu time? I would like to have some idea of >>>time used when I try some of the ideas I've seen here. >>> >>> >>> >>> >>> >>You may use this function: >> >>from time import clock >> >>def gettime(repetitions, function, *arguments): >> start = clock() >> for i in range(repetitions): >> function(*arguments) >> end = clock() >> return end - start >> >> >>which measures the time used for repetitions repetitions >>of the function function with an arbitrary number of arguments. >>Regards >>Gregor >> >> >> >>>_______________________________________________ >>>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 magnus@thinkware.se Mon Sep 23 14:32:10 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 23 Sep 2002 15:32:10 +0200 Subject: [Tutor] What would you say is the best way to continue learning python In-Reply-To: <3D8EF347.10509@aon.at> References: <000001c261ad$096cb1b0$7ccbe0cf@hewlett5k1589j> <5.1.0.14.0.20020922004855.036340e8@www.thinkware.se> <5.1.0.14.0.20020922234840.036412d0@www.thinkware.se> Message-ID: <5.1.0.14.0.20020923152817.02c3c958@www.thinkware.se> At 12:56 2002-09-23 +0200, Gregor Lingl wrote: >To expect this to be done by a student just beginning to >program was recently described as a proof of D. Knuth's >somewhat weird sense of humour. He does come through as a slightly odd person... See: http://www.thinkware.se/cgi-bin/thinki.cgi/DiscussTheArtOfComputerProgrammin= g --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From d.j.kniep@chello.nl Mon Sep 23 15:02:36 2002 From: d.j.kniep@chello.nl (Dick Kniep) Date: 23 Sep 2002 16:02:36 +0200 Subject: [Tutor] [Fwd: Please help, I'm a newbie] Message-ID: <1032789762.4411.10.camel@kniep02.kniep> Hi there, I am trying to write a piece of coding that uses a standard routine to open SQL tables into dictionaries.I do not wish to enter all the columns, because that severely cuts the flexibility of my code. Therefore, I want to get my columns from the database. Here are a few snippets of my code. The first part gives the routine (TableObjs) uses a config file to determine whether a table should be processed or not. It it is to be processed, it uses another list of tuples to determine the actual tablename as it is defined in Postgresql. Next a statement is defined, and that statement is "exec"ed. (It's written on a Windows system, so please forgive the CRLF's) ;-) .... .... def TableObjs(dbObj, config): """ Get Tables in Dictionaries """ db = SQLDict(dbObj) for x in Tables: h = string.lower('memtable.' + x) if config[h] == '1': if Tables[x][0] == "'": Tabnm = string.replace(Tables[x],"'","") elif Tables[x][0] == '"': Tabnm = string.replace(Tables[x],'"','') else: Tabnm = Tables[x] stmt = "db." + Tabnm + " = db.Table(" + Tables[x] + ")" exec stmt return db .... .... The next part is a standard routine that I downloaded. It works properly if I use it in the documented way. However, in the _init_ routine I have added a few statements, and now it can't find the class SQLDict: """SQLDict: An object class which implements something resembling a Python dictionary on top of an SQL DB-API database.""" def __init__(self, db): """Create a new SQLDict object. db: an SQL DB-API database connection object""" # Most database objects are native C, so they can't be subclassed. self.db = db def __del__(self): self.close() def close(self): try: self.db.close() except: pass def __getattr__(self, attr): # Get any other interesting attributes from the base class. return getattr(self.db, attr) class _Table: """Table handler for a SQLDict object. These should not be created directly by user code.""" def __init__(self, db, table, columns=[], updatecolumns=[]): """Construct a new table definition. Don't invoke this directly. Use Table method of SQLDict instead.""" self.db = db self.table = table self.columns = columns if not columns: Sqlstmt = "SELECT * FROM " + self.table cursor = db.cursor(Sqlstmt) columns = [ d[0] for d in cursor.description ] self.SELECT = "SELECT %s FROM %s " % \ (self._columns(columns), self.table) self.INSERT = "INSERT INTO %s (%s)\n VALUES (%s) " % \ (self.table, self._columns(columns), self._values(columns)) self.DELETE = "DELETE FROM %s " % self.table self.Update(updatecolumns or columns) def Table(self, table, columns=[], updatecolumns=[]): """Add a new Table member. Usage: db.Table(tablename, columns) Where: tablename = name of table in database columns = tuple containing names of columns of interest """ return self._Table(self.db, table, columns, updatecolumns) The error I get is that the name "columns" is not defined. But that is weird because it gets the error on the "if not columns", and I would expect the error on the statement before that, because there columns is referenced. Furthermore, I want to test whether the length of the tuple is 0, if it is, I want to generate the list of columns automatically, by defining a cursor, and reading the description. I have included the 2 routines, so if you could help me PLEASE! Having searched a little further, it looks a little less weird, but I still do not understand what is happening. It seems that the error occurs on the import of the routine. But I still don'y know what is happening here.... Kind regards, D Kniep From bigmaddrongo@yahoo.co.uk Mon Sep 23 15:35:15 2002 From: bigmaddrongo@yahoo.co.uk (=?iso-8859-1?q?Big=20Mad=20Drongo?=) Date: Mon, 23 Sep 2002 15:35:15 +0100 (BST) Subject: [Tutor] [Fwd: Please help, I'm a newbie] In-Reply-To: <1032789762.4411.10.camel@kniep02.kniep> Message-ID: <20020923143515.59909.qmail@web14003.mail.yahoo.com> --- Dick Kniep wrote: > def __init__(self, db, table, columns=[], > updatecolumns=[]): > if not columns: >The error I get is that the name "columns" is not >defined. But that is weird because it gets the error >on the "if not columns", and I would expect the error >on the statement before that, because there columns >is referenced. Is this an indentation problem? Your "if" statement appears to be at the same indentation as the def for __init__ so at that level of the class the name columns is not defined, it is only defined *inside* __init__ where the "if" is not. I am myself only at newbie at python, so I may be incorrect, in fact this is my first attempt at answering somebody elses problem on Tutor rather than causing trouble for all the other wonderful people on the list, so fingers crossed for the both of us... Russell ===== -- Tulips Ate My Socks http://www.bigmaddrongo.com Chair of The York Glee Singers: http://www.gleesingers.co.uk __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com From d.j.kniep@chello.nl Mon Sep 23 15:45:53 2002 From: d.j.kniep@chello.nl (Dick Kniep) Date: 23 Sep 2002 16:45:53 +0200 Subject: [Tutor] [Fwd: Please help, I'm a newbie] In-Reply-To: <20020923143515.59909.qmail@web14003.mail.yahoo.com> References: <20020923143515.59909.qmail@web14003.mail.yahoo.com> Message-ID: <1032792364.4411.31.camel@kniep02.kniep> Hi Russel, Helas, that is not that the problem. I copied the routine into the message, and it seems to have screwed up the indentation somewhat. But indentation doesn't seem to be the problem, the problem occurs when I am importing the module. Perhaps someone can explain to me how import checks these kind of things. Kind regards, D. Kniep On Mon, 2002-09-23 at 16:35, Big Mad Drongo wrote: > --- Dick Kniep wrote: > > def __init__(self, db, table, columns=[], > > updatecolumns=[]): > > > if not columns: > > >The error I get is that the name "columns" is not > >defined. But that is weird because it gets the error > >on the "if not columns", and I would expect the error > > >on the statement before that, because there columns > >is referenced. > > Is this an indentation problem? Your "if" statement > appears to be at the same indentation as the def for > __init__ so at that level of the class the name > columns is not defined, it is only defined *inside* > __init__ where the "if" is not. > > I am myself only at newbie at python, so I may be > incorrect, in fact this is my first attempt at > answering somebody elses problem on Tutor rather than > causing trouble for all the other wonderful people on > the list, so fingers crossed for the both of us... > > Russell > > > ===== > -- > Tulips Ate My Socks > http://www.bigmaddrongo.com > Chair of The York Glee Singers: > http://www.gleesingers.co.uk > > __________________________________________________ > Do You Yahoo!? > Everything you'll ever need on one web page > from News and Sport to Email and Music Charts > http://uk.my.yahoo.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From thorsten@thorstenkampe.de Mon Sep 23 16:54:49 2002 From: thorsten@thorstenkampe.de (Thorsten Kampe) Date: Mon, 23 Sep 2002 17:54:49 +0200 Subject: [Tutor] Re: newbie looking for code suggestions In-Reply-To: <002f01c262bf$d8225740$6401a8c0@swbell.net> References: <20020922081002.28057.51973.Mailman@mail.python.org> <11464707464.20020922141315@thorstenkampe.de> <002f01c262bf$d8225740$6401a8c0@swbell.net> Message-ID: <17164396169.20020923175449@thorstenkampe.de> * Bob Roher >> The "total of their digits" is the "cross sum" of a number. I've >> written three variations to demonstrate different techniques: [...] > > Thanks, I've gotten the chance to look at the first one so far. I'll > check the other two out when I get a chance tomorrow. Well, the third is the same as your algorithm (just slightly shorter). And the other ones were translated from two C programs I found by googling. So you see: no brain activity on my side ;-) >> >>> min_number, max_number, digit_total = 1, 999999, 21 >> >>> len(quotient_set(range(min_number, max_number+1), cross_sum)[str(digit_total)]) >> 39962 > > Is that a typo on that output, or is that what you actually got? I > got 39662 when I ran it... Yes, never type, when you can copy and paste. >> cpu: 28.121, total: 29.832 > > Neat. How do you get the cpu and total time to show up? This a variation of Peter Norvig's original: (http://www.norvig.com/python/utils.html) #v+ def timer(iteration, *func_and_args): """ print the time elapsed (in seconds) evaluating func iteration times (default is '1') """ import gc, time if isinstance(iteration, int): func, args = func_and_args[0], func_and_args[1:] else: # if first argument is not a number, set func to iteration and iteration # to '1' iteration, func, args = 1, iteration, func_and_args iteration = range(iteration) gc.collect() # force garbage collection start_time_cpu = time.clock() start_time_total = time.time() for i in iteration: func(*args) print 'cpu: %(cpu).3f,' % {'cpu': time.clock() - start_time_cpu}, \ 'total: %(total).3f' % {'total': time.time() - start_time_total} #v- I timed my program with: timer(quotient_set, range(1000000), cross_sum) I tried to rewrite the program so... timer(quotient_set(range(1000000), cross_sum)) or timer(len(quotient_set(range(1000000), cross_sum)['21'])) timer(what_you_actually_type_when_you_run_the_program) ...would work, but wasn't able to pass the functions correctly. >> Please omit the HTML part. Thanks! > > Sorry again. I thought it was set to plain text. Is this better? Yes, plain text - like god intended ;-) One more plea: please do not reply to the mailing list *and* to myself. I'm currently on the text digest and thinking about switching (depending on the volume). Anyhow: your way I'm getting the reply twice. Thorsten From ATrautman@perryjudds.com Mon Sep 23 17:16:43 2002 From: ATrautman@perryjudds.com (Alan Trautman) Date: Mon, 23 Sep 2002 11:16:43 -0500 Subject: [Tutor] basic python question Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B587D@mail.pjinet.com> Ron, I apologize unfortunately I am forced to use VB all day and a M$ ism crept into my answer. It should read x=3 if x%2 == 0: print x,"is even" else: print x,"is odd" The == means is this equal to as opposed to = which means assigned to. Sorry about the problem. Alan -----Original Message----- From: Ron Nixon [mailto:nixonron@yahoo.com] Sent: Monday, September 23, 2002 8:21 AM To: Alan Trautman Subject: RE: [Tutor] basic python question Still can't get it to work. I keep getting an error message Ron Alan Trautman wrote: Ron, Python is totally dependant on indentation for program flow. To make your program work type if x%2 = 0: print x,"is even" else: print x,"is odd" The indentations tell Python that these are the steps to perform when the condition is true (ie.. even) or what to do in all other cases (odd). -----Original Message----- From: Ron Nixon [mailto:nixonron@yahoo.com] Sent: Friday, September 20, 2002 9:17 AM To: tutor@python.org Subject: [Tutor] basic python question I'm playing around with the "How to Think Like A Computer Scientist" book and trying one of the examples and I keep getting syntax errors even though I'm typing word for word. if X%2==0: print x, "Is even" else: print x, "is odd" but I get a syntax error on the "else:" as shown below. Can I not do this with IDLE? SyntaxError: invalid syntax >>> if x%2==0: print x, "is even" else: SyntaxError: invalid syntax >>> Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! From ATrautman@perryjudds.com Mon Sep 23 18:11:13 2002 From: ATrautman@perryjudds.com (Alan Trautman) Date: Mon, 23 Sep 2002 12:11:13 -0500 Subject: [Tutor] basic python question Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B587E@mail.pjinet.com> Ok I'll go through the steps I would use to get this to work in IDLE. Once the idle screen is opened -> choose File->New Window and a screen without all the interactive stuff will appear. (This caused me no end of confusion at first and has been change in the IDLE fork available on Source Forge) Cut and paste the sample code into the blank new window x=3 if x%2 == 0: print x,"is even" else: print x,"is odd" Save it as filename.py Choose ->Edit->Run Script and it should produce: 3 is odd in the original window. Hope this helps. Alan -----Original Message----- From: Ron Nixon [mailto:nixonron@yahoo.com] Sent: Monday, September 23, 2002 11:22 AM To: Alan Trautman Subject: RE: [Tutor] basic python question Alan: Thanks for you relies on this, but I still can't get it to work. I can get the first couple of lines. But when I hit enter after "If x, "is even" and IDLE indents, I type else: but when I try to hit enter and go to the next line, I get a error message. Alan Trautman wrote: Ron, I apologize unfortunately I am forced to use VB all day and a M$ ism crept into my answer. It should read x=3 if x%2 == 0: print x,"is even" else: print x,"is odd" The == means is this equal to as opposed to = which means assigned to. Sorry about the problem. Alan -----Original Message----- From: Ron Nixon [mailto:nixonron@yahoo.com] Sent: Monday, September 23, 2002 8:21 AM To: Alan Trautman Subject: RE: [Tutor] basic python question Still can't get it to work. I keep getting an error message Ron Alan Trautman wrote: Ron, Python is totally dependant on indentation for program flow. To make your program work type if x%2 = 0: print x,"is even" else: print x,"is odd" The indentations tell Python that these are the steps to perform when the condition is true (ie.. even) or what to do in all other cases (odd). -----Original Message----- From: Ron Nixon [mailto:nixonron@yahoo.com] Sent: Friday, September 20, 2002 9:17 AM To: tutor@python.org Subject: [Tutor] basic python question I'm playing around with the "How to Think Like A Computer Scientist" book and trying one of the examples and I keep getting syntax errors even though I'm typing word for word. if X%2==0: print x, "Is even" else: print x, "is odd" but I get a syntax error on the "else:" as shown below. Can I not do this with IDLE? SyntaxError: invalid syntax >>> if x%2==0: print x, "is even" else: SyntaxError: invalid syntax >>> Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! From dyoo@hkn.eecs.berkeley.edu Mon Sep 23 18:44:51 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 23 Sep 2002 10:44:51 -0700 (PDT) Subject: [Tutor] newbie looking for code suggestions In-Reply-To: <003501c262c1$73ae2d00$6401a8c0@swbell.net> Message-ID: > > I see that you're calculating it by finding the maximum number out of > > the number range; it might just be easier to take the maximum outright > > and use that. Let's pretend we had a function that, given the lower > > and upper ranges, tells us what the highest possible digit total can > > be: > > > > ### > > def maximum_digit_total(min_number, max_number): > > ## fix me! We should really look at min_number and > > ## max_number here. > > return 9*6 > > ### [some text cut] > Thanks Danny, that helps some. I still have a problem with that > maximum_digit_total, though. Can you explain what you meant for that? > I thought I was being pretty slick when I put in a function that would > add all the digits for the upper limit and use that as a digit total, > but my wife tested the program for me and put in a range from 1 to 200. > Of course, you can have a higher digit total than 2 in that range. So, > that's why I put it in the loop, since the only way I could think to > calculate it was a simple compare and replace type of deal and I didn't > want to have to run through a million number sequence twice. Very true --- if the lower and upper range wraps around a power of ten, then I think that's a special case that we can calculate really fast... but for the general case of any range (like from 1 to 200), I'm not seeing an obvious way of doing it yet. An interesting problem! Is it really necessary for us to go through the whole range to get the maximum digit total? I didn't think so at first, but now I'm not so sure. I'll have to think about it some more. Here's a heuristic approach that I'm taking on the problem: I don't yet know if it's correct yet. ### import string, operator def maximum_digit_total(min_number, max_number): return sum(int_to_list(find_maximum_digits(min_number, max_number))) def find_maximum_digits(min_number, max_number): width = max(len(str(min_number)), len(str(max_number))) maximum_digits = map(int, string.zfill(min_number, width)) for i in range(width): while maximum_digits[width - i - 1] != 9: maximum_digits[width - i - 1] += 1 if list_to_int(maximum_digits) > max_number: maximum_digits[width - i - 1] -= 1 break return list_to_int(maximum_digits) def list_to_int(digits): return int(''.join(map(str, digits))) def int_to_list(number): return map(int, str(number)) def sum(l): return reduce(operator.add, l) ### Here's a brief explanation of what find_maximum_digits() is doing: I first convert things so that I'm working with a list of integers, just to make manipulation easier. My answer starts off being the lower limit, and slowly try to improve the answer by incrementing, but by least significant digits first. I stop and undo things whenever I go over the max_number. Here are a few tests I've done on this: ### >>> maximum_digit_total(1, 1000) 27 >>> maximum_digit_total(1, 1) 1 >>> maximum_digit_total(1, 2) 2 >>> maximum_digit_total(1, 10) 9 >>> maximum_digit_total(1, 200) 19 >>> maximum_digit_total(1, 199) 19 >>> maximum_digit_total(199, 200) 19 >>> maximum_digit_total(1, 10**6) 54 ### But this should not be taken as conclusive proof that the function is correct... *grin* By the way, this would be a great opportunity for someone to show how to formulate the informal tests I've done as unit tests. I have to go at the moment though; I'll try to come back to this in the evening. Good luck! From magnus@thinkware.se Mon Sep 23 17:27:12 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 23 Sep 2002 18:27:12 +0200 Subject: [Tutor] [Fwd: Please help, I'm a newbie] In-Reply-To: <1032789762.4411.10.camel@kniep02.kniep> Message-ID: <5.1.0.14.0.20020923175816.02a8e288@www.thinkware.se> At 16:02 2002-09-23 +0200, Dick Kniep wrote: >Hi there, > >I am trying to write a piece of coding that uses a standard routine to >open SQL tables into dictionaries. Before reinventing the wheel, it's a good thing to search Vaults of Parnassus: http://www.vex.net/parnassus/ (and Google for that matter.) There is already a SQLDict by Andy Dustman. Guess what it does... And there is Boudewijn Rempt's dbObj... Then there is Kevin Jacobs' db_row... Those are the ones I found as Parnassus, but I seem to recall that Greg Stein wrote one as well. Let's look at www.lyra.org. Certainy, there is a dtuple.py at http://www.lyra.org/greg/python/ I hope one of these four wheels will fit! ;) --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From lbrannma@cablespeed.com Tue Sep 24 01:19:01 2002 From: lbrannma@cablespeed.com (Lance) Date: Mon, 23 Sep 2002 17:19:01 -0700 Subject: [Tutor] recommended Editor? Message-ID: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> This is a multi-part message in MIME format. ------=_NextPart_000_0020_01C26325.4F909390 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Can someone suggest a good editor to use with Python? I like Crisp, but = I would need to code all the indents, etc. Thanks, Lance ------=_NextPart_000_0020_01C26325.4F909390 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
Can someone suggest a good editor to = use with=20 Python? I like Crisp, but I would need to code all the indents,=20 etc.
 
Thanks,
Lance
------=_NextPart_000_0020_01C26325.4F909390-- From gus.tabares@verizon.net Tue Sep 24 01:26:19 2002 From: gus.tabares@verizon.net (Gus Tabares) Date: Mon, 23 Sep 2002 20:26:19 -0400 (EDT) Subject: [Tutor] recommended Editor? In-Reply-To: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> Message-ID: Lance, Have you tried Visual SlickEdit? I'm not quite sure it does auto-indentation, but it's worth a shot. It runs on both Win32/Unix. Also, I'm not sure it's freeware, so you might end up coughing up some dough to use it. Just a suggestion....good luck. Gus Gus Tabares On Mon, 23 Sep 2002, Lance wrote: > Hi, > > Can someone suggest a good editor to use with Python? I like Crisp, but I would need to code all the indents, etc. > > Thanks, > Lance From pythonpython@hotmail.com Tue Sep 24 01:43:18 2002 From: pythonpython@hotmail.com (Hy Python) Date: Tue, 24 Sep 2002 00:43:18 +0000 Subject: [Tutor] How to convert a hex value string into a real unicode? Message-ID: Could you please tell me if it's possible to convert a hex value string into a real unicode? I mean that if myHexStr="5E74" then how can I convert myHexStr into a unicode which looks like u'u\5E74' ? I understand that '5E74'+u'' returns u'5E74' but this is not what I want. I need u'\u5E74" Thanks a lot for your help. Hy _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com From pythonpython@hotmail.com Tue Sep 24 01:55:36 2002 From: pythonpython@hotmail.com (Hy Python) Date: Tue, 24 Sep 2002 00:55:36 +0000 Subject: [Tutor] recommended Editor? Message-ID: UltraEdit32 is pretty good. Hy >From: "Lance" >To: "Tutor" >Subject: [Tutor] recommended Editor? >Date: Mon, 23 Sep 2002 17:19:01 -0700 > >Hi, > >Can someone suggest a good editor to use with Python? I like Crisp, but I >would need to code all the indents, etc. > >Thanks, >Lance _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com From jccoellar@yahoo.es Tue Sep 24 02:19:28 2002 From: jccoellar@yahoo.es (=?iso-8859-1?q?Juan=20Carlos=20Coellar?=) Date: Tue, 24 Sep 2002 03:19:28 +0200 (CEST) Subject: [Tutor] need help Message-ID: <20020924011928.13445.qmail@web12708.mail.yahoo.com> hello! to all First :Thanks you for your reply to my request i am indebted you,it sure would save me a lot of time Second point:I need info about ,?how may i do to create a executable programs (exe or other) from python to anything computer ,as the same way that the other language On other words:for example.from my C++, C+++(borland) or Visual Basic 6 ,i may choose the option to create executable programs to run on over anything computer (Dos ,Window) If anyone has any suggestion ,please let me know . Thanks in advance. very your truly ATT JCCN _______________________________________________________________ Yahoo! Messenger Nueva versión: Webcam, voz, y mucho más ¡Gratis! Descárgalo ya desde http://messenger.yahoo.es From abarker@xminc.com Tue Sep 24 04:13:41 2002 From: abarker@xminc.com (Anthony Barker) Date: Mon, 23 Sep 2002 23:13:41 -0400 Subject: [Tutor] was What IDE do you prefer? - now folding python in emacs References: <5.1.0.14.0.20020922015344.03641418@www.thinkware.se> <5.1.0.14.0.20020922230604.02b62ab0@www.thinkware.se> Message-ID: <3D8FD865.2040907@xminc.com> >> >> emacs has a folding add-in module- have you tried it? >> fte has folding - but I am not crazy about it. > > > I never really used emacs a lot. I know that there is > a folding mode that is based on some special notation > in the text. Can it fold python purely based on indentation? Yes it is fairly simple - I picked up the script from google groups. It doesn't require the fancy script Anders Lindgren wrote. taken from: http://groups.google.ca/groups?q=emacs+folding+python&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=uelftqprw.fsf%40cs.unc.edu&rnum=2 Just use the builtin outline-minor-mode and set up the outline-regexp and outline-level to work with Python. Here is what you put in your .emacs to make it work. ;; setup python mode (setq auto-mode-alist ; trigger python mode automatically (cons '("\\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t) ; add my customization (add-hook 'python-mode-hook 'my-python-hook) ; this gets called by outline to deteremine the level. Just use the length of the whitespace (defun py-outline-level () (let (buffer-invisibility-spec) (save-excursion (skip-chars-forward "\t ") (current-column)))) ; this get called after python mode is enabled (defun my-python-hook () ; outline uses this regexp to find headers. I match lines with no indent and indented "class" ; and "def" lines. (setq outline-regexp "[^ \t]\\|[ \t]*\\(def\\|class\\) ") ; enable our level computation (setq outline-level 'py-outline-level) ; do not use their \C-c@ prefix, too hard to type. Note this overides some python mode bindings (setq outline-minor-mode-prefix "\C-c") ; turn on outline mode (outline-minor-mode t) ; initially hide all but the headers (hide-body) ; I use CUA mode on the PC so I rebind these to make the more accessible (local-set-key [?\C-\t] 'py-shift-region-right) (local-set-key [?\C-\S-\t] 'py-shift-region-left) ; make paren matches visible (show-paren-mode 1) ) From dman@dman.ddts.net Tue Sep 24 04:40:06 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 23 Sep 2002 23:40:06 -0400 Subject: [Tutor] Re: How to convert a hex value string into a real unicode? In-Reply-To: References: Message-ID: <20020924034006.GA29763@dman.ddts.net> --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 24, 2002 at 12:43:18AM +0000, Hy Python wrote: | Could you please tell me if it's possible to convert a hex value string= =20 | into a real unicode? |=20 | I mean that | if myHexStr=3D"5E74" | then how can I convert myHexStr into a unicode which looks like u'u\5E74'= ? |=20 | I understand that | '5E74'+u'' returns u'5E74' | but this is not what I want. | I need u'\u5E74" # obtained from some input, I assume hs =3D "5E74" # processing begins here hs =3D '0x'+hs unistr =3D unichr( int(hs) ) This method, as shown, only works for a single character. It converts the hex string to an integer, and from there to a unicode character (or a unicode string of length 1, if you prefer). -D --=20 Failure is not an option. It is bundled with the software. =20 http://dman.ddts.net/~dman/ --XsQoSWH+UP9D9v3l Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2P3pYACgkQO8l8XBKTpRQU3gCfeqOdfRXBae7LTqiknvbXDXyf E1EAoIKhTtxCXAXey5vWjjHdqHQR7Zzp =QvBT -----END PGP SIGNATURE----- --XsQoSWH+UP9D9v3l-- From dman@dman.ddts.net Tue Sep 24 04:40:44 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 23 Sep 2002 23:40:44 -0400 Subject: [Tutor] Re: recommended Editor? In-Reply-To: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> References: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> Message-ID: <20020924034044.GB29763@dman.ddts.net> --NMuMz9nt05w80d4+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 23, 2002 at 05:19:01PM -0700, Lance wrote: | Can someone suggest a good editor to use with Python? I like vim. YMMV. -D --=20 Stay away from a foolish man, for you will not find knowledge on his lips. Proverbs 14:7 =20 http://dman.ddts.net/~dman/ --NMuMz9nt05w80d4+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2P3rwACgkQO8l8XBKTpRRBAwCdF/A3V7Kz3w+QQmLn/Q8ff8gW LMQAnR5PocZOlRlQYftXBMm4Wv3nIRA9 =2y/t -----END PGP SIGNATURE----- --NMuMz9nt05w80d4+-- From lists@shrestha.net.np Tue Sep 24 03:57:55 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Tue, 24 Sep 2002 08:42:55 +0545 Subject: [Tutor] recommended Editor? References: Message-ID: <3D8FD4B3.5040901@shrestha.net.np> Why don't you check out http://www.python.org/cgi-bin/moinmoin/PythonEditors by the way, i use vim and jedit! ashish >> From: "Lance" >> To: "Tutor" >> Subject: [Tutor] recommended Editor? >> Date: Mon, 23 Sep 2002 17:19:01 -0700 >> >> Hi, >> >> Can someone suggest a good editor to use with Python? I like Crisp, >> but I would need to code all the indents, etc. >> >> Thanks, >> Lance From stefanus.arief@ai.astra.co.id Tue Sep 24 04:30:04 2002 From: stefanus.arief@ai.astra.co.id (Arief) Date: Tue, 24 Sep 2002 10:30:04 +0700 Subject: [Tutor] Re: recommended Editor? In-Reply-To: <20020924034044.GB29763@dman.ddts.net> Message-ID: >On Mon, Sep 23, 2002 at 05:19:01PM -0700, Lance wrote: > >| Can someone suggest a good editor to use with Python? > >I like vim. YMMV. I am using kwrite or kate in my Linux. That's quite good. ----- Arief From dman@dman.ddts.net Tue Sep 24 04:46:52 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 23 Sep 2002 23:46:52 -0400 Subject: [Tutor] Re: publishing programs In-Reply-To: References: Message-ID: <20020924034652.GC29763@dman.ddts.net> --lMM8JwqTlfDpEaS6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 22, 2002 at 08:50:59AM -0700, CameronStoner wrote: | Hi all, |=20 | How do programs get published and people make money from them? To make money? Well, that depends. For the commercial software you are probably most familiar with, that would requires copyrighting the source code, then creating a license for using the software which doesn't permit any redistribution, modification, etc. (the opposite of the GPL or the BSD-style licenses). Then you hire someone to print manuals, boxes, and cd labels so you can shrink-wrap it and then try to find a distributor willing to stock your box. Another possibility is to offer your services as a consultant or free-lance programmer. Apply for a job writing custom software for some business entity. No one (except your co-workers) will know about your software, but you'll be making money from it. "Shareware" is another possibility. You develop the software for fun, then allow people to freely distribute it via the Internet. However, in your licensing terms you specify that you will be paid a royalty for any use beyond the evaluation period. I don't think this mechanism is very profitable. HTH, -D --=20 It took the computational power of three Commodore 64s to fly to the moon. It takes at least a 486 to run Windows 95. Something is wrong here. =20 http://dman.ddts.net/~dman/ --lMM8JwqTlfDpEaS6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2P4CwACgkQO8l8XBKTpRT1FgCgwUtvQnJ6iL0fQh/AtxM/7lnx Nf8An1xAQs0yBMfvAQVj0Qx2HBfORmOw =E6uJ -----END PGP SIGNATURE----- --lMM8JwqTlfDpEaS6-- From dman@dman.ddts.net Tue Sep 24 04:47:51 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 23 Sep 2002 23:47:51 -0400 Subject: [Tutor] Re: recommended Editor? In-Reply-To: References: <20020924034044.GB29763@dman.ddts.net> Message-ID: <20020924034751.GD29763@dman.ddts.net> --kvUQC+jR9YzypDnK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 24, 2002 at 10:30:04AM +0700, Arief wrote: | >On Mon, Sep 23, 2002 at 05:19:01PM -0700, Lance wrote: | > | >| Can someone suggest a good editor to use with Python? | > | >I like vim. YMMV. |=20 | I am using kwrite or kate in my Linux. That's quite good. FYI vim is available for a multitude of platforms (including MS Windows and MacOS), not just linux or other unix-like systems. -D --=20 Contrary to popular belief, Unix is user friendly. It just happens to be selective about who it makes friends with. -- Dave Parnas =20 http://dman.ddts.net/~dman/ --kvUQC+jR9YzypDnK Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2P4GcACgkQO8l8XBKTpRTAnQCfb0yqEUfeiJUCi8ml489FvnLo Fo0AniAjyJf48KZxzyTMS2U8xKbQkTbj =861A -----END PGP SIGNATURE----- --kvUQC+jR9YzypDnK-- From dman@dman.ddts.net Tue Sep 24 04:50:10 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Mon, 23 Sep 2002 23:50:10 -0400 Subject: [Tutor] Re: What IDE do you prefer? In-Reply-To: <200209221229.07784.scot@possum.in-berlin.de> References: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> <200209221229.07784.scot@possum.in-berlin.de> Message-ID: <20020924035010.GE29763@dman.ddts.net> --zaRBsRFn0XYhEU69 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 22, 2002 at 12:29:07PM +0200, Scot W. Stevenson wrote: | Hello Steve,=20 |=20 | > Just curious. What are some of your favorite IDEs and/or text editors? |=20 | If you use all ten fingers to type, definitely take the time to learn vim= =20 | for both. It has wonderful Python support (including automatically=20 | continuing comments), there is a version for every platform, and you will= =20 | only have to learn how to use one editor for the rest of you life.=20 Ditto. In addition to learning vim, take the time to learn your (UNIX) OS. It comes with batteries ;-). What I mean is that it has all the tools and functionality you'll need already there and in modular components you can plug-n-play with any way you like. For example, use 'ctags' to generate a tags file that vim can use to jump around your code. Use 'find' and 'grep' and the like to search for stuff in your source tree. -D --=20 In his heart a man plans his course, but the Lord determines his steps. Proverbs 16:9 =20 http://dman.ddts.net/~dman/ --zaRBsRFn0XYhEU69 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2P4PIACgkQO8l8XBKTpRRW6wCdFFGjFJnadC47pFPPX+6cqUfm qpIAn0JQXB3+D1JtTyczu3HeEez6mr55 =Sqm3 -----END PGP SIGNATURE----- --zaRBsRFn0XYhEU69-- From shiska@swbell.net Tue Sep 24 05:20:29 2002 From: shiska@swbell.net (Bob Roher) Date: Mon, 23 Sep 2002 23:20:29 -0500 Subject: [Tutor] newbie looking for code suggestions References: Message-ID: <000f01c26381$b84ed3e0$6401a8c0@swbell.net> Danny Yoo wrote: >>> I see that you're calculating it by finding the maximum number out >>> of the number range; it might just be easier to take the maximum >>> outright and use that. Let's pretend we had a function that, given >>> the lower and upper ranges, tells us what the highest possible >>> digit total can be: >>> >>> ### >>> def maximum_digit_total(min_number, max_number): >>> ## fix me! We should really look at min_number and >>> ## max_number here. >>> return 9*6 >>> ### > > [some text cut] > >> Thanks Danny, that helps some. I still have a problem with that >> maximum_digit_total, though. Can you explain what you meant for >> that? I thought I was being pretty slick when I put in a function >> that would add all the digits for the upper limit and use that as a >> digit total, but my wife tested the program for me and put in a >> range from 1 to 200. Of course, you can have a higher digit total >> than 2 in that range. So, that's why I put it in the loop, since >> the only way I could think to calculate it was a simple compare and >> replace type of deal and I didn't want to have to run through a >> million number sequence twice. > > > Very true --- if the lower and upper range wraps around a power of > ten, then I think that's a special case that we can calculate really > fast... but for the general case of any range (like from 1 to 200), > I'm not seeing an obvious way of doing it yet. An interesting > problem! > > > > Is it really necessary for us to go through the whole range to get the > maximum digit total? I didn't think so at first, but now I'm not so > sure. I'll have to think about it some more. > > > > Here's a heuristic approach that I'm taking on the problem: I don't > yet know if it's correct yet. > > ### > import string, operator > > def maximum_digit_total(min_number, max_number): > return sum(int_to_list(find_maximum_digits(min_number, > max_number))) > > > def find_maximum_digits(min_number, max_number): > width = max(len(str(min_number)), len(str(max_number))) > maximum_digits = map(int, string.zfill(min_number, width)) > for i in range(width): > while maximum_digits[width - i - 1] != 9: > maximum_digits[width - i - 1] += 1 > if list_to_int(maximum_digits) > max_number: > maximum_digits[width - i - 1] -= 1 > break > return list_to_int(maximum_digits) > > > def list_to_int(digits): > return int(''.join(map(str, digits))) > > def int_to_list(number): > return map(int, str(number)) > > def sum(l): > return reduce(operator.add, l) > ### > > Here's a brief explanation of what find_maximum_digits() is doing: I > first convert things so that I'm working with a list of integers, > just to make manipulation easier. My answer starts off being the > lower limit, and slowly try to improve the answer by incrementing, > but by least significant digits first. I stop and undo things > whenever I go over the max_number. > > > > Here are a few tests I've done on this: > > ### >>>> maximum_digit_total(1, 1000) > 27 >>>> maximum_digit_total(1, 1) > 1 >>>> maximum_digit_total(1, 2) > 2 >>>> maximum_digit_total(1, 10) > 9 >>>> maximum_digit_total(1, 200) > 19 >>>> maximum_digit_total(1, 199) > 19 >>>> maximum_digit_total(199, 200) > 19 >>>> maximum_digit_total(1, 10**6) > 54 > ### > > > But this should not be taken as conclusive proof that the function is > correct... *grin* By the way, this would be a great opportunity for > someone to show how to formulate the informal tests I've done as unit > tests. > > > I have to go at the moment though; I'll try to come back to this in > the evening. Good luck! > Well, it looks good. I'm still trying to figure out exactly what you did there, though. Once I figure out map() and reduce() a little better I should be able to understand it. Another approach I was thinking of was only using the last half of the range (i.e. [(min+max)/2, max] ) to test for the maximum_digit_total. I can't think of any range of numbers where the max digit total wouldn't be in the last half of the range. For example, 1 to 100. The max would be at 99, which falls in the range [50,100]. Another arbitrary range, 1 to 1997, would have a max at 999, which is the halfway point between those two numbers. I haven't tested this fully yet, but it looks accurate so far. From dman@dman.ddts.net Tue Sep 24 05:57:41 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Tue, 24 Sep 2002 00:57:41 -0400 Subject: [Tutor] Re: Compiling Python on MacOSX. In-Reply-To: <17724E5C-CD77-11D6-B05D-00039315F4DA@knology.net> References: <17724E5C-CD77-11D6-B05D-00039315F4DA@knology.net> Message-ID: <20020924045740.GF29763@dman.ddts.net> --XStn23h1fwudRqtG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 21, 2002 at 10:30:43AM -0500, montana wrote: | Hi Everyone- |=20 | I'm following the directions from: |=20 | http://tony.lownds.com/macosx/tkinter.html |=20 | I'm trying to compile Python 2.2 with aqua Tk support for my computer.= =20 | I'm running 10.2.1 on a G4 Powerbook. When I run 'make' it barfs on the= =20 | followign error: |=20 | Modules/_tkinter.c: In function `Sleep': | Modules/_tkinter.c:252: warning: implicit declaration of function=20 | `select' | make: *** [Modules/_tkinter.o] Error 1 Ooh, ouch. Does anyone know if OSX lacks a select()? On my Debian/linux system, sleep() is declared in /usr/include/sys/select.h. Do you have a file like that? If you look in Include/pyport.h, you'll see that sys/select.h is included but only if the macro HAVE_SYS_SELECT_H is defined. The purpose of that C idiom is to allow the actual code being compiled to change based on what is available on the system. If doesn't exist on some platform, then the code doesn't try to include it (which would be an error). One way to see if that macro is defined on your system is to put this line just below it : #warn HAVE_SYS_SELECT_H _is_ defined and put this line just below the #else line #warn HAVE_SYS_SELECT_H is _not_ defined | Here is the guilty piece of code: |=20 | static void | Sleep(int milli) | { | /* XXX Too bad if you don't have select(). */ =2E.. | select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); Don't you just love that comment? ;-) | Any ideas how to get around this? (see above) | Is this an issues with the new gcc 3 on 10.2 versus the old gcc from | 10.1? I don't know. HTH, -D --=20 If Microsoft would build a car... =2E.. Occasionally your car would die on the freeway for no reason. You would have to pull over to the side of the road, close all of the car windows, shut it off, restart it, and reopen the windows before you could continue. For some reason you would simply accept this. =20 http://dman.ddts.net/~dman/ --XStn23h1fwudRqtG Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2P8MQACgkQO8l8XBKTpRQ3EACgnpiBTDTL6/RDPKGzaL2Tcsln PzMAnj+1/f7dDMWYXWaXsWrSzO54UIjk =I/9Z -----END PGP SIGNATURE----- --XStn23h1fwudRqtG-- From cyberdiction@hotmail.com Tue Sep 24 05:58:33 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Mon, 23 Sep 2002 21:58:33 -0700 Subject: [Tutor] Attachments Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0027_01C2634C.5C748680 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hello, I notice blank email messages that contain attachments. Why is this effective communication, why is it safe to open them? Regards, Stephen ------=_NextPart_000_0027_01C2634C.5C748680 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
Hello,
 
I notice blank email messages that = contain=20 attachments.
Why is this effective communication, = why is it safe=20 to open them?
 
Regards,
Stephen
------=_NextPart_000_0027_01C2634C.5C748680-- From yaya@ntlworld.com Tue Sep 24 06:02:44 2002 From: yaya@ntlworld.com (Phil Watson) Date: Tue, 24 Sep 2002 06:02:44 +0100 Subject: [Tutor] Newbie!!!!!! Message-ID: <002201c26387$9e55e7c0$c5c90350@sn010966720387> This is a multi-part message in MIME format. ------=_NextPart_000_001F_01C2638F.FFF69B20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi there! As my heading says, I am new to programming. Well my question is this: I have started writing some small programs in = Python, with the help of a few tutorials. Now, in order to get them to = run I must first save them as .py files??? I have been doing this but I = don't know how to run the programs to see if they are working out or = not. So I have come to a standstill, as there is no point inputting programs = if I cannot test them. Can anyone help me? I would be very appreciative. Thanks. ------=_NextPart_000_001F_01C2638F.FFF69B20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi there!
As my heading says, I am new to=20 programming.
 
Well my question is this: I have = started writing=20 some small programs in Python, with the help of a few tutorials.  = Now, in=20 order to get them to run I must first save them as .py files???  I = have=20 been doing this but I don't know how to run the programs to see if they = are=20 working out or not.
 
So I have come to a standstill, as = there is no=20 point inputting programs if I cannot test them.
 
Can anyone help me?
 
I would be very = appreciative.
 
Thanks.
------=_NextPart_000_001F_01C2638F.FFF69B20-- From shiska@swbell.net Tue Sep 24 06:15:06 2002 From: shiska@swbell.net (Bob Roher) Date: Tue, 24 Sep 2002 00:15:06 -0500 Subject: [Tutor] Attachments References: Message-ID: <006b01c26389$5894a080$6401a8c0@swbell.net> This is a multi-part message in MIME format. --Boundary_(ID_KATmDDdv0bZXDAAuCUXD3A) Content-type: text/plain; charset=Windows-1252 Content-transfer-encoding: 7BIT > Hello, > > I notice blank email messages that contain attachments. > Why is this effective communication, why is it safe to open them? > > Regards, > Stephen I was wondering that myself. I usually never open attachments unless I sent it to myself. --Boundary_(ID_KATmDDdv0bZXDAAuCUXD3A) Content-type: text/html; charset=Windows-1252 Content-transfer-encoding: 7BIT > Hello,
>
> I notice blank email messages that contain attachments.
> Why is this effective communication, why is it safe to open them?
>
> Regards,
> Stephen

I was wondering that myself.  I usually never open attachments unless I sent it to myself. --Boundary_(ID_KATmDDdv0bZXDAAuCUXD3A)-- From shiska@swbell.net Tue Sep 24 06:51:05 2002 From: shiska@swbell.net (Bob Roher) Date: Tue, 24 Sep 2002 00:51:05 -0500 Subject: [Tutor] Newbie!!!!!! References: <002201c26387$9e55e7c0$c5c90350@sn010966720387> Message-ID: <00d701c2638e$5f7c9060$6401a8c0@swbell.net> This is a multi-part message in MIME format. --Boundary_(ID_eJl7rdIBJ2Pnpb/Q/UhKpg) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT > Hi there! > As my heading says, I am new to programming. > > Well my question is this: I have started writing some small > programs in Python, with the help of a few tutorials. Now, in > order to get them to run I must first save them as .py files??? I > have been doing this but I don't know how to run the programs to > see if they are working out or not. > > So I have come to a standstill, as there is no point inputting > programs if I cannot test them. > > Can anyone help me? > > I would be very appreciative. > > Thanks. Hi Phil. Have you downloaded and installed Python from python.org yet? You'll need the interpreter to run the program. If so, then you can run the program from a command line like such: c:\python22\python program.py I believe you'll need to be in the directory that python is installed in to do that or pointing to that directory. You might also want to check out IDLE, you can open a new window for each program or function you are working on and test them in the Python shell as you write. You should have IDLE installed if you have downloaded Python, it comes with it. (This advice applies to the Windows version, I don't have Linux installed so you'll have to muddle through the instructions if you're using that OS) --Boundary_(ID_eJl7rdIBJ2Pnpb/Q/UhKpg) Content-type: text/html; charset=iso-8859-1 Content-transfer-encoding: 7BIT > Hi there!
> As my heading says, I am new to programming.
>
> Well my question is this: I have started writing some small
> programs in Python, with the help of a few tutorials.  Now, in
> order to get them to run I must first save them as .py files???  I
> have been doing this but I don't know how to run the programs to
> see if they are working out or not.   
>
> So I have come to a standstill, as there is no point inputting
> programs if I cannot test them.
>
> Can anyone help me?
>
> I would be very appreciative.
>
> Thanks.

Hi Phil.  Have you downloaded and installed Python from python.org yet?  You'll need the interpreter to run the program.  If so, then you can run the program from a command line like such:  c:\python22\python program.py  I believe you'll need to be in the directory that python is installed in to do that or pointing to that directory.  You might also want to check out IDLE, you can open a new window for each program or function you are working on and test them in the Python shell as you write.  You should have IDLE installed if you have downloaded Python, it comes with it. (This advice applies to the Windows version, I don't have Linux installed so you'll have to muddle through the instructions if you're using that OS) --Boundary_(ID_eJl7rdIBJ2Pnpb/Q/UhKpg)-- From kalle@lysator.liu.se Tue Sep 24 06:56:32 2002 From: kalle@lysator.liu.se (Kalle Svensson) Date: Tue, 24 Sep 2002 07:56:32 +0200 Subject: [Tutor] recommended Editor? In-Reply-To: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> References: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> Message-ID: <20020924055632.GA1656@i92.ryd.student.liu.se> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [Lance] > Can someone suggest a good editor to use with Python? I like Crisp, > but I would need to code all the indents, etc. I like emacs (http://gnu.org/software/emacs/) with python-mode (http://python.org/emacs/python-mode/). Peace, Kalle - -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 iD8DBQE9j/6EdNeA1787sd0RAkwWAJkB7gQO3EO1qkw4NEb+4Rg+fyTgIACgt3RH pwDPEf9k3bXfVinC9kmUGaA= =rkMh -----END PGP SIGNATURE----- From kalle@lysator.liu.se Tue Sep 24 07:12:17 2002 From: kalle@lysator.liu.se (Kalle Svensson) Date: Tue, 24 Sep 2002 08:12:17 +0200 Subject: [Tutor] Attachments In-Reply-To: References: Message-ID: <20020924061217.GB1656@i92.ryd.student.liu.se> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [Stephen Harris] > Hello, > > I notice blank email messages that contain attachments. > Why is this effective communication, why is it safe to open them? I'm guessing that you're referring to Dman's messages. They have MIME-encoded PGP signatures. Microsoft Outlook Express (and maybe other software, though I've never seen any) seems to get confused by this and displays them as attachments. This is a problem with MSOE, as far as I can tell. As for why it's safe to open them: Well, it just is. In my opinion, every attachment should be safe to open, it's just text anyway. But this isn't true using an insecure email client like MSOE. My suggestion would be to change to something more secure and robust. Sadly, I don't have any real examples for Windows, but maybe the Mozilla (http://www.mozilla.org/) email program would work for you. Peace, Kalle - -- Kalle Svensson, http://www.juckapan.org/~kalle/ Student, root and saint in the Church of Emacs. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 iD8DBQE9kAI9dNeA1787sd0RAt4wAKCH2ow4m6WE7LhIVXWV2+unwT4MywCffIK4 gkYK6bhTDnRkPipQwys/ic8= =zaDW -----END PGP SIGNATURE----- From dyoo@hkn.eecs.berkeley.edu Tue Sep 24 07:44:14 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 23 Sep 2002 23:44:14 -0700 (PDT) Subject: [Tutor] newbie looking for code suggestions In-Reply-To: <000f01c26381$b84ed3e0$6401a8c0@swbell.net> Message-ID: > > Here's a heuristic approach that I'm taking on the problem: I don't > > yet know if it's correct yet. > > > > ### > > import string, operator > > > > def maximum_digit_total(min_number, max_number): > > return sum(int_to_list(find_maximum_digits(min_number, > > max_number))) > > > > > > def find_maximum_digits(min_number, max_number): > > width = max(len(str(min_number)), len(str(max_number))) > > maximum_digits = map(int, string.zfill(min_number, width)) > > for i in range(width): > > while maximum_digits[width - i - 1] != 9: > > maximum_digits[width - i - 1] += 1 > > if list_to_int(maximum_digits) > max_number: > > maximum_digits[width - i - 1] -= 1 > > break > > return list_to_int(maximum_digits) > > > > > > def list_to_int(digits): > > return int(''.join(map(str, digits))) > > > > def int_to_list(number): > > return map(int, str(number)) > > > > def sum(l): > > return reduce(operator.add, l) > > ### > > > Well, it looks good. I'm still trying to figure out exactly what you > did there, though. Once I figure out map() and reduce() a little better > I should be able to understand it. If it helps, we can try it by hand. Let's take the tricky range between 172 and 255. The reason this is "tricky" is because our lower end of the range is NOT 1, nor is our upper range in the even hundreds. We have to think deviously. *grin* The approach I'm taking is to start off with a guaranteed wrong answer, and slowly turn it right. I think I have a better understanding of the problem now, and I hope I can explain it well. Pretend that we all we know right now is that we have a starting number: starting = [1, 7, 2] and we have some sort of maximum number 'maximum': target = [2, 5, 5] What we're told off, initially, is that 'starting' is guaranteed to be already smaller than our target, and at any given time, we can tell if starting is ever larger than target, just by doing a simple comparision. Our goal is to fiddle around with our starting number, and to get as many digits as high as possible, without going over our maximum. Well, we know that least significant digits matter the least, so perhaps incrementing them will allow us to cautiously tread toward an answer. We can start by incrementing the right hand side of our starting number: [1, 7, 2] ---> [1, 7, 3] ---> ...all the way up to ... ---> [1, 7, 9] And we stop incrementing the one's position. We don't need to check against [1, 8, 0]: if we do, that won't help, because rather than getting closer toward maximizing the digit sum, we've taken a huge step backwards! Let's see if we can do good by continuously improving our answer. (This is a "greedy" way of getting an answer, but in this case, I believe a greedy solution does work.) Now that we've improved our answer as far as we can get in the units position, we start stepping, more courageously, through the units: [1, 7, 9] ---> [1, 8, 9] ---> [1, 9, 9] ... and we still haven't gone over the maximum limit of [2, 5, 5] yet, so we're still good. We're more confident now, so let's start incrementing the hundreds position! [1, 9, 9] ---> [2, 9, 9] .... wait! We've gone over! So we can't improve the situation by incrementing the hundreds position. Our best answer, then, is the one we just calculated: [1, 9, 9]. My mind is still sputtering a bit, but I think that when I can organizing the ideas properly, I can give a formal induction proof of why this works. But can someone else do it? *grin* > Another approach I was thinking of was only using the last half of the > range (i.e. [(min+max)/2, max] ) to test for the maximum_digit_total. The case of [172--255] breaks this, as: ### >>> (255 + 172) / 2 213 ### is out of the ballpark: our best answer can't be between 213 and 255, because 199 beats everything in there: ### >>> def digit_sum(n): ... digits = map(int, str(n)) ... sum = 0 ... for d in digits: sum = sum + d ... return sum ... >>> digit_sum(199) 19 >>> max([digit_sum(x) for x in range(213, 256)]) 15 ### > I can't think of any range of numbers where the max digit total wouldn't > be in the last half of the range. Diabolical is the key here. If we're afraid of human bias, we don't pick the numbers ourselves, but allow Python to pick them for us: ### >>> import random >>> random.randrange(1000) 895 >>> random.randrange(1000) 724 ### > For example, 1 to 100. The max would be at 99, which falls in the range > [50,100]. Another arbitrary range, 1 to 1997, would have a max at 999, > which is the halfway point between those two numbers. I haven't tested > this fully yet, but it looks accurate so far. The problem is that both endpoints are involved, and we've got to shake around the left point as much as we do the right side. That is, we've got to move both ends in parallel. Furthermore, we should try to stray get away from nice round numbers. The example: min=277, max=388 is another great example where we could think go ahead and 'print 378' as our answer, where in reality it's 299. Again, thank you. This was an even more fun problem than the original problem that we started from. *grin* Best of wishes to you! From dyoo@hkn.eecs.berkeley.edu Tue Sep 24 07:51:41 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 23 Sep 2002 23:51:41 -0700 (PDT) Subject: [Tutor] newbie looking for code suggestions In-Reply-To: Message-ID: > The problem is that both endpoints are involved, and we've got to shake > around the left point as much as we do the right side. That is, we've got > to move both ends in parallel. Furthermore, we should try to stray get > away from nice round numbers. The example: > > min=277, max=388 > > is another great example where we could think go ahead and 'print 378' > as our answer, where in reality it's 299. I knew I was getting too clever for myself. I meant to say: """... is another great example where we could think go ahead and 'print 388' as our answer, where in reality it's 299. """ But that just ruins the nice parallel port joke I was trying to smuggle in there... *sigh* Oh well. From cyberdiction@hotmail.com Tue Sep 24 07:50:44 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Mon, 23 Sep 2002 23:50:44 -0700 Subject: [Tutor] Attachments References: <003501c26387$e7dd25c0$c5c90350@sn010966720387> Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_00B9_01C2635C.08286000 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable The recent email with attachments came from Derrick 'dman' Hudson and had legitimate sounding subjects. The attachments that I checked were named: ATT00171.txt and ATT00174.dat on one particula file. I thought it odd, that there was no message which sometimes introduces code that is sent as an attachment. No text in the main email window, as in where I am typing now. I never open attachments unless the source is=20 trusted. And ya never know, maybe some of these pyhtonistas are = hacklings. Regards, Stephen ----- Original Message -----=20 From: Phil Watson=20 To: Stephen Harris=20 Sent: Monday, September 23, 2002 10:04 PM Subject: Re: [Tutor] Attachments There should not be any attachments on the email. Can you tell me what the attachment is called?? And please do not open = it until I can find what it is. Regards ----- Original Message -----=20 From: Stephen Harris=20 To: tutor@python.org=20 Sent: Tuesday, September 24, 2002 5:58 AM Subject: [Tutor] Attachments Hello, I notice blank email messages that contain attachments. Why is this effective communication, why is it safe to open them? Regards, Stephen ------=_NextPart_000_00B9_01C2635C.08286000 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
The recent email with attachments came = from Derrick=20 'dman' Hudson
and had legitimate sounding subjects. = The=20 attachments that I checked
were named: ATT00171.txt and = ATT00174.dat on one=20 particula file.
 
I thought it odd, that there was no = message which=20 sometimes introduces
code that is sent as an attachment. No = text in the=20 main email window, as
in where I am typing now. I never open = attachments=20 unless the source is
trusted. And ya never know, maybe some = of these=20 pyhtonistas are hacklings.
 
Regards,
Stephen
----- Original Message -----
From:=20 Phil = Watson=20
Sent: Monday, September 23, = 2002 10:04=20 PM
Subject: Re: [Tutor] = Attachments

There should not be any attachments = on the=20 email.
 
Can you tell me what the attachment = is called??=20 And please do not open it until I can find what it is.
 
Regards
----- Original Message -----
From:=20 Stephen Harris
Sent: Tuesday, September 24, = 2002 5:58=20 AM
Subject: [Tutor] = Attachments

Hello,
 
I notice blank email messages that = contain=20 attachments.
Why is this effective = communication, why is it=20 safe to open them?
 
Regards,
Stephen
------=_NextPart_000_00B9_01C2635C.08286000-- From dyoo@hkn.eecs.berkeley.edu Tue Sep 24 08:11:34 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 24 Sep 2002 00:11:34 -0700 (PDT) Subject: [Tutor] Re: Compiling Python on MacOSX. In-Reply-To: <20020924045740.GF29763@dman.ddts.net> Message-ID: On Tue, 24 Sep 2002, Derrick 'dman' Hudson wrote: > On Sat, Sep 21, 2002 at 10:30:43AM -0500, montana wrote: > | Hi Everyone- > | > | I'm following the directions from: > | > | http://tony.lownds.com/macosx/tkinter.html > | > | I'm trying to compile Python 2.2 with aqua Tk support for my computer. > | I'm running 10.2.1 on a G4 Powerbook. When I run 'make' it barfs on the > | followign error: > | > | Modules/_tkinter.c: In function `Sleep': > | Modules/_tkinter.c:252: warning: implicit declaration of function > | `select' > | make: *** [Modules/_tkinter.o] Error 1 > > Ooh, ouch. Does anyone know if OSX lacks a select()? That just can't be right. OS X is a BSD Unix: it would be a Cardinal sin for it not to have select(). *grin* On the other hand, that error doesn't really appear to be about select(), as the computer is just giving a warning about the missing declaration. I think it might be somewhere else. Do you mind cutting-and-pasting a bit more of your compilation? Try searching for the phrase 'error:' rather than 'warning:'. You might also want to check with the pythonmac-sig about this problem: http://www.python.org/sigs/pythonmac-sig/ Someone there should know more about the oddities in compiling Python and Tk for your system. Best of wishes to you! From dyoo@hkn.eecs.berkeley.edu Tue Sep 24 08:17:51 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 24 Sep 2002 00:17:51 -0700 (PDT) Subject: [Tutor] Attachments In-Reply-To: Message-ID: On Mon, 23 Sep 2002, Stephen Harris wrote: > The recent email with attachments came from Derrick 'dman' Hudson and > had legitimate sounding subjects. The attachments that I checked were > named: ATT00171.txt and ATT00174.dat on one particula file. > > I thought it odd, that there was no message which sometimes introduces > code that is sent as an attachment. No text in the main email window, as > in where I am typing now. I never open attachments unless the source is > trusted. Very true. Using the 'pine' email program, Dman's attachments show up correctly as PGP signature files; here's what it looks like to me: ### [ Part 2, Application/PGP-SIGNATURE 248bytes. ] [ Cannot display this part. Press "V" then "S" to save in a file. ] ### So there is real content in that attachment, but I wonder why your email program is trying to do weird things with it. In any case, there shouldn't be important attachments on the Tutor mailing list, so you don't have to open any of them here. > And ya never know, maybe some of these pyhtonistas are hacklings. Hmmmm... I wonder... ### dyoo@coffeetable:~$ wordnet hackling -hypev Synonyms/Hypernyms (Ordered by Frequency) of verb hackle 1 sense of hackle Sense 1 heckle, hackle, hatchel => comb => straighten, straighten out => change, alter ### Yes, that's right. We do try to straighten messy programs. *grin* I hope you have a good evening! From dyoo@hkn.eecs.berkeley.edu Tue Sep 24 08:26:56 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 24 Sep 2002 00:26:56 -0700 (PDT) Subject: [Tutor] Newbie!!!!!! In-Reply-To: <002201c26387$9e55e7c0$c5c90350@sn010966720387> Message-ID: On Tue, 24 Sep 2002, Phil Watson wrote: > Well my question is this: I have started writing some small programs in > Python, with the help of a few tutorials. Now, in order to get them to > run I must first save them as .py files??? I have been doing this but I > don't know how to run the programs to see if they are working out or > not. > > So I have come to a standstill, as there is no point inputting programs > if I cannot test them. > > Can anyone help me? Hi Phil, I wrote a small tutorial on getting started with Python a few months ago; I don't know if it would help, but it couldn't hurt taking a peek... *grin* Here's the link: http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/ You don't have to save things if you're just experimenting with Python, but then, that will only allow you to try out programs that you can type out in a day. So learning how to save a Python program as a '.py' is important because it'll let you work on more interesting programs. The tutorial on the link above shows how to save and load Python programs. Good luck! From cyberdiction@hotmail.com Tue Sep 24 08:35:32 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Tue, 24 Sep 2002 00:35:32 -0700 Subject: [Tutor] Attachments References: Message-ID: ----- Original Message ----- From: "Danny Yoo" To: "Stephen Harris" Cc: "Phil Watson" ; "Tutor" Sent: Tuesday, September 24, 2002 12:17 AM Subject: Re: [Tutor] Attachments > > Very true. Using the 'pine' email program, Dman's attachments show up > correctly as PGP signature files; here's what it looks like to me: > > ### > [ Part 2, Application/PGP-SIGNATURE 248bytes. ] > [ Cannot display this part. Press "V" then "S" to save in a file. ] > ### > > So there is real content in that attachment, but I wonder why your email > program is trying to do weird things with it. In any case, there > shouldn't be important attachments on the Tutor mailing list, so you don't > have to open any of them here. > I decided to try the email plugin. http://www.pgpi.org/cgi/tools.cgi?category=Email+plugin&platform=95%2F98%2FN T&pgpversion=&license=&text= MS Outlook and Exchange plugin Category: Email plugin Platform: Windows 95/98/NT For use with: PGP 5.x/6.x License: Freeware Homepage: http://www.pgpi.com/cgi/download-wizard.cgi?country=US&platform=Windows+95%2 F98%2FNT&license=freeware Description: This plugin integrates PGP with Microsoft Outlook 97/98/2000 or Exchange. It is included in the PGP 6.5.1 distribution. MS Outlook Express plugin Category: Email plugin Platform: Windows 95/98/NT For use with: PGP 5.x/6.x License: Freeware Homepage: http://www.pgpi.com/cgi/download-wizard.cgi?country=US&platform=Windows+95%2 F98%2FNT&license=freeware Description: This plugin integrates PGP with Microsoft Outlook Express 4/5. It is included in the PGP 6.5.1 distribution. PGP Extension for Microsoft Exchange 1.10 > ### > dyoo@coffeetable:~$ wordnet hackling -hypev > > Synonyms/Hypernyms (Ordered by Frequency) of verb hackle > > 1 sense of hackle > > Sense 1 > heckle, hackle, hatchel > => comb > => straighten, straighten out > => change, alter > ### > > Yes, that's right. We do try to straighten messy programs. *grin* > > > I hope you have a good evening! > Well, I was thinking hacker when the term enjoyed a better reputation. So I decided to use the pejorative diminutive like: duck-->ugly duckling I've noticed that spambayes is not truly a Bayesian probability method. The discussion was quite interesting. My download is complete. Prospero, Stephen From dyoo@hkn.eecs.berkeley.edu Tue Sep 24 08:51:21 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 24 Sep 2002 00:51:21 -0700 (PDT) Subject: [Tutor] need help In-Reply-To: <20020924011928.13445.qmail@web12708.mail.yahoo.com> Message-ID: On Tue, 24 Sep 2002, [iso-8859-1] Juan Carlos Coellar wrote: > hello! to all > > First: Thanks you for your reply to my request i am indebted you,it > sure would save me a lot of time > > Second point: I need info about ,?how may i do to create a executable > programs (exe or other) from python to anything computer ,as the same > way that the other language There's a specialized utility called py2exe that we can use to bundle Python programs as EXE's: http://py2exe.sourceforge.net/ It's specialized because once it's in this bundled form, it becomes quite a bit harder to fix problems in the program. I wouldn't recommend using it until the target program is pretty well finished. But it's a good way to share programs with people who haven't installed Python yet. Good luck to you! From cyberdiction@hotmail.com Tue Sep 24 08:59:43 2002 From: cyberdiction@hotmail.com (Stephen Harris) Date: Tue, 24 Sep 2002 00:59:43 -0700 Subject: [Tutor] Testing pgp References: Message-ID: Testing pgp. Did not select "Use pgp and Mime checkbox" ----- Original Message ----- From: "Stephen Harris" To: Sent: Tuesday, September 24, 2002 12:35 AM Subject: Re: [Tutor] Attachments From shiska@swbell.net Tue Sep 24 09:17:23 2002 From: shiska@swbell.net (Bob Roher) Date: Tue, 24 Sep 2002 03:17:23 -0500 Subject: [Tutor] newbie looking for code suggestions References: Message-ID: <013e01c263a2$d03ff760$6401a8c0@swbell.net> > > >> I can't think of any range of numbers where the max digit total >> wouldn't be in the last half of the range. > > Diabolical is the key here. If we're afraid of human bias, we > don't pick the numbers ourselves, but allow Python to pick them for > us: > > ### >>>> import random >>>> random.randrange(1000) > 895 >>>> random.randrange(1000) > 724 > ### > > > >> For example, 1 to 100. The max would be at 99, which falls in the >> range [50,100]. Another arbitrary range, 1 to 1997, would have a >> max at 999, which is the halfway point between those two numbers. >> I haven't tested this fully yet, but it looks accurate so far. > > The problem is that both endpoints are involved, and we've got to > shake around the left point as much as we do the right side. That > is, we've got to move both ends in parallel. Furthermore, we > should try to stray get away from nice round numbers. The example: > > min=277, max=388 > > is another great example where we could think go ahead and 'print > 378' as our answer, where in reality it's 299. > > > > Again, thank you. This was an even more fun problem than the > original problem that we started from. *grin* Best of wishes to > you! > > Doh. After I had all this written out to test my theory: import random def sum_of_digits(in_string): return reduce(lambda x,y: int(x) + int(y), in_string) def get_user_input(): min_number = random.randrange(1,1000001) max_number=0 while max_number < min_number: max_number = random.randrange(1,1000001) return min_number, max_number max_possible=0 rangelist=[] for q in range (1,1000): min_number,max_number=get_user_input() for i in range (min_number, max_number+1): x=str(i) p=sum_of_digits(x) if p>=max_possible: max_possible=p hit=i percent=(float(hit)/max_number)*100 print """The max possible digit total between %d and %d is %d, occurs at %d and is %d percent of the max number""" %(min_number,max_number,max_possible,hit,percent) rangelist.append(percent) hit=0 i=0 max_possible=0 p=0 print rangelist As you can see, I ran 1000 iterations. I won't even begin to guess how long it took, I started it at lunch and I left. Nothing was under 62 percent. And now you prove my little program wrong. :cry: Thanks for explaining your function to me, though. I knew what it was supposed to do, but all the syntax I'm unfamiliar with still makes it a bit confusing for me. I'll get it sorted out when I get the language down a bit better. From shiska@swbell.net Tue Sep 24 06:34:10 2002 From: shiska@swbell.net (Bob Roher) Date: Tue, 24 Sep 2002 00:34:10 -0500 Subject: [Tutor] Newbie!!!!!! References: <002201c26387$9e55e7c0$c5c90350@sn010966720387> Message-ID: <008f01c2638c$026a7e20$6401a8c0@swbell.net> This is a multi-part message in MIME format. --Boundary_(ID_1gQSOfMGq4pykJoBnZshaw) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT > Hi there! > As my heading says, I am new to programming. > > Well my question is this: I have started writing some small > programs in Python, with the help of a few tutorials. Now, in > order to get them to run I must first save them as .py files??? I > have been doing this but I don't know how to run the programs to > see if they are working out or not. > > So I have come to a standstill, as there is no point inputting > programs if I cannot test them. > > Can anyone help me? > > I would be very appreciative. > > Thanks. Hi Phil. Have you downloaded and installed Python from python.org yet? You'll need the interpreter to run the program. If so, then you can run the program from a command line like such: c:\python22\python program.py I believe you'll need to be in the directory that python is installed in to do that or pointing to that directory. You might also want to check out IDLE, you can open a new window for each program or function you are working on and test them in the Python shell as you write. You should have IDLE installed if you have downloaded Python, it comes with it. (This advice applies to the Windows version, I don't have Linux installed so you'll have to muddle through the instructions if you're using that OS) --Boundary_(ID_1gQSOfMGq4pykJoBnZshaw) Content-type: text/html; charset=iso-8859-1 Content-transfer-encoding: 7BIT
> Hi there!
> As my heading says, I am new to programming.
>
> Well my question is this: I have started writing some small
> programs in Python, with the help of a few tutorials.  Now, in
> order to get them to run I must first save them as .py files???  I
> have been doing this but I don't know how to run the programs to
> see if they are working out or not.   
>
> So I have come to a standstill, as there is no point inputting
> programs if I cannot test them.
>
> Can anyone help me?
>
> I would be very appreciative.
>
> Thanks.

Hi Phil.  Have you downloaded and installed Python from python.org yet?  You'll need the interpreter to run the program.  If so, then you can run the program from a command line like such:  c:\python22\python program.py  I believe you'll need to be in the directory that python is installed in to do that or pointing to that directory.  You might also want to check out IDLE, you can open a new window for each program or function you are working on and test them in the Python shell as you write.  You should have IDLE installed if you have downloaded Python, it comes with it. (This advice applies to the Windows version, I don't have Linux installed so you'll have to muddle through the instructions if you're using that OS)
--Boundary_(ID_1gQSOfMGq4pykJoBnZshaw)-- From d.j.kniep@chello.nl Tue Sep 24 10:26:07 2002 From: d.j.kniep@chello.nl (Dick Kniep) Date: 24 Sep 2002 11:26:07 +0200 Subject: [Tutor] [Fwd: Please help, I'm a newbie] In-Reply-To: <5.1.0.14.0.20020923175816.02a8e288@www.thinkware.se> References: <5.1.0.14.0.20020923175816.02a8e288@www.thinkware.se> Message-ID: <1032859568.1628.0.camel@kniep02.kniep> Hi Magnus, Yes I know. SQLDict is the routine you mentioned. I only want to adapt it.... But strange things are happening... Cheers Dick On Mon, 2002-09-23 at 18:27, Magnus Lycka wrote: > At 16:02 2002-09-23 +0200, Dick Kniep wrote: > >Hi there, > > > >I am trying to write a piece of coding that uses a standard routine to > >open SQL tables into dictionaries. >=20 > Before reinventing the wheel, it's a good thing to search > Vaults of Parnassus: http://www.vex.net/parnassus/ (and > Google for that matter.) >=20 > There is already a SQLDict by Andy Dustman. Guess what it does... >=20 > And there is Boudewijn Rempt's dbObj... >=20 > Then there is Kevin Jacobs' db_row... >=20 > Those are the ones I found as Parnassus, but I seem to > recall that Greg Stein wrote one as well. Let's look at > www.lyra.org. Certainy, there is a dtuple.py at > http://www.lyra.org/greg/python/ >=20 > I hope one of these four wheels will fit! ;) >=20 >=20 >=20 >=20 > --=20 > Magnus Lyck=E5, Thinkware AB > =C4lvans v=E4g 99, SE-907 50 UME=C5 > tel: 070-582 80 65, fax: 070-612 80 65 > http://www.thinkware.se/ mailto:magnus@thinkware.se >=20 >=20 > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From erikprice@mac.com Tue Sep 24 10:56:42 2002 From: erikprice@mac.com (Erik Price) Date: Tue, 24 Sep 2002 05:56:42 -0400 Subject: [Tutor] Attachments In-Reply-To: Message-ID: On Tuesday, September 24, 2002, at 02:50 AM, Stephen Harris wrote: > And ya never know, maybe some of these pyhtonistas are hacklings. They all are. Fortunately, no harm will befall you, as long as you don't try to execute any of the attachment as code/scripts. Unfortunately, you're using Outlook Express, which is often configured to do this automatically. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From AKolinski@nriindustries.com Tue Sep 24 16:59:06 2002 From: AKolinski@nriindustries.com (Andrzej Kolinski) Date: Tue, 24 Sep 2002 11:59:06 -0400 Subject: [Tutor] HTMLgen Message-ID: I'd like to work with the HTMLgen package but I am encountering some difficulties. (I hope) I succeeded with its installation - I ran HTMLtest and the program generated most of the HTML files (I replaced regex with re, and there was another I had to remove completely). I was able to run a simple code at the C: prompt: C:\>python >>> from HTMLgen import * >>> p = Paragraph("bla, bla/n, bla") >>> print p

bla, bla bla

But when I wanted to run the same test within IDLE I got: >>> from HTMLgen import * Traceback (most recent call last): File "", line 1, in ? from HTMLgen import * ImportError: No module named HTMLgen >>> I suspect I have some kind of installation/setup problem, but I don't know what the problem is. I have another question regarding the use of HTMLgen. How can I insert a simple text file to my HTML page? Open ti, readlines, write, but how? Thanks _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/ Andrzej From lsloan@umich.edu Tue Sep 24 17:03:11 2002 From: lsloan@umich.edu (Lance E Sloan) Date: Tue, 24 Sep 2002 12:03:11 -0400 Subject: [Tutor] Re: Compiling Python on MacOSX. In-Reply-To: References: Message-ID: <8101922.1032868991@[10.0.1.28]> --On Tuesday, September 24, 2002 0:11 -0700 Danny Yoo wrote: > On Tue, 24 Sep 2002, Derrick 'dman' Hudson wrote: >> On Sat, Sep 21, 2002 at 10:30:43AM -0500, montana wrote: >> | Modules/_tkinter.c: In function `Sleep': >> | Modules/_tkinter.c:252: warning: implicit declaration of function >> | `select' >> | make: *** [Modules/_tkinter.o] Error 1 >> >> Ooh, ouch. Does anyone know if OSX lacks a select()? > > That just can't be right. OS X is a BSD Unix: it would be a Cardinal sin > for it not to have select(). *grin* It has select(2): % man select SELECT(2) System Calls Manual SELECT(2) NAME select - synchronous I/O multiplexing [...] I responded to "montana", and I think I cc'ed this list, that I didn't have any trouble compiling it on my OS X.2 machine. I thought that maybe he was using the wrong version of Python 2.2 source. I wondered if he had gotten it from CVS rather than the tar file. CVS may contain a "bleeding edge" version. I had trouble compiling Tcl/Tk, but Tony Lownds forwarded some instructions to me about that. I think "montana" forwarded that to this list a couple days ago, too. I followed those and then Tony's Python build instructions and now I have a working Python interpreter with Tkinter on my Mac OS X.2 machine. There is a slight problem, though. Tkinter calls work properly from within IDLE. However, if I start Python from a UNIX commandline, I'm unable to manipulate the Tk window. I emailed Tony about that and he acknowledged that problem is becoming a FAQ. He suggested I use pythonw or name my files with .pyw, but the build process didn't produce a pythonw, so I'll have to figure out how to do that. Tony suggested another "bleeding edge" solution, try Python 2.3. He said it has a Mac IDE that's built "automagically". I haven't had time to try it yet. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From pythonpython@hotmail.com Tue Sep 24 17:25:12 2002 From: pythonpython@hotmail.com (Hy Python) Date: Tue, 24 Sep 2002 16:25:12 +0000 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? Message-ID: Could you please tell me if it's possible to display non-ascii charaters on tkinter-made GUIs? Can interfaces made with tkinter display non-ascii charaters? Can tkinter display the 650,00+ unicode characters? Is there a way to set default system encoding to something other than ascii? (sys module has a getdefaultencoding() method, but there is no setdefaultdencoding() method.) Thanks a lot. Hy _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx From lists@shrestha.net.np Tue Sep 24 17:18:11 2002 From: lists@shrestha.net.np (Ashish Shrestha) Date: Tue, 24 Sep 2002 22:03:11 +0545 Subject: [Tutor] was What IDE do you prefer? - now folding python in emacs References: <5.1.0.14.0.20020922015344.03641418@www.thinkware.se> <5.1.0.14.0.20020922230604.02b62ab0@www.thinkware.se> <3D8FD865.2040907@xminc.com> Message-ID: <3D909043.6070401@shrestha.net.np> Anthony Barker wrote: >>> >>> emacs has a folding add-in module- have you tried it? >>> fte has folding - but I am not crazy about it. >> >> >> >> I never really used emacs a lot. I know that there is >> a folding mode that is based on some special notation >> in the text. Can it fold python purely based on indentation? > > > > Yes it is fairly simple - I picked up the script from google groups. It > doesn't require the fancy script Anders Lindgren wrote. > > taken from: > http://groups.google.ca/groups?q=emacs+folding+python&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=uelftqprw.fsf%40cs.unc.edu&rnum=2 > [snip] well, the folding in vim and jedit is simpler. both can be told to fold on indent. for vim it is: set fdm=indent to set folding column width set fdc=4 in jedit there it is under global options/editing ashish From rob@uselesspython.com Tue Sep 24 18:19:18 2002 From: rob@uselesspython.com (Rob) Date: Tue, 24 Sep 2002 12:19:18 -0500 Subject: [Tutor] What IDE do you prefer? In-Reply-To: <1302.192.168.1.76.1032650696.squirrel@192.168.1.1> Message-ID: While I can't say it's my favorite, because I've only had it for a few days, I thought it would be interesting to point out that Kobol for Linux/Windows supports Python highlighting out of the box. It's a COBOL IDE, which is a trippy concept in itself. http://www.thekompany.com/products/kobol/ Rob > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Steve Lewis > Sent: Saturday, September 21, 2002 6:25 PM > To: tutor@python.org > Subject: [Tutor] What IDE do you prefer? > > > Just curious. What are some of your favorite IDEs and/or text editors? > > Steve Lewis > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From llazarre@yahoo.com Tue Sep 24 20:37:40 2002 From: llazarre@yahoo.com (Levy Lazarre) Date: Tue, 24 Sep 2002 12:37:40 -0700 (PDT) Subject: [Tutor] Conditional output of a header line Message-ID: <20020924193740.25050.qmail@web40402.mail.yahoo.com> Good afternoon all, I have written a script that cleans an error log and writes the output to a new file. Basically, I read the file line by line, apply various filters to eliminate the trashy lines, and output the desired lines to a new file via print statements. I am having some difficulty with one last task however. I need to conditionally eliminate a header line depending on what comes on the next line. Please see the sample below. When a line starts with "Console Log" I need to 'look ahead' and see if it is followed by a time stamp hh:mm:ss. If so, output it. If not suppress it. In the example enclosed, I would want to output the first "Console Log ..." line but ignore the second one. Is there an easy way to do this in Python? Apparently I can't use a regexp since I am reading line by line. All suggestions (except coding a state machine!) will be appreciated. Thanks, Levy Lazarre Integration Coordinator Mid-Florida Medical Services ------------------------------sample----------------------------------------- Console Log for 09/20/02 - Messages starting 3466 of 4238 16:25:58 I/B ORDER/RES - Test Code Invalid For Specified CLINSTAR PATIENT CARE Order...Data Discarded! 1625 . . . Console Log for 09/21/02 - Messages starting 2797 of 3826 E Order...Data Discarded! 0925 . . . __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com From glingl@aon.at Tue Sep 24 20:56:56 2002 From: glingl@aon.at (Gregor Lingl) Date: Tue, 24 Sep 2002 21:56:56 +0200 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? References: Message-ID: <3D90C388.4070705@aon.at> Hy Python schrieb: > Could you please tell me if it's possible to display non-ascii > charaters on tkinter-made GUIs? > > Can interfaces made with tkinter display non-ascii charaters? I have the following code in my sitecustomize.py import sys, locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if encoding != "ascii": sys.setdefaultencoding(encoding) And on my machine the following works: t = "32 " + unichr(0x20ac) from Tkinter import * root = Tk() Label(root, text=t).pack() mainloop() Gregor > > Can tkinter display the 650,00+ unicode characters? > Is there a way to set default system encoding to something other than > ascii? > (sys module has a getdefaultencoding() method, but there is no > setdefaultdencoding() method.) > > Thanks a lot. > > Hy > > _________________________________________________________________ > MSN Photos is the easiest way to share and print your photos: > http://photos.msn.com/support/worldwide.aspx > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > From glingl@aon.at Tue Sep 24 20:47:45 2002 From: glingl@aon.at (Gregor Lingl) Date: Tue, 24 Sep 2002 21:47:45 +0200 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? References: Message-ID: <3D90C161.4060100@aon.at> Hy Python schrieb: > Could you please tell me if it's possible to display non-ascii > charaters on tkinter-made GUIs? > > Can interfaces made with tkinter display non-ascii charaters? > Can tkinter display the 650,00+ unicode characters? > Is there a way to set default system encoding to something other than > ascii? > (sys module has a getdefaultencoding() method, but there is no > setdefaultdencoding() method.) Yes there is! See: http://www.python.org/doc/current/lib/module-sys.html#l2h-264 Regards Gregor > > > Thanks a lot. > > Hy > > _________________________________________________________________ > MSN Photos is the easiest way to share and print your photos: > http://photos.msn.com/support/worldwide.aspx > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > From shalehperry@attbi.com Tue Sep 24 21:06:36 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Tue, 24 Sep 2002 13:06:36 -0700 Subject: [Tutor] Conditional output of a header line In-Reply-To: <20020924193740.25050.qmail@web40402.mail.yahoo.com> References: <20020924193740.25050.qmail@web40402.mail.yahoo.com> Message-ID: <200209241306.36275.shalehperry@attbi.com> On Tuesday 24 September 2002 12:37, Levy Lazarre wrote: > Good afternoon all, > > I have written a script that cleans an error log and > writes the output to a > new file. Basically, I read the file line by line, > apply various filters to > eliminate the trashy lines, and output the desired > lines to a new file via > print statements. I am having some difficulty with one > last task however. > I need to conditionally eliminate a header line > depending on what comes on > the next line. > Please see the sample below. When a line starts with > "Console Log" I need to > 'look ahead' and see if it is followed by a time stamp > hh:mm:ss. If so, > output it. If not suppress it. In the example > enclosed, I would want to output > the first "Console Log ..." line but ignore the second > one. > last_line =3D '' for line in lines: if line is console log line: last_line =3D line elif last_line and this line has valid time stamp: output last_line last_line =3D '' Now this code is missing some piece like 'line is console log line' needs= to=20 be implemented. But the idea should get you rolling. From steve_lewis@openiso.com Tue Sep 24 21:27:47 2002 From: steve_lewis@openiso.com (Steve Lewis) Date: Tue, 24 Sep 2002 15:27:47 -0500 (CDT) Subject: [Tutor] HTMLgen In-Reply-To: References: Message-ID: <1106.192.168.1.76.1032899267.squirrel@192.168.1.1> I have been trying to use HTMLgen. I have not been able to do anything with it. Does anybody have any links to how-tos that you have found to be good. Thanks, Steve Lewis > > I'd like to work with the HTMLgen package but I am encountering some > difficulties. (I hope) I succeeded with its installation - I ran > HTMLtest and the program generated most of the HTML files (I replaced > regex with re, and there was another I had to remove completely). I was > able to run a simple code at the C: prompt: > > C:\>python >>>> from HTMLgen import * >>>> p = Paragraph("bla, bla/n, bla") >>>> print p >

bla, bla > bla

> > But when I wanted to run the same test within IDLE I got: > >>>> from HTMLgen import * > Traceback (most recent call last): > File "", line 1, in ? > from HTMLgen import * > ImportError: No module named HTMLgen >>>> > > I suspect I have some kind of installation/setup problem, but I don't > know what the problem is. > > > I have another question regarding the use of HTMLgen. How can I insert > a simple text file to my HTML page? Open ti, readlines, write, but how? > > Thanks > > > _/_/ _/ _/ > _/ _/ _/ _/ > _/_/_/_/ _/_/ > _/ _/ _/ _/ > _/ _/ _/ _/ > > Andrzej > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From rob@zoism.org Wed Sep 25 00:42:14 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 25 Sep 2002 11:42:14 +1200 Subject: [Python-Help] Re: [Tutor] What would you say is the best way to continue learning python In-Reply-To: References: Message-ID: <1032910933.3480.37.camel@caspian.everglade> On Sun, 2002-09-22 at 12:48, Danny Yoo wrote: > Yes, I agree; learning by doing works, and it's my feeling that it's a lot > more effective if it's done with other people. In this sense, I believe > we learn any language more effectively through practice and exposure. It's pretty unanimous, pick a small application and make it. But please no more mp3 players or chat programmes ;o) I would suggest finding a small thing that you know something about, and that could be automated or what ever and make a programe that does this task for you. When it's done look around for another slightly more complicated task and repeat a few more times. -- * * Rob Brown-Bayliss * From pythonpython@hotmail.com Wed Sep 25 01:14:52 2002 From: pythonpython@hotmail.com (Hy Python) Date: Wed, 25 Sep 2002 00:14:52 +0000 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? Message-ID: Thanks a lot for your great reply, Gregor. However, I just could not find the method in setdefaultencoding() in when I imported the sys module. Do you have to do something special to make setdefaultencoding() show up in the sys. namespace? >>>import sys >>>dir(sys) ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__st din__', '__stdout__', '_getframe', 'argv', 'builtin_module_names', 'byteorder', 'copyright', 'displayhook', 'dllhandle', 'exc_info', 'exc_type', 'excepthook', ' exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getrecursionlimit', ' getrefcount', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'maxint ', 'maxunicode', 'modules', 'path', 'platform', 'prefix', 'ps1', 'ps2', 'setchec kinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 's tdout', 'version', 'version_info', 'warnoptions', 'winver'] >>> >From: Gregor Lingl >To: Hy Python >CC: tutor@python.org >Subject: Re: [Tutor] How to display non-ascii charaters on tkinter-made >GUIs? >Date: Tue, 24 Sep 2002 21:56:56 +0200 > >Hy Python schrieb: > >>Could you please tell me if it's possible to display non-ascii charaters >>on tkinter-made GUIs? >> >>Can interfaces made with tkinter display non-ascii charaters? > >I have the following code in my sitecustomize.py > >import sys, locale >loc = locale.getdefaultlocale() >if loc[1]: > encoding = loc[1] >if encoding != "ascii": > sys.setdefaultencoding(encoding) > >And on my machine the following works: > >t = "32 " + unichr(0x20ac) >from Tkinter import * >root = Tk() >Label(root, text=t).pack() >mainloop() > >Gregor > > >> >>Can tkinter display the 650,00+ unicode characters? >>Is there a way to set default system encoding to something other than >>ascii? >>(sys module has a getdefaultencoding() method, but there is no >>setdefaultdencoding() method.) >> >>Thanks a lot. >> >>Hy >> >>_________________________________________________________________ >>MSN Photos is the easiest way to share and print your photos: >>http://photos.msn.com/support/worldwide.aspx >> >> >>_______________________________________________ >>Tutor maillist - Tutor@python.org >>http://mail.python.org/mailman/listinfo/tutor >> >> > > > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx From wilson@visi.com Wed Sep 25 02:11:18 2002 From: wilson@visi.com (Tim Wilson) Date: Tue, 24 Sep 2002 20:11:18 -0500 Subject: [Tutor] complex file parsing Message-ID: <20020925011118.GA26676@isis.visi.com> Hi everyone, I'm wondering if some of the experts on this list have some advise regarding more complex parsing of files. Here's the scenario: I'm a Ph.D. student in eduation, specifically Instructional Systems and Technology. I'm taking a class right now where we are supposed to survey the literature in our field and find trends, summarize what sort of work is being done, etc. Being a geek I naturally gravitate toward automation for tasks like this. :-) I do the searches in a large database of education-related articles called ERIC (see http://www.askeric.org/ for an example of one interface to the database). I can export the results of my search to a format compatible with EndNote (http://www.endnote.com/). I'm going to include a snippet of the resulting file below. What I'd like to know is if there's a decent chance of creating a parser that can pull out the data from this record. I'm particularly interested in the Descriptor field which consists of one or more major descriptors and one or more minor descriptors. Of course, separating all the useful bits would be handy. I wonder if this would be an application where creating an XML file would be useful? Anyway, here's the file. I'd love to get some comments from everyone here. -Tim Database: ERIC Ownership: FirstSearch indicates your institution subscribes to this publication. Libraries that Own Item: 149Connect to the catalog at University of Minnesota Libraries Accession No: EJ646012 Author(s): Kumar, David D. ; Altschuld James W. Title: Complementary Approaches to Evaluation of Technology in Science Education. Source: Journal of Science Education and Technology v11 n2 p179-191 Jun 2002 Standard No: ISSN: 1059-0145 Clearinghouse: SE566729 Language: English Abstract: Discusses an interesting and relevant case involving two distinct systematic evaluations, traditional as well as somewhat nontraditional, of a science teacher education project with a heavy technology emphasis. Reports the complexity of evaluating technology projects and the multifaceted ways in which the evaluation endeavor could be approached. (Contains 23 references.) (Author/YDS) SUBJECT(S) Descriptor: (Major): Educational Technology Evaluation Methods Teacher Education (Minor): Higher Education Science Education Science Teachers Document Type: Journal Article (CIJE) Record Type: 080 Journal Articles; 143 Reports--Research Announcement: CIJSEP2002 Provider: OCLC Database: ERIC --------------------------------------------------------------------------------+-------------------------------------------------------------------------------+----------------------------------------- Ownership: FirstSearch indicates your institution subscribes to this publication. Libraries that Own Item: 149Connect to the catalog at University of Minnesota Libraries Accession No: EJ646006 Author(s): Marbach-Ad, Gili ; Sokolove, Phillip G. Title: The Use of E-Mail and In-Class Writing To Facilitate Student-Instructor Interaction in Large-Enrollment Traditional and Active Learning Classes. Source: Journal of Science Education and Technology v11 n2 p109-119 Jun 2002 Standard No: ISSN: 1059-0145 Clearinghouse: SE566723 Language: English -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | | http://linux.com From glingl@aon.at Wed Sep 25 02:20:10 2002 From: glingl@aon.at (Gregor Lingl) Date: Wed, 25 Sep 2002 03:20:10 +0200 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? References: Message-ID: <3D910F4A.2080104@aon.at> Hy Python schrieb: > Thanks a lot for your great reply, Gregor. > > However, I just could not find the method in setdefaultencoding() in > when I imported the sys module. Do you have to do something special to > make setdefaultencoding() show up in the sys. namespace? I thought, I had sent you the link to the documentation, didn't I? Yes there is! See: http://www.python.org/doc/current/lib/module-sys.html#l2h-264 The documentation for setdefaultencoding consists of approx. three lines. I think you would only have to read them thoroughly. Regards, Gregor From pythonpython@hotmail.com Wed Sep 25 03:12:37 2002 From: pythonpython@hotmail.com (Hy Python) Date: Wed, 25 Sep 2002 02:12:37 +0000 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? Message-ID: Thanks a lot for your fast reply, Gregor. I have read the documentation you sent to me the first time. But it's not clear to me that what are steps I need to take. Does this (http://www.python.org/doc/current/lib/module-sys.html#l2h-264) mean that I have go into site.py and modify the setdefaultencoding section? Is there a way round this? Your help is appreciated. Hy >From: Gregor Lingl >To: Hy Python >CC: tutor@python.org >Subject: Re: [Tutor] How to display non-ascii charaters on tkinter-made >GUIs? >Date: Wed, 25 Sep 2002 03:20:10 +0200 > >Hy Python schrieb: > >>Thanks a lot for your great reply, Gregor. >> >>However, I just could not find the method in setdefaultencoding() in when >>I imported the sys module. Do you have to do something special to make >>setdefaultencoding() show up in the sys. namespace? > > >I thought, I had sent you the link to the documentation, didn't I? > >Yes there is! See: >http://www.python.org/doc/current/lib/module-sys.html#l2h-264 > >The documentation for setdefaultencoding consists of approx. three lines. >I think you would only have to read them thoroughly. > >Regards, >Gregor > > > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com From rob@uselesspython.com Wed Sep 25 04:16:30 2002 From: rob@uselesspython.com (Rob) Date: Tue, 24 Sep 2002 22:16:30 -0500 Subject: [Python-Help] Re: [Tutor] What would you say is the best wayto continue learning python In-Reply-To: <1032910933.3480.37.camel@caspian.everglade> Message-ID: When in doubt, hit http://uselesspython.com and poke around for ideas. Rob > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Rob Brown-Bayliss > Sent: Tuesday, September 24, 2002 6:42 PM > To: Danny Yoo > Cc: Magnus Lycka; Gregor Lingl; danny@i4.net; Tutor > Subject: Re: [Python-Help] Re: [Tutor] What would you say is the best > wayto continue learning python > > > On Sun, 2002-09-22 at 12:48, Danny Yoo wrote: > > > Yes, I agree; learning by doing works, and it's my feeling that > it's a lot > > more effective if it's done with other people. In this sense, I believe > > we learn any language more effectively through practice and exposure. > > It's pretty unanimous, pick a small application and make it. But please > no more mp3 players or chat programmes ;o) > > I would suggest finding a small thing that you know something about, and > that could be automated or what ever and make a programe that does this > task for you. When it's done look around for another slightly more > complicated task and repeat a few more times. > > > -- > > * > * Rob Brown-Bayliss > * > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From lbrannma@cablespeed.com Wed Sep 25 05:59:45 2002 From: lbrannma@cablespeed.com (Lance) Date: Tue, 24 Sep 2002 21:59:45 -0700 Subject: [Tutor] Outlook Express Message-ID: <001801c26450$5dd18a50$3212eb42@MYNEWBOX> This is a multi-part message in MIME format. ------=_NextPart_000_0015_01C26415.B1542DD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi All, Many thanks for the informative posts. I want to create a folder in = Outlook Express for the Tutor messages. My message rule says look for = Tutor in the subject line and move the success to a Tutor folder. = However, I cannot find Tutor. Apparently the mailer inserts it.. and = Outlook Express can't find it. Any suggestions? Thanks. Lance ------=_NextPart_000_0015_01C26415.B1542DD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi All,
 
Many thanks for the informative posts. = I want to=20 create a folder in Outlook Express for the Tutor messages. My message = rule says=20 look for Tutor in the subject line and move the success to a Tutor = folder.=20 However, I cannot find Tutor. Apparently the mailer inserts it.. and = Outlook=20 Express can't find it.
 
Any suggestions?
 
Thanks.
Lance
------=_NextPart_000_0015_01C26415.B1542DD0-- From allyn.@tardigrade.net Wed Sep 25 08:08:20 2002 From: allyn.@tardigrade.net (Allyn Weaks) Date: Wed, 25 Sep 2002 00:08:20 -0700 Subject: [Tutor] Outlook Express In-Reply-To: <001801c26450$5dd18a50$3212eb42@MYNEWBOX> References: <001801c26450$5dd18a50$3212eb42@MYNEWBOX> Message-ID: On 24/9/02, Lance wrote: > Many thanks for the informative posts. I want to create a folder > in Outlook Express for the Tutor messages. My message rule says look > for Tutor in the subject line and move the success to a Tutor folder. A lot of mail clients seem to completely ignore anything in square brackets, which is irritating. But for filtering mailing lists, it's best to use the Sender: line anyway if possible, i.e. Sender: tutor-admin@python.org Search for the complete address in your filter, not part of it. Sender is the best bet because it's rarely forged, and indicates where the message is actually coming from. This list does include a Sender line, so you're home free. For lists that don't have one (unusual, but it happens) examine the headers for other header lines that are always present, are unique to the list, and are unlikely to occur by accident. For Tutor, a few possibilites would be: Errors-To: tutor-admin@python.org List-Post: and maybe X-BeenThere: tutor@python.org One might be tempted to use the To: line, but that will generate false positives. If someone replies to your post with both the list address and your address in To:, both will end up in the list folder. The Subject line is generally the least useful choice because it has nothing to do with origin. Anyone can put anything they want in the Subject and they do. Viruses/worms frequently use subject lines that they find lying around in mailboxes. -- Allyn Weaks allyn@tardigrade.net Seattle, WA Sunset zone 5 Pacific NW Native Wildlife Gardening: http://www.tardigrade.org/natives/ "The benefit of even limited monopolies is too doubtful, to be opposed to that of their general suppression." Thomas Jefferson From glingl@aon.at Wed Sep 25 09:45:31 2002 From: glingl@aon.at (Gregor Lingl) Date: Wed, 25 Sep 2002 10:45:31 +0200 Subject: [Tutor] How to display non-ascii charaters on tkinter-made GUIs? References: Message-ID: <3D9177AB.80005@aon.at> This is a multi-part message in MIME format. --------------070600090508060204070709 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hy Python schrieb: > Thanks a lot for your fast reply, Gregor. > > I have read the documentation you sent to me the first time. But it's > not clear to me that what are steps I need to take. Did you try to put the attached module sitecustomize.py into the --Python2?-\Lib - Directory. (Where site.py also lives) It was this what solved my problems. You may put additional statements of whatever sort into this module to customize your Python-installation for your needs. Gregor > > Does this > (http://www.python.org/doc/current/lib/module-sys.html#l2h-264) mean > that I have go into site.py and modify the setdefaultencoding section? > Is there a way round this? > > > Your help is appreciated. > > Hy --------------070600090508060204070709 Content-Type: text/plain; name="sitecustomize.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sitecustomize.py" import sys, locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if encoding != "ascii": sys.setdefaultencoding(encoding) --------------070600090508060204070709-- From karthik@james.hut.fi Wed Sep 25 11:27:49 2002 From: karthik@james.hut.fi (Karthikesh Raju) Date: Wed, 25 Sep 2002 13:27:49 +0300 Subject: [Tutor] First Serious Num-Python Prog. In-Reply-To: <20020925010201.31744.39071.Mailman@mail.python.org> 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. ---2098615039-2145140557-1032949669=:814238 Content-Type: TEXT/PLAIN; charset=US-ASCII Hi All, The following is my first serious python program. This does LS based estimation. i havent commented it but i was filled with enthu that i wanted to get the comments of people on how better i could do and the means and methods to imporve this. (Please leave the comments and the synthetic ones). Hoping to get a lot of improvement suggestions, Best regards karthik ---2098615039-2145140557-1032949669=:814238 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="ls.py" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="ls.py" ZnJvbSBOdW1lcmljIGltcG9ydCAqDQpmcm9tIFJhbmRvbUFycmF5IGltcG9y dCAqDQpmcm9tIExpbmVhckFsZ2VicmEgaW1wb3J0ICoNCmltcG9ydCBiaWdn bGVzDQoNCiMgZ2VuZXJhdGUgdGhlIHNpZ25hbA0KDQppID0gaW5kaWNlcyA9 IGFyYW5nZSgxLDE2MikNCnggPSAtOCArIChpLTEpLzEwLjANCg0KYTAgPSAw DQphMSA9IC0xMDANCmEyID0gMA0KYTMgPSAxDQoNCnogPSBhMCArIGExKngg KyBhMip4KioyICsgYTMqeCoqMw0KDQojIGdlbmVyYXRlIE5vc2llDQoNClNp Z21hID0gc3FydCgxMCkNCnYgPSBub3JtYWwoMCxTaWdtYSwxNjEpDQoNCiMg Z2VuZXJhdGUgTm9pc3kgU2lnbmFsDQp5ID0geiArIHYNCg0KIyBnZW5lcmF0 ZSBzaWduYWwgd2l0aCBvdXRsaWVycw0KcmVwbGFjZSA9IHJhbmRpbnQoMSwx NjEsMTcpDQoNCmZvciBpbmQgaW4gcmFuZ2UoMTcpOg0KICAgIHlbcmVwbGFj ZVtpbmRdXSA9IHJhbmRvbSgpKjQwMA0KDQoNCiMgR2VuZXJhdGUgSA0KDQpI ID0gemVyb3MoKDE2MSw0KSwnZmxvYXQnKTsNCmZvciBpbmQgaW4gcmFuZ2Uo MTYxKToNCiAgICBIW2luZF0gPSBbMSwgeFtpbmRdLCB4W2luZF0qKjIsIHhb aW5kXSoqM10NCg0KZGVmIHBpbnYoSCk6DQogICAgUiA9IG1hdHJpeG11bHRp cGx5KGludmVyc2UobWF0cml4bXVsdGlwbHkodHJhbnNwb3NlKEgpLEgpKSx0 cmFuc3Bvc2UoSCkpDQogICAgcmV0dXJuIFINCg0KcEggPSBwaW52KEgpDQoN CnRMUyA9IG1hdHJpeG11bHRpcGx5KHBILHRyYW5zcG9zZSh5KSk7DQp5SGF0 TFMgPSB0TFNbMF0rIHRMU1sxXSp4ICsgdExTWzJdKngqKjIgKyB0TFNbM10q eCoqMw0KDQoNCmRlZiBhbmRyZXdTaW5lKGVzdEVycm9yKToNCiAgICBzaWdt YSA9IHNxcnQoMTApDQogICAgYSA9IDMqc2lnbWEvcGkNCg0KICAgIGlmIGFi cyhlc3RFcnJvcikgPD0gYSpwaToNCiAgICAgICAgcHNpID0gc2luKGVzdEVy cm9yL2EpL2VzdEVycm9yDQogICAgZWxzZToNCiAgICAgICAgcHNpID0gMC4w DQogICAgcmV0dXJuIHBzaQ0KDQojIGJ5IE0tZXN0aW1hdGlvbg0KDQojIFdl aWdodCBtYXRyaXgNCg0KVyA9IGlkZW50aXR5KDE2MSwnZmxvYXQnKQ0KDQpV ID0gbWF0cml4bXVsdGlwbHkoaW52ZXJzZShtYXRyaXhtdWx0aXBseShtYXRy aXhtdWx0aXBseSh0cmFuc3Bvc2UoSCksVyksSCkpLHRyYW5zcG9zZShIKSkN CnRoZXRhSGF0ID0gbWF0cml4bXVsdGlwbHkobWF0cml4bXVsdGlwbHkoVSxX KSx0cmFuc3Bvc2UoeSkpDQoNCnlIYXQgPSB0aGV0YUhhdFswXSArIHRoZXRh SGF0WzFdKnggKyB0aGV0YUhhdFsyXSp4KioyICsgdGhldGFIYXRbM10qeCoq Mw0KZXN0RXJyb3IgPSAoeS15SGF0KQ0KDQpzdW1PZkVycm9ycyA9IHN1bShh YnMoZXN0RXJyb3IpKQ0KaiA9IDANCnRvdGFsRXJyb3JzID0gW10NCg0KIyB1 cGRhdGUgbWF0cml4DQp3aGlsZSBzdW1PZkVycm9ycyA+IDFlLTg6DQogICAg Zm9yIGluZCBpbiByYW5nZSgxNjEpOg0KICAgICAgICBXW2luZCxpbmRdID0g YW5kcmV3U2luZShlc3RFcnJvcltpbmRdL1NpZ21hKQ0KICAgICAgICANCiAg ICBVID0gbWF0cml4bXVsdGlwbHkoaW52ZXJzZShtYXRyaXhtdWx0aXBseSht YXRyaXhtdWx0aXBseSh0cmFuc3Bvc2UoSCksVyksSCkpLHRyYW5zcG9zZShI KSkNCiAgICB0aGV0YUhhdCA9IG1hdHJpeG11bHRpcGx5KG1hdHJpeG11bHRp cGx5KFUsVyksdHJhbnNwb3NlKHkpKQ0KDQogICAgeUhhdCA9IHRoZXRhSGF0 WzBdICsgdGhldGFIYXRbMV0qeCArIHRoZXRhSGF0WzJdKngqKjIgKyB0aGV0 YUhhdFszXSp4KiozDQogICAgZXN0RXJyb3IgPSAoeS15SGF0KQ0KICAgIHRv dGFsRXJyb3JzLmluc2VydChqLHN1bShhYnMoZXN0RXJyb3IpKSkNCg0KICAg IGlmIGogPj0gMToNCiAgICAgICAgc3VtT2ZFcnJvcnMgPSBhYnMoKHRvdGFs RXJyb3JzW2pdIC0gdG90YWxFcnJvcnNbai0xXSkvdG90YWxFcnJvcnNbal0p DQogICAgICAgIA0KICAgIHByaW50ICctJyozMA0KICAgIHByaW50ICcnDQog ICAgcHJpbnQgJ0l0ZXJhdGlvbiAjLi4uLi4uLi4uLi4uLi4uJyxqKzENCiAg ICBwcmludCAnRXJyb3JzICAgIC4uLi4uLi4uLi4uLi4uLi4nLCBzdW1PZkVy cm9ycw0KICAgIHByaW50ICdBbHBoYSAgLi4uLi4uLi4uLi4uLi4uLi4uLicN CiAgICBwcmludCB0aGV0YUhhdA0KICAgIHByaW50ICcnDQogICAgcHJpbnQg Jy0nKjMwDQogICAgaiA9IGorMQ0KDQoNCg0KDQojIHBsb3R0aW5nIHJvdXRp bmVzDQoNCnAgPSBiaWdnbGVzLkZyYW1lZFBsb3QoKQ0KcC5mcmFtZTEuZHJh d19ncmlkID0gMQ0KcC5mcmFtZTEudGlja2RpciA9IDANCnAuZnJhbWUyLmRy YXdfZ3JpZCA9IDENCnAuYWRkKCBiaWdnbGVzLkN1cnZlKHgseSxjb2xvcj0n Ymx1ZScpKQ0KcC5hZGQoIGJpZ2dsZXMuQ3VydmUoeCx5SGF0TFMsIGNvbG9y PSdncmVlbicpKQ0KcC5hZGQoIGJpZ2dsZXMuQ3VydmUoeCx5SGF0LCBjb2xv cj0ncmVkJykpDQpwLndyaXRlX2VwcygiY3VydmVzLmVwcyIpDQpwLnNob3co KQ0KDQpxID0gYmlnZ2xlcy5GcmFtZWRQbG90KCkNCnEueHJhbmdlID0gMCwx NjENCnEueXJhbmdlID0gMCwxDQpxLmFzcGVjdF9yYXRpbyA9IDENCmEgPSBi aWdnbGVzLlBvaW50cyhpbmRpY2VzLEMsdHlwZT0nY2lyY2xlJykNCnEuYWRk KGEpDQpxLndyaXRlX2Vwcygid2VpZ2h0cy5lcHMiKQ0KcS5zaG93KCkNCg== ---2098615039-2145140557-1032949669=:814238-- From lsloan@umich.edu Wed Sep 25 11:38:17 2002 From: lsloan@umich.edu (Lance E Sloan) Date: Wed, 25 Sep 2002 06:38:17 -0400 Subject: [Tutor] HTMLgen In-Reply-To: References: Message-ID: <608069.1032935897@[192.168.2.201]> --On Tuesday, September 24, 2002 11:59 -0400 Andrzej Kolinski wrote: > C:\>python >>>> from HTMLgen import * >>>> p = Paragraph("bla, bla/n, bla") >>>> print p >

bla, bla > bla

> > But when I wanted to run the same test within IDLE I got: > >>>> from HTMLgen import * > Traceback (most recent call last): > File "", line 1, in ? > from HTMLgen import * > ImportError: No module named HTMLgen >>>> > > I suspect I have some kind of installation/setup problem, but I don't know > what the problem is. I haven't used IDLE very much, so I'm not sure about this, but I would guess that your path (in sys.path) isn't set up correctly. I bet that when you ran your program in the interpreter, HTMLgen was in your current directory, but when you were running IDLE, the current directory became the directory where IDLE is installed. I think you could solve the problem like this: import sys sys.path.append('c:/path/to/HTMLgen/here') Followed by the rest of your program. Of course, fill in the correct path instead of using my example. You could also add that path to Python's default sys.path. You can edit one of the Python config files (I forget which) and I think you can also set an environment variable to do the same thing. I'd also like to say that I recommend against putting HTML or HTML-generating code in programs. I write CGIs for a living and at my organization, we always put HTML in template files, separate from the programs. We had modules for doing this in Perl and when I introduced Python into our mix, I had to find something similar. At first, I came up with my own solution. Read lines from a file and replace values using %-substitution: def fillTemplate(filename = None, varDict = vars()): """Read a template from the specified file and using the string formatting operator (%), fill blanks in the template (e.g. %()s) with values from the specified dictionary.""" if (filename == None) or (varDict == None): raise "filename and variable dictionary required" fo = open(filename, 'r') tmpl = fo.read() % varDict fo.close() return tmpl So if I have a template file that contains: %(title)s %(message)s and I call fillTemplate like this: fillTemplate('templatefilename', {'title': 'Hello', message: 'World'}) I get: Hello World That function is one of the first I wrote in Python, so it could probably use some fixing, but in general it's a working idea. Later I learned about Zope's DocumentTemplate module. It's quite complex, but for my projects, it was what I needed. I just downloaded Zope and pried DocumentTemplate out of it and it has worked well for me. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From erikprice@mac.com Wed Sep 25 12:10:52 2002 From: erikprice@mac.com (Erik Price) Date: Wed, 25 Sep 2002 07:10:52 -0400 Subject: [Tutor] Outlook Express In-Reply-To: Message-ID: <745A5411-D077-11D6-ACA7-00039351FE6A@mac.com> On Wednesday, September 25, 2002, at 03:08 AM, Allyn Weaks wrote: > Sender is the best bet because it's rarely forged, and indicates where > the message is actually coming from. This list does include a Sender > line, so you're home free. For lists that don't have one (unusual, but > it happens) examine the headers for other header lines that are always > present, are unique to the list, and are unlikely to occur by accident. In theory, the "List-ID" header is designed for this very purpose (I think). Unfortunately, certain mail clients (I think older ones) don't faithfully reproduce the header, so once in a while a message that was filtered by List-ID ends up in my main Inbox. For Python Tutor, I have a rule that filters based on the presence of the string tutor.python.org in the List-ID header. It works most of the time. Erik -- Erik Price (zombies roam) email: erikprice@mac.com jabber: erikprice@jabber.org From marta_andrea@libero.it Wed Sep 25 12:39:02 2002 From: marta_andrea@libero.it (Andrea Valle) Date: Wed, 25 Sep 2002 13:39:02 +0200 Subject: [Tutor] an error on recursion depth Message-ID: Hi list, my program stops with this: RuntimeError: maximum recursion depth exceeded Why? I used the program in Python 1.5.2.: never happened. I think I alrea= dy used it also for exactly the same task (same parameters, same complexity) also in 2.1. It's the first time it breaks. How can I avoid it? thank you -a- tutor-admin@python.org PS:(down I attach the whole final part: the fisrt line is repeat alot of times and then you have the ending part) File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in percorri_a= rco tre_punti=3Dgrafista0.tre_punti(perc, vel, dur) File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti print spazio File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write self.shell.write(s, self.tags) File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write OutputWindow.write(self, s, tags, "iomark") File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in writ= e self.text.insert(mark, s, tags) File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in insert self.top.insert(index, chars, tags) File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in insert UndoDelegator.insert(self, index, chars, tags) File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in ins= ert self.addcmd(InsertCommand(index, chars, tags)) File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in addcmd cmd.do(self.delegate) File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in do text.insert(self.index1, self.chars, self.tags) File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in insert self.notify_range(index, index + "+%dc" % len(chars)) File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in notify_range self.after_id =3D self.after(1, self.recolorize) File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after name =3D self._register(callit) File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in _register f =3D CallWrapper(func, subst, self).__call__ RuntimeError: maximum recursion depth exceeded Andrea Valle via Lanzo 108 10073 - Ciri=E8 (TO) ITALIA 011/921 45 84 - 349/55 47 343 From magnus@thinkware.se Wed Sep 25 13:02:48 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 25 Sep 2002 14:02:48 +0200 Subject: [Tutor] complex file parsing In-Reply-To: <20020925011118.GA26676@isis.visi.com> Message-ID: <5.1.0.14.0.20020925131842.02b6f6e8@www.thinkware.se> At 20:11 2002-09-24 -0500, Tim Wilson wrote: >What I'd like to know is if there's a decent chance of creating a parser >that can pull out the data from this record. I'm particularly interested >in the Descriptor field which consists of one or more major descriptors >and one or more minor descriptors. Of course, separating all the useful >bits would be handy. I wonder if this would be an application where >creating an XML file would be useful? Doesn't seem to be very difficult, does it? I'm not absolutely sure that the file came through to us the way it looked in the original though. Are there really line breaks in the data fields? Unless we know the names of all headers, we would have trouble with lines like: ''' publication. Libraries that Own Item: 149Connect to the catalog at ''' How do we know that "publication. Libraries that Own Item" isn't a field heading, like "Author(s)". And what if the title would be: Title: Going back to the Source: Remebering our ancestry. or something like that... How would we know that the second line of the Title data wasn't the Source field? I'd say the format is broken if it looks like in your mail. Not even whitespace in the beginning of continuation lines? But never mind, we can still do things: import re author_title =3D= re.compile(r'Author\(s\):\s*(.+?)\nTitle:\s*(.+?)\nSource:', re.DOTALL) for record in author_title.findall(text): print "Author: %s\nTitle: %s\n\n" % record Assuming that the text is in the variable "text", those lines will print all Authors and Titles. For Descriptors, you might have to solve it in two steps. If (as I suspect) the data fields are actually one long line, it's really very simple. You won't even need the re module. # N.B. Untested code follows. #First, read all your data as a long string. all_data =3D open('whatever','rt').read() #Then split on record breaks rb =3D=20 "---------------------------------------------------------------------------= -----+----------------------------------------------------------------------= ---------+-----------------------------------------" records =3D all_data.split(rb) # Put the stuff in a list of dicts l =3D [] for record in records: d =3D {} for line in record.split('\n'): key, value =3D line.split(':',1) d[key.strip()] =3D value.strip() l.append(d) >Database: ERIC > > >Ownership: FirstSearch indicates your institution subscribes to this >publication. Libraries that Own Item: 149Connect to the catalog at >University of Minnesota Libraries >Accession No: EJ646012 >Author(s): Kumar, David D. ; Altschuld James W. >Title: Complementary Approaches to Evaluation of Technology in >Science Education. >Source: Journal of Science Education and Technology v11 n2 >p179-191 Jun 2002 >Standard No: ISSN: 1059-0145 >Clearinghouse: SE566729 >Language: English >Abstract: Discusses an interesting and relevant case involving two >distinct systematic evaluations, traditional as well as somewhat >nontraditional, of a science teacher education project with a >heavy technology emphasis. Reports the complexity of evaluating >technology projects and the multifaceted ways in which the evaluation >endeavor could be approached. (Contains 23 references.) >(Author/YDS) >SUBJECT(S) >Descriptor: (Major): Educational Technology >Evaluation Methods >Teacher Education >(Minor): Higher Education >Science Education >Science Teachers >Document Type: Journal Article (CIJE) >Record Type: 080 Journal Articles; 143 Reports--Research >Announcement: CIJSEP2002 >Provider: OCLC >Database: ERIC >---------------------------------------------------------------------------= -----+----------------------------------------------------------------------= ---------+----------------------------------------- > >Ownership: FirstSearch indicates your institution subscribes to this >publication. Libraries that Own Item: 149Connect to the catalog at >University of Minnesota Libraries >Accession No: EJ646006 >Author(s): Marbach-Ad, Gili ; Sokolove, Phillip G. >Title: The Use of E-Mail and In-Class Writing To Facilitate >Student-Instructor Interaction in Large-Enrollment Traditional and >Active Learning Classes. >Source: Journal of Science Education and Technology v11 n2 >p109-119 Jun 2002 >Standard No: ISSN: 1059-0145 >Clearinghouse: SE566723 >Language: English --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Wed Sep 25 13:19:46 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 25 Sep 2002 14:19:46 +0200 Subject: [Tutor] an error on recursion depth In-Reply-To: Message-ID: <5.1.0.14.0.20020925140957.0555f2d0@www.thinkware.se> At 13:39 2002-09-25 +0200, Andrea Valle wrote: >Hi list, >my program stops with this: > >RuntimeError: maximum recursion depth exceeded > >Why? I used the program in Python 1.5.2.: never happened. I think I already >used it also for exactly the same task (same parameters, same complexity) >also in 2.1. It's the first time it breaks. >How can I avoid it? Well, you can do import sys sys.setrecursionlimit(2000) to double the default value, but I doubt that you really want this deep recursion in Tkinter... I suspect that increasing the recursion limit will only make the bug appear a little slower... If you didn't change anything (can you go back to previous Python versions and verify that your code still works there?) I can only assume that something in Tkinter, Tk, or possibly in general Python changed in a way that bites you. It seems a piece of code calls itself in an infinite loop. Unless you figure it out I suggest that you try to strip down your code to the smallest possible size where it will still behave this way, and we can take a look at it. (It would probably be easier to help you if you didn't write your code in Italian...) >thank you > >-a- >tutor-admin@python.org > >PS:(down I attach the whole final part: the fisrt line is repeat alot of >times and then you have the ending part) > > >File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in= percorri_arco > tre_punti=3Dgrafista0.tre_punti(perc, vel, dur) > File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti > print spazio > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write > self.shell.write(s, self.tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write > OutputWindow.write(self, s, tags, "iomark") > File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in write > self.text.insert(mark, s, tags) > File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in insert > self.top.insert(index, chars, tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in insert > UndoDelegator.insert(self, index, chars, tags) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in= insert > self.addcmd(InsertCommand(index, chars, tags)) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in >addcmd > cmd.do(self.delegate) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in do > text.insert(self.index1, self.chars, self.tags) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in >insert > self.notify_range(index, index + "+%dc" % len(chars)) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in >notify_range > self.after_id =3D self.after(1, self.recolorize) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after > name =3D self._register(callit) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in _register > f =3D CallWrapper(func, subst, self).__call__ >RuntimeError: maximum recursion depth exceeded > >Andrea Valle >via Lanzo 108 >10073 - Ciri=E8 (TO) >ITALIA >011/921 45 84 - 349/55 47 343 > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From rob@uselesspython.com Wed Sep 25 13:56:09 2002 From: rob@uselesspython.com (Rob) Date: Wed, 25 Sep 2002 07:56:09 -0500 Subject: [Tutor] Outlook Express In-Reply-To: <001801c26450$5dd18a50$3212eb42@MYNEWBOX> Message-ID: Have you tried filtering for [Tutor] instead of for Tutor? I know that works in Outlook 2000, and seem to vaguely recall that it works in Outlook Express. Rob -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Lance Sent: Wednesday, September 25, 2002 12:00 AM To: Tutor Subject: [Tutor] Outlook Express Hi All, Many thanks for the informative posts. I want to create a folder in Outlook Express for the Tutor messages. My message rule says look for Tutor in the subject line and move the success to a Tutor folder. However, I cannot find Tutor. Apparently the mailer inserts it.. and Outlook Express can't find it. Any suggestions? Thanks. Lance From glingl@aon.at Wed Sep 25 14:45:52 2002 From: glingl@aon.at (Gregor Lingl) Date: Wed, 25 Sep 2002 15:45:52 +0200 Subject: [Tutor] an error on recursion depth References: Message-ID: <3D91BE10.80204@aon.at> Andrea Valle schrieb: >Hi list, >my program stops with this: > >RuntimeError: maximum recursion depth exceeded > >Why? I used the program in Python 1.5.2.: never happened. I think I already >used it also for exactly the same task (same parameters, same complexity) >also in 2.1. It's the first time it breaks. >How can I avoid it? > >thank you > > > Hi, Andrea! There are two functions in the sys-Module, to read and to set the recursion-limit. http://www.python.org/doc/current/lib/module-sys.html#l2h-252 So you can investigate, what your current limit is an if your program should exceed it. If so set a higher one. If not, something is wrong with the your program. One had to have a look at the sourc-code to find out what the problem is. Regards, Gregor >-a- >tutor-admin@python.org > >PS:(down I attach the whole final part: the fisrt line is repeat alot of >times and then you have the ending part) > > >File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in percorri_arco > tre_punti=grafista0.tre_punti(perc, vel, dur) > File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti > print spazio > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write > self.shell.write(s, self.tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write > OutputWindow.write(self, s, tags, "iomark") > File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in write > self.text.insert(mark, s, tags) > File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in insert > self.top.insert(index, chars, tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in insert > UndoDelegator.insert(self, index, chars, tags) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in insert > self.addcmd(InsertCommand(index, chars, tags)) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in >addcmd > cmd.do(self.delegate) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in do > text.insert(self.index1, self.chars, self.tags) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in >insert > self.notify_range(index, index + "+%dc" % len(chars)) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in >notify_range > self.after_id = self.after(1, self.recolorize) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after > name = self._register(callit) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in _register > f = CallWrapper(func, subst, self).__call__ >RuntimeError: maximum recursion depth exceeded > >Andrea Valle >via Lanzo 108 >10073 - Ciriè (TO) >ITALIA >011/921 45 84 - 349/55 47 343 > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > > From magnus@thinkware.se Wed Sep 25 15:08:02 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 25 Sep 2002 16:08:02 +0200 Subject: [Tutor] an error on recursion depth In-Reply-To: Message-ID: <5.1.0.14.0.20020925160650.02ad4d10@www.thinkware.se> At 13:39 2002-09-25 +0200, Andrea Valle wrote: >PS:(down I attach the whole final part: the fisrt line is repeat alot of >times and then you have the ending part) Actually, it's the repeating parts that you should investigate. Somewhere your code bites it's own tail and you need to figure out why. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From glingl@aon.at Wed Sep 25 15:03:56 2002 From: glingl@aon.at (Gregor Lingl) Date: Wed, 25 Sep 2002 16:03:56 +0200 Subject: [Tutor] an error on recursion depth References: <3D91BE10.80204@aon.at> Message-ID: <3D91C24C.4070506@aon.at> Sorry, I overlooked Magnus' posting, GL From =?ISO-8859-1?B?YW50b25tdWhpbiDt4CByYW1ibGVyLnJ1?= Wed Sep 25 16:15:09 2002 From: =?ISO-8859-1?B?YW50b25tdWhpbiDt4CByYW1ibGVyLnJ1?= (=?ISO-8859-1?B?YW50b25tdWhpbiDt4CByYW1ibGVyLnJ1?=) Date: Wed, 25 Sep 2002 19:15:09 +0400 Subject: [Tutor] Working with RTF In-Reply-To: <20020922160004.6947.22706.Mailman@mail.python.org> References: <20020922160004.6947.22706.Mailman@mail.python.org> Message-ID: <95034178.20020925191509@rambler.ru> Hello everybody! Does anyone know any Python module to deal with RTF files? Unicode processing is essentail too. I need a tool to read files and don't want to use OLE to process documents. Best regards, Anton. From marta_andrea@libero.it Wed Sep 25 17:39:35 2002 From: marta_andrea@libero.it (Andrea Valle) Date: Wed, 25 Sep 2002 18:39:35 +0200 Subject: R: [Tutor] an error on recursion depth In-Reply-To: <5.1.0.14.0.20020925140957.0555f2d0@www.thinkware.se> Message-ID: Thanks a lot, sirs. The occasion of the error discovery has led me to rethink (in a very simplier way) the code. So, I solved the problem simply avoiding (effectively, infinite) recursion. Much more elegant and practice. Thank you again to all for your kindness. -a- From dyoo@hkn.eecs.berkeley.edu Wed Sep 25 19:06:40 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 25 Sep 2002 11:06:40 -0700 (PDT) Subject: [Tutor] an error on recursion depth (fwd) Message-ID: Hi Marta, Do not send Python questions to 'tutor-admin@python.org'. That address only is meant for administrative stuff (subscription questions), and only reaches a paltry three people. You probably meant to send to tutor@python.org, so I'll forward the message to the mailing list for you. Best of wishes to you! ---------- Forwarded message ---------- Date: Wed, 25 Sep 2002 12:33:36 +0200 From: Andrea Valle To: tutor-admin@python.org Subject: an error on recursion depth Hi list, my program stops with this: RuntimeError: maximum recursion depth exceeded Why? I used the program in Python 1.5.2.: never happened. I think I already used it also for exactly the same task (same parameters, same complexity) also in 2.1. It's the first time it breaks. How can I avoid it? thank you -a- tutor-admin@python.org PS:(down I attach the whole final part: the fisrt line is repeat alot of times and then you have the ending part) File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in percorri_arc= o tre_punti=3Dgrafista0.tre_punti(perc, vel, dur) File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti print spazio File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write self.shell.write(s, self.tags) File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write OutputWindow.write(self, s, tags, "iomark") File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in write self.text.insert(mark, s, tags) File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in insert self.top.insert(index, chars, tags) File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in insert UndoDelegator.insert(self, index, chars, tags) File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in inser= t self.addcmd(InsertCommand(index, chars, tags)) File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in addcmd cmd.do(self.delegate) File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in do text.insert(self.index1, self.chars, self.tags) File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in insert self.notify_range(index, index + "+%dc" % len(chars)) File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in notify_range self.after_id =3D self.after(1, self.recolorize) File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after name =3D self._register(callit) File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in _register f =3D CallWrapper(func, subst, self).__call__ RuntimeError: maximum recursion depth exceeded Andrea Valle via Lanzo 108 10073 - Ciri=E8 (TO) ITALIA 011/921 45 84 - 349/55 47 343 From asoleyma@lightspeed.com Tue Sep 24 20:57:14 2002 From: asoleyma@lightspeed.com (Ali Soleymanzadeh) Date: Tue, 24 Sep 2002 12:57:14 -0700 Subject: [Tutor] Matching word, time Message-ID: <3D90C39A.90FFB647@lightspeed.com> Hi I have two line in my test log file, which are starting and ending time of my test as: Test Run By asoleyma on Tue Sep 24 12:33:47 2002 runtest completed at Tue Sep 24 12:33:48 2002 How can I calculate the time, in seconds, which my test was running? Note that I know how to use start = time.clock(), but I cannot use it and the only way to have time is getting from log file. Thanks, -Ali From lbrannma@yahoo.com Wed Sep 25 15:13:49 2002 From: lbrannma@yahoo.com (Lance B) Date: Wed, 25 Sep 2002 07:13:49 -0700 (PDT) Subject: [Tutor] Object design and Python Message-ID: <20020925141350.52510.qmail@web11508.mail.yahoo.com> Coding seems much easier in Python than other object oriented languages. One could argue that design therefore becomes relatively more important. Are there design discussions, books, papers, etc specifically targeted to Python? What are your favorite design books? Thanks, Lance __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com From shalehperry@attbi.com Wed Sep 25 19:54:32 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Wed, 25 Sep 2002 11:54:32 -0700 Subject: [Tutor] Matching word, time In-Reply-To: <3D90C39A.90FFB647@lightspeed.com> References: <3D90C39A.90FFB647@lightspeed.com> Message-ID: <200209251154.32572.shalehperry@attbi.com> On Tuesday 24 September 2002 12:57, Ali Soleymanzadeh wrote: > Hi > > I have two line in my test log file, which are starting and ending > time of my test as: > Test Run By asoleyma on Tue Sep 24 12:33:47 2002 > runtest completed at Tue Sep 24 12:33:48 2002 > > How can I calculate the time, in seconds, which my test was running? > Note that I know how to use start =3D time.clock(), but I cannot use > it and the only way to have time is getting from log file. > there is a handy python package called mxDateTime, search for it in the v= aults=20 of Parnasus. From shalehperry@attbi.com Wed Sep 25 19:59:56 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Wed, 25 Sep 2002 11:59:56 -0700 Subject: [Tutor] Object design and Python In-Reply-To: <20020925141350.52510.qmail@web11508.mail.yahoo.com> References: <20020925141350.52510.qmail@web11508.mail.yahoo.com> Message-ID: <200209251159.56172.shalehperry@attbi.com> On Wednesday 25 September 2002 07:13, Lance B wrote: > Coding seems much easier in Python than other object > oriented languages. One could argue that design > therefore becomes relatively more important. Are there > design discussions, books, papers, etc specifically > targeted to Python? What are your favorite design > books? > All of my fav books are language neutral. 'Design Patterns' ranks high w= hen=20 it comes to Python coding. Others will chime in I am sure. From steve@openiso.com Wed Sep 25 23:00:26 2002 From: steve@openiso.com (steve lewis) Date: Wed, 25 Sep 2002 17:00:26 -0500 (CDT) Subject: [Tutor] Re: recommended Editor...and more In-Reply-To: <20020925205545.GB3115@i92.ryd.student.liu.se> References: <002301c2635f$fc12ab00$3212eb42@MYNEWBOX> <20020924055632.GA1656@i92.ryd.student.liu.se> <1102.192.168.1.76.1032898903.squirrel@192.168.1.1> <20020925205545.GB3115@i92.ryd.student.liu.se> Message-ID: <3531.199.66.1.5.1032991226.squirrel@www.absolutenettech.com> Thanks Kalle, I appreciate your response. Also, I mistakenly did not reply to tuor list, but am cc:ing the list on this. Once again thanks. Kalle Svensson said: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > [Steve Lewis] >> It is nice to see so much reponse to this thread. This has helped me >> narrow down my efforts on learning an editor. > > Good. > >> I use both Linux and Windows to learn Python and prefer Linux. Vim has >> both win and lin versions, does Emacs? > > Yes. Both are available from the main distribution site > (http://www.gnu.org/software/emacs/). > > [more about portability] > I don't know much about developing software for Windows and Linux > simultaneously, since I don't use Windows. You might want to ask on > the mailing list. > > Peace, > Kalle > - -- > Kalle Svensson, http://www.juckapan.org/~kalle/ > Student, root and saint in the Church of Emacs. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.7 (GNU/Linux) > Comment: Processed by Mailcrypt 3.5.6 > > > iD8DBQE9kiLMdNeA1787sd0RArc7AKCIqBEtCvDo1CEgl+wZuWO3JSL7JQCeM+p5 > x0kPoB04uMV1YNa/oYitZ7Q= > =/ULP > -----END PGP SIGNATURE----- -- thanks, steve lewis usa "do or do not, there is no try." yoda From magnus@thinkware.se Wed Sep 25 23:50:14 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Thu, 26 Sep 2002 00:50:14 +0200 Subject: [Tutor] Matching word, time In-Reply-To: <200209251154.32572.shalehperry@attbi.com> References: <3D90C39A.90FFB647@lightspeed.com> <3D90C39A.90FFB647@lightspeed.com> Message-ID: <5.1.0.14.0.20020925234629.0555ef80@www.thinkware.se> At 11:54 2002-09-25 -0700, Sean 'Shaleh' Perry wrote: >On Tuesday 24 September 2002 12:57, Ali Soleymanzadeh wrote: > > Test Run By asoleyma on Tue Sep 24 12:33:47 2002 > > runtest completed at Tue Sep 24 12:33:48 2002 > > > > How can I calculate the time, in seconds, which my test was running? > >there is a handy python package called mxDateTime, search for it in the=20 >vaults >of Parnasus. You don't really need mxDateTime for this (although, in the long run it might well be worth having). On most unices, the time modules contains a time.strptime() method that will handle this. (The time module is just a thin wrapper on top of the C time library. There are strptime implementations in Python I think.) >>> import time >>> timestamp =3D "Tue Sep 24 12:33:48 2002" >>> format =3D "%a %b %d %H:%M:%S %Y" >>> print time.strptime(timestamp, format) (2002, 9, 24, 12, 33, 48, 1, 267, 0) Now you have a time tuple, and you can convert it to seconds since epoch and just subtract from another one. It's not so difficult to handle without strptime though... Use good old re: import re, time pattern =3D re.compile(r"""(?P.+?)#Whatever leading text (?P\w{3})\ #Day of Week 3 letters (?P\w{3})\ #Month 3 letters (?P\d{1,2})\ # Day of month 1-2 digits (?P\d{1,2}):# Hour (?P\d{1,2}):# Minutes (?P\d{1,2})\ # Seconds (?P\d{4})# Year 4 digits""",re.VERBOSE) data =3D """Test Run By asoleyma on Tue Sep 24 12:33:47 2002 runtest complete at Tue Sep 24 12:33:48 2002""".split('\n') months =3D 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split() days =3D 'Mon Tue Wed Thu Fri Sat Sun'.split() lastTime =3D 0 for line in data: match =3D pattern.search(line) if not match: print "Could not analyze:", line continue d =3D match.groupdict() print d['comment'], ttuple =3D (int(d['year']), months.index(d['month'])+1, int(d['day']), int(d['hour']), int(d['min']), int(d['sec']), days.index(d['dow']), 0, 0) print time.asctime(ttuple), newTime =3D time.mktime(ttuple) if lastTime: print "Duration =3D %i seconds" % (newTime-lastTime), print lastTime =3D newTime Test Run By asoleyma on Tue Sep 24 12:33:47 2002 runtest complete at Tue Sep 24 12:33:48 2002 Duration =3D 1 seconds I'm cheating a bit with time zones etc... With mxDateTime >>> from mx import DateTime >>> print DateTime.DateTimeFrom("Tue Sep 24 12:33:48 2002") 2002-09-24 12:33:48.00 >>> # But be aware, bad times are silently accepted or ignored... >>> print DateTime.DateTimeFrom("Tue Sep 2344 12:33:48 211002") 2021-10-02 12:33:48.00 >>> print DateTime.DateTimeFrom("Tue Slept 2344 12:33:48 211002") 2021-10-02 12:33:48.00 >>> print DateTime.DateTimeFrom("Tue Slept 24 12:33:48 211002") 2021-10-02 12:33:48.00 >>> print DateTime.DateTimeFrom("Tue Slept 24 12:33:48 2002") 2002-09-26 12:33:48.00 --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Wed Sep 25 23:59:59 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Thu, 26 Sep 2002 00:59:59 +0200 Subject: [Tutor] [tutor]Newby!!!! In-Reply-To: Message-ID: <5.1.0.14.0.20020926005409.05572338@www.thinkware.se> Please correct your date setting (year 2001 passed), your mail ends up in the wrong end of our lists... At 12:33 2001-09-24 +0100, carlos sousa wrote: >hello to everyone >this my first program using python. >I am building a webpage, and I use python to manipulate a Postgresql= database. >My problem is that i would like create a function similar in functionality= =20 >to the HTML "checkbox" in witch the number of check inputs is variable=20 >(the number of check inputs depends from a parameter 'names' witch=20 >contains a list of names). I think you need to supply some code to let us understand exactly what you are after here. There are many ways to build webpages from Python. See http://www.python.org/cgi-bin/moinmoin/WebProgramming and http://starship.python.net/crew/friedrich/HTMLgen/html/main.html for a few... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From linux1011@HotPOP.com Thu Sep 26 00:02:39 2002 From: linux1011@HotPOP.com (David Mccowan) Date: Wed, 25 Sep 2002 18:02:39 -0500 Subject: [Tutor] an error on recursion depth (fwd) In-Reply-To: References: Message-ID: <20020925180239.41fc5068.linux1011@HotPOP.com> On Wed, 25 Sep 2002 11:06:40 -0700 (PDT) Danny Yoo wrote: I had this same problem in a program I was writing, my solution was to use a loop instead. I not only noticed that it worked but ran much faster. Most recursive functions can be written as loops and vice versa just by keeping track of the variable manually. A good example of this exists in Structure and Interpretation of Computer Programs, although the book uses scheme its concepts can easily be applied to most high level programming languanges http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.1 In a addition to this section the entire book is online at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start > Date: Wed, 25 Sep 2002 12:33:36 +0200 > From: Andrea Valle > To: tutor-admin@python.org > Subject: an error on recursion depth > > Hi list, > my program stops with this: > > RuntimeError: maximum recursion depth exceeded > > Why? I used the program in Python 1.5.2.: never happened. I think I > already used it also for exactly the same task (same parameters, same > complexity) also in 2.1. It's the first time it breaks. > How can I avoid it? > > thank you > > -a- > tutor-admin@python.org > > PS:(down I attach the whole final part: the fisrt line is repeat alot > of times and then you have the ending part) > > > File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in > percorri_arco > tre_punti=grafista0.tre_punti(perc, vel, dur) > File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti > print spazio > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write > self.shell.write(s, self.tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write > OutputWindow.write(self, s, tags, "iomark") > File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in > write > self.text.insert(mark, s, tags) > File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in > insert > self.top.insert(index, chars, tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in > insert > UndoDelegator.insert(self, index, chars, tags) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in > insert > self.addcmd(InsertCommand(index, chars, tags)) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in > addcmd > cmd.do(self.delegate) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in > do > text.insert(self.index1, self.chars, self.tags) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in > insert > self.notify_range(index, index + "+%dc" % len(chars)) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in > notify_range > self.after_id = self.after(1, self.recolorize) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after > name = self._register(callit) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in > _register > f = CallWrapper(func, subst, self).__call__ > RuntimeError: maximum recursion depth exceeded > > Andrea Valle > via Lanzo 108 > 10073 - Ciriè (TO) > ITALIA > 011/921 45 84 - 349/55 47 343 > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From Jmllr891@cs.com Thu Sep 26 02:16:29 2002 From: Jmllr891@cs.com (Jmllr891@cs.com) Date: Wed, 25 Sep 2002 21:16:29 EDT Subject: [Tutor] Need Help Embedding Python in C++ Message-ID: --part1_d8.1e16ea25.2ac3b9ed_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, I am having trouble embedding Python in C++. I am using the DJGPP compiler and Python 2.2.1. I am using extremely basic code just to try and see if I can successfully embed Python in my program without errors. This is my "test code": ------------------------------------------------------------------------------ ---------- #include int main() { return 0; } ------------------------------------------------------------------------------ ---------- This produces the following errors when I try to compile: ------------------------------------------------------------------------------ ---------- Compiling: c:/windows/desktop/test.cpp d:/djgpp/include/python.h(62) In file included from d:/djgpp/include/python.h62, ../desktop/test.cpp(6) d:/djgpp/include/pyport.h(480) Error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?). There were some errors. ------------------------------------------------------------------------------ ---------- I am running Windows ME (bleh, trying to switch to Linux) and I've never encountered any problems like this before with C/C++ or Python. --part1_d8.1e16ea25.2ac3b9ed_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, I am having trouble embedding Python in C++. I am using the DJGPP compiler and Python 2.2.1. I am using extremely basic code just to try and see if I can successfully embed Python in my program without errors.

This is my "test code":

----------------------------------------------------------------------------------------

#include <Python.h>

int main()
{
  return 0;
}

----------------------------------------------------------------------------------------

This produces the following errors when I try to compile:

----------------------------------------------------------------------------------------

Compiling: c:/windows/desktop/test.cpp

d:/djgpp/include/python.h(62) In file included from d:/djgpp/include/python.h62,
../desktop/test.cpp(6)

d:/djgpp/include/pyport.h(480) Error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?).

There were some errors.

----------------------------------------------------------------------------------------

I am running Windows ME (bleh, trying to switch to Linux) and I've never encountered any problems like this before with C/C++ or Python.
--part1_d8.1e16ea25.2ac3b9ed_boundary-- From marta_andrea@libero.it Thu Sep 26 09:38:06 2002 From: marta_andrea@libero.it (Andrea Valle) Date: Thu, 26 Sep 2002 10:38:06 +0200 Subject: R: [Tutor] an error on recursion depth (fwd) In-Reply-To: <20020925180239.41fc5068.linux1011@HotPOP.com> Message-ID: David, thank you. You are completely right. And that is what I did. In fact, my program wor= ks much faster. ciao -a- -----Messaggio originale----- Da: David Mccowan [mailto:linux1011@HotPOP.com] Inviato: gioved=EC 26 settembre 2002 1.03 A: marta_andrea@libero.it Cc: tutor@python.org Oggetto: Re: [Tutor] an error on recursion depth (fwd) On Wed, 25 Sep 2002 11:06:40 -0700 (PDT) Danny Yoo wrote: I had this same problem in a program I was writing, my solution was to use a loop instead. I not only noticed that it worked but ran much faster. Most recursive functions can be written as loops and vice versa just by keeping track of the variable manually. A good example of this exists in Structure and Interpretation of Computer Programs, although the book uses scheme its concepts can easily be applied to most high level programming languanges http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.1 In a addition to this section the entire book is online at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start > Date: Wed, 25 Sep 2002 12:33:36 +0200 > From: Andrea Valle > To: tutor-admin@python.org > Subject: an error on recursion depth > > Hi list, > my program stops with this: > > RuntimeError: maximum recursion depth exceeded > > Why? I used the program in Python 1.5.2.: never happened. I think I > already used it also for exactly the same task (same parameters, same > complexity) also in 2.1. It's the first time it breaks. > How can I avoid it? > > thank you > > -a- > tutor-admin@python.org > > PS:(down I attach the whole final part: the fisrt line is repeat alot > of times and then you have the ending part) > > > File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in > percorri_arco > tre_punti=3Dgrafista0.tre_punti(perc, vel, dur) > File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti > print spazio > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write > self.shell.write(s, self.tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write > OutputWindow.write(self, s, tags, "iomark") > File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in > write > self.text.insert(mark, s, tags) > File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in > insert > self.top.insert(index, chars, tags) > File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in > insert > UndoDelegator.insert(self, index, chars, tags) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in > insert > self.addcmd(InsertCommand(index, chars, tags)) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in > addcmd > cmd.do(self.delegate) > File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in > do > text.insert(self.index1, self.chars, self.tags) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in > insert > self.notify_range(index, index + "+%dc" % len(chars)) > File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in > notify_range > self.after_id =3D self.after(1, self.recolorize) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after > name =3D self._register(callit) > File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in > _register > f =3D CallWrapper(func, subst, self).__call__ > RuntimeError: maximum recursion depth exceeded > > Andrea Valle > via Lanzo 108 > 10073 - Ciri=E8 (TO) > ITALIA > 011/921 45 84 - 349/55 47 343 > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From lsloan@umich.edu Thu Sep 26 13:56:21 2002 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 26 Sep 2002 08:56:21 -0400 Subject: [Tutor] Re:Newby!!!! In-Reply-To: <5.1.0.14.0.20020926005409.05572338@www.thinkware.se> References: <5.1.0.14.0.20020926005409.05572338@www.thinkware.se> Message-ID: <2765905.1033030581@[10.0.1.38]> --On Thursday, September 26, 2002 0:59 +0200 Magnus Lycka wrote: > Please correct your date setting (year 2001 passed), > your mail ends up in the wrong end of our lists... Not to mention in the wrong part of the list archives. We have messages in the archive for years 1980 (before Python was created), 2003, 2011, 2012, and 2027. Can somebody fix those messages in the archives? Better yet, can we get the mailing list software (It's Mailman, right?) to not accept or deliver messages that don't have a reasonable date? -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From steve@openiso.com Thu Sep 26 18:42:42 2002 From: steve@openiso.com (steve lewis) Date: Thu, 26 Sep 2002 12:42:42 -0500 (CDT) Subject: [Tutor] W2K environment... Message-ID: <3608.199.66.1.5.1033062162.squirrel@www.absolutenettech.com> hello, i am searching for any special environment settings to run Python 2.2 on W2K Pro. -- thanks, steve lewis usa "do or do not, there is no try." yoda From dana@pixelenvy.ca Thu Sep 26 19:01:51 2002 From: dana@pixelenvy.ca (Dana Larose) Date: Thu, 26 Sep 2002 13:01:51 -0500 (CDT) Subject: [Tutor] W2K environment... In-Reply-To: <3608.199.66.1.5.1033062162.squirrel@www.absolutenettech.com> Message-ID: I've set up 2.2 on a number of W2K pro machines, and haven't had to set an special environment settings. I do find it conventient to include the Python directly in my path setting, though. Dana. On Thu, 26 Sep 2002, steve lewis wrote: > hello, > > i am searching for any special environment settings to run Python 2.2 on > W2K Pro. > -- > thanks, > > steve lewis > usa > "do or do not, there is no try." yoda > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From john@pertalion.org Thu Sep 26 19:11:19 2002 From: john@pertalion.org (John Pertalion) Date: Thu, 26 Sep 2002 14:11:19 -0400 Subject: [Tutor] W2K environment... In-Reply-To: <3608.199.66.1.5.1033062162.squirrel@www.absolutenettech.com> Message-ID: I install it in the C:\ directory on my W2K Pro box. That doesn't require any changes. John > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > steve lewis > Sent: Thursday, September 26, 2002 1:43 PM > To: tutor@python.org > Subject: [Tutor] W2K environment... > > > hello, > > i am searching for any special environment settings to run Python 2.2 on > W2K Pro. > -- > thanks, > > steve lewis > usa > "do or do not, there is no try." yoda > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > From steve@openiso.com Thu Sep 26 21:02:12 2002 From: steve@openiso.com (steve lewis) Date: Thu, 26 Sep 2002 15:02:12 -0500 (CDT) Subject: [Tutor] W2K environment... In-Reply-To: References: <3608.199.66.1.5.1033062162.squirrel@www.absolutenettech.com> Message-ID: <4198.199.66.1.5.1033070532.squirrel@www.absolutenettech.com> i have mine installed under c:\ also, just making sure i was not missing something in all of the online stuff and books i am using. as my learning script i am doing something simple, but am running into some problems. i am creating a script to launch apps on my w2k pro box at work. ##code snip 1 import os 2 3 #start apps 4 #os.system('start C:\WINNT\NOTEPAD.exe') 5 #os.system('start C:\WINNT\explorer.exe') 6 os.system('start "C:\Program Files\NoteTab Light\NoteTab.exe"') 7 os.system('start "C:\Reflection\tyson1.r2w"') ##end code snip lines 4 and 5 work, but lines 6 and 7 do not. not quite sure what is going wrong here or what i am not considering in the w2k system. also, any "good coding" pointers any may have, please offer them. thanks, steve lewis John Pertalion said: > > I install it in the C:\ directory on my W2K Pro box. That doesn't > require any changes. > > John > >> -----Original Message----- >> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf >> Of steve lewis >> Sent: Thursday, September 26, 2002 1:43 PM >> To: tutor@python.org >> Subject: [Tutor] W2K environment... >> >> >> hello, >> >> i am searching for any special environment settings to run Python 2.2 >> on W2K Pro. >> -- >> thanks, >> >> steve lewis >> usa >> "do or do not, there is no try." yoda >> >> >> >> _______________________________________________ >> 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 emile@fenx.com Thu Sep 26 21:17:26 2002 From: emile@fenx.com (Emile van Sebille) Date: Thu, 26 Sep 2002 13:17:26 -0700 Subject: [Tutor] Re: W2K environment... References: <3608.199.66.1.5.1033062162.squirrel@www.absolutenettech.com> <4198.199.66.1.5.1033070532.squirrel@www.absolutenettech.com> Message-ID: "steve lewis" wrote in message news:4198.199.66.1.5.1033070532.squirrel@www.absolutenettech.com... > i have mine installed under c:\ also, just making sure i was not missing > something in all of the online stuff and books i am using. > as my learning script i am doing something simple, but am running into > some problems. > i am creating a script to launch apps on my w2k pro box at work. > > ##code snip > > 1 import os > 2 > 3 #start apps > 4 #os.system('start C:\WINNT\NOTEPAD.exe') > 5 #os.system('start C:\WINNT\explorer.exe') > 6 os.system('start "C:\Program Files\NoteTab Light\NoteTab.exe"') > 7 os.system('start "C:\Reflection\tyson1.r2w"') > Backslashes introduce a control character when included in python strings. Either double the character, try forward slashes, or use raw strings instead. I expect all three of these would work: os.system(r'start "C:\Reflection\tyson1.r2w"') os.system('start "C:\\Reflection\\tyson1.r2w"') os.system('start "C:/Reflection/tyson1.r2w"') HTH, -- Emile van Sebille emile@fenx.com --------- From thomi@thomi.imail.net.nz Thu Sep 26 22:34:30 2002 From: thomi@thomi.imail.net.nz (Thomi Richards) Date: Fri, 27 Sep 2002 09:34:30 +1200 Subject: [Tutor] Re:Newby!!!! In-Reply-To: <2765905.1033030581@[10.0.1.38]> References: <5.1.0.14.0.20020926005409.05572338@www.thinkware.se> <2765905.1033030581@[10.0.1.38]> Message-ID: <20020927093430.19b78fc8.thomi@thomi.imail.net.nz> or better yet, get mailman to set the date according to when mailman recieved the message, as opposed to when it was sent? there's an option in there somewhere... On Thu, 26 Sep 2002 08:56:21 -0400 Thus said Lance E Sloan : > --On Thursday, September 26, 2002 0:59 +0200 Magnus Lycka > wrote: > > Please correct your date setting (year 2001 passed), > > your mail ends up in the wrong end of our lists... > > Not to mention in the wrong part of the list archives. We have > messages in the archive for years 1980 (before Python was created), > 2003, 2011, 2012, and 2027. Can somebody fix those messages in the > archives? Better yet, can we get the mailing list software (It's > Mailman, right?) to not accept or deliver messages that don't have a > reasonable date? > > -- > Lance E Sloan > Web Services, Univ. of Michigan: Full-service Web and database design, > development, and hosting. Specializing in Python & Perl CGIs. > http://websvcs.itd.umich.edu/ - "Putting U on the Web" > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Thomi Richards thomi@imail.net.nz http://thomi.imail.net.nz/ Thomi Richards, thomi@imail.net.nz From rob@uselesspython.com Fri Sep 27 07:37:47 2002 From: rob@uselesspython.com (Rob) Date: Fri, 27 Sep 2002 01:37:47 -0500 Subject: [Tutor] W2K environment... In-Reply-To: <4198.199.66.1.5.1033070532.squirrel@www.absolutenettech.com> Message-ID: There's got to be some more *pythonic* way to do this, but at 1:30 in the morning I think of the following hack. I also use NoteTab Light, although I keep it in a different spot. However, I'm betting that if you try your code in IDLE, you get back a complaint to the effect that it can't find 'C:\Program' when it hits the space between "Program" and "Files" in "Program Files". Now, on with the hack: Create a shortcut to NoteTab.exe in C:\. Rename the shortcut to just "notetab". Change line 6 to os.system('start C:/notetab') This way you execute the shortcut, which points to notetab. It just worked here. Now I'll wait around for one of the more talented among us to offer the preferred answer, but this should get you through in the mean. Rob http://uselesspython.com > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > steve lewis > Sent: Thursday, September 26, 2002 3:02 PM > To: tutor@python.org > Subject: RE: [Tutor] W2K environment... > > > i have mine installed under c:\ also, just making sure i was not missing > something in all of the online stuff and books i am using. > as my learning script i am doing something simple, but am running into > some problems. > i am creating a script to launch apps on my w2k pro box at work. > > ##code snip > > 1 import os > 2 > 3 #start apps > 4 #os.system('start C:\WINNT\NOTEPAD.exe') > 5 #os.system('start C:\WINNT\explorer.exe') > 6 os.system('start "C:\Program Files\NoteTab Light\NoteTab.exe"') > 7 os.system('start "C:\Reflection\tyson1.r2w"') > > ##end code snip > > lines 4 and 5 work, but lines 6 and 7 do not. not quite sure what is going > wrong here or what i am not considering in the w2k system. also, any "good > coding" pointers any may have, please offer them. > thanks, > > steve lewis > > > John Pertalion said: > > > > I install it in the C:\ directory on my W2K Pro box. That doesn't > > require any changes. > > > > John > > > >> -----Original Message----- > >> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf > >> Of steve lewis > >> Sent: Thursday, September 26, 2002 1:43 PM > >> To: tutor@python.org > >> Subject: [Tutor] W2K environment... > >> > >> > >> hello, > >> > >> i am searching for any special environment settings to run Python 2.2 > >> on W2K Pro. > >> -- > >> thanks, > >> > >> steve lewis > >> usa > >> "do or do not, there is no try." yoda > >> > >> > >> > >> _______________________________________________ > >> Tutor maillist - Tutor@python.org > >> http://mail.python.org/mailman/listinfo/tutor > >> > >> > > > > > > > > _______________________________________________ > > 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 rob@zoism.org Fri Sep 27 07:34:09 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 27 Sep 2002 18:34:09 +1200 Subject: [Tutor] [Fwd: Please help, I'm a newbie] In-Reply-To: <1032789762.4411.10.camel@kniep02.kniep> References: <1032789762.4411.10.camel@kniep02.kniep> Message-ID: <1033108449.2783.10.camel@caspian.everglade> On Tue, 2002-09-24 at 02:02, Dick Kniep wrote: > > Having searched a little further, it looks a little less weird, but I still > do not understand what is happening. It seems that the error occurs on the import > of the routine. But I still don'y know what is happening here.... It looks like columns isn't defiened becuase of the indentaion. Also are you sure there is a 'columns' ? I know you define it in the init routine to be and empty [] but what happens if the calling routine passes a None to the columns variable? Then there is no columns variable (I think). Try doing a print columns just before the error to see exactly what columns is. -- * * Rob Brown-Bayliss * From rob@zoism.org Fri Sep 27 07:25:28 2002 From: rob@zoism.org (Rob Brown-Bayliss) Date: 27 Sep 2002 18:25:28 +1200 Subject: [Tutor] recommended Editor? In-Reply-To: References: Message-ID: <1033107927.2725.2.camel@caspian.everglade> On Tue, 2002-09-24 at 12:26, Gus Tabares wrote: > Lance, > > Have you tried Visual SlickEdit? I'm not quite sure it does > auto-indentation, but it's worth a shot. It runs on both Win32/Unix. Also, > I'm not sure it's freeware, so you might end up coughing up some dough to > use it. Just a suggestion....good luck. I use Moleskine on linux, it's a gnome app that uses the scintilla widget. I just cut and pasted teh python reserved words onto it's language file and then setup different colours for things like class and function descriptors etc. It's not perfect but does autoindent, colorises all sorts (like comments, strings, numbers def's etc) -- * * Rob Brown-Bayliss * From nano@intermatik.co.id Fri Sep 27 09:10:32 2002 From: nano@intermatik.co.id (nano) Date: 27 Sep 2002 15:10:32 +0700 Subject: [Tutor] downloader-script Message-ID: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> hi pythoners, from the mail subject u guys can guess that i'm a newbie too. now i'm using webware to develop a website. i want to know how to make a function for downloading an object from the page. the object is in html-format, (contains html tag) and i want to convert them (without the tags) into text format. anybody can help me (sure there are...) sorry for my english. thanks in advance, nano' From magnus@thinkware.se Fri Sep 27 09:48:30 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 27 Sep 2002 10:48:30 +0200 Subject: [Tutor] [Fwd: Please help, I'm a newbie] In-Reply-To: <1033108449.2783.10.camel@caspian.everglade> References: <1032789762.4411.10.camel@kniep02.kniep> <1032789762.4411.10.camel@kniep02.kniep> Message-ID: <5.1.0.14.0.20020927103405.02b5ab58@www.thinkware.se> At 18:34 2002-09-27 +1200, Rob Brown-Bayliss wrote: >On Tue, 2002-09-24 at 02:02, Dick Kniep wrote: > > > > Having searched a little further, it looks a little less weird, but I=20 > still > > do not understand what is happening. It seems that the error occurs on= =20 > the import > > of the routine. Yes. That is because of the indentation error. The "if..." part is not inside the function, but in the scope of the class. "column" doesn't exist there. > > But I still don'y know what is happening here.... > >It looks like columns isn't defiened becuase of the indentaion. That's my impression too. Note that python assumes tabstop =3D 8. Never ever ever mix spaces and tabs for indentation in a file. This might not be the same as in your editor. Two tips: * Run python with the -t or -tt flag. This will give you warnings or errors due to inconsistent use of space/tab. (I think this should be default...) * Use an editor/IDE that can show whitespace, and use that. For instance in PythonWin "View->Whitespace" >Also >are you sure there is a 'columns' ? > >I know you define it in the init routine to be and empty [] but what >happens if the calling routine passes a None to the columns variable? >Then there is no columns variable (I think). None and not existing is not the same thing. You remove things with "del" >>> x =3D 5 >>> print x 5 >>> x =3D None >>> print x None >>> del x >>> print x Traceback (most recent call last): File "", line 1, in ? NameError: name 'x' is not defined --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Fri Sep 27 10:14:46 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 27 Sep 2002 11:14:46 +0200 Subject: [Tutor] downloader-script In-Reply-To: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> Message-ID: <5.1.0.14.0.20020927105003.02b54668@www.thinkware.se> At 15:10 2002-09-27 +0700, nano wrote: >now i'm using webware to develop a website. i want to know how to make a >function for downloading an object from the page. the object is in >html-format, (contains html tag) and i want to convert them (without the >tags) into text format. Ok, you want to remove HTML tags from an HTML file and turn it into plain text? This has been up here before I think. I've used htmllib to do it, but that is really to stupid for the task. sgmllib is probably a better choice. See http://mail.python.org/pipermail/tutor/2002-August/016567.html Another option is to use regular expressions. See: http://www.faqts.com/knowledge_base/view.phtml/aid/3680/fid/199 --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From stefanus.arief@ai.astra.co.id Fri Sep 27 10:30:03 2002 From: stefanus.arief@ai.astra.co.id (Arief) Date: Fri, 27 Sep 2002 16:30:03 +0700 Subject: [Tutor] downloader-script In-Reply-To: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> Message-ID: How to download a web page? Try this ... ##### import urllib url = 'http://www.python.org/' f = urllib.urlopen(url) html = f.read() f.close() print html ##### It uses "urllib" module. The url is the url you wish to download. How to convert html page to text? It won't be easy. But you can use "HTMLParser" or "sgmllib". They both are almost the same. Try this ... ##### from HTMLParser import HTMLParser class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print 'Tag & attrs:', tag, attrs def handle_endtag(self, tag): print 'Tag:', tag def handle_data(self, data): print 'Data:', data import urllib url = 'http://www.python.org/' f = urllib.urlopen(url) html = f.read() f.close() p = MyHTMLParser() p.feed(html) p.close() ##### To make it works as you wish, you should read the Python documentation. Hope it helps you. ----- Arief >-----Original Message----- >From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of >nano >Sent: Friday, 27 September 2002 3:11 PM >To: python-tutor >Subject: [Tutor] downloader-script > > >hi pythoners, > >from the mail subject u guys can guess that i'm a newbie too. >now i'm using webware to develop a website. i want to know how to make a >function for downloading an object from the page. the object is in >html-format, (contains html tag) and i want to convert them (without the >tags) into text format. >anybody can help me (sure there are...) >sorry for my english. > >thanks in advance, > >nano' > > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > From magnus@thinkware.se Fri Sep 27 11:18:15 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Fri, 27 Sep 2002 12:18:15 +0200 Subject: [Tutor] Factories agian... In-Reply-To: <5.1.0.14.0.20020927105003.02b54668@www.thinkware.se> References: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> Message-ID: <5.1.0.14.0.20020927121630.00be4ee8@www.thinkware.se> In case someone is still wondering about the Factory patterns, I just saw that they are nicely covered in Bruce Eckel's book draft: Thinking In Python. It's available at: http://www.mindview.net/Books/TIPython -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From fgranger@altern.org Fri Sep 27 12:23:23 2002 From: fgranger@altern.org (Francois Granger) Date: Fri, 27 Sep 2002 13:23:23 +0200 Subject: [Tutor] downloader-script In-Reply-To: <5.1.0.14.0.20020927105003.02b54668@www.thinkware.se> References: <5.1.0.14.0.20020927105003.02b54668@www.thinkware.se> Message-ID: At 11:14 +0200 27/09/02, in message Re: [Tutor] downloader-script, Magnus Lycka wrote: > >Ok, you want to remove HTML tags from an HTML >file and turn it into plain text? > >http://www.faqts.com/knowledge_base/view.phtml/aid/3680/fid/199 I was looking in the same issue. This looks like a good simple solution. From ajs@ix.netcom.com Fri Sep 27 14:56:54 2002 From: ajs@ix.netcom.com (Arthur) Date: Fri, 27 Sep 2002 09:56:54 -0400 Subject: [Tutor] Factories agian... References: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> <5.1.0.14.0.20020927121630.00be4ee8@www.thinkware.se> Message-ID: <001601c2662d$bcd878e0$9865fea9@arthur> ----- Original Message ----- From: "Magnus Lycka" To: "python-tutor" Sent: Friday, September 27, 2002 6:18 AM Subject: [Tutor] Factories agian... > In case someone is still wondering about the > Factory patterns, I just saw that they are > nicely covered in Bruce Eckel's book draft: > Thinking In Python. It's available at: > http://www.mindview.net/Books/TIPython > > > -- > Magnus Lycka, Thinkware AB > Alvans vag 99, SE-907 50 UMEA, SWEDEN > phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 > http://www.thinkware.se/ mailto:magnus@thinkware.se > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From ajs@ix.netcom.com Fri Sep 27 14:56:35 2002 From: ajs@ix.netcom.com (Arthur) Date: Fri, 27 Sep 2002 09:56:35 -0400 Subject: [Tutor] Factories agian... References: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> <5.1.0.14.0.20020927121630.00be4ee8@www.thinkware.se> Message-ID: <001501c2662d$b21ea730$9865fea9@arthur> > In case someone is still wondering about the > Factory patterns, I just saw that they are > nicely covered in Bruce Eckel's book draft: > Thinking In Python. It's available at: > http://www.mindview.net/Books/TIPython I don't want to be negative, Especially since I did get much out of the TIPython draft, and do use it as a source of reference and feel the Python world is a better place for it. But... I do wish it maintained its original title - Thinking in Patterns. Because I do feel Python is really being used in it as an example language for a Pattern approach. I *don't* think, as it is, it is very Python specific at all. Which is fine. But in being generic, it seems to me to sometimes to specifically *not* be thinking in Python. I doesn't provide, let's say, Pythonic "shortcuts" to achieving the effect of established Patterns, or seem to focus on Patterns that might address the specific needs, let's say, of a dynamically typed language. Two points, though : Eckel is a much more advanced guy in general understanding of programming than I. I am stating an impression, understanding that I might be missing something that is simply over my head at this point in the game. The book is in draft form. It sometimes simply says this is the Python transliteration from the Java. Eckel might be specifically working to address the issue I bring up. Art From steve@openiso.com Fri Sep 27 16:37:18 2002 From: steve@openiso.com (steve lewis) Date: Fri, 27 Sep 2002 10:37:18 -0500 (CDT) Subject: [Tutor] W2K environment... In-Reply-To: References: <4198.199.66.1.5.1033070532.squirrel@www.absolutenettech.com> Message-ID: <4774.199.66.1.5.1033141038.squirrel@www.absolutenettech.com> Rob, thanks for the tip, worked like a charm. also, does NoteTab have any Python modules or Pythoncentric setup? thanks, steve lewis usa "do or do not, there is no try." yoda From dyoo@hkn.eecs.berkeley.edu Fri Sep 27 17:28:52 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 27 Sep 2002 09:28:52 -0700 (PDT) Subject: [Tutor] downloader-script In-Reply-To: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> Message-ID: On 27 Sep 2002, nano wrote: > from the mail subject u guys can guess that i'm a newbie too. now i'm > using webware to develop a website. i want to know how to make a > function for downloading an object from the page. the object is in > html-format, (contains html tag) and i want to convert them (without the > tags) into text format. anybody can help me (sure there are...) sorry > for my english. Hi Nano, Hmmm... can you give a concrete example of a particular page and a particular object of that page? The word "object" is so overloaded --- so abstract --- that it's often hard trying to figure out what is being meant... *grin* You can download a web page by using the 'urllib' standard library: http://www.python.org/doc/lib/module-urllib.html This, however, gives us the literal page, including its HTML tags. So we can combine this with some sort of HTML-stripping program to do what I think you're trying to do. Here's a quicky HTML stripper: ### from sgmllib import SGMLParser class HTMLStripper(SGMLParser): def __init__(self): SGMLParser.__init__(self) self._text = [] def handle_data(self, data): self._text.append(data) def read_text(self): return ''.join(self._text) def strip_html(text): stripper = HTMLStripper() stripper.feed(text) return stripper.read_text() ### Let's see how this might work: ### >>> strip_html("hello") 'hello' >>> strip_html("

hello

") 'hello' >>> text = strip_html(urllib.urlopen('http://python.org').read()) >>> text[:100] '\n\n\n\n\n\n\n\n\n\nPython Language Website\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n\n\n\n\n\n \nHome\n \n \nSearch\n \n' ### Wow, there's a lots of whitespace there. So we may need to do additional processing like whitespace strip()ping. I hope this helps! From dyoo@hkn.eecs.berkeley.edu Fri Sep 27 17:40:46 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 27 Sep 2002 09:40:46 -0700 (PDT) Subject: [Tutor] downloader-script In-Reply-To: Message-ID: On Fri, 27 Sep 2002, Francois Granger wrote: > At 11:14 +0200 27/09/02, in message Re: [Tutor] downloader-script, > Magnus Lycka wrote: > > > >Ok, you want to remove HTML tags from an HTML > >file and turn it into plain text? > > > >http://www.faqts.com/knowledge_base/view.phtml/aid/3680/fid/199 > > I was looking in the same issue. This looks like a good simple solution. It's simple, but it has a bug: it assumes that a whole HTML tag lies entirely on the same line. ### >>> data = """ ... hello world ...
""" >>> text = re.sub('<.*?>', '', data) >>> text '\n hello world\n ### This may not be an issue on simple pages, but still one to be aware of. One way to fix the regular expression would be to tell the regular expression engine to allow the '.' to span across lines: ### >>> html_pattern = re.compile('<.*?>', re.DOTALL) >>> text = html_pattern.sub('', data) >>> text '\n hello world\n ' ### Good luck! From monashee@junction.net Fri Sep 27 17:57:22 2002 From: monashee@junction.net (J or M Montgomery) Date: Fri, 27 Sep 2002 09:57:22 -0700 Subject: [Tutor] downloader-script References: <5.1.0.14.0.20020927105003.02b54668@www.thinkware.se> Message-ID: <3D948DF2.505@junction.net> Francois Granger wrote: > At 11:14 +0200 27/09/02, in message Re: [Tutor] downloader-script, > Magnus Lycka wrote: > >> >> Ok, you want to remove HTML tags from an HTML >> file and turn it into plain text? >> If you are working in windows or a dual boot system, there is a nice program called NoteTab. It will strip all html and leave plain text. Freeware too! John Montgomery From aicolburn@yahoo.com Fri Sep 27 18:50:37 2002 From: aicolburn@yahoo.com (Alan Colburn) Date: Fri, 27 Sep 2002 10:50:37 -0700 Subject: [Tutor] Introduction to the cmd Module Message-ID: <002c01c2664e$6303c970$cae68b86@fo5132> I picked up a copy of Lutz & Ascher's 'Learning Python' book recently and, while looking through it, learned about the cmd module. I'd love to start using it, but I'm having some difficulties. I'm not quite sure what information I'm missing, but I can't seem to get simple tests to work properly (...and I couldn't really understand the online documentation :-) For example, consider this simple script: import cmd class Test(cmd.Cmd): def __init__(self): cmd.Cmd.__init__(self) self.prompt="% " def do_printHello(self): print 'hello' x=Test() x.cmdloop() The new prompt appears, but the printHello command generates an error (do_printHello takes 1 argument, 2 given). Before posting here, I looked around a bit to try to find answers online somewhere, but ended up more confused than before I started :-) It seems as though sometimes people pass an added variable, "argline" into their class method definitions, and sometimes they don't. The scripts work fine for me when I add an "argline," but I don't really know what it is or why I'm doing it. Anybody feel like a brief tutorial? :-) As always, my thanks to you all. -- Al C. From shalehperry@attbi.com Fri Sep 27 19:06:00 2002 From: shalehperry@attbi.com (Sean 'Shaleh' Perry) Date: Fri, 27 Sep 2002 11:06:00 -0700 Subject: [Tutor] Introduction to the cmd Module In-Reply-To: <002c01c2664e$6303c970$cae68b86@fo5132> References: <002c01c2664e$6303c970$cae68b86@fo5132> Message-ID: <200209271106.00394.shalehperry@attbi.com> On Friday 27 September 2002 10:50, Alan Colburn wrote: > > For example, consider this simple script: > import cmd > class Test(cmd.Cmd): > def __init__(self): > cmd.Cmd.__init__(self) > self.prompt=3D"% " > def do_printHello(self): > print 'hello' > x=3DTest() > x.cmdloop() > > The new prompt appears, but the printHello command generates an error > (do_printHello takes 1 argument, 2 given). > > Anybody feel like a brief tutorial? :-) > Here is the __doc__ string for the cmd modules. """A generic class to build line-oriented command interpreters. Interpreters constructed with this class obey the following conventions: 1. End of file on input is processed as the command 'EOF'. 2. A command is parsed out of each line by collecting the prefix composed of characters in the identchars member. 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method is passed a single argument consisting of the remainder of the line. 4. Typing an empty line repeats the last command. (Actually, it calls th= e method `emptyline', which may be overridden in a subclass.) 5. There is a predefined `help' method. Given an argument `topic', it calls the command `help_topic'. With no arguments, it lists all topic= s with defined help_ functions, broken into up to three topics; document= ed commands, miscellaneous help topics, and undocumented commands. 6. The command '?' is a synonym for `help'. The command '!' is a synonym for `shell', if a do_shell method exists. 7. If completion is enabled, completing commands will be done automatical= ly, and completing of commands args is done by calling complete_foo() with arguments text, line, begidx, endidx. text is string we are matching against, all returned matches must begin with it. line is the current input line (lstripped), begidx and endidx are the beginning and end indexes of the text being matched, which could be used to provide different completion depending upon which position the argument is in. The `default' method may be overridden to intercept commands for which th= ere is no do_ method. =20 The `completedefault' method may be overridden to intercept completions f= or commands that have no complete_ method. The data member `self.ruler' sets the character used to draw separator li= nes in the help messages. If empty, no ruler line is drawn. It defaults to = "=3D". If the value of `self.intro' is nonempty when the cmdloop method is calle= d, it is printed out on interpreter startup. This value may be overridden via an optional argument to the cmdloop() method. The data members `self.doc_header', `self.misc_header', and `self.undoc_header' set the headers used for the help function's listings of documented functions, miscellaneous topics, and undocumented functions respectively. These interpreters use raw_input; thus, if the readline module is loaded, they automatically support Emacs-like command history and editing feature= s. """ Item number 3. gives you the answer to your problem. Every do_??? method= must=20 take a parameter which is the rest of the input line. You then read this= =20 value to get your arguments. From fgranger@altern.org Fri Sep 27 19:52:17 2002 From: fgranger@altern.org (Francois Granger) Date: Fri, 27 Sep 2002 20:52:17 +0200 Subject: [Tutor] downloader-script In-Reply-To: References: Message-ID: At 9:40 -0700 27/09/02, in message Re: [Tutor] downloader-script, Danny Yoo wrote: > >It's simple, but it has a bug: it assumes that a whole HTML tag lies >entirely on the same line. > >This may not be an issue on simple pages, but still one to be aware of. >One way to fix the regular expression would be to tell the regular >expression engine to allow the '.' to span across lines: Thanks for correcting. From jpollack@socrates.Berkeley.EDU Fri Sep 27 20:15:15 2002 From: jpollack@socrates.Berkeley.EDU (Joshua Pollack) Date: Fri, 27 Sep 2002 12:15:15 -0700 Subject: [Tutor] gnuplot.py installation and some general questions Message-ID: <003f01c2665a$37519b20$184e0e82@Priscilla> This is a multi-part message in MIME format. ------=_NextPart_000_003C_01C2661F.89AC1250 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I'm having trouble with my gnuplot.py installation under Windows XP. It = goes as follows (with some digressions as to general python = questions..): Here's what's happening. I unzipped the gnuplot1.6 file into my .\site-packages directory (same place Numeric automatically puts itself. = As you suggested, I put pgnuplot.exe in \bin and added it to my PATH = variable. Do I have this straight? The PATH variable allows you to call all of = the entities listed from anywhere on your computer, correct? (i.e.- I could = call python from c:\mystuff\shakespeare or whatever) and the PYTHONPATH = variable is all the places python looks for modules when you import them? (is = this the same as sys.path?) So anyway: I do the little python setup.py install dance and get a load of output = that looks promising. However when I import Gnuplot and assign a variable = like so: map=3DGnuplot.Gnuplot(debug=3D1) and then try and plot something, = such as sin(x) or something I get the following output: Traceback (most recent call last): File "", line 1, in ? map('sin(x)') File "c:\Python22\Lib\site-packages\Gnuplot\_Gnuplot.py", line 206, in __call__ self.gnuplot(s) File "c:\Python22\Lib\site-packages\Gnuplot\gp_win32.py", line 122, in __call__ self.write(s + '\n') IOError: [Errno 22] Invalid argument I get some additional errors when I try and run it from the command line = (I ran this from the shell), but these two were ubiquitous. It seems to = have something to do with the s variable in both functions, but as far as I = can tell, it's just an input string, both functions look correct. Somehow, = I'm not sure my python is piping correctly to pgnuplot.exe. Does putting it = in the \bin file and adding that to PATH take care of that? Anyway, let me know if there's something obvious. Thanks and have a good weekend. Josh ------=_NextPart_000_003C_01C2661F.89AC1250 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
I'm having trouble with my gnuplot.py = installation=20 under Windows XP.  It goes as follows (with some digressions as to = general=20 python questions..):
 
Here's what's happening.  I unzipped the gnuplot1.6 file into=20 my
.\site-packages directory (same place Numeric automatically puts=20 itself.  As
you suggested, I put pgnuplot.exe in \bin and added = it to my=20 PATH variable.
Do I have this straight?  The PATH variable = allows you to=20 call all of the
entities listed from anywhere on your computer, = correct?=20 (i.e.- I could call
python from c:\mystuff\shakespeare or whatever) = and the=20 PYTHONPATH variable
is all the places python looks for modules when = you=20 import them?  (is this
the same as sys.path?)  So = anyway:

I=20 do the little python setup.py install dance and get a load of output=20 that
looks promising.  However when I import Gnuplot and assign = a=20 variable like
so: map=3DGnuplot.Gnuplot(debug=3D1) and then try and = plot=20 something, such as
sin(x) or something I get the following=20 output:

Traceback (most recent call last):
  File=20 "<pyshell#2>", line 1, in ?
    = map('sin(x)')
 =20 File "c:\Python22\Lib\site-packages\Gnuplot\_Gnuplot.py", line 206,=20 in
__call__
    self.gnuplot(s)
  File=20 "c:\Python22\Lib\site-packages\Gnuplot\gp_win32.py", line 122,=20 in
__call__
    self.write(s + '\n')
IOError: = [Errno 22]=20 Invalid argument

I get some additional errors when I try and run = it from=20 the command line (I
ran this from the shell), but these two were=20 ubiquitous.  It seems to have
something to do with the s = variable in=20 both functions, but as far as I can
tell, it's just an input string, = both=20 functions look correct.  Somehow, I'm
not sure my python is = piping=20 correctly to pgnuplot.exe.  Does putting it in
the \bin file and = adding=20 that to PATH take care of that?

Anyway, let me know if there's = something=20 obvious.

Thanks and have a good=20 weekend.

Josh
------=_NextPart_000_003C_01C2661F.89AC1250-- From dyoo@hkn.eecs.berkeley.edu Fri Sep 27 21:18:33 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 27 Sep 2002 13:18:33 -0700 (PDT) Subject: [Tutor] downloader-script (fwd) Message-ID: ---------- Forwarded message ---------- Date: Fri, 27 Sep 2002 21:03:18 +0200 From: Magnus Lycka To: Danny Yoo Subject: Re: [Tutor] downloader-script At 09:28 2002-09-27 -0700, you wrote: >Wow, there's a lots of whitespace there. So we may need to do additional >processing like whitespace strip()ping. If we accept to get all text just separated by single spaces, that's as simple as text =3D " ".join(text.split()) =2Esplit() without parameters will split on any sequnece of whitespace. In case we want to preserve some breaks, I think we have to keep

and
tags in the text. Another option would be text =3D os.popen('lynx -dump %s' % url).read() but that assumes that we have lynx installed (not a bad idea anyway) and you will have to filter out links given as footnotes unless you think they are ok. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From dyoo@hkn.eecs.berkeley.edu Fri Sep 27 21:18:39 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 27 Sep 2002 13:18:39 -0700 (PDT) Subject: [Tutor] downloader-script (fwd) Message-ID: ---------- Forwarded message ---------- Date: Fri, 27 Sep 2002 21:07:16 +0200 From: Magnus Lycka To: Danny Yoo Subject: Re: [Tutor] downloader-script At 09:40 2002-09-27 -0700, you wrote: >It's simple, but it has a bug: it assumes that a whole HTML tag lies >entirely on the same line. Woops! Will you fix that on FAQTS? I didn't write it from the start, I just corrected some other bug, but I missed that one. I guess it would be a good thing to show an sgmllib solution as well... :) My paying customer is starting to complain again, so I'd better stay away from tutor etc for a while and do what I should... --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From rob@uselesspython.com Fri Sep 27 22:54:25 2002 From: rob@uselesspython.com (Rob) Date: Fri, 27 Sep 2002 16:54:25 -0500 Subject: [Tutor] W2K environment... In-Reply-To: <4774.199.66.1.5.1033141038.squirrel@www.absolutenettech.com> Message-ID: > thanks for the tip, worked like a charm. also, does NoteTab have any > Python modules or Pythoncentric setup? > thanks, > Not to my knowledge, although I suppose it would be a simple enough matter to add in basic Python support. I haven't bothered, since I'm not aware of a way to add color-coding of keywords and such to NoteTab. I like pretty colors, so I find myself using IDLE, PythonWin, Kobol (I'm sure I've already mentioned this, but it's a COBOL IDE for Windows and Linux that supports syntax highlighting for Python and several other languages.), etc. peace, Rob From steve@openiso.com Fri Sep 27 23:06:55 2002 From: steve@openiso.com (steve lewis) Date: Fri, 27 Sep 2002 17:06:55 -0500 (CDT) Subject: [Tutor] W2K environment... In-Reply-To: References: <4774.199.66.1.5.1033141038.squirrel@www.absolutenettech.com> Message-ID: <5617.199.66.1.5.1033164415.squirrel@www.absolutenettech.com> thanks again rob, will give those a try, i have been testing Komodo by ActiveState. but must settle on one that is linux and windows compatible since i use both. thanks again, steve Rob said: > >> thanks for the tip, worked like a charm. also, does NoteTab have any >> Python modules or Pythoncentric setup? >> thanks, >> > > Not to my knowledge, although I suppose it would be a simple enough > matter to add in basic Python support. I haven't bothered, since I'm > not aware of a way to add color-coding of keywords and such to NoteTab. > I like pretty colors, so I find myself using IDLE, PythonWin, Kobol > (I'm sure I've already mentioned this, but it's a COBOL IDE for Windows > and Linux that supports syntax highlighting for Python and several > other languages.), etc. > > peace, > Rob > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- thanks, steve lewis usa "do or do not, there is no try." yoda From glenbar@gte.net Sat Sep 28 05:11:25 2002 From: glenbar@gte.net (Glen Barnett) Date: Fri, 27 Sep 2002 21:11:25 -0700 Subject: [Tutor] Sending Email Message-ID: <000f01c266a5$322ad4e0$f118153f@gb> This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C2666A.6FFE52A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, I'm trying to send email but I get this error: >>> import smtplib >>> s=3Dsmtplib.SMTP("localhost") Traceback (most recent call last): File "", line 1, in ? s=3Dsmtplib.SMTP("localhost") File "C:\PYTHON22\lib\smtplib.py", line 234, in __init__ (code, msg) =3D self.connect(host, port) File "C:\PYTHON22\lib\smtplib.py", line 283, in connect raise socket.error, msg error: (10061, 'Connection refused') >>>=20 I'm connected to my ISP while I try it. Is there something else I need = to use for the host? Thanks ------=_NextPart_000_000A_01C2666A.6FFE52A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi all,
 
I'm trying to send email but I get this error:
 

>>> import smtplib
>>>=20 s=3Dsmtplib.SMTP("localhost")
Traceback (most recent call = last):
  File=20 "<pyshell#2>", line 1, in ?
   =20 s=3Dsmtplib.SMTP("localhost")
  File = "C:\PYTHON22\lib\smtplib.py", line=20 234, in __init__
    (code, msg) =3D = self.connect(host,=20 port)
  File "C:\PYTHON22\lib\smtplib.py", line 283, in=20 connect
    raise socket.error, msg
error: (10061,=20 'Connection refused')
>>>
 
I'm connected to my ISP while I try it. Is there something else I = need to=20 use for the host?
 
Thanks
------=_NextPart_000_000A_01C2666A.6FFE52A0-- From dyoo@hkn.eecs.berkeley.edu Sat Sep 28 05:49:40 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 27 Sep 2002 21:49:40 -0700 (PDT) Subject: [Tutor] Sending Email In-Reply-To: <000f01c266a5$322ad4e0$f118153f@gb> Message-ID: On Fri, 27 Sep 2002, Glen Barnett wrote: > >>> import smtplib > >>> s=smtplib.SMTP("localhost") > Traceback (most recent call last): > File "", line 1, in ? > s=smtplib.SMTP("localhost") > File "C:\PYTHON22\lib\smtplib.py", line 234, in __init__ > (code, msg) = self.connect(host, port) > File "C:\PYTHON22\lib\smtplib.py", line 283, in connect > raise socket.error, msg > error: (10061, 'Connection refused') > >>> > > I'm connected to my ISP while I try it. Is there something else I need > to use for the host? Hi Glen, On your line here: > >>> s=smtplib.SMTP("localhost") that address there should be that of your SMTP mail server --- it probably shouldn't be 'localhost' because that's refering to your computer, not the ISP's computer. Check your email setup, and you should be able to find something that refers to your ISP's SMTP server. Once you've set this to the appropriate server, you shouldn't get that error message anymore. Hope this helps! From idiot1@netzero.net Sat Sep 28 08:08:44 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 28 Sep 2002 03:08:44 -0400 Subject: [Tutor] wheel.py Message-ID: <3D95557C.66776E2F@netzero.net> ok, I long ago wrote code to randomly pick a line from a file and return it for use in a web page, and it handles banners and quotes and such. But I wanted to see if I could write a script to play such data IN A SEQUENCE, so it would go around and around in an orderly manner- a wheel, so to speak, with each entry a 'spoke'. This way I could have a source file and it would display them in a preset pattern, and begin again when the end was reached. Note this thing rewrites the file with the count for the next item in the first line, and resets it to zilch when the end is reached. The source file is a flat plain vanilla text file, and any text editor will serve- and html code is fine, as are lines of any length, so it could handle a book. Here is that script (latter portion of letter). Here is a link to the demo page: http://www.tinylist.org/testwheel.shtml Here is a link to a page listing the actual working script in the server: http://www.tinylist.org/viewwheel.shtml The script: #!/usr/local/bin/python import string, sys #declare what to import- not much really. def gangstrip(thing): # ok, everybody STRIP! index=0 # This strips out whitespace chars while index < len(thing): #240 define exit thing[index]=string.strip(thing[index]) index=index+1 # increase the counter # file=sys.argv[1] # extract the file to examine f1=open(file,'r') # open it, totalfile=f1.readlines() # read it all in, f1.close() gangstrip(totalfile) # see, them newline chars really mess things up! next=int(totalfile[0]) # read that first line in, conveting to a number, wheel=totalfile[1:] # then all the other lines into a seperate variable, size=len(wheel) # which we want to measure the size of. if next >= size: # if next has reached or exceeded the limit, next = 0 # start over at the beginning. # comment out the next line if not needed, remove the '#' if it is. #print "Content-type: text/html\n" # this tells the http server what this is print wheel[next] # then print the spoke, next= next + 1 # and increment the count. f1=open(file,'w') # now increment the count, f1.write(str(next)+"\n") # and write that as a string to the file, for i in wheel: # and write out all the spokes f1.write(i+"\n") # followed by the wheel. f1.close() # and close the file # that's it! -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From kyle@sent.com Sat Sep 28 12:40:23 2002 From: kyle@sent.com (Kyle Babich) Date: Sat, 28 Sep 2002 11:40:23 UT Subject: [Tutor] pygame help Message-ID: <20020928114024.07DAA936D1@server2.fastmail.fm> Today I downloaded the pygame exe for python 2.2 on win32 into my c:\ and installed it into c:\python22. I was able to "import pygame" but anything else like "import pygame.CD" tells me the module doesn't exist. What did I do wrong? Thank you, -- Kyle From johnharvey@earthlink.net Sat Sep 28 16:48:14 2002 From: johnharvey@earthlink.net (John Harvey) Date: Sat, 28 Sep 2002 08:48:14 -0700 Subject: [Tutor] pygame help In-Reply-To: <20020928114024.07DAA936D1@server2.fastmail.fm> Message-ID: <5.1.1.6.0.20020928082210.01986ee0@pop.earthlink.net> At 11:40 AM 9/28/2002 +0000, Kyle Babich wrote: >Today I downloaded the pygame exe for python 2.2 on win32 into my c:\ >and installed it into c:\python22. I was able to "import pygame" but >anything else like "import pygame.CD" tells me the module doesn't >exist. What did I do wrong? I'm in the process of learning how one answers this kind of question with a new Python package. Maybe one of the old timers here could point us to a tutorial regarding the use of the help system. After seeing your question I downloaded pygame and tried to find the answer to your question. If my understanding is correct, you can find the names of the modules in pygame as follows: >>>help(pygame) --OR-- >>>help() help>pygame Either of these yield the following: -----8<----------snip---------->8----- PACKAGE CONTENTS SDL SDL_image SDL_mixer SDL_ttf __init__ base cdrom constants cursors display draw -----8<----------snip---------->8----- Which means that there isn't a module named CD. help> pygame.cdrom yields: -----8<----------snip---------->8----- FUNCTIONS CD(...) pygame.cdrom.CD(id) -> CD create new CD object Creates a new CD object for the given CDROM id. The given id must be less than the value from pygame.cdrom.get_count(). -----8<----------snip---------->8----- Therefore, CD is a function (not a module) of the cdrom module of the pygame package. From lbrannma@cablespeed.com Sat Sep 28 18:27:41 2002 From: lbrannma@cablespeed.com (Lance) Date: Sat, 28 Sep 2002 10:27:41 -0700 Subject: [Tutor] Speed guidelines Message-ID: <001401c26714$592810c0$3212eb42@MYNEWBOX> This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C266D9.ACA499C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I saw a very brief discussion of execution speed in the Python Cookbook, = relating to one of the examples (a filter is faster than a list = comprehension). Can anyone suggest where I might find a general = discussion of execution speed in Python? Thanks, Lance ------=_NextPart_000_0011_01C266D9.ACA499C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
I saw a very brief discussion of = execution speed in=20 the Python Cookbook, relating to one of the examples (a filter is faster = than a=20 list comprehension). Can anyone suggest where I might find a general = discussion=20 of execution speed in Python?
 
Thanks,
Lance
 
------=_NextPart_000_0011_01C266D9.ACA499C0-- From dyoo@hkn.eecs.berkeley.edu Sat Sep 28 20:58:55 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 28 Sep 2002 12:58:55 -0700 (PDT) Subject: [Tutor] Re: [Python-Help] Example Source Code In-Reply-To: <20020928190759.41695.qmail@web40012.mail.yahoo.com> Message-ID: On Sat, 28 Sep 2002, Mr. Smiley wrote: > Hello fellow Python Developers, > > I am new to the Python language and have been studying it extensively, > but I have found that I learn better when there is example source code > out there. Do you know of any web-sites who provide example source code. > I have tried searching in the various documentation on the web-site and > looked extensively on the Python search engine but could not find > anything. Thanks for the help. [I'm taking python-help out of CC] Hello! Yes, there's a site called "Useless Python" that collects source code from people here on Tutor. If you're interested, you can visit it here: http://uselesspython.com For more advanced stuff, people have been collecting Python snippets in the "Python Cookbook": http://aspn.activestate.com/ASPN/Python/Cookbook/ I hope these resources will help make your Python knowledge more concrete. If you have more questions, please feel free to ask on Tutor! From magnus@thinkware.se Sat Sep 28 21:55:26 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 28 Sep 2002 22:55:26 +0200 Subject: [Tutor] wheel.py In-Reply-To: <3D95557C.66776E2F@netzero.net> Message-ID: <5.1.0.14.0.20020928220207.02aa5ae8@www.thinkware.se> I'm taking the liberty to reinvent your wheel! ;) Since you are rewriting your file on every run to store your index number, you might as well swap the lines around instead. Always read from the top and place that line last when you are done. Skip the number. (Beware, untested code follows) ---- fileName=sys.argv[1] f=open(fileName,'rt'), textList=f.readlines() f.close() firstLine = textList.pop(0) print firstLine.strip() textList.append(firstLine) f=open(file,'wt') f.writelines(textList) f.close() ---- If the text file is big, it might be better to keep the index in a separate file and use your indexing scheme. Both files are now given as arguments. (Another option would be to have myfile.txt and myfile.ix etc.) BTW, the official way to open a file is now "file()". (See library reference.) ---- indexFileName, dataFileName=sys.argv[1:3] # To make sure this works in Jython we must explicitly # close the file we'll later open for writing. # In CPython we could write it more compact as # index = int(file(indexFileName, 'rt').read()) ixFile = file(indexFileName, 'rt') index = int(ixFile.read()) ixFile.close() text = file(dataFileName, 'rt').readlines() try: print text[index].strip() index += 1 except IndexError: print text[0].strip() index = 1 ixFile = file(indexFileName, 'wt') ixFile.write(str(index)) ixFile.close() ---- Finally, if the file is very big, we don't want to read in more than we have to... ---- indexFileName, dataFileName=sys.argv[1:3] ixFile = file(indexFileName, 'rt') index = int(ixFile.read()) ixFile.close() i = 0 for line in file(dataFileName, 'rt'): if i == 0: lineZero = line if i == index: print line.strip() index += 1 break i += 1 else: print lineZero.strip() index = 1 ixFile = file(indexFileName, 'wt') ixFile.write(str(index)) ixFile.close() ---- If it's even bigger...we'll use a database of some sort. import anydbm etc... Another day... -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From CCampbell@ede.org Sat Sep 28 22:06:12 2002 From: CCampbell@ede.org (Colin Campbell) Date: Sat, 28 Sep 2002 15:06:12 -0600 Subject: [Tutor] Turn a file into a dictionary Message-ID: <3D9619C4.8070009@ede.org> Hello Python gurus! I have a file containing a series of records. Each record consists of a username in the first field, then a comma separated list of a variable number of tab names.I optimistically built the file in what I thought would be the form of a dictionary: {user1:tab3,tab5} {User2:tab1,tab2,tab3,tab4,tab5} with the intent of simply writing: f=open('C:\Other\Prg\ACL.CSV','r') dict=f.readlines() Regrettably, this turns each record into a string, rather than a dictionary entry. My question, then, is: do I need to readline() records one by each, parsing the resulting string into a key:(list) sort of form or is there a more pythonic way of doing it as a single operation? I don't mind record level processing where it's absolutely necessary, but if it can be avoided, I find the result cleaner and easier to read. Any advice or links where I can RTFM will be valued. rgds, Colin -- A closed mouth gathers no feet. -Unattributed From magnus@thinkware.se Sat Sep 28 22:11:54 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 28 Sep 2002 23:11:54 +0200 Subject: [Tutor] Speed guidelines In-Reply-To: <001401c26714$592810c0$3212eb42@MYNEWBOX> Message-ID: <5.1.0.14.0.20020928230700.02af1e68@www.thinkware.se> At 10:27 2002-09-28 -0700, Lance wrote: >I saw a very brief discussion of execution speed in the Python Cookbook, >relating to one of the examples (a filter is faster than a list >comprehension). >Can anyone suggest where I might find a general discussion of execution >speed in Python? Sure, see http://www.thinkware.se/cgi-bin/thinki.cgi/PythonPerformance But most importantly: it's usually rather simple to measure, and that's really the only way to be certain... -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Sat Sep 28 22:53:05 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sat, 28 Sep 2002 23:53:05 +0200 Subject: [Tutor] Turn a file into a dictionary In-Reply-To: <3D9619C4.8070009@ede.org> Message-ID: <5.1.0.14.0.20020928232459.02b06cc8@www.thinkware.se> At 15:06 2002-09-28 -0600, Colin Campbell wrote: >Hello Python gurus! > >I have a file containing a series of records. Each record consists of a >username in the first field, then a comma separated list of a variable >number of tab names.I optimistically built the file in what I thought >would be the form of a dictionary: > >{user1:tab3,tab5} >{User2:tab1,tab2,tab3,tab4,tab5} A python dictionary would be d = {user1: (tab3,tab5), User2:(tab1,tab2,tab3,tab4,tab5)} right? You don't want a separate dictionary with just one key for each user, do you? >with the intent of simply writing: > >f=open('C:\Other\Prg\ACL.CSV','r') >dict=f.readlines() When you read a text file with .readlines(), you get a list of strings. Nothing else. I think you understand that text files can contain lots of things, and Python can't by magic assume that it should interpret read text as code, even if the text would look like code. That would certainly cause much more grief than happiness. What if you write a python programmers editor, and instead of presenting your code in the editor, it tries to execute it when you open a file? For python to interpret a file as code, you typically use import, but you can for instance read it in like a string and use the eval() function to evaluate it as python code. (There is also exec() etc.) So, if you wrote your file as: user1: (tab3,tab5), User2:(tab1,tab2,tab3,tab4,tab5), you could do: myFileText = file(filename).read() d = eval("{ %s }" % myFileText) and you would get: d = {user1: (tab3,tab5), User2:(tab1,tab2,tab3,tab4,tab5)} But what happened here? user1, tab3 etc are assumed to be variable names. So for this to work, there must already be variable with these names in your code, or you will get NameError: name 'user1' is not defined I would certainly not recommend using this strategy. Maybe the dict you wanted was really? d = {'user1': ('tab3','tab5'), 'User2':('tab1','tab2','tab3','tab4','tab5')} A dictionary with a string as key, and a tuple of strings as value? In that case I'd recommend that you simply write your file as: user1, tab3, tab5 User2, tab1, tab2, tab3, tab4, tab5 And do: d = {} for line in file(filename, 'rt'): items = [x.strip() for x in line.split(',')] d[items[0]] = tuple(items[1:]) A similar situation would be to read a unix passwd file. There items are separated by : and arbitrary whitespace is not allowed if memory serves me right. Then it would be: users = {} for line in file('/etc/passwd', 'rt'): items = line.rstrip().split(':') users[items[0]] = tuple(items[1:]) -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From wolf_binary@hotmail.com Sun Sep 29 03:23:32 2002 From: wolf_binary@hotmail.com (CameronStoner) Date: Sat, 28 Sep 2002 19:23:32 -0700 Subject: [Tutor] classes and inheritance Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C26724.8861F580 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Say I have a class Animal , Mamal, and Human. Then go on to say that = Mamal inherits from Animal and that Human does from Mamal. Can you make = an object from Mamal that then is a generic Mamal that doesn't have the = attributes of Human and is this a good programming practice? Thanks, Cameron Stoner ------=_NextPart_000_0008_01C26724.8861F580 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
Say I have a class Animal , Mamal, = and=20 Human.  Then go on to say that  Mamal inherits from Animal and = that=20 Human does from Mamal.  Can you make an object from Mamal that then = is a=20 generic Mamal that doesn't have the attributes of Human and is this a = good=20 programming practice?
 
Thanks,
Cameron = Stoner
------=_NextPart_000_0008_01C26724.8861F580-- From magnus@thinkware.se Sun Sep 29 03:35:21 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 29 Sep 2002 04:35:21 +0200 Subject: [Tutor] classes and inheritance In-Reply-To: Message-ID: <5.1.0.14.0.20020929041150.02ae6d60@www.thinkware.se> At 19:23 2002-09-28 -0700, "CameronStoner" wrote: >Hi all, > >Say I have a class Animal , Mamal, and Human. Then go on to say=20 >that Mamal inherits from Animal and that Human does from Mamal. Can you= =20 >make an object from Mamal that then is a generic Mamal that doesn't have=20 >the attributes of Human and is this a good programming practice? Well... Yes and no... It's really pointless to dicuss classes without knowing what kind of problem you are trying to solve. Classes are not written to model the world, but to serve some kind of function. I think you will be better of if you think of a concrete program, and the classes evolve because they are needed in the program, not being written as an empty exercise. Anyway, all animals are of a species. You will never see a "generic animal" walking in the forest. So, if your classes are to correspond to the real world, you will never have any instances of the animal class. It will be an abstract base class. Although, this might not be true... Your program might be working with generalizations in a concrete way I suppose... There are certainly base classes that aren't abstract though. But not if the base class represents some kind of generalizations that don't have an individual real work existence. You can imagine a person class that you use as it is in an address book program. A person has a name, and one or several addresses, phone numbers, email addresses etc. You reuse this class in a HR application, but there you need some extra features, so you subclass an employee class which keeps track of salary, vacation status, manager, pension fund payments etc. And in the sales contact program you make another subclass from person called sucker, no I mean customer of course, keeping tracks of orders, complaints and preferences etc. In this case, person is a concrete base class. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From idiot1@netzero.net Sun Sep 29 04:00:56 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 28 Sep 2002 23:00:56 -0400 Subject: [Tutor] wheel.py References: <3D95557C.66776E2F@netzero.net> <20020928111404.GB401@silmarill.org> Message-ID: <3D966CE8.F52AA1BB@netzero.net> Actually, not really, as if it's written right there are no such errors, and to do what you sugegest, it still has to rewrite the file, and if there are errors, it will write errors. But I DID have the idea of looping the wheel, writing it out again to the file FROM THE NEXT ITEM FIRST TO THE ONE JUST PRINTED OUT AS LAST, dispensing with the counter altogether. It actually would ROTATE the data through the physical file's sequence one spoke at a time. Andrei Kulakov wrote: > [snip unimportant part] > Wouldn't it be easier to keep a copy of the main file, grab one line out > of eat each invocation and delete it, and when no lines are left, copy the > main file again into its place? That way you don't have to keep track of > error-prone counters at all... > > - andrei -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From idiot1@netzero.net Sun Sep 29 04:02:35 2002 From: idiot1@netzero.net (Kirk Bailey) Date: Sat, 28 Sep 2002 23:02:35 -0400 Subject: [Tutor] wheel.py References: <5.1.0.14.0.20020928220207.02aa5ae8@www.thinkware.se> Message-ID: <3D966D4B.C99424B@netzero.net> Actually, AFTER I got everything right, it occurred to me to do it this way. But it's working, and I have a kinkier idea cooking... Magnus Lycka wrote: > > I'm taking the liberty to reinvent your wheel! ;) > > Since you are rewriting your file on every run > to store your index number, you might as well swap > the lines around instead. Always read from the top > and place that line last when you are done. Skip > the number. > > (Beware, untested code follows) > > ---- > fileName=sys.argv[1] > > f=open(fileName,'rt'), > textList=f.readlines() > f.close() > > firstLine = textList.pop(0) > print firstLine.strip() > textList.append(firstLine) > > f=open(file,'wt') > f.writelines(textList) > f.close() > ---- > > If the text file is big, it might be better > to keep the index in a separate file and > use your indexing scheme. Both files are > now given as arguments. (Another option > would be to have myfile.txt and myfile.ix > etc.) > > BTW, the official way to open a file is now > "file()". (See library reference.) > > ---- > indexFileName, dataFileName=sys.argv[1:3] > > # To make sure this works in Jython we must explicitly > # close the file we'll later open for writing. > # In CPython we could write it more compact as > # index = int(file(indexFileName, 'rt').read()) > ixFile = file(indexFileName, 'rt') > index = int(ixFile.read()) > ixFile.close() > > text = file(dataFileName, 'rt').readlines() > > try: > print text[index].strip() > index += 1 > except IndexError: > print text[0].strip() > index = 1 > > ixFile = file(indexFileName, 'wt') > ixFile.write(str(index)) > ixFile.close() > ---- > > Finally, if the file is very big, we don't want to read > in more than we have to... > > ---- > indexFileName, dataFileName=sys.argv[1:3] > > ixFile = file(indexFileName, 'rt') > index = int(ixFile.read()) > ixFile.close() > > i = 0 > for line in file(dataFileName, 'rt'): > if i == 0: lineZero = line > if i == index: > print line.strip() > index += 1 > break > i += 1 > else: > print lineZero.strip() > index = 1 > > ixFile = file(indexFileName, 'wt') > ixFile.write(str(index)) > ixFile.close() > ---- > > If it's even bigger...we'll use a database of some > sort. import anydbm etc... Another day... > > -- > Magnus Lycka, Thinkware AB > Alvans vag 99, SE-907 50 UMEA, SWEDEN > phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 > http://www.thinkware.se/ mailto:magnus@thinkware.se -- end Respectfully, Kirk D Bailey +---------------------"Thou Art Free." -Eris-----------------------+ | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net | | KILL spam dead! http://www.scambusters.org/stopspam/#Pledge | | http://www.tinylist.org +--------+ mailto:grumpy@tinylist.org | +------------------Thinking| NORMAL |Thinking----------------------+ +--------+ ------------------------------------------- Introducing NetZero Long Distance Unlimited Long Distance only $29.95/ month! Sign Up Today! www.netzerolongdistance.com From dyoo@hkn.eecs.berkeley.edu Sun Sep 29 10:38:22 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 29 Sep 2002 02:38:22 -0700 (PDT) Subject: [Tutor] classes and inheritance [a walk on flatland] In-Reply-To: <5.1.0.14.0.20020929041150.02ae6d60@www.thinkware.se> Message-ID: On Sun, 29 Sep 2002, Magnus Lycka wrote: > >Say I have a class Animal, Mamal, and Human. Then go on to say that > >Mamal inherits from Animal and that Human does from Mamal. Can you > >make an object from Mamal that then is a generic Mamal that doesn't > >have the attributes of Human and is this a good programming practice? > > Well... Yes and no... A good elvish answer. *grin* > It's really pointless to dicuss classes without knowing what kind of > problem you are trying to solve. Classes are not written to model the > world, but to serve some kind of function. Hi Cameron, Just as a side note: it's my feeling that too many OOP examples in textbooks put way more emphasis on inheritance than is necessary. Let's pretend that we're doing a simulation of the universe. Hmmm... that's a bit too big. Let's do something simpler: let's simulate a flat line. What we can imagine are objects that are walking on a straight line: each object can decide to either step to the left, or to the right. It's like an ant farm... except in 2d. *grin* Let's call these things "Walkers". A walker has a simple life: it can move either "L"eft or "R"ight. For this particular problem, we'll say that it's nonsense to construct a vanilla one --- we want people to subclass new walkers, to give them color, and we can force the issue by raising an exception: ### class ImplementationException(Exception): pass class Walker: def walk(self): """Returns either 'L' or 'R', depending if the walker is shifting to the left or to the right. Overwritten by subclasses.""" raise ImplementationException, "not implemented. Override me." ### That is, any subclass of a Walker here will be forced to write an implementation of walk() or face extinction by exception. ### >>> w = Walker() >>> w.walk() Traceback (most recent call last): File "", line 1, in ? File "/tmp/python-830twU", line 18, in walk __main__.ImplementationException: not implemented. Override me. ### This may not be an appropriate thing to do in other circumstances! So that's why your initial question is a "yes" and "no" sort of thing: it really depends on the problem. Here, we just want to force the issue, so we'll say that it should be impossible to instantiate a vanilla Walker. Going back to this Flatland... we can make particular kinds of walkers: 1. Walkers that walk in a single direction. 2. Walkers that pace around. They're impatient. 3. Walkers that just go in random directions. A concrete example of #2 could be: ### class RandomWalker(Walker): """A slightly sillier walker that just goes in a random direction.""" def walk(self): return random.choice(['L', 'R']) ### And now since we've defined how a RandomWalker() walks, we should be all good here. I've gone through and written a program to show these poor walkers pacing around. Here it is for your enjoyment: ### """A toy example of classes and inheritance. Danny Yoo (dyoo@hkn.eecs.berkeley.edu) This reminds me of an old computer game. *grin* """ import random class ImplementationException(Exception): pass class Walker: def walk(self): """Returns either L or R, depending if the walker is shifting to the left or to the right. Overwritten by subclasses.""" raise ImplementationException, "not implemented. Override me." def label(self): """Returns the character label of the walker. Overwritten by subclasses.""" return "?" class LeftWalker(Walker): """A boring implementation of a walker that always moves to the left.""" def walk(self): return "L" def label(self): return "l" class RandomWalker(Walker): """A slightly sillier walker that just goes in a random direction.""" def walk(self): return random.choice(['L', 'R']) def label(self): return "!" class PacingWalker(Walker): def __init__(self, length=20): self.path_length = length / 2 self.delta = 1 self.counter = 0 def walk(self): self.counter = self.counter + 1 if self.counter > self.path_length: self.counter = 0 self.delta = -self.delta if self.delta == 1: return "L" return "R" def label(lelf): return 'p' def clamp(x, low, high): """Forces x to be clamped between a high and low boundary.""" if x < low: return low if x > high: return high return x class WalkerSimulation: def __init__(self, line_width=80): self.walkers = [] self.positions = [] self.line_width = line_width def addWalker(self, w): self.walkers.append(w) self.positions.append(self.line_width / 2) def render(self): line = list(' '*self.line_width) for i in range(len(self.walkers)): pos = clamp(self.positions[i], 0, self.line_width-1) line[pos] = self.walkers[i].label() return ''.join(line) def step(self): for i in range(len(self.walkers)): self._stepSingleWalker(i) def _stepSingleWalker(self, i): next_step = self.walkers[i].walk() if next_step == 'L': self.positions[i] = self.positions[i] - 1 elif next_step == 'R': self.positions[i] = self.positions[i] + 1 else: pass ## no movement def driverLoop(walkers): simulation = WalkerSimulation() for w in walkers: simulation.addWalker(w) while 1: print simulation.render(), user_input = raw_input() if user_input == 'q': break simulation.step() if __name__ == '__main__': print "Hold down enter to watch the walkers walk around." print "To quit, type 'q' and then enter." print "*" * 50 driverLoop([RandomWalker(), PacingWalker(7), PacingWalker(30), LeftWalker(), RandomWalker()]) ### Anyway, sorry about going off on this tangent! But this shows a concrete example of interface inheritance in action, and should be easy to experiment with. Good luck! From charlie@begeistert.org Sun Sep 29 13:29:07 2002 From: charlie@begeistert.org (Charlie Clark) Date: Sun, 29 Sep 2002 12:29:07 +0000 Subject: [Tutor] re: turn a file into a dictionary In-Reply-To: <20020929093802.26719.4729.Mailman@mail.python.org> References: <20020929093802.26719.4729.Mailman@mail.python.org> Message-ID: <20020929122907.2255.6@gormenghast.1033292446.fake> On 2002-09-29 at 09:38:02 [+0000], you wrote: > {user1:tab3,tab5} > {User2:tab1,tab2,tab3,tab4,tab5} > > with the intent of simply writing: > > f=3Dopen('C:\Other\Prg\ACL.CSV','r') > dict=3Df.readlines() > > Regrettably, this turns each record into a string, rather than a > dictionary entry. My question, then, is: do I need to readline() records > one by each, parsing the resulting string into a key:(list) sort of form > or is there a more pythonic way of doing it as a single operation? I > don't mind record level processing where it's absolutely necessary, but > if it can be avoided, I find the result cleaner and easier to read. > > Any advice or links where I can RTFM will be valued. Magnus has already answered the question but I thought I'd mention a couple= of alternatives. First of all, as Magnus points out, you could do: myFileText =3D file(filename).read() d =3D eval("{ %s }" % myFileText) He advises you against this - the reason being that 'eval' won't do any security checking. It's conceivable, therefore, that your file contains some text will might be dangerous when run as Python code. This kind of security risk is common to all programming languages notably cgi and SQL. What do you want to do with your file? ie. how do you want to manage data in the future: by direct manipulation of the textfile in a text editor or through your program? If you still need to edit the textfile you're best following Magnus' suggestion. If not you will might consider using the pickle or shelve module to store your data and thus avoid the overhead of converting from string to dictionary and back again. Pickle and shelve use textfiles to store binary data such as dictionaries. Pickle is a generic tool for storing all kinds of Python objects in textfiles whereas shelve is= specifically for dictionaries. You can edit the textfiles thus created if you are really careful but it's not advisable. XML-Pickle may give you the best of both worlds allowing you to manage your data either in a text editor or in a program. Charlie -- Charlie Clark Helmholtzstr. 20 D=1Asseldorf D- 40215 Tel: +49-211-938-5360 GSM: +49-178-782-6226 From wolf_binary@hotmail.com Sun Sep 29 17:10:20 2002 From: wolf_binary@hotmail.com (CameronStoner) Date: Sun, 29 Sep 2002 09:10:20 -0700 Subject: [Tutor] classes and inheritance References: <5.1.0.14.0.20020929041150.02ae6d60@www.thinkware.se> Message-ID: I do have a concrete program I am making. It's a game. I don't know if you know anything about Japanese Anime, but it has some gundam things in it. (gundams are big robots piloted by people) I was thinking of making a series of inheritance that would then result in a final subclass called player that would have all the components necessary to describe that player without having to make new objects out of the classes. I was going to make one object and then have a whole bunch of actions that could be placed upon the player. I still ,however, need to be able to make computer controled opponents that are of the gundam class. See example: class User: data: name (used for saving and file name) passwrd actions: get name get passwrd class gundam inherits from User: data: gundam name gundam health actions: get gundam name get gundam health class player inherits from gundam: data: character's name character's health actions: get character's name get character's health OOP seemed to be the only way to feezably handle what was going on in an easier way than the usual functional programming. Thank, Cameron Stoner >Say I have a class Animal , Mamal, and Human. Then go on to say >that Mamal inherits from Animal and that Human does from Mamal. Can you >make an object from Mamal that then is a generic Mamal that doesn't have >the attributes of Human and is this a good programming practice? Well... Yes and no... It's really pointless to dicuss classes without knowing what kind of problem you are trying to solve. Classes are not written to model the world, but to serve some kind of function. I think you will be better of if you think of a concrete program, and the classes evolve because they are needed in the program, not being written as an empty exercise. From glingl@aon.at Sun Sep 29 17:40:51 2002 From: glingl@aon.at (Gregor Lingl) Date: Sun, 29 Sep 2002 18:40:51 +0200 Subject: [Tutor] How to subclass built-in types? Message-ID: <3D972D13.8020304@aon.at> Hi pythonistas! This time I have the following question: If I subclass the built-in type list as follows: >>> class L(list): pass >>> a = L() >>> a [] >>> b = L([1,2,3]) >>> b [1, 2, 3] >>> c = L("xyz") >>> c ['x', 'y', 'z'] >>> So L seems to use list as a constructor or at least behaves as if. Next example: >>> class M(list): def __init__(self, x): self.x = x >>> e = M(3) >>> e [] >>> e.x 3 This constructor only constructs empty lists. Now, how do I define a constructor, which, for instance as the first argument takes a sequenze to initialize itself (as a list) and more arguments for other purposes. This class should behave like the following: >>> class N(list): def __init__(self, seq, x): self.x = x self.extend(seq) >>> f = N( (3,4,5), "C" ) >>> f [3, 4, 5] >>> f.x 'C' >>> However, I think that this is not the canonical way to do things like this, because it depends on the existence of the extend - method, which exists only for lists, whereas the given problem is one which applies to subclassing built-in types in general. Who knows how to do it "according to the rules"? Regards, Gregor From dman@dman.ddts.net Sun Sep 29 18:15:59 2002 From: dman@dman.ddts.net (Derrick 'dman' Hudson) Date: Sun, 29 Sep 2002 13:15:59 -0400 Subject: [Tutor] Re: How to subclass built-in types? In-Reply-To: <3D972D13.8020304@aon.at> References: <3D972D13.8020304@aon.at> Message-ID: <20020929171559.GA5648@dman.ddts.net> --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 29, 2002 at 06:40:51PM +0200, Gregor Lingl wrote: | Next example: |=20 | >>> class M(list): | def __init__(self, x): | self.x =3D x | | >>> e =3D M(3) | >>> e | [] | >>> e.x | 3 |=20 | This constructor only constructs empty lists. | Now, how do I define a constructor, which, for instance as | the first argument takes a sequenze to initialize itself (as | a list) and more arguments for other purposes. |=20 | This class should behave like the following: |=20 | >>> class N(list): | def __init__(self, seq, x): | self.x =3D x list.__init__( self , seq ) #^^^^ superclass object | Who knows how to do it "according to the rules"? It's the same as for non-builtin types. (note: python >=3D 2.2 must be used to subclass built-in types) -D --=20 If your life is a hard drive, Christ can be your backup. =20 http://dman.ddts.net/~dman/ --r5Pyd7+fXNt84Ff3 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj2XNU8ACgkQO8l8XBKTpRS1iwCfX7atGDUyWkiOdlqME7lvJ5M4 Gc8AniRUecrAJAFhaorAdvil22PNDQKB =Ei7h -----END PGP SIGNATURE----- --r5Pyd7+fXNt84Ff3-- From glingl@aon.at Sun Sep 29 18:07:21 2002 From: glingl@aon.at (Gregor Lingl) Date: Sun, 29 Sep 2002 19:07:21 +0200 Subject: [Tutor] Re: How to subclass built-in types? References: <3D972D13.8020304@aon.at> <20020929171559.GA5648@dman.ddts.net> Message-ID: <3D973349.1000805@aon.at> Derrick 'dman' Hudson schrieb: > >| >>> class N(list): >| def __init__(self, seq, x): >| self.x = x > list.__init__( self , seq ) > #^^^^ superclass object > >| Who knows how to do it "according to the rules"? > >It's the same as for non-builtin types. (note: python >= 2.2 must be >used to subclass built-in types) > >-D > > > Many thanks, that was it! How simple! (Should have done a look at dir(list)). Gregor From ericblack69@yahoo.com Sun Sep 29 19:26:45 2002 From: ericblack69@yahoo.com (Eric Black) Date: Sun, 29 Sep 2002 11:26:45 -0700 (PDT) Subject: [Tutor] wish and tkinter Message-ID: <20020929182645.92102.qmail@web40611.mail.yahoo.com> hello all, i've just downloaded Python 2.2.1 from ActiveState for Windows. >>> import Tkinter >>> import _tkinter >>> Tkinter._test() all of these work. but i can't use the demos in the tk8.3 directory. i get a message saying must use wish.exe. find can't find that file. Does any one know where to get wish.exe and where to put it so an exec command can find it and i can run these demos? TIA, Eric Black __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com From magnus@thinkware.se Sun Sep 29 22:49:41 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Sun, 29 Sep 2002 23:49:41 +0200 Subject: [Tutor] wish and tkinter In-Reply-To: <20020929182645.92102.qmail@web40611.mail.yahoo.com> Message-ID: <5.1.0.14.0.20020929233821.02a559c0@www.thinkware.se> At 11:26 2002-09-29 -0700, Eric Black wrote: >hello all, > >i've just downloaded Python 2.2.1 from ActiveState for >Windows. > >>> import Tkinter > >>> import _tkinter > >>> Tkinter._test() >all of these work. >but i can't use the demos in the tk8.3 directory. i >get a message saying must use wish.exe. find can't >find that file. >Does any one know where to get wish.exe and where to >put it so an exec command can find it and i can run >these demos? I assume www.scriptics.com has them, but those things have nothing to do with Python, so I wouldn't bother. The Python programming language has no GUI of it's own. The Tkinter module "piggybacks" on the Tcl programming language and its Tk GUI toolkit. This means that you need parts of Tcl/Tk installed to run Tkinter. (I thought tcl83.dll and tk83.dll was enough though.) If you want to investigate Tkinter, have a look at: http://www.python.org/topics/tkinter/ , http://www.python.org/doc/life-preserver/ and http://www.pythonware.com/library/tkinter/introduction/ --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From dyoo@hkn.eecs.berkeley.edu Sun Sep 29 23:15:53 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 29 Sep 2002 15:15:53 -0700 (PDT) Subject: [Tutor] wish and tkinter In-Reply-To: <5.1.0.14.0.20020929233821.02a559c0@www.thinkware.se> Message-ID: > > >>> import Tkinter > > >>> import _tkinter > > >>> Tkinter._test() > >all of these work. but i can't use the demos in the tk8.3 directory. > >i get a message saying must use wish.exe. find can't find that file. > >Does any one know where to get wish.exe and where to put it so an exec > >command can find it and i can run these demos? > > I assume www.scriptics.com has them, but those things have nothing to do > with Python, so I wouldn't bother. > > The Python programming language has no GUI of it's own. The Tkinter > module "piggybacks" on the Tcl programming language and its Tk GUI > toolkit. > > This means that you need parts of Tcl/Tk installed to run Tkinter. (I > thought tcl83.dll and tk83.dll was enough though.) Hello! Those demo files are specifically for TK stuff only, and not for Python/Tkinter. 'wish' stands for "WIndowing SHell", and Tcl/Tk uses that. I think the ActiveState folks just bundled a bit too much, and accidently included the Tk-only demos. Best of wishes! From dyoo@hkn.eecs.berkeley.edu Sun Sep 29 23:37:07 2002 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 29 Sep 2002 15:37:07 -0700 (PDT) Subject: [Tutor] First Serious Num-Python Prog. In-Reply-To: Message-ID: On Wed, 25 Sep 2002, Karthikesh Raju wrote: > The following is my first serious python program. This does LS based > estimation. i havent commented it but i was filled with enthu that i > wanted to get the comments of people on how better i could do and the > means and methods to imporve this. (Please leave the comments and the > synthetic ones). Hi Karthikesh, Have you gotten any responses yet? If not, this is probably because many of us haven't had extensive experience with Numeric; you may get a better response by posting on a forum that focuses on Numeric issues. >From a straightforward programming standpoint, I'll try to offer some suggestions. Let's take a look at some of your code: ###### # generate the signal i = indices = arange(1,162) x = -8 + (i-1)/10.0 a0 = 0 a1 = -100 a2 = 0 a3 = 1 z = a0 + a1*x + a2*x**2 + a3*x**3 ###### I'm not sure what all these variables are, but I'll assume that 'z' is the ultimate result that we want out of these statements. If so, perhaps we can wrap these statements into a single function called "generate_signal()": ### def generate_signal(): i = indices = arange(1,162) x = -8 + (i-1)/10.0 a0 = 0 a1 = -100 a2 = 0 a3 = 1 z = a0 + a1*x + a2*x**2 + a3*x**3 return z ### This adds no additional functionality, but does emphasize the fact that 'i', 'x', 'a0', 'a1', 'a2', and 'a3' are just temporary "scratchpaper" local variables that are being used to build up 'z'. This same kind of function wrapping can be applied to other chunks of your code. It's not quite clear what the significance of "162" holds in this code. Can you explain what it means? Let's take a look at a few more chunks of code: ###### # generate Nosie Sigma = sqrt(10) v = normal(0,Sigma,161) # generate Noisy Signal y = z + v # generate signal with outliers replace = randint(1,161,17) for ind in range(17): y[replace[ind]] = random()*400 ###### If I understand this code correctly, I think we can apply a similar function factorization to those three chunks: ### def generate_noise(): """Creates a new noisy signal.""" Sigma = sqrt(10) v = normal(0,Sigma,161) return v def generate_noisy_signal(signal): """Given a signal, returns a new signal with noise.""" return signal + generate_noise() def add_outliers(signal): """Modifies a preexisting signal with outliers.""" replace = randint(1,161,17) for ind in range(17): signal[replace[ind]] = random()*400 ### Whenever you feel the need to put a comment for a block of code, that's a prime target for this function treatment. *grin* With these changes, your main code will look like this: ### z = generate_signal() z = generate_noisy_signal(z) add_outliers(z) ### And in this version, the overall motion of the the program is easier to see --- it doesn't get lost within the particular details of generating noise or outliers. We use functions to wrap the details of events: in a sense, we're turning multiple, disconnected statements into compound verbs. I hope this helps! From alan.gauld@bt.com Sun Sep 29 23:39:06 2002 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 29 Sep 2002 23:39:06 +0100 Subject: [Tutor] classes and inheritance Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C909@mbtlipnt02.btlabs.bt.co.uk> PMFJI America was great, but I'm back and got this was my first tutor email after resuming the feed... > class User: > data: > name (used for saving and file name) > passwrd > actions: > get name > get passwrd Recall responsibility driven design is the key to good OO. What are the responsibilities of the objects, not the data they contain? Now maybe a User object has the responsibility to manage user names/passwords but what else does it DO? Those are the methods you need to focus on, then just add the necessary data to support that. Thus you need change password as a method probably. But maybe also you need to monitor status of users - alive/dead/numer of lives etc depending on the rules of the game... I could be way off line here, but every time I see a class where the only methods are get/set methods of the data I get nervous. Its nearly always the wrong design. As regards the subclasses you don't need to repeat the data/operations since they are already specified when you say you inherit from User... Finally I concur with the bottom comment about instantiating abstract classes. You might use the subclasses *as if* they were higher level abstracts but you would likely never instantiate an abstract directly. Alan G. From nano@intermatik.co.id Mon Sep 30 05:31:33 2002 From: nano@intermatik.co.id (nano) Date: 30 Sep 2002 11:31:33 +0700 Subject: [Tutor] downloader-script In-Reply-To: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> References: <1033114241.4768.15.camel@jrwd.internal.intermatik.com> Message-ID: <1033360362.3162.12.camel@jrwd.internal.intermatik.com> hi guys, thanks for all your help. i'll try all your suggestion first. i'll ask for help again if i need some help again. thanks very much. sincerely, nano' --let's make our world better-- From glingl@aon.at Mon Sep 30 07:57:50 2002 From: glingl@aon.at (Gregor Lingl) Date: Mon, 30 Sep 2002 08:57:50 +0200 Subject: [Tutor] New classes Message-ID: <3D97F5EE.60902@aon.at> Hi! I'm on my way to discover the secrets of new type classes. Despite of the fact, that some (or all) of what I want to know might have been discussed recently, I dare to ask the following: >>> class C: pass >>> class N(object): pass >>> c=C() >>> n=N() >>> c <__main__.C instance at 0x0093C160> >>> n <__main__.N object at 0x0092D158> >>> dir(c) ['__doc__', '__module__'] >>> dir(n) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__repr__', '__setattr__', '__str__', '__weakref__'] >>> So there seem to be substantial differences. Can you gibe a *concise list* of the advantages of using N over using C, or of using n over using c? Thanks in advance Gregor From Jmllr891@cs.com Mon Sep 30 10:12:31 2002 From: Jmllr891@cs.com (Jmllr891@cs.com) Date: Mon, 30 Sep 2002 05:12:31 EDT Subject: [Tutor] Pythonwin Question Message-ID: <152.14f409c6.2ac96f7f@cs.com> --part1_152.14f409c6.2ac96f7f_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I recently decided to check out Pythonwin just to see what it was like. I found the page for it on the Python web site and was quite amused. It says that Pythonwin is a wrapper for the MFC library. Where can I get the MFC library? And second of all (since we're talking about Microsoft), how much would it (the MFC library) or a product that it comes with cost? --part1_152.14f409c6.2ac96f7f_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit I recently decided to check out Pythonwin just to see what it was like. I found the page for it on the Python web site and was quite amused. It says that Pythonwin is a wrapper for the MFC library.

Where can I get the MFC library? And second of all (since we're talking about Microsoft), how much would it (the MFC library) or a product that it comes with cost?
--part1_152.14f409c6.2ac96f7f_boundary-- From magnus@thinkware.se Mon Sep 30 11:18:28 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 30 Sep 2002 12:18:28 +0200 Subject: [Tutor] Pythonwin Question In-Reply-To: <152.14f409c6.2ac96f7f@cs.com> Message-ID: <5.1.0.14.0.20020930115424.02a039b0@www.thinkware.se> At 05:12 2002-09-30 -0400, Jmllr891@cs.com wrote: >I recently decided to check out Pythonwin just to see what it was like. I >found the page for it on the Python web site and was quite amused. It says >that Pythonwin is a wrapper for the MFC library. > >Where can I get the MFC library? And second of all (since we're talking >about Microsoft), how much would it (the MFC library) or a product that it >comes with cost? Well, it depends on what version of Windows you want to buy. I dunno, Win ME is about $70 I guess, and the more stable versions cost a few hundred? But I guess you have Windows already...and with it a file called mfc42.dll or something like that. ;) So, MS Windows and ActiveState Python, or standard python with the win32-all package is all you need. At least with ActiveState Python, there is a bunch of docs included. You reach it from the PythonWin help menu. Another source if information is the excellent book Python Programming on Win 32, see http://www.thinkware.se/cgi-bin/thinki.cgi/PythonProgrammingOnWinThirtyTwo or http://www.ora.com/catalog/pythonwin32/ Note the sample chapters and examples. There is some info of relevance in http://www.oreilly.com/catalog/pythonwin32/chapter/ch20.html The obvious limitation with MFC is that it only runs on Windows. It's also much less used (I think) than Tkinter and wxPython. (Although, it you use Tkinter or wxPython you'll get into trouble if you try to run your GUI programs from within PythonWin, since you get two event loops inside each other, and they don't get along...) In PythonWin you can do stuff like this do play with MFC: >>> import win32ui >>> from pywin.mfc.dialog import Dialog >>> d=Dialog(win32ui.IDD_SIMPLE_INPUT) >>> d.CreateWindow() >>> button=d.GetDlgItem(win32ui.IDC_PROMPT1) >>> button.SetWindowText("Hello from Python") You can also use COM and other things, so you can perform magic with Word and Excel etc. Have fun! -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From magnus@thinkware.se Mon Sep 30 13:28:19 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Mon, 30 Sep 2002 14:28:19 +0200 Subject: [Tutor] New classes In-Reply-To: <3D97F5EE.60902@aon.at> Message-ID: <5.1.0.14.0.20020930142439.02a10be8@www.thinkware.se> At 08:57 2002-09-30 +0200, Gregor Lingl wrote: >So there seem to be substantial differences. >Can you gibe a *concise list* of the advantages of >using N over using C, or of using n over using c? The new style classes that appeared in 2.2 was perhaps the biggest change in python since I started using 1.4 in 1996. I have not tried to use new style classes in a serious way. My feeble attempts made me understand that there are a lot of problems involved...at least in combination with multiple inheritance. My impression is that new style classes needs to mature a bit, and I'll stay away from them until 2.3 arrives. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From wolf_binary@hotmail.com Mon Sep 30 16:14:13 2002 From: wolf_binary@hotmail.com (CameronStoner) Date: Mon, 30 Sep 2002 08:14:13 -0700 Subject: [Tutor] classes and inheritance References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C909@mbtlipnt02.btlabs.bt.co.uk> Message-ID: I'm glad you had a good time. So your saying that I should just leave them as seperate classes? Oh, and I didn't list all the actions. I'm in the design phase now and I am just brainstorming how to do this. Your not off base either on what you were seeing in my design, I knew something was wrong and didn't know what. I was concentrating on the data and not on the methods. This would make for easier reusablility and make more sense. I kept thinking why are these inheriting from each other and only found that encapsulating them into one class was the only reason. > > class User: > > data: > > name (used for saving and file name) > > passwrd > > actions: > > get name > > get passwrd > > Recall responsibility driven design is the key to good OO. > > What are the responsibilities of the objects, not the data > they contain? > > Now maybe a User object has the responsibility to manage > user names/passwords but what else does it DO? > Those are the methods you need to focus on, then just add > the necessary data to support that. > > Thus you need change password as a method probably. > But maybe also you need to monitor status of users > - alive/dead/numer of lives etc depending on the rules > of the game... > > I could be way off line here, but every time I see > a class where the only methods are get/set methods of > the data I get nervous. Its nearly always the wrong design. > > As regards the subclasses you don't need to repeat the > data/operations since they are already specified when > you say you inherit from User... > > Finally I concur with the bottom comment about instantiating > abstract classes. You might use the subclasses *as if* they > were higher level abstracts but you would likely never > instantiate an abstract directly. > > Alan G. > From CCampbell@ede.org Mon Sep 30 16:58:01 2002 From: CCampbell@ede.org (Colin Campbell) Date: Mon, 30 Sep 2002 09:58:01 -0600 Subject: [Tutor] [Fwd: re: turn a file into a dictionary] Message-ID: <3D987489.6030102@ede.org> -------- Original Message -------- Subject: re: turn a file into a dictionary Date: Sun, 29 Sep 2002 12:29:07 +0000 From: Charlie Clark To: tutor@python.org CC: CCampbell@ede.org References: <20020929093802.26719.4729.Mailman@mail.python.org> Message-ID: If yes which module is it? From MysteryMann89@aol.com Fri Sep 27 18:24:32 2002 From: MysteryMann89@aol.com (MysteryMann89@aol.com) Date: Fri, 27 Sep 2002 13:24:32 EDT Subject: [Tutor] (no subject) Message-ID: <137.14dd38e8.2ac5ee50@aol.com>
how can I learn it  fast


From tank_uddf@yahoo.com  Sat Sep 28 20:07:59 2002
From: tank_uddf@yahoo.com (Mr. Smiley)
Date: Sat, 28 Sep 2002 12:07:59 -0700 (PDT)
Subject: [Tutor] Example Source Code
Message-ID: <20020928190759.41695.qmail@web40012.mail.yahoo.com>

Hello fellow Python Developers,

I am new to the Python language and have been studying
it extensively, but I have found that I learn better
when there is example source code out there. Do you
know of any web-sites who provide example source code.
I have tried searching in the various documentation on
the web-site and looked extensively on the Python
search engine but could not find anything. Thanks for
the help.



__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com


From oren@softserv.attunity.co.il  Mon Sep 30 09:25:55 2002
From: oren@softserv.attunity.co.il (Oren Levy)
Date: Mon, 30 Sep 2002 11:25:55 +0300
Subject: [Tutor] (no subject)
Message-ID: <001c01c2685a$ff6e28b0$a242cbc7@softserv.attunity.co.il>

This is a multi-part message in MIME format.

------=_NextPart_000_0019_01C26874.2465C6A0
Content-Type: text/plain;
	charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

Hi,
I need your help
I have the example of "spam.c"
It complie & link well to dll (Im using MS-Visual studio 6)
But I didn't understand how to use it ?,Where I need to put the files =
"spam.dll" and "spam.h"?

tnx
Oren

------=_NextPart_000_0019_01C26874.2465C6A0
Content-Type: text/html;
	charset="windows-1255"
Content-Transfer-Encoding: quoted-printable








Hi,
I need your help
I have the example of = "spam.c"
It complie & link well to dll (Im = using=20 MS-Visual studio 6)
But I didn't understand how to use it = ?,Where I=20 need to put the files "spam.dll" and "spam.h"?
 
tnx
Oren
------=_NextPart_000_0019_01C26874.2465C6A0-- From dandudle@msn.com Mon Sep 30 10:01:28 2002 From: dandudle@msn.com (Peter Dudleston) Date: Mon, 30 Sep 2002 03:01:28 -0600 Subject: [Tutor] help How do I use a program I built in linux Message-ID: Help Hello Everyone I have decided to join the linux revolution and I need some help I have python2.2 pre-installed with this version of linux "mandrake" and I was wondering what do I type at the shell to run my programs do I need to make a new directory because no matter what I change the directory to I can't run my programs for example I have one called now which just tells you the time and I saved it as now.py and I can't get it to run no matter what it says that the command doesn't exist does anyone have anything they can tell me "keep in mind I'm a very newbie to this envirment" so if you could explain it in lame mans terms I would really appreciate it thanks for all you help everyone and talk to you all soon Sincerely Danny D _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com From alan.gauld@btinternet.com Mon Sep 30 10:48:37 2002 From: alan.gauld@btinternet.com (Alan Gauld) Date: Mon, 30 Sep 2002 10:48:37 +0100 Subject: [Tutor] msg for Cameron Stoner Message-ID: <007601c26866$8ca0b350$6401a8c0@xp> Cameron, You sent me two messages while I was on holiday but they have strange email addresses to which replies bounce. Please send me a direct email with your 'reply to' address in the body so that I can answer your questions. Sorry for wasting others bandwidth but this is the only other route I know to Cameron! Alan G.