how to get an output python from java input? -


actually, i'm new in python. here, want output class of python. here, input string java.

here's java code:

    string word;     scanner in = new scanner(system.in);     system.out.println("input: ");     word = in.nextline();      tryinpythontojavaagain ie = new tryinpythontojavaagain();     ie.execfile("~\\hello.py");      pyinstance hello = ie.createclass("hello", word);     hello.invoke("run"); 

python code:

class hello:  def __init__(self, abc):     self.abc  = abc  def run(self):     print(self.abc) 

if input : "hello" have error this:

input: hello exception in thread "main" traceback (most recent call last): file "", line 1, in nameerror: name 'hello' not defined java result: 1

and if input >2 word (e.g "hello world"), have error this:

input: hello world exception in thread "main" syntaxerror: ("no viable alternative @ input 'world'", ('', 1, 12, 'hello(hello world)\n')) java result: 1

what should fix in code? thanks

if code in createclass method looks ...

pyinstance createclass( final string classname, final string opts )   {       return (pyinstance) this.interpreter.eval(classname + "(" + opts + ")");   } 

... think need add quotes round opts variable. code above here works since "none" gets turned this.interpreter.eval(classname(none)) valid whereas yours becomes this.interpreter.eval(classname(hello world)) isn't.

i've not tried it, this.interpreter.eval(classname("hello world")) seem more work.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -