Обратите внимание, что приведенный ниже код написан на Python с использованием самой последней версии PyCharm.
Вот код, который я использую для получения информации от пользователя:
Код: Выделить всё
def EnterRecordDetails():
FileData = {}
# Get information from user
name = str(input("Name: "))
medium = str(input("Medium: "))
status = str(input("Current Status: "))
genre = str(input("Genre: "))
rating = int(input("Rating: "))
link = str(input("Link: "))
total_eps = int(input("Total Episodes: "))
current_ep = int(input("Current Episode: "))
# Enter Data into dictionary
FileData["name"] = name
FileData["medium"] = medium
FileData["status"] = status
FileData["genre"] = genre
FileData["rating"] = rating
FileData["link"] =link
FileData["total"] =total_eps
FileData["current"] =current_ep
print(FileData)
# set the File path
FilePath = "Database/" + medium + "/" + name
return FilePath, FileData
Код: Выделить всё
def AddRecord():
fileLocation, fileData = EnterRecordDetails()
Directory = os.path.dirname(fileLocation)
Dir_exists = os.path.exists(Directory)
if Dir_exists:
with open(fileLocation + ".json", "w") as file:
json.dump(fileData, file)
return
Изменить:
Я только что протестировал свой код и по какой-то причине оно работает? Я не знаю, может быть, я просто неправильно вводил данные или что-то в этом роде
Подробнее здесь: https://stackoverflow.com/questions/793 ... ad-so-that