Dec-16-2020, 01:28 PM
I found it.
Sry for disturbing you!!
Sry for disturbing you!!
Why do i get these errors?
|
Dec-16-2020, 01:28 PM
I found it.
Sry for disturbing you!!
Dec-16-2020, 01:30 PM
I need help on solving the errors,
Script, import csv import os.path import time import imp import sys if not os.path.exists(r"D:\My folder\Projects\Programing\Python\Student Data storing app\Register.csv"): #run start up script print("Cache was Deleted!\nCreating new Cache") time.sleep(3) with open (r"D:\My folder\Projects\Programing\Python\Student Data storing app\Register.csv", "w") as new_file : fieldnames = ["Full name", "Phone 1", "Phone 2", "Identity Number", "Email", "Paid/not"] csv_writer = csv.DictWriter(new_file, fieldnames = fieldnames, delimiter = ",") csv_writer.writeheader() file = open (r"D:\My folder\Projects\Programing\Python\Student Data storing app\Data.txt", "w") #creates our file to say startup is complete you could write to this if you wanted as well def pass_new(): password = input("Please enter a password.\nUse only letters.") pass_len = len(password) if pass_len < 10: print("Password saved!") file.write("Pass = " + password) else : print("Password must not exceed 10 characters.") sys.exit() pass_new() file.write() print("Startup is complete.") file.close def pass_check(): f = open(r"D:\My folder\Projects\Programing\Python\Student Data storing app\Data.txt") global data data = imp.load_source('data', '', f) f.close() correct_pass = data.Pass user_input_pass = input("Please enter your Password.") if user_input_pass == correct_pass: print("Password accepted!") else : print("Password incorrect.\nAccess denied!") sys.exit() pass_check() print("'add' - Adds a new user. \n'update' - Updates a user.") print("'remove' - Removes a user.\n {confrim}") user_input = input("Enter a command : ").lower() if user_input == "add": print("Command - 'add'\n{Fullname} {Phone 1} {Phone 2} {Identity Number} {Email} {Paid/not}") else : print("Error!\nPlease enter a valid option.") if user_input == "update": print("Command - 'update'\n{Fullname} {Phone 1} {Phone 2} {Identity Number} {Email} {Paid/not}") else : print("Error!\nPlease enter a valid option.") if user_input == "remove": print("Command - 'remove'\n {Full name} {Identity number} ") confirm = input("Please 'Confirm' removal of user.\nThis cannot be undone! ~~~ (Type 'confirm')").lower() if confirm == "confrim": print("User removed") else : print("User not removed. :D") else : print("Error!\nPlease enter a valid option.")Errors, What causes these errors?I don't know how to fix it!.
Please, don't start new thread. Keep the discussion in this thread. If the answer you get does not solve the problem, say so, don't start new thread.
what exactly you want to do with imp ? You don't need it at all.also what do you think this line data = imp.load_source('data', '', f) is doing?I would suggest you read again on how you work with files (like csv files) in python. here is our tutorial: https://python-forum.io/Thread-Basic-Files Note that there are number of issues with your script (that don't raise errors [yet]). For example:
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Dec-16-2020, 02:56 PM
(Dec-16-2020, 02:23 PM)buran Wrote: Please, don't start new thread. Keep the discussion in this thread. If the answer you get does not solve the problem, say so, don't start new thread.Sorry, but it solved some of the problems!. I'll not do it again. (Dec-16-2020, 02:23 PM)buran Wrote: what exactly you want to do with imp? You don't need it at all.That is the thing. i was watching a tutorial. I don't know what it does, but I haven't finished the script though. If you want. let me know, ill link the tutorial. (Dec-16-2020, 02:23 PM)buran Wrote: also what do you think this line data = imp.load_source('data', '', f) is doing?That also I don't know. (Dec-16-2020, 02:23 PM)buran Wrote: on lines 11-14, you create a CSV file, then you completely overwrite it on line 16.No, I create register.csv in the lines 11 - 14. and create another file, data.txt in line 16. Doesn't it? (Dec-16-2020, 02:56 PM)Oshadha Wrote: No, I create register.csv in the lines 11 - 14.Yes, sorry, my error - with these long path names. the imp (now depreciated and replaced with importlib ) is used to import modules using module name. You don't need to use it in simple script like yours. In any case it is not intended to "load" data/csv/txt files. Open the csv/txt file in read mode (i.e. r ). You may decide to use csv module to read it - it will make it more convenient, but not necessary. You can just read the file with e.g. read() or readlines() method.Also, it's better to use with context manager, like on line 11. Use it also when creating data.txt
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Dec-16-2020, 03:12 PM
As a side note - if using csv/txt is not mandatory, you may look into using different format like
JSON or even better - a real detabase like sqlite3 (support for sqlite3, which is file based database comes with python).
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Dec-17-2020, 03:32 AM
(Dec-16-2020, 03:12 PM)buran Wrote: As a side note - if using csv/txt is not mandatory, you may look into using different format like Lets put my script aside.Now, I want to make a system. that stores data about students. I'm storing data in a csv file. I want to know all the commands when working with csv.(I want them clearly pls) And all the commands when working with txt files.(Also clearly) If you can link me these commands then, I can script a new one without watching a tutorial. (So I can understand better!) Then I want to know how to turn .py into .exe. So that people cant edit the script/see the script.
There is a module in the standard library for working with CSV files: https://docs.python.org/3/library/csv.html. You really should familiarise yourself with the standard library docs if you haven't already.
Also, why do you want to stop people reading your script? Who'll be using it anyway? As for stopping edits, can't you just use whatever your OS has for managing permissions? Looks like you're on Windows, so I can't help further with that. |
|