Hi,
I'm just starting out learning IronPython. How can I convert a string that
someone writes in a textbox to a python expression or statement?? Compare it
to the console input: If I write for example a=2 in the console it's not
just a string I assume? It becomes an expression in the python code
context = {}
def inputBox_KeyDown(s, e):
root.message.Text = ''
key = e.Key.value__
result = root.inputBox.Text
if key == 3: #If 'Enter' key is pressed
try:
try:
root.message.Text = eval(result)
except SyntaxError:
exec result in
xkrja wrote:
Thanks!
I'm using Ironpython with Silverlight so I can't get access to Windows.Forms
Ah - in which case it probably lives in System.Windows.Input
Please bear with me :-) New stuff's showing up all the time. The solution
you proposed worked but there must be something I don't
xkrja wrote:
Thanks for the reply. This is what I have:
def inputBox_KeyDown(s, e):
root.message.Text = ''
key = e.Key.value__
if key == 3:
result = eval(root.inputBox.Text)
root.message.Text = str(result)
eval() seems to work sometimes. For example if the text in
Thanks for the replies guys.
I tried the solution below and it works in some cases. But a strange thing
is (remember I'm a newbie) that if I first type, for example a=1 in the
inputBox and then hit enter, the debugger goes down to exec
root.inputBox.Text and nothing is reported so I assume the
Thanks for the reply.
Below is a snippet of what I've got:
def inputBox_KeyDown(s, e):
root.message.Text = ''
key = e.Key.value__
result = root.inputBox.Text
if key == 3: #If 'Enter' key is pressed
try:
root.message.Text = eval(result)
except:
Ok, did you mean something like below?:
*
clr.AddReference(Mapack, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null)
from Mapack import *** #A library that contain classes for working with
algebra etc.*
*context = {}
context['m'] = Matrix(5,5)#creating a 5 rows, 5 columns matrix
Kristian Jaksch wrote:
Ok, did you mean something like below?:
*
clr.AddReference(Mapack, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null)
from Mapack import *** #A library that contain classes for working
with algebra etc.*
*context = {}
context['m'] = Matrix(5,5)#creating
2008/12/16 xkrja kristian.jak...@gmail.com:
Hi,
I'm just starting out learning IronPython. How can I convert a string that
someone writes in a textbox to a python expression or statement?? Compare it
to the console input: If I write for example a=2 in the console it's not
just a string I
I use IronPython 2.0.
In Program.py I have:
print hello
DEBUGMODE=0
.
.
.
import LogMessage
In LogMessage.py I have
from Program import DEBUGMODE
When I run :
ipy Program.py
I observe that hello is printed twice: Once when Program.py is run and
next when a symbol from Program.py is imported in
you have to pass the context to eval as well:
eval(result, context)
make sure that the context doesn't change between calls to eval and
exec. It should be a property on your form, really, but it doesn't seem
so. Just make sure that you don't re-create the context every time.
If you don't
xkrja wrote:
Thanks for the replies guys.
I tried the solution below and it works in some cases. But a strange thing
is (remember I'm a newbie) that if I first type, for example a=1 in the
inputBox and then hit enter, the debugger goes down to exec
root.inputBox.Text and nothing is reported so
This is just a Python issue (not specific to IronPython).
exec is used for statement(s) and eval() for expressions. You might have to:
try:
eval(root.inputBox.Text)
except:
exec root.inputBox.Text
-Doug
- xkrja kristian.jak...@gmail.com wrote:
Thanks for the reply. This is what I
Michael Foord wrote:
Kristian Jaksch wrote:
*
def inputBox_KeyDown(s, e):
key = e.Key.value__
result = root.inputBox.Text
if key == 3: #If 'Enter' key is pressed
try:
try:
root.message.Text = eval(result)
except SyntaxError:
exec result in
You would find the same thing in CPython. When you execute Program.py it
is run with the name '__main__' (the main program being executed). When
you import it, you import it with the name 'Program' which causes it to
be imported with a different name. I suggest you put your debug symbol
in a
Thanks for the reply. This is what I have:
def inputBox_KeyDown(s, e):
root.message.Text = ''
key = e.Key.value__
if key == 3:
result = eval(root.inputBox.Text)
root.message.Text = str(result)
eval() seems to work sometimes. For example if the text in the textbox is
I'm not sure about sockets. The only example I have found in the wild so
far is with files in PIL.
The python implementation seems to have socket.fileno() returning a file
descriptor which comes from sys/socket.h's socketpair function in the
standard C library (see socketmodule.c if you are
We see a very strange side effect of running the follwing code on the
performance of recalculations in Resolver One.
def Dumbcorator(fn):
def _inner(self, *args):
return fn(self, *args)
return _inner
class Locker(object):
@property
@Dumbcorator
def thing(self):
We see a very strange side effect of running the follwing code on the
performance of recalculations in Resolver One.
def Dumbcorator(fn):
def _inner(self, *args):
return fn(self, *args)
return _inner
class Locker(object):
@property
@Dumbcorator
def thing(self):
Kristian Jaksch wrote:
Michael,
What do you mean exec the import * inside the context to poulate it?
Something like:
*context['Mapack'] = exec from Mapack import * #Doesn't work
*Hmmm... think I'm getting tired.
exec doesn't return anything.
Try:
*exec from Mapack import * in
My guess would be that we're pushing the PythonContext._callSplatSite outside
of the sweet spot in DLR site caches.
You could check this by putting a breakpoint in PythonContext.Call(object,
params object[]). Then look and see if _callSplatSite._rules is an instance of
EmptyRuleSetT with
21 matches
Mail list logo