import help
Rob Wolfe
blue99 at interia.pl
Tue Aug 8 02:50:30 EDT 2006
placid wrote:
> Hi all,
>
> How do i import a module that has an hypen/dash (-) in its name ? I get
> a SytaxError exception
You can use function __import__.
>>> print open("-test.py").read()
def fun2():
return "Hello from -test !"
>>> import -test
File "<stdin>", line 1
import -test
^
SyntaxError: invalid syntax
>>> __import__("-test", globals(), locals(), [])
<module '-test' from '-test.pyc'>
But here is another problem:
>>> -test.fun2()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'test' is not defined
>>> import sys
>>> sys.modules["-test"].fun2()
'Hello from -test !'
Regards,
Rob
More information about the Python-list
mailing list