Python Forum

Full Version: how to use arguments of classes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I'm new to python
I am writing a code and i imported a module that has many classes and functions
I wanted to know how can i access to arguments in those classes/functions Or just i can access to name of classes and functions in my code not arguments that have been defined in functions ?
I would be grateful if someone clarify me on this
Can you give an example code of what you are trying to access?
for example:
class cat:
            def __init__(self,name):
              self.name = name
              self.trick = []
            def add_trick(self,trick):
               self.trick.append(trick)
             
now i imported cat class in my code
i want to know can i use trick argument in my code Or i just can access to cat class and add_trick function
and no access to arguments inside of class/function?
first of all you can and should read the docs.
you can use dir() function to get and print all available classes, functions, etc.
also for more detailed info - you can use help() function

e.g. for third-party requests module, but you can use the same for any module

import requests
 
print(dir(requests))
print(help(requests.Session))
(Nov-03-2019, 09:11 AM)ati68 Wrote: [ -> ]for example:
class cat:
            def __init__(self,name):
              self.name = name
              self.trick = []
            def add_trick(self,trick):
               self.trick.append(trick)
             
now i imported cat class in my code
i want to know can i use trick argument in my code Or i just can access to cat class and add_trick function
and no access to arguments inside of class/function?

def my_func():
    kisa = cat('Murzik')
    kisa.add_trick('jumping')
    kisa.add_trick('running')

    for current_trick in kisa.trick:
       print(current_trick)