Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'else:': 0.03; 'parameters': 0.04; 'subject:Python': 0.06; 'perl,': 0.07; '__name__': 0.09; 'cursor': 0.09; 'line:': 0.09; 'null,': 0.09; 'spaces': 0.09; 'valueerror:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '>>': 0.16; "'__main__':": 0.16; "'a',": 0.16; '23,': 0.16; 'attempted': 0.16; 'message):': 0.16; 'perl.': 0.16; 'rather,': 0.16; 'set()': 0.16; 'spotted': 0.16; 'thread,': 0.16; 'weight,': 0.16; '\xc2\xa0if': 0.16; 'topics': 0.16; 'language': 0.16; 'wrote:': 0.18; 'all,': 0.19; "python's": 0.19; 'example': 0.22; 'programming': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'rules': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; 'aspect': 0.24; 'exists': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; "i've": 0.25; '>': 0.26; 'second': 0.26; 'least': 0.26; 'primary': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'raise': 0.29; 'start,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'towards': 0.31; 'author,': 0.31; 'indentation': 0.31; 'perl': 0.31; 'file': 0.32; 'run': 0.32; 'url:python': 0.33; '(most': 0.33; 'bugs': 0.33; 'comment': 0.34; 'table': 0.34; 'maybe': 0.34; 'skip:d 20': 0.34; 'message.': 0.35; 'beyond': 0.35; 'point.': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; '8bit%:9': 0.36; 'url:listinfo': 0.36; "didn't": 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'step': 0.37; 'skip:& 10': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; 'aspects': 0.39; 'weight': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; 'how': 0.40; 'even': 0.60; 'above,': 0.60; 'blank': 0.60; 'ian': 0.60; 'removing': 0.60; 'skip:\xc2 10': 0.60; 'new': 0.61; 'refer': 0.63; 'more': 0.64; 'taking': 0.65; '30,': 0.65; 'talking': 0.65; '20,': 0.68; 'line,': 0.68; 'subject:there': 0.68; 'caused': 0.69; 'to,': 0.72; 'cost,': 0.84; 'draws': 0.84; 'id,': 0.84; 'kennedy': 0.84; 'message)': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc :content-type; bh=Uz2s87LGHc9u6Dqbldp8x5y0QT5xzpGOfFloI22A+qU=; b=i8FfieiQGWnPtWSABPsKfHVdyNPTAg3Bx2hu1Go0tN8FF7s2mvp5QUV/MtiT6QcEE0 d5ZKd4jKtF86I2lMLOAY1kpSKsnDp/1bxCsX5AGMOxKzocGr2rUACAHwRybykQTaqy5Z lwEF1A/Xvb43YCaVcDQquHCW2a97YuQQzC7qHUyIThz2ZW+0uBXL5C78RHpbi/PjlLCp 9pp0VwFJFURVBDjbnmxSUU3GiQHECMXoqA7CE6DY4O+h8n4pAUJVkdYVI5gVBGPLKeHy cIXjPEsAdsoaaMSaf4LsugoqDFGffZ3wkNBlCo0pl9o+Pe4rejLtSi4uPrC2+qFs/HtX Jfhw== X-Received: by 10.112.224.162 with SMTP id rd2mr5218170lbc.95.1413831869374; Mon, 20 Oct 2014 12:04:29 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <9a0c67be-de3a-4770-bf06-e158783bfff0@googlegroups.com> <54424691$0$12978$c3e8da3$5496439d@news.astraweb.com> From: Juan Christian Date: Mon, 20 Oct 2014 17:04:09 -0200 Subject: Re: Is there an easy way to control indents in Python Cc: Python Content-Type: multipart/alternative; boundary=001a113604ec58ac770505df628f X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 239 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413831877 news.xs4all.nl 2897 [2001:888:2000:d::a6]:36525 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79324 --001a113604ec58ac770505df628f Content-Type: text/plain; charset=UTF-8 Ok, new code using ?: import sqlite3 db = sqlite3.connect('db.sqlite') def create_db(): db.execute(''' CREATE TABLE TOPICS( ID INT PRIMARY KEY NOT NULL, URL VARCHAR NOT NULL, AUTHOR VARCHAR NOT NULL, MESSAGE VARCHAR NOT NULL ); ''') def insert_db(_id, url, author, message): db.execute("INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES (?, ?, ?, ?)", (_id, url, author, message)) db.commit() def get_db(_id): cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE ID = ?", (_id)) return cursor.fetchone() if __name__ == '__main__': create_db() insert_db(12, 'abc.com', 'a', 'b') print(get_db(12)) db.close() ------------- But now when I execute I get Traceback (most recent call last): File ".\sql.py", line 30, in print(get_db(12)) File ".\sql.py", line 23, in get_db cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE ID = ?", (_id)) ValueError: parameters are of unsupported type ------------- And the second time, again, I get Traceback (most recent call last): File ".\sql.py", line 28, in create_db() File ".\sql.py", line 14, in create_db ''') sqlite3.OperationalError: table TOPICS already exists On Mon, Oct 20, 2014 at 3:57 PM, Ian Kelly wrote: > On Mon, Oct 20, 2014 at 11:54 AM, Ian Kelly wrote: > > On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy > wrote: > >> Not having ever attempted to go beyond even the basics of Perl, the > aspect that causes me to refer to Perl 'dismissively' as well comment in > this thread, is that I don't find Perl to be an aesthetically pleasing > language and I consider Python functions which have no blank lines in them > to be a small step towards Perl. > >> > >> Some people do not like Python's indentation rules but for me it's a > large part of what draws me to program in Python. Spaces for indentation > and blank lines are both aspects of how I like to program. > >> > >> I write in Python because I like to, not because I have to. > >> > >> I think the only reason I might code a function with no blank lines was > if I was programming in a language that using blank lines caused it to run > too slowly. > > > > So to be clear, I'm not talking about taking a function like this > > (contrived) example and just removing the blank line: > > > > def find_path(graphdata, start, end): > > edges = map(str.split, lines) > > graph = collections.defaultdict(list) > > for node1, node2, weight in edges: > > graph[node1].append((node[2], int(weight))) > > graph[node2].append((node[1], int(weight))) > > > > open_heap = [(0, (start,))] > > closed_set = set() > > while open_heap: > > cost, path = heapq.heappop(open_heap) > > current_node = path[-1] > > if current_node == end: > > return path > > if current_node in closed_set: > > continue > > for next_node, weight in graph[current_node]: > > heapq.heappush((cost + weight, path + (next_node,))) > > closed_set.add(current_node) > > else: > > raise ValueError("No path from start to end") > > > > Rather, I'm saying that where the blank line is should be the start of > > a new function. There would still be a blank line, just no longer > > inside the function. > > > > Now, maybe you think there should be more blank lines in the above, in > > which case we'll just have to disagree on that point. > > By the way, I didn't test that at all, which is why I've spotted at > least two bugs in it since sending the message. > -- > https://mail.python.org/mailman/listinfo/python-list > --001a113604ec58ac770505df628f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ok, new code using ?:

import sqlit= e3

db =3D sqlite3.connect('db.sqlite')


def create_db():
=C2=A0 =C2= =A0 db.execute('''
=C2=A0 =C2=A0 CREATE TABLE TOPICS(
=C2=A0 =C2=A0= ID INT PRIMARY KEY NO= T NULL,
=C2=A0 =C2=A0 = URL VARCHAR NOT NULL,
=C2=A0 =C2=A0 AUTHOR VARCHAR NOT NULL,
=C2=A0= =C2=A0 MESSAGE VARCHA= R NOT NULL
=C2=A0 =C2=A0 );
=C2=A0 =C2=A0 ''')


def= insert_db(_id, url, author, message):
=C2=A0 =C2=A0 db.execute(&= quot;INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES (?, ?, ?, ?)"= ;, (_id, url, author, message))
=C2=A0 =C2=A0 db.commit()


def get_db(_id):
cursor =3D db.execute("SELECT ID, = URL, AUTHOR, MESSAGE FROM TOPICS WHERE ID =3D ?", (_id))
return cursor.fetchone()


if __name__ =3D=3D '__main__'= :
create_db()<= /div>
insert_db(12, = 'abc.com', 'a', 'b')=
print(get_db(= 12))
db.close(= )

-------------

But= now when I execute I get=C2=A0

Traceback (mo= st recent call last):
=C2=A0 File ".\sql.py", line 30, = in <module>
=C2=A0 =C2=A0 print(get_db(12))
=C2= =A0 File ".\sql.py", line 23, in get_db
=C2=A0 =C2=A0 c= ursor =3D db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHER= E ID =3D ?", (_id))
ValueError: parameters are of unsupporte= d type

-------------

And the second time, again, I get

Traceback= (most recent call last):
=C2=A0 File ".\sql.py", line = 28, in <module>
=C2=A0 =C2=A0 create_db()
=C2=A0 = File ".\sql.py", line 14, in create_db
=C2=A0 =C2=A0 &#= 39;'')
sqlite3.OperationalError: table TOPICS already exi= sts

On Mon, Oct 20, 2014 at 3:57 PM, Ian Kelly <ian.g.kelly@gmail.com<= /a>> wrote:
On Mon, Oct 20, 2014 at 11:54 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Mon, Oct 20, 2014 at 9:54 AM, Simon Kennedy <sffjunkie@gmail.com> wrote:
>> Not having ever attempted to go beyond even the basics of Perl, th= e aspect that causes me to refer to Perl 'dismissively' as well com= ment in this thread, is that I don't find Perl to be an aesthetically p= leasing language and I consider Python functions which have no blank lines = in them to be a small step towards Perl.
>>
>> Some people do not like Python's indentation rules but for me = it's a large part of what draws me to program in Python. Spaces for ind= entation and blank lines are both aspects of how I like to program.
>>
>> I write in Python because I like to, not because I have to.
>>
>> I think the only reason I might code a function with no blank line= s was if I was programming in a language that using blank lines caused it t= o run too slowly.
>
> So to be clear, I'm not talking about taking a function like this<= br> > (contrived) example and just removing the blank line:
>
> def find_path(graphdata, start, end):
>=C2=A0 =C2=A0 =C2=A0edges =3D map(str.split, lines)
>=C2=A0 =C2=A0 =C2=A0graph =3D collections.defaultdict(list)
>=C2=A0 =C2=A0 =C2=A0for node1, node2, weight in edges:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0graph[node1].append((node[2], int(wei= ght)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0graph[node2].append((node[1], int(wei= ght)))
>
>=C2=A0 =C2=A0 =C2=A0open_heap =3D [(0, (start,))]
>=C2=A0 =C2=A0 =C2=A0closed_set =3D set()
>=C2=A0 =C2=A0 =C2=A0while open_heap:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cost, path =3D heapq.heappop(open_hea= p)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0current_node =3D path[-1]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if current_node =3D=3D end:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return path
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if current_node in closed_set:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for next_node, weight in graph[curren= t_node]:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0heapq.heappush((cost + = weight, path + (next_node,)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0closed_set.add(current_node)
>=C2=A0 =C2=A0 =C2=A0else:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0raise ValueError("No path from s= tart to end")
>
> Rather, I'm saying that where the blank line is should be the star= t of
> a new function. There would still be a blank line, just no longer
> inside the function.
>
> Now, maybe you think there should be more blank lines in the above, in=
> which case we'll just have to disagree on that point.

By the way, I didn't test that at all, which is why I'v= e spotted at
least two bugs in it since sending the message.
--
https://mail.python.org/mailman/listinfo/python-list

--001a113604ec58ac770505df628f--