Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3673196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:42:10+00:00 2026-05-19T02:42:10+00:00

Kinda knew to Python: I have the following code: def printCSV(output, values, header): 63

  • 0

Kinda knew to Python:

I have the following code:

def printCSV(output, values, header):
 63     """
 64         prints the output data as comma-separated values
 65     """
 66 
 67     try:
 68         with open(output, 'w') as csvFile:
 69             #print headers
 70             csvFile.write(header)
 71 
 72             for value in values:
 73                 #print value, "\n"
 74                 csvFile.write(",".join(value))
 75                 csvFile.write("\n")
 76     except:
 77        print "Error occured while writing CSV file..."



Values is a list constructed somewhat like this:

values = []

for i in range(0,5):
    row = "A,%s,%s,%s" % (0,stringval, intval)
    values.append(row)

When I open the file created by the above function, I expect to see something like this:

Col1,Col2,Col3,Col4
A,0,'hello',123
A,0,'foobar',42

Instead, I am seeing data like this:

Col1,Col2,Col3,Col4
A,0,'h','e','l','l','o',1,2,3
A,0,'f','o','o','b','a','r',4,2

Anyone knows what is causing this?

I even tried to use fopen and fwrite() directly, still the same problem exists.

Whats causing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:42:11+00:00Added an answer on May 19, 2026 at 2:42 am

    The problem you’re encountering is that you’re doing ",".join(value) with value being a string. Strings act like a collection of characters, so the command translates to “Join each character with a comma.”

    What you could do instead is use a tuple instead of a string for your row values you pass to printCSV, like this:

    values = []
    
    for i in range(0,5):
        row = ('A', 0, stringval, intval)
        values.append(row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm kinda' new to python, but I have already written many programs including some
I'm kinda new in the mobile world and wcf world. I have develop a
I have this kinda of input: x4.9 x.25 C400 What is the best way
I have a huge string of text that is apparently raw data for a
Suppose you have an application that consists of two layers: A: A data layer
Kinda new to Silverlight and have some experience with WPF but I'm doing a
Kinda long title, but anyways... I've been looking at these examples, specifically on the
i kinda know how to create a Custom Web Part. But now i need
This is kinda oddball, but I was poking around with the GNU assembler today
I'm a kinda newbie developer with a few years under my belt. Recently I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.