S
Scott Simpson
Suppose I have the following python program:
def func():
from sys import stderr, exit
try:
f = open("foo", 'r')
except IOError:
print >> stderr, "Input file foo does not exist"
exit(1)
def main():
import sys
if len(args) != 0:
sys.exit(1)
func()
if __name__ == '__main__':
main()
Notice that I have two "import sys" statements, one for each function.
Is there any way to import the "sys" stuff to the global symbol table so
I don't need two "import" statements?
Lastly, is there an equivalent of Perl's "die" function? I'm writing to
stderr and dieing above but I'm not quite sure if this is the "correct" way.
def func():
from sys import stderr, exit
try:
f = open("foo", 'r')
except IOError:
print >> stderr, "Input file foo does not exist"
exit(1)
def main():
import sys
if len(args) != 0:
sys.exit(1)
func()
if __name__ == '__main__':
main()
Notice that I have two "import sys" statements, one for each function.
Is there any way to import the "sys" stuff to the global symbol table so
I don't need two "import" statements?
Lastly, is there an equivalent of Perl's "die" function? I'm writing to
stderr and dieing above but I'm not quite sure if this is the "correct" way.