Похожие чаты

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 ответов

59 просмотров

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

Ædel- Автор вопроса
𝘞𝘦𝘢𝘳𝘪𝘯𝘨𝘔𝘦𝘥𝘢𝘭 🦋
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)

Ædel
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)

Ædel- Автор вопроса
𝘞𝘦𝘢𝘳𝘪𝘯𝘨𝘔𝘦𝘥𝘢𝘭 🦋
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

Ædel- Автор вопроса
Ædel- Автор вопроса
Ædel- Автор вопроса
Ædel
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

Ædel
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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
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...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
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...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта