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 8484153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:18:04+00:00 2026-06-10T20:18:04+00:00

I have the following code: for node, value in sorted(d.iteritems()): outfile.write([node] + value) print(node,

  • 0

I have the following code:

for node, value in sorted(d.iteritems()):
    outfile.write([node] + value)
    print(node, value)

I read a few different SO posts about this and am still somewhat confused. The print statement works perfectly, printing the key and value correctly in the interpreter. But I couldn’t figure out a way to get the outfile.write() statement to work here. Would greatly appreciate any clarification!

  • 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-10T20:18:06+00:00Added an answer on June 10, 2026 at 8:18 pm

    print automatically converts the given variable to a string (using the __repr__ method). file.write does not. You could still write to a file with something like:

    outfile.write("%s %s\n" % (node, value))
    

    (I also added a newline). However, you don’t make clear in the question what the types of node and value are. The expression [node] + value implies that value is a list. If you want the list to be comma separated (as implied by your question’s title) you can combine them and join them with commas like so:

    outfile.write(",".join(map(str, [node] + value)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my node.js server I have the following code: //Generate a token var token
I have the following node.js server-side code: var app = require('http').createServer(handler) , io =
I have the following recursion code, at each node I call sql query to
Hello there I have the following code: struct Edge { Node * nodeA, *
In my node.js app, I have the following code to get the last mark
I have the following code where i'm trying to get the c:CreationDate nodes: value
I have the following test code... I am trying to pass a node-set as
I have the following 2 lines of code: Dim node As XmlNode = xDoc.SelectSingleNode(//response/agentStatusList/agentStatus/protectableVolumes/protectableVolume/metrics/lastWriteTime)
Hi i have the following code to read the xml file and change the
I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node;

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.