0

I'm new to python and i'm trying to make a password manager. the problem is that my program works fine when i run it through IDLE or Pycharm but it stops running when i run it directly from windows when it reaches the line where I import the file where i store the password.

import time

user = raw_input("Username: ")
pw = raw_input("Password: ")
if user == "PrOoOg" and pw == "aka443":
    def add_acc_func(acc, user, pw):
        database.write("\nAccount: ")
        database.write(acc)
        database.write("    Username: ")
        database.write(user)
        database.write("    Password: ")
        database.write(pw)
        database.close()


    def print_database_func():
        for lines in database.readlines():
            print lines.strip('\n')
        database.close()

    user_input = raw_input('Press "A" to add a new account\nPress "M" to modify and existing account\n'
                            'Press "D" to delete and existing account\nPress "S" to show all accounts and passwords\n')
    user_choice = user_input.lower()
    if user_choice == "a":
        database = open("source.txt", "a") #Everything worked fine when i deleted this line
        acc_to_add = raw_input("Write the name of the site or service: ").lower()
        acc_to_add_user = raw_input("Write the username or email you want to set for that account: ")
        acc_to_add_pw = raw_input("Write the password you want to set to that account: ")
        add_acc_func(acc_to_add, acc_to_add_user, acc_to_add_pw)
        print "Account added"


    if user_choice == "s":
        database = open("source.txt", "r") #Everything worked fine when i deleted this line
        print_database_func()

    raw_input("Press Enter to quit")
else:
    print ("Wrong username or password")
    time.sleep(3)

I tried to delete the lines where I import the text file and it worked. i don't know why the code can't open the file when opened from windows and can open it when opened from IDLE or Pycharm

6
  • Is this all of the code? Do you get any error messages, or does it just not write to the file? Commented Apr 8, 2016 at 21:57
  • What error does it give. I don't know specifically about IDLE - but it could be to do with the current working directory being different when you use the IDE. Commented Apr 8, 2016 at 21:58
  • yes this is all the code, and it works fine with both IDLE and Pycharm. it's just crashes when i run it from windows (rightclick ==> open with ==> python.exe) it prints an error message but i can't read what it says since the program stops running immediatly after the error message. Commented Apr 8, 2016 at 22:08
  • 1
    run it from a command line Commented Apr 8, 2016 at 22:16
  • how can I run it from a command line ? Commented Apr 8, 2016 at 22:34

1 Answer 1

0

"it's just crashes when i run it from windows (rightclick ==> open with ==> python.exe)"

When you do this the working directory is C:\Windows\system32. Most likely you don't have write permissions to this directory. When running the script using the other methods the working directory is most likely the one containing the script. You need to change to a directory which you have write permissions for. Here is an example to use the current user's Documents folder:

import os dir = os.path.expanduser('~/Documents') os.chdir(dir)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.