[IronPython] DB-API for IronPython, odbc and sqlclient
Mark Rees wrote, debugged, tested, and sent me a DB-API driver for ODBC and SQL server, based on my generic_connect, and fixes needed to dbapi.py. Thanks! Get them here: http://sparcs.kaist.ac.kr/~tinuviel/fepy/dbapi/ It seems that one needs to set Transaction attribute of DbCommand explicitly after doing CreateCommand on DbConnection. However, all open source ADO.NET connectors I tested (MySQL, PostgreSQL, SQLite) didn't need this step as they defaulted to the current transaction of the connection the command was created from. But ones in MS.NET do. -- Seo Sanghyeon ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] How to dynamically define and call a function?
hi, I confess to being a newbie at this sort of thing in Python or IronPython, so I'm hoping that there is a simple answer to the subject question. I started off trying to use standard compile() function and exec statement, but was unable to make it work, although I'm sure there must be a way. Is there? How? So then I tried the following instead: import IronPython from IronPython import Hosting s = def myAdd(x,y):\nreturn x+y\n engine = Hosting.PythonEngine() mod = engine.CreateModule() engine.Execute(s,mod) My understanding is that the above should have created a function named myAdd inside the newly minted mod module, but if it did so I was unable to find any evidence of it. How would I access/use it? So then I modified the above to name the module and import it (even though this doesn't really meet my ultimate requirements): import IronPython from IronPython import Hosting s = def myAdd(x,y):\nreturn x+y\n engine = Hosting.PythonEngine() mod = engine.CreateModule(testing,True) engine.Execute(s,mod) import testing but alas this throws an ImportError: No module named testing. Why? yrs in puzzlement, gary ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] How to dynamically define and call a function?
2006/9/18, Gary Stephenson [EMAIL PROTECTED]: I started off trying to use standard compile() function and exec statement, but was unable to make it work, although I'm sure there must be a way. Is there? How? This works for me: IronPython 1.0.2449 on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. code = def add(x, y):\n\treturn x + y\n exec code add(2, 3) 5 Seo Sanghyeon ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] How to dynamically define and call a function?
Alternatively, you can simply use the file object to write it to a new module and import it later. newmod=file('newmodule.py','w')newmod.write('def add(x,y):\n return x+y\n')newmod.close()import newmodule print newmodule.add(10,20)VagmiOn 9/18/06, Sanghyeon Seo [EMAIL PROTECTED] wrote: 2006/9/18, Gary Stephenson [EMAIL PROTECTED]: I started off trying to use standard compile() function and exec statement, but was unable to make it work, although I'm sure there must be a way. Is there? How?This works for me:IronPython 1.0.2449 on .NET 2.0.50727.42Copyright (c) Microsoft Corporation. All rights reserved. code = def add(x, y):\n\treturn x + y\n exec code add(2, 3)5Seo Sanghyeon___users mailing listusers@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com-- http://geekswithblogs.net/vagmi.mudumbaihttp://installneo.blogspot.comPeace is its own reward. - Mahatma Gandhi ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] How to dynamically define and call a function?
d'oh! I knew there must have been a straightforward way. I'm still curious as to how to use the IronPython.Hosting stuff though, as I thinkultimately it might prove to be more what I'm really after. thanks, gary This works for me: IronPython 1.0.2449 on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. code = def add(x, y):\n\treturn x + y\n exec code add(2, 3) 5 ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] What PythonEngine called my C# code? (was: custom ConfigurationSection in IronPython)
Not that I saw. On Sep 18, 2006, at 11:14 AM, J. Merrill wrote: Was an answer to this ever given? At 12:34 PM 9/1/2006, Jason Ferrara wrote If I wanted to write a stub in C#, how do I get access to a PythonEngine that represents the python environment that called the C# code? Just calling IronPython.Hosting.PythonEngine() seems to get me a new environment. J. Merrill / Analytical Software Corp ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] What PythonEngine called my C# code? (was: custom ConfigurationSection in IronPython)
Probably the lack of an answer is due to the fact that there isn't a really great way to do this. Here's two possible ways to pull this off: For #1 you presumably kicked off the Python code via the hosting APIs, and therefore you know the engine that kicked it off. If you have multiple Python engines this might be tricky (if you have only one running on each thread at a time you could store it in a [ThreadStatic]). If you start getting into more complicated scenarios obviously this is going to break down quickly... For #2 you're looking at using ICallerContext. This is a bit of internal machinery that IronPython uses to flow state around for things that might need state (e.g. hiding CLR methods, locals(), exec, etc...). Off of ICallerContext there is both a SystemState and a PythonModule property. Unfortunately there's nothing that leads you directly to a PythonEngine. Instead you'd need to maintain a table of either modules-engines or SystemState (sys module) - engines. #2 will work reliably if you control the creation of all engines in the process - the instance you go out of that it'll break down. The alternate plan here might be that having access to a SystemState and PythonModule you could already do some interesting things even though you don't have the full blown PythonEngine. It'd be interesting to hear if those are sufficient or if you really do need the engine in this case (and how horrible you think the 2 solutions are :) ). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jason Ferrara Sent: Monday, September 18, 2006 8:48 AM To: Discussion of IronPython Subject: Re: [IronPython] What PythonEngine called my C# code? (was: custom ConfigurationSection in IronPython) Not that I saw. On Sep 18, 2006, at 11:14 AM, J. Merrill wrote: Was an answer to this ever given? At 12:34 PM 9/1/2006, Jason Ferrara wrote If I wanted to write a stub in C#, how do I get access to a PythonEngine that represents the python environment that called the C# code? Just calling IronPython.Hosting.PythonEngine() seems to get me a new environment. J. Merrill / Analytical Software Corp ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] __getattr__ overflow
Hi, I was trying to wrap a rather verbose library to something more concise. Essentially, I have a module with a bunch of static functions and I wanted to create an object that automatically adds a prefix to the function calls. For example: my_wrapper.CallFunction(*args)Would be like:myapi.F_ApiPrefixCallFunction(*args)In CPython I could do something like this:class wrap(myapi): def __getattr__(self, method): prefix_method = F_ApiPrefix + method return self.prefix_methodc = wrap()c.CallFunction() This returns the right thing.In IronPython it gives a buffer overflow. I have posted the following code I used to test this out. class C:... def __getattr__(self, var):... pre_name = say_ + str(var)... return self.pre_name... def hello(self, name):... print Hello %s! % name ... c = C() c.hello('eric')Hello eric!Sorry if this has already been posted/reported. I took a quick glance at the codeplex database, but I didn't know if it was the same issue reported for other __getattr__ bugs. Thanks!Eric ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] [Python-Dev] IronPython and AST branch
Brett Cannon wrote: As for making the AST branch itself more of a standard, I have talked to Jeremy Hylton about that and he didn't like the idea, at least for now. The reasons for keeping it as experimental in terms of exposure at the Python level is that we do not want to lock ourselves down to some AST spec that we end up changing in the future. It's the same reasoning behind not officially documenting the marshal format; we want the flexibility. How best to resolve all of this, I don't know. I completely understand not wanting to lock ourselves down to an AST too soon. Might need to wait a little while after the AST has been out in the wild to see what the user response is and then make a decision. One of the biggest issues I have with the current AST is that I don't believe it really gets the slice and extended slice terminology correct (it uses 'extended slice' to refer to multi-dimensional indexing, but the normal meaning of that phrase is to refer to the use of a step argument for a slice [1]) Cheers, Nick. [1] http://www.python.org/doc/2.3.5/whatsnew/section-slices.html -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://www.boredomandlaziness.org ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] A SourceForge project?
+1 for sourceforge. On 9/15/06, David Fraser [EMAIL PROTECTED] wrote: Sanghyeon Seo wrote: I am thinking about creating a SourceForge project, to host files under http://sparcs.kaist.ac.kr/~tinuviel/fepy/ directory. So that you can keep up-to-date just by doing svn update. So that I can release IPCE zip to mirrors with beefy bandwidths, not to a feeble webserver of my former university's computer society. Maybe one of you can join me and I can give you a write access. What do you think? Do you have a hosting recommendation over SourceForge? (CodePlex is no-no for me, I don't have TFS client.)I'm up for a sourceforge project - lots of open source developers (like me :-) ) have accounts there, svn is good and they have good downloadmirrors although the upload mechanism is a pain :-) - and you can set upa web site for it.I'm davidfraser on sourceforge if you want to add me as a developer :-) Would be nice if the IronPython source repository could somehow bemirrored into subversion... any projects that do that from Team Foundation?CheersDavid___ users mailing listusers@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Trying (unsuccessfully) to subclass Gtk.Widget class
I think you might have to set your module your of your PythonEngine to __main__. For example:PythonEngine myPyEngine = new PythonEngine(someEngineOptions);EngineModule mainModule = myPyEngine.CreateModule (__main__, someVariables, true);myPyEngine.ExecuteFile(someScriptFile, mainModule);There are some extra there such as the someVariables but hopefully that might get you going in the right direction. HTHEricOn 9/15/06, Michael Welch [EMAIL PROTECTED] wrote: Hello,I'm running IPython 1.0 on mono on Linux. I'm importing the gtk-sharpdll and I want to subclass the Gtk.Widget class( http://www.go-mono.com/docs/[EMAIL PROTECTED]).Here is my script:clr.AddReference(gtk-sharp)clr.AddReference(gnome-sharp)from Gtk import * from Gnome import *Application.Init()class Table: passclass Sheet(Widget): def __init__(self, table): Widget.__init__(self)Here is my ipy session where I try to use SheetIronPython 1.0.2432 on .NET 2.0.50727.42Copyright (c) Microsoft Corporation. All rights reserved. import sheet from sheet import * t = Table() s = Sheet(t)Traceback (most recent call last): TypeError: no overloads of Sheet could match (type, Table)Sheet(type, IntPtr)Sheet(type, GType)It tells me it can't find an appropriate overload for Sheet and thengives me what looks like the only two possible candidates. However, the candidates it lists looks like they are from the parent classWidget. Does IronPython hava a constraint that the __init__ methodmust take the same parameters as the parent class? Here is the list ofconstructors for Widget: http://www.go-mono.com/docs/[EMAIL PROTECTED]If I remove the parameter from __init__ it works. I've tested this scenario with made up classes and it works. CPython documentationseems to indicate that a child class can have different parameters onits __init__method then the parent class. Any help? Is there somethingwrong with the gt-sharp library (I don't think so, as I could write a C# app that did this same thing and it worked).I'm convinced this must be user-error and I'm just not seeing the problemThanks,Michael___users mailing list users@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] A SourceForge project?
I'll add my vote.On 9/18/06, Eric Larson [EMAIL PROTECTED] wrote: +1 for sourceforge. On 9/15/06, David Fraser [EMAIL PROTECTED] wrote: Sanghyeon Seo wrote: I am thinking about creating a SourceForge project, to host files under http://sparcs.kaist.ac.kr/~tinuviel/fepy/ directory. So that you can keep up-to-date just by doing svn update. So that I can release IPCE zip to mirrors with beefy bandwidths, not to a feeble webserver of my former university's computer society. Maybe one of you can join me and I can give you a write access. What do you think? Do you have a hosting recommendation over SourceForge? (CodePlex is no-no for me, I don't have TFS client.)I'm up for a sourceforge project - lots of open source developers (like me :-) ) have accounts there, svn is good and they have good downloadmirrors although the upload mechanism is a pain :-) - and you can set upa web site for it.I'm davidfraser on sourceforge if you want to add me as a developer :-) Would be nice if the IronPython source repository could somehow bemirrored into subversion... any projects that do that from Team Foundation?CheersDavid___ users mailing listusers@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___users mailing listusers@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Cheetah works on IronPython
The md5 is a known issue; I know Seo has code, but I seem to recall a post saying that it didn't work (http://sparcs.kaist.ac.kr/~tinuviel/fepy/lib ). Kevin Chu posted an md5 module to this list - you might give try using that before spending too much time investigating your sys.path. --Thane -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Russell Sent: Saturday, September 16, 2006 12:19 PM To: users@lists.ironpython.com Subject: Re: [IronPython] Cheetah works on IronPython Sanghyeon Seo wrote: Cheetah is a template engine written in Python: http://cheetahtemplate.org/ IronPython is an implementation of the Python programming language running on .NET: http://www.codeplex.com/IronPython I tested Cheetah 2.0rc7 with IronPython 1.0 for a while, and it seems to work nicely. Here is a sample code I used to test. It should print environment variables. I'm new to IronPython, so I'm probably missing something terribly obvious! My problem is that I'm unable to get Cheetah even close to working - which is unfortunate since I do use Cheetah. I've gone through the IronPython tutorial and written some C# to work between the two worlds. Things (mostly) work. I can import and use the fundimentals like StringIO, sys, os, os.path, logging, re but some things just won't import. In particular, importing urllib2 or Cheetah will fail because md5 can't be found. I suspect I'm not setting my sys.path correctly, but it looks like it should work. I'm using IronPython 1.0.60816 on .NET 2.0.50727.42 with Python 2.4.1. Any ideas? Thanks, Russell. ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] socket for IronPython update
Actually, there were some related discussions after the release of IronPython 0.7. It is archived in the list archives, starting in March 2005. Hopefully, it will answer some of your questions. Second link is Jason Matusow's blog which has some related comments too. http://lists.ironpython.com/pipermail/users-ironpython.com/2005-March/date.html http://blogs.msdn.com/jasonmatusow/archive/2005/03.aspx Martin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Fraser Sent: Friday, September 15, 2006 10:11 AM To: Discussion of IronPython Subject: Re: [IronPython] socket for IronPython update Dino Viehland wrote: Unfortunately we cannot currently accept changes back into the IronPython core right now. :( Not at all? What are the issues? David ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] Performance comparisons
Hello all, I have used Python extensively for research and algorithm development, and I am just beginning to explore IronPython. I wanted to start using IronPython for some web/database related work. I have seen the performance comparisons between IronPython and CPython, does anyone know of any comparisons for IronPython vs C# or IronPython vs Java (and C++)? Thanks, Elliot ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] Pyc IronPython Sample
Were happy to announce the release of another sample, Pyc, which shows how to generate .NET executables from IronPython scripts. This includes the pyc.py helper script which accepts a few command line parameters and generates the executables for you. The sample can be downloaded from http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=IronPythonReleaseId=423 (IronPython-1.0-Samples-Pyc.zip) and details on whats provided can be found at http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPythontitle=Samples . Please note that due to a problem in Codeplex it was not possible to update IronPython-1.0-Samples-All.zip to include Pyc. Have fun! The IronPython Team ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Performance concerns with mail merge
It sounds like you want the PythonEngine.CreateMethod API. This allows you to create a delegate that you can call from C# repeatedly w/o any recompilation happening. If you want to swap this out w/ a different delegate you can just call CreateMethod again and update your table of delegates. The way this works is you give it a delegate type (via the generic parameter) and then you give it a body of code (minus the function declaration) and optionally argument names incase youre not happy w/ the names the delegate has. Itll return an instance of the delegate type to you, and you can call it from your try block. The 1.0 release includes a .chm which includes full documentation on the API as well. From there its just up to you to decide how to invalidate your delegates that you hold a reference to and request a new delegate. When you release the reference to the delegate the memory associated w/ the code will be released as well. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David C Sent: Monday, September 18, 2006 3:10 PM To: users@lists.ironpython.com Subject: [IronPython] Performance concerns with mail merge Hi, We have a mail merge engine. We wish to have the option of blessing mail merge fields (say ##FirstName##) with the ability to do string formatting, such as proper casing, all caps, date formatting, and such. And the idea is while the mail merge engine is compiled C# code, we are hoping to leverage the dynamic nature of ironpython to allow business analysts and other staff to bless these mail merge fields with dynamic behaviors at a later date--through scripting. We imagine the signature of such a filter would go something like: protected string Filter_SomeBase32GibberishThatsSafeAlphaNumeric(string dirtyText, Xml filterContext) { string cleanText = ; try { // the dynamic part that do something with cleanText, given additional information provided by filterContext xml dom // as an aside, this source code is checked into the db in raw source code form, until the time it need be used } finally { return cleanText; } } So far what I have learned is that I can do this in C#, using something like this example: http://www.codeproject.com/dotnet/evaluator.asp?df=100forumid=13971exp=0fr=26select=394822 But we want a ton of performance out of this merge intelligence. We hope whatever was compiled (bytecode), is kepted in a hash tree so that recompilation is not a tax levied on each invocation. There will be many such functions, and we need to invoke it by reference/delegate (storing them in a lookup table). If we are really really greedy, we would make further requests like it be possible to update a function. To recompile an updated source code to one such instance and call the new updated bytecode. I have no experience with IronPython in terms of embedding it, and making use of it in such a scenario, and wish to consult the list for any suggestions or feasibility comments you may have. Thank you for your time and big kudos ahead of time for any participation on this. Best regards, -- Li-fan chen Be one of the first to try Windows Live Mail. ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Pyc IronPython Sample
Just out of curiosity. Is the dll/exe consumable by other .NET apps? I had read in the sdk that the compiled code created would not be usable by other .NET apps I thought. Does this have the same limitations? Thanks Josh From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave Fugate Sent: Monday, September 18, 2006 5:15 PM To: Discussion of IronPython Subject: [IronPython] Pyc IronPython Sample Were happy to announce the release of another sample, Pyc, which shows how to generate .NET executables from IronPython scripts. This includes the pyc.py helper script which accepts a few command line parameters and generates the executables for you. The sample can be downloaded from http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=IronPythonReleaseId=423 (IronPython-1.0-Samples-Pyc.zip) and details on whats provided can be found at http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPythontitle=Samples . Please note that due to a problem in Codeplex it was not possible to update IronPython-1.0-Samples-All.zip to include Pyc. Have fun! The IronPython Team ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] yield in nested try blocks
2006/9/19, Sanghyeon Seo [EMAIL PROTECTED]: Differences doc says IronPython does not allow yield statements in nested try blocks. I have never experienced this before, but I do now. PyFileServer http://pyfilesync.berlios.de/pyfileserver.html 0.2.1 won't run because of this. Just to let you know. Filed as CodePlex #3410. -- Seo Sanghyeon ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] Not bugs
CodePlex #3216, #3301, #3361 are not bugs, but they point to possible improvements to the documentation. http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPythonWorkItemId=3216 http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPythonWorkItemId=3301 http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPythonWorkItemId=3361 #3216: Problem calling APIs with object Array Parameters IronPython Tutorial should say something about how to create and manipulate .NET arrays. Especially, it should mention Array.CreateInstance and Array[Object] syntax, that Array can be treated as a generic type in the section discussing generics. This is not obvious at all. #3301: Modules/time year calculation bug Python's time functions don't need to return UNIX timestamps as long as they are consistent. However, many CPython users would expect this, so this could be documented in the differences doc, as well as the rationale. #3361: IronPython does not run PYTHONSTARTUP The tutorial could have a section devoted to various console options and environment variables. I *thought* ipy.exe -h is pretty obvious, but it seems not. It could mention -X:ExceptionDetail for example, which can help debugging a lot. -- Seo Sanghyeon ___ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com