Похожие чаты

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

19 просмотров

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

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

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

а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
using next image component with s3 image: "url" parameter is valid but upstream response is invalid code: <Image fill src={s...
Fasil
3
Эх кто-то пришел и весь праздник испортил :( You need complex FBX scene importing setup to change things on import? good luck with that. You need navigation and pathfinding? g...
Serg Gini
5
Friends, how can I find my Wazirx wallet address?
Silm Silm
31
Всем привет! Подскажите. Я написал приложение на Delphi 10.2 Tokyo под Windows 10. И передо мной стал вопрос о том чтобы сделать это приложение кроссплатформенным (под Linux и...
Дмитрий Завгородний
24
Какого хера? /Sources/App/Modules/User/Models/UserLinkApple.swift:21:20: warning: stored property '_id' of 'Sendable'-conforming class 'UserLinkApple' is mutable @ID(...
Alexander Sherbakov
14
My 7 year old daughter recognizes the Bitcoin symbol and knows it's currency. What are the top ,3-5 most basic important concepts to convey to a kid about BCH? I started with ...
Big Hair
24
How many Cashfusion server now?
Crypto life
22
But I'm wondering how exactly we can increase our chances of winning. Do you think it's just a matter of luck, or are there specific actions we need to take to qualify?
Luqman Ayman
12
Кто знает локации, где можно машину красиво отфоткать?
Lalalashechki Lalala
23
Карта сайта