• (cs)

    People who use Python are HEAVY with Whitespace. <tic>

  • (cs)

    My eyes, zie goggles, they do nothing!

  • eld (unregistered)

    it's the mayan temple pattern!

  • (cs)

    This is stupid in any language, but this shows that crappy programmers use Python too and not only VB or PHP.

  • QJo (unregistered)

    Let me guess: the real WTF is the use of "elif" when everyone knows that it should be "eleph". It's short for "elephant", isn't it?

  • (cs)
    Jakob continues, "I can only hope this language doesn't have a goto statement…"

    Well, not natively, but there is a module for that

  • Raniz (unregistered)

    I think this is the first time I've seen an algorithm that's O(n^15)

  • Richie Hindle (unregistered)

    The Real WTF is goto for Python.

  • Chris (unregistered)

    Surley the Python thing is barely here nor there - if you were going to write like this, you'd indent pretty much the same in languages like Java or C#?

  • (cs)

    Wow... that's so bad I was compelled to fix it...

    def genpassword(wlc, maxchar, txt, verbose):
        wlclen = len(wlc)
        txtfile = open(txt, 'w')
        for i in xrange(wlclen ** maxchar):
            word = ""
            for j in xrange(maxchar):
                word = wlc[i % wlclen] + word
                i /= wlclen
            if verbose:
                print word
            txtfile.write(word + '\n')
        txtfile.close()
    

    The beauty of the original function is that if (wlc[-1] != '9zZzZZ'[List - 1]), then the function will generate a file with (len(wlc) ** 15) lines: assuming wlc is alphanumeric, this would be 221073919720733357899776 lines.

  • Daniel (unregistered)
    for i in range(len(word)):
        lword[i] = "Z"

    Is it code for Zliminator?

    Serieously, what does it do? Create all possible combinations? I thought that if function name is generate_password you need to generate only one password.

  • QJo (unregistered) in reply to Chris
    Chris:
    Surley the Python thing is barely here nor there - if you were *going* to write like this, you'd indent pretty much the same in languages like Java or C#?

    On the contrary. I've seen work from a programmer who refused to use indentation at all because "all that white space is wasteful." And no, his code was rarely as streamlined and efficient as the example included (he eschewed loops for a similar reason, and refused to use subroutines because, as he said, the overhead of handling the stack may significantly slow operation down, or something). Fortunately I was not required to work for long on the same project.

  • scott (unregistered)
    On the contrary. I've seen work from a programmer who refused to use indentation at all because "all that white space is wasteful."

    And I once worked with a guy who felt the same way about line breaks. Not blank lines, all line breaks, so every line of code was the full width of the editor screen (which thank god back then was 80 characters), naturally all with 1- and 2-char var names. No, I am not kidding.

  • QJo (unregistered) in reply to scott
    scott:
    On the contrary. I've seen work from a programmer who refused to use indentation at all because "all that white space is wasteful."

    And I once worked with a guy who felt the same way about line breaks. Not blank lines, all line breaks, so every line of code was the full width of the editor screen (which thank god back then was 80 characters), naturally all with 1- and 2-char var names. No, I am not kidding.

    Fortunately you can't write like that in FORTRAN as the end of a command is signalled by a line feed.

  • (cs)

    This makes me want to pull out a gun and say "Not Today MF'er!!!"

  • Mijzelf (unregistered)

    Am I missing something, or is this a passwordgenerator without random() function?

  • JolleSax (unregistered)

    It shows pretty clearly though why they call it Python though.

  • Eevee (unregistered) in reply to ubersoldat
    ubersoldat:
    This is stupid in any language, but this shows that crappy programmers use Python too and not only VB or PHP.
    This goes a bit beyond crappy programming; the author of this code is defiantly incompetent.

    Language wars focus too much on how the best devs always write good code and the worst devs always write bad code. There's a huge chunk of mediocrity in the middle of that spectrum, and those are the devs most influenced by the language they use. (Plus it's nice when your language doesn't actively resist your attempts to use it well.)

  • Lawrence Hudson (unregistered)

    That algorithm sucks whatever language it's written in.

  • Olius (unregistered)

    If you squint slightly and turn your head to one side, it kinda looks like a Space Invader.

  • (cs) in reply to JolleSax
    JolleSax:
    It shows pretty clearly though why they call it Python though.

    Is it that it's full of snakes that can bite you in the ass if not careful?

    I think that can happen in any language.

  • (cs) in reply to Mijzelf
    Mijzelf:
    Am I missing something, or is this a passwordgenerator without random() function?

    Given a list of characters (wlc) and a length (maxchar), it prints out all the possible combinations to a file (txt) and if verbose is true it also prints them to screen.

    The List variable is used to tell it when to stop. If that equals 1 it stops when it gets to all 9's, 2 tells it to stop at all z's, 3 all Z's, 4 all z's again, 5 and 6 both all Z's. I don't understand why it repeats the z and Z ones multiple times. Also, this is a silly way to get it to stop to begin with.

    To show a very simple one, if you gave it wlc = '89', maxchar = 2 and List = 1 you'll just get this:

    88 89 98 99

    Unless I'm also missing something.

  • Some damn Yank (unregistered) in reply to QJo
    QJo:
    scott:
    On the contrary. I've seen work from a programmer who refused to use indentation at all because "all that white space is wasteful."

    And I once worked with a guy who felt the same way about line breaks. Not blank lines, all line breaks, so every line of code was the full width of the editor screen (which thank god back then was 80 characters), naturally all with 1- and 2-char var names. No, I am not kidding.

    Fortunately you can't write like that in FORTRAN as the end of a command is signalled by a line feed.
    Ah, FORTRAN. Those were the days. You'll find far fewer "c"s in FORTRAN than you'll find semicolons in most other languages. Why the others make the programmer do the compiler's job I never understood. Semicolons to end a line only make sense in Pascal, because Pascal was intended to be "compiled" by the teacher. For the rest, if the compiler can't figure out where the line ends, what good is it?

    CAPTCHA: esse - Enjoy my comments, or esse!

  • JDege (unregistered) in reply to QJo
    QJo:
    Fortunately you can't write like that in FORTRAN as the end of a command is signalled by a line feed.
    If you're doing FORTRAN right, the end of a command is signaled by the end of the card.
  • Mr X (unregistered) in reply to Some damn Yank

    Pascal didn't use semicolon to end a line - it used it to concatenate two statements. The effect is similar, but symantically different.

  • Samuel L. Jackson (unregistered) in reply to Silfax
    Silfax:
    JolleSax:
    It shows pretty clearly though why they call it Python though.

    Is it that it's full of snakes that can bite you in the ass if not careful?

    I think that can happen in any language.

    I have had it with this motherfuckin' Python on this motherfuckin' website!
  • Mike MacKenzie (unregistered) in reply to Some damn Yank

    FORTRAN line continuation is analogous to IBM line printer continuation. Teletypes used line feed/ carriage returns to move the lines, IBM printers use magic characters at the beginning of the line to tell the printer what to do. IBM did this so they could patent it, since LF/CR was obvious and had already been invented.

  • (cs) in reply to ubersoldat
    ubersoldat:
    This is stupid in any language, but this shows that crappy programmers use Python too and not only VB or PHP.
    Indeed. That is why I advocate the use of "difficult" languages like Haskell, Common Lisp or Factor. The sort of programmer who writes today's WTF wouldn't be able to get anything to work in those languages.
  • (cs) in reply to Olius
    Olius:
    If you squint slightly and turn your head to one side, it kinda looks like a Space Invader.

    If you squint slightly and turn your head to one side, it kinda looks like sunglasses for Bill the Cat. http://www.murphdogg.com/images/bill.jpg

  • Rfoxmich (unregistered)

    I am sick and tired of these motherfuckin snakes on this motherfuckin plane

  • Slapout (unregistered)

    i6 = i6 ?

  • (cs)

    Whacha gonna do, Brother, when this 15 iterator python comes crashing down on you?!

  • Macho (unregistered) in reply to Mr X
    Mr X:
    Pascal didn't use semicolon to end a line - it used it to concatenate two statements. The effect is similar, but symantically different.

    I love how you concatenated “semantically” and “syntactically” into one word.

  • airdrik (unregistered)

    Of course recursion is a bad thing because setting up base cases is hard and you never know if you accidentally miss a base case and end up recursing too far, plus it increases your memory useage and makes everything in general slower!

    def recursiveGP(wlc, maxchar):
        if maxchar == 0:
            yield ''
        else:
            for c in wlc:
                for word in recursiveGP(wlc, maxchar-1):
                    yield c + word
    
    def genpassword(wlc, maxchar, txt, verbose):
        with open(txt, 'w') as txtfile:
            for word in recursiveGP(wlc, maxchar):
                txtfile.write(word + '\n')
                if int(verbose) == 1:
                    print word
    

    (for functional equivalence, you would need another recursion depth counter which starts at 15, a check which only concatenates the next digit if len(wlc) < maxchar, and include the checks for 9s, Zs, and zs in the outer loop)

    Of course another WTF is assuming they don't want to generate passwords with more than 15 characters.

    The crap about checking for 9s, Zs and zs at the end is a workaround to try and keep it from taking forever.

    Of course, I could mention all of the things scattered throughout the code which just screams: I'm a C programmer who knows nothing about Python programming; but that's half of the fun of these Code SODs.

  • Child of the '90s (unregistered) in reply to frits
    frits:
    Whacha gonna do, Brother, when this 15 iterator python comes crashing down on you?!
    What the h*** are you talking about?
  • (cs) in reply to scott
    scott:
    On the contrary. I've seen work from a programmer who refused to use indentation at all because "all that white space is wasteful."

    And I once worked with a guy who felt the same way about line breaks. Not blank lines, all line breaks, so every line of code was the full width of the editor screen (which thank god back then was 80 characters), naturally all with 1- and 2-char var names. No, I am not kidding.

    Former MS BASIC programmer.

  • airdrik (unregistered) in reply to Slapout
    Slapout:
    i6 = i6 ?
    to be doublly sure that he initialized the variable. After all since you can just create variables any-old-where in python, he could only be so sure that the variable did get created before it actually needed to be created.

    captcha mara: this is a good example of how to mara python program with C-isms.

  • Harrow (unregistered) in reply to Some damn Yank
    Some damn Yank:
    Ah, FORTRAN. Those were the days. You'll find far fewer "c"s in FORTRAN than you'll find semicolons in most other languages. Why the others make the programmer do the compiler's job I never understood. Semicolons to end a line only make sense in Pascal, because Pascal was intended to be "compiled" by the teacher. For the rest, if the compiler can't figure out where the line ends, what good is it?
    Borland's ObjectPAL language (used in Paradox for Windows) doesn't use any markers -- not semicolons, not line ends, nothing -- to terminate statements. The compiler figures out where the statement ends via context. (Apparently a statement ends when the next token would trigger a grammar error.)

    When I first saw this I was sure that grammatical errors would be flagged miles away from where they occurred, but in deed this almost never happens. Turns out, even inexperienced coders rarely make the mistake of concatenating two operators or two operands.

    I used this language heavily for over a decade and never felt the lack of explicit statement terminators.

    -Harrow.

  • (cs) in reply to Child of the '90s
    Child of the '90s:
    frits:
    Whacha gonna do, Brother, when this 15 iterator python comes crashing down on you?!
    What the h*** are you talking about?
    Brooke Hogan's Dad.
  • Bob (unregistered) in reply to Harrow
    Harrow:
    Some damn Yank:
    Ah, FORTRAN. Those were the days. You'll find far fewer "c"s in FORTRAN than you'll find semicolons in most other languages. Why the others make the programmer do the compiler's job I never understood. Semicolons to end a line only make sense in Pascal, because Pascal was intended to be "compiled" by the teacher. For the rest, if the compiler can't figure out where the line ends, what good is it?
    Borland's ObjectPAL language (used in Paradox for Windows) doesn't use any markers -- not semicolons, not line ends, nothing -- to terminate statements. The compiler figures out where the statement ends via context. (Apparently a statement ends when the next token would trigger a grammar error.)

    When I first saw this I was sure that grammatical errors would be flagged miles away from where they occurred, but in deed this almost never happens. Turns out, even inexperienced coders rarely make the mistake of concatenating two operators or two operands.

    I used this language heavily for over a decade and never felt the lack of explicit statement terminators.

    -Harrow.

    I've used BobX for well over a decade now and never felt the need for anything else.

    Also, don't put a "signature" at the bottom of your posts. It make you look like a douche.

  • Monkey Fighting from Monday to Friday (unregistered) in reply to Samuel L. Jackson
    Samuel L. Jackson:
    I have had it with this motherfuckin' Python on this motherfuckin' website!

    You win the internet for today. I LOL'd, this made my day.

  • Bob (the real one) (unregistered) in reply to Bob
    Bob:
    Harrow:
    Some damn Yank:
    Ah, FORTRAN. Those were the days. You'll find far fewer "c"s in FORTRAN than you'll find semicolons in most other languages. Why the others make the programmer do the compiler's job I never understood. Semicolons to end a line only make sense in Pascal, because Pascal was intended to be "compiled" by the teacher. For the rest, if the compiler can't figure out where the line ends, what good is it?
    Borland's ObjectPAL language (used in Paradox for Windows) doesn't use any markers -- not semicolons, not line ends, nothing -- to terminate statements. The compiler figures out where the statement ends via context. (Apparently a statement ends when the next token would trigger a grammar error.)

    When I first saw this I was sure that grammatical errors would be flagged miles away from where they occurred, but in deed this almost never happens. Turns out, even inexperienced coders rarely make the mistake of concatenating two operators or two operands.

    I used this language heavily for over a decade and never felt the lack of explicit statement terminators.

    -Harrow.

    I've used BobX for well over a decade now and never felt the need for anything else.

    Also, don't put a "signature" at the bottom of your posts. It make you look like a douche.

    Please show some sensitivity. I had a son who used ObjectPAL, BobX, and put a signature at the bottom of his posts: but that was because he was retarded.

  • Mike (unregistered)
    def genpassword (wlc, maxchar, txt, List, verbose):
      from itertools import product
      txtfile = open(txt,'w')
      for word in product(*[wlc]*maxchar):
        word = ''.join(word)
        if verbose: print word
        txtfile.write(word+"\n")
        if List == 1 and word == "9"*maxchar: break
        if List in (2,4) and word == "z"*maxchar: break
        if List in (3,5,6) and word == "Z"*maxchar: break
      txtfile.close()
    
  • shash (unregistered)

    Pfft! This is freakin' Python!

    from itertools import combinations

    passwords = [[''.join(i) for i in combinations(plm, r)] for r in xrange(2, len(plm)]

    Not exactly the same as that gibberish, but something pretty close, and it's a one-liner!

  • Take that, Hofstadter (unregistered) in reply to Harrow
    Harrow:
    I used this language heavily for over a decade and never felt the lack of explicit statement terminators.

    The real question is whether, after the first year, you felt the need for psychotropic drugs to control your insanity.

    Paradox was EEVIL.

  • Tim (unregistered)

    I hope they generated that source code. However, I don't want to see the source code for the generator.

  • Intchanter (unregistered)

    Luckily, Python includes a multi-purpose module to solve situations like this. It's great for up-front training, gentle correction, meditation, and very occasionally (when the earlier opportunities were sufficiently missed) as a ton of lead bricks:

    import this

  • (cs)

    I want to die.

  • z00n3$!$ Fan (unregistered) in reply to Intchanter
    Intchanter:
    Luckily, Python includes a multi-purpose module to solve situations like this. It's great for up-front training, gentle correction, meditation, and very occasionally (when the earlier opportunities were sufficiently missed) as a ton of lead bricks:

    import this

    Come on z00n3$!$, do your thing!

  • z00n3$!$ Fan (unregistered) in reply to z00n3$!$ Fan
    z00n3$!$ Fan:
    Intchanter:
    Luckily, Python includes a multi-purpose module to solve situations like this. It's great for up-front insertion, gentle penetration, masturbation, and very occasionally (when the earlier opportunities were sufficiently missed) as a ton of lead dicks:

    import dicks

    Come on z00n3$!$, do your thing!

    Oh WTF, fixed that myself.

Leave a comment on “Python Charmer”

Log In or post as a guest

Replying to comment #:

« Return to Article