1 import time 2 time.time()
1 import time,sys 2 time.time() 3 sys.path
1 from time import time 2 time()
导入指定包下全部模块python
1 from time import * 2 time()
__all__暴露指定属性spa
test.py:code
1 __all__ = ['func1'] 2 3 4 def func1(): 5 print('from func1') 6 7 8 def func2(): 9 print('from func2')
1 from test import * 2 3 func1() 4 func2() # NameError: name 'func2' is not defined 5 6 # 只能访问到导入原文件中__all__中指定的属性
1 try: 2 ret = int(input('number >>>')) # 'a' 3 print(ret * '*') 4 except ValueError: # 输入a时转int失败 throw ValueError 5 print('输入的数据类型有误') 6 except Exception: 7 print('会捕获任何异常') 8 else: 9 print('没有异常的时候执行else中的代码')