Re: [Tutor] iteration is overwriting the previous set value

2005-10-20 Thread Jonas Melian
bob wrote: > At 04:16 PM 10/19/2005, Jonas Melian wrote: > >> def _pre_save(self): >> for field in [self.name, self.native_name]: >> if not field.istitle(): >> #print field.title() >> field = field.title() >> >> The change I try to do there (field = field.title(

Re: [Tutor] iteration is overwriting the previous set value

2005-10-20 Thread Jonas Melian
Your code is correct. Thanks I understood it. 'field' is a local variable inner that loop. Respect to a related matter, a should be '42' Danny Yoo wrote: >On Thu, 20 Oct 2005, Jonas Melian wrote: > > > >Hi Jonas, > > >Do you understand why it isn't working? > >The issue is that 'field' is just

[Tutor] pytunes (Was __slots__, struct, etc.)

2005-10-20 Thread Liam Clarke
Hi all, Well, the fruits of my labour and your assistance is now at a basic level. 'Tis called pytunes, designed to parse and make sense of the iPod's database file. I'm not satisfied with it at all, it's a bit half baked in terms of functions and classes, but I would heartily welcome your perusa

[Tutor] file opening and errors.

2005-10-20 Thread Dan Klose
Hi, I usually use perl but fancy a bit of a change so have started playing with python. using perl to open a file or directory I usually use: open(FILE, $file) or die "Error: $!\n"; The $! is a perl variable that holds an error should the open fail, example being : "No such file or directory".

Re: [Tutor] file opening and errors.

2005-10-20 Thread w chun
On 10/20/05, Dan Klose <[EMAIL PROTECTED]> wrote: > > I usually use perl but fancy a bit of a change so have started playing > with python. congrats! :-) > using perl to open a file or directory I usually use: > open(FILE, $file) or die "Error: $!\n"; > > The $! is a perl variable that holds an

[Tutor] Rebate on "Beginning Python"

2005-10-20 Thread Kent Johnson
Apress, publisher of the book "Beginning Python: From Novice to Professional", is offering a $10 rebate if you purchase the book before October 30. See for example http://www.bookpool.com/sm/159059519X Kent ___ Tutor maillist - Tutor@python.org http

Re: [Tutor] file opening and errors.

2005-10-20 Thread Kent Johnson
Dan Klose wrote: > Hi, > > I usually use perl but fancy a bit of a change so have started playing > with python. > > using perl to open a file or directory I usually use: > > open(FILE, $file) or die "Error: $!\n"; > > The $! is a perl variable that holds an error should the open fail, > exampl

Re: [Tutor] regular expression matching a dot?

2005-10-20 Thread Frank Bloeink
Hi [Christian|List] This post is not regarding your special problem (which anyway has been solved by now), but I'd like to share some general tip on working with regular expressions. There are some nice regex-debuggers out there that can help clearify what went wrong when a regex doesn't match whe

Re: [Tutor] regular expression matching a dot?

2005-10-20 Thread Kent Johnson
Frank Bloeink wrote: > There are some nice regex-debuggers out there that can help clearify > what went wrong when a regex doesn't match when it should or vice versa. > > Kodos http://kodos.sourceforge.net/ is one of them, but there are many > others that can make your life easier ; at least in te

Re: [Tutor] "Decompile" pyc file

2005-10-20 Thread Bernard Lebel
Sorry for the late reply. Thanks a lot Kent, that was really helpful. Bernard On 10/14/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Bernard Lebel wrote: > > Hello, > > > > Is there a way to "decompile" a pyc file? I have a big problem where > > the py file was lost, but the pyc file is insta

Re: [Tutor] define vars by iteration

2005-10-20 Thread Luke Jordan
Danny,   It does help. I'm still stuck on part of it though, maybe a little background will help.   To learn more about classes I decided to make a class Map, with many instances that have directions pointing to other Map instances. Each Map has different objects you can find on it, but is still a

Re: [Tutor] iteration is overwriting the previous set value

2005-10-20 Thread bob
At 12:32 AM 10/20/2005, Jonas Melian wrote: >bob wrote: > > > At 04:16 PM 10/19/2005, Jonas Melian wrote: > > > >> def _pre_save(self): > >> for field in [self.name, self.native_name]: > >> if not field.istitle(): > >> #print field.title() > >> field = field.titl

[Tutor] how to do systematic searching in dictionary and printing it

2005-10-20 Thread Srinivas Iyyer
dear group, I have two files in a text format and look this way: File a1.txt: >a1 TTAATTGGAACA >a2 AGGACAAGGATA >a3 TTAAGGAACAAA File b1.txt: >b1 TTAATTGGAACA >b2 AGGTCAAGGATA >b3 AAGGCCAATTAA I want to check if there are common elements based on ATGC sequences. a1 and b1 are identical se

Re: [Tutor] file opening and errors.

2005-10-20 Thread Andrew P
It's not in direct answer to your question, but a real short answer is "Python doesn't need 'or die' here." It throws exceptions gleefully whenever it encounters an error: >>> f = open('no_such_file') Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 2] No such file or d

Re: [Tutor] how to do systematic searching in dictionary and printing it

2005-10-20 Thread Kent Johnson
I would do this by making a dictionary mapping sequence to header for each data set. Then make a set that contains the keys common to both data sets. Finally use the dictionaries again to look up the headers. a = '''>a1 TTAATTGGAACA >a2 AGGACAAGGATA >a3 TTAAGGAACAAA'''.split() # Make a dict map

Re: [Tutor] file opening and errors.

2005-10-20 Thread Danny Yoo
> open(FILE, $file) or die "Error: $!\n"; > > The $! is a perl variable that holds an error should the open fail, > example being : "No such file or directory". > > With python I have use a try except block but I have no idea how I would > get the same warning from python as I would from perl (th

Re: [Tutor] regular expression matching a dot?

2005-10-20 Thread Hugo González Monteverde
I personally fancy Kiki, that comes with the WxPython installer... It has very nice coloring for grouping in Regexes. Hugo Kent Johnson wrote: > Frank Bloeink wrote: > >>There are some nice regex-debuggers out there that can help clearify >>what went wrong when a regex doesn't match when it sho

[Tutor] file.read..... Abort Problem

2005-10-20 Thread Tomas Markus
Hello Pythoners, This is probably a very newbie question (after all I am one): I am trying to read a file with some 2500 lines and to do a scan for "not allowed" characters in there (such as accented ones and so on). The problem is that the file I am testing with has got one of those somewhere o

Re: [Tutor] define vars by iteration

2005-10-20 Thread Danny Yoo
> Also, I have done what I'm trying to do successfully by populating a > dictionary with class instances named after self.name , > which, after the function runs, I can access this way > >>> classDictionary["Yard"] > > the thing is I would like to be able to get at Yard's at

Re: [Tutor] "Decompile" pyc file

2005-10-20 Thread Kent Johnson
Bernard Lebel wrote: > Sorry for the late reply. > > Thanks a lot Kent, that was really helpful. What did you end up doing? I'm interested in what worked for you... Kent > > > Bernard > > > > On 10/14/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > >>Bernard Lebel wrote: >> >>>Hello, >>> >>

Re: [Tutor] file.read..... Abort Problem

2005-10-20 Thread Kent Johnson
Tomas Markus wrote: > Hello Pythoners, > > This is probably a very newbie question (after all I am one): > > I am trying to read a file with some 2500 lines and to do a scan for > "not allowed" characters in there (such as accented ones and so on). The > problem is that the file I am testing wi

Re: [Tutor] file.read..... Abort Problem

2005-10-20 Thread Danny Yoo
On Thu, 20 Oct 2005, Tomas Markus wrote: > I am trying to read a file with some 2500 lines and to do a scan for "not > allowed" characters in there (such as accented ones and so on). The problem > is that the file I am testing with has got one of those somewhere on line > 2100 (the hex value of

Re: [Tutor] file.read..... Abort Problem

2005-10-20 Thread Kent Johnson
Danny Yoo wrote: > > On Thu, 20 Oct 2005, Tomas Markus wrote: >>what is the most effective way to check a file for not allowed >>characters or how to check it for allowed only characters (which might >>be i.e. ASCII only). > > > If the file is small enough to fit into memory, you might use regul

[Tutor] is mxDateTime recommended?

2005-10-20 Thread Lance E Sloan
Hello, all. It's been quite some time since I've sent a message to the Python tutor list. I would like to know if mxDateTime is still the recommended module to use for date calculations. I've been using it for a few years with a set of CGIs I had written. Should I continue to use that, or is

Re: [Tutor] file.read..... Abort Problem

2005-10-20 Thread Kent Johnson
Kent Johnson wrote: > Here is a program that scans a string for test chars, either using a single > regex search or by individually searching for the test chars. The test data > set doesn't include any of the test chars so it is a worst case (neither scan > terminates early): > > # FindAny.py >

Re: [Tutor] is mxDateTime recommended?

2005-10-20 Thread Kent Johnson
Lance E Sloan wrote: > Hello, all. It's been quite some time since I've sent a message to the > Python tutor list. > > I would like to know if mxDateTime is still the recommended module to use > for date calculations. I've been using it for a few years with a set of > CGIs I had written. Sho

Re: [Tutor] file.read..... Abort Problem

2005-10-20 Thread Danny Yoo
> I was going to ask why you think regex is a sledgehammer for this one, Regex's are more complex because we have to then make sure that none of the testchars have any special meaning as regular expression metacharacters. If one of those test chars, for example, contained things like '-' or '\\',

[Tutor] Time - sum/difference

2005-10-20 Thread Jonas Melian
I would get the local time of a country, using UTC (Universal Time Coordinated) and DST (Daylight SavingTime) of that country. An example, utc time -02:30 and dst +1 : country_utc = datetime.time(2,30) isUTCNegative = True dst = datetime.time(1,0) Now I would the difference of both times. -02:3

[Tutor] greetings...

2005-10-20 Thread carl.badgley
Greetings to list, Tomorrow is my last day in class with Lutz.  I am not only new to Python but new to programming in general, this is my first language.  Looking forward to your help in the days and weeks to come. Any suggestions for self tutorial, whether on python.org or not, would be greatly

Re: [Tutor] is mxDateTime recommended?

2005-10-20 Thread John Fouhy
On 21/10/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Since 2.3 Python includes a datetime module which has some facility for date > calculations. I think mxDateTime is more sophisticated but if your needs are > simple take > a look at datetime. The only significant difference I've come across i

[Tutor] Help(!) with OOP/Composition from "Learning Python"

2005-10-20 Thread Andrew P
I've been reading about composition vs inheritance, and went back to "Learning Python" to look at something I found very confusing a year ago. Turns out I still find it very confusing :) The code at the bottom was taken from the OOP chapter, it's a solution to one of the end-of-chapter problems.

Re: [Tutor] pytunes (Was __slots__, struct, etc.)

2005-10-20 Thread John Fouhy
Hmm, neat. I don't have any feedback for you on your code, but since you're working with this sort of thing, I have a puzzle for you: Suppose you have a collection of MP3 files. You want to build a random playlist, subject to the condition that tracks by the same artist are as far apart as possib

[Tutor] PYBSDDB help

2005-10-20 Thread Valone, Toren W.
I am creating my Db with this code def open_db(self): self.cadmvinfo.open(self.filename, db.DB_HASH, db.DB_CREATE,db.DB_DUP) I am putting the data with this code def store_data(self,manual_processing_code,date,file_code,license_number,vin_num ber, year_model,make

Re: [Tutor] PYBSDDB help

2005-10-20 Thread Danny Yoo
Hi Toren, Ok, I see that you've asked your question on the pybsddb mailing list as well a few weeks ago, which is fine. http://lists.sourceforge.net/lists/listinfo/pybsddb-users Unfortunately, it looks like spammers have attacked that mailing list badly enough that it appears they've done s

Re: [Tutor] Help(!) with OOP/Composition from "Learning Python"

2005-10-20 Thread Alan Gauld
> I've been reading about composition vs inheritance, and went back to > "Learning Python" to look at something I found very confusing a year > ago. Turns out I still find it very confusing :) I don;t know the example but from the snippetts you've posted it doresn't look like a particularly good

Re: [Tutor] file.read..... Abort Problem (fwd)

2005-10-20 Thread Danny Yoo
[Keeping tutor in CC] -- Forwarded message -- Date: Thu, 20 Oct 2005 23:21:13 +0200 From: Tomas Markus <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] file.read. Abort Problem Hi All, Just to let you know my ressults (+ one tiny question :-): I did

Re: [Tutor] Time - sum/difference

2005-10-20 Thread Kent Johnson
Jonas Melian wrote: > I would get the local time of a country, using UTC (Universal Time > Coordinated) and DST (Daylight SavingTime) of that country. > > An example, utc time -02:30 and dst +1 : > > country_utc = datetime.time(2,30) > isUTCNegative = True > dst = datetime.time(1,0) > > Now I w

Re: [Tutor] file.read..... Abort Problem (fwd)

2005-10-20 Thread Kent Johnson
> From: Tomas Markus <[EMAIL PROTECTED]> > Just to let you know my ressults (+ one tiny question :-): > I did a bit of investigation and narrowed the "invalid" characters group to > jus one the hex 1a. My code now looks quite small: > > fpath = 'c:\\pytemp\\bafir550.edi' > fl = file(fpath, 'rb') >

Re: [Tutor] Help(!) with OOP/Composition from "Learning Python"

2005-10-20 Thread Andrew P
Hi Alan, thanks for taking the time to answer so thoroughly. I've responded to a few things below. But let me say right off I have gone through the OOP section in your excellent tutor. It was one of my main resources learning Python. I actually have Bertand Meyer's book here (and have written

[Tutor] Dynamic Function Assignment

2005-10-20 Thread Greg Lindstrom
Hello- Suppose I have three objects... a = MyObject(id=1) b = MyObject(id=2) c = MyObject(id=3) As I read in segments from my file, I need to choose one of the above based on the segment, something like this; segment = 'A Segment to Process' for id, S in (('A',a), ('B',b), ('C',c)):   if segme

Re: [Tutor] Dynamic Function Assignment

2005-10-20 Thread John Fouhy
On 21/10/05, Greg Lindstrom <[EMAIL PROTECTED]> wrote: > Suppose I have three objects... > > a = MyObject(id=1) > b = MyObject(id=2) > c = MyObject(id=3) > > segment = 'A Segment to Process' > > for id in ('A', 'B', 'C'): > if segment.upper().startswith(id): >??how can I select th

Re: [Tutor] Dynamic Function Assignment

2005-10-20 Thread Kent Johnson
John Fouhy wrote: > On 21/10/05, Greg Lindstrom <[EMAIL PROTECTED]> wrote: > >> Suppose I have three objects... >> >> a = MyObject(id=1) >> b = MyObject(id=2) >> c = MyObject(id=3) >> >> segment = 'A Segment to Process' >> >> for id in ('A', 'B', 'C'): >>if segment.upper().startswith(id): >>

Re: [Tutor] "Decompile" pyc file

2005-10-20 Thread Johan Geldenhuys
When I want to download the zip file from the source, I get the error that the page does not exist. Where can I get it? Thanx. Bernard Lebel wrote: Sorry for the late reply. Thanks a lot Kent, that was really helpful. Bernard On 10/14/05, Kent Johnson <[EMAIL PROTECTED]> wrote:

[Tutor] How do I recursively remove the contents of a directory??

2005-10-20 Thread Suri Chitti
If I have a directory /u01/qa/logs and the logs has a number of children directories and I want to remove everything in logs and logs itself, is there a single method or command to do that?  I want to avoid recursively removing the files in each child directory and so on.   _