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

  • SEARCH
  • Home
  • 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 8202709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:17:00+00:00 2026-06-07T07:17:00+00:00

Possible Duplicate: python csv: save results to csv file Python: How to write a

  • 0

Possible Duplicate:
python csv: save results to csv file
Python: How to write a dictionary of tuple values to a csv file?

Previously I use this to write the results line by line to a text file, in each line, values are separated by tab

fd_out.write("%s\t%d\t%d\t%s\n" % (obj["name"],obj["count"],obj["age"],obj["params"]["country"])

but now I want to have CSV output instead, how am I suppose to write the code?
Just like this or should I import CSV and use some other method?
Sorry, I am quite a newbie of programming…

fd_out.write("%s,%d,%d,%s\n" % (obj["name"],obj["count"],obj["age"],obj["params"]["country"])
  • 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-06-07T07:17:02+00:00Added an answer on June 7, 2026 at 7:17 am

    Your code should work for basic data, but some problem may arise in some cases, if you have commas in your data.

    The csv module takes care of that problem, as well as any similar problems. The usage is quite easy, you would just do :

    writer = csv.writer(fd_out)
    writer.writerows((obj["name"],obj["count"],obj["age"],obj["params"]["country"]))
    

    Note the double parens, we pass a tuple because writerows except an iterable. Don’t hesitate to check the doc if you want more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python dictionary: are keys() and values() always the same order? If i
Possible Duplicate: Python dictionary, keep keys/values in same order as declared If I have
Possible Duplicate: Python: Sort a dictionary by value I need to sort by values
Possible Duplicate: python: how to jump to a particular line in a huge text
Possible Duplicate: Python or Ruby Interpreter on iOS I just discovered this apps pypad
Possible Duplicate: Python: How to read huge text file into memory To process a
Possible Duplicate: Python List vs. Array - when to use? I'm working on a
Possible Duplicate: python: how to encrypt a file? I'm trying to make application that
Possible Duplicate: Python “extend” for a dictionary I know that Python list can be
Possible Duplicate: python: creating excel workbook and dumping csv files as worksheets How would

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.