Open bleudev opened 2 months ago
Subtraction
s = UStr("Hello 3")
s - "3" # Hello
s - UStr("3") # Hello
s - 3 # Hello
s2 = UStr("Hello, my name is banana")
s2 - ["Hello", "banana"] # my name is
s2 - UList(["Hello", "banana"]) # my name is
Comparison by length
UStr("dddd") > UStr("d") # True
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Good idea, i wanted to do that. And override all methods with changes
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Good idea, i wanted to do that. And override all methods with changes
Why didn't you do that for UDict?
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Good idea, i wanted to do that. And override all methods with changes
But If you want to overwrite all default functions, why even bother making it a string subclass? I mean, as far as I know, that approach worked for UDict, as @n0n1m mentioned.
By the way, I have an idea for a function.
UStr.merge()
will merge several symbols or strings into one, while stripping or enlarging them to a specified length to easily create progress bars.
There will be an additional class UMergeStr that inherits from UStr, and it will be used to create strings for the merge function.
It will work something like this:
new = UStr.merge([
UMergeStr("#", 0.25),
UMergeStr(" ", 0.75)
], target_length=10)
# "### "
new = UStr.merge([
UMergeStr("-=", percentage),
UMergeStr("•", 1), # if the second argument of UMergeStr is an integer that is equal or larger than 1, it will instead be interpreted as a set amount of characters instead of a percentage like above
UMergeStr(" ", 1-percentage)
], target_length=15)
# percentage == 0.5:
# "-=-=-=-• "
# percentage == 0.0:
# "• "
# percentage == 0.8:
# "-=-=-=-=-=-=• "
I hope you get my point.
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Good idea, i wanted to do that. And override all methods with changes
But If you want to overwrite all default functions, why even bother making it a string subclass? I mean, as far as I know, that approach worked for UDict, as @n0n1m mentioned.
Does he overwrite all of them?
In UDict, there are __len__ for example, and if UDict was subclass of dict, you wouldn't need to reimplement it
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Good idea, i wanted to do that. And override all methods with changes
But If you want to overwrite all default functions, why even bother making it a string subclass? I mean, as far as I know, that approach worked for UDict, as @n0n1m mentioned.
Does he overwrite all of them?
Idk, but judging by his response to a suggestion above he does in fact want to overwrite all methods
Idk, but judging by his response to a suggestion above he does in fact want to overwrite all methods
Good idea, i wanted to do that. And override all methods with changes
Idk, but judging by his response to a suggestion above he does in fact want to overwrite all methods
Good idea, i wanted to do that. And override all methods with changes
That's exactly what I'm talking about
Idk, but judging by his response to a suggestion above he does in fact want to overwrite all methods
Good idea, i wanted to do that. And override all methods with changes
That's exactly what I'm talking about
He says he want to overwrite the methods that he changes, but he didn't say he changes all of them
Idk, but judging by his response to a suggestion above he does in fact want to overwrite all methods
Good idea, i wanted to do that. And override all methods with changes
That's exactly what I'm talking about
He says he want to overwrite the methods that he changes, but he didn't say he changes all of them
Dang I thought he said he wanted to overwrite all methods and change them
Also all methods of
str
Suggestion: maybe make UStr a subclass of built-in str?
Good idea, i wanted to do that. And override all methods with changes
Why didn't you do that for UDict?
in UDict there are very much methods fron dict with changes. But it'll be great to subclass dict. It'll make using isinstance()
function more great (you can use just inbuilt dict class to check for dict and UDict class. I'll make it.
Create UStr object for simplification of working with strings.
Methods:
split(*s: str) -> list[UStr]
center(length: int, fill: str = ' ') -> UStr
Can also fill with multiply characters (inbuild str - doesn't)!
s.center(10, '#@') # '#@#@34#@#@'
Properties:
letters
words
sentences
lines
Magic methods:
s2 = UStr("Hello, my name is banana") s2 - ["Hello", "banana"] # u', my name is ' s2 - UList(["Hello", "banana"]) # Same
Also all methods of
str
Thank @mbutsk and @n0n1m for help with creating issue ❤️