0

I'm new to Python (this is my second language), so hopefully my question can help somebody else also struggling with something similar.

For reference, I'm using Netbeans IDE 6.9.1 and running Python 2.7.3.

A bit of a backstory, I'm studying a transportation problem for thesis, and I need to generate a network of cities (nodes) and roads (arcs). What I'm doing with the code below is generating a string that I'll pass to an open(file,'w') operation, where I'll write randomly-generated data to a text file.

For example: FNodes = '\DijkstraShortestPath\Data\100Nodes\Node5.txt'

I keep getting a "name 'Fnodes' not defined" error when I run this code below.

I've spent hours trying to figure this out; shouldn't this be defined? After all, I did write "FNodes = bla bla bla".

I tried taking it out of the loop, but that brought up the same errors with 'item' and 'replications' since they are used in the FNodes string. This makes sense since they are defined in the for loop.

If you could help a new guy understand this syntax mistake, that'd be great.

Thanks for your help.

R = 10  #Number of replications (trials)
NumNodes = [50,100,150] #Number of nodes (cities). Also the names of 3 folders.

for item in NumNodes: #Cycle through 50, 100, 150 nodes for folder path XXXNodes

    for replications in range(R): #Cycle through fileR.txt by replication number

        fNodes = "\\DijkstraShortestPath\\Data\\" + str(item) + "Nodes\\Node" \
        + str(replications + 1) + ".txt"

        print FNodes #This is a debugging step for me so I can see what's happening

        #Write to files and stuff...
Chris
  • 61
  • 5
  • 1
    I wonder why you don't show the actual code that raises the exception. Where is the `open` call? Please expand your code snippet. By the way, if your path is relative, it probably shouldn't start with slashes. – Lev Levitsky Mar 12 '13 at 19:29
  • I noticed the error--I was trying to reference FNodes when I had actually defined fNodes. Capitalization mistake. What do you mean by "relative" path? – Chris Mar 14 '13 at 04:05
  • Relative path shows the file location relative to the current directory. Absolute path starts from the root of the filesystem tree. – Lev Levitsky Mar 14 '13 at 07:14

1 Answers1

0

I noticed the error and was able to move on.

It was a capitalization error; print FNodes should have been print fNodes

Chris
  • 61
  • 5