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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:35:35+00:00 2026-06-08T11:35:35+00:00

I have a question with Python 2.5 . First, I save a file in

  • 0

I have a question with Python 2.5 . First, I save a file in list format as below:

list_f = open("list.txt", "w")
list = [{"a" : "b", "c" : 100}, {"a" : "c", "c" : 101}]
print >> list_f, list

So, we get a list.txt like this:

[{'a' : 'b', 'c': 100}, {'a' : 'c', 'c' : 101}]

This is its only line in this file. Notice that there are two dict objects in the list and each dict has a value in String and a value in integer .

My question is how to load the file and re-create a list object as the former one.

  • 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-08T11:35:37+00:00Added an answer on June 8, 2026 at 11:35 am
    import ast
    with open('list.txt') as f:
        output = ast.literal_eval(f.read())
    

    returns output as a real list of dictionaries and not as its string representation f.read() would return.

    Anyway, if you are both writing and reading the file, use some serialization interface, such as cPickle or json.

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

Sidebar

Related Questions

first post, so play nice! I have a fairly basic question about Python dictionaries.
This is a slight update to my previous question I have a Python list
I have two String.printable mysteries in the one question. First, in Python 2.6: >>>
I have a small question about a problem I encountered writing my first python
I have a question about python mechanize's proxy support. I'm making some web client
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about interpreting strings as packed binary data in C++. In python,
I have a question related to understanding of how python dictionaries work. I remember
I'm currently developing some things in Python and I have a question about variables
A python/django beginner's question: I have a datetime object (drive_date), a time object (start_time)

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.