[Tutor] Create file / Print list to file

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Aug 12 01:37:44 CEST 2004


> I dont know what i am doing diffrent from you but i dont get it to
work:
> ...This is the inputlist
> [['Parent Name', ';', 'Parent Revision', ';', 'Child Name', ';',
'Child
> Revision', ';', 'Quantity', ';', 'Find Number', ';', 'Reference
Designator',
> ';', 'Remark', ';', 'Usage', ';', 'WP', ';', 'PRP'], ['03003365',
';', 'AB',


> i want the file to look something like
>
> Parent name;Parent Revision;Child Name;.......
> 03003365;AB;03003240;.....

The difference is you are printing Pythons string representation
of a list - henvce the brackets. You want the contents of the list.

> Alan! I will try recursion tomorrow if nessesary

Thats what the recursive solution does - it will flatten the list
and print out the elements. That might still not be exactly what
you want. But between them...

>>> L = [[1,2,3],[4,5,6]]
>>> print L
[[1, 2, 3], [4, 5, 6]]
>>> for item in L: print item
[1, 2, 3]
[4, 5, 6]
>>> printList(L)    # as defined in my tutor
1,2,3,4,5,6


It all depends what you actually want.

Alan G.



More information about the Tutor mailing list