Re: Let's talk about debuggers!

2017-10-27 Thread Robin Becker

On 25/10/2017 15:08, Michele Simionato wrote:

pdb plus plus: https://pypi.python.org/pypi/pdbpp

I like the idea, but in putty at least changing the terminal size causes pdb++ 
to detach immediately from the process and mess up the screen. I think this is 
caused by (5, 'Input/output error') here


/home/rptlab/devel/otr/local/lib/python2.7/site-packages/pyrepl/fancy_termios.py 
in tcsetattr




def copy(self):
return self.__class__(self.as_list())
def tcgetattr(fd):
return TermState(termios.tcgetattr(fd))
def tcsetattr(fd, when, attrs):
termios.tcsetattr(fd, when, attrs.as_list())

 error is here

class Term(TermState):
TS__init__ = TermState.__init__
def __init__(self, fd=0):
self.TS__init__(termios.tcgetattr(fd))
self.fd = fd



--
Robin Becker

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


Re: How to plot

2017-10-27 Thread Thomas Jollans
On 2017-10-27 07:18, Andrew Z wrote:
> Hello,
>  i'd like to create a graph/plot based a DB table's data, but not sure
> where to start. I
> 
>  also would like to have the following functionality:
>  a. i'd like to have it in the separate window ( xwindow to be precise).
>  b. and i'd like to have the graph updating with every record added to the
> table.
> 
> The workflow:
>  a. main code is running and occasionally adding records to the table
>  b. graph gets updated "automagically" and is shown in a separate from the
> main terminal window.
> 
> Main program does not have GUI, nor is Web based, just runs in the terminal
> on Xwindows.
> 
> i don't' really care about cross-platform compability and only want to run
> that on linux xwindows.
> 
> Thank you for your advise.
> 

Matplotlib  is the standard Python plotting
library, and it has GUI backends (Tk, Qt, Gtk, ...) that should be
perfectly suitable for your purposes.

The API maybe takes some getting used to, but there are plenty of
examples to be found around the web, and the main documentation is quite
good.

If you need the plots to update quickly (it doesn't sound like it) then
you might need to luck into something else, like pyqtgraph or vispy.


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


Re: Python noob having a little trouble with strings

2017-10-27 Thread Peter J. Holzer
On 2017-10-27 02:59, randyli...@gmail.com  wrote:
> On Thursday, October 26, 2017 at 7:41:10 PM UTC-7, boB Stepp wrote:
>> On Thu, Oct 26, 2017 at 9:25 PM,   wrote:
[...]
>> Why not find out for yourself and print these in the Python
>> interpreter?  For instance:
>> 
>> > py
>> Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64
>> bit (AMD64)] on win32
[...]
> 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

Open "Python Console ..." in the "Tools" menu.

Or just open a terminal window and type "python" there.

BTW, I find it hard to believe that PyCharm for the Mac "comes with"
Python 2.6. Python 2.6 is quite old. The Linux version isn't bundled
with a python interpreter and just uses whatever is already installed on
the machine. I guess it's the same for the Mac: Your version of MacOS
happens to include Python 2.6, so this is what PyCharm uses.

Oh, and ask your professor if you are really supposed to use Python 2.6.
There are differences between versions (especially between 2.x and 3.x)
and you'll be hopelessly confused if you use 2.6 and your professor's
examples are written for 3.5.

hp


-- 
   _  | Peter J. Holzer| Fluch der elektronischen Textverarbeitung:
|_|_) || Man feilt solange an seinen Text um, bis
| |   | h...@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compression of random binary data

2017-10-27 Thread Ben Bacarisse
Marko Rauhamaa  writes:

> Ben Bacarisse :
>
>>> In this context, "random data" really means "uniformly distributed
>>> data", i.e. any bit sequence is equally likely to be presented as
>>> input. *That's* what information theory says can't be compressed.
>>
>> But that has to be about the process that gives rise to the data, not
>> the data themselves.  No finite collection of bits has the property you
>> describe.
>
> Correct. Randomness is meaningful only in reference to future events.
> Once the events take place, they cease to be random.
>
> A finite, randomly generated collection of bits can be tested against a
> probabilistic hypothesis using statistical methods.

But beware of parlour tricks.  You can't reliably test for random
looking data that are, in fact, carefully crafted.  If the claim is
about compressing arbitrary data, then the claimant won't mind testing
inputs chosen by me!  The only reason this matters is that such people
usually won't reveal the algorithm.

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


headless python app for android/ios

2017-10-27 Thread Robin Becker
In the past we have developed reportlab applications for use on android/ios 
devices. We used Kivy for the gui and the kivy setup did allow us to create a 
working reportlab pdf producer under the kivy gui. It was not exactly easy, but 
in the end we had a working PDF producer.


A possible requirement is for pdf production using reportlab, but with others 
providing the gui using possible something called electron.


I know very little about what is actually possible to provide api's in python 
under ios/android. Can the front end spawn a python process or must we run some 
kind of background app with  listening sockets etc etc? Can applications call 
out to the world to download updated templates and so on?


Any pointers would be useful.
--
Robin Becker

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


Re: How to plot

2017-10-27 Thread Andrew Z
 Rrhank you Thomas.

On Oct 27, 2017 04:23, "Thomas Jollans"  wrote:

> On 2017-10-27 07:18, Andrew Z wrote:
> > Hello,
> >  i'd like to create a graph/plot based a DB table's data, but not sure
> > where to start. I
> >
> >  also would like to have the following functionality:
> >  a. i'd like to have it in the separate window ( xwindow to be precise).
> >  b. and i'd like to have the graph updating with every record added to
> the
> > table.
> >
> > The workflow:
> >  a. main code is running and occasionally adding records to the table
> >  b. graph gets updated "automagically" and is shown in a separate from
> the
> > main terminal window.
> >
> > Main program does not have GUI, nor is Web based, just runs in the
> terminal
> > on Xwindows.
> >
> > i don't' really care about cross-platform compability and only want to
> run
> > that on linux xwindows.
> >
> > Thank you for your advise.
> >
>
> Matplotlib  is the standard Python plotting
> library, and it has GUI backends (Tk, Qt, Gtk, ...) that should be
> perfectly suitable for your purposes.
>
> The API maybe takes some getting used to, but there are plenty of
> examples to be found around the web, and the main documentation is quite
> good.
>
> If you need the plots to update quickly (it doesn't sound like it) then
> you might need to luck into something else, like pyqtgraph or vispy.
>
>
> --
> Thomas Jollans
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-10-27 Thread David Gabriel
Dears,

I am running a python code that generates for me this error :

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.

Do you have any idea how can I solve this problem.
Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python noob having a little trouble with strings

2017-10-27 Thread Christopher Reimer
On Oct 27, 2017, at 1:49 AM, Peter J. Holzer  wrote:
> 
> BTW, I find it hard to believe that PyCharm for the Mac "comes with"
> Python 2.6. Python 2.6 is quite old. The Linux version isn't bundled
> with a python interpreter and just uses whatever is already installed on
> the machine. I guess it's the same for the Mac: Your version of MacOS
> happens to include Python 2.6, so this is what PyCharm uses.

I find it hard to believe that a professor would recommend downloading an IDE 
at the start of an intro class. Students usually start off with a text editor.

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


psycopg2.ProgrammingError: syntax error at or near "\"

2017-10-27 Thread maheshyadav1771
Hello,

I am using 'psycopg2' library to access my PostgreSQL database from a python. I 
want to pass a variable input in psql query something like this :- 

psql>>\set my_user table1
psql>>select * from :my_user limit 10;

So I am just running these sql commands and getting this error :-

>>> cur.execute("""\set my_user table1""")
Traceback (most recent call last):
  File "", line 1, in 
psycopg2.ProgrammingError: syntax error at or near "\"
LINE 1: \set my_user table1


Can anyone please help me out here.

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


Re: psycopg2.ProgrammingError: syntax error at or near "\"

2017-10-27 Thread Karsten Hilbert
On Fri, Oct 27, 2017 at 08:35:20AM -0700, maheshyadav1...@gmail.com wrote:

> I am using 'psycopg2' library to access my PostgreSQL database from a python. 
> I want to pass a variable input in psql query something like this :- 
> 
> psql>>\set my_user table1
> psql>>select * from :my_user limit 10;
> 
> So I am just running these sql commands and getting this error :-
> 
> >>> cur.execute("""\set my_user table1""")
> Traceback (most recent call last):
>   File "", line 1, in 
> psycopg2.ProgrammingError: syntax error at or near "\"
> LINE 1: \set my_user table1

\set is a psql specific pseudo command rather than SQL. Only
SQL code can be run through psycopg2.

You want to read up on query parameter handling in the
psycopg2 docs. Psycopg2 and (/usr/bin/)psql(.exe) are not the
same thing.

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


Re: Python noob having a little trouble with strings

2017-10-27 Thread Chris Angelico
On Sat, Oct 28, 2017 at 1:14 AM, Christopher Reimer
 wrote:
> On Oct 27, 2017, at 1:49 AM, Peter J. Holzer  wrote:
>>
>> BTW, I find it hard to believe that PyCharm for the Mac "comes with"
>> Python 2.6. Python 2.6 is quite old. The Linux version isn't bundled
>> with a python interpreter and just uses whatever is already installed on
>> the machine. I guess it's the same for the Mac: Your version of MacOS
>> happens to include Python 2.6, so this is what PyCharm uses.
>
> I find it hard to believe that a professor would recommend downloading an IDE 
> at the start of an intro class. Students usually start off with a text editor.

No, I can definitely believe it. Among other advantages, getting
everyone onto a cross-platform IDE will tend to paper over a lot of OS
differences. You have three sets of instructions for downloading some
IDE for Lin/Mac/Win, and then everything else is just "here's how you
do it in ".

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


Just a quick question about main()

2017-10-27 Thread ROGER GRAYDON CHRISTMAN
While teaching my introductory course in Python, I occasionally see
submissions containing the following two program lines, even before
I teach about functions and modules:

if __name__ = '__main__':
...  main()

When I ask about it, I hear things like they got these from other instructors,
or from other students who learned it from their instructors, or maybe
from some on-line programming tutorial site.

I'm all on board with the first of these two lines -- and I teach it myself
as soon as I get to modules.

My question is more about the second.

Do "real" Pythonista's actually define a new function main() instead
of putting the unit test right there inside the if?

Or am I correct in assuming that this main() is just an artifact from
people who have programmed in C, C++, or Java for so long that
they cannot imagine a program without a function named "main"?

I guess I'm not stuck on that habit, since my programming experiences
go way back to the old Fortran days


Roger Christman
Pennsylvania State University
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Just a quick question about main()

2017-10-27 Thread Chris Angelico
On Sat, Oct 28, 2017 at 5:05 AM, ROGER GRAYDON CHRISTMAN  wrote:
> While teaching my introductory course in Python, I occasionally see
> submissions containing the following two program lines, even before
> I teach about functions and modules:
>
> if __name__ = '__main__':
> ...  main()
>
> When I ask about it, I hear things like they got these from other instructors,
> or from other students who learned it from their instructors, or maybe
> from some on-line programming tutorial site.
>
> I'm all on board with the first of these two lines -- and I teach it myself
> as soon as I get to modules.
>
> My question is more about the second.
>
> Do "real" Pythonista's actually define a new function main() instead
> of putting the unit test right there inside the if?
>
> Or am I correct in assuming that this main() is just an artifact from
> people who have programmed in C, C++, or Java for so long that
> they cannot imagine a program without a function named "main"?

If it's JUST for unit tests, I'd expect no main(), but instead to have
it go straight into unittest.main(). IMO, the construct you show there
implies three things:

1) This module is intended to be run from the command line
2) This module is intended to be imported by other modules
3) If imported by another module, this can also be invoked as if it
were the top-level app.

If #1 is not true, you don't need any sort of "if name is main" code,
because that's not the point. If #2 is not true, you don't need to
guard your main routine, because the condition will always be true.
(Note that external unit tests count as
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Just a quick question about main()

2017-10-27 Thread Chris Angelico
On Sat, Oct 28, 2017 at 5:23 AM, Chris Angelico  wrote:
> On Sat, Oct 28, 2017 at 5:05 AM, ROGER GRAYDON CHRISTMAN  wrote:
>> While teaching my introductory course in Python, I occasionally see
>> submissions containing the following two program lines, even before
>> I teach about functions and modules:
>>
>> if __name__ = '__main__':
>> ...  main()
>>
>> When I ask about it, I hear things like they got these from other 
>> instructors,
>> or from other students who learned it from their instructors, or maybe
>> from some on-line programming tutorial site.
>>
>> I'm all on board with the first of these two lines -- and I teach it myself
>> as soon as I get to modules.
>>
>> My question is more about the second.
>>
>> Do "real" Pythonista's actually define a new function main() instead
>> of putting the unit test right there inside the if?
>>
>> Or am I correct in assuming that this main() is just an artifact from
>> people who have programmed in C, C++, or Java for so long that
>> they cannot imagine a program without a function named "main"?
>
> If it's JUST for unit tests, I'd expect no main(), but instead to have
> it go straight into unittest.main(). IMO, the construct you show there
> implies three things:
>
> 1) This module is intended to be run from the command line
> 2) This module is intended to be imported by other modules
> 3) If imported by another module, this can also be invoked as if it
> were the top-level app.
>
> If #1 is not true, you don't need any sort of "if name is main" code,
> because that's not the point. If #2 is not true, you don't need to
> guard your main routine, because the condition will always be true.
> (Note that external unit tests count as

Whoops, premature send. External unit tests count as importing this
from another module, so that satisfies that.

But if #3 is not the case, then you might well have an "if name is
main" block, but there's no point having "def main()". Unless you
would import the module *and then call main*, don't bother having a
main(). Just have whatever other code you need, right there in the
'if' block. One thing I'll often do, for instance, is to have a pure
function that can be imported, and then do some simple command-line
parsing:

def spamify(ham, eggs, sausages):
"""Spamify stuff"""

if __name__ == "__main__":
import sys
_, ham, eggs, sausages, *_ = sys.argv + ["", "", ""]
print(spamify(ham, eggs, sausages))

No point having a main() to do that; the real work is in the
importable function, and for command-line usage, it simply calls that
function and prints the result.

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


Re: Just a quick question about main()

2017-10-27 Thread Thomas Jollans
On 27/10/17 20:05, ROGER GRAYDON CHRISTMAN wrote:
> While teaching my introductory course in Python, I occasionally see
> submissions containing the following two program lines, even before
> I teach about functions and modules:
> 
> if __name__ = '__main__':
> ...  main()
> 
> When I ask about it, I hear things like they got these from other instructors,
> or from other students who learned it from their instructors, or maybe
> from some on-line programming tutorial site.
> 
> I'm all on board with the first of these two lines -- and I teach it myself
> as soon as I get to modules.
> 
> My question is more about the second.
> 
> Do "real" Pythonista's actually define a new function main() instead
> of putting the unit test right there inside the if?

Perhaps not for unit tests, but for scripts, particularly if they come
with a larger package, this is actually fairly common: it allows
setuptools to generate a wrapper script that runs with the Python
version and environment it was installed with.

https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html

Combined with the way "python -m ..." works, this leads to slightly
silly-looking __main__.py modules like this:

https://github.com/jupyter/jupyter_core/blob/master/jupyter_core/__main__.py


> 
> Or am I correct in assuming that this main() is just an artifact from
> people who have programmed in C, C++, or Java for so long that
> they cannot imagine a program without a function named "main"?
> 
> I guess I'm not stuck on that habit, since my programming experiences
> go way back to the old Fortran days
> 
> 
> Roger Christman
> Pennsylvania State University
> 

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


Re: Compression of random binary data

2017-10-27 Thread Ian Kelly
On Thu, Oct 26, 2017 at 8:19 PM,   wrote:
> It looks like that averages my two examples.

I don't know how you can look at two numbers and then look at a third
number that is larger than both of them and conclude it is the
average.

> H by the way that equation is really coolwhy does it return a high 
> bit count when compared to >>>dec to bin?

I don't understand what you're asking. The binary representation of
either of those number is 16 bits, which is larger than my 15.8.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compression of random binary data

2017-10-27 Thread Ian Kelly
On Thu, Oct 26, 2017 at 8:48 PM,   wrote:
> Shouldn't that be?
>
> py> 16 * (-7/16 * math.log2(7/16) - 6/16 * math.log2(6/16)) =

No, that's failing to account for 3/16 of the probability space.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Just a quick question about main()

2017-10-27 Thread Grant Edwards
On 2017-10-27, Chris Angelico  wrote:
> On Sat, Oct 28, 2017 at 5:05 AM, ROGER GRAYDON CHRISTMAN  wrote:
>> While teaching my introductory course in Python, I occasionally see
>> submissions containing the following two program lines,[...]

>> if __name__ = '__main__':
>> ...  main()

> If it's JUST for unit tests, I'd expect no main(), but instead to have
> it go straight into unittest.main(). IMO, the construct you show there
> implies three things:
>
> 1) This module is intended to be run from the command line
> 2) This module is intended to be imported by other modules
> 3) If imported by another module, this can also be invoked as if it
>were the top-level app.

I sometimes create a main function out of habit even if I can't
imagine a case #3.

A typical situation that I often encounter is that I write a set of
functions to perform some task(s) via a serial or network connection
using some industrial protocol.  [For example, updating firmware in a
device.]

There are often two use cases:

1) It can be used from the command-line as a stand-alone application
   with various command line options and arguments that specify the
   operation[s] to be performed. 

2) It can be imported by a GUI application in order to provide to the
   GUI framework code the functions that can be called to do the
   individual operations.

Even if the real-world end-user use case is purely the GUI one, it's
often far easier and faster to also include a main() for deveopment
and testing of the functions provided to the GUI.

-- 
Grant Edwards   grant.b.edwardsYow! ONE LIFE TO LIVE for
  at   ALL MY CHILDREN in ANOTHER
  gmail.comWORLD all THE DAYS OF
   OUR LIVES.

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


PEP Post-History

2017-10-27 Thread Barry Warsaw
We’ve made a small change to the PEP process which may affect readers of 
python-list and python-ideas, so I’d like to inform you of it.  This change was 
made to PEP 1 and PEP 12.

PEPs must have a Post-History header which records the dates at which the PEP 
is posted to mailing lists, in order to keep the general Python community in 
the loop as a PEP moves to final status.  Until now, PEPs in development were 
supposed to be posted at least to python-dev and optionally to python-list[1].  
This guideline predated the creation of the python-ideas mailing list.

We’ve now changed this guideline so that Post-History will record the dates at 
which the PEP is posted to python-dev and optionally python-ideas.  python-list 
is dropped from this requirement.

python-dev is always the primary mailing list of record for Python development, 
and PEPs under development should be posted to python-dev as appropriate.  
python-ideas is the list for discussion of more speculative changes to Python, 
and it’s often where more complex PEPs, and even proto-PEPs are first raised 
and their concepts are hashed out.  As such, it makes more sense to change the 
guideline to include python-ideas and/or python-dev.  In the effort to keep the 
forums of record to a manageable number, python-list is dropped.

If you have been watching for new PEPs to be posted to python-list, you are 
invited to follow either python-dev or python-ideas.

Cheers,
-Barry (on behalf of the Python development community)

https://mail.python.org/mailman/listinfo/python-dev
https://mail.python.org/mailman/listinfo/python-ideas

Both python-dev and python-ideas are available via Gmane.

[1] PEPs may have a Discussions-To header which changes the list of forums 
where the PEP is discussed.  In that case, Post-History records the dates that 
the PEP is posted to those forums.  See PEP 1 for details.



signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-10-27 Thread Robert
Hi,

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?


I do see a space before the comma ','. Is it a typo or not?


Thanks,



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,
)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Just a quick question about main()

2017-10-27 Thread Ned Batchelder

On 10/27/17 2:05 PM, ROGER GRAYDON CHRISTMAN wrote:

While teaching my introductory course in Python, I occasionally see
submissions containing the following two program lines, even before
I teach about functions and modules:

if __name__ = '__main__':
...  main()

When I ask about it, I hear things like they got these from other instructors,
or from other students who learned it from their instructors, or maybe
from some on-line programming tutorial site.

I'm all on board with the first of these two lines -- and I teach it myself
as soon as I get to modules.

My question is more about the second.

Do "real" Pythonista's actually define a new function main() instead
of putting the unit test right there inside the if?

Or am I correct in assuming that this main() is just an artifact from
people who have programmed in C, C++, or Java for so long that
they cannot imagine a program without a function named "main"?


There's no need for "if __name__ == '__main__':" for unit tests. You can 
let unittest or pytest discover the tests themselves, and run them.


I often write this clause:

    if __name__ == '__main__':
    sys.exit(main(sys.argv))

Then I can write tests that call main() to be sure it does what I think 
it does.


Or, I can let setuptools entry_points handle that clause for me:

    entry_points={
    'console_scripts': [
    'coverage = coverage.cmdline:main',
    ],
    },


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


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

2017-10-27 Thread edmondo . giovannozzi
Il giorno venerdì 27 ottobre 2017 22:35:45 UTC+2, Robert ha scritto:
> Hi,
> 
> 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?
> 
> 
> I do see a space before the comma ','. Is it a typo or not?
> 
> 
> Thanks,
> 
> 
> 
> 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,
> )

cast is the name of keyword argument of the function slider called "cast". It 
likely means that it should return a float. Quite likely inside the function 
"slider" there will be something like 

return cast(...)

that if you pass float will become equivalent to

return float(...)

Of course I don't know that function so take it as just a likely possibility.

By the way, it can be a method of an object named forms or a function in a 
module named forms.

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


Speed Race between old and new version 'working with files'

2017-10-27 Thread japy . april
import time

avg = float(0)

# copy with WITH function and execute time
for i in range(500):
start = time.clock()
with open('q://my_projects/cricket.mp3', 'rb') as old, 
open('q://my_projects/new_cricket.mp3', 'wb') as new:
for j in old:
new.write(j)
stop = time.clock()

avg += (stop - start) / 500
print('Execute time with WITH version : ', avg)

# copy with OLD version OPEN FILE function and execute time
for i in range(500):
start = time.clock()
old = open('q://my_projects/cricket.mp3', 'rb')
new = open('q://my_projects/old_cricket.mp3', 'wb')
for j in old:
new.write(j)
old.close()
new.close()
stop = time.clock()

avg += (stop - start) / 500
print('Execute time with OLD version : ', avg)
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-10-27 Thread Cameron Simpson

On 27Oct2017 15:56, David Gabriel  wrote:

I am running a python code that generates for me this error :

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.


You need to fetch the "packaging" module. That is what pip is for, eg:

 pip install --user packaging

The --user is to install it in your "personal" python library space.

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Speed Race between old and new version 'working with files'

2017-10-27 Thread Steve D'Aprano
On Sat, 28 Oct 2017 09:11 am, japy.ap...@gmail.com wrote:

> import time
> 
> avg = float(0)

That should be written as 

avg = 0.0

or better still not written at all, as it is pointless.


> # copy with WITH function and execute time
> for i in range(500):
> start = time.clock()

time.clock() is an old, platform-dependent, low-resolution timer. It has been
deprecated in recent versions of Python. It is better to use:

from timeit import default_timer as clock

and use that, as the timeit module has already chosen the best timer available
on your platform.

In fact, you probably should be using timeit rather than re-inventing the
wheel, unless you have a good reason.

> with open('q://my_projects/cricket.mp3', 'rb') as old,
> open('q://my_projects/new_cricket.mp3', 'wb') as new:
> for j in old:
> new.write(j)

Reading a *binary file* line-by-line seems rather dubious to me. I wouldn't do
it that way, but for now we'll just keep it.

The simplest way to do this time comparison would be: 


oldfile = 'q://my_projects/cricket.mp3'
newfile = 'q://my_projects/new_cricket.mp3'

from timeit import Timer

def test_with():
with open(oldfile, 'rb') as old, \
open(newfile, 'wb') as new:
for line in old:
new.write(line)

def test_without():
old = open(oldfile, 'rb')
new = open(newfile, 'wb')
for line in old:
new.write(line)
old.close()
new.close()

setup = "from __main__ import test_with, test_without"

t1 = Timer("test_with()", setup)
t2 = Timer("test_without()", setup)

print('Time using with statement:')
print(min(t1.repeat(number=100, repeat=5)))
print('Time not using with statement:')
print(min(t2.repeat(number=100, repeat=5)))


On my computer, that gives a value of about 5.3 seconds and 5.2 seconds
respectively. That figure should be interpreted as:

- the best value of five trials (the 'repeat=5' argument);

- each trial calls the test_with/test_without function 100 times
  (the 'number=100' argument)

so on my computer, each call to the test function takes around 5/100 seconds,
or 50ms. So there's no significant speed difference between the two: using
the with statement is a tiny bit slower (less than 2% on my computer).

[...]
> avg += (stop - start) / 500

Better to skip the pointless initialision of avg and just write:

avg = (stop - start)/500

> avg += (stop - start) / 500
> print('Execute time with OLD version : ', avg)

That *adds* the time of the second test to the original timing, so your last
line should be:

print('Execute time with NEW version plus time with OLD version : ', avg)

to be accurate. But I don't think that's what you intended.




-- 
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: What use is of this 'cast=float ,'?

2017-10-27 Thread Tim Chase
[rearranging for easier responding]

On 2017-10-27 13:35, Robert wrote:
> 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,
> )
> I am interested in the second of the last line.
> 
>  cast=float ,

The space doesn't do anything.  You have a parameter list, so the
comma just separates "cast=float" from the next parameter,
"proportion=1". The "cast=float" passes the "float()" function as a
way of casting the data.  In this case, it likely expects a function
that takes a number or string, and returns a number that can be used
to render the slider's value/position.

You could create one that works backwards:

  def backwards_float(input):
return -float(input) # note the "-" inverting the interpreted
  value

  forms.slider(
…
cast=backwards_float,
…
)

> I've tried it in Python. Even simply with 
> 
> float

This is just the float() function.

> it has no error, but what use is it?

It's good for passing to something like the above that wants a
function to call.  The body of the function likely has something like

   resulting_value = cast(value)

which, in this case is the same as

   resulting_value = float(value)

> I do see a space before the comma ','. Is it a typo or not?

I think it's unintended.


The whole question started off peculiar because outside of a
function-invocation

   thing = other,

with the comma creates a one-element tuple and assigns the resulting
tuple to "thing"

  >>> x = 42
  >>> x
  42
  >>> y = 42,
  >>> y
  (42,)

Usually people will be more explicit because that comma is easy to
miss, so they'll write

  >>> z = (42,)
  >>> z
  (42,)

so that later people reading the code know that it's intended to be a
one-element tuple.

-tkc






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


Re: Just a quick question about main()

2017-10-27 Thread Ian Kelly
In addition to what others have answered, if the code in question has any
variables then I'll prefer to put it inside a function and call the
function. This ensures that the variables are local and not going. It's a
minor code hygiene point, but a good practice in my opinion.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Just a quick question about main()

2017-10-27 Thread Ian Kelly
On Oct 27, 2017 5:38 PM, "Ian Kelly"  wrote:

In addition to what others have answered, if the code in question has any
variables then I'll prefer to put it inside a function and call the
function. This ensures that the variables are local and not going. It's a
minor code hygiene point, but a good practice in my opinion.


s/going/global/ :P
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python noob having a little trouble with strings

2017-10-27 Thread Naman Bhalla
I guess your professor just asked you to download Pycharm. It is just MacOS 
that happens to have Python 2.6 inbuilt. Had your professor actually wanted you 
to be using Python 2 (I doubt), that would have been 2.7. Regardless of that I 
recommend having latest Python 2 or 3 as per your requirements, from 
python.org. 
In Pycharm, you can access Python Console from bottom right (Make sure you 
select correct version of Python in your project settings.) Or in MacOS, just 
type python and then type commands and check for yourself.
BTW, You can know more about what you are going to test here:- 
https://docs.python.org/3/tutorial/introduction.html#strings

Regards.

On 27/10/17, 08:33, "python-list-bounces+dev=namanbhalla...@python.org on 
behalf of randyli...@gmail.com" 
 wrote:

On Thursday, October 26, 2017 at 7:41:10 PM UTC-7, boB Stepp wrote:
> On Thu, Oct 26, 2017 at 9:25 PM,   wrote:
> > If s1 = "Welcome students", what is the output when you print the 
following:
> >
> > 1. s4 = 3 * s1
> >
> > 2. s1[3 : 6]
> >
> > 3. 'W' in s1
> >
> > 4. S1[-1]
> >
> > 5. S1[:-1]
> >
> > Any help would be great, thanks!
> 
> Why not find out for yourself and print these in the Python
> interpreter?  For instance:
> 
> > py
> Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64
> bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> py3: s1 = "Welcome students"
> py3: s4 = 3 * s1
> py3: print(s4)
> Welcome studentsWelcome studentsWelcome students
> 
> 
> 
> -- 
> boB

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
-- 
https://mail.python.org/mailman/listinfo/python-list



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


Ide vs ide

2017-10-27 Thread Andrew Z
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?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SciPy 1.0 released!

2017-10-27 Thread Paul Dubois
The DNA of this work goes much further back. After some discussion as
mentioned, Jim Hugunin wrote a numerical extension (called Numerical) and
after a bit I took over as its coordinator with financial support for my
work from Lawrence Livermore National Laboratory. They also supported the
Foundation. I do not remember the exact timing but certainly Numerical was
running before the 4th International was held at the Lab in the early 90s.
Guido put in the complex type and other things to help us. We had endless
discussion amongst us as how to spell it: 1i or 1j!

One should note that the Lab was breaking new ground in supporting an open
source project. SciPy was born to try to improve and extend a product that
was already crucial to a lot of people. Indeed, it is a big part of several
ongoing projects. Even non-numerical applications are important there.

I retired in 2005, and everyone who writes software knows that what they do
is ephemeral, but I don’t want history to be lost so soon.

Paul Dubois
... moving as we speak to La Mesa, CA



On Wed, Oct 25, 2017 at 5:05 AM Ralf Gommers  wrote:

> Hi all,
>
> We are extremely pleased to announce the release of SciPy 1.0, 16 years
> after
> version 0.1 saw the light of day.  It has been a long, productive journey
> to
> get here, and we anticipate many more exciting new features and releases in
> the
> future.
>
>
> Why 1.0 now?
> 
>
> A version number should reflect the maturity of a project - and SciPy was a
> mature and stable library that is heavily used in production settings for a
> long time already.  From that perspective, the 1.0 version number is long
> overdue.
>
> Some key project goals, both technical (e.g. Windows wheels and continuous
> integration) and organisational (a governance structure, code of conduct
> and a
> roadmap), have been achieved recently.
>
> Many of us are a bit perfectionist, and therefore are reluctant to call
> something "1.0" because it may imply that it's "finished" or "we are 100%
> happy
> with it".  This is normal for many open source projects, however that
> doesn't
> make it right.  We acknowledge to ourselves that it's not perfect, and
> there
> are some dusty corners left (that will probably always be the case).
> Despite
> that, SciPy is extremely useful to its users, on average has high quality
> code
> and documentation, and gives the stability and backwards compatibility
> guarantees that a 1.0 label imply.
>
>
> Some history and perspectives
> -
>
> - 2001: the first SciPy release
> - 2005: transition to NumPy
> - 2007: creation of scikits
> - 2008: scipy.spatial module and first Cython code added
> - 2010: moving to a 6-monthly release cycle
> - 2011: SciPy development moves to GitHub
> - 2011: Python 3 support
> - 2012: adding a sparse graph module and unified optimization interface
> - 2012: removal of scipy.maxentropy
> - 2013: continuous integration with TravisCI
> - 2015: adding Cython interface for BLAS/LAPACK and a benchmark suite
> - 2017: adding a unified C API with scipy.LowLevelCallable; removal of
> scipy.weave
> - 2017: SciPy 1.0 release
>
>
> **Pauli Virtanen** is SciPy's Benevolent Dictator For Life (BDFL).  He
> says:
>
> *Truthfully speaking, we could have released a SciPy 1.0 a long time ago,
> so I'm
> happy we do it now at long last. The project has a long history, and during
> the
> years it has matured also as a software project.  I believe it has well
> proved
> its merit to warrant a version number starting with unity.*
>
> *Since its conception 15+ years ago, SciPy has largely been written by and
> for
> scientists, to provide a box of basic tools that they need. Over time, the
> set
> of people active in its development has undergone some rotation, and we
> have
> evolved towards a somewhat more systematic approach to development.
> Regardless,
> this underlying drive has stayed the same, and I think it will also
> continue
> propelling the project forward in future. This is all good, since not long
> after 1.0 comes 1.1.*
>
> **Travis Oliphant** is one of SciPy's creators.  He says:
>
> *I'm honored to write a note of congratulations to the SciPy developers and
> the
> entire SciPy community for the release of SciPy 1.0.   This release
> represents
> a dream of many that has been patiently pursued by a stalwart group of
> pioneers
> for nearly 2 decades.   Efforts have been broad and consistent over that
> time
> from many hundreds of people.   From initial discussions to efforts coding
> and
> packaging to documentation efforts to extensive conference and community
> building, the SciPy effort has been a global phenomenon that it has been a
> privilege to participate in.*
>
> *The idea of SciPy was already in multiple people’s minds in 1997 when I
> first
> joined the Python community as a young graduate student who had just fallen
> in
> love with the expressibility and extensibility of Python.   The internet
> was
> just starting to bringing

Re: Python noob having a little trouble with strings

2017-10-27 Thread Lutz Horn
On Thu, Oct 26, 2017 at 07:59:10PM -0700, randyli...@gmail.com 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


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

2017-10-27 Thread 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


Keep or drop index.html from Django?

2017-10-27 Thread Christopher Reimer
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?

Thank you,

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