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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:47:33+00:00 2026-06-06T21:47:33+00:00

Working with Python 2.6 and receiving an annoying error, and I’m still unsure why.

  • 0

Working with Python 2.6 and receiving an annoying error, and I’m still unsure why. My file of interest contains multiple lines of only a single value. I want to retrieve these values. This snippet of code

f = open(file, 'r')
for line in file:
    value = eval(line)

results in the following error message:

   File "<string>", line 1, in <module>
NameError: name 'c' is not defined

So I researched here on Stack Overflow.. with this question and another one.. but I’m having trouble drawing connections between their problems and mine. What I got from them is that my use of eval() may be confusing Python and I should use raw_input to let Python know that it doesn’t have to evaluate line but rather the actual variables line represents. However, fixing my code to be:

for line in file:
    value = eval(raw_input(line))

Which kicked out the following error (and may have overloaded terminal.. it simply froze up until I quit the program):

File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing

What am I doing wrong here? I’ve picked up the fact that eval() isn’t the favorite to use around SO, am I misunderstanding it’s function?
EDIT: My file is a list of values so,

2 
3
2
3
1
0

etc

EDIT So it was a misunderstanding. Thank you to DSM for pointing out my file names being mismatched and to Levon for still helping out and showing int as a better alternative to eval.

  • 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-06T21:47:34+00:00Added an answer on June 6, 2026 at 9:47 pm

    If you just want to read those numbers from a file and convert them to integers this will do.

    with open('data.txt') as f:
        for line in f:
            value = int(line)
    

    Then you can use the value as needed.

    Aside: The advantage of using with to open the file is that it is automatically closed for you when you are done, or an exception is encountered.

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

Sidebar

Related Questions

I'm working through the Django tutorial and receiving the following error when I run
I'm working with python and am trying to extract numbers from a .txt file
Working on importing a tab-delimited file over HTTP in Python. Before inserting a row's
Working with Python in Emacs if I want to add a try/except to a
now I am working with python. So one question about dict .... suppose I
I am working in python on appengine. I am trying to create what is
I am working with python plugins.I used list to store some values as below:
I am working with python plugins for qgis .I developed the plugin same as
I'm working in Python. I have the following code: while not is_suffix(pattern[:k], pattern[:q]): k
I am working on python plugins.I designed my form using pyqt4 designer. I used

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.