Re: new here

2024-08-25 Thread Marco Moock via Python-list
messages? Do yall prefer I post a pastebin link if > it's over a certain number of lines? I know this isn't IRC - just > asking. Welcome! Pastebin and other stuff has the disadvantage that the content might be removed later. What about pasting it under your actual message if it

Re: Anonymous email users

2024-06-17 Thread Marco Moock via Python-list
she/... must be identifiable. The mailing list has a Usenet gateway Those users use the Usenet to post. Check the Injection-Info header for the address of the news server operator. He can identify the account that posted it. -- kind regards Marco Send spam to 1718440236mu...@cartoonies

Am I banned from Discuss forum?

2023-02-10 Thread Marco Sulla
I was banned from the mailing list and Discuss forum for a very long time. Too much IMHO, but I paid my dues. Now this is my state in the forum: - I never posted something unrespectful in the last months - I have a limitation of three posts per threads, but only on some threads - Some random posts

Re: How to generate a .pyi file for a C Extension using stubgen

2022-07-30 Thread Marco Sulla
On Fri, 29 Jul 2022 at 23:23, Barry wrote: > > > > > On 29 Jul 2022, at 19:33, Marco Sulla wrote: > > > > I tried to follow the instructions here: > > > > https://mypy.readthedocs.io/en/stable/stubgen.html > > > > but the instructions a

How to generate a .pyi file for a C Extension using stubgen

2022-07-29 Thread Marco Sulla
I tried to follow the instructions here: https://mypy.readthedocs.io/en/stable/stubgen.html but the instructions about creating a stub for a C Extension are a little mysterious. I tried to use it on the .so file without luck. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why I fail so bad to check for memory leak with this code?

2022-07-22 Thread Marco Sulla
On Fri, 22 Jul 2022 at 09:00, Barry wrote: > With code as complex as python’s there will be memory allocations that occur that will not be directly related to the python code you test. > > To put it another way there is noise in your memory allocation signal. > > Usually the signal of a memory lea

Re: Why I fail so bad to check for memory leak with this code?

2022-07-21 Thread Marco Sulla
llect() snapshot2 = tracemalloc.take_snapshot().filter_traces( (tracemalloc.Filter(True, __file__), ) ) top_stats = snapshot2.compare_to(snapshot1, 'lineno') tracemalloc.stop() for stat in top_stats: print(stat) The result is: /home/marco/sources/test.py:14: size=3339 B (+3339 B)

Re: Why I fail so bad to check for memory leak with this code?

2022-07-21 Thread Marco Sulla
This naif code shows no leak: import resource import pickle c = 0 while True: pickle.dumps(iter([])) if (c % 1) == 0: max_rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss print(f"iteration: {c}, max rss: {max_rss} kb") c += 1 -- https://mail.python.org/

Re: Why I fail so bad to check for memory leak with this code?

2022-07-21 Thread Marco Sulla
On Thu, 21 Jul 2022 at 22:28, MRAB wrote: > > It's something to do with pickling iterators because it still occurs > when I reduce func_76 to: > > @trace > def func_76(): > pickle.dumps(iter([])) It's too strange. I found a bunch of true memory leaks with this decorator. It seems to be relia

Why I fail so bad to check for memory leak with this code?

2022-07-21 Thread Marco Sulla
I tried to check for memory leaks in a bunch of functions of mine using a simple decorator. It works, but it fails with this code, returning a random count_diff at every run. Why? import tracemalloc import gc import functools from uuid import uuid4 import pickle def getUuid(): return str(uuid

Re: Subtract n months from datetime

2022-06-22 Thread Marco Sulla
The package arrow has a simple shift method for months, weeks etc https://arrow.readthedocs.io/en/latest/#replace-shift -- https://mail.python.org/mailman/listinfo/python-list

Re: tail

2022-05-19 Thread Marco Sulla
On Wed, 18 May 2022 at 23:32, Cameron Simpson wrote: > > On 17May2022 22:45, Marco Sulla wrote: > >Well, I've done a benchmark. > >>>> timeit.timeit("tail('/home/marco/small.txt')", globals={"tail":tail}, > >>>>

Re: tail

2022-05-18 Thread Marco Sulla
Well, I've done a benchmark. >>> timeit.timeit("tail('/home/marco/small.txt')", globals={"tail":tail}, >>> number=10) 1.5963431186974049 >>> timeit.timeit("tail('/home/marco/lorem.txt')", globals={"t

Re: tail

2022-05-16 Thread Marco Sulla
On Fri, 13 May 2022 at 12:49, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-05-13 at 12:16:57 +0200, > Marco Sulla wrote: > > > On Fri, 13 May 2022 at 00:31, Cameron Simpson wrote: > > [...] > > > > This is nearly the worst "specificat

Re: tail

2022-05-13 Thread Marco Sulla
On Fri, 13 May 2022 at 00:31, Cameron Simpson wrote: > On 12May2022 19:48, Marco Sulla wrote: > >On Thu, 12 May 2022 at 00:50, Stefan Ram wrote: > >> There's no spec/doc, so one can't even test it. > > > >Excuse me, you're very right. > >

Re: tail

2022-05-12 Thread Marco Sulla
Thank you very much. This helped me to improve the function: import os _lf = b"\n" _err_n = "Parameter n must be a positive integer number" _err_chunk_size = "Parameter chunk_size must be a positive integer number" def tail(filepath, n=10, chunk_size=100): if (n <= 0): raise ValueErr

Re: tail

2022-05-12 Thread Marco Sulla
On Thu, 12 May 2022 at 00:50, Stefan Ram wrote: > > Marco Sulla writes: > >def tail(filepath, n=10, chunk_size=100): > >if (n <= 0): > >raise ValueError(_err_n) > ... > > There's no spec/doc, so one can't even test it. Excuse me, you&#

Re: tail

2022-05-11 Thread Marco Sulla
On Wed, 11 May 2022 at 22:09, Chris Angelico wrote: > > Have you actually checked those three, or do you merely suppose them to be > true? I only suppose, as I said. I should do some benchmark and some other tests, and, frankly, I don't want to. I don't want to because I'm quite sure the impleme

Re: tail

2022-05-11 Thread Marco Sulla
On Mon, 9 May 2022 at 23:15, Dennis Lee Bieber wrote: > > On Mon, 9 May 2022 21:11:23 +0200, Marco Sulla > declaimed the following: > > >Nevertheless, tail is a fundamental tool in *nix. It's fast and > >reliable. Also the tail command can't handle different

Re: tail

2022-05-09 Thread Marco Sulla
On Mon, 9 May 2022 at 19:53, Chris Angelico wrote: > > On Tue, 10 May 2022 at 03:47, Marco Sulla > wrote: > > > > On Mon, 9 May 2022 at 07:56, Cameron Simpson wrote: > > > > > > The point here is that text is a very different thing. Because you >

Re: tail

2022-05-09 Thread Marco Sulla
On Mon, 9 May 2022 at 07:56, Cameron Simpson wrote: > > The point here is that text is a very different thing. Because you > cannot seek to an absolute number of characters in an encoding with > variable sized characters. _If_ you did a seek to an arbitrary number > you can end up in the middle of

Re: tail

2022-05-08 Thread Marco Sulla
On Sun, 8 May 2022 at 22:34, Barry wrote: > > > On 8 May 2022, at 20:48, Marco Sulla wrote: > > > > On Sun, 8 May 2022 at 20:31, Barry Scott wrote: > >> > >>>> On 8 May 2022, at 17:05, Marco Sulla > >>>> wrote: > >>> &g

Re: tail

2022-05-08 Thread Marco Sulla
On Sun, 8 May 2022 at 22:02, Chris Angelico wrote: > > Absolutely not. As has been stated multiple times in this thread, a > fully general approach is extremely complicated, horrifically > unreliable, and hopelessly inefficient. Well, my implementation is quite general now. It's not complicated a

Re: tail

2022-05-08 Thread Marco Sulla
On Sun, 8 May 2022 at 20:31, Barry Scott wrote: > > > On 8 May 2022, at 17:05, Marco Sulla wrote: > > > > def tail(filepath, n=10, newline=None, encoding=None, chunk_size=100): > >n_chunk_size = n * chunk_size > > Why use tiny chunks? You can read 4KiB as f

Re: tail

2022-05-08 Thread Marco Sulla
I think I've _almost_ found a simpler, general way: import os _lf = "\n" _cr = "\r" def tail(filepath, n=10, newline=None, encoding=None, chunk_size=100): n_chunk_size = n * chunk_size pos = os.stat(filepath).st_size chunk_line_pos = -1 lines_not_found = n with open(filepath

Re: tail

2022-05-07 Thread Marco Sulla
On Sat, 7 May 2022 at 19:02, MRAB wrote: > > On 2022-05-07 17:28, Marco Sulla wrote: > > On Sat, 7 May 2022 at 16:08, Barry wrote: > >> You need to handle the file in bin mode and do the handling of line > >> endings and encodings yourself. It’s not that hard

Re: tail

2022-05-07 Thread Marco Sulla
On Sat, 7 May 2022 at 16:08, Barry wrote: > You need to handle the file in bin mode and do the handling of line endings > and encodings yourself. It’s not that hard for the cases you wanted. >>> "\n".encode("utf-16") b'\xff\xfe\n\x00' >>> "".encode("utf-16") b'\xff\xfe' >>> "a\nb".encode("utf-16

Re: tail

2022-05-07 Thread Marco Sulla
On Sat, 7 May 2022 at 01:03, Dennis Lee Bieber wrote: > > Windows also uses for the EOL marker, but Python's I/O system > condenses that to just internally (for TEXT mode) -- so using the > length of a string so read to compute a file position may be off-by-one for > each EOL in the stri

Re: tail

2022-05-06 Thread Marco Sulla
I have a little problem. I tried to extend the tail function, so it can read lines from the bottom of a file object opened in text mode. The problem is it does not work. It gets a starting position that is lower than the expected by 3 characters. So the first line is read only for 2 chars, and th

Re: tail

2022-05-02 Thread Marco Sulla
On Mon, 2 May 2022 at 00:20, Cameron Simpson wrote: > > On 01May2022 18:55, Marco Sulla wrote: > >Something like this is OK? > [...] > >def tail(f): > >chunk_size = 100 > >size = os.stat(f.fileno()).st_size > > I think you want

Re: tail

2022-05-02 Thread Marco Sulla
Ok, I suppose \n and \r are enough: readline(size=- 1, /) Read and return one line from the stream. If size is specified, at most size bytes will be read. The line terminator is always b'\n' for binary files; for text files, the newline argument to open() can be used to select the line

Re: tail

2022-05-02 Thread Marco Sulla
On Mon, 2 May 2022 at 18:31, Stefan Ram wrote: > > |The Unicode standard defines a number of characters that > |conforming applications should recognize as line terminators:[7] > | > |LF:Line Feed, U+000A > |VT:Vertical Tab, U+000B > |FF:Form Feed, U+000C > |CR:Carriage Return, U+0

Re: new sorting algorithm

2022-05-01 Thread Marco Sulla
I suppose you should write to python-...@python.org , or in https://discuss.python.org/ under the section Core development -- https://mail.python.org/mailman/listinfo/python-list

Re: tail

2022-05-01 Thread Marco Sulla
Something like this is OK? import os def tail(f): chunk_size = 100 size = os.stat(f.fileno()).st_size positions = iter(range(size, -1, -chunk_size)) next(positions) chunk_line_pos = -1 pos = 0 for pos in positions: f.seek(pos) chars = f.read(chunk_si

Re: tail

2022-04-24 Thread Marco Sulla
on code! > If I understand Marco correctly, what he want is to read the lines from > bottom to top, i.e. tac instead of tail, despite his subject. > I use tail very frequently too, but tac is something I almost never use. > Well, the inverse reader is only a secondary suggestion

Re: tail

2022-04-24 Thread Marco Sulla
On Sun, 24 Apr 2022 at 00:19, Cameron Simpson wrote: > An approach I think you both may have missed: mmap the file and use > mmap.rfind(b'\n') to locate line delimiters. > https://docs.python.org/3/library/mmap.html#mmap.mmap.rfind > Ah, I played very little with mmap, I didn't know about this.

Re: tail

2022-04-24 Thread Marco Sulla
On Sat, 23 Apr 2022 at 23:18, Chris Angelico wrote: > Ah. Well, then, THAT is why it's inefficient: you're seeking back one > single byte at a time, then reading forwards. That is NOT going to > play nicely with file systems or buffers. > > Compare reading line by line over the file with readline

Re: tail

2022-04-23 Thread Marco Sulla
n". When it find it, it stops and do a readline(): def tail(filepath): """ @author Marco Sulla @date May 31, 2016 """ try: filepath.is_file fp = str(filepath) except AttributeError: fp = filepath with open(fp, "

Re: tail

2022-04-23 Thread Marco Sulla
On Sat, 23 Apr 2022 at 20:59, Chris Angelico wrote: > > On Sun, 24 Apr 2022 at 04:37, Marco Sulla > wrote: > > > > What about introducing a method for text streams that reads the lines > > from the bottom? Java has also a ReversedLinesFileReader with Apac

Re: Receive a signal when waking or suspending?

2022-04-23 Thread Marco Sulla
I don't know in Python, but maybe you can create a script that writes on a named pipe and read it from Python? https://askubuntu.com/questions/226278/run-script-on-wakeup -- https://mail.python.org/mailman/listinfo/python-list

tail

2022-04-23 Thread Marco Sulla
What about introducing a method for text streams that reads the lines from the bottom? Java has also a ReversedLinesFileReader with Apache Commons IO. -- https://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-04-18 Thread Marco Sulla
On Sat, 16 Apr 2022 at 17:14, Peter J. Holzer wrote: > > On 2022-04-16 16:49:17 +0200, Marco Sulla wrote: > > Furthermore, you didn't answer my simple question: why does the > > security update package contain metadata about Debian patches, if the > > Ubuntu secur

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-04-16 Thread Marco Sulla
On Sat, 16 Apr 2022 at 10:15, Peter J. Holzer wrote: > It doesn't (or at least you can't conclude that from the evidence you > posted). > > There is a subdirectory called "debian" in the build directory of every > .deb package. This is true on Debian, Ubuntu and every other > distribution which us

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-14 Thread Marco Sulla
On Thu, 14 Apr 2022 at 19:16, MRAB wrote: > > When you're working only with dates, timedelta not having a 'days' > attribute would be annoying, especially when you consider that a day is > usually 24 hours, but sometimes 23 or 25 hours (DST). I agree. Furthermore, timedelta is, well, a time delta

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-04-14 Thread Marco Sulla
On Wed, 13 Apr 2022 at 20:05, Peter J. Holzer wrote: > > On 2022-04-12 21:03:00 +0200, Marco Sulla wrote: > > On Tue, 29 Mar 2022 at 00:10, Peter J. Holzer wrote: > > > They are are about a year apart, so they will usually contain different > > > versions of most

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-04-12 Thread Marco Sulla
On Tue, 29 Mar 2022 at 00:10, Peter J. Holzer wrote: > They are are about a year apart, so they will usually contain different > versions of most packages right from the start. So the Ubuntu and Debian > security teams probably can't benefit much from each other. Well, this is what my updater on

Re: dict.get_deep()

2022-04-03 Thread Marco Sulla
On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer wrote: > > > > data.get_deep("users", 0, "address", "street", default="second star") > > Yep. Did that, too. Plus pass the final result through a function before > returning it. I didn't understand. Have you added a func parameter? > I'm not sure whet

Re: dict.get_deep()

2022-04-03 Thread Marco Sulla
On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote: > You know you can easily implement this yourself -- in your own > `dict` subclass. Well, of course, but the question is if such a method is worth to be builtin, in a world imbued with JSON. I suppose your answer is no. -- https://mail.python.org

Re: dict.get_deep()

2022-04-03 Thread Marco Sulla
On Sun, 3 Apr 2022 at 16:59, Kirill Ratkin via Python-list wrote: > > Hi Marco. > > Recently I met same issue. A service I intergated with was documented > badly and sent ... unpredictable jsons. > > And pattern matching helped me in first solution. (later I switched to >

dict.get_deep()

2022-04-02 Thread Marco Sulla
A proposal. Very often dict are used as a deeply nested carrier of data, usually decoded from JSON. Sometimes I needed to get some of this data, something like this: data["users"][0]["address"]["street"] What about something like this instead? data.get_deep("users", 0, "address", "street") and

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-31 Thread Marco Sulla
On Thu, 31 Mar 2022 at 18:38, Cecil Westerhof via Python-list wrote: > Most people think that > Ubuntu is that also, because it is based on Debian. But Ubuntu wants > also provide the newest versions of software and this will affect the > stability and security negatively. I think you're referrin

Re: Temporally disabling buffering

2022-03-31 Thread Marco Sulla
Dirty suggestion: stderr? On Thu, 31 Mar 2022 at 18:38, Cecil Westerhof via Python-list wrote: > > In Python when the output of a script is going to a pipe stdout is > buffered. When sending output to tee that is very inconvenient. > > We can set PYTHONUNBUFFERED, but then stdout is always unbuff

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-29 Thread Marco Sulla
On Tue, 29 Mar 2022 at 00:10, Peter J. Holzer wrote: > They are are about a year apart, so they will usually contain different > versions of most packages right from the start. So the Ubuntu and Debian > security teams probably can't benefit much from each other. Are you sure? Since LTS of Debian

Re: Best practice for caching hash

2022-03-16 Thread Marco Sulla
On Wed, 16 Mar 2022 at 09:11, Chris Angelico wrote: > Caching the hash of a > string is very useful; caching the hash of a tuple, not so much; again > quoting from the CPython source code: > > /* Tests have shown that it's not worth to cache the hash value, see >https://bugs.python.org/issue96

Re: Best practice for caching hash

2022-03-16 Thread Marco Sulla
On Wed, 16 Mar 2022 at 00:59, Chris Angelico wrote: > > (Though it's a little confusing; a frozendict has to have nothing but > immutable objects, yet it permits them to be unhashable? It can have mutable objects. For example, a key k can have a list v as value. You can modify v, but you can't as

Re: Best practice for caching hash

2022-03-16 Thread Marco Sulla
On Wed, 16 Mar 2022 at 00:42, Cameron Simpson wrote: > > Is it sensible to compute the hash only from the immutable parts? > Bearing in mind that usually you need an equality function as well and > it may have the same stability issues. [...] > In that case I would be inclined to never raise Typ

Re: Best practice for caching hash

2022-03-15 Thread Marco Sulla
On Sat, 12 Mar 2022 at 22:37, <2qdxy4rzwzuui...@potatochowder.com> wrote: > Once hashing an object fails, why would an application try again? I can > see an application using a hashable value in a hashable situation again > and again and again (i.e., taking advantage of the cache), but what's > th

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-14 Thread Marco Sulla
On Mon, 14 Mar 2022 at 18:33, Loris Bennett wrote: > I am not sure how different the two situations are. Ubuntu is > presumably relying on the Debian security team as well as other > volunteers and at least one company, namely Canonical. So do you think that Canonical contributes to the LTS secu

Best practice for caching hash

2022-03-12 Thread Marco Sulla
think about? Here is the python code: https://github.com/Marco-Sulla/python-frozendict/blob/35611f4cd869383678104dc94f82aa636c20eb24/frozendict/src/3_10/frozendictobject.c#L652-L697 -- https://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-11 Thread Marco Sulla
On Fri, 11 Mar 2022 at 19:10, Michael Torrie wrote: > Both Debian stable and Ubuntu LTS state they have a five year support > life cycle. Yes, but it seems that official security support in Debian ends after three years: "Debian LTS is not handled by the Debian security team, but by a separate g

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-11 Thread Marco Sulla
On Fri, 11 Mar 2022 at 06:38, Dan Stromberg wrote: > That's an attribute of your desktop environment, not the Linux distribution. > > EG: I'm using Debian with Cinnamon, which does support ctrl-alt-t. Never used Cinnamon. It comes from Mint, right? > Some folks say the desktop environment matter

Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-10 Thread Marco Sulla
On Thu, 10 Mar 2022 at 14:13, Jack Dangler wrote: > or why not get a cloud desktop running whatever distro you want and you > don't have to do anything Three reasons: privacy, speed, price. Not in this order. On Thu, 10 Mar 2022 at 15:20, Chris Angelico wrote: > Very easy. I use Debian with Xfc

Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-03-10 Thread Marco Sulla
On Thu, 10 Mar 2022 at 04:50, Michael Torrie wrote: > > On 3/9/22 13:05, Marco Sulla wrote: > > So my laziness pays. I use only LTS distros, and I update only when > > there are security updates. > > PS: any suggestions for a new LTS distro? My Lubuntu is reaching its &

Re: Could frozendict or frozenmap be of some use for PEP 683 (Immortal objects)?

2022-03-10 Thread Marco Sulla
On Wed, 9 Mar 2022 at 23:28, Martin Di Paola wrote: > Think in the immutable strings (str). What would happen with a program > that does heavy parsing? I imagine that it will generate thousands of > little strings. If those are immortal, the program will fill its memory > very quickly as the GC wi

Could frozendict or frozenmap be of some use for PEP 683 (Immortal objects)?

2022-03-09 Thread Marco Sulla
As title. dict can't be an immortal object, but hashable frozendict and frozenmap can. I think this can increase their usefulness. Another advantage: frozen dataclass will be really immutable if they could use a frozen(dict|map) instead of a dict as __dict__ -- https://mail.python.org/mailman/lis

Re: PSA: Linux vulnerability

2022-03-09 Thread Marco Sulla
So my laziness pays. I use only LTS distros, and I update only when there are security updates. PS: any suggestions for a new LTS distro? My Lubuntu is reaching its end-of-life. I prefer lightweight debian-like distros. On Tue, 8 Mar 2022 at 19:56, Ethan Furman wrote: > > https://arstechnica.com/

Re: Cpython: when to incref before insertdict

2022-03-06 Thread Marco Sulla
On Sun, 6 Mar 2022 at 03:20, Inada Naoki wrote: > In general, when reference is borrowed from a caller, the reference is > available during the API. > But merge_dict borrows reference of key/value from other dict, not caller. > [...] > Again, insertdict takes the reference. So _PyDict_FromKeys() *

Re: virtualenv and make DESTDIR=

2022-03-05 Thread Marco Sulla
On Sat, 5 Mar 2022 at 17:36, Barry Scott wrote: > Note: you usually cannot use pip when building an RPM with mock as the > network is disabled inside the build for > security reasons. Can't he previously download the packages and run pip on the local packages? -- https://mail.python.org/mailman

Cpython: when to incref before insertdict

2022-03-05 Thread Marco Sulla
I noticed that some functions inside dictobject.c that call insertdict or PyDict_SetItem do an incref of key and value before the call, and a decref after it. An example is dict_merge. Other functions, such as _PyDict_FromKeys, don't do an incref before. When an incref of key and value is needed b

Re: Error installing requirements

2022-02-19 Thread Marco Sulla
Maybe you compiled Python 2.7 by hand, David? It happened to me when I tried to compile Python without zlib headers installed on my OS. Don't know how it can be done on Windows. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to solve the given problem?

2022-02-10 Thread Marco Sulla
Narshad, I propose you post your questions to StackOverflow. I'm sure they will be very happy. -- https://mail.python.org/mailman/listinfo/python-list

Re: Global VS Local Subroutines

2022-02-10 Thread Marco Sulla
I agree with Chris. I don't know if it was already written: if you want a local function for speed reasons, you can use the classic approach of a main function. -- https://mail.python.org/mailman/listinfo/python-list

Re: How do you log in your projects?

2022-02-10 Thread Marco Sulla
On Wed, 9 Feb 2022 at 20:40, Martin Di Paola wrote: > > If the logs are meant to be read by my users I log high level messages, > specially before parts that can take a while (like the classic > "Loading..."). ? Logs are not intended to be read by end users. Logs are primarily used to understand

Re: How do you log in your projects?

2022-02-08 Thread Marco Sulla
These are a lot of questions. I hope we're not off topic. I don't know if mine are best practices. I can tell what I try to do. On Tue, 8 Feb 2022 at 15:15, Lars Liedtke wrote: > - On a line per line basis? on a function/method basis? I usually log the start and end of functions. I could also lo

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Marco Sulla
You could add a __del__ that calls stop :) On Wed, 2 Feb 2022 at 21:23, Cecil Westerhof via Python-list wrote: > > I need (sometimes) to repeatedly execute a function. For this I wrote > the below class. What do you think about it? > from threading import Timer > > > > class repeated_tim

Re: Why dict.setdefault() has value as optional?

2022-02-02 Thread Marco Sulla
On Wed, 2 Feb 2022 at 14:34, Lars Liedtke wrote: > > This is a quite philosophical queston if you look at it in general: > "What value do you give a variable, that is not set?" Maybe I expressed my question badly. My existential doubt is why setdefault has an optional parameter for the value and

Why dict.setdefault() has value as optional?

2022-02-02 Thread Marco Sulla
Just out of curiosity: why dict.setdefault() has the default parameter that well, has a default value (None)? I used setdefault in the past, but I always specified a value. What's the use case of setting None by default? -- https://mail.python.org/mailman/listinfo/python-list

Re: Segfault after deepcopy in a C extension

2022-01-31 Thread Marco Sulla
and I had to Py_INCREF(memo)! Thank you A LOT! On Mon, 31 Jan 2022 at 23:01, Chris Angelico wrote: > On Tue, 1 Feb 2022 at 08:54, Marco Sulla > wrote: > > PyObject* d = PyDict_New(); > > args = PyTuple_New(2); > > PyTuple_SET_ITEM(args, 0, d); > >

Segfault after deepcopy in a C extension

2022-01-31 Thread Marco Sulla
Well, this is more or less what I'm trying to do. I have an immutable object. I would have copy.deepcopy() will return the object itself if it's hashable. If not, it must return a deepcopy of it. So I tried to implement a __deepcopy__ for the object. It segfaults if the object is not hashable. An

Re: Pandas or Numpy

2022-01-26 Thread Marco Sulla
On Mon, 24 Jan 2022 at 05:37, Dennis Lee Bieber wrote: > Note that the comparison warns that /indexing/ in pandas can be slow. > If your manipulation is always "apply operationX to columnY" it should be > okay -- but "apply operationX to the nth row of columnY", and repeat for > other rows

Re: Why operations between dict views return a set and not a frozenset?

2022-01-16 Thread Marco Sulla
Thank you a lot for letting me understand :) On Tue, 11 Jan 2022 at 22:09, Peter J. Holzer wrote: > On 2022-01-11 19:49:20 +0100, Marco Sulla wrote: > > I think this is what you mean: > > > > >>> dis.dis("for _ in {1, 2}: pass") > > 1

Doc or example about conda custom build?

2022-01-16 Thread Marco Sulla
Sorry for being maybe a little OT. I tried to get help from other Conda users, from chat and from the mailing list without success. I would add a custom build on my conda package. Is there somewhere a doc or an example about it? (Specifically, I want to pass a custom parameter to the setup.py tha

Re: Pickle segfaults with custom type

2022-01-15 Thread Marco Sulla
Found. I simply forgot: if (PyType_Ready(&PyFrozenDictIterKey_Type) < 0) { goto fail; } in the frozendict_exec function for the module. On Fri, 7 Jan 2022 at 20:27, Marco Sulla wrote: > I have a custom implementation of dict using a C extension. All works but >

Re: Why operations between dict views return a set and not a frozenset?

2022-01-11 Thread Marco Sulla
>> 12 POP_BLOCK >> 14 LOAD_CONST 0 (None) 16 RETURN_VALUE On Tue, 11 Jan 2022 at 01:05, Chris Angelico wrote: > On Tue, Jan 11, 2022 at 10:26 AM Marco Sulla > wrote: > > > > On Wed, 5 Jan 2022 at 23:02, Chris Angelico wrote

Re: Why operations between dict views return a set and not a frozenset?

2022-01-10 Thread Marco Sulla
On Wed, 5 Jan 2022 at 23:02, Chris Angelico wrote: > > On Thu, Jan 6, 2022 at 8:01 AM Marco Sulla > wrote: > > > > On Wed, 5 Jan 2022 at 14:16, Chris Angelico wrote: > > > That's an entirely invisible optimization, but it's more than just > >

Pickle segfaults with custom type

2022-01-07 Thread Marco Sulla
0, obj=obj@entry=0x7f043e1fb0b0, pers_save=pers_save@entry=0) at /home/marco/sources/cpython_3_10/Modules/_pickle.c:4381 #3 0x7f043ce2534d in dump (self=self@entry=0x7f043d8507d0, obj=obj@entry=0x7f043e1fb0b0) at /home/marco/sources/cpython_3_10/Modules/_pickle.c:4515 #4 0x7f043

Re: Why operations between dict views return a set and not a frozenset?

2022-01-05 Thread Marco Sulla
27;m starting to think that neither set nor frozenset are good for dict items: (venv_3_10) marco@buzz:~$ python Python 3.10.0 (heads/3.10-dirty:f6e8b80d20, Nov 18 2021, 19:16:18) [GCC 10.1.1 20200718] on linux Type "help", "copyright", "credits" or "license&

Re: Why operations between dict views return a set and not a frozenset?

2022-01-05 Thread Marco Sulla
On Wed, 5 Jan 2022 at 00:54, Chris Angelico wrote: > That's because a tuple is the correct data type when returning two > distinct items. It's not a list that has two elements in it; it's a > tuple of (key, value). Immutability is irrelevant. Immutability is irrelevant, speed no. A tuple is faste

Re: Why operations between dict views return a set and not a frozenset?

2022-01-04 Thread Marco Sulla
On Tue, 4 Jan 2022 at 19:38, Chris Angelico wrote: > [...] should the keys view be considered > frozen or not? Remember the set of keys can change (when the > underlying dict changes). Well, also the items can change, but they are returned as tuples with 2 elements. It seems to me that the stdli

Why operations between dict views return a set and not a frozenset?

2022-01-04 Thread Marco Sulla
$ python Python 3.10.0 (heads/3.10-dirty:f6e8b80d20, Nov 18 2021, 19:16:18) [GCC 10.1.1 20200718] on linux Type "help", "copyright", "credits" or "license" for more information. >>> a = {1:2} >>> c = {1:2, 3:4} >>> c.keys() - a.keys() {3} >>> Why not frozenset({3})? -- https://mail.python.org/ma

Re: ModuleNotFoundError: No module named 'DistUtilsExtra'

2022-01-02 Thread Marco Sulla
https://askubuntu.com/questions/584857/distutilsextra-problem On Sun, 2 Jan 2022 at 18:52, hongy...@gmail.com wrote: > > On Ubuntu 20.04.3 LTS, I try to install pdfarranger [1] as follows but failed: > > $ sudo apt-get install python3-pip python3-distutils-extra \ >

Who wrote Py_UNREACHABLE?

2022-01-02 Thread Marco Sulla
#if defined(RANDALL_WAS_HERE) # define Py_UNREACHABLE() \ Py_FatalError( \ "If you're seeing this, the code is in what I thought was\n" \ "an unreachable state.\n\n" \ "I could give you advice for what to do, but honestly, why\n" \ "should you trust me? I clear

Re: How to implement freelists in dict 3.10 for previous versions?

2022-01-01 Thread Marco Sulla
Ooookay, I suppose I have to study a little the thing :D On Thu, 30 Dec 2021 at 07:59, Inada Naoki wrote: > > On Wed, Dec 29, 2021 at 7:25 PM Marco Sulla > wrote: > > > > I noticed that now freelists in dict use _Py_dict_state. I suppose > > this is done for thread sa

How to make a type of a C extension compatible with mypy

2022-01-01 Thread Marco Sulla
I created a type in a C extension, that is an immutable dict. If I do: a: mydict[str, str] it works. But it doesn't work with mypy, as signalled to me by an user: https://github.com/Marco-Sulla/python-frozendict/issues/39 How can I make it work? I don't know what he means with

Re: recover pickled data: pickle data was truncated

2022-01-01 Thread Marco Sulla
I agree with Barry. You can create a folder or a file with pseudo-random names. I recommend you to use str(uuid.uuid4()) On Sat, 1 Jan 2022 at 14:11, Barry wrote: > > > > > On 31 Dec 2021, at 17:53, iMath wrote: > > > > 在 2021年12月30日星期四 UTC+8 03:13:21, 写道: > >>> On Wed, 29 Dec 2021 at 18:33, iM

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

2021-12-31 Thread Marco Sulla
It was already done: https://pypi.org/project/tail-recursive/ On Thu, 30 Dec 2021 at 16:00, hongy...@gmail.com wrote: > > I try to compute the factorial of a large number with tail-recursion > optimization decorator in Python3. The following code snippet is converted > from the code snippet giv

Re: recover pickled data: pickle data was truncated

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 18:33, iMath wrote: > But I found the size of the file of the shelve data didn't change much, so I > guess the data are still in it , I just wonder any way to recover my data. I agree with Barry, Chris and Avi. IMHO your data is lost. Unpickling it by hand is a harsh work

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 12:11, Dieter Maurer wrote: > > Marco Sulla wrote at 2021-12-29 11:59 +0100: > >On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: > >> `MutableMapping` is a so called abstract base class (--> `abc`). > >> > >> It uses the `__subcl

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: > `MutableMapping` is a so called abstract base class (--> `abc`). > > It uses the `__subclass_check__` (and `__instance_check__`) of > `abc.ABCMeta` to ensure `issubclass(dict, MutableMapping)`. > Those can be customized by overriding `MutableMap

How to implement freelists in dict 3.10 for previous versions?

2021-12-29 Thread Marco Sulla
I noticed that now freelists in dict use _Py_dict_state. I suppose this is done for thread safety. I would implement it also for a C extension that uses CPython < 3.10. How can I achieve this? -- https://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   5   6   7   8   >