[IronPython] Newbie: convert string to python expression??

2008-12-16 Thread xkrja
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread xkrja
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread xkrja
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:

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Kristian Jaksch
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Konrad Delong
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

[IronPython] Modules importing each other

2008-12-16 Thread Yash Ganthe
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Orestis Markou
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Douglas Blank
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Modules importing each other

2008-12-16 Thread Michael Foord
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

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread xkrja
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

Re: [IronPython] IronPython and file descriptors

2008-12-16 Thread Tom Wright
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

[IronPython] weird performance issue

2008-12-16 Thread Kamil Dworakowski
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):

[IronPython] weird performance issue

2008-12-16 Thread Kamil Dworakowski
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):

Re: [IronPython] Newbie: convert string to python expression??

2008-12-16 Thread Michael Foord
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

Re: [IronPython] weird performance issue

2008-12-16 Thread Dino Viehland
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