Python Pycharm和sys.argv[1]

Python Pycharm和sys.argv[1],python,pycharm,tweets,Python,Pycharm,Tweets,我正在尝试运行此程序: # Chap02-03/twitter_hashtag_frequency.py import sys from collections import Counter import json def get_hashtags(tweet): entities = tweet.get('entities', {}) hashtags = entities.get('hashtags', []) return [tag['text'].lower()

我正在尝试运行此程序:

# Chap02-03/twitter_hashtag_frequency.py
import sys
from collections import Counter
import json

def get_hashtags(tweet):
    entities = tweet.get('entities', {})
    hashtags = entities.get('hashtags', [])
    return [tag['text'].lower() for tag in hashtags]

if __name__ == '__main__':
    fname = sys.argv[1]
    with open(fname, 'r') as f:
        hashtags = Counter()
        for line in f:
            tweet = json.loads(line)
            hashtags_in_tweet = get_hashtags(tweet)
            hashtags.update(hashtags_in_tweet)
        for tag, count in hashtags.most_common(20):
            print("{}: {}".format(tag, count))
我想在Pycharm中运行程序m
twitter\u hashtag\u frequency.py
,使用json文件
stream\u.jsonl
作为参数,该文件与程序位于同一目录中。你能告诉我如何编辑这个代码吗?我试了好几次,没有成功,我犯了这个错误:

 fname = sys.argv[1]
IndexError: list index out of range

感谢您的帮助。

如果按绿色播放按钮(编辑配置旁边)运行文件,则需要在参数的配置菜单中指定参数。在文本框中输入
stream.jsonl

还要仔细检查工作目录是否设置为包含这两个文件的目录


我使用Pycharm Professional 2019.3,在脚本路径的配置窗口中,我有C:\Users\HP\PycharmProjects\Bonzanini\u Book\u Exercises\twitter\u hashtag\u frequency.py,在我放置的参数“stream.jsonl”和我的工作目录中,我有:C:\Users\HP\PycharmProjects\Bonzanii\u Book\u Exercises。我仍然有错误错误是什么错误?你能发布你的配置截图吗?这是截图![1] :这是错误![1] :您可以共享.jsonl文件的内容吗?前几行的截图很有用