首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python语法问题- TypeError:未找到必需的参数'name‘(pos 1)

Python语法问题- TypeError:未找到必需的参数'name‘(pos 1)
EN

Stack Overflow用户
提问于 2019-06-20 07:09:01
回答 1查看 3.3K关注 0票数 2

我试图将一些文件按其内容分开,我的代码如下所示,它不断地向我显示错误。

代码语言:javascript
复制
__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

我犯了这个错误

代码语言:javascript
复制
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

有人能帮忙吗。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-06-20 07:14:08

正如您可以看到的,内置函数这里 open不把文件作为关键字参数,它需要直接设置,您的错误说找不到所需的参数“名称”,这是因为您需要直接设置文件的名称,而不是作为关键字参数。

即:open(one_meter_File, 'w+')

编辑,如果有人读到:,如注释中所述,这个错误只发生在python2上,因为python3将kwargs作为普通的args处理,如果键名正确的话。因此,校对您的python安装,或将其更正为python 2需要,这里是用于open的python 2文档。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56680740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档