Tuesday 11 March 2014

how to find what all methods an object have in python, when you import that.


>>> import boto

>>> dir(boto)
Out[9]:
['BotoConfigLocations',
 'BucketStorageUri',
 'Config',
 'FileStorageUri',
 'InvalidUriError',
 'NullHandler',
 'UserAgent',
 'Version',
 '__builtins__',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '__path__',
 '__version__',
 '_aws_cache',
 '_get_aws_conn',
 'boto',
 'check_extensions',
 'config',
 'connect_autoscale',
 'connect_cloudformation',
 'connect_cloudfront',
 'connect_cloudwatch',
 'connect_dynamodb',
 'connect_ec2',
 'connect_ec2_endpoint',
 'connect_elb',
 'connect_emr',
 'connect_euca',
 'connect_fps',
 'connect_gs',
 'connect_ia',
 'connect_iam',
 'connect_mturk',
 'connect_rds',
 'connect_route53',
 'connect_s3',
 'connect_sdb',
 'connect_ses',
 'connect_sns',
 'connect_sqs',
 'connect_sts',
 'connect_swf',
 'connect_vpc',
 'connect_walrus',
 'exception',
 'handler',
 'init_logging',
 'log',
 'logging',
 'lookup',
 'os',
 'plugin',
 'pyami',
 're',
 'resultset',
 'set_file_logger',
 'set_stream_logger',
 'storage_uri',
 'storage_uri_for_key',
 'sys',
 'urlparse']


>>> hasattr(boto,"ec2_connect")
 False

>>> hasattr(boto,"connect_ec2")
 True

>> help(boto.connect_ec2)

connect_ec2(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
    :type aws_access_key_id: string
    :param aws_access_key_id: Your AWS Access Key ID
    
    :type aws_secret_access_key: string
    :param aws_secret_access_key: Your AWS Secret Access Key
    
    :rtype: :class:`boto.ec2.connection.EC2Connection`
    :return: A connection to Amazon's EC2
(END)


link:
http://www.diveintopython.net/power_of_introspection/index.html
http://stackoverflow.com/questions/34439/finding-what-methods-an-object-has
http://en.wikipedia.org/wiki/Python_%28programming_language%29

No comments:

Post a Comment