Re: Print Function

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 2:28 PM, Rodrick Brown wrote: > Go away troll! Troll? It looked like a sincere question to me. -- http://mail.python.org/mailman/listinfo/python-list

Re: Print Function

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 3:11 PM, Alister wrote: > On Fri, 21 Sep 2012 14:54:14 -0600, Ian Kelly wrote: > >> On Fri, Sep 21, 2012 at 2:28 PM, Rodrick Brown >> wrote: >>> Go away troll! >> >> Troll? It looked like a sincere question to me. > > but one

Re: Functional way to compare things inside a list

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 7:25 PM, Steven D'Aprano wrote: > On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote: > >> On Fri, Sep 21, 2012 at 1:54 PM, 8 Dihedral >> wrote: >>> I don't think functional aspects are only marked as lazy programming. >&g

Re: 'str' object does not support item assignment

2012-09-23 Thread Ian Kelly
On Sun, Sep 23, 2012 at 12:31 PM, jimbo1qaz wrote: > spots[y][x]=mark fails with a "'str' object does not support item assignment" > error,even though: a=[["a"]] a[0][0]="b" > and: a=[["a"]] a[0][0]=100 > both work. > Spots is a nested list created as a copy of another lis

Re: Invalid identifier claimed to be valid by docs (methinks)

2012-09-23 Thread Ian Kelly
On Sun, Sep 23, 2012 at 4:24 PM, Joshua Landau wrote: > The docs describe identifiers to have this grammar: > > identifier ::= xid_start xid_continue* > id_start ::= Nl, the underscore, and characters with the Other_ID_Start property> > id_continue ::= categories Mn, Mc, Nd, Pc and oth

Re: A little morning puzzle

2012-09-23 Thread Ian Kelly
On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto wrote: > Why don't you all look at the code(python and C), and tell me how much > code it took to write the functions the other's examples made use of > to complete the task. > > Just because you can use a function, and make it look easier, doesn't > m

Re: metaclass question

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 11:43 AM, Chris Withers wrote: > Hi All, > > Is there a metaclass-y way I could cause the following: > > class TheParser(Parser): > def handle_ARecord(self): > pass > def handle_ARecord(self): > pass > > ...to raise an exception as a result of the 'h

Re: python file API

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico wrote: > file.pos = 42 # Okay, you're at position 42 > file.pos -= 10 # That should put you at position 32 > foo = file.pos # Presumably foo is the integer 32 > file.pos -= 100 # What should this do? Since ints are immutable, the language specifies

Re: A little morning puzzle

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 4:07 PM, Dwight Hutto wrote: > They stated: > > 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? > > No, to me it meant to find similar values in several dicts wi

Re: python file API

2012-09-25 Thread Ian Kelly
On Mon, Sep 24, 2012 at 11:32 PM, Thomas Rachel wrote: > Am 25.09.2012 00:37 schrieb Ian Kelly: >> Since ints are immutable, the language specifies that it should be the >> equivalent of "file.pos = file.pos - 100", so it should set the file >> pointer to 68 byte

Re: data attributes override method attributes?

2012-09-25 Thread Ian Kelly
On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy wrote: > On 9/25/2012 11:03 AM, Chris Angelico wrote: >> Instance attributes override (shadow) class attributes. > > > except for (some? all?) special methods Those names are shadowed too. If you call foo.__len__() and the name is bound on the instanc

Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Ian Kelly
On Tue, Sep 25, 2012 at 12:17 PM, Oscar Benjamin wrote: > Also I think lambda functions might be able to keep the frame alive. Are > they by any chance being created in a function that is called in a loop? I'm pretty sure they don't. Closures don't keep a reference to the calling frame, only to

Re: Article on the future of Python

2012-09-26 Thread Ian Kelly
On Wed, Sep 26, 2012 at 1:23 AM, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > >> Py 3.3 succeeded to somehow kill unicode and it has been transformed >> into an "American" product for "American" users. > > For the first time in Python's history, Python on 32-bit

Fwd: Re: Article on the future of Python

2012-09-26 Thread Ian Kelly
Resending to the list. -- Forwarded message -- From: "Ian Kelly" Date: Sep 26, 2012 12:57 PM Subject: Re: Article on the future of Python To: On Sep 26, 2012 12:42 AM, wrote: > Py 3.3 succeeded to somehow kill unicode and it has > been transformed into an "

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

2012-09-26 Thread Ian Kelly
On Wed, Sep 26, 2012 at 3:20 PM, TP wrote: > Hi everybody, > > I have tried, naively, to do the following, so as to make lists quickly: > a=[0]*2 a > [0, 0] a[0]=3 a > [3, 0] > > All is working fine, so I extended the technique to do: > a=[[0]*3]*2 a > [[0, 0, 0], [0,

Re: Article on the future of Python

2012-09-27 Thread Ian Kelly
On Thu, Sep 27, 2012 at 4:43 AM, Alex Strickland wrote: > I thought that jmf's concerns were solely concerned with the selection of > latin1 as the 1 byte set. My impression was that if some set of characters > was chosen that included all characters commonly used in French then all > would be wel

Re: Article on the future of Python

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 8:58 AM, Chris Angelico wrote: > Yes, MySQL has definitely improved. There was a time when its > unreliability applied to all your data too, but now you can just click > in InnoDB and have mostly-real transaction support etc. But there's > still a lot of work that by requir

Re: howto handle nested for

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 8:39 AM, Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in

Re: howto handle nested for

2012-09-28 Thread Ian Kelly
On Sep 28, 2012 9:49 AM, "Ian Kelly" wrote: > levels = 6 > for combination in itertools.product(xrange(n_syms), levels): > # do stuff Sorry, that should have read "product(xrange(n_syms), repeat=levels)". The repeat argument is keyword-only. -- http://mail.pytho

Re: data attributes override method attributes?

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 12:02 PM, Prasad, Ramit wrote: > Just to make sure I am following, if you call > foo.__len__() it goes to the instance code while > if you do len(foo) it will go to class.__len__()? Yes: >>> class Foo(object): ... def __len__(self): ... return 42 ... >>> foo =

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 12:07 PM, Prasad, Ramit wrote: > I guess you can consider re.match's pattern to be > prefixed with '^'. You can in this case, but they're not equivalent in multi-line mode: >>> re.match('^two', 'one\ntwo', re.M) >>> re.search('^two', 'one\ntwo', re.M) <_sre.SRE_Match obje

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

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 5:39 PM, dave wrote: > a = ['a', 'b', x] > > b = sorted(a) > > What does x need to be to always be last on an ascending sort no matter what > 'a' and 'b' are within reason... I am expecting 'a' and 'b' will be not > longer than 10 char's long I tried making x = 'z

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

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 8:17 PM, Tim Chase wrote: > On 09/28/12 20:58, Mark Lawrence wrote: >> On 29/09/2012 02:35, Tim Chase wrote: >>> On 09/28/12 19:31, iMath wrote: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212. >>> >>> Okay, that was pretty easy. Thanks for the c

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

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 6:59 PM, Demian Brecht wrote: >> f = filter(lambda s: s == a[-1], a) > > That line's assuming that the last element may also be found in arbitrary > locations in the list. If it's guaranteed that they're all contiguous at the > upper bounds, I'd just walk the list backwar

Re: Slicing iterables in sub-generators without loosing elements

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 10:14 AM, Thomas Bach wrote: > Hi, > > say we have the following: > data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] > > is there a way to code a function iter_in_blocks such that > result = [ list(block) for block in iter_in_blocks(data) ] > > evaluates to

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 7:27 AM, Ramchandra Apte wrote: > Should one always add super().__init__() to the __init__? The reason for this > is the possibility of changing base classes (and forgetting to update the > __init__). As long as the class and its subclasses only use single inheritance, i

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

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 3:38 AM, Mark Lawrence wrote: > My understanding is that Python 3.3 has regressed the performance of ''. > Surely the Python devs can speed the performance back up and, just for us, > use less memory at the same time? At least it will be stored as a Latin-1 '' for efficien

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

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 11:01 AM, 8 Dihedral wrote: > > Don't you get it why I avoided the lambda one liner as a functon. > > I prefer the def way with a name chosen. Certainly, but the Bresenham line algorithm is O(n), which is why it is so superior to quicksort that is O(n log n). Of cours

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano wrote: > On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: > >> It is not necesarily calling the parent class. It calls the initializer >> of the next class in the MRO order and what class that is depends on the >> actual multiple inherit

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 10:55 PM, Ramchandra Apte wrote: > When I said "super().__init__()" it could have been > "super().__init__(size+67)" or whatever arguments are needed for __init__ But if you change the base class, couldn't those arguments change? Then you would have to change the call whe

Re: where to view range([start], stop[, step])'s C implementation source code ?

2012-10-01 Thread Ian Kelly
On Mon, Oct 1, 2012 at 9:28 AM, iMath wrote: > where to view range([start], stop[, step])'s C implementation source code ? http://hg.python.org/cpython/file/3f739f42be51/Objects/rangeobject.c -- http://mail.python.org/mailman/listinfo/python-list

Re: design question:game skill system

2012-10-02 Thread Ian Kelly
On Tue, Oct 2, 2012 at 2:00 PM, Littlefield, Tyler wrote: > Hello all: > I'm looking at a skill/perk system, where the player builds up his char by > using perk points to add abilities. > Each perk is under a category, and generally costs go up as you increase the > perk. > So I'm trying to figure

Re: + in regular expression

2012-10-03 Thread Ian Kelly
On Wed, Oct 3, 2012 at 9:01 PM, contro opinion wrote: > why the "\s{6}+" is not a regular pattern? Use a group: "(?:\s{6})+" -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is pylaucher in Python 3.3 being installed in Windows folder?

2012-10-03 Thread Ian Kelly
On Wed, Oct 3, 2012 at 8:04 PM, Steven D'Aprano wrote: > On Wed, 03 Oct 2012 14:13:10 -0700, Piotr Dobrogost wrote: > >> Why is pylauncher in Python 3.3 being installed in Windows folder and >> not in Program Files folder? Installing into Windows folder was maybe >> acceptable 10 years ago but not

Re: Why is pylaucher in Python 3.3 being installed in Windows folder?

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 8:41 AM, Piotr Dobrogost wrote: > Now, the question is why not put pylauncher together with python.exe > now, when 3.3 has an option to add Python's folder to the PATH? In > case there are more than one Python installed this would mean changing > pylauncher when changing act

Re: sum function

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 2:52 PM, wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > total = 0.0 > r = client.scannerGet(scanner) > while r: > for k in (r[0].columns): > total += float(r[0].columns[k].value) > r = client.scannerGet(scanner) > > print total > >

Re: sum function

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 3:04 PM, Ian Kelly wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > next_r = itertools.partial(client.scannerGet, scanner) > total = sum(float(col.value) for r in iter(next_r, None) for co

Re: notmm is dead!

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 6:22 PM, Steven D'Aprano wrote: > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. It's an ISC license. The notmm-0.4.4/LICENSE file is a link to th

Re: sum function

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 6:40 PM, Mike wrote: > Traceback (most recent call last): > File "test.py", line 16, in > total = sum(float(col.value) for r in iter(next_r, None) for col in > r.itervalues()) > File "test.py", line 16, in > total = sum(float(col.value) for r in iter(next_r, N

Re: + in regular expression

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 9:44 PM, Saroo Jain wrote: > x3=re.match("\s{6}+",str) > > instead use > x3=re.match("\s{6,}",str) > > This serves the purpose. And also give some food for thought for why the > first one throws an error. That matches six or more spaces, not multiples of six spaces. -- ht

Re: notmm is dead!

2012-10-05 Thread Ian Kelly
On Oct 4, 2012 6:56 PM, "Etienne Robillard" wrote: > > You probably have a old tarball or something... Not unless you've replaced it since I made my post, as I had just downloaded it to check the license. -- http://mail.python.org/mailman/listinfo/python-list

Re: sum function

2012-10-05 Thread Ian Kelly
On Fri, Oct 5, 2012 at 7:39 AM, Mike wrote: > Sorry about that. Here you go > > Traceback (most recent call last): > File "test.py", line 17, in > total = sum(float(col.value) for r in iter(next_r, None) for col in > r[0].columns.itervalues()) > File "test.py", line 17, in > total =

Re: sum function

2012-10-05 Thread Ian Kelly
On Fri, Oct 5, 2012 at 2:03 PM, Mike wrote: > I added the print command. > > It prints [] when there is no data. Change "iter(next_r, None)" to "iter(next_r, [])" -- http://mail.python.org/mailman/listinfo/python-list

Re: fmap(), "inverse" of Python map() function

2012-10-05 Thread Ian Kelly
On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: > > http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html Your fmap is a special case of reduce. def fmap(functions, argument): return reduce(lambda result, func: func(result), functions, argument) -- http://mail.python.

Re: fmap(), "inverse" of Python map() function

2012-10-05 Thread Ian Kelly
On Fri, Oct 5, 2012 at 3:31 PM, Ian Kelly wrote: > On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: >> >> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html > > Your fmap is a special case of reduce. > > def fmap(functions, argument): >

Re: fmap(), "inverse" of Python map() function

2012-10-05 Thread Ian Kelly
On Fri, Oct 5, 2012 at 4:52 PM, Devin Jeanpierre wrote: > On Fri, Oct 5, 2012 at 5:31 PM, Ian Kelly wrote: >> On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: >>> >>> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html >> >> Your f

Re: instance.attribute lookup

2012-10-05 Thread Ian Kelly
On Fri, Oct 5, 2012 at 11:39 AM, Ethan Furman wrote: > There is a StackOverflow question [1] that points to this on-line book [2] > which has a five-step sequence for looking up attributes: > >> When retrieving an attribute from an object (print >> objectname.attrname) Python follows these steps:

Re: Coexistence of Python 2.x and 3.x on same OS

2012-10-06 Thread Ian Kelly
On Sat, Oct 6, 2012 at 1:27 AM, wrote: > Using Python on Windows is a dream. > > Python uses and needs the system, but the system does > not use Python. > > Every Python version is installed in its own isolated > space, site-packages included and without any defined > environment variable. Every

Re: Insert item before each element of a list

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 1:28 PM, wrote: > What's the best way to accomplish this? Am I over-complicating it? My gut > feeling is there is a better way than the following: > import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in ran

Re: Insert item before each element of a list

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 1:52 PM, Joshua Landau wrote: > But it's not far. I wouldn't use Ian Kelly's method (no offence), because of > len(x): it's less compatible with iterables. Others have ninja'd me with > good comments, too. That's fair, I probably wouldn't use it either. It points to a poss

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 9:13 PM, Token Type wrote: > yes, thanks all your tips. I did try sorted with itemgetter. However, the > sorted results are same as follows whether I set reverse=True or reverse= > False. Isn't it strange? Thanks. First of all, "sorted" does not sort the list in place as

Re: FW: question Python custome events

2012-10-09 Thread Ian Kelly
On Tue, Oct 9, 2012 at 2:35 AM, Hussain, Mushabbar wrote: > > > Hi, > > Is it possible to define an Event which should fire when a value of a > variable changes? Something like below > > > > self.Bind(wx.EVT_ON_VAL_CHANGE, variable_to_watch, self.Callback) > > > > I need a Text ctrl UI which conti

Re: an error in python lib?

2012-10-10 Thread Ian Kelly
On Wed, Oct 10, 2012 at 6:18 AM, Ulrich Eckhardt wrote: >> The .acquire method will return True if the attempt to acquire has been >> successful. This can occur only if it is not currently owned. > > > The comment clearly states "owned by current thread", not "owned by any > thread". The latter wo

Re: __setitem__ without position

2012-10-11 Thread Ian Kelly
On Thu, Oct 11, 2012 at 4:13 PM, Kevin Anthony wrote: > I'm not supprised... and understand why it's happening. I'm asking how to > get around it. > > Basically i'm asking how to override, if i can, the `=` You cannot override assignment of local variables. To get around it, use slicing as Dave

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 some timings if I get a > chance later tod

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

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
On Wed, Oct 24, 2012 at 12:54 PM, David M Chess wrote: > Seeking any thoughts on other/better ways to do this, or whether the > inefficiency will be too eyerolling if we get say one request per second > with an average service time a bit under a second but maximum service time > well over a second

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: 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 to be 6:3??? That is what ranges do, bu

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
On Mon, Oct 29, 2012 at 10:12 AM, andrea crotti wrote: > Also because how doi I make an immutable object in pure Python? I sometimes use namedtuples for this. from collections import namedtuple MyImmutableClass = namedtuple('MyImmutableClass', 'field1 field2 field3 field4') If you want default

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