[SOLVED] Python3: return=Boolean conditional=localEnvironmentIsVirtual example? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

15th Sep 2017, 4:02 PM
Fox
Fox - avatar
4 Answers
+ 6
Good one!
29th May 2018, 6:08 AM
David Ashton
David Ashton - avatar
+ 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)
29th May 2018, 12:23 AM
Fox
Fox - avatar
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
15th Sep 2017, 4:46 PM
Enzo
Enzo - avatar