Re: Should setuptools version propagate to a module's __version__? If so, how?

2020-05-10 Thread John Ladasky
On Saturday, May 9, 2020 at 8:17:19 PM UTC-7, Cameron Simpson wrote:
> I also autopatch the module itself to 
> set __version__ to match when I make that release tag.

Yes, that's exactly what the module I wrote for my company's internal use does. 
 The official version number is hard-coded into setup.py.  My setup.py opens my 
module's __init__.py, and patches the line that starts with "__version__ = ".

I can see that this approach is one of several suggested approaches described 
in the Python packaging guide.  If I'm going to work with a package that 
eventually ends up on PyPI, I want to make sure that I don't do something 
unexpected or fragile.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Should setuptools version propagate to a module's __version__? If so, how?

2020-05-08 Thread John Ladasky
On Friday, May 8, 2020 at 6:07:33 PM UTC-7, John Ladasky wrote:
> Is there a recommended way to keep the internal reference and the setup.py 
> reference in sync?  Is there any reason someone would NOT want these numbers 
> to match?

Replying to myself... I just found this:

https://packaging.python.org/guides/single-sourcing-package-version/


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


Should setuptools version propagate to a module's __version__? If so, how?

2020-05-08 Thread John Ladasky
I just came across a package in PyPI which is in a state of neglect.  The 
official version on the PyPI page is 1.3.1 -- but the installed module reports 
its version as 1.2.0.  This is confusing.

There are several bugs in this package besides the mismatched version number.  
I've forked a copy of the package on GitHub, and I will attempt a cleanup.

In another private package of my own, I performed an unsavory hack in setup.py. 
 There is a "version" argument to the setup() call.  I define "version" as a 
global variable in setup.py.  Before I call setup with this version number, I 
also modify the line of package code which defines its __version__.  This works 
for me, but it feels wrong.

Is there a recommended way to keep the internal reference and the setup.py 
reference in sync?  Is there any reason someone would NOT want these numbers to 
match?

Thanks for your input.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing vs. concurrent.futures, Linux vs. Windows

2020-05-04 Thread John Ladasky
On Monday, May 4, 2020 at 4:09:53 PM UTC-7, Terry Reedy wrote:
> On 5/4/2020 3:26 PM, John Ladasky wrote:
> > Several years ago I built an application using multiprocessing.  It only 
> > needed to work in Linux.  I got it working fine.  At the time, 
> > concurrent.futures did not exist.
> > 
> > My current project is an application which includes a PyQt5 GUI, and a live 
> > video feed with some real-time image processing.  Running all this in one 
> > process resulted in unacceptable performance, so I'm trying to move all of 
> > the heavy video work into its own process.  I only need to define one child 
> > process.  I don't need a Pool.  The child Process can run indefinitely, and 
> > it will communicate multiple messages to the main process using a Pipe.
> > 
> > I built a working example in Linux, but it hangs in Windows.  I built a 
> > minimum example.  My problem has nothing to do with PyQt.  In Windows, my 
> > example hangs when I try to create the child Process.  Code:
> > 
> > 
> > import os
> > from multiprocessing import Pipe, Process
> > 
> > def child_app():
> >  inlet.send("Child process id = {}".format(os.getpid()))
> > 
> > if __name__ == "__main__":
> >  outlet, inlet = Pipe()
> >  print("Parent process id =", os.getpid())
> >  child_process = Process(target=child_app)  # Windows hangs here
> >  child_process.start()
> >  print(outlet.recv())
> >  child_process.join()
> >  child_process.close()
> >  print("Program complete.")
> > 
> > 
> > I'm working in Python 3.7.6 on Windows 10, and 3.7.5 on Ubuntu Linux 19.10.
> 
> Does the minimal example in the doc work for you?
> (IE, do you only have a problem with Pipe?)
> 
> from multiprocessing import Process
> 
> def f(name):
>  print('hello', name)
> 
> if __name__ == '__main__':
>  p = Process(target=f, args=('bob',))
>  p.start()
>  p.join()
> 
> How about the Pipe example?
> 
> from multiprocessing import Process, Pipe
> 
> def f(conn):
>  conn.send([42, None, 'hello'])
>  conn.close()
> 
> if __name__ == '__main__':
>  parent_conn, child_conn = Pipe()
>  p = Process(target=f, args=(child_conn,))
>  p.start()
>  print(parent_conn.recv())   # prints "[42, None, 'hello']"
>  p.join()
> 
> If this does not work on Windows, the example or doc should be changed.
> But I believe I tested it once. Note that unlike your code, the 
> child_conn is sent as argument.  The relation between the module code 
> and child processes is different on Windows than *nix.

Hi Terry,

Thanks for your reply.  I have been hacking at this for a few hours.  I have 
learned two things:

1. Windows hangs unless you explicitly pass any references you want to use in 
the subprocess through args.  That would include the Pipe connection. 
 Using multiprocessing in Linux requires the reference names to be global, 
however the use of args is not required.  Finally, Linux does not appear to 
cause any problems if args are specified.

2. Even if you fix problem 1, the parent process must be distinguished by 
creating the subprocess inside an "if __name__ == '__main__'" block.  Again, 
Linux just pushes on through, but Windows will hang if you don't do this.

The example code you posted shows exactly these two changes.  They are 
OS-specific, and my multiprocessing code has been (up to now) only required to 
run on Linux.  These recommendations can be found in the official Python docs, 
e.g.:

https://docs.python.org/3.7/library/multiprocessing.html#programming-guidelines
-- 
https://mail.python.org/mailman/listinfo/python-list


Multiprocessing vs. concurrent.futures, Linux vs. Windows

2020-05-04 Thread John Ladasky
Several years ago I built an application using multiprocessing.  It only needed 
to work in Linux.  I got it working fine.  At the time, concurrent.futures did 
not exist.

My current project is an application which includes a PyQt5 GUI, and a live 
video feed with some real-time image processing.  Running all this in one 
process resulted in unacceptable performance, so I'm trying to move all of the 
heavy video work into its own process.  I only need to define one child 
process.  I don't need a Pool.  The child Process can run indefinitely, and it 
will communicate multiple messages to the main process using a Pipe.

I built a working example in Linux, but it hangs in Windows.  I built a minimum 
example.  My problem has nothing to do with PyQt.  In Windows, my example hangs 
when I try to create the child Process.  Code:


import os
from multiprocessing import Pipe, Process

def child_app():
inlet.send("Child process id = {}".format(os.getpid()))

if __name__ == "__main__":
outlet, inlet = Pipe()
print("Parent process id =", os.getpid())
child_process = Process(target=child_app)  # Windows hangs here
child_process.start()
print(outlet.recv())
child_process.join()
child_process.close()
print("Program complete.")


I'm working in Python 3.7.6 on Windows 10, and 3.7.5 on Ubuntu Linux 19.10.

I am reading through the multiprocessing documentation, and I'm guessing that 
I've run into a problem with spawning vs. forking a new Process.  The former is 
the Windows default, and the latter is the Posix default.

Before I dig too deeply, I am wondering whether this cross-platform problem is 
something that concurrent.futures might handle automatically.  The concurrent 
API looks foreign to me.  But if it is meant to replace multiprocessing, I 
suppose this would be a good time for me to learn it.

Thanks for any advice and suggestions!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ModuleNotFoundError, even though I can see module in dist-packages folder, Setuptools / EGG issue?

2020-04-08 Thread John Ladasky
On Wednesday, April 8, 2020 at 10:47:42 AM UTC-7, John Ladasky wrote:
> Hi folks,
> 
> Something broke in my Python installation in the past two or three days.  I'm 
> working in Ubuntu 19.10 and Python 3.7, without virtual environments.  
> 
> I have two modules of Python source code that I am developing.  I regularly 
> change this code and "distribute" it to myself using setuptools.  From the 
> command prompt in the module's base folder, I execute:
> 
>   python3 setup.py sdist
>   sudo python3 setup.py install
> 
> That process has been working for me for years.  But after recent rebuilds, 
> when I try to import those modules today, I get ModuleNotFoundErrors for each 
> of them.  I tried importing other modules that were installed by pip3.  They 
> work fine.
> 
> I looked in /usr/local/lib/python3.7/dist-packages.  The one thing that is 
> unique to my two packages is the .egg extension at the end of the file names. 
>  Oddly, one of the two modules is a single .egg archive file, and the other 
> is a normal folder with folders inside it, despite the .egg extension in the 
> name.
> 
> A third package of mine which I did not build recently appears as a normal 
> sub-folder within dist-packages, and it imports correctly.
> 
> What is setuptools supposed to do?  Why has its behavior apparently changed?  
> Hope someone can offer some advice.  Thanks.

Followup observation:

One of the two Python packages I'm building using setuptools depends on 
argparse 1.4.  The default version of argparse in my Python 3.7 distro is 1.1. 
 I watched setuptools fetch argparse 1.4 from the Net when I built it.

When I start my Python interpreter and import argparse, I get version 1.1.

I found an argparse 1.4 sub-folder in my site-packages folder.  It was built 
yesterday.  It has a .egg extension, just like my two modules that won't import.
-- 
https://mail.python.org/mailman/listinfo/python-list


ModuleNotFoundError, even though I can see module in dist-packages folder, Setuptools / EGG issue?

2020-04-08 Thread John Ladasky
Hi folks,

Something broke in my Python installation in the past two or three days.  I'm 
working in Ubuntu 19.10 and Python 3.7, without virtual environments.  

I have two modules of Python source code that I am developing.  I regularly 
change this code and "distribute" it to myself using setuptools.  From the 
command prompt in the module's base folder, I execute:

  python3 setup.py sdist
  sudo python3 setup.py install

That process has been working for me for years.  But after recent rebuilds, 
when I try to import those modules today, I get ModuleNotFoundErrors for each 
of them.  I tried importing other modules that were installed by pip3.  They 
work fine.

I looked in /usr/local/lib/python3.7/dist-packages.  The one thing that is 
unique to my two packages is the .egg extension at the end of the file names.  
Oddly, one of the two modules is a single .egg archive file, and the other is a 
normal folder with folders inside it, despite the .egg extension in the name.

A third package of mine which I did not build recently appears as a normal 
sub-folder within dist-packages, and it imports correctly.

What is setuptools supposed to do?  Why has its behavior apparently changed?  
Hope someone can offer some advice.  Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to specific multiple dtypes in numpy.ndarray?

2019-12-21 Thread John Ladasky
On Thursday, December 19, 2019 at 2:53:18 AM UTC-8, lampahome wrote:
> I meet performance is low when I use struct.unpack to unpack binary data.
> 
> So I tried to use numpy.ndarray
> But meet error when I want to unpack multiple dtypes
> 
> Can anyone teach me~
> 
> Code like below:
> # python3
> import struct
> import numpy as np
> s1 = struct.Struct("@QIQ")
> ss1 = s1.pack(1,11,111)
> np.ndarray((3,), [('Q','I','Q')], ss1)
> # ValueError: mismatch in size of old and new data-descriptor.

Is there some reason that you're calling the np.ndarray constructor directly 
instead of the np.array convenience function?  The arguments that you pass to 
each are slightly different.  Generally, you want to use np.array.

The first argument to np.ndarray is the shape.  You appear to want three 
elements.

The second argument to np.ndarray is the data type (dtype).  It needs to be a 
SINGLE data type, like 'float' or 'int' or 'object'.  All elements in in array 
are of the same dtype.  If you want different behavior, I think that you want 
lists, not arrays.  You can set the dtype to 'object' and you should be able to 
store any data type as an array element.  But I don't think that offers you any 
advantages over using ordinary Python lists.

In any case, it appears that you aren't passing a dtype as your second 
argument.  You're trying to pass the data itself, as a tuple wrapped in a 
single list.  This seems to be certain to raise an error.

The third argument to np.ndarray is supposed to be the buffer which contains 
your data.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html#numpy.array

ile:///usr/share/doc/python-numpy-doc/html/reference/generated/numpy.array.html#numpy.array
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Don't install on the system Python"

2019-12-01 Thread John Ladasky
On Sunday, December 1, 2019 at 12:47:43 AM UTC-8, Cameron Simpson wrote:
> On 01Dec2019 09:29, Manfred Lotz <...@posteo.de> wrote:
> >On Sat, 30 Nov 2019 20:42:21 -0800 (PST)
> >John Ladasky <...@sbcglobal.net> wrote:
> >> For years, I've read warnings about not installing one's personal
> >> stack of Python modules on top of the system Python.  It is possible
> >> to corrupt the OS, or so I've gathered.
> >
> >This is nonsense as you presumably have no permission to change
> >anything Python related in /usr.
> >
> >The only possiblity I can imagine is that you somehow screw up your
> >personal Python related setting in your home directory tree. But I have
> >never (in the short period of time I've been using Python) encountered
> >anything like this.
> 
> What is to be avoided: Some people run pip as root and install in the 
> vendor/supplier controlled space.  This can lead to various problems, as 
> it can conflict with or simply vary the system installed packages.
> 
> Provided the OP is using pip in its (modern default) "install in my home 
> directory" mode, they should be fine.
> 
> Cheers,
> Cameron Simpson <...@cskk.id.au>

The only thing I must install with pip is tensorflow-gpu.  For everything else, 
I make use of the Ubuntu repositories.  The Synaptic package manager installs 
packages (including Python modules) for all user accounts at the same time, 
which I like.

When I installed tensorflow-gpu using pip, I was in fact frustrated because I 
couldn't figure out how to deploy it across multiple user accounts at one time. 
 I ended up installing it three times, once in each account.  You're suggesting 
that's actually preferred, at least when pip is performing the installation.  
OK, I will endure the repetition.
-- 
https://mail.python.org/mailman/listinfo/python-list


"Don't install on the system Python"

2019-11-30 Thread John Ladasky
Long-time Ubuntu user here.

For years, I've read warnings about not installing one's personal stack of 
Python modules on top of the system Python.  It is possible to corrupt the OS, 
or so I've gathered.

Well, I've never heeded this advice, and so far nothing bad has happened to me. 
 I don't like Anaconda, or virtual environments in general.  I don't like 
heavyweight IDE's.  I like to be able to type "python3" at the command prompt 
and be sure what I'll be getting.  I have multiple user accounts on a system 
that I manage, and I want every user account to have access to the same modules.

Maybe the modules that I require are safe to install on the system Python, I'm 
not sure.  My must-haves are mostly scientific computing and data management 
modules: Numpy, Scipy, Scikit-learn, Matplotlib, Pandas, Biopython, and 
Tensorflow.  I also use PyQt5 from time to time.

Can anyone provide concrete examples of problems arising from installing 
modules on top of the system Python?  Am I courting disaster?

Thanks for your advice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meanwhile Norwegian trolls created ...

2019-08-19 Thread John Ladasky
On Saturday, August 17, 2019 at 2:40:14 AM UTC-7, Abdur-Rahmaan Janhangeer 
wrote:
> But it is not so easy to combine different memory management paradigms.

Oh, I feel this.  I love the look and feel of PyQt5, but object management has 
bitten me more than once.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Amber Brown: Batteries Included, But They're Leaking

2019-05-19 Thread John Ladasky
On Saturday, May 18, 2019 at 2:21:59 PM UTC-7, Paul Rubin wrote:
> http://pyfound.blogspot.com/2019/05/amber-brown-batteries-included-but.html
> 
> This was a controversial talk at the Python language summit, giving
> various criticisms of Python's standard library,

I will try to find some time to read through Amber Brown's remarks.  For now, I 
just want to remind everyone that we had this exact discussion here, about two 
years ago.  First post in the thread, if you want to see the source:

https://groups.google.com/forum/#!original/comp.lang.python/B2ODmhMS-x4/KMpF4yuHBAAJ


Here are a few excerpts from the thread:


On Saturday, September 16, 2017 at 11:01:03 PM UTC-7, Terry Reedy wrote: 
> The particular crippler for CLBG [Computer Language Benchmark Game]
> problems is the non-use of numpy in numerical calculations, such as the
> n-body problem.  Numerical python extensions are over two decades old 
> and give Python code access to optimized, compiled BLAS, LinPack, 
> FFTPack, and so on.  The current one, numpy, is the third of the series.
> It is both a historical accident and a continuing administrative
> convenience that numpy is not part of the Python stdlib. 


On Monday, September 18, 2017 at 10:21:55 PM UTC+1, John Ladasky wrote: 
> OK, I found this statement intriguing.  Honestly, I can't function without
> Numpy, but I have always assumed that many Python programmers do so. 
> Meanwhile: most of the time, I have no use for urllib, but that module is
> in the standard library. 
> 
> I noticed the adoption of the @ operation for matrix multiplication.  I 
> have yet to use it myself. 
> 
> So is there a fraction of the Python community that thinks that Numpy 
> should in fact become part of the Python stdlib?  What is the 
> "administrative convenience" to which you refer? 


On 2017-09-18 23:08, bream...@gmail.com wrote: 
> My very opinionated personnal opinion is that many third party libraries 
> are much better off outside of the stdlib, numpy particulary so as it's
> one of the most used, if not the most used, such libraries. 
> 
> My rationale is simple, the authors of the libraries are not tied into 
> the (c)Python release cycle, the PEP process or anything else, they can
> just get on with it. 
> 
> Consider my approach many blue moons ago when I was asking when the "new"
> regex module was going to be incorporated into Python, and getting a bit
> miffed in my normal XXXL size hat autistic way when it didn't happen.  I
> am now convinved that back then I was very firmly wrong, and that staying
> out of the stdlib has been the best thing that could have happened to
> regex.


On Tuesday, September 19, 2017 at 12:11:58 AM UTC-7, Steven D'Aprano wrote:
> On Tue, 19 Sep 2017 01:13:23 +0100, MRAB wrote:
> 
> > I even have it on a Raspberry Pi. "pip install regex" is all it took. No
> > need for it to be in the stdlib. :-)
> 
> That's fine for those of us who can run pip and install software from the 
> web without being immediately fired, and for those who have installation 
> rights on the computers they use. And those with easy, cheap and fast 
> access to the internet.
> 
> Not everyone is so lucky.


I'm not offering an opinion, just some historical context FYI.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's needed for jpegtran in Python 3?

2018-09-27 Thread John Ladasky
On Thursday, September 27, 2018 at 10:48:16 AM UTC-7, Chris Green wrote:
> I think that must be what I have already installed, it doesn't make
> the module available in Python 3, it just says this when I try and
> install it:-
> 
> root@t470:~# pip install jpegtran-cffi
> Requirement already satisfied: jpegtran-cffi in 
> /usr/local/lib/python2.7/dist-packages
> Requirement already satisfied: cffi>=0.8 in 
> /usr/lib/python2.7/dist-packages (from jpegtran-cffi)
> root@t470:~# 
> 
> Python 3 isn't going to find that is it?  When I run my program it
> says:-
> 
> chris$ picimport.py
> Traceback (most recent call last):
>   File "/home/chris/bin/picimport.py", line 28, in 
> from jpegtran import JPEGImage
> ModuleNotFoundError: No module named 'jpegtran'
> chris$ 

It appears that you are working in Linux.  Many of the command-line Linux 
utilities are written in Python 2.7.  In a few years that may change, for now 
Py 2.7 is the system Python.

On a Linux system, when you type "python" you will start the system's Py 2.7 
interpreter.  When you type "pip" you will start the installer for Py 2.7.  So 
you installed jpegtran, but you installed it for Py 2.7.

Linux (Ubuntu, at least, I'm not sure about other distros) also ships with a 
version of Python 3, but it's not the default.  If you want to invoke Py 3.x 
from a Linux command prompt, you need to type "python3".  If you want to 
install packages for your Python 3 platform, you need to install python3-pip, a 
system package which is not included in (Ubuntu) Linux by default.  You can 
access that package from the command line by typing "pip3" where you would have 
typed "pip".

It's good that you want to use Py 3, in a few years the changeover will be 
complete.  The one thing you did not show was your text for picimport.py, which 
I expect is trying to use Py 3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: clever exit of nested loops

2018-09-27 Thread John Ladasky
On Wednesday, September 26, 2018 at 12:50:20 AM UTC-7, vito.d...@gmail.com 
wrote:

> I have "abused" the "else" clause of the loops to makes a break "broke" more 
> loops

I did this once upon a time.  In recent years, when I start writing tricky 
nested loops, I frequently find myself reaching for itertools.product() to 
flatten the loops instead.

This code accomplishes the same task as yours.  I'll leave it to you to decide 
whether you prefer it.  There are things that I dislike about it, but the flow 
control part is clear.


from itertools import product

msgs = ("i: {}", "\tj: {}", "\t\tk: {}")
old = 3*[None]
for new in product(range(10), repeat=3):
for n, (msg, changed) in enumerate(zip(msgs, [x!=y for x, y in zip(old, 
new)])):
if changed:
print(msg.format(new[n]))
if condition(*new):# your condition() took three separate arguments
break
old = new

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


Re: How to sort over dictionaries

2018-08-28 Thread John Ladasky
The top-level object you are showing is a list [], not a dictionary {}.  It has 
dictionaries inside of it though.  Do you want to sort the list?

Python's sorted() function returns a sorted copy of a sequence.  Sorted() has 
an optional argument called "key".  Key accepts a second function which can be 
used to rank each element in the event that you don't want to compare them 
directly.  

The datetime module has functions which can convert the time strings you are 
showing into objects which are ordered by time and are suitable as keys for 
sorting.  Look at datetime.datetime.strptime().  It takes two arguments, the 
date/time string, and a second string describing the format of the first 
string.  There are many ways to format date and time information as strings and 
none are standard.  This function call seems to work for your data:

>>> datetime.strptime("04-08-2018 19:12", "%d-%m-%Y %H:%M")
datetime.datetime(2018, 8, 4, 19, 12)

Hope that gets you started.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can pip install packages for all users (on a Linux system)?

2018-07-25 Thread John Ladasky
On Wednesday, July 25, 2018 at 7:15:35 AM UTC-7, Stephan Houben wrote:
> Op 2018-07-24, John Ladasky schreef :
> > I believe that I now have tensorflow 1.8 installed twice on my system,
> > once for each user.  If anyone can share how to convince pip to behave
> > like Synaptic, I would appreciate it.  Thanks.
> 
> I would recommend against using pip to install packages into the system
> Python. The reason is that you may get into a conflict with the package
> manager. You can try to be careful and not install tensorflow using
> Synaptic, but once you install some other package which happens to
> depend on tensorflow, you will start getting package manager conflicts.

That won't be a problem.  Tensorflow is not available in the Canonical 
repository, so it cannot be installed through Synaptic unless someone has made 
a PPA somewhere.  I don't know why Tensorflow is not part of Canonical, since 
it is free, open-source, and popular.

I don't (yet) have any that depends on tensorflow.  Tensorflow's Python API 
depends on other software, the NVidia drivers and CUDA for example.  But that's 
the opposite issue.  And I did install those manually.

> An alternative is to install Python yourself (from source, without the package
> manager) in, say, /opt/python. You are then in splendid isolation from
> the package manager and can install any version of Python and tensorflow
> you desire.

That's an interesting strategy, and I will consider it.  Two copies of Python 
are easier to accept than two copies of tensorflow.

> Stephan

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


Can pip install packages for all users (on a Linux system)?

2018-07-24 Thread John Ladasky
I've been using "sudo pip3 install" to add packages from the PyPI repository.  
I have multiple user accounts on the computer in question.  My goal is to 
install packages that are accessible to all user accounts.  I know that using 
the Synaptic Package Manager in Ubuntu will install for all users, but not 
every Python package is included in the Canonical repository.

I hadn't noticed any discrepancies until recently.  I upgraded from Ubuntu 
17.10 to 18.04.  In parallel, I upgraded tensorflow-gpu 1.4.0 to 1.8.0.  
Everything worked on my main account.  However, attempting to import tensorflow 
from Python on a secondary account failed.  Eventually I checked the pip lists 
in each account, and I found a reference to the old tensorflow 1.4 on the 
secondary account.  Uninstalling that, and reinstalling tensorflow-gpu 1.8 on 
the secondary account fixed the problem.

I believe that I now have tensorflow 1.8 installed twice on my system, once for 
each user.  If anyone can share how to convince pip to behave like Synaptic, I 
would appreciate it.  Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib 3D limitations, please recommend alternative

2018-07-07 Thread John Ladasky
On Saturday, July 7, 2018 at 6:36:16 AM UTC-7, Rick Johnson wrote:
> John Ladasky wrote:
> 
> > Back then I wrote:
> > 
> > "I have concluded that Qt, PyQt, and OpenGL are all
> > rapidly-evolving, and huge, software packages.  There may
> > be compatibility problems, and relevant examples with the
> > right software combination may be hard to find.  Two weeks
> > of searching web pages hasn't turned up a single example
> > which demonstrates PyQt5 doing something simple in 3D with
> > OpenGL that I can study."
> 
> PyQT is not the only GUI toolkit with OpenGL support, you
> know. I would suggest you have a look at the alternatives.

I'm fully aware of that.  I have tried a few Python GUIs, and I have the most 
experience with PyQt5.  It is not necessary for me to integrate my current 3D 
graphics project with PyQt5, but it would be nice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib 3D limitations, please recommend alternative

2018-07-06 Thread John Ladasky
On Wednesday, July 4, 2018 at 6:38:18 PM UTC-7, William Ray Wing wrote:
> > On Jul 4, 2018, at 5:53 PM, John Ladasky  wrote:
[snip]
> > I explored Python OpenGL bindings about three years ago, and quickly got 
> > bogged down.  Even with Python to assist, dealing with OpenGL was like 
> > trying to program Java.  Of course, OpenGL can do EVERYTHING.  Far more 
> > than I need.
> > 
> 
> The Python Open GL bindings have apparently changed fairly dramatically.  I’m 
> no expert, I’m working my way through the on-line book here:
> 
>   http://www.labri.fr/perso/nrougier/python-opengl/
> 
> But the author DOES lay things out in a nice step by step fashion - and with 
> particular emphasis on scientific 3D plotting (which is what I’m after).

I've started to read your link.  Maybe I will attempt OpenGL a second time.  

I found my posts documenting my request for help the last time that I attempted 
OpenGL here:

https://groups.google.com/forum/#!msg/comp.lang.python/Hj-UHbAFpWs/7vz-vcSHCAAJ;context-place=forum/comp.lang.python

Back then I wrote:

"I have concluded that Qt, PyQt, and OpenGL are all rapidly-evolving, and huge, 
software packages.  There may be compatibility problems, and relevant examples 
with the right software combination may be hard to find.  Two weeks of 
searching web pages hasn't turned up a single example which demonstrates PyQt5 
doing something simple in 3D with OpenGL that I can study."

It's nice to see that Nicolas Rougier confirms exactly that very near the 
beginning of his book (Section 2.1, "A bit of history").

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


Re: Matplotlib 3D limitations, please recommend alternative

2018-07-06 Thread John Ladasky
On Wednesday, July 4, 2018 at 3:30:32 PM UTC-7, Rick Johnson wrote:
> On Wednesday, July 4, 2018 at 4:53:19 PM UTC-5, John Ladasky wrote:
> > There are many 3D graphics packages on PyPI.  Some appear to be quite 
> > specialized.  I would appreciate your recommendations.  Thanks!
> 
> If you don't want to mess with pyOpenGL, then try VPython.

Thanks for the suggestion Rick, I have found some VPython examples here:

http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/
-- 
https://mail.python.org/mailman/listinfo/python-list


Matplotlib 3D limitations, please recommend alternative

2018-07-04 Thread John Ladasky
I'm a regular Matplotlib user.  Normally, I graph functions.  I just attempted 
to graph an icosahedral surface using the plot_trisurf() methods of 
Matplotlib's Axes3D. I have discovered that Matplotlib is basically hard-wired 
for graphing functions, and therefore will not work for general-purpose 3D 
rendering.

If I have repeated X and Y values in my arrays, it doesn't matter that the Z 
values might be different.  Matplotlib raises a ValueError, with the message "x 
and y arrays must consist of at least 3 unique points."  If I break down my 
polyhedron into individual triangles, I can get 16 of the 20 faces to render, 
but not all of them.  Here's some minimal example code, which also catches and 
prints the cause of the ValueError.

# 

from itertools import cycle
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

COLOR = cycle("cmyrbg")

ϕ = (1 + np.sqrt(5)) / 2

R = np.sqrt(1 + ϕ**2)

VERTICES = np.array(((-1,0,ϕ), (1,0,ϕ), (-1,0,-ϕ), (1,0,-ϕ),
 (0,ϕ,1), (0,ϕ,-1), (0,-ϕ,1), (0,-ϕ,-1),
 (ϕ,1,0), (-ϕ,1,0), (ϕ,-1,0), (-ϕ,-1,0))) / R

FACES = np.array(((0,4,1), (4,5,8), (4,8,1), (5,3,8),
  (0,9,4), (9,5,4), (9,2,5), (5,2,3),
  (9,0,11), (9,11,2), (7,2,11), (2,7,3),
  (11,0,6), (7,11,6), (7,6,10), (7,10,3),
  (0,1,6), (8,10,1), (6,1,10), (8,3,10)))

fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='3d')
for t in FACES:
print("\n\n", t, end=" ")
try:
ax.plot_trisurf(*zip(*VERTICES[t]), color=next(COLOR), alpha=0.5)
except ValueError as e:
print(e)
print(VERTICES[t], end="")
plt.show()


# 

I explored Python OpenGL bindings about three years ago, and quickly got bogged 
down.  Even with Python to assist, dealing with OpenGL was like trying to 
program Java.  Of course, OpenGL can do EVERYTHING.  Far more than I need.

I would like to render polyhedra, preferably with uniformly colored faces (I 
understand that color is a property that is associated with vertices in 
OpenGL).  I would appreciate a simple interface.  The rendering doesn't have to 
be especially fast or high quality.  The Matplotlib visualization is 
acceptable, except of course for the missing faces.

There are many 3D graphics packages on PyPI.  Some appear to be quite 
specialized.  I would appreciate your recommendations.  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Posting warning message

2018-06-10 Thread John Ladasky
On Sunday, June 10, 2018 at 7:47:01 AM UTC-7, T Berger wrote:
> When I go to post a reply, I get a warning asking if I want my email address 
> (or other email addresses listed) visible to all, and do I want to edit my 
> post. What should I do?

Are you posting through Google Groups?  Sometimes I see that warning as well.

Some, but not all, Usenet software deliberately mangles email addresses when 
composing posts.  It's a good thing to mangle email addresses when posting 
publicly, as it makes it harder for spammers to find new targets.  So answer 
"yes", and manually edit any email addresses you see in the post so that they 
can't be recovered.  For example, if my email address was posted undisguised, 
you could edit it to "j...@g...com" and that should do the trick.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Plot not working

2018-05-04 Thread John Ladasky
On Friday, May 4, 2018 at 9:13:02 PM UTC-7, Sharan Basappa wrote:
> I am new to Python and using it to learn machine learning.
> 
> Below is a sample program I am running to plot IRIS data set.
> The code runs but no plot comes up. I am not sure what the issue is with the 
> code.
> 
> # Imports
> from matplotlib import pyplot as plt
> from sklearn.datasets import load_iris
> import numpy as np
> 
> # load the data with load_iris from sklearn
> data = load_iris()
> features = data['data']
> feature_names = data['feature_names']
> target = data['target']
> 
> #print("features\n",features)
> #print("feature names\n",feature_names)
> #print("target\n",target);
> #print("data\n",data)
> 
> for t,marker,c in zip(range(3),">ox","rgb"):
> # plot each class on its own to get different colored markers
> plt.scatter(features[target == t,0],
> features[target == t,1],
> marker=marker,
> c=c)

Try adding a call to plt.show() at the end.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Thank you Python community!

2018-03-20 Thread John Ladasky
On Monday, March 19, 2018 at 9:28:09 AM UTC-7, Etienne Robillard wrote:

> I would like to thank you guys sincerely for helping a lot of people to 
> stay clean, and focus on programming high-level stuff in Python instead 
> of doing some really nasty drugs.

Yeah, it's either Python or that horrifying street drug PHP.  I know which one 
I'm choosing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: This newsgroup (comp.lang.python) may soon be blocked by Google Gro

2018-02-09 Thread John Ladasky
On Friday, February 9, 2018 at 12:50:16 AM UTC-8, Tim Golden wrote:

[snip and rearrange]

> So dropping GG altogether would probably not add very much, as we're 
> generally blocking undesirable posts from there and we'd rather not 
> block genuine posts which happen to be made through the relative 
> convenience of the GG interface.

I thank you for this point of view.  I am using Google Groups.  I migrated here 
back in the days of Deja News.  I don't like having mailing lists streaming 
into my inbox, having to hunt around to unsubscribe.  I want a newsreader with 
integrated posting capability which is separate from my inbox.


> Gmane offers a newsgroup interface to the mailing list

I haven't visited GMane in a few years, but I found it difficult to navigate.  
In particular, I found searching to be cumbersome.  Weren't the archives broken 
into 30-day blocks?

I just tried GMane again two minutes ago.  I can't confirm my recollections, 
but right now what I'm seeing is worse.  If you follow this link right now... 
(http://gmane.org/find.php?list=comp.lang.python)... you get this:

"Not all of Gmane is back yet - We're working hard to restore everything"

And if you follow the link labeled "The latest news is at Gmane News" at the 
bottom of that page, it takes you here... (http://home.gmane.org/)... and the 
top blog post discussing site repairs is dated September 2016!

I'm not too excited about trying GMane again after seeing that.

One final thought: although Google is not the Python community, there are a lot 
of shared interests and overlap.  Google sponsored and employed Guido for 
years.  The most popular Tensorflow API is the Python API.  

Can't this relationship be used to ask Google to get more serious about the 
spam problem that originates in their domain, but that people in this 
discussion think they will hold against comp.lang.python?  Alternately, how 
about giving Google Groups users killfiles and/or the same Spambayes filter 
tools that are already used on GMail inboxes?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where has the practice of sending screen shots as source code come from?

2018-01-29 Thread John Ladasky
On Sunday, January 28, 2018 at 7:07:11 AM UTC-8, Steven D'Aprano wrote:
>
> (The day a programmer posts a WAV file of themselves reading their code 
> out aloud, is the day I turn my modem off and leave the internet forever.)

What's a... modem?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread John Ladasky
On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote:

> Python never makes a copy unless you ask it to.
> 
> What x1=X does is make the name x1 refer to the same object that X 
> refers to. No copying.

Well, except with very simple, mutable data types like scalars... compare this:

>>> x=5
>>> y=x
>>> x,y
(5, 5)
>>> x+=1
>>> x,y
(6, 5)

To this:

>>> a=[1,2,3]
>>> b=a
>>> a,b
([1, 2, 3], [1, 2, 3])
>>> a[1]=9
>>> a,b
([1, 9, 3], [1, 9, 3])

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


Re: converting numbers into words (Posting On Python-List Prohibited)

2017-11-09 Thread John Ladasky
On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D’Oliveiro wrote:
> On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16...@rguktrkv.ac.in 
> wrote:
> 
> > How can I covert numbers into word like ex:-123 One hundred twenty three?
> 
> Here’s  one I 
> did earlier, in Algol 68.
> 
> Conversion to Python is left as an exercise for the reader.

I think that gives away rather more than I wanted the student to see.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to build a simple neural network in 9 lines of Python code

2017-06-29 Thread John Ladasky
On Tuesday, June 27, 2017 at 7:28:58 PM UTC-7, Steve D'Aprano wrote:
> On Wed, 28 Jun 2017 06:22 am, Marko Rauhamaa wrote:
> 
> > You saw the APL example, right? APL's standard runtime/library contains
> > most of Numpy functionality because that's what APL has been designed
> > for.
> > 
> > Is that cheating?
> 
> 
> Of course not. That demonstrates beautifully (or perhaps "unreadably tersely")
> that the APL language primitives are extremely powerful (too powerful?).

Interesting how this discussion has detoured into APL.  I think that these 
comments underscore my point that Numpy's way of doing things isn't quite 
Python's way of doing things, that it's a little esoteric.

I don't know APL, but...  some years ago, I remember reading that the concept 
of a scalar did not exist in APL.  The equivalent of a scalar in APL is (if I 
understand correctly) a one-dimensional array with one element in it.  

When I first read that, I thought it was a needless complication.

After ten years of Numpy and three months of TensorFlow, it's starting to dawn 
on me why that might actually make programming sense... if you're thinking in 
matrix algebra all the time, which increasingly, I find myself doing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to build a simple neural network in 9 lines of Python code

2017-06-29 Thread John Ladasky
On Tuesday, June 27, 2017 at 12:34:46 PM UTC-7, Marko Rauhamaa wrote:
> John Ladasky <j@s...l.net>:
> > OK, that's cheating a bit, using Numpy. It's a nice little program,
> > but it leverages a huge, powerful library.
> 
> What would *not* be cheating? A language without a library would be
> dead.

Python's standard library is huge, and useful.  Numpy is not part of Python's 
STANDARD library.

I love Numpy, and use it in almost everything I write.  But I see that many 
people won't need it, would find it overwhelming, and would find its way of 
doing things rather different than standard Python (vectorized mathematical 
operations, fancy slicing, broadcasting, etc.).

So to use Numpy in a post that says, "implement a neural network in Python with 
just nine lines of code!" seems a little misleading to me.  Python is IMHO the 
best programming language in use today -- and it's the best one for a beginner 
to start learning.  But I wouldn't want to oversell the language to a novice 
programmer.  It's going to take you a long time to understand exactly what 
those nine lines of code are doing, if you're new to this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread John Ladasky
On Tuesday, June 27, 2017 at 9:24:07 AM UTC-7, Sam Chats wrote:
> https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1

OK, that's cheating a bit, using Numpy.  It's a nice little program, but it 
leverages a huge, powerful library.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: os.walk the apostrophe and unicode

2017-06-24 Thread John Ladasky
On Saturday, June 24, 2017 at 12:07:05 PM UTC-7, Rod Person wrote:
> Hi,
> 
> I'm working on a program that will walk a file system and clean the id3
> tags of mp3 and flac files, everything is working great until the
> follow file is found
> 
> '06 - Todd's Song (Post-Spiderland Song in Progress).flac'
> 
> for some reason that I can't understand os.walk() returns this file
> name as
> 
> '06 - Todd\xe2\x80\x99s Song (Post-Spiderland Song in Progress).flac'
> 
> which then causes more hell than a little bit for me. I'm not
> understand why apostrophe(') becomes \xe2\x80\x99, or what I can do
> about it.

That's a "right single quotation mark" character in Unicode.

http://unicode.scarfboy.com/?s=E28099

Something in your code is choosing to interpret the text variable as an 
old-fashioned byte array of characters, where every character is represented by 
a single byte.  That works as long as the file name only uses characters from 
the old ASCII set, but there are only 128 of those.

> The script is Python 3, the file system it is running on is a hammer
> filesystem on DragonFlyBSD. The audio files reside on a QNAP NAS which
> runs some kind of Linux so it probably ext3/4. The files came from
> various system (Mac, Windows, FreeBSD).

Since you are working in Python3, you have the ability to call the .encode() 
and .decode() methods to translate between Unicode and byte character arrays 
(which you still need on occasion).


> 
> -- 
> Rod
> 
> http://www.rodperson.com

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


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread John Ladasky
On Thursday, May 18, 2017 at 3:55:01 AM UTC-7, qasi...@gmail.com wrote:
> @jladasky and @Gregory:
> 

> 3) Divide the ligand molecule into two parts (except for ligand heavy atom 
> closest to the COM of the whole ligand) based on the COM previously 
> calculated.

OK, now I agree with Gregory Ewing.  This part of your problem is incompletely 
defined.  Divide the molecule into two parts... how?  You need to choose a 
plane in 3-dimensional space which cuts your molecule in two.  Describe the 
criteria that this cut needs to satisfy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-16 Thread John Ladasky
On Monday, May 15, 2017 at 7:23:52 PM UTC-7, jeanbi...@gmail.com wrote:
> What may make this tricky is that the vinyl group can rotate at the point 
> where it attaches to the benzene ring so the full molecule may not lie in a 
> plane.

But the OP has coordinates for each atom which are used in the center of mass 
calculation for the whole molecule.  Why would the atoms be stationary for that 
calculation, and yet free to move in the calculation performed on a subset of 
the atoms?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-16 Thread John Ladasky
On Monday, May 15, 2017 at 10:23:12 PM UTC-7, qasi...@gmail.com wrote:
> @Cameron:
> Thanks, I will try what you suggest. I am not sure that I'll tackle it 
> because I am new to python.

I teach programming to people with varying levels of expertise, from 
middle-school students to working professionals.  Do you program in any other 
languages?  What do you know how to do?  Can you write loops?

Why do you have a function named heavy_atoms() which takes all of your data and 
parses it internally, when you know that you sometimes want to work with 
subsets of that data?

Also, can you show us the rest of the program?  Right now you define a function 
that is never called, and it never returns anything either.

One final point: I think you have complicated your task by jumping straight 
into using Numpy arrays.  You may need to understand Numpy's vectorized 
function calls (the last line of your code).  If you want to select subsets of 
data from Numpy arrays, you could use Numpy's fancy indexing, but you have to 
understand that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Theory] How to speed up python code execution / pypy vs GPU

2016-11-08 Thread John Ladasky
On Monday, November 7, 2016 at 5:23:25 PM UTC-8, Steve D'Aprano wrote:
> On Tue, 8 Nov 2016 05:47 am, j...@i...edu wrote:
> > It has been very important for the field of computational molecular
> > dynamics (and probably several other fields) to get floating-point
> > arithmetic working right on GPU architecture.  I don't know anything about
> > other manufacturers of GPU's, but NVidia announced IEEE-754,
> > double-precision arithmetic for their GPU's in 2008, and it's been
> > included in the standard since CUDA 2.0.
> 
> That's excellent news, and well-done to NVidia.
> 
> But as far as I know, they're not the only manufacturer of GPUs, and they
> are the only ones who support IEEE 754. So this is *exactly* the situation
> I feared: incompatible GPUs with varying support for IEEE 754 making it
> difficult or impossible to write correct numeric code across GPU platforms.
> 
> Perhaps it doesn't matter? Maybe people simply don't bother to use anything
> but Nvidia GPUs for numeric computation, and treat the other GPUs as toys
> only suitable for games.

Maybe so.  I only know for certain that recent NVidia devices comply with 
IEEE-754.  Others might work too.

> > If floating-point math wasn't working on GPU's, I suspect that a lot of
> > people in the scientific community would be complaining.
> 
> I don't.
> 
> These are scientists, not computational mathematics computer scientists. In
> the 1980s, the authors of the "Numeric Recipes in ..." books, William H
> Press et al, wrote a comment about the large number of scientific papers
> and simulations which should be invalidated due to poor numeric properties
> of the default pseudo-random number generators available at the time.
> 
> I see no reason to think that the numeric programming sophistication of the
> average working scientist or Ph.D. student has improved since then.

I work a lot with a package called GROMACS, which does highly iterative 
calculations to simulate the motions of atoms in complex molecules.  GROMACS 
can be built to run on a pure-CPU platform (taking advantage of multiple cores, 
if you want), a pure-GPU platform (leaving your CPU cores free), or a blended 
platform, where certain parts of the algorithm run on CPUs and other parts on 
GPUs.  This latter configuration is the most powerful, because only some parts 
of the simulation algorithm are optimal for GPUs.  GROMACS only supports NVidia 
hardware with CUDA 2.0+.

Because of the iterative nature of these calculations, small discrepancies in 
the arithmetic algorithms can rapidly lead to a completely different-looking 
result.  In order to verify the integrity of GROMACS, the developers run 
simulations with all three supported hardware configurations, and verify that 
the results are identical.  Now, I don't know that every last function and 
corner case in the IEEE-754 suite gets exercised by GROMACS, but that's a 
strong vote of confidence.

> The average scientist cannot even be trusted to write an Excel spreadsheet
> without errors that invalidate their conclusion:
> 
> https://www.washingtonpost.com/news/wonk/wp/2016/08/26/an-alarming-number-of-scientific-papers-contain-excel-errors/
>
>
> let alone complex floating point numeric code. Sometimes those errors can
> change history: the best, some might say *only*, evidence for the austerity
> policies which have been destroying the economies in Europe for almost a
> decade now is simply a programming error.
> 
> http://www.bloomberg.com/news/articles/2013-04-18/faq-reinhart-rogoff-and-the-excel-error-that-changed-history

I know this story.  It's embarrassing.

> These are not new problems: dubious numeric computations have plagued
> scientists and engineers for decades, there is still a huge publication
> bias against negative results, most papers are written but not read, and
> even those which are read, most are wrong.
> 
> http://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.0020124
> 
> Especially in fast moving fields of science where there is money to be made,
> like medicine and genetics. There the problems are much, much worse.
> 
> Bottom line: I'm very glad that Nvidia now support IEEE 754 maths, and that
> reduces my concerns: at least users of one common GPU can be expected to
> have correctly rounded results of basic arithmetic operations.
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

You're right Steve, the election results are rolling in.


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


Re: comapring 2 sequences of DNA ouput the silent and non mutations

2016-10-29 Thread John Ladasky
Disha,

Before you struggle to reinvent the wheel, you might want to check out the 
Biopython package.

http://biopython.org/wiki/Biopython

I haven't used it for a few years, but the version that I did use was very 
comprehensive.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5, OpenGL, where to start, minimal example code?

2016-10-08 Thread John Ladasky
Well, I've made some progress.  My program doesn't draw any 3D objects yet, but 
it creates an OpenGL rendering window, binds the OpenGL functions, and 
generates no errors.  Here's the corrected initializeGL method:


def initializeGL(self):
c = self.context()
f = QSurfaceFormat() # The default
p = QOpenGLVersionProfile(f)
self.GL = c.versionFunctions(p)
super().initializeGL()



On Tuesday, October 4, 2016 at 12:56:53 AM UTC-7, Phil Thompson wrote:
> On 4 Oct 2016, at 5:57 am, John Ladasky <j...@s...net> wrote:
> > 
> > On Monday, October 3, 2016 at 1:30:29 AM UTC-7, Phil Thompson wrote:
> >> On 3 Oct 2016, at 4:29 am, John Ladasky <j...@s...net> wrote:
> > If I ever understand a GUI like PyQt5 well enough, I'd like to contribute 
> > to its documentation.  Sigh.
> 
> If you are an OpenGL expert 

Ha!  

While I have experience with quite a few scientific computing Python tools 
(numpy, scipy, matplotlib, pandas, scikit-learn), I know less about OpenGL than 
I do PyQt5.  There's always more to learn.

>then you could help a lot by answering my questions about how individual 
>functions should be bound.

In all the examples I've encountered on the Net (most of which are written in 
C++ -- or if they are PyQt examples, they're binding older versions of OpenGL), 
the preferred approach seems to be the one that I've taken above.  If you want 
to call an OpenGL function, you have to look it up in the self.GL namespace.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5, OpenGL, where to start, minimal example code?

2016-10-03 Thread John Ladasky
On Monday, October 3, 2016 at 1:30:29 AM UTC-7, Phil Thompson wrote:
> On 3 Oct 2016, at 4:29 am, John Ladasky <j...@s...net> wrote:

> > And as you can see: trying to call versionFunctions() is exactly where my 
> > program failed.
> 
> Try passing a QOpenGLVersionProfile object to versionFunctions() that has a 
> version set to one supported by PyQt.

Hi Phil,

I'm trying to follow your advice.  It's strange, "from PyQt5.QtGui import 
QOpenGLVersionProfile" works fine, and I can make an object of that type.

However: http://pyqt.sourceforge.net/Docs/PyQt5/ DOES NOT DOCUMENT 
QOpenGLVersionProfile.  I did find Qt documentation, at 
http://doc.qt.io/qt-5/qopenglversionprofile.html.  I will investigate this 
issue further.  Sometimes it isn't obvious how the C++ constructors are wrapped 
in Python.

If I ever understand a GUI like PyQt5 well enough, I'd like to contribute to 
its documentation.  Sigh.

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


Re: PyQt5, OpenGL, where to start, minimal example code?

2016-10-02 Thread John Ladasky
On Sunday, October 2, 2016 at 7:21:15 PM UTC-7, blue wrote:
> You have here a PyQt5 Reference Guide 
> http://pyqt.sourceforge.net/Docs/PyQt5/index.html
> Some example can be found here 4 and 5 
> http://codeprogress.com/python/libraries/pyqt/

That's a nice page of examples, but there are no OpenGL examples.
 
> Support for OpenGL http://pyqt.sourceforge.net/Docs/PyQt5/opengl.html told us:
> 
> When compiled against Qt v5.1 or later, PyQt5 implements a set of either 
> desktop QOpenGL bindings or OpenGL ES v2 bindings depending on how Qt was 
> configured. This removes the dependency on any third-party OpenGL bindings 
> such as PyOpenGL.
> 
> At the moment the desktop bindings are for OpenGL v2.0 and are mostly 
> complete. Other versions will be added in later releases. If there are calls 
> which you need, but are currently unsupported, then please ask for the 
> support to be added.

I found that page many days ago.  I am not sure whether OpenGL 4.5, which is 
what Ubuntu installed for me, is an extension of OpenGL ES v2, or something 
completely different.

PyQt5 seems to be at least nominally aware of recent versions of OpenGL, and it 
knows that I have version 4.5 -- since my program went looking for a module 
called "QOpenGLFunctions_4_5_Compatibility".  On this page...

http://doc.qt.io/qt-5/qtgui-module.html

...the Qt5 QTGui documentation lists a plethora of functions to retrieve OpenGL 
"specifications" and "compatibility profiles", ranging from OpenGL 1.0 through 
4.5.

Note, these are not PyQt docs, they are for Qt.  I have been sometimes 
frustrated by the fact that the PyQt modules do not appear to have a one-to-one 
mapping with the hierarchy of Qt itself.

> Obtaining an object that implements the bindings for a particular OpenGL 
> version and profile is done in the same way as it is done from C++, i.e. by 
> calling versionFunctions(). In addition, the bindings object also contains 
> attributes corresponding to all of the OpenGL constants.

And as you can see: trying to call versionFunctions() is exactly where my 
program failed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5, OpenGL, where to start, minimal example code?

2016-10-02 Thread John Ladasky
On Sunday, October 2, 2016 at 7:45:50 PM UTC-7, Lawrence D’Oliveiro wrote:
> On Monday, October 3, 2016 at 2:14:13 PM UTC+13, John Ladasky wrote:
> > 
> > I am making my first attempt at 3D rendering.
> 
> Bear in mind there are two kinds of 3D rendering: realtime (with OpenGL) and 
> non-realtime.

Real time is what I want.  My object is not complex, but I need to rotate it.
-- 
https://mail.python.org/mailman/listinfo/python-list


PyQt5, OpenGL, where to start, minimal example code?

2016-10-02 Thread John Ladasky
Hi there,

I am making my first attempt at 3D rendering.  My system configuration:

OS : Ubuntu 16.04 64-bit
Python : 3.5.1
Qt : 5.5.1
PyQt   : 5.5.1
OpenGL : 4.5.0 (I have a modern GPU)

All software was installed from the Canonical repository.  I didn't build any 
binaries myself.

>From my reading, I have concluded that Qt, PyQt, and OpenGL are all 
>rapidly-evolving, and huge, software packages.  There may be compatibility 
>problems, and relevant examples with the right software combination may be 
>hard to find.

Two weeks of searching web pages hasn't turned up a single example which 
demonstrates PyQt5 doing something simple in 3D with OpenGL that I can study.  
My own attempt to write such a program displays my QOpenGLWidget subclass 
instance, and calls the methods I defined, but throws this exception:

ImportError: No module named 'PyQt5._QOpenGLFunctions_4_5_Compatibility'

Here's a snippet of the offending method of my QOpenGLWidget:

def initializeGL(self):
ctx = self.context()  # This works, ctx is a PyQt5.QtGui.QOpenGLContext
print(ctx.versionFunctions())  # ImportError occurs here

Searching for that ImportError, I found a page which says that error occurs 
when "you have a more capable version of OpenGL than PyQt has support for", but 
no advice is offered on how to fix that problem.

I like the idea of using PyQt5, because I'm getting pretty familiar with it, 
BUT I am open to trying any quick and clear route to 3D rendering.  I would 
appreciate the community's recommendations.  Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-03 Thread John Ladasky
On Sunday, July 3, 2016 at 12:42:14 AM UTC-7, Chris Angelico wrote:
> On Sun, Jul 3, 2016 at 4:58 PM, John Ladasky wrote:

> Very good question! The detaily answer is here:
> 
> https://docs.python.org/3/reference/lexical_analysis.html#identifiers
> 
> > A philosophical question.  Why should any character be excluded from a 
> > variable name, besides the fact that it might also be an operator?
> 
> In a way, that's exactly what's happening here. Python permits certain
> categories of character as identifiers, leaving other categories
> available for operators. Even though there aren't any non-ASCII
> operators in a vanilla CPython, it's plausible that someone could
> create a Python-based language with more operators (eg ≠ NOT EQUAL TO
> as an alternative to !=), and I'm sure you'd agree that saying "≠ = 1"
> is nonsensical.

I agree that there are some characters in the Unicode definition that could 
(should?) be operators and, as such, disallowed in identifiers.  "≠", "≥" and 
"√" come to mind.  I don't know whether the Unicode "character properties" are 
assigned to the characters in a way that would be satisfying to the needs of 
programmers.  I'll do some reading.

> Symbols like that are a bit of a
> grey area, so you may find that you're starting a huge debate :)

Oh, I can see that debate coming.  I know that not all of these characters are 
easily TYPED, and so I have to reach for a Unicode table to cut and paste them. 
 But once but and pasted, they are easily READ, and that's a big plus.

Here's another worm for the can.  Would you rather read this...

d = sqrt(x**2 + y**2)

...or this?

d = √(x² + y²)

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


Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-03 Thread John Ladasky
Lawrence, I trust you understand that I didn't post a complete working program, 
just a few lines showing the intended usage?
-- 
https://mail.python.org/mailman/listinfo/python-list


Well, I finally ran into a Python Unicode problem, sort of

2016-07-03 Thread John Ladasky
A while back, I shared my love for using Greek letters as variable names in my 
Python (3.4) code -- when, and only when, they are warranted for improved 
readability.  For example, I like to see the following:


from math import pi as π

c = 2 * π * r


When I am copying mathematical formulas from publications, and Greek letters 
are used in that publication, I prefer to follow the text exactly as written.

Up until today, every character I've tried has been accepted by the Python 
interpreter as a legitimate character for inclusion in a variable name.  Now 
I'm copying a formula which defines a gradient.  The nabla symbol (∇) is used 
in the naming of gradients.  Python isn't having it.  The interpreter throws a 
"SyntaxError: invalid character in identifier" when it encounters the ∇.

I am now wondering what constitutes a valid character for an identifier, and 
how they were chosen.  Obviously, the Western alphabet and standard Greek 
letters work.  I just tried a few very weird characters from the Latin Extended 
range, and some Cyrillic characters.  These are also fine.

A philosophical question.  Why should any character be excluded from a variable 
name, besides the fact that it might also be an operator?

This might be a problem I can solve, I'm not sure.  Is there a file that the 
Python interpreter refers to which defines the accepted variable name 
characters?  Perhaps I could just add ∇.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting back into PyQt and not loving it.

2016-06-27 Thread John Ladasky
On Sunday, June 26, 2016 at 7:41:17 PM UTC-7, Michael Torrie wrote:
> If GTK+ had first-class support on Windows and Mac, including native
> themes and seamless UI integration (file and print dialogs), I'd say
> GTK+ would be the only game in town for Python programmers.
> Unfortunately, unless you're only concerned with Linux, GTK+ is probably
> not going to be your choice.

Although I work almost exclusively in Linux, I've been teaching Python for 
several years as a sideline, and my students usually do not use Linux.  I 
insist on teaching my students Python 3.  Unless they're professionals who must 
work with legacy code (and, so far, none of them have been), I think I would be 
doing them a disservice to teach them Python 2.

I started with WxPython, but WxPython/Phoenix has been very slow to migrate to 
Python 3.  

Between the Py3 requirement and the need to work with all major OS's, I decided 
to learn PyQt and not GTK+.  

In my current day job, I'm developing an application on a Linux box, but I'll 
be handing it off to Windows users.  My choice of PyQt turned out to be the 
right one in that situation as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: value of pi and 22/7

2016-06-18 Thread John Ladasky
On Friday, March 18, 2011 at 5:17:48 AM UTC-7, Neil Cerutti wrote:
> RIIght.  What's a cubit?
> 
> -- 
> Neil Cerutti

How long can you tread water?  (Showing my age...)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [spam] Re: look what I've found [ignore]

2016-05-29 Thread John Ladasky
On Sunday, May 29, 2016 at 11:55:04 AM UTC-7, Peter Pearson wrote:
>
> No, it reached me, too, through NNTP.

I also saw it, through the Google Groups gateway.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Guido on python3 for beginners

2016-02-18 Thread John Ladasky
On Wednesday, February 17, 2016 at 11:28:17 PM UTC-8, Chris Angelico wrote:

> 5) print statement/function. Py3 forces you to put parentheses on it,
> which is no different from C's printf() or Pike's write() or any
> number of other languages where console I/O needs no language support.
> Maybe a tiny TINY advantage to Py2 in the short term, but as soon as
> you introduce the less basic features, keyword arguments are way
> better than the magic syntax the statement needs. (Also, trying to
> explain the interaction between the print statement's "soft space" and
> other console I/O is not easy.) By the time you've really learned the
> language, the advantage belongs to Py3.

Another advantage to the Py3 print function over the Py2 print statement is 
that it makes redirecting output SO much easier.  If I write a function that 
might sometimes print output to the console, and might at some other time print 
to a GUI window, or to a log file, I can just pass in the relevant output 
function name as an argument to my own function.  

This is very helpful, and I use it often.  I teach my new Python students to 
write their application's core logic, without regards to any GUI.  Later, when 
I teach them to use a GUI, building it is easier because the process is modular.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-15 Thread John Ladasky
On Monday, February 15, 2016 at 6:02:24 PM UTC-8, Rick Johnson wrote:
> On Friday, February 12, 2016 at 1:51:35 AM UTC-6, John Ladasky wrote:
> 
> Reguarding a migration from Python2 to Pyhton3, John said:
> >  I had to wait until my favorite packages were ported
> > (numpy, scipy, matplotlib, pandas).
> 
> WxPython is not ported either, much to my chagrin.

I was a big fan of WxPython myself.  I waited for Phoenix for a while, then 
decided to learn PyQt5.  Having been exposed to both GUI's ways of doing 
things, I'm not sure which I prefer.  I never liked Tkinter.

> > But once that happened, I moved from Py2 to Py3 years ago
> > with scarcely a bump, bruise, or scratch.
> 
> So you have no Python2.x code remaining in your repos? Are
> you telling us that you moved *EVERYTHING* to Python3? If
> so, i can't imagine how something like that would even be
> possible, hmm, unless of course, you don't have much code to
> move...?
>
> I could imagine that *IF* someone's entire Python repo
> consisted of a couple hundred (or less) small scripts, with
> few, or no, dependencies, such a migration would be
> relatively easy. But even though i've only been writing
> Python code for a handful of years, my repo consists of
> thousands of scripts, millions of lines of code, and many,
> *MANY* dependencies -- because after all, DRY is very
> important, yes?

It's true, I only have about 25,000 lines of code.  My largest program suite is 
only about 10% of that.  And indeed, it's now all in Py3. The 2to3 utility took 
care of most of my porting needs.  Yes, I aspire to the DRY principle.  I've 
written a few packages which extend Numpy's behavior in specific ways which 
I've re-used many times.

I acknowledge that there's a vocal group of Py2 users who have decided that 
it's too much trouble to switch.  The PSF has decided that its energies are 
better expended on growing Py3 than on maintaining Py2 for that diminishing 
user base.

But no one owns Python.  There is no law that states that Py2 adherents cannot 
maintain the language themselves, if they want it.  Sheesh.  Just do it.  Make 
it yours.  

Or make something better if you want.  You state:

> I don't need Python3. And i reckon that by the time i do, 
> something more interesting will come along, or, i'll create 
> something more interesting myself. i've been drafting, and 
> dreaming, of a new language spec for over a year now.. And 
> the best thing about starting a new language, you can do 
> anything you want... no dependencies! 

If you have all the skills that you claim, you're a far better programmer than 
I.  So -- exactly why are you complaining to people who are developing and/or 
using Py3?  Go off and impress everyone.  Become your own BDFL.

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


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-11 Thread John Ladasky
On Saturday, February 6, 2016 at 12:54:41 PM UTC-8, Rick Johnson wrote:
> On Wednesday, February 3, 2016 at 12:02:35 AM UTC-6, John Ladasky wrote:
> 
> > Rick, you don't like Python?  
> 
> If i didn't like Python, then i would happily let it self-
> destruct, yes? The problem is, i *DO* like Python. Python2
> was a great language, but python3 has been a disaster. Heck,
> even the BDFL has warned that Python4 cannot introduce as
> many backwards incompatible changes as python3. So obviously,
> he is admitting that Python3 was a disaster.

I had to wait until my favorite packages were ported (numpy, scipy, matplotlib, 
pandas).  But once that happened, I moved from Py2 to Py3 years ago with 
scarcely a bump, bruise, or scratch.  

I like lazy evaluation.  I think that Unicode handling is vastly improved (and 
yes, I'm fully aware that exactly two people in this newsgroup don't agree, 
they make sure we all know).  I have encountered few surprises, and nothing 
that makes my job harder.  

To be sure, people who are entrenched in the Py2 way of doing things, with a 
lot of legacy code, have some work to do -- on their code, and possibly on 
their brains.  Keep Py2 if you want it, then.  You still have a few more years 
before the PSF stops maintaining it.  If you really like it that much, why not 
maintain it yourself?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-03 Thread John Ladasky
Yeah, I know, I shouldn't answer this troll-bait.

Rick, you don't like Python?  Fine, go program in a language that you do like.  
There are many to choose from!  Meanwhile, Python is satisfying many 
programmers' needs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where are we in the Python 3 transition?

2016-01-04 Thread John Ladasky
I switched to Python 3 between three and four years ago, I think.  I was 
actually eager to make the switch, as I could see the value of clean Unicode 
support and lazy evaluation.  I had to wait until Matplotlib supported Py3, 
then I changed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hi

2015-07-26 Thread John Ladasky
On Saturday, July 25, 2015 at 10:39:48 AM UTC-7, 김지훈 wrote:
 Hi.
 I recently changed my path to be a programmer so I decided to learn python.
 I downloaded files(Python 2.7.10 - 2015-05-23) to setup on your website.

Unless you need to maintain someone's older software, I would personally 
recommend that you use Python 3 instead of Python 2.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: beginners choice: wx or tk?

2015-07-11 Thread John Ladasky
On Saturday, July 11, 2015 at 2:51:32 AM UTC-7, Ulli Horlacher wrote:
 Chris Angelico ros...@gmail.com wrote:
  There are other choices, too - pygtk/pygobject (GTK) and pyqt (Qt)
  come to mind
 
 Both create BIG executables, much bigger than with wx or tk.

I worked with wxPython back when I was using Python 2.  I got impatient waiting 
for Phoenix when I switched to Python 3, so I started using PyQt as my GUI.  

I'm happy with PyQt.  I haven't created standalone executable files with it, 
though.  Do they necessarily have to be large?  I would think that well-written 
import statements would cut down on the file size.  Just import the objects you 
need, rather than the whole namespace.  PyQt is even organized in sub-modules, 
apparently to encourage you to refrain from importing everything.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python programming classes for children

2015-07-01 Thread John Ladasky
On Wednesday, July 1, 2015 at 6:03:06 AM UTC-7, beli...@aol.com wrote:
 My 11yo son is taking the online class Intermediate Programming with Python 
 http://www.artofproblemsolving.com/school/course/catalog/python2 offered by 
 the Art of Problem Solving company (AoPS). Classes meet for 1.5 hours a week 
 for 12 weeks. During the classes the instructor lectures (types into a 
 console -- there is no sound) and students type answers to questions. There 
 are weekly programming assignments. AoPS is a U.S. company whose focus is 
 preparing students for math competitions.
 
 Are there other groups offering Python courses for pre-college students?

I would recommend that you investigate web sites which match tutors to 
students.  Find a Python tutor who can come to your home, or meet your son at a 
nearby public library.

I love technology, but it's not good for everything.  I have taught Python to a 
range of students, from middle-school age through working professionals.  I am 
also married to an elementary school teacher, and we sometimes discuss teaching 
methods and strategies.  I can't imagine that this remote, text-only method of 
teaching would be very effective, especially for a student that young.

If you have been programming for a while, you take some things for granted that 
kids have to learn, and be shown, with great patience.  For example, my 
youngest students often have trouble at first understanding the difference 
between variable names and their contents, especially when the variables are 
strings.

The only way that I agree to teach is face-to-face.  I have had a few potential 
students ask me to tutor over Skype, and I have always declined.

I bring a laptop, and the student sits at their own computer.  I have broad 
goals for a lesson when I arrive.  However I will, and indeed I must, deviate 
from my plans when the student doesn't understand a concept.

Occasionally I type on my own laptop, when instant visual feedback is needed.  
But mostly, I converse with the student, and look over their shoulders as they 
develop their code.  I let them make mistakes.  I ask them to run their buggy 
code, and when it doesn't work the way that they intended, I ask them if they 
can figure out why.

One more thing: I do NOT teach my students Python 2.  I have been working with 
a QA Engineer whose company uses Python 2, but all of my other students are 
free to choose to learn only Python 3.  Python 3 has been available for about 
five years now, and most new code is being developed in Py3.  I will not 
handicap my students by teaching them an obsolescent version of Python.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: most ambiguous line of code ever written?

2015-06-03 Thread John Ladasky
On Wednesday, June 3, 2015 at 8:21:43 AM UTC-7, Mark Lawrence wrote:

 right = not right
 
 Isn't that just beautiful?

A few weeks ago, we were discussing the fact that, in Python 2, True = False, 
and False = True, were both legal statements in Python.  I remarked: every 
politician's dream!  This remark would apply equally well to your clever 
statement.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where is 'palindrome' defined?

2015-06-02 Thread John Ladasky
On Monday, June 1, 2015 at 2:22:02 AM UTC-7, Marko Rauhamaa wrote:

 Sota-apina nakataan raastimeen.
   Apelle pane emit.
   Saarnaa takanani paatos.
 
 (= The war monkey will be chucked into a grater.
 Hand the pistils to father-in-law.
 Pathos does preach behind me.)

With this post, you have convinced me that 1) Finnish is a very interesting, 
and even poetic, language; and that 2) eating the velvet off of reindeer 
antlers must have a very similar effect to LSD.  :^)


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


Re: anomaly

2015-05-12 Thread John Ladasky
On Monday, May 11, 2015 at 3:16:16 AM UTC-7, Antoon Pardon wrote:

 Try overriding None, True or False in python3 and see what happens.

Much fun was able to be had in Python 2, though:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type help, copyright, credits or license for more information.
 True = False
 True
False


Every politician's dream!

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


Re: CHALLENGE HELP - GOOGLE DEVELOPER DAY

2015-05-05 Thread John Ladasky
On Tuesday, May 5, 2015 at 4:59:51 PM UTC-7, Chris Angelico wrote:
 On Wed, May 6, 2015 at 2:59 AM,  worship.bro...@gmail.com wrote:
  Good afternoon everyone.
 
  I'm with the following exercise of the option is a modification of a google 
  developer day exercise.
 
  SOMEONE HELP ME IN THIS CHALLENGE?
 
 You haven't posted any of your own code, so you're just asking for
 someone to do it for you. No, I will not.
 
 ChrisA

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


Re: Tit for tat

2015-04-28 Thread John Ladasky
On Tuesday, April 28, 2015 at 1:10:14 PM UTC-7, Robert Kern wrote:
 On 2015-04-28 07:58, Steven D'Aprano wrote:

 I do believe he is trying to make a crude joke.

I agree, that's what he's doing.  And I find it ironic, since he started this 
thread, and seemed to invite a serious discussion of the topic.

I thought that Patrick Grim's analysis was very interesting, showing that the 
Spatialized Iterated Prisoner's Dilemma (SIPD) could emulate the Wireworld 
cellular automaton, which is a Turing-complete system.  Thus, the SIPD, a 
seemingly simple system at first glance, includes configurations which are 
formally undecidable in the Gödelian sense.  I'm not sure whether Grim proved 
that an SIPD which includes the Tit for Tat strategy could emulate Wireworld, 
but it seems likely that one could be built.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tit for tat

2015-04-27 Thread John Ladasky
Following up to myself...

Here's a link to Patrick Grim's results that you can actually download 
(Springer really retains a 1997 research paper behind a paywall?):

http://www.pgrim.org/pgrim/SPATIALP.HTM
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tit for tat

2015-04-26 Thread John Ladasky
On Sunday, April 26, 2015 at 6:41:08 PM UTC-7, Seymore4Head wrote:
 
 Richard Dawkins explains with passion the idea of game theory and tit
 for tat, or why cooperation with strangers is often a strong strategy.
 
 He talks of a computer program tournament.  I don't know what I could
 say that would be more interesting than just watching the video.

Well, I'm not sure sure what any of this has to do with Python -- but since I 
know something about the subject, I'll reply.

That Richard Dawkins video is quite old -- it would appear to be from the 
middle 1980's.  Douglas Hofstadter's 1985 book, _Metamagical_Themas_, covered 
this exact same material.  A game called the Iterated Prisoner's Dilemma is 
played (I'll abbreviate it as IPD).  Humans can play, of course, but in this 
case it is played by algorithms.  An algorithm called Tit for Tat is 
surprisingly simple and robust.  When meeting a new contestant, Tit for Tat 
plays nice in round 1; and on every subsequent round, it plays however that 
opponent played the last time.  

Evolutionary biologists like Dawkins point to the success of Tit for Tat in IPD 
as a model of how cooperation could emerge in a population of selfish 
organisms.  Now, in a round-robin IPD game, Tit for Tat wins pretty handily.  
But in some other scenarios, as I recall, Tit for Tat is not a runaway winner.

Suppose that instead of each strategy playing EVERY other, each strategy 
inhabits a territory in a space, and each strategy only plays its neighbors.  
In rough neighborhoods, Tit for Tat can lose out to more punitive strategies. 
 If Tit for Tat is around more cooperative strategies, it thrives.  The 
boundaries between good neighborhoods and bad are chaotic.  Tit for Tat more or 
less holds the borders, but usually can't clean out a bad neighborhood.

This finding came out many years after the Hofstadter and Dawkins reports, so 
it's not covered in the video.  My reference to the idea is a 1997 paper 
entitled The Undecidability of the Spatialized Prisoner's Dilemma, by Patrick 
Grim (http://link.springer.com/article/10.1023%2FA%3A1004959623042).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Matplotlib] Ploting an exponential distribution frequency curve

2015-04-25 Thread John Ladasky
On Saturday, April 25, 2015 at 4:16:04 PM UTC-7, Mario Figueiredo wrote:
[snip]
 This works as intended. But plots a jagged curve due to the small
 discrepancies normal of a random number generation.
 
 Other than replacing the random module with the probability density
 function for the exponential distribution, do you have a suggestion of
 how I could smooth the curve?

Since you have a finite data set which only approximates the exponential 
distribution, a visual representation which connects the dots with line 
segments will definitely emphasize the noise in your data.

Matplotlib.pyplot has another useful function, scatter().  Scatter does not 
draw lines between adjacent values.  Start there.  See how your eye likes that.

If you really want to show a curve, and you do not want to calculate the 
limiting (infinite data samples) exponential variate on which your sample would 
eventually converge, you could construct moving averages using a sliding-window 
sample of the points (ordered by x value, of course) and then connect those 
averages.

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


Re: Sudoku solver

2015-03-25 Thread John Ladasky
On Wednesday, March 25, 2015 at 4:39:40 AM UTC-7, Marko Rauhamaa wrote:

 I post below a sudoku solver. I eagerly await neater implementations (as
 well as bug reports).

So, it's a brute-force, recursive solver?  The code is nice and short.  But I 
bet it takes a long time to run.

I and a student of mine are working on Sudoku solvers which solve puzzles the 
way that humans would.  Smart, pattern-recognition strategies take less time to 
run... but, obviously, far more time to turn into code!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Topic Modeling LDA Gensim

2015-03-17 Thread John Ladasky
Hey you two, get a room.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parallelization of Python on GPU?

2015-02-26 Thread John Ladasky
On Thursday, February 26, 2015 at 8:41:26 AM UTC-8, Sturla Molden wrote:
 If you are doing SVM regression with scikit-learn you are using libSVM.
 There is a CUDA accelerated version of this C library here:
 http://mklab.iti.gr/project/GPU-LIBSVM
 
 You can presumably reuse the wrapping code from scikit-learn.
 
 Sturla

Hi Sturla,  I recognize your name from the scikit-learn mailing list.  

If you look a few posts above yours in this thread, I am aware of gpu-libsvm.  
I don't know if I'm up to the task of reusing the scikit-learn wrapping code, 
but I am giving that option some serious thought.  It isn't clear to me that 
gpu-libsvm can handle both SVM and SVR, and I have need of both algorithms. 

My training data sets are around 5000 vectors long.  IF that graph on the 
gpu-libsvm web page is any indication of what I can expect from my own data (I 
note that they didn't specify the GPU card they're using), I might realize a 
20x increase in speed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Parallelization of Python on GPU?

2015-02-25 Thread John Ladasky
I've been working with machine learning for a while.  Many of the standard 
packages (e.g., scikit-learn) have fitting algorithms which run in single 
threads.  These algorithms are not themselves parallelized.  Perhaps, due to 
their unique mathematical requirements, they cannot be paralleized.  

When one is investigating several potential models of one's data with various 
settings for free parameters, it is still sometimes possible to speed things 
up.  On a modern machine, one can use Python's multiprocessing.Pool to run 
separate instances of scikit-learn fits.  I am currently using ten of the 
twelve 3.3 GHz CPU cores on my machine to do just that.  And I can still browse 
the web with no observable lag.  :^)

Still, I'm waiting hours for jobs to finish.  Support vector regression fitting 
is hard.

What I would REALLY like to do is to take advantage of my GPU.  My NVidia 
graphics card has 1152 cores and a 1.0 GHz clock.  I wouldn't mind borrowing a 
few hundred of those GPU cores at a time, and see what they can do.  In theory, 
I calculate that I can speed up the job by another five-fold.

The trick is that each process would need to run some PYTHON code, not CUDA or 
OpenCL.  The child process code isn't particularly fancy.  (I should, for 
example, be able to switch that portion of my code to static typing.)

What is the most effective way to accomplish this task?

I came across a reference to a package called Urutu which may be what I need, 
however it doesn't look like it is widely supported.

I would love it if the Python developers themselves added the ability to spawn 
GPU processes to the Multiprocessing module!

Thanks for any advice and comments.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parallelization of Python on GPU?

2015-02-25 Thread John Ladasky
On Wednesday, February 25, 2015 at 7:03:23 PM UTC-8, Steven D'Aprano wrote:

 I would like to point out that GPUs 
 typically don't support IEE-754 maths, which means that while they are 
 likely significantly faster, they're also likely significantly less 
 accurate.

Historically, that has been true.  According to this document...

https://developer.nvidia.com/sites/default/files/akamai/cuda/files/NVIDIA-CUDA-Floating-Point.pdf

...NVidia's GPU cards which implement compute capability versions 2.0 and 
higher are IEEE-754 compliant, both for single- and double-precision floating 
point operations.

The current compute capability version is 5.2, so there are several 
generations of GPU hardware out there by now which should give satisfactory 
floating-point results.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parallelization of Python on GPU?

2015-02-25 Thread John Ladasky
Thanks for the various links, Ethan.  I have encountered PyCUDA before, but not 
the other options.

So far, I'm not seeing code examples which appear to do what I would like, 
which is simply to farm out one Python process to one GPU core.  The examples 
all appear to parallelize array operations.  I know, that's the easier way to 
break up a task.

I may have to bite the bullet and learn how to use this:

http://mklab.iti.gr/project/GPU-LIBSVM

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


Re: Python discussed in Nature

2015-02-13 Thread John Ladasky
On Thursday, February 12, 2015 at 7:12:01 PM UTC-8, Steven D'Aprano wrote:
 John Ladasky wrote:
 
  And I use Unicode in my Python.  In implementing some mathematical models
  which have variables like delta, gamma, and theta, I decided that I didn't
  like the line lengths I was getting with such variable names.  I'm using
  δ, γ, and θ instead.  It works fine, at least on my Ubuntu Linux system
  (and what scientist doesn't use Linux?).  I also have special mathematical
  symbols, superscripted numbers, etc. in my program comments.  It's easier
  to read 2x³ + 3x² than 2*x**3 + 3*x**2.
 
 
 Oooh! What is your font of choice for this?

Steven, I'm trying to answer your question.  It's proving to be harder than I 
expected.

The default font that the Geany program editor uses on my Ubuntu system renders 
everything I've tried.  When I look up that font in Geany's Preferences menu, 
it is called, simply, monospace.

However, when I browse through fonts using the Ubuntu (14.04, 64-bit) Font 
Viewer, I do not find a font with that simple name.  I find several fonts whose 
name includes mono in the string: Liberation Mono, Nimbus Mono, Ubuntu Mono, 
etc.  All these fonts are listed as alternate choices in Geany's font selection 
menu.

Any Unicode that I use in my Python also renders nicely in the Ubuntu terminal. 
   In the Terminal Profile Preferences, the use the system fixed width font 
check box is selected.

So, it would appear that I'm using a font that the OS is selecting for me.  
Which font that is, I'm still trying to figure out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python discussed in Nature

2015-02-12 Thread John Ladasky
On Thursday, February 12, 2015 at 3:08:10 AM UTC-8, Fabien wrote:

 ... what a coincidence then that a huge majority of scientists 
 (including me) dont care AT ALL about unicode. But since scientists are 
 not paid to rewrite old code, the scientific world is still stuck to 
 python 2.

I'm a scientist.  I'm a happy Python 3 user who migrated from Python 2 about 
two years ago.

And I use Unicode in my Python.  In implementing some mathematical models which 
have variables like delta, gamma, and theta, I decided that I didn't like the 
line lengths I was getting with such variable names.  I'm using δ, γ, and θ 
instead.  It works fine, at least on my Ubuntu Linux system (and what scientist 
doesn't use Linux?).  I also have special mathematical symbols, superscripted 
numbers, etc. in my program comments.  It's easier to read 2x³ + 3x² than 
2*x**3 + 3*x**2.

I am teaching someone Python who is having a few problems with Unicode on his 
Windows 7 machine.  It would appear that Windows shipped with a 
less-than-complete Unicode font for its command shell.  But that's not Python's 
fault.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread John Ladasky
On Tuesday, February 10, 2015 at 11:00:32 AM UTC-8, Chris Angelico wrote:
 On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
 j...@sbcglobal.net wrote:
  I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 64-bit.
 
 
 That's  nice recent Python, but I just tried installing ipython using
 pip3, and got version 2.4.1, and was unable to reproduce your
 scenario. Is it possible you're having problems due to the version
 mismatch? Can you upgrade your ipython?
 
 ChrisA

Thank you Chris, that did the trick.  I now have ipython 2.4.1 as well, and my 
tracebacks are behaving.  Ubuntu's repository apparently has an outdated 
version of ipython.  

Also, a heads-up: the pip3 utility does not recognize a package named ipython3, 
the name that Ubuntu expects.  The package name reverts to plain-old ipython.  
This name conflict might cause problems for someone who wants to run ipython 
with Py2 -- while that isn't me, it may affect some of you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Taming the verbosity of ipython tracebacks

2015-02-10 Thread John Ladasky
Hi folks,

I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 64-bit.

Whenever I execute code from within ipython which triggers an exception -- any 
exception -- I get a page full of information.  The exceptions in my code 
trigger exceptions within ipython.

Every error message looks like this:



ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File /usr/lib/python3/dist-packages/IPython/core/interactiveshell.py, line 
2821, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
  File ipython-input-3-85f78e96b07a, line 1, in module
  
 MY ERRONEOUS CODE, AND THE EXCEPTION IT GENERATED, ARE PRINTED HERE 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File /usr/lib/python3/dist-packages/IPython/core/interactiveshell.py, line 
1713, in showtraceback
stb = value._render_traceback_()
AttributeError: 'NameError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File /usr/lib/python3/dist-packages/IPython/core/ultratb.py, line 759, in 
structured_traceback
records = _fixed_getinnerframes(etb, context, tb_offset)
  File /usr/lib/python3/dist-packages/IPython/core/ultratb.py, line 242, in 
_fixed_getinnerframes
records  = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File /usr/lib/python3.4/inspect.py, line 1332, in getinnerframes
framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File /usr/lib/python3.4/inspect.py, line 1292, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
  File /usr/lib/python3.4/inspect.py, line 583, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File /usr/lib/python3.4/inspect.py, line 629, in getmodule
os.path.realpath(f)] = module.__name__
AttributeError: 'FakeModule' object has no attribute '__name__'

Unfortunately, your original traceback can not be constructed.



When I run the same script directly from the Linux shell, I get a tidy 
traceback which tells me exactly what I want, and nothing more.  But then, 
obviously, I lose the interactive ipython shell's capabilities.

I would like to get rid of all that fluff surrounding my ipython error message. 
 I'm not sure what the purpose of the inspect module is, or what FakeModule is. 
 I wonder whether I have failed to install something correctly.  Any advice is 
appreciated!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread John Ladasky
On Tuesday, February 10, 2015 at 11:34:12 AM UTC-8, Albert-Jan Roskam wrote:
 - Original Message -
 
  From: Chris Angelico r...@gmail.com
  To: 
  Cc: python-list@python.org python-list@python.org
  Sent: Tuesday, February 10, 2015 8:00 PM
  Subject: Re: Taming the verbosity of ipython tracebacks
  
  On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
  j...@sbcglobal.net wrote:
   I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 
  64-bit.
  
  
  That's  nice recent Python, but I just tried installing ipython using
  pip3, and got version 2.4.1, and was unable to reproduce your
  scenario. Is it possible you're having problems due to the version
  mismatch? Can you upgrade your ipython?
 
 
 Huh? What's pip3? I thought pip works on Python 2 and 3?
 https://pypi.python.org/pypi/pip/. I always install everything with the pip 
 of my system python, e.g. for Python 3.4 I would do sudo python3.4 $(which 
 pip) install somepackage. Are there any benefits of having multiple pips 
 (except in virtualenvs)?
 
 Regards,
 Albert-Jan

Albert-Jan, on my Ubuntu system, pip and pip3 are two different utilities.  
Anything that I install with pip is linked to my Python 2 interpreter; 
likewise, pip3 links to Python 3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please help.

2015-02-09 Thread John Ladasky
On Monday, February 9, 2015 at 9:44:16 AM UTC-8, chim...@gmail.com wrote:
 Hello. Am trying to change the key words to my tribal language. Eg change 
 English language: print() to igbo language: de(). I have been stuck for 
 months I need a mentor or someone that can guide me and answer some of my 
 questions when I get stuck. Thanks..
 I will really appreciate it if someone attends to me.


In Python, functions are bound to names, exactly like other variables are.  You 
can bind any new name you want to an existing function, like this:

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type help, copyright, credits or license for more information.
 print(English)
English
 de = print
 de(Igbo)
Igbo
 print(Both function names work)
Both function names work
 de(Both function names work)
Both function names work


Hope that helps you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please help.

2015-02-09 Thread John Ladasky
On Monday, February 9, 2015 at 10:26:47 AM UTC-8, Dave Angel wrote:

 That will help him with the functions.  But not with the keywords.  The 
 OP didn't specify Python version, but in 3.x, print() is a function, and 
 can be rebound.  Since he said keyword, he's either mistaken, or he's 
 running 2.x
 
 But any real keywords, are a real problem.  For example, changing 'if' 
 to some other string.

That's true, Dave, he did say key words.  I only helped him with his example 
of a Python built-in function.  And you're right, shadowing key words is 
currently not possible.

Are you familiar with a program known as a talk filter?  They've been around 
for decades.  

http://www.hyperrealm.com/talkfilters/talkfilters.html

Talk filters are usually used for off-color humor, rather than for serious 
purposes.  A talk filter processes a text stream, line-by-line, typically in a 
chat room setting.  A dictionary of words, and their replacements, is defined.  

I could see a talk filter being used to translate a non-English version of 
Python into standard English Python code.  I suppose that a hook for a talk 
filter could be added to the interpreter itself.  It wouldn't be easy to change 
word order to accommodate the syntax of another language, but words themselves 
could be altered.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Formatting string with accented characters for printing

2015-01-27 Thread John Ladasky
Jerry,

I can tell from your code that you are using Python 2.  If you are a new Python 
programmer, and you do not HAVE to use Python 2, use Python 3 instead.

In Python 3, text objects are something called Unicode rather than just 
sequences of bytes.  Unicode makes it much easier to handle characters which 
are not part of the English alphabet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What killed Smalltalk could kill Python

2015-01-21 Thread John Ladasky
On Wednesday, January 21, 2015 at 11:18:54 AM UTC-8, Grant Edwards wrote:
 On 2015-01-21, Steven D'Aprano st...@pearwood.info wrote:
  In 2009, Robert Martin gave a talk at RailsConf titled What Killed
  Smalltalk Could Kill Ruby.
 
 But does he answer the more important question and can we use it to
 kill PHP?.

LOL!

Seriously, I did.

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


Namespace puzzle, list comprehension fails within class definition

2015-01-12 Thread John Ladasky
I've never come across this before.  Here's a minimal example (in Python 3.4):


Code:
-

d = {0:a, 1:b, 2:c, 3:d}
e = [d[x] for x in (0,2)]

class Foo:
f = {0:a, 1:b, 2:c, 3:d}
print(f)
g = [f[x] for x in (0,2)]

foo = Foo()


Output:
-

{0: 'a', 1: 'b', 2: 'c', 3: 'd'}

Traceback (most recent call last):
  File minimal example.py, line 6, in module
class Foo:
  File minimal example.py, line 9, in Foo
g = [f[x] for x in (0,2)]
  File minimal example.py, line 9, in listcomp
g = [f[x] for x in (0,2)]
NameError: name 'f' is not defined

-

When I am working in the top-level namespace, I get no errors when referencing 
the dictionary, d, inside the list comprehension which generates e.

When I am working inside the class namespace, the print function call on line 8 
recognizes the name f and prints the dictionary bound to that name.

However, the LIST COMPREHENSION defined inside the class namespace generates a 
NameError.

In all my years of Python programming, I guess that I have never tried to 
define a class attribute using a list comprehension.  Why doesn't it work?  Any 
advice, and suggestions for Pythonic workarounds, are appreciated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Namespace puzzle, list comprehension fails within class definition

2015-01-12 Thread John Ladasky
Following up to myself: I finally did the right keyword search, and found a 
relevant article:

http://stackoverflow.com/questions/13905741/accessing-class-variables-from-a-list-comprehension-in-the-class-definition

Maybe I HAVE tried to define a list comprehension inside a class definition 
before.  What I tried to do would have apparently worked in Python 2.  But in 
Python 3, the namespace behavior has changed (and I'm still reading the article 
to understand how and why).

I guess that I could define my objects as globals... now, why would Python 
force me into doing that? :^(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Namespace puzzle, list comprehension fails within class definition

2015-01-12 Thread John Ladasky
On Monday, January 12, 2015 at 12:41:30 PM UTC-8, Ethan Furman wrote:

 In Foo 'f' is part of an unnamed namespace; the list comp 'g' has its own 
 namespace, effectively making be a nonlocal;
 class name lookup skips nonlocal namespaces.
 
 Workaround:  use an actual for loop.

Thanks, Ethan.  That works.

As you can see from my other post, I've just discovered that the scoping rules 
for list comprehensions were changed between Py2 and Py3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pickle, modules, and ImportErrors

2015-01-07 Thread John Ladasky
On Wednesday, January 7, 2015 12:56:29 PM UTC-8, Devin Jeanpierre wrote:

[snip]

 If you never run model directly, and only ever import it or run it as
 my_svr.model, then you will be fine, and pickles will all serialize
 and deserialize the same way.

Thank you Devin... I re-ran TrainingSession from within ipython, and everything 
worked the way I hoped.  I obtained an SVRModel object which I could pickle to 
disk, and unpickle in a subsequent session.  I don't actually need to run the 
test code that I appended to training.py any more, so I won't.

[snip]

 P.S. don't use pickle, it is a security vulnerability equivalent in
 severity to using exec in your code, and an unversioned opaque
 schemaless blob that is very difficult to work with when circumstances
 change.

For all of its shortcomings, I can't live without pickle.  In this case, I am 
doing data mining.  My TrainingSession class commandeers seven CPU cores via 
Multiprocessing.Pool.  Still, even my toy TrainingSessions take several 
minutes to run.  I can't afford to re-run TrainingSession every time I need my 
models.  I need a persistent object.

Besides, the opportunity for mischief is low.  My code is for my own personal 
use.  And I trust the third-party libraries that I am using.  My SVRModel 
object wraps the NuSVR object from scikit-learn, which in turn wraps the libsvm 
binary.

  try:
  from model import *
  from sampling import *
  except ImportError:
  from .model import *
  from .sampling import *
 
 
  This bothers me.  I don't know whether it is correct usage.  I don't know 
  whether it is causing my remaining ImportError problem.
 
 This is a symptom of the differing ways you are importing these
 modules, as above. If you only ever run them and import them as
 my_svr.blahblah, then only the second set of imports are necessary.

OK, I will try refactoring the import code at some point.
 
 I hope that resolves all your questions!

I think so, thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


pickle, modules, and ImportErrors

2015-01-07 Thread John Ladasky
I am progressing towards organizing a recent project of mine as a proper Python 
package.  It is not a huge package, about 700 lines of code so far.  But it 
breaks into logical pieces, and I don't feel like scrolling back and forth 
through a 700-line file.

I am running Python 3.4.0 on Ubuntu 14.04, if it matters.  

I want a package which I can use in an iPython session, as well as in programs 
which share the package directory.  Compatibility within the package directory 
appears to be easy.  From outside the package, I am getting ImportErrors that I 
have not been able to fix.

Although I have used pickle often, this is the first time that I have written a 
package with an __init__.py.  It reads thus:


# __init__.py for my_svr module

from .database import MasterDatabase
from .sampling import Input
from .sampling import MultiSample
from .sampling import Sample
from .sampling import Target
from .sampling import DataPoint
from .model import Prediction
from .model import SVRModel
from .model import comparison
from .training import TrainingSession

__all__ = (MasterDatabase, Input, MultiSample, Sample, Target,
   DataPoint, Prediction, SVRModel, comparison,
   TrainingSession)


If I execute import my_svr in an iPython interpreter, everything works as I 
think that I should expect:


In [8]: dir(my_svr)
Out[8]: 
['Input',
 'MasterDatabase',
 'MultiSample',
 'Prediction',
 'SVRModel',
 'Sample',
 'Target',
 'DataPoint',
 'TrainingSession',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'comparison',
 'database',
 'model',
 'sampling',
 'training']



My training.py program produces an SVRModel object, and pickles it to a binary 
file.  The following simple program will unpickle the file saved by 
training.py, provided that the program resides in the module's own folder:


# reload_test.py

from pickle import load

with open(../models/sample model.pkl, rb) as f:
model = load(f)
print(model)


And, I get the str representation of my SVRModel instance.

However, a nearly-identical program in the parent folder fails (note that all I 
change is the relative path to the file):


# parent_folder_reload_test.py

from pickle import load

with open(models/sample model.pkl, rb) as f:
model = load(f)
print(model)


Traceback (most recent call last):
  File reload test different directory.py, line 6, in module
model = load(f)
ImportError: No module named 'model'


Do I need to import my_svr.model as model then?  Adding that line changes 
nothing. I get the exact same ImportError: No module named 'model'.  

Likewise for import my_svr, from my_svr import *, or even from 
my_svr.model import SVRModel.

It is clear that I'm failing to understand something important.

I do not have any circular import dependencies; however, some of the files in 
my package do need to import definitions from files earlier in my data 
pipeline.  In order to make everything work inside the module, as well as 
making a parent-folder import my_svr work from a iPython,  I find myself 
needing to use statements like these inside my training.py program:


try:
from model import *
from sampling import *
except ImportError:
from .model import *
from .sampling import *


This bothers me.  I don't know whether it is correct usage.  I don't know 
whether it is causing my remaining ImportError problem.

Any advice is appreciated.  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


How about some syntactic sugar for __name__ == '__main__' ?

2014-11-12 Thread John Ladasky
I have taught Python to several students over the past few years.  As I have 
worked with my students, I find myself bothered by the programming idiom that 
we use to determine whether a module is being executed or merely imported:

  if __name__ == '__main__':

The use of two dunder tokens -- one as a name in a namespace, and the other as 
a string, is intimidating.  It exposes too much of Python's guts.  As such, I 
think that it is less Pythonic than we might want.  Myself, I've been 
programming in Python for a decade, and I still haven't dug very deeply into 
what exactly __name__ means or does.

I would like to start a discussion about whether Python should include a 
function which executes this evaluation, and hides all of the unfriendly 
dunderish details.  And if that's a good idea, I would invite a discussion of 
how, exactly, it should be implemented.  I'm nowhere near proposing a PEP, but 
that may come later.

Thanks for your thoughts.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How about some syntactic sugar for __name__ == '__main__' ?

2014-11-12 Thread John Ladasky
It appears that I'm not the first person to have thoughts along these lines.  
Here's a relevant article:

http://aliles.tumblr.com/post/7455032885/sugar-for-pythons-main
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Dinamically set __call__ method

2014-11-06 Thread John Ladasky
On Tuesday, November 4, 2014 11:12:31 AM UTC-8, Ethan Furman wrote:

 If you really absolutely positively have to have the signature be correct for 
 each instance, you may to either look at a 
 function creating factory, a class creating factory, or a meta-class.

+1.  Overriding __call__() within the class definition, over and over again, 
with different function, looks awkward to me.


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


Re: Teaching Python

2014-09-29 Thread John Ladasky
I am actually teaching Python as a side job.  My students have ranged from 
eighth graders, up to a Silicon Valley hardware engineer who had no coding 
experience, but who needed to do some test engineering.

My wife is an elementary school teacher.  We occasionally talk about 
age-appropriate learning, and pedagogical strategies.  I once watched a 
research biologist try to explain restriction enzymes to my sixth-grade son.  
It was painful to watch.  Sure, my son is a smart kid, but there was no way he 
was going to understand what she was talking about without some background.

For my younger Python students, I interact with them directly, sitting by their 
side while they type.  Initially, I do not ask them to read any computer 
documentation.  It's too difficult for them, even the official Python tutorial. 
  The tutorial is aimed at an adult reader who has at least a little computer 
experience -- and sometimes, quite a lot.  Just read Chapter 1.  Imagine that 
you're 14 years old, reading that.  Even if you have already programmed in one 
of the languages aimed at children, like Scratch, you will be in way over your 
head.  

Now, even though I think that the Python tutorial is too hard for young 
students to read, I do cover much of the MATERIAL in that tutorial, and in 
approximately the same order.  I sit the student down in front of the 
interpreter, explain what an interpreter is, and then have them type simple 
mathematical expressions.  I introduce variable names, and then strings, and 
lists.  This is, more or less, the material in Chapter 3 of the tutorial -- 
although lists are not discussed until Chapter 5.

Next, I introduce the idea of a program file, and have them start working with 
an editor.  That's not in the tutorial at all.  I introduce the print() 
function (briefly mentioned in Chapter 3), and the for statement (Section 4.2). 
 Once you introduce the for statement, you need to explain code blocks, the use 
of a colon at the end of a line, and the use of indentation.

This is enough information to get the student to write short programs.  I start 
with single loops.  Then, I have the student write a multiplication table 
program.  Getting the student to grasp the idea of a loop inside a loop can 
sometimes be challenging.

The next three things that I teach are the if statement (Section 4.1), the 
input() function (which appears in Chapter 4 of the tutorial, without any 
introduction or explanation), and string concatenation using the + operator.  
This is enough to get the student to write a program which accepts an input 
string, and prints out an alphabetized version of that string.  I do not show 
the student the sorted() function until after they write the program with what 
they know!

Typically, I move on to the range() function and slicing operations next.  But 
unless you are working with very bright kids, that should be enough to keep 
them busy for a while.  :^)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bicyclerepairman python24 windows idle :(

2014-09-04 Thread John Ladasky
On Thursday, September 4, 2014 1:52:37 PM UTC-7, Ned Batchelder wrote:

 This seems like enough of a non-sequitur that I wonder if you posted it 
 in the wrong place?

Maybe someone is trying out a new chatbot program?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple question

2014-08-24 Thread John Ladasky
On Saturday, August 23, 2014 6:10:29 AM UTC-7, explode...@gmail.com wrote:
 Can some one explain why this happens:
 
 True, False = False, True
 
 print True, False
 
 False True

Shush!  That's one of Python's most closely-guarded secrets!  Every politician 
on Earth will want to learn to program in Python after seeing that!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function error

2014-06-14 Thread John Ladasky
On Saturday, June 14, 2014 11:17:50 AM UTC-7, sandhyaran...@gmail.com wrote:
 I am new to python, pls help me to resolve the below error
 
 
 
 
 
  def fib(n):
 
 ... Print a Fibonacci series up to n.
 
   File stdin, line 2
 
 Print a Fibonacci series up to n.
 
   ^
 
 IndentationError: expected an indented block

Python uses indentation to delineate blocks of code, instead of (for example) 
curly brackets.  Add some white space (the convention is four characters) after 
at least the first line that ends with a colon, and then indent every line that 
is in the code block accordingly.  Like this:

def fib(n):
Print a Fibonacci series up to n.
do_something()
do_something_else()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is there a list/group for beginners?

2014-05-27 Thread John Ladasky
Hi, Deb.

Ten years ago (or eleven?), I was completely new to Python.  I could not begin 
to understand over 90 percent of what I was reading here in comp.lang.python.  
Still, I asked my newbie questions here.  For the most part, I got excellent 
responses.  I think you're in the right place.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Method(s) called by square brackets, slice objects

2014-04-10 Thread John Ladasky
Thanks to both Ethan and Steven for their replies.

Steven: I was trying to use the interpreter and wasn't getting results that I 
understood -- because I didn't know that __getslice__ was simply gone in Python 
3.  I implemented a __getslice__ method in my subclass that never got called.

Ethan: I saw that slice objects were being sent to __getitem__, but that 
confused me as I thought that its purpose, as implied by the method name, was 
to return a SINGLE item.

OK, I think that I've got all that sorted out!
-- 
https://mail.python.org/mailman/listinfo/python-list


Method(s) called by square brackets, slice objects

2014-04-09 Thread John Ladasky
I would like to build a multi-dimensional array that allows numpy-style 
indexing and, ideally, uses Python's familiar square-bracket and slice 
notations.

For example, if I declare a two-dimensional array object, x, then x[4,7] 
retrieves the element located at the 4th row and the 7th column.  If I ask for 
x[3:6,1:3], I get a 3 x 2 array object consisting of the intersection of the 
3rd-5th rows, and the 1st-2nd columns, of x.

In this case I'm not allowed to use numpy, I have to restrict myself to the 
standard library.  I thought that I might achieve the desired behavior by 
defining an object with specific __getitem__ and/or __getslice__ methods.  
However, the documentation of these methods that I am reading suggests that the 
arguments are pre-parsed into certain formats which may not allow me to do 
things numpy's way.  Is this true?
-- 
https://mail.python.org/mailman/listinfo/python-list


Mutable objects inside tuples - good or bad?

2014-04-06 Thread John Ladasky
I find this programming pattern to be useful... but can it cause problems?

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
[GCC 4.8.1] on linux
Type help, copyright, credits or license for more information.
 a = [1,2,3]
 b = [4,5,6]
 c = (a,b)
 c
([1, 2, 3], [4, 5, 6])
 c[0][0] = 0
 c
([0, 2, 3], [4, 5, 6])

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


Re: Python programming

2014-03-08 Thread John Ladasky
On Friday, March 7, 2014 4:38:54 PM UTC-8, Dennis Lee Bieber wrote:
 On Fri, 7 Mar 2014 10:03:35 -0800 (PST), John Ladasky
 j...@sbcglobal.net declaimed the following:
 
   More than once, I have queried Google with the phrase Why isn't FORTRAN
 dead yet?  For some reason, it lives on.  I can't say that I understand
 why.  

   Well, for one thing, no one can justify rewriting all the numerics
 libraries... LAPACK http://en.wikipedia.org/wiki/LAPACK , NEC-2
 http://en.wikipedia.org/wiki/Numerical_Electromagnetics_Code (and likely
 NEC-4).

I have used Numpy for years, and I'm pretty sure that Numpy calls LAPACK under 
the hood.  But if that is true, then I get LAPACK as a pre-compiled binary.  I 
didn't need a FORTRAN compiler until last week.

If one or two specialized applications are the only reason we are keeping a 50 
year-old programming language around, I would be tempted to rewrite those 
applications -- in C, at least.  C's not dead yet!  (It's just resting!)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python programming

2014-03-07 Thread John Ladasky
On Thursday, February 13, 2014 12:30:39 AM UTC-8, larry@gmail.com wrote:
 On Wed, Feb 12, 2014 at 10:56 PM, William Ray Wing w...@mac.com wrote:
 
  OK, and how many of you remember the original version of the 
  tongue-in-cheek essay Real Programmers Don't Use Pascal from the back 
  page of Datamation?
 
 I do remember it.
 
 http://www.webcitation.org/659yh1oSh


As do I, though I couldn't have been more than about 16 years old when it came 
out.  I just re-read it, and this comment jumped out at me:

Neither OS/370 nor FORTRAN show any signs of dying out, despite all the 
efforts of Pascal programmers the world over.

Well, OS/370, RIP.

As for FORTRAN?  This week, I actually downloaded an application which required 
a FORTRAN compiler.  This is the only FORTRAN application I've ever needed.  
It's not old code, the first revision came out about 10 years ago.  More than 
once, I have queried Google with the phrase Why isn't FORTRAN dead yet?  For 
some reason, it lives on.  I can't say that I understand why.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to begin

2014-02-13 Thread John Ladasky
On Thursday, February 13, 2014 7:06:03 AM UTC-8, pete suchsland wrote:

 if x = 99:

Surely, Pete, you meant to write if x == 99: ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Welcome to the Internet. No one here likes you. (was: Newcomer Help)

2014-02-13 Thread John Ladasky
On Thursday, February 13, 2014 8:32:46 AM UTC-8, larry@gmail.com wrote:

 This reminds me of post that was circulating in the early 90's:
 
 Welcome to the Internet.
 
 No one here likes you.
 
 We're going to offend, insult, abuse, and belittle the living hell out
 of you. And when you rail against us with FUCK YOU YOU GEEK WIMP
 SKATER GOTH LOSER PUNK FAG BITCH!1!!, we smile to ourselves. We laugh
 at you because you don't get it. Then we turn up the heat, hoping to
 draw more entertainment from your irrational fuming.
[snip]

Ummm... Larry, I hope you are just posting this rant because Rustom Mody's 
remarks reminded you of it.  I hope that you do not personally subscribe to 
this behavior.

Yes, I too was a bullied nerd when I was young.  I don't use my history as an 
excuse to do unto others what was done unto me.  No one should.  No one should 
bully another person, period.  It's not entertainment, it's a deeply harmful 
practice, and does not deserve any respect.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Combination Function Help

2014-02-12 Thread John Ladasky
On Wednesday, February 12, 2014 7:56:05 AM UTC-8, kjak...@gmail.com wrote:
[snip]
 choices(n, k)

 Changed it like you said, didn't work

What are you doing with the value returned by the function, choices()?  Right 
now, you aren't doing anything with it.  You are throwing it away.  That's the 
beginning of your problem.

In your own program, you have two other working examples of functions which 
return and use values.  You should study these.  

The first, and easier function call for you to understand is the call to int(). 
 You call it twice.  The first time, you ASSIGN the name n to the value 
returned by int().  The second time, you assign the name k to the value 
returned by another run of int().

Assigning the names to the values returned by the function calls is what allows 
you to work with those values later, on other lines of your program.  Without 
assigning n and k, attempting to call choices(n,k) would generate an error.

If int() was written in Python (it probably isn't; most of the Python core is 
written in C) and you looked at int()'s source code, it would have a return 
statement in it, just like your choices() does.

Does that help you to see how you should modify the last line of your program, 
and what you might do after that?

There's a second function call in your program as well: you call input().  This 
function call would be harder for a beginner to understand, because it happens 
to be nested inside the int() function call.  Let's take the simpler one first.
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   >