开发者

Python Virtualbox API

http://enomalism.com/api/pyvb/

here we have def _init_(self,**kw):

what parameter(s) sho开发者_Python百科uld be passed when we create an instance for pyvb.vm.vbVM ???


What you are seeing is "keyword arguments". You can call the constructor with a dictionary or named arguments. Here is an example of using keyword arguments:

class MyClass(object):
   def __init__(self,**kwargs):
       if 'val' in kwargs:
           self.__value = kwargs['val'];
       elif 'value' in kwargs:
           self.__value = kwargs['value'];
       else:
           raise ValueError("Requires parameter 'val' or 'value'.");
   def getValue(self):
       return self.__value;

# ...

def main(argv=None):
    # ...
    instance1 = MyClass(val=5);
    x = instance1.getValue(); # value is 5

    instance2 = MyClass(value=6);
    y = instance2.getValue(); # value is 6

    valuedict = {'val':10};
    instance3 = MyClass(**valuedict);
    z = instance3.getValue(); # value is 10

Keyword arguments are nice because they can make your functions and constructors very flexible, and -- as can be seen from the last instantiation case -- it becomes possible to construct the object from a configuration dictionary. The main downside to keyword arguments is that, because it is so flexible, it may not be obvious what the options are. You can try executing "pydoc pyvb.vm" or, as has been pointed out, you can take a look at the source code, which shows the supported attributes.


Looks like you want to pass in an array of configuration items. See the source code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜