11 odpowiedzi
+ 6
Spammers are a part of life.
Maybe they are just having a bad day.
Don't let them get to you.
You have an interesting idea.
If you must, it is really not too hard to do. The first answer by ChaoticDawg tells you what you need to do.
Here is an example:
https://code.sololearn.com/cbY25zLmF7R9/?ref=app
+ 9
def convert_to_int(func):
def wrap(*args, **kwargs):
return int(func(*args, **kwargs))
return wrap
This decorator function above as;
@convert_to_int
Will convert the return value of any function to an int, similar to int(func(n))
It should be all that you need, depending on your code.
+ 6
Decorators are functions that take a function as input.
We normally don't have such builtin function.
+ 5
Everything is a class. So how about you make a subclass of the main data classes that takes data types and wraps them by making a custom string output?
Also, liking your own question/answer is super lame. Mabey just shouldn't do that. No reason to get mad though, like up or down votes actually do anything.
+ 5
Slick
i really appreciate your answer but not your comment im just saying that there are ppl that randomly gives minus for anything ,and im talking to the mf who gave me a minus , i wasn't talking to you bro
+ 5
(人◕‿◕) 𝕡𝕒𝕚𝕟𝕜𝕚𝕝𝕝𝕖𝕣 (•◡•)
int is a class. By itself it can't be used as a decorator to a function as is, due to the class's implementation. You could, however, extend the class to make a decorator class. That being said, I think that might be overkill and just making a standard function decorator that does what you want will probably be simpler to implement and manage.
+ 4
Hi (人◕‿◕) 𝕡𝕒𝕚𝕟𝕜𝕚𝕝𝕝𝕖𝕣 (•◡•)
how about this . I am creating a new class called ModifiedInt which inherits all the properties of the int Class
Here is my implementation
>>> class ModifiedInt(int):
def __init__(self,number):
self.number = number
>>> a = ModifiedInt(1.0)
>>> a
1
>>> a = ModifiedInt(1)
>>> a
1
>>> a = ModifiedInt(12.3456789)
>>> a
12
I hope my answer helps you
+ 3
hamishhr
my problem here is to use built-in functions as decorators to wrap up other functions for example :
@round
def my_func():
a = 1
b = 2
return a/b
here's the output is supposed to be a rounded number
similar to
round(my_func())
+ 3
(人◕‿◕) 𝕡𝕒𝕚𝕟𝕜𝕚𝕝𝕝𝕖𝕣 (•◡•)
Like Chaotic Dawg said you could that. But that would be just an overkill
+ 3
hamishhr
yes , when i use it as decor it just takes the object not the object's call so basically you have to use your own decorator
+ 3
ChaoticDawg
exactly bro 👍👍
def intt(func):
return int(func())
@intt
it just needs to implement the call among other functionality