唐,不知道如何解决这个问题? [英] Don, t know how to solve this?

查看:82
本文介绍了唐,不知道如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from sys import argv
from os.path import exists

print(f"Copying from test.txt to copy-write.txt ")

# We could do these two on new line, how ?

in_file = open(test.txt)
indata = in_file.read()


print(f"The input file is {len(in_file)} long")

print(f"Does the output file exist? {exists(copy-write)}")

print('Ready , hit RETURN to continue , CTRL + C to abort')
input()

out_file = open(copy-write, 'w')
out_file.write(indata)

print("Alright It,s done baby")

out_file.close()
in_file.close()





我尝试过:



i收到名称错误。我找到的文件我已经给文件位置正确,但我得到这个名称没有定义



What I have tried:

i am getting a name error . the file i located i have gave the file location right but i am getting the this name is not defined

推荐答案

你需要在你的文件名周围加上引号声明。它们是文件的名称,而不是Python对象。



我建议你去 Python教程 - Python 3.7.1文档 [ ^ ]并通过它几次。您将比在此处发布基本问题更快地学习。
You need to put quotes around your file names in the open statements. They are names of files, not Python objects.

I suggest you go to The Python Tutorial — Python 3.7.1 documentation[^] and work your way through it a few times. You will learn much faster than posting basic questions here.


这篇关于唐,不知道如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆