On Jan 16, 2017, at 11:34 PM, Peter Otten <__pete...@web.de> wrote:
>
> Gregory Ewing wrote:
>
>> Israel Brewster wrote:
>>> The problem is that, from time to time, I can't get a connection, the
>>> result being that cursor is None,
>>
>> That's your problem right there -- you want a better-beha
On Jan 16, 2017, at 8:01 PM, Gregory Ewing wrote:
>
> Israel Brewster wrote:
>> The problem is that, from time to time, I can't get a connection, the result
>> being that cursor is None,
>
> That's your problem right there -- you want a better-behaved
> version of psql_cursor().
>
> def get_psq
On Jan 16, 2017, at 1:27 PM, Terry Reedy wrote:
>
> On 1/16/2017 1:06 PM, Israel Brewster wrote:
>> I generally use context managers for my SQL database connections, so I can
>> just write code like:
>>
>> with psql_cursor() as cursor:
>>
>>
>> And the context manager takes care of making
Gregory Ewing wrote:
> Israel Brewster wrote:
>> The problem is that, from time to time, I can't get a connection, the
>> result being that cursor is None,
>
> That's your problem right there -- you want a better-behaved
> version of psql_cursor().
>
> def get_psql_cursor():
> c = psql_curso
Terry Reedy wrote:
Traceback (most recent call last):
File "", line 1, in
with None: pass
AttributeError: __enter__
Like he said, you get an AttributeError!
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
Israel Brewster wrote:
The problem is that, from time to time, I can't get a connection, the result
being that cursor is None,
That's your problem right there -- you want a better-behaved
version of psql_cursor().
def get_psql_cursor():
c = psql_cursor()
if c is None:
raise CantGet
On 1/16/2017 1:06 PM, Israel Brewster wrote:
I generally use context managers for my SQL database connections, so I can just
write code like:
with psql_cursor() as cursor:
And the context manager takes care of making a connection (or getting a
connection from a pool, more likely), and cl
Steve D'Aprano :
> or you can let the context manager do what it does, and write your own code
> to do what you do:
>
> try:
> with ...:
>...
> except:
> ...
Even better:
try:
a = open(...)
except ...:
...
with a:
...
You want to catch exceptions
On Tue, 17 Jan 2017 05:06 am, Israel Brewster wrote:
> I generally use context managers for my SQL database connections, so I can
> just write code like:
>
> with psql_cursor() as cursor:
>
>
> And the context manager takes care of making a connection (or getting a
> connection from a pool,
Israel Brewster wrote:
> I generally use context managers for my SQL database connections, so I can
> just write code like:
>
> with psql_cursor() as cursor:
>
>
> And the context manager takes care of making a connection (or getting a
> connection from a pool, more likely), and cleaning up
On Tue, Jan 17, 2017 at 5:06 AM, Israel Brewster wrote:
> I generally use context managers for my SQL database connections, so I can
> just write code like:
>
> with psql_cursor() as cursor:
>
>
> And the context manager takes care of making a connection (or getting a
> connection from a po
I generally use context managers for my SQL database connections, so I can just
write code like:
with psql_cursor() as cursor:
And the context manager takes care of making a connection (or getting a
connection from a pool, more likely), and cleaning up after the fact (such as
putting the
12 matches
Mail list logo