Python function Learning sys.argv[1]

Source: Internet
Author: User

One, sys module

SYS is a "standard library" of Python, which is the official "module", a shorthand for "system" that encapsulates information and interfaces for some systems.

Official documentation Reference: https://docs.python.org/2/library/sys.html

Document reference in the Chinese version: http://xukaizijian.blog.163.com/blog/static/170433119201111625428624/


Second, SYS.ARGV parameters

Sys.argv[] is used to get command line arguments, Sys.argv[0] represents the code itself file path, so the parameters starting from 1, the following two examples illustrate:

1. A simple example of using sys.argv[]:
The following is the sample1.py file:

   import Sys,os     print (SYS.ARGV) #打印输出命令行执行参数列表.
Os.system (sys.argv[1]) #打印输出 "system command Execution Results"

This example Os.system receive command line arguments, run parameter directives, cmd command line with parameters run Python sample1.py notepad, will open Notepad program

2. Operation result

  

Python function Learning sys.argv[1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.