The new version of the Python Cookbook suggests using "isinstance" rather than
direct comparison of types -- hopefully, the gentest() method "is a" generator.
So you'd use
if not isinstance(process, types.GeneratorType):
I have not checked if that would work (in either current CPython or
IronPython), and if it does that's what should be in simpy -- but isinstance
wasn't added until 2.2 (I think) and simpy was probably built before that.
You might want to look at this (long) thread:
http://www.gossamer-threads.com/lists/python/python/365821?nohighlight=1#365821
which (it seems to me) somewhat suggests using
if not hasattr(process, '__iter__'):
in this case.
Good luck...
At 04:27 AM 12/21/2005, Stanislas Pinte wrote
>Hello,
>
>Internally we use a wonderful simulation framework written in python:
>http://simpy.sourceforge.net/
>
>I cannot make it work on python because it rests on generators...
>
>the main loop of simpy uses type(myFunction) == types.GeneratorType) to
>determine if it is a
>generator or not...
>
>> if not (type(process) == types.GeneratorType):
>> raise Simerror("Fatal SimPy error: activating function which"+
>> " is not a generator (contains no 'yield')")
>
>However, in IronPython:
>
>>>> import types
>>>> def gentest():
> for i in range(0,10):
> yield i
>>>> print type(gentest)
>
><type '__main__+gentest0'>
>
>whereas in CPython it returns
>
><type 'generator'>
>
>Any idea if we can fix this easely?
>
>thanks,
>
>Stan.
J. Merrill / Analytical Software Corp
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com