我正在尝试运行一个 python 程序,该程序从用户那里获取输入,例如目录名、文件名及其内容,然后我尝试使用该文件在当前路径中创建目录,然后将数据写入其中,但我得到一个错误“os没有属性mkdir”。
//Code
import os
print(os.getcwd())
class createfile:
__name=''
__file_name=''
__input_text=''
def read_and_create(self):
name = input("Enter the directory name, you want to create: ")
os.mkdir(self.__name)
#sdos.mkdir(self.__name)
self.__file_name=input("Enter the file name, you want to create: ")
f=open(self.___file_name,'w')
self.__input_text=input("Enter the text : ")
f.write(self.__input_text)
f.close()
def read_file_content(self):
x=open(self.__file_name,'r')
print(x.read())
o=createfile()
o.read_and_create()
o.read_file_content()
Run Code Online (Sandbox Code Playgroud)
这是我使用 Pycharm 时遇到的错误。
> "C:\Users\Aryan
> Kumar\AppData\Local\Programs\Python\Python37-32\python.exe"
> "C:/Users/Aryan Kumar/Desktop/0/os.py"
> Fatal Python error: initsite: Failed to import the site module
> Traceback (most recent call last):
> File …Run Code Online (Sandbox Code Playgroud) python-3.7 ×1