Re: Automatically Writing a Dictionary

2008-01-25 Thread Tim Chase
>> d = dict(line.split(',').rstrip('\n')? > > Thanks. That worked except for the rstrip. So I did this: Sorry...I got the order wrong on them (that's what I get for editing after copy&pasting). They should be swapped: d = dict(line.rstrip('\n').split(',')) to strip off the newline before you

Re: Automatically Writing a Dictionary

2008-01-25 Thread tonylabarbara
onary[key] = value Thanks again, Tony -Original Message- From: Tim Chase <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Cc: python-list@python.org Sent: Wed, 23 Jan 2008 3:37 pm Subject: Re: Automatically Writing a Dictionary > input = "/usr/local/machine-lang-trans/dictionary.tx

Re: Automatically Writing a Dictionary

2008-01-23 Thread Tim Chase
> input = "/usr/local/machine-lang-trans/dictionary.txt" > > input = open(input,'r') > > dict = "{" > for line in input: > ? tup = re.split(','line) > ? dict += '"' + tup[0] +'":"' + tup[1] +'", ' > dict += "}" > input.close() > > > Of course, that will just give me a string. How do I convert >

Automatically Writing a Dictionary

2008-01-23 Thread tonylabarbara
Hi; I have data in a file and I would like to write it to a dictionary, and then perform commands on it, something like this: input = "/usr/local/machine-lang-trans/dictionary.txt" input = open(input,'r') dict = "{" for line in input: ? tup = re.split(','line) ? dict += '"' + tup[0] +'":"' +