songwentao 发表于 2022-3-19 22:00:24

【os.path】为什么报错说没有exists方法(已导入os.path模块))?

原代码:
import os.path
def GDOS():
    while True:
      inp = str(input('请输入指令:'))
      if inp[:8] == 'G_print:':
            content = inp
            print(content)
      elif inp == 'G_quit':
            print('退出登录!')
            break
      elif inp == 'Nfile':
            fileName = str(input('新创建文件的文件名(需要写后缀):'))
            filePath = str(input('新创建文件的路径:'))
            openFilePath = filePath + fileName
            temp = open(openFilePath,'w')
            writeStr = str(input('要写入文件的内容:'))
            temp.write(writeStr)
            temp.close
      elif inp == 'Wfile':
            fileName = str(input('要打开文件的文件名:'))
            filePath = str(input('要打开文件的路径:'))
            openFilePath = filePath + fileName
            temp = open(openFilePath,'a')
            writeStr = str(input('要写入文件的内容:'))
            temp.write(writeStr)
            temp.close
      elif inp[:5] == 'help:':
            if inp == 'GDOS_encoding':
                print('光电OSpyhon_cmd版默认采用cp936的文件编码格式')
      elif inp == 'Nfile_pro':
            print('由于此功能过于灵活,可能会报错,不要惊慌,那是因为编码格式不存在导致的,不会危害电脑。')
            fileName = str(input('新创建文件的文件名(需要写后缀):'))
            filePath = str(input('新创建文件的路径:'))
            fileCoding = str(input('新创建文件的文件编码格式'))
            openFilePath = filePath + fileName
            temp = open(openFilePath,'w',encoding = fileCoding )
            writeStr = str(input('要写入文件的内容:'))
            temp.write(writeStr)
            temp.close
def new():
    name = str(input('请输入用户名:'))
    if name in user:
      print('已存在用户名为' + name + '的用户!')
    else:
      code = str(input('请输入密码:'))
      user = code
      print('注册成功!')
def loin():
    name_search = str(input('请输入用户名:'))
    if name_search in user:
      code_search = str(input('请输入密码:'))
      if code_search == user:
            print('登录成功!')
            print('欢迎进入GD_cmd系统!')
            GDOS()
      else:
            print('密码输入错误!')
    else:
      print('您输入的用户不存在!')

print('请登录GD OS的账户以使用GD OS的所有功能')
print('|---新建用户: N/n----|')
print('|---登录账号: E/e----|')
print('|---关闭系统: Q/q----|')
if os.path.exists('C:\\gdcmd\\gdcmduser.txt') == True:
    temp = open('C:\\gdcmd\\gdcmduser.txt','w')
    temp1 = temp.read()
    user = temp1
else:
    user = {}
while True:
    instructions = str(input('请输入指令代码:'))
    if instructions == 'N' or instructions == 'n':
      new()
    elif instructions == 'E' or instructions == 'e':
      loin()
    elif instructions == 'Q' or instructions == 'q':
      print('关闭系统!')
      if os.path.exsits('C:\\gdcmd') == True:
            temp = open('C:\\gdcmd\\gdcmduser.txt','w')
            temp.write(user)
            temp.close
      else:
            os.path.mkdir('C:\\gdcmd')
            temp = open('C:\\gdcmd\\gdcmduser.txt','w')
            temp.write(user)
            temp.close
      break
    else:
      print('该指令不存在!')报错信息:<blockquote>Traceback (most recent call last):请问为什么它说没有exists方法?

boss98 发表于 2022-3-20 20:23:23

本帖最后由 boss98 于 2022-3-20 20:33 编辑

你可以看一下环境中有没有这个包

boss98 发表于 2022-3-20 20:35:37

boss98 发表于 2022-3-20 20:23
你可以看一下环境中有没有这个包

我这里你的代码是可以直接运行的

suchocolate 发表于 2022-3-20 21:37:19

你的这个脚本不要命令成 os.py 或者os.path.py
页: [1]
查看完整版本: 【os.path】为什么报错说没有exists方法(已导入os.path模块))?