Re: How to control the creation of an instance?

2007-06-03 Thread KingMax
On Jun 3, 2:17 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On Jun 2, 10:31 pm, lialie <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > suppose i have a free_object list[Sample1, Smaple2]. when create a
> > new object sample(*args, **kwds), if free_object_list isn't empty, just
> > pop one from free_object_list instead of creating a new instance.
>
> > any way to do this?
>
> > I do some work as follows:
>
> > class Sample(object):
> > used_object = []
> > free_object = []
>
> > def __init__(self, *args, **kwds):
> > pass
>
> > def __new__(self, *args, **kwds):
> > if Sample.free_object:
> > obj = Sample.free_object.pop(0)
> > else:
> > obj = object.__new__(Sample, *args, **kwds)
> > Sample.used_object.append(obj)
> > return obj
>
> >  still get a new instance :(
>
> > def Release(self):
> > Sample.used_object.remove(self)
> > Sample.free_object.append(self)
> > return True
>
> This seems to work for me:
>
> import collections
>
> class Sample(object):
>
> free_objects = collections.deque()
> used_objects = []
>
> def __new__(cls, *args, **kwds):
> if not Sample.free_objects:
> temp = object.__new__(Sample, args, kwds)
> Sample.used_objects.append(temp)
> return temp
> else:
> return Sample.free_objects.popleft()
>
> def __init__(self, *args, **kwds):
> self.args = args
> self.kwds = kwds
>
> def release(self):
> Sample.used_objects.remove(self)
> Sample.free_objects.append(self)
>
> s1 = Sample(10, name="Bob")
> print s1
> print s1.args
> print s1.kwds
>
> s2 = Sample("red", name="Bill")
> print s2
> print s2.args
> print s2.kwds
>
> s1.release()
> s3 = Sample("blue", name="Tim")
> print s3
> print s3.args
> print s3.kwds

Thank you.
> def __new__(cls, *args, **kwds):
> if not Sample.free_objects:
> temp = object.__new__(Sample, args, kwds)
> Sample.used_objects.append(temp)
> return temp
> else:
> return Sample.free_objects.popleft() # Here you may lost one 
> object :)

The free_objects list doesn't have orders. My sample code seems to
work. But follows may create a new instance:

class Sample(wx.Image):
free_objects = []
used_objects
def __int__(self, *args, **kwds):
wx.Image.__init__(self, *args, **kwds)  play tricks with
me :)
pass

def __new__(cls, *args, **kwds):
# The same

wx.Image always create a new instance. It seems that I have to avoid
wx.Image.__init__.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with write binary data to OLE field in Access

2008-03-28 Thread KingMax
On 3月27日, 下午7时22分, Tim Golden <[EMAIL PROTECTED]> wrote:
> lialie wrote:
>
> [... snip slightly confused indication that reading back a
> binary item using GetChunk appears to double its length ...]
>
> Well I don't know why this should be happening, but I do at
> least have a few suggestions:
>
> 1) Try using ADODB.Stream instead of GetChunk etc.
>
> 2) Try using the adodbapi dbapi-compliant wrapper
>
> 3) Try using ODBC (via PyODBC, CeODBC etc.)
>
> I've no idea if any of these will do any better but at
> least it gives you some possibilities :)
>
> TJG

Thanks!
I try using ADODB.Stream to implement it. But the situation is the
same.
At last, I try this, and it seems to work.
1) Save the image to the dist.
2) using ADODB.Stream.LoadFromFile
3) Save it into access
and then first step done.

when using it, I try this:
1) ADODB.Stream.Write(Record.Fields("xxx").Value)
2) ADODB.Stream.SaveToFile("test.jpg")
3) using wxImage to load it in.

a little stupid :(
-- 
http://mail.python.org/mailman/listinfo/python-list

Is it good to create a thread in a non gui thread?

2006-12-14 Thread Lialie - KingMax
Hi,
I create a thread in a non gui thread, and it does well. But it seems
strange. Somebody told me better not for it may cause something hard to
imagine.
Is there any different between them?

THX
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: hyperthreading locks up sleeping threads

2006-05-09 Thread Lialie KingMax

I haven't try the files yet. But have got a similar problem before. The
situation is nearly the same.
Always at random time , it reported that the memory read or write
violently.But I use Windows 2000(Python 2.3, wxPython 2.4). Windows
issue says 2000 doesn't support HP, so I simply turn it off. It didn't
appear.

-- 
http://mail.python.org/mailman/listinfo/python-list

how to read a list from python in C?

2006-05-19 Thread Lialie KingMax

Hi, all

I am writing a C extension with .Net.
Now I have a list of points, like [(0.0, 0.0), (2.0, 3.0), (random x,
random y)].
Is there a better way to translate it to an array than doing it one by one?

Thanks


-- 
http://mail.python.org/mailman/listinfo/python-list