-
Notifications
You must be signed in to change notification settings - Fork 1
Converting Open GENIE to genie_python
Scripting > Converting Open GENIE to genie_python
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.
We've included some common genie_python commands on this page, but for a full list refer to the `genie\_python reference manual`_.
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.