#๐Ÿ”’ Quite new to python, tried to follow a tutorial but ended up hitting a roadblock.

36 messages ยท Page 1 of 1 (latest)

lunar tulip
#

I was following a tutorial on creating a password manager (link: https://youtu.be/DLn3jOsNRVE?si=kcyynhvXcKFQhsSD&t=4708). In the video, after he quitted the program, a txt file was created. But when I tried to do as he did, there was no txt file created. I already checked multiple times and I don't really notice any difference between our code so help would be much appreciated. I've spent nearly an hour trying to figure this thing alone ๐Ÿ˜ญ

Welcome back to another video! In this video, I will be showing 5 mini python projects for beginners.
I'll be showing you how I would create a template from scratch. Using this template, you can keep building and practicing your programming skills.

๐Ÿ’ป AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify in...

โ–ถ Play video
silver galeBOT
#

@lunar tulip

Python help channel opened

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.

lunar tulip
#
master_pwd = input("What is the master password? ")

def view():
    pass

def add():
    name = input("Account Name: ")
    pwd = input("Password: ")

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

while True:
    mode = input(
        "Would you like to add a new password or view existing ones (view, add), press q to quit:").lower()
    if mode == "q":
        break

    if mode == "view":
        view()
    elif mode == "add":
        add()
    else:
        print("Invalid mode.")
        continue
onyx delta
#

my first thought is that youre assuming your code is running in some place, but its actually running in a different place. do you get any error messages when running your code? if not, your file is most likely being created and you just havent realised where

lunar tulip
#

doesnt seem to be any error mesasges

onyx delta
#

ok, then your file is probably created. can you import os and print out os.getcwd() somewhere?

lunar tulip
#

sorry i dont understand

onyx delta
#
import os
print(os.getcwd())

add these lines somewhere near the top of your script

lunar tulip
#

whats import os

#

oh

#

ok

onyx delta
#

os is just a builtin library in this case.

lunar tulip
#

do i just run it after adding it to the top of my code?

onyx delta
#

(getcwd tells you the current working directory of your python script)

#

yeah, and check output

#

it should display a full path to the folder where the code is running from. (aka its "working directory")

lunar tulip
#

im not noticing anything different

#

i put it on top like this right?

onyx delta
#

it displayed that extra line in the output. see the folder C users patrick evan?

#

can you open that folder, see if your password file is there

lunar tulip
#

ohhhhhhhhh

#

thank you so much bro

#

ive been malding over this so much

#

lol

onyx delta
#

np. so couple of things to keep in mind: if you want the file to be created in a specific folder, use full paths, not just a file name

#

second: remember, all code runs from some "working" directory. things will default to being created there if you dont give full paths

#

in this case, the open command accepts full paths. so with open(r"C:/full/path/to/passwords.txt"....

#

note the little "r" i wrote at the start before the string. that allows you to use backslashes without issues as well, but ive gotten used to writing forward slashes now

#

python can handle both iirc

lunar tulip
#

thanks for the help and tips bro

#

very helpful

#

๐Ÿ™

onyx delta
#

glad to help!

wide smelt
silver galeBOT
#
Python help channel closed

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.