#Python decimal module is cool, but be careful to use strings for initialization, or you might not get what you want:
>>> Decimal(1.5)
Decimal('1.5')
>>> Decimal(1.6)
Decimal('1.600000000000000088817841970012523233890533447265625')
>>> Decimal('1.6')
Decimal('1.6')
#repostfromapastlife #pythontip #Python
#Python decimal module is cool, but be careful to use strings for initialization, or you might not get what you want:
>>> Decimal(1.5)
Decimal('1.5')
>>> Decimal(1.6)
Decimal('1.600000000000000088817841970012523233890533447265625')
>>> Decimal('1.6')
Decimal('1.6')
#repostfromapastlife #pythontip #Python
Do you know that `0` when passed to `open` function is a shortcut to open stdin stream input in #python?
pydoc3 builtins
A short screencast showing how to use the command `pydoc3` to access the Python documentation in the terminal on a Linux based operating system.
https://www.youtube.com/watch?v=oUxRyur1vBg
#CommandLine #Documentation #LinuxHowto #ManPageMonday #Pydoc #PythonDocumentation #PythonProgrammer #PythonTip #ReferenceManual #RTFM #Screencast #SoftwareDevelopment #TerminalTip #UnixHowto #TerminalTok
#commandline #documentation #linuxhowto #manpagemonday #pydoc #pythondocumentation #pythonprogrammer #pythontip #referencemanual #rtfm #screencast #softwaredevelopment #terminaltip #unixhowto #terminaltok
In case you ever need to jump around in Python code without using functions #python #pythontip
RT @python_tip@twitter.com
Get key with minimum value in a dict:
>>> d = {'a':11, 'b':2, 'c':14, 'd':2}
>>> min(d, key=d.get)
'b'
>>> min_value = min(d.values())
>>> [k for k, v in d.items() if v==min_value]
['b', 'd']
adapted from #pythontip by @bguberfain@twitter.com
🐦🔗: https://twitter.com/python_tip/status/1384165712340525061
RT @python_tip@twitter.com
If you want to get multiple items from a dictionary, you might either use a list comprehension
>>> [mydict[x] for x in mykeys]
or you can use `operator.itemgetter` as follows
>>> from operator import itemgetter
>>> itemgetter(*mykeys)(mydict)
#pythontip from @IDryer@twitter.com 👇 https://twitter.com/IDryer/status/1196526211796783110
🐦🔗: https://twitter.com/python_tip/status/1198747702953234433
RT @python_tip@twitter.com
Use beautiful_date when need to create date/datetime objects in a simple way.
pip install beautiful-date
from beautiful_date import *
>>> d = 5/Mar/2019
BeautifulDate(2019, 3, 5)
>>> d[4:13]
datetime.datetime(2019, 3, 5, 4, 13)
#pythontip from @KuzmovychBox@twitter.com
🐦🔗: https://twitter.com/python_tip/status/1192214829257363458