这段代码输入python编译器里面显示错误,不知道哪里出现了问题
import osimport glob
folder_path = 'C:/Users/2546028300/Desktop/新建文件夹 (2)'
line_number = 7
with open('output.txt', 'w') as outfile:
for filename in glob.glob(os.path.join(folder_path, '*.txt')):
with open(filename, 'r') as infile:
line = infile.readlines()
outfile.write(line)
SyntaxError: multiple statements found while compiling a single statement
尝试修复你的代码的缩进 由于代码缩进不正确,导致Python解释器不能正确地解析代码块,for循环和with语句的代码块都需要缩进,这样才能让Python解释器正确的解析
import os
import glob
folder_path = 'C:/Users/2546028300/Desktop/新建文件夹 (2)'
line_number = 7
with open('output.txt', 'w') as outfile:
for filename in glob.glob(os.path.join(folder_path, '*.txt')):
with open(filename, 'r') as infile:
line = infile.readlines()
outfile.write(line) 都提示了是语法错误 qq499414099 发表于 2023-10-5 11:40
由于代码缩进不正确,导致Python解释器不能正确地解析代码块,for循环和with语句的代码块都需要缩进,这样 ...
非常感谢 用文心一言差不多就能解决你的问题。
页:
[1]