-
-
October 1, 2021 at 3:45 am
mhorn2
SubscriberHello,
I am developing a python script to automatically generate some named selections. I am using 2021R1 Mechanical Scripting.
I am wondering how to clear all the variables that I have defined from the namespace, or better yet, restart the "Shell".
When I develop python code outside of ANSYS I often restart the iPython console to provide a fresh namespace. This prevents a script from successfully running, when there are indeed errors. The error I am concerned about is when a script accesses a variable before its definition. If I am developing a code in a shell that has stale variables from a previous run, then they could be accessed without issue by my script that has this error. When I run the script in a new Mechanical session it will error out.
PS - scripting is an AWESOME feature. The 2021R1 updates are making a world of difference for me. Good stuff.
Any help is appreciated. Thanks!
Mike
October 5, 2021 at 10:23 pmmhorn2
SubscriberThis would also be very useful when importing local modules. I have defined some python functions in a module that I import. If I make any changes to these modules I cannot re-import then to the shell if they have already been imported. In order to re-import the new version of the module the shell needs to be restarted (I think). Thanks!
Update: I found the reload module command in Python 2 which re-loads locally imported modules.
Viewing 1 reply thread- The topic ‘Clearing the Python shell namespace in Mechanical Scripting’ is closed to new replies.
Innovation SpaceTrending discussionsTop Contributors-
5694
-
1891
-
1419
-
1305
-
1021
Top Rated Tags© 2026 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-
Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.