Re: Control stript which is runing in background.

2021-01-01 Thread jak

Il 01/01/2021 06:23, Alan Bawden ha scritto:

jak  writes:

Running the command:

$ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe

the three texts do not mix

The three texts do not mix as long at the contents of bible.txt is short
enough (and provided `cat' only calls `write' once).  In the POSIX
specification, the manual page for the `write' system call describes
writing to a pipe or FIFO as follows:

   Write requests of {PIPE_BUF} bytes or less shall not be interleaved
   with data from other processes doing writes on the same pipe.  Writes
   of greater than {PIPE_BUF} bytes may have data interleaved, on
   arbitrary boundaries, with writes by other processes, whether or not
   the O_NONBLOCK flag of the file status flags is set.


Ok. And...
 ...Running the command:

 $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat 
bible.txt > cmdpipe


 the three texts do not mix
--
https://mail.python.org/mailman/listinfo/python-list


Re: Funny error message

2021-01-01 Thread Peter Otten

On 31/12/2020 23:46, Bob van der Poel wrote:


When I run python from the command line and generate an error I get the
following:

Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

z

/home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89:
RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't
match a supported version!
   warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
   File "", line 1, in 
NameError: name 'z' is not defined

I understand "z in not defined" ... but what's with the warnings?


It looks like Python tries to import requests as a side effect of 
printing the traceback.

Start the interpreter in verbose mode

$ python -v

and trigger the name error again to see which module triggers that import.

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


Re: Control stript which is runing in background.

2021-01-01 Thread jak

Il 01/01/2021 04:14, [email protected] ha scritto:

On 2021-01-01 at 03:43:43 +0100,
Regarding "Re: Control stript which is runing in background.,"
jak  wrote:


Il 01/01/2021 01:43, Cameron Simpson ha scritto:

On 01Jan2021 01:21, jak  wrote:

Il 01/01/2021 00:58, [email protected] ha scritto:

Most of the time, I have several shells open, often with their own
background jobs running.  Limiting write permission on the pipe to "me"
wouldn't prevent concurrent access.


This is true but there would be no difference if this happened through
a socket.


Accessing a socket makes a distinct separate data connection - other
openers do not conflict with it. That's the critical difference between
a socket and a pipe in terms of functionality, and why sockets have a
connect/accept step.

Cheers,
Cameron Simpson 



Maybe the fact that I'm not English and I don't know the language well
doesn't allow me to express myself clearly. Try it one more time:
The OP would like to give some command to a script that is running. How?
With a script that sends commands to it. One of the ways, as mentioned,
is by using a mini socket server. Given the needs of the OP and the fact
that sockets are a limited resource in a system, I took the liberty of
proposing a simple alternative: using a named pipe, also because, IMO,
sockets, in this case, are an overkill. with a few lines of code in a
thread in the running script they can allow it to receive commands:
#-
import os, errno

fnpipe = 'cmdpipe'

try:
 os.mkfifo(fnpipe)
except OSError as e:
 if e.errno != errno.EEXIST:
 raise
while True:
 with open(fnpipe, 'rt', 1) as fifo:
 for line in fifo:
 print(line, ends='')
#-

Running the command:

$ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt >
cmdpipe

the three texts do not mix. IMO, the OP should be enough. after that, I
know that a pipe is more like a queue than a soket and in this case a
socket, IMO, is wasted.


Only the OP knows for sure.  :-)   Does the server send data back to the
client that made the request?  Are the requests (and the responses, if
any) small enough to be sent/received atomically?  *If* the answers are
no and yes, then you're right, a named pipe would be good enough.  If
not, then a socket *might* be better.  Until the OP clarifies, we can't
tell.


greetings, hoping to have been clearer than before.


I think you were clear enough before, but you may not have considered
things the OP did not specify.  One of the hardest parts of software
development is understanding and specifying the actual problem to be
solved.  I've never done that in a second language (I'm nowhere near
fluent in anything other than English); I can only imagine the extra
layers of complexity.



This is the OP's initial request:

Hi. 
I would like to make something like this:

A python script would run headlessly in the background.
I would like to control the script from the command line using other python 
scripts or from the python shell.
From time to time I would ask the main script to create a popup window with an 
image or a plot.
What would be the proper way to approach it. How to make communication between 
two scripts?
Thank you.
Petro.


I have suggested an alternative way for his necessity.
It will be up to him to decide which one he should adopt. That way he
has a choice, at least.
I don't know where you work. I know, however, that in these zones, if
you do more than necessary wasting their time, they will kick you away.
--
https://mail.python.org/mailman/listinfo/python-list


Plotting in python for Monte Carlo Method

2021-01-01 Thread Meghna Karkera
Dear Respected Sir

May I request you to help me plot the number of histories versus standard
deviation along with mean for integral of 2x dx from 0 to 5 abtained using
the Monte Carlo python program.

I've calculated the integral of 2x dx from 0 to 5 using the Monte Carlo
method described in the following link. https://youtu.be/WAf0rqwAvgg

Thanks

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


Re: help

2021-01-01 Thread Sibylle Koczian

Am 31.12.2020 um 18:06 schrieb Mats Wichmann:
What you're doing is going to give you probably unexpected results 
anyway. Here's why:  (when it's set up properly) when clicking from 
explorer Windows will create a window to run the Python interpreter in, 
and when your script finishes, Python quits. Windows will take that as a 
clue that the window is no longer needed, and it will be discarded. This 
will usually have the visual effect of a window flashing onto the screen 
and then vanishing, as if things were broken, but they're not.  Only a 
Python script that is written to manage a display window, is going to 
stay around. An old is to add an input() call at the end of your script, 
so it waits for you to hit the enter key before finishing, and that will 
leave the window open)


But that doesn't help, if the script raises an exception. In that case 
the input() call won't be reached and the window will close anyway 
before you could see anything. And in a script with errors that's even 
worse. Same effect with the "run" window.



Either run your scripts from a command shell...

It's really bad that Windows doesn't put links to the command shell on 
the desktop and into the task bar on installation.


Or use an editor or IDE that has an integrated way to run your programs 
there in the editor's environment - here the IDE manages the windows so 
you don't get the opens-then-closes effect.


Hope this helps.




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


Re: Why do I have both /usr/lib/python3 and /usr/lib/python3.8?

2021-01-01 Thread john steve
On Wednesday, December 30, 2020 at 9:03:28 AM UTC-8, Chris Green wrote:
> Anssi Saari  wrote: 
> > Chris Green  writes: 
> > 
> > > Why are there both /usr/lib/python3 and /usr/lib/python3.8 on my 
> > > x[ubuntu] system? 
> > 
> > While it's more of an Ubuntu (or Debian) question better asked in some 
> > relevant Linux forum, in the end it's because some package managers 
> > decided to do that. You can use commands like these to see which 
> > packages put stuff in which directory: 
> > 
> > dpkg -S /usr/lib/python3.8 
> > dpkg -S /usr/lib/python3 
> > 
> > On my Debian system the corresponding output looks like this: 
> > 
> > $ dpkg -S /usr/lib/python3.7 
> > python3.7, libpython3.7-minimal:amd64, python3-tk:amd64, 
> > libpython3.7-dev:amd64, libpython3.7-stdlib:amd64, libpython3.7:amd64, 
> > python3-distutils, python3-lib2to3: /usr/lib/python3.7 
> > 
> > $ dpkg -S /usr/lib/python3 
> > python3-scipy, python3-opengl, python3-statsmodels, iotop, 
> > python3-reportlab-accel:amd64, python3-magic, python3-pkg-resources, 
> > python3-kiwisolver, python3.7, python3-pandas-lib, python3-kerberos, 
> > python3-lz4, python3-renderpm:amd64, python3-numexpr, 
> > python3-cffi-backend, python3-crypto, python3-tables, python3-rencode, 
> > python3-gi, python3-dbus, devscripts, python3-gpg, python3-pyasn1, 
> > python3-py, python3-eyed3, pdfarranger, python3-pip, python3-virtualenv, 
> > xpra, python3-pandas, python3-pil:amd64, python3-requests, 
> > python3-urllib3, python3-psutil, python3-paramiko, python3-netifaces, 
> > python3-patsy, python3-gssapi, python3-sklearn, python3-cycler, 
> > python3-sip, python3-cairo:amd64, python3-six, python3-chardet, 
> > python3-nose, python3-debian, python3-wheel, python3-attr, 
> > python3-soupsieve, python3-bcrypt, python3-bs4, python3-sklearn-lib, 
> > python3-scour, python3-setuptools, python3-entrypoints, 
> > python3-gi-cairo, python3-cups, python3-keyrings.alt, python3-pluggy, 
> > python3-tz, python3-ifaddr, python3-joblib, python3-cvxopt, 
> > python3-secretstorage, python3-reportlab, python3-more-itertools, 
> > python3-keyring, python3-asn1crypto, python3-html5lib, python3-dns, 
> > python3-decorator, python3-dateutil, meson, python3-pexpect, 
> > python3-idna, python3-seaborn, lsb-release, python3-numpy, 
> > python3-brotli, python3-tables-lib, python3-lxml:amd64, python3-pytest, 
> > python3-simplejson, python3-nacl, python3-zeroconf, python3-xdg, 
> > python3-libvoikko, python3-gst-1.0, python3-pypdf2, python3-evdev, 
> > python3-matplotlib, python3-statsmodels-lib, python3-cryptography, 
> > python3-certifi, python3-atomicwrites, python3-pyparsing, 
> > python3-ptyprocess, python3-webencodings, piper, python3-uno, 
> > python3-apt, python3-setproctitle:amd64, hplip: /usr/lib/python3 
> > 
> > So I'd say as a rule stuff relevant to the specific version of python 
> > goes in the specific version directory (i.e. /usr/lib/python3.8 in your 
> > case) and python software packages in general go in /usr/lib/python3. 
> >
> Yes, there are some oddities though, for example python3.7 seems to be 
> installed in both locations (python3.8 in my case). 
> 
> -- 
> Chris Green 
> ·
some tools require any of them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-01 Thread 2QdxY4RzWzUUiLuE
On 2021-01-01 at 11:11:47 +0100,
jak  wrote:

> Il 01/01/2021 04:14, [email protected] ha scritto:
> > On 2021-01-01 at 03:43:43 +0100,
> > jak  wrote:
> > 
> > I think you were clear enough before, but you may not have
> > considered things the OP did not specify.  One of the hardest parts
> > of software development is understanding and specifying the actual
> > problem to be solved.  I've never done that in a second language
> > (I'm nowhere near fluent in anything other than English); I can only
> > imagine the extra layers of complexity.
> 
> This is the OP's initial request:
> 
> > Hi. I would like to make something like this:
> > A python script would run headlessly in the background.
> > I would like to control the script from the command line using other python 
> > scripts or from the python shell.
> > From time to time I would ask the main script to create a popup window with 
> > an image or a plot.
> > What would be the proper way to approach it. How to make communication 
> > between two scripts?
> > Thank you.
> > Petro.
> 
> I have suggested an alternative way for his necessity.
> It will be up to him to decide which one he should adopt. That way he
> has a choice, at least.
> I don't know where you work. I know, however, that in these zones, if
> you do more than necessary wasting their time, they will kick you away.

So what is necessary?  Does "control the script" include reporting
success or failure of a request?  The OP also said "communication
between two scripts," which to me means two way traffic.  Only the OP
knows for sure, and at least one of us might get it wrong if we don't
ask, or at least acknowledge that we don't know.

If I start with a named pipe because it's good enough for Phase Zero, or
Version 0.0.1, or Release Experimental Alpha, then I'm going to end up
ripping that out or reinventing something that already existed on top of
that named pipe.

Suppose I look ahead just a little, and use a socket in the first place.
Yes, you could argue that it's more than what was necessary and kick me
away.  Will you kick me again when you can build on it (I can't; I'm
gone) instead of having to rebuild what already worked?

I'm retired now, but I at one employer, I worked on products with (a)
lifetimes measured in decades, (b) extremely expensive (money, time,
convenience, etc.) upgrade/maintenance cycles, and therefore (c) strict
interoperability requirements.¹  A little bit of foresight and extra
analysis up front went a long way towards saving a lot of headaches and
development resources (and customers!)  in the long term.
Communications protocols in particular had to be well thought out, and
often more complex than was immediately necessary, because backwards and
forwards compatibility were not negotiable.

Again, I'm not (and no one else is, either) saying that your solution is
wrong or won't work.  Your solution may even be the be the best solution
to the OP's problem.  All I'm saying is that we can't know until the OP
tells us more.  Yes, the OP has a choice to make.  Maybe we have helped,
not by making that choice, but by giving it to the OP with enough
supporting information to make it.

¹ Think about a system containing dozens of individually field
upgradeable components.  It had to work when a customer upgraded one
component at a time (over the course of weeks or months), or plugged in
an old component while they were waiting for a broken one to be
repaired, or added a brand new component to a system that hadn't been
changed or upgraded for years.  There was no such thing as telling the
customer to wait, or to make them take down the entire system to upgrade
everything at once.  *That* was what was necessary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help

2021-01-01 Thread Eryk Sun
On 1/1/21, Sibylle Koczian  wrote:
>
> But that doesn't help, if the script raises an exception. In that case
> the input() call won't be reached and the window will close anyway
> before you could see anything. And in a script with errors that's even
> worse. Same effect with the "run" window.

The simplest, best option is running the script from an existing shell
that owns the console session.  That said, here are a couple
alternatives to calling input() in a `finally` block.

If you have .py files associated with the py launcher, for testing you
can use a shebang such as `#!/usr/bin/python3 -i`. The "-i" option
enters interactive mode after executing the script, even if there's an
unhandled Python exception.

Entering interactive mode won't work if the process crashes at a low
level. To handle that, you can instead spawn a child process in the
console session that waits forever. A good candidate is "waitfor.exe",
which opens a mailslot and waits for it to be signaled. For example:

import subprocess
subprocess.Popen('waitfor.exe ever')

This process will still be attached to the console session after
Python exits. You can kill it by closing the console window, or by
running `waitfor.exe /si ever` to signal it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I have both /usr/lib/python3 and /usr/lib/python3.8?

2021-01-01 Thread Barry Scott



> On 29 Dec 2020, at 15:10, Chris Green  wrote:
> 
> Why are there both /usr/lib/python3 and /usr/lib/python3.8 on my
> x[ubuntu] system?
> 
> /usr/lib/python3 has just the dist-packages directory in it,
> /usr/lib/python3.8 has lots of individual python files in it as well
> as quite a number of directories.  
> 
> There's also a /usr/lib/python3.9 directory even though Ubuntu hasn't
> moved to python3.9 yet.
> 

It is common on linux systems for python3 to be a sym link to the systems 
preferred
version of python3 to use.

It is also common to be able to install multiple versions of python on a system.
Both older and newer versions.

Usually I use '#!/usr/bin/python3' in my scripts unless I know that a script
has version dependences.

By using python3 you do not have to edit your scripts shebang lines when
your distro updates to a newer version of python.

If you are testing your code against multiple version of python you need the
version specific names like python3.8, python3.10 etc.

Barry

FYI this is what I have installed (lspy is a personal script):

$ lspy
/bin/python: 3.9.1 final 0
/bin/python2: 2.7.18 final 0
/bin/python2.7: 2.7.18 final 0
/bin/python3: 3.9.1 final 0
/bin/python3.10: 3.10.0 alpha 3
/bin/python3.4: 3.4.10 final 0
/bin/python3.5: 3.5.10 final 0
/bin/python3.6: 3.6.12 final 0
/bin/python3.9: 3.9.1 final 0
/bin/python34: 3.4.10 final 0
/bin/python35: 3.5.10 final 0
/usr/bin/python: 3.9.1 final 0
/usr/bin/python2: 2.7.18 final 0
/usr/bin/python2.7: 2.7.18 final 0
/usr/bin/python3: 3.9.1 final 0
/usr/bin/python3.10: 3.10.0 alpha 3
/usr/bin/python3.4: 3.4.10 final 0
/usr/bin/python3.5: 3.5.10 final 0
/usr/bin/python3.6: 3.6.12 final 0
/usr/bin/python3.9: 3.9.1 final 0
/usr/bin/python34: 3.4.10 final 0
/usr/bin/python35: 3.5.10 final 0


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


Does windows edit .py file shebangs?

2021-01-01 Thread Barry Scott
I found python scripts have had their shebang lines edited behind my back.

The shebang line I'm seeing is:

#!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE

Is this Microsoft being "helpful"?
Does anyone know what I will have done to best with this "help"?

What do I need to do to prevent this happening?

Barry

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


Re: Funny error message

2021-01-01 Thread Bob van der Poel
It appears that a couple of things are happening ... and not being a python
install expert by a long shot, none of it makes sense to me.

But, let me first state that I've never screwed around with the python
installation. I let the Ubuntu packager take care of that.

- running "python -v" I get A LOT of data about various modules being
loaded, etc. I see that most of the modules are loaded from the system dir
/usr/lib/python3.8 but some from .local/lib/python3.8. I have never created
the .local tree so I, again, assume that the installer is doing this. BTW,
sys.path is:
['', '/usr/lib/python38.zip', '/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload', '/home/bob/.local

   /lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages',
'/usr/lib/python3/dist-packages']

- running python -v gives too much info. I really can't see what is causing
the unneeded text, but assume it is "requests". Note that this is the
module from .local. Experimenting, I deleted .local/.../requests and it is
now using /usr/.../requests. I've undeleted the .local version.

- creating a one line script with only a bad command in it and running
"python -v script.py >err_file" does not give the lengthy printout. The
same error message is displayed on the terminal.

I really have no idea ... and don't care that much, except it is annoying
to have these same lines repeated over and over again after every error.
Could this be a bug in requests?


On Fri, Jan 1, 2021 at 3:03 AM Peter Otten <[email protected]> wrote:

> On 31/12/2020 23:46, Bob van der Poel wrote:
>
> > When I run python from the command line and generate an error I get the
> > following:
> >
> > Python 3.8.5 (default, Jul 28 2020, 12:59:40)
> > [GCC 9.3.0] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
>  z
> > /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89:
> > RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't
> > match a supported version!
> >warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported
> "
> > Traceback (most recent call last):
> >File "", line 1, in 
> > NameError: name 'z' is not defined
> >
> > I understand "z in not defined" ... but what's with the warnings?
>
> It looks like Python tries to import requests as a side effect of
> printing the traceback.
> Start the interpreter in verbose mode
>
> $ python -v
>
> and trigger the name error again to see which module triggers that import.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I have both /usr/lib/python3 and /usr/lib/python3.8?

2021-01-01 Thread Chris Angelico
On Sat, Jan 2, 2021 at 3:36 AM Barry Scott  wrote:
>
> FYI this is what I have installed (lspy is a personal script):
>
> $ lspy
> /bin/python: 3.9.1 final 0
> /bin/python2: 2.7.18 final 0
> /bin/python2.7: 2.7.18 final 0
> /bin/python3: 3.9.1 final 0
> /bin/python3.10: 3.10.0 alpha 3
> /bin/python3.4: 3.4.10 final 0
> /bin/python3.5: 3.5.10 final 0
> /bin/python3.6: 3.6.12 final 0
> /bin/python3.9: 3.9.1 final 0
> /bin/python34: 3.4.10 final 0
> /bin/python35: 3.5.10 final 0
> /usr/bin/python: 3.9.1 final 0
> /usr/bin/python2: 2.7.18 final 0
> /usr/bin/python2.7: 2.7.18 final 0
> /usr/bin/python3: 3.9.1 final 0
> /usr/bin/python3.10: 3.10.0 alpha 3
> /usr/bin/python3.4: 3.4.10 final 0
> /usr/bin/python3.5: 3.5.10 final 0
> /usr/bin/python3.6: 3.6.12 final 0
> /usr/bin/python3.9: 3.9.1 final 0
> /usr/bin/python34: 3.4.10 final 0
> /usr/bin/python35: 3.5.10 final 0
>

Pretty similar to mine, except that (a) most of the Pythons are in
/usr/local/bin rather than /bin or /usr/bin, and (b) with just a
couple of exceptions, they're all alphas and betas (eg 3.7.0a4+) built
from git. I keep a single 2.7 around (provided by Debian Stable), and
a couple of different 3.x versions are Debian-provided, with all the
rest (from 3.4 to 3.10) hanging around from having been built.

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


Re: Funny error message

2021-01-01 Thread Bob van der Poel
On Thu, Dec 31, 2020 at 9:25 PM DL Neil via Python-list <
[email protected]> wrote:

> On 1/1/21 11:46 AM, Bob van der Poel wrote:
> > When I run python from the command line and generate an error I get the
> > following:
> >
> > Python 3.8.5 (default, Jul 28 2020, 12:59:40)
> > [GCC 9.3.0] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
>  z
> > /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89:
> > RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't
> > match a supported version!
> >   warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > NameError: name 'z' is not defined
> >
> > I understand "z in not defined" ... but what's with the warnings?
>
>
> The implication is that there is a version-mismatch between Python 3.8
> and whichever urllib3 and chardet libraries currently installed.
>
> Recommend updating the system, container, or venv: either Python, pip3
> of the two and/or requests or html-parser [as appropriate to the
> installed libraries - see below], or both/all.
>
>
> System here runs as-expected:
>
> dn $ ... python
> Python 3.9.1 (default, Dec  8 2020, 00:00:00)
> [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> z
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'z' is not defined
> >>> import chardet
> >>> import urllib3
> >>> exit()
> dn $ ... pip show chardet urllib3
> Name: chardet
> Version: 3.0.4
> Summary: Universal encoding detector for Python 2 and 3
> Home-page: https://github.com/chardet/chardet
> Author: Mark Pilgrim
> Author-email: [email protected]
> License: LGPL
> Location: /usr/lib/python3.9/site-packages
> Requires:
> Required-by: html5-parser, requests
> ---
> Name: urllib3
> Version: 1.25.8
> Summary: HTTP library with thread-safe connection pooling, file post,
> and more.
> Home-page: https://urllib3.readthedocs.io/
> Author: Andrey Petrov
> Author-email: [email protected]
> License: MIT
> Location: /usr/lib/python3.9/site-packages
> Requires:
> Required-by: requests
>
>
Found it!

I had the proper urllib3 installed. But, in my .local/lib/ a previous
version was installed. Removing .local/lib/python3.8 has resolved the
problem.

Anyone hazard a guess as to why I had a .local tree (nope, I did not create
it ... I don't think!).


-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I have both /usr/lib/python3 and /usr/lib/python3.8?

2021-01-01 Thread Barry Scott



> On 1 Jan 2021, at 16:42, Chris Angelico  wrote:
> 
> On Sat, Jan 2, 2021 at 3:36 AM Barry Scott  > wrote:
>> 
>> FYI this is what I have installed (lspy is a personal script):
>> 
>> $ lspy
>> /bin/python: 3.9.1 final 0
>> /bin/python2: 2.7.18 final 0
>> /bin/python2.7: 2.7.18 final 0
>> /bin/python3: 3.9.1 final 0
>> /bin/python3.10: 3.10.0 alpha 3
>> /bin/python3.4: 3.4.10 final 0
>> /bin/python3.5: 3.5.10 final 0
>> /bin/python3.6: 3.6.12 final 0
>> /bin/python3.9: 3.9.1 final 0
>> /bin/python34: 3.4.10 final 0
>> /bin/python35: 3.5.10 final 0
>> /usr/bin/python: 3.9.1 final 0
>> /usr/bin/python2: 2.7.18 final 0
>> /usr/bin/python2.7: 2.7.18 final 0
>> /usr/bin/python3: 3.9.1 final 0
>> /usr/bin/python3.10: 3.10.0 alpha 3
>> /usr/bin/python3.4: 3.4.10 final 0
>> /usr/bin/python3.5: 3.5.10 final 0
>> /usr/bin/python3.6: 3.6.12 final 0
>> /usr/bin/python3.9: 3.9.1 final 0
>> /usr/bin/python34: 3.4.10 final 0
>> /usr/bin/python35: 3.5.10 final 0
>> 
> 
> Pretty similar to mine, except that (a) most of the Pythons are in
> /usr/local/bin rather than /bin or /usr/bin, and (b) with just a
> couple of exceptions, they're all alphas and betas (eg 3.7.0a4+) built
> from git. I keep a single 2.7 around (provided by Debian Stable), and
> a couple of different 3.x versions are Debian-provided, with all the
> rest (from 3.4 to 3.10) hanging around from having been built.

In my case they are all installed from Fedora officially built and maintained 
RPMs.

Barry

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


Re: Funny error message

2021-01-01 Thread Barry Scott



> On 1 Jan 2021, at 16:50, Bob van der Poel  wrote:
> 
> On Thu, Dec 31, 2020 at 9:25 PM DL Neil via Python-list <
> [email protected] > wrote:
> 
>> On 1/1/21 11:46 AM, Bob van der Poel wrote:
>>> When I run python from the command line and generate an error I get the
>>> following:
>>> 
>>> Python 3.8.5 (default, Jul 28 2020, 12:59:40)
>>> [GCC 9.3.0] on linux
>>> Type "help", "copyright", "credits" or "license" for more information.
>> z
>>> /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89:
>>> RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't
>>> match a supported version!
>>>  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
>>> Traceback (most recent call last):
>>>  File "", line 1, in 
>>> NameError: name 'z' is not defined
>>> 
>>> I understand "z in not defined" ... but what's with the warnings?
>> 
>> 
>> The implication is that there is a version-mismatch between Python 3.8
>> and whichever urllib3 and chardet libraries currently installed.
>> 
>> Recommend updating the system, container, or venv: either Python, pip3
>> of the two and/or requests or html-parser [as appropriate to the
>> installed libraries - see below], or both/all.
>> 
>> 
>> System here runs as-expected:
>> 
>> dn $ ... python
>> Python 3.9.1 (default, Dec  8 2020, 00:00:00)
>> [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
> z
>> Traceback (most recent call last):
>>  File "", line 1, in 
>> NameError: name 'z' is not defined
> import chardet
> import urllib3
> exit()
>> dn $ ... pip show chardet urllib3
>> Name: chardet
>> Version: 3.0.4
>> Summary: Universal encoding detector for Python 2 and 3
>> Home-page: https://github.com/chardet/chardet
>> Author: Mark Pilgrim
>> Author-email: [email protected]
>> License: LGPL
>> Location: /usr/lib/python3.9/site-packages
>> Requires:
>> Required-by: html5-parser, requests
>> ---
>> Name: urllib3
>> Version: 1.25.8
>> Summary: HTTP library with thread-safe connection pooling, file post,
>> and more.
>> Home-page: https://urllib3.readthedocs.io/
>> Author: Andrey Petrov
>> Author-email: [email protected]
>> License: MIT
>> Location: /usr/lib/python3.9/site-packages
>> Requires:
>> Required-by: requests
>> 
>> 
> Found it!
> 
> I had the proper urllib3 installed. But, in my .local/lib/ a previous
> version was installed. Removing .local/lib/python3.8 has resolved the
> problem.
> 
> Anyone hazard a guess as to why I had a .local tree (nope, I did not create
> it ... I don't think!).
> 

That is where "python3.8 -m pip install --user" puts the packages you install.

Barry


> 
> -- 
> 
>  Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
>  
> Bob van der Poel ** Wynndel, British Columbia, CANADA **
> EMAIL: [email protected] 
> WWW:   http://www.mellowood.ca 
> -- 
> https://mail.python.org/mailman/listinfo/python-list 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does windows edit .py file shebangs?

2021-01-01 Thread Abdur-Rahmaan Janhangeer
Greetings list,

Being a windows user since long, this made
me laugh. Tell me

1/ What version of Python are you running?
2/ What editor/IDE are you using?



Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Fri, Jan 1, 2021 at 8:43 PM Barry Scott  wrote:

> I found python scripts have had their shebang lines edited behind my back.
>
> The shebang line I'm seeing is:
>
> #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE
>
> Is this Microsoft being "helpful"?
> Does anyone know what I will have done to best with this "help"?
>
> What do I need to do to prevent this happening?
>
> Barry
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does windows edit .py file shebangs?

2021-01-01 Thread Eryk Sun
On 1/1/21, Barry Scott  wrote:
> I found python scripts have had their shebang lines edited behind my back.
>
> The shebang line I'm seeing is:
>
> #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE
>
> Is this Microsoft being "helpful"?
> Does anyone know what I will have done to best with this "help"?
>
> What do I need to do to prevent this happening?

Shebang lines may be localized to the current interpreter when
installing a package. Otherwise I don't know what's causing that.

Regarding Windows, the system doesn't support shebang lines in any
way. Python's installer associates .py files with the py.exe launcher,
which looks for a shebang line in a script in order to determine which
executable to run. It supports shebangs with fully-qualified Windows
paths, as well as virtual commands for registered installations, such
as "python", "python3", "python3.9-32", "/usr/bin/python3", and
"/usr/bin/env python".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Funny error message

2021-01-01 Thread Bob van der Poel
Found it!

>
> I had the proper urllib3 installed. But, in my .local/lib/ a previous
> version was installed. Removing .local/lib/python3.8 has resolved the
> problem.
>
> Anyone hazard a guess as to why I had a .local tree (nope, I did not create
> it ... I don't think!).
>
>
> That is where "python3.8 -m pip install --user" puts the packages you
> install.
>
> Barry
>
>
>
> Okay ... I'll take your word for it. But, I really don't think I've every
run that command :)


-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Funny error message

2021-01-01 Thread DL Neil via Python-list
On 1/2/21 6:35 AM, Bob van der Poel wrote:
> Found it!

Well done!


>> I had the proper urllib3 installed. But, in my .local/lib/ a previous
>> version was installed. Removing .local/lib/python3.8 has resolved the
>> problem.
>>
>> Anyone hazard a guess as to why I had a .local tree (nope, I did
>> not create
>> it ... I don't think!).
>>
> 
> That is where "python3.8 -m pip install --user" puts the packages
> you install.
> 
> Barry
> 
> 
> 
> Okay ... I'll take your word for it. But, I really don't think I've
> every run that command :)

Assuming Python is maintained only at the system-level (cf --user or
venv) then it may be possible that installing some application that runs
'on' Python added the local-library (as a "dependency"). Alternately,
many beginners following installation instructions on a paint-by-numbers
basis, may type/copy-paste commands without retaining any memory of same.
[observation, not personal criticism]

Python has been designed to offer flexibility. One of which is the
ability to have multiple, co-resident, versions of Python and/or
libraries. Of course, this also produces exactly the type of 'gotcha'
illustrated (detected, and solved) here.

Someone more familiar with Python-packaging may improve/correct...


On a thematically-related, but OT-note:
I decided to install a 'fresh' version of Fedora 33 on this machine,
rather than performing a version-update. (required one hour from
start-to-finish - try that MS-Win users!) The Python-relevance was to
ensure there was no legacy-Python2 left 'lying-around'. However, the
GIMP (popular graphics package) still uses (and has some sort of
'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak
option - which will enable my Python3-only objective by ring-fencing the
GIMP and its dependencies. However... now I have a system package
manager (dnf (~apt)) installing most system-software and 'other stuff'
under a different method (I took the same approach with the Chromium
browser) - how long will it be before such 'cleverness' is
forgotten/trips me up?
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Funny error message

2021-01-01 Thread Bob van der Poel
On Fri, Jan 1, 2021 at 12:17 PM DL Neil via Python-list <
[email protected]> wrote:

> On 1/2/21 6:35 AM, Bob van der Poel wrote:
> > Found it!
>
> Well done!
>
>
> >> I had the proper urllib3 installed. But, in my .local/lib/ a
> previous
> >> version was installed. Removing .local/lib/python3.8 has resolved
> the
> >> problem.
> >>
> >> Anyone hazard a guess as to why I had a .local tree (nope, I did
> >> not create
> >> it ... I don't think!).
> >>
> >
> > That is where "python3.8 -m pip install --user" puts the packages
> > you install.
> >
> > Barry
> >
> >
> >
> > Okay ... I'll take your word for it. But, I really don't think I've
> > every run that command :)
>
> Assuming Python is maintained only at the system-level (cf --user or
> venv) then it may be possible that installing some application that runs
> 'on' Python added the local-library (as a "dependency"). Alternately,
> many beginners following installation instructions on a paint-by-numbers
> basis, may type/copy-paste commands without retaining any memory of same.
> [observation, not personal criticism]
>
> Python has been designed to offer flexibility. One of which is the
> ability to have multiple, co-resident, versions of Python and/or
> libraries. Of course, this also produces exactly the type of 'gotcha'
> illustrated (detected, and solved) here.
>
> Someone more familiar with Python-packaging may improve/correct...
>
>
> On a thematically-related, but OT-note:
> I decided to install a 'fresh' version of Fedora 33 on this machine,
> rather than performing a version-update. (required one hour from
> start-to-finish - try that MS-Win users!) The Python-relevance was to
> ensure there was no legacy-Python2 left 'lying-around'. However, the
> GIMP (popular graphics package) still uses (and has some sort of
> 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak
> option - which will enable my Python3-only objective by ring-fencing the
> GIMP and its dependencies. However... now I have a system package
> manager (dnf (~apt)) installing most system-software and 'other stuff'
> under a different method (I took the same approach with the Chromium
> browser) - how long will it be before such 'cleverness' is
> forgotten/trips me up?
>

I have installed a few packages using pip. I "try" to do so as root (this
is basically a one user machine) ... but I may have installed as user.
Still, it should not have brought in a complete py set of libraries. I'm
going with the idea that some other package, either via apt or flatpak
(which I really don't trust) decided to be nice. But it was a mess to have
python distros in /usr/lib, /usr/local/lib and ./local ... I am going to
really try in the future to have everything in one spot!

Speaking of "one spot" I also see that some functions do not create the
.pyc versions. Running as a user, the compressed version can't be created
in /usr/lib/. I assume the installer is supposed to do that, but it does
appear that it's not 100%.


-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-01 Thread jak

Il 01/01/2021 14:49, [email protected] ha scritto:

On 2021-01-01 at 11:11:47 +0100,
jak  wrote:


Il 01/01/2021 04:14, [email protected] ha scritto:

On 2021-01-01 at 03:43:43 +0100,
jak  wrote:

I think you were clear enough before, but you may not have
considered things the OP did not specify.  One of the hardest parts
of software development is understanding and specifying the actual
problem to be solved.  I've never done that in a second language
(I'm nowhere near fluent in anything other than English); I can only
imagine the extra layers of complexity.


This is the OP's initial request:


Hi. I would like to make something like this:
A python script would run headlessly in the background.
I would like to control the script from the command line using other python 
scripts or from the python shell.
 From time to time I would ask the main script to create a popup window with an 
image or a plot.
What would be the proper way to approach it. How to make communication between 
two scripts?
Thank you.
Petro.


I have suggested an alternative way for his necessity.
It will be up to him to decide which one he should adopt. That way he
has a choice, at least.
I don't know where you work. I know, however, that in these zones, if
you do more than necessary wasting their time, they will kick you away.


So what is necessary?  Does "control the script" include reporting
success or failure of a request?  The OP also said "communication
between two scripts," which to me means two way traffic.  Only the OP
knows for sure, and at least one of us might get it wrong if we don't
ask, or at least acknowledge that we don't know.

If I start with a named pipe because it's good enough for Phase Zero, or
Version 0.0.1, or Release Experimental Alpha, then I'm going to end up
ripping that out or reinventing something that already existed on top of
that named pipe.

Suppose I look ahead just a little, and use a socket in the first place.
Yes, you could argue that it's more than what was necessary and kick me
away.  Will you kick me again when you can build on it (I can't; I'm
gone) instead of having to rebuild what already worked?

I'm retired now, but I at one employer, I worked on products with (a)
lifetimes measured in decades, (b) extremely expensive (money, time,
convenience, etc.) upgrade/maintenance cycles, and therefore (c) strict
interoperability requirements.¹  A little bit of foresight and extra
analysis up front went a long way towards saving a lot of headaches and
development resources (and customers!)  in the long term.
Communications protocols in particular had to be well thought out, and
often more complex than was immediately necessary, because backwards and
forwards compatibility were not negotiable.

Again, I'm not (and no one else is, either) saying that your solution is
wrong or won't work.  Your solution may even be the be the best solution
to the OP's problem.  All I'm saying is that we can't know until the OP
tells us more.  Yes, the OP has a choice to make.  Maybe we have helped,
not by making that choice, but by giving it to the OP with enough
supporting information to make it.

¹ Think about a system containing dozens of individually field
upgradeable components.  It had to work when a customer upgraded one
component at a time (over the course of weeks or months), or plugged in
an old component while they were waiting for a broken one to be
repaired, or added a brand new component to a system that hadn't been
changed or upgraded for years.  There was no such thing as telling the
customer to wait, or to make them take down the entire system to upgrade
everything at once.  *That* was what was necessary.


Sorry if I made you argumentative. It was not my intention. Let me
reiterate once again that my intention was to offer an alternative to
the OP and that I never claimed my way was better than the other
suggestions. Furthermore, the OP will have already made its choice by
now. Just one last comment: I understand your point of view but I
disagree because the difficulty in providing assistance as the customer
wishes depends on how you have designed the product and not on how you
develop the pieces that compose it. One more thing: you probably don't
care anymore, but people have taught me that if you give a customer
something, you can't sell it to him anymore.

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


Re: ANN: unicode 2.8

2021-01-01 Thread garabik-news-2005-05
Terry Reedy  wrote:
> On 12/31/2020 9:36 AM, [email protected] wrote:
>> unicode is a simple python command line utility that displays
>> properties for a given unicode character, or searches
>> unicode database for a given name.
> ...
>> Changes since previous versions:
>> 
>>   * display ASCII table (either traditional with --ascii or the new
>> EU–UK Trade and Cooperation Agreement version with --brexit-ascii)
> 
> Are you reproducing it with bugs included?
> How is that of any use to anyone?

Including the (correct) ASCII table has been a long term, low priority -
I am using ascii(1) utility reasonably often and it makes sense to
reproduce this functionality.

And when implementing this, it was a no-brainer to include also the
brexit varian (verbatim). After all, given the blood and sweat and tears
shed during the negotiations, I am sure each and every line of the
Agreement has been combed and (re)negotiated over and over by experienced
negotiators and verified an army of experts in the fields 

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-01 Thread Cameron Simpson
On 01Jan2021 03:43, jak  wrote:
>Maybe the fact that I'm not English and I don't know the language well
>doesn't allow me to express myself clearly. Try it one more time:
>The OP would like to give some command to a script that is running. How?
>With a script that sends commands to it. One of the ways, as mentioned,
>is by using a mini socket server. Given the needs of the OP and the fact
>that sockets are a limited resource in a system, I took the liberty of
>proposing a simple alternative: using a named pipe, also because, IMO,
>sockets, in this case, are an overkill. with a few lines of code in a
>thread in the running script they can allow it to receive commands:

You're right. For receive only of small things this is pretty simple.  
Not to mention much easier on the command sender:

echo "my command" >the-named-pipe

I'm sorry for conflating the concurrency and return-a-response needs of 
a full blown client/server app with the much simpler request of the OP: 
to control a daemon simply. I've even done exactly what you suggested 
myself.

I think it's pretty clear that you're aware of the difference in 
behaviours and semantics between UNIX named pipes (unidirection shared 
single channel) with sockets (bidirection distinct multichannels).

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


Re: Funny error message

2021-01-01 Thread DL Neil via Python-list
On 1/2/21 9:39 AM, Bob van der Poel wrote:
> 
> 
> On Fri, Jan 1, 2021 at 12:17 PM DL Neil via Python-list
> mailto:[email protected]>> wrote:
> 
> On 1/2/21 6:35 AM, Bob van der Poel wrote:
> > Found it!
> 
> Well done!
> 
> 
> >>     I had the proper urllib3 installed. But, in my .local/lib/ a
> previous
> >>     version was installed. Removing .local/lib/python3.8 has
> resolved the
> >>     problem.
> >>
> >>     Anyone hazard a guess as to why I had a .local tree (nope, I did
> >>     not create
> >>     it ... I don't think!).
> >>
> >
> >     That is where "python3.8 -m pip install --user" puts the packages
> >     you install.
> >
> >     Barry
> >
> >
> >
> > Okay ... I'll take your word for it. But, I really don't think I've
> > every run that command :)
> 
> Assuming Python is maintained only at the system-level (cf --user or
> venv) then it may be possible that installing some application that runs
> 'on' Python added the local-library (as a "dependency"). Alternately,
> many beginners following installation instructions on a paint-by-numbers
> basis, may type/copy-paste commands without retaining any memory of
> same.
> [observation, not personal criticism]
> 
> Python has been designed to offer flexibility. One of which is the
> ability to have multiple, co-resident, versions of Python and/or
> libraries. Of course, this also produces exactly the type of 'gotcha'
> illustrated (detected, and solved) here.
> 
> Someone more familiar with Python-packaging may improve/correct...
> 
> 
> On a thematically-related, but OT-note:
> I decided to install a 'fresh' version of Fedora 33 on this machine,
> rather than performing a version-update. (required one hour from
> start-to-finish - try that MS-Win users!) The Python-relevance was to
> ensure there was no legacy-Python2 left 'lying-around'. However, the
> GIMP (popular graphics package) still uses (and has some sort of
> 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak
> option - which will enable my Python3-only objective by ring-fencing the
> GIMP and its dependencies. However... now I have a system package
> manager (dnf (~apt)) installing most system-software and 'other stuff'
> under a different method (I took the same approach with the Chromium
> browser) - how long will it be before such 'cleverness' is
> forgotten/trips me up?
> 
> 
> I have installed a few packages using pip. I "try" to do so as root
> (this is basically a one user machine) ... but I may have installed as
> user. Still, it should not have brought in a complete py set of
> libraries. I'm going with the idea that some other package, either via
> apt or flatpak (which I really don't trust) decided to be nice. But it
> was a mess to have python distros in /usr/lib, /usr/local/lib and
> ./local ... I am going to really try in the future to have everything in
> one spot!

I'm not sure if you mean that you intend moving files from the directory
where they were loaded to somewhere else - I would hesitate!


As before, there is a tradeoff between 'tidiness' and 'flexibility'.
Perhaps do some reading to ensure a grasp of Python's library/directory
structures and system/virtual environments, first?

Suggestions:
sys.path https://docs.python.org/3/using/cmdline.html
2.3. Python-related paths and files
https://docs.python.org/3/using/unix.html#python-related-paths-and-files
PEP 370 -- Per user site-packages directory
https://www.python.org/dev/peps/pep-0370/
and to really dive 'under the covers'
https://www.python.org/dev/peps/pep-0587/
- with plenty more, both on-site and externally.

It quickly becomes apparent that there are risks in assuming that what
'should be done' for one project/application will 'always' be OK. Sadly,
such may have an (undesirable) impact on another/others. Thus, the
virtue of project-dedicated venvs (alternately OpSys-level containers)!


> Speaking of "one spot" I also see that some functions do not create the
> .pyc versions. Running as a user, the compressed version can't be
> created in /usr/lib/. I assume the installer is supposed to do that, but
> it does appear that it's not 100%.

There are multiple reasons for this, but the first time that code is
run, a .pyc will (presumably) be created - and we're back to
considerations of Python environments, Python cf C, perhaps even
differences between OpSys - certainly and once-again, 'here be dragons'...
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Funny error message

2021-01-01 Thread Bob van der Poel
> Assuming Python is maintained only at the system-level (cf --user or
> > venv) then it may be possible that installing some application that
> runs
> > 'on' Python added the local-library (as a "dependency"). Alternately,
> > many beginners following installation instructions on a
> paint-by-numbers
> > basis, may type/copy-paste commands without retaining any memory of
> > same.
> > [observation, not personal criticism]
> >
> > Python has been designed to offer flexibility. One of which is the
> > ability to have multiple, co-resident, versions of Python and/or
> > libraries. Of course, this also produces exactly the type of 'gotcha'
> > illustrated (detected, and solved) here.
> >
> > Someone more familiar with Python-packaging may improve/correct...
> >
> >
> > On a thematically-related, but OT-note:
> > I decided to install a 'fresh' version of Fedora 33 on this machine,
> > rather than performing a version-update. (required one hour from
> > start-to-finish - try that MS-Win users!) The Python-relevance was to
> > ensure there was no legacy-Python2 left 'lying-around'. However, the
> > GIMP (popular graphics package) still uses (and has some sort of
> > 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak
> > option - which will enable my Python3-only objective by ring-fencing
> the
> > GIMP and its dependencies. However... now I have a system package
> > manager (dnf (~apt)) installing most system-software and 'other
> stuff'
> > under a different method (I took the same approach with the Chromium
> > browser) - how long will it be before such 'cleverness' is
> > forgotten/trips me up?
> >
> >
> > I have installed a few packages using pip. I "try" to do so as root
> > (this is basically a one user machine) ... but I may have installed as
> > user. Still, it should not have brought in a complete py set of
> > libraries. I'm going with the idea that some other package, either via
> > apt or flatpak (which I really don't trust) decided to be nice. But it
> > was a mess to have python distros in /usr/lib, /usr/local/lib and
> > ./local ... I am going to really try in the future to have everything in
> > one spot!
>
> I'm not sure if you mean that you intend moving files from the directory
> where they were loaded to somewhere else - I would hesitate!
>
>
> As before, there is a tradeoff between 'tidiness' and 'flexibility'.
> Perhaps do some reading to ensure a grasp of Python's library/directory
> structures and system/virtual environments, first?
>
> What me? Read? Actually a good suggestion ... I'll make note of the
recommended reading list. Thanks.


> Suggestions:
> sys.path https://docs.python.org/3/using/cmdline.html
> 2.3. Python-related paths and files
> https://docs.python.org/3/using/unix.html#python-related-paths-and-files
> PEP 370 -- Per user site-packages directory
> https://www.python.org/dev/peps/pep-0370/
> and to really dive 'under the covers'
> https://www.python.org/dev/peps/pep-0587/
> - with plenty more, both on-site and externally.
>
> It quickly becomes apparent that there are risks in assuming that what
> 'should be done' for one project/application will 'always' be OK. Sadly,
> such may have an (undesirable) impact on another/others. Thus, the
> virtue of project-dedicated venvs (alternately OpSys-level containers)!
>
>
> > Speaking of "one spot" I also see that some functions do not create the
> > .pyc versions. Running as a user, the compressed version can't be
> > created in /usr/lib/. I assume the installer is supposed to do that, but
> > it does appear that it's not 100%.
>
> There are multiple reasons for this, but the first time that code is
> run, a .pyc will (presumably) be created - and we're back to
> considerations of Python environments, Python cf C, perhaps even
>
>
Oh no! Not these damned dragons again :)

But, seriously. No, I have no idea of moving installed stuff around between
/usr /.local and /usr/local. There lies no dragons but madness :) I meant
that I will pay more attention as to what the installer(s) are doing.

Thanks for the input.


-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


A random word from one of two lists

2021-01-01 Thread Bischoop
I have two lists *animal* and *fruit* and I try to get a random variable
animal or fruit and then random word from that list.
I thought that dictionary(*words*) could help me but no succes, the only way 
I've
done partially what was with list *kinds* and by using two times
random.choice. However print(kind) return me a list not a variable:
animal or fruit so now I'm kinda confuse if I can achieve that.



import random
animal = ['koala', 'kangaroo']
fruit = ['banana', 'apple']
kinds = [animal,fruit]
words = {'animals': animal, 'fruits': fruit}


kind = random.choice(kinds)
print(kind)
word = random.choice(kind)
print(word)
#output:
['kolala', 'kangaroo']
kangaroo

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


Re: Control stript which is runing in background.

2021-01-01 Thread 2QdxY4RzWzUUiLuE
On 2021-01-01 at 21:41:24 +0100,
jak  wrote:

> Sorry if I made you argumentative ...

And I didn't mean to be argumentative.  :-)

We both offered alternatives, and we both argued for them (in the sense
of claiming that our own ideas were good).  Each solution is better,
depending on certain details of the OP's requirements.

> ... Furthermore, the OP will have already made its choice by now ...

We don't know that.

> ... Just one last comment: I understand your point of view but I
> disagree because the difficulty in providing assistance as the
> customer wishes depends on how you have designed the product and not
> on how you develop the pieces that compose it ...

I agree:  most companies have no more customer service.  :-)

Our business was emergency communications equipment; if we didn't
provide such assistance, or the equipment didn't do certain things,
there was a distinct possibility that someome could die.

When a police officer presses the button, he or she has to talk to the
dispatcher in 250ms or less.  Same for an emergency medical technician
in an ambulance.  A 60-second TCP timeout or an HTTP 503 error is not
okay.  You can't tell people in a burning building to wait until the
dispatch center has finished their upgrades, and you can't take the
whole fire department off line to upgrade the radios in all the trucks
at once.  It's not a matter of what's easiest to develop, or the easiest
to support.

I think I'm coming off gruffly again, but I don't mean to.

> ... One more thing: you probably don't care anymore, but people have
> taught me that if you give a customer something, you can't sell it to
> him anymore.

Please don't tell me what I do or don't care about.  :-)

I agree:  once you give something away for free, it's very difficult to
charge money for it later.  Believe me, we didn't give our
communications equipment (or the subsequent software upgrades, unless
there was a serious bug) away for free.  :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A random word from one of two lists

2021-01-01 Thread Richard Damon
On 1/1/21 5:58 PM, Bischoop wrote:
> I have two lists *animal* and *fruit* and I try to get a random variable
> animal or fruit and then random word from that list.
> I thought that dictionary(*words*) could help me but no succes, the only way 
> I've
> done partially what was with list *kinds* and by using two times
> random.choice. However print(kind) return me a list not a variable:
> animal or fruit so now I'm kinda confuse if I can achieve that.
>
>
>
> import random
> animal = ['koala', 'kangaroo']
> fruit = ['banana', 'apple']
> kinds = [animal,fruit]
> words = {'animals': animal, 'fruits': fruit}
>
>
> kind = random.choice(kinds)
> print(kind)
> word = random.choice(kind)
> print(word)
> #output:
> ['kolala', 'kangaroo']
> kangaroo
>
> --
> Thanks

random.choice doesn't return 'a variable' but an object. Which is the
same object that one of the variables that you used.

IF you wanted to use words, then you could have made kinds = {'animals',
'fruits'} and then looked up the list in words, but that is really just
more work (unless you want to know which list it came from)

Note that 'animals' isn't a variable, but a string value.

-- 
Richard Damon

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


Re: A random word from one of two lists

2021-01-01 Thread Cameron Simpson
On 01Jan2021 22:58, Bischoop  wrote:
>I have two lists *animal* and *fruit* and I try to get a random variable
>animal or fruit and then random word from that list.
>I thought that dictionary(*words*) could help me but no succes, the only way 
>I've
>done partially what was with list *kinds* and by using two times
>random.choice. However print(kind) return me a list not a variable:
>animal or fruit so now I'm kinda confuse if I can achieve that.
>
>import random
>animal = ['koala', 'kangaroo']
>fruit = ['banana', 'apple']

This is fine.

>kinds = [animal,fruit]

This probably isn't what you intend. Print out kinds:

print(repr(kinds))

>words = {'animals': animal, 'fruits': fruit}

I suspect you want, after this line:

kinds = list(words.keys())

which gets you a list of the dictionary keys. Print that, too, to see 
the difference.

>kind = random.choice(kinds)
>print(kind)

When the earlier stuff works, this should be a string.

>word = random.choice(kind)

This picks a random character from the string. Probably not what you 
want. You want to pick from the list of animals or fruits. Since you 
(will) have the word "animals" or "fruits" in "kind", how do you 
reference the appropriate list?

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


Re: A random word from one of two lists

2021-01-01 Thread Marco Sulla
Try this:

>>> animal = ['koala', 'kangaroo']
>>> fruit = ['banana', 'apple']
>>> words = {'animals': animal, 'fruits': fruit}
>>> kinds = tuple(words.keys())
>>> kind = random.choice(kinds)
>>> kind
'animals'
>>> word = random.choice(words[kind])
>>> word
'koala'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-01 Thread Alan Bawden
jak  writes:

   Il 01/01/2021 06:23, Alan Bawden ha scritto:
   > jak  writes:
   >
   > Running the command:
   >
   > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe
   >
   > the three texts do not mix
   >
   > The three texts do not mix as long at the contents of bible.txt is short
   > enough (and provided `cat' only calls `write' once).  In the POSIX
   > specification, the manual page for the `write' system call describes
   > writing to a pipe or FIFO as follows:
   >
   >Write requests of {PIPE_BUF} bytes or less shall not be interleaved
   >with data from other processes doing writes on the same pipe.  Writes
   >of greater than {PIPE_BUF} bytes may have data interleaved, on
   >arbitrary boundaries, with writes by other processes, whether or not
   >the O_NONBLOCK flag of the file status flags is set.
   >
   Ok. And...
...Running the command:

$ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe

the three texts do not mix

Saying it again doesn't make it any more true.  If bible.txt is large
enough, they most definitely DO mix!  Just to make sure I wasn't missing
something, I tested your exact command before I sent my previous reply.
They mixed.

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


Re: A random word from one of two lists

2021-01-01 Thread Bischoop
On 2021-01-01, Cameron Simpson  wrote:
>
> kinds = list(words.keys())
>

Yes, solved it with that exeactly.

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


Re: A random word from one of two lists

2021-01-01 Thread Bischoop
On 2021-01-02, Python  wrote:
>
> >>> from random import choice
> >>> choice(words[choice(list(words.keys()))])
> 'apple'
> >>> choice(words[choice(list(words.keys()))])
> 'kangaroo'
> >>> choice(words[choice(list(words.keys()))])
> 'koala'
> >>> choice(words[choice(list(words.keys()))])
> 'apple'
> >>> choice(words[choice(list(words.keys()))])
> 'kangaroo'
>
> or this?
>
> >>> randstuff = lambda: choice(words[choice(list(words.keys()))])
> >>> randstuff()
> 'kangaroo'
> >>> randstuff()
> 'kangaroo'
> >>> randstuff()
> 'apple'
> >>> randstuff()
> 'kangaroo'
> >>> randstuff()
> 'koala'
> >>> randstuff()
> 'banana'

that lambada method is good.


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