Re: KeyError: self._index[x]

2018-05-07 Thread tango ward
Thanks, now I understand. Thank you so much for being so helpful to a newbie same with Sir Adrian. On Tue, May 8, 2018 at 12:58 PM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Monday, May 7, 2018, tango ward wrote: > >> I didn't know it. Is it only in psycopg2 that the name of t

Re: KeyError: self._index[x]

2018-05-07 Thread David G. Johnston
On Monday, May 7, 2018, tango ward wrote: > I didn't know it. Is it only in psycopg2 that the name of the columns > will use the name of the function? > The server assigns column names - hence the advice to use psql to investigate SQL issues more easily since there is one less moving part to de

Re: KeyError: self._index[x]

2018-05-07 Thread tango ward
Yeah you're right, making 'translate' as the key works. Thanks for pointing this out Sir David "That said, by default the name of columns whose values are derived by a single function call should be the name of the function." I didn't know it. Is it only in psycopg2 that the name of the columns wil

Re: KeyError: self._index[x]

2018-05-07 Thread tango ward
Shall I loop using the 'translate' as key to my row? On Tue, May 8, 2018 at 12:10 PM, Adrian Klaver wrote: > On 05/07/2018 08:11 PM, tango ward wrote: > >> Sorry, accidentally pressed send. >> >> >> cur_p = conn_pr(cursor_factory=psycopg2.extras.DictCursor) >> cur_t = conn_t.cursor(cursor_factor

Re: KeyError: self._index[x]

2018-05-07 Thread Adrian Klaver
On 05/07/2018 08:11 PM, tango ward wrote: Sorry, accidentally pressed send. cur_p = conn_pr(cursor_factory=psycopg2.extras.DictCursor) cur_t = conn_t.cursor(cursor_factory=psycopg2.extras.DictCursor) cur_t.execute("""     SELECT TRANSLATE(snumber, ' ', '')     FROM s

Re: KeyError: self._index[x]

2018-05-07 Thread Adrian Klaver
On 05/07/2018 08:50 PM, David G. Johnston wrote: On Monday, May 7, 2018, tango ward > wrote: cur_t.execute("""     SELECT TRANSLATE(snumber, ' ', '')     FROM sprofile """) # This will result in KeyError for row in cur

Re: KeyError: self._index[x]

2018-05-07 Thread David G. Johnston
On Monday, May 7, 2018, tango ward wrote: > > cur_t.execute(""" > SELECT TRANSLATE(snumber, ' ', '') > FROM sprofile """) > > # This will result in KeyError > for row in cur_t: > print row['snumber'] > > # This works fine > for row in cur_t: > print row[0] > So ap

Re: KeyError: self._index[x]

2018-05-07 Thread tango ward
Sorry, accidentally pressed send. cur_p = conn_pr(cursor_factory=psycopg2.extras.DictCursor) cur_t = conn_t.cursor(cursor_factory=psycopg2.extras.DictCursor) cur_t.execute(""" SELECT TRANSLATE(snumber, ' ', '') FROM sprofile """) # This will result in KeyError f

KeyError: self._index[x]

2018-05-07 Thread tango ward
Good day, Apologies for asking again. I am trying to remove the whitespace on student number by using TRANSLATE() inside the execute() of psycopg2. Problem that I am getting is, even if I will just print the row with the column name(e.g. row['snumber']), I am getting KeyError error message. The c