Good point, but I think the worst thing about it is using the term re as that is the standard lib’s regular expression library and is quite common, so would cause confusion.
Checked the blame, the second line predates the first by a few years.
I think what happened is the author returned to the file to add something new, typed requests, saw that it wasn't defined and told their IDE to import it.
Yes. That makes sense too. And in VS code it even automatically inserts imports it if it finds typed module in environment. Pretty annoying sometimes tbh.
import requests as re import re as requests import hashlib as string import import sys as np import os as pd import numpy as turtle import pandas as zlib
If you pick nicknames for your imports I hate you. Unless that shit is absolutely necessary like you are importing a bunch of different clients and all of them are named client from x import client as x_client; from y import client as y_client or some shit like that.
Also why the fuck does every single data science thing that uses pandas import pandas as pd, and tensor flow as tf, and numpy as np. Just fucking write the whole thing like a normal programmer. This shit isn't code golf, it's real life. We get paid by the keystroke. For every time I gotta scroll back to the top to check what bullshit module you nicknamed I hate you.
Technically not that bad: maybe sometimes you want to call it by the full name for clarity, maybe others you want to use it so many times on a single line that having a shorter alias would make it more readable.
You should never abbreviate just because the full thing is inconvenient to type. Simple, easily recognizable things like kmph or ft are fine, but nobody who looks at re.get(...) is going to immediately recognize that as the requests library (especially since Python already has a built-in module called re that does something completely different).
If you're using the full name of the module that many times in one line that's probably a good indicator you need to separate that one line into multiple lines.
Tell that to every single person who writes pandas/numpy/tensorflow tutorials. pd/np/tf. It makes people think it's okay to just nickname whatever module to whatever the fuck they want.
You should avoid abbreviating just because you are too lazy to retype everything. It is against self documenting code rules and really makes it hard for someone else but you to read it. There are so many autocomplete tools nowadays anyways so that should not be an issue in any case
28
u/sweet-n-sombre Feb 15 '23
I think i know how this happened. Muscle memory.
Dev A: let's make something. Copies some boilerplate code from stack etc.
Later...
Dev A: yo. I ain't not typing r e q u e s t s.. that's lame.
import request as reGood now.Hmm. What about refactoring that earlier code with with full name? Better not touch it, it works.. !
235
u/oj_mudbone Feb 15 '23
Error: module “re” has no function “match”
203
u/pmMe-PicsOfSpiderMan Feb 15 '23
when you copy 2 different stackoverflow answers
73
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Feb 15 '23
Image Transcription: Code
[Other import lines are partially cut off above and below the following visible code:]
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
51
u/tazzadar1337 evil Feb 15 '23
import requests as REEEE34
u/[deleted] Feb 15 '23
They found a way to make regex even harder, 👏
23
u/klamiti Feb 15 '23
import re as requests
7
u/[deleted] Feb 15 '23
this will not go well. then again, can't say much, since even my best code is as readable as a pile of wet shredded paper
5
u/BanishDank Feb 16 '23 edited Feb 16 '23
import requests as re
import re as requests
import hashlib as string
import import sys as np
import os as pd
import numpy as turtle
import pandas as zlib
print(“Farewell World!”)
4
u/pittybrave Feb 15 '23
REEEEEEEEE
3
u/Any-Limit-7282 Feb 16 '23
Import Regequestex as re
5
u/tehtris Feb 16 '23
If you pick nicknames for your imports I hate you. Unless that shit is absolutely necessary like you are importing a bunch of different clients and all of them are named client
from x import client as x_client; from y import client as y_clientor some shit like that.Also why the fuck does every single data science thing that uses pandas import pandas as pd, and tensor flow as tf, and numpy as np. Just fucking write the whole thing like a normal programmer. This shit isn't code golf, it's real life. We get paid by the keystroke. For every time I gotta scroll back to the top to check what bullshit module you nicknamed I hate you.
1
u/mikeyj777 Feb 16 '23
This has got to be a joke. I know I'm a noob, but I've never seen requests given an alias. Especially one this common.
1
u/Plant_Curious Feb 17 '23
Pray you don’t need to do regex
-22
u/jarfil Feb 15 '23 edited Dec 02 '23
CENSORED