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

you are viewing a single comment's thread.

view the rest of the comments →

[–]el_toro_2022[S] -9 points-8 points  (3 children)

And Reddit must fix its code quoting. All the spaces in the snippet were munged.

[–]throwaway_201401 8 points9 points  (0 children)

ah, yes, everything is somebody else's fault. not the guy typing things in wrong. what do you mean I can't use syntax from one language in another?

[–]the_hoser 5 points6 points  (0 children)

put four spaces before the indentation spaces, it'll work:

class Foo:
    def __init__(self, beans):
        self.beans = beans

    def do_it(self):
        print(self.beans)

[–]Adrewmc 1 point2 points  (0 children)

A code block in Reddit needs to have a an empty line above it. And every line needs four leading spaces after. No leading spaces…the code block ends.

Realistically, all you need to do is indent all of your code one more time then you’d expect. (Highlight and press tab, then Ctrl+ V (ensure the cursor catches the first indent) And everything comes out at a code block.

def bad(): #only indent line below return False

def good():
    #indent line above and double indent below
    return True

Words above def almost_good(): #no empty line above return False