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

2012-08-26 Thread Ian Kelly
On Sun, Aug 26, 2012 at 2:13 PM, Steven D'Aprano wrote: > On Sun, 26 Aug 2012 09:40:13 -0600, Ian Kelly wrote: > >> I think the documentation for those functions is simply badly worded. >> The "width in bytes" it returns is not the width of the rune (which as &g

Re: set and dict iteration

2012-08-27 Thread Ian Kelly
to occur? Bearing in mind that this error is meant for debugging and not production error handling, you could even make the version a single byte and I'd still be fine with that. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

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

2012-08-27 Thread Ian Kelly
On Mon, Aug 27, 2012 at 1:16 PM, wrote: > - Why int32 and not uint32? No idea, I tried to find an > answer without asking. UCS-4 is technically only a 31-bit encoding. The sign bit is not used, so the choice of int32 vs. uint32 is inconsequential. (In fact, since they made the decision to limit

Re: Python 2.6 and Sqlite3 - Slow

2012-08-27 Thread ian douglas
>From the sqlite documentation he quoted, it appears that ANY network filesystem, local or otherwise, should be avoided. On Aug 27, 2012 8:13 PM, wrote: > On Monday, August 27, 2012 10:32:47 PM UTC-4, Bryan wrote: > > bruceg113 wrote: > > > > > I selected sqlite for the following reasons: > > > >

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

2012-08-28 Thread Ian Kelly
d benchmarks that I've seen, 3.3 is as fast as or faster than 3.2. Here's a much more realistic benchmark that nonetheless still focuses on strings: word counting. Source: http://pastebin.com/RDeDsgPd C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc" "

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

2012-08-30 Thread Ian Kelly
On Thu, Aug 30, 2012 at 2:51 AM, wrote: > But as soon as you introduce artificially a "latin-1" > bottleneck, all this machinery just become useless. How is this a bottleneck? If you removed the Latin-1 encoding altogether and limited the flexible representation to just UCS-2 / UCS-4, I doubt v

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

2012-08-31 Thread Ian Kelly
not the relative size of the string data. Again from the comments: Compact strings use only one memory block (structure + characters), whereas legacy strings use one block for the structure and one block for characters. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: how to get character hex number?

2012-08-31 Thread Ian Kelly
On Fri, Aug 31, 2012 at 8:21 PM, contro opinion wrote: for i in "english" : > ... print(hex((ord(i > ... > 0x65 > 0x6e > 0x67 > 0x6c > 0x69 > 0x73 > 0x68 u"english".encode("utf-8") > 'english' u"english".encode("ascii") > 'english' > > how can i get 656e676c697368 in encode me

Re: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python

2012-09-01 Thread Ian Kelly
Resending to the list... On Sep 1, 2012 12:19 PM, "Ian Kelly" wrote: > On Sep 1, 2012 9:37 AM, "Ramchandra Apte" wrote: > > Doesn't the pipes module already do this? > > No, that deals with actual Unix pipes. This appears to be about pipelined > pro

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

2012-09-02 Thread Ian Kelly
On Sun, Sep 2, 2012 at 1:36 AM, wrote: > I still remember my thoughts when I read the PEP 393 > discussion: "this is not logical", "they do no understand > typography", "atomic character ???", ... That would indicate one of two possibilities. Either: 1) Everybody in the PEP 393 discussion exce

Re: running Lua in Python

2012-09-02 Thread Ian Kelly
On Sun, Sep 2, 2012 at 3:04 AM, Arnaud Delobelle wrote: > Hi all, > > I'm looking for a way to run Lua scripts in Python, and also send and > receive data between the two. Something like lunatic-python [1] would > be ideal. However, so far I haven't been able to build it on the > machines it's s

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

2012-09-03 Thread Ian Kelly
On Sun, Sep 2, 2012 at 6:00 AM, Serhiy Storchaka wrote: > On 02.09.12 12:52, Peter Otten wrote: >> >> Ian Kelly wrote: >> >>> Rewriting the example to use locale.strcoll instead: >> >> >>>>>> sorted(li, key=functools.cmp_to_key(locale

Re: set and dict iteration

2012-09-03 Thread Ian Kelly
On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > We could use a Python long object for the version index to prevent overflow. > Combined with P. Rubin's idea to count the number of open iterators, most use > cases still wouldn't exceed a single word comparison; we could reset the > counte

Re: Python Interview Questions

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 8:34 AM, Chris Angelico wrote: > I wouldn't go that far. The 'name' parameter, I would expect, would be > a constant. The 'item' parameter, though, is probably not a constant, and it's interpolated just the same. > However, this strikes me as encouraging some really > inef

Re: Python Interview Questions

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico wrote: > On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly wrote: >> The lack of an ORDER BY is the least of the problems with that SQL. >> He's also using LIMIT without OFFSET, so the only thing that the >> 'item' a

Re: is implemented with id ?

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 8:13 AM, Steven D'Aprano wrote: > You *cannot* replace is with id() except when the objects are guaranteed > to both be alive at the same time, and even then you *shouldn't* replace > is with id() because that is a pessimation (the opposite of an > optimization -- something

Re: Function for examine content of directory

2012-09-06 Thread Ian Foote
ions = [] Try using a set here instead of a list: extensions = set() for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() name , ext = os.path.splitext(f.name) extensions.append(ext) and use: extensions.add(ext) This should take care of duplicates for you. Regards, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: os.stat() distorts filenames that end with period (nt.stat())

2012-09-06 Thread Ian Kelly
'goo' doesn't exist, os.stat will complain. Due to the weirdness of Windows filename extensions, these names refer to the same file. C:\Users\Ian>echo hello > goo C:\Users\Ian>type goo hello C:\Users\Ian>type goo. hello C:\Users\Ian>type goo.. hello C:\Users\Ian&

Re: simple client data base

2012-09-08 Thread Ian W
irst project. It's the same way with programming. I'm wondering what his backup plan is for the information, in case his database somehow messes things up. It's smarter to start with something that's not vital to the functioning of your wife's business. Ian -- http://ma

Re: Is there any difference between print 3 and print '3' in Python ?

2012-09-09 Thread Ian Foote
ference is that 3 is an integer whereas '3' is a string. The print statement (function in python 3) converts any object to a string before displaying it on the screen, so print 3 and print '3' both display the same result. Ian F -- http://mail.python.org/mailman/listinfo/python-list

Re: submit jobs on multi-core

2012-09-11 Thread Ian Kelly
On Mon, Sep 10, 2012 at 11:53 PM, Laszlo Nagy wrote: > On 2012-09-11 06:16, Dhananjay wrote: >> >> Dear all, >> >> I have a python script in which I have a list of files to input one by one >> and for each file I get a number as an output. >> I used for loop to submit the file to script. >> My scr

Re: Single leading dash in member variable names?

2012-09-11 Thread Ian Kelly
On Tue, Sep 11, 2012 at 12:45 PM, wrote: > All > > Python noob here. Trying to understand a particular syntax: > > class stuff: > def __init__(self): > self._bongo = "BongoWorld" > > --- > > What is the significance of the leading underscore in "self._bongo"? I've > seen t

Re: Single leading dash in member variable names?

2012-09-11 Thread Ian Kelly
On Tue, Sep 11, 2012 at 2:53 PM, wrote: > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: >> Single leading underscore is a convention indicating that the name >> should be considered private and not used externally. It's a softer >> version of the doub

Re: generators as decorators simple issue

2012-09-12 Thread Ian Kelly
On Wed, Sep 12, 2012 at 4:22 AM, pyjoshsys wrote: > The output is still not what I want. Now runtime error free, however the > output is not what I desire. [SNIP] > class Trial(object): > '''class to demonstrate with''' > def __init__(self): > object.__init__(self) > sel

Re: Single leading dash in member variable names?

2012-09-12 Thread Ian Kelly
On Tue, Sep 11, 2012 at 11:10 PM, Dwight Hutto wrote: > Not to jump in with another question(this seems somewhat relevant to the > conversation, maybe not), but is this similar to a private,public, or > protected class similar to the C type langs? More like "this is an implementation detail and i

Re: Single leading dash in member variable names?

2012-09-12 Thread Ian Kelly
On Wed, Sep 12, 2012 at 9:23 AM, wrote: > > On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote: > > On 09/11/2012 01:53 PM, me wrote: > > > PEP 8 says this is bad form. What do you think? > > > > > > > > Where does it say that? > > Apologies. It's in David Goodger's "Code Li

Re: datetime

2012-09-13 Thread Ian Kelly
On Thu, Sep 13, 2012 at 9:19 AM, Max wrote: > How do I set the time in Python? On what platform? I don't know of any libraries for this, so it would be a matter of making the necessary system calls (which is all that a library would do anyway). > Also, is there any *direct* way to shift it? On

Re: equiv of perl regexp grammar?

2012-09-13 Thread Ian Kelly
On Thu, Sep 13, 2012 at 5:30 AM, Neal Becker wrote: > I noticed this and thought it looked interesting: > > http://search.cpan.org/~dconway/Regexp- > Grammars-1.021/lib/Regexp/Grammars.pm#DESCRIPTION > > I'm wondering if python has something equivalent? The pyparsing module is a good option for b

Re: hi

2012-09-14 Thread Ian Kelly
On Fri, Sep 14, 2012 at 12:09 AM, alex23 wrote: > On Sep 14, 3:44 pm, Dwight Hutto wrote: >> CEO:http://www.hitwebdevelopment.com > > I don't know what gives more of a negative impression of your > business, your acting like a tedious douchebag or the website itself. Holy cow, that's the website

Re: Decorators not worth the effort

2012-09-14 Thread Ian Kelly
ameter unpacking was removed in Python 3. It's not a complicated upgrade path, however: @make_parameterized_wrapper def complex_decorator(func, params, *args, **kwargs): (param1, param2, param3) = params do_stuff(param1, param2) result = func(*args, **kwargs) do_more_stuff(param2, param3) return result Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: how to use property?

2012-09-17 Thread Ian Kelly
On Mon, Sep 17, 2012 at 6:26 PM, MRAB wrote: > On 2012-09-18 00:46, Dave Angel wrote: >> An important difference from every other language I've used: The user >> of the attribute does not need to change his code when you decide it >> needs reimplementation as a property. >> >> In C++ and java, fo

Re: 'indent'ing Python in windows bat

2012-09-17 Thread Ian Kelly
On Mon, Sep 17, 2012 at 7:08 PM, David Smith wrote: > How do I "indent" if I have something like: > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > sys.exit(3) How about: if sR == 'Cope': sys.exit(1) elif sR == 'Perform': sys.exit(2) else: sys.exit(3) I don't re

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 8:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > sum((8,5,9,3)) > 25 sum([5,8,3,9,2]) > 27 sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that s

Re: A little morning puzzle

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 6:13 AM, Antoon Pardon wrote: > On 19-09-12 13:17, Neal Becker wrote: >> 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? > common_items = reduce(opereator.__an

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 9:06 AM, Neil Cerutti wrote: > Are iterables and sequences different enough to warrant posting a > bug report? The glossary is specific about the definitions of both, so I would say yes. http://docs.python.org/dev/glossary.html#term-iterable http://docs.python.org/dev/glo

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > Sequences are iterables, so I'd say the docs are technically correct, > but maybe I'm misunderstanding what you would be trying to clarify. The doc string suggests that the argument to sum() must be a sequence, when in fact any iterable will

Re: How to get the list of all my open file(descriptor)s and locks?

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 11:34 AM, Ismael Farfán wrote: > So the question: > * If I execve a python script (from C), how can I retrieve the list of > files, and optionally the list of locks, from within the execve(d) > python process so that I can use them? > > > Some more info: > I'm working with

Re: How to get the list of all my open file(descriptor)s and locks?

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 2:36 PM, Ismael Farfán wrote: > It seems like I can use os.fstat to find out if a fd exists and also > get it's type and mode (I'm getting some pipes too : ) Sure, because files and pipes both use the file descriptor abstraction. If your process does any networking, you'l

Re: looping in array vs looping in a dic

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:09 PM, MRAB wrote: > for col in range(cols): > for row in range(rows): > cat = valuesCategory[row, col] > ras = valuesRaster[row, col] > totals[cat] += ras Expanding on what MRAB wrote, since you probably have far fewer categories than pixels,

Re: looping in array vs looping in a dic

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:28 PM, Ian Kelly wrote: > Expanding on what MRAB wrote, since you probably have far fewer > categories than pixels, you may be able to take better advantage of > numpy's vectorized operations (which are pretty much the whole point > of using numpy in th

Re: When should I use "development mode"?

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:38 PM, py_lrnr wrote: > Can anyone (very briefly) explain to me, in a sentence or two: > > what 'development mode' is? > how 'development mode' differs from other 'modes'? > why/when I would use 'development mode'? > what 'development mode' does or does not allow me to do

Re: portable way of locating an executable (like which)

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 4:21 PM, Chris Angelico wrote: > os.sep is the directory separator, but os.pathsep may be what you > want. Between that and os.getenv('path') you can at least get the > directories. Then on Windows, you also need to check out > os.getenv('pathext') and split _that_ on the s

Re: how to do draw pattern with python?

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 10:50 AM, Ismael Farfán wrote: > 2012/9/21 Peter Otten <__pete...@web.de>: >> echo.hp...@gmail.com wrote: >> >> print "\x1b[2J\x1b[0;0H" # optional > > Nice code : ) > > Could you dissect that weird string for us? > > It isn't returning the cursor to (0,0), it's just li

Re: Exact integer-valued floats

2012-09-21 Thread Ian Kelly
ere c is an integer, the gap between floats is equal to 2 ** q. There are 53 bits of precision in a double-precision float (technically an implicit 1 followed by 52 bits), so q becomes greater than 0 at 2 ** 53. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Algorithms using Python?

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 1:45 PM, Dennis Lee Bieber wrote: > You can probably implement them, but they're not going to be very > efficient. (And never "remove" an element from the linked-list > implementation because Python would shift all the other elements, hence > your "links" become inv

Re: Functional way to compare things inside a list

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 1:54 PM, 8 Dihedral wrote: > I don't think functional aspects are only marked as lazy > programming. He wrote "lazy evaluation", not "lazy programming". Two entirely different things. > It just means when one is experimenting something > the efficient execution in sp

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
s like a candidate for recursion. Also sounds like a use for yield. Any > suggestions? levels = 6 for combination in itertools.product(xrange(n_syms), levels): # do stuff Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

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

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
ge. Observers are also conceptually simpler than events. You can find information about pubsub at: http://wiki.wxpython.org/WxLibPubSub Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

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

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