Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48071

Re: My son wants me to teach him Python

References <Pine.LNX.4.64.1306131844240.11512@tau.ceti.pl> <mailman.3219.1371154780.3114.python-list@python.org> <637daa98-9a0e-46ab-bb9a-f5638b7c0038@googlegroups.com> <51bab49a$0$29997$c3e8da3$5496439d@news.astraweb.com>
Date 2013-06-14 17:21 +1000
Subject Re: My son wants me to teach him Python
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3256.1371194515.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jun 14, 2013 at 4:13 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Here's another Pepsi Challenge for you:
>
> There is a certain directory on your system containing 50 text files, and
> 50 non-text files. You know the location of the directory. You want to
> locate all the text files in this directory containing the word
> "halibut", then replace the word "halibut" with "trout", but only if the
> file name begins with a vowel.

That sounds extremely contrived, to be honest. Try this one: Massage a
set of MySQL dump files (text, pure SQL) so they can be imported into
PostgreSQL. I'll leave out my Wednesday's encoding headaches (MySQL
produced so-called "UTF-8" output that contained "don\222t" - boggle!)
and restrict this challenge to one thing:

CREATE TABLE blah
(
    blah INT(11) blah blah
);

All through the CREATE TABLE statements, integer fields are followed
by (11), and smallint fields by something else - (9) I think? - and
you have no guarantee that they'll be exactly these numbers, but they
will immediately follow the word INT.

Okay. I can hear some of you screaming "Regular expression!!", and
others yelling "Search across files, any good editor can do that!!". I
happened to use sed for the job. Bear in mind, there are heaps of
other files in the directory, so do this only on *.sql.

Any point-and-click solution to this is likely to end up cheating and
calling on some system that uses text strings (eg regexps). I'd like
to see any solution that proves me wrong, if only out of morbid
curiosity. I'm 100% confident that it won't be faster than me with
sed, or a Perl fanatic with a good regex.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: My son wants me to teach him Python Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-13 21:18 +0100
  Re: My son wants me to teach him Python Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-13 20:33 -0700
    Re: My son wants me to teach him Python Chris Angelico <rosuav@gmail.com> - 2013-06-14 14:02 +1000
      Re: My son wants me to teach him Python Anssi Saari <as@sci.fi> - 2013-06-14 15:02 +0300
        Re: My son wants me to teach him Python Chris Angelico <rosuav@gmail.com> - 2013-06-15 03:12 +1000
    Re: My son wants me to teach him Python Chris Angelico <rosuav@gmail.com> - 2013-06-14 14:05 +1000
      Re: My son wants me to teach him Python Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-16 12:04 -0700
        Re: My son wants me to teach him Python Chris Angelico <rosuav@gmail.com> - 2013-06-17 07:52 +1000
          Re: My son wants me to teach him Python Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-16 15:33 -0700
            Re: My son wants me to teach him Python Alister <alister.ware@ntlworld.com> - 2013-06-17 21:11 +0000
    Re: My son wants me to teach him Python Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-14 06:11 +0100
    Re: My son wants me to teach him Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-14 06:13 +0000
      Re: My son wants me to teach him Python Chris Angelico <rosuav@gmail.com> - 2013-06-14 17:21 +1000
      Re: My son wants me to teach him Python Tim Chase <python.list@tim.thechases.com> - 2013-06-14 05:41 -0500
        Re: My son wants me to teach him Python Alister <alister.ware@ntlworld.com> - 2013-06-14 15:35 +0000
      Re: My son wants me to teach him Python Neil Cerutti <neilc@norwich.edu> - 2013-06-14 16:01 +0000
        Re: My son wants me to teach him Python Chris Angelico <rosuav@gmail.com> - 2013-06-15 03:14 +1000
      Re: My son wants me to teach him Python Jason Swails <jason.swails@gmail.com> - 2013-06-14 13:03 -0400
    Re: My son wants me to teach him Python Jason Swails <jason.swails@gmail.com> - 2013-06-14 02:28 -0400
    Re: My son wants me to teach him Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-14 20:12 -0400

csiph-web