This is a read-only mirror of pymolwiki.org
Difference between revisions of "PythonTerminal"
Jump to navigation
Jump to search
(redundant script, functionality already in PyMOL) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | PyMOL allows the execution of python commands from the PyMOL command line. It is very useful for both debugging, and for discovering new functions. | |
− | + | ||
+ | * Any expression that is not recognized as a PyMOL command is passed to the underlying python interpreter | ||
+ | * To force a one-line expression to be executed as python, begin the line with a slash (/) | ||
+ | * Use the [[python]] command to input multi-line python code | ||
+ | |||
+ | == Examples == | ||
− | |||
<source lang="python"> | <source lang="python"> | ||
− | + | # there is no "print" command in PyMOL, so this will go to the python interpreter | |
− | + | print "Hello World (1)" | |
+ | # same, but force it to be python | ||
+ | /print "Hello World (2)" | ||
− | + | # no lets trick this system by introducing a PyMOL command named "print" | |
− | + | cmd.extend('print', lambda msg: sys.stdout.write("You gave me `%s`\n" % (msg))) | |
− | + | # see what happens | |
− | + | print "Hello World (3)" | |
− | + | # this will still go to the python interpreter | |
+ | /print "Hello World (4)" | ||
</source> | </source> | ||
− | [[Category: | + | |
+ | [[Category:System_Scripts]] |
Revision as of 15:52, 18 August 2011
PyMOL allows the execution of python commands from the PyMOL command line. It is very useful for both debugging, and for discovering new functions.
- Any expression that is not recognized as a PyMOL command is passed to the underlying python interpreter
- To force a one-line expression to be executed as python, begin the line with a slash (/)
- Use the python command to input multi-line python code
Examples
# there is no "print" command in PyMOL, so this will go to the python interpreter
print "Hello World (1)"
# same, but force it to be python
/print "Hello World (2)"
# no lets trick this system by introducing a PyMOL command named "print"
cmd.extend('print', lambda msg: sys.stdout.write("You gave me `%s`\n" % (msg)))
# see what happens
print "Hello World (3)"
# this will still go to the python interpreter
/print "Hello World (4)"