Re: pyw program not displaying unicode characters properly

2012-10-14 Thread Ian Kelly
On Sun, Oct 14, 2012 at 1:36 PM, jjmeric wrote: > Is there some sort of defaut font, or is there in Python or Python for > Windows any ini file where the font used can be seen, eventually changed > to a more appropriate one with all the required glyphs (like Lucida Sans > Unicode has). No, this i

Re: trouble with nested closures: one of my variables is missing...

2012-10-14 Thread Ian Kelly
On Sun, Oct 14, 2012 at 3:54 PM, Cameron Simpson wrote: > | You assign to it, but there's no nonlocal declaration, so Python thinks > | it's a local var, hence your error. > > But 'unset_object' is in locals(). Why one and not the other? > Obviously there's something about closures here I'm missi

Re: trouble with nested closures: one of my variables is missing...

2012-10-14 Thread Ian Kelly
On Sun, Oct 14, 2012 at 7:08 PM, Cameron Simpson wrote: > On 14Oct2012 18:32, Ian Kelly wrote: > | 'attr_name' is not in locals because while it's a local variable, it > | has not been assigned to yet. It has no value and an attempt to > | reference it at th

Re: numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread Ian Kelly
On Oct 15, 2012 3:12 PM, "someone" wrote: > How to initialize my array directly using variables ? Why not just use the list-of-lists constructor instead of the string constructor? m = numpy.matrix([[1,2,3],[4,5,6],[7,8,test]]) -- http://mail.python.org/mailman/listinfo/python-list

Re: cx_Oracle clause IN using a variable

2012-10-16 Thread Ian Kelly
On Tue, Oct 16, 2012 at 7:41 AM, Beppe wrote: > Hi all, > I don't know if it is the correct place to set this question, however, The best place to ask questions about cx_Oracle would be the cx-oracle-users mailing list. > what is wrong? > suggestions? With the bind parameter you're only passing

Re: OT Questions

2012-10-16 Thread Ian Kelly
On Tue, Oct 16, 2012 at 9:21 AM, Demian Brecht wrote: > There's a small light somewhere deep down that says maybe this is just > someone quite misdirected. A brief search shows that he has multiple > domains, all with the same type of design. I would be hard pressed to think > that someone would g

Re: Script for finding words of any size that do NOT contain vowels with acute diacritic marks?

2012-10-17 Thread Ian Kelly
On Wed, Oct 17, 2012 at 9:32 AM, wrote: import unicodedata def HasDiacritics(w): > ... w_decomposed = unicodedata.normalize('NFKD', w) > ... return 'no' if len(w) == len(w_decomposed) else 'yes' > ... HasDiacritics('éléphant') > 'yes' HasDiacritics('elephant') > 'no' >

Re: Change computername

2012-10-17 Thread Ian Kelly
On Wed, Oct 17, 2012 at 8:07 AM, Anatoli Hristov wrote: > Hello, > > Can you please help me out how can I change the computername of > windows XP with or without the "WIN32" module ? Untested: from ctypes import * ComputerNamePhysicalDnsHostname = 5 computer_name = u'COMPUTER' success = windl

Re: Script for finding words of any size that do NOT contain vowels with acute diacritic marks?

2012-10-17 Thread Ian Kelly
On Wed, Oct 17, 2012 at 12:17 PM, wrote: > Not at all, I knew this. In this I decided to program like > this. > > Do you get it? Yes/No or True/False It's just bad style, because both 'yes' and 'no' evaluate true. if HasDiacritics('éléphant'): print('Correct!') if HasDiacritics('elephant

Re: Aggressive language on python-list

2012-10-17 Thread Ian Kelly
On Wed, Oct 17, 2012 at 5:17 PM, Steven D'Aprano wrote: > Excuse me, I think that anybody who was offended by it needs to take a > long, hard look at themselves. Would you be offended if Rurpy asked "Are > you diabetic?" If the question were sincere, no. On the other hand, if it were a rhetorica

Re: len() on mutables vs. immutables

2012-10-18 Thread Ian Kelly
On Thu, Oct 18, 2012 at 1:18 PM, Prasad, Ramit wrote: > Why does pointer arithmetic work for dicts? I would think the position > of a value would be based on the hash of the key and thus "random" for > the context of this conversation. It doesn't. len() on CPython dicts is O(1) because the dict

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Ian Kelly
On Thu, Oct 18, 2012 at 10:47 AM, Dave Angel wrote: > I never use the backslash at end-of-line to continue a statement to the > next. Not only is it a readability problem, but if your editor doesn't > have visible spaces, you can accidentally have whitespace after the > backslash, and wonder what

Re: Python does not take up available physical memory

2012-10-19 Thread Ian Kelly
On Fri, Oct 19, 2012 at 11:08 AM, Pradipto Banerjee wrote: > Is there any reason why python can’t read a 1GB file in memory even when a > 2.3 GB physical memory is available? Do I need to make a change in some > setting or preferences? > > > > I am using python(x,y) distribution (python 2.7) and u

RE: Python does not take up available physical memory

2012-10-19 Thread Ian Kelly
On Oct 19, 2012 1:05 PM, "Pradipto Banerjee" < pradipto.baner...@adainvestments.com> wrote: > > I have a 32-bit machine. Can I install a 64-bit build even if my PC is 32-bit? No. Try following up on Emile's suggestion instead. -- http://mail.python.org/mailman/listinfo/python-list

Re: 'generator ignored GeneratorExit''

2012-10-20 Thread Ian Kelly
On Sat, Oct 20, 2012 at 2:03 PM, Charles Hixson wrote: > If I run the following code in the same module, it works correctly, but if I > import it I get the message: > Exception RuntimeError: 'generator ignored GeneratorExit' in object getNxtFile at 0x7f932f884f50> ignored > > def getNxtFile (star

Re: change the first letter into uppercase (ask)

2012-10-20 Thread Ian Kelly
On Sat, Oct 20, 2012 at 5:14 PM, contro opinion wrote: > the pattern `re.compile(".(?#nyh2p){0,1}")` , make me confused, > can you explain how it can match the first letter of every word? It doesn't. >>> pattern = re.compile(".(?#nyh2p){0,1}") >>> pattern.findall("a test of capitalizing") ['a'

Re: change the first letter into uppercase (ask)

2012-10-20 Thread Ian Kelly
On Sat, Oct 20, 2012 at 1:30 PM, Dennis Lee Bieber wrote: >> >>> for match in re.findall(pattern, "a test of capitalizing"): >> ... result = f(result + match) > > result = result + f(match) > > Or closer... Don't both with f and str.capitalize > > result = result + match.

Re: get each pair from a string.

2012-10-21 Thread Ian Kelly
On Sun, Oct 21, 2012 at 12:33 PM, Vincent Davis wrote: > I am looking for a good way to get every pair from a string. For example, > input: > x = 'apple' > output > 'ap' > 'pp' > 'pl' > 'le' > > I am not seeing a obvious way to do this without multiple for loops, but > maybe there is not :-) Use

Re: get each pair from a string.

2012-10-21 Thread Ian Kelly
On Sun, Oct 21, 2012 at 12:58 PM, Vincent Davis wrote: > x = 'apple' > for f in range(len(x)-1): > print(x[f:f+2]) > > @Ian, > Thanks for that I was just looking in to that. I wonder which is faster I > have a large set of strings to process. I'll try so

Re: get each pair from a string.

2012-10-21 Thread Ian Foote
sible approaches, and their upsides and downsides. Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: A desperate lunge for on-topic-ness

2012-10-22 Thread Ian Kelly
On Mon, Oct 22, 2012 at 1:03 AM, Chris Angelico wrote: > Python's system "just works" most of > the time, but can introduce yet another trap for the unsuspecting > newbie who doesn't understand the difference between rebinding and > mutating; I've not looked into multiple levels of closures but I

Re: Python 3.3 can't sort memoryviews as they're unorderable

2012-10-22 Thread Ian Kelly
On Mon, Oct 22, 2012 at 4:58 PM, Mark Lawrence wrote: >> http://docs.python.org/py3k/library/stdtypes.html#typememoryview only >> gives examples of equality comparisons and there was nothing that I >> could see in PEP3118 to explain the rationale behind the lack of other >> comparisons. What have

Re: get each pair from a string.

2012-10-23 Thread Ian Kelly
On Tue, Oct 23, 2012 at 12:47 AM, wrote: > The latest Python version is systematically slower > than the previous ones as soon as one uses non "ascii > strings". No, it isn't. You've previously demonstrated a *microbenchmark* where 3.3 is slower than 3.2. This is a far cry from demonstrating t

Re: A desperate lunge for on-topic-ness

2012-10-23 Thread Ian Kelly
On Mon, Oct 22, 2012 at 7:39 PM, Dennis Lee Bieber wrote: > On Mon, 22 Oct 2012 16:02:34 -0600, Ian Kelly > declaimed the following in gmane.comp.python.general: > >> On my wishlist for Python is a big, fat SyntaxError for any variable >> that could be interpreted as either

Re: Style help for a Smalltalk-hack

2012-10-23 Thread Ian Kelly
On Tue, Oct 23, 2012 at 9:13 AM, Travis Griggs wrote: > > On Oct 22, 2012, at 6:33 PM, MRAB wrote: > >> Another way you could do it is: >> >> while True: >>chunk = byteStream.read(4) >>if not chunk: >>break >>... >> >> And you could fetch multiple signatures in one read: >> >>

Re: regex function driving me nuts

2012-10-23 Thread Ian Kelly
On Tue, Oct 23, 2012 at 1:51 PM, MartinD. wrote: > Hi, > > I'm new to Python. > Does someone has an idea what's wrong. I tried everything. The only regex > that is tested is the last one in a whole list of regex in keywords.txt > Thanks! > Martin How do you know that it's the only one being tes

ANN: Urwid 1.1.0 - Usability and Documentation

2012-10-23 Thread Ian Ward
Announcing Urwid 1.1.0 -- Urwid home page: http://excess.org/urwid/ Manual: http://excess.org/urwid/docs/ Package: http://pypi.python.org/pypi/urwid/1.1.0 About this release: === This is a major feature release for Urwid. The first focus for this rel

Re: A desperate lunge for on-topic-ness

2012-10-23 Thread Ian Kelly
On Tue, Oct 23, 2012 at 4:34 PM, Steven D'Aprano wrote: > On Tue, 23 Oct 2012 10:50:11 -0600, Ian Kelly wrote: > >>> if someone is foolish enough to use the >>> >>> from xyz import * >>> >>> notation... >> >> It's

Re: A lock that prioritizes acquire()s?

2012-10-24 Thread Ian Kelly
you can see that everything went in order. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: A lock that prioritizes acquire()s?

2012-10-24 Thread Ian Kelly
On Wed, Oct 24, 2012 at 2:19 PM, Ian Kelly wrote: > I used a PriorityQueue and Conditions to get rid of the ugly while True loop. Same things, but with Events instead of Conditions. This is just a bit more readable. The PriorityQueue is also probably unnecessary, since it's always

Re: while expression feature proposal

2012-10-24 Thread Ian Kelly
On Wed, Oct 24, 2012 at 2:40 PM, Dan Loewenherz wrote: > So I'm sure a lot of you have run into the following pattern. I use it > all the time and it always has felt a bit awkward due to the duplicate > variable assignment. > > VAR = EXPR > while VAR: > BLOCK > VAR = EXPR The idiomatic wa

Re: while expression feature proposal

2012-10-24 Thread Ian Kelly
On Wed, Oct 24, 2012 at 3:54 PM, Tim Chase wrote: > It may be idiomatic, but that doesn't stop it from being pretty > ugly. I must say I really like the parity of Dan's > > while EXPR as VAR: > BLOCK > > proposal with the "with" statement. It also doesn't fall prey to > the "mistaken-assi

Re: while expression feature proposal

2012-10-24 Thread Ian Kelly
On Wed, Oct 24, 2012 at 5:08 PM, Paul Rubin wrote: > 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 itertools primitives, but I > think it

Re: while expression feature proposal

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel wrote: >> j = next(j for j in iter(partial(randrange, n), None) if j not in >> selected) > > > This generator never ends. If it meets a non-matching value, it just skips > it and goes on. next() only returns one value. After it is returned, the gene

Re: while expression feature proposal

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 3:52 AM, Thomas Rachel wrote: > Am 25.10.2012 06:50 schrieb Terry Reedy: > > >> Keep in mind that any new syntax has to be a substantial improvement in >> some sense or make something new possible. There was no new syntax in >> 3.2 and very little in 3.3. > > > I would cons

Re: while expression feature proposal

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 10:36 AM, Ian Kelly wrote: > On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel > > wrote: >>> j = next(j for j in iter(partial(randrange, n), None) if j not in >>> selected) >> >> >> This generator never ends. If it meets a non-ma

Re: bit count or bit set && Python3

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 11:25 AM, Christian Gollwitzer wrote: > There is a very geeky algorithm with only a few integer operations. > > Checkout > http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64 > > for a C version. Maybe the same thing is equally fast when ported to Python. It

Re: bit count or bit set && Python3

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti wrote: > Yes indeed! Python string operations are fast enough and its > arithmetic slow enough that I no longer assume I can beat a neat > lexicographical solution. Try defeating the following with > arithmetic: > > def is_palindrom(n): >s = str(n)

Re: while expression feature proposal

2012-10-26 Thread Ian Kelly
On Fri, Oct 26, 2012 at 9:29 AM, Dan Loewenherz wrote: > while client.spop("profile_ids") as truthy, profile_id: > if not truthy: > break > > print profile_id > > Here, client.spop returns a tuple, which will always returns true. We then > extract the first element

Re: Recommended way to unpack keyword arguments using **kwargs ?

2012-10-26 Thread Ian Kelly
On Fri, Oct 26, 2012 at 10:58 AM, Jeff Jeffries wrote: > I have been doing the following to keep my class declarations short: > > class MyClass(MyOtherClass): > def __init__(self,*args,**kwargs): > self.MyAttr = kwargs.get('Attribute',None) #To get a default > MyOtherClass.__in

Re: while expression feature proposal

2012-10-26 Thread Ian Kelly
On Fri, Oct 26, 2012 at 4:03 PM, Cameron Simpson wrote: > It will work anywhere an expression is allowed, and superficially > doesn't break stuff that exists if "as" has the lowest precedence. Please, no. There is no need for it outside of while expressions, and anywhere else it's just going to

Re: notmm is dead!

2012-10-28 Thread ian douglas
On 10/05/2012 12:37 PM, Prasad, Ramit wrote: I might be misunderstanding, but I think Etienne wants money in exchange for letting someone else take over. Not to stir up the hornet's nest any more, but it also sounds like now he wants money for people to license things as well: "The license fee

Re: Negative array indicies and slice()

2012-10-28 Thread Ian Kelly
On Sun, Oct 28, 2012 at 9:12 PM, wrote: > The slice operator does not give any way (I can find!) to take slices from > negative to positive indexes, although the range is not empty, nor the > expected indexes out of range that I am supplying. > > Many programs that I write would require introdu

Re: Negative array indicies and slice()

2012-10-28 Thread Ian Kelly
On Sun, Oct 28, 2012 at 10:00 PM, wrote: > Hi Ian, > Well, no it really isn't equivalent. > Consider a programmer who writes: > xrange(-4,3) *wants* [-4,-3,-2,-1,0,1,2] > > That is the "idea" of a range; for what reason would anyone *EVER* want -4 to > +3

Re: OT Questions

2012-10-29 Thread Ian Kelly
On Sun, Oct 28, 2012 at 10:15 AM, Joshua Landau wrote: > I feel necessity to argue against this point. > > It is a common thing to stereotype teens in this way - but, being teen > myself, I feel one should try to avoid it. It's painful to watch every time > someone claims "he can't be a teenager

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Oct 29, 2012 7:10 AM, "Andrew Robinson" wrote: > I will be porting Python 3.xx to a super low power embedded processor > (MSP430), both space and speed are at a premium. > Running Python on top of Java would be a *SERIOUS* mistake. .NET won't even > run on this system. etc. If that's the ca

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 1:54 AM, Andrew wrote: > My intended inferences about the iterator vs. slice question was perhaps not > obvious to you; Notice: an iterator is not *allowed* in __getitem__(). Yes, I misconstrued your question. I thought you wanted to change the behavior of slicing to wra

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 10:58 AM, Johannes Bauer wrote: > Ah, that's nice. I didn't know that nested classes could access their > private members naturally (i.e. without using any magic, just with plain > old attribute access). There is nothing at all special about nested classes that is differen

Re: Immutability and Python

2012-10-29 Thread Ian Kelly
cls, field1, field2, field3=None, field4=42): return super().__new__(cls, field1, field2, field3, field4) def get_sum(self): return self.field1 + self.field2 Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Immutability and Python

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 1:36 PM, Chris Angelico wrote: > Question: Is it clearer to take advantage of the fact that the base > class can be an arbitrary expression? > > class MyImmutableClass(namedtuple('MyImmutableClass', 'field1 field2 > field3 field4')): > > You lose the unnecessary temporary a

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 9:20 AM, Andrew Robinson wrote: > FYI: I was asking for a reason why Python's present implementation is > desirable... > > I wonder, for example: > > Given an arbitrary list: > a=[1,2,3,4,5,6,7,8,9,10,11,12] > > Why would someone *want* to do: > a[-7,10] > Instead of saying

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 9:42 AM, Andrew Robinson wrote: > The list was generated in a single pass by many .append() 's, and then > copied once -- the original was left in place; and then I attempted to slice > it. Note that if the list was generated by .appends, then it was copied more than once.

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 5:24 PM, Roy Smith wrote: > I think you're missing the point of "amortized constant time". Yes, the > first item appended to the list will be copied lg(20,000,000) ~= 25 > times, because the list will be resized that many times(*). But, on > average (I'm not sure if "aver

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 5:43 PM, Ian Kelly wrote: > The growth factor is approximately 1.125. "Approximately" because > there is also a small constant term. The average number of copies per > item converges on 8. Of course, that is the *maximum* number of copies. The act

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 12:00 PM, Andrew Robinson wrote: > I downloaded the source code for python 3.3.0, as the tbz; > In the directory "Python-3.3.0/Python", look at Python-ast.c, line 2089 & > ff. Python-ast.c is part of the compiler code. That's not the struct used to represent the object at

Re: Negative array indicies and slice()

2012-10-29 Thread Ian Kelly
On Mon, Oct 29, 2012 at 4:39 PM, Andrew Robinson wrote: > In addition to those items you mention, of which the reference count is not > even *inside* the struct -- there is additional debugging information not > mentioned. Built in objects contain a "line number", a "column number", and > a "cont

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Mon, Oct 29, 2012 at 7:49 PM, Chris Kaynor wrote: > NOTE: The above is taken from reading the source code for Python 2.6. > For some odd reason, I am getting that an empty tuple consists of 6 > pointer-sized objects (48 bytes on x64), rather than the expected 3 > pointer-sized (24 bytes on x64)

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Mon, Oct 29, 2012 at 6:17 PM, Andrew Robinson wrote: > If you re-check my post to chris, I listed the struct you mention. > The C code is what is actually run (by GDB breakpoint test) when a tuple is > instantiated. When you were running GDB, were you debugging the interactive interpreter or a

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Mon, Oct 29, 2012 at 5:54 PM, Andrew Robinson wrote: >> I don't know of a reason why one might need to use a negative start >> with a positive stop, though. > > I've already given several examples; and another poster did too I meant that I don't know of a reason to do that given the existing s

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Tue, Oct 30, 2012 at 1:21 AM, Ian Kelly wrote: > I'm not entirely certain why collection objects get this special > treatment, but there you have it. Thinking about it some more, this makes sense. The GC header is there to support garbage collection for the object. Atomic types l

Re: calling one staticmethod from another

2012-10-30 Thread Ian Kelly
On Tue, Oct 30, 2012 at 7:41 AM, Ethan Furman wrote: > class Spam(): > @staticmethod > def green(): > print('on a train!') > @staticmethod > def question(): > print('would you, could you', end='') > Spam.green() > > It can be a pain if you change the class n

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Tue, Oct 30, 2012 at 10:14 AM, Ethan Furman wrote: > File a bug report? Looks like it's already been wontfixed back in 2006: http://bugs.python.org/issue1501180 -- http://mail.python.org/mailman/listinfo/python-list

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Tue, Oct 30, 2012 at 3:33 PM, Mark Lawrence wrote: > On 30/10/2012 18:02, Ian Kelly wrote: >> >> On Tue, Oct 30, 2012 at 10:14 AM, Ethan Furman wrote: >>> >>> File a bug report? >> >> >> Looks like it's already been wontfixed

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Tue, Oct 30, 2012 at 8:21 AM, Andrew Robinson wrote: > D'Apriano mentioned the named values, start, stop, step in a slice() which > are an API and legacy issue; These three names must also be stored in the > interpreter someplace. Since slice is defined at the "C" level as a struct, > have yo

Re: Negative array indicies and slice()

2012-10-30 Thread Ian Kelly
On Tue, Oct 30, 2012 at 3:55 PM, Ian Kelly wrote: > On Tue, Oct 30, 2012 at 8:21 AM, Andrew Robinson > wrote: >> D'Apriano mentioned the named values, start, stop, step in a slice() which >> are an API and legacy issue; These three names must also be stored in the &

Re: Negative array indicies and slice()

2012-10-31 Thread Ian Kelly
On Tue, Oct 30, 2012 at 4:25 PM, Andrew Robinson wrote: > Ian, > >> Looks like it's already been wontfixed back in 2006: > >> http://bugs.python.org/issue1501180 > > Absolutely bloody typical, turned down because of an idiot. Who the hell is > Tim Peters anyway

Re: sort order for strings of digits

2012-10-31 Thread Ian Kelly
On Wed, Oct 31, 2012 at 9:17 AM, djc wrote: > The best I can think of is to split the input sequence into two lists, sort > each and then join them. In the example you have given they already seem to be split, so you could just do: sorted(n, key=int) + sorted(s) If that's not really the case, t

Re: Negative array indicies and slice()

2012-10-31 Thread Ian Kelly
On Wed, Oct 31, 2012 at 7:42 AM, Andrew Robinson wrote: > Then; I'd note: The non-goofy purpose of slice is to hold three data > values; They are either numbers or None. These *normally* encountered > values can't create a memory loop. > So, FOR AS LONG, as the object representing slice does no

Re: sort order for strings of digits

2012-10-31 Thread Ian Kelly
y=cmp_to_key(my_cmp))" The cmp builtin is also gone. If you need it, the suggested replacement for "cmp(a, b)" is "(b < a) - (a < b)". Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: pythonic way

2012-11-01 Thread Ian Kelly
On Thu, Nov 1, 2012 at 9:32 AM, inshu chauhan wrote: > what is the most pythonic way to do this : > >if 0 < ix < 10 and 0 < iy < 10 ??? > I suppose you could do if all(0 < i < 10 for i in (ix, iy)): but I think that the original is more readable unless you have several

Re: Negative array indicies and slice()

2012-11-01 Thread Ian Kelly
On Thu, Nov 1, 2012 at 5:32 AM, Andrew Robinson wrote: > H was that PEP the active state of Python, when Tim rejected the bug > report? Yes. The PEP was accepted and committed in March 2006 for release in Python 2.5. The bug report is from June 2006 has a version classification of Pytho

Re: lazy properties?

2012-11-01 Thread Ian Kelly
On Thu, Nov 1, 2012 at 3:38 PM, Andrea Crotti wrote: > What I would like to write is > @lazy_property > def var_lazy(self): > return long_computation() > > and this should imply that the long_computation is called only once.. If you're using Python 3.2+, then functools.lru_cache p

Re: Private methods

2012-11-01 Thread Ian Kelly
On Tue, Oct 9, 2012 at 5:51 PM, Steven D'Aprano wrote: > On Tue, 09 Oct 2012 11:08:13 -0600, Ian Kelly wrote: > >> I tend to view name mangling as being more for avoiding internal >> attribute collisions in complex inheritance structures than for >> designating na

Re: Negative array indicies and slice()

2012-11-01 Thread Ian Kelly
On Thu, Nov 1, 2012 at 4:25 PM, Andrew Robinson wrote: > The bottom line is: __getitem__ must always *PASS* len( seq ) to slice() > each *time* the slice() object is-used. Since this is the case, it would > have been better to have list, itself, have a default member which takes the > raw slice

Re: Obnoxious postings from Google Groups

2012-11-02 Thread Ian Kelly
east I require it for testing and debugging. I could use virtualization to run Unix as well, and I have known some who do, but my philosophy is: why waste time dealing with two distinct environments where only one is required? Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Haskell -> Python

2012-11-02 Thread Ian Kelly
:] yield from (head + [x] + tail for x in range(heap)) "yield from" is Python 3.3 syntax. If you're not using Python 3.3, then that line could be replaced by: for x in range(heap): yield head + [x] + tail Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Haskell -> Python

2012-11-02 Thread Ian Kelly
On Fri, Nov 2, 2012 at 3:40 PM, Ian Kelly wrote: > On Fri, Nov 2, 2012 at 1:19 PM, wrote: >> Is there anything anyone could recommend to make it more "Pythonic" or more >> functional. It looks clumsy next to the Haskell. > > def options(heaps): >

Re: Haskell -> Python

2012-11-02 Thread Ian Kelly
On Fri, Nov 2, 2012 at 4:24 PM, Dave Angel wrote: > Perhaps range(heap) should be replaced by range(len(heap)) "heaps" is a list of ints per the OP, so "heap" is an int. -- http://mail.python.org/mailman/listinfo/python-list

Re: Obnoxious postings from Google Groups

2012-11-04 Thread Ian Kelly
On Sun, Nov 4, 2012 at 11:39 AM, Mark Lawrence wrote: > Anybody serious about programming should know that an OS is a combination > of the hardware and software. Can the *Nix variants now do proper > clustering or are they still decades behind VMS? Never used the other > main/mini frame systems

Re: Multi-dimensional list initialization

2012-11-06 Thread Ian Kelly
On Tue, Nov 6, 2012 at 1:21 AM, Andrew Robinson wrote: > If you nest it another time; > [[[None]]]*4, the same would happen; all lists would be independent -- but > the objects which aren't lists would be refrenced-- not copied. > > a=[[["alpha","beta"]]]*4 would yield: > a=[[['alpha', 'beta']], [

Re: Base class and Derived class question

2012-11-06 Thread Ian Kelly
On Tue, Nov 6, 2012 at 8:03 AM, wrote: > I've used angle brackets just for posting here,becauze this forum doesn't > support [code][/code] This is a Usenet group, not a web forum. > Just got answer, I didn't call a class it's self. Correct code is: > class derivedClass(baseClassMod.baseClass)

Re: Multi-dimensional list initialization

2012-11-06 Thread Ian Kelly
On Tue, Nov 6, 2012 at 2:36 PM, Andrew Robinson wrote: > I meant all lists are shallow copied from the innermost level out. > Equivalently, it's a deep copy of list objects -- but a shallow copy of any > list contents except other lists. Why only list objects, though? When a user writes [[]] *

Re: Multi-dimensional list initialization

2012-11-06 Thread Ian Kelly
On Tue, Nov 6, 2012 at 3:41 PM, Andrew Robinson wrote: >> Q: What about other mutable objects like sets or dicts? >> A: No, the elements are never copied. > > They aren't list multiplication compatible in any event! It's a total > nonsense objection. > > If these are inconsistent in my i

Re: Pickling a dictionary

2012-11-07 Thread Ian Kelly
On Wed, Nov 7, 2012 at 9:07 AM, Devashish Tyagi wrote: > So I want to store the current state of a InteractiveInterpreter Object in > database. In order to achieve this I tried this > > obj = InteractiveInterpreter() > local = obj.locals() > pickle.dump(local, open('obj.dump','rw')) > > But I rec

Re: Pickling a dictionary

2012-11-07 Thread Ian Kelly
On Wed, Nov 7, 2012 at 9:16 AM, Ian Kelly wrote: > On Wed, Nov 7, 2012 at 9:07 AM, Devashish Tyagi > wrote: >> So I want to store the current state of a InteractiveInterpreter Object in >> database. In order to achieve this I tried this >> >> obj = InteractiveInter

Re: Pickling a dictionary

2012-11-07 Thread Ian Kelly
On Wed, Nov 7, 2012 at 10:40 AM, Devashish Tyagi wrote: > Here is the code > > from code import InteractiveInterpreter > import StringIO > import pickle > > src = StringIO.StringIO() > inter = InteractiveInterpreter() > inter.runcode('a = 5') > local = inter.locals > > pickle.dump(local,open('obj.

Re: Multi-dimensional list initialization

2012-11-07 Thread Ian Kelly
On Wed, Nov 7, 2012 at 12:51 PM, Andrew Robinson wrote: > Interesting, you avoided the main point "lists are copied with list > multiplication". It seems that each post is longer than the last. If we each responded to every point made, this thread would fill a book. Anyway, your point was to su

Re: Multi-dimensional list initialization

2012-11-07 Thread Ian Kelly
On Wed, Nov 7, 2012 at 3:02 PM, Andrew Robinson wrote: > Draw up some use cases for the multiplication operator (I'm calling on your > experience, let's not trust mine, right?); What are all the Typical ways > people *Do* to use it now? > > If those use cases do not *primarily* center around *wan

Re: Multi-dimensional list initialization

2012-11-07 Thread Ian Kelly
On Wed, Nov 7, 2012 at 8:13 PM, Andrew Robinson wrote: > OK, and is this a main use case? (I'm not saying it isn't I'm asking.) I have no idea what is a "main" use case. > There is a special keyword which signals the new type of comprehension; A > normal comprehension would say eg: '[ foo for

Re: get weekday as week number in a month

2012-11-07 Thread Ian Kelly
On Thu, Nov 8, 2012 at 12:09 AM, Nikhil Verma wrote: > What i want to know is if i convert it to > > date_object = datetime.strptime(' Friday November 9 2012 11:30PM', '%u %B %d > %Y %I:%M%p' ) > > It is giving me ValueError saying u is unsupported directive ! Use '%A' to match 'Friday', not '%u'

Re: Multi-dimensional list initialization

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 1:26 AM, Andrew Robinson wrote: > OK: Then copy by reference using map: > > values = zip( map( lambda:times, xrange(num_groups) ) ) > if len(values) < len(times) * num_groups ... > > Done. It's clearer than a list comprehension and you still really don't > need a li

Re: int.__init__ incompatible in Python 3.3

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 8:55 AM, Ulrich Eckhardt wrote: > Hi! > > Preparing for an upgrade from 2.7 to 3, I stumbled across an incompatibility > between 2.7 and 3.2 on one hand and 3.3 on the other: > > class X(int): > def __init__(self, value): > super(X, self).__init__(value) > X(42)

Re: duck typing assert

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 10:30 AM, Andriy Kornatskyy wrote: > > People who come from strongly typed languages that offer interfaces often are > confused by lack of one in Python. Python, being dynamic typing programming > language, follows duck typing principal. It can as simple as this: > > asser

Re: Right solution to unicode error?

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 11:32 AM, Oscar Benjamin wrote: > If I want the other characters to work I need to change the code page: > > O:\>chcp 65001 > Active code page: 65001 > > O:\>Q:\tools\Python33\python -c "import sys; > sys.stdout.buffer.write('\u03b1\n'.encode('utf-8'))" > α > > O:\>Q:\tools\

Re: Right solution to unicode error?

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 12:54 PM, wrote: > Font has nothing to do here. > You are "simply" wrongly encoding your "unicode". > '\u2013' > '–' '\u2013'.encode('utf-8') > b'\xe2\x80\x93' '\u2013'.encode('utf-8').decode('cp1252') > '–' No, it seriously is the font. This is what I ge

Re: Right solution to unicode error?

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 1:54 PM, Prasad, Ramit wrote: > Why would font not matter? Unicode is the abstract definition > of all characters right? From that we map the abstract > character to a code page/set, which gives real values for an > abstract character. From that code page we then visually di

Re: duck typing assert

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 4:33 PM, Steven D'Aprano wrote: > On Thu, 08 Nov 2012 20:34:58 +0300, Andriy Kornatskyy wrote: > >> People who come from strongly typed languages that offer interfaces >> often are confused by lack of one in Python. Python, being dynamic >> typing programming language, follo

Re: Writing game-state data...

2012-11-09 Thread Ian Kelly
On Fri, Nov 9, 2012 at 12:20 AM, Graham Fielding wrote: > file_object = open('savegame.sav', 'wb') Here you open a file and assign it to "file_object". > file['map'] = map Here you attempt to write to "file" instead of "file_object". "file" is the name of a built-in type, hence your e

Re: int.__init__ incompatible in Python 3.3

2012-11-09 Thread Ian Kelly
On Fri, Nov 9, 2012 at 4:37 AM, Steven D'Aprano wrote: > In Python 3.3: > > py> class X(int): > ... def __init__(self, *args): > ... super().__init__(*args) # does nothing, call it anyway > ... > py> x = X(22) > Traceback (most recent call last): > File "", line 1, in > File "",

Re: Python3.3 str() bug?

2012-11-09 Thread Ian Kelly
On Fri, Nov 9, 2012 at 2:18 AM, Helmut Jarausch wrote: > Hi, > > probably I'm missing something. > > Using str(Arg) works just fine if Arg is a list. > But > str([],encoding='latin-1') > > gives the error > TypeError: coercing to str: need bytes, bytearray or buffer-like object, >

<    1   2   3   4   5   6   7   8   9   10   >