Importing Classes from child folders.
Trying to do some OO Python with files in different directories. I have a blank __init__.py in each directory. It is my assumption that having an __init__.py marks the directory as a module. I am trying to run Controller.py from the command line. I would assume this has already been solved but could not find in forum I am somewhat new to Python. Using Python3 under Ubuntu. ... So I have a project structure as follows: ... ProjectX (root folder) __init__.py Controller.py + service (folder under ProjectX) __init__.py SystemSetup.py (has a class SystemSetup) + model (folder under ProjectX) __init__.py Directory.py (has a class Directory) In Controller.py if I want to use SystemSetup class, I do: from service.SystemSetup import SystemSetup ... and in Controller Class I have: def main(): systemSetup = SystemSetup() I get error: File "Controller.py", line 4, in from service.SystemSetup import SystemSetup ImportError: cannot import name SystemSetup What am I doing wrong? I am running from the command line. Do I need to set the project in PYTHONPATH first? But if SystemSetup and Directory are in same directory as Controller I have no problems. Your help would be highly appreciated. ... Btw I also tried: import sys, os.path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) from service.SystemSetup import SystemSetup ... No luck. Thank you again. Monosij -- http://mail.python.org/mailman/listinfo/python-list
pycache directories
I am doing some OO python3 where I am using multiple dirs/sub-dirs. So everything works fine, however when I run code __pycache__ directories are being created in every directory touched by the execution. Is it possible to set a configuration to be able to create these pycache directories in a specific location? Coming from the Java world - am used to the /src, /bin aspects - so somewhat prefer the 'executables' out of the way. I am using python3 on Ubuntu so wondering if there is some environ setting? Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: pycache directories
On Tuesday, January 22, 2013 1:01:44 AM UTC-5, Terry Reedy wrote: > > > I am doing some OO python3 where I am using multiple dirs/sub-dirs. > > > > > > So everything works fine, however when I run code __pycache__ > > > directories are being created in every directory touched by the > > > execution. > > > > This is much better than having multiple .pyc files in every directory, > > as in Py2. You should soon learn to ignore them. > > > > > Is it possible to set a configuration to be able to create these > > > pycache directories in a specific location? > > > > No. (I am very sure.) You can however, not have the .pyc files written, > > but that means recompile with every run. So that option is meant for > > running off a read-only medium. > > > > -- > > Terry Jan Reedy Thanks Terry. I understand needing to adjust. Appreciate this forum. Monosij -- http://mail.python.org/mailman/listinfo/python-list