Re: pip and venvs on Debian

2024-05-21 Thread Roel Schroeven via Python-list

Op 20/05/2024 om 23:48 schreef Akkana Peck via Python-list:

Every so often I need to regenerate it (like when Debian updates the system 
Python version) but that's easy to do: I don't try to duplicate what's 
installed there, I just delete the old venv, create a new one and then pip 
install packages as needed.

I know this isn't the usual pythonista model of "you should have a zillion different 
venvs, one for each program you use, and never use system Python packages", but it 
works well for me: my pip installed packages are all in a predictable place, and I get 
security updates for all the software Debian *does* package. That's my biggest beef with 
pip, the lack of an easy way to update everything at once, and it's the reason I prefer 
Debian packages when available.
If you have a requirements.txt file with all packages you want, I think 
you can do pip -install --upgrade -r requirements.txt to update them 
all. That only works if you don't specify exact versions in the 
requirements.txt file, so don't use the output of pip freeze to generate 
that requirements file. Just create it yourself: it's a simple text file 
with one package per line. Also I prefer not to include dependencies in 
it for use cases like this (it's another story for packaging, where it 
can be useful or requirements.txt to mirror your exact environment with 
dependencies and specific versions).


Having such a requirements.txt file also makes it easier to install all 
the packages again after you re-create your venv.


--
"I love science, and it pains me to think that to so many are terrified
of the subject or feel that choosing science means you cannot also
choose compassion, or the arts, or be awed by nature. Science is not
meant to cure us of mystery, but to reinvent and reinvigorate it."
-- Robert Sapolsky

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


Cprod -- (writing this: itertools.product([0, 1], repeat=N )

2024-05-21 Thread HenHanna via Python-list



How can i write this function Cprod (Cartesian Product) simply?

(writing this out: itertools.product([0, 1], repeat=N )

The value can be a list or a Tuple.

cprod([0, 1], 1) => ((0) (1))

cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1))



This works:

   def cprod(x, c):
if c==1: return [[i] for i in x]
Sub= cprod(x, c-1)
return [i  for F in x   for i in [[F]+R for R in Sub]]


-- Is there another way to write [F]+R ???

   Other ways to improve it?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cprod -- (writing this: itertools.product([0, 1], repeat=N )

2024-05-21 Thread dn via Python-list

On 22/05/24 07:14, HenHanna via Python-list wrote:


How can i write this function Cprod (Cartesian Product) simply?

     (writing this out: itertools.product([0, 1], repeat=N )

The value can be a list or a Tuple.

     cprod([0, 1], 1) => ((0) (1))

     cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1))



This works:

    def cprod(x, c):
     if c==1: return [[i] for i in x]
     Sub= cprod(x, c-1)
     return [i  for F in x   for i in [[F]+R for R in Sub]]


-- Is there another way to write [F]+R ???

    Other ways to improve it?


https://python.readthedocs.io/en/stable/library/itertools.html#itertools.product

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