鱼C论坛

 找回密码
 立即注册
查看: 1331|回复: 3

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

[复制链接]
发表于 2022-3-19 22:00:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
原代码:
  1. import os.path
  2. def GDOS():
  3.     while True:
  4.         inp = str(input('请输入指令:'))
  5.         if inp[:8] == 'G_print:':
  6.             content = inp[8:]
  7.             print(content)
  8.         elif inp == 'G_quit':
  9.             print('退出登录!')
  10.             break
  11.         elif inp == 'Nfile':
  12.             fileName = str(input('新创建文件的文件名(需要写后缀):'))
  13.             filePath = str(input('新创建文件的路径:'))
  14.             openFilePath = filePath + fileName
  15.             temp = open(openFilePath,'w')
  16.             writeStr = str(input('要写入文件的内容:'))
  17.             temp.write(writeStr)
  18.             temp.close
  19.         elif inp == 'Wfile':
  20.             fileName = str(input('要打开文件的文件名:'))
  21.             filePath = str(input('要打开文件的路径:'))
  22.             openFilePath = filePath + fileName
  23.             temp = open(openFilePath,'a')
  24.             writeStr = str(input('要写入文件的内容:'))
  25.             temp.write(writeStr)
  26.             temp.close
  27.         elif inp[:5] == 'help:':
  28.             if inp[5:] == 'GDOS_encoding':
  29.                 print('光电OSpyhon_cmd版默认采用cp936的文件编码格式')
  30.         elif inp == 'Nfile_pro':
  31.             print('由于此功能过于灵活,可能会报错,不要惊慌,那是因为编码格式不存在导致的,不会危害电脑。')
  32.             fileName = str(input('新创建文件的文件名(需要写后缀):'))
  33.             filePath = str(input('新创建文件的路径:'))
  34.             fileCoding = str(input('新创建文件的文件编码格式'))
  35.             openFilePath = filePath + fileName
  36.             temp = open(openFilePath,'w',encoding = fileCoding )
  37.             writeStr = str(input('要写入文件的内容:'))
  38.             temp.write(writeStr)
  39.             temp.close
  40. def new():
  41.     name = str(input('请输入用户名:'))  
  42.     if name in user:
  43.         print('已存在用户名为' + name + '的用户!')
  44.     else:
  45.         code = str(input('请输入密码:'))
  46.         user[name] = code
  47.         print('注册成功!')
  48. def loin():
  49.     name_search = str(input('请输入用户名:'))
  50.     if name_search in user:
  51.         code_search = str(input('请输入密码:'))
  52.         if code_search == user[name_search]:
  53.             print('登录成功!')
  54.             print('欢迎进入GD_cmd系统!')
  55.             GDOS()
  56.         else:
  57.             print('密码输入错误!')
  58.     else:
  59.         print('您输入的用户不存在!')

  60. print('请登录GD OS的账户以使用GD OS的所有功能')
  61. print('|---新建用户: N/n----|')
  62. print('|---登录账号: E/e----|')
  63. print('|---关闭系统: Q/q----|')
  64. if os.path.exists('C:\\gdcmd\\gdcmduser.txt') == True:
  65.     temp = open('C:\\gdcmd\\gdcmduser.txt','w')
  66.     temp1 = temp.read()
  67.     user = temp1
  68. else:
  69.     user = {}
  70. while True:
  71.     instructions = str(input('请输入指令代码:'))
  72.     if instructions == 'N' or instructions == 'n':
  73.         new()
  74.     elif instructions == 'E' or instructions == 'e':
  75.         loin()
  76.     elif instructions == 'Q' or instructions == 'q':
  77.         print('关闭系统!')
  78.         if os.path.exsits('C:\\gdcmd') == True:
  79.             temp = open('C:\\gdcmd\\gdcmduser.txt','w')
  80.             temp.write(user)
  81.             temp.close
  82.         else:
  83.             os.path.mkdir('C:\\gdcmd')
  84.             temp = open('C:\\gdcmd\\gdcmduser.txt','w')
  85.             temp.write(user)
  86.             temp.close
  87.         break
  88.     else:
  89.         print('该指令不存在!')
复制代码
报错信息:
  1. <blockquote>Traceback (most recent call last):
复制代码
请问为什么它说没有exists方法?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-3-20 20:23:23 | 显示全部楼层
本帖最后由 boss98 于 2022-3-20 20:33 编辑

你可以看一下环境中有没有这个包
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-3-20 20:35:37 | 显示全部楼层
boss98 发表于 2022-3-20 20:23
你可以看一下环境中有没有这个包

我这里你的代码是可以直接运行的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-3-20 21:37:19 | 显示全部楼层
你的这个脚本不要命令成 os.py 或者os.path.py
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 12:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表