treyhunner, 11 days ago What are your favorite #Python one liners?
What are your favorite #Python one liners?
bmispelon, 10 days ago @treyhunner One I came up with today: print("".join(chr(127397 + ord(c.upper())) for c in country_code)) # where country_code is a 2-letter country code string, like FR, NO or US
@treyhunner One I came up with today:
print("".join(chr(127397 + ord(c.upper())) for c in country_code)) # where country_code is a 2-letter country code string, like FR, NO or US
jonny, 10 days ago @treyhunner p=print;print=lambda *a, **k:p(*[str(b).upper()+'!!!' for b in a], **k)
@treyhunner
p=print;print=lambda *a, **k:p(*[str(b).upper()+'!!!' for b in a], **k)
romanroe, 10 days ago @jonny @treyhunner group by id: {o.id: o for o in objs}
@jonny @treyhunner
group by id:
{o.id: o for o in objs}
jonny, 10 days ago @romanroe @treyhunner what kinda objects do ya got with an id attribute?
@romanroe @treyhunner what kinda objects do ya got with an id attribute?
id
ildave, 10 days ago @treyhunner i love any list comprehension.
@treyhunner i love any list comprehension.
Sevoris, 10 days ago @treyhunner "TypeError: cannot (operation) type 'Timestamp' with type 'datetime64[ns]'"
@treyhunner "TypeError: cannot (operation) type 'Timestamp' with type 'datetime64[ns]'"
iris, 10 days ago @treyhunner print("\n".join([s for s in dir(something) if substring in s])) in the interactive shell, for installations without ipython
@treyhunner print("\n".join([s for s in dir(something) if substring in s])) in the interactive shell, for installations without ipython
print("\n".join([s for s in dir(something) if substring in s]))
iris, 10 days ago @treyhunner relatedly: locals()
@treyhunner relatedly: locals()
treyhunner, 10 days ago @iris Great ones! Here's an even shorter equivalent to locals(): vars() Relatedly: dir() (for just the names) Also vars(an_object) or dir(an_object). Since vars(an_object) only looks at dict they're a bit different. Sometimes I'll do vars(an_object).keys() to see just the attributes that live directly on an object.
@iris Great ones!
Here's an even shorter equivalent to locals():
vars()
Relatedly: dir() (for just the names)
Also vars(an_object) or dir(an_object).
Since vars(an_object) only looks at dict they're a bit different. Sometimes I'll do vars(an_object).keys() to see just the attributes that live directly on an object.
siddhantgoel, 10 days ago @treyhunner anything that uses functools.partial.
@treyhunner anything that uses functools.partial.
mariatta, 10 days ago @treyhunner breakpoint()
@treyhunner breakpoint()
rochacbruno, 10 days ago @treyhunner import("ipdb").set_trace()
import("ipdb").set_trace()
treyhunner, 10 days ago @rochacbruno nice one. In case you're unaware of it: export PYTHONBREAKPOINT="ipdb.set_trace" https://kortina.nyc/notes/use-ipdb-as-the-default-python-debugger-with-breakpoint-and-pythonbreakpoint/
@rochacbruno nice one.
In case you're unaware of it:
export PYTHONBREAKPOINT="ipdb.set_trace"
https://kortina.nyc/notes/use-ipdb-as-the-default-python-debugger-with-breakpoint-and-pythonbreakpoint/
Add comment