如何使用命令行参数从另一个脚本打开一个脚本?

时间:2019-06-26 20:16:49

标签: python arguments

我有一个脚本以命令行参数arg(例如python [-h]最新90210)打开。另一个程序将打开一个对话框,并保存zip并将结果排序到一个变量中。

如何从对话框程序中调用第一个脚本并使用对话框程序中存储的变量来运行第一个脚本?

第一个脚本

if __name__ == "__main__":


# Reading arguments

argparser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
argparser.add_argument('zipcode', help='')
sortorder_help = """
available sort orders are :
newest : Latest property details,
cheapest : Properties with cheapest price
"""

argparser.add_argument('sort', nargs='?', help=sortorder_help, default='Homes For You')
args = argparser.parse_args()
zipcode = args.zipcode
sort = args.sort
print ("Fetching data for %s" % (zipcode))
scraped_data = parse(zipcode, sort)
if scraped_data:
    print ("Writing data to output file")
    write_data_to_csv(scraped_data)

对话程序

from tkinter import *
from io import StringIO
import zillow
import sys

root = Tk()

#window size and location
root.geometry("300x150+50+50")

#label
label = Label(root, text='Enter Zip Code')
label.pack()

# Create single line text entry box
entry = Entry(root)
entry.pack()

#second label
label = Label(root, text='Select a Filter')
label.pack()

#drop down menu
variable= StringVar(root)
variable.set("newest")

w= OptionMenu(root, variable, "newest", "cheapest")
w.pack()

# Print the contents of entry widget to console
def print_content():
print("python zillow.py [-h] {0} {1}"
.format(entry.get(),variable.get())) 

result = StringIO()
sys.stdout = result
result_string = result.getvalue()
print(result)

# Create a button that will print the contents of the entry
button = Button(root, text='Search', command=print_content)
button.pack()

root.mainloop()

0 个答案:

没有答案