+ 7
[SOLVED] Python3: return=Boolean conditional=localEnvironmentIsVirtual example?
Can anybody give me an example of a Python3 script that returns a boolean value from a conditional statement testing whether or not the local environment (that the script is running in) is virtual ... ? I was wondering due to having a lot of codes that I'd like to post here on Sololearn... with the majority of those codes not being able to run within SL's virtual environment ... So I'd like to implement code that will throw some sort of exception (and print something) if the conditional returns false.
4 Answers
+ 6
Good one!
+ 5
David Ashton
I found something that works. I forgot about asking this question, lol.
import os, sys
if os.environ['COMPUTERNAME'] == 'CODE-PLAYGROUND':
print('Run on your local machine.')
sys.exit(1)
+ 2
This is above my pay grade, but these might help
https://stackoverflow.com/questions/1871549/JUMP_LINK__&&__python__&&__JUMP_LINK-determine-if-running-inside-virtualenv
https://stackoverflow.com/questions/27691434/python-virtualenv-check-environment
0
Im not sure if you can do that but you could have a variable at the top of your code that you can change to true when you upload it here instead