如今,让我们看看怎么定义一个可以接收随便率性参数的函数。我们应用元组来实现。
调试
下面的例子应用inspect模块。该模块用于调试目标时是异常有效的,它的功能远比这琅绫氰述的要多。
这篇文┞仿不会覆盖这个模块的每个细节,但会展示给你一些用例。
- import logging, inspect
- logging.basicConfig(level=logging.INFO,
- format='%(asctime)s %(levelname)-8s %(filename)s:%(lineno)-4d: %(message)s',
- datefmt='%m-%d %H:%M',
- )
- logging.debug('A debug message')
- logging.info('Some information')
- logging.warning('A shot across the bow')
- def test():
- frame,filename,line_number,function_name,lines,index=\
- inspect.getouterframes(inspect.currentframe())[1]
- print(frame,filename,line_number,function_name,lines,index)
- test()
- # Should print the following (with current date/time of course)
- #10-19 19:57 INFO test.py:9 : Some information
- #10-19 19:57 WARNING test.py:10 : A shot across the bow
- #(, 'C:/xxx/pyfunc/magic.py', 16, '', ['test()\n'], 0)
生成独一ID
在有些情况下你须要生成一个独一的字符串。我看到很多人应用md5()函数来达到此目标,但它确切不是以此为目标。
其实有一个名为uuid()的Python函数是用于这个目标的。

网友点评
精彩导读
科技快报
品牌展示