-2
가능한 중복 : 다음 코드를 확인하기 위해 인쇄 명령과 문을 넣어해야하는 경우
Why am I not getting any output?인쇄 문
이 어떻게 그것을 삽입 할에 설명해주십시오? 아래 코드에서 예제를 제공함으로써 저에게 맞습니까?
service = ('u', 'urn:schemas-upnp-org:service:SwitchPower:1')
binary_light_type = 'urn:schemas-upnp-org:device:BinaryLight:1'
def on_new_device(dev):
""" Callback triggered when a new device is found.
"""
print 'Got new device:', dev.udn
print "Type 'list' to see the whole list"
if not dev:
return
def get_switch_service(device):
return device.services[service[1]]
def create_control_point():
""" Creates the control point and binds callbacks to device events.
"""
c = ControlPoint()
c.subscribe('new_device_event', on_new_device)
c.subscribe('removed_device_event', on_removed_device)
return c
def main():
""" Main loop iteration receiving input commands.
"""
c = create_control_point()
c.start()
run_async_function(_handle_cmds, (c,))
reactor.add_after_stop_func(c.stop)
reactor.main()
def _exit(c):
""" Stops the _handle_cmds loop
"""
global running_handle_cmds
running_handle_cmds = False
def _search(c):
""" Start searching for devices of type upnp:rootdevice and repeat
search every 600 seconds (UPnP default)
"""
c.start_search(600, 'upnp:rootdevice')
def _get_status(c):
""" Gets the binary light status and print if it's on or off.
"""
try:
service = get_switch_service(c.current_server)
status_response = service.GetStatus()
if status_response['ResultStatus'] == '1':
print 'Binary light status is on'
else:
print 'Binary light status is off'
except Exception, e:
if not hasattr(c, 'current_server') or not c.current_server:
print 'BinaryLight device not set.Please use set_light <n>'
else:
print 'Error in get_status():', e
def _get_target(c):
""" Gets the binary light target and print if it's on or off.
"""
try:
service = get_switch_service(c.current_server)
status_response = service.GetTarget()
if status_response['RetTargetValue'] == '1':
print 'Binary light target is on'
else:
print 'Binary light target is off'
except Exception, e:
if not hasattr(c, 'current_server') or not c.current_server:
print 'BinaryLight device not set.Please use set_light <n>'
else:
print 'Error in get_target():', e
def _stop(c):
""" Stop searching
"""
c.stop_search()
def _list_devices(c):
""" Lists the devices that are in network.
"""
k = 0
for d in c.get_devices().values():
print 'Device no.:', k
print 'UDN:', d.udn
print 'Name:', d.friendly_name
print 'Device type:', d.device_type
print 'Services:', d.services.keys() # Only print services name
print 'Embedded devices:', [dev.friendly_name for dev in \
d.devices.values()] # Only print embedded devices names
print
k += 1
if __name__ == '__main__':
main()
형식을 지정하십시오 (수정 하겠지만 편집 권한이 없습니다) –
자세한 내용을 입력하십시오. 당신이 궁금한 것이 무엇인지는 분명하지 않습니다. – Ikke
어떤 버전의 파이썬입니까? – wheaties