Python Forum
how to use arguments of classes
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
Reply
#2
Can you give an example code of what you are trying to access?
Reply
#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?
Reply
#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))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#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)
Reply


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

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020