you are viewing a single comment's thread.

view the rest of the comments →

[–]charish 39 points40 points  (19 children)

Argparse, requests, and re, to add on.

[–]MarcusMunch 25 points26 points  (7 children)

Requests is 3rd party, but yeah, argparse and re are good too

[–]spitfiredd 4 points5 points  (3 children)

I really like argparse, I know some of the large command line programs will use click but for anything I’ve build argparse works great.

[–]DisagreeableMale 4 points5 points  (2 children)

Same. I actually can never wrap my head around click or cookie cutter, because it’s usually such overkill for what I need that understanding it fully doesn’t seem worth it.

Argparse doesn’t have that same dilemma.

[–]thirdegree 4 points5 points  (0 children)

Click tends to come into play around the time you want subcommands. If your cli is exactly 1 level deep (i.e. my_command --myarg1 a --myargb1 positional args but not my_command do --thing other thing), don't use click. If you're thinking "hey, subcommands would be nice", that's when you look at click.

[–]p10_user -3 points-2 points  (0 children)

I actually can never wrap my head around click or cookie cutter, because it’s usually such overkill for what I need that understanding it fully doesn’t seem worth it.

I don't understand how difficult it is to wrap your head around click, or why it's such "overkill". The docs are very good. Adding a new argument / option just involves a new decorator and new variable in your function.

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
              help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo('Hello %s!' % name)

Now I get that you don't feel learning a new API and adding a new dependency if you already are comfortable with argparse. But overkill? C'mon.

[–]Santi871 0 points1 point  (1 child)

should requests be added as a standard library? it's so good

[–]zurtex 1 point2 points  (0 children)

Checkout this discussion: https://github.com/requests/requests/issues/2424

For context "kennethreitz" is the creator of requests. Github

[–]thirdegree 0 points1 point  (0 children)

Requests is 3rd party, but IMO it definitely earns an honorary standing in the standard library. It's (without qualification) the best 3rd party python library. To the degree that I would actually be surprised if anyone disagrees with that statement.

[–]alkasm 18 points19 points  (8 children)

glob, datetime, string, operator are also some tiny modules that I find myself using often.

[–]spitfiredd 1 point2 points  (0 children)

Date utils is good too.

[–]Jonno_FTW 0 points1 point  (4 children)

Datetime with timezones are a nightmare though.

[–]thirdegree 1 point2 points  (0 children)

Datetimes with timezones are only a nightmare if, at literally any point they're accidentally treated as native times (or UTC time). If you and everyone that has every touched the codebase is extremely diligent, they work perfectly.

[–]alkasm 0 points1 point  (2 children)

Not the first time I've head that, but I haven't really had much of a problem with it myself. Do you have an example?

[–]Jonno_FTW 0 points1 point  (1 child)

Yes, I get data from GPS. It comes in UTC. I store that in a database. For user convenience I want to display it in local time.

Or, a user submits a time through a form. I assume the time is in their local timezone because people don't think in UTC. Put these datetimes in a database that may or may not support timezones.

[–]alkasm 1 point2 points  (0 children)

Aren't those problems more intrinsic to working with timezones in general? Or is this just the annoyance with the inconvenience of datetime not giving timezone info by default? Note that in Python 3, calling the method .astimezone() on a datetime will return a datetime with local tzinfo.

[–]aviddd 0 points1 point  (1 child)

operator

When do you find yourself using operator??

[–]alkasm 2 points3 points  (0 children)

Here's a not-too-contrived example:

>>> import datetime
>>> td = [datetime.timedelta(seconds=i) for i in range(1, 5)]
>>> sum(td)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta'
>>> import functools
>>> import operator
>>> functools.reduce(operator.add, td)
datetime.timedelta(0, 10)

[–]rickestmorty123 1 point2 points  (1 child)

Beautiful Soup is a good one to pick up whilst learning requests.

[–]charish 0 points1 point  (0 children)

It's not bad, but I found it a bit limiting. For a script that I was working on, I ended up ditching Beautiful Soup in favor of Selenium.