Using pipe in a system call

Cecil Westerhof Cecil at decebal.nl
Sat Oct 10 08:17:41 EDT 2015


On Saturday 10 Oct 2015 13:42 CEST, Cecil Westerhof wrote:

> On Saturday 10 Oct 2015 09:45 CEST, Frank Millman wrote:
>
>> "Cecil Westerhof" wrote in message
>> news:87a8rsnkmw.fsf at Equus.decebal.nl...
>>
>> This has got nothing to do with your question (which I found
>> interesting) but I thought I would mention it.
>>
>>> export_spreekwoorden is defined as:
>>> export_spreekwoorden        = '''
>>> SELECT      spreekwoord
>>> FROM        spreekwoorden
>>> ORDER BY    spreekwoord COLLATE LOCALIZED
>>> '''
>>
>> This works fine, but if anyone examines the resulting sql, it is
>> full of extra spaces and newlines.
>>
>> To avoid this, I have adopted this habit -
>>
>> export_spreekwoorden = (
>> "SELECT spreekwoord "
>> "FROM spreekwoorden "
>> "ORDER BY spreekwoord COLLATE LOCALIZED"
>> )
>>
>> To my eye, the result is nicer, at virtually no extra effort. Just
>> don't forget the trailing space on all but the last line.
>
> Good idea, I will adopt it. With one modification: I also put a
> trailing space on the last line. That makes it easier when you
> extend the query. ;-)

I tried it, but it does not make things much better. I used something
like this (with another statement):
    create_links_table  = (
        'CREATE TABLE links (\n'
        '    ID          integer PRIMARY KEY AUTOINCREMENT,\n'
        '    year        integer NOT NULL,\n'
        '    month       integer NOT NULL,\n'
        '    description text    NOT NULL,\n'
        '    URL         text    NOT NULL UNIQUE\n'
        ')\n'
    )

This because I want to be able to print it and get something easy to
understand. I prefer:
CREATE TABLE links (
    ID          integer PRIMARY KEY AUTOINCREMENT,
    year        integer NOT NULL,
    month       integer NOT NULL,
    description text    NOT NULL,
    URL         text    NOT NULL UNIQUE
)
above:
CREATE TABLE links ( ID          integer PRIMARY KEY AUTOINCREMENT, year        integer NOT NULL, month       integer NOT NULL, description text    NOT NULL, URL         text    NOT NULL UNIQUE\n)

It gets rid of the spaces before, but for the rest it does not make
much difference. Using
    create_links_table
looks bad, while using
    print(create_links_table)
looks good.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list