Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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文件,错误?_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

写入Python文件,错误?

写入Python文件,错误?,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我试图在文件中写入: f = open('parsed.txt', 'w') f.write(url + '\n' + title + '\n' + email + '\n\n') 但我得到了一个错误: Traceback (most recent call last): File "C:/Users/Brand Cream/AppData/Local/Programs/Python/Python35/index.py", line 122, in parsePage f =

我试图在文件中写入:

 f = open('parsed.txt', 'w')

f.write(url + '\n' + title + '\n' + email + '\n\n')
但我得到了一个错误:

Traceback (most recent call last):
  File "C:/Users/Brand Cream/AppData/Local/Programs/Python/Python35/index.py", line 122, in parsePage
    f = open('parsed.txt', 'w')
TypeError: open() takes 1 positional argument but 2 were given

怎么了?

您可能在代码的另一个地方有一个名为
open
的函数,它只接受一个参数。这就是您出现此错误的原因。

您的代码中是否碰巧有自己的
open
函数?您有自己的
open()
函数,或者您使用来自。。。导入*并覆盖oryginal
open()
函数。是的,您是对的,但我得到了一个空文件,因此,我在运行脚本的同一目录中创建了该文件