New to Python, haven't programed in 30 year. Code will not run on a new version of Python

When I run this code, the program goes to complete; but nothing has happened. I have no idea what is the problem, suggestions welcome.
New version is Python 3.11.0, Pycharm is 2022.2.4, Old version was 3.7.?? for a 32bit system. This code ran on an older version of Python on an old 32bit laptop.

pwd = input('What is the master password? ')

def view():
    with open('passwords.txt', 'r') as f:
        for line in f.readlines():
            data = line.rstrip()
            user, passw = data.split('|')
            print('Usr:', user, "| Password:", passw)


def add():
    name = input('Account Nmae')
    pwd = input('Password')

    with open('passwords.txt', 'a' ) as f:
        f.write(name + "|" +pwd +"\n")

while True:
    mode = input('Would you like to adda new password or view existing passwords?, Enter add or view or Q to quit).lower()
   if mode == "q:":
        break

    if mode == "view":
        view()

    elif mode == "add":
        add()

else:
    print("Not a valid code"):
        continue

C:\Users\User1\Scripts\python.exe C:\Users\User1\PycharmProjects\pythonProject\Pwdmanager\main.py

Process finished with exit code 0

This line will throw a Syntax Error because it’s missing a single quote '.

File "<string>", line 21
    mode = input('Would you like to adda new password or view existing passwords?, Enter add or view or Q to quit).lower()
                                                                                                                         ^
SyntaxError: EOL while scanning string literal

Yes thank you, I was missing a quit, however adding the quote in did not change the result. The program stills completes with a 0 error code. It seems to be skipping all the code, the opening input request id not being executed.

There is an indentation error here if mode == "q":.

The points that @abdnafees has raised indicate that you’re not running the same code that you posted, and possibly not the same code that you think you are running. You could do some good old-fashioned printf-style debugging by adding some prints or intentional exceptions to your code to make sure that you’re definitely running what you think you are, and report back with a direct copy of the code that you ran if you’re still having issues.

1 Like

You are correct, when I brought the code over from the old laptop the there were differences and I tried to catch them all. I had placed a print(‘Hello’) at the start “before the pwd = input” and it never got acted on.

Thank you, fixed the indentation, however it made no difference. Indentation error would have given an error code other than 0.

Exactly, so I remain unconvinced that you’re running the code you think you’re running :slight_smile:

Make sure your changes are saved, double check the file path, look at the file in a third program (not Python, not your IDE, maybe just type), and try again.

You could also try to reduce the whole thing down to just

print('yes, this is it')
1 / 0

in a new file. If that doesn’t print yes, this is it and then a ZeroDivisionError traceback with a non-0 exit code, then we need to figure out whether the python.exe you’re using is actually what it should be; try C:\Users\User1\Scripts\python.exe -V, which should give you information about which version of Python is running, and C:\Users\User1\Scripts\python.exe -c "print('hi')" which should just print hi.

1 Like

Ok, thanks for the pointer. It seems Windows fire wall is blocking some features of Pycharm Community Edition 2022.2.4.

pydev debugger: CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)
pydev debugger: The debugger may still function, but it will work slower and may miss breakpoints.
pydev debugger: Related bug: http://bugs.python.org/issue1666807
-------------------------------------------------------------------------------
Connected to pydev debugger (build 222.4459.20)
pydev debugger: Unable to find real location for: <frozen codecs>

Do not use a debugger when you are just starting with Python. Use just the Python interpreter directly from your Windows command line (Power Shell or cmd.exe). Test what Zachary suggested and/or possibly:

  1. Try to call the interpreter without parameters to start an interactive session (REPL). Depending on the way Python was installed on Windows the command to call it can be one or more of:
    • py
    • python3
    • python
  2. Try to execute few python statements in the interactive mode. For example: print('hello')
  3. Quit the interactive interpreter: Ctrl+Z (in Windows)
  4. After that try to run your script: python3 main.py
    • Intead of python3 use the command which worked in the step 1.
    • Do not forget to add the path to your main.py file name if you are not in its directory.