Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

In order to use the google data API without using (much) python,
I want to use Inline::Python.

The following code works, however, I do not know how to call the
function CreateEntry() from the ContactsSample class in
the perl code.

Thanks for any help with this.

Eric Smith


print "Hello from perl\n";

use Inline Python => <<'END_OF_PYTHON_CODE';
import sys
import getopt
import getpass
import atom
import gdata.contacts
import gdata.contacts.service

class ContactsSample(object):
  """ContactsSample object demonstrates operations with the Contacts feed."""

  def __init__(self, email, password):
    """Constructor for the ContactsSample object."""

    self.gd_client = gdata.contacts.service.ContactsService() = email
    self.gd_client.password = password
    self.gd_client.source = 'GoogleInc-ContactsPythonSample-1'

  def CreateEntry(self):
    name = 'John Doe''
    notes = "Something about him"
    primary_email = ''

    new_contact = gdata.contacts.ContactEntry(title=atom.Title(text=name))
    new_contact.content = atom.Content(text=notes),
        primary='true', rel=gdata.contacts.REL_WORK))
    entry = self.gd_client.CreateContact(new_contact)

    if entry:
      print 'Creation successful!'

  def Run(self):

def main():

  user = 'XXXXXXXXX'
  pw = 'XXXXXXXX'

    sample = ContactsSample(user, pw)
  except gdata.service.BadAuthentication:
    print 'Invalid user credentials given.'


if __name__ == '__main__':

Re: Inline::Python

Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it

I've never used Inline::Python, but did you try (in Perl)

    my $cs = ContactsSample->new;

That's usually how Inline modules work: they just import the appropriate
symbols into your Perl namespace.


Re: Inline::Python

Thanks Ben, but no dice alas.

I also tried this from the manual:
py_bind_class("Inline::Python", "__main__", "ContactsSample",\
"set_data", "get_data");
my $o = new ContactsSample;

Both respond with:
Can't locate object method "new" via package "ContactsSample"

Any suggestions / help?



Quoted text here. Click to load it

Eric Smith

Site Timeline