Skip to content Skip to sidebar Skip to footer

Why Do I Get "nameerror: Name '...' Is Not Defined" In Python Module?

filename:recom.py # Returns a distance-based similarity score for person1 and person2 def sim_distance(prefs,person1,person2): # Get the list of shared_items si={} for item

Solution 1:

I use python 3.4.3, and I just encountered the same problem. The below solution solved it for me.

When you use reload() you should also use from imp import reload before you use it.

As to getting the Euclidean Distance Score, you can get your answer like:

from recom import critics
 from recom import sim_distance
 sim_distance(critics,'Lisa Rose','Gene Seymour')

The result is: 0.29429805508554946

Solution 2:

You need to have imported the module using "import recom" before it can be reloaded. Also, make sure the code is executing where it can resolve the path to recom.

Post a Comment for "Why Do I Get "nameerror: Name '...' Is Not Defined" In Python Module?"