@nedbat@hachyderm.io
@nedbat@hachyderm.io avatar

nedbat

@nedbat@hachyderm.io

Python, software, coverage.py, typography, juggling, Boston, autism (dad). Laughing at the world doesn't mean I don't take it seriously. He/him.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

o76923, to python
@o76923@kitty.social avatar

I still think it's nuts that 's best solutions for rendering are a bunch of wrappers around CairoSVG with the two next best solutions being use Inkscape from the command line and wand, a wrapper around ImageMagick.

nedbat,
@nedbat@hachyderm.io avatar

@o76923 Can you say more about why it's nuts to wrap CairoSVG? Is there something wrong with it?

nedbat, to random
@nedbat@hachyderm.io avatar

A fun browser toy: The Blob Toy.
Here's an example: https://oimo.io/works/blob/
https://oimo.io/works/blob/?id=07eb178b

nedbat, to python
@nedbat@hachyderm.io avatar

Nested loops can sometimes be replaced by one itertools.product() from the #Python stdlib:

nedbat, to python
@nedbat@hachyderm.io avatar

Mostly you shouldn't subclass built-in types. But if you do, dict subclasses can define missing: it's called when a key is missing. Instead of hiding a dict in a function as a cache, how about hiding a function in a dict!? A Fibonacci dictionary:

nedbat, to python
@nedbat@hachyderm.io avatar

Are you sure you know how #Python decorators work? This should be no problem! 😈 🤯 🤓

nedbat,
@nedbat@hachyderm.io avatar

@brohrer I love this graph!

nedbat,
@nedbat@hachyderm.io avatar

@sovietfish @feudjais Yes: __doc__ is the docstring for the class (or function, method, or module). Any string syntax is fine.

nedbat,
@nedbat@hachyderm.io avatar

@dluz lol

nedbat,
@nedbat@hachyderm.io avatar

@thejcannon Oh no! This is too clever for production code in my opinion. I would much prefer:

class Foo:  
 ...

foo = Foo()  
nedbat, to python
@nedbat@hachyderm.io avatar

I guess the time has come. I think I have to finally figure out what #Python's sys.meta_path does...
https://docs.python.org/3/library/sys.html#sys.meta_path

nedbat, (edited ) to random
@nedbat@hachyderm.io avatar

How long am I willing to stick with something if it works? I'm currently editing an XSLT file that underpins my blog... https://nedbatchelder.com/site/xuffpx.html

nedbat, to random
@nedbat@hachyderm.io avatar

Achievement unlocked: found a bug in https://coderpad.io during a coding interview!

Run this Python 3 code:

for l in range(70, 80):
line = (f"{l:2d}: " + "0123456789" * 10)[:l]
print(line)

Why are lines 72 and 73 the same? Where are the "8"s in lines 73 and up?

nedbat,
@nedbat@hachyderm.io avatar

@geos The bug is in the output pane in the picture: the character "8" is in the position where the text wraps, and it is not displayed.

nedbat,
@nedbat@hachyderm.io avatar

@eichin It's the output panel. On Firefox, the 8 is missing where the lines wrap. Font size doesn't seem to matter. On Chrome, the 8 is present.

jscholes, to python
@jscholes@dragonscave.space avatar

Needed to rename a test fixture in a #Python file, and find/replace wasn't up for the job. So I decided to give #VSCode a go:

I started by pressing Ctrl+F2, for "Change All Occurrences". I think that is basically find/replace, and hence didn't do what I wanted.

Instead, I installed the recommended Python extension, and pressed F2 for "Rename Symbol". That claims to have only made one change, and the references to the function are still using the old name.

So, consider me confused. I'm using #pytest, whereby the test fixtures are referenced as function arguments rather than being called directly. Maybe that's what VS Code is struggling with? Either way, I've now spent more time on this than just manually editing the text.

#VisualStudioCode

nedbat,
@nedbat@hachyderm.io avatar

@jscholes Pytest's style of associating fixtures with tests is quirky, and confuses most language tooling.

nedbat,
@nedbat@hachyderm.io avatar

@mdione @jscholes
@pytest.fixture
def a_fixture(): return 17

def test_some_function(a_fixture):
assert a_fixture == 17

Pytest finds fixtures by the names of arguments, but nothing else in Python works that way.

nedbat,
@nedbat@hachyderm.io avatar

@mdione @jscholes Yes, search and replace will work. The names match.

nedbat,
@nedbat@hachyderm.io avatar

@mdione @jscholes "Change all occurrences" is using language-specific semantics to find uses of a variable. Here is a function called fx, but it's never used:

def fx(): return 17

def other_func(fx): return fx+1

print(other_func(12)) # 13

mariatta, to random
@mariatta@fosstodon.org avatar

Maybe I'm overthinking this, but I'm wondering if people end their inline code comments (in english language) with period, or without period?

For example:

Assert that the data didn't change

or

Assert that the data didn't change.

I normally don't end my inline comments with period, but wondering if I should start doing it 😓

nedbat,
@nedbat@hachyderm.io avatar

@mariatta I think it's more readable to use a period. The reader doesn't have to scan ahead to see if there's more of the sentence on the next line. And it's more consistent with your comments that have multiple sentences.

sloanlance, to random
@sloanlance@mastodon.social avatar

@pycon, when will the PyCon US 2024 videos be released on YouTube? I can't wait to see the sessions I couldn't attend because I couldn't be in two places at the same time. 😆

I see that the playlist is available on YouTube and it contains 144 unavailable, private videos. I guess those are probably all the videos from the conference. I hope the videos WILL NOT use automatic captions. Please use the captions written by the stenographers.

nedbat,
@nedbat@hachyderm.io avatar

@sloanlance @pycon If you attended PyCon, you can see the videos in the online experience now. It's on your dashboard.

nedbat, to random
@nedbat@hachyderm.io avatar

Why when I go to my bank's web site is there a "Log Out" button displayed, but then when I click on my account, it asks me to log in?

nedbat, to random
@nedbat@hachyderm.io avatar

One open question in dribbling blog posts for decades: how to highlight the "evergreens" that could be useful into the future?

An attempt: I made a page of "Frequent Python questions" that inspired some of my often-referenced posts over the years:
https://nedbatchelder.com/text/pyfaq.html

nedbat,
@nedbat@hachyderm.io avatar

@llimllib Thanks this piece is interesting both for its content and its form(!). It is easily the most elaborately structured and formatted "blog post" I have seen. It's addressing a slightly different problem than mine: he's talking about how to alert people when a post has been substantially updated.

nedbat, to python
@nedbat@hachyderm.io avatar

New blog post: One way to fix circular imports.

There are better ways, but sometimes simply changing the form of the import statements can untangle the problem:

https://nedbatchelder.com/blog/202405/one_way_to_fix_python_circular_imports.html

nedbat,
@nedbat@hachyderm.io avatar

@Bleyddyn Yes, another reason to prefer it.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • ngwrru68w68
  • everett
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • GTA5RPClips
  • Durango
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • DreamBathrooms
  • provamag3
  • tacticalgear
  • osvaldo12
  • tester
  • cubers
  • cisconetworking
  • mdbf
  • ethstaker
  • modclub
  • Leos
  • anitta
  • normalnudes
  • megavids
  • lostlight
  • All magazines