Re: String comparison question

2006-03-19 Thread Michael Spencer
Olivier Langlois wrote: > I would like to make a string comparison that would return true without > regards of the number of spaces and new lines chars between the words > > like 'A B\nC' = 'A\nBC' > import string NULL = string.maketrans("","") WHITE = string.whitespace def compare(a,b)

Re: Is there such an idiom?

2006-03-19 Thread Michael Spencer
Per wrote: > Thanks Ron, > surely set is the simplest way to understand the question, to see > whether there is a non-empty intersection. But I did the following > thing in a silly way, still not sure whether it is going to be linear > time. > def foo(): > l = [...] > s = [...] > dic =

Re: String comparison question

2006-03-19 Thread Michael Spencer
Olivier Langlois wrote: > Hi Michael! > > Your suggestion is fantastic and is doing exactly what I was looking > for! Thank you very much. > There is something that I'm wondering though. Why is the solution you > proposed wouldn't work with Unicode strings? > Simply, that str.translate with two a

Re: String comparison question

2006-03-19 Thread Michael Spencer
Alex Martelli wrote: > Michael Spencer <[EMAIL PROTECTED]> wrote: >> >> Here, str.translate deletes the characters in its optional second argument. >> Note that this does not work with unicode strings. > > With unicode, you could do something strictly equ

Re: user-supplied locals dict for function execution?

2006-03-20 Thread Michael Spencer
Lonnie Princehouse wrote: >> What's your use case exactly ? > > I'm trying to use a function to implicitly update a dictionary. The > whole point is to avoid the normal dictionary semantics, so kw['x'] = 5 > unfortunately won't do. > > I think bytecode hacks may be the way to go > I once messed

Re: String comparison question

2006-03-20 Thread Michael Spencer
Fredrik Lundh wrote: > " hello world ".split() > ['hello', 'world'] a.split() == b.split() is a convenient test, provided you want to normalize whitespace rather than ignore it. I took the OP's requirements to mean that 'A B' == 'AB', but this is just a guess. Michael -- http://mail.

Re: Per instance descriptors ?

2006-03-22 Thread Michael Spencer
bruno at modulix wrote: > Ziga Seilnacht wrote: >> bruno at modulix wrote: >> >>> Hi >>> >>> I'm currently playing with some (possibly weird...) code, and I'd have a >>> use for per-instance descriptors, ie (dummy code): >> >> >> >>> Now the question: is there any obvious (or non-obvious) drawback

Re: Wrap a dictionary in a class?

2006-03-22 Thread Michael Spencer
Joseph Turian wrote: > In another thread, it was recommended that I wrap a dictionary in a > class. > How do I do so? > >Joseph > > that thread: > http://groups.google.com/group/comp.lang.python/browse_frm/thread/9a0fbdca450469a1/b18455aa8dbceb8a?q=turian&rnum=1#b18455aa8dbceb8a > Perhaps li

Re: Per instance descriptors ?

2006-03-22 Thread Michael Spencer
Bruno Desthuilliers wrote: > Michael Spencer a écrit : >> I may be missing the subtlety of what you're up to, but why is >> overriding __getattribute__ more desirable than simply defining the >> descriptor in a subclass? > > The code snippet I gave as an exa

Re: overlapping sets

2006-03-24 Thread Michael Spencer
kpp9c wrote: > I have a question... and ... whew ... i am gonna be honest, i haven't > the slightest clue how to even start ... i am not sure if i used up all > my good will here or can take a mulligan.. i love to try to at least > post some lame broken code of my own at first... but like i said, n

Re: Help: Creating condensed expressions

2006-03-24 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Nevermind, I didn't understand the problem/question... Sorry. > > Bye, > bearophile > Really? Your solution looks fine to me. In any case, here's an alternative approach to the (based on the same understanding of the problem as bearophile's, but with the additional

Re: String To Dict Problem

2006-03-26 Thread Michael Spencer
Kamilche wrote: > Hi everyone. I'm trying to convert a string that looks like this: > > gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2 = 'more > text without quotes', fmtline = "@VALUE @SIGNAL", signals = [('FPS', > None), ('FPS2', 'something')] > > to a dict that looks like this

Re: String To Dict Problem

2006-03-26 Thread Michael Spencer
Kamilche wrote: > Thanks! It's interesting, and nearly what I want, but not quite there. > > When I run my sample code through it, I get a syntax error because it's > not a valid expression. If I were to put a 'dict(' in front and a ')' > at the end, THEN it nearly works - but it gives me an > 'Un

Re: wildcard exclusion in cartesian products

2006-03-26 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > The python code below is adapted from a Haskell program written by > Tomasz > Wielonka on the comp.lang.functional group. It's more verbose than his > since I wanted to make sure I got it right. > > http://groups.google.com/group/comp.lang.functional/browse_frm/thread...

Re: Merging Objects

2006-04-03 Thread Michael Spencer
Cloudthunder wrote: > Sorry, I don't understand, how does this solve my problem? > __getattr__ and __setattr__ allow you to set up dynamic delegation e.g., class Foo(object): def __init__(self, **kw): self.__dict__.update(kw) def methFoo(self, x): return "Foo.methFoo(%

Re: How to determine if a line of python code is a continuation of the line above it

2006-04-08 Thread Michael Spencer
Sandra-24 wrote: > No it's not an academic excercise, but your right, the situation is > more complex than I originally thought. I've got a minor bug in my > template code, but it'd cause more trouble to fix than to leave in for > the moment. > > Thanks for your input! > -Sandra > Take a look at

Re: how to make a generator use the last yielded value when it regains control

2006-04-08 Thread Michael Spencer
John Salerno wrote: > Ben Cartwright wrote: > >> Definitely go for (1). The Morris sequence is a great candidate to >> implement as a generator. As a generator, it will be more flexible and >> efficient than (2). > > Actually I was just thinking about this and it seems like, at least for > my

Re: how to make a generator use the last yielded value when it regains control

2006-04-08 Thread Michael Spencer
John Salerno wrote: > Michael Spencer wrote: > >> itertools.groupby makes this very straightforward: > > I was considering this function, but then it seemed like it was only > used for determing consecutive numbers like 1, 2, 3 -- not consecutive > equivalent numbers l

Re: updated pre-PEP: The create statement

2006-04-10 Thread Michael Spencer
Steven Bethard wrote: > Azolex wrote: >> Steven Bethard wrote: >>> and named, nested hierarchies like XML documents could be created >>> like:: >>> >>> create ETobject html: >>> "This statement would generate an ElementTree object" >>> >>> create ETobject head: >>> "

Hello python users

2009-10-12 Thread Spencer Heckathorn
. I also want to make a synchronizing program. Lastly, I love poker and I would love even more to make a cool app for poker maybe an iPhone app or something I can post to the iGoogle page. So with that in mind where would you start? Thanks, Spencer -- http://mail.python.org/mailman/listinfo/python

Fix problems with email list

2009-10-28 Thread Spencer Heckathorn
I am getting doubles of every email on this list. Is there a list manager I can inform? Please help this is getting very annoying and makes it very hard to follow along. Spencer -- http://mail.python.org/mailman/listinfo/python-list

Tuples vs. variable-length argument lists

2010-03-19 Thread Spencer Pearson
Hi! This might be more of a personal-preference question than anything, but here goes: when is it appropriate for a function to take a list or tuple as input, and when should it allow a varying number of arguments? It seems as though the two are always interchangeable. For a simple example... def

Class changes in circular imports when __name__ == '__main__'

2010-09-05 Thread Spencer Pearson
Hi! I'm writing a package with several files in it, and I've found that "isinstance" doesn't work the way I expect under certain circumstances. Short example: here are two files. # fileone.py import filetwo class AClass( object ): pass if __name__ == '__main__': a = AClass() filetwo.is_acl

Re: Class changes in circular imports when __name__ == '__main__'

2010-09-08 Thread Spencer Pearson
All right, thank you for helping! I'd had a little voice in the back of my mind nagging me that it might not be logical to include a bunch of classes and function definitions in my startup file, but I never got around to splitting it up. The module/script distinction makes sense, and it seems more

How do i execute some code when I have subscribed to a topic with a message payload for mqtt in python?

2019-08-08 Thread Spencer Du via Python-list
age to topic","microscope/light_sheet_microscope/UI") client.publish("microscope/light_sheet_microscope/UI",device) time.sleep(2) # wait print("subscribing ") client.subscribe("microscope/light_sheet_microscope/UI") client.loop_stop() #stop the loop Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

Re: How do i execute some code when I have subscribed to a topic with a message payload for mqtt in python?

2019-08-08 Thread Spencer Du via Python-list
On Thursday, 8 August 2019 22:48:11 UTC+2, Spencer Du wrote: > Ok so here is some code below. How do I write an if code block to execute > some commands when I subscribe to the topic: > microscope/light_sheet_microscope/UI and which has a message which is a > device type publis

How do I decouple these two modules?

2019-08-28 Thread Spencer Du via Python-list
ght_sheet_microscope/UI") def on_message(self, mqttc, userdata, message): msg = str(message.payload.decode("utf-8")) print("File which you want to import(with .py extension)") print("message topic=", message.topic) print("message qos=", message.qos) print("message retain flag=", message.retain) def run(self): self.connect("broker.hivemq.com", 1883, 60) Thanks Spencer -- https://mail.python.org/mailman/listinfo/python-list

How to create list for stuff inside mqtt and GUI?.

2019-09-01 Thread Spencer Du via Python-list
Hi I have code for GUI and MQTT. In GUI.py I have "def loadGUI" which loads up a GUI file if the file exists in current directory. I want to add the file name to a list when a file is imported and for each subsequent file that is imported I want the file name to be imported to the same list an

<    1   2   3   4   5