#🔒 Python automatically gets closed after being opened by hand.
130 messages · Page 1 of 1 (latest)
@wicked locust
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
that's normal behavior
it's not python that's closing; it's the cmd.exe (or powershell.exe) window that it's running in
well python is "closing", in the sense that the python process exits. But that's what you'd want.
it works on win10 but not on win11 yeah thats reasonable
no? how?
there might be a way to tell Windows to not do that. But if it were me, I'd just not start it by clicking an icon.
how am I supposed to run it then?
unless your python program is a server that you intend to run forever, it is likely doing some work, and then exiting when that work is finished.
when I run it through cmd, that doesn’t happen.
that's what I'd do
you did read the description, right?
I honestly don't know what "multiple inputs" means
oh, so it's interactive.
I don't think that's relevant though
yes
what's relevant is: do you want the program to run forever, or not?
I mean how am I supposed to make it into a console application then?
it is already a console application 🙂
yes, unless the user wants it closed tho
ok, does your program have a "while True" or similar in it?
well if it closes instantly and I need to open it through cmd there is no reason to call it that
yep
multiple
that's the accepted terminology
can you post the code? Maybe the real problem is that it's exiting unexpectedly
and since the window goes away, you can't read any error message that it might have printed
here is the full code:
i can run it through VS code without any compiling errors
and it can be ran on windows 10
I am still waiting to see the code
i do have one, I just cant reach it en
rn
well wait until you can, then re-ask the question 🤷
yhe code was done on my computer
import sqlite3
con = sqlite3.connect("password_manager.db")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS informations (
title text,
username text,
password text
)""")
cur.execute("""CREATE TABLE IF NOT EXISTS masterpassword (
masterpassword text
)""")
result = cur.execute("""SELECT masterpassword FROM masterpassword""")
apass = ""
setpass = result.fetchone()
if setpass:
print("A Password Already Exists")
while True:
print("Please Enter Your Password.")
apass = input()
if apass == setpass[0]:
print("Password Is Correct.")
break
else:
print("Incorrect Input.")
else:
print("You haven't Set A Masterpassword Yet. Select A New Password:")
while True:
newpass = input()
if len(newpass) < 7:
print("Your Password Must Be At Least 8 Characters Long.")
else:
print("Successfully set your new password.")
break
cur.execute("INSERT INTO masterpassword VALUES (?)", [newpass])
while True:
a = 0
print("--------------------------------------------------------")
print("What would you like to do?")
print("1)Browse through Informations.")
print("2)Add Information.")
print("3)Close App")
choice = str(input())
if choice == "1":
title = cur.execute("""SELECT title FROM informations""").fetchall()
username = cur.execute("""SELECT username FROM informations""").fetchall()
password = cur.execute("""SELECT password FROM informations""").fetchall()
if title:
for i in title:
print("---------------------------")
print(title[a][0])
print(username[a][0])
print(password[a][0])
a += 1
print("---------------------------")
else:
print("--------------------------------------------------------")
print("""
_ _ _
| | | | | |
| | | | | |
|| || ||
() () ()
""")
print("You Have NO logged account information.")
elif choice == "2":
print("What is the account branded? e.g. Youtube Account/Twitter Account")
title = input()
print("What is the account username?")
username = input()
print("What is the account password?")
password = input()
cur.execute("""INSERT INTO informations VALUES (?, ?, ?)""", (title, username, password))
con.commit()
elif choice == "3":
break
else:
print("Invalid Option.Try Again.")
con.commit()
con.close()
Hey @wicked locust!
It looks like you are trying to paste code into this channel.
You seem to be using the wrong symbols to indicate where the code block should start. The correct symbols would be ```, not """.
Here is an example of how it should look:
```
Hello, world!
```
This will result in the following:
Hello, world!```
You can **edit your original message** to correct your code block.
that should be OK. Gimme a few while I look at it
I can't prove it, but I suspect your problem is that something in your loop has raised an exception.
import sqlite3
con = sqlite3.connect("password_manager.db")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS informations (
title text,
username text,
password text
)""")
cur.execute("""CREATE TABLE IF NOT EXISTS masterpassword (
masterpassword text
)""")
result = cur.execute("""SELECT masterpassword FROM masterpassword""")
apass = ""
setpass = result.fetchone()
if setpass:
print("A Password Already Exists")
while True:
print("Please Enter Your Password.")
apass = input()
if apass == setpass[0]:
print("Password Is Correct.")
break
else:
print("Incorrect Input.")
else:
print("You haven't Set A Masterpassword Yet. Select A New Password:")
while True:
newpass = input()
if len(newpass) < 7:
print("Your Password Must Be At Least 8 Characters Long.")
else:
print("Successfully set your new password.")
break
cur.execute("INSERT INTO masterpassword VALUES (?)", [newpass])
while True:
a = 0
print("--------------------------------------------------------")
print("What would you like to do?")
print("1)Browse through Informations.")
print("2)Add Information.")
print("3)Close App")
choice = str(input())
if choice == "1":
title = cur.execute("""SELECT title FROM informations""").fetchall()
username = cur.execute("""SELECT username FROM informations""").fetchall()
password = cur.execute("""SELECT password FROM informations""").fetchall()
if title:
for i in title:
print("---------------------------")
print(title[a][0])
print(username[a][0])
print(password[a][0])
a += 1
print("---------------------------")
else:
print("--------------------------------------------------------")
print("""
_ _ _
| | | | | |
| | | | | |
|_| |_| |_|
(_) (_) (_)
""")
print("You Have NO logged account information.")
elif choice == "2":
print("What is the account branded? e.g. Youtube Account/Twitter Account")
title = input()
print("What is the account username?")
username = input()
print("What is the account password?")
password = input()
cur.execute("""INSERT INTO informations VALUES (?, ?, ?)""", (title, username, password))
con.commit()
elif choice == "3":
break
else:
print("Invalid Option.Try Again.")
con.commit()
con.close()
Since you don't catch exceptions, that will break the loop and exit the program, and that will close the window.
uhm why does it work on windows10 tho?
linux or mac?
linux on a mac?
just tried it locally and it works (well, at the very least it doesn't close instantly)
oh alright
I use "linux on a mac" occasionally if I'm too lazy to deploy my code and run it on Linux
are you using win10 or 11?
linux but i doubt it matters
well it might.
Perhaps there's something in there that, on Windows 11, causes an exception.
well it worjs on win10 but not on 11 ðŸ˜
i had a friend try it too
On Windows its what way you run it
@wicked locust do this on Windows 11: start a command window, then at the prompt, type py -3 c:/users/path/to/this/program.py and see what happens
but when I convert it to exe it doesnt work on work on win10 too 😦
if you're lucky, it'll die with an exception message, and then we can figure out what to do from that.
what do you mean by "convert it to exe"?
oh.
I've never actually gotten pyinstaller to work, and I strongly suspect that it adds a lot of complexity
I wouldn't use it if I didn't absolutely have to
but else your code is litteraly free for everyone to grab thats why I convert to exe
mostly my friends do it and brag on me so thats why I do it
🤷
Unfortunately that's the same with an exe
doesnt really matter
up to you -- bragging rights with your friends, or simple reliable code.
they can be converted back to py?
yh makes sense
An exe can be reverse engineered to get the source code
Especially with using pyinstaller
I'd run the executable in a cmd window
yeah when I do that it works dine
fine
it just opens like an application
like it is intended
Where's the problem?
when I open it by double clicking the terminal opens and closes
and the application sort of dies
screen record it
well thats not really possible
well my laptop is dead and I am going to sleep in a little while
but I do have the code
and the file
oh ok
well when you have the time, that's what I do
Screen record it and see what's happening
I'm also going to sleep so I can't run it rn
so would you be up in about 8 hours?
i mean I would probably take longer too
lets say 9-10 hours
I would, but I have an extremely tough day tomorrow so I won't be around to help much, sorry
But other people may be able to
i am sure other people can help, thanks tho
will the channel be closed?
by tomorrow?
uhhhhh no clue, you'll have to ask someone else on that
you can always open a new one with a link to this
Does the problem only happen when you turn your file to exe?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.