Skip to content
Advertisement

Tag: python-3.x

How to use the Python packaging library with a custom regex?

I’m trying to build and tag artifacts, the environment name gets appended at the end of the release, e.g.: 1.0.0-stg or 1.0.0-sndbx, none of them are PEP-440 compliance, raising the following error message: Using the packaging library I know I can access the regex by doing: However, my question is how can I customize the regex rule also to support

Get latest timestamp from list of dictionaries

I have list of dictionaries that I am pulling from a ticketing system. Each dictionary contains the name and timestamp of a ticket. There are cases where multiple tickets are entered for the same user and I would like to filter this list to only append the ‘latest’ timestamp to the list, rather than all occurrences. Edit: I am looking

Add a space after a word if it’s at the beginning of a string or if it’s after one or more spaces, and at the same time it must be at end or before n

How to obtain this outputs from those inputs? Note that for examples 4, 5, 6 and 7 the regex should not make any changes, since after the word there is already a space placed, or because in the case of “uno”, the word “un” is not at the end of the sentence, or in the case of “treinta yun” the

django url error this problem is happening only when user is logged in

##error is with line 12 #log ” Traceback (most recent call last): File “/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py”, line 34, in inner response = get_response(request) File “/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/base.py”, line 115, in _get_response response = self.process_exception_by_middleware(e, request) File “/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/base.py”, line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File “/app/website/views.py”, line 298, in gallery return render ( request, ‘gallery.html’, context) File “/app/.heroku/python/lib/python3.10/site-packages/django/shortcuts.py”, line 19, in render

How do I put this into one line? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 months ago. Improve this question So I have this basic code. How could I make it into line? without including the with open, as other stuff

Python split a string between different delimiters

I would like to split a string like this to something like this: but I can also have this: to something like this: The idea at the end is to print it like that Does someone has an idea ? Thx Answer You can take advantage of the fact that re.split retains the “splitter” in the results if it’s a

Python equality statement of the form a==b in [c,d,e]

I just came across some python code with the following statement: It turns out that: Am I right in assuming that a==b in [c,d,e] is equivalent to (a==b) in [c,d,e] and therefore only really makes sense if [c,d,e] is a list of True/False values? And in the case of the code I saw b is always in the list [c,d,e].

Advertisement