alain MONTMORY wrote:
> Hello everybody,
>
> I am a newbie to python so I hope I am at the right place to expose my
> problem..... :-[
>
> I am working on linux mandrake 10.1 with python :
> python -V
> Python 2.3.4
> I am trying o run the example which stay in the documentation in paragraph
> http://www.python.org/doc/2.4.2/ext/pure-embedding.html 5.3 Pure Embedding
> I download the code example from
> http://www.python.org/doc/2.4.2/ext/run-func.txt
> I call the file "TestOfficiel.c" and I compile it with :
> gcc -g -I/usr/include/python2.3/ TestOfficiel.c -o TestOfficiel
> -lpython2.3 -ldl
> all is OK (or seems to be...).
> as stated in the documentation  I creat a file "TestPythonFoo.py" which
> contain
> "
> def multiply(a,b):
>     print "Will compute", a, "times", b
>     c = 0
>     for i in range(0, a):
>         c = c + b
>     return c
> "
> I launch
> ./TestOfficiel ./TestPythonFoo.py multiply 3 2
> and as a result :
> ValueError: Empty module name
> Failed to load "./TestPythonFoo.py"

This is (I believe) because of the "." at the front.

> if I try an absolute path to the python file :
> ./TestOfficiel `pwd`/TestPythonFoo.py multiply 3 2
> I obtain :
> ImportError: No module named
> /space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py

It's quite correct, there never could be a module named that. The name
of your module is TestPythonFoo -- so all you should have to do is
    ./TestOfficiel TestPythonFoo multiply 3 2

> Failed to load
> "/space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py"


> Of course the file exist :
> [EMAIL PROTECTED] swigCallPython]$ ll
> /space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py
> -rwxrwx--x  1 montmory esoppe 126 sep 29 14:04
> /space/ESOPPE_PROJET/Outils/SwigPython/swigCallPython/TestPythonFoo.py*
>
> I found lot of post about "ValueError: Empty module name" but no clear
> solution (clear for me...).
> What's wrong ?
> my python version?
> Additionnal informations :
> gcc version 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)
>
> Thanks for your help,
>
> best regards,
>
> Alain
>
>
>
>
> --------------070105030901000008070407
> Content-Type: text/plain
> Content-Disposition: inline;
>       filename="TestOfficiel.c"
> X-Google-AttachSize: 2022
>
> #include <Python.h>
>
> int
> main(int argc, char *argv[])
> {
>     PyObject *pName, *pModule, *pDict, *pFunc;
>     PyObject *pArgs, *pValue;
>     int i;
>
>     if (argc < 3) {
>         fprintf(stderr,"Usage: call pythonfile funcname [args]\n");

"pythonfile" is confusing; it should be "modulename".


>         return 1;
>     }
>
>     Py_Initialize();
>     pName = PyString_FromString(argv[1]);
>     /* Error checking of pName left out */
>
>     pModule = PyImport_Import(pName);

As the docs for this function say, it just calls the same routine that
is called by the __import__ built-in function. One can experiment with
that:


OS-prompt>copy con foo.py
print 'hello fubar world'
^Z
        1 file(s) copied.

OS-prompt>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> __import__("foo")
hello fubar world
<module 'foo' from 'foo.py'>
>>> __import__("foo.py")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named py
>>> __import__("")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: Empty module name
>>> __import__(r".\foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: Empty module name
>>> __import__(r"./foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: Empty module name
>>> __import__(r"/foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named /foo
>>> __import__(r".foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: Empty module name
>>>

Hmmm ... "empty module name" is rather misleading when it starts with a
"." -- I can feel a bugfix^^^^^^ enhancement request coming on :-)

HTH,
John

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to