python为我们提供了强大的开源自学,可以登录python官网那里有很多资料可供研究

官方的idie编辑器就是我今天要说的其中之一:

1 >>> dir(__builtins__)
2 ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property
bif查看代码
然后点击help(列表中的bif)
 1 #/usr/bin/env pathon3
 2 #-*- coding: utf-8 -*-
 3 # @Author: UrAir
 4 # @Date: 2018-01-16 00:50:50
 5 import os, sys, time
 6 
 7 # 关机代码调用系统 shutdown 命令 并添加了 -f 参数
 8 # 所以请确保关键程序都已关闭 以防数据丢失
 9 def shutdown(seconds):
10     length = len(str(seconds))
11     while seconds:
12         print('关机时间剩余 {0:<{1}} 秒(中断退出: CTRL + C)'.format(seconds,length), end='\r')
13         time.sleep(1)
14         seconds -= 1
15     print('关闭计算机中........拜拜!',' '*10)
16     # 真实使用时请把下面语句的注释符号删除
17     # os.system('shutdown -s -f -t 0')
18 
19 # 判断字符串是否是小数
20 def isfloat(string):
21     try:
22         float(string)
23         return True
24     except Exception:
25         return False
26 
27 # 对用户输入预处理
28 def input_time():
29     while True:
30         T = input('多少小时后关闭电脑?(单位:小时)[退出请直接"回车"]>>> ')
31         if not T:
32             sys.exit()
33         elif T.isdigit():
34             return int(T) * 3600
35         elif isfloat(T):
36             return int(float(T) * 3600)
37         else:
38             print('不是数字,请重新输入!', end='\n\n')
39 
40 # 运行中 捕捉 中断信号 退出程序
41 def main():
42     sec = input_time()
43     try:
44         shutdown(sec)
45     except KeyboardInterrupt:
46         pass
47 
48 
49 if __name__ == '__main__':
50     main()
网上摘录的关机小程序仅仅学习参考

 

posted on 2018-01-25 21:59  仓鼠大人爱吃肉  阅读(226)  评论(0编辑  收藏  举报