Re: Iterators, iterables and special objects

2020-07-23 Thread Peter Slížik
> The view are iterables.  They can be iterated more than once and used in
> other operations.
>
> The transformers should be once-through iterators because they can be
> passed once-through interators.


This is important, thank you for pointing it out.



> Python's design that iter(iterator) is iterator is extremely handy.
>

Yes,  but it has the unfortunate consequence that an iterator is expected
to define

def __iter__(self):return self

which I saw people *not* doing, supposedly because the official
documentation says that it needs to be done, but does not explain why (and
the interpreter does not enforce it, and the code works anyway).

Moreover, some tutorial authors make it even more difficult with using the
terms iterator and iterable interchangeably. A notorious example is this
wiki:
https://wiki.python.org/moin/Iterator

It says:

*Here is an *iterator* that returns a random number of 1's: *

class RandomIterable:def __iter__(self):return self

I remember the time when I started to look into iterators, and frankly,
with this wiki article, it took me ages to understand,why do iterables
return self in their *__iter__* method.

But I think I'm getting off-topic...

Again, thanks guys, @Terry and @dn for your explanations, you've made the
situation clear.
Peter
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: True is True / False is False?

2020-07-23 Thread Peter Slížik
Dear Tim,

in Python 2, None is a keyword and True and False are just identifiers. In
Python 3, all of them are keywords.

There is an interesting article by Guido explaining the reason for their
different implementations.

http://python-history.blogspot.com/2013/11/story-of-none-true-false.html

Just ignore the first few introductory paragraphs... probably jump to the
article starting with *"So, after this long detour about built-ins vs.
keywords, back to None."*

Hope this helps,
Peter

On Wed, Jul 22, 2020 at 3:06 AM Tim Chase 
wrote:

> I know for ints, cpython caches something like -127 to 255 where `is`
> works by happenstance based on the implementation but not the spec
> (so I don't use `is` for comparison there because it's not
> guaranteed by the language spec). On the other hand, I know that None
> is a single object that can (and often *should*) be compared using
> `is`. However I spent some time reading through the language specs and
> didn't encounter anything about booleans returned from
> comparisons-operators, guaranteeing that they always return The One
> True and The One False.
>
>   x = 3 == 3 # some boolean expression evaluating to True/False
>   y = 4 > 0 # another boolean expression
>   if x is y:
> print("cool, same as always")
>   else:
> print("is this ever possible?")
>
> Is there some theoretical world in which that `else` branch could ever
> be hit because the True referenced by x is not the same True
> referenced by y? (assuming non-pathological overriding of dunder
> methods to return true-ish or false-ish values; or at least assuming
> any dunder-overriding is pure standard-library)
>
> In the big picture, this is likely irrelevant and I should just use
> "==" instead, but I got the question stuck in my head and ended up
> bothered that I couldn't disinter an answer from docs.
>
> Thanks,
>
> -tkc
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iterators, iterables and special objects

2020-07-23 Thread Chris Angelico
On Thu, Jul 23, 2020 at 5:55 PM Peter Slížik  wrote:
> > Python's design that iter(iterator) is iterator is extremely handy.
> >
>
> Yes,  but it has the unfortunate consequence that an iterator is expected
> to define
>
> def __iter__(self):return self
>
> which I saw people *not* doing, supposedly because the official
> documentation says that it needs to be done, but does not explain why (and
> the interpreter does not enforce it, and the code works anyway).

Works in what way? You can't use it in a 'for' loop if it doesn't
define __iter__.

> Moreover, some tutorial authors make it even more difficult with using the
> terms iterator and iterable interchangeably. A notorious example is this
> wiki:
> https://wiki.python.org/moin/Iterator
>
> It says:
>
> *Here is an *iterator* that returns a random number of 1's: *
>
> class RandomIterable:def __iter__(self):return self

Yes? It is indeed an iterator, since its iter method returns itself.
It is also iterable, since it has an iter method. The article goes on
to explain this. I don't think they're being used interchangeably
here.

> I remember the time when I started to look into iterators, and frankly,
> with this wiki article, it took me ages to understand,why do iterables
> return self in their *__iter__* method.

It's so you can do things like this:

def show_with_header(stuff):
stuff = iter(stuff)
hdr = next(stuff)
print(hdr)
for line in stuff:
print(line)
if new_page(): print(hdr)

You can pass this any (non-empty) iterable and it'll work. If __iter__
didn't return self, both this function and the for loop inside it
would need to check for an iterator and an iterable, and there'd be
the possibility of a conflict.

Having __iter__ return self is a pretty elegant way to handle it. I
suppose the same thing could be signalled some other way (having it
return None, for instance), but it wouldn't gain you anything.

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


Re: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track)

2020-07-23 Thread Christian Heimes
On 23/07/2020 02.12, Cameron Simpson wrote:
> On 22Jul2020 15:00, Christian Heimes  wrote:
>> Hi MAL,
>>
>> would it be possible to reduce the amount of EuroPython spam on
>> @python.org mailing lists to a sensible level? This mailing list is a
>> general discussion list for the Python programming language. It's not a
>> conference advertisement list.
>>
>> Something between 1 to 3 mails per conference and year (!) sounds
>> sensible to me. [...]
> 
> I, OTOH, am unperturbed.
> 
> Things have been much in flux this year, and a last minute short notice 
> thing like this post needs wide dissemination. Normally a conference 
> needs few posts, but this year everything is different and plans have 
> changed a lot, on the fly.
> 
> I have never attended EuroPython and probably never will (I'm on the 
> other side of the planet) but I'm still interested. Rather than 
> subscribe to every conference thing, getting them here is very 
> convenient.

I have been to a lot of EuroPython conferences. EP 2003 in
Charleroi/Belgium was my first Python conference. I have given several
talks at EP in recent years and have participated in one panel
discussion / AMA about Python core development.

I'm not disputing the fact that a conference can use the generic Python
users list for announcements. It's the fact that EP is literally
spamming the list with threads like "Opening our merchandise shop",
"Find a new job", "Introducing our diamond sponsor", and "Presenting our
conference booklet". That's just spam to advertise for the conference or
a company. Some EP announcements were cross-posted to multiple mailing
lists like psf-commun...@python.org, too.

python.org has a dedicated conference mailing list for conference
related announcements. Additional to general conferen...@python.org
EuroPython has 2 (in words *TWO*) additional mailing lists for
announcements and discussions (europyt...@python.org,
europython-annou...@python.org).

> As with all posters and topics, a truly annoying one can always be
> blocked at your personal discretion with a filter rule, eg to discard
> "europython". I know that advice verges on the spammers' claim that "you
> can always opt out" but for me this stuff isn't spam.

See https://geekfeminism.wikia.org/wiki/Missing_stair

Some people have replied to me in private because they did not dare to
speak out against a prominent member of the Python community in public.
At least one person has followed up with Code Of Conduct working group
because they are annoyed by the spam.

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


Re: Iterators, iterables and special objects

2020-07-23 Thread Chris Angelico
On Thu, Jul 23, 2020 at 5:55 PM Peter Slížik  wrote:
> Moreover, some tutorial authors make it even more difficult with using the
> terms iterator and iterable interchangeably. A notorious example is this
> wiki:
> https://wiki.python.org/moin/Iterator
>
> It says:
>
> *Here is an *iterator* that returns a random number of 1's: *
>
> class RandomIterable:def __iter__(self):return self
>

BTW, that article had been written using the Python 2 syntax, with a
"next" function rather than "__next__". I've now updated it, so the
examples should work if copied and pasted into a current Python
interpreter.

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


Re: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track)

2020-07-23 Thread Chris Angelico
On Thu, Jul 23, 2020 at 6:40 PM Christian Heimes  wrote:
> I'm not disputing the fact that a conference can use the generic Python
> users list for announcements. It's the fact that EP is literally
> spamming the list with threads like "Opening our merchandise shop",
> "Find a new job", "Introducing our diamond sponsor", and "Presenting our
> conference booklet". That's just spam to advertise for the conference or
> a company. Some EP announcements were cross-posted to multiple mailing
> lists like psf-commun...@python.org, too.

Five threads in a month isn't THAT much spam. Yes, four of them
arrived close together, but that's what happens when something is
temporal in nature. We've had roughly the same number of threads
saying "Python v3.x.y has been released" referencing small revisions
to stable releases of Python, and those are equally irrelevant to
people who don't need to update (for instance, 3.9.0b5 is irrelevant
unless you're tracking the betas, and 3.7.8 doesn't make a lot of
difference unless you need the very latest 3.7 and don't get it from a
package manager). Is that a problem? I don't think so. These lists get
a lot of traffic and the normal way to distinguish them is by their
subject lines, and every one of these EuroPython threads has had that
word in the subject.

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


Re: Iterators, iterables and special objects

2020-07-23 Thread Peter Slížik
> Works in what way? You can't use it in a 'for' loop if it doesn't
> define __iter__.
>

class Iterable:
def __iter__(self):
return Iterator(...)

class Iterator:
def __next__(self):
return 

# No __iter__ here.
# I've just forgotten to def it.

With this setup, using for to iterate over Iterable *will* still work,
though you cannot use the trick described below.

> Yes? It is indeed an iterator, since its iter method returns itself. It
is also iterable, since it has an iter method.
Of course, you're right. But you're reading the article through the eyes of
an experienced developer.


> It's so you can do things like this:
>
> def show_with_header(stuff):
> stuff = iter(stuff)
> hdr = next(stuff)
> print(hdr)
> for line in stuff:
> print(line)
> if new_page(): print(hdr)
>

Yes, @Terry had given the same example. Frankly, I didn't know about it
before, I somehow had the misconception that for always got a 'fresh'
iterator...

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


Re: Installing Python 3.8.3 with tkinter

2020-07-23 Thread Christian Gollwitzer

Am 23.07.20 um 06:30 schrieb Klaus Jantzen:

On 7/22/20 11:05 PM, Ned Deily wrote:

On 2020-07-22 06:20, Klaus Jantzen wrote:

Trying to install Python 3.8.3 with tkinter I run configure with the
following options

./configure --enable-optimizations --with-ssl-default-suites=openssl
--with-openssl=/usr/local --enable-loadable-sqlite-extensions
--with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6'
--with-tcltk-includes='-I/opt/ActiveTcl-8.6/include'

Running Python gives the following information

[...]

How do that correctly?

Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6'



Thank you for your suggestion; unfortunately it did not help.



Does the configure process output something when checking for Tcl/Tk? 
Does it say "no"? THen you can analyse the config.log file what happened.


In order to compile Tk extensions, you need X11 development headers. 
Maybe that is one problem.


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


Re: Installing Python 3.8.3 with tkinter

2020-07-23 Thread Ned Deily
On 2020-07-23 00:30, Klaus Jantzen wrote:
> On 7/22/20 11:05 PM, Ned Deily wrote:
>> On 2020-07-22 06:20, Klaus Jantzen wrote:
>>> Trying to install Python 3.8.3 with tkinter I run configure with the
>>> following options
>>>
>>> ./configure --enable-optimizations --with-ssl-default-suites=openssl
>>> --with-openssl=/usr/local --enable-loadable-sqlite-extensions
>>> --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6'
>>> --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include'
>>>
>>> Running Python gives the following information
>> [...]
>>> How do that correctly?
>> Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6'
>>
>>
> Thank you for your suggestion; unfortunately it did not help.

Without knowing exactly how the /opt/ActiveTcl-8.6 directory is laid
out, we can only guess at what the right options should be.  The basic
idea is that there needs to be one or more -I entries that covers the
top-level directory(ies) with Tcl and Tk include files and for the
libraries there needs to be a -L entry for the directory and a -l entry
for the name of the shared library (minus the "lib" prefix), assuming
Tcl and Tk were built with --enable-shared. Usually both libraries are
installed into the same directory, in which case you only need one -L as
above.  If they do not have a common parent, you would need to specify
each separately, like -L/libtclparent -l tcl8.6 -L/libtkparent -ltk8.6.

If that doesn't help, you could display the show the contents of the
include and directories here:

ls -l /opt/ActiveTcl-8.6/include /opt/ActiveTcl-8.6/lib

Also exactly what platform are you building on?  And, btw, Python 3.8.5
is now current.

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


Re: Installing Python 3.8.3 with tkinter

2020-07-23 Thread Anssi Saari
Klaus Jantzen  writes:

> On 7/22/20 11:05 PM, Ned Deily wrote:
>> On 2020-07-22 06:20, Klaus Jantzen wrote:
>>> Trying to install Python 3.8.3 with tkinter I run configure with the
>>> following options
>>>
>>> ./configure --enable-optimizations --with-ssl-default-suites=openssl
>>> --with-openssl=/usr/local --enable-loadable-sqlite-extensions
>>> --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6'
>>> --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include'
>>>
>>> Running Python gives the following information
>> [...]
>>> How do that correctly?
>> Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6'
>>
>>
> Thank you for your suggestion; unfortunately it did not help.

Are you sure the libs you need (presumably libtcl8.6.so and libtk8.6.so)
are both in /opt/ActiveTcl-8.6/lib/tcl8.6? Or where are they actually?
Presumably not in /opt/ActiveTcl-8.6/lib since that didn't work.

Could be something else too. You may need to dig into setup.py and the
configure script.

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


Re: Fwd: [BUG] missing ')' causes syntax error on next line

2020-07-23 Thread Chris Angelico
On Fri, Jul 24, 2020 at 4:00 AM Dennis Lee Bieber  wrote:
>
> On Thu, 23 Jul 2020 09:51:42 +1000, Chris Angelico 
> declaimed the following:
>
> >On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list
> > wrote:
> >> However, questions remain:-
> >>
> >> Robot: any machine or mechanical device that operates automatically with
> >> humanlike skill
> >>
> >
> >What about a human that operates mechanically with merely robot-like
> >skill? I'm pretty sure I've spoken to them on the phone many times.
>
> Would that be... a computer?
>
>
>
> Using the original meaning of "one who computes"
>

I suspect that even that is too generous for some of them. They merely
follow instructions like good little automatons, until the caller
gives up...

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


Re: Spam, bacon, sausage and Spam

2020-07-23 Thread dn via Python-list

On 23/07/2020 20:39, Christian Heimes wrote:

On 23/07/2020 02.12, Cameron Simpson wrote:

On 22Jul2020 15:00, Christian Heimes  wrote:

...


would it be possible to reduce the amount of EuroPython spam on
@python.org mailing lists to a sensible level? This mailing list is a
general discussion list for the Python programming language. It's not a
conference advertisement list.


+1 (see later)



I, OTOH, am unperturbed.


+1


...


I have never attended EuroPython and probably never will (I'm on the
other side of the planet) but I'm still interested. Rather than
subscribe to every conference thing, getting them here is very
convenient.


+1
(and make a note to follow-up afterwards, because many PyCons post 
videos of the presentations - not as good as being-there, but less 
expensive than an RtW air-ticket!)


...

I'm not disputing the fact that a conference can use the generic Python
users list for announcements. It's the fact that EP is literally
spamming the list with threads like "Opening our merchandise shop",
"Find a new job", "Introducing our diamond sponsor", and "Presenting our
conference booklet". That's just spam to advertise for the conference or
a company. Some EP announcements were cross-posted to multiple mailing
lists like psf-commun...@python.org, too.


Agreed:
There is a difference between announcing conference details, and selling 
'stuff' to attendees.

(I don't know: but would a non-attendee buy the t-shirt?)



python.org has a dedicated conference mailing list for conference
related announcements. Additional to general conferen...@python.org
EuroPython has 2 (in words *TWO*) additional mailing lists for
announcements and discussions (europyt...@python.org,
europython-annou...@python.org).

...

Agreed
However, "This mailing list is a general discussion list for the Python 
programming language" and per earlier reply, advice of a conference 
holds general interest (as well) - and is an encouragement to other 
PyCons (organisers) around the world.


Were we to ban EuroPython, would we also have to take a stand against 
beginners posting basic questions (given that there is a specific Tutor 
list)?


"General" means nothing-specific (as anyone in the military can tell you)!

In truth, I did delete many of these msgs after a cursory scan of their 
content (cf reading).




Some people have replied to me in private because they did not dare to
speak out against a prominent member of the Python community in public.
At least one person has followed up with Code Of Conduct working group
because they are annoyed by the spam.


Like the decision to use vim or emacs, this topic can generate a lot of 
heat and emotion. Is there room for both? (and for 'modern IDEs')


The "dare not speak out" is sad - both for the individuals and/or the 
organisation. Wither "inclusion" and "tolerance"?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


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

2020-07-23 Thread Chris Green
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?  

Alternatively (but much harder work) what is the Python 3 equivalent
of the the Python 2 pygtk and gtk modules.


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


Re: How to limit *length* of PrettyPrinter

2020-07-23 Thread dn via Python-list

Redirected from Digest (see below)


On 23/07/2020 11:59, Stavros Macrakis wrote:
> Mousedancer, thanks!

Yes, I even look like a (younger) Kevin Costner!
(you believe me - right!?)


> As a finger exercise, I thought I'd try implementing print-level and 
print-length as an object-to-object transformer (rather than a pretty 
printer). I know that has a bunch of limitations, but I thought I might 
learn something by trying.

>
> Here's a simple function that will copy nested lists while limiting 
their depth and length. When it encounters a non-iterable object, it 
treats it as atomic:

>
> scalartypes = list(map(type,(1,1.0,1j,True,'x',b'x',None)))
>
> def limit(obj,length=-2,depth=-2):
>  if type(obj) in scalartypes:
>  return obj
>  if depth==0:
>  return 'XXX'
>  lencnt = length
>  try:
>  new = type(obj).__new__(type(obj)) # empty object of 
same type

>  for i in obj:
>  lencnt = lencnt - 1
>  if lencnt == -1:
>  new.append('...')  # too long
>  break
>  else:
>  new.append(limit(i,length,depth-1))
>  return new
>  except:# which exceptions?
>  return obj # not iterable/appendable
>
> limit( [1,2,[31,[321,[3221, 3222],323,324],33],4,5,6], 3,3)
>
> => [1, 2, [31, [321, 'XXX', 323, '...'], 33], '...']
>
>
>
> This works fine for lists, but not for tuples (because they're 
immutable, so no *append*) or dictionaries (must use *for/in* 
*obj.items*, and there's no *append*). There must be some way to handle 
this generically so I don't have to special-case tuples (which are 
immutable, so don't have *append*) and dictionaries (where you have to 
iterate over *obj.items()*... and there's no *append*), but I'm stuck. 
Should I accumulate results in a list and then make the list into a 
tuple or dictionary or whatever at the end? But how do I do that?

>
> It's not clear how I could handle /arbitrary/ objects... but let's 
start with the standard ones.


This looks like fun!
BTW why are we doing it: is it some sort of 'homework assignment' or are 
you a dev 'scratching an itch'?



May I suggest a review of the first few pages/chapters in the PSL docs 
(Python Standard Library): Built-in Functions, -Constants, -Types, and 
-Exceptions. Also, try typing into the REPL:


pp.__builtins__.__dict__()

(you will recognise the dict keys from the docs). These may give you a 
more authoritative basis for "scalartypes", etc.


If you're not already familiar with isinstance() and type() then these 
(also) most definitely useful tools, and thus worth a read...



With bottom-up prototyping it is wise to start with the 'standard' 
cases! (and to 'extend' one-bite at a time)



Rather than handling objects (today's expansion on the previous), might 
I you refer back to the objective, which (I assume) requires the output 
of a 'screen-ready' string. Accordingly, as the data-structure/network 
is parsed/walked, each recognised-component could be recorded as a 
string, rather than kept/maintained?reproduced in its native form.


Thus:
- find a scalar, stringify it
- find a list, the string is "["
- find a list, the string is "{"
- find a tuple, the string is "("
etc

The result then, is a series of strings.

a) These could be accumulated, ready for output as a single string. This 
would make it easy to have a further control which limits the number of 
output characters.


b) If the accumulator is a list, then

accumulator.append( stringified_element )

works happily. Plus, the return statement can use a str.join() to 
produce a single accumulator-list as a string.
(trouble is, if the values should be comma-separated, you don't want to 
separate a bracket (eg as a list's open/close) from the list-contents 
with a comma!) So, maybe that should be done at each layer of nesting?


Can you spell FSM?
(Finite State Machine)


Next set of thoughts: I'm wondering if you mightn't glean a few ideas 
from reviewing the pprint source-code?
(on my (Fedora-Linux) machine it is stored as 
/usr/lib64/python3.7/pprint.py)


Indeed, with imperial ambitions of 'embrace and extend', might you be 
able to sub-class the pprint class and bend it to your will?



Lastly, (and contrasting with your next comment) I became a little 
intrigued, so yesterday, whilst waiting for an on-line meeting's (rather 
rude, IMHO) aside to finish (and thus move-on to topics which involved 
me!), I had a little 'play' with the idea of a post-processor (per 
previous msg).


What I built gives the impression that "quick and dirty" is a 
thoroughly-considered and well-designed methodology, but the prototype 
successfully shortens pprint-output to a requisite number of elements. Thus:


source_data = [1,2,[31,[321,[3221, 3222],323,324],33],4,5,6]
lim

Re: Fwd: [BUG] missing ')' causes syntax error on next line

2020-07-23 Thread Jeff Linahan
Interesting PEG thing.  C++ compilers are getting better at suggesting
fixes for minor syntax errors (in 2011 on MSVC I remember seeing pages of
errors for forgetting a semicolon after a struct.) but python seems to be
lagging behind in this regard.. will check out superhelp, maybe it'll help
me patiently wait for the day where the python compiler does machine
learning on my specific style of mistakes to suggest fixes lol.

On Thu, Jul 23, 2020, 2:09 PM Chris Angelico  wrote:

> On Fri, Jul 24, 2020 at 4:00 AM Dennis Lee Bieber 
> wrote:
> >
> > On Thu, 23 Jul 2020 09:51:42 +1000, Chris Angelico 
> > declaimed the following:
> >
> > >On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list
> > > wrote:
> > >> However, questions remain:-
> > >>
> > >> Robot: any machine or mechanical device that operates automatically
> with
> > >> humanlike skill
> > >>
> > >
> > >What about a human that operates mechanically with merely robot-like
> > >skill? I'm pretty sure I've spoken to them on the phone many times.
> >
> > Would that be... a computer?
> >
> >
> >
> > Using the original meaning of "one who computes"
> >
>
> I suspect that even that is too generous for some of them. They merely
> follow instructions like good little automatons, until the caller
> gives up...
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-l
> 
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track)

2020-07-23 Thread Cameron Simpson
On 23Jul2020 10:39, Christian Heimes  wrote:
>On 23/07/2020 02.12, Cameron Simpson wrote:
>> I have never attended EuroPython and probably never will (I'm on the
>> other side of the planet) but I'm still interested. Rather than
>> subscribe to every conference thing, getting them here is very
>> convenient.
>
>I have been to a lot of EuroPython conferences. [...]
>I'm not disputing the fact that a conference can use the generic Python
>users list for announcements. It's the fact that EP is literally
>spamming the list with threads like "Opening our merchandise shop",
>"Find a new job", "Introducing our diamond sponsor", and "Presenting our
>conference booklet". That's just spam to advertise for the conference or
>a company. Some EP announcements were cross-posted to multiple mailing
>lists like psf-commun...@python.org, too.

Hmm, yes. For these posts, colour me convinced. I'd be happy to see 
these dialed back - they arguably belong on a europython announcement 
list.  Things like "conference rescheduled", "attendance arrangements 
changes due to the virus" etc seem worthy of the main list to me, by 
contrast.

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


Re: Iterators, iterables and special objects

2020-07-23 Thread Terry Reedy

On 7/23/2020 5:14 AM, Peter Slížik wrote:

Works in what way? You can't use it in a 'for' loop if it doesn't
define __iter__.



class Iterable:
 def __iter__(self):
 return Iterator(...)

class Iterator:
 def __next__(self):
 return 

 # No __iter__ here.
 # I've just forgotten to def it.


Which means that an Iterator is not an iterator.


With this setup, using for to iterate over Iterable *will* still work,
though you cannot use the trick described below.


Yes? It is indeed an iterator, since its iter method returns itself. It

is also iterable, since it has an iter method.
Of course, you're right. But you're reading the article through the eyes of
an experienced developer.



It's so you can do things like this:

def show_with_header(stuff):
 stuff = iter(stuff)
 hdr = next(stuff)
 print(hdr)
 for line in stuff:
 print(line)
 if new_page(): print(hdr)



Yes, @Terry had given the same example. Frankly, I didn't know about it
before, I somehow had the misconception that for always got a 'fresh'
iterator...


The way 'for' gets its iterator is to call iter(iterable).  If the 
iterable is an iterator, iter(iterator) returns iterator.  Open files 
are *iterators*.


>>> file.__iter__() is file
True

This means that one can do things like

file  = open(...)
for line in file:  # Section 1 of file.
if separator(line): break
process1(line)
process_sep(line)  # Special line that broke iteration.
for line in file:  # Section 2 of file.
process2(line)

One alternative is something like

file = open(...)
section = 1
for line in file:
if section == 1:
if separator(line):
process_sep(line)
section = 2
continue
process1(line)
continue
else:
process2(line)

Another is to use while loops and explicit next(line) calls.  The ':=' 
assignment operator makes this a bit easier.  I used to commonly process 
files with multiple sections and different 'key' lines marking them.


--
Terry Jan Reedy


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


Issues Download the Latest Version of Python Programming Language

2020-07-23 Thread Ejiofor Chidinma Peace
Dear Sir/Madam,
I trust this email finds you well.

I have been having issues downloading the latest version of Python
programming Language on my PC (windows 10 operating system). Kindly assist
in resolving this issue at your earliest convenience.

Looking forward to hearing from you soon.

Yours sincerely,
Ejiofor, Chidinma Peace.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2020-07-23 Thread Akkana Peck
Chris Green writes:
> I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
> 20.04.  [ ... ]
> The error I am getting is:-
[ ... ]
> ImportError: No module named gtk
> 
> So what do I need to install on my Ubuntu 20.04 system to provide the
> gtk module?  

Ubuntu doesn't provide python-gtk any more at all. Which makes a
number of programs rather difficult now ...

> Alternatively (but much harder work) what is the Python 3 equivalent
> of the the Python 2 pygtk and gtk modules.

... because there is no close equivalent. In Python 3, GTK is
accessed via something called GObject Introspection (module "gi")
which requires significant changes to code beyond the usual 2to3
Python migration.

You might be able to get the program working using pygtkcompat.
Try inserting these lines near the beginning of the program:

from gi import pygtkcompat
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

If that doesn't work, you might be able to get the old Python 2/GTK 2
packages working by installing these two files with dpkg -i.
No warranty of safety or efficacy implied.

http://mirrors.kernel.org/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-6_amd64.deb
http://mirrors.kernel.org/ubuntu/pool/universe/g/gimp/gimp-python_2.10.8-2_amd64.deb

Good luck! It was a nasty shock discovering that Ubuntu had removed
python-gtk, especially since they kept lots of other python2 packages
(I could have understood it if they'd removed python2 entirely).
I don't know what the reasoning was for removing python-gtk while
keeping python2.

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


Re: Issues Download the Latest Version of Python Programming Language

2020-07-23 Thread Mats Wichmann
On 7/24/20 12:05 AM, Ejiofor Chidinma Peace wrote:
> Dear Sir/Madam,
> I trust this email finds you well.
> 
> I have been having issues downloading the latest version of Python
> programming Language on my PC (windows 10 operating system). Kindly assist
> in resolving this issue at your earliest convenience.
> 
> Looking forward to hearing from you soon.

Sorry to not be helpful, but you are going to have to be more descriptive.

"Having issues downloading" tells us nothing that we can use to help you
with.




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