25 Aug 10:44
TypeError question
From: Heshan Suriyaarachchi <heshan.suri <at> gmail.com>
Subject: TypeError question
Newsgroups: gmane.comp.lang.jython.user
Date: 2008-08-25 08:45:15 GMT
Subject: TypeError question
Newsgroups: gmane.comp.lang.jython.user
Date: 2008-08-25 08:45:15 GMT
Hi,
I need to analyse a python script(annotationScript.py) from another python script(Processor) within java.
1). I did like below and it gave an error. It is confusing for me because when I called the method using python it worked without errors. Can anyone help me to overcome this error.
//java code
interp.exec("import annotationScript");
interp.exec("import Processor");
String stt = "Processor.getDictionary(annotationScript)";
PyObject ob1 = interp.eval(stt);
#python method
def getDictionary(str1):
#strFile = "/home/heshan/workspace/IdeaProjects/PYtest/src/pythonScripts/annotationScript.py"
#fh = open(strFile,"r")
fh = open(str1,"r")
igot = fh.readlines()
Dictionary = {}
for line in igot:
#store the necessary data to Dictionary
print Dictionary
return Dictionary
StackTrace
Exception in thread "main" Traceback (innermost last):
File "<string>", line 1, in ?
File "/home/heshan/workspace/IdeaProjects/PYtest/src/pythonScripts/Processor.py", line 20, in getDictionary
TypeError: org.python.core.PyFile(): 1st arg can't be coerced to java.io.OutputStream, java.io.InputStream, java.io.RandomAccessFile or java.io.Writer
2). Since the error was a casting error I thought of doing it like below. It gave an error as well.
//java code
interp.exec("import Processor");
String filePath = "/home/heshan/repo/scripts/annotationScript.py";
String stt = "Processor.getDictionary(" + filePath +")";
PyObject ob1 = interp.eval(stt);
StackTrace
Exception in thread "main" Traceback (innermost last):
(no code object) at line 0
SyntaxError: ('invalid syntax', ('<string>', 1, 25, 'Processor.getDictionary(/home/heshan/repo/scripts/annotationScript.py)'))
Can anyone give me an idea of how to overcome this issue.
--
Regards,
Heshan Suriyaarachchi
http://heshans.blogspot.com/
I need to analyse a python script(annotationScript.py) from another python script(Processor) within java.
1). I did like below and it gave an error. It is confusing for me because when I called the method using python it worked without errors. Can anyone help me to overcome this error.
//java code
interp.exec("import annotationScript");
interp.exec("import Processor");
String stt = "Processor.getDictionary(annotationScript)";
PyObject ob1 = interp.eval(stt);
#python method
def getDictionary(str1):
#strFile = "/home/heshan/workspace/IdeaProjects/PYtest/src/pythonScripts/annotationScript.py"
#fh = open(strFile,"r")
fh = open(str1,"r")
igot = fh.readlines()
Dictionary = {}
for line in igot:
#store the necessary data to Dictionary
print Dictionary
return Dictionary
StackTrace
Exception in thread "main" Traceback (innermost last):
File "<string>", line 1, in ?
File "/home/heshan/workspace/IdeaProjects/PYtest/src/pythonScripts/Processor.py", line 20, in getDictionary
TypeError: org.python.core.PyFile(): 1st arg can't be coerced to java.io.OutputStream, java.io.InputStream, java.io.RandomAccessFile or java.io.Writer
2). Since the error was a casting error I thought of doing it like below. It gave an error as well.
//java code
interp.exec("import Processor");
String filePath = "/home/heshan/repo/scripts/annotationScript.py";
String stt = "Processor.getDictionary(" + filePath +")";
PyObject ob1 = interp.eval(stt);
StackTrace
Exception in thread "main" Traceback (innermost last):
(no code object) at line 0
SyntaxError: ('invalid syntax', ('<string>', 1, 25, 'Processor.getDictionary(/home/heshan/repo/scripts/annotationScript.py)'))
Can anyone give me an idea of how to overcome this issue.
--
Regards,
Heshan Suriyaarachchi
http://heshans.blogspot.com/
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ Jython-users mailing list Jython-users <at> lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jython-users
RSS Feed