Re: Documentaion of dunder methods

2015-05-26 Thread Steven D'Aprano
On Tuesday 26 May 2015 14:34, Ian Kelly wrote: >> Apart from PEP 8, is this documented anywhere in the official >> documentation? If so, I have been unable to find it. > > https://docs.python.org/3/reference/lexical_analysis.html#reserved- classes-of-identifiers That's the bunny! Thanks for th

Re: should "self" be changed?

2015-05-26 Thread Steven D'Aprano
nice solution to the problem, really. It doesn't > become PERLish because you've made it into a genuine operator -- "self" > was always a non-variable that looked like a variable and hence created an > itch that couldn't be scratched. That is completely wrong. se

Re: should "self" be changed?

2015-05-26 Thread Steven D'Aprano
On Wednesday 27 May 2015 05:46, Marko Rauhamaa wrote: > Python's practice works. However, a small problem is presented by nested > classes: > > class Connection: > def __init__(self): > class Idle: > def signal_start(self): > # how to re

Re: should "self" be changed?

2015-05-26 Thread Steven D'Aprano
On Wednesday 27 May 2015 06:45, Mark Lawrence wrote: > Apart from breaking all the tools that rely on "self" being spelt "self" > this looks like an excellent idea. Tools which rely on self being spelled "self" are already broken. It's a convention, nothing more, and there are various good reaso

Re: should "self" be changed?

2015-05-26 Thread Steven D'Aprano
On Wednesday 27 May 2015 14:39, Ben Finney wrote: > zipher writes: > >> Arrgh. Sorry, that was meant privately... > > I'm glad we saw it publicly, so that we get more of an idea how you > treat people. > > That kind of homophobic slur is inappropriate from anyone in this > community. Kindly c

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

2015-05-27 Thread Steven D'Aprano
t;", line 1, in UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 11: invalid continuation byte py> b.decode("utf-8", errors="replace") # lossy, but works 'My Russian �� name' py> s = b.decode("utf-8", errors="surrogateescape") # magic! py> s 'My Russian \udce4\udcea name' It round-trips as well: py> s.encode("utf-8", errors="surrogateescape") == b True Converting this back to Python 2.7 is left as an exercise for the reader. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: assertRaises() help

2015-05-27 Thread Steven D'Aprano
e assertRaises method from the standard library unittest module. If it is some custom method written by you, or part of pandas, then I have no idea if you are doing something wrong. But I expect that the real problem is that you are mistaken to believe that to_datetime('2015-02-29', coerc

Re: SyntaxError on progress module

2015-05-27 Thread Steven D'Aprano
oops, best of 3: 2.6 usec per loop [steve@ando ~]$ python3.3 -m timeit "i='1'; L=sorted([30,20,50,10,40]); L[int(i)+1]" 10 loops, best of 3: 2.29 usec per loop which is a 12% speed up. So the lesson is, micro-benchmarks are not a good guide to whole-application benchmarks. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Returning a custom file object (Python 3)

2015-05-27 Thread Steven D'Aprano
I'd like to return a custom file object, say my own subclass. I can easily subclass the file object: from io import TextIOWrapper class MyFile(TextIOWrapper): pass but how do I tell open() to use MyFile? Answers for Python 3, thanks. -- Steven -- https://mail.python.org/ma

Re: Returning a custom file object (Python 3)

2015-05-27 Thread Steven D'Aprano
On Thursday 28 May 2015 15:56, Gary Herron wrote: > On 05/27/2015 10:29 PM, Marko Rauhamaa wrote: >> Ben Finney : >> >>> It seems the existing ‘open’ implementation doesn't allow you to >>> override the type of object returned. >> The question is, can you assign to the builtin namespace. I'm guess

Re: Returning a custom file object (Python 3)

2015-05-28 Thread Steven D'Aprano
On Thursday 28 May 2015 15:49, Chris Angelico wrote: > ... but I don't think replacing all of open() is what Steven has in > mind; it's a function that does a lot of work, most of which is what's > wanted. Correct. If I wanted to replace open(), I would have just shadowe

Re: should "self" be changed?

2015-05-28 Thread Steven D'Aprano
classes are themselves values, there is no reason why a class *must* be instantiated, particularly if you're only using a single instance of the class. Anyone ever come across a named design pattern that involves using classes directly without instantiating them? I'm basically looking for a less inelegant term for "instanceless class" -- not so much a singleton as a zeroton. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: should "self" be changed?

2015-05-28 Thread Steven D'Aprano
On Fri, 29 May 2015 12:00 pm, Steven D'Aprano wrote: > I haven't studied this in close detail, but first impressions is that this > is not well-written Python code. The obvious problems that come to mind: Well, first impressions can be misleading... I wrote the above, thinking

Re: Logic problem: need better logic for desired thruth table.

2015-05-28 Thread Steven D'Aprano
ve English speaker, but "thruth" sounds like the name of a bird (thrush) spoken with a lisp. > Since there are 2 inputs, this means 4 possible outputs, which means 2 to > the power of 4 different thruth tables possible, which is indeed 16. > > Perhaps you hav

Re: python

2015-05-29 Thread Steven D'Aprano
ere you got it from, and the *exact* error message. Then perhaps I can stop relying on my crystal ball and give you some more useful advice. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Steven D'Aprano
State machines. The structure of URLs (they're more than just "http://blahblah.com";). Anything to do with HTTP (client or server). Commandline argument processing (argparse, optparse, etc.) Some of the intermediate topics start at an intermediate level, but can go on to include more

Re: Minus operator versus unary minus

2015-05-30 Thread Steven D'Aprano
advantage over the obvious > > result[elem] = -count > > ? py> class Thingy: ... def __neg__(self): ... return [1, 2, 3, 4] ... py> -Thingy() [1, 2, 3, 4] py> 0 - Thingy() Traceback (most recent call last): File "", line 1, in TypeError: unsupporte

Re: Creating a reliable sandboxed Python environment

2015-05-30 Thread Steven D'Aprano
security/advisories/mfsa2013-53/ Yes, I can see why you think Javascript is securely sandboxed... *wink* -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Creating a reliable sandboxed Python environment

2015-05-30 Thread Steven D'Aprano
On Sat, 30 May 2015 09:24 pm, Laura Creighton wrote: > In a message of Sat, 30 May 2015 19:00:14 +1000, "Steven D'Aprano" writes: >>I wouldn't have imagined that the claim "it's easier to secure a small >>language with a few features than a big languag

Re: Everything is an object in python - object class and type class

2015-05-31 Thread Steven D'Aprano
> As can be attested by using type() function as below : [...] > From my understanding this means all of this are instances of the class > type. which means the class type was used to create this instances. Correct. > Now if i look at the __bases__ of all this objects i get : > >>>&

Re: Everything is an object in python - object class and type class

2015-05-31 Thread Steven D'Aprano
n does. Ruby, which is otherwise very similar to Python, does not: In Python, everything is an object, and we have metaclasses. In Ruby, everything is an object, but we don't have metaclasses. http://ruby.dzone.com/news/ruby-doesnt-have-meta-classes -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Everything is an object in python - object class and type class

2015-05-31 Thread Steven D'Aprano
On Mon, 1 Jun 2015 01:09 pm, Eddilbert Macharia wrote: > Thank you for you responses guys. > > So what I'm getting from above responses, everything in python is an > object because the are instance of the metaclass type (from Steven > response) and also because they are sub

Re: A simple print cannot run in Python Shell

2015-06-01 Thread Steven D'Aprano
On Monday 01 June 2015 17:50, fl wrote: > Hi, > > When I try the following (They are saved in a main.py file) > > #!/usr/bin/python > print r'C:\\nowhere' Aside: Don't use raw strings for file names. They aren't intended for file names, and while they will *usually* work, some day you will try

Zero [was Re: What is considered an "advanced" topic in Python?]

2015-06-01 Thread Steven D'Aprano
On Mon, 1 Jun 2015 07:36 pm, Marko Rauhamaa wrote: > However, I constantly run into engineers who don't understand what > zero means. Okay, I'll bite. What does zero mean, and how do engineers misunderstand it? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Religion [was Re: Everything is an object in python - object class and type class]

2015-06-01 Thread Steven D'Aprano
On Tuesday 02 June 2015 15:01, Rustom Mody wrote: > eg Would it make sense to you if you were told that there are widespread > religions like Buddhism that are agnostic or Jainism that are strictly > atheistic? No of course it wouldn't make sense. But nothing to do with religion, spirituality an

Re: Everything is an object in python - object class and type class

2015-06-01 Thread Steven D'Aprano
On Tuesday 02 June 2015 11:15, TheDoctor wrote: > A type is not an object. Yes it is. py> isinstance(type, object) True py> isinstance(int, object) True > You see it as one, because you are MENTALLY > lexing your own code on the screen. No, I see it as one, because it is one. > But python d

Re: Everything is an object in python - object class and type class

2015-06-01 Thread Steven D'Aprano
On Tuesday 02 June 2015 11:02, TheDoctor wrote: > On Monday, June 1, 2015 at 7:33:11 PM UTC-5, Chris Angelico wrote: >> On Tue, Jun 2, 2015 at 10:24 AM, TheDoctor >> wrote: >> > A type is not an object in the same way an instantiated type is an >> > object -- anymore than a blueprint for a buildi

Re: Everything is an object in python - object class and type class

2015-06-02 Thread Steven D'Aprano
On Tuesday 02 June 2015 10:24, TheDoctor wrote: > A type is not an object in the same way an instantiated type is an object > -- anymore than a blueprint for a building is the building itself. Nobody says that blueprints are *buildings*. But buildings are not the only kind of object that exists.

Re: Language design

2015-06-02 Thread Steven D'Aprano
On Tuesday 02 June 2015 10:10, TheDoctor wrote: > On Friday, September 13, 2013 at 12:08:04 AM UTC-5, Steven D'Aprano wrote: Mark, you are digging up a conversation from nearly two years ago. Seriously? >> It makes no difference whether I write: >> >> atoms ->

Re: What use of string module?

2015-06-02 Thread Steven D'Aprano
On Tuesday 02 June 2015 12:14, fl wrote: > Hi, > > I read the online help about string. It lists string constants, string > formatting, template strings and string functions. After reading these, > I am still puzzled about how to use the string module. > > Could you show me a few example about t

Re: Language design

2015-06-02 Thread Steven D'Aprano
On Tuesday 02 June 2015 07:45, TheDoctor wrote: > On Wednesday, September 11, 2013 at 6:40:22 PM UTC-5, Steven D'Aprano > wrote: >> On Wed, 11 Sep 2013 14:30:54 -0700, Mark Janssen wrote: >> >> > 1) It tried to make Object the parent of every class. >>

Re: Everything is an object in python - object class and type class

2015-06-02 Thread Steven D'Aprano
on 1.5: - everything is an object [the general concept] - nothing is an instance of the class called "object" In Python 2: - everything is an object [the general concept] - some things, but not all things, are instances of the class called "object" In Python 3: - everything is an object [the general concept] - everything is an instance of the class called "object" -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Everything is an object in python - object class and type class

2015-06-02 Thread Steven D'Aprano
On Tue, 2 Jun 2015 09:40 pm, Rustom Mody wrote: > On Tuesday, June 2, 2015 at 4:57:31 PM UTC+5:30, Steven D'Aprano wrote: >> On Tue, 2 Jun 2015 08:36 pm, Eddilbert Macharia wrote: [...] >> > *** The instance of class type is a data type an instance of class >> >

Re: How to access the low digits of a list

2015-06-02 Thread Steven D'Aprano
] > Then, > I can use a -1 step to get the last two digits. Or, you may have much > better ways to do that. Python is really too versatile I feel. Last two digits of a string: mystring = "123456" mystring[-2:] -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: should "self" be changed?

2015-06-02 Thread Steven D'Aprano
On Fri, 29 May 2015 12:00 pm, Steven D'Aprano wrote: [...] > in a language where classes are > themselves values, there is no reason why a class must be instantiated, > particularly if you're only using a single instance of the class. Anyone > ever come across a nam

Re: Everything is an object in python - object class and type class

2015-06-02 Thread Steven D'Aprano
On Tue, 2 Jun 2015 10:49 pm, BartC wrote: > On 02/06/2015 12:27, Steven D'Aprano wrote: > >> "Object" has a general meaning in computer science and programming, it is >> a compound data structure that is explicitly linked to a type which >> provides f

Re: should "self" be changed?

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 03:19, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Fri, 29 May 2015 12:00 pm, Steven D'Aprano wrote: >> >> [...] >>> in a language where classes are >>> themselves values, there is no reason why a class must be i

Re: Everything is an object in python - object class and type class

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 03:59, BartC wrote: > Javascript primitives include Number and String. > > What does Python allow to be done with its Number (int, etc) and String > types that can't be done with their Javascript counterparts, that makes > /them/ objects? That's a good question, and I'm

Re: Everything is an object in python - object class and type class

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 08:49, Dr. Bigcock wrote: > You need classes for objects. Anything else, and you're confusing > yourself. Not quite. https://en.wikipedia.org/wiki/Prototype-based_programming -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: Please help on this sorted function

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 06:42, Joonas Liik wrote: > my_dict = {1: 'D', 2: 'B', 3: 'A', 4: 'E', 5: 'B'} > > # dict.items() returns an iterator that returns pairs of (key, value) > # pairs the key argument to sorted tells sorted what to sort by, > operator.itemgetter is a factory function , itemg

Re: Everything is an object in python - object class and type class

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 08:33, Marko Rauhamaa wrote: > Grant Edwards : > >> On 2015-06-02, Ian Kelly wrote: >>> Accepting for the sake of argument that "something to be subclassed" >>> is a reasonable definition of object, >> >> Huh? You can't subclass an object. You can subclass a Class. >

Re: Everything is an object in python - object class and type class

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 05:31, Jon Ribbens wrote: > On 2015-06-02, Dr. Bigcock wrote: >> On Tuesday, June 2, 2015 at 1:49:03 PM UTC-5, Jon Ribbens wrote: >>> On 2015-06-02, Dr. Bigcock wrote: >>> > It doesn't really do anything. No one uses integers as objects. >>> > (Any dissenters?) >>> >>

Re: fork/exec & close file descriptors

2015-06-03 Thread Steven D'Aprano
ing a file is a clear and obvious fault that should be reported. But in the scenario that Marko is describing, I'm not so sure that is the case. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: How to access the low digits of a list

2015-06-04 Thread Steven D'Aprano
ver, allow slicing to extend beyond the first and last indexes without error. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Argument Presence Checking via Identity or Boolean Operation?

2015-06-04 Thread Steven D'Aprano
None, 0, 0.0, [], (), {}, False, etc. to trigger the myClass() behaviour? Then the right answer is to use a short-circuit boolean. (And you probably should use False as the default for arg2.) Do you want *only* None to trigger the myClass() behavious? Then the right answer is to use the identity check.

Re: Regular Expression

2015-06-04 Thread Steven D'Aprano
_string1_string2", 1) ['', '_string1_string2'] > How to fix this issue? Again, this is a small problem, and regular expressions are not needed. Just strip the underscores off the left, then split: py> s = "__string1_string2" py> s.lstrip("_").split("_") ['string1', 'string2'] -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
"Joe, I think our son might be lost in the woods" "Don't worry, I have his social security number" http://effbot.org/zone/call-by-object.htm This may also be helpful: http://import-that.dreamwidth.org/1130.html -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Everything is an object in python - object class and type class

2015-06-04 Thread Steven D'Aprano
lse Surprise! If you can come up with a sensible justification for why Boolean(false) is falsey, but new Boolean(false) is truthy, you're a better man than me. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
;ve never come across it. > Not > that the pointlessness of an argument is going to slow down a > thread... Clear thinking is pointless? Well, that explains how you can claim that Python is pass by reference immediately after Marko demonstrates that it cannot possibly be pass by reference *wink* -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Parser needed.

2015-06-04 Thread Steven D'Aprano
ight be hard to traverse in sequence... Use an ordered dict: from collections import OrderedDict -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 03:26 am, [email protected] wrote: > On Thu, Jun 4, 2015, at 09:47, Steven D'Aprano wrote: >> In other words, according to this Java philosophy, following `x = 23`, >> the >> value of x is not 23 like any sane person would expect, but some >&g

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 03:30 am, [email protected] wrote: > On Thu, Jun 4, 2015, at 13:11, Steven D'Aprano wrote: >> You need at least one more test to prove pass by value: you need to >> demonstrate that the value bound to y is copied when passed to the >> function.

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 03:30 am, Marko Rauhamaa wrote: > Steven D'Aprano : > >>> On 2015-06-04, Marko Rauhamaa wrote: >>>> If it prints 1, it's pass by value. If it prints 3, it's pass by >>>> reference. >> >> Wrong. Why do you [

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 04:17 am, Alain Ketterlin wrote: > Steven D'Aprano writes: > > [...] >> But you still find a few people here and there who have been exposed to >> Java foolishness, and will argue that Python is "pass by value, where the >> value is an

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
reason that many people seem to confused about > Python's argument passing is that they don't understand what > assignment does. I don't see the connection, but do explain, I'm interested. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 06:52 am, BartC wrote: > On 04/06/2015 18:11, Steven D'Aprano wrote: > >>If there is >> any language where assignment uses one style and argument passing always >> uses another, I've never come across it. > > My language does that. I&#x

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 11:40 am, Mark Lawrence wrote: > On 05/06/2015 01:16, BartC wrote: >> On 05/06/2015 00:13, Steven D'Aprano wrote: >>> On Fri, 5 Jun 2015 06:52 am, BartC wrote: >>> >>>> On 04/06/2015 18:11, Steven D'Aprano wrote: >>>&g

Re: Can Python function return multiple data?

2015-06-04 Thread Steven D'Aprano
On Fri, 5 Jun 2015 08:59 am, [email protected] wrote: > On Thu, Jun 4, 2015, at 18:16, Steven D'Aprano wrote: >> Remember, you've tried to claim that it is not invisible or unknown, so >> you >> must be able to see and know that value. So what is the value?

Re: Can Python function return multiple data?

2015-06-05 Thread Steven D'Aprano
t I know) in this wobbly world is to hold > to two concepts: > 1. The abstract platonic immutable type -- good to think with, supported > by python in only a half-assed way > > 2. The 'maybe-reference-maybe-value' actual mess > > And to keep dancing between these All the words are in English, but I have no idea what you are trying to say here. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: So what's happening here?

2015-06-05 Thread Steven D'Aprano
n object, and returns that. When you do it again, numpy goes through the same process, and returns a second object with the same numeric value. Hence, the IDs are different. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Sorting in reverse is not the same as sorting then reversing

2015-06-05 Thread Steven D'Aprano
=str.lower) py> b.reverse() py> a ['fox', 'dog', 'DOG', 'cat', 'ape'] py> b ['fox', 'DOG', 'dog', 'cat', 'ape'] Sorting in reverse keeps the initial order of any equal elements unchanged. Sorting, then reversing, reverses them. (Thanks to Tim Peters for the tip.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-05 Thread Steven D'Aprano
use of the word > 'intelligent' > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD618.html Nice rant, but as is typical of so many rants by Dijkstra, it's overflowing with smugness at his own cleverness, and very light on actual reasoning or sense. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: [RELEASED] Python 3.5.0b2 is now available

2015-06-06 Thread Steven D'Aprano
using a ^ caret. That may give you some hint as to what the issue is. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-06 Thread Steven D'Aprano
. He is having trouble with *basic* Python questions, like returning multiple items from a single function call. Showing him advanced techniques like generators, especially when the example you show is wrong, will just confuse him more. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-06 Thread Steven D'Aprano
you will have a brand new fresh generator. Now call list(x), the list function will iterate over the items yielded, and assemble them into a list or tuple. "a*2" and "a*3" will be printed, and the list will be [10, 15]. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-06 Thread Steven D'Aprano
them), it is still the same list. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can Python function return multiple data?

2015-06-06 Thread Steven D'Aprano
On Sat, 6 Jun 2015 03:32 pm, Rustom Mody wrote: > On Saturday, June 6, 2015 at 10:20:49 AM UTC+5:30, Steven D'Aprano wrote: >> On Sat, 6 Jun 2015 01:20 pm, Rustom Mody wrote: >> > As a parallel here is Dijkstra making fun of AI-ers use of the word >> > 'intell

Re: Function to show time to execute another function

2015-06-07 Thread Steven D'Aprano
dom numbers, affected more by the other ten thousand processes running on your computer than by the Python code itself. In that case, you should learn how to use the timeit module. It's a little complex, but worth it for timing small code snippets. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to show time to execute another function

2015-06-07 Thread Steven D'Aprano
: ... x = 12 ... y = x/3 ... elapsed time is very small; consider using timeit.Timer for micro-timings of small code snippets time taken: 0.000114 seconds The first run was over 160 times slower than the second run. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to show time to execute another function

2015-06-07 Thread Steven D'Aprano
led to ignore them. You're just pissed off because he rightly noted that your answer to his question *doesn't solve his problem*. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Ah Python, you have spoiled me for all other languages

2015-06-07 Thread Steven D'Aprano
On Sun, 7 Jun 2015 06:21 pm, Thomas 'PointedEars' Lahn wrote: > Ned Batchelder wrote: > >> On Saturday, May 23, 2015 at 9:01:29 AM UTC-4, Steven D'Aprano wrote: >>> On Sat, 23 May 2015 10:33 pm, Thomas 'PointedEars' Lahn wrote: >>> > If

Re: Is it a newsgroup or a list?

2015-06-07 Thread Steven D'Aprano
t. Apart from some spam, which gets filtered from the mailing list but not the newsgroup, or vise versa, you can post to the mailing list or the newsgroup and the message will show up on both. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing random

2015-06-07 Thread Steven D'Aprano
7-1 before it repeats. Its randomness properties are very good indeed. (Although of course that isn't to say that there aren't bugs in the Python implementation.) Mersenne Twister is is not suitable for cryptographic work, but apart from that, it is pretty much as indistinguishable from random as any deterministic computer program can be. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing random

2015-06-07 Thread Steven D'Aprano
On Sun, 7 Jun 2015 10:52 pm, Steven D'Aprano wrote: > The median is unchanged, the mean shifts slightly higher, and the standard > deviation increases. But as you can see, these are not particularly > powerful tests of randomness: only the mode shows an obvious deviation > from u

Re: Find in ipython3

2015-06-07 Thread Steven D'Aprano
o you mean it's free? You mean its pirated?") For many of those people, they've already gone through the process to get Python and the standard library approved. It might be part of the school's SOE, or already installed on the corporate server, for example, so they can use the standard library easily enough, but nothing else. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Ah Python, you have spoiled me for all other languages

2015-06-07 Thread Steven D'Aprano
On Sun, 7 Jun 2015 10:08 pm, Chris Angelico wrote: > On Sun, Jun 7, 2015 at 9:42 PM, Steven D'Aprano > wrote: >> My opinion is that a programming language like Python or ECMAScript >> should operate on *code points*. If we want to call them "characters" >>

Re: Ah Python, you have spoiled me for all other languages

2015-06-07 Thread Steven D'Aprano
On Mon, 8 Jun 2015 12:58 am, [email protected] wrote: > On Sun, Jun 7, 2015, at 07:42, Steven D'Aprano wrote: >> The question of graphemes (what "ordinary people" consider letters and >> characters, e.g. "ch" is two letters to an English speaker but one

Re: Testing random

2015-06-07 Thread Steven D'Aprano
525/387420489 or approximately 0.0009 For 100 samples: Pr(at least one element has zero count) = 7.4e-18 (approx) which means that with 100 samples from the set (1, 2, 3), if you could run one million trials every second, it would on average take you almost 4300 years to see a trial that had a

Re: Testing random

2015-06-07 Thread Steven D'Aprano
thousand times. But if you toss the coin once, your chances of getting "no heads" is 1/2. If you toss it a thousand times, your chances of getting "no heads" is 1/2**1000. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Random vs. Cython C Rand for Dice Rolls

2015-06-07 Thread Steven D'Aprano
On Mon, 8 Jun 2015 03:17 am, C.D. Reimer wrote: > Greetings, > > I've revisited my misbegotten childhood by translating the programs from > "BASIC Computer Games" by David H. Ahl into Python. This is mostly an > exercise in unraveling spaghetti code with all those GOTO statements > going all over

Re: Testing random

2015-06-07 Thread Steven D'Aprano
ur real mistake is hubris. *Nothing* in Chris' comments in this thread should lead you to the conclusion he doesn't know what he is talking about, but you're so full of the preconceived notion that he must be wrong because he is not Thomas Lahn that you've actually made an astonishing blunder and compounded it with laughable arrogance. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing random

2015-06-07 Thread Steven D'Aprano
ent seen at least once) in 90 trials 1.0 Pr(every element seen at least once) in 95 trials 1.0 -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing random

2015-06-07 Thread Steven D'Aprano
On Sun, 7 Jun 2015 11:35 pm, Peter Otten wrote: > Steven D'Aprano wrote: > > >>> I wrote a very simple function to test random: >>> def test_random(length, multiplier = 1): >>> number_list = length * [0] >&

Re: Rule of order for dot operators?

2015-06-08 Thread Steven D'Aprano
miter, but in once sense it is more than that because it also performs an attribute lookup. In any case, the order of applying dots is *strictly* left-to-right. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

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

2015-06-09 Thread Steven D'Aprano
On Wednesday 10 June 2015 10:47, Devin Jeanpierre wrote: > Passing around data that can be put into ast.literal_eval is > synonymous with passing around data taht can be put into eval. It > sounds like a trap. In what way? literal_eval will cleanly and safely refuse to evaluate strings like:

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

2015-06-09 Thread Steven D'Aprano
On Wednesday 10 June 2015 13:57, [email protected] wrote: > On Tue, Jun 9, 2015, at 23:52, Steven D'Aprano wrote: >> > For human readable serialized data, text format protocol buffers are >> > seriously underrated. (Relatedly: underdocumented, too.) >> >>

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

2015-06-10 Thread Steven D'Aprano
On Wednesday 10 June 2015 14:48, Devin Jeanpierre wrote: [...] > and literal_eval is not a great idea. > > * the common serializer (repr) does not output a canonical form, and > can serialize things in a way that they can't be deserialized For literals, the canonical form is that understood by

Re: Python NBSP DWIM

2015-06-10 Thread Steven D'Aprano
\u00A0eggs cheese') [u'hello', u'world', u'spam\\xa0eggs', 'cheese'] """ words = [] NBSP = u'\u00A0' substrings = s.split(NBSP) for i, sub in enumerate(substrings): parts = sub.split() if i == 0:

Re: Python NBSP DWIM

2015-06-10 Thread Steven D'Aprano
On Thu, 11 Jun 2015 10:09 am, Chris Angelico wrote: > On Thu, Jun 11, 2015 at 3:11 AM, Steven D'Aprano > wrote: >> (Oh, and for the record, there are at least two non-breaking spaces in >> Unicode, U+00A0 "NO-BREAK SPACE" and U+202F "NARROW NO-BREAK SPACE&

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

2015-06-10 Thread Steven D'Aprano
riting it from scratch. I can't do this: class MyClass: pass a = MyClass() serialised = repr(a) b = ast.literal_eval(serialised) assert a == b which is what I mean when I say literal_eval isn't powerful enough to handle arbitrary types. That's not a bug, that's a feature of literal_eval. It is *designed* to have that limitation. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python NBSP DWIM

2015-06-10 Thread Steven D'Aprano
pplications (or fonts) are permitted to treat U+FEFF as a zero-width invisible character, so perhaps you can raise a feature request with VLC. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

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

2015-06-11 Thread Steven D'Aprano
On Thursday 11 June 2015 15:39, Devin Jeanpierre wrote: >> But I'm not talking about re-inventing what already exists. If I want >> JSON, I'll use JSON, not spend weeks or months re-writing it from >> scratch. I can't do this: >> >> class MyClass: >>pass >> >> a = MyClass() >> serialised = repr(a)

Re: Error in or

2015-06-12 Thread Steven D'Aprano
On Thu, 11 Jun 2015 08:40:50 -0700, subhabrata.banerji wrote: > if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in > inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" > in inp1) or (''' " ''' in inp1): This is better written as: if any(substr in inp

Re: Get classes from "self.MyClass" to improve subclassability

2015-06-12 Thread Steven D'Aprano
On Fri, 12 Jun 2015 04:12:52 -0700, Thomas Güttler wrote: > Here is a snippet from the argparse module: > > {{{ > def parse_known_args(self, args=None, namespace=None): > ... > # default Namespace built from parser defaults if namespace is > None: > namespa

Re: Passing new fields to an object

2015-06-12 Thread Steven D'Aprano
On Fri, 12 Jun 2015 16:53:08 +0100, Paulo da Silva wrote: > I would like to do something like this: > > class C: > def __init__(self,**parms): > ... > > c=C(f1=1,f2=None) > > I want to have, for the object > self.f1=1 > self.f2=None > > for an arbitrary number of parame

Re: zip as iterator and bad/good practices

2015-06-13 Thread Steven D'Aprano
On Sat, 13 Jun 2015 13:32:59 +0800, jimages wrote: > I am a newbie. I also have been confused when I read the tutorial. It > recommends make a copy before looping. Then I try. > #-- > Test = [1, 2] > For i in Test: > Test.append(i) > #-- You don

Re: zip as iterator and bad/good practices

2015-06-13 Thread Steven D'Aprano
On Sat, 13 Jun 2015 13:48:45 +0100, Oscar Benjamin wrote: > On 13 June 2015 at 08:17, Steven D'Aprano > wrote: >> But an easier way is: >> >> Test = [1, 2] >> Test.extend(Test) >> print(Test) > > I can't see anything in the docs that spec

Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread Steven D'Aprano
gt; I've been using Notepad++ (Windows) and TextWrangler (Mac) for over a > decade now. Idle may be pure Python, but that's not enough for me to > switch. :) You don't have to switch for good. You can fire up IDLE to do this one job, then never use it again. -- Steven D

Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread Steven D'Aprano
On Sun, 14 Jun 2015 04:11:59 +0200, Laura Creighton wrote: > In a message of 14 Jun 2015 01:59:10 +, "Steven D'Aprano" writes: >>On Sat, 13 Jun 2015 14:09:48 -0700, C.D. Reimer wrote: >> >>> On 6/13/2015 1:59 PM, Laura Creighton wrote: >>&

Set a flag on the function or a global?

2015-06-15 Thread Steven D'Aprano
se give reasons, and remember that the function is intended for interactive use. -- Steven D'Aprano -- https://mail.python.org/mailman/listinfo/python-list

<    73   74   75   76   77   78   79   80   81   82   >