On Monday 21 August 2006 10:59, dave s wrote:

Several hours +1 Sometimes it is usefull spelling out my problem in an email - 
seems to clarify it - maybe when I get to the 'im stuck' I should send an 
email to myself :)


clean_csv.append(clean_line) ... should by
clean_csv.append(clean_line[:])

But the real showstopper was 

clean_line = clean_csv = []

and then 
if len(string) > 0: clean_line.append(string[1:-1])
changes clean_csv as well, I guess because its an appens not a reassignment

Sorry for bothering you guys

Dave













> Help :)
>
> I have been playing with this for several hours & am totally stuck !
>
> I am happy with the following ...
>
> >>> a=[1,2,3]
> >>> b=[5,6,7]
> >>> a
>
> [1, 2, 3]
>
> >>> b
>
> [5, 6, 7]
>
> >>> g=[]
> >>> g
>
> []
>
> >>> g.append(a)
> >>> g
>
> [[1, 2, 3]]
>
> >>> g.append(b)
> >>> g
>
> [[1, 2, 3], [5, 6, 7]]
>
>
> So when I needed to make a list of a list in the following code I thought
> no problem ...
>
>
>    def CSV_Lines(self, csv, from_, to):
>         """Returns a list of cleaned up lines from csv 'from_' line
> number  'to' line number"""
>
>         clean_line = clean_csv = []
>         for string in range(from_, to):
>             split_string = csv[string].split(',')
>             split_string = split_string[1:-1]  # Strip the LHS column +
> the /n'
>             if split_string[0] == '' : continue  # Skip empty lines
>             print '##########################'
>             print 'split_string ', split_string
>             for string in split_string:
>                 if len(string) > 0: clean_line.append(string[1:-1])
>             print 'clean_line ',clean_line
>             clean_csv.append(clean_line)
>             print 'clean_csv ',clean_csv
>             clean_line = []
>
> But I get clean_csv trouble  ...
>
> [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/main$ ./crosscheck.py
> ##########################
> split_string  ['"temp1"', '"wow a variable"', '', '', '']
> clean_line  ['temp1', 'wow a variable']
> clean_csv  ['temp1', 'wow a variable', [...]]
> ##########################
> split_string  ['"temp2"', '', '', '', '']
> clean_line  ['temp2']
> clean_csv  ['temp1', 'wow a variable', [...], ['temp2']]
> [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/main$
>
> ie clean_csv ends up as ['temp1', 'wow a variable', [...], ['temp2']]
> instead of [[temp1, wow a variable], [temp2]]
>
> Please help
>
> Dave
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to