Re: [Tutor] flattening a list

2005-01-22 Thread Orri Ganel
Jacob S. wrote: Ahh, my pitiful form of flattening a list that cheats... def flatten(li): li = str(li) li = li.replace("[","") li = li.replace("]","") li = li.replace("(","") li = li.replace(")","") li = "[%s]"%li return eval(li) It works! It's probably just a bit slower

Re: [Tutor] Print record x in a file

2005-01-22 Thread Orri Ganel
Jacob S. wrote: This will get a random record I hope you do not think the comments are patronising but you did say you are new so I did not want to give naked code. import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.r

Re: [Tutor] flattening a list

2005-01-22 Thread Jacob S.
Ahh, my pitiful form of flattening a list that cheats... def flatten(li): li = str(li) li = li.replace("[","") li = li.replace("]","") li = li.replace("(","") li = li.replace(")","") li = "[%s]"%li return eval(li) It works! It's probably just a bit slower. Jacob Schmidt

Re: [Tutor] Print record x in a file

2005-01-22 Thread Jacob S.
This will get a random record I hope you do not think the comments are patronising but you did say you are new so I did not want to give naked code. import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.readlines() #give

Re: [Tutor] Python Scripting

2005-01-22 Thread Danny Yoo
On Sat, 22 Jan 2005, Ali Polatel wrote: >I want to ask you something that I am really curious about. >Can I design web-pages with python or use py files to write html? Hi Ali, Almost every programming language allows us to write strings into files, so from an academic standpoint, 'yes

Re: [Tutor] read line x from a file

2005-01-22 Thread Danny Yoo
On Sat, 22 Jan 2005, Kent Johnson wrote: > Jay Loden wrote: > > One simple solution is to do: > > > > fle = open(file) > > contents = file.readlines() > > file.close() > > print contents[x] #or store this in a variable, whatever > > That is the simplest solution. If your file gets bigger and yo

[Tutor] Python Scripting

2005-01-22 Thread Ali Polatel
   Hi all tutors,    I want to ask you something that I am really curious about.    Can I design web-pages with python or use py files to write html?    if the answer is yes and if I upload some scripts to the web-site with* .py    does someone have to ahve python interepreter in his computer to b

[Tutor] Print record x in a file

2005-01-22 Thread David Holland
This will get a random record I hope you do not think the comments are patronising but you did say you are new so I did not want to give naked code. import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.readlines() #gi

Re: [Tutor] read line x from a file

2005-01-22 Thread Kent Johnson
Max Noel wrote: On Jan 22, 2005, at 13:53, Kent Johnson wrote: That is the simplest solution. If your file gets bigger and you don't want to read it all at once, you can use enumerate to iterate the lines and pick out the one you want: f = open(...) for i, line in enumerate(f): if i==targetLin

[Tutor] Threaded Script Runs Fine in IDLE, Never Terminates from Windows Command Prompt

2005-01-22 Thread Gooch, John
I have a threaded python ( Python 2.3.4 ) script that runs perfectly on Windows 2000 Server SP4 when it is executed from IDLE ( i.e. press 'F5' from the editor ), the threads do their work, halt, and the 'join' command picks them up. When I run the same script from windows command line ( cmd.exe ),

RE: [Tutor] Re: glob or filter help

2005-01-22 Thread Barnaby Scott
For anyone who doesn't like lambda, how about import os def get_fles(exts, upd_dir): return [i for i in os.listdir(upd_dir) if i.split('.')[-1] in exts] > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > Behalf Of Javier > Ruere > Sent: 22

[Tutor] Re: glob or filter help

2005-01-22 Thread Javier Ruere
Jay Loden wrote: > Thanks! That's exactly the kind of feedback I was looking for. If it's not > too much trouble, do you think you could explain how lambda works, or just > point me towards a lambda explanation/tutorial that a new programmer can > understand? It seems to give you some great power

Re: [Tutor] glob or filter help

2005-01-22 Thread Jacob S.
Filter can be replaced with IMHO the more readable list comprehensions. I would try def get_fles(exts,upd_dir): "return list of all the files matching any extensions in list exts" fle_list = [] for each in exts: ext_ls = glob.glob("%s*.%s" % (upd_dir,each)) fle_list.extend(ex

Re: [Tutor] Re: glob or filter help

2005-01-22 Thread Kent Johnson
Javier Ruere wrote: Jay Loden wrote: I have the following code in my updates script (gets the five most recent updated files on my site) def get_fles(exts, upd_dir): '''return list of all the files matching any extensions in list exts''' fle_list = [] for each in exts: cmd = upd_dir + "*." + ea

Re: [Tutor] read line x from a file

2005-01-22 Thread Max Noel
On Jan 22, 2005, at 13:53, Kent Johnson wrote: That is the simplest solution. If your file gets bigger and you don't want to read it all at once, you can use enumerate to iterate the lines and pick out the one you want: f = open(...) for i, line in enumerate(f): if i==targetLine: print lin

Re: [Tutor] read line x from a file

2005-01-22 Thread Kent Johnson
Jay Loden wrote: One simple solution is to do: fle = open(file) contents = file.readlines() file.close() print contents[x] #or store this in a variable, whatever That is the simplest solution. If your file gets bigger and you don't want to read it all at once, you can use enumerate to iterate t