Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how to use arguments of classes
#1
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
Quote
#2
Can you give an example code of what you are trying to access?
Quote
#3
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?
Quote
#4
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))
Quote
#5
(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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Using classes? Can I just use classes to structure code? muteboy 5 1,768 Nov-01-2017, 04:20 PM
Last Post: metulburr
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 1,670 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:


Users browsing this thread: 1 Guest(s)