Тёмный

How to use environment variables in a Python script 

Gavin Wiener - Funnel and Automation Operator
Просмотров 14 тыс.
50% 1

💡 Join 150+ others learning to use automation to grow their own businesses, or becoming automation freelancers 👉 gavinwiener.co...

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 36   
@gavinwiener
@gavinwiener 3 года назад
💡 Get weekly tips on how to SAVE TIME and GROW YOUR BUSINESS using automation 👉bit.ly/3jOjzva
@tripod_1545
@tripod_1545 3 года назад
I have literally been trying to figure out how to export multiple environment variables without having to type them one by one in the terminal and you are the only person that has actually giving me the answer. Thank you so much!!!
@gavinwiener
@gavinwiener 3 года назад
Makes me so happy to hear! Let me know if there are any other topics that you haven't found good explanations/examples for.
@jonahkollenberg1060
@jonahkollenberg1060 Год назад
Absolute legend. Thanks so much, boet
@gavinwiener
@gavinwiener Год назад
My pleasure, glad it helped
@CaptainBravo87
@CaptainBravo87 Год назад
Great video!
@gavinwiener
@gavinwiener Год назад
My pleasure. Don't hesitate to let me know if you wany any other videos that would help you
@MLDawn
@MLDawn 2 года назад
Lovely man! Really great video!
@gavinwiener
@gavinwiener 2 года назад
Really appreciate the support. What inspires me to make more!
@bls512
@bls512 2 года назад
Thank you so much for this video! This is packed with helpful approaches and key concepts that never get addressed in many pricey tutorials.
@gavinwiener
@gavinwiener 2 года назад
My pleasure! Just helping where I can
@ozair100awesome
@ozair100awesome 3 года назад
Very concise and useful video ! thank you
@gavinwiener
@gavinwiener 3 года назад
Appreciate the kind words! Any other topics you'd like me to cover?
@preachit7446
@preachit7446 Год назад
Very nice. Keep up the good work. subbed.
@gavinwiener
@gavinwiener Год назад
Appreciate the support. Glad it helped!
@ccc44448
@ccc44448 3 года назад
This is so useful and quality content, thanks !
@gavinwiener
@gavinwiener 3 года назад
Really appreciate the comment. Anything else in the Python world you'd find a video helpful on?
@WokeSoros
@WokeSoros 2 года назад
You can also unset the variable in the deactivate call of activate. Then it only exists while the environment does.
@gavinwiener
@gavinwiener 2 года назад
Thanks for sharing! Hadn't actually thought of that
@ahmedalhallag3338
@ahmedalhallag3338 Год назад
What keyboard are you using :D
@gavinwiener
@gavinwiener Год назад
Haha literally just the built-in keyword of my Dell laptop
@beatboss9275
@beatboss9275 3 года назад
export isn't working in windows. can you tell me the commands to set and get environment variables.
@gavinwiener
@gavinwiener 3 года назад
Hi Beat Boss. I think I mentioned in the video that the commands I was using will only work on Linux and you'd need to check the ones for Windows. www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-windows-command-line-and-registry/ - This tutorial looks pretty good, but I don't know the Windows world very well.
@quartz2844
@quartz2844 3 года назад
Hey, thanks this really helped me out. Just curious, if we use git, wouldn't be people able to see the venv/bin/activate file and therefore, the variables inside?
@gavinwiener
@gavinwiener 3 года назад
Hi! (I need to sort out these comment notifications). You actually raise a very important point. You want to always exclude/ignore the `env` or `venv` folder from Git in y our `.gitignore`. Like you said, security wise, but also otherwise it makes your Git repository unnecessary big.
@timurtimaev8808
@timurtimaev8808 2 года назад
At last someone explained how to work with env vars in venv. BTW, can you please tell where are these variables are stored? If I'm exporting in venv or if I'm exporting outside venv in a normal bash. Also is there a way to save variable in the activate file with our browsing it with nano? like some sort of persistent export command inside venv?
@gavinwiener
@gavinwiener 2 года назад
Appreciate the question Timur. LOCATING ENV VARS So when you create a virtual environment, it shouldn't be pulling in any outside environment variables. That's the idea of a virtual environment, it's an isolated world. But, in general environment variables are pulled from many different files. I don't know Windows very well but in Linux, this answers it well... askubuntu.com/a/164590 CREATING PERSISTENT ENV VARS You CAN save the variables in the activate file. So we're obviously used to activating the virtual environment by doing something like... "source env/bin/activate" (on Linux if your virtual environment folder is called "env"). But, like you said, activate is just a file. So if you open it using nano, `nano env/bin/activate`... Then you can add any extra commands to do (because it's essentially just a script of terminal commands). E.g. you want to add a variable called "API_KEY". Then at the end of the activate file you'd add... `export API_KEY="123abc"` And whenever you activate the virtual environment, API_KEY will be an available env var
@timurtimaev8808
@timurtimaev8808 2 года назад
@@gavinwiener thank you very much for the detailed explanation!
@gavinwiener
@gavinwiener 2 года назад
@@timurtimaev8808 happy to help. I'm curious, are you learning some more coding just for yourself, or is it work related?
@timurtimaev8808
@timurtimaev8808 2 года назад
@@gavinwiener it's both. I'm still learning and I try to implement my knowledge immediately in my programming-unrelated job.
@user-fn3fg6qg4g
@user-fn3fg6qg4g 3 года назад
do you know why it doesn't show when we saw environment variable in window?
@gavinwiener
@gavinwiener 3 года назад
Hi :) Thanks for the question. I'm not quite understanding the question, could you post it again in a slightly different way?
@aashisahu6232
@aashisahu6232 2 года назад
He was saying that when we check environment variables directly from system settings (not from the script)then why it is not showing there.
@gavinwiener
@gavinwiener 2 года назад
@@aashisahu6232 I'm not actually sure to be honest, could be a Windows specific thing. And environment variables are pulled from multiple places as well.
@kicknotes
@kicknotes 11 месяцев назад
I don't trust anyone who codes in light mode...
@gavinwiener
@gavinwiener 11 месяцев назад
You shouldn't, we're the worst! ;)
Далее
The Complete Guide to Python Virtual Environments!
15:52
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Просмотров 3,8 млн
Linux for Programmers #7 | Environment Variables
12:31
Why You Shouldn't Use the Global Keyword in Python
17:59
Python Logging - Tutorial
15:02
Просмотров 159 тыс.
Load Environment Variables From .env Files in Python
10:18
Python UUID - Explanation and UUID generation
18:07
Просмотров 14 тыс.