Q:

How to use a bash variable in python

In bash I'm able to do this  in bashIP=$(wget -qO- ipinfo.io/ip) This captures my public IP and stores it as the variable $IP on my Raspberry Pi.
Now I want to capture this variable in python to make a led connected to GPIO 1 turn on when the $IP is not equal to 82.1x.xxx.xx .
I'm kind of a newbie in python so I need some help, I have very little knowledge in python but very good knowledge in bash. Any help or suggestions will be appreciated.
Thank you in advance.

A:

You should use os.environ dict. Try it out:
>>> import os
>>> os.environ['IP'] 

or 
>>> os.environ.get('IP')

From doc:
os.environ

A mapping object representing the string environment. For example,
  environ['HOME'] is the pathname of your home directory (on some
  platforms), and is equivalent to getenv("HOME") in C.

BONUS GAME
You could grab IP from http response just using pure Python, something like this:
import urllib2
# that's really cool!
IP = urllib2.urlopen("http://ipinfo.io/ip").read().strip()

