Some notes on IronPython, CPython, .Net and integration…
Avoiding importing some CPython modules: you may not want to make your IronPython coded assemblies depend on an installation of CPython at c:\python25. If so you must avoid importing a lot of modules that CPython coding takes for granted…
- types – don’t use expressions like if type(myObj) == types.ListType. Use if type(myObj) == type([]) instead. Sometimes implicit is better than explicit !
- string – if you go back to CPython 1.5.2 you may still be in the habit of coding string.split() or string.join(). Switch over to member methods eg “”.join( ) andyou can avoid importing the string module.
Some modules can be imported just the same in IronPython and CPython…
- re
- exceptions
Genericity
- Use ContainsKey, not has_key. Both Hashtable and Python’s built in dictionary have it.
October 8, 2007 at 3:50 pm
[…] 8th, 2007 I’m collecting IronPython observations here… Posted in coding […]
October 12, 2007 at 12:36 pm
Hmm… given that most of the standard library *works* with IronPython it seems a shame not to use it.
In Resolver we just have our own copy of the standard library in the application folder – that way we are not dependent on Python being installed (and we still get to use the awesome Python standard library).
If your application is just a single script then this is fair enough advice, but if your application has its own directory then you might as well use the standard library.
October 12, 2007 at 8:45 pm
I want to avoid mandating a c:\python25 install for trader desktops. Could I put the std Python libs in a .Net assembly ?
October 31, 2007 at 8:48 pm
For IronPython 1.1 you can compile Python files to assemblies (actually executables – but assemblies nonetheless).
You could possibly combine these as a single assembly? Not something I’ve tried though. 🙂
Distributing source files seems better to me.
October 31, 2007 at 8:50 pm
(As I mentioned – we distribute the standard library *with* our application – which means we are not dependent on any Python install.)