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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:40:05+00:00 2026-06-01T05:40:05+00:00

I have written a few lines of code in Python to see if I

  • 0

I have written a few lines of code in Python to see if I can make it read a text file, make a list out of it where the lines are lists themselves, and then turn everything back into a string and write it as output on a different file. This may sound silly, but the idea is to shuffle the items once they are listed, and I need to make sure I can do the reading and writing correctly first. This is the code:

import csv,StringIO

datalist = open('tmp/lista.txt', 'r')

leyendo = datalist.read()
separando = csv.reader(StringIO.StringIO(leyendo), delimiter = '\t')

macrolist = list(separando)

almosthere = ('\t'.join(i) for i in macrolist)

justonemore = list(almosthere)

arewedoneyet = '\n'.join(justonemore)

with open('tmp/randolista.txt', 'w') as newdoc:
    newdoc.write(arewedoneyet)

newdoc.close()
datalist.close()

This seems to work just fine when I run it line by line on the interpreter, but when I save it as a separate Python script and run it (myscript.py) nothing happens. The output file is not even created. After having a look at similar issues raised here, I have introduced the ‘with’ parameter (before I opened the output file through output = open()), I have tried flushing as well as closing the file… Nothing seems to work. The standalone script does not seem to do much, but the code can’t be too wrong if it works on the interpreter, right?

Thanks in advance!

P.S.: I’m new to Python and fairly new to programming, so I apologise if this is due to a shallow understanding of a basic issue.

  • 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-01T05:40:07+00:00Added an answer on June 1, 2026 at 5:40 am

    Where are the input file and where do you want to save the output file. For this kind of scripts i think that it’s better use absolute paths

    Use:

    open('/tmp/lista.txt', 'r')
    

    instead of:

    open('tmp/lista.txt', 'r')
    

    I think that the error can be related to this

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

Sidebar

Related Questions

I have written a few lines of code which I think should not compile.
I have written a few modules of code in Access vba. Each code runs
I have written a few Python tools in the past to extract data from
I am learning Python for the past few days and I have written this
I have never written multi-threaded code before (barring a few basic backgroundworker tricks) and
I have written a few MSBuild custom tasks that work well and are use
I have written a few Excel 2003/2007 add-ins using VSTO, and I usually end
I have written a few nearly identical functions, except for their names. For example:
I have written quite a few Ruby programs, but if I need to show
I have written a small makefile for a few simple C programs that compiles

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.