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: 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: 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: 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: 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: 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: 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: 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: 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: "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-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: 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: 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: [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: 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: 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: 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: 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-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: 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-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: 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: 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: 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: 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-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: 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: 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: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-27 Thread Serhiy Storchaka
On 27.06.12 17:34, Christian Tismer wrote: That's why I was unhappy with py3's missing flexibility. Excessive flexibility is amorphism. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-27 Thread Serhiy Storchaka
On 27.06.12 14:22, Stefan Behnel wrote: For comparison, the revival of the "u" string prefix in Py3.3 is a simple change in the parser grammar that's easy to maintain but that has a huge impact on the Py3 compatibility of code that accepts to drop support for Py2.5 and earlier (as well as Py3.[01

Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-27 Thread Serhiy Storchaka
On 28.06.12 00:14, Terry Reedy wrote: Another prediction: people who code Python without reading the manual, at least not for new features, will learn about 'u' somehow (such as by reading this list) and may do either of the following, both of which are bad. 1. They will confuse themselves by th

Re: code review

2012-06-29 Thread Serhiy Storchaka
The project page is at: http://code.google.com/p/pymud Any information is greatly appreciated. Do you mean https://github.com/benthomasson/pymud, http://pymud.blogspot.com/ or http://sourceforge.net/projects/pymud/ ? -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-06-30 Thread Serhiy Storchaka
On 29.06.12 17:44, Littlefield, Tyler wrote: On 6/29/2012 2:14 AM, Serhiy Storchaka wrote: The project page is at: http://code.google.com/p/pymud Any information is greatly appreciated. Do you mean No, I mean http://code.google.com/p/pymud Then you probably should choose another name

Re: how to use tkinter in python3.2?

2012-07-01 Thread Serhiy Storchaka
On 01.07.12 07:25, contro opinion wrote: i have installed tk ,how to use tkinker in python3.2? You must install tk-dev (or whatever it's called on your system) before Python building (don't forget to rerun configure). -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Serhiy Storchaka
On 15.07.12 19:50, Rick Johnson wrote: We must NEVER present "if" in such confusing manner as ExampleA. ## EXAMPLE C ## py> if bool(money) == True: ... do_something() -- http://mail.python.org/mailman/listinfo/python-list

Re: the meaning of r.......ïŸ

2012-07-26 Thread Serhiy Storchaka
On 23.07.12 18:49, Steven D'Aprano wrote: ≤ for <= ≥ for >= I insist on the use of ⩽ and ⩾ too. -- http://mail.python.org/mailman/listinfo/python-list

Re: conditional running of code portion

2012-08-05 Thread Serhiy Storchaka
On 05.08.12 09:30, Steven D'Aprano wrote: If you are working in a tight loop, you can do this: if VERBOSE_FLAG: for item in loop: print(DEBUG_INFORMATION) do_actual_work(item) else: for item in loop: do_actual_work(item) Or this: if VERBOSE_FLAG: def d

Re: conditional running of code portion

2012-08-06 Thread Serhiy Storchaka
On 06.08.12 20:02, Dieter Maurer wrote: Serhiy Storchaka writes: On 05.08.12 09:30, Steven D'Aprano wrote: If you are working in a tight loop, you can do this: if VERBOSE_FLAG: for item in loop: print(DEBUG_INFORMATION) do_actual_work(item) else: for it

Re: py2c - an open source Python to C/C++ is looking for developers

2012-09-02 Thread Serhiy Storchaka
On 02.09.12 06:15, Ramchandra Apte wrote: It converts to *pure* C/C++ *without* using Python or its API so that it can be the same speed as C/C++ How is it implemented long integers? -- http://mail.python.org/mailman/listinfo/python-list

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

2012-09-02 Thread Serhiy Storchaka
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.strcoll)) There is also locale.strxfrm() which you can use directly: sorted(li, key=locale.strxfrm) Hmm, and with locale.strxfrm Python

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

2012-09-02 Thread Serhiy Storchaka
On 30.08.12 09:55, Steven D'Aprano wrote: And Python's solution uses those: UCS-2, UCS-4, and UTF-8. I see that this misconception widely spread. In fact Python 3.3 uses four kinds of ready strings. * ASCII. All codes <= U+007F. * UCS1. All codes <= U+00FF, at least one code > U+007F. * UCS2

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

2012-09-02 Thread Serhiy Storchaka
On 02.09.12 23:38, Serhiy Storchaka wrote: Indexing is O(0) for any string. Typo. O(1) -- http://mail.python.org/mailman/listinfo/python-list

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

2012-09-03 Thread Serhiy Storchaka
On 03.09.12 04:42, Steven D'Aprano wrote: If you are *seriously* interested in debugging why string code is slower for you, you can start by running the full suite of Python string benchmarks: see the stringbench benchmark in the Tools directory of source installations, or see here: http://hg.py

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

2012-09-03 Thread Serhiy Storchaka
On 03.09.12 04:54, Steven D'Aprano wrote: This means that Python 3.3 will no longer have surrogate pairs. Am I right? As Terry said, basically, yes. Python 3.3 does not need in surrogate pairs, but does not prevent their creation. You can create a surrogate code (U+D800..U+DFFF) intentionall

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

2012-09-03 Thread Serhiy Storchaka
On 03.09.12 09:15, Peter Otten wrote: wxjmfa...@gmail.com wrote: Le dimanche 2 septembre 2012 14:01:18 UTC+2, Serhiy Storchaka a écrit : Hmm, and with locale.strxfrm Python 3.3 20% slower than 3.2. With a memory gain = 0 since my text contains non-latin-1 characters! I can't confirm

Re: The opener parameter of Python 3 open() built-in

2012-09-03 Thread Serhiy Storchaka
On 03.09.12 16:29, Christian Heimes wrote: Am 03.09.2012 14:32, schrieb Marco: Does anyone have an example of utilisation? The opener argument is a new 3.3 feature. For example you can use the feature to implement exclusive creation of a file to avoid symlink attacks. Or you can use new dir_

Re: set and dict iteration

2012-09-03 Thread Serhiy Storchaka
On 27.08.12 22:17, Ian Kelly wrote: May I suggest an alternate approach? Internally tag each set or dict with a "version", which is just a C int. Every time the hash table is modified, increment the version. When an iterator is created, store the current version on the iterator. When the iter

Re: The opener parameter of Python 3 open() built-in

2012-09-04 Thread Serhiy Storchaka
On 04.09.12 04:13, Steven D'Aprano wrote: Why does the open builtin need this added complexity? Why not just call os.open directly? Or for more complex openers, just call the opener directly? What is the rationale for complicating open instead of telling people to just call their opener directly

Re: The opener parameter of Python 3 open() built-in

2012-09-04 Thread Serhiy Storchaka
On 03.09.12 15:32, Marco wrote: Does anyone have an example of utilisation? http://bugs.python.org/issue13424 -- http://mail.python.org/mailman/listinfo/python-list

Re: Division help in python

2012-09-07 Thread Serhiy Storchaka
On 07.09.12 15:53, Ramyasri Dodla wrote: > I am brand new to python. checking over basic stuff. I came across the > problem while doing so. If any body aware of the problem, kindly respond me. > > >>> 5/10 > 0 > >>> - 5/10 > -1 > > The second case also should yield a 'zero' but it is giving a

Re: Is there a unique method in python to unique a list?

2012-09-09 Thread Serhiy Storchaka
On 09.09.12 08:47, Donald Stufft wrote: If you don't need to retain order you can just use a set, Only if elements are hashable. -- http://mail.python.org/mailman/listinfo/python-list

Re: Article on the future of Python

2012-09-27 Thread Serhiy Storchaka
On 27.09.12 09:08, Chris Angelico wrote: LAMP usually means PHP these days. There's a lot of that around. And Cyrillic Р means Ruby. :-P -- http://mail.python.org/mailman/listinfo/python-list

Re: Article on the future of Python

2012-09-27 Thread Serhiy Storchaka
On 27.09.12 12:33, Steven D'Aprano wrote: Nevertheless, I think there is something here. The consequences are nowhere near as dramatic as jmf claims, but it does seem that replace() has taken a serious performance hit. Perhaps it is unavoidable, but perhaps not. If anyone else can confirm simila

Re: Article on the future of Python

2012-09-27 Thread Serhiy Storchaka
On 27.09.12 18:06, Ian Kelly wrote: I understand ISO 8859-15 (Latin-9) to be the preferred Latin character set for French, as it includes the Euro sign as well as a few characters that are not in Latin-1 but are nonetheless infrequently found in French. Even for Latin-9 Python 3.3 can be a litt

Re: portable unicode literals

2012-10-15 Thread Serhiy Storchaka
On 15.10.12 16:05, Ulrich Eckhardt wrote: I need a little nudge in the right direction, as I'm misunderstanding something concerning string literals in Python 2 and 3. In Python 2.7, b'' and '' are byte strings, while u'' is a unicode literal. In Python 3.2, b'' is a byte string and '' is a unico

Re: how to insert random error in a programming

2012-10-15 Thread Serhiy Storchaka
On 15.10.12 17:04, Chris Angelico wrote: > On Tue, Oct 16, 2012 at 12:55 AM, Debashish Saha wrote: >> how to insert random error in a programming? > > how to ask question good in forumming? > http://www.catb.org/~esr/faqs/smart-questions.html > > But here's one way to do it: > > raise > random

Re: bit count or bit set && Python3

2012-10-25 Thread Serhiy Storchaka
Chris Angelico's suggestion: >>> bitcount = bytes(bin(i).count("1") for i in range(256)) >>> t = Timer('sum(number.to_bytes((number.bit_length() + 7) // 8,' ... '"little").translate(bitcount))', ... setup='from __main__ import bitcount; number=2**10001-1') >>> min(t.repeat(number=1, repeat=7)

Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Serhiy Storchaka
On 25.11.12 12:19, kobayashi wrote: Under platform that has fixed pitch font, I want to get a "screen" length of a multibyte string --- sample --- s1 = u"abcdef" s2 = u"あいう" # It has same "screen" length as s1's. print len(s1) # Got 6 print len(s2) # Got 3, but I want get 6. -- Ab

Re: Py 3.3, unicode / upper()

2012-12-27 Thread Serhiy Storchaka
On 19.12.12 17:40, Chris Angelico wrote: Interestingly, IDLE on my Windows box can't handle the bolded characters very well... s="\U0001d407\U0001d41e\U0001d425\U0001d425\U0001d428, \U0001d430\U0001d428\U0001d42b\U0001d425\U0001d41d!" print(s) Traceback (most recent call last): File "", li

Re: difference between random module in python 2.6 and 3.2?

2012-02-07 Thread Serhiy Storchaka
07.02.12 00:06, Matej Cepl написав(ла): > return seq[int(random.random() * len(seq))] > > doesn't seem like something so terrible (and maintenance intense). :) _choice('abc') returns 'a' with probability P('a') = 1501199875790165/4503599627370496 = 1/3 - 1/13510798882111488 and 'b' with probabi

Re: Cycle around a sequence

2012-02-09 Thread Serhiy Storchaka
08.02.12 22:15, Terry Reedy написав(ла): To make a repeating rotator is only a slight adjustment: k = n - len(seq) while True: i = k while i < n: yield seq[i] i += 1 for i in range(n, len(seq)): yield seq[i] while True: fo

Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-21 Thread Serhiy Storchaka
18.02.12 20:58, SherjilOzair написав(ла): Has it been considered to add shell features to python, such that it can be used as a default shell, as a replacement for bash, etc. I'm sure everyone would agree that doing this would make the terminal very powerful. What are your views on this? Lo

Re: PyWart: Language missing maximum constant of numeric types!

2012-02-25 Thread Serhiy Storchaka
25.02.12 02:37, MRAB написав(ла): We already have arbitrarily long ints, so there could be a special infinite int singleton (actually, 2 of them, one positive, the other negative). float('inf') and float('-inf'). -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is readable

2012-03-15 Thread Serhiy Storchaka
15.03.12 16:19, Kiuhnm написав(ла): > Ok, so they're mandatory, but I was mainly talking of design. Why are they > needed? http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Why not use juxtaposition to indicate function application

2012-03-16 Thread Serhiy Storchaka
16.03.12 18:45, Steven D'Aprano написав(ла): If f is a function which normally takes (for the sake of the argument) one argument, then f would call the function with no arguments (which may return a curried function, or may apply default arguments, or perhaps raise an exception). So how would you

Re: Why not use juxtaposition to indicate function application

2012-03-16 Thread Serhiy Storchaka
16.03.12 23:02, Chris Rebert написав(ла): On Fri, Mar 16, 2012 at 1:57 PM, Serhiy Storchaka wrote: lambda:f Doesn't help; wouldn't the lambda be implicitly called? No, the lambda is only for declaration. I prefer to use braces for lambda syntax, it will be fine with '

Re: "convert" string to bytes without changing data (encoding)

2012-03-30 Thread Serhiy Storchaka
28.03.12 21:13, Heiko Wundram написав(ла): Reading from stdin/a file gets you bytes, and not a string, because Python cannot automagically guess what format the input is in. In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for access to byte stream. And reading from file

Re: escaping/encoding/formatting in python

2012-04-06 Thread Serhiy Storchaka
06.04.12 08:28, rusi написав(ла): All this mess would vanish if the string-literal-starter and ender were different. [You dont need to escape a open-paren in a lisp sexp] But you need to escape an escape symbol. -- http://mail.python.org/mailman/listinfo/python-list

Re: escaping/encoding/formatting in python

2012-04-06 Thread Serhiy Storchaka
06.04.12 16:22, rusi написав(ла): Yes. I hand it to you that I missed the case of explicitly unbalanced strings. But are not such cases rare? No, unfortunately. }:-( For example code such as: print '"' print str(something) print '"' could better be written as print '"%s"' % str(something)

Re: escaping

2012-04-16 Thread Serhiy Storchaka
16.04.12 00:07, Kiuhnm написав(ла): path = path.replace('\\', '') If you think that it is too complicated: path = re.sub('', '', path) -- http://mail.python.org/mailman/listinfo/python-list

Re: escaping

2012-04-17 Thread Serhiy Storchaka
This was the original intention, i.e. 'format' preferred over '%' but even the core developers have backtracked on this issue. If I could remember the thread it was on I'd give you a reference, but I haven't the faintest idea as to which mailing list it was on. I'm certain that other subscribers w

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Serhiy Storchaka
[] is [] False id([]) == id([]) True >>> id([1]) == id([2]) True ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-04-29 Thread Serhiy Storchaka
29.04.12 19:05, Peter Pearson написав(ла): Hey, guys, am I the only one here who can't even guess what this code does? When did Python become so obscure? This isn't Python at all. It's Ruby. -- http://mail.python.org/mailman/listinfo/python-list

Re: specify end of line character for readline

2012-05-15 Thread Serhiy Storchaka
On 15.05.12 09:29, Ian Kelly wrote: In Python 3 you can pass the argument newline='\r\n' to the open function when you open the file. I don't know of anything comparable in Python 2. io.open supports "newline" argument. -- http://mail.python.org/mailman/listinfo/python-list

Re: python3 raw strings and \u escapes

2012-05-30 Thread Serhiy Storchaka
On 30.05.12 14:54, Thomas Rachel wrote: There is a 3rd one: use r'[ ' + '\u3000' + ']'. Not very nice to read, but should do the trick... Or r'[ %s]' % ('\u3000',). -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.3.0a4, please add ru'...'

2012-06-17 Thread Serhiy Storchaka
On 16.06.12 20:36, jmfauth wrote: u'a' 'a' ur'a' 'a' Please, never use u'' in new Python 3 code. This is only for compatibility with Python 2. And Python 2 does not support ru''. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python programming language vulnerabilities

2017-09-10 Thread Serhiy Storchaka
08.09.17 20:34, Stephen Michell пише: I chair ISO/IEC/JTC1/SC22/WG23 Programming Language Vulnerabilities. We publish an international technical report, ISO IEC TR 24772 Guide to avoiding programming language vulnerabilities through language selection use. Annex D in this document addresses vu

Re: Standard for dict-contants with duplicate keys?

2017-09-15 Thread Serhiy Storchaka
16.09.17 00:45, Terry Reedy пише: On 9/15/2017 3:36 PM, Tim Chase wrote: Looking through docs, I was unable to tease out whether there's a prescribed behavior for the results of defining a dictionary with the same keys multiple times d = { "a": 0, "a": 1, "a": 2, }

Re: Performance of map vs starmap.

2017-11-01 Thread Serhiy Storchaka
30.10.17 12:10, Kirill Balunov пише: Sometime ago I asked this question at SO [1], and among the responses received was paragraph: - `zip` re-uses the returned `tuple` if it has a reference count of 1 when the `__next__` call is made. - `map` build a new `tuple` that is passed to the mapped

Re: A use-case for for...else with no break

2017-11-03 Thread Serhiy Storchaka
02.11.17 12:10, Steve D'Aprano пише: Occasionally it is useful to loop over a bunch of stuff in the interactive interpreter, printing them as you go on a single line: for x in something(): print(x, end='') If you do that, the prompt overwrites your output, and you get a mess: py> for x i

Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-25 Thread Serhiy Storchaka
26.11.17 01:59, Terry Reedy пише: On 11/25/2017 5:12 PM, Chris Angelico wrote: On Sun, Nov 26, 2017 at 9:05 AM,  wrote: Hi, my goal is to obtain an interpreter that internally uses UCS-2. Such a simple code should print 65535:    import sys    print sys.maxunicode This is enabled in Windows,

Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-29 Thread Serhiy Storchaka
26.11.17 21:46, wojtek.m...@gmail.com пише: On Sunday, November 26, 2017 at 1:00:19 AM UTC+1, Terry Reedy wrote: You must be trying to compile 2.7. There may be Linux distributions that compile this way. You're right, I need 2.7. Any hint which distro has got these settings? UCS-2 is used b

Re: Why does __ne__ exist?

2018-01-07 Thread Serhiy Storchaka
07.01.18 22:33, Chris Angelico пише: On Mon, Jan 8, 2018 at 7:13 AM, Thomas Jollans wrote: On 07/01/18 20:55, Chris Angelico wrote: Under what circumstances would you want "x != y" to be different from "not (x == y)" ? In numpy, __eq__ and __ne__ do not, in general, return bools. a = np.ar

Re: Generating SVG from turtle graphics

2018-01-14 Thread Serhiy Storchaka
11.01.18 13:03, Steven D'Aprano пише: I'd like to draw something with turtle, then generate a SVG file from it. Is this possible? If not, is there something I can do which lets me plot lines, shapes and curves and output to SVG? You can translate the following Tcl/Tk recipe to Python/Tkinter:

Re: Is this the right way to write a codec error handler?

2018-01-20 Thread Serhiy Storchaka
20.01.18 10:32, Steven D'Aprano пише: I want an error handler that falls back on Latin-1 for anything which cannot be decoded. Is this the right way to write it? def latin1_fallback(exception): assert isinstance(exception, UnicodeError) start, end = exception.start, exception.end

Re: Why no '|' operator for dict?

2018-02-05 Thread Serhiy Storchaka
05.02.18 10:14, Ian Kelly пише: On Mon, Feb 5, 2018 at 12:35 AM, Frank Millman wrote: So I have 2 questions - 1. Is there any particular reason why '|' is not supported? '|' is the set union operation, roughly equivalent to the set.union method. Dicts don't have a union operation. If they di

Re: [RELEASED] Python 3.4.8 and Python 3.5.5 are now available

2018-02-10 Thread Serhiy Storchaka
05.02.18 02:35, Larry Hastings пише: On behalf of the Python development community, I'm happy to announce the availability of Python 3.4.8 and Python 3.5.5. Both Python 3.4 and 3.5 are in "security fixes only" mode.  Both versions only accept security fixes, not conventional bug fixes, and bo

Re: How to make Python run as fast (or faster) than Julia

2018-02-22 Thread Serhiy Storchaka
22.02.18 14:29, Chris Angelico пише: Not overly misleading; the point of it is to show how trivially easy it is to memoize a function in Python. For a fair comparison, I'd like to see the equivalent Julia code: the function, unchanged, with something around the outside of it to manage caching and

Re: RFC: Proposal: Deterministic Object Destruction

2018-02-28 Thread Serhiy Storchaka
01.03.18 04:46, Rick Johnson пише: On Wednesday, February 28, 2018 at 5:02:17 PM UTC-6, Chris Angelico wrote: Here's one example: reference cycles. When do they get detected? Taking a really simple situation: class Foo: def __init__(self): self.self = self *shudders* Can you p

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread Serhiy Storchaka
02.03.18 02:49, Rick Johnson пише: This is true, but it does not answer the challenge directly because function CRs are a consequence of Python _internals_ *NOT* consequences of a custom class written by a programmer which references itself _explicitly_. This doesn't matter. You question was "C

Re: Why assert is not a function?

2021-03-11 Thread Serhiy Storchaka
03.03.21 01:24, Chris Angelico пише: > On Wed, Mar 3, 2021 at 10:22 AM Mirko via Python-list > wrote: >> >> Am 02.03.2021 um 23:09 schrieb Stestagg: >>> Ignoring the question about this feature being particularly useful, it >> >> It is useful because "assert" is primarily (if not purely and >> exc

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Serhiy Storchaka
01.03.21 23:59, Cameron Simpson пише: > On 28Feb2021 23:47, Alan Gauld wrote: >> On 28/02/2021 00:17, Cameron Simpson wrote: >>> BUT... It also has a __iter__ value, which like any Box iterates over >>> the subboxes. For MDAT that is implemented like this: >>> >>> def __iter__(self): >>>

Re: Why assert is not a function?

2021-03-11 Thread Serhiy Storchaka
11.03.21 20:31, Chris Angelico пише: >> assert(expensive_computation()) > > Do you have any asserts like that, or is that a purely theoretical > complaint? I have never once seen anything that costly - usually it'll > be something like checking a length (and this isn't C's strlen, since > Python c

Re: Immutable view classes - inherit from dict or from Mapping?

2021-04-13 Thread Serhiy Storchaka
12.04.21 19:01, Andreas R Maier пише: > Hi, > I have written some classes that represent immutable views on collections > (see "immutable-views" package on Pypi). > > Currently, these view classes inherit from the abstract collection classes > such as Mapping, Sequence, Set. However, they implem

Re: Immutable view classes - inherit from dict or from Mapping?

2021-04-13 Thread Serhiy Storchaka
13.04.21 15:47, Peter Otten пише: > As to the | operator, maybe it could be added to Mapping? The | operator returns a new instance, but constructor is not a part of the Mapping interface. You cannot make a general implementation, and making __or__ an abstract method will break all existing Mappin

Re: Defining a Python enum in a C extension - am I doing this right?

2021-07-30 Thread Serhiy Storchaka
23.07.21 11:20, Bartosz Golaszewski пише: > I'm working on a Python C extension and I would like to expose a > custom enum (as in: a class inheriting from enum.Enum) that would be > entirely defined in C. I think that it would be much easier to define it in Python, and then either import a Python

Re: Defining a Python enum in a C extension - am I doing this right?

2021-08-06 Thread Serhiy Storchaka
03.08.21 13:03, Bartosz Golaszewski пише: > Just a follow-up: this is how I did it eventually: I think it can be simpler. 1. No need to create the __main__ module. You can just create a dict. If some attributes are required (e.g. __name__) it is easy to set them in the Python code (__name__ = 'py

Re: How to support annotations for a custom type in a C extension?

2021-09-18 Thread Serhiy Storchaka
18.09.21 03:54, MRAB пише: > static PyMethodDef customdict_methods[] = { > ... >     {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_CLASS | > METH_O | METH_COEXIST, PyDoc_STR("See PEP 585")}, > ... > }; > > > Note the flags: METH_CLASS says that it's a class method and > METH_COEXIST sa

Re: How to support annotations for a custom type in a C extension?

2021-09-18 Thread Serhiy Storchaka
18.09.21 09:40, Marco Sulla пише: > Ooook. I have a question. Why is this code not present in > dictobject.c? Where are the dict annotations implemented? In dictobject.c. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to support annotations for a custom type in a C extension?

2021-09-19 Thread Serhiy Storchaka
19.09.21 05:59, MRAB пише: > On 2021-09-18 16:09, Serhiy Storchaka wrote: >> "(PyCFunction)" is redundant, Py_GenericAlias already has the right >> type. Overuse of casting to PyCFunction can hide actual bugs. >> > I borrowed that from listobject.c, which

  1   2   3   >