import help

P

placid

Hi all,

How do i import a module that has an hypen/dash (-) in its name ? I get
a SytaxError exception

Cheers
 
G

Gary Herron

placid said:
Hi all,

How do i import a module that has an hypen/dash (-) in its name ? I get
a SytaxError exception

Cheers
You can't do that directly. However, the internals of the import
mechanism are available to the programmer through a module named imp. It
allows you to import a file whose name is specified in a string -- that
should work for you.

Gary Herron
 
R

Rob Wolfe

placid said:
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__.
def fun2():
return "Hello from -test !" File "<stdin>", line 1
import -test
^
SyntaxError: invalid syntax
__import__("-test", globals(), locals(), [])
<module '-test' from '-test.pyc'>

But here is another problem:
Traceback (most recent call last):
File said:
import sys
sys.modules["-test"].fun2()
'Hello from -test !'

Regards,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top