Forum Discussion

andy_12_5042's avatar
andy_12_5042
Icon for Nimbostratus rankNimbostratus
Feb 02, 2011

create a method parameter for protocol type

 

Is there a way I can properly do this below? I am trying to allow the protocol type to be defined in the call itself via a method. However, my lack of Python or in depth programming is killing me with this simple issue. What is the correct way to do this ?

 

 

 

vs_def.protocol = proto + "." + prot_type

 

TypeError: unsupported operand type(s) for +: 'instance' and 'str'

 

3 Replies

  • just to be clear, it should look like this :

     

     

    proto = v.typefactory.create('Common.ProtocolType')

     

    vs_def.protocol = proto.PROTOCOL_TCP

     

  • It would seem I am thinking about this all wrong. So I decided to do this in a better way and just test the paramter string that I use for protocol and based on the comparison I will set it accordingly. So something like this will work fine and I will have each type defined per the icontrol SDK. I am not a big fan of if statements but since python does not appear to have a "case" as in other languages and this is a small amount of comparisons.... it will do.. This gets away from the trying to concatenate a string with a non-string object, which will not work. Anyway it may not be the best way but it seems to work ok so far..

     

     

     

    p_type is a parameter to a web service call

     

     

     

    proto = v.typefactory.create('Common.ProtocolType')

     

     

    if p_type == "tcp":

     

    p= proto.PROTOCOL_TCP

     

     

    vs_def.protocol = p

     

     

     

  • ok yeah that is cleaner way... Awesome thanks for your help!! That saves me from having to do the comparison logic with if statements...

     

     

     

    Andy