Elektrine lite

← Feed

@eliocamp@mastodon.social

Post #2203542

2026-05-07 05:29 UTC

Almost every single time I try to use #python for data analysis I rediscover Clause Wilke's post. Especially the part about separating logic from logistics. In today's instance: I want to get the full path of all the files/folders in a folder, in #RStats that's just `list.files(path, full.names = TRUE)`. Simple and clear. In python you need some variation on files = [os.path.join(path, f) for f in os.listdir(path')] Which sucks. https://blog.genesmindsmachines.com/p/python-is-not-a-great-language-for?open=false#%C2%A7separating-the-logic-from-the-logistics

Replies (5)

  • @eliocamp@mastodon.social 2026-05-07 06:07

    I found a one-liner: `list(Path(path).iterdir())`. It's still rather convoluted and impossible to discover, but at least doesn´t require explicit loops.

    Open ##2273797

  • @gspeed0689@mapstodon.space 2026-05-07 05:36

    @eliocamp@mastodon.social just addressing the example py code and not the article or idea of python being bad for this, there is a nicer way now with Pathlib path = pathlib.Path(path) files = list(path.rglob("*"))

    Open ##2273798

  • @bmaxv@noc.social 2026-05-07 05:49

    @eliocamp@mastodon.social Hmmm. Yes. Of course it could be that your brain simply can't contain the vast(!) intellect required to write python. That's not your fault, it's a skill that can only be acquired by studying in a sufficiently pure field. Please consult the chart: https://xkcd.com/435/ Yes that was sarkasm. This is serious: I don't like that example. Don't use list comprehensions like that.

    Open ##2273807

  • @jimgar@hachyderm.io 2026-05-07 07:29

    @eliocamp@mastodon.social This isn’t apecific to your issue, but I’ve read Python people saying list comprehensions are easier to read than for loops. I simply cannot understand how that’s possible.

    Open ##2273823

  • @eliocamp@mastodon.social Why on earth is files a method on the list class? And what do you do if you have 5 million files you want to do something to?

    Open ##2273830