1

I was looking at this Stack Overflow answer and in it the author says for the original poster to check if the PYTHONSTARTUP variable is defined. I looked around and can not find out how to check to see if it is defined.

How do you check to see if the PYTHONSTARTUP variable is defined?

Community
  • 1
  • 1

2 Answers2

1

Windows (cmd.exe):

echo %PYTHONSTARTUP%

Elsewhere (in a shell, e.g. bash):

echo $PYTHONSTARTUP

In Python:

import os
print(os.environ['PYTHONSTARTUP'])
sje397
  • 41,293
  • 8
  • 87
  • 103
  • When I do `echo $PYTHONSTARTUP` a blank line gets printed in bash. Nothing there it seems. Sorry that I posted the name as PYTHONSTART, it is indeed PYTHONSTARTUP. –  Dec 19 '11 at 09:20
  • So you can put `export PYTHONSTARTUP="/blah/blah.py"` in your `.bashrc` file and it should set the variable when you run bash. – sje397 Dec 20 '11 at 12:30
0

I assume it's an environment variable.

import os

if os.getenv("PYTHONSTART"):
    do_something()
Chewie
  • 7,095
  • 5
  • 29
  • 36
  • The name of the var is really `PYTHONSTARTUP` so when I run your code example with `PYTHONSTARTUP` and a `print 'hi'` on the next line, nothing gets printed. Perhaps PYTHONSTARTUP is missing. –  Dec 19 '11 at 09:25