Hi
I'm trying to make a python script (which would be called from a C#
application) and communicates with an IMAP server.
Passing variables from C# to python and back is no problem, but when I type
"import imaplib" on top of the python script to support IMAP, the script fails
to run at line with following code: "func.Invoke(arguments)". Showing error
message in the C# developer: "<null reference>".
I also tried to call PythonEngine.ImportModule("imaplib") first, but no change.
Is there a way to import the library? Thank you in advance.
Tip: Just found out about an amazing C# developer http://www.sharpdevelop.net
(open source)
Regards,
Kris
C#
***
try { string imapUser = "kris"; string imapPassword = "a password";
PythonEngine.Initialize(); PyObject[] arguments = new PyObject[2];
arguments[0] = PyObject.FromManagedObject(imapUser); arguments[1] =
PyObject.FromManagedObject(imapPassword); PyObject pyportal =
PythonEngine.ImportModule("PyPortal"); PyObject func =
pyportal.GetAttr("invoker"); PyObject result = func.Invoke(arguments);
this.label1.Text = result.ToString();} catch (Exception err) { this.label1.Text
= err.Message.ToString();}
The file PyPortal.py
***************
import imaplib # <-- causes error
def invoker(imapUser, imapPassword):
messages = [] M = imaplib.IMAP4('imap.next.mail.yahoo.com')
M.login(imapUser, imapPassword) M.select() typ, data = M.search(None,
'ALL') for num in data[0].split(): typ, data = M.fetch(num,
'(RFC822)') messages.append('Message %s\n%s\n' % (num, data[0][1]))
M.close() M.logout() return '<delimiter>'.join(messages)
_________________________________________________________________
Ontdek Windows Live Hotmail, het ultieme online mailprogramma!
http://get.live.com/mail/overview
_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet