Re: [Tutor] Reading and Manipulating XML Data

2009-07-26 Thread Luis Galvan
Hi Alan, I'm liking how clean Element tree is, thanks for the quick reply! Nice definition by the way, I think its a bit clearer now. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] First code snipet

2009-07-26 Thread Darth Kaboda
> Good point. It is important to state your goal for the code, preferably > in comments in your code, as well as in the message asking us the > question. Suggest you include a doc-string for each class and method > declaration. > > But it's important to tell us how you expect to use it, as wel

Re: [Tutor] simple text replace

2009-07-26 Thread Dave Angel
j booth wrote: Hello, I am scanning a text file and replacing words with alternatives. My difficulty is that all occurrences are replaced (even if they are part of another word!).. This is an example of what I have been using: for line in fileinput.FileInput("test_file.txt",inplace=1):

Re: [Tutor] simple text replace

2009-07-26 Thread j booth
oops, I mean that the script opens a file and splits it into words; Then it takes each word and searches for an alternative online; with the alternative now stored in a variable, it simply needs to be written back over the original word in the same file. at the moment this might solve the problem,

Re: [Tutor] simple text replace

2009-07-26 Thread Che M
> I am scanning a text file and replacing words with alternatives. My > difficulty > is that all occurrences are replaced (even if they are part of another > word!).. Could you search for the string ' word ' with the white spaces around it? Shouldn't that only replace words that are not par

[Tutor] simple text replace

2009-07-26 Thread j booth
Hello, I am scanning a text file and replacing words with alternatives. My difficulty is that all occurrences are replaced (even if they are part of another word!).. This is an example of what I have been using: for line in fileinput.FileInput("test_file.txt",inplace=1): > line = lin

Re: [Tutor] renaming files within a directory

2009-07-26 Thread Tim Golden
davidwil...@safe-mail.net wrote: OK I am lost ;( I changed the code to: reader = csv.reader(open("countries.csv"), delimiter=";") for row in reader: ... print row ... ['bi', 'Burundi'] ['km', 'Comoros'] ['dj', 'Djibouti'] ['er', 'Eritrea'] ... Now each row is a list with two items ea

Re: [Tutor] renaming files within a directory

2009-07-26 Thread davidwilson
OK I am lost ;( I changed the code to: >>> reader = csv.reader(open("countries.csv"), delimiter=";") >>> for row in reader: ... print row ... ['bi', 'Burundi'] ['km', 'Comoros'] ['dj', 'Djibouti'] ['er', 'Eritrea'] ... Now each row is a list with two items each. But when I do this: >>>

Re: [Tutor] Reading Data From File

2009-07-26 Thread Chris Castillo
On 7/26/09, Dave Angel wrote: > Chris Castillo wrote: >> ya i was kind of in a hurry composing the email earlier. sorry for the >> typos and misunderstanding. This is what I actually have. >> >> grades = [] >> names = [] >> gradeTotal = 0 >> numStudents = 0 >> >> inputFile = open("input.txt", "r")

Re: [Tutor] renaming files within a directory

2009-07-26 Thread Tim Golden
davidwil...@safe-mail.net wrote: Here is what I have so far, but I get stuck on the mapping of the filename with the csv file. import os files = [file for file in os.listdir(os.getcwd()) if file.endswith('svg')] files ['Flag_of_Abkhazia.svg', 'Flag_of_Afghanistan.svg', 'Flag_of_Albania.svg',

Re: [Tutor] renaming files within a directory

2009-07-26 Thread davidwilson
OK, I know that. Here is what I have so far, but I get stuck on the mapping of the filename with the csv file. >>> import os >>> files = [file for file in os.listdir(os.getcwd()) if file.endswith('svg')] >>> files ['Flag_of_Abkhazia.svg', 'Flag_of_Afghanistan.svg', 'Flag_of_Albania.svg', 'Flag_

Re: [Tutor] renaming files within a directory

2009-07-26 Thread Tim Golden
davidwil...@safe-mail.net wrote: Hello, I have a directory containing svg/Flag_of_United_States.svg etc... Flag_of_the_Seychelles.svg Flag_of_the_Solomon_Islands.svg Flag_of_the_United_Arab_Emirates.svg Flag_of_the_United_Kingdom.svg Flag_of_the_United_States.svg Flag_of_the_Vatican_City.svg

[Tutor] renaming files within a directory

2009-07-26 Thread davidwilson
Hello, I have a directory containing svg/Flag_of_United_States.svg etc... Flag_of_the_Seychelles.svg Flag_of_the_Solomon_Islands.svg Flag_of_the_United_Arab_Emirates.svg Flag_of_the_United_Kingdom.svg Flag_of_the_United_States.svg Flag_of_the_Vatican_City.svg Also I have a CSV file like "us",

Re: [Tutor] Need help in making this code more pythonic

2009-07-26 Thread Rich Lovely
> --- On Sun, 7/26/09, ammar azif wrote: > > From: ammar azif > Subject: [Tutor] Need help in making this code more pythonic > To: tutor@python.org > Date: Sunday, July 26, 2009, 6:23 AM > > Hello, > > I need some suggestions on how to make this code pythonic. The program > basically runs a simul

Re: [Tutor] First code snipet

2009-07-26 Thread Alan Gauld
"Dave Angel" wrote len() is very fast, so there's no need for a separate variable to keep track of the lengths of inpile1 and inpile2. So eliminate all refs to pile1c and pile2. In the while, just use while len(inpile1) and len(inpile2): Or even simpler: while inpile1 and inpile2:

Re: [Tutor] First code snipet

2009-07-26 Thread Dave Angel
Darth Kaboda wrote: Subject: Re: [Tutor] First code snipet From: andr...@kostyrka.org To: darthkab...@msn.com CC: tutor@python.org Date: Sun, 26 Jul 2009 03:02:27 +0200 Some things: 1) It's Python, not Phython. 2) Slightly shorter solution to your problem: import random input = range(53

Re: [Tutor] sqlite: don't understand a code snippet

2009-07-26 Thread David
Rich, thanks a lot -- that was the problem. David Rich Lovely wrote: > 2009/7/25 David : > >> Dear tutors, >> >> I am trying to teach myself the way Python's works with databases. >> I decided to start with SQLite, and am looking at Summerfield's >> 'Programming in Python 3'. >> I got a code

Re: [Tutor] Need help in making this code more pythonic

2009-07-26 Thread ammar azif
Sorry I forgot to attach the code file. Here it is. --- On Sun, 7/26/09, ammar azif wrote: From: ammar azif Subject: [Tutor] Need help in making this code more pythonic To: tutor@python.org Date: Sunday, July 26, 2009, 6:23 AM Hello, I need some suggestions on how to make this code pythonic.

[Tutor] Need help in making this code more pythonic

2009-07-26 Thread ammar azif
Hello, I need some suggestions on how to make this code pythonic. The program basically runs a simulation of an object that moves on a 2D plane. The object keeps on moving from its current coordinate to  randomly picked adjacent coordinates with the object is not allowed to move move to a previ

Re: [Tutor] Reading Data From File

2009-07-26 Thread Dave Angel
Chris Castillo wrote: ya i was kind of in a hurry composing the email earlier. sorry for the typos and misunderstanding. This is what I actually have. grades = [] names = [] gradeTotal = 0 numStudents = 0 inputFile = open("input.txt", "r") for line in inputFile: if line.strip().isdigit():

Re: [Tutor] Reading Data From File

2009-07-26 Thread Chris Castillo
ya i was kind of in a hurry composing the email earlier. sorry for the typos and misunderstanding. This is what I actually have. grades = [] names = [] gradeTotal = 0 numStudents = 0 inputFile = open("input.txt", "r") for line in inputFile: if line.strip().isdigit(): grade = float(li

Re: [Tutor] First code snipet

2009-07-26 Thread Alan Gauld
"Darth Kaboda" wrote The one worry I have is not coding things the Phython way ...So would like to have people look at a simplistic class rpile = pile1[0:0] #get blank copy of the passed in object types. This will return an empty list regardless of the type of passed in object. T