[IronPython] [python] Re: Need a Good Embedded Example
Joshua J. Pearce
joshua.pearce at gmail.com
Mon Oct 22 17:47:47 CEST 2007
I tried to following code in my simple test app:
var1 = "Josh"
for i in range(5):
print i
pe.ExecuteCommand threw a SyntaxErrorException, "unexpected token 'for'
exception.
It works fine if execute it in a file like, ipy test.py at the command line.
If I leave off the "var1 = "Josh", and the for loop starts at the first
line, it works.
The problem I am having probably stems from my lack of understanding of the
ipy engine, but I though that this statement:
If you're executing code from a multiline textblock - then it shouldn't
be a problem as you won't be executing code one line at a time...
suggested my code would work.
- Josh Pearce
On 10/20/07, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>
> Joshua J. Pearce wrote:
> > Thanks! Where can I find help with getting the python engine to deal
> > with the indents involved with loops, defs, and such?
> Well - indents and loops and such is just ordinary Python code. Do you
> want this code to be entered one line at a time, like an interactive
> interpreter?
>
> If you're executing code from a multiline textblock - then it shouldn't
> be a problem as you won't be executing code one line at a time...
>
> In Mike Stall's article
>
> 'Evaluate' executes a single expression and returns the result.
>
> 'Execute' executes a block of code.
>
> That article is from 2005 though.
>
> Michael
> http://www.manning.com/foord
>
> > I read Mike Stalls article, 10 Easy Steps to Embedding..., but I still
> > can't understand the difference between evaluate and execute methods.
> >
> > I am trying to use IPY as a scripting language for my ASP.NET
> > <http://ASP.NET> app, so I really need to know how to build my own
> > shell in C# in addition to the help you all have already given me in
> > using my c# classes in the python code.
> >
> > Thanks!
> >
> > On 10/19/07, *Michael Foord* <fuzzyman at voidspace.org.uk
> > <mailto:fuzzyman at voidspace.org.uk>> wrote:
> >
> > Joshua J. Pearce wrote:
> > > What am I doing wrong? I have a form with two text boxes and a
> > button.
> > > When I type, "tb.clear()" into the first textbox and click the
> > button,
> > > I get the a MissingMemberException which states, "'TextBox'
> > object has
> > > no attribute 'clear'".
> >
> > Do you mean "tb.Clear()" ?
> >
> > Michael
> >
> >
> > >
> > >
> > > public partial class Form1 : Form
> > > {
> > > public static PythonEngine pe = PythonEngine.CurrentEngine
> ;
> > > public Form1()
> > > {
> > > InitializeComponent();
> > >
> > >
> > ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable
> ("tb",
> > > textBox2);
> > > }
> > >
> > >
> > > private void button1_Click(object sender, EventArgs e)
> > > {
> > > pe.ExecuteCommand (textBox1.Text);
> > >
> > > }
> > > }
> > >
> > >
> > > Thanks,
> > >
> > > Josh Pearce
> > >
> > >
> > > On 10/18/07, *Joshua J. Pearce* < joshua.pearce at gmail.com
> > <mailto:joshua.pearce at gmail.com>
> > > <mailto: joshua.pearce at gmail.com
> > <mailto:joshua.pearce at gmail.com>>> wrote:
> > >
> > > I am very sorry! I just noticed this:
> > >
> > > ScriptDomainManager.CurrentMan
> > > ager.Host.DefaultModule.SetVariable("SomeName",
> > > SomeObject);
> > >
> > > SomeObject is then available to user code as SomeName...
> > >
> > > That is exactly what I want to do!!!
> > >
> > > Thank you very much!
> > >
> > >
> > >
> > > On 10/18/07, *JoeSox* <joesox at gmail.com
> > <mailto:joesox at gmail.com> <mailto:joesox at gmail.com
> > <mailto:joesox at gmail.com>>>
> > > wrote:
> > >
> > > On 10/18/07, Joshua J. Pearce < joshua.pearce at gmail.com
> > <mailto:joshua.pearce at gmail.com>
> > > <mailto:joshua.pearce at gmail.com
> > <mailto:joshua.pearce at gmail.com>>> wrote:
> > > > My application is ASP.NET <http://ASP.NET>
> > <http://ASP.NET>, I hardly think
> > > integrating CPython is going to be a better choice.
> > >
> > > You never mentioned you were using ASP.NET
> > <http://ASP.NET> <http://ASP.NET>.
> > > You have mentioned C#.
> > >
> > > > Is is possible to 'expose' c# methods that exist in
> > the same
> > > scope as an IPY
> > > > engine,
> > >
> > > Can you clarify what you mean by this line for me? Can
> you
> > > provide a
> > > C# method that exists in the same scope as an IPY engine?
> > >
> > > There must be a custom interface, how would an outside
> > script know
> > > about a custom method outside it's scope without an custom
> > > interface?
> > > Michael and myself have both provided examples.
> > >
> > > If you have a C# method it must be represented by
> something
> > > else in
> > > the script or python code that IronPythonEngine is
> > using, then
> > > update
> > > the script or python code loaded in the IronPythonEngine
> > using
> > > the
> > > examples provided.
> > >
> > > Since I have not seen your source, I don't know why you
> > believe
> > > importing the AppService dll and create your own
> > instance in
> > > the IP
> > > engine will be too much overhead. That sounds like the
> bet
> > > way to go
> > > but I am not familiar with your source.
> > > Good Luck!
> > > --
> > > Later, JoeSox
> > > _______________________________________________
> > > Users mailing list
> > > Users at lists.ironpython.com
> > <mailto:Users at lists.ironpython.com> <mailto:
> > Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>>
> > >
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > <http://lists.ironpython.com/listinfo.cgi/users-ironpython.com>
> > >
> > >
> > >
> > >
> > > --
> > > Joshua Pearce
> > >
> > >
> > >
> > >
> > > --
> > > Joshua Pearce
> > >
> >
> ------------------------------------------------------------------------
> >
> > >
> > > _______________________________________________
> > > Users mailing list
> > > Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
> > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > >
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> >
> >
> >
> > --
> > Joshua Pearce
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
--
Joshua Pearce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20071022/ada2fa28/attachment.html>
More information about the Ironpython-users
mailing list