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
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
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
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
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
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
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
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
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
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
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
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
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
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:
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
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
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
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
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
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
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
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
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
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
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
http;//123maza.com/48/moon670/
--
http://mail.python.org/mailman/listinfo/python-list
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",
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
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
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
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
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
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
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
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
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
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
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:
>>>
>>>
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.
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
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
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
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
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
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
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
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.
>>
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
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
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
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
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
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
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
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
> 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
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
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? 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
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
> 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
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
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
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
> 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\
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
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
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
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
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
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
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
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
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
> 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
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
--
76 matches
Mail list logo