[Tutor] Create file / Print list to file
Klas Marteleur
klas.martelleur at telia.com
Thu Aug 12 00:43:33 CEST 2004
I dont know what i am doing diffrent from you but i dont get it to work:
This is my function:
def writeListToFile(inputList, outputFile):
print "\nThis is the inputlist\n",inputList
f = open(outputFile,"w")
print "\nThis is f\n", f
for line in inputList:
lineData = ' '.join(line)
f.write(lineData)
f.write('\n')
f.close()
and this is a snippet of the output:
...This is the inputlist
[['Parent Name', ';', 'Parent Revision', ';', 'Child Name', ';', 'Child
Revision', ';', 'Quantity', ';', 'Find Number', ';', 'Reference Designator',
';', 'Remark', ';', 'Usage', ';', 'WP', ';', 'PRP'], ['03003365', ';', 'AB',
';', '03003240', ';', 'AC', ';', '1', ';', 100, ';', '10', ';', '-', ';', '',
';', '-', ';', '-'], ['03003365', ';', 'AB', ';', '03003358', ';', 'AA', ';',
'2', ';', 90, ';', '9', ';', 'Mtrl. spec.: 56-3239-47 ', ';', '', ';', 'YES',
';', '-'], ['03003365', ';', 'AB', ';', '03003359', ';', 'AB', ';', '8', ';',
80, ';', '8', ';', '-', ';', '', ';', '-', ';', 'YES'], ['03003365', ';',
'AB', ';', '03003360', ';', 'AB', ';', '1', ';', 70, ';', '7', ';', '-', ';',
'', ';', 'YES', ';', 'YES'], ['03003365', ';', 'AB', ';', '03003361', ';',
'AA', ';', '2', ';', 60, ';', '6', ';', '-', ';', '', ';', '-', ';', '-'],
['03003365', ';', 'AB', ';', '03003362', ';', 'AB', ';', '1', ';', 50, ';',
'5', ';', '-', ';', '', ';', 'YES', ';', 'YES'], ['03003365', ';', 'AB', ';',
'03003363', ';', 'AB', ';', '1', ';', 40, ';', '4', ';', '-', ';', '', ';',
'YES', ';', 'YES'], ['03003365', ';', 'AB', ';', '03003364', ';', 'AB', ';',
'1', ';', 30, ';', '3', ';', '-', ';', '', ';', 'YES', ';', 'YES'],
['03003365', ';', 'AB', ';', '59-0763-00', ';', '1', ';', '16', ';', 20, ';',
'2', ';', 'DIN 934 ', ';', '', ';', '-', ';', '-'], ['03003365', ';', 'AB',
';', '59-0781-00', ';', '1', ';', '16', ';', 10, ';', '1', ';', '-', ';', '',
';', '-', ';', '-']]
This is f
<open file '/home/klas/Python_filer/Tragic/output.txt', mode 'w' at 0x857b8c0>
Traceback (most recent call last):
File "/home/klas/Python_filer/Tragic/CreateEbomFromFile4.py", line 109, in ?
writeListToFile(modifiedList,'/home/klas/Python_filer/Tragic/output.txt')
File "/home/klas/Python_filer/Tragic/CreateEbomFromFile4.py", line 80, in
writeListToFile
lineData = ' '.join(line)
TypeError: sequence item 10: expected string, int found
i want the file to look something like
Parent name;Parent Revision;Child Name;.......
03003365;AB;03003240;.....
Alan! I will try recursion tomorrow if nessesary
again thanks all
Klas
Klas
More information about the Tutor
mailing list