[Tutor] crash when importing random or sys module, in my embedded python

R. Alan Monroe R. Alan Monroe" <amonroe@columbus.rr.com
Thu Jun 19 23:13:01 2003


------------EC5313E3B8CF383
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

> On my machine 2*pi = 6.2831853071795862


C:\>python
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.pi
3.1415926535897931
>>> import random
>>> random.TWOPI
6.2831853071795862
>>> math.pi*2
6.2831853071795862
>>>


> version? Is your embedded version somehow using single
> precision floating points instead of double?

Since the error occurs during "import random", at the very top, I've
not yet defined any variables at all :^)


> You don't have anything else in your version of random.py
> than "from math import ... pi as _pi ... TWOPI = 2.0 * _pi"
> do you?

I didn't see anything...

I'm not too concerned since I have a workaround, but the error is kind
of interesting in its own right :^)

My script is attached.

Here's how I'm embedding it:

Py_Initialize();
themodule = PyImport_ImportModule("vis");
thefunc = PyDict_GetItemString( PyModule_GetDict(themodule), "render");


Alan
------------EC5313E3B8CF383
Content-Type: text/plain; name="vis.py"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="vis.py"

DQojCXVuc2lnbmVkIGxvbmcJTWlsbFNlYzsJCQkvKiBTb25pcXVlIHNldHMgdGhpcyB0byB0aGUg
dGltZSBzdGFtcCBvZiBlbmQgdGhpcyBibG9jayBvZiBkYXRhICovDQojCXVuc2lnbmVkIGNoYXIJ
V2F2ZWZvcm1bMl1bNTEyXTsJLyogU29uaXF1ZSBzZXRzIHRoaXMgdG8gdGhlIFBDTSBkYXRhIGJl
aW5nIG91dHB1dHRlZCBhdCB0aGlzIHRpbWUgKi8NCiMJdW5zaWduZWQgY2hhcglTcGVjdHJ1bVsy
XVsyNTZdOwkvKiBTb25pcXVlIHNldHMgdGhpcyB0byBhIGxvd2ZpZGVseSB2ZXJzaW9uIG9mIHRo
ZSBzcGVjdHJ1bSBkYXRhIA0KIwkJCQkJC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