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
> 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
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):
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,
> 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
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
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
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:
>>>
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")
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',
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_
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
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",
> --- 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
"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:
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
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
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.
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
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():
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
"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
22 matches
Mail list logo