Re: class inheritance

2010-03-13 Thread Patrick Maupin
On Mar 13, 11:03 am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = V

Re: class inheritance

2010-03-13 Thread Patrick Maupin
On Mar 13, 11:37 am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): >   def __add__(self, other)

Re: iterator/generator

2010-03-14 Thread Patrick Maupin
First of all, as Steve Holden mentioned, do look at xlrd. It's awesome. Second, for your (a) question, if you want an iterator, that's quite easy: matriz = iter(matriz) matriz.next() # Discard the first one for i in matriz: This technique works really well, especially if you have sub-loops. Th

Re: highlight words by regex in pdf files using python

2010-03-16 Thread Patrick Maupin
On Mar 4, 6:57 pm, Peng Yu wrote: > I don't find a general pdf library in python that can do any > operations on pdfs. > > I want to automatically highlight certain words (using regex) in a > pdf. Could somebody let me know if there is a tool to do so in python? The problem with PDFs is that they

Re: to pass self or not to pass self

2010-03-16 Thread Patrick Maupin
On Mar 16, 1:59 pm, Jason Tackaberry wrote: > Why not create the bound methods at instantiation time, rather than > using the descriptor protocol which has the overhead of creating a new > bound method each time the method attribute is accessed? Well, for one thing, Python classes are open. They

Re: to pass self or not to pass self

2010-03-17 Thread Patrick Maupin
On Mar 17, 4:12 am, Bruno Desthuilliers wrote: > Patrick Maupin a écrit : > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > >> Why not create the bound methods at instantiation time, rather than > >> using the descriptor protocol which has the overhead of creatin

Re: highlight words by regex in pdf files using python

2010-03-17 Thread Patrick Maupin
On Wed, Mar 17, 2010 at 9:53 AM, Peng Yu wrote: > Thank you for your long reply! But I'm not sure if you get my question or not. > > Acrobat can highlight certain words in pdfs. I could add notes to the > highlighted words as well. However, I find that I frequently end up > with highlighting some

Re: to pass self or not to pass self

2010-03-17 Thread Patrick Maupin
On Mar 17, 2:55 pm, Terry Reedy wrote: > On 3/17/2010 1:35 AM, Patrick Maupin wrote: > > >>>> def a(s, count, lenfunc): > > ...     for i in xrange(count): > > ...        z = lenfunc(s) > > ... > >>>> >>>  a('abcdef', 10

Re: to pass self or not to pass self

2010-03-17 Thread Patrick Maupin
On Mar 17, 5:34 pm, Joaquin Abian wrote: > On Mar 17, 3:43 pm, Patrick Maupin wrote: > > > > > On Mar 17, 4:12 am, Bruno Desthuilliers > > 42.desthuilli...@websiteburo.invalid> wrote: > > > Patrick Maupin a écrit : > > > > > On Mar 16, 1:59 p

Re: Need to create subprocess...

2010-03-18 Thread Patrick Maupin
On Mar 18, 11:17 am, "drstoka" wrote: > Hello, > > I have to run a program as a child process inside my python program and > redirect it's output through a pipe to a parent program process. > So, I wrote this: > > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout > > and i

Re: GC is very expensive: am I doing something wrong?

2010-03-18 Thread Patrick Maupin
On Mar 18, 7:13 pm, Weeble wrote: > I am loading a dictionary from a text file and constructing a trie > data structure in memory. However, it takes longer than I'm happy with > - about 12 seconds on my computer. I profiled it, came up with some > clever ideas to cut down on the work (such as by e

RSON 0.06 released

2010-03-21 Thread Patrick Maupin
I am pleased to announce the release of RSON 0.06. The goal of the RSON project is to create a file format that is easy to edit, diff, and version control, that is a superset of JSON and smaller than YAML. I consider this release to be feature complete on the file format, and I believe the pure P

Re: How to automate accessor definition?

2010-03-21 Thread Patrick Maupin
On Mar 21, 11:57 am, kj wrote: > > Just accessing attributes looks a bit dangerous to me, due to bugs > like typing > >   i.typo = 'foo' > > when what you meant is > >   i.type = 'foo' > > I tried fixing this by mucking with __setattr__, but I didn't hit > on a satisfactory solution (basically, I

Re: Python is cool!!

2010-03-23 Thread Patrick Maupin
On Mar 23, 3:12 pm, Tim Golden wrote: > I can't say I thought *very* hard before sending that but... > The OP asked for "integrate Python in Web Pages with HTML" > which I understood -- perhaps wrongly -- to mean: run Python > in the browser. The only two ways I'm aware of doing that > in Python a

Re: Python is cool!!

2010-03-23 Thread Patrick Maupin
On Tue, Mar 23, 2010 at 4:50 PM, Shashwat Anand wrote: > There is a project PyWhip (renamed as PyKata) which aims for the same > purpose. Google AppEmgine + Django does the trick for that. May be you can > take an inspiration or two from there especially because all code is open > to/for you. But

Re: Create a class at run-time

2010-03-25 Thread Patrick Maupin
On Mar 25, 5:00 pm, Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: Well, you

Re: Revisiting Generators and Subgenerators

2010-03-25 Thread Patrick Maupin
On Mar 25, 7:31 pm, Winston Wolff wrote: (a bunch of stuff about coroutines) There have been proposals in the past for more full-featured generators, that would work as general purpose coroutines. Among other things, there were issues with exception propagation, and the design was deliberately

Re: function decorator-like function

2010-03-27 Thread Patrick Maupin
On Mar 27, 10:24 am, vsoler wrote: > Hi, > > Still learning Python, now decorators. > > Before diving deeply into decorators, I'd like to apply a function to > another function. > > My "extremely simple function" should print number 3, then the sum of > its 2 arguments. > > Say that I call   f(5,7

Re: function decorator-like function

2010-03-27 Thread Patrick Maupin
On Mar 27, 11:24 am, vsoler wrote: > I see what happened. The first line was somehow hidden. > Thank you very much. You're welcome. Sorry about the formatting. Also, note that if your decorator is complicated, you might want to use a class instead of a nested function. Here's the same thing, u

Re: Classes as namespaces?

2010-03-27 Thread Patrick Maupin
On Mar 27, 12:10 pm, Terry Reedy wrote: > On 3/27/2010 7:28 AM, Jonathan Hartley wrote: > > > On Mar 26, 6:26 pm, Luis M. González  wrote: > > But defining and then calling the function like that is a tad > > cumbersome. So I was wondering about: > > > x = 1 > > class account_for_non_square_pixels

Re: function decorator-like function

2010-03-28 Thread Patrick Maupin
On Mar 28, 9:17 am, Michele Simionato wrote: > Another option is to use my own decorator module (http:// > pypi.python.org/pypi/decorator): > > from decorator import decorator > > @decorator > def d(func, *args): >     print 3 >     return func(*args) > > @d > def f(a, b): >     print a + b > > f(

Re: sum for sequences?

2010-03-28 Thread Patrick Maupin
On Mar 28, 10:17 am, Duncan Booth wrote: > Doing add-in-place isn't the only way to make sum more efficient: if you > assume that addition is associative (which of course the builtin sum can't) > then you can form partial sums. e.g. instead of calculating: ... > > Doing it this way helps summing l

Re: sum for sequences?

2010-03-28 Thread Patrick Maupin
On Mar 28, 11:56 am, "Alf P. Steinbach" wrote: >  From a more practical point of view, the sum efficiency could be improved by > doing the first addition using '+' and the rest using '+=', without changing > the > behavior. Mod parent up :-) -- http://mail.python.org/mailman/listinfo/python

Re: sum for sequences?

2010-03-28 Thread Patrick Maupin
On Mar 28, 12:34 pm, Steve Howell wrote: > FYI I later obtained similar results with the more general: >                   accum += sublist Yeah, but you still have to create an object of the correct type for accum. And for summing small lists, that will actually increase the runtime. (Worst ca

Re: sum for sequences?

2010-03-29 Thread Patrick Maupin
On Mar 28, 9:45 pm, Steven D'Aprano wrote: > And what about tuples? And subclasses of list/tuples? How many different > types need to be optimized? One of the beautiful things about Python is that, for most things, there are few surprises for even new users. "There should be one obvious way to d

Re: sum for sequences?

2010-03-29 Thread Patrick Maupin
On Mar 29, 6:19 pm, Steven D'Aprano wrote: > How does the existence of math.fsum contradict the existence of sum? You're exceptionally good at (probably deliberately) mis-interpreting what people write. Regards, Pat -- http://mail.python.org/mailman/listinfo/python-list

Re: sum for sequences?

2010-03-29 Thread Patrick Maupin
On Mar 29, 6:38 pm, Steven D'Aprano wrote: > With a very few exceptions (e.g. dict lookup being "usually" O(1), list > append being amortized O(1)), Python makes no promises about performance. > It's not part of the language. If you, the programmer, are making any > assumptions about performance t

Re: sum for sequences?

2010-03-29 Thread Patrick Maupin
On Mar 29, 10:29 pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 19:24:42 -0700, Patrick Maupin wrote: > > On Mar 29, 6:19 pm, Steven D'Aprano > cybersource.com.au> wrote: > >> How does the existence of math.fsum contradict the existence of sum? > >

Re: Binary Decimals in Python

2010-03-30 Thread Patrick Maupin
On Mar 30, 10:13 am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that thi

Re: sum for sequences?

2010-03-30 Thread Patrick Maupin
On Mar 30, 8:53 am, Mel wrote: > floats are nasty -- as evidence the recent thread on comparing floats for > equality.  People use floats when they have to.  fsum exists because of > this: ... I understand there are technical reasons for why math.fsum() exists. I still think that whatever math.f

Re: sorting ascending/descending with operator.attrgetter

2010-03-31 Thread Patrick Maupin
On Mar 31, 12:08 pm, Chris Curvey wrote: > I must be having a brain cramp.  Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: >     def __init__(self, a, b,

Re: sorting ascending/descending with operator.attrgetter

2010-03-31 Thread Patrick Maupin
On Mar 31, 5:57 pm, Steven D'Aprano wrote: > Did you mean list sort method? Why, yes. Yes, I did. Yes, I'm an old forgetful man who sometimes misspeaks or mistypes, and you're the smartest, sharpest guy in the world. Most helpful, too. It's much more useful to show how I'm wrong than to provi

Re: sorting ascending/descending with operator.attrgetter

2010-03-31 Thread Patrick Maupin
On Mar 31, 11:28 pm, Steven D'Aprano wrote: > I wouldn't so much say "literal" as "precise". Being precise in your own words is an admirable trait. Asking others to be more precise can be done politely when necessary, but in this case it obviously wasn't necessary, since even you, who deliberat

Re: sorting ascending/descending with operator.attrgetter

2010-03-31 Thread Patrick Maupin
On Mar 31, 11:40 pm, Steven D'Aprano wrote: > By the way, why are we acting as if seeking accuracy and truth is a bad > thing? I don't think anybody is acting like that is a bad thing. It's all how you choose to interpret things. > Personally, if I were interviewing job applicants, one of the

Re: sorting ascending/descending with operator.attrgetter

2010-04-01 Thread Patrick Maupin
On Apr 1, 1:54 am, Steven D'Aprano wrote: > At the risk of offending you further, I will suggest that I'm not the > only one who needs to apply some introspection here. If your skin is so > thin that you react so explosively to such a minor slight, how are you > going to react to some of the more

Re: sorting ascending/descending with operator.attrgetter

2010-04-01 Thread Patrick Maupin
On Apr 1, 12:50 am, Steve Holden wrote: > > I can well imagine that everybody who has to work with you thoroughly > >  enjoys proving you wrong as often as possible. > > I am glad I wasn't drinking when I read this. Liquid in one's nose is so > uncomfortable. Well, in that case, I'm glad you enjo

Re: C-style static variables in Python?

2010-04-01 Thread Patrick Maupin
On Apr 1, 6:10 pm, Steve Holden wrote: > Chris Rebert wrote: > > Personally, I hate such abuse with a passion; I think a global > > variable is clearest. > > But the real problem is that the OP is insisting on using purely > procedural Python when the problem is screaming for an object-oriented >

Re: off topic but please forgive me me and answer

2010-04-01 Thread Patrick Maupin
On Apr 1, 4:42 pm, Tim Chase wrote: > superpollo wrote: > > how much is one half times one half? > > Uh, did you try it at the python prompt?  If not, here's the answer: > >   0.1b * 0.1b = 0.01b > > Now all you need is to find the recent thread that converts > binary floats to decimal floats ;-)

Re: off topic but please forgive me me and answer

2010-04-01 Thread Patrick Maupin
On Apr 1, 7:49 pm, Tim Chase wrote: > David Robinow wrote: > > $ python -c "print 1/2 * 1/2" > > 0 > > >  But that's not what I learned in grade school. > > (Maybe I should upgrade to 3.1?) > > That's because you need to promote one of them to a float so you > get a floating-point result: > >    >

Re: off topic but please forgive me me and answer

2010-04-01 Thread Patrick Maupin
On Apr 1, 9:50 pm, Lie Ryan wrote: > On 04/02/10 13:01, Patrick Maupin wrote: > > > > > On Apr 1, 7:49 pm, Tim Chase wrote: > >> David Robinow wrote: > >>> $ python -c "print 1/2 * 1/2" > >>> 0 > > >>>  But tha

Re: off topic but please forgive me me and answer

2010-04-01 Thread Patrick Maupin
On Apr 1, 11:52 pm, Dennis Lee Bieber wrote: > On Thu, 01 Apr 2010 22:44:51 +0200, superpollo > declaimed the following in gmane.comp.python.general: > > > how much is one half times one half? > > import math > print math.exp((math.log(1) - math.log(2)) >                                  + (math.

Re: Splitting a string

2010-04-02 Thread Patrick Maupin
On Apr 2, 6:24 am, Peter Otten <__pete...@web.de> wrote: > Thomas Heller wrote: > > Maybe I'm just lazy, but what is the fastest way to convert a string > > into a tuple containing character sequences and integer numbers, like > > this: > > > 'si_pos_99_rep_1_0.ita'  -> ('si_pos_', 99, '_rep_', 1,

Re: C-style static variables in Python?

2010-04-02 Thread Patrick Maupin
On Apr 2, 1:21 pm, Ethan Furman wrote: > For this type of situation, my preference would be: > > class spam(object): >      def __call__(self, x, y, z): >          try: >              mongo = self.mongo >          except AttributeError: >              mongo = self.mongo = heavy_lifting_at_runtime(

Re: off topic but please forgive me me and answer

2010-04-02 Thread Patrick Maupin
On Apr 2, 2:41 pm, Andreas Waldenburger wrote: > While everyone else is mocking you: Can you please elaborate on why you > want to know and what kind of problem you're trying to solve with this? > Also, don't you think you should have picked a maths forum for this > kind of question? Methinks th

Re: C-style static variables in Python?

2010-04-02 Thread Patrick Maupin
On Apr 2, 2:38 pm, Ethan Furman wrote: > Patrick Maupin wrote: > > On Apr 2, 1:21 pm, Ethan Furman wrote: > >> For this type of situation, my preference would be: > > >> class spam(object): > >>      def __call__(self, x, y, z): > >>  

Re: C-style static variables in Python?

2010-04-02 Thread Patrick Maupin
On Apr 2, 3:33 pm, Ethan Furman wrote: > My main point, though, was using __call__, and not some weird _ method.  ;) Yes, __call__ is good. In general, not naming things that don't need to be named is good (but if you have too many of them to keep track of, then, obviously, they need to be named

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Patrick Maupin
On Apr 2, 3:12 pm, kj wrote: > Is that for real???  It's the QWERTY rationale all over again.  Swell. Well, bearing in mind that everybody seems to have an agenda, so you can't (or shouldn't, anyway) take all your news from a single source, it may be that the common wisdom about the QWERTY thing

Re: Splitting a string

2010-04-02 Thread Patrick Maupin
On Apr 2, 4:32 pm, Peter Otten <__pete...@web.de> wrote: > _split = re.compile(r"(\d+)").split > def split(s): >     if not s: >         return () >     parts = _split(s) >     parts[1::2] = map(int, parts[1::2]) >     if parts[-1] == "": >         del parts[-1] >     if parts[0] == "": >        

Re: C-style static variables in Python?

2010-04-02 Thread Patrick Maupin
On Apr 2, 6:57 pm, Steven D'Aprano wrote: > On Fri, 02 Apr 2010 12:39:16 -0700, Patrick Maupin wrote: > > On Apr 2, 2:38 pm, Ethan Furman wrote: > [...] > >> Sounds like a personal preference issue, rather than a necessary / > >> unnecessary issue -- aft

Re: off topic but please forgive me me and answer

2010-04-02 Thread Patrick Maupin
On Apr 2, 6:50 pm, Mensanator wrote: > On Apr 2, 2:34 pm, Patrick Maupin wrote: > > > Methinks the OP is fluent in the way of choosing newsgroups. > > According to google, he has posted 6855 messages in 213 groups. > > Does that really mean anything? Hell, I have 12765

Re: off topic but please forgive me me and answer

2010-04-02 Thread Patrick Maupin
On Apr 2, 8:29 pm, Mensanator wrote: > Don't you know how Usenet works? No, but my cat does. -- http://mail.python.org/mailman/listinfo/python-list

Re: C-style static variables in Python?

2010-04-02 Thread Patrick Maupin
On Apr 2, 10:11 pm, Stephen Hansen wrote: > > I don't know if properties are really faster or slower then a > __getattr__, but I find them a lot cleaner if I want to delay some > calculation until needed like that. Well, the relative speed of properties vs. __getattr__ can become irrelevant in at

Re: off topic but please forgive me me and answer

2010-04-03 Thread Patrick Maupin
On Apr 3, 9:43 am, "Martin P. Hellwig" > IMHO, the crackpot in this regard is actually partially right, > multiplication does mean that the number must get bigger, however for > fractions you multiply four numbers, two numerators and two > denominators. The resulting numerator and denominator by th

Re: off topic but please forgive me me and answer

2010-04-03 Thread Patrick Maupin
On Apr 3, 8:00 am, superpollo wrote: > > sorry if I misunderstood. > > no no you understood prfectly *but* the thing is i am a regular in an > italian language math ng which is haunted by a crackpot who insists that > 1/2 * 1/2 cannot be 1/4, "because multiplication means getting bigger", > so i t

Re: Splitting a string

2010-04-03 Thread Patrick Maupin
On Apr 3, 4:17 am, Peter Otten <__pete...@web.de> wrote: > Patrick Maupin wrote: > > On Apr 2, 4:32 pm, Peter Otten <__pete...@web.de> wrote: > > >> _split = re.compile(r"(\d+)").split > >> def split(s): > >>     if not s: > >

Re: passing command line arguments to executable

2010-04-03 Thread Patrick Maupin
On Apr 3, 11:09 am, mcanjo wrote: > I have an executable (I don't have access to the source code) that > processes some data. I double click on the icon and a Command prompt > window pops up. The program asks me for the input file, I hit enter, > and then it asks me for and output filename, I hit

Re: off topic but please forgive me me and answer

2010-04-03 Thread Patrick Maupin
On Apr 3, 11:59 am, Emile van Sebille wrote: > On 4/3/2010 8:46 AM Patrick Maupin said... > > > On Apr 3, 9:43 am, "Martin P. Hellwig">  IMHO, the crackpot in this > > regard is actually partially right, > >> multiplication does mean that the number must ge

Re: passing command line arguments to executable

2010-04-03 Thread Patrick Maupin
On Apr 3, 12:20 pm, mcanjo wrote: > On Apr 3, 11:15 am, Patrick Maupin wrote: > > > > > On Apr 3, 11:09 am, mcanjo wrote: > > > > I have an executable (I don't have access to the source code) that > > > processes some data. I double click on the ic

Re: off topic but please forgive me me and answer

2010-04-03 Thread Patrick Maupin
On Apr 3, 12:39 pm, MRAB wrote: > Patrick Maupin wrote: > > On Apr 3, 11:59 am, Emile van Sebille wrote: > >> On 4/3/2010 8:46 AM Patrick Maupin said... > > >>> On Apr 3, 9:43 am, "Martin P. Hellwig">  IMHO, the crackpot in this > >>>

Re: off topic but please forgive me me and answer

2010-04-03 Thread Patrick Maupin
On Apr 3, 9:24 pm, Steven D'Aprano wrote: > To put it another way, even though there are an infinite number of > rationals, they are vanishingly rare compared to the irrationals. If you > could choose a random number from the real number line, it almost > certainly would be irrational. Yet anothe

Re: Splitting a string

2010-04-03 Thread Patrick Maupin
On Apr 3, 10:00 pm, Steven D'Aprano wrote: > Tests which you know can't fail are called assertions, pre-conditions and > post-conditions. We test them because if we don't, they will fail :) Well, yes, but that can get rather tedious at times: a = 1 assert 0 < a < 2 b = a + 3 assert 2 < b - a < 4

Re: Splitting a string

2010-04-04 Thread Patrick Maupin
On Apr 4, 4:58 am, Peter Otten <__pete...@web.de> wrote: > Personally, though, I prefer unit tests over assertions. IMO, the primary use cases for assertions and unit tests are not the same. When I have a well-defined, clearly understood specification that I am coding to and fully implementing w

Re: Splitting a string

2010-04-04 Thread Patrick Maupin
On Apr 4, 2:37 am, Steven D'Aprano wrote: > In any case, the *right* test would be: > > a = 1 > assert a == 1 and a*5==5 and str(a)=='1' and [None,a,None][a] is a You're right. I was very tired when I wrote that, and forgot the last 3 assertions... -- http://mail.python.org/mailman/listinfo/py

Re: Is there a standard name for this tree structure?

2010-04-04 Thread Patrick Maupin
On Apr 4, 9:06 am, Duncan Booth wrote: > Do you have any carniverous apes? If so it's a directed acyclic graph. Well, since he has a root node, he's really only described the *use* of this data structure implementation for a rooted tree. As you point out, the implementation itself is more genera

Re: Is there a standard name for this tree structure?

2010-04-04 Thread Patrick Maupin
On Apr 4, 10:41 am, Patrick Maupin wrote: > The primary differences between this structure and just haphazardly > wiring up random objects into a directed graph are that (1) there may > be some performance differences (but when the garbage collector has to > figure out how to break c

Re: off topic but please forgive me me and answer

2010-04-04 Thread Patrick Maupin
On Apr 4, 10:00 am, rantingrick wrote: > This is amazing, how can such an off topic post based completely on > lunacy exist so long here? 54 posts and counting. I think i had this > very argument in grade school. We have SD'A, Tim Chase, MSRB, and yes > even Steve Holden again participating in th

Re: In disGuiodoise?

2010-04-04 Thread Patrick Maupin
On Apr 4, 11:14 am, "Alf P. Steinbach" wrote: > "He walks among you, and you don't recognize him" - Old jungle proverb > > Hm, interesting Google results for that phrase. Interesting self-promotion :-) http://www.google.com/#q=%22He+walks+among+you,+and+you+don%27t+recognize+him%22&hl=en&safe=of

Re: C-style static variables in Python?

2010-04-04 Thread Patrick Maupin
On Apr 4, 1:57 pm, John Nagle wrote: >     If you want functions with state, use an object. That's what they're > for.  Don't muck with the internal representation of functions. > While "Don't muck with the internal representation of functions" is excellent advice over 99% of the time, it is also

Re: passing command line arguments to executable

2010-04-05 Thread Patrick Maupin
On Apr 5, 11:22 am, mcanjo wrote: > On Apr 4, 6:32 am, Simon Brunning wrote: > > > > > On 3 April 2010 18:20, mcanjo wrote: > > > > I tried doing the following code: > > > > from subprocess import Popen > > > from subprocess import PIPE, STDOUT > > > exefile = Popen('pmm.exe', stdout = PIPE, std

Re: C-style static variables in Python?

2010-04-05 Thread Patrick Maupin
On Apr 5, 6:50 pm, Ethan Furman wrote: (Posted some code with a timeit...) Well, I'm not going to debug this, but with the *original* thing you posted, and the thing I posted, with a call and everything (more realistic scenario), the exception version seems slower on my machine: #!/usr/bin/env

Re: sum for sequences?

2010-04-06 Thread Patrick Maupin
On Apr 6, 8:39 am, Albert van der Horst wrote: > To a mathematician sum(set) suggest that the order of summation > doesn't matter. (So I wouldn't use sum for concatenating lists.) > Harshly, sum() should be used only for operator + both associative and > commutative. That's all well and good, bu

Re: s-expression parser in python

2010-04-06 Thread Patrick Maupin
On Apr 6, 7:02 pm, James Stroud wrote: I have a parser/emitter I wrote about 4 years ago for EDIF. Take a look at the wikipedia article http://en.wikipedia.org/wiki/EDIF If that is close to you want, I can send it to you. The whole parser/ emitter/XML round-tripper etc. is only 500 lines, whic

Re: lambda with floats

2010-04-06 Thread Patrick Maupin
On Apr 6, 10:16 pm, monkeys paw wrote: > I have the following acre meter which works for integers, > how do i convert this to float? I tried > > return float ((208.0 * 208.0) * n) > >  >>> def s(n): > ...     return lambda x: (208 * 208) * n > ... >  >>> f = s(1) >  >>> f(1) > 43264 >  >>> 208 * 2

Re: lambda with floats

2010-04-06 Thread Patrick Maupin
On Apr 6, 11:04 pm, Patrick Maupin wrote: > On Apr 6, 10:16 pm, monkeys paw wrote: > > > I have the following acre meter which works for integers, > > how do i convert this to float? I tried > > > return float ((208.0 * 208.0) * n) > > >  >>> def

Re: lambda with floats

2010-04-06 Thread Patrick Maupin
On Apr 6, 11:10 pm, Patrick Maupin wrote: > On Apr 6, 11:04 pm, Patrick Maupin wrote: > > > > > On Apr 6, 10:16 pm, monkeys paw wrote: > > > > I have the following acre meter which works for integers, > > > how do i convert this to float? I tried &g

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 4:40 pm, J wrote: > Can someone make me un-crazy? > > I have a bit of code that right now, looks like this: > > status = getoutput('smartctl -l selftest /dev/sda').splitlines()[6] >         status = re.sub(' (?= )(?=([^"]*"[^"]*")*[^"]*$)', ":",status) >         print status > > Basicall

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 4:47 pm, Grant Edwards wrote: > On 2010-04-07, J wrote: > > > Can someone make me un-crazy? > > Definitely.  Regex is driving you crazy, so don't use a regex. > >   inputString = "# 1  Short offline       Completed without error     00%     >   679         -" > >   print ' '.join(input

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 7:49 pm, Patrick Maupin wrote: > On Apr 7, 4:40 pm, J wrote: > > > > > Can someone make me un-crazy? > > > I have a bit of code that right now, looks like this: > > > status = getoutput('smartctl -l selftest /dev/sda'

Re: Python and Regular Expressions

2010-04-07 Thread Patrick Maupin
On Apr 7, 3:52 am, Chris Rebert wrote: > Regular expressions != Parsers True, but lots of parsers *use* regular expressions in their tokenizers. In fact, if you have a pure Python parser, you can often get huge performance gains by rearranging your code slightly so that you can use regular expr

Re: Performance of list vs. set equality operations

2010-04-07 Thread Patrick Maupin
On Apr 7, 8:41 pm, Steven D'Aprano wrote: > On Wed, 07 Apr 2010 10:55:10 -0700, Raymond Hettinger wrote: > > [Gustavo Nare] > >> In other words: The more different elements two collections have, the > >> faster it is to compare them as sets. And as a consequence, the more > >> equivalent elements

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:02 pm, James Stroud wrote: > Patrick Maupin wrote: > > BTW, although I find it annoying when people say "don't do that" when > > "that" is a perfectly good thing to do, and although I also find it > > annoying when people tell you what

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:36 pm, Grant Edwards wrote: > On 2010-04-08, Patrick Maupin wrote:> On Apr 7, 4:47?pm, > Grant Edwards wrote: > >> On 2010-04-07, J wrote: > > >> > Can someone make me un-crazy? > > >> Definitely. ?Regex is driving you crazy, so d

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:51 pm, Steven D'Aprano wrote: > On Wed, 07 Apr 2010 18:03:47 -0700, Patrick Maupin wrote: > > BTW, although I find it annoying when people say "don't do that" when > > "that" is a perfectly good thing to do, and although I also find it >

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:51 pm, Steven D'Aprano wrote: > This is one of the reasons we're so often suspicious of re solutions: > > >>> s = '# 1  Short offline       Completed without error       00%' > >>> tre = Timer("re.split(' {2,}', s)", > > ... "import re; from __main__ import s")>>> tsplit = Timer("[x f

Re: Regex driving me crazy...

2010-04-07 Thread Patrick Maupin
On Apr 7, 9:51 pm, Steven D'Aprano wrote: BTW, I don't know how you got 'True' here. > >>> re.split(' {2,}', s) == [x for x in s.split('  ') if x.strip()] > True You must not have s set up to be the string given by the OP. I just realized there was an error in my non-regexp example, that actua

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Patrick Maupin
On Apr 8, 1:49 pm, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:

Re: Dynamically growing an array to implement a stack

2010-04-08 Thread Patrick Maupin
On Apr 8, 3:21 pm, "M. Hamed" wrote: > I have trouble with some Python concept. The fact that you can not > assign to a non-existent index in an array. For example: > > a = [0,1] > a[2] => Generates an error > > I can use a.append(2) but that always appends to the end. Sometimes I > want t

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Patrick Maupin
On Apr 8, 3:40 pm, gry wrote: > >    >>> s='555tHe-rain.in#=1234' > >    >>> import re > >    >>> r=re.compile(r'([a-zA-Z]+|\d+|.)') > >    >>> r.findall(s) > >    ['555', 'tHe', '-&

Re: lambda with floats

2010-04-08 Thread Patrick Maupin
On Apr 8, 6:06 pm, monkeys paw wrote: > On 4/7/2010 1:08 PM, Peter Pearson wrote: > > > > > On Tue, 06 Apr 2010 23:16:18 -0400, monkeys paw  wrote: > >> I have the following acre meter which works for integers, > >> how do i convert this to float? I tried > > >> return float ((208.0 * 208.0) * n)

Re: Performance of list vs. set equality operations

2010-04-08 Thread Patrick Maupin
On Apr 8, 6:35 pm, "Gabriel Genellina" wrote: > The CPython source contains lots of shortcuts like that. Perhaps the   > checks should be stricter in some cases, but I imagine it's not so easy to   > fix: lots of code was written in the pre-2.2 era, assuming that internal   > types were not subcl

Re: Dynamically growing an array to implement a stack

2010-04-08 Thread Patrick Maupin
On Apr 8, 3:54 pm, "M. Hamed" wrote: > Thanks Patrick, that is what I was exactly looking for. You're welcome! But I have to say, you should consider what Paul and Lie are saying. In general, when I use a stack, I just use append() and pop(), as they mention, and let the list

Re: The Regex Story

2010-04-08 Thread Patrick Maupin
On Apr 8, 9:32 pm, Dotan Cohen wrote: > > Regexes do have their uses. It's a case of knowing when they are the > > best approach and when they aren't. > > Agreed. The problems begin when the "when they aren't" is not recognised. Arguing against this is like arguing against motherhood and apple pi

Re: lambda with floats

2010-04-09 Thread Patrick Maupin
On Apr 9, 1:22 pm, monkeys paw wrote: > On 4/9/2010 3:43 AM, Bas wrote: > > > On Apr 7, 6:15 am, Patrick Maupin  wrote: > >> I should stop making a habit of responding to myself, BUT.  This isn't > >> quite an acre in square feet.  I just saw the 43xxx and ass

Re: Performance of list vs. set equality operations

2010-04-09 Thread Patrick Maupin
On Apr 9, 1:07 pm, "Gabriel Genellina" wrote: > En Thu, 08 Apr 2010 21:02:23 -0300, Patrick Maupin   > escribió: > > > On Apr 8, 6:35 pm, "Gabriel Genellina" wrote: > > >> The CPython source contains lots of shortcuts like that. Perhaps the   >

Re: Striving for PEP-8 compliance

2010-04-09 Thread Patrick Maupin
On Apr 9, 5:31 pm, Lawrence D'Oliveiro wrote: > >> Anybody who ever creates another indentation-controlled language should > >> be beaten to death with a Guido van Rossum voodoo doll. > > >     No ... > > Yes, because otherwise you wouldn’t have stupid problems like the one which > is preoccupying

Re: Striving for PEP-8 compliance

2010-04-10 Thread Patrick Maupin
On Apr 10, 5:10 am, Lawrence D'Oliveiro wrote: > In message <18988a53-e88f-4abf- > > a83a-314b16653...@x12g2000yqx.googlegroups.com>, Patrick Maupin wrote: > > I want nothing to do with any programmer who would mis-indent their > > code. > > But what happe

Re: On Class namespaces, calling methods

2010-04-10 Thread Patrick Maupin
On Apr 10, 9:26 am, vsoler wrote: > class Uno: >     a=1 >     def m(): >         print "mouse" > ... > I cannot write >       Uno.m() By default (at least in Python 2.x), Python will pass any function which is accessed through getattr on class or instance (usually called a "method") an instan

Re: Python and Regular Expressions

2010-04-10 Thread Patrick Maupin
On Apr 8, 5:13 am, Nobody wrote: > On Wed, 07 Apr 2010 18:25:36 -0700, Patrick Maupin wrote: > >> Regular expressions != Parsers > > > True, but lots of parsers *use* regular expressions in their > > tokenizers.  In fact, if you have a pure Python parser, you can oft

Re: Python and Regular Expressions

2010-04-10 Thread Patrick Maupin
On Apr 10, 11:35 am, Neil Cerutti wrote: > On 2010-04-10, Patrick Maupin wrote: > > as Pyparsing".  Which is all well and good, except then the OP > > will download pyparsing, take a look, realize that it uses > > regexps under the hood, and possibly be very confused. &

Re: doctest.testfile fails on text files with Windows line endings

2010-04-10 Thread Patrick Maupin
On Apr 10, 10:16 pm, Steven D'Aprano wrote: > After converting a text file containing doctests to use Windows line > endings, I'm getting spurious errors: > > ValueError: line 19 of the docstring for examples.txt has inconsistent > leading whitespace: '\r' > > I don't believe that doctest.testfile

<    1   2   3   4   5   6   7   >