Receive runtime arguments in Python 2.7

Receive runtime arguments in Python 2.7

I used it when changing the process with the argument passed when executing the script

Operating environment

OS: Windows7 Language: Python 2.7.10

manner

ʻImport sys to get the arguments stored in the array of sys.argv`

Sample code

test.py


#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

if __name__ == "__main__":
    count = 0
    for roop in sys.argv:
        print str(count) + 'Second argument: ' + str(roop)
        count += 1

Execution example

python test.py aiu e o 1 23

Execution result

0th argument: test.py
1st argument: aiu
Second argument: e
Third argument: o
4th argument: 1
5th argument: 23

Qiita用_引数.png

Recommended Posts

Receive runtime arguments in Python 2.7
How to receive command line arguments in Python
Included notation in Python function arguments
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Decompose command arguments in one line in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Python> datetime> runtime arguments> start processing immediately
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Automatically register function arguments to argparse in Python
Receive websocket of kabu station ® API in Python
Receive and display HTML form data in Python
Python> Run with run-time arguments> Use import argparse
POST JSON in Python and receive it in PHP
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
Read DXF in python