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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:27:20+00:00 2026-06-14T17:27:20+00:00

I am currently working on python programming. class A: def LoadPosition(self): FILE = open(‘a.txt’,

  • 0

I am currently working on python programming.

class A:
    def LoadPosition(self):
        FILE = open('a.txt', "r+")

        i = 0
        for node in self.nodes:
            line = FILE.readline()
            if i == 0:
                scaling_factor == float(line)
                i += 1
            else:
                tmpn, tmpx, tmpy, tmpa = line.split('\t')
                node.id = tmpn
                node.coordinate_x = float(tmpx)
                node.coordinate_y = float(tmpy)
                node.area = int(tmpa)
        FILE.close()

It was fine before, but all of sudden, it shows the NameError message. Please help me out.

Thanks in advance.

  • 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-14T17:27:20+00:00Added an answer on June 14, 2026 at 5:27 pm

    You’re mixing spaces and tabs in strange ways, which is probably confusing Python. Here’s what I get when I copy-and-paste your code from the edit window:

    In [2]: for line in s.splitlines():
       ...:     print repr(line)
       ...:     
    ''
    '    class A:'
    '    \tdef LoadPosition(self):'
    '\t        FILE = open(\'a.txt\', "r+")'
    '    \t'
    '\t\t    i = 0'
    '    \t    for node in self.nodes:'
    '    \t    \tline = FILE.readline()'
    '    \t    \tif i == 0:'
    '    \t    \t\tscaling_factor == float(line)'
    '    \t    \t\ti += 1'
    '    \t    \telse:'
    "    \t    \t\ttmpn, tmpx, tmpy, tmpa = line.split('\t')"
    '\t       \t     \tnode.id = tmpn'
    '   \t\t         \tnode.coordinate_x = float(tmpx)'
    '   \t\t         \tnode.coordinate_y = float(tmpy)'
    '   \t\t     \t    node.area = int(tmpa)'
    '\t\t    FILE.close()'
    

    [Note that if someone copies code from the posted question and not the raw edit window, this might not happen — at least sometimes it’s suppressed seeing the original tabs for me — and so people who try your code might not have any problems.]

    Step #1: run your code using python -tt yourfilenamehere.py to confirm that it’s a tab error.

    Step #2: switch to using four-space tabs everywhere.

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

Sidebar

Related Questions

I'm currently working on a python project, that requires file transmission from a client
I am currently working with Python and have been confused over the fact that
I'm currently working on sprite sheet tool in python that exports the organization into
I am currently working on a small app engine project with python, jquery. I
I am currently working on a web-app/server in python and cherrypy. Right now, I
I have a python program that I am currently working on which is working
I'm currently working on a project 'email to voice call'. Using python i'v extracted
I'm mainly a C# developer, but I'm currently working on a project in Python.
I'm currently working on the topic of programming-languages and interpreter-design. I have already created
I'm currently working on a Python/Twisted project which is to be distributed and tested

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.