r/Python • • Oct 07 '20

Discussion Anyone else uses the Python interpreter as a calculator?

It's just so comfy.

1.7k Upvotes

252 comments sorted by

View all comments

614

u/underscores_ftw Oct 07 '20

Yes, and especially to do math with dates. Need to know what the date will be in 90 days? Easy:

import datetime
datetime.datetime.now() + datetime.timedelta(days=90)

272

u/gambitloveslegos Oct 07 '20

I really thought you meant doing math with dates, as in a person you are on a romantic outing with. I was wondering why you were interested in what 90 days out was, unless you’re doing some sort of 90 day fiancé thing.

36

u/engineering_too_hard Oct 07 '20

Same! And honestly, I have a couple times lol

80

u/gambitloveslegos Oct 07 '20

I mean, my now husband impressed me on our 4th date by walking me through his PhD thesis and the different simulations going into it. Seeing how excited he got was one of the reasons there was a 5th date.

12

u/dotancohen Oct 08 '20

I really thought you meant doing math with dates, as in a person you are on a romantic outing with.

There are no STDs involved when doing math with dates. There is no risk of pregnancy when doing math with dates. The cleanup is easier and there is (usually) less noise.

I'm convinced! Uninstalling Tinder now and installing Integrate instead!

15

u/grnngr Oct 08 '20

No STDs involved? Sad numpy.std() noises…

→ More replies (3)

12

u/EnfantTragic Oct 08 '20

I really thought doing math with dates, as in the fruit

→ More replies (1)
→ More replies (7)

27

u/XUtYwYzz It works on my machine Oct 08 '20

The datetime module is a blessing. It's literally magic and reduces days worth of date programming work down to 30 seconds. I can't praise it enough.

5

u/irrelevantPseudonym Oct 08 '20

There are third party alternatives, eg arrow that can be better, although being in the standard library is a big plus for datetime.

57

u/yespunintended Oct 08 '20
$ date -d now+90days

8

u/irrelevantPseudonym Oct 08 '20

Don't think you even need the now

$ date -d '90 days'

0

u/[deleted] Oct 08 '20

[deleted]

→ More replies (1)
→ More replies (2)

0

u/[deleted] Oct 07 '20

[deleted]

27

u/benargee Oct 08 '20

We don't take too kindly to your kind around here mister!

→ More replies (1)

24

u/Stressed_engineer Oct 07 '20

Or you could just Google what's the date in 90 days time and it will tell you.

35

u/minishorty Oct 08 '20

Or just throw a neural network at it

8

u/[deleted] Oct 08 '20

Data-driven Bayesian Date PredictorTM

5

u/abruptreddit Oct 08 '20

😅😅😅😅

5

u/LakeRat Oct 08 '20

Or just throw a neural network at it

First you have to generate a data set to train the neural network:

import datetime
for x in range(100000):
    dataset[x] = datetime.datetime.now() + datetime.timedelta(days=90)
→ More replies (3)

6

u/taladan Oct 08 '20

One might go so far as to develop a common library of useful imports they use on a daily or weekly basis and just keep that terminal open.

4

u/TheBlackCat13 Oct 08 '20

Ipython lets you define profiles, each of which can be configured to automatically run different lines of code (such as imports) on startup.

→ More replies (1)
→ More replies (1)
→ More replies (14)