Re: Need to 'import gtk' on Ubuntu 20.04, what do I need?

2020-07-25 Thread Liste guru

Il 24/07/2020 10:31, Chris Green ha scritto:


   ...

I'm a *fairly* competant Python programmer so, if I have to, I 
willconsider converting from using the gtk module to using the gi 
module,are there any good tutorials which might help me down this road?



   If you look at the pygobject documentation there is a chapter (and a 
script, similar to 2to3) to help the migration: 
https://pygobject.readthedocs.io/en/latest/guide/porting.html


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


Re: Need to 'import gtk' on Ubuntu 20.04, what do I need?

2020-07-25 Thread Michael Torrie
On 7/23/20 2:41 PM, Chris Green wrote:
> I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
> 20.04.  I have some Oki printer/scanner driver software that is
> written in Python 2 and, although python 2 is still installed on my
> system it's no longer the default python and the Oki software no
> longer runs.
> 
> The error I am getting is:-
> 
> chris@esprimo$ ./scantool.py
> Traceback (most recent call last):
>   File "./scantool.py", line 52, in 
> import gtk
> ImportError: No module named gtk
> 
> So what do I need to install on my Ubuntu 20.04 system to provide the
> gtk module?  

Someone has made a PPA with the python2 pygtk2 package:

https://launchpad.net/~nrbrtx/+archive/ubuntu/python2-stuff

sudo add-apt-repository ppa:nrbrtx/python2-stuff
sudo apt-get install python-gtk2

I can't vouch for the source, so use at your own risk.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to limit *length* of PrettyPrinter

2020-07-25 Thread dn via Python-list
Let me preface this reply with the concern that my level of competence, 
in this area, is insufficient. However, there are a number of folk 
'here' who are 'into' Python's internals, and will (hopefully) jump-in...



Also, whilst we appear to be concentrating on understanding the content 
of a data-structure, have we adequately defined "length"?

(per msg title)

- total number of o/p lines (per paper.ref)
- total number of characters 'printed'
- total number of elements l-r (of any/all embedded data-structures)
- the number of elements in each embedded data-structure
- the number of characters displayed from each embedded d-s
- depth of data-structure t-d
- something else?


On 25/07/2020 10:52, Stavros Macrakis wrote:

dn, Thanks again.

For background, I come from C and Lisp hacking (one of the MIT 
developers of Macsyma /Maxima 
) and also play with 
R, though I haven't been a professional developer for many years. I know 
better than to Reply to a Digest -- sorry about that, I was just being 
sloppy.


Us 'silver-surfers' have to stick-together! Also in the seventies I 
decided Lisp was not for me...



The reason I wanted print-length limitation was that I wanted to get an 
overview of an object I'd created, which contains some very long lists. 
I expected that this was standard functionality that I simply couldn't 
find in the docs.


I'm familiar with writing pretty-printer ("grind") functions with string 
output (from way back: see section II.I, p. 12 
), but 
I'm not at all familiar with Python's type/class system, which is why 
I'm trying to understand it by playing with it.


I accept, one might say 'on faith', that in Python "everything is an 
object", and proceed from there. Sorry!


Similarly, I've merely accepted the limitations of pprint() - and 
probably use it less-and-less, as I become more-and-more oriented 
towards TDD...



I did try looking at the Python Standard Library docs, but I don't see 
where it mentions the superclasses of the numerics or of the collection 
types or the equivalent of *numberp*. If I use *type(4).__bases__*, I 
get just*(,)*, which isn't very helpful. I suspect that 
that isn't the correct way of finding a class's superclasses -- what is?


If you haven't already, try:
- The Python Language Reference Manual (see Python docs)
in particular "Data Model"
- PSL: Data Types = "types -- Dynamic type creation and names for 
built-in types"

- PSL: collections
- PSL: collections.abc

Another source of 'useful background' are PEPs (Python Enhancement 
Proposals). Note that some have been accepted and are part of the 
current-language - so the "proposal" part has become an historic record. 
In comparison: some have been rejected, and others are still 
under-discussion...


- PEP 0: an index
- PEP 3119 -- Introducing Abstract Base Classes
- PEP 3141 -- A Type Hierarchy for Numbers
- and no-doubt many more, which will keep you happily entertained, and 
save the members of your local flock of sheep from thinking that to you 
they are a mere number...



BTW, where do I look to understand the difference between *dir(type(4)) 
*(which does not include *__bases__*) and *type(4).__dir__(type(4)) 
*(which does)? According to Martelli (2017, p. 127), *dir(*x*)* just 
calls /*x*./*__dir__()*; but *type(4).__dir__() *=> ERR for me. Has this 
changed since 3.5, or is Martelli just wrong?


I don't know - and I'm not about to question Alex!


There's nothing else obvious in dir(0) or in dir(type(0)). After some 
looking around, I find that the base classes are not built-in, but need 
to be added with the *numbers* and *collections.abc *modules? That's a 
surprise!


Yes, to me there is much mystery in this (hence "faith", earlier).

Everything is a sub-class of object. When I need to differentiate, eg 
between a list and a dict; I either resort to isinstance() or back to 
the helpful table/taxonomy in collections.abc and hasattr() - thus a 
tuple is a Collection and a Sequence, but not a MutableSequence like a 
list. A set looks like a list until it comes to duplicate values or 
behaving as a Sequence. A dict is a MutableMapping, but as you say 
(below), when considered a Collection will only behave as a list of 
keys. So, we then chase the *View-s...



You suggested I try *pp.__builtins__.__dict__()* . I couldn't figure out 
what you meant by *pp* here (the module name *pprint*? the class 
*pprint.PrettyPrint*? the configured function 
*pprint.PrettyPrinter(width=20,indent=3).pprint*? none worked...). I 
finally figured out that you must have meant something like 
*pp=pprint.PrettyPrinter(width=80).print; pp(__builtins__.__dict__)*. 
Still not sure which attributes could be useful.


With apologies: "pp" is indeed pprint. The code-example should have been 
prefaced with:


from pprint import pprint as pp

This is (?my) sho