C# Python Input Method Returns An Error
I've just started to learn IronPython and I tried the code below which returned
IronPython.Runtime.UnboundNameException: 'name 'hello' is not defined'.
var py = Python.CreateEngine(); var scope = py.CreateScope(); py.Execute(@"word = input('Input string\n')", scope); var input = scope.GetVariable("word"); py.Execute("print " + input);
Console run ok, then it asked me to
Input string, and I typed into
"hello". And then it fired off the above error message. Then I tried this one just to see if it does without
py.Execute(@"x = 2 + 3", scope); py.Execute("print 'result'," + scope.GetVariable("x"));
So that one was ok.
Can someone please explain why can I not retrieve a variable from
"input" method? and why is it an
Having never worked with ironpython the answer lies within your own code.
py.Execute(@"word = input('Input string\n')", scope); (I type in dog) var input = scope.GetVariable("word"); py.Execute("print " + input);
results in that last line saying py.Execute("print dog") ... but there is no dog varaible.
py.Execute("print 'result'," + scope.GetVariable("x"));
You know to encapsulate text in quotes..
Id speculate that
py.Execute("print " + input);
py.Execute("print '" + input + "'");
Which results in print 'dog'
- → How to Fire Resize event after all images resize
- → URL routing requires /Home/Page?page=1 instead of /Home/Page/1
- → Getting right encoding from HTTPContext
- → How to create a site map using DNN and C#
- → I want integrate shopify into my mvc 4 c# application
- → Bootstrap Nav Collapse via Data Attributes Not Working
- → Shopify api updating variants returned error
- → ASP.NET C# SEO for each product on detail page on my ECOMMERCE site
- → SEO Meta Tags From Behind Code - C#
- → How to implement search with two terms for a collection?