Python script, incoming parameter * To use single quote ' * '

Source: Internet
Author: User

* # as an incoming parameter to a Python script, you must use single quotation marks ' to pass in correctly. such as Python test.py ' * ' age

Python test.py * age is wrong.



Like what

The test.py script is as follows

Import Sys
Hdfs_report_historical_year = sys.argv[1]
# eg:2014-05,2014-12,etc.
Hdfs_report_historical_month = sys.argv[2]
# eg:all,region,citylevel,etc.
Pig_script_type = sys.argv[3]

Print Hdfs_report_historical_year
Print Hdfs_report_historical_month
Print Pig_script_type


It prints three incoming parameters. Invoke command

Python test.py * Age

Output:

[[email protected] new_pig]$ python test.py * age
2014
Age.pig
Appcategory.pig

You can see that the parameter * did not pass in correctly, but instead passed the file name in the current directory to sys.argv[2] and sys.argv[3]. To use the ' * ': Python test.py ' * ' age if you want to pass in correctly

We can see * No single quotes will pass through many parameters, test.py add parameters to print as follows

Import Sys
Hdfs_report_historical_year = sys.argv[1]
# eg:2014-05,2014-12,etc.
Hdfs_report_historical_month = sys.argv[2]
# eg:all,region,citylevel,etc.
Pig_script_type = sys.argv[3]


Print Hdfs_report_historical_year
Print Hdfs_report_historical_month
Print Sys.argv[4]
Print Sys.argv[5]
Print Sys.argv[6]
Print Sys.argv[7]
Print Sys.argv[8]

Run

[[email protected] new_pig]$ python test.py * age
2014
Age.pig
Appcategory.pig.backup
backup.py
Citylevel.pig
config.py
Config.pyc

As you can see, the current directory pathname is basically passed into the script.

So be careful.




Python script, incoming parameter * To use single quote ' * '

Related Article

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.