[Tutor] Iterating through a list of replacement regex patterns

David Hutto smokefloat at gmail.com
Sun Sep 5 20:00:12 CEST 2010

On Sat, Sep 4, 2010 at 6:16 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sat, 4 Sep 2010 11:57:00 am David Hutto wrote:
>> First of all, I'll respond more thoroughly tomorrow, when I can
>> review what you said more clearly, but for now I'll clarify.
>> Here is the whole code that I'm using:
>> http://pastebin.com/Ak8DFjrb
> David, in genrandfiles() you say this:
>    mkd = 0
>    # This makes the range dir for range of the files for later matched
>    # len of dictionary regex word matches
>    if mkd == 0:
>        makerangedirs()
> Firstly, I don't understand the comment. All the words individually make
> sense, but altogether, they look like something generated by one of
> those monkeys with a typewriter... *wink*

The comments are mainly for me, which is why they get wordy, so I know
exactly why I placed it there.

> Secondly, given that in the previous line you just set mkd = 0, is there
> any possible circumstance where the test "if mkd == 0" would *not*
> succeed? Why don't you just unconditionally call makerangedirs()?
>    mkd = 0
>    makerangedirs()

This only called once to initially create the list of range files. If
it gets called again then it throws an error that the dir
already exists. I haven't checked to see, but I did this because I was
under the impression, that once the while loop is broken it went back
through the function. But once I have it working correctly, I'll
revise it a little more.
>> This is supposed to recreate a thought experiment I've heard about,
>> in which, if you have an infinite amount of monkeys, with an infinite
>> amount of typewriters, they'll eventually spit out Shakespeare.
> Ha ha, well, I don't want to discourage you, but the sun will burn out
> and die long before you get more than a couple of words of Shakespeare
> from this technique.

But that would be the point, that infinite monkeys with infinite typewriters,
would be forced to work until the end of time like good little domesticated
beasts of burden.

> On the other hand, there are ways to randomly generate non-random text
> *incredibly quickly*. See http://en.wikipedia.org/wiki/Weasel_program
> for more detail.

Will take a look at it later. The characters were just to start at the
initial. I was going to replace that with
randomly selected words from the dictionary instead because of the
above mentioned
time constraints on testing it continuously. Although I'd like to see
it, I might not have until
the sun burns out to test the theory.

Thanks for the help though.

> --
> Steven D'Aprano
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list