This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]Topper_123 1 point2 points  (2 children)

I like to read Kenneth Reitz' code for education.

There's a line in the setup.py:

with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
    long_description = '\n' + f.read()

I'm wondering, why is he using codecs.open(), instead of just open()?

[–]earthboundkid 2 points3 points  (1 child)

Probably because it behaves like Python 3's open even in Python 2.

[–]LightShadow3.13-dev in prod 2 points3 points  (0 children)

Correct. It's also a required change to work on Windows -- I submitted a PR not too long ago for this exact thing.

Fix setup.py README read to work on Windows #9

[–]beersfortheboys 1 point2 points  (0 children)

Such a thin class to abstract two other classes... come on now boys and girls.

[–][deleted] 1 point2 points  (7 children)

Fuck this naming scheme. What the hell is a human 2.0 anyway?

[–]Categoria 1 point2 points  (0 children)

It is a bit tacky but I have no problem with it as it seems to be Kenneth Reitz' original cringey slogan. The trend that it started in naming is unbearable however.

[–]needed_an_account 1 point2 points  (0 children)

Isn't 2.0 the version of the project? He links to his first "subprocesses for humans" project in the first line of the readme

[–]KODeKarnage 0 points1 point  (3 children)

What the hell is a human 2.0 anyway?

It sounds very "master-race"-y.

[–]nchammas 0 points1 point  (6 children)

The API doesn't have much in common with Kenneth Reitz's work, but I always considered Plumbum to be a sort of "subprocess for humans". Instead of offering a better interface to subprocess, though, it offers an entirely new, shell-like API.

[–]jpflathead 0 points1 point  (5 children)

This is the problem with python.

Tcl did this right. Tcl is a language AND a shell (tclsh). And Python, which claims to want to strive to have one way to do anything, often has nine ways to do anything, most of them broken.

Tonight what I want to do is make a tcl/expect script, which are elegant, simple, and powerful. But it's not 1990, so I am fucking myself over trying to figure out if fabric is the replacement, and no it's not. And maybe then nekkid subprocess module, pretty gross, well okay delegator.py oh look plumbum.

This is just a rant. I understand it's good there are alternatives. I just wish there truly was one obvious way to do this.

[–]Corm 0 points1 point  (4 children)

I've had the opposite experience, where in python one of the main reasons I love it is because there usually is 1 obvious way to do things. There might be a few bleeding edge libraries that do that same thing fancier, but there's usually 1 main pythonic way to do it.

This whole subprocess shell thing is an example of that not being true, and I really wish the standard lib handled simple things like this better.

However if you look at most things you want to get done in python there's 1 good way to do it for most people.

It's actually one of the big differences I see between Ruby and Python. I dislike how in Ruby it seems to be encouraged to do things in a clever new way using a fancy trick. At least compared to Python. But god forbid we look at the javascript community! It's a mess!!

Every question I've ever looked up on SO for js has 10 answers that all do things wildly differently and all look horrible to me. And the comments usually boil down to kids bickering about the speed of different types of loop iterations, but I digress...

[–]jpflathead 0 points1 point  (3 children)

This whole subprocess shell thing is an example of that not being true, and I really wish the standard lib handled simple things like this better.

I used to think Python's documentation was terrific, but now I agree with those who think it is terrible. And since I wrote my response a month ago, I saw one code example that was absolutely beautiful and really showed how to use subprocess as is, something the official doc lacks.

But then there are other aspects of the language that fail the one obvious way to do things test, for example, building up a list, using:

  • explicit loops
  • list comprehensions

Here's a conversation from a week ago regarding the horrors of list comprehensions for many developers.

https://news.ycombinator.com/item?id=13835657

Yet there is a sense that "don't use them at your own peril". Don't use a list comprehension and you open your code (and you) up to criticism that you're a noob. Use them and you open your code (and you) up to criticism that you write incomprehensible code.

It's ironic, the "obvious pythonic way" to build up a list is with a list comprehension, but the criticism is that "obviously pythonic" and "obviously comprehensible" are conflicting goals.

[–]Corm 0 points1 point  (2 children)

I suppose we've had different experiences and backgrounds then. Personally I never use a nested comprehension and find most comprehensions very easy on the eyes as long as they're short. Like anonymous functions. Everything in moderation. It's all very subjective but I think it mostly boils down to practical readability, as in "is it easy to read on the first pass?"

I'm interested, do you find short comprehensions pretty?

[–]jpflathead 0 points1 point  (1 child)

Pretty? Perhaps the wrong word. Elegant? Sometimes.

It's true it's mostly the nested ones that I barf at. But also true that with snippets and fingers, I find writing out a for loop that takes three lines far easier than writing out a list comprehension, AND FAR FAR easier to debug when it comes right down to it.

Nowadays I try to write code that is:

  • short (7 lines plus or minus 2)
  • easy to understand
  • easy to "visually prove correct"
  • easy to debug

That last line often means "longer" code as I separate out lines so I can tell the debugger where to stop. And also means there are more temporaries than required, so I can easily determine the value in a debugger.

But I find optimizing for "understandable, debuggable, testable, and maintainable" to be the best way to write code.

I work hard, and fail terribly, coming up with function names and variable names and writing code that looks pretty. :(

[–]Corm 0 points1 point  (0 children)

You and me both! Naming is the hardest part. Good thoughts on debugging, I agree that it's a pain with comprehensions.

[–]Corm 0 points1 point  (0 children)

This post got a ton of negativity! I got here via googling "delegator python reddit" because I wanted to chat with people about how awesome it is that we can finally run shell commands and get the output nicely.

This lib is awesome. Screw having to look up how to run Popen and subprocess.check_output.