[JAVA/PYTHON] Command Line Argument | String[] args | sys.argv

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[JAVA/PYTHON] Command Line Argument | String[] args | sys.argv相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/span' title='span'>span   ble   ++   ack   cond   system   amp   com   pre   

 

JAVA

public class Args
{
    public static void main(String[] args)
    {
        // for (String arg : args)
        //     System.out.println(arg);
        //鎴栬€呬笅闈㈢殑閬嶅巻鏂规硶
        for (int i = 0; i < args.length; i++)
            System.out.println(args[i]);
    }
}

 

terminal杈撳叆:

javac Args.java && java Args jerry elaine george kramer

 

杈撳嚭缁撴灉:

jerry
elaine
george
kramer

 

 

 

 

PYTHON

sys.argv

Argument varible

import sys

# unpacking
scriptName, first, second, third, fourth = sys.argv
print("type(sys.argv) = " + str(type(sys.argv))) #鍙互鐪嬪嚭sys.argv鐨勭被鍨嬪氨鏄釜list print("scriptName = " + scriptName) print(first) print(second) print(third) print(fourth) print()
#閬嶅巻鍒楄〃 for item in sys.argv: print(item)

 

terminal 涓緭鍏?

python3 Sys.py jerry elaine george kramer

 

杈撳嚭缁撴灉

type(sys.argv) = <class 鈥?/span>list鈥?/span>>
scriptName = Sys.py
jerry
elaine
george
kramer

Sys.py
jerry
elaine
george
kramer

 

以上是关于[JAVA/PYTHON] Command Line Argument | String[] args | sys.argv的主要内容,如果未能解决你的问题,请参考以下文章

解决AttributeError:模块'pandas'没有使用command-prompt或pycharm属性'core'

LinuxLinux服务器(centos7)环境搭建java/python3/nginx

Linux Performance tool

adb指令介绍

Linux performance monitor tool

命令行脚本 PHP 不运行