Converting Open GENIE to genie_python
Warning
This guide is obsolete; Open GENIE is no longer in use on any instrument.
If you know a little bit of Python already, converting Open GENIE
scripts to genie_python
is very often straightforward. Even if
you’re new to Python, once you know a few simple pieces of syntax,
you’ll be able to convert many scripts without issue.
Note: If you are new to Python, consult the Introduction to Python on the Mantid web-site.
List of functions
We’ve included some common genie_python
commands on this page, but for a full
list refer to the genie
reference documentation.
Indentation
One thing where there is no direct comparison between Python and Open GENIE is with indentation.
In Python, different code blocks are identified by their indentation
level. In many programming languages, code blocks are encased in curly
braces ({...}
), but Python uses indentation. For example:
print "No indent"
def my_func():
print "1 indent. Inside the function"
if True:
print "2 indents. Inside the if clause"
print "2 indents. Still inside the if clause"
print "1 indent. In the function but not the if clause"
print "No indent. Outside the function"
Typically an indent
is 3 or 4 spaces. Tabs can be used too, but
Python won’t recognise that a tab is the same as 4 spaces so can lead to
problems. It’s often best to avoid them. This might be a new concept if
you’ve only ever written Open GENIE, but trust us in that it opens up a
lot of ways to make scripts more powerful, easier to read and more
reliable.
Side-by-side comparison
Open GENIE syntax |
|
Comments |
---|---|---|
PROCEDURE |
|
This is the standard way to define a function in Python |
|
|
Many functions in |
|
|
To execute a function, give its name and then the argument in brackets. This is a user-defined function, not a |
|
|
As above, except that multiple arguments are separated by a comma |
|
|
Some methods can take named arguments. In these cases you simply give named arguments in the form |
|
|
Some Open GENIE commands take optional arguments. The same principle applies as in the above example. |
|
|
Comments are the same in both languages |