【问题标题】:searching for a word in a file using command argument? in python3, popping up no answers使用命令参数在文件中搜索单词?在python3中,弹出没有答案
【发布时间】:2016-04-22 07:48:47
【问题描述】:

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

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

import sys
import os

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

另一方面,这可以工作并吐出你好,你好,你好,等等......但它不是作为命令行参数传递的。

import sys
import os

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

【问题讨论】:

    标签: file python-3.x command arguments line


    【解决方案1】:

    使用下面的sn-p,返回一个字符串对象

    stem = sys.argv[1]
    

    【讨论】:

      猜你喜欢
      • 2014-01-18
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      相关资源
      最近更新 更多