python - pyhton如何接受shell脚本传入的参数
天蓬老师
天蓬老师 2017-04-17 16:04:49
0
3
436

我在服务器上的得到一些数据,然后用shell截取并整理,每3个分成一组。然后是我想把这若干组数据每组当作一组参数传入一个python的函数,应该怎样做?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
巴扎黑

You can use the argparse module:

# coding: utf-8

import argparse


def bar(*args, **kwargs):
    print 'command parameter:', args, kwargs


if __name__ == '__main__':

    parser = argparse.ArgumentParser()  
    parser.add_argument("port", help="listen to the server port.", type=int)
    args = parser.parse_args()

    parser = argparse.ArgumentParser()  

    bar(args.port)
Peter_Zhu

If you use bash to process data, you can also use python to receive and process it. This way you don’t have to pass the data to python through bash, and python is also very simple.

左手右手慢动作

I feel like you said this amount is huge? Consider pipe or save it as a file and read it with Python

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template