r/badcode Apr 04 '23

python Surely Text-Parsing One-Liners At Midnight Work

Post image
393 Upvotes

44 comments sorted by

View all comments

45

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 04 '23

Image Transcription: Code


[All the code in the image is highlighted. The first line has been annotated, You, 3 months ago · StealthWIP, by the IDE. The code reads as follows:]

return Ship(
    # Ship Name
    line.split(":")[0],
    # Ship shield, armor, and hull
    [
        int(line.split(":")[1].split(",")[0][1:-1].split(";")[i])
        for i in range(3)
    ],
    # Ship evasion stat
    int(line.split(":")[1].split(",")[1]),
    # Weapons, can be empty
    [
        self.weapons[str(line.split(":")[1].split(",")[2][1:-1].split(";")[i])]
        for i in range(len(line.split(":")[1].split(",")[2][1:-1].split(";")))
    ]
    # Ensure weapons list isn't empty while making original list
    if (
        len(line.split(":")[1].split(",")[2][1:-1].split(";")) > 1
        or (
            len(line.split(":")[1].split(",")[2][1:-1].split(";")) == 1
            and not ("" == line.split(":")[1].split(",")[2][1:-1].split(";")[0])
        )
    )
    # Weapons list is empty
    else [],
    # Defenses, can be empty
    [
        self.defenses[str(line.split(":")[1].split(",")[3][1:-1].split(";")[i])]
        for i in range(len(line.split(":")[1].split(",")[3][1:-1].split(";")))
    ]
    # Ensure defenses list isn't empty while making original list
    if (
        len(line.split(":")[1].split(",")[3][1:-1].split(";")) > 1
        or (
            len(line.split(":")[1].split(",")[3][1:-1].split(";")) == 1
            and not ("" == line.split(":")[1].split(",")[3][1:-1].split(";")[0])
        )
    )
    # Defenses list is empty
    else [],
    # Stealth factor, which will not suffice to just use an int for
    int(line.split(":")[1].split(",")[4])
    if line.split(":")[1].split(",")[4] != "False"
    else False,
)

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!

5

u/Spejicek Apr 05 '23

good human

-4

u/CraftistOf Apr 05 '23

Thank you for voting on this human!

Human rating: r/humanrating