| | |
Text File
![]() |
•
•
Join Date: Dec 2006
Posts: 25
Reputation:
Solved Threads: 0
How do i take results in a mutli dim array and write it to a text file. Each sub array goes on a new line. I am a newbie at this.
I would was wondering if I can place every subarry in a text file as below each new line in the text file will contain a sub array:
[2934110, 'B1', 'D4', '7C7C7C7C804040404040F140404000']
[2934110, 5, 1, 1, '01', 'Actes Sud ']
[2934110, 4, 1, 2, '8C00Dubbelganger (motief)']
[2934110, 3, 1, 1, '01', '01', '03', 'Les amants imparfaits', ' : roman']
[2934110, 6, 7, '104', 0], [2934110, 6, 1, 1, '01', '01', '03', 'Domain']
[2934110, 2, 1, 1, '01', 0, 'C4', 'Fleutiaux, Pierrette']
Please help
Python Syntax (Toggle Plain Text)
[[2934110, 'B1', 'D4', '7C7C7C7C804040404040F140404000'], [2934110, 5, 1, 1, '01', 'Actes Sud '], [2934110, 4, 1, 2, '8C00Dubbelganger (motief)'], [2934110, 3, 1, 1, '01', '01', '03', 'Les amants imparfaits', ' : roman'], [2934110, 6, 7, '104', 0], [2934110, 6, 1, 1, '01', '01', '03', 'Domain'], [2934110, 2, 1, 1, '01', 0, 'C4', 'Fleutiaux, Pierrette']]
I would was wondering if I can place every subarry in a text file as below each new line in the text file will contain a sub array:
[2934110, 'B1', 'D4', '7C7C7C7C804040404040F140404000']
[2934110, 5, 1, 1, '01', 'Actes Sud ']
[2934110, 4, 1, 2, '8C00Dubbelganger (motief)']
[2934110, 3, 1, 1, '01', '01', '03', 'Les amants imparfaits', ' : roman']
[2934110, 6, 7, '104', 0], [2934110, 6, 1, 1, '01', '01', '03', 'Domain']
[2934110, 2, 1, 1, '01', 0, 'C4', 'Fleutiaux, Pierrette']
Please help
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
just use the for loop to go over each item, then manipulate from there
Python Syntax (Toggle Plain Text)
>>> for i in alist: ... print ' '.join(map(str,i)) ... 2934110 B1 D4 7C7C7C7C804040404040F140404000 2934110 5 1 1 01 Actes Sud 2934110 4 1 2 8C00Dubbelganger (motief) 2934110 3 1 1 01 01 03 Les amants imparfaits : roman 2934110 6 7 104 0 2934110 6 1 1 01 01 03 Domain 2934110 2 1 1 01 0 C4 Fleutiaux, Pierrette >>>
•
•
Join Date: Dec 2006
Posts: 25
Reputation:
Solved Threads: 0
Thanks for the assistance it works. But when I want to put the print results in a text file it only reads one line. I have tried this code but still gives me inputs one line
.
. Python Syntax (Toggle Plain Text)
for i in results: valfinal=' '.join(map(str,i)) textfile = file('C:/new_file1.txt','wt') final =open('C:/new_file1.txt','w') final.writelines(str(valfinal)) final.close()
You have to add a newline character to the end of each line in the string:
python Syntax (Toggle Plain Text)
mylist = [[2934110, 'B1', 'D4', '7C7C7C7C804040404040F140404000'], [2934110, 5, 1, 1, '01', 'Actes Sud '], [2934110, 4, 1, 2, '8C00Dubbelganger (motief)'], [2934110, 3, 1, 1, '01', '01', '03', 'Les amants imparfaits', ' : roman'], [2934110, 6, 7, '104', 0], [2934110, 6, 1, 1, '01', '01', '03', 'Domain'], [2934110, 2, 1, 1, '01', 0, 'C4', 'Fleutiaux, Pierrette']] mystr = "" for x in mylist: mystr = mystr + str(x) + '\n' # test print mystr filename = "data1.txt" fout = open(filename, "w") fout.write(mystr) fout.close()
drink her pretty
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
if you just want to print to one output file, just do a redirect on your command prompt. eg
Python Syntax (Toggle Plain Text)
python yourscript.py > outfile
•
•
Join Date: Dec 2006
Posts: 25
Reputation:
Solved Threads: 0
Thanks for the assistance. here is the final

Python Syntax (Toggle Plain Text)
mystr="" for x in results: mystr2 = "" for y in x: mystr2 = mystr2 + str(y) mystr = mystr +str(mystr2)+'\n' final =open('C:/new_file1.txt','w') final.writelines(str(mystr)) final.close()
Last edited by wandie; Apr 30th, 2007 at 5:53 am.
![]() |
Similar Threads
- connect to text file database (Visual Basic 4 / 5 / 6)
- Output in Text file-How to apply fprintf()? (C)
- Output in the text file (C)
- Create stats from a text file (Java)
- Store Bluetooth remote address to a text file (C++)
- 10 line text file (Java)
- Read and write to an ASCII Text file (Java)
Other Threads in the Python Forum
- Previous Thread: Get position on Canvas
- Next Thread: Referring to other files
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui heads homework http ideas import input itunes java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite ssh statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






