This is a read-only mirror of pymolwiki.org
Difference between revisions of "Python"
m (3 revisions) |
m (python3) |
||
Line 23: | Line 23: | ||
python | python | ||
x = 10 | x = 10 | ||
− | print x | + | print(x) |
python end | python end | ||
</source> | </source> | ||
Line 29: | Line 29: | ||
<source lang="python"> | <source lang="python"> | ||
python | python | ||
− | print x | + | print(x) |
python end | python end | ||
</source> | </source> | ||
Line 39: | Line 39: | ||
Python scripts and commands used within PyMOL can only be written using the current version of Python that is supported by your version of PyMOL. To determine which version of Python you can use, type the following command into PyMOL: | Python scripts and commands used within PyMOL can only be written using the current version of Python that is supported by your version of PyMOL. To determine which version of Python you can use, type the following command into PyMOL: | ||
<source lang="python"> | <source lang="python"> | ||
− | print sys.version | + | print(sys.version) |
</source> | </source> | ||
Revision as of 06:28, 12 February 2020
Issuing the Python command will put you into a stateful pseudo-interactive Python session. Or, more simply it's stateful in that you can invoke the Python session write some code, end the session, then restart the session and your data will be saved (see Example 1). It's pseudo-interactive in that you don't get feedback until you type "python end," upon which your code is run the output appears.
This is a helpful command for testing different scripting or state-editing strategies for movie making.
USAGE
# start the session
python
# ...
# your Python code goes here
# ...
# end the session
python end
EXAMPLES
- Start the session. Set x to 10. End the session. Restart the session and see if the value of x is recalled.
python
x = 10
print(x)
python end
python
print(x)
python end
Output:
10
Python Version
Python scripts and commands used within PyMOL can only be written using the current version of Python that is supported by your version of PyMOL. To determine which version of Python you can use, type the following command into PyMOL:
print(sys.version)
Note that this version of Python is not necessarily related to the version that you may have installed on your system.
This command can also be used to ensure that code you are distributing can be supported by the user's system.