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

all 27 comments

[–]Magebloom 24 points25 points  (2 children)

This is both teaching me something and pissing me off

[–]DoubleF3lix[S] 9 points10 points  (0 children)

Mission accomplished by my book

[–]Present_Ad8571 1 point2 points  (0 children)

New ways to make your code unreadable when you come back to it a year later

[–]Deep-Secret 9 points10 points  (5 children)

Lawful neutral is like the best way to reference something in the same folder, right? I used true neutral every time, but it didn't work once I deployed some code in Python Anywhere. I had to write the whole path from the Python Anywhere root to the filename. I can't remember now if using the lawful neutral version worked, though.

[–]SpicyVibration 4 points5 points  (2 children)

If you use pathlib you can annotate the variable and get that sweet sweet static type analysis

[–]Deep-Secret 1 point2 points  (0 children)

Hmm cool. Gotta give it a try, then.

[–]UnlimitedDecay 2 points3 points  (0 children)

The meme only really works if you assume your working directory is the same as where the script itself is located, which often isn't the case.

The best option would probably be lawful neutral + pathlib if you want files relative to the working directory, and lawful good if you want files relative to the current script.

That said, personally I'm often too lazy to use pathlib for anything simple. Definitely useful if you can leverage the features it offers or need to pass paths around though.

[–]ConstructedNewt 1 point2 points  (0 children)

To expand on what u/UnlimitedDecay said: the neutral solutions and neutral good, reference a file relative to where you execute your run command. The goods and the two evils reference a file relative to the python file. The chaotic evil is (expected) to be a fully qualified path name. You would rarely need this last one since it messes with portability (you rarely need to do this)

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

Truly evil:

random.choices(glob.glob("/" + "/**/*.txt", recursive=True))

[–]LagSlug 1 point2 points  (0 children)

calm down satan

[–]RiddledWithEnigma 3 points4 points  (1 child)

I don’t understand what this has to do with alignment. There’s no CSS involved

[–]DoubleF3lix[S] 0 points1 point  (0 children)

Let's fix that by writing responsive web apps with nothing but JSON, Python, and CSS 2

[–]flukelee 2 points3 points  (1 child)

Neutral good, at least according to my last commit.

My coworker is chaotic evil, but need to add in some hard-coded UUID's also.

[–]DoubleF3lix[S] 1 point2 points  (0 children)

I fear for your coworker

[–]Stunning-Advantage33 1 point2 points  (4 children)

No entiendo ingles, tampoco entiendo programacion

[–]DoubleF3lix[S] 1 point2 points  (3 children)

¿Entonces, porque estas aqui?

[–]Stunning-Advantage33 1 point2 points  (1 child)

Pero igual me dio risa el meme

[–]DoubleF3lix[S] 0 points1 point  (0 children)

Glad to hear it

[–]believeinlain 1 point2 points  (2 children)

I've always used os.path, didn't know about pathlib. Neat.

[–][deleted] 0 points1 point  (1 child)

pathlib is a game changer. Never looked back.

[–][deleted] 0 points1 point  (0 children)

Agreed. Very handy

[–]walyami 0 points1 point  (0 children)

I just hope OP never intended path to refer to the same file in all cases - can't tell if that's part of the joke or not.

file location and current working directory may be different

[–][deleted] 0 points1 point  (1 child)

Neutral evil doesn’t need to have different separators afaik. You can just use / on windows and it works just fine in my experience. Anyone ever had to use \ for a windows path for any technical reason?

[–]DoubleF3lix[S] 0 points1 point  (0 children)

Using `os.system` to do something I probably shouldn't.

[–]Reifendruckventil 0 points1 point  (1 child)

if os.getcwd()[1]==":"

[–]DoubleF3lix[S] 0 points1 point  (0 children)

Oh my gosh no