Re: Test None for an object that does not implement ==

2011-12-25 Thread Nobody
On Sat, 24 Dec 2011 23:09:50 -0800, GZ wrote: > I run into a weird problem. I have a piece of code that looks like the > following: > > f(, a=None, c=None): > assert (a==None)==(c==None) > > > The problem is that == is not implemented sometimes for values in a > and c, causing an excep

Re: Test None for an object that does not implement ==

2011-12-25 Thread Lie Ryan
On 12/25/2011 08:38 PM, Nobody wrote: nothing should compare equal to None except for None itself, so "x is None" > and "x == None" shouldn't produce different results unless there's a > bug in the comparison method. not necessarily, for example: import random class OddClass: def __eq__(s

help - obtaining the type of the object using tp_name

2011-12-25 Thread Mrinalini Kulkarni
Hello, I have embedded python into a vc++ app. I need to obtain type of the variable defined in the python script, in my c++ code. PyObject *pMyObject; -> assume points to a variable defined in the python script Now I want to do something like this const char * typeName; typeName = pMyObj

Re: Adding an interface to existing classes

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 17:24:14 -0800, Rick Johnson wrote: >> class DrawablePoint( geometry.Point ): >>     class draw( self, ... ): >>         ... > > "DrawablePoint"? I suppose there is an "ImaginaryPoint" somewhere in > this API? Geez No, but there's an abstract Point, which presumably refers to

Re: Adding an interface to existing classes

2011-12-25 Thread Chris Angelico
On Sun, Dec 25, 2011 at 11:10 PM, Steven D'Aprano wrote: > class Point:  # An abstract class. >    def intersect(self, other): >        blah; blah; blah >        return Point(x, y)  # No, wrong, bad!!! Don't do this. > > Instead: > >        return self.__class__(x, y)  # Better. This would work i

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 06:54:07 -0800, Eelco wrote: > Context dependence is not something to be avoided at all costs, but all > else being equal, less is certainly more. The general concept of > grouping thing together which parenthesis is an extremely pervasive one > in programming, and thus deserve

Re: help - obtaining the type of the object using tp_name

2011-12-25 Thread Yaşar Arabacı
And by the way, I would advice asking these kinds of questions in #python-dev IRC channel (Freenode). I believe you can get much better help about your problems regarding C-api there. 2011/12/25 Mrinalini Kulkarni > Hello, > > I have embedded python into a vc++ app. I need to obtain type of the

Re: help - obtaining the type of the object using tp_name

2011-12-25 Thread Yaşar Arabacı
I am not sure if I understood your question correctly, but I would advice checking this: http://docs.python.org/c-api/object.html#PyObject_Type Sun, 25 Dec 2011 13:28:55 +0200 tarihinde Mrinalini Kulkarni şöyle yazmış: Hello, I have embedded python into a vc++ app. I need to obtain typ

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 06:45:01 -0800, Eelco wrote: > Can you give an example of a construct in python where two whitespace > delimited identifiers are legal? Not apart from the trivial case of two identifiers separated by newlines. What's your point? -- Steven -- http://mail.python.org/mailman

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 06:39:39 -0800, Eelco wrote: > On Dec 20, 4:30 am, alex23 wrote: >> On Dec 19, 8:15 pm, Eelco wrote: >> >> > What does that have to do with collection packing/unpacking? >> >> It's mocking your insistance that collection unpacking is a type >> constraint. > > This is really

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 06:47:21 -0800, Eelco wrote: > I would like to be able to write something like: > > a, middle::tuple, b = ::sequence > > Where I would like the extra :: before the sequence to explicitly signal > collection unpacking on the rhs, to maintain the symmetry with > collection unpa

Re: what does 'a=b=c=[]' do

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 19:41:55 +0100, Thomas Rachel wrote: >> The only times you need the brackets around a tuple is to control the >> precedence of operations, or for an empty tuple. > > IBTD: > > a=((a, b) for a, b, c in some_iter) > b=[(1, c) for ] > > Without the round brackets, it is a synta

Re: Test None for an object that does not implement ==

2011-12-25 Thread Roy Smith
In article , Lie Ryan wrote: > Now, whether doing something like that is advisable or not, that's a > different question; however nothing in python states that you couldn't > have something that compare equal to None whether there is a bug or not > in the comparison method. Just for fun, I t

Re: Adding an interface to existing classes

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 23:32:41 +1100, Chris Angelico wrote: > On Sun, Dec 25, 2011 at 11:10 PM, Steven D'Aprano > wrote: >> class Point:  # An abstract class. >>    def intersect(self, other): >>        blah; blah; blah >>        return Point(x, y)  # No, wrong, bad!!! Don't do this. >> >> Instead:

Random string of digits?

2011-12-25 Thread Roy Smith
I want to create a string of 20 random digits (I'm OK with leading zeros). The best I came up with is: ''.join(str(random.randint(0, 9)) for i in range(20)) Is there something better? -- http://mail.python.org/mailman/listinfo/python-list

Re: Test None for an object that does not implement ==

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote: > Just for fun, I tried playing around with subclassing NoneType and > writing an __eq__ for my subclass.  Turns out, you can't do that: > > Traceback (most recent call last): >  File "./none.py", line 5, in >    class Nihil(NoneType): > TypeErro

Re: Adding an interface to existing classes

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:27 AM, Steven D'Aprano wrote: > There's nothing in the above that assumes that other has the same type as > self. It's just that the type of other is ignored, and the type of self > always wins. I find that a nice, clear rule: x.intersection(y) always > returns a point w

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: > I want to create a string of 20 random digits (I'm OK with leading > zeros). The best I came up with is: > > ''.join(str(random.randint(0, 9)) for i in range(20)) > > Is there something better? '%20d' % random.randint(0, 10**20-1) -- St

Re: Adding an interface to existing classes

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 00:37:22 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:27 AM, Steven D'Aprano > wrote: >> There's nothing in the above that assumes that other has the same type >> as self. It's just that the type of other is ignored, and the type of >> self always wins. I find tha

Re: Test None for an object that does not implement ==

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 00:35:46 +1100, Chris Angelico wrote: [...] >> TypeError: Error when calling the metaclass bases >>    type 'NoneType' is not an acceptable base type > > Yes; unfortunately quite a few Python built-in classes can't be > subclassed. I can't think of any other un-subclassable

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:30 AM, Roy Smith wrote: > I want to create a string of 20 random digits (I'm OK with leading > zeros).  The best I came up with is: > > ''.join(str(random.randint(0, 9)) for i in range(20)) > > Is there something better? The simple option is: random.randint(0,99

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:50 AM, Chris Angelico wrote: > The Python 2 docs [1] Forgot to provide link. Python 2: http://docs.python.org/library/random.html And same in Python 3: http://docs.python.org/py3k/library/random.html ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano wrote: > On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: > >> I want to create a string of 20 random digits (I'm OK with leading >> zeros).  The best I came up with is: >> >> ''.join(str(random.randint(0, 9)) for i in range(20)) >> >> Is there

Re: Test None for an object that does not implement ==

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano wrote: > I can't think of any other un-subclassable classes other than NoneType. > Which ones are you thinking of? I don't remember, but it was mentioned in a thread a little while ago. Experimentation shows that 'bool' is one of them, though. Thi

Re: Adding an interface to existing classes

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:46 AM, Steven D'Aprano wrote: > class DrawableLine(Line): >    intersection_kind = DrawablePoint Ha! That works. I was sure there'd be some simple way to do it! ChrisA -- http://mail.python.org/mailman/listinfo/python-list

ckjdlkfnl,ndf,nfd,fndfnkdnk mmdlssdlndnll; k; as; lkds sjdsljdlskjdsl; kdslksdl; ddlk

2011-12-25 Thread D. Mohan M. Dayalan
http;//123maza.com/48/moon670/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Test None for an object that does not implement ==

2011-12-25 Thread Roy Smith
In article , Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote: > > Just for fun, I tried playing around with subclassing NoneType and > > writing an __eq__ for my subclass.  Turns out, you can't do that: > > > > Traceback (most recent call last): > >  File "./none.py",

Re: Test None for an object that does not implement ==

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 1:13 AM, Roy Smith wrote: > If you were designing the interface from scratch, you would probably > represent that with an exception hierarchy Or possibly with "returns a False value", giving the option of None for none available, False for none will ever be available. Of c

Re: Random string of digits?

2011-12-25 Thread Roy Smith
In article , Chris Angelico wrote: > "%020d"%random.randint(0,) > (the latter gives you a string, padded with leading zeroes). But I'm > assuming that you discarded that option due to lack of entropy (ie you > can't trust randint() over that huge a range). Actually, the only

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 1:21 AM, Roy Smith wrote: > It turns out, I don't really need 20 digits.  If I can count on > "%020d" % random.randint(0,999) > > to give me 15-ish digits, that's good enough for my needs and I'll > probably go with that.  Thanks. I'd say you can. The info

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Eelco
On Dec 25, 2:01 am, Rick Johnson wrote: > On Dec 24, 6:24 pm, alex23 wrote: > > > That you're a condescending douchebag with nothing of value to > > contribute? > > > Crystal. > > Take it from me Eelco. Once Alex drops into your thread and starts > name calling, it's over my friend. Yes, he has

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Eelco
On Dec 25, 1:45 pm, Steven D'Aprano wrote: > On Sat, 24 Dec 2011 06:54:07 -0800, Eelco wrote: > > Context dependence is not something to be avoided at all costs, but all > > else being equal, less is certainly more. The general concept of > > grouping thing together which parenthesis is an extreme

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Arnaud Delobelle
On Dec 25, 2011 2:55 PM, "Eelco" wrote: > > On Dec 25, 2:01 am, Rick Johnson wrote: > > On Dec 24, 6:24 pm, alex23 wrote: > > > > > That you're a condescending douchebag with nothing of value to > > > contribute? > > > > > Crystal. > > > > Take it from me Eelco. Once Alex drops into your thread

Re: Random string of digits?

2011-12-25 Thread Peter Otten
Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:30 AM, Roy Smith wrote: >> I want to create a string of 20 random digits (I'm OK with leading >> zeros). The best I came up with is: >> >> ''.join(str(random.randint(0, 9)) for i in range(20)) >> >> Is there something better? > > The simple opt

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 01:51:30 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 1:21 AM, Roy Smith wrote: >> It turns out, I don't really need 20 digits.  If I can count on >> > "%020d" % random.randint(0,999) >> >> to give me 15-ish digits, that's good enough for my needs and

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Eelco
On Dec 25, 2:12 pm, Steven D'Aprano wrote: > On Sat, 24 Dec 2011 06:39:39 -0800, Eelco wrote: > > On Dec 20, 4:30 am, alex23 wrote: > >> On Dec 19, 8:15 pm, Eelco wrote: > > >> > What does that have to do with collection packing/unpacking? > > >> It's mocking your insistance that collection unpa

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Eelco
On Dec 25, 1:50 pm, Steven D'Aprano wrote: > On Sat, 24 Dec 2011 06:45:01 -0800, Eelco wrote: > > Can you give an example of a construct in python where two whitespace > > delimited identifiers are legal? > > Not apart from the trivial case of two identifiers separated by newlines. > > What's your

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 00:54:40 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano > wrote: >> On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: >> >>> I want to create a string of 20 random digits (I'm OK with leading >>> zeros).  The best I came up with is: >>> >>>

Plot seems weird

2011-12-25 Thread Yigit Turgut
Hi all, I have a text file as following; 0.2000470.00 0.2000530.16 0.2000590.00 0.2000650.08 0.2000720.00 0.2000780.16 And I am trying to plot it with ; filenames = sys.argv[1:] if len(filenames) == 0: filenames = [sys.

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Eelco
On Dec 25, 2:13 pm, Steven D'Aprano wrote: > On Sat, 24 Dec 2011 06:47:21 -0800, Eelco wrote: > > I would like to be able to write something like: > > > a, middle::tuple, b = ::sequence > > > Where I would like the extra :: before the sequence to explicitly signal > > collection unpacking on the r

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 2:46 AM, Steven D'Aprano wrote: > Use the Source, Luke, er, Chris :) > > If I've read the source correctly, randint() will generate sufficient > bits of randomness to ensure that the entire int is random. > > http://hg.python.org/cpython/file/default/Lib/random.py I prefer

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 06:55:28 -0800, Eelco wrote: > Anyway, braces are used at > least an order of magnitude more than collection packing/ unpacking in > typical code. That's a wild and unjustified claim. Here's a quick and dirty test, using the standard library as an example of typical idiomati

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 2:38 AM, Eelco wrote: > Until that time, im going > to ask you to take 'type constraint' by its literal meaning; a > coercion of the type of a symbol, rather than whatever particular > meaning it has acquired for you (it might help if you explained that). > Im not sure if i

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 07:38:17 -0800, Eelco wrote: > On Dec 25, 2:12 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Sat, 24 Dec 2011 06:39:39 -0800, Eelco wrote: >> > On Dec 20, 4:30 am, alex23 wrote: >> >> On Dec 19, 8:15 pm, Eelco wrote: >> >> >> > What does that have to do w

Re: Plot seems weird

2011-12-25 Thread Rick Johnson
On Dec 25, 9:33 am, Yigit Turgut wrote: > Hi all, > > I have a text file as following; > > 0.200047        0.00 > 0.200053        0.16 > 0.200059        0.00 > 0.200065        0.08 > 0.200072        0.00 > 0.200078        0.16 > > And I am trying to plot it with ; > > filen

Re: Test None for an object that does not implement ==

2011-12-25 Thread Lie Ryan
On 12/26/2011 01:13 AM, Roy Smith wrote: In article, Chris Angelico wrote: On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote: Just for fun, I tried playing around with subclassing NoneType and writing an __eq__ for my subclass. Turns out, you can't do that: Traceback (most recent call la

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 2:46 AM, Steven D'Aprano > wrote: >> Use the Source, Luke, er, Chris :) >> >> If I've read the source correctly, randint() will generate sufficient >> bits of randomness to ensure that the entire int is random. >>

Re: Random string of digits?

2011-12-25 Thread Serhiy Storchaka
25.12.11 15:48, Steven D'Aprano написав(ла): On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: I want to create a string of 20 random digits (I'm OK with leading zeros). The best I came up with is: ''.join(str(random.randint(0, 9)) for i in range(20)) Is there something better? '%20d' % ran

Re: Random string of digits?

2011-12-25 Thread Roy Smith
On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: > > I prefer not to rely on the source. That tells me what happens, not > > what's guaranteed to happen. Steven D'Aprano wrote: > In this case, the source explicitly tells you that the API includes > support for arbitrary large ranges if

Re: Random string of digits?

2011-12-25 Thread Joshua Landau
On 25 December 2011 17:32, Serhiy Storchaka wrote: > 25.12.11 15:48, Steven D'Aprano написав(ла): > > On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: >> >>> I want to create a string of 20 random digits (I'm OK with leading >>> zeros). The best I came up with is: >>> ''.join(str(random.ran

Re: Python education survey

2011-12-25 Thread Rick Johnson
On Dec 19, 9:51 pm, Raymond Hettinger wrote: > Do you use IDLE when teaching Python? > If not, what is the tool of choice? I believe IDLE has the potential to be a very useful teaching tool and even in it's current abysmal state, i find it to be quite useful. > Students may not be experienced wi

Re: Plot seems weird

2011-12-25 Thread Yigit Turgut
On Dec 25, 7:06 pm, Rick Johnson wrote: > On Dec 25, 9:33 am, Yigit Turgut wrote: > > Hi all, > > > I have a text file as following; > > > 0.200047        0.00 > > 0.200053        0.16 > > 0.200059        0.00 > > 0.200065        0.08 > > 0.200072        0.00 > > 0.200078    

Re: Random string of digits?

2011-12-25 Thread 88888 Dihedral
Roy Smith於 2011年12月26日星期一UTC+8上午1時41分29秒寫道: > On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: > > > I prefer not to rely on the source. That tells me what happens, not > > > what's guaranteed to happen. > > Steven D'Aprano wrote: > > In this case, the source explicitly tells you that t

RSA and Cryptography in PYTHON

2011-12-25 Thread 88888 Dihedral
Long integer is really excellent in Python. Encoding RSA 2048bits in a simple and elegant way in Python is almost trivial. How about the nontrivial decoding part ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Test None for an object that does not implement ==

2011-12-25 Thread Larry Hudson
On 12/24/2011 11:09 PM, GZ wrote: Hi, I run into a weird problem. I have a piece of code that looks like the following: f(, a=None, c=None): assert (a==None)==(c==None) <...> At first glance this looked like it should be a simple boolean "and", but then I realized that when a and

Re: Test None for an object that does not implement ==

2011-12-25 Thread Devin Jeanpierre
> At first glance this looked like it should be a simple boolean "and", but > then I realized that when a and c are both unequal to None, the result would > also be True. This implies the logical approach would be exclusive-or (^). Among booleans, "!=" is exclusive or and "==" is its negation. I

Re: Test None for an object that does not implement ==

2011-12-25 Thread Roy Smith
In article , Devin Jeanpierre wrote: > The issue here is that "== None" is being used instead of "is None", > but I believe that's been covered. Your response doesn't include it, > so maybe it's worth restating. Which of course leads to a SillyPEP for a new keyword, "are", which would allow yo

Re: Test None for an object that does not implement ==

2011-12-25 Thread Christian Heimes
Am 25.12.2011 15:04, schrieb Chris Angelico: > I think there are certain types that are actually not implemented as > classes, and hence cannot be subclassed. This is almost certainly an > implementation detail though; my testing was done in Py3.2 (on Windows > fwiw). Some extension types are not

How safe is this way of getting a default that allows None?

2011-12-25 Thread Dan Stromberg
How safe is this? I like the idea. #!/usr/bin/python UNSPECIFIED = object() def fn(x, y=UNSPECIFIED): if y is UNSPECIFIED: print x, 'default' else: print x, y fn(0, 1) fn(0, None) fn(0) -- http://mail.python.org/mailman/listinfo/python-list

Re: Test None for an object that does not implement ==

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 15:45:10 -0800, Larry Hudson wrote: > On 12/24/2011 11:09 PM, GZ wrote: >> Hi, >> >> I run into a weird problem. I have a piece of code that looks like the >> following: >> >> f(, a=None, c=None): >> assert (a==None)==(c==None) >> > <...> > > At first glance this loo

Re: Test None for an object that does not implement ==

2011-12-25 Thread Devin Jeanpierre
> Which of course leads to a SillyPEP for a new keyword, "are", which > would allow you to write: > a and c are None > > instead of the much more verbose > a is None and c is None How about: >>> a is b is None ;) -- Devin On Sun, Dec 25, 2011 at 7:27 PM, Roy Smith wrote: > In ar

Backslash Escapes

2011-12-25 Thread Felipe O
Hi all, Whenever I take any input (raw_input, of course!) or I read from a file, etc., any backslashes get escaped automatically. Is there any elegant way of parsing the backslashes as though they were written in a python string. The best I have so far right now goes like this: def parse_backslash

Re: How safe is this way of getting a default that allows None?

2011-12-25 Thread Tim Chase
On 12/25/11 18:49, Dan Stromberg wrote: How safe is this? I like the idea. UNSPECIFIED = object() def fn(x, y=UNSPECIFIED): if y is UNSPECIFIED: print x, 'default' else: print x, y safe? It's idiomatic :) -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: Backslash Escapes

2011-12-25 Thread MRAB
On 26/12/2011 01:04, Felipe O wrote: Hi all, Whenever I take any input (raw_input, of course!) or I read from a file, etc., any backslashes get escaped automatically. Is there any elegant way of parsing the backslashes as though they were written in a python string. The best I have so far right n

Re: Backslash Escapes

2011-12-25 Thread Devin Jeanpierre
> Whenever I take any input (raw_input, of course!) or I read from a > file, etc., any backslashes get escaped automatically. They don't get escaped, they get... treated as the bytes that they are. If you want them to mean what they do in Python, use the 'string_escape' codec. >>> x = r'nyan\

Re: Test None for an object that does not implement ==

2011-12-25 Thread Ian Kelly
On Sun, Dec 25, 2011 at 2:38 AM, Nobody wrote: > On Sat, 24 Dec 2011 23:09:50 -0800, GZ wrote: > >> I run into a weird problem. I have a piece of code that looks like the >> following: >> >> f(, a=None, c=None): >>     assert  (a==None)==(c==None) >> >> >> The problem is that == is not impleme

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 12:41:29 -0500, Roy Smith wrote: > On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: >> > I prefer not to rely on the source. That tells me what happens, not >> > what's guaranteed to happen. > > Steven D'Aprano wrote: >> In this case, the source explicitly tells you

Re: Python education survey

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 4:44 AM, Rick Johnson wrote: > Why install an IDE when IDLE is already there? Oh, yes, IDLE SUCKS. I > know that already. But this revelation begs the question... Why has > this community allowed IDLE to rot? Why has guido NOT started a public > discussion on the matter? C

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 2:00 PM, Steven D'Aprano wrote: > The implementation of getrandbits is not documented at all. You would > have to read the C source of the _random module to find out how the > default pseudo-random number generator produces random bits. But note the > leading underscore: _r

Re: Backslash Escapes

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:04 PM, Felipe O wrote: > Hi all, > Whenever I take any input (raw_input, of course!) or I read from a > file, etc., any backslashes get escaped automatically. Is there any > elegant way of parsing the backslashes as though they were written in > a python string... I gues

Re: Random string of digits?

2011-12-25 Thread Roy Smith
In article <4ef7e337$0$29973$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > And I'm afraid that you have missed my point. The above comment from the > source is from a docstring: it *is* public, official documentation. See > help(random.Random). When you wrote, "the source expl

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 3:17 PM, Roy Smith wrote: > Of course it is.  Those things constitute doc bugs which need to get > fixed.  The fact that the specification is flawed does not change the > fact that it *is* the specification. Also, the specification is what can be trusted across multiple im

Re: Test None for an object that does not implement ==

2011-12-25 Thread Ethan Furman
GZ wrote: Hi, I run into a weird problem. I have a piece of code that looks like the following: f(, a=None, c=None): assert (a==None)==(c==None) Um -- if you don't want a and c being passed in, why put them in the function signature? ~Ethan~ -- http://mail.python.org/mailman/list

Re: Test None for an object that does not implement ==

2011-12-25 Thread Ethan Furman
Nobody wrote: nothing should compare equal to None except for None itself, so "x is None" and "x == None" shouldn't produce different results unless there's a bug in the comparison method. Why wouldn't you want other types that can compare equal to None? It could be useful for a Null type to

Re: Test None for an object that does not implement ==

2011-12-25 Thread Devin Jeanpierre
> Um -- if you don't want a and c being passed in, why put them in the > function signature? He wants both or neither to be passed in. -- Devin On Sun, Dec 25, 2011 at 11:27 PM, Ethan Furman wrote: > GZ wrote: >> >> Hi, >> >> I run into a weird problem. I have a piece of code that looks like th

Re: Python education survey

2011-12-25 Thread Monte Milanuk
Not a teacher here, but I'm curious why Komodo Edit never seems to get any love in the IDE debates... a free version for personal/non-profit use, pro versions for those that need the extra features, seems to work fairly well but then again I'm probably not the best judge... Thanks, Monte --