CherryPy Session object creation logic

2017-06-02 Thread Israel Brewster
I have a CherryPy app, for which I am using a PostgreSQL session. To be more exact, I modified a MySQL session class I found to work with PostgreSQL instead, and then I put this line in my code: cherrypy.lib.sessions.PostgresqlSession = PostgreSQLSession And this works fine. One thing about its

Re: Basic misunderstanding on object creation

2015-05-13 Thread Steven D'Aprano
On Thu, 14 May 2015 06:33 am, Ned Batchelder wrote: > On Wednesday, May 13, 2015 at 3:46:16 PM UTC-4, Mark Lawrence wrote: >> On 13/05/2015 19:42, andrew cooke wrote: >> > On Wednesday, 13 May 2015 13:37:23 UTC-3, Terry Reedy wrote: >> >> On 5/13/2015 9:25 AM, andrew cooke wrote: [...] >> >> >

Re: Basic misunderstanding on object creation

2015-05-13 Thread Ned Batchelder
On Wednesday, May 13, 2015 at 3:46:16 PM UTC-4, Mark Lawrence wrote: > On 13/05/2015 19:42, andrew cooke wrote: > > On Wednesday, 13 May 2015 13:37:23 UTC-3, Terry Reedy wrote: > >> On 5/13/2015 9:25 AM, andrew cooke wrote: > >> > >>> The following code worked on Python 3.2, but no longer works in

Re: Basic misunderstanding on object creation

2015-05-13 Thread Mark Lawrence
On 13/05/2015 19:42, andrew cooke wrote: On Wednesday, 13 May 2015 13:37:23 UTC-3, Terry Reedy wrote: On 5/13/2015 9:25 AM, andrew cooke wrote: The following code worked on Python 3.2, but no longer works in 3.4. Bugfixes break code that depends on buggy behavior. See https://bugs.python.or

Re: Basic misunderstanding on object creation

2015-05-13 Thread Terry Reedy
On 5/13/2015 2:42 PM, andrew cooke wrote: On Wednesday, 13 May 2015 13:37:23 UTC-3, Terry Reedy wrote: On 5/13/2015 9:25 AM, andrew cooke wrote: The following code worked on Python 3.2, but no longer works in 3.4. Bugfixes break code that depends on buggy behavior. See https://bugs.python.o

Re: Basic misunderstanding on object creation

2015-05-13 Thread andrew cooke
On Wednesday, 13 May 2015 13:37:23 UTC-3, Terry Reedy wrote: > On 5/13/2015 9:25 AM, andrew cooke wrote: > > > The following code worked on Python 3.2, but no longer works in 3.4. > > Bugfixes break code that depends on buggy behavior. See > https://bugs.python.org/issue1683368 > Your code also

Re: Basic misunderstanding on object creation

2015-05-13 Thread Mark Lawrence
On 13/05/2015 18:05, Terry Reedy wrote: On 5/13/2015 12:38 PM, Mark Lawrence wrote: I'm completely convinced that I've seen a change go through on the bug tracker that impacts on this area, but many months if not years ago. Unfortunately searching the bug tracker for super, __new__, __init__ an

Re: Basic misunderstanding on object creation

2015-05-13 Thread Terry Reedy
On 5/13/2015 12:36 PM, Terry Reedy wrote: On 5/13/2015 9:25 AM, andrew cooke wrote: The following code worked on Python 3.2, but no longer works in 3.4. Bugfixes break code that depends on buggy behavior. See https://bugs.python.org/issue1683368 Your code also fails in 2.7.9 if you inherit Fo

Re: Basic misunderstanding on object creation

2015-05-13 Thread Terry Reedy
On 5/13/2015 12:38 PM, Mark Lawrence wrote: I'm completely convinced that I've seen a change go through on the bug tracker that impacts on this area, but many months if not years ago. Unfortunately searching the bug tracker for super, __new__, __init__ and so on gets a lot of hits, leaving my Mk

Re: Basic misunderstanding on object creation

2015-05-13 Thread Mark Lawrence
On 13/05/2015 14:25, andrew cooke wrote: Hi, The following code worked on Python 3.2, but no longer works in 3.4. Did something change, or have I always been doing something dumb? (I realise the code is pointless as is - it's the simplest example I can give of a problem I am seeing with mor

Re: Basic misunderstanding on object creation

2015-05-13 Thread Terry Reedy
On 5/13/2015 9:25 AM, andrew cooke wrote: The following code worked on Python 3.2, but no longer works in 3.4. Bugfixes break code that depends on buggy behavior. See https://bugs.python.org/issue1683368 Your code also fails in 2.7.9 if you inherit Foo from object. The exact error messages cha

Re: Basic misunderstanding on object creation

2015-05-13 Thread andrew cooke
On Wednesday, 13 May 2015 11:56:21 UTC-3, Ian wrote: > On Wed, May 13, 2015 at 8:45 AM, andrew cooke wrote: > class Foo: > > ... def __new__(cls, *args, **kargs): > > ... print('new', args, kargs) > > ... super().__new__(cls) > > ... > class Bar(Foo): > > ... def

Re: Basic misunderstanding on object creation

2015-05-13 Thread Ian Kelly
On Wed, May 13, 2015 at 8:45 AM, andrew cooke wrote: class Foo: > ... def __new__(cls, *args, **kargs): > ... print('new', args, kargs) > ... super().__new__(cls) > ... class Bar(Foo): > ... def __init__(self, a): > ... print('init', a) > ... Bar(1) >

Re: Basic misunderstanding on object creation

2015-05-13 Thread Ian Kelly
On Wed, May 13, 2015 at 8:42 AM, andrew cooke wrote: > On Wednesday, 13 May 2015 11:36:12 UTC-3, Thomas Rachel wrote: >> Am 13.05.2015 um 15:25 schrieb andrew cooke: >> >> class Foo: >> > ... def __new__(cls, *args, **kargs): >> > ... print('new', args, kargs) >> > ... su

Re: Basic misunderstanding on object creation

2015-05-13 Thread Peter Otten
andrew cooke wrote: >> But then nothing will be passed to __init__ on the subclass. >> >> Andrew > class Foo: > ... def __new__(cls, *args, **kargs): > ... print('new', args, kargs) > ... super().__new__(cls) > ... class Bar(Foo): > ... def __init__(self, a): >

Re: Basic misunderstanding on object creation

2015-05-13 Thread andrew cooke
> But then nothing will be passed to __init__ on the subclass. > > Andrew >>> class Foo: ... def __new__(cls, *args, **kargs): ... print('new', args, kargs) ... super().__new__(cls) ... >>> class Bar(Foo): ... def __init__(self, a): ... print('init', a) ... >>> B

Re: Basic misunderstanding on object creation

2015-05-13 Thread andrew cooke
On Wednesday, 13 May 2015 11:36:12 UTC-3, Thomas Rachel wrote: > Am 13.05.2015 um 15:25 schrieb andrew cooke: > > class Foo: > > ... def __new__(cls, *args, **kargs): > > ... print('new', args, kargs) > > ... super().__new__(cls, *args, **kargs) > > > new (1,) {} > > Tra

Re: Basic misunderstanding on object creation

2015-05-13 Thread Thomas Rachel
Am 13.05.2015 um 15:25 schrieb andrew cooke: class Foo: ... def __new__(cls, *args, **kargs): ... print('new', args, kargs) ... super().__new__(cls, *args, **kargs) new (1,) {} Traceback (most recent call last): File "", line 1, in File "", line 4, in __new__ TypeE

Basic misunderstanding on object creation

2015-05-13 Thread andrew cooke
Hi, The following code worked on Python 3.2, but no longer works in 3.4. Did something change, or have I always been doing something dumb? (I realise the code is pointless as is - it's the simplest example I can give of a problem I am seeing with more complex code). >>> class Foo: ... de

Re: how to optimize object creation/reading from file?

2009-01-28 Thread perfreem
On Jan 28, 10:06 am, Bruno Desthuilliers wrote: > perfr...@gmail.com a écrit : > > > > > hi, > > > i am doing a series of very simple string operations on lines i am > > reading from a large file (~15 million lines). i store the result of > > these operations in a simple instance of a class, and t

Re: how to optimize object creation/reading from file?

2009-01-28 Thread Bruno Desthuilliers
perfr...@gmail.com a écrit : hi, i am doing a series of very simple string operations on lines i am reading from a large file (~15 million lines). i store the result of these operations in a simple instance of a class, and then put it inside of a hash table. i found that this is unusually slow..

how to optimize object creation/reading from file?

2009-01-28 Thread perfreem
hi, i am doing a series of very simple string operations on lines i am reading from a large file (~15 million lines). i store the result of these operations in a simple instance of a class, and then put it inside of a hash table. i found that this is unusually slow... for example: class myclass(o

Re: object creation

2008-11-14 Thread Jerry Hill
On Fri, Nov 14, 2008 at 6:38 PM, Joe Strout <[EMAIL PROTECTED]> wrote: > On Nov 14, 2008, at 4:33 PM, Jerry Hill wrote: > >> Then add >> def __init__(self): >> a = 0 >> b = 0 > > Doesn't that have to be "self.a" and "self.b"? Yes, that should indeed have been self.a and self.b! Sorry about that

Re: object creation

2008-11-14 Thread Steven D'Aprano
On Fri, 14 Nov 2008 16:38:15 -0700, Joe Strout wrote: > On Nov 14, 2008, at 4:33 PM, Jerry Hill wrote: > >> Then add >> def __init__(self): >> a = 0 >> b = 0 >> >> to your box class to make a and b instance variables. > > Doesn't that have to be "self.a" and "self.b"? Only if you want it to

Re: object creation

2008-11-14 Thread Bruno Desthuilliers
BiraRai a écrit : (snip) class box: a = int() b = int() I strongly suggest you read the tutorial. -- http://mail.python.org/mailman/listinfo/python-list

Re: object creation

2008-11-14 Thread Bruno Desthuilliers
BiraRai a écrit : for record in roll: x = box() x.createSomething(record) do something Can anyone tell me why python keeps return the original object x that was created in the FOR loop. Where is the "return" statement ? I want to instantiate a new x object for each iterat

Re: object creation

2008-11-14 Thread Bruno Desthuilliers
Jerry Hill a écrit : On Fri, Nov 14, 2008 at 6:10 PM, BiraRai <[EMAIL PROTECTED]> wrote: class box: a = int() b = int() def createSomething(self,x): At a guess, x = box() does create a new instance of your box class, but since you've declared a and b to be class variables instead of inst

Re: object creation

2008-11-14 Thread Joe Strout
On Nov 14, 2008, at 4:33 PM, Jerry Hill wrote: Then add def __init__(self): a = 0 b = 0 to your box class to make a and b instance variables. Doesn't that have to be "self.a" and "self.b"? Best, - Joe -- http://mail.python.org/mailman/listinfo/python-list

Re: object creation

2008-11-14 Thread Jerry Hill
On Fri, Nov 14, 2008 at 6:10 PM, BiraRai <[EMAIL PROTECTED]> wrote: > class box: > a = int() > b = int() > > def createSomething(self,x): At a guess, x = box() does create a new instance of your box class, but since you've declared a and b to be class variables instead of instance variables,

Re: object creation

2008-11-14 Thread BiraRai
On Nov 14, 5:44 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Nov 14, 5:16 pm, BiraRai <[EMAIL PROTECTED]> wrote: > > > for record in roll: > >     x = box() > >     x.createSomething(record) > >     do something > > > Can anyone tell me why python keeps return the original object x that >

Re: object creation

2008-11-14 Thread George Sakkis
On Nov 14, 5:16 pm, BiraRai <[EMAIL PROTECTED]> wrote: > for record in roll: >     x = box() >     x.createSomething(record) >     do something > > Can anyone tell me why python keeps return the original object x that > was created in the FOR loop.  I want to instantiate a new x object for > e

object creation

2008-11-14 Thread BiraRai
for record in roll: x = box() x.createSomething(record) do something Can anyone tell me why python keeps return the original object x that was created in the FOR loop. I want to instantiate a new x object for each iteration of the FOR loop -- http://mail.python.org/mailman/list

Re: Costly object creation (was : Having Trouble with Scoping Rules)

2006-01-31 Thread Charles Krug
On 2006-01-31, bruno at modulix <[EMAIL PROTECTED]> wrote: > See other answers in this thread for how to solve the UnboundLocalError > problem. > > Now about your *real* problem - which is nothing new -, you may want to > read about some known solutions: > > http://en.wikipedia.org/wiki/Singleton_p

Re: Costly object creation (was : Having Trouble with Scoping Rules)

2006-01-31 Thread bruno at modulix
Charles Krug wrote: > List: > > I've a module that's not doing what I expect. My guess is that I don't > quite understand the scoping rules the way I should. > > I have an object that's costly to create. My thought was to create it > at the module level like this: (snip) > What's the correct