Похожие чаты

I have a class in python with a function: class OTPManager:

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.

18 ответов

76 просмотров

You don't have to do this... you just pass self... your function requires only phone_number and otp

Крепкий-Самовар Автор вопроса
Тюльпанная Возвышенность
You don't have to do this... you just pass self......

thanks, but no it needs api_key as well, which is a variable in the class itself (and not in any of its functions)

Крепкий Самовар
thanks, but no it needs api_key as well, which is ...

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)

Крепкий-Самовар Автор вопроса
Тюльпанная Возвышенность
You could use an init func in the class: class OT...

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

Тюльпанная Возвышенность
screenshot It works

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

Крепкий-Самовар Автор вопроса
Крепкий Самовар
screenshot this is so weird!😂

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

Крепкий Самовар
screenshot this is so weird!😂

Use this if the method doesn't use any instance specific information https://docs.python.org/3/library/functions.html#staticmethod

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Мелодичный Сырник
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Фетровый Лингвист
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Настойчивый Кварк
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
Льдистая Лужица
2
30500 за редактор? )
Замшевый Алхимик
47
а через ESC-код ?
Виноградная Притча
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Звенящий Циферблат
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Туманный Ларец
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Длинный Минерал
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Тягучая Ракушка
11
Карта сайта