Skip to content

Instantly share code, notes, and snippets.

@kcuzner
Created March 8, 2016 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcuzner/061919b5b4b5dddfe91e to your computer and use it in GitHub Desktop.
Save kcuzner/061919b5b4b5dddfe91e to your computer and use it in GitHub Desktop.
Getting a property based on the hostname
#!/usr/bin/env python2
# Demonstration for host to use the hostname to determine which property of the
# Field is "mine"
import socket
from geometry_msgs.msg import Pose2D
from bh_vision.msg import Field
hosts = {'BECKHAM': '1',
'HOWARD': '2'}
def get_pose(field):
hostname = socket.gethostname()
hasProp = 'hasHome' + hosts[hostname]
if getattr(field, hasProp, False):
poseProp = 'home' + hosts[hostname]
return getattr(field, poseProp)
return None
def test():
field = Field()
field.hasHome1 = True
field.home1 = Pose2D(1, 2, 3)
field.hasHome2 = False
print get_pose(field) # this returns either the pose for the current machine or None
if __name__ == '__main__':
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment