正如标题所说,我正在使用Python制作数据库系统(非常非常早期的开发阶段,所以请不要对它进行评判)并且我对文件i / o有一些问题。更具体地说,我打开和写入的文件将不会被代码创建,即使我手动创建文件也不会写入它...基本上文件i / o函数什么也不做,并且不是返回任何错误!
pydb.py
=23
testing.py
import os
class schema:
__tableName = ""
__colCnt = 0
__columns = []
# This constructor DOES NOT make the columns it simple set some of the schema variables
def __init__(self, tableName, colCnt):
self.__tableName = tableName
self.__colCnt = colCnt
# Considering we didn't make the columns in this function we will redirect to the method to do so
self.__createCols()
# This function actually cycles through each column expecting a name for it
def __createCols(self):
for i in range(0, self.__colCnt):
self.__columns.append(None)
self.__columns[i] = input("Column #{0}: ".format(i))
# Checking for schema structures' folders and creating empty schema file
if os.path.exists("/schema/"):
os.chdir("/schema/")
open(self.__tableName + ".schema", "a").close()
else:
os.mkdir("/schema/")
os.chdir("/schema/")
open(self.__tableName + ".schema", "a").close()
# Writes to schema file that was just created
os.chdir("/schema/")
f = open(self.__tableName + ".schema", "w+")
f.write("{0}:schema[{1}] = (".format(self.__tableName, self.__colCnt))
for i in range(0, self.__colCnt):
f.write(self.__columns[i] + ", ")
f.close()
# Some responses and concern messages after schema file has been created successfully
print("All columns successfully created!")
print("[this is simply a temporary layout for a table not an actual table] Please bake this schema for use.")