Am Tue, Nov 12, 2024 at 09:52:31AM +0100 schrieb Loris Bennett via Python-list:
> Regarding your example above, if 'missingfile.py' contains the following
>
> import configparser
>
> config = configparser.ConfigParser()
>
> try:
> config.read('/foo/bar')
> except FileNotFoundError as
Am Thu, Oct 31, 2024 at 07:47:17AM +0100 schrieb Loris Bennett via Python-list:
> However I didn't make myself clear: I understand that there are
> different functions, depending on whether I have a file name or a
> stream. Nevertheless, I just can't think of a practical example where I
> might j
Am Tue, Oct 08, 2024 at 04:59:48PM -0400 schrieb Alan Bawden via Python-list:
> Karsten Hilbert writes:
>
>Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
>Type "help", "copyright", "credits" or "license" for more
> information.
>>>> tex = '\
Am Tue, Oct 08, 2024 at 08:07:04PM +0100 schrieb MRAB via Python-list:
> >unwanted_tex = '\sout{'
> >if unwanted_tex not in line: do_something_with_libreoffice()
> >
> That should be:
>
> unwanted_tex = r'\sout{'
Hm.
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Am Mon, Oct 07, 2024 at 08:35:32AM -0500 schrieb Michael F. Stemper via
Python-list:
> I'm trying to discard lines that include the string "\sout{" (which is TeX,
> for
> those who are curious. I have tried:
> if not re.search("\sout{", line):
> if not re.search("\sout\{", line):
> if not
Am Sun, Oct 06, 2024 at 12:21:09AM +0200 schrieb Karsten Hilbert via
Python-list:
> Am Sat, Oct 05, 2024 at 10:27:33PM +0200 schrieb Ulrich Goebel via
> Python-list:
>
> > Debian (or even Python3 itself) doesn't allow to pip install required
> > packages system wide
Am Sat, Oct 05, 2024 at 10:27:33PM +0200 schrieb Ulrich Goebel via Python-list:
> Debian (or even Python3 itself) doesn't allow to pip install required
> packages system wide, so I have to use virtual environments even there. But
> is it right, that I have to do that for every single user?
>
> C
Am Tue, Sep 10, 2024 at 08:38:30AM - schrieb Jon Ribbens via Python-list:
> Ok. So we've moved away from "In any DBMS worth its salt, rollback is
> something that happens automatically"
Nope. The original post asked something entirely different.
> and now you're saying it isn't automatic aft
Am Mon, Sep 09, 2024 at 10:00:11AM - schrieb Jon Ribbens via Python-list:
> So the Python code is half-way through a transaction when it throws
> a (non-database-related) exception and that thread of execution is
> aborted. The database connection returns to the pool,
How does it return to th
Am Mon, Sep 09, 2024 at 10:00:11AM - schrieb Jon Ribbens via Python-list:
> > The database only needs to commit when it is explicitly told. Anything
> > less -- no commit.
>
> So the Python code is half-way through a transaction when it throws
> a (non-database-related) exception and that thre
Am Mon, Sep 09, 2024 at 01:48:32PM +1200 schrieb Greg Ewing via Python-list:
> That code doesn't inspire much confidence in me. It's far too
> convoluted with too much micro-management of exceptions.
It is catching two exceptions, re-raising both of them,
except for re-raising one of them as anot
Am Mon, Sep 09, 2024 at 01:48:32PM +1200 schrieb Greg Ewing via Python-list:
> That code doesn't inspire much confidence in me. It's far too
> convoluted with too much micro-management of exceptions.
>
> I would much prefer to have just *one* place where exceptions are
> caught and logged.
I am o
Am Sun, Sep 08, 2024 at 02:58:03PM +0100 schrieb Rob Cliffe via Python-list:
> >Ugly:
> >
> > try:
> > do something
> > except:
> > log something
> > finally:
> > try:
> > .commit()
> > except:
> >
Am Sun, Sep 08, 2024 at 12:48:50PM +1200 schrieb Greg Ewing via Python-list:
> On 8/09/24 9:20 am, Karsten Hilbert wrote:
> > try:
> > do something
> > except:
> > log something
> > finally:
> > .commit()
> >
> >cadence is fairly Pythonic and elegant
Am Sun, Sep 08, 2024 at 12:48:50PM +1200 schrieb Greg Ewing via Python-list:
> On 8/09/24 9:20 am, Karsten Hilbert wrote:
> > try:
> > do something
> > except:
> > log something
> > finally:
> > .commit()
> >
> >cadence is fairly Pythonic and elegant
Am Sat, Sep 07, 2024 at 02:09:28PM -0700 schrieb Adrian Klaver:
> >Right, and this was suggested elsewhere ;)
> >
> >And, yeah, the actual code is much more involved :-D
> >
>
> I see that.
>
> The question is does the full code you show fail?
>
> The code sample you show in your original post is
Am Sat, Sep 07, 2024 at 01:03:34PM -0700 schrieb Adrian Klaver:
> In the case you show you are doing commit() before the close() so any errors
> in the
> transactions will show up then. My first thought would be to wrap the
> commit() in a
> try/except and deal with error there.
Right, and this
Am Sat, Sep 07, 2024 at 09:46:03AM -0700 schrieb Adrian Klaver:
> >unto now I had been thinking this is a wise idiom (in code
> >that needs not care whether it fails to do what it tries to
> >do^1):
> >
> > conn = psycopg2.connection(...)
>
> In the above do you have:
>
> https://www.psycopg.o
Dear all,
unto now I had been thinking this is a wise idiom (in code
that needs not care whether it fails to do what it tries to
do^1):
conn = psycopg2.connection(...)
curs = conn.cursor()
try:
curs.execute(SOME_SQL)
except PSYCOPG2-Exception:
Am Sun, May 19, 2024 at 10:45:09PM +0100 schrieb Barry via Python-list:
> > On 18 May 2024, at 16:27, Peter J. Holzer via Python-list
> > wrote:
> >
> > I don't think Linux users have to deal with venvs
>
> Modern debian (ubuntu) and fedora block users installing using pip.
> You must use a venv
> On Tue, 30 Jan 2024, Karsten Hilbert wrote:
>
> > It doesn't need to. It just sends the (pre-personalized-by-Python) mail
> > files.
>
> Karsten,
>
> In which case, I might as well have Python format and send the messages. :-)
Certainly. But it seems you are wrestling with Python. Might as well
> > Why not foxus on just the part you think you are better off using python,
> > namely personalization ?
> >
> > Create personalized files and send them with your trusted mailx solution ?
>
> Karsten,
>
> Too much time. And while mailx accepts the '-a' option for attachments but
> has none for
> For 30 years I've used a bash script using mailx to send messages to a list
> of recipients. They have no salutation to personalize each one. Since I want
> to add that personalized salutation I decided to write a python script to
> replace the bash script.
Why not foxus on just the part you thi
Am Sat, Jan 13, 2024 at 09:20:00PM +0100 schrieb Karsten Hilbert via
Python-list:
> > I was wondering if
> > your type hint for queries shouldn't be the following.
> >
> > queries:list[dict[str,str]|dict[str,list]|dict[str,dict[str, dict[str,
> > Ant]]]
Wait,
Am Fri, Jan 12, 2024 at 02:23:43PM +0100 schrieb Antoon Pardon via Python-list:
> > queries:list[dict[str, str | list | dict[str, Any]]]=None,
> >
> >into
> >
> > "List[Dict[str, Union[str, List[Any], Dict[str, Any"
> >
> >seems accurate. I just don't understand why list[dict[str,
> >s
Thanks to all. I ended up using Sequence for the list part
and Mapping for the dict part, which does require "import
typing" which I would rather have avoided.
Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
--
https://mail.python.org/mailman/listinfo/python-list
> I'm fairly sure your database queries don't actually give you strings or
> dicts, right? You probably get lists (or iterators) of tuples and
> somewhere you convert them to the arguments you are feeding to
> run_queries().
Ah, no, those queries are enshrined within the middleware as Python stri
> It occurs to me that you could simplify things if you converted those
> plain query strings to dicts:
>
> 'SELECT 1' --> {'SQL': 'SELECT 1'}
Ha, indeed. There's likely not that many "simple string SQL queries"
in that codebase so I shall take it as an opportunity to refactor them.
So, at least
Dear Thomas,
thanks for taking the time to look into my issue.
Maybe it helps if I explain what I want (sorry that my web mailer does not
respect
indentation, I will insert dots).
I want a function to run SQL queries:
run_queries(conn, queries):
...for q in queries:
..conn.execute(q)
I no
Hi Greg,
> dict[str, str] is not a subtype of dict[str, str | something_else]
> because you can assign a value of type something_else to the latter
> but not the former.
I understand what you are saying but I do not yet understand why this
applies to my situation.
I don't have Python at hand cur
Am Fri, Dec 29, 2023 at 11:04:59AM -0700 schrieb Mats Wichmann via Python-list:
> >For what it's worth here's the signature of that function:
> >
> > def run_rw_queries (
> > link_obj:_TLnkObj=None,
> > queries:list[dict[str, str | list | dict[str, Any]]]=None,
> >
Am Fri, Dec 29, 2023 at 07:49:17AM -0700 schrieb Mats Wichmann via Python-list:
> >I am not sure why mypy thinks this
> >
> >gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible
> >type "List[Dict[str, str]]"; expected
> >"List[Dict[str, Union[str, List[Any], Dict[str, Any
Am Fri, Dec 29, 2023 at 01:15:29PM +0100 schrieb Karsten Hilbert via
Python-list:
> I am not sure why mypy thinks this
>
> gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible
> type "List[Dict[str, str]]"; expected
> "
Hi all,
I am not sure why mypy thinks this
gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible
type "List[Dict[str, str]]"; expected
"List[Dict[str, Union[str, List[Any], Dict[str, Any" [arg-type]
rows, idx = run_rw_queries(link_obj = conn, queri
> > .From all the posts I gather the answer to my question is
> > "simply": unpackaged-but-needed modules need to be packaged.
>
> I think there is one aspect that isn't getting consideration here. And
> that is whether or not you want these packages installed in the default
> system Python instal
Am Mon, Nov 06, 2023 at 02:43:47PM -0700 schrieb Mats Wichmann via Python-list:
> >I had just hoped someone here might have a handy pointer for
> >how to deal with modules having to be installed from pip for
> >use with an apt-installed python-based application.
>
> That just shouldn't happen - su
Am Mon, Nov 06, 2023 at 08:58:00AM +0100 schrieb Dieter Maurer:
> I know that debian packagers create debian packages
> from Python distributions not using the approach sketched above
> and likely they have their reasons.
>
> You might want to discuss this on an `apt` related mailing list.
Yeah,
Am Mon, Nov 06, 2023 at 01:17:11AM - schrieb Jon Ribbens via Python-list:
> >> >> Are they not available in your system's package manager?
> >> >
> >> > ... this clearly often answers to "no" for applications of
> >> > any complexity.
> >> >
> >> > Is there a suggested proper path to deal with
Am Sun, Nov 05, 2023 at 03:00:41PM + schrieb Chris Green via Python-list:
> > * contact every single maintainer of every single one of the packages
> > that needs updating and persuade them to update their packages and
> > reassure them that you are getting all the other package main
Am Fri, Nov 03, 2023 at 01:53:32PM - schrieb Jon Ribbens via Python-list:
> >> Are they not available in your system's package manager?
> >
> > ... this clearly often answers to "no" for applications of
> > any complexity.
> >
> > Is there a suggested proper path to deal with that (Debian is
>
Am Fri, Nov 03, 2023 at 05:26:06PM +0100 schrieb Dieter Maurer:
> Karsten Hilbert wrote at 2023-11-3 14:47 +0100:
> > ...
> >> Are they not available in your system's package manager?
> >
> >... this clearly often answers to "no" for applications of
> >any complexity.
> >
> >Is there a suggested p
Am Thu, Nov 02, 2023 at 04:07:33PM -0600 schrieb Mats Wichmann via Python-list:
> >So they now have only python3 and there is no python executable in
> >PATH.
>
> FWIW, for this you install the little stub package python-is-python3.
> Especially if you
> want to keep a python2 installation around
Am Thu, Nov 02, 2023 at 09:35:43PM - schrieb Jon Ribbens via Python-list:
Regardless of ...
> Because pip barely plays well by itself, let alone with other package
> managers at the same time.
... being true ...
> > I do only install a few things using pip.
>
> Are they not available in you
> > As per my recent foray into abusing existence-checking for Singleton
> > assurance
> > along such lines as
> >
> > >>> try: self.initialized
> > >>> except AttributeError: print('first instantiation'); self.initialized =
> > >>> True
> >
> > and then changing that to
> >
> > >>> try: self.ini
> > > Fundamentally no, at least not without some shenanigans. Type hints do
> > > not affect the regular running of the code,
> >
> > Except when they do ;-)
> >
> > ... depending on what counts as (valid) code ...
> >
> > In Python a distinction can be made between "runnable" and "valid" :-D
> >
> > or something like that. Basically, any way to avoid writing `= None` over
> > and over again.
>
> Fundamentally no, at least not without some shenanigans. Type hints do
> not affect the regular running of the code,
Except when they do ;-)
... depending on what counts as (valid) code ...
In
Am Wed, Oct 04, 2023 at 05:25:04PM +1300 schrieb dn via Python-list:
> The first question when dealing with the Singleton Pattern is what to do when
> more than
> one instantiation is attempted:
>
> - silently return the first instance
This, in my case.
> and so, returning to the matter of 'rea
Sorry for having conflated the core of the matter with all
the Borg shenanigans, that's where I found the problem in my
real code, so there :-)
Consider this:
#
class Surprise:
def __init__(self, with_type_annotation=False):
Am Sun, Oct 01, 2023 at 09:04:05AM +1300 schrieb dn via Python-list:
> >class WorkingSingleton(Borg):
> >
> > def __init__(self):
> > print(self.__class__.__name__, ':')
> > try:
> > self.already_initialized
> > print('already ini
A type annotation isn't supposed to change what code does,
or so I thought:
#
class Borg:
_instances:dict = {}
def __new__(cls, *args, **kargs):
# look up subclass instance cache
if Borg._i
Am Sat, Sep 16, 2023 at 02:17:19PM +1200 schrieb Rimu Atkinson via Python-list:
> Everyone uses virtual environments.
Umm, like, no.
Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
--
https://mail.python.org/mailman/listinfo/python-list
51 matches
Mail list logo