#๐ not calling variable
114 messages ยท Page 1 of 1 (latest)
@spice pasture
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.
what
Could it be that you need to call load_dotenv()?
Does os.getenv('test') work?
Strange, no I don't think you should have to install anything. Currently looking at some guide showing this exact code
But there's also an example where it loads the specific file
do i have to restart my computer
and try
cuz im doing this for security
im tryna test
im going to try restarting my computer real quick
Try this:
from dotenv import load_dotenv
from pathlib import Path
envfile = Path(".env")
load_dotenv(dotenv_path=envfile)
print(os.getenv("test"))
It could be due to cwd
Do you know if os.getcwd() is in the learning folder or in the main one?
Just run print(os.getwd()) and see if it ends with /learning
Okay. So then the relative path would be ../.env
from dotenv import load_dotenv
from pathlib import Path
envfile = Path("../.env")
load_dotenv(dotenv_path=envfile)
print(os.getenv("test"))
Maybe it can
I think it's due to directory the code is run from. But I don't know
Let me setup on my side, easier for me to test like that
also says os is not defined
yeah thank you
im new to python
so this is all just so zzzz
Yeah I get you. I'll need a min
Hmm, I tested with something slightly different
But I did pip install dotenv I don't know if you have the same one
And with this code:
import dotenv
print(dotenv.Dotenv("../.env"))
At least I got the right output
on the bottom right of vscode
what does this say
for example im using a venv 3.12.1
if you click it
it will let you change the interpreter
you just had to save? xD
๐ซก
amaeteuer mistake
Everyones done it
Could you solve the rest too?
wdym the rest
it worked with the code you gave me
let me see if i can use the originial code
oh yeah
both works
niceeeee
ok thanks
Awesome
@vocal swan
WAIT
SORRY
ONE MORE QUESTOIN
how come my friend can just swithc between the files and not manually save it
when i have to click the top left and save everytime
is there a way i can change that
so i auto saves like his
I'm not really familiar with your IDE, I know Pycharm does that
I think it should be a setting for that
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.