Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
Well, I've tried both and can't produce what I was doing with the for construct. With a listpl = ['a', 'b', 'c', 'd'] of the path components I'm trying to add justified non repeated path elements, say pl[2] and pl [3] to csvline so that csvline would end up '"",'*x plus '"c","d",' >>> pl

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Kent Johnson
Lee Cullens wrote: > On Jun 4, 2005, at 6:54 PM, Kent Johnson wrote: >> dlst = os.listdir(pname) >> if len(dlst): >> for dlf in dlst: >> >> There is no need for the if(dlst); if the list is empty the iteration >> will do nothing. You can write this as >> for dlf in os.listdir(pn

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
On Jun 4, 2005, at 9:32 PM, Javier Ruere wrote: > Lee Cullens wrote: > >> The initial os.walk() approach I tried is simple in concept: >> >> pgo = os.walk(base_directory) >> for xnode in pgo: >> >> >> but I ended up with much more processing in having to sort the rows >> and then blank repeat

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
Thanks for the critique Kent On Jun 4, 2005, at 6:54 PM, Kent Johnson wrote: > Lee Cullens wrote: > > >> Pythonese/Efficiency/Generalese critique please >> >> I'm new to Python and as an exercise created a little utility module. >> I'm learning from the O'Reilly books and updating that understan

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Javier Ruere
Lee Cullens wrote: > The initial os.walk() approach I tried is simple in concept: > > pgo = os.walk(base_directory) > for xnode in pgo: > > > but I ended up with much more processing in having to sort the rows > and then blank repeated cells, than the recursive listdir approach > which ga

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Javier Ruere
Kent Johnson wrote: > dlst = os.listdir(pname) > if len(dlst): > for dlf in dlst: > > There is no need for the if(dlst); if the list is empty the iteration will do > nothing. You can write this as > for dlf in os.listdir(pname): Though it is quite distant, there is an else s

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Javier Ruere
Kent Johnson wrote: > Javier Ruere wrote: > >>for i in range(alvl, clvl): >> csvline = csvline + '"' + pl[i] + '",' >> >>should be replaced by something like the following: >> >>cvsline += '"' + pl[alvl:clvl].join('",') > > > or maybe more like this: > cvsline += '"' + '",'.join(pl[alvl:clvl

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Kent Johnson
Javier Ruere wrote: > for i in range(alvl, clvl): > csvline = csvline + '"' + pl[i] + '",' > > should be replaced by something like the following: > > cvsline += '"' + pl[alvl:clvl].join('",') or maybe more like this: cvsline += '"' + '",'.join(pl[alvl:clvl]) + '",' though if alvl == clvl

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Kent Johnson
Lee Cullens wrote: > Pythonese/Efficiency/Generalese critique please > > I'm new to Python and as an exercise created a little utility module. > I'm learning from the O'Reilly books and updating that understanding > from the 2.4 documentation. > > I would appreciate any comments you see fit

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
Sorry about the double post. I sent with the wrong from address so I resent with the correct address and before I could cancel the first the moderator had let it through :~) Lee C ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailm

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
Thank you for the critique Javier. You made some good points that I will play with before moving on. Beyond that, I intentionally neglected error checking in this exercise as you may have surmised. Checking input arguments and handling access restrictions gracefully would indeed be important

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
Thank you for the critique Javier. You made some good points that I will play with before moving on. Beyond that, I intentionally neglected error checking in this exercise as you may have surmised. Checking input arguments and handling access restrictions gracefully would indeed be important

Re: [Tutor] how to generate random numbers in Python

2005-06-04 Thread Danny Yoo
On Fri, 3 Jun 2005, Xiaoxia Xu wrote: > I tried to use a Python library module random() to generate some noise > to my data. But the interpreter gave me an error message saying > NameError: name 'random' is not defined. I thought this error is > because I don't have the pertinent library includ

Re: [Tutor] how to generate random numbers in Python

2005-06-04 Thread Pujo Aji
Don't forget to call : import random try: import random print random.randint(2,8) print random.random() good luck pujo On 6/4/05, Xiaoxia Xu <[EMAIL PROTECTED]> wrote: > Hello, > > I tried to use a Python library module random() to generate some > noise to my data. But the interpreter gave me

[Tutor] how to generate random numbers in Python

2005-06-04 Thread Xiaoxia Xu
Hello, I tried to use a Python library module random() to generate some noise to my data. But the interpreter gave me an error message saying NameError: name 'random' is not defined. I thought this error is because I don't have the pertinent library included. Could anyone tell me how can I ge

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Javier Ruere
Lee Cullens wrote: > Pythonese/Efficiency/Generalese critique please > > The utility produces a csv file of a specified directory tree for import > to a spreadsheet application. My first attempt employed os.walk(), but > I found converting the results of such more troublesome than the > recurs

Re: [Tutor] Help: Possible to Pickle and Image?

2005-06-04 Thread Javier Ruere
Aaron Elbaz wrote: > Hi again :), > > My goal is to store an image file with lots of information relating to > the image and the file it was extracted from, persistantly. Pickle seems > like a really easy way to do this. So I'm wondering, is it possible to > serialize > things like images into a

[Tutor] Help: Possible to Pickle and Image?

2005-06-04 Thread Aaron Elbaz
Hi again :), My goal is to store an image file with lots of information relating to the image and the file it was extracted from, persistantly. Pickle seems like a really easy way to do this. So I'm wondering, is it possible to serialize things like images into a pickle? How do I do it? If not,

Re: [Tutor] interactif or not

2005-06-04 Thread Michael P. Reilly
On 6/3/05, Cedric BRINER <[EMAIL PROTECTED]> wrote: hi,How can I know if a script is launched interactively or not because I'd like to make a script verbose or not depending if it is executed as interactive or not.eg.If I invoke it in a shell.. then it can be verboseIf it is launched from a crontab

[Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-04 Thread Lee Cullens
Pythonese/Efficiency/Generalese critique pleaseI'm new to Python and as an exercise created a little utility module.  I'm learning from the O'Reilly books and updating that understanding from the 2.4 documentation.  The utility produces a csv file of a specified directory tree for import to a sprea