At the beginning of a python script, there are some import
statements. Could someone explain what they imply?
import getopt
import os
import re
import string
import sys
import getpass
import urllib
import subprocess
The import
statements are similar (but different) to the #include
statements in C: they allow you to use functions defined elsewhere (either in a standard module, or your own).
For example, module sys
allows you to do this:
import sys
# ... somewhere down in the file
sys.exit(0)
Which would terminate your program. Note that you did not have to write any code for the exit()
function, but it is defined within the standard sys
module that ships with the interpreter.
Any Python tutorial should explain this. For example, this.
It's importing modules (like libraries). When imported in this manner you'll find in the code calls to functions of this kind < module_name >.< function >
To know what each module do and offers, look at the documentation; a quick googling "python " should land you in the right place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With