{"id":204318,"date":"2020-11-10T08:11:49","date_gmt":"2020-11-10T00:11:49","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=204318"},"modified":"2020-10-29T15:13:24","modified_gmt":"2020-10-29T07:13:24","slug":"python-sys-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-sys-linux.html","title":{"rendered":"\u901a\u8fc7\u4ee3\u7801\u5b9e\u4f8b\u7b80\u5355\u4e86\u89e3Python sys\u6a21\u5757"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u901a\u8fc7\u4ee3\u7801\u5b9e\u4f8b\u4e86\u89e3Python sys\u6a21\u5757,\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b \n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n sys-\u7cfb\u7edf\u7279\u5b9a\u7684\u53c2\u6570\u548c\u529f\u80fd<\/strong><\/span><\/div>\n \u8be5\u6a21\u5757\u63d0\u4f9b\u5bf9\u89e3\u91ca\u5668\u4f7f\u7528\u6216\u7ef4\u62a4\u7684\u4e00\u4e9b\u53d8\u91cf\u7684\u8bbf\u95ee\uff0c\u4ee5\u53ca\u4e0e\u89e3\u91ca\u5668\u5f3a\u70c8\u4ea4\u4e92\u7684\u51fd\u6570\u3002\u5b83\u59cb\u7ec8\u53ef\u7528\u3002<\/p>\n \u4ee3\u7801\u5982\u4e0b<\/p>\n \r\n#!\/usr\/bin\/python\r\n# Filename: cat.py\r\n \r\nimport sys\r\n \r\ndef readfile(filename):\r\n '''Print a file to the standard output.'''\r\n f = file(filename)\r\n while True:\r\n line = f.readline()\r\n if len(line) == 0:\r\n break\r\n print line, # notice comma\r\n f.close()\r\n \r\n# Script starts from here\r\nif len(sys.argv) < 2:\r\n print 'No action specified.'\r\n sys.exit()\r\n \r\nif sys.argv[1].startswith('--'):\r\n option = sys.argv[1][2:]\r\n # fetch sys.argv[1] but without the first two characters\r\n if option == 'version':\r\n print 'Version 1.2'\r\n elif option == 'help':\r\n print '''\\\r\nThis program prints files to the standard output.\r\nAny number of files can be specified.\r\nOptions include:\r\n --version : Prints the version number\r\n --help : Display this help'''\r\n else:\r\n print 'Unknown option.'\r\n sys.exit()\r\nelse:\r\n for filename in sys.argv[1:]:\r\n readfile(filename)<\/pre>\n |