NameError Problem

Amit Patel amitp at Xenon.Stanford.EDU
Fri Jun 18 22:32:54 EDT 1999


 Jonathon <jblake at eskimo.com> wrote:
| 
| 	I'm writing a long << 25K line >> script to verify data from a
|  	database.
| 		
| 	The following bit of script is giving me a NameError, and
| 	I can't figure out why.
| 
| 	datafile = open ( the_data_file_is, "r" )
| 	new_datafile = open ( the_temp_data_file_is, "w" )
| 	line_kounter = 0
| 	while line_kounter < 50000
| 	    line_kounter = line_kounter + 1
| 	    templine = datafile.readline(line_kounter)
|             validate_line = templine
| 	    if ( the_file_is == "john_www.db" ) :
| 	         temp_record_id = int(validate_line[2:18])
| 		 temp_country  = strip(validate_line[20:50])
|             elif ( the_file_is == "jan_www.db " ):
|                  temp_record_id = int(validate_line[2:10])
|                  temp_country = strip(validate_line[12:20])
|             print temp_record_id

You have an 'if' and then some 'elif's.  However, if the_file_is does
not match any of the strings, then temp_record_id does not get set,
and you get a NameError.  That's probably what's happening.

One thing to check:                            |
                                               v
|             elif ( the_file_is == "jan_www.db " ):
                                               ^
                                               |
                                  Did you mean to put this space here?


    - Amit




More information about the Python-list mailing list