Is there a nice way to switch between 2 different packages providing the same APIs?

2018-07-05 Thread Mark Summerfield via Python-list
For GUI programming I often use Python bindings for Qt.

There are two competing bindings, PySide and PyQt.

Ideally I like to have applications that can use either. This way, if I get a 
problem I can try with the other bindings: if I still get the problem, then it 
is probably me; but if I don't it may be an issue with the bindings.

But working with both means that my imports are very messy. Here's a tiny 
example:

if PYSIDE: # bool True -> Use PySide; False -> Use PyQt5
from PySide2.QtCore import Qt
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import (
QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton,
QVBoxLayout)
else:
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (
QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton,
QVBoxLayout)

The PYSIDE constant is imported from another module and is used for all .py 
files in a given project so that just by changing PYSIDE's value I can run an 
entire application with PySide2 or with PyQt5.

But I'd really rather just have one lot of imports per file.

One obvious solution is to create a 'Qt.py' module that imports everything 
depending on the PYSIDE switch and that I then use in all the other .py files, 
something like this:

from Qt.QtCore import Qt
from Qt.QtGui import QIcon
... etc.

But I'm just wondering if there's a nicer way to do all this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Rosetta: Sequence of non-squares

2017-05-02 Thread Mark Summerfield via Python-list
On Monday, May 1, 2017 at 9:47:10 PM UTC+1, jlad...@itu.edu wrote:
> On Monday, May 1, 2017 at 11:27:01 AM UTC-7, Robert L. wrote:
> [no Python]
> 
> Do you ever plan to ask any questions about Python?  Or are you just using a 
> few lines of code as a fig leaf for the race baiting that you post in your 
> signatures?

This person sometimes includes Ruby code but clearly the purpose of their posts 
is to present signatures that contain racist/anti-semitic/etc content and/or 
links to such content.

I don't reply to these posts (some of which are new topics; some of which are 
replies to legitimate topics). Instead I click near the Google reply button to 
get a menu and click the "Report abuse" link. If the post directly contains 
offensive content, then I click "Hateful or violent content"; but if it doesn't 
I simply leave the default of "Spam" and then click "Submit report". Hopefully, 
sooner or later if enough people do this Google Groups will automatically 
filter out these posts. (The posts are already filtered out of the official 
comp.lang.python list, but they can't do this for the Google Groups version.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why am I getting a 'sqlite3.OperationalError'?

2017-05-11 Thread Mark Summerfield via Python-list
The ? is indeed for variable substitution, but AFAIK only for field values, not 
for table names, which is why your first example doesn't work and your second 
and third examples do work.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install Python package from source on Windows

2017-05-16 Thread Mark Summerfield via Python-list
I think the problem that Deborah has encountered is a more general one on
Windows: many pip-installable packages assume that a C compiler is
available.

Now an "obvious" solution is for pip to recognise that a C compiler is
needed and give an appropriate error message. But while that may reduce
confusion, it won't actually help someone who wants to install a Python
package that needs a C compiler.

Of course, the error message could give a link to the appropriate
compiler. And then the user (who presumably isn't a Windows compiler
expert) will if they're really lucky get to download and install an
enormous Visual Studio compiler. Of course they may not be so lucky and
may discover that the installer tells them that they need some component
(and may or may not give the link to get it). And then they get that
component and, you guessed it, that component says it needs another
component, ... and eventually you end up with all the pieces. And even
then it doesn't necessarily work. (This has happened to me more than
once.)

Here's a fantasy:

C:\> pip install pkg_needs_c
Error: the pkg_needs_c package needs development tools which haven't been
found on this computer.
Run pip install --listtools pkg_needs_c for information on the required
tools or run pip install --useprebuilt pkg_needs_c to download prebuilt
components so no additional development tools are needed.

C:\> pip install --listtools pkg_needs_c
The pkg_needs_c needs Visual Studio 2015 (which itself may have additional
dependencies). This can be downloaded from http://www

C:\> pip install --useprebuilt pkg_needs_c
...

This will send the minimum necessary details of the machine back to PyPI
which will then do a request on a Windows server farm which will send back
a matching pre-built package (building the package the first time it is
needed).

I have no idea if this is possible/practical!

But I do think that installing dev tools on Windows can be really difficult 
(esp. if you're on older versions of Windows, e.g., XP, Vista, or 7) and that 
this can make things hard for people coming to Python on Windows. I guess the 
best that can be done for now is to recommend Annaconda or a similar distro 
with lots of prebuilt stuff.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 is non-transactional??

2017-06-15 Thread Mark Summerfield via Python-list
On Thursday, June 15, 2017 at 9:50:18 AM UTC+1, Michele Simionato wrote:
> Thanks. I suspected the culprit was executescript, but I did not see it 
> documented in 
> https://docs.python.org/3/library/sqlite3.html#connection-objects.

Although the standard library's sqlite3 module is useful, personally, I've 
switched to using APSW which I've found to be extremely reliable and gives much 
more access to SQLite functionality: https://rogerbinns.github.io/apsw/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sqlite in 2.7 on redhat 6

2017-06-15 Thread Mark Summerfield via Python-list
On Thursday, June 15, 2017 at 1:47:00 PM UTC+1, larry@gmail.com wrote:
> I am trying to use sqlite
> 
> $ python2.7
> Python 2.7.10 (default, Feb 22 2016, 12:13:36)
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import _sqlite3
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named _sqlite3
> 
> It's there at: 
> /opt/rh/python27/root/usr/lib64/python2.7/lib-dynload/_sqlite3.so
> but that is not in my path.
> 
> I tried adding /opt/rh/python27/root/usr/lib64/python2.7/lib-dynload/
> to my path and then it fails with:
> 
> ImportError: libpython2.7.so.1.0: cannot open shared object file: No
> such file or directory
> 
> Isn't sqlite part of the standard lib? Shouldn't this just work?

Try:

>>> import sqlite3 # no leading underscore
-- 
https://mail.python.org/mailman/listinfo/python-list