Re: Global variables within classes.

2007-11-27 Thread Kevac Marko
On Nov 10, 8:39 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> Don't think so.  It's a surprise for many but then class attributes are
> not that common in code or they even use this "gotcha" for
> immutable default values.  As long a the value isn't changed the default
> value is just referenced from the class then and not every instance.
>

When changing default value, is there any way to change class
attribute and all referenced attributes too?

class M:
name = u"Marko"

a, b = M(), M()
a.name = u"Kevac"
print M.name, a.name, b.name
-> Marko Kevac Marko

Is there any way to get here -> Kevac Kevac Kevac ?
Or what is the right way of keeping global variables in classes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Twisted: UDP socket not closed.

2007-12-22 Thread Kevac Marko
Hi.

I have to send UDP packets very often. Approx twice in a second.
But socket is not closed after sending packet. So soon i bump into
open sockets\files limit.
How to close socket after sending data?

Python 2.5, Twisted

class DataClient(DatagramProtocol):

def __init__(self, address, datagram = "PONG"):
self.address, self.datagram = address, datagram

def startProtocol(self):
self.transport.socket.setsockopt(socket.SOL_SOCKET, \
socket.SO_BROADCAST, True)
self.transport.connect(self.address[0], self.address[1])
self.sendDatagram()

def sendDatagram(self):
self.transport.write(self.datagram)
debug("Data client: Sending to %s" % repr(self.address))

while True:
clientprotocol = DataClient(("255.255.255.255", 5999), data)
reactor.listenUDP(0, clientprotocol).stopListening()

[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
43
[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
44
[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
44
[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
44
[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
45
[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
45
[EMAIL PROTECTED]:~$ ls -la /proc/15429/fd/ | wc -l
46

Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list