api_key = "abc"
def send(self, phone_number, otp):
address = "https://api.url.com/{0}/".format(self.api_key)
return address
for using this function I need to make an instance of the class, and the use it like this:
otpmgr = OTPManager
otpmgr.send(otpmgr , phone_number, otp)
my goal Is that i don't want to pass in the class instance itself, when using the function. how can i do it? is it even possible? because this current code looks a bit weird to me.
You don't have to do this... you just pass self... your function requires only phone_number and otp
thanks, but no it needs api_key as well, which is a variable in the class itself (and not in any of its functions)
You could use an init func in the class: class OTPManager: api_key = "" def __init__(self): self.api_key = "yourapikeyfromfileorenv" def send(self, phone, otp): print(self.api_key) print(phone, opt)
thanks, i tried that. instance.send() still requires three arguments. i called it with instance.send(phone, otp) and it gave me this error TypeError: OTPManager.send() missing 1 required positional argument: 'otp' added self as the first argument and name "self" is not defined
duh i am not able to create a class in programiz, i always have to use the pc. what can be the problem?
You can define a staticmethod instead
I don't know, lol... every compiler is the same 🤷♂
right, thanks.
oh lol! the () yea it works, thank you.
Try the same code I wrote
the screen just stays empty when i click on run. anyways ty, i do prefer vscode obv lol. maybe time to get a new phone
I think it's not related to your mobile phone.
maybe. i have no idea, will prolly ask somebody in-person
Use this if the method doesn't use any instance specific information https://docs.python.org/3/library/functions.html#staticmethod
Обсуждают сегодня