Re: My son wants me to teach him Python

2013-06-13 Thread Paul Rubin
Tomasz Rola writes: > I've reposted on another list and got this reply. At first I was sceptic > a bit, but for the sake of completeness, here goes. Processing language > seems to be interesting in its own right. Examples are Java-flavoured, > images are ok. There is a book "Python for Kids" t

Re: [newbie] Equivalent to PHP?

2012-06-21 Thread Paul Rubin
Gilles writes: > Do Python hosters provide a VM so that it's just like a remote Linux > server where I'm free to install whatever I want, or do they force > users to use specific versions of Python and specific frameworks eg. > Django? There are both kinds. The first kind is called a Virtual Pri

Re: tiffany 0.6.1 released

2012-06-30 Thread Paul Rubin
Christian Tismer writes: > Tiffany stands for any tiff. The tiny module solves a large set of > problems, has no dependencies and just works wherever Python works. > Tiffany was developed in the course of the *DiDoCa* project and will > always appear on PyPi. This sounds pretty neat. I didn't co

Re: adding a simulation mode

2012-07-04 Thread Paul Rubin
andrea crotti writes: > copytree(src, dest) becomes: > if not PRETEND_ONLY: > copytree(src, dest) > > But I don't like it too much because I would have to add a lot of > garbage around.. I've had good results writing the module under test in the style of a java applet, i.e. one of its args is

2 + 2 = 5

2012-07-04 Thread Paul Rubin
I just came across this (https://gist.github.com/1208215): import sys import ctypes pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5)) five = ctypes.cast(id(5), pyint_p) print(2 + 2 == 5) # False five.contents[five.contents[:].index(5)] = 4 print(2 + 2 == 5) # Tru

Re: Finding duplicate file names and modifying them based on elements of the path

2012-07-18 Thread Paul Rubin
"larry.mart...@gmail.com" writes: > I have an interesting problem I'm trying to solve. I have a solution > almost working, but it's super ugly, and know there has to be a > better, cleaner way to do it. ... > > My solution involves multiple maps and multiple iterations through the > data. How woul

Re: Finding duplicate file names and modifying them based on elements of the path

2012-07-19 Thread Paul Rubin
"larry.mart...@gmail.com" writes: > Thanks for the reply Paul. I had not heard of itertools. It sounds > like just what I need for this. But I am having 1 issue - how do you > know how many items are in each group? Simplest is: for key, group in groupby(xs, lambda x:(x[-1],x[4],x[5])): gs

Re: Finding duplicate file names and modifying them based on elements of the path

2012-07-19 Thread Paul Rubin
"larry.mart...@gmail.com" writes: > You can't do a len on the iterator that is returned from groupby, and > I've tried to do something with imap or defaultdict, but I'm not > getting anywhere. I guess I can just make 2 passes through the data, > the first time getting counts. Or am I missing

Re: Finding duplicate file names and modifying them based on elements of the path

2012-07-20 Thread Paul Rubin
"larry.mart...@gmail.com" writes: > It seems that if you do a list(group) you have consumed the list. This > screwed me up for a while, and seems very counter-intuitive. Yes, that is correct, you have to carefully watch where the stuff in the iterators is getting consumed, including when there ar

Re: Converting a list of strings into a list of integers?

2012-07-22 Thread Paul Rubin
Tony the Tiger writes: > # options.modus_list contains, e.g., "[2,3,4]" Try this: import ast MODUS_LIST = ast.literal_eval(options.modus_list) literal_eval is like eval except it can only evaluate literals rather than calling functions and the like. The idea is you can use it on untrus

Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Paul Rubin
Dieter Maurer writes: > I have only one vague idea: should something try to terminate the > process, modules would start to lose their variables during shutdown. That happens all the time with multi-threaded programs, because the shutdown is happening concurrently with other threads doing stuff.

Re: Is Python a commercial proposition ?

2012-07-29 Thread Paul Rubin
Rodrick Brown writes: > Hence the reason why no one will seriously look at Python for none > glue work or simple web apps. When it comes to designing complex > applications that need to exploit large multicore systems Python just > isn't an option. That's wrong, I've run multicore apps in Python

Re: Is Python a commercial proposition ?

2012-07-30 Thread Paul Rubin
Steven D'Aprano writes: > And at that level, you aren't going to write your app in Python anyway, > and not because of the GIL. (These microcontrollers are unlikely to have > multiple cores -- why the hell does your microwave oven need two cores?) http://greenarrays.com ;-) > It seems to me th

Re: On-topic: alternate Python implementations

2012-08-04 Thread Paul Rubin
Stefan Krah writes: > In the free software world, apparently many people like C. C is also > quite popular in the zero-fault software world: Several verification > tools do exist and Leroy et al. are writing a certified compiler for > C to plug the hole between the verified source code and the gen

Re: On-topic: alternate Python implementations

2012-08-04 Thread Paul Rubin
Stefan Behnel writes: >> C is pretty poor as a compiler target: how would you translate Python >> generators into C, for example? > Depends. If you have CPython available, that'd be a straight forward > extension type. Calling CPython hardly counts as compiling Python into C. > For the yielding,

Re: On-topic: alternate Python implementations

2012-08-04 Thread Paul Rubin
Stefan Behnel writes: >> Calling CPython hardly counts as compiling Python into C. > CPython is written in C, though. So anything that CPython does can be > done in C. It's not like the CPython project used a completely unusual > way of writing C code. CPython is a relatively simple interpreter,

Re: On-topic: alternate Python implementations

2012-08-04 Thread Paul Rubin
Steven D'Aprano writes: > Runtime optimizations that target the common case, but fall back to > unoptimized code in the rare cases that the optimization doesn't apply, > offer the opportunity of big speedups for most code at the cost of > trivial slowdowns when you do something unusual. The pr

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread Paul Rubin
Steven D'Aprano writes: >> I suspect), but can't say that I've ever used a "factory function"... > If you've ever used an ordinary function decorator, you almost certainly > have. > If you've every created a closure, you definitely have. Or anything with a __iter__ method... -- http://mail.pyth

Re: dictionary comprehensions with Python 2.4/2.5

2012-08-07 Thread Paul Rubin
Iryna Feuerstein writes: > code. The dictionary comprehensions were added to Python in version > 2.7 at first time. Is it possible to make it compatible with Python > 2.5 anyway? Perhaps by using the __future__ module? Not back to 2.5, but they're not that important anyway. Just use: d = dict

Re: I thought I understood how import worked...

2012-08-07 Thread Paul Rubin
Roy Smith writes: >> In general, you should avoid non-idempotent code. > I don't understand your aversion to non-idempotent code as a general > rule. Most code is non-idempotent. Surely you're not saying we > should never write: foo += 1 > or my_list.pop() > ??? I don't think "in gen

Re: Arithmetic with Boolean values

2012-08-11 Thread Paul Rubin
John Ladasky writes: > I have gotten used to switching back and forth between Boolean algebra > and numerical values. Python generally makes this quite easy. Generally ugly though, at least to my tastes. "Explicit is better than implicit" as the saying goes. > If the length of the list L is o

Re: Arithmetic with Boolean values

2012-08-12 Thread Paul Rubin
> which can be simplified to: > for x in range(len(L)//2 + len(L)%2): for x in range(sum(divmod(len(L), 2))): ... -- http://mail.python.org/mailman/listinfo/python-list

Re: set and dict iteration

2012-08-16 Thread Paul Rubin
Dave Angel writes: > Everything else is implementation defined. Why should an implementation > be forced to have ANY extra data structure to detect a static bug in the > caller's code? For the same reason the interpreter checks for type errors at runtime and raises TypeError, instead of letting

Re: set and dict iteration

2012-08-16 Thread Paul Rubin
Ian Kelly writes: > With regard to key insertion and deletion while iterating over a dict > or set, though, there is just no good reason to be doing that > (especially as the result is very implementation-specific), and I > wouldn't mind a more complete low-level check against it as long as > it's

Re: set and dict iteration

2012-08-16 Thread Paul Rubin
Steven D'Aprano writes: > Luckily, Python is open source. If anyone thinks that sets and dicts > should include more code protecting against mutation-during-iteration, > they are more than welcome to come up with a patch. Don't forget unit and > regression tests, and also a set of timing result

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Paul Rubin
Steven D'Aprano writes: > (There is an extension to UCS-2, UTF-16, which encodes non-BMP characters > using two code points. This is fragile and doesn't work very well, > because string-handling methods can break the surrogate pairs apart, > leaving you with invalid unicode string. Not good.) .

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Paul Rubin
Chris Angelico writes: > UTF-8 is highly inefficient for indexing. Given a buffer of (say) a > few thousand bytes, how do you locate the 273rd character? How often do you need to do that, as opposed to traversing the string by iteration? Anyway, you could use a rope-like implementation, or an i

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Paul Rubin
Chris Angelico writes: "asdfqwer"[4:] > 'qwer' > > That's a not uncommon operation when parsing strings or manipulating > data. You'd need to completely rework your algorithms to maintain a > position somewhere. Scanning 4 characters (or a few dozen, say) to peel off a token in parsing a UTF

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Paul Rubin
Chris Angelico writes: > Sure, four characters isn't a big deal to step through. But it still > makes indexing and slicing operations O(N) instead of O(1), plus you'd > have to zark the whole string up to where you want to work. I know some systems chop the strings into blocks of (say) a few hund

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Paul Rubin
Chris Angelico writes: > Generally, I'm working with pure ASCII, but port those same algorithms > to Python and you'll easily be able to read in a file in some known > encoding and manipulate it as Unicode. If it's pure ASCII, you can use the bytes or bytearray type. > It's not so much 'random

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Steven D'Aprano writes: > This is a long post. If you don't feel like reading an essay, skip to the > very bottom and read my last few paragraphs, starting with "To recap". I'm very flattered that you took the trouble to write that excellent exposition of different Unicode encodings in response

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Steven D'Aprano writes: > result = text[end:] if end not near the end of the original string, then this is O(N) even with fixed-width representation, because of the char copying. if it is near the end, by knowing where the string data area ends, I think it should be possible to scan backward

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Chris Angelico writes: > And of course, taking the *entire* rest of the string isn't the only > thing you do. What if you want to take the next six characters after > that index? That would be constant time with a fixed-width storage > format. How often is this an issue in practice? I wonder how

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Terry Reedy writes: >> Meanwhile, an example of the 393 approach failing: > I am completely baffled by this, as this example is one where the 393 > approach potentially wins. What? The 393 approach is supposed to avoid memory bloat and that does the opposite. >> I was involved in a project that

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Ian Kelly writes: sys.getsizeof(bytes(range(256)).decode('latin1')) > 329 Please try: print (type(bytes(range(256)).decode('latin1'))) to make sure that what comes back is actually a unicode string rather than a byte string. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Ian Kelly writes: print (type(bytes(range(256)).decode('latin1'))) > Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Abuse of Big Oh notation

2012-08-19 Thread Paul Rubin
Steven D'Aprano writes: > Of course *if* k is constant, O(k) is constant too, but k is not > constant. In context we are talking about string indexing and slicing. > There is no value of k, say, k = 2, for which you can say "People will > sometimes ask for string[2] but never ask for string[3]"

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Paul Rubin
Steven D'Aprano writes: > Paul Rubin already told you about his experience using OCR to generate > multiple terrabytes of text, and how he would not be happy if that was > stored in UCS-4. That particular text was stored on disk as compressed XML that had UTF-8 in the data field

Re: Abuse of Big Oh notation

2012-08-20 Thread Paul Rubin
Oscar Benjamin writes: > No it doen't. It is still O(k). The point of big O notation is to > understand the asymptotic behaviour of one variable as it becomes > large because of changes in other variables. Actually, two separate problems got mixed together late at night. In neither case is k an

Re: Abuse of Big Oh notation

2012-08-20 Thread Paul Rubin
Ian Kelly writes: > The difference between the two is that the former is bounded by a > constant that is fundamental to the algorithm at hand,... S is > clearly bounded by the constraints of actual shoes, so we can safely > treat S as a constant and call it O(N). Thanks, that is a good explain o

Re: How to convert base 10 to base 2?

2012-08-20 Thread Paul Rubin
Ian Kelly writes: > Everybody should know the generic algorithm, though: > from itertools import chain ... For n>0, assuming you just want the converted digits and not a string. String conversion and minus sign for n<0 left as exercise. Note this returns a generator that you can convert to a lis

Re: Why doesn't Python remember the initial directory?

2012-08-20 Thread Paul Rubin
alex23 writes: > Oh my god, how DARE people with EXPERIENCE in a language challenge the > PRECONCEPTIONS of an AMATEUR!!! HOW DARE THEY?!?! +1 QOTW :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Paul Rubin
Steven D'Aprano writes: >> http://golang.org/ref/spec#Numeric_types > Thanks. > Well that's just plain nuts. I'm not sure how Rust handles Unicode, but overall I think it is more clueful than Go while having sort of comparable goals. See: http://rust-lang.org . -- http://mail.python.org/mailman

Re: Looking for an IPC solution

2012-08-31 Thread Paul Rubin
Laszlo Nagy writes: > application will be running on a single computer, so the IPC should be > using shared memory (or mmap) and have very short response times. Zeromq (suggested by someone) is an option since it's pretty fast for most purposes, but I don't think it uses shared memory. The close

Re: Logging handler: No output

2012-09-02 Thread Paul Rubin
Florian Lindner writes: > The file is being created but stays empty. If I use a print output in the > while loop it works, so output is catched and the applications stdout in > working. But why the logger proclog catching nothing? I don't see you setting the log level anyplace in that sample, a

Re: tornado.web ioloop add_timeout eats CPU

2012-09-04 Thread Paul Rubin
Laszlo Nagy writes: > but a threaded server cannot handle 100+ simultaneous (long running) > requests, because that would require 100+ threads to be running. On a reasonable server these days, 100 threads seems to be no big deal. I've run several times that many. I think things get ragged at a f

Re: Parsing ISO date/time strings - where did the parser go?

2012-09-06 Thread Paul Rubin
John Nagle writes: > There's an iso8601 module on PyPi, but it's abandoned; it hasn't been > updated since 2007 and has many outstanding issues. Hmm, I have some code that uses ISO date/time strings and just checked to see how I did it, and it looks like it uses iso8601-0.1.4-py2.6.egg . I don't

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Paul Rubin
rusi writes: > On an 8086/8088 a MUL (multiply) instruction was of the order of 100 > clocks ... On most modern processors (after the pentium) the > difference has mostly vanished. I cant find a good data sheet to > quote though See http://www.agner.org/optimize/ : 4. Instruction tables: L

Re: simple client data base

2012-09-08 Thread Paul Rubin
Mark R Rivet writes: >>ones for a few dollars. You're reading about lists, tuples, and >>dictionary data? Great, but other home accounting businesses have >>their client databases automatically synced with their smart-phones >>and their time-charging and their invoicing. > Well I have to say that

Re: Is there a unique method in python to unique a list?

2012-09-09 Thread Paul Rubin
Token Type writes: def average_polysemy(pos): > synset_list = list(wn.all_synsets(pos)) > sense_number = 0 > lemma_list = [] > for synset in synset_list: > lemma_list.extend(synset.lemma_names) > for lemma in list(set(lemma_list)): >

Re: Is there a unique method in python to unique a list?

2012-09-09 Thread Paul Rubin
Paul Rubin writes: > I think you mean (untested): > > synsets = wn.all_synsets(pos) > sense_number = 0 > lemma_set = set() > for synset in synsets: > lemma_set.add(synset.lemma_names) > for lemma in lemma_set: > sense_number

Re: simple client data base

2012-09-09 Thread Paul Rubin
Tim Chase writes: > urge you in a direction less fraught with peril. Rather than starting > by duplicating existing functionality of a complex domain More importantly, as others have mentioned, the main peril comes from having someone else relying on the success of the program. If you want to l

Re: A little morning puzzle

2012-09-19 Thread Paul Rubin
Neal Becker writes: > I have a list of dictionaries. They all have the same keys. I want to find > the > set of keys where all the dictionaries have the same values. Suggestions? Untested, and uses a few more comparisons than necessary: # ds = [dict1, dict2 ... ] d0 = ds[0] ks = set(k for

Re: Exact integer-valued floats

2012-09-21 Thread Paul Rubin
Steven D'Aprano writes: > Have I got this right? Is there a way to work out the gap between one > float and the next? Yes, 53-bit mantissa as people have mentioned. That tells you what ints can be exactly represented. But, arithmetic in some situations can have a 1-ulp error. So I wonder if i

Re: How to limit CPU usage in Python

2012-09-22 Thread Paul Rubin
Rolando Cañer Roblejo writes: > Is it possible for me to put a limit in the amount of processor usage > (% CPU) that my current python script is using? Is there any module > useful for this task? One way is check your cpu usage once in a while, compare with elapsed time, and if your % usage is a

Re: [RELEASED] Python 3.3.0 release candidate 3

2012-09-23 Thread Paul Rubin
Georg Brandl writes: > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier porting between 2.x and 3.x. Major new features and changes > in the 3.3 release series are: [good stuff snipped] This is cool, and Python 3 is finally starting to show some real advantages

Re: For Counter Variable

2012-09-24 Thread Paul Rubin
alex23 writes: > To highlight the vast gulf between what you think you are and what you > actually produce. By now I think we're in the DNFTT zone. -- http://mail.python.org/mailman/listinfo/python-list

Re: Article on the future of Python

2012-09-25 Thread Paul Rubin
Kevin Walzer writes: > language, but it's another thing entirely to call Python the One > Language to Rule Them All. (That's C, because all other languages are > implemented in it. :-) ) I got into a discussion about that in another newsgroup and noticed that C seems to have been a 20th-century l

Re: Article on the future of Python

2012-09-25 Thread Paul Rubin
Chris Angelico writes: > That is true, but the concept is still around - that you can write > your code in some other language and compile to js. http://www.haskell.org/haskellwiki/The_JavaScript_Problem -- http://mail.python.org/mailman/listinfo/python-list

Re: Article on the future of Python

2012-09-26 Thread Paul Rubin
Chris Angelico writes: > When you compare against a wide build, semantics of 3.2 and 3.3 are > identical, and then - and ONLY then - can you sanely compare > performance. And 3.3 stacks up much better. I like to have seen real world benchmarks against a pure UTF-8 implementation. That means O(n)

Re: Article on the future of Python

2012-09-26 Thread Paul Rubin
Chris Angelico writes: > So, I don't actually have any stats for you, because it's really easy > to just not index strings at all. Right, that's why I think the O(n) indexing issue of UTF-8 may be overblown. Haskell 98 was mentioned earlier as a language that did Unicode "correctly", but its str

Re: using "*" to make a list of lists with repeated (and independent) elements

2012-09-26 Thread Paul Rubin
TP writes: > copies a list, he copies in fact the *pointer* to the list > Is it the correct explanation? Yes, that is correct. > In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" > without this behavior? >>> a = [[0]*3 for i in xrange(2)] >>> a[0][0]=2 >>>

Re: creating an artificial "last element" in sort list

2012-09-28 Thread Paul Rubin
dave writes: > What does x need to be to always be last on an ascending sort no > matter what 'a' and 'b' are within reason... Why are you trying to do that? It sounds ugly. Just sort the list with the a's and b's. If you absolutely have to, you could make a class with comparison methods

Re: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212.

2012-09-28 Thread Paul Rubin
iMath writes: > write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. And then you have two problems. -- http://mail.python.org/mailman/listinfo/python-list

Re: Slicing iterables in sub-generators without loosing elements

2012-09-29 Thread Paul Rubin
Thomas Bach writes: result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] > by _only_ _iterating_ over the list (caching all the elements sharing > the same first element doesn't count)? itertools.groupby(data, lambda (x,y) : x) is basically what you want. -- http://mail.python.o

Re: Convert MAC to hex howto

2012-10-07 Thread Paul Rubin
Johannes Graumann writes: > '00:08:9b:ce:f5:d4' > ... > hexcall = "\\x".join(hexcall).decode('string_escape') I think it's best not to mess with stuff like that. Convert to integers then convert back: mac = '00:08:9b:ce:f5:d4' hexcall = ''.join(chr(int(c,16)) for c in mac.split(':'))

Re: Insert item before each element of a list

2012-10-08 Thread Paul Rubin
mooremath...@gmail.com writes: x = [1, 2, 3] .. y > ['insertme', 1, 'insertme', 2, 'insertme', 3] def ix(prefix, x): for a in x: yield prefix yield a y = list(ix('insertme', x)) from itertools import * y = list(chain.from_iterable(izip(repeat('insertme'

Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Paul Rubin
tinn...@isbd.co.uk writes: > I want to fix an error in some code I have installed, however I don't > really want to just bodge it. ... > Now its *probably* something higher up the tree causing the problem > (it's only one particular image in 20 thousand or so that breaks > things) but I really want

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Paul Rubin
Zero Piraeus writes: > 2. Say "screw it" and break the line using a backslash. Often the line will break ok without a backslash, but I don't feel any particular pain in using a backslash in the other cases. I do pretty rigorously try to keep all lines shorter than 72 columns or so, unless there'

Re: Fast forward-backward (write-read)

2012-10-23 Thread Paul Rubin
Virgil Stokes writes: > Finally, to my question --- What is a fast way to write these > variables to an external file and then read them in backwards? Seeking backwards in files works, but the performance hit is significant. There is also a performance hit to scanning pointers backwards in memor

Re: Fast forward-backward (write-read)

2012-10-23 Thread Paul Rubin
Paul Rubin writes: > Seeking backwards in files works, but the performance hit is > significant. There is also a performance hit to scanning pointers > backwards in memory, due to cache misprediction. If it's something > you're just running a few times, seeking backwards t

Re: Fast forward-backward (write-read)

2012-10-23 Thread Paul Rubin
Tim Chase writes: > Again, the conversion to/from decimal hasn't been a great cost in my > experience, as it's overwhelmed by the I/O cost of shoveling the > data to/from disk. I've found that cpu costs both for processing and conversion are significant. Also, using a binary format makes the fil

Re: Fast forward-backward (write-read)

2012-10-23 Thread Paul Rubin
Virgil Stokes writes: > Yes, I do wish to inverse the order, but the "forward in time" file > will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performan

Re: Fast forward-backward (write-read)

2012-10-24 Thread Paul Rubin
Emile van Sebille writes: >> probably somewhere close to 400-500Gb in memory > I went looking for a machine capable of this and got about halfway > there with http://www.tech-news.com/publib/pl2818.html which allows up > to 248Gb memory -- near as I can tell the price for the maxed out > syste

Re: while expression feature proposal

2012-10-24 Thread Paul Rubin
Dan Loewenherz writes: > VAR = EXPR > while VAR: > BLOCK > VAR = EXPR for VAR in iter(lambda: EXPR, None): BLOCK where the termination sentinel might be False or '' or whatever instead of None. Of course if EXPR is a callable, there's no lambda. > while EXPR as VAR: > BLOCK Thi

Re: while expression feature proposal

2012-10-24 Thread Paul Rubin
Cameron Simpson writes: > if re_FUNKYPATTERN.match(test_string) as m: > do stuff with the results of the match, using "m" class memo: def __call__(f, *args, **kw): self.result = f(*args, **kw) m = memo() if result(re_FUNKYPATTERN.match, test_string): do stuff wit

Re: while expression feature proposal

2012-10-24 Thread Paul Rubin
Paul Rubin writes: > class memo: > def __call__(f, *args, **kw): > self.result = f(*args, **kw) obviously add return self.result -- http://mail.python.org/mailman/listinfo/python-list

Re: while expression feature proposal

2012-10-24 Thread Paul Rubin
Ian Kelly writes: > j = int(random() * n) > while j in selected: > j = int(random() * n) from itertools import dropwhile j = dropwhile(lambda j: j in selected, iter(lambda: int(random() * n), object())) .next() kind of ugly, makes me wish for a few more itertoo

Re: while expression feature proposal

2012-10-25 Thread Paul Rubin
Dan Loewenherz writes: > In this case, profile_id is "None" when the loop breaks. It would be > much more straightforward (and more Pythonic, IMO), to write: > > client = StrictRedis() > while client.spop("profile_ids") as profile_id: > print profile_id That is pretty loose, in my

Re: while expression feature proposal

2012-10-26 Thread Paul Rubin
Dan Loewenherz writes: > We also don't special case things like this just because x is an empty > string. If this "while EXPR as VAR" thing were to move forward, we > shouldn't treat the truth testing any differently than how we already > do. IMO we should write our applications with the understan

Re: while expression feature proposal

2012-10-26 Thread Paul Rubin
Steven D'Aprano writes: > There's no need for it *inside* of while expressions. It doesn't add to > the expressiveness of the language, or increase the power of the > language, or help people write correct code. It saves one trivial line of > code in some, but not all, while loops, at the cost

Re: Negative array indicies and slice()

2012-10-28 Thread Paul Rubin
Andrew writes: > So: Why does python choose to convert them to positive indexes, and > have slice operate differently than xrange There was a thread a few years back, I think started by Bryan Olson, that made the case that slice indexing is a Python wart for further reasons than the above, and s

Re: Immutability and Python

2012-10-29 Thread Paul Rubin
andrea crotti writes: > and we want to change its state incrementing the number ... > the immutability purists would instead suggest to do this: > def increment(self): > return NumWrapper(self.number + 1) Immutability purists would say that numbers don't have "state" and if you're tr

Re: Immutability and Python

2012-10-29 Thread Paul Rubin
andrea crotti writes: > Also because how doi I make an immutable object in pure Python? Numbers in Python are already immutable. What you're really looking for is a programming style where you don't bind any variable more than once. This gives rise to a programming style that Python can support

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Paul Rubin
Johannes Bauer writes: > This makes the source files largish however (they're currently split up > in different files). Can I use the nested class advantage and somehow > include the inner class from another file? You could possibly duck-punch class A: import B class A: ... A.B = B.B

Re: Organisation of python classes and their methods

2012-11-02 Thread Paul Rubin
Martin Hewitson writes: > So, is there a way to put these methods in their own files and have > them 'included' in the class somehow? ... Is there an official python > way to do this? I don't like having source files with 100's of lines > of code in, let alone 1000's. That code sounds kind of sme

Re: Organisation of python classes and their methods

2012-11-02 Thread Paul Rubin
Martin Hewitson writes: > Well, here we disagree. Suppose I have a class which encapsulates > time-series data. Below is a list of the absolute minimum methods one > would have to process that data. ... > 'abs' > 'acos' > 'asin' > ... Ok, THERE is your problem. Why do you have separ

Re: Organisation of python classes and their methods

2012-11-02 Thread Paul Rubin
Martin Hewitson writes: >> you want just ONE method, something like "map"... > Well, because one of the features that the framework will have is to > capture history steps (in a tree structure) so that each processing > step the user does is tracked. So while methods such as abs(), cos(), > etc wi

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-09 Thread Paul Rubin
bruceg113...@gmail.com writes: > Is there a simpler way to modify all arguments in a function before > using the arguments? Why do you want to do that? > For example, can the below code, in the modify arguments section be > made into a few statements? Whenever someone uses that many variables on

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-09 Thread Paul Rubin
Chris Angelico writes: > Contrived example: > def send_email(from, to, subj, body, whatever, other, headers, you, like): That should be a dictionary with the header names as indexes. In fact there are already some email handling modules in the stdlib that represent headers that way. -- http://m

Re: Format specification mini-language for list joining

2012-11-10 Thread Paul Rubin
Tobia Conforto writes: > Now, as much as I appreciate the heritage of Lisp, I won't deny than > its format string mini-language is EVIL. ... Still, this is the > grand^n-father of Python's format strings... Without having yet read the rest of your post carefully, I wonder the particular historica

Re: A gnarly little python loop

2012-11-11 Thread Paul Rubin
Cameron Simpson writes: > | I'd prefer the original code ten times over this inaccessible beast. > Me too. Me, I like the itertools version better. There's one chunk of data that goes through a succession of transforms each of which is very straightforward. -- http://mail.python.org/mailman/lis

Re: Paid Python work for 30mins - 1 hour

2012-11-19 Thread Paul Rubin
blockedu...@gmail.com writes: > I have three scripts that I would like written, they are designed to > do the following: > Backup.py – Zip a folder and store it on amazon S3 ... > If you are interested get in touch! You could just type "python s3 upload" into web search and see if you can use the

Re: Paid Python work for 30mins - 1 hour

2012-11-19 Thread Paul Rubin
Mark Adam writes: > You might consider putting your request on elance.com or guru.com > where you can hire programmers for small projects like this. Even though the coding task is very small, I think it's unrealistic to scope it at less than 2-4 hours, given communication overhead etc. It would

Re: logger doesn't roll over

2012-11-21 Thread Paul Rubin
cerr writes: > 2.2MB and should've rolled over after ever 1MB. > LOGFILE, maxBytes=(1048576*10), backupCount=5 1048576*10 is 10MB, not 1MB. -- http://mail.python.org/mailman/listinfo/python-list

Re: Exponential arrival distribution in Python

2012-11-28 Thread Paul Rubin
Ricky writes: > I am doing a project on traffic simulation. I want to introduce > exponential arrival distribution to precede this task. Therefore I > want write a code in python for exponential arrival distribution. I've never heard of an "exponential arrival distribution" and googling fails. D

Re: Secretly passing parameter to function

2012-12-06 Thread Paul Rubin
Olivier Scalbert writes: > # We ask the framework to do some work. > do(step1, param = None) from functools import partial do(partial(step1, param = None)) -- http://mail.python.org/mailman/listinfo/python-list

Re: Secretly passing parameter to function

2012-12-06 Thread Paul Rubin
Paul Rubin writes: > from functools import partial > do(partial(step1, param = None)) Or more directly: do(lambda: step1(param = None)) -- http://mail.python.org/mailman/listinfo/python-list

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-06 Thread Paul Rubin
Nick Mellor writes: > I came across itertools.dropwhile only today, then shortly afterwards > found Raymond Hettinger wondering, in 2007, whether to drop [sic] > dropwhile and takewhile from the itertools module > Almost nobody else of the 18 respondents seemed to be using them. What? I'm am

Re: Delete dict and subdict items of some name

2012-12-17 Thread Paul Rubin
Gnarlodious writes: > Hello. What I want to do is delete every dictionary key/value of the > name 'Favicon' regardless of depth in subdicts, of which there are > many. What is the best way to do it? Untested: def unfav(x): if type(x) != dict: return x return dict((k,unfav(v)) for k,v in x.it

  1   2   3   4   5   6   7   8   9   10   >