Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SyntaxError:Can';t分配给函数调用_Python_Python 2.x - Fatal编程技术网

Python SyntaxError:Can';t分配给函数调用

Python SyntaxError:Can';t分配给函数调用,python,python-2.x,Python,Python 2.x,我是python和编程新手,我正在学习一门在线课程。要编写的代码是计算谁在txt文件中发送了最多的电子邮件,并且只读取“中以“”开头的行。我的代码是 name = raw_input("Enter file:") if len(name) < 1 : name = "mbox-short.txt" handle = open(name) counts = dict() for line in handle: if line.startswith("From"): wd

我是python和编程新手,我正在学习一门在线课程。要编写的代码是计算谁在txt文件中发送了最多的电子邮件,并且只读取“中以“”开头的行。我的代码是

name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
counts = dict()
for line in handle:
   if line.startswith("From"):
        wds =  line.split()
        if len(wds)<2: continue
        email = wds[1]
        print email
   counts(email) = counts.get(email , 0)+1
name=raw\u输入(“输入文件:”)
如果len(name)<1:name=“mbox short.txt”
句柄=打开(名称)
计数=dict()
对于线输入句柄:
如果行开始于(“起始”):
wds=line.split()

如果len(wds)要写入一个
dict
,请使用方括号:

counts[email] = ...
而不是

counts(email) = ...

圆括号
()
用于调用函数,因此解释器认为您正在尝试为函数调用赋值。

此:
计数(电子邮件)
是函数调用。您无法将其设置为值。对于将来的问题:错误是当场发生的。对于初学者来说,这可能有点神秘,但一些研究有很长的路要走。