Hi Dave,

On Wednesday 26 February 2014 16:09:33 Dave Howorth wrote:
>  I have a simple test script that works:
> 
> use Inline Python => 'from fastCif.fastParser import cifToHashParser';
> my $parser = new cifToHashParser;
> my $result = $parser->parse($file);
> 
> But when I include the same code in a Perl module I get an error when I
> try to use the Perl module in the test program:
> 
> Can't locate object method "new" via package "cifToHashParser" (perhaps
> you forgot to load "cifToHashParser"?) at

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;

It's the same as when your TestPy package imports names from other Perl 
modules.

Your test script worked because in Perl you don't have to qualify names in the 
main package, though doing so works as well:

package main;
use Inline Python => 'from StringIO import StringIO';
my $stringio = main::StringIO->new; # works
my $stringio = ::StringIO->new; # shortcut works, too
my $stringio = StringIO->new; # unqualified works as well

Regards,
Stefan

Reply via email to