我创建的应用程序在网站列表中查找并返回完全匹配,如果输入的输入值与应用程序打印的列表中的任何元素完全匹配,或者如果输入的值不匹配,则应用程序打印输入的内容与列表中的任何元素不匹配,或者,如果输入部分匹配列表中的任何元素,则应用程序打印的部分匹配项是found.The,问题是,我以一种方式编写了该应用程序,所以当我运行它时,会出现一个输入字段,以便输入我希望它们是否与现有列表中的任何元素匹配的“单词”或“链接”,但是当我运行该应用程序时,我不想输入这个输入字段的值,而是想直接输入输入的值:
python3 app.py http://www.virus.com/
然后应用程序在列表中进行所有查找并打印结果,是否有完全匹配、部分匹配或不匹配。
listOfSites = ( "www.phishingsite.com",
"www.virus.net.org/clickme",
"zxcmalware.com",
"trojan.badsite.org",
"www.tgby.com/ratlink"
)
while stop == False:
# Input Variable
enter_site = str(input('Enter your URL here: '))
# Conditional list Comprehension
matching = [s for s in listOfSites if enter_site in s]
reply = False
if enter_site in listOfSites:
reply = False
print(f'Full match for {enter_site}')
elif matching:
reply = False
print(f'Partial match found for {matching}')
elif enter_site not in listOfSites:
reply = False
print(f'No match found for {enter_site}')
while reply == False:
go_on = str(input('Keep on searching? (y/n): '))
if go_on.lower() =='n':
stop=True
reply=True
elif go_on.lower() == 'y':
reply =True
stop = False
elif go_on.lower() != 'n' and go_on.lower() != 'y':
plus = 'Type y for yes or n for no'
print(plus + go_on)
print('You left the search')我希望我说的很清楚
提前谢谢你!
发布于 2021-04-08 10:55:55
在命令行中运行程序时,可以使用sys模块访问这些参数。
sys.argv包含所有参数,在您的例子中调用'python3 app.py www.virus.com‘,它看起来像下面的['app.py', 'www.virus.com']
在这里,URL在sys.argv[1]中。
https://stackoverflow.com/questions/67002438
复制相似问题