Re: Expression can be simplified on list

2016-09-14 Thread Serhiy Storchaka
On 14.09.16 11:28, Steven D'Aprano wrote: I'm not sure if it makes sense to talk about an "empty regular expression", or if that is the same as re.compile(''). Presumably if such a thing makes sense, it would match nothing, from any input at all. Actually, it matches anything. re.compile('').ma

Re: [RELEASE] Python 3.6.0b1 is now available

2016-09-14 Thread Serhiy Storchaka
On 14.09.16 17:36, Guido van Rossum wrote: Fortunately that page isn't linked from anywhere on the home page AFAIK. If it is, could someone file an issue in the pydotorg tracker? The url is at the bottom of every page. This is on of the first results (actually the first besides manually edited

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Serhiy Storchaka
On 12.10.16 04:30, Skip Montanaro wrote: https://docs.python.org/3/whatsnew/3.1.html It's the third hit when searching for 'float'. Assuming I understand what it's saying. ;) Thanks. Is that the "David Gay's algorithm"? That seems to apply only to repr(), while the change I observed was in

Re: Different behaviour of regexp in 3.6.0b2

2016-10-15 Thread Serhiy Storchaka
On 14.10.16 18:40, Lele Gaifax wrote: Hi all, trying out pgcli with Python 3.6.0b2 I got an error related to what seem a different behaviour, or even a bug, of re.sub(). The original intent is to replace spaces within a string with the regular expression \s+ (see https://github.com/dbcli/pgcl

Re: Different behaviour of regexp in 3.6.0b2

2016-10-15 Thread Serhiy Storchaka
On 14.10.16 20:01, Peter Otten wrote: Lele Gaifax wrote: So, how am I supposed to achieve the mentioned intent? By doubling the escape in the replacement? If there are no escape sequences aimed to be handled by re.sub() you can escape the replacement wholesale: re.sub(r'\s+', re.escape(r'\s+

Re: Different behaviour of regexp in 3.6.0b2

2016-10-15 Thread Serhiy Storchaka
On 14.10.16 19:15, Chris Angelico wrote: I wasn't specifically aware that the re module was doing the same thing, but it'll be from the same purpose and goal. The idea is that, for instance, Windows path names in non-raw string literals will no longer behave differently based on whether the path

Re: Reversing \N{...} notation?

2016-10-27 Thread Serhiy Storchaka
On 26.10.16 23:47, Peter Otten wrote: def mynamereplace(exc): return u"".join( "\\N{%s}" % unicodedata.name(c) for c in exc.object[exc.start:exc.end] ), exc.end codecs.register_error("namereplace", mynamereplace) Not all characters has standard na

Re: if iter(iterator) is iterator

2016-11-13 Thread Serhiy Storchaka
On 14.11.16 02:40, Steve D'Aprano wrote: I'm surprised that the inspect module doesn't appear to have isiterable and isiterator functions. Here's my first attempt at both: Just use isinstance() with collections ABC classes. -- https://mail.python.org/mailman/listinfo/python-list

Re: Simulating int arithmetic with wrap-around

2016-12-30 Thread Serhiy Storchaka
On 30.12.16 16:47, Steve D'Aprano wrote: Again, assume both operands are in range for an N-bit signed integer. What's a good way to efficiently, or at least not too inefficiently, do the calculations in Python? def to_unsigned(bits, x): return x & ((1

Re: Simulating int arithmetic with wrap-around

2016-12-30 Thread Serhiy Storchaka
On 31.12.16 02:30, Steve D'Aprano wrote: Are you saying that the best way of doing this is this? (1) convert signed Python ints to unsigned; (2) perform operation and bitmask; (3) convert unsigned back to signed. Here's an example. I want to multiply 7*3 using a signed 4-bit int, getting 5 a

Re: Temporary variables in list comprehensions

2017-01-09 Thread Serhiy Storchaka
On 09.01.17 05:53, Steven D'Aprano wrote: Suppose you have an expensive calculation that gets used two or more times in a loop. The obvious way to avoid calculating it twice in an ordinary loop is with a temporary variable: result = [] for x in data: tmp = expensive_calculation(x) result

Re: Temporary variables in list comprehensions

2017-01-09 Thread Serhiy Storchaka
On 09.01.17 12:46, Paul Rubin wrote: Serhiy Storchaka writes: gen = (expensive_calculation(x) for x in data) result = [(tmp, tmp + 1) for tmp in gen] result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)] Yes, of course, but only in the case of one-argument function

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Serhiy Storchaka
On 28.01.17 10:03, Steve D'Aprano wrote: Is shutil.get_terminal_size useless? When, if ever, should I use it in preference to the os version? If the shutil version is broken, can it be fixed? Read the history of shutil.get_terminal_size(). All this was discussed. -- https://mail.python.org/mai

Re: Since when builtin dict preserve key order?

2018-03-24 Thread Serhiy Storchaka
24.03.18 10:48, Marko Rauhamaa пише: Chris Angelico : On Sat, Mar 24, 2018 at 3:34 PM, Arkadiusz Bulski wrote: I already asked on PYPY and they confirmed that any version of pypy, including 2.7, has dict preserving insertion order. I am familiar with ordered **kw which was introduced in 3.6 bu

Re: Pep8 for long pattern

2018-03-27 Thread Serhiy Storchaka
27.03.18 17:17, Ganesh Pal пише: How do I split the below regex , so that it fits within the character limit of 79 words pattern = [ r'(?P([0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))', r'(?P(owner:\s+[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]

Improving syntax error messages

2018-04-26 Thread Serhiy Storchaka
What syntax errors did you see most often? Which of them looks the most weird? How would you like to improve their messages. -- https://mail.python.org/mailman/listinfo/python-list

Re: Tk covering the entire screen

2018-05-05 Thread Serhiy Storchaka
04.05.18 22:54, Skip Montanaro пише: I suspect this is a Tk issue as much as anything, but this is the only place I know to ask Tk questions. Any ideas? There is more specific place for Tkinter questions: https://mail.python.org/mailman/listinfo/tkinter-discuss -- https://mail.python.org/mail

Re: Tk covering the entire screen

2018-05-05 Thread Serhiy Storchaka
04.05.18 23:15, Skip Montanaro пише: I forgot to mention that when running on Linux (displaying back on Windows), the Python 3 version (3.6.4, Tk 8.6) does cover all three screens. The Windows Python 2.7.14 version with Tk 8.5 has problems. Try to upgrade to 2.7.15. It should be shipped with Tk

Re: itemgetter with default arguments

2018-05-05 Thread Serhiy Storchaka
04.05.18 20:04, Steven D'Aprano пише: On Fri, 04 May 2018 09:17:14 -0600, Ian Kelly wrote: On Fri, May 4, 2018 at 7:01 AM, Steven D'Aprano wrote: Here are the specifications: * you must use lambda, not def; Why? This seems like an arbitrary constraint. You'll have to ask the two core devs

Re: itemgetter with default arguments

2018-05-05 Thread Serhiy Storchaka
05.05.18 12:59, Steven D'Aprano пише: On Sat, 05 May 2018 10:31:17 +0300, Serhiy Storchaka wrote: Consider a concrete example. You need to sort a list of 2- or 3- element tuples by the first and third items (third items are strings if presented). itemgetter(0, 2) doesn't work be

Re: Why is calling eval so slow?

2018-05-05 Thread Serhiy Storchaka
05.05.18 19:10, Steven D'Aprano пише: # calling a regular function python3.5 -m timeit -s "f = lambda: 99" "f()" # evaluating a function code object python3.5 -m timeit -s "f = (lambda: 99).__code__" "eval(f)" # estimate the overhead of the eval name lookup python3.5 -m timeit "eval" # evaluating

Re: Why is calling eval so slow?

2018-05-05 Thread Serhiy Storchaka
06.05.18 05:29, Steven D'Aprano пише: On Sat, 05 May 2018 20:11:28 +0300, Serhiy Storchaka wrote: Why so slow? 1. Add an overhead of calling eval(), not just looking up its name. It is comparable with a time of calling a simple lambda. 2. Add an overhead of getting the globals dic

Re: Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Serhiy Storchaka
07.05.18 22:59, Terry Reedy пише: I intend to improve the IDLE doc section on IDLE-console differences. Don't haste to document it. The behavior of the standard interactive mode can be changed in 3.8. -- https://mail.python.org/mailman/listinfo/python-list

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Serhiy Storchaka
15.05.18 18:14, Skip Montanaro пише: Consider this: bytes("abc", encoding="utf-8") b'abc' Looks reasonable. Then consider this: str(bytes("abc", encoding="utf-8")) "b'abc'" Why is the b'...' bit still there? I suppose it's because I didn't tell it explicitly how to decode the bytes object

Re: syntax oddities

2018-05-15 Thread Serhiy Storchaka
15.05.18 22:10, Tobiah пише: Why is it len(object) instead of object.len? Because the first form looked better to Guido van Rossum. Why is it getattr(object, item) rather then object.getattr(item)? How do you get the 'getattr' attribute then? -- https://mail.python.org/mailman/listinfo/pyt

Re: what does := means simply?

2018-05-17 Thread Serhiy Storchaka
17.05.18 15:07, Paul Moore пише: It's a good example, because it makes it clear that the benefits of := are at least in some cases, somewhat dependent on the fact that Python evaluates arguments left to right :-) Unless it evaluates them in other order. -- https://mail.python.org/mailman/listi

Re: List replication operator

2018-05-25 Thread Serhiy Storchaka
25.05.18 10:28, Peter Otten пише: Steven D'Aprano wrote: But what do people think about proposing a new list replication with copy operator? [[]]**5 would return a new list consisting of five shallow copies of the inner list. Yet another arcanum to learn for beginners with little retur

Re: Enums: making a single enum

2018-05-26 Thread Serhiy Storchaka
26.05.18 08:07, Ian Kelly пише: On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano wrote: Am I silly for wanting to make a single enum? I have a three-state flag, True, False or Maybe. Is is confusing or bad practice to make a single enum

Re: Why exception from os.path.exists()?

2018-06-01 Thread Serhiy Storchaka
01.06.18 16:58, Chris Angelico пише: Possibly more confusing, though, is this: os.path.exists(1) True os.path.exists(2) True os.path.exists(3) False I think it's testing that the file descriptors exist, because os.path.exists is defined in terms of os.stat, which can stat a path or an FD.

Re: Why exception from os.path.exists()?

2018-06-01 Thread Serhiy Storchaka
02.06.18 03:05, Chris Angelico пише: The permissions error is reported differently by stat, but then exists() just says "oh that's an OS error so we're going to say it doesn't exist". If you truly want the reliable form of os.path.exists, it would be this: try: os.stat(path) return Tru

Re: Dealing with dicts in doctest

2018-07-06 Thread Serhiy Storchaka
05.07.18 20:57, Steven D'Aprano пише: I think that's really clever. Is it too clever? How do you deal with dicts in doctests? There was a proposition for adding a doctest option for order-insensitive matching (like NORMALIZE_WHITESPACE and ELLIPSIS). But it was rejected because there is a sim

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Serhiy Storchaka
01.08.18 21:03, Chris Angelico пише: And in any code that does not and cannot run on Python 2, the warning about bytes and text comparing unequal is nothing more than a false positive. Not always. If your code supported Python 2 in the past, or third-party dependencies supports or supported Py

Re: Calling an unbound method in C using the Public API

2018-08-30 Thread Serhiy Storchaka
29.08.18 17:33, Matthieu Dartiailh пише: I tried to look at the public C API for a way to call an unbound method with a minimal cost (in term of speed and memory). It seems to me, but please correct me if I am wrong, that one cannot call a MethodDef using only the public API. To use the public

Re: Python indentation (3 spaces)

2018-10-05 Thread Serhiy Storchaka
05.10.18 23:53, Chris Angelico пише: I don't understand how three spaces would prevent errors in a way that four wouldn't. In many editors and on terminal for a in x: if a: b() <-tab-->c() looks indistinguishable from for a in x: if a: b() c() but the former i

Re: How to parameterize unittests

2016-04-15 Thread Serhiy Storchaka
On 14.04.16 18:05, Steven D'Aprano wrote: On Fri, 15 Apr 2016 12:08 am, Antoon Pardon wrote: I have a unittest for my avltree module. Now I want this unittest to also run on a subclass of avltree. How can I organise this, so that I can largely reuse the original TestCase? class Test_AVLTree(

Re: How to parameterize unittests

2016-04-15 Thread Serhiy Storchaka
On 15.04.16 11:20, Antoon Pardon wrote: But the tests, at this moment, are not written to instantiate self.tree but to call avltree directly. So I have to rewrite these tests. That will IMO involve a lot of cut and paste. There is yet one approach. Import your original test file, patch it by s

Re: Detecting repeated subsequences of identical items

2016-04-21 Thread Serhiy Storchaka
On 21.04.16 06:07, Steven D'Aprano wrote: Now I want to group subsequences. For example, I have: "ABCABCABCDEABCDEFABCABCABCB" and I want to group it into repeating subsequences. [...] How can I do this? Does this problem have a standard name and/or solution? This is a part of lossless da

Re: Odd truth result with in and ==

2018-11-21 Thread Serhiy Storchaka
21.11.18 22:17, Cameron Simpson пише: Can someone show me a real world, or failing that - sane looking, chained comparison using "in"? s[0] == s[-1] in '\'"' Tests that string s starts and ends with a single or double quote. It can be also used with sets: elem in set1 <= set2 -- htt

Re: Why Python don't accept 03 as a number?

2018-12-07 Thread Serhiy Storchaka
08.12.18 03:17, jf...@ms4.hinet.net пише: 00 0 03 File "", line 1 03 ^ SyntaxError: invalid token In Python 3.8 the error message will be more informative: 03 File "", line 1 SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for o

Re: Why Python don't accept 03 as a number?

2018-12-08 Thread Serhiy Storchaka
08.12.18 08:53, Henrik Bengtsson пише: A comment from the sideline: one could imagine extending the Python syntax with a (optional) 0d prefix that allows for explicit specification of decimal values. They would "complete" the family: * 0b: binary number * 0o: octal number * 0d: decimal number *

Re: Are all items in list the same?

2019-01-08 Thread Serhiy Storchaka
08.01.19 11:07, Peter Otten пише: Bob van der Poel wrote: I need to see if all the items in my list are the same. I was using set() for this, but that doesn't work if items are themselves lists. So, assuming that a is a list of some things, the best I've been able to come up with it: if a

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Serhiy Storchaka
02.09.19 12:24, Chris Angelico пише: But the curious difference happens in 3.7. I don't know what changed to cause this, but from there on, the list gets built and then unpacked. This was a side effect of moving the optimization for `x in [a, b]` from the peepholer to the AST optimizer. -- h

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Serhiy Storchaka
03.09.19 11:02, Chris Angelico пише: On Tue, Sep 3, 2019 at 5:53 PM Serhiy Storchaka wrote: 02.09.19 12:24, Chris Angelico пише: But the curious difference happens in 3.7. I don't know what changed to cause this, but from there on, the list gets built and then unpacked. This was a

Re: How do I give a decorator acces to the class of a decorated function

2019-09-05 Thread Serhiy Storchaka
04.09.19 17:21, Antoon Pardon пише: What I am trying to do is the following. class MyClass (...) : @register def MyFunction(...) ... What I would want is for the register decorator to somehow create/mutate class variable(s) of MyClass. Is that possible or do I have to rethin

Re: python3, regular expression and bytes text

2019-10-12 Thread Serhiy Storchaka
12.10.19 21:08, Eko palypse пише: So how can I make it work with utf8 encoded text? You cannot. First, \w in re.LOCALE works only when the text is encoded with the locale encoding (cp1252 in your case). Second, re.LOCALE supports only 8-bit charsets. So even if you set the utf-8 locale, it w

Re: decorator needs access to variables where it is used.

2019-10-12 Thread Serhiy Storchaka
09.10.19 14:02, Chris Angelico пише: The decorator has full access to the function object, including a reference to that function's module globals. def trace(func): log = func.__globals__["log"] ... proceed as before As long as you can depend on "log" always being a module-level (glob

Re: Change in behaviour Python 3.7 > 3.8

2020-02-06 Thread Serhiy Storchaka
06.02.20 14:58, Frank Millman пише: I have noticed a change in behaviour in Python 3.8 compared with previous versions of Python going back to at least 2.7. I am pretty sure that it is not a problem, and is caused by my relying on a certain sequence of events at shutdown, which of course is not

Re: Change in behaviour Python 3.7 > 3.8

2020-02-07 Thread Serhiy Storchaka
07.02.20 07:27, Frank Millman пише: @Serhiy I import the common object *from* Module A. Sorry, I incorrectly described the change made in issue1. Even if you import it from module A, you can see that it was set to None at the time of executing __del__. But you could see this even before

Re: How to remove "" from starting of a string if provided by the user

2020-08-12 Thread Serhiy Storchaka
12.08.20 18:53, MRAB пише: > I would suggest: > while s[ : 1] in {'"', "'"} and s[ : 1] == s[-1 : ]: > ... s = s[1 : -1] And the condition can be written as s[ : 1] == s[-1 : ] in {'"', "'"} or more efficiently as s and s[0] == s[-1] in '\'"' -- https://mail.python.org/mailm

Re: Puzzling difference between lists and tuples

2020-09-21 Thread Serhiy Storchaka
18.09.20 03:55, Chris Angelico пише: > On Fri, Sep 18, 2020 at 10:53 AM Grant Edwards > wrote: >> Yea, the syntax for tuple literals has always been a bit of an ugly >> spot in Python. If ASCII had only had one more set of open/close >> brackets... > > ... then I'd prefer them to be used for set

Re: Simple question - end a raw string with a single backslash ?

2020-10-13 Thread Serhiy Storchaka
13.10.20 11:52, Tony Flury via Python-list пише: > I am trying to write a simple expression to build a raw string that ends > in a single backslash. My understanding is that a raw string should > ignore attempts at escaping characters but I get this : > >     >>> a = r'end\' >       File "", line

Re: Simple question - end a raw string with a single backslash ?

2020-10-15 Thread Serhiy Storchaka
15.10.20 22:16, Roland Müller via Python-list пише: > I used the triple single quotes as delimiter: > s = r'''a single quote ', a double quote "''' s > > 'a single quote \', a double quote "' It does not help if the string contains both kinds of triple quotes You have to use triple

Re: Pickle in C does not work

2020-10-20 Thread Serhiy Storchaka
20.10.20 01:28, Marco Sulla пише: > PyObject *d = PyObject_Call((PyObject *)&PyDict_Type, args, NULL); You can use PyDict_New() + PyDict_Merge() to create a dict from your mapping. > but I get: > _pickle.PicklingError: Can't pickle : attribute lookup > frozendict on builtins failed tp_name o

Re: Py_BuildValue vs PyTuple_Pack vs PyTuple_New

2020-10-20 Thread Serhiy Storchaka
20.10.20 18:05, Marco Sulla пише: > I read these three C api functions, They are similar, because they all > construct a tuple[1]. > > IMHO, Py_BuildValue is more simple to use than PyTuple_Pack that is more > simple to use than PyTuple_New. > > Where to use one or the other? What's the relative

Re: Pickle in C does not work

2020-10-20 Thread Serhiy Storchaka
20.10.20 17:12, Marco Sulla пише: > On Tue, 20 Oct 2020 at 16:07, Serhiy Storchaka wrote: >> You can use PyDict_New() + PyDict_Merge() to create a dict from your >> mapping. > Well, yes, I know. I just wrote it for simplicity now. Do you think this is > the problem? I thin

Re: Best way to determine user's screensize?

2020-10-31 Thread Serhiy Storchaka
30.10.20 17:56, flaskee via Python-list пише: > Perhaps a more tactical approach would best to figure > out how to do cross-platform python apps. > > What is the best approach to determining the user's available screensize, > when they open your python application? > > Note that the "desktop" app

Re: constant folding - why not more

2020-11-11 Thread Serhiy Storchaka
11.11.20 02:46, Skip Montanaro пише: > I can think of two reasons. One, this kind of comparison will almost never > appear in production code (maybe in unit tests?). Unlike the C family of > languages, Python doesn't have a macro processor which would give symbolic > names to numeric constants or s

Re: Changing strings in files

2020-11-11 Thread Serhiy Storchaka
10.11.20 22:40, Dennis Lee Bieber пише: > Testing for extension in a list of exclusions would be much faster than > scanning the contents of a file, and the few that do get through would have > to be scanned anyway. Then the simplest method should work: read the first 512 bytes and check if

Re: Changing strings in files

2020-11-11 Thread Serhiy Storchaka
10.11.20 11:07, Manfred Lotz пише: > Perhaps better. I like to use os.scandir this way > > def scantree(path: str) -> Iterator[os.DirEntry[str]]: > """Recursively yield DirEntry objects (no directories) > for a given directory. > """ > for entry in os.scandir(path): >

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Serhiy Storchaka
15.12.20 19:07, Mark Polesky via Python-list пише: > # Running this script > > D = {'a':1} > def get_default(): >     print('Nobody expects this') >     return 0 > print(D.get('a', get_default())) > > # ...generates this output: > > Nobody expects this > 1 > > ### > > Since I'm brand new t

Re: C#3.0 and lambdas

2005-09-21 Thread Serhiy Storchaka
gt; def drawline(p1, p2): > # draw a line from p1[0], p1[1] to p2[0], p2[1] > foo(p1[0], p1[1]) > bar(p2[0], p2[1]) def drawline(p1, p2): # draw a line from p1 to p2 foo(*p1) bar(*p2) -- Serhiy Storchaka -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive list comprehension

2004-12-06 Thread Serhiy Storchaka
hat way did not look pythonic.. I tried print [x for x in y for y in c_vars] and got NameError: name 'y' is not defined. sum(c_vars, []) -- Serhiy Storchaka -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP: Simple Thunks

2005-04-18 Thread Serhiy Storchaka
f.read() t = "no file read yet" for f in with_file('file.txt'): t = f.read() -- Serhiy Storchaka -- http://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 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: 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: 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: 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: 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: 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: 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: "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: "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-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-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 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: 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: 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: [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: 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: 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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: 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: Pyhon 2.x or 3.x, which is faster?

2016-03-08 Thread Serhiy Storchaka
On 08.03.16 03:34, Steven D'Aprano wrote: Chris, I think that's exactly what BartC has done: he has a program that he actually uses, one which processes JPG files. It's written in pure Python, so he's not comparing the quality of C libraries, he's comparing Python versus Python. I haven't looked

Re: Adding Icon To Tkinter Window - Followup

2016-03-09 Thread Serhiy Storchaka
On 06.03.16 18:30, Wildman via Python-list wrote: That does not work... $ ./makexface.py Traceback (most recent call last): File "./makexface.py", line 236, in root.wm_iconphoto(True, img) File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1897, in __getattr__ return getattr(self

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: 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-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: 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: 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: 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

<    1   2   3   >