使用命令参数在文件中搜索单词?在 python3 中,没有弹出任何答案

searching for a word in a file using command argument? in python3, popping up no answers

尝试编写一个程序,在字典文件中搜索以第一个命令行参数开头的单词,这是它们的词干,但我什么也没得到。

这是我的代码,我做错了什么?

import sys
import os

stem = str(sys.argv[1:])
searchline = open("american-english-insane")
for line in searchline:
 if line.startswith(stem):
  print(word)

另一方面,它可以工作并发出 hello、helloes、helloeing 等...但它不会作为命令行参数传递。

import sys
import os

stem = sys.argv[1:]
searchline = open("american-english-insane")
for line in searchline:
 if line.startswith('hello'):
  print(line)

使用下面的代码片段,returns 一个字符串对象

stem = sys.argv[1]