Draw rectangle on a Window DC

2007-01-04 Thread Raymond
Hi: I want to Draw rectangle on Dc when gived a position. Can you teach me? Let me view your code? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

sed to python: replace Q

2008-04-29 Thread Raymond
's/].*$//' yet the following Python code does nothing: line = line.replace('^.*\[', '', 1) line = line.replace('].*$', '') Is there a decent description of string.replace() somewhere? Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: sed to python: replace Q

2008-05-06 Thread Raymond
>Another approach is to use the split() function in "re" module. Ah ha, thar's the disconnect. Thanks for all the pointers, my def is now working. Still don't understand the logic behind this design though. I mean why would any programming language have separate search or find functions, one for

Re: New Science Discovery: Perl Detractors Remain Idiots After A Decade

2012-03-12 Thread Raymond Wiker
Shmuel (Seymour J.) Metz writes: > In , on 03/12/2012 >at 11:27 AM, Albert van der Horst said: > >>You're confused. > > No, s/h/it is just an acephalic troll with delusions of adequacy. Another way to put it is to say that Xah is a legend in his own mind. -- http://mail.python.or

Re: Standard Deviation One-liner

2011-06-03 Thread Raymond Hettinger
http://mathcentral.uregina.ca/QQ/database/QQ.09.06/h/murtaza2.html Another interesting avenue to is aim for highest possible accuracy. Consider using math.fsum() to avoid rounding errors in the summation of large numbers of nearly equal values. Raymond - follow my python tips on

Bloom Filter in 22 lines of Python (updated)

2011-06-03 Thread Raymond Hettinger
Thanks for all the feedback on the earlier post. I've updated the recipe to use a cleaner API, simpler code, more easily subclassable, and with optional optimizations for better cache utilization and speed: http://code.activestate.com/recipes/577684-bloom-filter/ Ra

Re: Bloom Filter in 22 lines of Python (updated)

2011-06-08 Thread Raymond Hettinger
On Jun 6, 10:47 am, geremy condra wrote: > On Fri, Jun 3, 2011 at 1:17 PM, Raymond Hettinger wrote: > > Thanks for all the feedback on the earlier post. > > > I've updated the recipe to use a cleaner API, simpler code, > > more easily subclassable, and with optional

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-25 Thread Raymond Hettinger
foo)) That works great and is very clear. If you want to also preserve order, use an OrderedDict: >>> list(OrderedDict.fromkeys('abracadabra')) ['a', 'b', 'r', 'c', 'd'] Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries and incrementing keys

2011-06-25 Thread Raymond Hettinger
). For new keys, it is a little slower because it calls the __missing__ method which returns zero. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: blist question

2011-07-07 Thread Raymond Hettinger
erged into Python source code? It was rejected as a replacement for the existing list implementation. There is some chance it will get accepted into the collections module someday. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 12:47 am, Xah Lee wrote: > i hope you'll participate. Just post solution here. Thanks. http://pastebin.com/7hU20NNL Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 7:15 am, Thomas 'PointedEars' Lahn wrote: > Did you notice the excessive crosspost?  Please do not feed the troll. IMO, this was a legitimate cross post since it is for a multi-language programming challenge and everyone can learn from comparing the results. Ray

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
utput of the program and running it through emacs to see that the cursor gets moved exactly to the location of the mismatched delimiter. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: list(), tuple() should not place at "Built-in functions" in documentation

2011-07-19 Thread Raymond Hettinger
udes str,int,list,tuple, etc in both Section 2 for builtin functions and Section 5 for builtin types. 'nuff said, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido rethinking removal of cmp from sort method

2011-03-26 Thread Raymond Hettinger
with older, unmaintained versions of Python. When it comes to moving pow() to another module or changing the signature for the __pow__ magic method, there's not much of a win to be had, but it will affect tons of existing code (including examples in printed books where pow() is commonly used in

Re: Understanding the Pystone measurement

2011-03-26 Thread Raymond Hettinger
00 pystones and your new shiny macbook scores 84000, then you can expect your non-i/o bound single threaded python apps to run about seven times faster on the new machine. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Understanding the Pystone measurement

2011-03-26 Thread Raymond Hettinger
I forgot to mention that PyStone is just a Python translation from C of the venerable Dhrystone benchmark. See http://en.wikipedia.org/wiki/Dhrystone for a short write-up on the history, purposes, and limitations of the benchmark. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: FW: ciao

2011-03-26 Thread Raymond Hettinger
t the length of each group, and emit the value whenever the count is more than one: >>> s = [1,2,3,3,4,4,5,6,7,7,7] >>> [k for k, g in groupby(s) if len(list(g)) > 1] [3, 4, 7] Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido rethinking removal of cmp from sort method

2011-03-28 Thread Raymond Hettinger
cations of the last paragraph is that if 2.7 style cmp- logic were reinstated in 3.3, not only would it clutter the API with two-ways-to-do-it, it would also disadvantage make the common case (using key-functions) run much more slowly. In other words, the performance mavens will have shot themselves (and us) in the foot. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
from collections import Counter from itertools import product print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, product(range(6), repeat=8))).items( almost-normally-yours, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
*** * *** * Re-posting (forgot to attach the output). Besides the interesting output, other interesting virtues include very low memory usage and that the inner-loop pipeline runs entirely in C

Re: delete namespaces

2011-03-29 Thread Raymond Hettinger
e the reload() function: Help on built-in function reload in module __builtin__: reload(...) reload(module) -> module Reload the module. The module must have been successfully imported before. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Dictionary Descriptors

2011-03-30 Thread Raymond Hettinger
u all might find it to be both interesting and educational. For more details on how it works and how it relates to descriptors, see http://mail.python.org/pipermail/python-ideas/2011-March/009657.html Raymond sample code class MyDict(object): def __init__(self, ma

Re: Fun python 3.2 one-liner

2011-03-30 Thread Raymond Hettinger
(list(g))) for k, g in groupby(sorted('abracadabra'))] [('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)] >>> [k for k, g in groupby(sorted('abracadabra')) if len(list(g)) > 1] ['a', 'b', 'r

Re: learn python the hard way exercise 42 help

2011-03-30 Thread Raymond Hettinger
t statements to the while loop: def play(self): next = self.start while True: room = getattr(self, next) print "--- Calling the method:", room, "---" next = room() print "--- That method retu

Re: popular programs made in python?

2011-03-30 Thread Raymond Hettinger
On Mar 29, 7:32 am, Neil Alt wrote: > i mean made with python only, not just a small part of python. BitTorrent was a huge success. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: delete namespaces

2011-03-30 Thread Raymond Hettinger
If you develop banner.py with adequate tests, you will want to restart > the test anyway, and you should not need to modify much thereafter. This is excellent advice. You're much better-off starting fresh each time. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Directly Executable Files in Python

2011-03-30 Thread Raymond Hettinger
l#how-can-i-create-a-stand-alone-binary-from-a-python-script Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Why aren't copy and deepcopy in __builtins__?

2011-03-30 Thread Raymond Hettinger
T, he was right. I've seen large projects where deepcopy and copy where not used even once. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: best python games?

2011-03-30 Thread Raymond Hettinger
most downloaded as far as i can tell At Pycon, I saw some impressive looking games written during the PyWeek, Python Game Programming Challenge http://www.pyweek.org/ I think they're fine examples of what Python is capable of. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Raymond Hettinger
need to make @property accessors that get and set the underlying attribute. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: a better way to invert a list?

2011-04-05 Thread Raymond Hettinger
[Ian Kelly] > Which is O(n).  If that is too verbose, you could also use a dictionary: > > def invert(p): >     return dict(map(reversed, enumerate(p))) def inv(p): return dict(zip(p, itertools.count())) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Fun python 3.2 one-liner

2011-04-05 Thread Raymond Hettinger
DE widows) much wider than 80 > characters. I'm using 140 for python these days. Seriously, who would > want to limit him/herself to 80 characters in 2011? I wonder how many people will shorten otherwise clear variable names just to get their lines to fit in 80 characters? Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
y exist and the whole operation becomes equivalent to an update(). You can see the same behavior with regular dictionaries: >>> d = dict(a=1, b=2) >>> d.__init__(b=4, c=5) >>> d {'a': 1, 'c': 5, 'b': 4} Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
d dict code internally calls __update() instead of update() so that a subclass can override update() without breaking the constructor * eval(repr(obj)) should round-trip whereever possible * containers should behave reasonable well even if someone makes the container reference itself: a=[]; a

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Raymond Hettinger
#x27; module for > details: > > http://docs.python.org/library/threading.html The docs for Python3.2 have a nice example for downloading multiple webpages in parallel: http://docs.python.org/py3k/library/concurrent.futures.html#threadpoolexecutor-example Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
t; from itertools import * >>> list(chain([1,2,3], ErrorResult(), [4,5,6])) [1, 2, 3, <__main__.ErrorResult object at 0x2250f70>, 4, 5, 6] > Any idea for a working and elegant solution? Hope these ideas have helped. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
) recipe in http://docs.python.org/py3k/library/itertools.html#itertools-recipes Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating unit tests on the fly

2011-04-08 Thread Raymond Hettinger
creator running as a producer thread. Writing your own test runner isn't difficult. 1) wait on the queue for a new test case. 2) invoke test_case.run() with a TestResult object to hold the result 3) accumulate or report the results 4) repeat forever. Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: python on iPad (PyPad)

2011-04-09 Thread Raymond Hettinger
itertools for example). I don't now how difficult the work is, but it would be nice to have a way to save multiple scripts, have an interactive prompt, and get more modules to work (random, collections, functools). Thanks again for your work. Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
ults.copy() result.update(d) Another approach is to use something like ChainMap() which has been added to Python 3.3. http://docs.python.org/dev/library/collections.html#collections.ChainMap result = ChainMap(d, multiple_defaults) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
t values. Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Questions about GIL and web services from a n00b

2011-04-15 Thread Raymond Hettinger
dvantage of multiple-cores is to run multiple pythons in separate processes. Threading is really only an answer if you need to share data between threads, if you only have limited scaling needs, and are I/O bound rather than CPU bound Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Raymond Hettinger
On Apr 16, 1:24 pm, candide wrote: > Consider the following code : > > # -- > def bool_equivalent(x): >      return True if x else False It's faster to write: def bool_equivalent(x): return not not x Raymond -- http://mail.python.

Re: suggestions, comments on an "is_subdict" test

2011-04-23 Thread Raymond Hettinger
uot;bar": 1} >  >>> base_dct = {"foo": 0, "bar": 1, "baz": 2} >  >>> >  >>> test_dct.items() <= base_dct.items() > False > > In Python 3: > >  >>> test_dct = {"foo": 0, "bar": 1} >  >>> base_dct = {"foo": 0, "bar": 1, "baz": 2} >  >>> test_dct.items() <= base_dct.items() > True > > YMMV That is because it is spelled differently in Python 2.7: >>> test_dct = {"foo": 0, "bar": 1} >>> base_dct = {"foo": 0, "bar": 1, "baz": 2} >>> test_dct.viewitems() <= base_dct.viewitems() True Raymond -- http://mail.python.org/mailman/listinfo/python-list

Simple map/reduce utility function for data analysis

2011-04-25 Thread Raymond Hettinger
Here's a handy utility function for you guys to play with: http://code.activestate.com/recipes/577676/ Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple map/reduce utility function for data analysis

2011-04-26 Thread Raymond Hettinger
On Apr 25, 7:42 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a handy utility function for you guys to play with: > >    http://code.activestate.com/recipes/577676/ > > Cute, but why not use collections.defaultdict for the return dict? > Untested: My

Re: Case study: debugging failed assertRaises bug

2011-04-26 Thread Raymond Hettinger
e the lessons learned will be helpful to your readers. Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: De-tupleizing a list

2011-04-26 Thread Raymond Hettinger
t; ['0A', '1B', '2C', '3D',... You could unpack the 1-tuple the same way you would with a 2-tuple. >>> result = [('0A',), ('1B',), ('2C',), ('3D',)] >>> for elem, in result: print elem 0A 1B 2C 3D Raymond http://twitter.com/raymondh -- http://mail.python.org/mailman/listinfo/python-list

Have you read the Python docs lately?

2011-04-27 Thread Raymond Hettinger
/howto/sorting.html http://docs.python.org/dev/library/collections.html#collections.namedtuple Raymond python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Have you read the Python docs lately?

2011-04-28 Thread Raymond Hettinger
On Apr 27, 11:28 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > A number of developers have been working on adding examples and useful > > advice to the docs.  To sharpen your skills, here are some pieces of > > recommended reading: > > Thanks, those are n

Coolest Python recipe of all time

2011-05-02 Thread Raymond Hettinger
I think it is time to give some visibility to some of the instructive and very cool recipes in ActiveState's python cookbook. My vote for the coolest recipe of all time is: http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ What are your favorites? Ra

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
near equation to a*x+b (= 0 implied). > > Hmmm... so if we used quaternions, could we solve systems > of linear equations in 3 variables? Yes :-) The implementation of a Quanternion class and the Quartic equation is left as an exercise for the reader ;-) Raymond @raymondh -- http://mai

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
, and most boring recipe ;-) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
requires three lines of executing code and at least 6 lines of additional > comment. Hopefully accompanied by an excuse of the developer. If you found nothing educational, interesting, or amusing about the three-line linear equation solver, then you're *really* going to hate this one:

Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
Here's a 22-line beauty for a classic and amazing algorithm: http://bit.ly/bloom_filter The wiki article on the algorithm is brief and well-written: http://en.wikipedia.org/wiki/Bloom_filter It turns out that people in the 1970's were pretty smart :-) Raymond --- follow my ot

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
ter was mentioned? Yes! As a matter of fact there was: http://www.slideshare.net/c.titus.brown/pycon-2011-talk-ngram-assembly-with-bloom-filters Raymond --- follow my other python tips and recipes on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 12:42 pm, Terry Reedy wrote: > On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > > The wiki article on the algorithm is brief and well-written: > >htt

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 12:27 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > The use of pickle to serialize the keys is a little bit suspicious if > there might be a reason to d

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
10 false positives in 5 runs is good. I've just posted an update with a spell checker using a large dictionary. That should make it easy to validate against some real world text samples. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Coolest Python recipe of all time

2011-05-06 Thread Raymond Hettinger
#x27;], ['fox', 'hare', 'turtle', 'kangaroo'], ['lazy', 'stupid', 'sleepy', 'confused'], ['dog', 'aardvark', 'sloth', 'wombat'], ) amb(lambda x, y, z: x*x + y*y == z*z, range(1, 11), range(1, 11), range(1, 11), ) Raymond follow my recipes and tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-06 Thread Raymond Hettinger
eps/pep-0008/ for the official recommendation. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Coolest Python recipe of all time

2011-05-07 Thread Raymond Hettinger
lver", no? FWIW, here's one of my favorite brute-force solvers: http://code.activestate.com/recipes/576615-alphametics-solver/ Raymond --- follow my recipes and tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Coolest Python recipe of all time

2011-05-09 Thread Raymond Hettinger
x27;, >         'Portuguese': 'en_pt', >         'Dutch'     : 'en_nl', >         'Japanese'  : 'en_ja', >     } > >     def translate(lang, text): >         kwds = { 'trtext' : text, 'lp' : langua

Re: string formatting

2011-05-10 Thread Raymond Hettinger
cpython/file/7254c03b7180/Lib/collections.py#l235 Note the template has both {typename} formatting for the first pass and %r style formatting in the generated code. Raymond follow my tips and recipes on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3 dict question

2011-05-10 Thread Raymond Hettinger
se: key, val = next(iter(MyDict.items())) The latter is nice because next() allows you to supply a default argument in case the dictionary is emtpy: key, val = next(iter(MyDict.items()), (None, None)) Raymond - follow my tips and recipes on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Raymond Wiker
Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On 18 May 2011 09:16:26 -0700, Thomas A. Russ >wrote: > : Well, unless you have a tree with backpointers, you have to keep the > : entire parent chain of nodes visited. Otherwise, you won't be able to > : fi

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Raymond Wiker
Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On Wed, 18 May 2011 20:20:01 +0200, Raymond Wiker >wrote: > : I don't think anybody mentioned *binary* trees. The context was > : directory traversal, in which cas

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Raymond Wiker
Hans Georg Schaathun writes: > ["Followup-To:" header set to comp.lang.python.] > On Wed, 18 May 2011 21:09:15 +0200, Raymond Wiker >wrote: > : > In the sense that the tree itself is a stack, yes. But if we > : > consider the tree (or one of its branches

Re: Faster Recursive Fibonacci Numbers

2011-05-24 Thread Raymond Hettinger
There are many ways to write this function. The one I like shows-off a general purpose dynamic programming technique while staying *very* close to a common textbook definition of a fibonacci number: @functools.lru_cache() def fibo(n): return 1 if n < 2 else fibo(n-1) + fibo(n-2) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: super() in class defs?

2011-05-25 Thread Raymond Hettinger
r Python toolkit. If any of the comp.lang.python readers want to review and comment on my latest draft, please email me and I'll send it to you directly. Cheers, Raymond Hettinger my email address is listed at http://users.rcn.com/python/download/Descriptor.htm -- http://mail.pytho

Re: Parse config file and command-line arguments, to get a single collection of options

2011-05-25 Thread Raymond Hettinger
ld get you started on your grand unified, do- everything-at-once vision with minimal deviation from the standard library. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Python's super() considered super!

2011-05-26 Thread Raymond Hettinger
uper-considered-super/ It would also be great if some of you would upvote it on HackerNews. Raymond Hettinger --- follow my python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-26 Thread Raymond Hettinger
> It would also be great if some of you would upvote it on HackerNews. Here's a link to the super() how-to-guide and commentary: bit.ly/ iFm8g3 Raymod -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Raymond Hettinger
27;s tweet (where shorter is better). Hope you enjoyed the post. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Class decorators might also be super too

2011-05-28 Thread Raymond Hettinger
David Beazley wrote a class decorator blog post that is worth reading: http://dabeaz.blogspot.com/2011/05/class-decorators-might-also-be-super.html Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Class decorators might also be super too

2011-05-29 Thread Raymond Hettinger
deeper understanding of class decorators, mixins, and inheritance. That makes the post worthwhile even if someone never ends up using those particular coding technique. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: float("nan") in set or as key

2011-05-29 Thread Raymond Hettinger
constant might yield twin paradoxes and other curiousities ;-) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: 3.1.4 release candidate 1

2011-05-29 Thread Raymond Hettinger
On May 29, 3:44 pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a swallow to announce a > release candidate for the fourth bugfix release for the Python 3.1 > series, Python > 3.1.4. The Pi release of Python :-) Raymond P.S. For the

Updated blog post on how to use super()

2011-05-31 Thread Raymond Hettinger
goal is to serve as a reliable guide to using super and how to design cooperative classes in a way that lets subclasses compose and extent them. Raymond Hettinger follow my python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

RE: Changing calling sequence

2022-05-11 Thread David Raymond
>> I have a function that I use to retrieve daily data from a >> home-brew database. Its calling sequence is; >> >> def TempsOneDay( year, month, date ): >> >> After using it (and its friends) for a few years, I've come to >> realize that there are times where it would be advantageous to >> invok

RE: Changing calling sequence

2022-05-12 Thread David Raymond
>>def TempsOneDay(*dateComponents): >>if len(dateComponents) == 3: >>year, month, date = dateComponents >>elif len(dateComponents) == 1 and isinstance(dateComponents[0], >> datetime.date): >>year, month, date = (dateComponents[0].year, dateComponents[0].month, >> dateCompo

Pip upgrade causing issues in 3.10

2022-07-19 Thread David Raymond
So after a long while I'm finally getting around to upgrading to 3.10 on Windows from 3.9, and my first pip upgrade is causing issues with the installation. Problem seems to be that I run pip from a command prompt in the Scripts folder, and it seems pip is trying to completely remove the Script

RE: Parallel(?) programming with python

2022-08-08 Thread David Raymond
>> But, an easier and often >> better option for concurrent data access is use a (relational) >> database, then the appropriate transaction isolation levels >> when reading and/or writing. >> > > That would obviusly save some coding (but would introduce the need to > code the interaction with the d

RE: Find 6-letter words that are hidden (embedded) within

2023-02-24 Thread David Raymond
> Find 6-letter words that are hidden (embedded) within each row of letters. > The letters are in the correct order. > > 1. JSOYOMFUBELR > 2. SCDUARWDRLYE > 3. DASNAGEFERTY > 4. CLULOOTSCEHN > 5. USENEARSEYNE > The letters are in the correct order. S

RE: How to escape strings for re.finditer?

2023-02-28 Thread David Raymond
> I wrote my previous message before reading this.  Thank you for the test you > ran -- it answers the question of performance.  You show that re.finditer is > 30x faster, so that certainly recommends that over a simple loop, which > introduces looping overhead.  >>     def using_simple_loop(

RE: Debugging reason for python running unreasonably slow when adding numbers

2023-03-15 Thread David Raymond
> Or use the sum() builtin rather than reduce(), which was > *deliberately* removed from the builtins. The fact that you can get > sum() without importing, but have to go and reach for functools to get > reduce(), is a hint that you probably shouldn't use reduce when sum > will work. Out of curios

RE: Debugging reason for python running unreasonably slow when adding numbers

2023-03-15 Thread David Raymond
> Then I'm very confused as to how things are being done, so I will shut > up. There's not enough information here to give performance advice > without actually being a subject-matter expert already. Short version: In this specific case "weights" is a 5,147 element list of floats, and "input" is

RE: Problem with __sub__

2023-03-23 Thread David Raymond
I believe your problem is __rsub__, not __sub__. When you havethen that uses the "r" version of the operators. In your __rsub__ (used when you have - ) you instead return - which is backwards. Notice how the final return should also be -4,95 and not the +4,95 it's returning. > If on th

RE: Initialising a Config class

2023-04-11 Thread David Raymond
Not sure if I'm fully understanding the question. But one option instead of making everything class attributes is to just define __getattr__ for when it doesn't find an attribute. Won't work for every single valid section and option name (because of spaces, name overlaps, etc) but should cover

RE: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread David Raymond
In regards to the various comments about adding in print() calls what I've found myself doing is to basically always use the logging module, and use logging.debug() for those. Somewhere at the top of the script I'll have a line like... DEBUG = False ...and when initializing the handler to stdo

RE: on writing a while loop for rolling two dice

2021-08-30 Thread David Raymond
> def how_many_times(): > x, y = 0, 1 > c = 0 > while x != y: > c = c + 1 > x, y = roll() > return c, (x, y) Since I haven't seen it used in answers yet, here's another option using our new walrus operator def how_many_times(): roll_count = 1 while (rolls := roll())[0] !=

RE: frozenset can be altered by |=

2021-11-22 Thread David Raymond
>> (venv_3_10) marco@buzz:~$ python >> Python 3.10.0 (heads/3.10-dirty:f6e8b80d20, Nov 18 2021, 19:16:18) >> [GCC 10.1.1 20200718] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> a = frozenset((3, 4)) >> >>> a >> frozenset({3, 4}) >> >>> a |= {5,} >> >>> a

RE: One-liner to merge lists?

2022-02-22 Thread David Raymond
> Is there a simpler way? >>> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} >>> [a for b in d.values() for a in b] ['aaa', 'bbb', 'ccc', 'fff', 'ggg'] >>> -- https://mail.python.org/mailman/listinfo/python-list

Re: best parallelisation strategy on python

2018-04-21 Thread raymond . nusbaum
On Wednesday, April 18, 2018 at 7:16:19 PM UTC-6, simona bellavista wrote: > I have a code fortran 90 that is parallelised with MPI. I would like to > traslate it in python, but I am not sure on the parallelisation strategy and > libraries. I work on clusters, with each node with 5GB memory and 1

RE: Checking whether type is None

2018-07-24 Thread David Raymond
https://docs.python.org/3.7/library/constants.html "None The sole value of the type NoneType..." "x is None" and "type(x) is type(None)" are equivalent because of that. I think though that the better way to do the first tests would be to use isinstance https://docs.python.org/3.7/library/functi

RE: Python bug in ArcGIS - Urban Network analysis tool

2018-07-30 Thread David Raymond
A note that Arc may have installed its own version of Python, which it is using from within its own tools. For example, I've got a full Python installation in C:\Python27\ArcGIS10.2 which Arc installed on top of a preexisting installation in C:\Python27. So you may need to explicitly run it with

RE: Python Console Menu

2018-07-31 Thread David Raymond
Take a look at the subprocess module for how to "spawn new processes, connect to their input/output/error pipes, and obtain their return codes." https://docs.python.org/2/library/subprocess.html -Original Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@p

RE: Dealing with errors in interactive subprocess running python interpreter that freeze the process

2018-08-01 Thread David Raymond
A couple notes: -I think the Python interpreter actually sends its output to stderr, so to capture it you'd probably want it to go to the same place as stdout, so use stderr = subprocess.STDOUT -You're only reading 1 line out output for each thing, so if 1 command creates multiple lines of out

  1   2   3   4   5   6   7   8   9   >