Hi, I am trying to write a list out to a file. But when I do, it prints it like one big word. I need them to be seperated by a comma.(It has to be a list, not a string). I am simply doing this:
filehandle.writelines(row2)
It comes back as one long word. How do I make them seperated by a comma? When I print the list out to the actual command line, they are formatted properly, it's just when I open the file up.
Thanks,
Casey
2 1174 bvdet 2,851
Expert Mod 2GB
Hi, I am trying to write a list out to a file. But when I do, it prints it like one big word. I need them to be seperated by a comma.(It has to be a list, not a string). I am simply doing this:
filehandle.writelines(row2)
It comes back as one long word. How do I make them seperated by a comma? When I print the list out to the actual command line, they are formatted properly, it's just when I open the file up.
Thanks,
Casey
if 'f' is an open file object: - f.write(','.join(your_list))
-
f.close()
Hi, I am trying to write a list out to a file. But when I do, it prints it like one big word. I need them to be seperated by a comma.(It has to be a list, not a string). I am simply doing this:
filehandle.writelines(row2)
It comes back as one long word. How do I make them seperated by a comma? When I print the list out to the actual command line, they are formatted properly, it's just when I open the file up.
Thanks,
Casey
-
myList = [1, 2, 3, 4]
-
f = open('temp.txt', 'w')
-
f.write( ", ".join(str(item) for item in myList) + "\n")
-
f.close()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Art |
last post by:
NEWBIE ALERT!
Esteemed List Participants and Lurkers:
(System: P-II 350, 192 meg, Win98 SE, Python 2.2.3,
wxPythonWIN32-2.4.1.2-Py22.exe)
I'm having a lot of fun getting started with Python...
|
by: sarmin |
last post by:
Hi Gurus...
I am using pythonwin to write the programming code and boa
constructor to build the GUI... the GUI and the python code work
fine when run through pythonwin platform...
i m now...
|
by: J.R. |
last post by:
Hi folks,
The python can only support passing value in function call (right?), I'm
wondering how to effectively pass a large parameter, such as a large list or
dictionary?
It could achieved...
|
by: vdavidster |
last post by:
Hello everyone,
I want to convert a tuple to a list, and I expected this behavior:
list(('abc','def')) ->
list(('abc')) ->
But Python gave me this behavior:
list(('abc','def')) ->
|
by: lester |
last post by:
a pre-beginner's question:
what is the pros and cons of .net, compared to ++
I am wondering what can I get if I continue to learn C# after I have learned
C --> C++ --> C# ??
I think there...
|
by: John Salerno |
last post by:
Ok, like I mentioned before, I'm learning C# for fun. I'm interested in
learning Python sort of as a "supplement" (by that, I mean a language
with scripting capabilities that can do things maybe...
|
by: Qun Cao |
last post by:
Hi Everyone,
I am a beginner on cross language development. My problem at hand is to
build a python interface for a C++ application built on top of a 3D
game engine. The purpose of this python...
|
by: bambam |
last post by:
Would someone like to suggest a replacement for this? This is a
function that returns different kinds of similar objects, depending
on what is asked for. PSP and PWR are classes. I don't really...
|
by: SMALLp |
last post by:
Hy! I have error something like this
TypeError: unbound method insert() must be called with insertData
instance as first argument (got str instance instead)
CODE:
File1.py...
|
by: Ben Keshet |
last post by:
I have a probably simple beginner's question -
I have a script that I am currently able to print its output. instead,
i want to write it into a file - I tried different versions of write()
but...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |