Why are String Formatted Queries Considered So Magical?
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Sat Jul 3 22:33:44 EDT 2010
In message <pan.2010.06.29.09.35.18.594000 at nowhere.com>, Nobody wrote:
> On Tue, 29 Jun 2010 12:30:36 +1200, Lawrence D'Oliveiro wrote:
>
>>> Seriously, almost every other kind of library uses a binary API. What
>>> makes databases so special that they need a string-command based API?
>>
>> HTML is also effectively a string-based API.
>
> HTML is a data format. The sane way to construct or manipulate HTML is via
> the DOM, not string operations.
What is this “DOM” of which you speak? I looked here
<http://docs.python.org/library/>, but can find nothing that sounds like
that, that is relevant to HTML.
>> And what about regular expressions?
>
> What about them? As the saying goes:
>
> Some people, when confronted with a problem, think
> "I know, I'll use regular expressions."
> Now they have two problems.
>
> They have some uses, e.g. defining tokens[1]. Using them to match more
> complex constructs is error-prone ...
What if they’re NOT more complex, but they can simply contain user-entered
data?
>> And all the functionality available through the subprocess
>> module and its predecessors?
>
> The main reason why everyone recommends subprocess over its predecessors
> is that it allows you to bypass the shell, which is one of the most
> common sources of the type of error being discussed in this thread.
How would you deal with this, then: I wrote a script called ExtractMac, to
convert various old Macintosh-format documents accumulated over the years
(stored in AppleDouble form by uploading to a Netatalk server) to more
cross-platform formats. This has a table of conversion commands to use. For
example, the entries for PICT and TEXT Macintosh file types look like this:
"PICT" :
{
"type" : "image",
"ext" : ".png",
"act" : "convert %(src)s %(dst)s",
},
"TEXT" :
{
"type" : "text",
"ext" : ".txt",
"act" : "LineEndings unix <%(src)s >%(dst)s",
},
The conversion code that uses this table looks like
Cmd = \
(
Act.get("act", "cp -p %(src)s %(dst)s")
%
{
"src" : ShellEscape(Src),
"dst" : ShellEscape(DstFileName),
}
)
sys.stderr.write("Doing: %s\n" % Cmd)
Status = os.system(Cmd)
How much simpler would your alternative be? I don’t think it would be
simpler at all.
More information about the Python-list
mailing list