Re: how to get bytes from bytearray without copying

2014-03-03 Thread Juraj Ivančić

On 3.3.2014. 1:44, Cameron Simpson wrote:


ValueError: cannot hash writable memoryview object


Have you considered subclassing memoryview and giving the subclass
a __hash__ method?


I have, and then, when I failed to subclass it, I considered doing 
aggregation, and make it behave byte-like. But how to implement the 
overridden __hash__ method? It will still require at least *some* 
redundant copying. And there is the slicing thing... the whole idea 
started to feel like I was performing tonsillectomy through the anal cavity.



--
https://mail.python.org/mailman/listinfo/python-list


Re: how to get bytes from bytearray without copying

2014-03-03 Thread Juraj Ivančić

On 3.3.2014. 1:49, Mark Lawrence wrote:


If your data is readonly why can't you simply read it as bytes in the
first place?  Failing that from
http://docs.python.org/3/library/stdtypes.html#memoryview

tobytes() - Return the data in the buffer as a bytestring. This is
equivalent to calling the bytes constructor on the memoryview.

  >>> m = memoryview(b"abc")
  >>> m.tobytes()
b'abc'
  >>> bytes(m)
b'abc'


Initially it has to be a bytearray because I read this data from a 
socket. My point is that once I have a bytearray x, then


m = memoryview(bytes(x))

is a very expensive way to make a read-only memoryview, opposed to

m = memoryview(x)

or (fictional)

m = memoryview(x, force_readonly=True)

especially if the x-es are many, large, and occur often.

I feel like memoryview's __hash__ is trying to be to smart for its own 
good, and that it should just return the damn hash like its name 
suggests, regardless of the value of 'writable' flag.







--
https://mail.python.org/mailman/listinfo/python-list


Re: how to get bytes from bytearray without copying

2014-03-03 Thread Juraj Ivančić

On 3.3.2014. 2:27, Ian Kelly wrote:


Python 3.3 has a C API function to create a memoryview for a char*,
that can be made read-only.

 http://docs.python.org/3/c-api/memoryview.html#PyMemoryView_FromMemory


Yes, this is probably what I'll do in absence of pure Python solution. 
Thanks for the tip.



Or you could bite the bullet and copy everything
once at the start to create a bytes object, and then never have to
worry about it again.


That would be a surrender :-)

--
https://mail.python.org/mailman/listinfo/python-list


Reference

2014-03-03 Thread ast

hello

Consider following code:


A=7
B=7
A is B

True

I understand that there is a single object 7 somewhere in memory and
both variables A and B point toward this object 7

now do the same with a list:


l1 = [1, 2]
l2 = [1, 2]
l1 is l2

False

It seems this time that there are 2 distincts objects [1, 2] in memory. l1 
points
toward the first one and l2 points toward the second one.

if I change one, the second remains unchanged


l1.append(3)
l1

[1, 2, 3]

l2

[1, 2]

I dont really understand why the behavior is different. 
Both integer 7 and list [1, 2] are objects. Why is it

different ?

thanks








--
https://mail.python.org/mailman/listinfo/python-list


[RELEASED] Python 3.3.5 release candidate 2

2014-03-03 Thread Georg Brandl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team, I'm happy to announce
the release of Python 3.3.5, release candidate 2.

Python 3.3.5 includes a fix for a regression in zipimport in 3.3.4
(see http://bugs.python.org/issue20621) and a few other bugs.

Python 3.3 includes a range of improvements of the 3.x series, as well
as easier porting between 2.x and 3.x.  In total, almost 500 API items
are new or improved in Python 3.3.  For a more extensive list of
changes in the 3.3 series, see

http://docs.python.org/3.3/whatsnew/3.3.html

To download Python 3.3.5 visit:

http://www.python.org/download/releases/3.3.5/


This is a preview release, please report any bugs to

 http://bugs.python.org/

The final release is scheduled one week from now.


Enjoy!

- -- 
Georg Brandl, Release Manager
georg at python.org
(on behalf of the entire python-dev team and 3.3's contributors)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.22 (GNU/Linux)

iEYEARECAAYFAlMUUKoACgkQN9GcIYhpnLD5OACfTpRkcM9aXUx2XbiXoZtIgSE7
BqwAnjwpAuqc9lKJ0O3XOw5qDvDPYsNb
=EGuB
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Object identity (was: Reference)

2014-03-03 Thread Ben Finney
"ast"  writes:

> >>> A=7
> >>> B=7
> >>> A is B
> True
>
> I understand that there is a single object 7 somewhere in memory and
> both variables A and B point toward this object 7

Try not to think in terms of “point to”. Rather, the names “A” and “B”
are bound to that object.

The distinction is subtle; but it's important to realise that *all*
references in Python do this, and there's no way to talk about an object
in Python without using a reference. The “pointer” model from other
languages doesn't exist in Python.

> now do the same with a list:
>
> >>> l1 = [1, 2]
> >>> l2 = [1, 2]
> >>> l1 is l2
> False
>
> It seems this time that there are 2 distincts objects [1, 2] in
> memory.

That's correct.

> I dont really understand why the behavior is different. Both integer 7
> and list [1, 2] are objects. Why is it different ?

Short answer: object identity is an implementation detail.

It's up to the Python implementation to decide when to re-use an object
when a new one is requested. No guarantee is made, when you ask to
create an object, that you won't get an existing one if that would work
just as well.

Since the integer object 7 is immutable, it will behave the same no
matter how many times you ask for a new one, the Python implementation
can choose to give you the same object. But it might not — don't depend
on this!

Since two separate lists are mutable, each one can have a distinct
history after creation, so it would be less helpful to return an
existing list when you ask for a new one. But again, there's no
guarantee here either! A Python implementation might decide to give you
an existing list, if existing guarantees can be kept.

The moral is: Don't depend on differences in object identity. You can be
guaranteed that an object will retain its own identity, and its identity
will always be different from all other co-existing objects that have
different values. Beyond that, don't make any assumptions.

-- 
 \  “Programs must be written for people to read, and only |
  `\incidentally for machines to execute.” —Abelson & Sussman, |
_o__)  _Structure and Interpretation of Computer Programs_ |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Alister
On Mon, 03 Mar 2014 06:14:09 +0700, musicdenotation wrote:

> If Python is not a fnctional language, then which programming paradigmis
> dominant?

Python follows the Pythonic paradigm :-)



-- 
Hope this helps some, sorry for not being able to do a brain dump.

- Mike Stump helping a clueless user on the gcc mailing list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Object identity (was: Reference)

2014-03-03 Thread ast

thanks ben, that's clear
--
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Bob Martin
in 718085 20140302 231409 musicdenotat...@gmail.com wrote:
>If Python is not a fnctional language, then which programming paradigmis dom=
>inant?=

Labels are always misleading.
-- 
https://mail.python.org/mailman/listinfo/python-list


python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
hi folks,

Python Decimal Library dmath.py v0.3 Released

https://code.google.com/p/pythondecimallibrary/

This code provides the C accelerated decimal module with 
scientific/transcendental functions for arbitrary precision. 
I have also included pilib.py which is a PI library of historic
algorithms for generating PI, which uses dmath.py. 

I wish to thank Oscar, Wolfgang, Steven, Chris (and others)
for the help you gave me understanding decimal, particularly
format, rounding, and context managers. 

Everything is documented well (including issues) on the code
site, and things are working better, and are certainly cleaner. 
No doubt there are still bugs, but its getting closer.

Thanks again.

marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 6:57:15 AM UTC+5:30, Ned Batchelder wrote:
> On 3/2/14 6:14 PM, musicdenotation wrote:
> > If Python is not a fnctional language, then which programming paradigmis 
> > dominant?

> is_a_functional_language() is not a binary condition, yes or no.  It's a 
> continuum.  Python has more functional constructs than Pascal, and fewer 
> than Haskell.

I find this the most agreeable answer. I would add:

There are really two continuaa:
the 'CAN' and the 'CANNOT' (sounds 180 deg apart but they are actually
rather independent)

As Ned says on the CAN spectrum python sits between standard
imperative languages like C,Pascal and Haskell, in fact coming quite close
to Haskell.

However it is also useful to consider the CANNOT spectrum for
beginners/pedagogical purposes.

If you start a beginner on a language like Haskell which CANNOT:
- express iteration except with recursion
- cannot have assignments (and therefore anything remotely like a normal
program variable; variables are only ever math variables)
- cannot do a 'type-incorrect' expression like
>>> [1,2] + [[3,4],[5]]
[1, 2, [3, 4], [5]]

the beginner will develop a significantly different mind-set than
starting from a python-like language

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 5:34:30 AM UTC-6, Mark H. Harris wrote:
> hi folks,

Terry,  I posted this mod as an idea on python-ideas, as you suggested.
Also, I made the additional suggestion that decimal floating point be 
considered as the primary floating point type for python4.x, with an 
optional binary floating type (2.345b) if the user might like that.

As Steven pointed out last week, we have a fast module now for decimal
floating point; it seems this is a good time to consider this as a serious 
idea for future python(s).

marcus

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Chris Angelico
On Mon, Mar 3, 2014 at 10:45 PM, Rustom Mody  wrote:
> - cannot do a 'type-incorrect' expression like
 [1,2] + [[3,4],[5]]
> [1, 2, [3, 4], [5]]

What do you mean by "type-incorrect"? This is adding two lists and
getting back a list. Seems perfectly correct to me.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
Hello,

I'm trying to use urllib and urllib2 to open an url + login_data in a for loop. 
How can I display when successfully logged in and how to show when the login is 
denied? 

I've tried use this:

html_content = urllib2.urlopen(url).read()
re.findall('ERROR: The password you entered for the username USER is 
incorrect.', html_content)

1. I want to try an if statement in a for loop
2. Iterate through a list and when the first password in the list is denied. It 
shall continue with the next password in the list and try that one.
3. When it's successfully logged in the program will stop the loop and print 
out the password that matches.

I'm stuck and need some help creating this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
This is the code right now: http://pastebin.com/pE1YZX2K
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Chris Angelico
On Mon, Mar 3, 2014 at 11:44 PM, Chris Angelico  wrote:
> So basically, you're doing a dictionary attack. May I ask why you're
> doing this, exactly?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Chris Angelico
On Mon, Mar 3, 2014 at 11:44 PM, Chris Angelico  wrote:
> So basically, you're doing a dictionary attack. May I ask why you're
> doing this, exactly?

oops, misclicked.

I note that the user name 'alex' does not appear to match your name.
I'm going to want a good reason for this code to be written, else
you're on your own - I don't intend to help you steal someone else's
password.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Chris Angelico
On Mon, Mar 3, 2014 at 11:35 PM, Marcus  wrote:
> This is the code right now: http://pastebin.com/pE1YZX2K

That looks short enough to include in-line, no need to point us to an
external site :)

So basically, you're doing a dictionary attack. May I ask why you're
doing this, exactly?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
Yes, it's only for my own use on my local WordPress installation. Only 
educational use. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Chris Angelico
On Mon, Mar 3, 2014 at 11:51 PM, Marcus  wrote:
> Yes, it's only for my own use on my local WordPress installation. Only 
> educational use.

What are you trying to learn, exactly? How to break into a WP site?

Still dubious.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 3:42:30 AM UTC-6, ast wrote:

> Consider following code:
> 
> >>> A=7
> >>> B=7
> >>> A is B
> True

The names A and B are both bound to the same object (7). 
You will discover that this is True for all small ints less
than 257;  on CPython3.3.4.  I just checked it.   :)

Its just more efficient to do this for small ints because they 
are immutable (1) and because they are used for frequently (2).

As somebody pointed out last week, don't use "is" for ints and 
strings (generally speaking). Value is what's important here,
not identity. My python coding is yet simple and straight
forward enough that I have not had a need yet for "is". 

Cheers
marcus

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Marcus
It's not that hard to find a program that does this already. But I'm trying to 
learn how to use these modules to create this. I've started it and now i want 
to complete it so I can create another program and learn more about other 
stuff, maybe a Twitter script or something. How do I learn when not practice? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Oscar Benjamin
On 3 March 2014 11:34, Mark H. Harris  wrote:
> hi folks,
>
> Python Decimal Library dmath.py v0.3 Released
>
> https://code.google.com/p/pythondecimallibrary/

Hi Mark,

Is this available on PyPI? It seems there already is a "dmath" package
on PyPI that was written by someone else some time ago so you might
need to use a different name:
https://pypi.python.org/pypi/dmath/0.9


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Jaap van Wingerde
Django views.py:
...
pwd = os.path.dirname(os.path.realpath(__file__ ))
home_lastmod =  
strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime(pwd+'/templates/art_index.html')))
...

The template gives a wrong modification time: "2014-03-02T19:03:55Z".

...
jaap@liakoster:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, time
>>> from time import
>>> gmtime
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
>>>   
'2014-03-02T19:03:55Z'
>>> quit()  
jaap@liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html
-rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
/var/django/test2/art/templates/art_index.html
jaap@liakoster:~$ 
...

ls gives the right modification time. What is wrong?

...
jaap@liakoster:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:Debian GNU/Linux 7.4 (wheezy)
Release:7.4
Codename:   wheezy
jaap@liakoster:~$ uname -a
Linux liakoster.shrl.nl 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 
GNU/Linux
jaap@liakoster:~$ 
...

-- 
Jaap van Wingerde
e-mail: 1234567...@vanwingerde.nl
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Password validation security issue

2014-03-03 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> The greatest threats these days are from the network, not from someone
> physically walking into an office. (That said, though, the low-hanging
> fruit from walking into an office can be *extremely* tempting. Pulling
> off a basic password leech off sticky notes is often so easy that it
> can be done as a visitor, or at least as a pizza deliveryman.)

Doesn't even require physical presence.  With the ubiquity of various 
video chat applications, as long as the sticky note is in the field of 
view of the camera, you've leaked the password.  With the right 
lighting, I wouldn't be surprised if you could pick up the reflection of 
a sticky note in somebody's eyeglasses.

So, here's my own (embarrassing) story of password leaking.  Back when 
smartphones were new, I had one of the early Palm Treos.  I decided a 
good place to store my passwords was as fields on my own card.  What I 
didn't realize was that if I beamed[*] my card to somebody, I was also 
giving them all my passwords, mostly because it had never occurred to me 
that I might want to beam my card to somebody.  Until somebody else in 
my office got another smart phone that had beaming capabilities and we 
decided to see how it worked.  It occurred to me as soon as we completed 
the first experiment.

I used to work at  which had a typical big company IT 
department which enforced all sorts of annoying pseudo-security rules.  
As far as I could figure out, however, all you needed to get them to 
reset anybody's password and tell you the new one was to know their 
employee ID number (visible on the front of their ID badge), and to make 
the call from their desk phone.

[*] Beaming: a prehistoric technology which allows exchange of data over 
an infrared light beam.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterate through a list and try log in to a website with urllib and re

2014-03-03 Thread Roy Smith
In article ,
 Marcus  wrote:
 
> I'm trying to use urllib and urllib2 to open an url + login_data in a for 
> loop.

Step 1: Ignore all that crap and get http://www.python-requests.org/

> How can I display when successfully logged in and how to show when the 
> login is denied? 
> 
> I've tried use this:
> 
> html_content = urllib2.urlopen(url).read()
> re.findall('ERROR: The password you entered for the username USER is 
> incorrect.', html_content)

In the ideal case, whatever you're talking to will return a success or 
failure indication in the HTTP status code.

Lacking that, it will at least return something intended to be parsed 
(like JSON).

Lacking that (and, unfortunately, common), you're reduced to 
screen-scraping.  But, if you've got to do that, at least use a tool 
like lxml or BeautifulSoup to parse the HTML.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 5:50:37 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Mar 3, 2014 at 10:45 PM, Rustom Mody  wrote:
> > - cannot do a 'type-incorrect' expression like
>  [1,2] + [[3,4],[5]]
> > [1, 2, [3, 4], [5]]

> What do you mean by "type-incorrect"? This is adding two lists and
> getting back a list. Seems perfectly correct to me.


Here's the behavior from an (old version of) haskell.

Unfortunately modern versions give a less helpful error message
'++' is list-append, '?' is the prompt

? [1,2] + [[3,4],[5]]   
ERROR: Type error in application
*** expression : [1,2] + [[3,4],[5]]
*** term   : [1,2]
*** type   : [Int]
*** does not match : [[Int]]

IOW [1,2,[3,4],[5]]
is a type-wise ill-formed expression just as in python
[[1,2])
is syntax-wise ill-formed

Is it worth having such a restriction?
Thats a different argument...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 7:18:00 PM UTC+5:30, Rustom Mody wrote:

> Unfortunately modern versions give a less helpful error message
> '++' is list-append, '?' is the prompt

> ? [1,2] + [[3,4],[5]]   

Whoops Wrong cut-paste!

? [1,2] ++ [[3,4],[5]]
ERROR: Type error in application
*** expression : [1,2] ++ [[3,4],[5]]
*** term   : [1,2]
*** type   : [Int]
*** does not match : [[Int]]

? 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Password validation security issue

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 12:41 AM, Roy Smith  wrote:
> I used to work at  which had a typical big company IT
> department which enforced all sorts of annoying pseudo-security rules.
> As far as I could figure out, however, all you needed to get them to
> reset anybody's password and tell you the new one was to know their
> employee ID number (visible on the front of their ID badge), and to make
> the call from their desk phone.

Technically, that's a separate vulnerability. If you figure out
someone else's password, you can log in as that person and nobody is
any the wiser (bar detailed logs eg of IP addresses). Getting a
password reset will at least alert the person on their next login.
That may or may not be safe, of course. Doing a password reset at
4:30pm the day before someone goes away for two months might give you
free reign for that time *and* might not even arouse suspicions ("I
can't remember my password after the break, can you reset it
please?").

But it's an attack vector that MUST be considered, which is why I
never tell the truth in any "secret question / secret answer" boxes.
Why some sites think "mother's maiden name" is at all safe is beyond
my comprehension. And that's not counting the ones that I can't answer
because I can't find the "NaN" key on my keyboard, like "Surname of
first girlfriend". *twiddle thumbs*

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 12:48 AM, Rustom Mody  wrote:
> ? [1,2] + [[3,4],[5]]
> ERROR: Type error in application
> *** expression : [1,2] + [[3,4],[5]]
> *** term   : [1,2]
> *** type   : [Int]
> *** does not match : [[Int]]
>
> IOW [1,2,[3,4],[5]]
> is a type-wise ill-formed expression just as in python
> [[1,2])
> is syntax-wise ill-formed
>
> Is it worth having such a restriction?
> Thats a different argument...

How do you know that [1,2] is a list that must contain nothing but
integers? By extension, it's also a list that must contain positive
integers less than three, so adding [5] violates that. And [] is a
list that must contain nothing, ergo it can't be added to, although
(since it contains nothing) it can be added to anything.

Some languages do let you specify element types (Pike has an "array"
type that can hold anything, or you can say "array(int)" to restrict
it to integers; you could also say "array(int(1..2))" to specify what
I said above, if you actually intend that), but without a declaration
from the programmer, it's dangerous to assume there's an error.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 12:35 AM, Jaap van Wingerde
 wrote:
 time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
> '2014-03-02T19:03:55Z'
 quit()
> jaap@liakoster:~$ ls --full-time 
> /var/django/test2/art/templates/art_index.html
> -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
> /var/django/test2/art/templates/art_index.html

See if ls is actually giving you ctime rather than mtime - compare the
results if you ask for os.path.getctime.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 7:30:17 PM UTC+5:30, Chris Angelico wrote:
> On Tue, Mar 4, 2014 at 12:48 AM, Rustom Mody wrote:
> > ? [1,2] + [[3,4],[5]]
> > ERROR: Type error in application
> > *** expression : [1,2] + [[3,4],[5]]
> > *** term   : [1,2]
> > *** type   : [Int]
> > *** does not match : [[Int]]
> > IOW [1,2,[3,4],[5]]
> > is a type-wise ill-formed expression just as in python
> > [[1,2])
> > is syntax-wise ill-formed
> > Is it worth having such a restriction?
> > Thats a different argument...

> How do you know that [1,2] is a list that must contain nothing but
> integers? By extension, it's also a list that must contain positive
> integers less than three, so adding [5] violates that. And [] is a
> list that must contain nothing, ergo it can't be added to, although
> (since it contains nothing) it can be added to anything.

If 'integer-less-than-3' were a type then yes there would be this
problem. More generally, if types could overlap then automatic
type-inference is impossible

Whether all thats good is as I earlier said a different argument

The OP asked about FP and so its appropriate to mention how python's
and standard FPL's choices differ
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:How security holes happen

2014-03-03 Thread Neal Becker
 Charles R Harris  Wrote in message:
> ___
> NumPy-Discussion mailing list
> numpy-discuss...@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 

Imo the lesson here is never write in low level c. Use modern
 languages with well designed exception handling.
-- 




Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] Can global variable be passed into Python function?

2014-03-03 Thread Grant Edwards
On 2014-03-02, Chris Angelico  wrote:
> On Mon, Mar 3, 2014 at 3:55 AM, Mark Lawrence  wrote:
>> On 02/03/2014 16:45, Grant Edwards wrote:
>>>
>>>
>>> That's irrelevent.  The actual location of the memory containing the
>>> struct object (static, stack, heap, shared) doesn't matter.  The
>>> address of the first field in a struture object _is_ the address of
>>> the structure object.
>>>
>>
>> You say struture, I'll say structure, let's call the whole thing off :)
>
>:)
>
> Note that, technically, Grant is correct as long as you grant (heh)
> that a structure may have an invisible member, the virtual function
> table pointer. C++ only (I don't believe C has virtual functions -
> but it may have grown them in one of the newer standards), so in C,
> all members are public.

Yes. I was talking about C, not C++.  I made that quite clear in
portions of my post that have been elided.  In C there is no such
thing as a virtual table pointer.

-- 
Grant Edwards   grant.b.edwardsYow! We have DIFFERENT
  at   amounts of HAIR --
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody  wrote:
>> How do you know that [1,2] is a list that must contain nothing but
>> integers? By extension, it's also a list that must contain positive
>> integers less than three, so adding [5] violates that. And [] is a
>> list that must contain nothing, ergo it can't be added to, although
>> (since it contains nothing) it can be added to anything.
>
> If 'integer-less-than-3' were a type then yes there would be this
> problem. More generally, if types could overlap then automatic
> type-inference is impossible
>

First, does Haskell allow this?

? [1,2,'foo'] ++ [3,4,'bar']

If not, then find some other form of the expression that has the same
point, and substitute in for the below. And then: which of these is
permitted?

? [1,2] ++ [3,4,'bar']
? [1,2,'foo'] ++ [3,4]
? [] ++ [3,4,'bar']
? [1,2,'foo'] ++ []
? ([1,2,'foo'] ++ []) ++ [3,4,'bar']
? [1,2,'foo'] ++ ([] ++ [3,4,'bar'])

If it's okay to have heterogeneous lists, how do you tell it that your
[1,2] is actually going to get strings in it later, and that it's okay
to combine it with one that has strings?

With Pike, that's all based on the variable type. (There is type
inference; the type of an array containing just 3 and 4 is
"array(int(3..4))", but it's acceptable to add that to an array
containing the string "asdf", which itself has type
"array(string(97..115))" - the combination would be "array(int(3..4) |
string(97..115))", which gets a bit wordy.) I can't assign an
array(string) to a variable that's been declared as taking array(int).
But I can assign an array(int) to a variable declared as accepting
array(int|string), and then I can append a string to it, because
that's legal based on the destination.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] Can global variable be passed into Python function?

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 1:18 AM, Grant Edwards  wrote:
>> Note that, technically, Grant is correct as long as you grant (heh)
>> that a structure may have an invisible member, the virtual function
>> table pointer. C++ only (I don't believe C has virtual functions -
>> but it may have grown them in one of the newer standards), so in C,
>> all members are public.
>
> Yes. I was talking about C, not C++.  I made that quite clear in
> portions of my post that have been elided.  In C there is no such
> thing as a virtual table pointer.

I wasn't certain of the newer C standards. C's been gaining all sorts
of features, not all of which are necessary, and it's entirely
possible based on my current knowledge that C specifies #include
 ...

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Jaap van Wingerde
Op  schreef Chris Angelico  
in bericht :

> See if ls is actually giving you ctime rather than mtime - compare the
> results if you ask for os.path.getctime.

jaap@liakoster:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, time
>>> from time import gmtime
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
'2014-03-02T19:03:55Z'
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html')))
'2014-03-02T19:03:55Z'
>>> quit()
jaap@liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html
-rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
/var/django/test2/art/templates/art_index.html
jaap@liakoster:~$ 

ls is giving me the modified time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Grant Edwards
On 2014-03-03, ast  wrote:
> hello
>
> Consider following code:
>
 A=7
 B=7
 A is B
> True
>
> I understand that there is a single object 7 somewhere in memory

Maybe, maybe not.  Integer are immutable, so that's allowed but not
required. In CPython, that's true for small integers, but that is an
implementation detail, and you shouldn't depend on it.

> and both variables A and B point toward this object 7

They might.  They might not.

> now do the same with a list:
>
 l1 = [1, 2]
 l2 = [1, 2]
 l1 is l2
> False
>
> It seems this time that there are 2 distincts objects [1, 2] in
> memory.

Yep.  Lists are mutable, therefore each literal produces a distinct
object.

> l1 points toward the first one and l2 points toward the
> second one.

Yep.

> I dont really understand why the behavior is different. 
> Both integer 7 and list [1, 2] are objects. Why is it
> different ?

Integer objects are immutable (they can't change value), therefore you
can reuse them without causing problems.  Lists are mutable (you can
change the values in them), so you can't reuse them.

-- 
Grant Edwards   grant.b.edwardsYow! Maybe I should have
  at   asked for my Neutron Bomb
  gmail.comin PAISLEY --
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 7:34:40 AM UTC-6, Oscar Benjamin wrote:

 > Python Decimal Library dmathlib.py v0.3 Released

> https://code.google.com/p/pythondecimallibrary/

> Is this available on PyPI? It seems there already is a "dmath" package
> on PyPI that was written by someone else some time ago so you might
> need to use a different name:

> Oscar

hi Oscar; thanks again for your help.

Yes, I actually intended to call it dmathlib.py at first, and then had my 
brain stuck on dmath, partly because several folks threw that name 
around, and partly because I got used to abbreviating it and forgot 
to fix things up name-wise. 

[ Done ]

Actually, code.google tries to help folks with that because if the name 
is taken you have to create a unique name; which I did, but I forgot to 
fix up all the references and heading.  Thanks again for keeping me
accountable. 

Kind regards,
marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 7:53:01 PM UTC+5:30, Chris Angelico wrote:
> On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote:
> >> How do you know that [1,2] is a list that must contain nothing but
> >> integers? By extension, it's also a list that must contain positive
> >> integers less than three, so adding [5] violates that. And [] is a
> >> list that must contain nothing, ergo it can't be added to, although
> >> (since it contains nothing) it can be added to anything.
> > If 'integer-less-than-3' were a type then yes there would be this
> > problem. More generally, if types could overlap then automatic
> > type-inference is impossible

> First, does Haskell allow this?

> ? [1,2,'foo'] ++ [3,4,'bar']

> If not, then find some other form of the expression that has the same
> point, and substitute in for the below. And then: which of these is
> permitted?


Dunno what you mean/whats the 'point'


> ? [1,2] ++ [3,4,'bar']
> ? [1,2,'foo'] ++ [3,4]
> ? [] ++ [3,4,'bar']
> ? [1,2,'foo'] ++ []
> ? ([1,2,'foo'] ++ []) ++ [3,4,'bar']
> ? [1,2,'foo'] ++ ([] ++ [3,4,'bar'])

> If it's okay to have heterogeneous lists, 

Its not.  None of the above work

If you want the (semantic) equivalent of python's [1,2,'foo']
you need to make an explicit union Int and String and its that
*single* union type's elements that must go in.

In all cases its always a single type. And so
sum([1,2,[3])
is a syntax error unlike python where its a runtime error


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 1:38 AM, Rustom Mody  wrote:
> If you want the (semantic) equivalent of python's [1,2,'foo']
> you need to make an explicit union Int and String and its that
> *single* union type's elements that must go in.
>
> In all cases its always a single type. And so
> sum([1,2,[3])

Okay. That's how the declaration goes, then. So how do you tell it
that 1 isn't an Int, it's a member of the union of Int and String? How
do you create a list which has [Int_String(1), Int_String(2)] and is
therefore allowed to be added to [Int_String('foo')] ? Can you do that
with literals?

This is why it's tricky to put rules in based on type inference. The
programmer's intent isn't in the picture. If Python ever acquires that
kind of restriction ("here's a list that can contain only this type /
these types of object"), I would hope that it's left up to the
programmer, not the compiler, to stipulate. That's how it is with Pike
(if you just say "array", it can take anything), and that's the only
way to be sure the programmer doesn't have to fight the language.

You said earlier

>> On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote:
>> > If 'integer-less-than-3' were a type then yes there would be this
>> > problem. More generally, if types could overlap then automatic
>> > type-inference is impossible

The type "Int" overlaps with the type "Union of Int and String". How
is that resolved? Type inference ignores unions? That's the only way I
can think of. Hence the original difficulty of type-inferring on a
list that isn't complete yet.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


How to create a voting website by Python and Flask?

2014-03-03 Thread Harry Wood
How to create a voting website by Python and Flask? I studying Python and Flask 
for some months, and

 - Now I have some Python & Flask basic skills.
 - I need some advices like following example: 
Step 1: You could writing an voting application by Python Step 2: You could 
build a website by Flask ...
Thanks very much!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 7:34:40 AM UTC-6, Oscar Benjamin wrote:
> On 3 March 2014 11:34, Mark H. Harris  wrote:
> 

> Is this available on PyPI? It seems there already is a "dmath" package
> on PyPI that was written by someone else some time ago so you might 
> need to use a different name:

> Oscar

Oscar, thanks again for your help, and for keeping me accountable. I did
intend on using the naming convention pythondecimallibrary but got 
dmath stuck in my mind from the discussions earlier last week. At any 
rate the naming problem is fixed.  Thanks again.

Python3.3 Decimal Library v0.3 is Released  here:

  https://code.google.com/p/pythondecimallibrary/

*pdeclib.py* is the decimal library, and *pilib.py* is the PI library.


marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 8:31:47 PM UTC+5:30, Chris Angelico wrote:
> On Tue, Mar 4, 2014 at 1:38 AM, Rustom Mody  wrote:
> > If you want the (semantic) equivalent of python's [1,2,'foo']
> > you need to make an explicit union Int and String and its that
> > *single* union type's elements that must go in.
> > In all cases its always a single type. And so
> > sum([1,2,[3])

> Okay. That's how the declaration goes, then. So how do you tell it
> that 1 isn't an Int, it's a member of the union of Int and String? How
> do you create a list which has [Int_String(1), Int_String(2)] and is
> therefore allowed to be added to [Int_String('foo')] ? Can you do that
> with literals?

Mmmm This is getting a bit OT for a python list
Anyway here goes
The Union type is called Either.
Its got two constructors -- Left and Right -- better to think of them as
tags to not confuse with OO constructors.
The names Left and Right seem to be a bit meaningless because the Either
type is completely generic -- any types S and T can be 'unioned' as
Either S T
where the S components look like Left x for x : S
and the T components look like Right x for x : T

So python's [1,2,"foo"] is
written as
[Left 1, Left 2, Right "foo"]

> This is why it's tricky to put rules in based on type inference. The
> programmer's intent isn't in the picture. If Python ever acquires that
> kind of restriction ("here's a list that can contain only this type /
> these types of object"), I would hope that it's left up to the
> programmer, not the compiler, to stipulate. That's how it is with Pike
> (if you just say "array", it can take anything), and that's the only
> way to be sure the programmer doesn't have to fight the language.

> You said earlier

> >> On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote:
> >> > If 'integer-less-than-3' were a type then yes there would be this
> >> > problem. More generally, if types could overlap then automatic
> >> > type-inference is impossible

> The type "Int" overlaps with the type "Union of Int and String". How
> is that resolved? 

By decreeing "no overlap!" :-)

Left 1 : Either Int String
whereas 1 : Int

Strictly speaking 'union' should be called 'disjoint union' but this is
so universal in programming that its dropped as redundant.

Heck even C's union is disjoint! If we have

union u
{ 
  int i;
  char c;
};

union u x;

Now you cant interchange the usages of x x.i and x.c

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Rustom Mody
On Monday, March 3, 2014 3:12:30 PM UTC+5:30, ast wrote:
> hello

> Consider following code:

> >>> A=7
> >>> B=7
> >>> A is B
> True

> I understand that there is a single object 7 somewhere in memory and
> both variables A and B point toward this object 7

> now do the same with a list:

> >>> l1 = [1, 2]
> >>> l2 = [1, 2]
> >>> l1 is l2
> False

> It seems this time that there are 2 distincts objects [1, 2] in memory. l1 
> points
> toward the first one and l2 points toward the second one.

> if I change one, the second remains unchanged

> >>> l1.append(3)
> >>> l1
> [1, 2, 3]
> >>> l2
> [1, 2]

> I dont really understand why the behavior is different. 
> Both integer 7 and list [1, 2] are objects. Why is it
> different ?

Short answer: Avoid using 'is'. 

Long answer: 
http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html

Pragmatic answer: Think of 'is' as a short-form for 'machine-rep-is'
And use machine representations with the same alacrity that a
C programmer uses inline assembly
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create a voting website by Python and Flask?

2014-03-03 Thread David Froger
Quoting Harry Wood (2014-03-03 16:22:22)
> How to create a voting website by Python and Flask? I studying Python and 
> Flask for some months, and
> 
>  - Now I have some Python & Flask basic skills.
>  - I need some advices like following example: 
> Step 1: You could writing an voting application by Python Step 2: You could 
> build a website by Flask ...
> Thanks very much!
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Hi Harry,

For example:

You define an URL, something like /voting. Used with a GET request, the Python
function associated to the /voting URL renders and returns a template
containing a form. You can create the form using Flask-WTF, and use
Flask-Bootstrap to make your page looks better. The user fill the form, and
submit it (POST request on /voting). Here, the function associated with
/voting get the form data, and store it in a database.

You define a second URL, /results, which on a GET request reads your database
and returns the results by rendering a template, something like
render_template('result.html', result=result)

Hope it helps!
David
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Password validation security issue

2014-03-03 Thread MRAB

On 2014-03-03 13:55, Chris Angelico wrote:

On Tue, Mar 4, 2014 at 12:41 AM, Roy Smith  wrote:

I used to work at  which had a typical big company IT
department which enforced all sorts of annoying pseudo-security rules.
As far as I could figure out, however, all you needed to get them to
reset anybody's password and tell you the new one was to know their
employee ID number (visible on the front of their ID badge), and to make
the call from their desk phone.


Technically, that's a separate vulnerability. If you figure out
someone else's password, you can log in as that person and nobody is
any the wiser (bar detailed logs eg of IP addresses). Getting a
password reset will at least alert the person on their next login.
That may or may not be safe, of course. Doing a password reset at
4:30pm the day before someone goes away for two months might give you
free reign for that time *and* might not even arouse suspicions ("I
can't remember my password after the break, can you reset it
please?").

But it's an attack vector that MUST be considered, which is why I
never tell the truth in any "secret question / secret answer" boxes.
Why some sites think "mother's maiden name" is at all safe is beyond
my comprehension. And that's not counting the ones that I can't answer
because I can't find the "NaN" key on my keyboard, like "Surname of
first girlfriend". *twiddle thumbs*


I don't think you're obliged to answer such questions truthfully.

Q: Surname of first girlfriend?
A: Luxury Yacht

--
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Oscar Benjamin
On 3 March 2014 15:22, Mark H. Harris  wrote:
> On Monday, March 3, 2014 7:34:40 AM UTC-6, Oscar Benjamin wrote:
>> On 3 March 2014 11:34, Mark H. Harris  wrote:
>>
>> Is this available on PyPI?
>
> Python3.3 Decimal Library v0.3 is Released  here:
>
>   https://code.google.com/p/pythondecimallibrary/
>
> *pdeclib.py* is the decimal library, and *pilib.py* is the PI library.

Is it on PyPI though? I was referring to a PyPI name so that people
could install it with "pip install pdeclib" (or whatever you called
it). That's how open source Python projects are usually distributed.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Password validation security issue

2014-03-03 Thread Steven D'Aprano
On Tue, 04 Mar 2014 00:55:45 +1100, Chris Angelico wrote:

> But it's an attack vector that MUST be considered, which is why I never
> tell the truth in any "secret question / secret answer" boxes. Why some
> sites think "mother's maiden name" is at all safe is beyond my
> comprehension. And that's not counting the ones that I can't answer
> because I can't find the "NaN" key on my keyboard, like "Surname of
> first girlfriend". *twiddle thumbs*

If you lie to these secret questions -- and I strongly recommend that you 
do -- you should record the answers somewhere so you can retrieve them 
later, long after you've forgotten whether the name of your first pet was 
Obama bin Bush or Tarzan the King of the Desert. Trust me on this, you 
will need them.

The missus has a Yahoo account, and being paranoid even by my standards 
for keeping her web presence completely separate from her real life, she 
invented fake answers to the secret questions like Your Birthday. (As you 
should. It is my opinion that lying to big faceless corporations is not a 
sin, but a duty. They are not on your side, and the more they know about 
you the more they will abuse the knowledge.) So fast forward a few 
months, and the Yahoos at Yahoo put through another bloody round of 
bloody so-called improvements that break everything in sight, including 
people's passwords. So She Who Must Be Obeyed resets her password, except 
now it's *permanently broken* -- no matter how many times she resets her 
password, Yahoo will let her log in *once* then the next time claim the 
password is invalid. 

And then a week or two ago, Yahoo added another piece of broken security 
theatre, and ask you to answer one of those secret questions before 
they'll reset your password. So now SWMBO is locked out of her account 
because she can't remember what she used.

Mind you, Yahoo is rapidly going from Worse to Even Worse, so it was only 
a matter of time before she would have dumped them for good. Still, it's 
annoying -- it's like having your identity stolen by a hermit on some 
mountain top who doesn't do anything with it, except prevent you from 
using it.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 10:44:16 AM UTC-6, Oscar Benjamin wrote:

> Is it on PyPI though? I was referring to a PyPI name so that people
> could install it with "pip install pdeclib" 
> Oscar

hi Oscar, I'm sorry, I completely missed the point of your question. No its not 
on PyPI, but I don't mind putting it there. Are there special instructions, or 
is it fairly straight-forward?

marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Wolfgang Maier
Am Montag, 3. März 2014 12:34:30 UTC+1 schrieb Mark H. Harris:
> hi folks,
> 
> 
> 
> Python Decimal Library dmath.py v0.3 Released
> 
> 
> 
> https://code.google.com/p/pythondecimallibrary/
> 
> 
> 
> This code provides the C accelerated decimal module with 
> 
> scientific/transcendental functions for arbitrary precision. 
> 
> I have also included pilib.py which is a PI library of historic
> 
> algorithms for generating PI, which uses dmath.py. 
> 
> 
> 
> I wish to thank Oscar, Wolfgang, Steven, Chris (and others)
> 
> for the help you gave me understanding decimal, particularly
> 
> format, rounding, and context managers. 
> 

Hi Marcus and thanks for the acknowledgement.
Here's one more suggestion for your code.
Your current implementation of fact() for calculating factorials has nothing to 
offer that isn't provided by math.factorial. Since this is all about Decimal 
calculations, shouldn't you modify it to something like:

def fact(x):
""" fact(x)factorial{x} int x > 0

(x must be integral)
"""
return +Decimal(math.factorial(x))

to make it return a Decimal rounded to context precision?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Steven D'Aprano
On Tue, 04 Mar 2014 02:01:47 +1100, Chris Angelico wrote:

> This is why it's tricky to put rules in based on type inference. The
> programmer's intent isn't in the picture. 

Of course it is. If I assign 23 to variable x, that signals my intent to 
assign an int to x. By Occam's razor, it is reasonable to extrapolate 
that intent to mean "x is an int", rather than "an int, or a list" or "an 
odd int larger than 7 but smaller than 25", or "any int except 13". Type 
inference picks the type which involves the fewest additional 
assumptions. The programmer can always over-ride the type inference by 
explicitly stating the type.

It works really well in practice, because most of the time you don't need 
a lot of type dynamism. Or even any.

Think about the sort of type declarations you have to do in (say) Pascal, 
and consider how stupid the compiler must be:

function add_one(x: integer):integer;
  begin
add_one := x+1;
  end;

Given that x is an integer, and that you add 1 (also an integer) to it, 
is it really necessary to tell the compiler that add_one returns an 
integer? What else could the output type be?

This was state of the art back in 1970, but these days, if the compiler 
cannot *at least* infer the type of the return result of a function given 
the argument types, the static type system is too dumb to bother with. A 
good static type system can even detect infinite loops at compile time:

http://perl.plover.com/yak/typing/notes.html

This is not cutting edge technology: ML dates back to the 1990s, if not 
older.


> If Python ever acquires that
> kind of restriction ("here's a list that can contain only this type /
> these types of object"), I would hope that it's left up to the
> programmer, not the compiler, to stipulate.

That's not type inference. That's ancient and annoying obligatory type 
declarations as used by ancient languages with primitive type systems, 
like Pascal and C.


> That's how it is with Pike
> (if you just say "array", it can take anything), and that's the only way
> to be sure the programmer doesn't have to fight the language.

To be sure, any form of static typing is going to restrict what you can 
do. This isn't intended to imply that static typing is better than 
dynamic typing. But if you have static typing, there's *no point* to it 
if the type system cannot detect bugs, and having to declare types is 
like having to calculate your own GOTO addresses. With a good type system 
like ML or Haskell have, you're not fighting the compiler, *every* type 
error you get is a real, actual bug in your code.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Password validation security issue

2014-03-03 Thread Steven D'Aprano
On Mon, 03 Mar 2014 08:41:10 -0500, Roy Smith wrote:

> In article ,
>  Chris Angelico  wrote:
> 
>> The greatest threats these days are from the network, not from someone
>> physically walking into an office. (That said, though, the low-hanging
>> fruit from walking into an office can be *extremely* tempting. Pulling
>> off a basic password leech off sticky notes is often so easy that it
>> can be done as a visitor, or at least as a pizza deliveryman.)
> 
> Doesn't even require physical presence.  With the ubiquity of various
> video chat applications, as long as the sticky note is in the field of
> view of the camera, you've leaked the password.  With the right
> lighting, I wouldn't be surprised if you could pick up the reflection of
> a sticky note in somebody's eyeglasses.

Let's see now... 

- one in a ten thousand chance that somebody will hack my account because 
it has a weak password; versus

- one in a thousand million chance that somebody will view my strong 
password reflected in my glasses and be able to identify what account 
name for which system it goes with, and be the sort of opportunistic 
black-hat who will use it to break into my account.

Nobody is saying that writing passwords down is secure against every and 
any possible attack. (When the Secret Police smash your door down at 3am, 
you probably won't have time to eat the passwords, even if you remembered 
to print them on rice paper instead of a sticky note.) The concept is 
that writing down strong passwords is preferable to remembering weak 
passwords given the typical threats most people are exposed to.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 4:27 AM, Steven D'Aprano
 wrote:
> On Tue, 04 Mar 2014 02:01:47 +1100, Chris Angelico wrote:
>
>> This is why it's tricky to put rules in based on type inference. The
>> programmer's intent isn't in the picture.
>
> Of course it is. If I assign 23 to variable x, that signals my intent to
> assign an int to x. By Occam's razor, it is reasonable to extrapolate
> that intent to mean "x is an int", rather than "an int, or a list" or "an
> odd int larger than 7 but smaller than 25", or "any int except 13". Type
> inference picks the type which involves the fewest additional
> assumptions. The programmer can always over-ride the type inference by
> explicitly stating the type.

Yes, and that's fine for most purposes. The problem isn't the
inference, the problem is when rules are created based on that kind of
guess - when the programmer's subsequent actions are governed by a
guess the compiler takes.

x = 23 # Compiler goes: Okay, x takes ints.
x += 5 # Compiler: No prob, int += int --> int
x = str(x) # Compiler: NO WAY! str(int) --> str, not allowed!

It's fine and correct to infer that x is an int, x is an int, x is a
str. It's *not* okay to make the third line a SyntaxError because you
just put a str into an int variable.

>> If Python ever acquires that
>> kind of restriction ("here's a list that can contain only this type /
>> these types of object"), I would hope that it's left up to the
>> programmer, not the compiler, to stipulate.
>
> That's not type inference. That's ancient and annoying obligatory type
> declarations as used by ancient languages with primitive type systems,
> like Pascal and C.

And that's exactly what Haskell apparently has, with homogeneous lists
and no easy way to say that it can take more types.

Python's handling is: A list can hold anything.

Pike's handling is: An array can hold anything, unless you specify
otherwise. You can specify whatever you can code:
array(int(1000..2000) | string('a'..'z') | float) foo = ({1234,
"abcd", 1.2});

Haskell's handling apparently is: A list/array can hold one thing and
one thing only. That 'thing' can be a union, but then you need to be
REALLY explicit about which side is which. It's not possible to
sub-specify a type (like the "string('a'..'x')" type in Pike that will
take only strings with nothing but the first 24 lower-case letters -
not that I've ever needed that), but the compiler can work out
everything else.

The way I see it, Python's form is fully dynamic and open, Pike's is
fully dynamic and the programmer's allowed to explicitly close things,
and Haskell's is rigidly tight. That's not to say that tight is a bad
thing (it's probably good for learning under), but personally, I'd
rather have the freedom.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Origin of 'self'

2014-03-03 Thread Terry Reedy

On 3/3/2014 1:16 AM, Westley Martínez wrote:

I understand that in an object method the first argument in the
object itself, called self.  However, it doesn't have to be called
self, and can be called anything.  So my question is why is it called
self and not this like from C++ and Java.  It's kind of a silly
question, but one that I'm curious about nevertheless.


Three responses and I learned or had something pointed out in each. That 
is a better track record than most threads.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Password validation security issue

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 3:46 AM, Steven D'Aprano
 wrote:
> On Tue, 04 Mar 2014 00:55:45 +1100, Chris Angelico wrote:
>
>> But it's an attack vector that MUST be considered, which is why I never
>> tell the truth in any "secret question / secret answer" boxes. Why some
>> sites think "mother's maiden name" is at all safe is beyond my
>> comprehension. And that's not counting the ones that I can't answer
>> because I can't find the "NaN" key on my keyboard, like "Surname of
>> first girlfriend". *twiddle thumbs*
>
> If you lie to these secret questions -- and I strongly recommend that you
> do -- you should record the answers somewhere so you can retrieve them
> later, long after you've forgotten whether the name of your first pet was
> Obama bin Bush or Tarzan the King of the Desert. Trust me on this, you
> will need them.
>
> The missus has a Yahoo account, and being paranoid even by my standards
> for keeping her web presence completely separate from her real life, she
> invented fake answers to the secret questions like Your Birthday. (As you
> should. It is my opinion that lying to big faceless corporations is not a
> sin, but a duty. They are not on your side, and the more they know about
> you the more they will abuse the knowledge.)

I've followed this for a long time. If anything asks for my date of
birth and appears to be just verifying that I'm at least 13 years old,
I'll say Jan 1st in some year that's vaguely near my year of birth.
(This is largely because the drop down combo boxes usually already say
Jan 1st, and it's pointlessly tedious to aim for my exact year, much
less the day within that.) My brother's new wife (married last Nov)
didn't understand this about me when I was helping her port her mobile
phone onto the family account. The system asks me for a date of birth,
and I turn to her and say, "What date of birth did you use?" - and she
looks at me funny, not understanding why I don't already know what to
fill in. But for all I know, she could have set up her mobile account
with a DOB of 1912/6/23 in commemoration of cryptography.

But yes, on the (frequent) occasions when I lie through my teeth, I
usually record my answers as separate passwords.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Terry Reedy

On 3/3/2014 4:42 AM, ast wrote:


Consider following code:


A=7
B=7
A is B


The 'is' operator has three uses, two intended and one not. In 
production code, 'is' tests that an object *is* a particular singular 
object, such as None or a sentinel instance of class object. In test 
code, 'is' can also be used to test details of a particular 
implementation, such as pre-allocation of small ints. New python 
programmers also use it to confuse themselves.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: 3.4rc2 and pip on windows

2014-03-03 Thread Mark Lawrence

On 03/03/2014 00:07, Terry Reedy wrote:

On 3/2/2014 6:55 PM, Mark Lawrence wrote:

Trying to install pyttsx, it doesn't strike me as very clever that, as
seen below, you get "Successfully installed pyttsx" despite the syntax
errors and you can't actually do an import.

c:\Users\Mark\CrossCode>c:\Python34\Scripts\pip3.4.exe install pyttsx
Downloading/unpacking pyttsx
   Downloading pyttsx-1.1.tar.gz
   Running setup.py
(path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\pyttsx\setup.py)
egg_info for package pyttsx

Installing collected packages: pyttsx
   Running setup.py install for pyttsx
   File "C:\Python34\Lib\site-packages\pyttsx\driver.py", line 105
 except Exception, e:
 ^
 SyntaxError: invalid syntax

[other syntax errors snipped]

Successfully installed pyttsx


A bug it seems to me.


Cleaning up...

c:\Users\Mark\CrossCode>py -3.4
Python 3.4.0rc2 (v3.4.0rc2:a300712ed38c, Feb 23 2014, 10:49:04) [MSC
v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pyttsx
Traceback (most recent call last):
   File "", line 1, in 
   File "C:\Python34\lib\site-packages\pyttsx\__init__.py", line 18, in

 from engine import Engine

I've looked at pyttsx in my 3.3 site-packages and it appears that I've
manually run 2to3.  Is this something that could be done automatically
by pip?  Your thoughts please, ladies and gentlemen.


I should hope so.



FTR I raised this as http://bugs.python.org/issue20846 and it was closed 
11 minutes after I raised it.  I won't say anything else as I'm 
extremely tired and irritable and might well regret it later.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 11:23:13 AM UTC-6, Wolfgang Maier wrote:

> def fact(x):
> """ fact(x)factorial{x} int x > 0
>
> return +Decimal(math.factorial(x))

> to make it return a Decimal rounded to context precision?

hi Wolfgang,  I'm not sure.  We're doing some things with very large factorials 
where (existentially) we want to know how many zeros are coming up and the end 
of the very large number (thousands of digits) and 2) what are the last 
significant figures (say twenty of them) that are just before the zero chain.
What I don't want is for the Decimal module to overflow (didn't know it would 
do that), and we don't want the number rounded in scientific notation at some 
number of places. We want to actually see the digits; all of them.
Python will do multiplications til the proverbial cows come home; well, as long 
as you don't try it recursively --- killing the recursive depth. Decimal has 
some limits internally which I still do not understand (and I have been looking 
at the doc and playing with it for hours). If I want to build a BIGNUM int in 
memory only the memory should limit what can be built, not some arbitrary limit 
inside Decimal.
Does any of this make sense?  and 2) can you help me understand the overflow in 
Decimal a little bit better. I know you're a busy guy, maybe you just know a 
link /

Thanks much.
-- 
https://mail.python.org/mailman/listinfo/python-list


pip and distutils2-1.0a4

2014-03-03 Thread Mark H. Harris
hi folks,

I am having a fit with pip this afternoon.  I finally
got pip installed on this system from a binary 
blob (what nightmare, talk about 1987). Anyway,
pip is installed, but when I go to PyPI to pull 
down distutils is gives a message that no such
package exists.   I feel like Obeewan;  "if the archive
computer says your planet is not there, it simply
does not exist".
Can somebody tell me what is the best way to get
distutils downloaded to this system?
Thanks in advance.
Somewhere I heard a rumor that distutils is preloaded
with Py3.3.x /  is this True?  like, I might already have 
it??
thanks again
marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread donarb
On Monday, March 3, 2014 6:28:21 AM UTC-8, Jaap van Wingerde wrote:
> Op  schreef Chris Angelico  
> in bericht 
> :
> 
> > See if ls is actually giving you ctime rather than mtime - compare the
> > results if you ask for os.path.getctime.
> 
> jaap@liakoster:~$ python
> Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import os, time
> >>> from time import gmtime
> >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
> '2014-03-02T19:03:55Z'
> >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html')))
> '2014-03-02T19:03:55Z'
> >>> quit()
> jaap@liakoster:~$ ls --full-time 
> /var/django/test2/art/templates/art_index.html
> -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
> /var/django/test2/art/templates/art_index.html
> jaap@liakoster:~$ 
> 
> ls is giving me the modified time.

You're using the months format '%m' when you should be using minutes '%M'.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip and distutils2-1.0a4

2014-03-03 Thread Mark Lawrence

On 03/03/2014 20:10, Mark H. Harris wrote:

hi folks,

I am having a fit with pip this afternoon.  I finally
got pip installed on this system from a binary
blob (what nightmare, talk about 1987). Anyway,
pip is installed, but when I go to PyPI to pull
down distutils is gives a message that no such
package exists.   I feel like Obeewan;  "if the archive
computer says your planet is not there, it simply
does not exist".
Can somebody tell me what is the best way to get
distutils downloaded to this system?
Thanks in advance.
Somewhere I heard a rumor that distutils is preloaded
with Py3.3.x /  is this True?  like, I might already have
it??
thanks again
marcus



distutils has been part of the standard library for years.

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Ben Finney
Jaap van Wingerde  writes:

> >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
> >>>   
> '2014-03-02T19:03:55Z'
> >>> quit()  
> jaap@liakoster:~$ ls --full-time 
> /var/django/test2/art/templates/art_index.html
> -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
> /var/django/test2/art/templates/art_index.html
> jaap@liakoster:~$ 
> ...
>
> ls gives the right modification time. What is wrong?

You're using ‘gmtime’ to display the Python datetime value, but ‘ls’
will display the time in the local timezone. Do you have a strange
timezone set?

What value does the Python datetime value show in the local timezone?
How does that compare to the time shown by ‘ls’?

-- 
 \  “When cryptography is outlawed, bayl bhgynjf jvyy unir |
  `\  cevinpl.” —Anonymous |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 7:22 AM, donarb  wrote:
> You're using the months format '%m' when you should be using minutes '%M'.

Heh! I didn't even notice that. When I tested it, I didn't use
strftime at all, just looked at gmtime's output.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Ben Finney
Rustom Mody  writes:

> Short answer: Avoid using 'is'. 

This is bad advice in a Python forum.

The ‘is’ operator is commonly used in Python, so please don't advise
against it in an unqualified “short answer”.

> Long answer: 
> http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html

Interesting, but mostly a distraction for the querent here.

Short answer: Use ‘use’ any time you need to compare object identity.
You usually do not need to compare object identity.

-- 
 \“Some people, when confronted with a problem, think ‘I know, |
  `\   I'll use regular expressions’. Now they have two problems.” |
_o__)   —Jamie Zawinski, in alt.religion.emacs |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 2:03:19 PM UTC-6, Mark H. Harris wrote:
> On Monday, March 3, 2014 11:23:13 AM UTC-6, Wolfgang Maier wrote:

Wolfgang,  answer is not so much, in fact, not at all. 
But it is an interesting question for me; where I am 
continuing to learn the limits of Decimal, and the 
decimal context. I don't need rounding for integer 
multiplication, of course. 

I am interested in arbitrary limits, like emax, for instance. 
The doc is a little ambiguous. Is emax the max exponent, 
and if so, is 9 the limit, or is that the default 
context value which might be bumped up? 
If so, why have a limit on the emin & emax values?
I'm playing with it. Shouldn't a Decimal value 
be able to continue to grow to the limit of memory if we 
wanted to be silly about it? According to the doc 'clamping'
occurs if the exponent falls outside the range of emin &  
emax (what is overflow vs clamping ?) if the significant digits
are allowed to grow and grow? Well, the doc then states that
overflow occurs if we blow past the emax exponent value?
What is the difference between overflow and clamping? Am
I able to set emin & emax arbitrarily high or low? 

I have discovered just by playing with integer multiplication 
that those BIGNUMS don't seem to have a physical limit. Of 
course there isn't a decimal to keep track of, and they can 
just grow and grow; wouldn't want to make a Decimal from 
one of those, other than it is interesting to me as I'm trying
to understand Decimal floating point.  

marcus


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Tim Chase
On 2014-03-04 08:10, Ben Finney wrote:
> > Long answer:
> > http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html  
> 
> Interesting, but mostly a distraction for the querent here.
> 
> Short answer: Use ‘use’ any time you need to compare object
> identity. You usually do not need to compare object identity.

I think there use something wrong with that sentence...unless there
usen't. ;-)

-tkc


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip and distutils2-1.0a4

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 2:53:00 PM UTC-6, Mark Lawrence wrote:

> distutils has been part of the standard library for years.

hi Mark, that's fabulous, why can't I import it? Because I'm doing 
something wrong of course.   :)

marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Ben Finney
Tim Chase  writes:

> On 2014-03-04 08:10, Ben Finney wrote:
> > Short answer: Use ‘use’ any time you need to compare object
> > identity. You usually do not need to compare object identity.

Damn it, a snappy response marred by a typo.

> I think there use something wrong with that sentence...unless there
> usen't. ;-)

That use correct. Thanks, Tim :-)

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__) highwayman.” —Anthony Taylor |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip and distutils2-1.0a4

2014-03-03 Thread Robert Kern

On 2014-03-03 21:20, Mark H. Harris wrote:

On Monday, March 3, 2014 2:53:00 PM UTC-6, Mark Lawrence wrote:


distutils has been part of the standard library for years.


hi Mark, that's fabulous, why can't I import it? Because I'm doing
something wrong of course.   :)


Probably. If you want us to help, you need to show us what you tried, tell us 
what results you expected, and copy-paste the output that you got.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Mark Lawrence

On 03/03/2014 21:10, Ben Finney wrote:

Rustom Mody  writes:


Short answer: Avoid using 'is'.


This is bad advice in a Python forum.

The ‘is’ operator is commonly used in Python, so please don't advise
against it in an unqualified “short answer”.


Long answer: 
http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html


Interesting, but mostly a distraction for the querent here.

Short answer: Use ‘use’ any time you need to compare object identity.
You usually do not need to compare object identity.



That last paragraph is as clear as mud.

I'd just like to know why people are so obsessed with identities, I've 
never thought to use them in 10+ years of writing Python.  Do I use the 
KISS principle too often?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
https://mail.python.org/mailman/listinfo/python-list


Re: pip and distutils2-1.0a4

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote:

> Probably. If you want us to help, you need to show us what you tried, tell us 
> what results you expected, and copy-paste the output that you got.

> Robert Kern

hi Robert,  well, I finally came up with trying to find setup().  Its a part of 
distutils.core. So, I tried:

from distutils.core import setup
from distutils import *

Then I tried to run setup() --help-commands and python3 crashed.

What did I do wrong?   running Py3.3.4

Thanks, marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why indentation should be part of the syntax

2014-03-03 Thread BartC



"Stefan Behnel"  wrote in message 
news:mailman.7568.1393756930.18130.python-l...@python.org...

Haven't seen any mention of it on this list yet, but since it's such an
obvious flaw in quite a number of programming languages, here's a good
article on the recent security bug in iOS, which was due to accidentally
duplicated code not actually being as indented as it looked:

https://www.imperialviolet.org/2014/02/22/applebug.html


Indentation is actually a little more fragile than block-delimited source 
code. (Press Delete inadvertently so that a tab disappears, and the code 
might still be valid, but is now wrong.)


Perhaps indentation /and/ block-delimiting would be more robust.

(And the link shows a bad example: the error should have been picked up 
anyway, but the language not only doesn't require formal indentation, but it 
uses optional block ({}) delimiters, another source of errors. Having an 
undifferentiated } to close all kinds of blocks doesn't help either.


--
Bartc 


--
https://mail.python.org/mailman/listinfo/python-list


Re: pip and distutils2-1.0a4

2014-03-03 Thread Roy Smith
In article <31feb451-7fb6-48a6-9986-bddce69c4...@googlegroups.com>,
 "Mark H. Harris"  wrote:

> On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote:
> 
> > Probably. If you want us to help, you need to show us what you tried, tell 
> > us 
> > what results you expected, and copy-paste the output that you got.
> 
> > Robert Kern
> 
> hi Robert,  well, I finally came up with trying to find setup().  Its a part 
> of 
> distutils.core. So, I tried:
> 
> from distutils.core import setup
> from distutils import *
> 
> Then I tried to run setup() --help-commands and python3 crashed.
> 
> What did I do wrong?   running Py3.3.4
> 
> Thanks, marcus

General advice to everybody who asks questions.  Please don't *describe* 
what you did.  *Show* us what you did.  Run your commands in a terminal 
window and then copy-and-paste everything that you typed and everything 
that got printed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Tim Chase
On 2014-03-03 21:35, Mark Lawrence wrote:
> I'd just like to know why people are so obsessed with identities,
> I've never thought to use them in 10+ years of writing Python.  Do
> I use the KISS principle too often?

There are a couple use-cases I've encountered where "is" matters:

1) the most popular:

  if foo is None:
do_stuff()

2) sentinels (which are effectively non-None None values)

  SENTINEL = object()

  def myfuntion(value=SENTINEL):
if value is SENTINEL:
  do_something_parameterless()
else:
  do_something_else(value) # allow for value=None

3) when doing recursion and you want to prevent touching the same
object multiple times, such as what happens when you do

  lst = [1,2,3]
  lst.append(lst)
  print(lst)

and it needs to recognize that the final element of "lst" is one that
it has already seen (as done by identity).


There might be some other use cases, but #1 is a good 95% of my
usage, #2 is a good 4%, and I can only think of once in my Python
career when I've needed to do what is described in #3.

-tkc





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to get bytes from bytearray without copying

2014-03-03 Thread Cameron Simpson
On 03Mar2014 09:15, Juraj Ivančić  wrote:
> On 3.3.2014. 1:44, Cameron Simpson wrote:
> >>ValueError: cannot hash writable memoryview object
> >
> >Have you considered subclassing memoryview and giving the subclass
> >a __hash__ method?
> 
> I have, and then, when I failed to subclass it, I considered doing
> aggregation, and make it behave byte-like. But how to implement the
> overridden __hash__ method? It will still require at least *some*
> redundant copying. And there is the slicing thing... the whole idea
> started to feel like I was performing tonsillectomy through the anal
> cavity.

Write a wrapper class instead and use:

  def __hash__(self):
return id(self)

Simple and fast. Unless you need slices with the same content to
hash the same (eg storing them as dict keys, or in sets).

And alternative would be a simple hash of the first few bytes in
whatever slice you had.

Cheers,
-- 
Cameron Simpson 

Why is it so hard for people to simply leave people alone? But, the answer
comes to me: they are idiots and in a perfect world, I would be permitted to
kill them all.  - Julie Rhodes 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Jerry Hill
On Mon, Mar 3, 2014 at 4:51 PM, Tim Chase  wrote:
> There are a couple use-cases I've encountered where "is" matters:
>
> 1) the most popular:
>
>   if foo is None:
> do_stuff()

I know this is the one that always comes up, but honestly, I feel like
"is" doesn't matter here.  That code would be just as correct if it
was written as:

if foo == None:
do_stuff()

The only time it would give you a different result from the "is"
version is if foo was bound to an object that returned True when
compared with None.  And if that were the case, I'm still not
convinced that you can tell from looking at those two lines of code
which one is buggy, except for the fact that there has been 20 years
of custom saying that comparing to None with equality is wrong.

-- 
Jerry
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Gregory Ewing

Steven D'Aprano wrote:
Given that x is an integer, and that you add 1 (also an integer) to it, 
is it really necessary to tell the compiler that add_one returns an 
integer? What else could the output type be?


Just because the compiler *can* infer the return type
doesn't necessarily mean it *should*. When I was playing
around with functional languages, I ended up adopting the
practice of always declaring the types of my functions,
because it helps the *human* reader. (It also helped the
compiler produce comprehensible error messages in the
event of a type error.)

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Marko Rauhamaa
Mark Lawrence :

> I'd just like to know why people are so obsessed with identities, I've
> never thought to use them in 10+ years of writing Python.  Do I use the
> KISS principle too often?

Calmly choosing the right tool for the job is not an obsession.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip and distutils2-1.0a4

2014-03-03 Thread Robert Kern

On 2014-03-03 21:37, Mark H. Harris wrote:

On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote:


Probably. If you want us to help, you need to show us what you tried, tell us
what results you expected, and copy-paste the output that you got.



Robert Kern


hi Robert,  well, I finally came up with trying to find setup().  Its a part of
distutils.core. So, I tried:

from distutils.core import setup
from distutils import *

Then I tried to run setup() --help-commands and python3 crashed.

What did I do wrong?   running Py3.3.4


You don't run `setup() --help-commands` in the Python interpreter. 
`--help-commands` is a command-line argument to the setup.py script that you 
will write. It is not Python syntax. Please read the documentation.


  http://docs.python.org/3/distutils/index.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 3:18:37 PM UTC-6, Mark H. Harris wrote:

Yeah, you can set Emin & Emax enormously large (or small), can set
off overflow, and set clamping. 

I am needing a small utility (tk?) that will allow the context to be set
manually by the interactive user dynamically (for a particular problem).
Its like, one context doesn't fit all.  Some of the pdeclib funcs will need
to take into account the various signals also. 

The context manger is fabulous, but not for the average user; all the
try block stuff is encapsulated (which makes the coding clean) but it
is not obvious in any way what is happening with __init__() , __enter__()
and __exit__() (although I did find a couple of good articles on the
subject. The 'with localcontext(cts=None) as ctx' is genius, but not
for the average user who just wants to get work done with python.

So, the bottom line is we have this fabulous speedy decimal module
that is nothing short of wonderful for experts, and completely out
of the grasp of average users relatively new to python or with 
limited experience with decimal floating point arithmetic. "They would
like to sing soft and sweet, like the cucumber, but they can't!"

So, we need a complete wrapper around the decimal module (or better
yet we need to make decimal floating point default) so that average 
users may take advantage of precise floating point math without 
having to be experts on decimal floating point arithmetic constraints
in the new high speed module.:-}

marcus
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 3.4rc2 and pip on windows

2014-03-03 Thread Zachary Ware
On Mon, Mar 3, 2014 at 1:47 PM, Mark Lawrence  wrote:
> FTR I raised this as http://bugs.python.org/issue20846 and it was closed 11
> minutes after I raised it.  I won't say anything else as I'm extremely tired
> and irritable and might well regret it later.

Best I can tell, the issue was closed correctly.  It doesn't look like
a Python or Pip bug, it looks like a bug in pyttsx's packaging.  Based
on empirical data [1], Pip does properly take care of running 2to3,
but *only when told to do so*.  Pip can't decide whether it should run
2to3 when it hasn't been told either way, because it's not safe.  It
can't try compiling .py files and running 2to3 if it gets
SyntaxErrors, because what if the SyntaxError is just a SyntaxError,
and not a ThisHasntBeenPortedToPython3Error?  Then 2to3 might blow up,
possibly leaving things in a state that makes the underlying issue
very hard to find.  It can't try importing the installed package,
because what if importing without specific external state in place has
ugly side-effects?  Pip can't safely do anything it's not told to do
with the packages it installs because then responsibility for the fire
in your hard drive could be laid at Pip's feet, not the evil evil
package author who wrote the code that started the fire.

It could be argued that Pip could compile any .py files that it
installs and just start screaming if it gets any SyntaxError, but what
if your package (for some weird reason) relies on .py file with bad
syntax?

I don't think Python itself is involved at all here, and I think Pip
is doing the right thing.  Everything installed successfully into the
right place (since `import pyttsx` did find the package); the fact
that it SyntaxError'd out is on the package author.

My 0.02USD, anyway.

-- 
Zach

[1] `pip install sphinx` from a 3.4 venv
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Ben Finney
Jerry Hill  writes:

> if foo == None:
> do_stuff()
>
> The only time it would give you a different result from the "is"
> version is if foo was bound to an object that returned True when
> compared with None.

That's right. Python provides this singleton and then recommends you
compare with ‘is’, precisely to protect against pathological cases like
a “return True when compared for equality with None” data type.

Using ‘if foo is None’ means you don't even have to spend time worrying
about such cases.

> And if that were the case, I'm still not convinced that you can tell
> from looking at those two lines of code which one is buggy, except for
> the fact that there has been 20 years of custom saying that comparing
> to None with equality is wrong.

Yes. And because of that widespread convention, it's much more correct
to compare against None with ‘is’.

-- 
 \   “Always do right. This will gratify some people, and astonish |
  `\the rest.” —Mark Twain |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Ben Finney
Marko Rauhamaa  writes:

> Mark Lawrence :
>
> > I'd just like to know why people are so obsessed with identities, I've
> > never thought to use them in 10+ years of writing Python.  Do I use the
> > KISS principle too often?
>
> Calmly choosing the right tool for the job is not an obsession.

Persistently banging your head in contradiction to the facts of Python's
data model, as you have been doing, starts to look very much like
obsession.

-- 
 \“Please to bathe inside the tub.” —hotel room, Japan |
  `\   |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Wolfgang Maier
On Monday, March 3, 2014 9:03:19 PM UTC+1, Mark H. Harris wrote:
> On Monday, March 3, 2014 11:23:13 AM UTC-6, Wolfgang Maier wrote:
> > def fact(x):
> > """ fact(x)factorial{x} int x > 0
> >
> > return +Decimal(math.factorial(x)
> > to make it return a Decimal rounded to context precision?
> 
> hi Wolfgang,  I'm not sure.  We're doing some things with very large 
> factorials where (existentially) we want to know how many zeros are coming up 
> and the end of the very large number (thousands of digits) and 2) what are 
> the last significant figures (say twenty of them) that are just before the 
> zero chain.

That's ok, but I do not understand
- why you shouldn't be able to use math.factorial for this purpose and
- why a factorial function accepting and returning ints should be part of your 
dmath package.

math.factorial is accurate and faster than your pure-Python function, 
especially for large numbers. Compare:
>>> a = math.factorial(10)
and your
>>> b = fact(10)

> What I don't want is for the Decimal module to overflow (didn't know it would 
> do that), and we don't want the number rounded in scientific notation at some 
> number of places. We want to actually see the digits; all of them.

Well, that may be your use-case, but then math.factorial is for you.
On the other hand, you may be interested in getting context-rounded factorials 
and rounding to context precision is what you'd expect from a Decimal function, 
so, logically, that's how it should be implemented in your package if you think 
it needs to have a fact function (which I'm not sure of).

> Python will do multiplications til the proverbial cows come home; well, as 
> long as you don't try it recursively --- killing the recursive depth.

While that's true you pay a heavy price for abusing this feature in terms of 
performance because with VERY large integers there will be just too much memory 
shuffling activity. (I haven't looked into how math.factorial handles this 
internally, but it's certainly performing much better for large numbers than 
Python integer multiplication.

Best,
Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Marko Rauhamaa
Jerry Hill :

> except for the fact that there has been 20 years of custom saying that
> comparing to None with equality is wrong.

"if foo == None" is not wrong in any manner. It's just that if you are
comfortable with the "is" operator and its semantics, "if foo is None"
is slightly more natural.

You generally use "==" if more than one object could be equal. If you
know there's only one object of the kind, you convey that knowledge by
the use of "is" even when functionally, it doesn't matter.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How security holes happen

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson  wrote:
> On 03Mar2014 09:17, Neal Becker  wrote:
>>  Charles R Harris  Wrote in message:
>> >
>>
>> Imo the lesson here is never write in low level c. Use modern
>>  languages with well designed exception handling.
>
> What, and rely on someone else's low level C?

Someone needs to port Python to LISP.

And then write a LISP interpreter in JavaScript.

And an ECMAScript engine in Pike.

And a Pike interpreter in Java.

And a Java run-time written in ActionScript.

It's turtles all the way down...

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Ben Finney
Marko Rauhamaa  writes:

> Jerry Hill :
>
> > except for the fact that there has been 20 years of custom saying that
> > comparing to None with equality is wrong.
>
> "if foo == None" is not wrong in any manner.

Marko, please don't keep asserting falsehoods. It's already been pointed
out in this forum many times, essentially since the forum existed, why
what you say here is false.

-- 
 \  “The fact that I have no remedy for all the sorrows of the |
  `\ world is no reason for my accepting yours. It simply supports |
_o__)  the strong probability that yours is a fake.” —Henry L. Mencken |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How security holes happen

2014-03-03 Thread Cameron Simpson
On 03Mar2014 09:17, Neal Becker  wrote:
>  Charles R Harris  Wrote in message:
> > 
> 
> Imo the lesson here is never write in low level c. Use modern
>  languages with well designed exception handling.

What, and rely on someone else's low level C?
-- 
Cameron Simpson 

Hag:Two things you must know about the wise woman.
First...she is a woman.  Second...she is...
Edmund Blackadder:  Wise?
Hag:Oh! You know her then?
Edmund Blackadder:  No, just a stab in the dark, which is what you'll be
getting in a minute if you don't become more helpful.
   - Edmund Blackadder to Old Hag, Bells, BA2
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 9:22 AM, Marko Rauhamaa  wrote:
> You generally use "==" if more than one object could be equal. If you
> know there's only one object of the kind, you convey that knowledge by
> the use of "is" even when functionally, it doesn't matter.

It's even simpler than that.

You use "==" when you care about value, and "is" when you care about identity.

This is because "==" tests value, and "is" tests identity.

I do not understand why there is confusion.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 9:31 AM, Ben Finney  wrote:
> def frobnicate(flang, splets, queeble=False):
> """ Righteously frobnicate the flang.
>
> :param flang: A file-like object, opened for reading.

I had to read that a few times before I was sure that you actually
meant "file" there, you used a real word with its real meaning!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Wolfgang Maier
On Monday, March 3, 2014 10:18:37 PM UTC+1, Mark H. Harris wrote:
> On Monday, March 3, 2014 2:03:19 PM UTC-6, Mark H. Harris wrote:
> 
> Wolfgang,  answer is not so much, in fact, not at all. 
> But it is an interesting question for me; where I am 
> continuing to learn the limits of Decimal, and the 
> decimal context. I don't need rounding for integer 
> multiplication, of course.
>
 
You don't want it and you don't get it for integer multiplication, but you may 
get it with Decimal multiplication and not high-enough precision:

>>> with localcontext() as ctx:
ctx.prec=2
Decimal(11)*Decimal(11)

Decimal('1.2E+2')

This is the very nature of rounding to context precision and functions dealing 
with Decimals shouldn't behave differently in my opinion. If you don't want 
rounding either use sufficiently high precision or use integers.

> 
> I am interested in arbitrary limits, like emax, for instance. 
> The doc is a little ambiguous. Is emax the max exponent, 
> and if so, is 9 the limit, or is that the default 
> context value which might be bumped up? 
>

I don't find much ambiguity in the docs here:

" class decimal.Context(prec=None, rounding=None, Emin=None, Emax=None, 
capitals=None, clamp=None, flags=None, traps=None)

Creates a new context. If a field is not specified or is None, the default 
values are copied from the DefaultContext. If the flags field is not specified 
or is None, all flags are cleared.
..
The Emin and Emax fields are integers specifying the outer limits allowable 
for exponents. Emin must be in the range [MIN_EMIN, 0], Emax in the range [0, 
MAX_EMAX]."

So, Emax is the maximal exponent allowed in a specific context and the constant 
MAX_EMAX is the maximum Emax that you can set in any context.
Also (on my system):

>>> from decimal import getcontext
>>> getcontext()

Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-99, Emax=99, 
capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, 
Overflow])

shows that my default context Emax is way smaller than MAX_EMAX.


> I have discovered just by playing with integer multiplication  
> that those BIGNUMS don't seem to have a physical limit. Of 
> course there isn't a decimal to keep track of, and they can 
> just grow and grow; wouldn't want to make a Decimal from 
> one of those, other than it is interesting to me as I'm trying
> to understand Decimal floating point.
>

decimal can handle BIGNUMS fairly well, you just need to increase context Emax. 
Have you ever tried to calculate stuff with ints as big as MAX_EMAX 
(10**99) or even close to it and still had a responsive system 
??
My point in suggesting the fix for your epx function was that the unnecessary 
juggling of extremely large values (Decimal or int) is a killer for performance.

> marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python decimal library dmath.py v0.3 released

2014-03-03 Thread Mark H. Harris
On Monday, March 3, 2014 4:15:39 PM UTC-6, Wolfgang Maier wrote:

> Well, that may be your use-case, but then math.factorial is for you.

> On the other hand, you may be interested in getting 
> context-rounded factorials and rounding to context 
> precision is what you'd expect from a Decimal function, 
> so, logically, that's how it should be implemented in your 
> package if you think it needs to have a fact function (which I'm not sure of).


hi Wolfgang,  you are absolutely right. I see what you're getting at
now. I've stuffed something into the library that really does not
belong in that library; it was just convenient for me. I get that.

marcus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functional programming

2014-03-03 Thread Ben Finney
Gregory Ewing  writes:

> Just because the compiler *can* infer the return type doesn't
> necessarily mean it *should*. When I was playing around with
> functional languages, I ended up adopting the practice of always
> declaring the types of my functions, because it helps the *human*
> reader.

Sure. In a duck-typed language like Python, it is still helpful to the
human reader to document the *meaning* of each parameter, beyond what is
indicated by the name. We have reStructuredText and docstrings for this
purpose.

def frobnicate(flang, splets, queeble=False):
""" Righteously frobnicate the flang.

:param flang: A file-like object, opened for reading.
:param splets: A sequence of unprocessed Splet instances.
:param queeble: If ``True``, re-vitrify the flang during
frobnication.
:return: A new list of processed Splet instances.

The flang is frobnicated according to the Weebly-Ruckford
algorithm.

"""
for line in flang:
…

> (It also helped the compiler produce comprehensible error messages in
> the event of a type error.)

Docstrings in the above reStructuredText field-list style will be
processed by Epydoc http://epydoc.sourceforge.net/fields.html>.

Other styles of specifying parameters in an mechanically-extractable
form are also used, by Sphinx for example. The point is, we have
docstrings, and conventions in docstrings for specifying parameters for
the human reader *and* for automated tools to read.

-- 
 \“… Nature … is seen to do all things Herself and through |
  `\ herself of own accord, rid of all gods.” —Titus Lucretius |
_o__) Carus, c. 40 BCE |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How security holes happen

2014-03-03 Thread Mark Lawrence

On 03/03/2014 22:25, Chris Angelico wrote:

On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson  wrote:

On 03Mar2014 09:17, Neal Becker  wrote:

  Charles R Harris  Wrote in message:




Imo the lesson here is never write in low level c. Use modern
  languages with well designed exception handling.


What, and rely on someone else's low level C?


Someone needs to port Python to LISP.

And then write a LISP interpreter in JavaScript.

And an ECMAScript engine in Pike.

And a Pike interpreter in Java.

And a Java run-time written in ActionScript.

It's turtles all the way down...

ChrisA



Or write every language in Applescript which has 42 not very obvious 
ways of doing each and everything.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
https://mail.python.org/mailman/listinfo/python-list


Re: How security holes happen

2014-03-03 Thread Chris Kaynor
On Mon, Mar 3, 2014 at 2:25 PM, Chris Angelico  wrote:

> On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson  wrote:
> > On 03Mar2014 09:17, Neal Becker  wrote:
> >>  Charles R Harris  Wrote in message:
> >> >
> >>
> >> Imo the lesson here is never write in low level c. Use modern
> >>  languages with well designed exception handling.
> >
> > What, and rely on someone else's low level C?
>
> Someone needs to port Python to LISP.
>
> And then write a LISP interpreter in JavaScript.
>
> And an ECMAScript engine in Pike.
>
> And a Pike interpreter in Java.
>
> And a Java run-time written in ActionScript.
>
> It's turtles all the way down...
>

You can go much simpler than that. Merely port Python to LISP, then write a
LISP interpreter in Python. Done.

Now, bootstrapping those interpreters might pose a bit of a challenge...


>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Roy Smith
In article ,
 Ben Finney  wrote:

> That's right. Python provides this singleton and then recommends you
> compare with ‘is’, precisely to protect against pathological cases like
> a “return True when compared for equality with None” data type.

Going off on a tangent, I've often wished Python provided more kinds of 
None-ness.  I'll often write:

def f(arg=None):
   whatever

where it would be nice to differentiate between "this was called with no 
arguments" and "this was called with an argument of None".  Sure, I can 
work around that with things like **kwargs, and then test

"args" in kwargs

vs.

kwargs["args"] is None

but that always feels clumsy.  It also makes the function declaration 
less sell-describing.  "Hmmm, let's see what help() says.  Oh, gee, I 
can pass it some stuff".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How security holes happen

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 9:55 AM, Chris Kaynor  wrote:
> You can go much simpler than that. Merely port Python to LISP, then write a
> LISP interpreter in Python. Done.

Actually, here's an easier way. Just write an 80x86 assembly language
interpreter in Python, then port CPython to Python.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How security holes happen

2014-03-03 Thread Roy Smith
In article ,
 Cameron Simpson  wrote:

> On 03Mar2014 09:17, Neal Becker  wrote:
> >  Charles R Harris  Wrote in message:
> > > 
> > 
> > Imo the lesson here is never write in low level c. Use modern
> >  languages with well designed exception handling.
> 
> What, and rely on someone else's low level C?

Don't laugh.  http://c2.com/cgi/wiki?TheKenThompsonHack
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reference

2014-03-03 Thread Chris Angelico
On Tue, Mar 4, 2014 at 10:02 AM, Roy Smith  wrote:
> In article ,
>  Ben Finney  wrote:
>
>> That's right. Python provides this singleton and then recommends you
>> compare with ‘is’, precisely to protect against pathological cases like
>> a “return True when compared for equality with None” data type.
>
> Going off on a tangent, I've often wished Python provided more kinds of
> None-ness.  I'll often write:
>
> def f(arg=None):
>whatever
>
> where it would be nice to differentiate between "this was called with no
> arguments" and "this was called with an argument of None".

That's why you have your own sentinel.

_NONE_PASSED=object()
def f(arg=_NONE_PASSED):
if f is not _NONE_PASSED: pass

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   >