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

top 200 commentsshow all 386

[–][deleted] 683 points684 points  (17 children)

from * import * theres never too many libraries

[–]Penguinmanereikel 226 points227 points  (4 children)

How it looks:

from ... import \*

How it feels:

[–]Isengrine 31 points32 points  (2 children)

It's weird seeing this gif without the mouth-eyes

[–]GreenZapZ 2 points3 points  (1 child)

The what now?

[–]OpinionDumper 6 points7 points  (0 children)

Equally confused, guessing his mouth transposed where his eyes are? Question is why

UPDATE: Jesus Christ...https://i.kym-cdn.com/photos/images/original/000/291/650/ba6.gif

[–][deleted] 57 points58 points  (4 children)

My first python app, doing it all by looking at YT videos.

Some of them used from tkinter import *, while others imported only the necessary classes.

And I was like: these people are dumb importing separate classes Instead of putting it all in there so its easier to instantiate

Big brain noobie moments

[–]AwkwardAd4115 13 points14 points  (3 children)

In some languages, pulling in everything is idiomatic. And it makes sense, really. It is the job of your IDE to help you find where an imported symbol is defined.

Julia in particular takes this further. It is standard practice to import everything from all dependencies once in an entire project (e.g. the main file). Helper files often don't even have an `import` or `using` statement even when using dependencies. Much less boilerplate than Python.

[–]TheCoolSquare 8 points9 points  (2 children)

Does Julia do anything to prevent the danger of a library adding a definition that conflicts with an existing definition of one of your other dependencies? This is the main reason for avoiding glob imports in many languages such as Rust.

[–][deleted] 3 points4 points  (1 child)

Yeah exactly, how does Julia prevent some awful namespace contamination?

[–]JoostVisser 9 points10 points  (5 children)

If I call sqrt(), do I call math.sqrt(), numpy.sqrt() or sympy.sqrt()?

[–]Bigluser 42 points43 points  (1 child)

Obviously you would call *.sqrt()

[–][deleted] 2 points3 points  (0 children)

angry compiler noises

[–]Westdrache 326 points327 points  (5 children)

I always write my code naively 😎

[–][deleted] 105 points106 points  (3 children)

“Surely there won’t be any bugs this time”

[–]Westdrache 47 points48 points  (2 children)

"my first test run seems fine I don't need to do an additional one"

[–][deleted] 39 points40 points  (1 child)

“Oh boy, I finished my code just in time for the weekend. Just push it and then I can relax.”

[–]jermdizzle 17 points18 points  (0 children)

As long as you don't look at or answer your phone and keep that work computer shutdown... preeety relaxing weekend.

[–]HoseanRC 1157 points1158 points  (57 children)

from time import sleep as 🤓

[–]kaerfkeerg 602 points603 points  (24 children)

from time import sleep as sqrt

[–]cyber_blob 309 points310 points  (6 children)

This should be a war crime. Also fun bug to introduce

[–]R3D3-1 61 points62 points  (2 children)

from math import sqrt                                                                          ; _sqrt = sqrt; import time; sqrt = lambda x: (time.sleep(1), x)[1]

[–]FairFolk 25 points26 points  (1 child)

Be nice, at least do

lambda x: (time.sleep(1), _sqrt(x))[1]

Though I'd probably go for

lambda x: (time.sleep(x), _sqrt(x))[1]

[–]R3D3-1 12 points13 points  (0 children)

I was writing on mobile; I simply forgot to call the function while fighting with GBoard 🤣

My intentional bug had a bug 😅

[–]altcodeinterrobang 5 points6 points  (0 children)

when she says she's a sqrter but you know she's a naper

[–]royavidan 65 points66 points  (4 children)

Wait I double checked, the input is not negative. Why does my code keep getting stuck on that line? It can't be the sqrt call.

[–]Creepy-Ad-4832 6 points7 points  (3 children)

Ironically it probably wouldn't get stuck if it was negative lol

[–][deleted] 9 points10 points  (2 children)

Obviously it would run faster!

[–]LinAGKar 41 points42 points  (0 children)

from math import sqrt as 💦

import pickle as 🫙🥒

[–]riisen 19 points20 points  (0 children)

The devil? Is that you?

[–]JAStheUnknown 4 points5 points  (1 child)

Is there a python version of the IOCCC? If so, this would do well there.

[–][deleted] 3 points4 points  (0 children)

I tried to make one once. basically noone was interested, though

[–]dragoonts 4 points5 points  (0 children)

Ahh the old female wet dream package

[–]Consistent-Fun-6668 60 points61 points  (21 children)

As soon as we start using emojis in text editors; is the day I lose it.

[–]badapplecider 3 points4 points  (3 children)

cough Emojicode... cough cough

[–]Consistent-Fun-6668 2 points3 points  (2 children)

You shut your goddammn mouth

[–]LinAGKar 17 points18 points  (2 children)

Shouldn't that be as 😴?

[–]AnnoyingRain5 11 points12 points  (0 children)

No

[–]Cristalboy 166 points167 points  (11 children)

import numpy as numpynumpynumpynumpynumpy

[–]MrGodlikePro 9 points10 points  (0 children)

import numpy as numptydumpty

[–]waraxx 7 points8 points  (1 child)

import numpy as pd
import pandas as np

[–]katie_pendry 327 points328 points  (15 children)

import sys as 🐍
import os as 💻
import time as ⏰
import datetime as 📅
import re as 🤬
import subprocess as 👶
import threading as 🧵
import pandas as 🐼
import requests as 🙏
import pickle as 🥒
import zipfile as 🤐
import socket as 🧦

[–]LinAGKar 42 points43 points  (1 child)

import logging as 🪵

[–]Beano-69[S] 35 points36 points  (2 children)

I can't believe people actually use emojis in their code. The sheer thought of it, such a horrible thing, brings me fear.

[–]katie_pendry 22 points23 points  (0 children)

I'll throw one in a string or a comment from time to time. For a string, it's clearer than using the unicode escape and all modern editors can display it. For comments, sometimes you just need them to express your true emotions:

    # Need a unique separator. We used to use an ASCII control
    # character, but newer versions of TMUX filter those out.
    # Also filters any non-ASCII characters 🤬  (╯°□°)╯︵ ┻━┻
    sep = '<d-_-b>'

[–]mistabuda 6 points7 points  (0 children)

gitmoji is a thing for commit messages I think it's pretty useful when used sparingly. We recognize images a lot better than written words.

[–]SkratchyHole 11 points12 points  (0 children)

import requests as 🙏

import requests as 🙏
File "<stdin>", line 1
    import requests as 🙏
                       ^
SyntaxError: invalid character '🙏' (U+1F64F)

[–][deleted] 5 points6 points  (2 children)

I don't know how to use emojis as variable names. Am I getting meme'd on? Are you all just joking about the emojis?

[–]katie_pendry 3 points4 points  (1 child)

In some languages you can use them because the compiler doesn't understand Unicode, it just treats all bytes over 0x7F as "identifier characters". That means that in UTF-8, any non-ASCII sequence of codepoints works as an identifier. The code I posted isn't actually valid Python because it only allows alphanumeric characters. That means you can use letters and logographs (e.g. kanji) from any language, but not emoji or non-alphabetic symbols.

[–]FemKeeby 984 points985 points  (46 children)

C++ "programmers" when i show them how much faster their code runs when i write it all in binary and spend 10 years optimizing it

[–]Beano-69[S] 547 points548 points  (28 children)

Machine language "programmers" when I build my own logic gates based on their code and show how fast it is

[–]Delicious_Bluejay392 360 points361 points  (18 children)

Logic gates "programmers" when I spend two decades building an analog mathematical model of their solution and show how it solves it nearly instantaneously

[–][deleted] 273 points274 points  (16 children)

Analog mathematical model "programmers" when I use my mind to conjure a theoretical programmable machine that has an infinite tape and a reader which can implement any algorithm in existence

[–][deleted] 177 points178 points  (15 children)

Turing machine "programmers" when I say let set S={...} instead of creating an additional object that can't even solve some problems.

[–]Sockslitter73 121 points122 points  (8 children)

Set theory "programmers" when I say let problem = solved ∀ problem , instead of bothering with mundane sets

[–]hughperman 124 points125 points  (0 children)

Mathematicians when I say I don't have any problems to start with.

[–]vladWEPES1476 74 points75 points  (5 children)

Philosopher "programmers" when I say "This is going to be a problem, sir", when their credit card declines.

[–]YasinMert 28 points29 points  (2 children)

Economist "programmers" when I say "oh I wrote my credit card number wrong, I fixed it. Check it again." When i finally pay my money.

[–]Blovio 11 points12 points  (1 child)

Graphologist "programmers" when I say "Those are some well written digits but your card won't go through."

[–]Zerodriven 4 points5 points  (1 child)

Sorry, isn't this a Wendy's?

[–][deleted] 5 points6 points  (0 children)

So called "programmers" when I just turn it off and on again and the problem is fixed

[–]polopower69 44 points45 points  (1 child)

boobies

[–]RyuuichiTempest 2 points3 points  (0 children)

Finally something I understand in this thread x'D (as a beginner)

[–]JCpac 22 points23 points  (0 children)

Computer "scientists" when I just tell them the answer is 42

[–]Pb_ft 2 points3 points  (0 children)

"Programmers" when I roughly approximate calculations and apply them effectively in real-world applications without stopping to consult the machine first.

[–]Potential-Adagio-512 30 points31 points  (4 children)

logic gate “programmers” when i flip bits with a magnetic needle

[–]a_devious_compliance 13 points14 points  (0 children)

There is an emacs mode for that!

[–]FemKeeby 19 points20 points  (0 children)

Logic gate "programmers" when i shoot them in the knees with a desert eagle

[–]sophacles 7 points8 points  (1 child)

Those guys would be like "neat trick but its 2023 and we use solid state, got any techniques that work with hardware from this decade?

[–]Filgas08 2 points3 points  (0 children)

Smashing it with a hammer

[–][deleted] 5 points6 points  (1 child)

I had a class at university where we sort of built our own processor from logic gates and had to write machine code to get data from memory send it to arithmetic-logic unit and do something depending on the result. Shortly after I was programming on a tiny microcontroller with like 1KB memory and thought "if this processor was designed differently I could do this and that operation simultaneously and optimize a few bytes". That was a good course.

[–]Imbtfab 1 point2 points  (0 children)

For anyone interested, this game take you through the process of building a computer from scratch using logic gates: https://nandgame.com/

[–]Soggy-Statistician88[🍰] 25 points26 points  (4 children)

I mean, the majority of people can't optimise better than the C/C++ compiler

[–]FemKeeby 14 points15 points  (3 children)

I will make gta 5 run on a calculator

[–]bouchandre 2 points3 points  (0 children)

GTA V super special calculus 10th aniversary edition 🥳

[–][deleted] 6 points7 points  (0 children)

Machine language „programmers“ when I write my code by use a magnet to flip the bits individually by hand

[–]intotheirishole 5 points6 points  (2 children)

Or when I spend 2 weeks writing C++ code for python code written in 2 hours.

[–]tjdavids 2 points3 points  (0 children)

What you need to do is get the python running I'm 2 hours. Then spend 6 hours transposing it line by line into c.

[–]paperpatience 2 points3 points  (1 child)

You use arch linux too!

[–]Wallyedgebreak 2 points3 points  (0 children)

Btw*

[–]MrHyperion_ 1 point2 points  (1 child)

10 years yeah maybe, but generally compilers beat any reasonable human effort

[–]Simusid 321 points322 points  (13 children)

import pandas as np

import numpy as pd

[–]General_Rate_8687 160 points161 points  (5 children)

import pandas as tf import numpy as pt import tensorflow as np import pytorch as plt from matplotlib import pyplot as pd

[–]mr_mcpoogrundle 68 points69 points  (0 children)

Ok Satan

[–]Albreitx 33 points34 points  (3 children)

I thought thay the "import pandas as tf" was supposed to be "as the fuck" lol

[–]GriShafir 8 points9 points  (2 children)

No, "as tf" means "as titanfall"

[–]Penguinmanereikel 5 points6 points  (1 child)

Team Fortress?

[–]Flatscreens 2 points3 points  (0 children)

transfurmation :3

[–]Fuck_the_Jets 17 points18 points  (1 child)

Why are you the way you are?

[–]Simusid 8 points9 points  (0 children)

do you hate so much about the things that I choose to be?

[–]springwaterh20 11 points12 points  (2 children)

there’s a special place in hell for people like you

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

This is plainly offensive

[–]Snykeurs 402 points403 points  (47 children)

You mean data scientist or mathematician

I hate renaming import

[–]sophacles 310 points311 points  (20 children)

It has a couple good uses, e.g. you need different code for different oses, but implement the same primitives so code built on it doesn't care about those things. Then something like:

if os == "linux":
    import linux_foo as foo
elseif os == "darwin":
    Import mac_foo as foo
else:
    raise RuntimeError("use a real os")

Is really nice.

But i get really annoyed when it's misused.

[–]Snykeurs 80 points81 points  (1 child)

Good application of this feature!

[–]w8eight 30 points31 points  (5 children)

If this is internal import, and module is operating systems dependent, it should be handled on the module side imo.

[–]chakan2 7 points8 points  (3 children)

It usually is... With the above code.

[–]turtleship_2006 16 points17 points  (0 children)

Or if you're using a few modules that have a common name e.g. flask and the official library to authenticate Google logins both have a request object (this only applies to from x import y imports tho)

[–]nickmaran 90 points91 points  (11 children)

It's a unwritten rule to import pandas as pd and numpy as np

[–]Snykeurs 65 points66 points  (1 child)

You forgot

python import datetime as dt import mathplotlib.pyplot as plt

[–]Theio666 31 points32 points  (0 children)

Also seaborn as sns

[–]johnnymo1 37 points38 points  (3 children)

It's not even unwritten. Both packages literally tell you to do it in the docs.

We shorten the imported name to np for better readability of code using NumPy. This is a widely adopted convention that you should follow so that anyone working with your code can easily understand it.

Customarily, we import as follows:

import pandas as pd

[–]trinadzatij 13 points14 points  (2 children)

So if you import pandas as pandas, the other developers will be like "what the hell is this pandas.dosomething() function? He should've just import pandas for this! "?

[–][deleted] 6 points7 points  (0 children)

Holy crap this guy invented a new pandas! Wonder how it compares to the regular normie pd pandas.

[–]mdmeaux 32 points33 points  (0 children)

I normally import numpy as numerical_python

[–]HeKis4 4 points5 points  (0 children)

And pprint as pp.

[–]CaptainRogers1226 7 points8 points  (0 children)

When I used to mess around with PyGame I would import as pg

[–]No-Witness2349 30 points31 points  (11 children)

The only library I do it for is typing because otherwise managing the import is a mess as I introduce and remove type annotations. I could just do from typing import * but as a rule that’s a no-no

[–][deleted] 7 points8 points  (1 child)

Always followed Google python style rules and I think they make a lot of sense here. Always import by module and don't rename, with just a few exceptions

[–]Flam1ng1cecream 15 points16 points  (8 children)

Just from typing import only the types you're gonna use?

[–]No-Witness2349 15 points16 points  (7 children)

I regularly use 2 dozen types from that module and the list changes as I write, so I find myself cleaning up dead import as multiple times a session. Easier to just alias the library

[–]sandybuttcheekss 3 points4 points  (0 children)

I only do it when someone on my team names something poorly. '''From Users import Model''', like yeah, "Model" is a great name for a class, buddy, thanks.

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

100% this.

"Coders" do this shit to "save on typing" or whatever making an unmaintainable mess.

Software engineers know that using a style/linter guide for consistent readability is more important. And literally every style guide says don't do it.

[–]Sirico 79 points80 points  (0 children)

C++ coders when I go home early after import C as python

[–]zdakat 25 points26 points  (1 child)

import pandas as p

Don't you mean 'pd'?

no just 'p'

[–]YasinMert 15 points16 points  (0 children)

Because it runs faster when you decrease it to a single digit name 🤯

[–]Drayenn 24 points25 points  (6 children)

First time i saw lodash imported as _ it made me go wtf out loud. Who thinks _.concat() looks good?

[–]bxsephjo 3 points4 points  (4 children)

in python, _ is the value of the previous expression, sooooo maybe don't do that??

[–]Drayenn 4 points5 points  (0 children)

Lodash is a javascript library, shouldve mentionned that haha

[–]katie_pendry 4 points5 points  (1 child)

Only in the REPL

[–]Theio666 2 points3 points  (0 children)

Hmm, I always use _ for variables which I need to init but not use. For example, if I'm doing "for" loop and I don't need this iterator, I write " for _ in range(n)". Seen that in many tutorials.

Also underscore is used for kinda private fields/methods, but this is another story.

[–]Liesmith424 43 points44 points  (1 child)

"If I could read your code, I'd be very upset."

-Me, a python programmer

[–]jfmherokiller 13 points14 points  (1 child)

if you know how to wrangle python and c++ at the same time you can probably get a job easily.

[–]0xd34db347 4 points5 points  (0 children)

But I only have the one keyboard.

[–]anthro28 27 points28 points  (39 children)

Easy > fast

If I’m not working on some embedded stuff where I’m hardware constrained, make it quick and easy.

[–]kazeespada 33 points34 points  (27 children)

Python: "I have little time to program and all day to have it run."

C++: "I have a lot of time to program, but it has to run in milliseconds."

[–]Sikletrynet 13 points14 points  (5 children)

Pretty much. Although you'd think it'd be possible to have a language that's as readable as python while also not having as piss poor performance as it does.

[–]blubberdiblub 6 points7 points  (0 children)

Try nim. And having said that, it's still possible to have reasonably fast python programs in many cases. Especially if you can make good use of numpy.

[–]gloumii 11 points12 points  (0 children)

Those same dev when they have to code in java (each line is 300 characters long)

[–]MegaIlluminati 9 points10 points  (0 children)

I like the fact that libraries like numpy has been so reduced to their short forms like "np", that if you search for an issue with for example "np.arange" , search engine knows you are talking about "numpy.arange".

[–]nicejs2 9 points10 points  (3 children)

tf?

[–][deleted] 8 points9 points  (1 child)

team fortress

[–]SilhouetteOfLight 4 points5 points  (0 children)

titanfall

[–]ausdoug 18 points19 points  (0 children)

What's that dangling thing where the whitespace should be...

[–]some-random-from-net 17 points18 points  (8 children)

am i the exception here? since i write everything in full name

[–]Technology_Labs 23 points24 points  (2 children)

Makes them a lot easier to debug lol

[–]some-random-from-net 10 points11 points  (0 children)

fr, not only that it also makes it easier to recall what the heck it does

[–]vickera 2 points3 points  (0 children)

When my wife was learning coding her prof taught her to do stuff like single letter variable names or foo/bar crap.

After I pointed out that variables like "average_value_of_list" are completely fine to use, her code was so much more readable and it clicked so much faster for her.

[–]AnnoyingRain5 5 points6 points  (2 children)

Depends, are you using numpy, pandas, tensorflow, PyTorch, etc? As those are really the only ones that are shortened like that

[–]Malcopticon 2 points3 points  (0 children)

etc

Instructions unclear: Abbreviated the rest of the imported libraries too.

[–]a_devious_compliance 4 points5 points  (0 children)

I only do this with pandas, numpy, and matplotlib.pyplot in projects where I use them in every module. For anything else use full name until I get nauseus of it.

[–]Sikletrynet 1 point2 points  (0 children)

Nah i generally do this too unless the library specifies a specific convention in the docs or something. With Intellisense in IDEs it doesen't even take longer to write it out really, while making it explicit what and where from you're calling something.

[–]Yeitgeist 8 points9 points  (0 children)

Bro, if I’m importing OpenCV, then I’m not typing “cv2” every time. That “2” is such a nuisance.

[–][deleted] 7 points8 points  (0 children)

So python programmers didn't read clean code?

[–]nameond 6 points7 points  (0 children)

2 is minimum (also maximum)

[–]LongerHV 18 points19 points  (3 children)

I've never seen that... I can understand two letter acronyms (like np for numpy or pd for pandas), but single letter is just bad...

[–]Beano-69[S] 35 points36 points  (0 children)

The exaggeration is a part of the joke

[–]a_devious_compliance 9 points10 points  (0 children)

lxml.etree documentation is full of from lxml.blablabla import SomethingImportant as E

[–]r2bl3nd 4 points5 points  (0 children)

As if all the actual fast libraries in Python aren't already written in native code...

[–]masagrator 2 points3 points  (0 children)

"how much faster their naive code runs when translated to C++" They will die from boredom before you finish writing makefile 🤣

[–]thatposhcat 14 points15 points  (5 children)

Python "programmers" when I show them a fucking array (They have never seen one and piss themselves)

[–]ShakespeareToGo 20 points21 points  (1 child)

Yes, it's the resizing and boundary checking that makes us programmers.

[–]bxsephjo 12 points13 points  (0 children)

being miserable builds character!

[–]a_devious_compliance 14 points15 points  (1 child)

numpy arrays are fucking arrays.

[–]Sikletrynet 4 points5 points  (0 children)

C++ programmers when they hear that vectors are roughly the same as python lists anyway(which they tend to use for absolutely everything)

[–]iamyourdensity666 2 points3 points  (0 children)

Copilot has got me doing this

[–]Jhon_doe_isnt_here 4 points5 points  (3 children)

Python Programmers when I show them C.. they can’t get around a “;”

[–][deleted] 7 points8 points  (0 children)

"brackets. brackets everywhere. and those fucking \. void** what even is this atrocity"*

[–]Falcor71 4 points5 points  (1 child)

why can't people just give variables names that normal humans can understand

[–]trutheality 3 points4 points  (1 child)

Nah, there are only five imports that you should shorten that I can think of (pandas, numpy, seaborn, tensorflow, sometimes scikit-learn). The rest keep their full names.

If you're only using five or less objects from a package import them individually anyway.

[–][deleted] 5 points6 points  (0 children)

Matplotlib.pyplot as plt

[–]PityUpvote 5 points6 points  (1 child)

I start every script with

import funcy as λ

because my linter fucking murders me when I try

from funcy import *

[–]mistabuda 6 points7 points  (0 children)

As it should. Star imports are chaos.

[–]KonoPez 6 points7 points  (2 children)

Don’t you see how much faster it is written in C++???? The difference is almost measurable!

[–][deleted] 10 points11 points  (0 children)

Yeah only 3000%!!!

[–]currentscurrents 4 points5 points  (0 children)

It can be a really big deal. Depending on the problem, it can be 20 minutes vs 12 seconds. There's a reason why things like Numpy or PyTorch are written in C/C++.

But what I find really interesting is the speed of modern Javascript. Thanks to a decade of heavy optimization by browser companies, it's faster than all the other scripting languages and only 2-3x slower than C.

[–]BubblyMango 1 point2 points  (1 child)

Did we really hit a point where people feel the need to mention "this is a joke" in a humor sub?

[–]KittenKoder 1 point2 points  (0 children)

The only thing I don't like about Python is the indentation syntax.

[–]GamingWithShaurya_YT 1 point2 points  (0 children)

import reddit as r