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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:19:50+00:00 2026-05-27T01:19:50+00:00

I am trying to write a very simple script that would simulate a pocket

  • 0

I am trying to write a very simple script that would simulate a pocket secretary for my homework, but I have a small issue.
I want all my data to be saved in a file (abstract form) each time I exit the program and then when i boot it up I want to read that file, eval(stack) (basically load the data into memory) then verify if it’s valid … anything that isn’t is deleted.
This is what I’ve done:

    def loadToString (stack):
        f = open ("data.txt", "w")
        load_stack = str(stack)  #convert to string
        f.write (load_stack)  #write in file
        f.close() 

    def loadFromString ():
       f = open ("data.txt", "r")
       load_stack = f.readline() #read string
       if (load_stack == "" or load_stack == " " or load_stack == None): 
           stack = []
           return stack 
      else:
          stack = eval(load_stack) #trying to convert from string to list
      f.close ()

My problem is when I look into the file … it’s not really a string because it lacks the apostrophes <“> thus when I try to “eval (stack)” something goes wrong and my “memory” ends up being empty (when I try to print the stack it’s empty -None-)

I cannot for the life of me understand why this is happening. Also I’m ok with a quick fix (artificially adding apostrophes in the .txt file)

I have no idea how to check if a file is empty or if I read an empty line so I’d also appreciate if you could help me with the “if” statement in “loadFromString”.
About eval () … like I said this is just homework so I’m not afraid about any malicious intents.

  • 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-27T01:19:51+00:00Added an answer on May 27, 2026 at 1:19 am

    To handle your immediate problem, change the line load_stack = str(stack) to load_stack = repr(stack). That will add the apostrophes.

    Afterwards, you may want to look at the csv module or shelve module. Both are easy to use and will take care of many of the low level details.

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

Sidebar

Related Questions

This is a very simple game I'm trying to write but I have a
I am trying to write a very simple RSS channel which would display the
I'm trying to write a very simple Python utility for personal use that counts
I'm trying to write a very simple terminal app that will scan for Bluetooth
I am trying to write a very simple Android application that checks the signal
I'm trying to write a very simple plugin that on anchor mouseover increases the
I am trying to write a simple bash script that is listening on a
I am trying to write a very simple slide up and slide function that
I'm trying to write a very simple app that will do just one very
I'm trying to write a very simple program in C++ that finds the modulus

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.