Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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语法问题-TypeError:必需参数';名称';(位置1)未找到_Python_Syntax_Io_Python 2.x - Fatal编程技术网

Python语法问题-TypeError:必需参数';名称';(位置1)未找到

Python语法问题-TypeError:必需参数';名称';(位置1)未找到,python,syntax,io,python-2.x,Python,Syntax,Io,Python 2.x,我正在尝试按内容分隔一些文件,我的代码如下所示 它不断向我显示错误 __author__ = 'Sahil Nagpal' from pyspark import SparkContext,SparkConf from pyspark.sql import SparkSession spark = SparkSession.builder.appName("GEOTRELLIS").getOrCreate() sparkcont = SparkContext.getOrCreate(Spa

我正在尝试按内容分隔一些文件,我的代码如下所示 它不断向我显示错误

__author__ = 'Sahil Nagpal'

from pyspark import SparkContext,SparkConf
from pyspark.sql import SparkSession


spark = SparkSession.builder.appName("GEOTRELLIS").getOrCreate()
sparkcont = SparkContext.getOrCreate(SparkConf().setAppName("GEOTRELLIS"))
logs = sparkcont.setLogLevel("ERROR")



imageFile = "/mnt/imagefile/IMGFileCopy.txt"
one_meter_File = "/mnt/imagefile/one_meter/one_meter_file.txt"
_13_File = "/mnt/imagefile/13_meter/_13_File.txt"
ned19_File = "/mnt/imagefile/ned19/ned19_File.txt"

#iterate over the file
try:
    with open(file=imageFile,mode="r+") as file, open(file=one_meter_File,mode='w+') as one_meter_File,open(file=_13_File,mode='w+') as _13_File,open(file=ned19_File,mode='w+') as ned19_File:

        for data in file.readlines():
            if("one_meter" in data):
                #writing the one_meter file
                one_meter_File.write(data)
            elif("_13" in data):
                # writing the _13 file
                _13_File.write(data)
            elif("ned19" in data):
                # writing the ned19 file
                ned19_File.write(data)


        one_meter_File.close()
        _13_File.close()
        ned19_File.close()
        file.close()
    print("File Write Done")

except FileNotFoundError:
    print("File Not Found")

#spark-submit --master local[*] project.py
我犯了这个错误

with open(file=imageFile,mode="r+") as file, open(file=one_meter_File,mode='w+') as one_meter_File,open(file=_13_File,mode='w+') as _13_File,open(file=ned19_File,mode='w+') as ned19_File:
TypeError: Required argument 'name' (pos 1) not found
有人能帮忙吗。提前谢谢。

如您所见 内置函数
open
没有将文件作为关键字参数,它需要直接设置,您的错误是找不到所需的参数“name”,这是因为您需要直接设置文件的名称,而不是作为关键字参数

i、 e:
打开(一个米文件“w+”)

如果有人阅读此内容,请编辑:
如注释中所述,此错误仅在Python2上发生,因为Python3在键名正确的情况下将KWARG作为普通参数处理。因此,请检查您的python安装,或根据python 2的需要进行更正,python 2文档是否适用于
打开

魔术是您的答案!另外,请注意这是一个Python2错误,非常奇怪,在Python3上发生了这种情况,如果我可以问的话,您使用的是什么版本和IDE?(正如您所看到的,所需参数仅在Python2中被称为“name”)是的,实际上现在理解了问题所在。我在AWS集群上运行代码,安装了默认的python,集群上的默认环境变量始终是Python2.7,而不是Python3。因此,我首先需要将版本设置为3或更高。导出PYSPARK_PYTHON=python3.4好的,对于python3,它应该可以工作,即使您使用关键字参数作为必需的参数,解释器也足够智能,可以正确地解释它。事实上,我被你的标签骗了。这是一个有用的标签,但是如果人们处于相同的位置,他们必须阅读这些评论才能理解为什么会发生这种情况(我编辑了我的答案)