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 1172 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: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |