0
use Inline Python => <<'END';
   from MYPYTHONLIBRARY import *
END



my $Obj = MYPYTHONLIBRARY->new($a, $b);       # line 30

the error I am getting is: Can't locate object method "new" via package "MYPYTHONLIBRARY" (perhaps you forgot to load "MYPYTHONLIBRARY "?) at /MY/LIBRARY/PATH/MYPERLLIBRARY.pm line 30.

So i searched on net and found that

"Inline::Python inspects the main namespace of the Python code and imports those names into the current package. Thus you have to specify the fully qualified name of the imported class:

package TestPy;
use Inline Python => 'from StringIO import StringIO';
my $stringio = TestPy::StringIO->new;"  

•Markdown example link

My problem is that, in my code there is lot of do and require statement and I am not able to get the fully qualified name.

Fully::Qualified::name::MYPYTHONLIBRARY->new($a, $b);

So how can I get the fully qualified name for my python library.

5
  • Can you just use "stock" python? Commented Dec 24, 2014 at 6:44
  • @keith: I don't understand. what do you mean by "stock", is this a package or something. Commented Dec 24, 2014 at 6:57
  • I mean the code you are showing is not Python. Any reason you can't just use regular Python? Commented Dec 24, 2014 at 7:50
  • 1
    You may have to add the directory containing your modules to the PYTHONPATH env variable or modify sys.path from right in the Inline Python. You could play with something like ` use strict; use warnings; use Inline Python => <<END; import sys print sys.path END` to see the search path you're already getting from Inline and if maybe the code you want is somewhere in there? Commented Dec 24, 2014 at 7:51
  • @Keith: I have test framework written in perl. But having problem in automating few test cases of type [Test]stackoverflow.com/questions/27498384/…). So I have written a python lib and want use it with perl framework Commented Dec 26, 2014 at 5:48

1 Answer 1

1
from MYPYTHONLIBRARY import *
...
...
my $Obj = MYPYTHONLIBRARY->new($a, $b);

You are importing the names defined INSIDE a file called MYPYTHONLIBRARY.py. Do you have a class inside that file named MYPYTHONLIBRARY? I doubt it.

Here is an example of what you should be doing:

~/perl_programs$ ls 9.pl python_lib.py
9.pl        python_lib.py


~/perl_programs$ cat python_lib.py
def greet():
    print "hello"

class Dog(object):
    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name

~/perl_programs$ cat 9.pl
use Inline Python; 

my $d = Dog->new("Sam");
print $d->get_name() . "\n";

greet();
__END__
__Python__
from python_lib import *

~/perl_programs$ perl 9.pl 
Sam
hello

By the way, you should NEVER use from abc import * in a python program, and you shouldn't do it when using inline python, either.

So how can I get the fully qualified name for my python library.

You don't need the fully qualified name for your python library--you need the name of the perl package into which you are importing the python.

My problem is that, in my code there is lot of do and require statement and I am not able to get the fully qualified name.

How about a simple example?

Sign up to request clarification or add additional context in comments.

2 Comments

I do have a class in MYPYTHONLIBRARY.py. example link
I do have a class in MYPYTHONLIBRARY.py.Please go through this thread example link. You're running your program the main package that's why it is giving no problem. I am using inline python inside a module and wasn't able to resolve the FQN for my python lib.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.