Computational biology PhD researcher. Interested in science, software development, and machine learning. I write about medical research at BioSky.co and contribute content to a variety of additional publications.CVAbout
The main use I’ve found for the Python sys module is allowing command-line arguments to be made to a script. Here is an example of how it looks:
import sys if len(sys.argv) == 2: input_file = sys.argv else: print "Please input a command-line argument specifying the file"
This script checks that 2 command-line arguments had been passed to the program before assigning the value sys.argv to a variable. We check for two command-line arguments because the first one (sys.argv) is the name of the Python script currently being executed.
Latest posts by Jack Simpson (see all)
- Fruit flies, honeybees, and alcohol - October 18, 2017
- I’m going to Silicon Valley! - October 15, 2017
- Sometimes working in the biology department is pretty neat - October 10, 2017