RE: What are your opinions on .NET Core vs Python?

2017-01-29 Thread Deborah Swanson
Juan C. wrote, on Saturday, January 28, 2017 7:07 PM
> 
> As you guys might know, .NET Core is up and running, 
> promising a "cross-platform, unified, fast, lightweight, 
> modern and open source experience" (source: .NET Core 
> official site). What do you guys think about it? Do you think 
> it will be able to compete with and overcome Python in the 
> opensource medium?

I don't really know what .NET does these days, but looking at the list
of languages it supports:
https://en.wikipedia.org/wiki/List_of_CLI_languages#Current_Languages
I don't see any I'd likely want to use instead of Python, with the
possible exception of IronPython. A few people on this list have
mentioned it, but I don't really see any good reason to paste any
version of Python onto some other kind of system. Unless maybe you're
required to use that system for some other reason.

Most of the languages on this "List_of_CLI_languages" supported by .NET
have already been shown to my satisfaction to have been overtaken and
subsumed by Python. It's a good thing that .NET's framework has shed
some baggage, which was sorely needed, but what really matters is what
you can do with it. And given the choices of languages available in
.NET, in most cases I think you'd be better off working in straight
Python. You can't put lipstick on a pig. It will still be a pig, even if
you give it flashy sunglasses and put it on jetskis.

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Grant Edwards :

> On 2017-01-28, Marko Rauhamaa  wrote:
>
>> (Although if I were to design an operating system, I don't know if I
>> would bother with controlling terminals, job control or chirping
>> modems.)
>
> I've been using serial ports on Unix for 35 years, and maintaining
> serial drivers for Linux for almost 20. Many days, it seems like the
> tty/serial API in Unix is the rug under which all the ugly dirt got
> swept...
>
> [...]
>
> It's really pretty impressive how orthogonal they did manage to make
> things.

I *have* been longing for a serial console in linux distros. That would
make it possible to set up virtual machines from ISO images
automatically as virtualization environments can emulate a serial
interface with an SSH connection. As it stands, such automation requires
ugly, brittle VNC tricks.


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


Fwd: What are your opinions on .NET Core vs Python?

2017-01-29 Thread Gerald Britton
>
> As you guys might know, .NET Core is up and running, promising a
> "cross-platform, unified, fast, lightweight, modern and open source
> experience" (source: .NET Core official site). What do you guys think about
> it? Do you think it will be able to compete with and overcome Python in the
> opensource medium?


It's an apples/oranges comparison.

.NET is a library that can be used from many languages, including Python.
 (Not just IronPython, but also Python for .NET (pythonnet.sourceforge*.*net
*))*

Python is a language that can use many libraries, including .NET

The set of libraries that can be used from all the languages that can also
use .NET (out of the box, that is) is smaller.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How coding in Python is bad for you

2017-01-29 Thread BartC

On 29/01/2017 01:35, pavlovevide...@gmail.com wrote:

On Monday, January 23, 2017 at 9:24:56 AM UTC-8, bream...@gmail.com wrote:

The article is here http://lenkaspace.net/index.php/blog/show/111

Kindest regards.

Mark Lawrence.


I remember the old days of Python when it was just Perl's little brother.  
Sometimes I feel moments of amazement whenever someone makes this much of an 
effort to badmouth it (and this blog is definitely badmouthing it, very little 
of criticism is reasonable).


I think it's completely reasonable for anyone to criticise Python if 
they want (or any other computer language for that matter).


(And it didn't cover that much; I could do a far more in-depth critique 
if I wanted.)


What might be unreasonable is to criticise it in a /Python/ group full 
of language aficionados who are going to view every feature and quirk of 
the language in a good light; nothing is ever a problem!


But the author of piece didn't post it here.

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


Re: How coding in Python is bad for you

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 12:05 AM, BartC  wrote:
> On 29/01/2017 01:35, pavlovevide...@gmail.com wrote:
>>
>> On Monday, January 23, 2017 at 9:24:56 AM UTC-8, bream...@gmail.com wrote:
>>>
>>> The article is here http://lenkaspace.net/index.php/blog/show/111
>>>
>>> Kindest regards.
>>>
>>> Mark Lawrence.
>>
>>
>> I remember the old days of Python when it was just Perl's little brother.
>> Sometimes I feel moments of amazement whenever someone makes this much of an
>> effort to badmouth it (and this blog is definitely badmouthing it, very
>> little of criticism is reasonable).
>
>
> I think it's completely reasonable for anyone to criticise Python if they
> want (or any other computer language for that matter).
>
> (And it didn't cover that much; I could do a far more in-depth critique if I
> wanted.)
>
> What might be unreasonable is to criticise it in a /Python/ group full of
> language aficionados who are going to view every feature and quirk of the
> language in a good light; nothing is ever a problem!
>
> But the author of piece didn't post it here.

It's completely reasonable for someone to critique Python. It's not
reasonable to post a bunch of baseless FUD, regardless of your forum.

There's plenty in Python that you can legitimately criticise.
Sometimes you'll get a response of "actually this is good, because X,
Y, Z"; sometimes you get "well, what you suggest is marginally better,
but not enough to justify breaking backward compatibility"; and
sometimes you get "good point, maybe we can change that in the next
version - want to write a patch?". But when all your criticisms are
either (a) true of virtually every programming language, yet you claim
they're Python's faults; or (b) actually false, you just make yourself
look like a troll.

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


Re: How coding in Python is bad for you

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 12:05 am, BartC wrote:

> What might be unreasonable is to criticise it in a Python group full
> of language aficionados who are going to view every feature and quirk of
> the language in a good light; 

It's all about the trade-offs we choose to make. Its not that we don't
understand that feature X has a downside; its that we value that feature
enough to make up for it.


> nothing is ever a problem! 

1. for...else is misspelled, and should be for...then;

2. Same for while...else;

3. shutil.get_terminal_size() is broken by design;

4. Decimal is not integrated with the numeric tower;

5. The statistics module is too slow (and if I ever meet the author, I'll
give him a kick in the head);

6. duck-typing with numbers often fails, requiring you to resort to
polymorphic code with type checking;

7. which is too slow;

8. fractions could easily support infinities (±1/0) and NAN (0/0) but don't;

9. the state of GUI toolkits in 2017 is nowhere near as easy to use as
Hypercard in 1986 (although that doesn't apply just to Python);

10. packaging is still too complex and hard to get right;

11. the last couple of years has seen an emphasis on asynchronous
programming that I don't understand and scares me;

12. there's no try...except expression;

13. or constants;

14. writing bullet-proof file handling code (e.g. atomic file save that
either is guaranteed to write to the disk or guaranteed to leave the
previous file contents in place) is too hard;

15. str.centre() is misspelled;

16. despite what the Zen says, there aren't enough namespaces;

17. unicodedata is missing a lot of functionality;

18. CPython makes object IDs look like memory addresses;

19. there's no way to tell the compiler to do certain calculations at
compile-time, instead of run-time;

20. the utf-8 encoder is strict, but the utf-16 and utf-32 encoders are not,
which makes them technically non-compliant;

21. the CPython compiler isn't smart enough, and so has to forgo the
opportunity for optimizations which apply 99.9% of the time, because of the
0.1% of the time that they don't apply (e.g. in-lining functions);

22. there's no syntax for Design By Contract;

23. no support for Snobol/Icon like string patterns (BNF context-free
grammars, more powerful than regular expressions);

24. lack of support for Prolog-like logic programming paradigm;

25. no way to bail out of generator expressions early, e.g. (expr for x in
seq while condition);

26. the glob module doesn't support escaping, or {a,b,c} alternatives;

27. in hindsight, all() and any() shouldn't coerce their result to True or
False, but return a truthy or falsey value from their inputs.


That's just off the top of my head. Is that enough for you?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Marko Rauhamaa  wrote:
> Grant Edwards :
>
>> On 2017-01-28, Marko Rauhamaa  wrote:
>>
>>> (Although if I were to design an operating system, I don't know if I
>>> would bother with controlling terminals, job control or chirping
>>> modems.)
>>
>> I've been using serial ports on Unix for 35 years, and maintaining
>> serial drivers for Linux for almost 20. Many days, it seems like the
>> tty/serial API in Unix is the rug under which all the ugly dirt got
>> swept...
>>
>> [...]
>>
>> It's really pretty impressive how orthogonal they did manage to make
>> things.
>
> I *have* been longing for a serial console in linux distros.

Well, all it takes is a tweak to the bootloader to add a kernel
"command-line" parameter...

> That would make it possible to set up virtual machines from ISO
> images automatically as virtualization environments can emulate a
> serial interface with an SSH connection. As it stands, such
> automation requires ugly, brittle VNC tricks.

-- 
Grant


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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Grant Edwards :

> On 2017-01-29, Marko Rauhamaa  wrote:
>> I *have* been longing for a serial console in linux distros.
>
> Well, all it takes is a tweak to the bootloader to add a kernel
> "command-line" parameter...

Can you give me a short Python script that effects the tweak to an ISO
image? I need to run the script as a regular user.


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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa  wrote:
> Grant Edwards :
>
>> On 2017-01-29, Marko Rauhamaa  wrote:
>>> I *have* been longing for a serial console in linux distros.
>>
>> Well, all it takes is a tweak to the bootloader to add a kernel
>> "command-line" parameter...
>
> Can you give me a short Python script that effects the tweak to an ISO
> image? I need to run the script as a regular user.

It'd start by mounting it somewhere, and finish by building a new ISO
with mkisofs, so a shell script would be more appropriate :)

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Chris Angelico :

> On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa  wrote:
>> Grant Edwards :
>>
>>> On 2017-01-29, Marko Rauhamaa  wrote:
 I *have* been longing for a serial console in linux distros.
>>>
>>> Well, all it takes is a tweak to the bootloader to add a kernel
>>> "command-line" parameter...
>>
>> Can you give me a short Python script that effects the tweak to an ISO
>> image? I need to run the script as a regular user.
>
> It'd start by mounting it somewhere, and finish by building a new ISO
> with mkisofs, so a shell script would be more appropriate :)

Mount? As a regular user?


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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 3:44 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa  wrote:
>>> Grant Edwards :
>>>
 On 2017-01-29, Marko Rauhamaa  wrote:
> I *have* been longing for a serial console in linux distros.

 Well, all it takes is a tweak to the bootloader to add a kernel
 "command-line" parameter...
>>>
>>> Can you give me a short Python script that effects the tweak to an ISO
>>> image? I need to run the script as a regular user.
>>
>> It'd start by mounting it somewhere, and finish by building a new ISO
>> with mkisofs, so a shell script would be more appropriate :)
>
> Mount? As a regular user?

Let me see, how much effort are you prepared to go to in order to do
this as a "regular user"... because at some point, "sudo" becomes only
one of many options, including "install another Unix system somewhere
that you are root of". But if you genuinely have to mount as a
non-root user, there's fusermount, which is often capable of loading
up an ISO.

But honestly, "ssh you@somebox" can be run by anyone, so there's
always a way around the whole not-having-root thing.

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa  wrote:
>>> Grant Edwards :
>>>
 On 2017-01-29, Marko Rauhamaa  wrote:
> I *have* been longing for a serial console in linux distros.

 Well, all it takes is a tweak to the bootloader to add a kernel
 "command-line" parameter...
>>>
>>> Can you give me a short Python script that effects the tweak to an ISO
>>> image? I need to run the script as a regular user.
>>
>> It'd start by mounting it somewhere, and finish by building a new ISO
>> with mkisofs, so a shell script would be more appropriate :)
>
> Mount? As a regular user?

https://linux.die.net/man/8/isoinfo

-- 
Grant



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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Marko Rauhamaa  wrote:

> Mount? As a regular user?

Yes, using a "fuse" use-space filesystem, you can mount things as a
normal user. There are a couple ISO9660 fuse implemenations.  But, you
can't modify a mounted ISO9660 filesystem.  I have read about how to
use a union mount to simulate a writable ISO9660 filesystem, but
that's going to require root (I've never tried it).

As long as you've got the disk space available, the simplest option is
to unpack the .iso into a directory, modify the files, and then use
mkisofs to create the new .iso image.

I've written scripts like that to build cusotmized bootable ISO images
(usually using systemrescuecd as the starting point).  It's not
particulary difficult, but it does burn up a lot of disk space.  It's
also rather slow, so when you get into the tweak-build-burn-test cycle
you don't get in a lot of guesses-per-hour.

-- 
Grant


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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 4:08 AM, Grant Edwards
 wrote:
> As long as you've got the disk space available, the simplest option is
> to unpack the .iso into a directory, modify the files, and then use
> mkisofs to create the new .iso image.
>
> I've written scripts like that to build cusotmized bootable ISO images
> (usually using systemrescuecd as the starting point).  It's not
> particulary difficult, but it does burn up a lot of disk space.  It's
> also rather slow, so when you get into the tweak-build-burn-test cycle
> you don't get in a lot of guesses-per-hour.

These days, CD images are a tiny proportion of typical hard disk
capacities. Every terabyte of disk can hold over a thousand ISOs, and
that's assuming they're using the whole disc (~760MB). Several
thousand, if they're only part-full images.

But the time factor is considerable. Especially if you then have to
boot up a VM or something to test it.

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Chris Angelico :

> On Mon, Jan 30, 2017 at 3:44 AM, Marko Rauhamaa  wrote:
>> Mount? As a regular user?
>
> Let me see, how much effort are you prepared to go to in order to do
> this as a "regular user"... because at some point, "sudo" becomes only
> one of many options, including "install another Unix system somewhere
> that you are root of". But if you genuinely have to mount as a
> non-root user, there's fusermount, which is often capable of loading
> up an ISO.
>
> But honestly, "ssh you@somebox" can be run by anyone, so there's
> always a way around the whole not-having-root thing.

At the moment, we have found it easiest to create our base OS snapshots
with some manual steps. Ideally, we could get rid of the manual steps
and just have a python script take the place of the human user. That
would be trivial if the distros continued the grand tradition of
offering serial consoles out of the box.

As it stands, all methods of working serial-interface support in the ISO
image would still be more trouble than the manual steps.

We also use "Packer" to build virtual machines automatically. That works
albeit in a somewhat kludgy manner. As far as I understand, Packer
delivers keystrokes to the boot command over VNC but can't interpret the
graphical responses but simply trusts that the commands do the right
thing with a proper timing.


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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Grant Edwards  wrote:
> On 2017-01-29, Marko Rauhamaa  wrote:
>
>> Mount? As a regular user?
>
> Yes, using a "fuse" use-space filesystem, you can mount things as a
> normal user. There are a couple ISO9660 fuse implemenations.  But, you
> can't modify a mounted ISO9660 filesystem.  I have read about how to
> use a union mount to simulate a writable ISO9660 filesystem, but
> that's going to require root (I've never tried it).
>
> As long as you've got the disk space available, the simplest option is
> to unpack the .iso into a directory, modify the files, and then use
> mkisofs to create the new .iso image.

OK, just one more level of pointless digression...

_If_ your ISO image is using syslinux as the bootloader (it probably
isn't, it's almost certainly using isolinux -- usually in hybrid
mode), then the bootloader stuff is actually an image of a bootable
floppy disk. It is sort of "outside" the normal ISO9660 filesystem
with a fixed size in a "well known" location.  I'm pretty sure you
could extract that chunk from the ISO using dd, tweak it, and then put
it back into the ISO image without having to mount/extract everything
and then recreate a new ISO9660 image.

But, it's very probably using isolinux, so the bootloader
configuration stuff is actually inside the ISO9660 filesystem tree,
and you'll have to extract the whole tree, modify the files, and
create a new ISO9660 image.

-- 
Grant

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


Looking for a basic address book/contacts program

2017-01-29 Thread Chris Green
I'm looking for a simple Address Book program written in Python, I've
looked at addressbook 1.0.1 from PyPi but it doesn't quite do what I
want.  I may have to start with this and modify it but maybe there's
something better out there.

In particular I want some sort of import/export ability and I'd really
like some more configurability.

Any ideas anyone?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: A new version (0.4.0) of python-gnupg has been released.

2017-01-29 Thread Vinay Sajip via Python-list
A new version of the Python module which wraps GnuPG has been released.

What Changed?
=
This is an enhancement and bug-fix release, and all users are encouraged to 
upgrade.
See the project website [1] for more information.

Brief summary:


* Added support for ``KEY_CONSIDERED`` in more places - encryption /
  decryption, signing, key generation and key import.

* Partial fix for #32 (GPG 2.1 compatibility). Unfortunately, better
  support cannot be provided at this point, unless there are certain
  changes (relating to pinentry popups) in how GPG 2.1 works.

* Fixed #60: An IndexError was being thrown by ``scan_keys()``.

* Ensured that utf-8 encoding is used when the ``--with-column`` mode is
  used. Thanks to Yann Leboulanger for the patch.

* ``list_keys()`` now uses ``--fixed-list-mode``. Thanks to Werner Koch
  for the pointer.

This release [2] has been signed with my code signing key:

Vinay Sajip (CODE SIGNING KEY) 
Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86

What Does It Do?

The gnupg module allows Python programs to make use of the
functionality provided by the Gnu Privacy Guard (abbreviated GPG or
GnuPG). Using this module, Python programs can encrypt and decrypt
data, digitally sign documents and verify digital signatures, manage
(generate, list and delete) encryption keys, using proven Public Key
Infrastructure (PKI) encryption technology based on OpenPGP.

This module is expected to be used with Python versions >= 2.4, as it
makes use of the subprocess module which appeared in that version of
Python. This module is a newer version derived from earlier work by
Andrew Kuchling, Richard Jones and Steve Traugott.

A test suite using unittest is included with the source distribution.

Simple usage:

>>> import gnupg
>>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory')
>>> gpg.list_keys()

[{
...
'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2',
'keyid': '197D5DAC68F1AAB2',
'length': '1024',
'type': 'pub',
'uids': ['', 'Gary Gross (A test user) ']},
{
...
'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A',
'keyid': '0C5FEFA7A921FC4A',
'length': '1024',
...
'uids': ['', 'Danny Davis (A test user) ']}]
>>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A'])
>>> str(encrypted)

'-BEGIN PGP MESSAGE-\nVersion: GnuPG v1.4.9 (GNU/Linux)\n
\nhQIOA/6NHMDTXUwcEAf
.
-END PGP MESSAGE-\n'
>>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret')
>>> str(decrypted)

'Hello, world!'
>>> signed = gpg.sign("Goodbye, world!", passphrase='secret')
>>> verified = gpg.verify(str(signed))
>>> print "Verified" if verified else "Not verified"

'Verified'

As always, your feedback is most welcome (especially bug reports [3],
patches and suggestions for improvement, or any other points via the
mailing list/discussion group [4]).

Enjoy!

Cheers

Vinay Sajip
Red Dove Consultants Ltd.

[1] https://bitbucket.org/vinay.sajip/python-gnupg
[2] https://pypi.python.org/pypi/python-gnupg/0.4.0
[3] https://bitbucket.org/vinay.sajip/python-gnupg/issues
[4] https://groups.google.com/forum/#!forum/python-gnupg
-- 
https://mail.python.org/mailman/listinfo/python-list


count points where is within the polygons using shapely and fiona

2017-01-29 Thread Xristos Xristoou
i tried to count points from the point shapefile where is within in the polygon 
shapefile but i fail.Maybe my code is complete wrong but i tried.
any idea how to fix my code ?
i want fast method because i have big data features
from shapely.geometry import shape
import fiona

filepath1 = "point.shp"
file1features = []
intersectfeatures_file1 = []
intersectfeatures_file2 = []
count =0
count=count+1
outschema = None
with fiona.collection(filepath1, "r") as input1:
outschema = input1.schema.copy()
for p1 in input1:
file1features.append(p1)

filepath2 = "polygon.shp"
with fiona.collection(filepath2, "r") as input2:
for p2 in input2:
for p1 in file1features:
[count for i in 
[shape(p1['geometry']).within(shape(p2['geometry']))]]
if p1 not in intersectfeatures_file1:
intersectfeatures_file1.append(p1)
if p2 not in intersectfeatures_file2:
intersectfeatures_file2.append(p2)

print count
'''
if intersectfeatures_file1:
outfile = "outputfile1.shp"
with fiona.collection(outfile, "w", "ESRI Shapefile", outschema) as output:
for outfeature in intersectfeatures:
output.write(outfeature)
if intersectfeatures_file2:
outfile = "outputfile2.shp"
with fiona.collection(outfile, "w", "ESRI Shapefile", outschema) as output:
for outfeature in intersectfeatures:
output.write(outfeature)
'''
on the print count i take 20 times the number 1. after for this count i want to 
export to new shapefile the polygons where have specific number of points. thnx
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Serhiy Storchaka

On 28.01.17 10:03, Steve D'Aprano wrote:

Is shutil.get_terminal_size useless? When, if ever, should I use it in
preference to the os version? If the shutil version is broken, can it be
fixed?


Read the history of shutil.get_terminal_size(). All this was discussed.

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


RE: What are your opinions on .NET Core vs Python?

2017-01-29 Thread Joseph L. Casale
> .NET is a library that can be used from many languages, including Python. 

No.

.NET Core (what the OP asked about which is not .NET) is a cross-platform
framework. Obviously Python and .NET differ in runtime semantics with
respect to the original source code, however they are now roughly equivalent
in that both specifications are cross platform.

I personally like .NET Core a great deal and as the framework matures and
it starts to present all of the .NET APIs, it will become a viable choice on non
Windows platforms.

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


Re: How coding in Python is bad for you

2017-01-29 Thread Gregory Ewing

Steve D'Aprano wrote:


5. The statistics module is too slow (and if I ever meet the author, I'll
give him a kick in the head);


Wow... ad-hominem take to a physical level!

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


Re: How coding in Python is bad for you

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 8:54 AM, Gregory Ewing
 wrote:
> Steve D'Aprano wrote:
>
>> 5. The statistics module is too slow (and if I ever meet the author, I'll
>> give him a kick in the head);
>
>
> Wow... ad-hominem take to a physical level!

If Steve ever comes face to face with the author of the statistics
module, he should avoid excessive violence, lest he get seven years of
bad luck... for breaking a mirror. :)

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


Re: What are your opinions on .NET Core vs Python?

2017-01-29 Thread Gregory Ewing

Joseph L. Casale wrote:
.NET is a library that can be used from many languages, including Python. 


No.


Yes:

http://pythonnet.sourceforge.net/

"Python for .NET is a package that gives Python programmers nearly seamless 
integration with the .NET Common Language Runtime (CLR) and provides a powerful 
application scripting tool for .NET developers. Using this package you can 
script .NET applications or build entire applications in Python, using .NET 
services and components written in any language that targets the CLR (Managed 
C++, C#, VB, JScript)."


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


RE: What are your opinions on .NET Core vs Python?

2017-01-29 Thread Deborah Swanson
Joseph L. Casale wrote, on January 29, 2017 1:14 PM
> 
> > .NET is a library that can be used from many languages, including 
> > Python.
> 
> No.
> 
> .NET Core (what the OP asked about which is not .NET) is a 
> cross-platform framework. Obviously Python and .NET differ in 
> runtime semantics with respect to the original source code, 
> however they are now roughly equivalent in that both 
> specifications are cross platform.
> 
> I personally like .NET Core a great deal and as the framework 
> matures and it starts to present all of the .NET APIs, it 
> will become a viable choice on non Windows platforms.
> 
> jlc

What .NET APIs are anticipated to be released that aren't on the
official CLI list now:
https://en.wikipedia.org/wiki/List_of_CLI_languages#Current_Languages,
and/or, are .NET supported languages expected to expand beyond the CLI
list?



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


Re: How coding in Python is bad for you

2017-01-29 Thread Erik

On 29/01/17 14:42, Steve D'Aprano wrote:

1. for...else is misspelled, and should be for...then;

2. Same for while...else;


I don't think I'll ever agree with you on this one.

"then", to me, implies the code following it is always executed.
"else" implies it's conditional.

In those constructs it's conditional and therefore, to me, "else" is a 
better reminder of that.


It would be even better if it was "else if not break:" to make the 
meaning clearer. I would agree that it would be even better than that if 
it was "then if not break:" (apart from needing the new keyword ;)), as 
then the conditional aspect is explicit.


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


Re: count points where is within the polygons using shapely and fiona

2017-01-29 Thread Peter Pearson
On Sun, 29 Jan 2017 11:42:47 -0800 (PST), Xristos Xristoou wrote:
> i tried to count points from the point shapefile where is within in
> the polygon shapefile but i fail.Maybe my code is complete wrong but i
> tried.
> any idea how to fix my code ?
> i want fast method because i have big data features
> from shapely.geometry import shape
> import fiona
>
> filepath1 = "point.shp"
> file1features = []
> intersectfeatures_file1 = []
> intersectfeatures_file2 = []
> count =0
> count=count+1

This is an illogical place to increment count.

> outschema = None
> with fiona.collection(filepath1, "r") as input1:
> outschema = input1.schema.copy()
> for p1 in input1:
> file1features.append(p1)

I believe you could also say file1features = list(input1).


> filepath2 = "polygon.shp"
> with fiona.collection(filepath2, "r") as input2:
> for p2 in input2:
> for p1 in file1features:
> [count for i in 
> [shape(p1['geometry']).within(shape(p2['geometry']))]]

The above line produces a list that is discarded because it is not
assigned any name.

> if p1 not in intersectfeatures_file1:
> intersectfeatures_file1.append(p1)
> if p2 not in intersectfeatures_file2:
> intersectfeatures_file2.append(p2)
>
> print count

> '''
> if intersectfeatures_file1:
> outfile = "outputfile1.shp"
> with fiona.collection(outfile, "w", "ESRI Shapefile", outschema) as 
> output:
> for outfeature in intersectfeatures:
> output.write(outfeature)
> if intersectfeatures_file2:
> outfile = "outputfile2.shp"
> with fiona.collection(outfile, "w", "ESRI Shapefile", outschema) as 
> output:
> for outfeature in intersectfeatures:
> output.write(outfeature)
> '''

The above lines between triple quotes should have been omitted
from this post.

> on the print count i take 20 times the number 1. after for this count i want 
> to export to new shapefile the polygons where have specific number of points. 
> thnx


-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How coding in Python is bad for you

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 10:52 am, Erik wrote:

> On 29/01/17 14:42, Steve D'Aprano wrote:
>> 1. for...else is misspelled, and should be for...then;
>>
>> 2. Same for while...else;
> 
> I don't think I'll ever agree with you on this one.
> 
> "then", to me, implies the code following it is always executed.
> "else" implies it's conditional.
> 
> In those constructs it's conditional and therefore, to me, "else" is a
> better reminder of that.

But it isn't conditional. When the code reaches the end of the for/while
block, the else block is ALWAYS executed. Unconditionally.

The only way to skip the else block is to avoid reaching the end of the
for/while block: raise, break or return out of the body of the block.


> It would be even better if it was "else if not break:" to make the
> meaning clearer.

break is not the only way to exit the for loop.


> I would agree that it would be even better than that if 
> it was "then if not break:" (apart from needing the new keyword ;)), as
> then the conditional aspect is explicit.

But it isn't conditional. Your syntax implies that the interpreter keeps
some sort of flag did_we_reach_the_end_of_the_loop_without_break or
something, and then it checks the state of that flag. There is no such
flag. If I remember correctly, that last time this came up here was because
somebody asked how they could read the value of that flag, instead of
setting their own:

for x in seq:
...
if not did_we_reach_the_end_of_the_loop_without_break:
print("break")


They hoped to use the same flag the for-loop used.

But if you use the dis module to decompile the CPython byte-code you will
see that there is no such flag. Code like this:

for i in seq:
break
else:
foo
bar

compiles to something like this (results may vary according to the version
of Python):


py> import dis
py> code = compile("""
... for i in seq:
... break
... else:
... foo
... bar
... """, "", "exec")
py> dis.dis(code)
  2   0 SETUP_LOOP  19 (to 22)
  3 LOAD_NAME0 (seq)
  6 GET_ITER
>>7 FOR_ITER 7 (to 17)
 10 STORE_NAME   1 (i)

  3  13 BREAK_LOOP
 14 JUMP_ABSOLUTE7
>>   17 POP_BLOCK

  5  18 LOAD_NAME2 (foo)
 21 POP_TOP

  6 >>   22 LOAD_NAME3 (bar)
 25 POP_TOP
 26 LOAD_CONST   0 (None)
 29 RETURN_VALUE


Not a single condition to be seen, anywhere. Its all unconditional jumps.

To anticipate a possible objection: it is possible that the FOR_ITER
bytecode is implemented with a conditional test, but even so, all that
tests for is whether to enter the main body of the for-loop (10
STORE_NAME ...) or jump to (18 LOAD_NAME ...).

If you remove the break completely, or replace it with raise or (in a
function) return, and you'll see the same structure to the code: for loops
run the main body of the loop, then unconditionally run the else block,
then unconditionally exit the loop and continue on with the rest of the
program. To avoid the else block, you have to jump out of the entire
for-loop.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 08:12 am, Serhiy Storchaka wrote:

> On 28.01.17 10:03, Steve D'Aprano wrote:
>> Is shutil.get_terminal_size useless? When, if ever, should I use it in
>> preference to the os version? If the shutil version is broken, can it be
>> fixed?
> 
> Read the history of shutil.get_terminal_size(). All this was discussed.

Where?



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Rename file without overwriting existing files

2017-01-29 Thread Steve D'Aprano
This code contains a Time Of Check to Time Of Use bug:

if os.path.exists(destination)
raise ValueError('destination already exists')
os.rename(oldname, destination)


In the microsecond between checking for the existence of the destination and
actually doing the rename, it is possible that another process may create
the destination, resulting in data loss.

Apart from keeping my fingers crossed, how should I fix this TOCTOU bug?



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread eryk sun
On Mon, Jan 30, 2017 at 2:16 AM, Steve D'Aprano
 wrote:
> On Mon, 30 Jan 2017 08:12 am, Serhiy Storchaka wrote:
>
>> On 28.01.17 10:03, Steve D'Aprano wrote:
>>> Is shutil.get_terminal_size useless? When, if ever, should I use it in
>>> preference to the os version? If the shutil version is broken, can it be
>>> fixed?
>>
>> Read the history of shutil.get_terminal_size(). All this was discussed.
>
> Where?

See issue 13609:
http://bugs.python.org/issue13609
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Rename file without overwriting existing files

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 1:49 PM, Steve D'Aprano
 wrote:
> This code contains a Time Of Check to Time Of Use bug:
>
> if os.path.exists(destination)
> raise ValueError('destination already exists')
> os.rename(oldname, destination)
>
>
> In the microsecond between checking for the existence of the destination and
> actually doing the rename, it is possible that another process may create
> the destination, resulting in data loss.
>
> Apart from keeping my fingers crossed, how should I fix this TOCTOU bug?

The Linux kernel (sorry, I don't know about others) provides a
renameat2() system call that has the option of failing if the
destination exists. However, I can't currently see any way to call
that from CPython. Seems like an excellent feature request - another
keyword-only argument for os.rename(), like the directory file
descriptors.

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


Re: Rename file without overwriting existing files

2017-01-29 Thread MRAB

On 2017-01-30 03:27, Chris Angelico wrote:

On Mon, Jan 30, 2017 at 1:49 PM, Steve D'Aprano
 wrote:

This code contains a Time Of Check to Time Of Use bug:

if os.path.exists(destination)
raise ValueError('destination already exists')
os.rename(oldname, destination)


In the microsecond between checking for the existence of the destination and
actually doing the rename, it is possible that another process may create
the destination, resulting in data loss.

Apart from keeping my fingers crossed, how should I fix this TOCTOU bug?


The Linux kernel (sorry, I don't know about others) provides a
renameat2() system call that has the option of failing if the
destination exists. However, I can't currently see any way to call
that from CPython. Seems like an excellent feature request - another
keyword-only argument for os.rename(), like the directory file
descriptors.


On Windows it raises FileExistsError if the destination already exists.

shutil.move, on the other hand, replaces if the destination already exists.

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


Re: Rename file without overwriting existing files

2017-01-29 Thread Cameron Simpson

On 30Jan2017 13:49, Steve D'Aprano  wrote:

This code contains a Time Of Check to Time Of Use bug:

   if os.path.exists(destination)
   raise ValueError('destination already exists')
   os.rename(oldname, destination)


In the microsecond between checking for the existence of the destination and
actually doing the rename, it is possible that another process may create
the destination, resulting in data loss.

Apart from keeping my fingers crossed, how should I fix this TOCTOU bug?


For files this is a problem at the Python level. At the UNIX level you can play 
neat games with open(2) and the various O_* modes.


however, with directories things are more cut and dry. Do you have much freedom 
here? What's the wider context of the question?


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


GeneratorExit masks StopIteration?

2017-01-29 Thread inyeol . lee
Does generator.close() prevent raising StopIteration?

I'm trying to get the return value from coroutine after terminating it.
Here is simple test code:

$ python3
Python 3.6.0 (default, Dec 23 2016, 12:50:55) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def cor():
...   try:
... item = yield
...   except GeneratorExit:
... return 1
... 
>>> c = cor()
>>> next(c)
>>> c.close()
>>>

I was expecting StopIteration from c.close() call, but Python 3.6 doesn't raise 
any.
Is this behavior expected? I couldn't find any reference regarding 
GeneratorExit and StopIteration interaction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Steven D'Aprano
On Monday 30 January 2017 08:12, Serhiy Storchaka wrote:

> On 28.01.17 10:03, Steve D'Aprano wrote:
>> Is shutil.get_terminal_size useless? When, if ever, should I use it in
>> preference to the os version? If the shutil version is broken, can it be
>> fixed?
> 
> Read the history of shutil.get_terminal_size(). All this was discussed.


Yes, it was discussed, but not resolved: Antoine Pitrou just closed the task 
and declared it done, without resolving the failures I am talking about here.

http://bugs.python.org/issue13609

(Thanks Eryk Sun for the link.)



-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

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


Re: GeneratorExit masks StopIteration?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 4:24 PM,   wrote:
> I was expecting StopIteration from c.close() call, but Python 3.6 doesn't 
> raise any.
> Is this behavior expected? I couldn't find any reference regarding 
> GeneratorExit and StopIteration interaction.

When you close() a generator, it raises GeneratorExit into it, and
then silences any StopIteration or GeneratorExit that comes out of it.
If you need different behaviour, what you could do is explicitly
throw() into it:

>>> c.throw(GeneratorExit)
Traceback (most recent call last):
  File "", line 1, in 
StopIteration: 1

which you'd obviously want to wrap in try/except, but at that point,
you have the result.

Maybe this could be a feature request - that generator.close() returns
the return value of the generator (or None if the GeneratorExit comes
out)?

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


Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Wildman via Python-list
On Sat, 28 Jan 2017 19:03:42 +1100, Steve D'Aprano wrote:

> shutil.get_terminal_size returns the wrong values when you pipe your output
> to another process, even it you do so in a terminal. Consider this script:
> 
> 
> import os
> import shutil
> print('shutil:', shutil.get_terminal_size(fallback=(999, 999)))
> print('os:', os.get_terminal_size(0))
> 
> 
> That uses two different methods to get the terminal size. If I run that in a
> terminal in the normal way, it works fine, returning the correct size for
> my terminal:
> 
> 
> [steve@ando ~]$ python3.5 test_gts.py
> shutil: os.terminal_size(columns=116, lines=29)
> os: os.terminal_size(columns=116, lines=29)
> 
> 
> But if I pipe the output to something else, the shutil version fails to
> determine the correct terminal size, and falls back on the default:
> 
> 
> [steve@ando ~]$ python3.5 test_gts.py | cat
> shutil: os.terminal_size(columns=999, lines=999)
> os: os.terminal_size(columns=116, lines=29)
> 
> 
> while the os version gives the correct result.
> 
> Is shutil.get_terminal_size useless? When, if ever, should I use it in
> preference to the os version? If the shutil version is broken, can it be
> fixed?
> 
> 
> Thanks to Bernardas Ališauskas:
> 
> http://granitosaurus.rocks/getting-terminal-size.html

I can suggest a third approach to try but I have not tried
piping it.  YMMV.

import fcntl
import os
import struct
import termios

tty = os.open(os.ctermid(), os.O_RDONLY)
ts = struct.unpack("hh", fcntl.ioctl(tty, termios.TIOCGWINSZ, "1234"))
os.close(tty)
columns = ts[1]
rows = ts[0]
print(str(columns) + "x" + str(rows))

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: GeneratorExit masks StopIteration?

2017-01-29 Thread Deborah Swanson
inyeol@gmail.com wrote, on January 29, 2017 9:24 PM

> 
> Does generator.close() prevent raising StopIteration?
> 
> I'm trying to get the return value from coroutine after 
> terminating it. Here is simple test code:
> 
> $ python3
> Python 3.6.0 (default, Dec 23 2016, 12:50:55) 
> [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on 
> darwin Type "help", "copyright", "credits" or "license" for 
> more information.
> >>> def cor():
> ...   try:
> ... item = yield
> ...   except GeneratorExit:
> ... return 1
> ... 
> >>> c = cor()
> >>> next(c)
> >>> c.close()
> >>>
> 
> I was expecting StopIteration from c.close() call, but Python 
> 3.6 doesn't raise any. Is this behavior expected? I couldn't 
> find any reference regarding GeneratorExit and StopIteration 
> interaction.

Use except StopIteration:

(Not sure what generator.close() should do, or if GeneratorExit is any
kind of equivalent, but StopIteration works. I'm less familiar with
Python 2.)

Python 3.4.3 |Anaconda 2.3.0 (32-bit)| (default, Mar  6 2015, 12:08:17)
[MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> help(generator.close)
Traceback (most recent call last):
  File "", line 1, in 
help(generator.close)
NameError: name 'generator' is not defined

So at the very least, generator needs to be defined, if it's possible to
define or import it in Python 3. Probably not.

In Python 2, GeneratorExit is raised when the generator's close() method
is called. But in my quick search, I couldn't find GeneratorExit in
Python 3, or any note that it had been dropped, but it's a good guess
that it was dropped. It's redundant with StopIteration.

I always use StopIteration. It works in all Python versions.

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


Display a label while pressing the button in my GUI

2017-01-29 Thread hmmeeranrizvi18
Hello Guys,
Here i am creating a GUI which will act as a search engine that will find the 
results from the browser and save the results as a xls file.
When i typed something in my search box and click the (GO)button.It should 
display search in progress.when the file is saved it should display done.
How to do that?
My button gets hung for a seconds.We should give any timeout for that?

Here is my script

from Tkinter import *
import mechanize
def clear_search(event):
search.delete(0,END)
obj = Tk()
Label = Label(obj,text="Top Findings:",font="-weight bold")
search = Entry(obj,width=100)
search.insert(0, "Enter the value to search")
search.bind("", clear_search)
def fun():
new = search.get()
url = "http://duckduckgo.com/html";
br = mechanize.Browser()
br.set_handle_robots(False)
br.open(url)
br.select_form(name="x")
br["q"] = str(new)
res = br.submit()
content = res.read()
with open("result1.xls", "w") as f:
f.write(content)
fun()
Go = Button(obj,text="GO",width=5,command=fun)
Label.pack()
search.pack()
Go.pack()
mainloop()

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


Re: GeneratorExit masks StopIteration?

2017-01-29 Thread inyeol . lee
On Sunday, January 29, 2017 at 9:54:44 PM UTC-8, Chris Angelico wrote:
> ...
> When you close() a generator, it raises GeneratorExit into it, and
> then silences any StopIteration or GeneratorExit that comes out of it.

Chris,
Thanks for the info. Is this (GenExit silencing StopIteration) documented 
somewhere?
I was suspecting this but couldn't find any reference.

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


Re: GeneratorExit masks StopIteration?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 5:38 PM,   wrote:
> On Sunday, January 29, 2017 at 9:54:44 PM UTC-8, Chris Angelico wrote:
>> ...
>> When you close() a generator, it raises GeneratorExit into it, and
>> then silences any StopIteration or GeneratorExit that comes out of it.
>
> Chris,
> Thanks for the info. Is this (GenExit silencing StopIteration) documented 
> somewhere?
> I was suspecting this but couldn't find any reference.

Actually. think this might be incorrect. I didn't look in the
docs, I looked in the source code, so my information is guaranteed
accurate; this is where I would expect the information to be:

https://docs.python.org/3/reference/expressions.html#generator.close

As a general rule, a generator shouldn't be leaking StopIteration. In
a future version of Python, this will trigger RuntimeError. (You can
get that behaviour in 3.6 with a future import, too.) So what this
really means is that close() will suppress any GeneratorExit, or the
generator returning, both of which are normal occurrences. The only
significant thing is that the generator's return value could usefully
be propagated out of close().

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


Re: GeneratorExit masks StopIteration?

2017-01-29 Thread inyeol . lee
On Sunday, January 29, 2017 at 10:47:09 PM UTC-8, Chris Angelico wrote:
> On Mon, Jan 30, 2017 at 5:38 PM,   wrote:
> > On Sunday, January 29, 2017 at 9:54:44 PM UTC-8, Chris Angelico wrote:
> >> ...
> >> When you close() a generator, it raises GeneratorExit into it, and
> >> then silences any StopIteration or GeneratorExit that comes out of it.
> >
> > Chris,
> > Thanks for the info. Is this (GenExit silencing StopIteration) documented 
> > somewhere?
> > I was suspecting this but couldn't find any reference.
> 
> Actually. think this might be incorrect. I didn't look in the
> docs, I looked in the source code, so my information is guaranteed
> accurate

I found PEP-342 describes this behavior - silencing other GenExit or 
StopIteration.

BTW, the reason why I was checking this was to find a solution on how to get 
return value from coroutine without relying on some sentinel value, something 
like (not tested):

def accumulator():
  sum = 0
  try:
while True:
  sum += yield
  except GeneratorExit:
return sum

Any alternatives? Explicitly throwing GenExit looks like a hack.

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


RE: What are your opinions on .NET Core vs Python?

2017-01-29 Thread Joseph L. Casale
> What .NET APIs are anticipated to be released that aren't on the
> official CLI list now:
> https://en.wikipedia.org/wiki/List_of_CLI_languages#Current_Languages,
> and/or, are .NET supported languages expected to expand beyond the CLI
> list?

I think this (and the last point) misinterprets the semantics of the OPs post.

.NET Core is not .NET, it's a **multi-platform** framework for a language
syntax specification (c#). It's not an implementation of some API that you
cannleverage in another language specification.

Writing a ctype accessor for a Windows API does not equate to cpp code
that is now magically Python. It means no more than what it is, "a foreign
function library for Python" (https://docs.python.org/3/library/ctypes.html).

.Net Core is fundamentally different and much like Python in the way that
a compiler and runtime for a common language syntax specification has been
written for multiple platforms. So in general, the same Python script could
run on both platforms, and most certainly the same .NET Core source could
compile and run on its supported platforms.

So back to the question, .NET Core is a wip which where applicable will soon
present all the existing .NET APIs, excluding those which are Windows specific
and don't make sense to present on a non-Windows platform like Windows Forms.

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


Overriding True and False ?

2017-01-29 Thread Irv Kalb
I teach intro to programming using Python.  In my first assignment, students 
are asked to assign variables of different types and print out the values.  

One student (who really did not understand Booleans) turned in the following 
for his/her interpretation of Booleans (Python 2.7):

True = 'shadow'
False = 'light'
print "If the sun is behind a cloud, there is", True
print "If it is a clear day, there is", False

And it printed:

If the sun is behind a cloud, there is shadow
If it is a clear day, there is light


It seems very odd that Python allows you to override the values of True and 
False.  In the code, True and False were clearly recognized as keywords as they 
were colored purple.  But there was no error message.

You cannot assign new values to other keywords.  Simple tests of things like:

for = 5

while = 2

not = 3

As expected, all result in SyntaxError: invalid syntax.  Why would Python allow 
you to override the values of True and False?  I wonder if this is some sort of 
historical thing as these are the only keywords besides None that are 
uppercased.  This line:

None = 5

Even gives a special SyntaxError: cannot assign to None

Just curious,

Irv


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


Re: Overriding True and False ?

2017-01-29 Thread INADA Naoki
It's fixed already in Python 3.
Please use Python 3 when teaching to students.

$ python3
Python 3.6.0 (default, Dec 24 2016, 00:01:50)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True = "foo"
  File "", line 1
SyntaxError: can't assign to keyword
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What are your opinions on .NET Core vs Python?

2017-01-29 Thread denis . akhiyarov
On Sunday, January 29, 2017 at 4:00:27 PM UTC-6, Gregory Ewing wrote:
> Joseph L. Casale wrote:
> >>.NET is a library that can be used from many languages, including Python. 
> >
> > No.
> 
> Yes:
> 
> http://pythonnet.sourceforge.net/
> 
> "Python for .NET is a package that gives Python programmers nearly seamless 
> integration with the .NET Common Language Runtime (CLR) and provides a 
> powerful 
> application scripting tool for .NET developers. Using this package you can 
> script .NET applications or build entire applications in Python, using .NET 
> services and components written in any language that targets the CLR (Managed 
> C++, C#, VB, JScript)."
> 
> -- 
> Greg

This is outdated location. pythonnet (python for .NET) is on GitHub since 2014.

https://github.com/pythonnet/pythonnet

We just released v2.2.2 with Python 3.6 support and transition to MIT license.

Download from PYPI using pip or from Anaconda using conda:

https://pypi.python.org/pypi/pythonnet/2.2.2
https://anaconda.org/pythonnet/pythonnet

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


RE: Overriding True and False ?

2017-01-29 Thread Deborah Swanson
Irv Kalb wrote, on Sunday, January 29, 2017 9:04 PM
> 
> I teach intro to programming using Python.  In my first 
> assignment, students are asked to assign variables of 
> different types and print out the values.  
> 
> One student (who really did not understand Booleans) turned 
> in the following for his/her interpretation of Booleans (Python 2.7):
> 
> True = 'shadow'
> False = 'light'
> print "If the sun is behind a cloud, there is", True
> print "If it is a clear day, there is", False
> 
> And it printed:
> 
> If the sun is behind a cloud, there is shadow
> If it is a clear day, there is light
> 
> 
> It seems very odd that Python allows you to override the 
> values of True and False.  In the code, True and False were 
> clearly recognized as keywords as they were colored purple.  
> But there was no error message.
> 
> You cannot assign new values to other keywords.  Simple tests 
> of things like:
> 
> for = 5
> 
> while = 2
> 
> not = 3
> 
> As expected, all result in SyntaxError: invalid syntax.  Why 
> would Python allow you to override the values of True and 
> False?  I wonder if this is some sort of historical thing as 
> these are the only keywords besides None that are uppercased. 
>  This line:
> 
> None = 5
> 
> Even gives a special SyntaxError: cannot assign to None
> 
> Just curious,
> 
> Irv

Just guessing, but in the examples you give in Python 2.7, substitute
strings are syntactically correct in print statements, but:

5 in list('abc'):

2 True:

if a 3 b:

would all be syntactical errors.

As is 'None = 5'.

Looks like the moral of the story is that in Python 2.7 you can redefine
keywords, so long as you don't get any syntax errors after (or during)
redefinition.

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


Re: Overriding True and False ?

2017-01-29 Thread Ben Finney
Irv Kalb  writes:

> I teach intro to programming using Python. […]

Thank you for teaching Python to beginners!

> It seems very odd that Python allows you to override the values of
> True and False.

Yes, it is. That's why Python 3 forbids it::

>>> True = "shadow"
  File "", line 1
SyntaxError: can't assign to keyword
>>> False = "light"
  File "", line 1
SyntaxError: can't assign to keyword

When teaching Python, please do not teach Python 2. Your students should
learn Python 3 first, primarily, and for most of the course.

Python 2 is a legacy that will never gain new features, and will only
slip further behind the current supported Python version. That makes
Python 2 a poor choice for teaching to beginners.

-- 
 \  “The entertainment industry calls DRM "security" software, |
  `\ because it makes them secure from their customers.” —Cory |
_o__) Doctorow, 2014-02-05 |
Ben Finney

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