Python help , output working on IDE but not console

Hi guys looking for a little help, had been using code academy previously and learned alot, doing it myself im having some issues with my program.

I am using pycharm and my pc has the latest python download installed, testing my program on ide works fine. In browser IDES it works fine, but when i run it on the console it crashes at a specific part, i cant figure out why.

My program is basic username and password creation program, though it would be good to move it into OOP when moving forward.

When you make your password if incorrect it responds correctly and tells you to try again, however when you enter the right combo it just crashes out saving none of the progress.

I think the error is around line 137 however no errors when compiling. There are some adjustments im going to make to it as well but id like to get it working on both. It was only showing a friend my program that i noticed it does not work in console.

Mega link to my code file and my saved file for my usernames and password lists

1 Like

This is going to take a minute to figure out. I found another bug, i created two users with the same password:

['stebar', 'stetes', 'testes']
['Letmein0205!', 'Y2uCDDGi#Ep5', 'Y2uCDDGi#Ep5'] // random generated password with duckduckgo

now testes can’t login. Its impossible. Because of this:

positioncheck2 = passwords.index(passtry)

because .index() will find the first match, which is at index 1, while the user is at index 2

also, os.system('cls') is platform specific.

1 Like

hi there thanks for the reply. Yeah i know my position check wont work if the password matches another user. Gonna fix that later on doing it within the same list.

the one u said i knew about so thats cool , i have a fix im working on for it. Thank you for the info on cls, just though it would make the output nicer, weird tho cause that is something that works in console and not ide lol

tried to steps to reproduce the issue you described:

that seems to work fine? No obvious flaw.

by platform i actually meant operating system. You can clearly see that for my OS its not working.

what do you mean by console? Because that is very broad term.

sorry, im on windows 10. So would be the cmd line console i guess ?

its here it crashes, when a valid entry is entered

Although i have Windows installed, i have nothing setup there (no python, nothing). So that would take me ages.

Lets see if any exceptions occur:

def CreatePass():
    try:
        valid_password = False
        while not valid_password:
            valid_password = True
            # to reset at the start of each loop

            print("**Barraclough Systems****")
            print("\nYou password must contain :")
            print("1 Upper Case Character")
            print("1 Lower Case Character")
            print("1 Number")
            print("1 Special Symbol from the following ! £ $ % & @ # ? ")
            print("Must be between 8 - 16 characters in length\n")
            print("")
            Symbols = ["!", "£", "$", "%", "&", "@", "#","?"]
            # creation of symbols to allow checking
            password = input("Enter a password = ")
            # password will then go through validation checks
            if len(password) < 8 or len(password) > 16:
                print ("\npassword needs to be between 8 and 16 characters")
                valid_password = False

            if not any(char.isupper() for char in password):
                print ("\nPassword needs an upper case character.")
                valid_password = False

            if not any(char.islower() for char in password):
                print ("\nPassword requires a lower case character.")
                valid_password = False

            if not any(char.isdigit() for char in password):
                print ("\nPassword requires a number.")
                valid_password = False

            if not any(char in Symbols for char in password):
                print ("\nPassword requires a special character (! £ $ % & @ # ? ). Please try again\n ")
                valid_password = False
            # If valid the password will be added to the list
            if valid_password:
                passwords.append(password)
                #open the file to save the data 2
                pck_file = open("data.pck", "wb")
                pickle.dump(usernames, pck_file)
                pickle.dump(passwords, pck_file)
                pck_file.close()
                #close the file
                print("\nYour Password Has been Accepted\n")
                print("You will now be redirected to the menu where you can log in")
                time.sleep(4)
                os.system("cls")
            else:
                print('\n\nPlease try again\n\n')
    except:
        print(sys.exc_info()[0])

don’t forgot to import sys. Does this given any output? Try/except allow us to handle exceptions (that is the only thing i added)

if it doesn’t work, you can always comment out everything after this line:

password = input("Enter a password = ")
print('get here')
# comment out the rest of functions

then slowly start uncommenting until you found the line it crashed.

permission error ?

Maybe something with the directory ?

Odd tho with the import sys in there and the except if i remove the except the program just opens and closes

That is a good start. Now we can narrow down on the permission issue:

            try:
                pck_file = open("data.pck", "wb")
                pickle.dump(usernames, pck_file)
                pickle.dump(passwords, pck_file)
                pck_file.close()
                #close the file
            except PermissionError as e:
                print(e)

what does this give? Also, you can now remove the try/catch from earlier. Maybe the file doesn’t exist in your working directory?

Looks to be something with the file then

Good, we have an error code. What would be a next logical step? If i take all the steps all the time, you miss a crucial learning opportunity.

im assuming the directory its set up in i maybe dont have the right permission ? either that is it because directory is not defined ?

i assumes it would default to the same folder as the .py no ?

…or possibly because the file already exits ? and theres not a check for that at that part of the code

What directory? data.pck is a file.

reference words like it can be confusing. What do you mean by it? Have you verified what you expect matches reality?

that is a possibility, good thing to check. the os module (which you already imported) allows to see which files are in the directory. Maybe try this? Your thinking process is heading in the right direction :slight_smile:

sorry i just meant that the file itself, when i set the program to save the file that it would go to the same directory as the .py file i had been using.

using the os module ? something like path ?, im not overly sure how to use those all.

Something like
import os.path path.isfile('data.pck')

but are you in the same directory when you run the program from command line? How could you find out?

is was more thinking something like listdir or getting the current working directory, you can google that :wink:

Well yeah. I use pycharm to click go to directory and i right click the .py file and run in python from there so i dont see how it could be another directory.

assumptions are a dangerous thing. try running both ways (command line and pycharm) and include getcwd:

https://www.tutorialspoint.com/python/os_getcwd.htm

check that you are in the same directory in both scenarios, or should i say: the script runs in the same working directory

yeah, im not good with command line at all. !

tried it with the slashes both ways and got the same error.

SUCK|690x386

You can do that another time, first add getcwd() (see reply previous link) to your program just before you try to open file, then run your program with the command line and the IDE. See if the working directory is the same in both cases.

1 Like

cool a new error …

Checking the ide it says its a shadow name from outer scope. I have no clue what that means

ok so its a class name error.

in pycharm