2011-02-14 4 views
-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() 
+0

형식을 지정하십시오 (수정 하겠지만 편집 권한이 없습니다) –

+0

자세한 내용을 입력하십시오. 당신이 궁금한 것이 무엇인지는 분명하지 않습니다. – Ikke

+0

어떤 버전의 파이썬입니까? – wheaties

답변

0

글쎄, 나는 쉼표가 원하는대로하지 않는다고 생각합니다. dev.udn이 문자열 인 경우 인쇄 "foo는"+ dev.udn을 할 수 있지만 dev.udn는 int이며, 그렇지 않으면 당신은, 예를 들어, 그래서 C 스타일 % 표기법을 사용하려면 :

print 'Got new device: %d' % dev.udn 
+3

'print 'foo', 42'는 완벽하게 괜찮아서'foo 42'를 출력합니다. –