Python - 30 File System Database Project - Read File and Directory

preview_player
Показать описание
This video is a continuation of the Python series. It covers the following:

- How to read files using the os module
- How to check if a file exists
- How to create a new file if it doesn't exist
- How to delete a file
- How to save user data

Key takeaways:
- The os module can be used to interact with the file system.
- The read function can be used to read the contents of a file.
- The write function can be used to write data to a file.
- The delete function can be used to delete a file.
- The exists function can be used to check if a file exists.
Рекомендации по теме
Комментарии
Автор

For people viewing this, here is a cleaner approach to the read function in the database.py before 15:49

def read(acc):
db_path = "data/user_record"
if str(acc) != acc:
file_path = db_path + str(acc) + '.txt'
else:
file_path = db_path + str(acc)

if os.path.exists(file_path):
try:
f = open(file_path, "r")
return f.readline()
except error:
print(error)
else:
print('Path doesn't exist')

bonarhyme
Автор

To eliminate the 'account number must be an integer' error

I just sliced the 'user' in the 'for loop' for 'does_email_exist' function, since .txt is still attached to print(user)

So I used print(read(user[:10])) to extract the numbers since the account number will always be 10 digits

OluwaseunAwosise
join shbcf.ru