Sometimes we're doing python When the program is running, it needs to receive external parameters

python Of sys.argv[] Can achieve

# test.py
import sys # Introduce modules 
str = sys.argv[1]
print str

When the above code is executed , If the execution command is :

python test.py hello

be str The value is hello

python More related articles on getting incoming parameters from outside

  1. python perform shell Get hardware parameters, write mysql

    Recently, I want to get various parameters of the server , Include cpu. Memory . disk . Model and other information . Tried Hyperic HQ.Nagios and Snmp, They are very powerful , But it doesn't match the demand , Or too heavy. So I thought of using python ...

  2. python Script program , Pass in the parameter * To use single quotes '*'

    * As python When passing in arguments to the script , You have to use single quotes '', Then it can be introduced correctly . Such as python test.py 2014 '*' age python test.py 2014 * age It's wrong. . such as te ...

  3. For applications, it is necessary to record the time-consuming scenarios of a certain method , You have to use clock_gettime Pass in CLOCK_MONOTONIC Parameters , This parameter obtains the nanosecond precision clock which increases monotonically since the system starts up , comparison gettimeofday The accuracy has been improved a lot , And not suffer NTP And other external services , Can be more accurate to count the time-consuming (java The corresponding in is System.nanoTime), That is to say, all use gettimeofday To count the time (java Medium is System.curre

    For applications, it is necessary to record the time-consuming scenarios of a certain method , You have to use clock_gettime Pass in CLOCK_MONOTONIC Parameters , This parameter obtains the nanosecond precision clock which increases monotonically since the system starts up , comparison gettimeofday Improved accuracy ...

  4. python Command line get parameters

    python Command line get parameters import sys # python To obtain parameters input_file = sys.argv[1] output_file = sys.argv[2] print(input ...

  5. spring mvc@RequestParam Get the value of the incoming parameter according to the parameter name

    stay SpringMVC There are two main ways for the background control layer to obtain parameters , One is request.getParameter("name"), The other is to use annotations @RequestParam Direct access to . The main thing here is ...

  6. JS obtain Url Parameters passed in

    One : Get it backstage , Front call backstage : object value= Request.QueryString[key]; The front desk js: $(function(){ var value="<%=va ...

  7. python *args **kwargs, Pass in an unfixed parameter to the function , Or pass in a lot of content to the function , Often used in constructors .

    ''' example 1: Exhibition *args Usage of , Pass in multiple parameters , No pre definition . This example introduces 3 Parameters . There is no pre-defined . Automatically generate tuples within functions () ''' def q1(*args): print(' example 1') print ...

  8. Python MySQLdb In the implementation of SQL Statement should be quoted if the field is str Type of

    Here's the picture : username In the table is string type , So you need to put quotation marks on the parameters you pass in

  9. python Learning notes (3)-- function 、 Parameters 、 Variable 、 recursive

    1. Basic syntax and properties of functions Background summary Now the boss asks you to write a monitoring program , Monitor the system status of the server , When cpu\memory\disk When the usage exceeds the threshold, an email will be sent to the police , Did you take out all the knowledge , Write the following code whi ...

Random recommendation

  1. C++ cast

    excerpted from Type conversions K&R Section 2.7 p59 Yes type conversion The explanation of : The precise meaning of ...

  2. Join me in data mining (21)——redis

    What is? Redis Redis Is an open source use ANSI C Language writing . Support network . Log type that can be memory based or persistent .Key-Value database , And provide multilingual API. from 2010 year 3 month 15 The date of ,Redis The developer of ...

  3. About ORACLE The restart command for

    Sometimes the data is dead , Or no monitoring , No need to restart the machine , Restart the database service , Here is linux The next startup step , Not in the win I have carried out , Maybe, too ! With oracle9i For example (1) With oracle Identity login database , command :s ...

  4. lnmp+phpmyadmin Configuration and problems

    This blog belongs to moka classmate ( Sina weibo :moka classmate ) I sort it out myself , If used , Please add a link to indicate the source . lnmp After the installation is complete , To configure phpmyadmin . Its access mode is http://202.18.400.379/p ...

  5. Learning notes :Twitter The core data library team Hadoop Optimization experience

    One . source Streaming Hadoop Performance Optimization at Scale, Lessons Learned at Twitter (Data platform @ ...

  6. weblogic Published project uses myeclipse Normal start , Click on startWeblogic.cmd Error reporting solutions

    The problems we encountered in the project today . Use weblogic Announced projects , Use myeclipse Normal start , But click startWeblogic.cmd Will report a mistake . I put forward a class not found. What's the problem with Chu . later ...

  7. hdu 4472 Count (2012 ACM-ICPC Chengdu live competition )

    Recurrence , Consider a n Can be i * j + 1 Put it together , That is, the second layer has j One contains i Subtree of elements ... And then it's all right .. #include<algorithm> #include<iostream& ...

  8. The depth resolution continue,break and return

    continue,break and return yes Java Keywords in , It is frequently used in process control of method body . In reality , There are often students in the use of confusion , This makes the process control statements confused . ad locum , I combine it with my personal experience ...

  9. linux install jdk as well as nginx Detailed process

    One . install jdk 1: First download jdk To local , And then through git  Upload to linux Server 2: Entry directory usr, And create a directory java, take jdk Move the compressed file to this directory cd /usr mkdir java mv ...

  10. vim Shortcut key binding

    1. sign out VIM, stay shell Compile below && Run the program :wq [root@fsjohnhuang ~]# gcc main.c -o main [root@fsjohnhuang ~]# ...