Getting name of windows computer running python script?

前端 未结 7 1727
耶瑟儿~
耶瑟儿~ 2021-01-30 01:15

I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which c

7条回答
  •  感动是毒
    2021-01-30 01:46

    It turns out there are three options (including the two already answered earlier):

    >>> import platform
    >>> import socket
    >>> import os
    >>> platform.node()
    'DARK-TOWER'
    >>> socket.gethostname()
    'DARK-TOWER'
    >>> os.environ['COMPUTERNAME']
    'DARK-TOWER'
    

提交回复
热议问题