Python Forum
Why do i get these errors?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do i get these errors?
#1
Hi I'm just a beginner programmer (13 yr old),
pls help!

So I was half-way through scripting the software, that saves student details in a csv file.
when I want to see the students details I just simply type search {Student name} and some details come related.
(Still need to be coded.)
I need help on,
Solving the errors.
Improving the script.
And how to make the body for this script.(Instead of running on the console, I need to change the appearance)


Heres the script
import csv
import os.path
import time
import imp
import sys

if not os.path.exists("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 ("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 ("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("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.")
The errors!
Error:
D:\My folder\Projects\Programing\Python\Student Data storing app\Main.py:4: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp Traceback (most recent call last): File "D:\My folder\Projects\Programing\Python\Student Data storing app\Main.py", line 47, in <module> pass_check() File "D:\My folder\Projects\Programing\Python\Student Data storing app\Main.py", line 38, in pass_check data = imp.load_source('data', '', f) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\imp.py", line 171, in load_source module = _load(spec) File "<frozen importlib._bootstrap>", line 711, in _load File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 786, in exec_module File "<frozen importlib._bootstrap_external>", line 922, in get_code File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\imp.py", line 152, in get_data self.file = file = open(self.path, 'rb') FileNotFoundError: [Errno 2] No such file or directory: ''
I'm new to these forums, sorry If I didn't do this correctly.
Always happy to learn!
Reply
#2
Please, post the code here on the site, using BBCode tags.
If you get any error, please, post the full traceback you get.
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
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

Reply
#3
(Dec-15-2020, 08:54 AM)buran Wrote: Please, post the code here on the site, using BBCode tags.
If you get any error, please, post the full traceback you get.
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.

Sorry buran,
Im hoping I did it correctly now!
Reply
#4
(Dec-16-2020, 09:38 AM)Oshadha Wrote: Im hoping I did it correctly now!
Yes, now it is OK. In the future, please, don't change content of your post after you have received a reply. This destroy the flow of conversation in the thread.

Now, on the error:
backslash \ has a special meaning when next char is one of several, e.g. n, u, etc. That is called escape sequence. You can find all escape sequences here. That's why you should be careful when use backslash in windows names. In your case the problem is \R
You have 3 options:
  • use raw string, i.e. that is to add r in front of your string, e.g.
    r"D:\My folder\Projects\Programing\Python\Student Data storing app\Register.csv"
  • use forward slash in windows paths
    "D:/My folder/Projects/Programing/Python/Student Data storing app/Register.csv"
  • escape the backslash
    "D:\\My folder\\Projects\\Programing\\Python\\Student Data storing app\\Register.csv"
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

Reply
#5
(Dec-16-2020, 09:53 AM)buran Wrote: Yes, not it is OK. In the future, please, don't change content of your post after you have received a reply. This destroy the flow of conversation in the thread.
Thanks!.
From now on, I will do what you said!
Reply
#6
(Dec-16-2020, 09:53 AM)buran Wrote: Now, on the error:
backslash \ has a special meaning when next char is one of several, e.g. n, u, etc. That is called escape sequence. You can find all escape sequences here. That's why you should be careful when use backslash in windows names. In your case the problem is \R
You have 3 options:
  • use raw string, i.e. that is to add r in front of your string, e.g.
    r"D:\My folder\Projects\Programing\Python\Student Data storing app\Register.csv"

  • use forward slash in windows paths
    "D:/My folder/Projects/Programing/Python/Student Data storing app/Register.csv"

  • escape the backslash
    "D:\My folder\Projects\Programing\Python\Student Data storing app\Register.csv"
I will use option number 1.
I think it will be the easiest!

And thank you again!
Have a nice day!!
Reply
#7
Is there any way of marking a reply as solved!?
Reply
#8
I cant post a new thread.
Pls help!
Reply
#9
(Dec-16-2020, 12:41 PM)Oshadha Wrote: I cant post a new thread.
There is no restriction. What happens when you try to post new thread?
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

Reply
#10
(Dec-16-2020, 01:04 PM)buran Wrote: There is no restriction. What happens when you try to post new thread?
I cant find the new thread/ new post button.
I'm sorry I'm new!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020