Thanks! I got some ideas to improve my module caled eletrica, that intends to be a simple way to calculate values in operations between rectangular (impedances) and polar (phasors)
For the same reason f-strings exist in the first place. It's just syntactic sugar for calling a method which returns a formatted string. You can always use a method instead if you prefer. For example, datetime implements both. You can either call d.strftime("Today is %A, %B %-d, %Y") or do f"{d:Today is %A, %B %-d, %Y}" or f"Today is {d:%A, %B %-d, %Y}".
***UPDATE: I cannot use PyCharm for any of my upcoming Python practice projects via these tutorials. I tried upgrading my PyCharm version a few weeks ago, and ended up losing it forever due to the new installation containing a virus. I will swap to using Visual Studio Code for the foreseeable future.*** This is so cool! So now, you can have a number class that, say, can have a hexadecimal, binary, octal, decimal, perhaps base64 representation, etc. and override the "def __format__(self, format_spec: str)" method to return the corresponding format for each of those options. That's very handy!!!
If you have windows and want to get used of using Linux I suggest getting WSL, whether you're coding C, python, JavaScript etc managing packages is way easier with a few commands And you don't ever have to worry about viruses when using a package manager
Dude! Working sick? Totally beast, but you really need to look after your health! Take care of yourself Brah! You're still young so it's easy now, but every time you do this makes the subsequent ones that much harder (voice of experience). As to format specifiers, 🤔,,, great ... more boilerplate code to have to knock out for every class. 🤕 IDK. I can see this being good maybe for some specific use cases, like padding time for hourly coders or typing skills practice maybe? Just kidding, yeah I CAN see it being useful ... ish, and actually rather cool. If I were fleshing out an API for publication as an example. I am probably in a minority here, but as a casual coder with responsibility for the entire project, I find myself looking for ways to decrease my typing. Slogging through vast wastelands of boilerplate, whether it's getters and setters in Java, or __str__, __repr__, if __name__ == "__main__" ... blah blah in Python, on and on (kinda like my comments😉) , really sux having to write the same code, over and over, every time. Takes all the fun and muse out of coding imo. As an observation of a 45+ year coder, I can say that no language is immune (though some clearly better than others), and that it generally gets worse with time as a language matures. Hoping you're feeling better soon. ✌and ❤ 🖖😎👍
Ok, but why? Why would you even use that? How is that any better than just returning the polar coordinates from a normal method and not having it tied to formatting?
You can add stuff that only makes sense when printing and not pollute your "normal methods" with it, nor do you have to add extra methods for printing in verious representations. Encapsulation, cleaner interface
@@samrijijkot i.e., then __str__() could call __format__() implicitly if any format specifiers were to be passed in. The parser for the CPython compiler would be most likely the thing to detect this.
Thanks! I got some ideas to improve my module caled eletrica, that intends to be a simple way to calculate values in operations between rectangular (impedances) and polar (phasors)
7:55 Using a format specifier inside a formatting function, peak humour!
Why not just use class.method() instead? What does this have over regular class functions?
For the same reason f-strings exist in the first place. It's just syntactic sugar for calling a method which returns a formatted string. You can always use a method instead if you prefer. For example, datetime implements both. You can either call d.strftime("Today is %A, %B %-d, %Y") or do f"{d:Today is %A, %B %-d, %Y}" or f"Today is {d:%A, %B %-d, %Y}".
***UPDATE: I cannot use PyCharm for any of my upcoming Python practice projects via these tutorials. I tried upgrading my PyCharm version a few weeks ago, and ended up losing it forever due to the new installation containing a virus. I will swap to using Visual Studio Code for the foreseeable future.***
This is so cool! So now, you can have a number class that, say, can have a hexadecimal, binary, octal, decimal, perhaps base64 representation, etc. and override the "def __format__(self, format_spec: str)" method to return the corresponding format for each of those options. That's very handy!!!
If you have windows and want to get used of using Linux
I suggest getting WSL, whether you're coding C, python, JavaScript etc managing packages is way easier with a few commands
And you don't ever have to worry about viruses when using a package manager
Dude! Working sick? Totally beast, but you really need to look after your health! Take care of yourself Brah! You're still young so it's easy now, but every time you do this makes the subsequent ones that much harder (voice of experience).
As to format specifiers, 🤔,,, great ... more boilerplate code to have to knock out for every class. 🤕
IDK. I can see this being good maybe for some specific use cases, like padding time for hourly coders or typing skills practice maybe?
Just kidding, yeah I CAN see it being useful ... ish, and actually rather cool. If I were fleshing out an API for publication as an example.
I am probably in a minority here, but as a casual coder with responsibility for the entire project, I find myself looking for ways to decrease my typing.
Slogging through vast wastelands of boilerplate, whether it's getters and setters in Java, or __str__, __repr__, if __name__ == "__main__" ... blah blah in Python, on and on (kinda like my comments😉) , really sux having to write the same code, over and over, every time. Takes all the fun and muse out of coding imo.
As an observation of a 45+ year coder, I can say that no language is immune (though some clearly better than others), and that it generally gets worse with time as a language matures.
Hoping you're feeling better soon. ✌and ❤
🖖😎👍
Thx_.
Ok, but why? Why would you even use that? How is that any better than just returning the polar coordinates from a normal method and not having it tied to formatting?
You can add stuff that only makes sense when printing and not pollute your "normal methods" with it, nor do you have to add extra methods for printing in verious representations. Encapsulation, cleaner interface
@@samrijijkot i.e., then __str__() could call __format__() implicitly if any format specifiers were to be passed in. The parser for the CPython compiler would be most likely the thing to detect this.
1st.