Home > Backend Development > Python Tutorial > sys.argv是什么?

sys.argv是什么?

WBOY
Release: 2016-06-06 16:24:26
Original
7379 people have browsed it
sys.argv是什么?程序小白报到!在《python简明教程》里看到一个小段,有import sys后面写到“for i in sys.argv”,这个sys.argv是从哪里来的?还有,解释里说sys.argv[0]是“we”,sys.argv[1]是“are”。这都是从哪来的,是自己写的么?放在哪呢?各位老师见笑了...

回复内容:

sys是Python的一个「标准库」,也就是官方出的「模块」,是「System」的简写,封装了一些系统的信息和接口,官方的文档请戳:27.1. sys — System-specific parameters and functions,中文版的可以参考:[python] sys模块

教程里的源码我抄下来:
<code class="language-python"><span class="c">#!/usr/bin/python</span>
<span class="c"># Filename: using_sys.py</span>

<span class="kn">import</span> <span class="nn">sys</span>

<span class="k">print</span> <span class="s">'The command line arguments are:'</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">:</span>
    <span class="k">print</span> <span class="n">i</span>

<span class="k">print</span> <span class="s">'</span><span class="se">\n\n</span><span class="s">The PYTHONPATH is'</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> 
</code>
Copy after login
用IDLE怎么运行带参的*.py文件 python新人来回答一发,下面进入正题:
1.首先打开python_shell,出现如下画面。 sys.argv是什么?
2.点击左上角File,打开所要调用的py文件。
sys.argv是什么?3.然后会生成一个新的对话框,如图。点击run即可在shell中看到结果。
sys.argv是什么?
4.结果:
sys.argv是什么?
嗯,就这样了,够仔细了吧。
以上。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template