#๐Ÿ”’ not calling variable

114 messages ยท Page 1 of 1 (latest)

vapid jungleBOT
#

@spice pasture

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.

spice pasture
#

what

vocal swan
#

Could it be that you need to call load_dotenv()?

spice pasture
#

it still didnt work

#

๐Ÿ˜ข

vocal swan
#

Does os.getenv('test') work?

spice pasture
#

let me try

#

negative

#

did i forget to install seomthing?

#

with pip

vocal swan
#

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

spice pasture
#

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

vocal swan
#

Try this:

from dotenv import load_dotenv
from pathlib import Path

envfile = Path(".env")
load_dotenv(dotenv_path=envfile)
print(os.getenv("test"))
vocal swan
#

It could be due to cwd

spice pasture
#

so what do i do

#

what can i do to make this code work

#

๐Ÿ˜ข

vocal swan
#

Do you know if os.getcwd() is in the learning folder or in the main one?

spice pasture
#

im not sure

#

but this everything expanded

vocal swan
#

Just run print(os.getwd()) and see if it ends with /learning

spice pasture
#

ok

vocal swan
#

getcwd

#

my bad

spice pasture
#

ye

#

its in learning

vocal swan
#

Okay. So then the relative path would be ../.env

spice pasture
#

oh

#

so its not

#

dotenv?

vocal swan
#
from dotenv import load_dotenv
from pathlib import Path

envfile = Path("../.env")
load_dotenv(dotenv_path=envfile)
print(os.getenv("test"))
spice pasture
#

ok

#

so i guess my question is

#

how come for my friend

vocal swan
#

Maybe it can

spice pasture
#

the og code worked

#

but for me

#

its not

#

oh

#

it still came back as none....

vocal swan
#

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

spice pasture
#

also says os is not defined

#

yeah thank you

#

im new to python

#

so this is all just so zzzz

vocal swan
#

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

spice pasture
#

i think i did

#

python -m venv venv

#

pip install ipykenernel

#

ipykernel

solid osprey
#

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

gusty jacinth
#

Did u save ur .env file?

#

To begin with

#

After u edited it

spice pasture
#

oh

#

i see

#

:D

vocal swan
#

you just had to save? xD

spice pasture
#

lol

#

xd

#

oops

gusty jacinth
#

๐Ÿซก

spice pasture
#

amaeteuer mistake

gusty jacinth
#

Everyones done it

spice pasture
#

thank you all

#

appreciate it

vocal swan
#

Could you solve the rest too?

spice pasture
#

wdym the rest

vocal swan
#

Loading the variable?

#

Could you go back to original code? ๐Ÿ˜›

spice pasture
#

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

vocal swan
#

Awesome

spice pasture
#

@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

vocal swan
#

I'm not really familiar with your IDE, I know Pycharm does that

#

I think it should be a setting for that

vapid jungleBOT
#
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.