I’m trying to create a simple python script and import a couple of custom classes. I’d like to do this as one module. Here is what I have:
point/point.py
class Point:
"""etc."""
point/pointlist.py
class PointList:
"""etc."""
point/__init__.py
from . import point, pointlist
script.py
import sys, point
verbose = False
pointlist = PointList()
When I run script.py I get NameError: name 'PointList' is not defined
What’s weird is that in point/, all three of the module files (__init__, pointlist, point) have a .pyc version created that was not there before, so it seems like it is finding the files. The class files themselves also compile without any errors.
I feel like I’m probably missing something very simple, so please bear with me.
Sorry, I seem to have made a blunder in my earlier answer and comments:
The problem here is that you should access the objects in
pointthrough the module you import:point/__init__.py:script.py:You access
PointListthrough the importpointwhich imports whatever is in__init__.pyIf you want to access
PointListandPointdirectly you could usefrom point import Point, PointListinscript.pyor the least preferablefrom point import *Again, sorry for my earlier error.