<< Main Manual

Tutorial #0.6. Files

TIP #1: The following examples are a crash course in Python programming showing the features that are most beneficial with the minimal amount of extraneous information. You can type the example code directly within PhysImage's 'Jython Console' or load the example files (*.py links below) directly from PhysImage as a demonstration, or test the code out with an independent installation of Python 2.7 on your preferred OS platform. These examples are independent of any specific PhysImage features and meant to be a succinct demonstration of very useful general Pythonic features.

TIP #2: The ">>> ", in the below example, is meant to represent PhysImage's 'Jython Console' prompt, while '#' in a line represents a comment (used to annotate Python code) and does not do anything. Therefore,
the text following the '#' is only for your benefit to understand the next bits of code and is not required to be typed in.

For a more expansive tutorial of the general Python programming language, see the Official Python Tutorial.

Example

The following code can be loaded within PhysImage from this file or typed in manually.

>>> # Reading/Writing text files
>>>
>>> # writing out a text file
>>> outputFile = open('output.txt', 'w')
>>> numberRange = range(100)
>>> for number in numberRange:
...    outputFile.write(str(number) + "\t" + str(number*2) + "\n")
...
>>> outputFile.close()
>>>
>>> # reading in the text file we just wrote
>>> inputFile = open('output.txt', 'r')
>>> for line in inputFile:
...    tokens = line.split()
...    print tokens[1] + " " + str(len(tokens))
...
>>> inputFile.close()
>>>
>>> # a slightly more verbose way to read the same file
>>> inputFile = open('output.txt', 'r')
>>> line = inputFile.readline()
>>> while len(line) > 0:
...    tokens = line.split()
...    print tokens[1] + " " + str(len(tokens))
...    line = inputFile.readline()
...
>>> inputFile.close()
>>>


After the data is in the WaveManager it got manipulated or plotted as a chart in the previously demonstrated ways.

<< Tutorial #0.5. Functions
>> Tutorial #0.7. Filesystem

<< Main Manual