Re: PEP668 / pipx and "--editable" installs

2023-09-15 Thread Rimu Atkinson via Python-list





I never 
used virtual environments and wouldn't like to start with it.


There's your problem - everything else is a result of this. There is 
just no nice way to work with a combination of pypi, apt-get and 
system-wide python.


Everyone uses virtual environments.

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


Re: PEP668 / pipx and "--editable" installs

2023-09-17 Thread Rimu Atkinson via Python-list




It is nothing bad about using virtual environments but also not about
not using them. In my own work I haven't see a use case where I needed
them. And I expect that some day I'll encounter a use case for it. This
here is not about pro and cons of virtual environments.

You are in a use case where you need them, right now :) When you 
understand the benefits of virtual environments you will understand what 
I meant by that.



Please explain how the two problems I explained are influenced by not
using virtual environments.


The first problem can be avoided because virtual environments can use a 
different version of python than the system one. If you need an earlier 
version of python then you can use it instead.


The second problem can be avoided because virtual environments exist in 
a part of the file system that you have write access to, so you don't 
need to use sudo to install packages. Your main user account does not 
have write access to /usr/bin.


Also when a virtual environment is activated the path to it's packages 
is a part of that environment so your code will always be able to import 
the packages you want.


It's much easier to understand if you try it for yourself. Google has 
many excellent resources, here is one 
https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/


Best of luck :)

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


Async options for flask app

2023-09-17 Thread Rimu Atkinson via Python-list

Hi all,

I'm writing a fediverse server app, similar to kbin https://kbin.pub/en 
and lemmy https://join-lemmy.org/. It's like reddit except anyone can 
run a server in the same way email works. This architecture involves a 
lot of inter-server communication, potentially involving thousands of 
different servers.


So, lots of network I/O. Lots of tasks running in parallel to do I/O 
with different servers simultaneously. A fair bit of DB access too.


The current fashion is to do this with cooperative multitasking 
(async/await/gevent/etc) to avoid the overhead associated with 
continually context switching threads and processes. Correct me if I'm 
wrong.


How can I do this with Flask? Any async/await tricks? Can I just 
configure gunicorn to use gevent worker threads? 
https://flask.palletsprojects.com/en/2.3.x/deploying/gunicorn/


Has anyone tried Quart? https://pypi.org/project/quart/

How well does gevent monkey-patch into a Flask app?

A penny for your thoughts

Thanks!

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


Re: Code improvement question

2023-11-16 Thread Rimu Atkinson via Python-list






Why don't you use re.findall?

re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)


I think I can see what you did there but it won't make sense to me - or 
whoever looks at the code - in future.


That answers your specific question. However, I am in awe of people who 
can just "do" regular expressions and I thank you very much for what 
would have been a monumental effort had I tried it.


I feel the same way about regex. If I can find a way to write something 
without regex I very much prefer to as regex usually adds complexity and 
hurts readability.


You might find https://regex101.com/ to be useful for testing your 
regex. You can enter in sample data and see if it matches.


If I understood what your regex was trying to do I might be able to 
suggest some python to do the same thing. Is it just removing numbers 
from text?


The for loop, "for bit in bits" etc, could be written as a list 
comprehension.


pieces = [bit if len(bit) > 6 else "" for bit in bits]

For devs familiar with other languages but new to Python this will look 
like gibberish so arguably the original for loop is clearer, depending 
on your team.


It's worth making the effort to get into list comprehensions though 
because they're awesome.






That little re.sub() came from ChatGPT and I can understand it without 
too much effort because it came documented


I suppose ChatGPT is the answer to this thread. Or everything. Or will be.


I am doubtful. We'll see!

R


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


Re: Code improvement question

2023-11-21 Thread Rimu Atkinson via Python-list






re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)


\b - a word boundary.
[0-9]{2,7} - 2 to 7 digits
-  - a hyphen-minus
[0-9]{2}   - exactly 2 digits
-  - a hyphen-minus
[0-9]{2}   - exactly 2 digits
\b - a word boundary.

Seems quite straightforward to me. I'll be impressed if you can write
that in Python in a way which is easier to read.



Now that I know what {} does, you're right, that IS straightforward! 
Maybe 2023 will be the year I finally get off my arse and learn regex.


Thanks :)

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


Re: Silly/crazy problem with sqlite

2023-11-25 Thread Rimu Atkinson via Python-list








I really can't think of a case
where the missing comma would make any sense at all.



That is pretty tricky, yes.

The comma means it's a tuple. Without the comma, it's just a string with 
parenthesis around it, which is a string.


PyDev console: starting.
Python 3.9.15 (main, Oct 28 2022, 17:28:38) [GCC] on linux
x = ('%' + "2023-11" + '%')
x
'%2023-11%'
x = ('%' +  x + '%',)
x
('%%2023-11%%',)
x.__class__.__name__
'tuple'


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