Re: Pyhon 2.x or 3.x, which is faster?

2016-03-08 Thread Serhiy Storchaka
On 08.03.16 04:12, Steven D'Aprano wrote: [steve@ando ~]$ python3.3 -m timeit -s 'from fp import Float' 'Float("1234.567")' 10 loops, best of 3: 13.6 usec per loop [steve@ando ~]$ python/python-dev/3.5/python -m timeit -s 'from fp import Float' 'Float("1234.567")' 1 loops, best of 3: 54

Re: Adding Icon To Tkinter Window

2016-03-05 Thread Serhiy Storchaka
On 05.03.16 18:47, Wildman via Python-list wrote: Anybody have the correct method of adding an icon to a window? I have found several code examples on the web but they all result in an error. Thanks. On Windows: root.wm_iconbitmap(default='myapp.ico') .ico-file can contain several icons

Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-27 Thread Serhiy Storchaka
On 27.02.16 11:49, Steven D'Aprano wrote: On Thu, 25 Feb 2016 06:30 pm, Chris Angelico wrote: How bad is it if you over-read? Pretty bad :-) Ideally, I'd rather not over-read at all. I'd like the user to be able to swap from "read N bytes" to "read to the next delimiter" (and possibly even "r

Re: Trailing zeros of 100!

2016-01-02 Thread Serhiy Storchaka
On 02.01.16 18:33, Tim Chase wrote: or mathematically: sum(1 for _ in itertools.takewhile( lambda x: n % (10**x) == 0, itertools.count(1))) The mathematician would prove that the result is not larger than 100/4. -- https://mail.python.org/mailman/listinfo/python-list

Re: Stupid Python tricks

2016-01-01 Thread Serhiy Storchaka
On 31.12.15 05:51, Steven D'Aprano wrote: Fifteen years later, and Tim Peters' Stupid Python Trick is still the undisputed champion! It may be platform depended, but on my computer the obvious way is 10% faster the Stupid Python Trick. -- https://mail.python.org/mailman/listinfo/python-list

Re: Stupid Python tricks

2016-01-01 Thread Serhiy Storchaka
On 01.01.16 21:00, paul.hermeneu...@gmail.com wrote: On Wed, Dec 30, 2015 at 11:09 PM, Steven D'Aprano wrote: On Thu, 31 Dec 2015 04:02 pm, Rick Johnson wrote: Fifteen years later, and Tim Peters' Stupid Python Trick is still the undisputed champion! And should we be happy about that revel

Re: Should stdlib files contain 'narrow non breaking space' U+202F?

2015-12-18 Thread Serhiy Storchaka
On 18.12.15 09:43, Chris Angelico wrote: On Fri, Dec 18, 2015 at 6:12 PM, Serhiy Storchaka wrote: Agreed. Please open an issue. Using non-ASCII apostrophes and like in docstrings may be considered a bug. http://bugs.python.org/issue25899 Thanks. Also noticed this. Is this a markup error

Re: Should stdlib files contain 'narrow non breaking space' U+202F?

2015-12-17 Thread Serhiy Storchaka
On 18.12.15 08:51, Chris Angelico wrote: On Fri, Dec 18, 2015 at 5:36 PM, Terry Reedy wrote: Last I knew, Guido still wanted stdlib files to be all-ascii, especially possibly in special cases. There is no good reason I can think of for there to be an invisible non-ascii space in a comment. It

Re: Is vars() the most useless Python built-in ever?

2015-12-04 Thread Serhiy Storchaka
On 02.12.15 11:28, Chris Angelico wrote: On Wed, Dec 2, 2015 at 7:22 PM, Serhiy Storchaka wrote: On 01.12.15 03:00, Steven D'Aprano wrote: I'm trying to understand why vars() exists. Does anyone use it? I use vars() exclusively for introspection in interactive environment. As w

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-04 Thread Serhiy Storchaka
On 04.12.15 00:26, Oscar Benjamin wrote: On 3 Dec 2015 16:50, "Terry Reedy" wrote: fileinput is an ancient module that predates iterators (and generators) and context managers. Since by 2.7 open files are both context managers and line iterators, you can easily write your own multi-file line i

Re: Is vars() the most useless Python built-in ever?

2015-12-02 Thread Serhiy Storchaka
On 01.12.15 03:00, Steven D'Aprano wrote: I'm trying to understand why vars() exists. Does anyone use it? I use vars() exclusively for introspection in interactive environment. As well as dir() and help(). Sad that it doesn't work with __slots__. -- https://mail.python.org/mailman/listinfo/

Re: Proposed keyword to transfer control to another function

2015-07-17 Thread Serhiy Storchaka
On 17.07.15 02:46, Chris Angelico wrote: Out of the lengthy thread on tail call optimization has come one broad theory that might be of interest, so I'm spinning it off into its own thread. The concept is like the Unix exec[vlpe] family of functions: replace the current stack frame with a new on

Re: 0 + not 0

2015-07-11 Thread Serhiy Storchaka
On 11.07.15 13:26, candide wrote: 0 + not 0 File "", line 1 0 + not 0 ^ SyntaxError: invalid syntax What is syntactically wrong with 0 + not 0? This looks as a bug to me. Please file a report on http://bugs.python.org. -- https://mail.python.org/mailman/listinfo/pytho

Re: enhancement request: make py3 read/write py2 pickle format

2015-06-11 Thread Serhiy Storchaka
On 11.06.15 02:58, Chris Angelico wrote: On Thu, Jun 11, 2015 at 8:10 AM, Devin Jeanpierre wrote: The problem is that there are two different ways repr might write out a dict equal to {'a': 1, 'b': 2}. This can make tests brittle -- e.g. it's why doctest fails badly at examples involving dictio

Re: enhancement request: make py3 read/write py2 pickle format

2015-06-09 Thread Serhiy Storchaka
On 09.06.15 21:31, Laura Creighton wrote: We have an issue about that. https://bugs.python.org/issue13566 Go there and say you want it too. :) I afraid issue title is too general. :) The issue is only about one minor detail of py3 to py2 compatibility. -- https://mail.python.org/mailman/lis

Re: enhancement request: make py3 read/write py2 pickle format

2015-06-09 Thread Serhiy Storchaka
On 09.06.15 21:08, Neal Becker wrote: One of the most annoying problems with py2/3 interoperability is that the pickle formats are not compatible. There must be many who, like myself, often use pickle format for data storage. It certainly would be a big help if py3 could read/write py2 pickle f

Re: Cheat sheet for the new string formatting?

2015-06-08 Thread Serhiy Storchaka
On 08.06.15 23:32, Skip Montanaro wrote: This is counterintuitive: >>> "{:.3}".format(-0.00666762259822) '-0.00667' >>> "{:.3f}".format(-0.00666762259822) '-0.007' >>> "%.3f" % -0.00666762259822 '-0.007' >>> "{:.3s}".format(-0.00666762259822) ValueError Unknown format code 's' for object of

Re: Can Python function return multiple data?

2015-06-03 Thread Serhiy Storchaka
On 03.06.15 02:56, Chris Angelico wrote: On Wed, Jun 3, 2015 at 7:27 AM, fl wrote: I just see the tutorial says Python can return value in function, it does not say multiple data results return situation. In C, it is possible. How about Python on a multiple data return requirement? Technicall

Re: Minus operator versus unary minus

2015-05-30 Thread Serhiy Storchaka
On 30.05.15 12:09, Peter Otten wrote: Serhiy Storchaka wrote: On 30.05.15 10:56, Peter Otten wrote: The following modification of the collections.Counter implementation https://hg.python.org/cpython/rev/fe4efc0032b5 was just checked in with the line result[elem] = 0 - count Does this have

Re: Minus operator versus unary minus

2015-05-30 Thread Serhiy Storchaka
On 30.05.15 10:56, Peter Otten wrote: The following modification of the collections.Counter implementation https://hg.python.org/cpython/rev/fe4efc0032b5 was just checked in with the line result[elem] = 0 - count Does this have an advantage over the obvious result[elem] = -count ? x = 0.

Re: Slices time complexity

2015-05-19 Thread Serhiy Storchaka
On 19.05.15 18:15, Ian Kelly wrote: On May 19, 2015 4:16 AM, "Serhiy Storchaka" mailto:storch...@gmail.com>> wrote: > > On 19.05.15 12:45, Steven D'Aprano wrote: >> >> On Tuesday 19 May 2015 05:23, Mario Figueiredo wrote: >>> >>> F

Re: Slices time complexity

2015-05-19 Thread Serhiy Storchaka
On 19.05.15 12:45, Steven D'Aprano wrote: On Tuesday 19 May 2015 05:23, Mario Figueiredo wrote: From the above link it seems slices work in linear time on all cases. I wouldn't trust that is always the case, e.g. deleting a contiguous slice from the end of a list could be O(1). It always ha

Re: Stripping unencodable characters from a string

2015-05-08 Thread Serhiy Storchaka
On 05.05.15 21:19, Paul Moore wrote: I want to write a string to an already-open file (sys.stdout, typically). However, I *don't* want encoding errors, and the string could be arbitrary Unicode (in theory). The best way I've found is data = data.encode(file.encoding, errors='replace').dec

Re: New to Python - block grouping (spaces)

2015-04-16 Thread Serhiy Storchaka
On 16.04.15 08:49, Steven D'Aprano wrote: I'm not aware of any pre-processor tools for Python that will syntactically check that added braces match the indentation. Such a tool would be unPythonic: if they match, the braces are redundant and are not needed, and if they do not match, then the comp

Re: try..except with empty exceptions

2015-04-11 Thread Serhiy Storchaka
On 11.04.15 10:11, Steven D'Aprano wrote: Anyway, in modern Python (2.6 onwards), now that string exceptions are gone, you can supply something to catch everything. Or nothing, for that matter: BaseException # catch everything Not everything. >>> class A: pass ... >>> try: raise A ... except

Re: How to find out which named regular expression group corresponds to which positional regex group

2015-04-09 Thread Serhiy Storchaka
On 08.04.15 16:23, Mattias Ugelvik wrote: I'm making a string manipulation tool in which I need to know this correlation. Take this example: re.match('(?Pa?)(?Pb?)', '') I need to know that 'first' is group #1, and 'second' is group #2. I need this to resolve certain ambiguities. I was hopin

Re: Best search algorithm to find condition within a range

2015-04-07 Thread Serhiy Storchaka
On 07.04.15 22:28, Ian Kelly wrote: On Tue, Apr 7, 2015 at 1:19 PM, Ian Kelly wrote: On Tue, Apr 7, 2015 at 12:55 PM, Terry Reedy wrote: % and probably // call divmod internally and toss one of the results. Slightly faster (5.7 versus 6.1 microseconds on my machine) is Not on my box. $ pyt

Re: Letter class in re

2015-03-09 Thread Serhiy Storchaka
On 09.03.15 14:26, Antoon Pardon wrote: So if I understand correctly the following should be a regular expression for a python3 identifier. (?:(?!_|\d)\w)\w+ It seems odd that one should need such an ugly expression for something that is used rather frequently for parsing computer languages

Re: Reading all buffered bytes without blocking

2015-03-03 Thread Serhiy Storchaka
On 03.03.15 18:07, Paul Moore wrote: Is it possible to say to a BufferedReader stream "give me all the bytes you have available in the buffer, or do one OS call and give me everything you get back"? The problem is that the "number of bytes" argument to read1() isn't optional, so I can't do avai

Re: Bug in timsort!?

2015-02-25 Thread Serhiy Storchaka
On 25.02.15 18:56, Chris Kaynor wrote: While the CPython implementation was only broken for arrays of length larger than 2**49, aka, practically not broken, the Java implementation (such as used on Android phones) was broken with arrays of length > 67,108,864 at the time the post was made. While

Re: Unrecognized backslash escapes in string literals

2015-02-23 Thread Serhiy Storchaka
On 23.02.15 04:55, Chris Angelico wrote: I agree, the fault is primarily with Windows. But I've seen similar issues when people use /-\| for box drawing and framing and such; Windows paths are by far the most common case of this, but not the sole. There is also issues with regular expressions.

Re: Challenge: optimizing isqrt

2014-11-26 Thread Serhiy Storchaka
On 26.11.14 02:46, Dave Angel wrote: Unfortunately, for many values, the version of the function with >>1 is slower. It's only when the argument is bigger than 10**40 that it's as much as 1% faster. But it's true that for really large values, it's quicker. Note that this path is used only for

Re: Challenge: optimizing isqrt

2014-11-25 Thread Serhiy Storchaka
п'ятниця, 21-лис-2014 08:15:57 ви написали: This looks very good indeed. As a matter of interest, is there any particular reason you have used 2*b instead of b+b? Might b+b be faster than b*2? Yes, it is slightly faster, but the effect is indiscernible in total time. But there is not harm to

Re: Challenge: optimizing isqrt

2014-11-20 Thread Serhiy Storchaka
On 01.11.14 03:29, Steven D'Aprano wrote: There is an algorithm for calculating the integer square root of any positive integer using only integer operations: Here is my optimized implementation inspired by Christian's ideas. import math, sys C1 = sys.float_info.radix ** sys.float_info.mant_d

Re: tkinter errors out without clear message

2014-05-22 Thread Serhiy Storchaka
21.05.14 20:19, Terry Reedy написав(ла): There is also the issue that TkVersion == 8.5 is underspecied -- there are multiple bugfix releases. root.call('info', 'patchlevel') returns more detailed info. -- https://mail.python.org/mailman/listinfo/python-list

Re: A curious bit of code...

2014-02-13 Thread Serhiy Storchaka
13.02.14 21:59, Zachary Ware написав(ла): don't use re for simple stuff (because while it may be very fast, it's dominated by attribute lookup and function call overhead), And the time of re variant depends on the size of input. -- https://mail.python.org/mailman/listinfo/python-list

Re: fseek In Compressed Files

2014-02-03 Thread Serhiy Storchaka
30.01.14 18:21, Peter Otten написав(ла): Do you know an efficient way to implement random access for a bzip2 or gzip file? See dictzip and BGZF. Unfortunately Python stdlib doesn't support them. -- https://mail.python.org/mailman/listinfo/python-list

Re: fseek In Compressed Files

2014-01-30 Thread Serhiy Storchaka
30.01.14 13:28, Peter Otten написав(ла): Ayushi Dalmia wrote: I need to randomly access a bzip2 or gzip file. How can I set the offset for a line and later retreive the line from the file using the offset. Pointers in this direction will help. with gzip.open(filename) as f: f.seek(some_p

Re: [RELEASED] Python 3.3.4 release candidate 1

2014-01-29 Thread Serhiy Storchaka
29.01.14 18:55, Andrew Svetlov написав(ла): Would you to accept fixes for http://bugs.python.org/issue20434 and http://bugs.python.org/issue20437 before 3.3.4 final? And http://bugs.python.org/issue20440. -- https://mail.python.org/mailman/listinfo/python-list

Re: Bytes indexing returns an int

2014-01-09 Thread Serhiy Storchaka
09.01.14 19:28, Ethan Furman написав(ла): On 01/09/2014 09:05 AM, Piet van Oostrum wrote: Please ignore jmf's repeated nonsense. Or ban him. His one, minor, contribution has been completely swamped by the rest of his belligerent, unfounded, refuted posts. Please not. I have a fun from every

Re: Bytes indexing returns an int

2014-01-07 Thread Serhiy Storchaka
07.01.14 18:12, Steven D'Aprano написав(ла): In Python 2.7, if you have a chunk of binary data, you can easily do this: data = b'\xE1\xE2\xE3\xE4' data[0] == b'\xE1' and it returns True just as expected. data[0] == b'\xE1'[0] works as expected in both Python 2.7 and 3.x. -- https://mail.pyt

Re: "More About Unicode in Python 2 and 3"

2014-01-06 Thread Serhiy Storchaka
06.01.14 15:44, Mark Lawrence написав(ла): Simply scrap PEP 404 and the currently unhappy customers will be happy as they'll be free to do all the work they want on Python 2.8, as my understanding is that the vast majority of the Python core developers won't do it for them. It's not necessary.

Re: "More About Unicode in Python 2 and 3"

2014-01-06 Thread Serhiy Storchaka
06.01.14 06:41, Tim Chase написав(ла): from codecs import getencoder getencoder("rot-13")(s2.decode('utf-8'))[0] 'Python' codecs.decode('rot13', s2.decode()) -- https://mail.python.org/mailman/listinfo/python-list

Re: "More About Unicode in Python 2 and 3"

2014-01-06 Thread Serhiy Storchaka
06.01.14 06:51, Chris Angelico написав(ла): data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to turn a hex dump into a bytes literal? >>> bytes.fromhex('43 6c 67 75 62 61') b'Clguba' -- https://mail.python.org/mailman/listinfo/python-list

Re: "More About Unicode in Python 2 and 3"

2014-01-05 Thread Serhiy Storchaka
I wonder why nobody complains about the absent of implicit conversion between int and str. In PHP you can write 2 + "3" and got 5, but in Python this is an error. So sad! -- https://mail.python.org/mailman/listinfo/python-list

Re: "More About Unicode in Python 2 and 3"

2014-01-05 Thread Serhiy Storchaka
05.01.14 15:34, Chris Angelico написав(ла): Why is a StopIteration bubbling up? (I don't have Flask, so I can't verify this.) Is it as simple as "this should be raising from None", or is there something else going on? Yes, it is. Stdlib json module uses "from None". -- https://mail.python.org/

Re: Why Python is like C++

2013-12-20 Thread Serhiy Storchaka
20.12.13 16:19, Roy Smith написав(ла): http://xkcd.com/1306/ QBASIC$, not $QBASIC. -- https://mail.python.org/mailman/listinfo/python-list

Re: Struggling with unittest discovery - how to structure my project test suite

2013-12-20 Thread Serhiy Storchaka
20.12.13 16:47, Paul Moore написав(ла): What's the best way of structuring my projects so that: 1. I can run all the tests easily on demand. 2. I can run just the functional or unit tests when needed. python -m unittest discover -s tests/functional python -m unittest discover tests/functional

Re: Python Unicode handling wins again -- mostly

2013-12-01 Thread Serhiy Storchaka
30.11.13 02:44, Steven D'Aprano написав(ла): (2) If you reverse that string, does it give "lëon"? The implication of this question is that strings should operate on grapheme clusters rather than code points. Python fails this test: py> print("noe\u0308l"[::-1]) leon >>> print(unicodedata.norma

Re: Byteorder of audioop functions

2013-11-18 Thread Serhiy Storchaka
18.11.13 18:51, Michael Schwarz написав(ла): Is the byteorder (or endianness) of the functions in the audioop module somewhere specified or does anyone know how it behaves on different systems? On my little-endian system it matches the system's endianness: It always matches the system's endia

Re: inconsistency in converting from/to hex

2013-11-17 Thread Serhiy Storchaka
17.11.13 08:31, Steven D'Aprano написав(ла): There's already at least two ways to do it in Python 2: py> import binascii py> binascii.hexlify('Python') '507974686f6e' py> import codecs py> codecs.encode('Python', 'hex') '507974686f6e' Third: >>> import base64 >>> base64.b16encode(b'Python')

Re: Implementing #define macros similar to C on python

2013-11-16 Thread Serhiy Storchaka
15.11.13 06:57, Chris Angelico написав(ла): On Fri, Nov 15, 2013 at 3:10 PM, Roy Smith wrote: Why would you want to? One of the most horrible things about C/C++ is the preprocessor. Hey, that's not fair! Without the preprocessor, how would you be able to do this: //Hide this part away in a

Re: python 3.3 repr

2013-11-15 Thread Serhiy Storchaka
15.11.13 17:32, Roy Smith написав(ла): Anybody remember RAD-50? It let you represent a 6-character filename (plus a 3-character extension) in a 16 bit word. RT-11 used it, not sure if it showed up anywhere else. In three 16-bit words. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 3.3 repr

2013-11-15 Thread Serhiy Storchaka
15.11.13 15:54, Ned Batchelder написав(ла): No, but I've found that significant programs that run on both 2 and 3 need to have some shims to make the code work anyway. You could do this: try: repr = ascii except NameError: pass and then use repr throughout. Or ra

Re: [Python-ideas] os.path.join

2013-11-04 Thread Serhiy Storchaka
04.11.13 20:01, Mark Lawrence написав(ла): On 04/11/2013 17:34, Ethan Furman wrote: On 11/04/2013 09:29 AM, random...@fastmail.us wrote: I did, incidentally, notice a bug in macpath's *split* function; macpath.split(':foo::bar') should return (':foo::','bar') rather than (':foo:','bar'). Ope

Re: Sexism in the Ruby community: how does the Python community manage it?

2013-10-17 Thread Serhiy Storchaka
17.10.13 20:37, MRAB написав(ла): It's interesting to note that, in the early days, programming was thought to be a suitable job for a woman because, after all, it involved typing, so basically it was just clerical activity! But in the earlier days, typing and clerical activity were male domin

Re: API for custom Unicode error handlers

2013-10-04 Thread Serhiy Storchaka
04.10.13 16:56, Steven D'Aprano написав(ла): I have some custom Unicode error handlers, and I'm looking for advice on the right API for dealing with them. I have a module containing custom Unicode error handlers. For example: # Python 3 import unicodedata def namereplace_errors(exc): c = e

Re: API for custom Unicode error handlers

2013-10-04 Thread Serhiy Storchaka
04.10.13 20:22, Chris Angelico написав(ла): I'd be quite happy with importing having a side-effect here. If you import a module that implements a numeric type, it should immediately register itself with the Numeric ABC, right? This is IMO equivalent to that. There is a difference. You can't use

Re: Weird ttk behaviour

2013-09-16 Thread Serhiy Storchaka
16.09.13 19:28, Rotwang написав(ла): On Windows 7 (sys.version is '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]') there's no problem; f() works fine in the first place. Does anybody know what's going on? What _root.wantobjects() returns? -- https://mail.pytho

Re: Chardet, file, ... and the Flexible String Representation

2013-09-11 Thread Serhiy Storchaka
09.09.13 22:27, random...@fastmail.us написав(ла): On Mon, Sep 9, 2013, at 15:03, Ian Kelly wrote: Do you mean that it breaks when overwriting Python string object buffers, or when overwriting arbitrary C strings either received from C code or created with create_unicode_buffer? If the former,

Re: PEP8 79 char max

2013-09-07 Thread Serhiy Storchaka
06.09.13 06:40, Steven D'Aprano написав(ла): PEP 8 certainly is a collection of rules. They are mandatory for new code added to the standard library, and optional but recommended for third party libraries. No. They are optional but recommended for new code added to the standard library, and in

Re: Script that converts between indentation and curly braces in Python code

2013-07-31 Thread Serhiy Storchaka
31.07.13 06:45, Musical Notation написав(ла): Is there any script that converts indentation in Python code to curly braces? The indentation is sometime lost when I copy my code to an application or a website. Look at the pindent.py script. -- http://mail.python.org/mailman/listinfo/python-li

Re: collections.Counter surprisingly slow

2013-07-30 Thread Serhiy Storchaka
29.07.13 14:49, Joshua Landau написав(ла): I find it hard to agree that counter should be optimised for the unique-data case, as surely it's much more oft used when there's a point to counting? Different methods are faster for different data. LBYL approach is best for the mostly unique data ca

Re: collections.Counter surprisingly slow

2013-07-29 Thread Serhiy Storchaka
29.07.13 20:19, Ian Kelly написав(ла): On Mon, Jul 29, 2013 at 5:49 AM, Joshua Landau wrote: Also, couldn't Counter just extend from defaultdict? It could, but I expect the C helper function in 3.4 will be faster since it doesn't even need to call __missing__ in the first place. I'm surpris

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Serhiy Storchaka
29.07.13 19:09, MRAB написав(ла): I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats are approximate anyway, and the float value 1/3 is more likely to be Fraction(1, 3) than Fraction(6004799503160661, 18014398509481984). >>> def approximate_fraction(f): prev_numer, numer

Re: collections.Counter surprisingly slow

2013-07-28 Thread Serhiy Storchaka
28.07.13 22:59, Roy Smith написав(ла): The input is an 8.8 Mbyte file containing about 570,000 lines (11,000 unique strings). Repeat you tests with totally unique lines. The full profiler dump is at the end of this message, but the gist of it is: Profiler affects execution time. In partic

Re: RE Module Performance

2013-07-24 Thread Serhiy Storchaka
24.07.13 21:15, Chris Angelico написав(ла): To my mind, exposing UTF-16 surrogates to the application is a bug to be fixed, not a feature to be maintained. Python 3 uses code points from U+DC80 to U+DCFF (which are in surrogates area) to represent undecodable bytes with surrogateescape error h

Re: Find and Replace Simplification

2013-07-21 Thread Serhiy Storchaka
21.07.13 14:29, Joshua Landau написав(ла): On 21 July 2013 08:44, Serhiy Storchaka wrote: 20.07.13 20:03, Joshua Landau написав(ла): Still, it seems to me that it should be optimizable for sensible builtin types such that .translate is significantly faster, as there's no theoretical

Re: Find and Replace Simplification

2013-07-21 Thread Serhiy Storchaka
20.07.13 20:03, Joshua Landau написав(ла): Still, it seems to me that it should be optimizable for sensible builtin types such that .translate is significantly faster, as there's no theoretical extra work that .translate *has* to do that .replace does not, and .replace also has to rebuild the str

Re: How can I make this piece of code even faster?

2013-07-21 Thread Serhiy Storchaka
20.07.13 23:22, pablobarhamal...@gmail.com написав(ла): e = math.e count = -1 for x in range(hidden_num): temp = 0 for y in range(input_num): count += 1 temp += inputs[y] * h_weight[count] hidden[

Re: Find and Replace Simplification

2013-07-20 Thread Serhiy Storchaka
20.07.13 14:16, Joshua Landau написав(ла): On 19 July 2013 18:29, Serhiy Storchaka wrote: The string replace() method is fastest (at least in Python 3.3+). See implementation of html.escape() etc. def escape(s, quote=True): if quote: return s.translate(_escape_map_full

Re: Find and Replace Simplification

2013-07-20 Thread Serhiy Storchaka
19.07.13 21:08, Skip Montanaro написав(ла): Serhiy> The string replace() method is fastest (at least in Python 3.3+). See Serhiy> implementation of html.escape() etc. I trust everybody knows by now that when you want to use regular expressions you should shell out to Perl for the best performance

Re: Find and Replace Simplification

2013-07-19 Thread Serhiy Storchaka
19.07.13 19:22, Steven D'Aprano написав(ла): I also expect that the string replace() method will be second fastest, and re.sub will be the slowest, by a very long way. The string replace() method is fastest (at least in Python 3.3+). See implementation of html.escape() etc. -- http://mail.p

Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-18 Thread Serhiy Storchaka
18.07.13 20:04, Terry Reedy написав(ла): On 7/18/2013 3:29 AM, Aseem Bansal wrote: About reading comp.lang.python can you suggest how to read it and reply? To read this list as a newsgroup use news.gmane.org. The difference between the mailing list interface and newsgroup interface is that the

Re: Floating point minimum and maximum exponent values

2013-07-16 Thread Serhiy Storchaka
16.07.13 15:04, Chris Angelico написав(ла): Piece of extreme oddity, this. help(sys.float_info) ... lots of other info ... | max_exp | DBL_MAX_EXP -- maximum int e such that radix**(e-1) is representable | | min_exp | DBL_MIN_EXP -- minimum int e such that radix**(e-1) is

Re: [Python-ideas] float('∞')=float('inf')

2013-07-14 Thread Serhiy Storchaka
14.07.13 06:09, Chris Angelico написав(ла): Incidents like this are a definite push, but my D&D campaign is demanding my attention right now, so I haven't made the move. Are you role-playing Chaos Mage [1]? [1] http://www.dandwiki.com/wiki/Chaos_Mage_(3.5e_Class) -- http://mail.python.org/mai

Re: Version Control Software

2013-06-13 Thread Serhiy Storchaka
13.06.13 05:41, Tim Chase написав(ла): -hg: last I checked, can't do octopus merges (merges with more than two parents) +git: can do octopus merges Actually it is possible in Mercurial. I just have made a merge of two files in CPython test suite (http://bugs.python.org/issue18048). -- http

Re: ValueError: I/O operation on closed file. with python3

2013-06-12 Thread Serhiy Storchaka
12.06.13 10:26, Peter Otten написав(ла): @contextmanager def my_urlopen(url): resp = urlopen(url) yield io.TextIOWrapper(resp.fp) with urlopen(url) as resp: yield io.TextIOWrapper(resp) Note that last bugfix releases (i.e. 3.3.1) are needed. There was a

Re: Split a list into two parts based on a filter?

2013-06-12 Thread Serhiy Storchaka
12.06.13 09:32, Phil Connell написав(ла): On 12 Jun 2013 01:36, "Roy Smith" mailto:r...@panix.com>> wrote: > Well, continuing down this somewhat bizarre path: > > new_songs, old_songs = [], [] > itertools.takewhile( > lambda x: True, > (new_songs if s.is_new() else old_songs).append

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-11 Thread Serhiy Storchaka
11.06.13 06:02, Steven D'Aprano написав(ла): On Mon, 10 Jun 2013 19:36:44 -0700, rusi wrote: And so languages nowadays tend to 'protect' against this feature. Apart from Erlang, got any other examples? C#? At least local variable can't shadow other local variable in outer scope (and it look

Re: Split a list into two parts based on a filter?

2013-06-11 Thread Serhiy Storchaka
11.06.13 01:50, Chris Angelico написав(ла): On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: new_songs = [s for s in songs if s.is_new()] old_songs = [s for s in songs if not s.is_new()] Hmm. Would this serve? old_songs = songs[:] new_songs = [songs.remove(s) or s for s in songs if s.is_new

Re: Split a list into two parts based on a filter?

2013-06-11 Thread Serhiy Storchaka
11.06.13 07:11, Roy Smith написав(ла): In article , Roel Schroeven wrote: new_songs, old_songs = [], [] [(new_songs if s.is_new() else old_songs).append(s) for s in songs] Thanks kind of neat, thanks. I'm trying to figure out what list gets created and discarded. I think it's [None] * le

Re: Mistakes in documentation

2013-06-06 Thread Serhiy Storchaka
06.06.13 15:01, Paul Volkov написав(ла): Where can I submit little mistakes in Python documantation? http://bugs.python.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-06 Thread Serhiy Storchaka
06.06.13 12:45, Chris Angelico написав(ла): For the "accept any object that has a next() method" sorts of rules, I don't know of any really viable system that does that usefully. The concept of implementing interfaces in Java comes close, but the class author has to declare that it's implementing

Re: Apache and suexec issue that wont let me run my python script

2013-06-05 Thread Serhiy Storchaka
05.06.13 11:09, Chris Angelico написав(ла): Oh, and I changed the root password, since the current one was sent in clear text across the internet. Nikos, the new password has been stored in /home/nikos/new_password - you should be able to access that using your non-root login. I recommend you cha

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-31 Thread Serhiy Storchaka
31.05.13 12:55, Peter Otten написав(ла): Serhiy Storchaka wrote: 30.05.13 23:46, Skip Montanaro написав(ла): Am I missing something about how io.StringIO works? I thought it was a more-or-less drop-in replacement for StringIO.StringIO. io.StringIO was backported from Python 3. It is a text

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-31 Thread Serhiy Storchaka
30.05.13 23:46, Skip Montanaro написав(ла): Am I missing something about how io.StringIO works? I thought it was a more-or-less drop-in replacement for StringIO.StringIO. io.StringIO was backported from Python 3. It is a text (unicode) stream. cStringIO.StringIO is a binary stream and StringI

Re: Python error codes and messages location

2013-05-28 Thread Serhiy Storchaka
28.05.13 11:17, Chris Angelico написав(ла): On Tue, May 28, 2013 at 6:10 PM, Fábio Santos wrote: Just to clarify, I am suggesting to have the unchanged messages in tracebacks, but having some methods in the exception to get the exception and message localised. Just like repr() and str() are dir

Re: object.enable() anti-pattern

2013-05-10 Thread Serhiy Storchaka
10.05.13 15:19, Robert Kern написав(ла): I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. Many (if not most) GUI frameworks use this pattern. button = Button("text") button.setForegroundColor(...) button.setBackgoundColor(...) bu

Re: Why chunks is not part of the python standard lib?

2013-05-01 Thread Serhiy Storchaka
01.05.13 09:26, Ricardo Azpeitia Pimentel написав(ла): After reading How do you split a list into evenly sized chunks in Python? and seeing this kind of mistakes happening https://code.djangopro

Re: Pythonic way to count sequences

2013-04-25 Thread Serhiy Storchaka
25.04.13 08:26, Chris Angelico написав(ла): So you can count them up directly with a dictionary: count = {} for sequence_tuple in list_of_tuples: count[sequence_tuple] = count.get(sequence_tuple,0) + 1 Or alternatives: count = {} for sequence_tuple in list_of_tuples: if sequence_tup

Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-22 Thread Serhiy Storchaka
On 21.04.13 23:31, James Jong wrote: I see, just to be clear, do you mean that Python 2.7.4 (stable) is incompatible with Tk 8.6 (stable)? Yes. -- http://mail.python.org/mailman/listinfo/python-list

Re: Porting 2.x to 3.3: BaseHTTPServer

2013-04-21 Thread Serhiy Storchaka
21.04.13 16:46, Chris Angelico написав(ла): Also, it's expecting bytes everywhere, and I can't find a simple way to declare an encoding and let self.wfile.write() accept str. Do I have to explicitly encode everything that I write, or is there a cleaner way? io.TextIOWrapper -- http://mail.pyt

Re: unzipping a zipx file

2013-04-20 Thread Serhiy Storchaka
19.04.13 20:59, b_erickson1 написав(ла): I have python 2.6.2 and I trying to get it to unzip a file made with winzip pro. The file extension is zipx. This is on a windows machine where I have to send them all that files necessary to run. I am packaging this with py2exe. I can open the file

Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-19 Thread Serhiy Storchaka
18.04.13 19:24, James Jong написав(ла): The file libtk8.6.so has 1.5M and is definitely there. So why did that compilation fail? LD_LIBRARY_PATH=/path_to_libtk However be careful. For now Python doesn't support Tk 8.6 (results of some functions changed in 8.6), this is

Re: a couple of things I don't understand wrt lists

2013-04-17 Thread Serhiy Storchaka
17.04.13 07:57, Larry Hudson написав(ла): So using a list comprehension you can do it in two lines: def get_rule(num): bs = bin(num)[2:] return [0] * (8 - len(bs)) + [int(i) for i in bs] You can do it in one line! def get_rule(num): return list(map(int, '{:08b}'.format(num)))

Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-16 Thread Serhiy Storchaka
On 16.04.13 07:46, Ian Kelly wrote: On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy wrote: I will keep the above in mind if I write or review a patch. here are 4 non-subclassable builtin classes. Two are already documented. Bool in one, forget which other. I believe it was recently decided to

Re: Performance of int/long in Python 3

2013-04-07 Thread Serhiy Storchaka
On 07.04.13 00:24, Chris Angelico wrote: On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka wrote: See also the discussion at http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with rejection. This is an implementation detail and different Python implementations (including future

Re: Performance of int/long in Python 3

2013-04-06 Thread Serhiy Storchaka
04.04.13 00:57, Chris Angelico написав(ла): On Thu, Apr 4, 2013 at 2:07 AM, Steven D'Aprano wrote: On Thu, 04 Apr 2013 01:17:28 +1100, Chris Angelico wrote: Probably, but it still has to scan the body of the string. It'd not be too bad if it's all astral, but if it's all BMP, it has to scan t

Re: Regular expression problem

2013-03-11 Thread Serhiy Storchaka
On 11.03.13 04:06, Terry Reedy wrote: On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python solvers by using the same time limit for all lan

<    1   2   3   >