I have a program that gets the code of a country with raw_input()
and then send an email based on it.
My code is:
import pandas as pd
import pymysql
import sys
data=pd.read_CVS("filename")
country=raw_input("country name : ")
print("country name is :",sys.argv[1])
for index in data['emailid']:
mail= index.split('@')[1]
if(country == 'US'):
if (mail=='yahoo.com'):
print index
elif(country == 'UK'):
if(mail=='yahoo.com' or mail=='yahoo.co.uk'):
print index
I want to change it to send the country code as command line argument input.
Example:
python programname.py 'UK'
and the related email ids as output.
raw_input
reads from standard input whereas sys.argv
is the list of command line arguments. So if you want to use command line to pass in the country code, just delete the line containing raw_input
and let country
be sys.argv[1]
.
you should try argparse module,
import argparse
parser = argparse.ArgumentParser(description='Example with non-optional arguments')
parser.add_argument('country')
args = parser.parse_args()
country = args.country
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.