I typically write my scripts with a structure like s
#!/usr/bin/python
import stuff
def do_things():
print "FOO"
def main():
do_things()
if __name__ == "__main__":
main()
The problem I have is I'd like to have a logging function that is defined globally and I"m not really sure how to开发者_StackOverflow do this. I tried a decorator function but if I define it in main I can't call it from other functions in the script. It seems like something that should be easy to do but not something I have experience with.
import logging
Python's logging
library should satisfy your requirements.
精彩评论