Re: Reading from a file and converting it into a list of lines

2006-06-06 Thread Girish Sahani
> On 6/06/2006 4:15 PM, Girish Sahani wrote: >> Really sorry for that indentation thing :) >> I tried out the code you have given, and also the one sreeram had >> written. >> In all of these,i get the same error of this type: >> Error i get in Sreeram's code is: >> n1,_,n2,_ = line.split(',') >> Va

Re: Reading from a file and converting it into a list of lines: code not working

2006-06-06 Thread skip
Girish> I have a text file in the following format: Girish> 1,'a',2,'b' Girish> 3,'a',5,'c' Girish> 3,'a',6,'c' Girish> 3,'a',7,'b' Girish> 8,'a',7,'b' Girish> . Girish> . Girish> . Girish> Now i need to generate 2 things by reading the file: Girish> 1)

Re: Reading from a file and converting it into a list of lines

2006-06-06 Thread John Machin
On 6/06/2006 4:15 PM, Girish Sahani wrote: > Really sorry for that indentation thing :) > I tried out the code you have given, and also the one sreeram had written. > In all of these,i get the same error of this type: > Error i get in Sreeram's code is: > n1,_,n2,_ = line.split(',') > ValueError: n

Re: Reading from a file and converting it into a list of lines

2006-06-05 Thread Girish Sahani
Really sorry for that indentation thing :) I tried out the code you have given, and also the one sreeram had written. In all of these,i get the same error of this type: Error i get in Sreeram's code is: n1,_,n2,_ = line.split(',') ValueError: need more than 1 value to unpack And error i get in you

Re: Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread John Machin
On 6/06/2006 2:10 PM, Girish Sahani wrote: > I have a text file in the following format: > > 1,'a',2,'b' > 3,'a',5,'c' > 3,'a',6,'c' > 3,'a',7,'b' > 8,'a',7,'b' Check out the csv module. > . > . > . > Now i need to generate 2 things by reading the file: > 1) A dictionary with the numbers as keys

Re: Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread K.S.Sreeram
Girish Sahani wrote: > 1) A dictionary with the numbers as keys and the letters as values. > e.g the above would give me a dictionary like > {1:'a', 2:'b', 3:'a', 5:'c', 6:'c' } def get_dict( f ) : out = {} for line in file(f) : n1,s1,n2,s2 = line.split(',') out.upd

Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread Girish Sahani
I have a text file in the following format: 1,'a',2,'b' 3,'a',5,'c' 3,'a',6,'c' 3,'a',7,'b' 8,'a',7,'b' . . . Now i need to generate 2 things by reading the file: 1) A dictionary with the numbers as keys and the letters as values. e.g the above would give me a dictionary like {1:'a', 2:'b', 3:'a',