Skip to content

Commit 5a3e599

Browse files
author
ds19991999
committed
commit note
0 parents  commit 5a3e599

File tree

190 files changed

+186831
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+186831
-0
lines changed

Linux命令行.pdf

2.77 MB
Binary file not shown.
Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# sys模块"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {
13+
"toc": true
14+
},
15+
"source": [
16+
"<h1>Contents<span class=\"tocSkip\"></span></h1>\n",
17+
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#命令行参数\" data-toc-modified-id=\"命令行参数-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>命令行参数</a></span></li><li><span><a href=\"#异常消息\" data-toc-modified-id=\"异常消息-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>异常消息</a></span></li><li><span><a href=\"#标准输入输出流\" data-toc-modified-id=\"标准输入输出流-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>标准输入输出流</a></span></li><li><span><a href=\"#退出Python\" data-toc-modified-id=\"退出Python-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>退出Python</a></span></li><li><span><a href=\"#Python-Path\" data-toc-modified-id=\"Python-Path-5\"><span class=\"toc-item-num\">5&nbsp;&nbsp;</span>Python Path</a></span></li><li><span><a href=\"#操作系统信息\" data-toc-modified-id=\"操作系统信息-6\"><span class=\"toc-item-num\">6&nbsp;&nbsp;</span>操作系统信息</a></span></li><li><span><a href=\"#Python版本信息\" data-toc-modified-id=\"Python版本信息-7\"><span class=\"toc-item-num\">7&nbsp;&nbsp;</span>Python版本信息</a></span></li></ul></div>"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 5,
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"import sys"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"## 命令行参数"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 8,
39+
"metadata": {},
40+
"outputs": [
41+
{
42+
"name": "stdout",
43+
"output_type": "stream",
44+
"text": [
45+
"Writing print_args.py\n"
46+
]
47+
}
48+
],
49+
"source": [
50+
"%%writefile print_args.py\n",
51+
"import sys\n",
52+
"print sys.argv"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 10,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"name": "stdout",
62+
"output_type": "stream",
63+
"text": [
64+
"['print_args.py', '1', 'foo']\n"
65+
]
66+
}
67+
],
68+
"source": [
69+
"%run print_args.py 1 foo"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"第一个参数 `(sys.args[0])` 表示的始终是执行的文件名,然后依次显示传入的参数。"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 11,
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"import os\n",
86+
"os.remove('print_args.py')"
87+
]
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"## 异常消息"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"metadata": {},
99+
"source": [
100+
"`sys.exc_info()` 可以显示 `Exception` 的信息,返回一个 `(type, value, traceback)` 组成的三元组,可以与 `try/catch` 块一起使用:"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 12,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"(<type 'exceptions.ZeroDivisionError'>, ZeroDivisionError('integer division or modulo by zero',), <traceback object at 0x04A4DCB0>)\n"
113+
]
114+
}
115+
],
116+
"source": [
117+
"try:\n",
118+
" x = 1/0\n",
119+
"except Exception:\n",
120+
" # sys.exc_clear() 用于清除所有的异常消息。\n",
121+
" print sys.exc_info()"
122+
]
123+
},
124+
{
125+
"cell_type": "markdown",
126+
"metadata": {},
127+
"source": [
128+
"## 标准输入输出流"
129+
]
130+
},
131+
{
132+
"cell_type": "markdown",
133+
"metadata": {},
134+
"source": [
135+
"* `sys.stdin`\n",
136+
"* `sys.stdout`\n",
137+
"* `sys.stderr`"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"metadata": {},
143+
"source": [
144+
"## 退出Python"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"metadata": {},
150+
"source": [
151+
"`sys.exit(arg=0)` 用于退出 `Python`。0 或者 `None` 表示正常退出,其他值表示异常。"
152+
]
153+
},
154+
{
155+
"cell_type": "markdown",
156+
"metadata": {},
157+
"source": [
158+
"## Python Path"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": 16,
164+
"metadata": {},
165+
"outputs": [
166+
{
167+
"data": {
168+
"text/plain": [
169+
"['',\n",
170+
" 'C:\\\\WINDOWS\\\\SYSTEM32\\\\python27.zip',\n",
171+
" 'd:\\\\python\\\\DLLs',\n",
172+
" 'd:\\\\python\\\\lib',\n",
173+
" 'd:\\\\python\\\\lib\\\\plat-win',\n",
174+
" 'd:\\\\python\\\\lib\\\\lib-tk',\n",
175+
" 'd:\\\\python',\n",
176+
" 'd:\\\\python\\\\lib\\\\site-packages',\n",
177+
" 'd:\\\\python\\\\lib\\\\site-packages\\\\IPython\\\\extensions',\n",
178+
" 'C:\\\\Users\\\\Alien\\\\.ipython']"
179+
]
180+
},
181+
"execution_count": 16,
182+
"metadata": {},
183+
"output_type": "execute_result"
184+
}
185+
],
186+
"source": [
187+
"# sys.path表示 Python 搜索模块的路径和查找顺序:\n",
188+
"sys.path"
189+
]
190+
},
191+
{
192+
"cell_type": "markdown",
193+
"metadata": {},
194+
"source": [
195+
"## 操作系统信息"
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": 17,
201+
"metadata": {},
202+
"outputs": [
203+
{
204+
"data": {
205+
"text/plain": [
206+
"'win32'"
207+
]
208+
},
209+
"execution_count": 17,
210+
"metadata": {},
211+
"output_type": "execute_result"
212+
}
213+
],
214+
"source": [
215+
"# 显示当前操作系统信息\n",
216+
"sys.platform"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": 18,
222+
"metadata": {},
223+
"outputs": [
224+
{
225+
"data": {
226+
"text/plain": [
227+
"sys.getwindowsversion(major=6, minor=2, build=9200, platform=2, service_pack='')"
228+
]
229+
},
230+
"execution_count": 18,
231+
"metadata": {},
232+
"output_type": "execute_result"
233+
}
234+
],
235+
"source": [
236+
"# 返回win操作系统版本\n",
237+
"sys.getwindowsversion()"
238+
]
239+
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {},
243+
"source": [
244+
"## Python版本信息"
245+
]
246+
},
247+
{
248+
"cell_type": "code",
249+
"execution_count": 19,
250+
"metadata": {},
251+
"outputs": [
252+
{
253+
"data": {
254+
"text/plain": [
255+
"sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0)"
256+
]
257+
},
258+
"execution_count": 19,
259+
"metadata": {},
260+
"output_type": "execute_result"
261+
}
262+
],
263+
"source": [
264+
"sys.version_info"
265+
]
266+
},
267+
{
268+
"cell_type": "code",
269+
"execution_count": 20,
270+
"metadata": {},
271+
"outputs": [
272+
{
273+
"data": {
274+
"text/plain": [
275+
"'2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)]'"
276+
]
277+
},
278+
"execution_count": 20,
279+
"metadata": {},
280+
"output_type": "execute_result"
281+
}
282+
],
283+
"source": [
284+
"sys.version"
285+
]
286+
},
287+
{
288+
"cell_type": "code",
289+
"execution_count": null,
290+
"metadata": {},
291+
"outputs": [],
292+
"source": []
293+
}
294+
],
295+
"metadata": {
296+
"kernelspec": {
297+
"display_name": "Python 2",
298+
"language": "python",
299+
"name": "python2"
300+
},
301+
"language_info": {
302+
"codemirror_mode": {
303+
"name": "ipython",
304+
"version": 2
305+
},
306+
"file_extension": ".py",
307+
"mimetype": "text/x-python",
308+
"name": "python",
309+
"nbconvert_exporter": "python",
310+
"pygments_lexer": "ipython2",
311+
"version": "2.7.13"
312+
},
313+
"latex_envs": {
314+
"LaTeX_envs_menu_present": true,
315+
"autoclose": false,
316+
"autocomplete": true,
317+
"bibliofile": "biblio.bib",
318+
"cite_by": "apalike",
319+
"current_citInitial": 1,
320+
"eqLabelWithNumbers": true,
321+
"eqNumInitial": 1,
322+
"hotkeys": {
323+
"equation": "Ctrl-E",
324+
"itemize": "Ctrl-I"
325+
},
326+
"labels_anchors": false,
327+
"latex_user_defs": false,
328+
"report_style_numbering": false,
329+
"user_envs_cfg": false
330+
},
331+
"toc": {
332+
"base_numbering": "1",
333+
"nav_menu": {},
334+
"number_sections": true,
335+
"sideBar": true,
336+
"skip_h1_title": true,
337+
"title_cell": "Contents",
338+
"title_sidebar": "Contents",
339+
"toc_cell": true,
340+
"toc_position": {
341+
"height": "calc(100% - 180px)",
342+
"left": "10px",
343+
"top": "150px",
344+
"width": "156px"
345+
},
346+
"toc_section_display": true,
347+
"toc_window_display": true
348+
}
349+
},
350+
"nbformat": 4,
351+
"nbformat_minor": 2
352+
}

0 commit comments

Comments
 (0)