Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'error:': 0.05; 'data:': 0.07; 'host,': 0.07; 'try:': 0.07; 'indeed,': 0.09; 'python:': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'charset:iso-8859-7': 0.15; 'row': 0.16; 'subject:Formatting': 0.16; 'syntax.': 0.16; 'sys.exit(0)': 0.16; 'wrote:': 0.17; 'specify': 0.17; 'written': 0.20; 'simpler': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'looks': 0.26; 'existence': 0.29; 'code': 0.31; 'print': 0.32; 'anywhere': 0.33; 'skip:s 30': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'except': 0.36; 'but': 0.36; 'thank': 0.36; 'item': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'skip:l 20': 0.38; 'received:209.85.214': 0.39; 'where': 0.40; 'your': 0.60; 'email addr:yahoo.com': 0.61; '8bit%:95': 0.61; 'more': 0.63; 'skip:= 30': 0.64; 'total': 0.65; '8bit%:100': 0.70; 'as:': 0.75; 'you:': 0.75; 'absolutely': 0.84; '2013': 0.84; 'much,': 0.84; 'skip:\xef 10': 0.84; 'subject:value': 0.84; 'write:': 0.91 X-Received: by 10.49.4.231 with SMTP id n7mr2176875qen.34.1359366283923; Mon, 28 Jan 2013 01:44:43 -0800 (PST) Newsgroups: comp.lang.python Date: Mon, 28 Jan 2013 01:44:43 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.68.70.179; posting-account=DYJQ-woAAACEPH85Au2BhUVfFTfSfVa4 References: <6ad78df4-0ec0-4760-8f5a-5ecf129c5e65@googlegroups.com> <63edba3c-55af-4c4c-a311-4188891bfdf0@googlegroups.com> <30d46f31-c056-45cf-8902-213536dc11fc@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 94.68.70.179 MIME-Version: 1.0 Subject: Re: Formatting a column's value output From: =?ISO-8859-7?B?yv7z9OHyINDh8OHk/PDv9evv8g==?= To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: , Message-ID: Lines: 142 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359366844 news.xs4all.nl 6950 [2001:888:2000:d::a6]:39502 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37801 =D4=E7 =CA=F5=F1=E9=E1=EA=DE, 27 =C9=E1=ED=EF=F5=E1=F1=DF=EF=F5 2013 10:50:= 33 =EC.=EC. UTC+2, =EF =F7=F1=DE=F3=F4=E7=F2 Mitya Sirenef =DD=E3=F1=E1=F8= =E5: > On 01/27/2013 03:24 PM, =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD wrote: >=20 > > =EF=BF=BD=EF=BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD, 27 =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD 2013 9:12:16 =EF=BF=BD.=EF=BF=BD. UTC+2,= =EF=BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD = ru...@yahoo.com =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD: >=20 > >> >=20 > > >=20 > > Yes indeed, there is no need to use a loop since i know the exact=20 >=20 > number of items i'am expecting. Thanks you very much for clarifying this= =20 >=20 > to me: >=20 > > One last thing i want to ask you: >=20 > > >=20 > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > > try: >=20 > > cur.execute( '''SELECT host, userOS, browser, hits, lastvisit FROM=20 >=20 > visitors >=20 > > WHERE counterID =3D (SELECT ID FROM counters WHERE URL =3D %s) ORDER B= Y=20 >=20 > lastvisit DESC''', (htmlpage,) ) >=20 > > except MySQLdb.Error, e: >=20 > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) >=20 > > else: >=20 > > data =3D cur.fetchall() >=20 > > >=20 > > for host, useros, browser, hits, lastvisit in data: >=20 > > print ( "" ) >=20 > > >=20 > > for item in host, useros, browser, hits, lastvisit.strftime('%A %e=20 >=20 > %b, %H:%M').decode('cp1253').encode('utf8'): >=20 > > print ( "
%s " % item ) >=20 > > >=20 > > sys.exit(0) >=20 > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > > >=20 > > That would be also written as: >=20 > > >=20 > > for row in data: >=20 > > print ("tr>") >=20 > > for item in row: >=20 > > print( "blah blah blah" ) >=20 > > >=20 > > And that would make the code easier to read and more clear, but its=20 >=20 > that 'lastvisit' column's value than needs formating,hence it makes me=20 >=20 > use the above syntax. >=20 > > >=20 > > Is there any simpler way to write the above working code without the= =20 >=20 > need to specify all of the columns' names into the loop? >=20 >=20 >=20 >=20 >=20 > You can write: >=20 >=20 >=20 > for row in data: >=20 > print ("tr>") >=20 > row =3D list(row) >=20 > row[-1] =3D row[-1].strftime(...) >=20 > for item in row: >=20 > print( "blah blah blah" ) >=20 >=20 >=20 >=20 >=20 > - mitya >=20 >=20 >=20 >=20 >=20 > --=20 >=20 > Lark's Tongue Guide to Python: http://lightbird.net/larks/ >=20 >=20 >=20 > The existence of any evil anywhere at any time absolutely ruins a total >=20 > optimism. George Santayana Thank you very much, your solution makes the code looks so much clearer!