Events: The Python Way
Hi, i'm a .net programmer and i'm learnig python, so this question can be very stupid or easy for python programmers. I've a doubt about events here is what: in c# for example i can write a delegate and an event in this way... public delegate SomethingChangedHandler(string message); public event SomethingChangedHandler SomethingChanged; and later in the code fire this event in this way... if(SomethingChanged != null) { SomethingChanged("Nothing important"); } and the subscription of this event of other objects can be easy as eventGeneratorObject.SomethingChanged += new SomethingChangedHandler(aFunctionto_takecareof_it); and even the handlig of the event is aesy... void aFunctionto_takecareof_it(string msg) { } now the question is.. how can i do the same using Python? Every help is appreciated Regards, Gianmaria -- http://mail.python.org/mailman/listinfo/python-list
Re: Events: The Python Way
"David Wilson" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi there, > > Python has no built-in way of doing this. You may consider writing > your own class if you like this pattern (I personally do): > > class Event(object): >def __init__(self): >self.subscribers = set() > >def __iadd__(self, subscriber): >self.subscribers.add(subscriber) >return self > >def __isub__(self, subscriber): >self.subscribers.pop(subscriber) >return self > >def __call__(self, *args, **kwargs): >for subscriber in self.subscribers: >subscriber(*args, **kwargs) > > > def HandleFoo(strng): >print "HandleFoo:", strng > > OnFoo = Event() > OnFoo += HandleFoo > > OnFoo("Test.") > > > On 29/07/07, Gianmaria <[EMAIL PROTECTED]> wrote: >> Hi, >> i'm a .net programmer and i'm learnig python, so this question can be >> very >> stupid or easy for python programmers. I've a doubt about events here >> is >> what: >> >> in c# for example i can write a delegate and an event in this way... >> >> public delegate SomethingChangedHandler(string message); >> public event SomethingChangedHandler SomethingChanged; >> >> and later in the code fire this event in this way... >> >> if(SomethingChanged != null) >> { >> SomethingChanged("Nothing important"); >> } >> >> and the subscription of this event of other objects can be easy as >> >> eventGeneratorObject.SomethingChanged += new >> SomethingChangedHandler(aFunctionto_takecareof_it); >> >> and even the handlig of the event is aesy... >> >> void aFunctionto_takecareof_it(string msg) >> { >> >> } >> >> >> now the question is.. how can i do the same using Python? Every help >> is >> appreciated >> >> >> >> >> >> Regards, >> Gianmaria >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> Txs so much. Gianmaria -- http://mail.python.org/mailman/listinfo/python-list
Bit Operations
Hi there, I'm so new to python (coming from .net so excuse me for the stupid question) and i'm tring to do a very simple thing,with bytes. My problem is this: i've a byte that naturally is composed from 2 nibbles hi&low, and two chars.. like A nd B. What i wonna do is to write A to the High nibble and B to the the lower nibble. Or an other example can be i've 2 numbers.. like 7 and 8 and whant to do the same as for chars. I'm really confused on how t do it, maybe cause python is type-less (dynamic typed) Any Help? Cheers, Gianmaria ITALY -- http://mail.python.org/mailman/listinfo/python-list
Re: Bit Operations
Txs all, i wont to respond to who asked why i needed it: I'm using python on GSM modules and the informations i have to move goes along GPRS/UMTS connections so it's beatiful for me to transfer more informations with less space... imagine i have to send this simple data 41.232323,12.345678 i can send it as it's or use the nibble trick and on the receiving station 'unlift" the data and rebuild the original information... isn'it??? cheers + TXS, Gianmaria ps: now i'm gonna read all your answers in details... txs again Firma Gianmaria Iaculo "Gianmaria Iaculo - NVENTA" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi there, > I'm so new to python (coming from .net so excuse me for the stupid > question) and i'm tring to do a very simple thing,with bytes. > > My problem is this: > > i've a byte that naturally is composed from 2 nibbles hi&low, and two > chars.. like A nd B. What i wonna do is to write A to the High nibble and > B to the the lower nibble. > Or an other example can be i've 2 numbers.. like 7 and 8 and whant to do > the same as for chars. > > I'm really confused on how t do it, maybe cause python is type-less > (dynamic typed) > > > Any Help? > > Cheers, > Gianmaria > ITALY > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Bit Operations
U are really nice guys... i'm really apreciating (sorry 4 my bad english) Chriss is right this are coordinates and i'm treating as strings naturally I dont really have floating points on my module.. it run a 1.5 python version from Telit. So i dont have zLib too... just have 1.5 Mb of Ram and 3Mb of Rom... not realy confortable..isn't it? I'm tring some experiments on the command line... i've tried this: My longitude is 42.237897 so as a first step... i created a X and done this job as your examples: a = 4 b = 2 x = (a<<4)|b x is 66 so i can do: aDecoded = x >> 4 and i have the 4 again...( a value) but i've some problems while i decode the b Where i go wrong? Gianmaria Firma Gianmaria Iaculo "Chris Mellon" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > On Nov 28, 2007 3:18 PM, J. Clifford Dyer <[EMAIL PROTECTED]> wrote: >> On Wed, Nov 28, 2007 at 10:05:40PM +0100, Gianmaria Iaculo - NVENTA wrote >> regarding Re: Bit Operations: >> > >> > Txs all, >> > i wont to respond to who asked why i needed it: >> > >> > I'm using python on GSM modules and the informations i have to move >> > goes >> > along GPRS/UMTS connections so it's beatiful for me to transfer more >> > informations with less space... >> > imagine i have to send this simple data >> > >> > 41.232323,12.345678 >> > >> > i can send it as it's or use the nibble trick and on the receiving >> > station >> > 'unlift" the data and rebuild the original information... >> > >> > isn'it??? >> > >> >> Um, no. It isn't. How exactly are you going to pack floating point >> numbers into a half a byte? >> >> Or are you sending it as strings? Also a waste of space, and >> unnecessarily complex. >> > > Assuming these are coordinates, not floats, using strings makes sense > but the zlib module is probably a much better choice than a > hand-written compression scheme. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bit Operations
John can you make an example of this solution? You maen that a more compact way is possible??? Firma Gianmaria Iaculo "John Machin" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > On Nov 29, 8:05 am, "Gianmaria Iaculo - NVENTA" > <[EMAIL PROTECTED]> wrote: >> Txs all, >> i wont to respond to who asked why i needed it: >> >> I'm using python on GSM modules and the informations i have to move goes >> along GPRS/UMTS connections so it's beatiful for me to transfer more >> informations with less space... >> imagine i have to send this simple data >> >> 41.232323,12.345678 >> >> i can send it as it's or use the nibble trick and on the receiving >> station >> 'unlift" the data and rebuild the original information... >> >> isn'it??? > > Sorry, but it's not apparent what you propose to do. If each number > has 8 decimal digits of precision (as in your example), you could > possibly get by with a 32-bit floating point number. If it's always 6 > decimal places and 0 <= number < 1000, you could pack (number * > 100) into a 32-bit integer. For the above two options, check out > the struct module. OTOH, maybe it's "packed decimal" that you mean -- > try Googling that phrase and see if it matches your intentions. If it > does, and you are concerned with speed, a 100-element dictionary > mapping each byte-pair to a packed byte might be a good idea instead > of the bit bashing: > convert = { > '78': '\x78', > ... > } > See http://mail.python.org/pipermail/python-list/2000-October/056329.html > > HTH, > John > -- http://mail.python.org/mailman/listinfo/python-list
Events - Design Patterns
ong somewhere.. but cant understand where...any Idea???I've tried to ask to Duncan directly by mail.. but the reported mail address is no more valid...Someone used this?? Someone uses an other way for events??? Regards,Gianmaria -- http://mail.python.org/mailman/listinfo/python-list
Thread
Hi all, i'm using python 1.5.2. Is it possible to use the Thread module? I need it for the Timer library. Regards, Gianmaria -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread
Diez i'm so sorry, You are right. thank you. Gianmaria Firma Gianmaria Iaculo "Diez B. Roggisch" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Gianmaria Iaculo - NVENTA wrote: > >> >> Hi all, >> i'm using python 1.5.2. >> >> Is it possible to use the Thread module? I need it for the Timer library. > > According to http://www.python.org/doc/1.5.2/lib/lib.html it's there. Why > don't you just import it and try? Would have cost less time than posting > here & waiting for an answer (This is not meant to be discouraging you > posting here - just showing you that in Python, trying first is often > easier than "gathering intelligence" first) > > Diez -- http://mail.python.org/mailman/listinfo/python-list