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中的代碼')