为啥会报Open没有定义
来源:1-4 文件的创建与写入(下)
6669ll
2022-10-12 15:14:48
import os
def create_package(path):
if os.path.exists(path):
raise Exception('%s 已经存在不可创建' % path)
os.makedirs(path)相关截图:
init_path=os.path.join(path,'init-gp.py')
f=open(init_path,'w')
f.write('#coding:utf-8\n')
f.close()
if __name__=='__main__':
current_path=os.getcwd()
def __init__(self,path,mode='w',is_return=True):
self.path=path
self.mode=mode
self.is_return=is_return
def write(self,message):
f=open(self.path,mode=self.mode)
if self.is_return:
message='%s\n' % message
f.write(message)
f.close()相关截图:
os (path): os.path.exists(path): (% path) os.makedirs(path) init_path=os.path.join(path) f=(init_path) f.write() f.close() __name__==: current_path=os.getcwd() open_path=os.path.join(current_path) o=Open(open_path) o.write() Open(): (pathmode=is_return=): .path=path .mode=mode .is_return=is_return (message): f=(.path=.mode) .is_return: message=% message f.write(message) f.close()
相关截图:

1回答
好帮手慕小猿
2022-10-12
同学,你好!同学提供的代码与运行文件代码不一致,运行的文件是package_pen.py,同学是否粘贴了所有代码呢?还是运行错了文件呢?报错提示没有定义Open()这个类,同学可找下代码中有没有Open 这个类

同学也可将所有代码以复制粘贴的形式粘贴到问答区,方便解决同学的问题。
相似问题