Using ipython is great for learning because of the instant feedback, but at some point you will want to save your code to use for another day. To do so, we use our text editor to write code in a file that ends with the extension '.py'.
Open a text editor
type: print("I can program in Python!\n")
Save the file as expert.py
1) in Unix, type python expert.py
python expert.py
I can program in Python!
2) in ipython type run expert.py
In [1]: run expert.py
I can program in Python!
3) include the following in the first line of your script and type ./expert.py in unix
#!/usr/bin/env python
4) in Canopy
Open expert.py
run expert.py
Example 2
In text editor, let's type our palindrome code from example1 of "Control flow and loops" section.
Name the file palindrome.py. The script should look like the following:
manyseqs=['ACTGATG','ACTGGTCA','ATGATG','TCGAAGCT','GCAGGCG','GATCCTAG','CATGTCGT','CTCTATCTC']
for seq in manyseqs:
if (seq==seq[::-1]):
print("%s" %seq)
1) in Unix: python palindrome.py
python palindrome.py
ACTGGTCA
TCGAAGCT
GATCCTAG
CTCTATCTC
2) in ipython:run palindrome.py
In [1]: run palindrome.py
ACTGGTCA
TCGAAGCT
GATCCTAG
CTCTATCTC
3) include the following in the first line of your script and type palindrome.py in unix
#!/usr/bin/env python