How do i use a function sort of like a class, to get access to the functions parameters explicitly without calling the function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do i use a function sort of like a class, to get access to the functions parameters explicitly without calling the function?

# Let's say I have a function that takes a name # parameter so, I want to do something like this: def get(func, name): name = None return func(name) Get = get.name print(Get)

20th May 2018, 5:44 PM
HumbleByNature
HumbleByNature - avatar
9 Answers
+ 1
No, it doesn't. You want to basically predict the future, grab elements from it, and use said elements to do something.
20th May 2018, 6:36 PM
Idriz Pelaj
+ 1
Declare a variable, instantiate it on the use of a function. Otherwise, no.
20th May 2018, 6:12 PM
Idriz Pelaj
+ 1
the class creates objects. I want to explicitly access a functions parameters without calling the function and basically call the function automatically via access to parameter. The functions parameter(s) can act as a pointer to it's own local function/method. Make sense.
20th May 2018, 6:30 PM
HumbleByNature
HumbleByNature - avatar
0
You mean classes? They're defined with the keyword class in python and usually have an __init__ method, think of it like a constructor. It works just the way any ool works.
20th May 2018, 5:55 PM
Idriz Pelaj
0
I think what you're looking for is a class. Sololearn covers the topic in great detail and there are many websites that explain them well. To address your question, this might be one way to do that: class Human(): def __init__(self, name): self.name = name person1 = Human('John') print(person1.name) #Output: John Let me know if I can clear something up :)
20th May 2018, 6:04 PM
Just A Rather Ridiculously Long Username
0
without a class
20th May 2018, 6:07 PM
HumbleByNature
HumbleByNature - avatar
0
Okay, so do you want to find the value of a particular argument passed to the function? Or do you want the names of all parameters a function takes? If you could show us exactly what you're trying to do, perhaps with an example, it would be easier to help.
20th May 2018, 6:12 PM
Just A Rather Ridiculously Long Username
0
You can't do that without storing it somehow.
20th May 2018, 6:25 PM
Idriz Pelaj
- 1
def function(param1, param2): if not param1 and not param2: param1 = None param2 = None else: t = (param1, param2) return t # with or without object variable Func = function print(get.param1) # without calling the # function
20th May 2018, 6:24 PM
HumbleByNature
HumbleByNature - avatar