Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.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 - Fatal编程技术网

Python 属性错误:';元组';对象没有属性';写';

Python 属性错误:';元组';对象没有属性';写';,python,Python,这是代码,我在写的时候遇到了这个错误 AttributeError:“tuple”对象没有属性“write” 我已经读了所有我能找到的东西 还是不知道我做错了什么 我对Python非常陌生 谢谢没关系。。。我看到了问题: line1 = (n1,'-',n2,'-',n3,'-',n4,'-',n5,'powerball =',pb,"----> Random Numbers",'\n') line2 = (l1,'-',l2,'-',l3,'-',l4,'-',l5,'pow

这是代码,我在写的时候遇到了这个错误 AttributeError:“tuple”对象没有属性“write” 我已经读了所有我能找到的东西 还是不知道我做错了什么 我对Python非常陌生
谢谢

没关系。。。我看到了问题:

line1 = (n1,'-',n2,'-',n3,'-',n4,'-',n5,'powerball =',pb,"----> Random       Numbers",'\n')
line2 = (l1,'-',l2,'-',l3,'-',l4,'-',l5,'powerball =',lpb,"----> Low Numbers",'\n')
line3 = (m1,'-',m2,'-',m3,'-',m4,'-',m5,'powerball =',mpb,"----> Medium Numbers",'\n')
line4 = (h1,'-',h2,'-',h3,'-',h4,'-',h5,'powerball =',hpb,"----> Hi Numbers",'\n')
line5 = (n1,'-',l2,'-',m3,'-',h4,'-',n5,'powerball =',lpb,"----> Mixed       Numbers",'\n')


file1 = (line1 + line2 + line3 + line4 + line5)

file_name = "file_name"
today1 = open(file_name , "r+")
file_name = file1
file_name.write();  
也许你想要这样的东西:

file_name = "file_name"
today1 = open(file_name , "r+")
# At this point, you've opened the file "file_name"

file_name = file1
# Here, the variable file_name now contains that monster string
#   you put together.
# You have utterly lost the handle to your open file.

file_name.write();
# You have just tried to write output to that monster string.
# "write" is a file command, not a string operation.

这将(尝试)将怪物字符串的值写入输出文件。我担心文件模式:“读取扩展”。你打算从文件中读什么?你想用这个做什么?

不;这将导致“NameError:名称'file1'未定义”。欢迎使用StackOverflow。请阅读并遵循帮助文档中的发布指南。适用于这里。在您发布MCVE代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中,并重现您描述的问题。更多代码行1=(n1',-',n2',-',n3',-',n4',-',n5,'powerball=',pb,“--->”随机数“,'\n')line2=(l1',-',l2',l3',-',l4',-',l5,'powerball=',lpb,“----”、'>Low Numbers“,'\n')line3=(m1 m1',-',m2',m3',m4',-,'powerball',mpb,“——>中号”、“\n’’line4=(h1’——”、h2’——”、h3’——”、h4’——”、h5、‘powerball=”、hpb、“——”、“\n’)line5=(n1’——”、l2’——”、m3’——”、h4’——“——”、n5、“\n’)file1=(line1+line2+line3+line4+line5)file name=“file\u name”today1=open file(file\u name),“r name”,“r name=”fileu=fileu;更多的代码将代码编辑到原始问题中,而不是在注释中。再次,请遵循发布指南。我知道有很多。我正在尝试编写一个文件发送到打印机。猜测我的字符串太长不,请阅读我的注释:您试图调用
write
,一个文件方法,使用字符串。您必须调用
write
,将数据(字符串)作为参数)。
file_name = "file_name"
today1 = open(file_name , "r+")
file_name.write(file1);