I try to import Vpython and I get a "ZeroDivisionError" - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I try to import Vpython and I get a "ZeroDivisionError" (/thread-40405.html) Pages:
1
2
|
RE: I try to import Vpython and I get a "ZeroDivisionError" - Jon2222 - Jul-25-2023 (Jul-24-2023, 02:10 PM)deanhystad Wrote: @snippsat is correct. You do not get the error when importing the library. It only has an effect when the program exits, which happens immediately if your program consists solely of "import vpython". Try this: I tried it and it doesn't work. The error is ZeroDivisionError as before. This is screenshot of the error.[attachment=2470] RE: I try to import Vpython and I get a "ZeroDivisionError" - Gribouillis - Jul-25-2023 You could also try this import atexit import vpython atexit.unregister(vpython.Exit) RE: I try to import Vpython and I get a "ZeroDivisionError" - deanhystad - Jul-25-2023 (Jul-25-2023, 08:28 AM)Gribouillis Wrote: You could also try thisExit is not exposed through the module interface. I did find this neat trick to get a list of registered atexit functions. https://stackoverflow.com/questions/16042463/how-can-i-get-the-list-of-registered-atexit-functions-in-python3 So you could write this: import vpython import atexit def unregister_by_name(name): funs = [] class Capture: def __eq__(self, other): funs.append(other) return False c = Capture() atexit.unregister(c) for func in funs: if func.__name__ == name: atexit.unregister(func) unregister_by_name("Exit")It is easier to edit the vpython.py file. I wish I could fine something about the intention behind Exit(). RE: I try to import Vpython and I get a "ZeroDivisionError" - Jon2222 - Jul-25-2023 (Jul-25-2023, 08:28 AM)Gribouillis Wrote: You could also try this I doesn't work. [attachment=2471]
RE: I try to import Vpython and I get a "ZeroDivisionError" - Jon2222 - Jul-25-2023 (Jul-25-2023, 11:04 AM)deanhystad Wrote:(Jul-25-2023, 08:28 AM)Gribouillis Wrote: You could also try thisExit is not exposed through the module interface. Your code runs successfully on my computer. But I would like to know if is there something wrong with my computer. I think developers of vpython must never upload a library that doesn't work. RE: I try to import Vpython and I get a "ZeroDivisionError" - deanhystad - Jul-25-2023 The library works. It just has an ugly exit behavior. You'll be able to use it just fine, making all kinds of pretty pictures and animations, and all weill be well until your program quits. That is when Exit gets called. When used in a notebook you wouldn't see this until you closed the notebook. It a web page you wouldn't see it at all. RE: I try to import Vpython and I get a "ZeroDivisionError" - Jon2222 - Jul-26-2023 (Jul-25-2023, 12:42 PM)deanhystad Wrote: The library works. It just has an ugly exit behavior. You'll be able to use it just fine, making all kinds of pretty pictures and animations, and all weill be well until your program quits. That is when Exit gets called. When used in a notebook you wouldn't see this until you closed the notebook. It a web page you wouldn't see it at all. Sure, thank you!!! |