Re: Ide vs ide

2017-10-28 Thread Rustom Mody
On Saturday, October 28, 2017 at 11:59:14 AM UTC+5:30, Andrew Z wrote:
> Yeah, lets start the war!
> // joking!
> 
> But if i think about it... there are tons articles and flame wars about "a
> vs b".
> And yet, what if the question should be different:
> 
> If you were to create the "ide" for yourself (think lego) , what are the
> functions that you _use_ and like a lot?

[Not really an answer to your question…]
But in a related direction:

I think we need to talk more systematically about 
- programming-in-the-small:  [< 70 lines — one or so screenfuls; only 1 file]
- -in-the-medium : all files in one directory
- -in-the-large : multiple directories/languages/OSes etc
- -huge : millions of lines; thousands of man-years

I think one of the main attractions (to me but also generally to teachers)
is that languages like python make programming-in-the-tiny a realistic 
possibility
ie a couple of lines worked out possibly file-less, at the interpreter prompt.

[The other day I was writing a program to split alternate lines of a file;
Apart from file-handling it was these two lines:

for x in lines[0::2]:   print(x.strip())
for x in lines[1::2]:   print(x.strip())
]

So coming to your question: IDEs are good for medium and (diminishingly) for 
large programs.

Useful python programs are often small; even tiny
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep or drop index.html from Django?

2017-10-28 Thread Thomas Jollans
On 28/10/17 08:55, Christopher Reimer wrote:
> Greetings,
> 
> When I set up my static website using Pelican several years ago, many URLs 
> ended with index.html. Now that I'm looking at Django, I got a small set of 
> URLs working with and without index.html to point to the correct pages.
> 
> I read somewhere that the Django philosophy was to keep the URLs as clean as 
> possible (i.e., no *.html at the end). I can go either way with this. What's 
> the best practice for this?

Best practice is to keep your URLs working in one way or another.

As you said, with Django it's unusual to add artificial file endings
like ".html". I'd recommend setting up the URLs in a way that makes
sense to you now (probably without index.html and so on) and set up HTTP
301 redirects to get your visitors to the right place. (Probably best in
the web server configuration, but you can do this in Django)

-- Thomas



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


testfixtures 5.3.0 released!

2017-10-28 Thread Chris Withers

Hi All,

I'm pleased to announce the release of testfixtures 5.3.0 featuring the 
following:


 * Add pytest traceback hiding for|TempDirectory.compare()|.
 * Add warnings that|log_capture()|,|tempdir()|and|replace()|are not
   currently compatible with pytest’s fixtures mechanism.
 * Better support for|stdout|or|stderr|/not/being set to|PIPE|when
   using|MockPopen|.
 * Add support to|MockPopen|for using|subprocess.Popen|
   as
   a context manager in Python 3.
 * Add support to|MockPopen|for|stderr=STDOUT|.

Thanks to Tim Davies for his work on|MockPopen|.

The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


https://github.com/Simplistix/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

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


Re: Ide vs ide

2017-10-28 Thread Christian Gollwitzer

Am 28.10.17 um 09:04 schrieb Rustom Mody:

[The other day I was writing a program to split alternate lines of a file;
Apart from file-handling it was these two lines:

 for x in lines[0::2]:   print(x.strip())
 for x in lines[1::2]:   print(x.strip())
]


...and using the best(TM) tool for it, it is a one-liner:

gawk '{ print > "split" NR%2}' input.txt



So coming to your question: IDEs are good for medium and (diminishingly) for 
large programs.


agreed


Useful python programs are often small; even tiny



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


Re: Ide vs ide

2017-10-28 Thread Rustom Mody
On Saturday, October 28, 2017 at 4:46:03 PM UTC+5:30, Christian Gollwitzer 
wrote:
> Am 28.10.17 um 09:04 schrieb Rustom Mody:
> > [The other day I was writing a program to split alternate lines of a file;
> > Apart from file-handling it was these two lines:
> > 
> >  for x in lines[0::2]:   print(x.strip())
> >  for x in lines[1::2]:   print(x.strip())
> > ]
> 
> ...and using the best(TM) tool for it, it is a one-liner:
> 
> gawk '{ print > "split" NR%2}' input.txt

Ooo!¡!
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: distlib 0.2.6 released on PyPI

2017-10-28 Thread Vinay Sajip via Python-list
I've just released version 0.2.6 of distlib on PyPI [1]. For newcomers,distlib 
is a library of packaging functionality which is intended to beusable as the 
basis for third-party packaging tools.
The main changes in this release are as follows:
* Fixed #99: Updated to handle a case where sys.getfilesystemencoding()  
returns None.
* Fixed #97: Eliminated a crash in EggInfoDistribution.list_distinfo_files()  
which was caused by trying to open a non-existent file.
* Fixed #96: SimpleScrapingLocator no longer fails prematurely when scraping  
links due to invalid versions.
* Improved error messages issued when interpreting markers.
* Improved the shebangs written into installed scripts when the interpreter  
path is very long or contains spaces (to cater for a limitation in shebang  
line parsing on Linux).
* Updated launcher binaries.
A more detailed change log is available at [2].
Please try it out, and if you find any problems or have any suggestions 
forimprovements, please give some feedback using the issue tracker! [3]
Regards,

Vinay Sajip
[1] https://pypi.python.org/pypi/distlib/0.2.6[2] https://goo.gl/M3kQzR[3] 
https://bitbucket.org/pypa/distlib/issues/new

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


Re: from packaging import version as pack_version ImportError: No module named packaging

2017-10-28 Thread David Gabriel
Thanks so Lutz much for your reply.
I am using python2.7 and I am running this code in an Openstack instance.
I will apply your recommandation and let you know about the result ...

Kind regards.

2017-10-27 16:13 GMT+02:00 Lutz Horn :

> On Fri, Oct 27, 2017 at 03:56:39PM +0200, David Gabriel wrote:
> > from packaging import version as pack_version
> > ImportError: No module named packaging
> >
> > I googled it and I have found so many suggestions regarding updating
> > 'pip' and installing python-setuptools but all of these did not fix
> > this issue.
>
> So many questions:
>
> * What is your Python version?
> * Do you use virtualenv?
> * How?
> * Did you install packaging in this virtualenv?
>
> Just one example of making this work:
>
> $ mkdir /tmp/pack
> $ cd /tmp/pack
> $ virtualenv -p $(which python3.5) .
> Running virtualenv with interpreter /usr/bin/python3.5
> Using base prefix '/usr'
> New python executable in /tmp/pack/bin/python3.5
> Also creating executable in /tmp/pack/bin/python
> Installing setuptools, pkg_resources, pip, wheel...done.
> $ source bin/activate
> $ pip3 install packaging
> Collecting packaging
>   Using cached packaging-16.8-py2.py3-none-any.whl
> Collecting six (from packaging)
>   Using cached six-1.11.0-py2.py3-none-any.whl
> Collecting pyparsing (from packaging)
>   Using cached pyparsing-2.2.0-py2.py3-none-any.whl
> Installing collected packages: six, pyparsing, packaging
> Successfully installed packaging-16.8 pyparsing-2.2.0 six-1.11.0
> $ python3.5
> Python 3.5.2 (default, Sep 14 2017, 22:51:06)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more
> information.
> >>> from packaging import version as pack_version
> >>>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: from packaging import version as pack_version ImportError: No module named packaging

2017-10-28 Thread David Gabriel
I forget to precise that I am using pycharm.
And this issue is reproducible also using command line to run the code.

Best regards

2017-10-28 14:31 GMT+02:00 David Gabriel :

> Thanks so Lutz much for your reply.
> I am using python2.7 and I am running this code in an Openstack instance.
> I will apply your recommandation and let you know about the result ...
>
> Kind regards.
>
> 2017-10-27 16:13 GMT+02:00 Lutz Horn :
>
>> On Fri, Oct 27, 2017 at 03:56:39PM +0200, David Gabriel wrote:
>> > from packaging import version as pack_version
>> > ImportError: No module named packaging
>> >
>> > I googled it and I have found so many suggestions regarding updating
>> > 'pip' and installing python-setuptools but all of these did not fix
>> > this issue.
>>
>> So many questions:
>>
>> * What is your Python version?
>> * Do you use virtualenv?
>> * How?
>> * Did you install packaging in this virtualenv?
>>
>> Just one example of making this work:
>>
>> $ mkdir /tmp/pack
>> $ cd /tmp/pack
>> $ virtualenv -p $(which python3.5) .
>> Running virtualenv with interpreter /usr/bin/python3.5
>> Using base prefix '/usr'
>> New python executable in /tmp/pack/bin/python3.5
>> Also creating executable in /tmp/pack/bin/python
>> Installing setuptools, pkg_resources, pip, wheel...done.
>> $ source bin/activate
>> $ pip3 install packaging
>> Collecting packaging
>>   Using cached packaging-16.8-py2.py3-none-any.whl
>> Collecting six (from packaging)
>>   Using cached six-1.11.0-py2.py3-none-any.whl
>> Collecting pyparsing (from packaging)
>>   Using cached pyparsing-2.2.0-py2.py3-none-any.whl
>> Installing collected packages: six, pyparsing, packaging
>> Successfully installed packaging-16.8 pyparsing-2.2.0 six-1.11.0
>> $ python3.5
>> Python 3.5.2 (default, Sep 14 2017, 22:51:06)
>> [GCC 5.4.0 20160609] on linux
>> Type "help", "copyright", "credits" or "license" for more
>> information.
>> >>> from packaging import version as pack_version
>> >>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compression of random binary data

2017-10-28 Thread Steve D'Aprano
On Fri, 27 Oct 2017 09:53 am, Ben Bacarisse wrote:

> A source of random can be defined but "random data" is much more
> illusive.

Random data = any set of data generated by "a source of random".





-- 
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


EuroPython 2017: Videos for Friday available online

2017-10-28 Thread M.-A. Lemburg
We are pleased to announce the last batch of cut videos for EuroPython 2017.

   * All 163 EuroPython 2017 videos are now online *

To see the new videos, please head over to our EuroPython YouTube
channel and select the "EuroPython 2017" playlist. The new videos start
at entry 129 in the playlist.

We have also published a few videos from Monday, we had missed in the
first batch.

  * EuroPython 2017 Videos *

http://europython.tv/


Enjoy,
--
EuroPython 2017 Team
http://ep2017.europython.eu/
http://www.europython-society.org/

PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/924283342291431424
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python noob having a little trouble with strings

2017-10-28 Thread William Ray Wing
OSX has been shipping with Python 2.7 for several years.  I’m not sure why you 
are seeing 2.6.

Bill

> On Oct 27, 2017, at 2:48 AM, Lutz Horn  wrote:
> 
> On Thu, Oct 26, 2017 at 07:59:10PM -0700, [email protected] wrote:
>> Hi Bob, thanks for responding. I'm not sure where to do so, my
>> professor had us download Pycharm for mac's which uses python 2.6
> 
> The code from your question is not specific to Python 2 or 3. Just try
> it in the Python installation you have available.
> 
> Lutz
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Compression of random binary data

2017-10-28 Thread Ben Bacarisse
Steve D'Aprano  writes:

> On Fri, 27 Oct 2017 09:53 am, Ben Bacarisse wrote:
>
>> A source of random can be defined but "random data" is much more
>> illusive.
>
> Random data = any set of data generated by "a source of random".

(I had an editing error there; it should be "a source of random data".)

Yes, that's a fine definition, but it has the disadvantage of not being
a verifiable property of the thing defined -- you can't know, from the
data themselves, if they constitute random data.  You would not care
about a compression program that worked on some data that looks random,
you'd want to present your own data for compression (and then you can
use a random source with confidence because the data are yours).  That's
the big win (for me) of talking about "arbitrary data".

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


Re: Ide vs ide

2017-10-28 Thread Andrew Z
I like this trajectory of conversation.
Can we re define "small tiny" as "scripts"?
 i can argue, based on my expirience with other languages, that there is no
need for an "ide". The most ive ever needed is a text editor and a few
plugins with "print".

Moving to "average" size projects.
What i found useful and what i use constantly:
 Built in, up to date, correct! help on _installed_classes, functions. The
golden standard all these years for me was Delphi (2,3).
 Drop downs to show list of functions for an object. Also validates your
logic as far as you  use of correct variable, type etc.
Templates- define a language construct,
Type a shortcut and get the whole construct inserted. Saves typing.
Built-in change control,  build.

This is the main functionality i use . Needless to say the ide itself has
to be professional. And, since im not doing coding 24x7, i prefer "buttons"
as opposite to shortcut-to-find-the-shortcut-so-i-can-shortcut to get the
action. (Yeah, i found myself far less productive  while using atom and
company).at the same time, using editors like atom, whenyou work with
multiple filetypes is a gods sent .





On Oct 28, 2017 07:40, "Rustom Mody"  wrote:

> On Saturday, October 28, 2017 at 4:46:03 PM UTC+5:30, Christian Gollwitzer
> wrote:
> > Am 28.10.17 um 09:04 schrieb Rustom Mody:
> > > [The other day I was writing a program to split alternate lines of a
> file;
> > > Apart from file-handling it was these two lines:
> > >
> > >  for x in lines[0::2]:   print(x.strip())
> > >  for x in lines[1::2]:   print(x.strip())
> > > ]
> >
> > ...and using the best(TM) tool for it, it is a one-liner:
> >
> > gawk '{ print > "split" NR%2}' input.txt
>
> Ooo!¡!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


sys.path[] question

2017-10-28 Thread ElChino

From the Python2.7 snippet in [1], Python2.7 reports that my
sys.path[] contains:
  f:\ProgramFiler\Python27\lib\site-packages\pyreadline-2.0-py2.7-win32.egg

(a .zip-file)

But I have also a 'f:\ProgramFiler\Python27\lib\site-packages\pyreadline'
directory. With the complete package AFAICS.

So my question is where will Python import a 'import pyreadline' from?
E.f. if I do a:
  python -vv 
f:\ProgramFiler\Python27\lib\site-packages\pyreadline\test\test_lineeditor.py

it shows a:
  # zipimport: found 89 names in 
F:\ProgramFiler\Python27\lib\site-packages\pyreadline-2.0-py2.7-win32.egg
But no other references to pyreadline-2.0-py2.7-win32.egg.

Does that mean that only this .egg is where python imports all pyreadline
files from? And if so, can I delete
  'f:\ProgramFiler\Python27\lib\site-packages\pyreadline' ?

--

[1]: in a py-path.bat file:
   f:\ProgramFiler\Python27\python.exe -c "import sys; [sys.stdout.write('%%2d: %%s\n' %% (i,p)) for (i,p) in 
enumerate(sys.path)]"


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


Re: What use is of this 'cast=float ,'?

2017-10-28 Thread Rick Johnson
On Friday, October 27, 2017 at 3:35:45 PM UTC-5, Robert wrote:
> I read below code snippet on line. I am interested in the
> second of the last line: `cast=float`. I've tried it in
> Python. Even simply with: `float` It has no error, but what
> use is it? 
> 
> self.freqslider=forms.slider(
>  parent=self.GetWin( ),
>  sizer=freqsizer,
>  value=self.freq,
>  callback= self.setfreq,
>  minimum=−samprate/2,
>  maximum=samprate/2,
>  num_steps=100,
>  style=wx.SL_HORIZONTAL,
>  cast=float ,
>  proportion=1,
> )

This is a fine example of the distinctly pungent form of
code-smell otherwise known as: "unintuitive naming
convention".

A more informative keyword argument would have been
something like "castFunc" or "castTo" or even "returnType",
any of which would indicate that the argument is (depending
on the specific implementation of course) expected to be a
function object or that some specific type of "casting
action" is to be performed on the return value. Whereas,
using the ambiguous word "cast" leaves too much to the
imagination. And while my crazy-uncle-who-lives-in-the-
basement swears that lingerie magazines are better than the
nudie mags (because, in the case of the former, more is
reserved for the imagination), an API that requires
imagination to grokk is a poorly designed API.

Here is an interactive example of assigning a builtin to a
generic, allbeit very _intuitive_, symbol.

>>> value = "12.3"
>>> type(value)

>>> castFunc = float
>>> valueAsFloat = castFunc(value)
>>> valueAsFloat
12.3
>>> type(valueAsFloat)

>>> value = "12.3"
#
# And now for integers...
#
>>> castfunc = int
>>> valueAsInteger = castfunc(value)
Traceback (most recent call last):
  File "", line 1, in 
valueAsInteger = castfunc(value)
ValueError: invalid literal for int() with base 10: '12.3'

Oops! O:-) Well, don't blame me because Python is so hobbled that
it cannot even convert a string-ified version of a float into
an integer. *SHRUGS*

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


Coding style in CPython implementation

2017-10-28 Thread Στέφανος Σωφρονίου
Greetings everyone.

I have noticed that in many if conditions the following syntax is used:

a) if (variable == NULL) { ... }
b) if (variable == -1) { ... }
c) if (variable != NULL) { ... }

What I wanted to ask is, is there a particular reason for not choosing

a) if (!variable) { ... } in place of if (variable == NULL) { ... },
b) if (-1 == variable) { ... } in place of if (variable == -1) { ... }, and
c) if (variable) { ... } in place of if (variable) { ... } ?

Especially the (b) syntax is extremely dangerous to assign -1 to variable in 
case of an accidental mistyping of equals sign; it had happened countless times 
by now to to many of us that use various C-family languages.

Is there a particular reason for using this specific coding style?

Regards,

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


Re: Coding style in CPython implementation

2017-10-28 Thread bartc

On 28/10/2017 19:42, Στέφανος Σωφρονίου wrote:

Greetings everyone.

I have noticed that in many if conditions the following syntax is used:

a) if (variable == NULL) { ... }
b) if (variable == -1) { ... }
c) if (variable != NULL) { ... }

What I wanted to ask is, is there a particular reason for not choosing

a) if (!variable) { ... } in place of if (variable == NULL) { ... },
b) if (-1 == variable) { ... } in place of if (variable == -1) { ... }, and
c) if (variable) { ... } in place of if (variable) { ... } ?


(Presumably you meant variable != NULL)


Especially the (b) syntax is extremely dangerous to assign -1 to variable in 
case of an accidental mistyping of equals sign; it had happened countless times 
by now to to many of us that use various C-family languages.

Is there a particular reason for using this specific coding style?


Which one do you think is more readable?

Which style would you prefer to read?

Or do you prefer the more cryptic style in open source code?


(The = vs. == issue is of one of numerous design flaws in C, but 
uglifying source code to get around it isn't the answer.)




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


Re: Coding style in CPython implementation

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 5:42 AM, Στέφανος Σωφρονίου
 wrote:
> Greetings everyone.
>
> I have noticed that in many if conditions the following syntax is used:
>
> a) if (variable == NULL) { ... }
> b) if (variable == -1) { ... }
> c) if (variable != NULL) { ... }
>
> What I wanted to ask is, is there a particular reason for not choosing
>
> a) if (!variable) { ... } in place of if (variable == NULL) { ... },
> b) if (-1 == variable) { ... } in place of if (variable == -1) { ... }, and
> c) if (variable) { ... } in place of if (variable) { ... } ?
>
> Especially the (b) syntax is extremely dangerous to assign -1 to variable in 
> case of an accidental mistyping of equals sign; it had happened countless 
> times by now to to many of us that use various C-family languages.
>
> Is there a particular reason for using this specific coding style?

Have you read PEP 7?

https://www.python.org/dev/peps/pep-0007/

PEP 7 and PEP 8 are a pair of style guides that govern the CPython
source code - PEP 7 for the C code, and PEP 8 for the Python code in
the standard library. Unfortunately, many people seem to think that
PEP 8 is supposed to govern *their* code, and as such, end up not even
realizing that PEP 7 exists to answer all the same sorts of questions.

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


Re: Ide vs ide

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 6:10 AM, Stefan Ram  wrote:
> Rustom Mody  writes:
>>Useful python programs are often small; even tiny
>
>   We must not forget that tiny programs are just large
>   problems with the size masterfully hidden.
>
>   For example, the »print« of Python is actually implemented
>   by a subprogram (in C or Python) which invokes other subprograms.
>
>   If we would add the listing to all subprograms invoked
>   during the execution of a small Python script such as
>
> print( 2 )
>
>   , it would become much larger.
>
>   So this serves to illustrate
>
>  "Fools ignore complexity.
>   Pragmatists suffer it.
>   Some can avoid it.
>   Geniuses remove it."

At which point you're just arguing levels of abstraction. If someone
comes to me and says, hey look, I can do all this numerical
computation and analysis in one line of simple code, I won't argue
that it's not really "one line" just because it depends on Pandas -
I'll agree with him/her on the basis that Pandas grants you an
extremely high level of abstraction for data manipulation. That print
function does a lot of work, yes, but logically it does one thing: it
prints stuff out.

Tiny Python programs are still tiny in terms of elegance and
readability. And the CPython interpreter has over four hundred
separate files full of unit tests to help ensure that the lower
abstraction layers are correctly representing the intent of the higher
layers.

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


Re: Compression of random binary data

2017-10-28 Thread Peter Pearson
On Thu, 26 Oct 2017 19:26:11 -0600, Ian Kelly  wrote:
>
> . . . Shannon entropy is correctly calculated for a data source,
> not an individual message . . .

Thank you; I was about to make the same observation.  When
people talk about the entropy of a particular message, you
can bet they're headed for confusion.

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


Re: Coding style in CPython implementation

2017-10-28 Thread Ned Batchelder

On 10/28/17 3:00 PM, Stefan Ram wrote:

=?UTF-8?B?zqPPhM6tz4bOsc69zr/PgiDOo8+Jz4bPgc6/zr3Or86/z4U=?= 
 writes:

What I wanted to ask is, is there a particular reason for not choosing

   I am not a CPython developer, but here are my 2 cents about
   the possibilities:


if (variable == NULL) { ... }
if (!variable) { ... }

   »!variable« is clearer, because it does not depend on the
   definition of »NULL«. »NULL« is not part of the C language proper.
Especially if NULL is not part of the standard, then you need to write 
"variable == NULL", since "!variable" may not have the same effect after 
"return NULL;" depending on how NULL is defined.


   (I sometimes like to write »if( variable ); else { ... }«.)

Ick.

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


Repairing Python installation?

2017-10-28 Thread Martin Schöön
It seems something is amiss with my Python 2.7 installation. Revisiting
Nikola (static web site generator written in Python) for the first time
in several years the other day I experience some unexpected problems. I
got some help form the Nikola people and the conclusion is something
is broken with my Python 2.7. Pip list throws exceptions at me while
pip3 list works the way I expect it to do.

All this is happening on a Debian machine.

Questions:

Should I try to pinpoint what is broken (and how is that done) or should
I just remove everything Python 2.7 and re-install?

Could mixing pip installs with Debian distro installs of Python
packages lead to conflicts or other problems?

TIA,

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


Re: Coding style in CPython implementation

2017-10-28 Thread Ned Batchelder

On 10/28/17 4:26 PM, Stefan Ram wrote:

Ned Batchelder  writes:

On 10/28/17 3:00 PM, Stefan Ram wrote:

=?UTF-8?B?zqPPhM6tz4bOsc69zr/PgiDOo8+Jz4bPgc6/zr3Or86/z4U=?= 
 writes:

What I wanted to ask is, is there a particular reason for not choosing

definition of »NULL«. »NULL« is not part of the C language proper.

Especially if NULL is not part of the standard,

   »NULL« is defined in the standard, but it is an identifier
   from the library and, therefore, needs an »#include«.

   The language proper is the language core without any
   library added.

   The expression »NULL« AFAIK has only the meaning that
   usually is intended if one of the headers needed for
   it has been »#include«d.

   The operator »!« and the if-statement do not require
   any »#include«.



I certainly wouldn't adjust my coding style to avoid #include'ing the 
definition of NULL.


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


Re: Repairing Python installation?

2017-10-28 Thread Karsten Hilbert
On Sat, Oct 28, 2017 at 08:41:34PM +, Martin Schöön wrote:

> It seems something is amiss with my Python 2.7 installation. Revisiting
> Nikola (static web site generator written in Python) for the first time
> in several years the other day I experience some unexpected problems. I
> got some help form the Nikola people and the conclusion is something
> is broken with my Python 2.7. Pip list throws exceptions at me
...
> All this is happening on a Debian machine.

Exceptions or crashes of the python interpreter ?

Karsten
-- 
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem with subprocess.Popen and EINTR

2017-10-28 Thread Piet van Oostrum
I am using Python 2.7.14 on MacOS Sierra.

I have a small Python program that calls a shell script in a loop with a 
time.sleep() in it.
The shell script is called with subprocess.Popen(), followed by a 
subprocess.wait().
No information is exchanged with the shell script.

Once in a while I send a SIGINT to the program to cancel the sleep. I don't 
know if the sleep is active at the time of the SIGINT, but most of the time it 
will be as it takes much more time than the shell script.

I do this by having a handler for the SIGINT which does nothing. It is just 
there to have the SIGINT silently cancel the sleep.

Now after weeks of running correctly it crashed. It appears that the SIGINT 
came during the Popen. This causes a system call in the Popen to be terminated 
with EINTR and Popen then retries that system call, but unfortunately it fails. 
It seems to me that this could be a bug.

Here is the traceback:

Traceback (most recent call last):
  File "/Users/piet/bin/smoveinloop.py", line 86, in 
main()
  File "/Users/piet/bin/smoveinloop.py", line 65, in main
task = subprocess.Popen([TASK], executable=TASK)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
 line 390, in __init__
errread, errwrite)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
 line 1001, in _execute_child
data = _eintr_retry_call(os.read, errpipe_read, 1048576)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
 line 121, in _eintr_retry_call
return func(*args)
OSError: [Errno 22] Invalid argument

TASK is a string with the name of the shell script.

Can anybody shed some light on this?
-- 
Piet van Oostrum 
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]

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


Re: Problem with subprocess.Popen and EINTR

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 8:56 AM, Piet van Oostrum  wrote:
> I am using Python 2.7.14 on MacOS Sierra.
>
> I have a small Python program that calls a shell script in a loop with a 
> time.sleep() in it.
> The shell script is called with subprocess.Popen(), followed by a 
> subprocess.wait().
> No information is exchanged with the shell script.
>
> Once in a while I send a SIGINT to the program to cancel the sleep. I don't 
> know if the sleep is active at the time of the SIGINT, but most of the time 
> it will be as it takes much more time than the shell script.
>
> I do this by having a handler for the SIGINT which does nothing. It is just 
> there to have the SIGINT silently cancel the sleep.
>
> Now after weeks of running correctly it crashed. It appears that the SIGINT 
> came during the Popen. This causes a system call in the Popen to be 
> terminated with EINTR and Popen then retries that system call, but 
> unfortunately it fails. It seems to me that this could be a bug.

That definitely could be a bug. The behaviour of signals and retries
of system calls got changed more recently, but Python 2.7 is the
oldstable version and didn't get that sort of change. My advice to you
is simply live with it; the probability of it recurring is low (if, as
you say, the sleep takes the bulk of the time), unless you can migrate
to Python 3, to take advantage of the new behaviour.

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


Re: Problem with subprocess.Popen and EINTR

2017-10-28 Thread Cameron Simpson

On 29Oct2017 10:11, Cameron Simpson  wrote:
It may be a bug. Or it may be a system call which cannot be meaningfulling 
retried. But had you considered only activating the handler around the sleep?  
You still need to copy with SIGINT single I infer that you send this from 
outside the program.


I need more coffee. Or less. "meaningfully". "copy" ==> "cope". "single" => 
"since".


Argh,
Cameron Simpson  (formerly [email protected])
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with subprocess.Popen and EINTR

2017-10-28 Thread Cameron Simpson

On 28Oct2017 23:56, Piet van Oostrum  wrote:

I am using Python 2.7.14 on MacOS Sierra.

I have a small Python program that calls a shell script in a loop with a 
time.sleep() in it.
The shell script is called with subprocess.Popen(), followed by a 
subprocess.wait().
No information is exchanged with the shell script.

Once in a while I send a SIGINT to the program to cancel the sleep. I don't 
know if the sleep is active at the time of the SIGINT, but most of the time it 
will be as it takes much more time than the shell script.

I do this by having a handler for the SIGINT which does nothing. It is just 
there to have the SIGINT silently cancel the sleep.

Now after weeks of running correctly it crashed. It appears that the SIGINT 
came during the Popen. This causes a system call in the Popen to be terminated 
with EINTR and Popen then retries that system call, but unfortunately it fails. 
It seems to me that this could be a bug.


It may be a bug. Or it may be a system call which cannot be meaningfulling 
retried. But had you considered only activating the handler around the sleep?  
You still need to copy with SIGINT single I infer that you send this from 
outside the program.  What if you did this:


 os.signal(SIGINT, SIG_IGN)
 ... code code code, including the Popen/wait ...
 old_handler = os.signal(SIGINT, do_nothing_handler)
 sleep(...)
 os.signal(SIGINT, old_handler)

SIG_IGN is different from a do-nothing handler; it prevents the process seeing 
the signal at all, and therefore prevents the signal interrupting system calls.


So you activate your dummy-quit-sleeping function only around the sleep itself.

Cheers,
Cameron Simpson  (formerly [email protected])
--
https://mail.python.org/mailman/listinfo/python-list


Re: Coding style in CPython implementation

2017-10-28 Thread Στέφανος Σωφρονίου
On Saturday, October 28, 2017 at 9:54:30 PM UTC+3, bartc wrote:
> On 28/10/2017 19:42, Στέφανος Σωφρονίου wrote:
> > Greetings everyone.
> > 
> > I have noticed that in many if conditions the following syntax is used:
> > 
> > a) if (variable == NULL) { ... }
> > b) if (variable == -1) { ... }
> > c) if (variable != NULL) { ... }
> > 
> > What I wanted to ask is, is there a particular reason for not choosing
> > 
> > a) if (!variable) { ... } in place of if (variable == NULL) { ... },
> > b) if (-1 == variable) { ... } in place of if (variable == -1) { ... }, and
> > c) if (variable) { ... } in place of if (variable) { ... } ?
> 
> (Presumably you meant variable != NULL)

Yep, I forgot to show the != NULL part; good catch!

> 
> > Especially the (b) syntax is extremely dangerous to assign -1 to variable 
> > in case of an accidental mistyping of equals sign; it had happened 
> > countless times by now to to many of us that use various C-family languages.
> > 
> > Is there a particular reason for using this specific coding style?
> 
> Which one do you think is more readable?
> 
> Which style would you prefer to read?
> 
> Or do you prefer the more cryptic style in open source code?
> 
> 
> (The = vs. == issue is of one of numerous design flaws in C, but 
> uglifying source code to get around it isn't the answer.)

I understand what you are saying and I don't have a styling preference, at 
least in CPython's case.

I do believe though that if (!d) is a lot clearer than if (d == NULL) as it is 
safer than falsely assigning NULL in d, by pure mistake.

But indeed it's a matter of taste.

I just wanted to see whether there is a certain favor around such coding style, 
that's all.

> 
> 
> 
> -- 
> bartc

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


Re: Repairing Python installation?

2017-10-28 Thread Percival John Hackworth
On 28-Oct-2017, Martin Schöön wrote
(in article ):

> It seems something is amiss with my Python 2.7 installation. Revisiting
> Nikola (static web site generator written in Python) for the first time
> in several years the other day I experience some unexpected problems. I
> got some help form the Nikola people and the conclusion is something
> is broken with my Python 2.7. Pip list throws exceptions at me while
> pip3 list works the way I expect it to do.
>
> All this is happening on a Debian machine.
>
> Questions:
>
> Should I try to pinpoint what is broken (and how is that done) or should
> I just remove everything Python 2.7 and re-install?
>
> Could mixing pip installs with Debian distro installs of Python
> packages lead to conflicts or other problems?
>
> TIA,
>
> /Martin

If this site is accessible from the internet, have you looked around other 
parts of the system? Like date/timestamps for /bin/*. I recently was asked to 
look at a friends web site and found they were doing several things that I 
consider a security no-no, like running the tomcat server as root to serve 
their web site. It had been root-kitted. I helped them setup a new system 
that ran tomcat under a non-priv user.

It's just a SWAG, but perhaps something further is amiss that you don't see. 
I was really surprised that my friend, a pretty good programmer, was clueless 
about such things.

The only other time I've seen python "damaged" was when some developer 
decided they wanted a more current version than the default installed on the 
CentOS system (2.6) which is required for updating the system. They borked it 
beyond repair and my boss took away root access after we repaired it.

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


Re: Compression of random binary data

2017-10-28 Thread Steve D'Aprano
On Sun, 29 Oct 2017 07:03 am, Peter Pearson wrote:

> On Thu, 26 Oct 2017 19:26:11 -0600, Ian Kelly  wrote:
>>
>> . . . Shannon entropy is correctly calculated for a data source,
>> not an individual message . . .
> 
> Thank you; I was about to make the same observation.  When
> people talk about the entropy of a particular message, you
> can bet they're headed for confusion.

I don't think that's right. The entropy of a single message is a well-defined
quantity, formally called the self-information. The entropy of a data source
is the expected value of the self-information of all possible messages coming
from that data source.

https://en.wikipedia.org/wiki/Self-information

We can consider the entropy of a data source as analogous to the population
mean, and the entropy of a single message as the sample mean. A single
message is like a sample taken from the set of all possible messages.

Self-information is sometimes also called "surprisal" as it is a measure of
how surprising an event is. If your data source is a coin toss, then actually
receiving a Heads has a self-information ("entropy") of 1 bit. That's not
very surprising. If your data source is a pair of fair, independent dice,
then the self-information of receiving a two and a four is 5.170 bits. Its a
logarithmic scale, not linear: if the probability of a message or event is p,
the self-information of that event is log_2 (1/p) bits.



-- 
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: Compression of random binary data

2017-10-28 Thread Ian Kelly
On Oct 28, 2017 10:30 AM, "Stefan Ram"  wrote:
> Well, then one can ask about the entropy of a data source
> thatt only is emitting this message. (If it needs to be endless:
> thatt only is emitting this message repeatedly.)

If there is only one possible message then the entropy is zero.

-1.0 * log2(1.0) == 0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compression of random binary data

2017-10-28 Thread Gregory Ewing

Ben Bacarisse wrote:

But that has to be about the process that gives rise to the data, not
the data themselves.



If I say: "here is some random data..." you can't tell if it is or is
not from a random source.  I can, as a parlour trick, compress and
recover this "random data" because I chose it.


Indeed. Another way to say it is that you can't conclude
anything about the source from a sample size of one.

If you have a large enough sample, then you can estimate
a probability distribution, and calculate an entropy.


I think the argument that you can't compress arbitrary data is simpler
...  it's obvious that it includes the results of previous
compressions.


What? I don't see how "results of previous compressions" comes
into it. The source has an entropy even if you're not doing
compression at all.

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


Re: Coding style in CPython implementation

2017-10-28 Thread Dan Sommers
On Sat, 28 Oct 2017 16:20:54 -0700, Στέφανος Σωφρονίου wrote:

> I do believe though that if (!d) is a lot clearer than if (d == NULL)
> as it is safer than falsely assigning NULL in d, by pure mistake.

Having made my living writing C code for a very long time, I always
found if (!d) *harder* to read, especially if it happened to be written
if(!d) without the space, because it was never a single character name
the ! disappeared into the noise.  OTOH, = vs. == always stuck out like
a sore thumb.  Then again, I grew up with monochrome terminals
vs. unusably slow syntax highlighting, and grayscale printers (and we
had to live in a small shoebox in the middle of the road).

YMMV.  Obviously.

Dan

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


Re: Compression of random binary data

2017-10-28 Thread Gregory Ewing

[email protected] wrote:

10101011
This equals
61611
This can be represented using
0-6 log2(7)*5= 14.0367746103 bits


11010101
This equals 
54543

This can be represented using
0-5 log2(6)*5= 12.9248125036 bits


You're missing something fundamental about what
entropy is in information theory.

It's meaningless to talk about the entropy of a single
message. Entropy is a function of the probability
distribution of *all* the messages you might want to
send.

What you calculated in your first example relates to
this situation: You want to send someone messages
consisting of 5 symbols drawn from the set {0, 1,
2, 3, 4, 5, 6}, where all such messages have equal
probability. In that case, you need and average of
about 14.03 bits for each message.

Note that this has essentially nothing to do with
the particular sequence of bits you started with.

Your second calculation was for a similar situation,
except that the set of symbols is just {0, 1, 2,
3, 4, 5}. There are fewer messages of length 5 that
can be constructed from that set, so the number of
bits needed is smaller.


In reality you can express 54543 with 10 bits.


Again, this statement is meaningless. You can't
say *anything* about the number of bits needed to
represent that particular number, without knowing
what *other* numbers you might want to represent.

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


Re: Compression of random binary data

2017-10-28 Thread Gregory Ewing

Steve D'Aprano wrote:


Random data = any set of data generated by "a source of random".


Any set of data generated by Grant Thompson?

https://www.youtube.com/user/01032010814

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


Re: Compression of random binary data

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 1:18 PM, Gregory Ewing
 wrote:
> You're missing something fundamental about what
> entropy is in information theory.
>
> It's meaningless to talk about the entropy of a single
> message. Entropy is a function of the probability
> distribution of *all* the messages you might want to
> send.

Which is where a lot of "password strength" confusion comes from. How
much entropy is there in the password "U3ZINVp3PT0="? Strong password
or weak? What about "dark-next-sure-secret"?
"with-about-want-really-going"? They were generated by, respectively:
double-MIME-encoding four bytes from /dev/random (32 bits of entropy),
picking four words from the top 1024 (40 bits), and picking 5 words
from the top 64 (30 bits). But just by looking at the passwords
themselves, you can't tell that.

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


Re: Compression of random binary data

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 1:32 PM, Chris Angelico  wrote:
> On Sun, Oct 29, 2017 at 1:18 PM, Gregory Ewing
>  wrote:
>> You're missing something fundamental about what
>> entropy is in information theory.
>>
>> It's meaningless to talk about the entropy of a single
>> message. Entropy is a function of the probability
>> distribution of *all* the messages you might want to
>> send.
>
> Which is where a lot of "password strength" confusion comes from. How
> much entropy is there in the password "U3ZINVp3PT0="? Strong password
> or weak? What about "dark-next-sure-secret"?
> "with-about-want-really-going"? They were generated by, respectively:
> double-MIME-encoding four bytes from /dev/random (32 bits of entropy),
> picking four words from the top 1024 (40 bits), and picking 5 words
> from the top 64 (30 bits). But just by looking at the passwords
> themselves, you can't tell that.

To clarify: The "top 1024 words" concept is XKCD 936 style password
generation, using my tabletop gaming room's resident parrot. So it's
based on the frequency of words used by D&D players. YMMV if you use a
different corpus :)

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


Re: Compression of random binary data

2017-10-28 Thread Gregory Ewing

Stefan Ram wrote:

  Well, then one can ask about the entropy of a data source
  that only is emitting this message.


You can, but it's still the *source* that has the entropy,
not the message.

(And the answer in that case is that the entropy is zero.
If there's only one possible message you can ever send, you
don't need to send it at all!)

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


Re: Compression of random binary data

2017-10-28 Thread Gregory Ewing

Steve D'Aprano wrote:

I don't think that's right. The entropy of a single message is a well-defined
quantity, formally called the self-information. 


https://en.wikipedia.org/wiki/Self-information


True, but it still depends on knowing (or assuming) the
probability of getting that particular message out of
the set of all possible messages.

This is *not* what danceswithnumbers did when he
calculated the "entropy" of his example bit sequences.
He didn't define the set they were drawn from or
what their probabilities were.

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


Re: Compression of random binary data

2017-10-28 Thread Chris Angelico
On Sun, Oct 29, 2017 at 2:08 PM, Gregory Ewing
 wrote:
> Stefan Ram wrote:
>>
>>   Well, then one can ask about the entropy of a data source
>>   that only is emitting this message.
>
>
> You can, but it's still the *source* that has the entropy,
> not the message.
>
> (And the answer in that case is that the entropy is zero.
> If there's only one possible message you can ever send, you
> don't need to send it at all!)

One bit. It might send the message, or it might NOT send the message.

And I have known situations in which that is exactly the system used.
Back before mobile phones were common, you could sometimes use a
payphone to cause someone's phone to ring, but you couldn't actually
speak on it. So you had one message you could send: "bing
bring". A pre-arranged meaning for that message might be "I'm at
the railway station, please come and pick me up"... but there's still
*some* information in the mere fact of the call.

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