Problem with loading textfiles into dictionaries.
Steven Bethard
steven.bethard at gmail.com
Mon Jan 31 01:25:17 EST 2005
Kartic wrote:
> mercuryprey at gmail.com said the following on 1/30/2005 7:43 PM:
>
>> Hello,
>> I want to do the following:
>>
>> def do_load(self, arg):
>> sitefile = file('sitelist', 'r+', 1)
>> while True:
>> siteline = sitefile.readline()
>> site_rawlist = siteline.split()
>> sitelist[site_rawlist[0]] = site_rawlist[1:]
>> if len(siteline) == 0:
>> break
>>
> You should move "if len(siteline) == 0" part right after your readline.
> The way you have done it really does not help.
Or better yet, don't use "if len(siteline) == 0" -- use "if siteline".
See this an other examples of dubious Python:
http://www.python.org/moin/DubiousPython
Specifically, see the section on Overly Verbose Conditionals.
Steve
More information about the Python-list
mailing list