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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:18:07+00:00 2026-05-16T22:18:07+00:00

Er, so im juggling parsers and such, and I’m going from one thing which

  • 0

Er, so im juggling parsers and such, and I’m going from one thing which processes files to another.

The output from the first part of my code is a list of strings; I’m thinking of each string as a line from a text file.

The second part of the code needs a file type as an input.

So my question is, is there a proper, pythonic, way to convert a list of strings into a file like object?

I could write my list of strings to a file, and then reopen that file and it would work fine, but is seems a little silly to have to write to disk if not necessary.

I believe all the second part needs is to call ‘read()’ on the file like object, so I could also define a new class, with read as a method, which returns one long string, which is the concatenation of all of the line strings.

thanks,
-nick

  • 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-16T22:18:07+00:00Added an answer on May 16, 2026 at 10:18 pm

    StringIO implements (nearly) all stdio methods. Example:

    >>> import StringIO
    >>> StringIO.StringIO("hello").read()
    'hello'
    

    cStringIO is a faster counterpart.

    To convert your list of string, just join them:

    >>> list_of_strings = ["hello", "line two"]
    >>> handle = StringIO.StringIO('\n'.join(list_of_strings))
    >>> handle.read()
    'hello\nline two'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one's got me stumped. Usually with a little CSS juggling here and there
One of the messier practices I have in Rails development is juggling validations of
Writing Rails apps means juggling a lot of files. Thank the gods for versatile
The docs simply say or define custom schema (non-juggling), for example, mongoose. Please note,
I have a collection of PHP scripts that are extremely CPU intensive, juggling millions
I am juggling with two ways of free() 'ing malloc() 'ed memory in a
I'm doing a small app juggling with calendars and I'd love to send invitations
I was reading PHP manual and I came across type juggling I was confused,
I'm working on implementing the UCT algorithm in Haskell, which requires a fair amount
I want to define the begin of a day in another timezone with .NET/C#.

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.