Python Forum
Why are these numbers broken into their digits?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why are these numbers broken into their digits?
#7
Still not sure what you are looking for, because you are ambiguous in the use of column, but I'll see what I can do.

If we take this code, which uses your 'for' statement:

import csv

cellContent = ['Peter', 'Paul', 'Mary', 'Jane']

with open('csv_file.csv', 'w') as new_file:
    writer = csv.writer(new_file)
    for cell in cellContent:
        writer.writerow(cell)
you end up with a file content of

Output:
P,e,t,e,r P,a,u,l M,a,r,y J,a,n,e
Not what you are looking for I take it, plus you have an extra line between rows. We can avoid the extra lines by adding newline='' to the open() function, and remove the commas using the split() function. The code now looks like:

import csv

cellContent = ['Peter', 'Paul', 'Mary', 'Jane']

with open('csv_file.csv', 'w', newline='') as new_file:
    writer = csv.writer(new_file)
    for cell in cellContent:
        writer.writerow(cell.split(','))
and the file looks like

Output:
Peter Paul Mary Jane
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
RE: Why are these numbers broken into their digits? - by sparkz_alot - Sep-26-2017, 01:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is copying and pasting a block now broken? WagmoreBarkless 2 1,441 May-05-2022, 05:01 AM
Last Post: WagmoreBarkless
  Why is copying and pasting a block now broken? WagmoreBarkless 1 1,264 May-04-2022, 11:40 PM
Last Post: Larz60+
  BrokenPipeError: [Errno 32] Broken pipe throwaway34 6 9,499 May-06-2021, 05:39 AM
Last Post: throwaway34
  Single digits seem to be greater than double digits Frosty_GM 4 3,561 Nov-20-2020, 10:13 AM
Last Post: DeaD_EyE
  Python broken if moved to a different folder ecastrotns 3 2,496 Oct-26-2020, 10:53 PM
Last Post: ecastrotns
  STT: recognition connection failed: [Errno 32] Broken pipe GrahamBerends 0 5,118 Jul-18-2020, 11:00 PM
Last Post: GrahamBerends
  Python DateTime is broken 10OctNotOct10a1 8 4,841 Jan-03-2020, 07:54 AM
Last Post: snippsat
  Broken interpreter? fcktheworld587 1 2,301 Dec-26-2019, 08:29 PM
Last Post: snippsat
  I need a query to select the numbers that include 2 digits of 3 omidvakili 1 1,663 Sep-20-2019, 03:49 PM
Last Post: Yoriz
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,775 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020