[Python-de] hostname aus os.environ

Max Brauer max.brauer at inqbus.de
Mo Mär 18 13:23:51 CET 2013


Hallo Andreas,

Am 18.03.2013 13:10, schrieb Andreas Röhler:
> I.Ü., das funktioniert hier auch
>
> os.environ.get('HOSTNAME')
>
> Kann jemand das Verhältnis zu
>
> os.environ['HOSTNAME']
>
> erklären? 

os.environ ist ein Dictionary. Bei einem Dictionary existiert auch die
Möglichkeit, mit "get" auf die Values zuzugreifen:

Python 2.7.3 (default, Jan  2 2013, 13:56:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = {'bar': 'batz'}
>>> foo['bar']
'batz'
>>> foo.get('bar')
'batz'

Liebe Grüße,

Max


Mehr Informationen über die Mailingliste python-de