3 Oct 2011 12:11
packages, modules and double imports - oh my!
Chris Withers <chris <at> simplistix.co.uk>
2011-10-03 10:11:56 GMT
2011-10-03 10:11:56 GMT
Hi All,
The attached package gives that smallest possible example of problems
I'm hitting with some SQLAlchemy declarative classes.
In short, I want to be able to do:
python -m pack.module and have if the __name__=='__main__' block spit
out the SQL to create the tables necessary for the modules in that class...
So, using the attached package to demonstrate, the first problem I get is:
cwithers <at> cwlin:~> python -m pack.module
Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 121, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/home/cwithers/pack/module.py", line 3, in <module>
class MyClass(object):
File "pack/__init__.py", line 7, in __init__
raise Exception('%r registered twice' % self.__name__)
Exception: 'MyClass' registered twice
Looks like I have a pack.module.MyClass and a __main__.MyClass, which
feels like a bug to me...
Ho hum, lets try something different:
cwithers <at> cwlin:~> python pack/module.py
(Continue reading)
RSS Feed