Receiving 'NAMEERROR:name' when I try and execute my code in DEBUG mode

T

telconstar99

Hello,

I'm writing a testing framework in Jython. My code executes successfully when I RUN my project, however, when I DEBUG my project I receive the following error

SOURCE:NAMEERROR:name 'Load_Configurations' is not defined["NameError: name'Load_Configurations' is not defined

I'm new to python. I am using execfile because I want to dynamically include files at runtime. I would appreciate assistance in resolving this error so that I can use a debugger on my project. I'm using Netbeans if that matters. Below I've pasted the code in my runner.py file (the file that gets executed):

if __name__ == "__main__":
#Required Imports
import os
import sys

root = os.path.dirname((os.getcwd()))

#Load all my files by walking through my source code
i=1
for r,d,f in os.walk(root + "\\src"):
for files in f:
if (files.endswith(".py") and files!="runner.py" and files!="setup.py" and files!="new_test.py"):
execfile(os.path.join(r,files))
if i==len(f):
i=1
break
i=i+1

#Load Configuration
RunnerSettings.load_config = Load_Configurations(root + '\\configuration.xml')
 
J

John Gordon

In said:
I'm writing a testing framework in Jython. My code executes successfully
when I RUN my project, however, when I DEBUG my project I receive the
following error
SOURCE:NAMEERROR:name 'Load_Configurations' is not defined["NameError:
name 'Load_Configurations' is not defined
I'm new to python. I am using execfile because I want to dynamically
include files at runtime. I would appreciate assistance in resolving this
error so that I can use a debugger on my project. I'm using Netbeans if
that matters. Below I've pasted the code in my runner.py file (the file
that gets executed):
if __name__ == "__main__":
#Required Imports
import os
import sys
root = os.path.dirname((os.getcwd()))
#Load all my files by walking through my source code
i=1
for r,d,f in os.walk(root + "\\src"):
for files in f:
if (files.endswith(".py") and files!="runner.py" and files!="setup.py" and files!="new_test.py"):
execfile(os.path.join(r,files))
if i==len(f):
i=1
break
i=i+1
#Load Configuration
RunnerSettings.load_config = Load_Configurations(root + '\\configuration.xml')

I don't know anything about Jython or Netbeans specifically, but looking at
your code I see that Load_Configurations is, indeed, not defined anywhere.
It's not imported nor does the code ever create an object with that name,
so I'm not surprised that you get that error.

This entire block of code is conditionally executed upon __name__ being
equal to "main"; perhaps that condition is false when the code is run and
thus the error is never triggered.
 
T

telconstar99

Hey John,

Thanks for the response. I really don't know why I didn't think about that. I decided to add the following statement:

print root

When I RUN, this is what I get:
C:\My Documents\Netbeans\Mytests

When I debug, this is what I get:
C:\Program Files

Having these two directories as different directories is a problem. Any thoughts on how to detect the runtime CWD? C:\Program Files is a pretty unhelpful CWD.

Hello,


I'm writing a testing framework in Jython. My code executes successfully
when I RUN my project, however, when I DEBUG my project I receive the
following error


SOURCE:NAMEERROR:name 'Load_Configurations' is not defined["NameError:
name 'Load_Configurations' is not defined


I'm new to python. I am using execfile because I want to dynamically
include files at runtime. I would appreciate assistance in resolving this
error so that I can use a debugger on my project. I'm using Netbeans if
that matters. Below I've pasted the code in my runner.py file (the file
that gets executed):


if __name__ == "__main__":
#Required Imports
import os
import sys


root = os.path.dirname((os.getcwd()))


#Load all my files by walking through my source code

for r,d,f in os.walk(root + "\\src"):
for files in f:
if (files.endswith(".py") and files!="runner.py" and files!="setup.py" and files!="new_test.py"):

if i==len(f):





#Load Configuration
RunnerSettings.load_config = Load_Configurations(root + '\\configuration.xml')



I don't know anything about Jython or Netbeans specifically, but looking at

your code I see that Load_Configurations is, indeed, not defined anywhere.

It's not imported nor does the code ever create an object with that name,

so I'm not surprised that you get that error.



This entire block of code is conditionally executed upon __name__ being

equal to "main"; perhaps that condition is false when the code is run and

thus the error is never triggered.



--

John Gordon Imagine what it must be like for a real medical doctor to

(e-mail address removed) watch 'House', or a real serial killer to watch 'Dexter'.
 
D

Dave Angel

Hey John,

Thanks for the response. I really don't know why I didn't think about that. I decided to add the following statement:

print root

When I RUN, this is what I get:
C:\My Documents\Netbeans\Mytests

When I debug, this is what I get:
C:\Program Files

Having these two directories as different directories is a problem. Any thoughts on how to detect the runtime CWD? C:\Program Files is a pretty unhelpful CWD.

import os
xxx = os.getcwd()

will fetch the current directory. Similary, you can change it with
os.chdir()

It is usually better to do one of two things:

1) make the environment set the current directory - fix the debugger

2) use absolute paths throughout the code.

One reason that chdir() is discouraged is that it's not clear what part
of the code will still be using the original cwd, even though you
think you've changed it. For example, I don't believe that sys.path is
re-evaluated.

Another reason is that on Windows, you have the strange characteristic
that there are multiple current directories, one per drive.

Most IDE's can set the current directory in the project settings, so
that it'll always be the same when you run a given program. I don't
know about Netbeans.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top