Re: Python/New/Learn

2022-05-05 Thread Chris Angelico
On Fri, 6 May 2022 at 09:53, Grant Edwards wrote: > > On 2022-05-05, Mats Wichmann wrote: > > > Without having any data at all on it, just my impressions, more > > people these days learn from in-person or video experiences. > > I've always been utterly baffled by video tutorials for > programmin

Re: Python/New/Learn

2022-05-04 Thread Chris Angelico
On Thu, 5 May 2022 at 13:14, Avi Gross wrote: > > Chris, > > It was an extremely open-ended question to a forum where > most of the readers are more advanced, at least I think. > > > My library has oodles of Python Books for free to borrow on paper and > return and I have read many of them. There

Re: Python/New/Learn

2022-05-04 Thread Chris Angelico
On Thu, 5 May 2022 at 12:57, Avi Gross via Python-list wrote: > > https://wiki.python.org/moin/PythonBooks > That's an incredibly daunting list, and not something I'd overly strongly recommend, but yes, if you want to get a dead-tree or e-book to read, there are quite a lot of options available.

Re: Python/New/Learn

2022-05-04 Thread Chris Angelico
On Thu, 5 May 2022 at 12:49, Patrick 0511 wrote: > > Hello, I'm completely new here and don't know anything about python. Can > someone tell me how best to start? So what things should I learn first? > I'd start right here with the tutorial! https://docs.python.org/3/tutorial/ Most important t

Re: tail

2022-05-02 Thread Chris Angelico
On Tue, 3 May 2022 at 04:38, Marco Sulla wrote: > > 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,

Re: tail

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 11:54, Cameron Simpson wrote: > > On 01May2022 23:30, Stefan Ram wrote: > >Dan Stromberg writes: > >>But what about Unicode? Are all 10 bytes newlines in Unicode encodings? > > It seems in UTF-8, when a value is above U+007F, it will be > > encoded with bytes that always

Re: new sorting algorithm

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 09:20, Dan Stromberg wrote: > > > On Sun, May 1, 2022 at 1:44 PM Chris Angelico wrote: >> >> On Mon, 2 May 2022 at 06:43, Dan Stromberg wrote: >> > On Sun, May 1, 2022 at 11:10 AM Chris Angelico wrote: >> >> >> &g

Re: tail

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 09:19, Dan Stromberg wrote: > > On Sun, May 1, 2022 at 3:19 PM Cameron Simpson wrote: > > > On 01May2022 18:55, Marco Sulla wrote: > > >Something like this is OK? > > > > Scanning backward for a byte == 10 in ASCII or ISO-8859 seems fine. > > But what about Unicode? Are al

Re: new sorting algorithm

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 01:53, Nas Bayedil wrote: > We believe that using this method to develop completely new, fast > algorithms, approaching the speed of the famous *QuickSort*, the speed of > which cannot be surpassed, but its drawback can be circumvented, in the > sense of stack overflow, on so

Re: Printing Unicode strings in a list

2022-04-30 Thread Chris Angelico
On Sun, 1 May 2022 at 00:03, Vlastimil Brom wrote: > (Even the redundant u prefix from your python2 sample is apparently > accepted, maybe for compatibility reasons.) Yes, for compatibility reasons. It wasn't accepted in Python 3.0, but 3.3 re-added it to make porting easier. It doesn't do anythi

Re: tail

2022-04-24 Thread Chris Angelico
On Mon, 25 Apr 2022 at 01:47, Marco Sulla wrote: > > > > 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 goin

Re: tail

2022-04-24 Thread Chris Angelico
On Sun, 24 Apr 2022 at 21:11, Antoon Pardon wrote: > > > > Op 23/04/2022 om 20:57 schreef Chris Angelico: > > On Sun, 24 Apr 2022 at 04:37, Marco Sulla > > wrote: > >> What about introducing a method for text streams that reads the lines >

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 10:04, Cameron Simpson wrote: > > On 24Apr2022 08:21, Chris Angelico wrote: > >On Sun, 24 Apr 2022 at 08:18, Cameron Simpson wrote: > >> An approach I think you both may have missed: mmap the file and use > >> mmap.rfind(b'\n'

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 08:18, Cameron Simpson wrote: > > On 24Apr2022 07:15, Chris Angelico wrote: > >On Sun, 24 Apr 2022 at 07:13, Marco Sulla > >wrote: > >> Emh, why chunks? My function simply reads byte per byte and compares > >> it to b"\n"

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 08:06, dn wrote: > > On 24/04/2022 09.15, Chris Angelico wrote: > > On Sun, 24 Apr 2022 at 07:13, Marco Sulla > > wrote: > >> > >> On Sat, 23 Apr 2022 at 23:00, Chris Angelico wrote: > >>>>> This is quite ineffici

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 08:03, Peter J. Holzer wrote: > > On 2022-04-24 04:57:20 +1000, 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 > > &

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 07:13, Marco Sulla wrote: > > On Sat, 23 Apr 2022 at 23:00, Chris Angelico wrote: > > > > This is quite inefficient in general. > > > > > > Why inefficient? I think that readlines() will be much slower, not > > > only more t

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 06:41, Marco Sulla wrote: > > 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 li

Re: tail

2022-04-23 Thread Chris Angelico
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 Apache > Commons IO. It's fundamentally difficult to get precise. In general, there are three steps to reading

Re: Style for docstring

2022-04-22 Thread Chris Angelico
On Sat, 23 Apr 2022 at 09:31, Rob Cliffe via Python-list wrote: > > I don't use docstrings much; instead I put a line or two of comments > after the `def ` line. > But my practice in such situations is as per the OP's 3rd suggestion, e.g. > # Returns True if . The point of docstrings is

Re: Style for docstring

2022-04-22 Thread Chris Angelico
On Sat, 23 Apr 2022 at 08:24, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-04-22 at 15:35:15 -0500, > "Michael F. Stemper" wrote: > > > On 22/04/2022 14.59, Chris Angelico wrote: > > > On Sat, 23 Apr 2022 at 05:56, Michael F. Stemper > >

Re: Style for docstring

2022-04-22 Thread Chris Angelico
On Sat, 23 Apr 2022 at 05:56, Michael F. Stemper wrote: > > I'm writing a function that is nearly self-documenting by its name, > but still want to give it a docstring. Which of these would be > best from a stylistic point of view: > > >Tells caller whether or not a permutation is even. > >

Re: code issue

2022-04-21 Thread Chris Angelico
On Fri, 22 Apr 2022 at 04:19, Jack Dangler wrote: > > > On 4/21/22 13:09, Chris Angelico wrote: > > On Fri, 22 Apr 2022 at 03:02, Tola Oj wrote: > >> for i in range(1, n+1): > >> if i % 3 == 0 and i % 5 == 0: > >> print

Re: code issue

2022-04-21 Thread Chris Angelico
On Fri, 22 Apr 2022 at 03:02, Tola Oj wrote: > > for i in range(1, n+1): > if i % 3 == 0 and i % 5 == 0: > print("Fizzbuzz") > elif i % 3 == 0: > print("Fizz") > elif i % 5 == 0: > print("Buzz") > else: > print(i) >

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 13:23, Abdur-Rahmaan Janhangeer wrote: > > Assumes checking for object equality before inserting. > If they are they same, do we need different hashes? > The point of the hash is to find things that are equal. That's why 1234, 1234.0, and 0j+1234.0 all have the same hash.

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 06:20, Avi Gross via Python-list wrote: > > This does raise an issue, Chris, if you use the method of making a tuple > companion for a list at a specific time just for use as a dictionary key, > then later change the list, you can end up with various situations. > Yes. An

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 05:30, Sam Ezeh wrote: > > Repeating the above points, here is an example of what would happen if > you tried. Dictionaries require their keys to be immutable as > under-the-hood they use hash tables and they'd fail when the > underlying values are allowed to change. > > ```

Re: Why no list as dict key?

2022-04-20 Thread Chris Angelico
On Thu, 21 Apr 2022 at 04:23, Abdur-Rahmaan Janhangeer wrote: > > Greetings list, Greetings tuple, > Using Python3.9, i cannot assign a list [1, 2] as key > to a dictionary. Why is that so? Thanks in advanced! > Because a list can be changed, which would change what it's equal to: >>> spam = [

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

2022-04-19 Thread Chris Angelico
On Wed, 20 Apr 2022 at 02:16, Loris Bennett wrote: > I now realise that timedelta is not really what I need. I am interested > solely in pure periods, i.e. numbers of seconds, that I can convert back > and forth from a format such as > > 11-22::44:55 > > (These are the lengths of time a job has

Re: Pre-Pre-PEP: The datetime.timedeltacal class

2022-04-17 Thread Chris Angelico
On Sun, 17 Apr 2022 at 18:17, Peter J. Holzer wrote: > > On 2022-04-17 06:08:54 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 03:37, Peter J. Holzer wrote: > > > Datetime arithmetic in the real world is typically not done in seconds, > > > but in calend

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 08:37, Dennis Lee Bieber wrote: > And proposals to make > DST permanent year round -- so "noon" (1200hrs) is not "noon" (sun at > zenith) pretty much anywhere. > Noon isn't precisely zenith anyway, for several reasons: 1) Time zones synchronize their clocks on the mean noo

Re: Tuple unpacking inside lambda expressions

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 07:37, Sam Ezeh wrote: > > Two questions here. > > Firstly, does anybody know of existing discussions (e.g. on here or on > python-ideas) relating to unpacking inside lambda expressions? > > I found myself wanting to write the following. > > ``` > map( > lambda (module,

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 05:38, Peter J. Holzer wrote: > > On 2022-04-17 02:46:38 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer wrote: > > > For adding a datetime and timedelta I think the answer is clear. > > > But subtract

Re: Pre-Pre-PEP: The datetime.timedeltacal class

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 03:37, Peter J. Holzer wrote: > Datetime arithmetic in the real world is typically not done in seconds, > but in calendaric units: Hours, days, weeks, months, years, ... > The problem is that several of these have varying lengths: > > * 1 minute may be 60 or 61 seconds (theo

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 03:52, Peter J. Holzer wrote: > > On 2022-04-17 02:46:38 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer wrote: > > > On 2022-04-17 02:14:44 +1000, Chris Angelico wrote: > > > > So which one is it? Which one

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer wrote: > > On 2022-04-17 02:14:44 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer wrote: > > > On the contrary. When a datetime is timezone aware, it must use that > > > timezone's

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer wrote: > > On 2022-04-16 14:22:04 -, Jon Ribbens via Python-list wrote: > > timedelta(days=1) is 24 hours (as you can check by > > calling timedelta(days=1).total_seconds() ), > > It shouldn't be. 1 Day is not 24 hours in the real world. > > > but

Re: Functionality like local static in C

2022-04-15 Thread Chris Angelico
On Sat, 16 Apr 2022 at 04:51, Python wrote: > > Cecil Westerhof wrote: > > In C when you declare a variable static in a function, the variable > > retains its value between function calls. > > The first time the function is called it has the default value (0 for > > an int). > > But when the funct

Re: code confusion

2022-04-15 Thread Chris Angelico
On Fri, 15 Apr 2022 at 17:42, Tola Oj wrote: > > i = int(input()) > lis = list(map(int,input().strip().split()))[:i] > z = max(lis) > while max(lis) == z: > lis.remove(max(lis)) > > print (max(lis)) > > this is an answer to a question from the discussion chat in hackerrank. i > didn't know the ans

Re: Functionality like local static in C

2022-04-14 Thread Chris Angelico
On Fri, 15 Apr 2022 at 03:53, Sam Ezeh wrote: > > I've seen people use function attributes for this. > ``` > Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> def function(): > ... print(function.var

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

2022-04-14 Thread Chris Angelico
On Fri, 15 Apr 2022 at 00:54, Loris Bennett wrote: > > Hi, > > With Python 3.9.2 I get > > $ import datetime > $ s = "1-00:01:01" > $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S") > $ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute, > seconds=t.second) > $ d.days >

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

2022-04-14 Thread Chris Angelico
On Fri, 15 Apr 2022 at 03:45, Marco Sulla wrote: > > 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

python-list@python.org

2022-04-13 Thread Chris Angelico
On Thu, 14 Apr 2022 at 11:00, Kevin M. Wilson via Python-list wrote: > > > > > > MS Edge settings are displayed in the first picture, the error I encountered > is the second picture...not sure how I get around this!I reloaded the browser > after checking the settings for JavaScript...confused. >

Re: Circular Import

2022-04-12 Thread Chris Angelico
On Wed, 13 Apr 2022 at 03:37, Stefano Ovus wrote: > > found a solution: importing modules instead of classes, ex. > > -- square.py > > import circle > > ... > @classmethod > def from_circle(cls, circle: circle.Circle) -> Square: > ... > return cls(...) Yep! Good solution. Be aware that

Re: Comparing sequences with range objects

2022-04-07 Thread Chris Angelico
On Fri, 8 Apr 2022 at 16:26, Peter J. Holzer wrote: > Unless you have a unique immutable identifier that's enforced by > some authority (like a social security number[1]), I don't think there > is a chance to do that reliably in a program (although with enough data, > a heuristic may be good enoug

Re: dict.get_deep()

2022-04-03 Thread Chris Angelico
On Mon, 4 Apr 2022 at 05:19, Marco Sulla wrote: > > 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

Re: dict.get_deep()

2022-04-03 Thread Chris Angelico
On Mon, 4 Apr 2022 at 00: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 > Pydantic models) > > For

Re: 'äÄöÖüÜ' in Unicode (utf-8)

2022-04-01 Thread Chris Angelico
On Fri, 1 Apr 2022 at 11:16, Dennis Lee Bieber wrote: > > On Fri, 1 Apr 2022 03:59:32 +1100, Chris Angelico > declaimed the following: > > > >That's jmf. Ignore him. He knows nothing about Unicode and is > >determined to make everyone aware of that fact. > &

Re: 'äÄöÖüÜ' in Unicode (utf-8)

2022-03-31 Thread Chris Angelico
On Fri, 1 Apr 2022 at 03:45, Dennis Lee Bieber wrote: > > On Thu, 31 Mar 2022 00:36:10 -0700 (PDT), moi > declaimed the following: > > 'äÄöÖüÜ'.encode('utf-8') > >b'\xc3\xa4\xc3\x84\xc3\xb6\xc3\x96\xc3\xbc\xc3\x9c' > len('äÄöÖüÜ'.encode('utf-8')) > >12 > > ? > > Is the

Re: Add a method to list the current named logging levels

2022-03-30 Thread Chris Angelico
On Thu, 31 Mar 2022 at 03:33, Edward Spencer wrote: > > 在 2022年3月30日星期三 UTC+1 16:38:26, 写道: > > > On 30 Mar 2022, at 16:11, Edward Spencer wrote: > > > > > > 在 2021年9月3日星期五 UTC+1 18:50:51, 写道: > > On 2 Sep 2021, at 23:38, Dieter Maurer wrote: > > >>> > > >>> Edward Spencer wrote at 2021-9

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-28 Thread Chris Angelico
On Tue, 29 Mar 2022 at 09:04, Cameron Simpson wrote: > > On 29Mar2022 06:10, Chris Angelico wrote: > >On Tue, 29 Mar 2022 at 06:08, Christian Gollwitzer wrote: > >> Am 28.03.22 um 20:03 schrieb Chris Angelico: > >> > Would you accept a solutio

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-28 Thread Chris Angelico
On Tue, 29 Mar 2022 at 06:08, Christian Gollwitzer wrote: > > Am 28.03.22 um 20:03 schrieb Chris Angelico: > > Would you accept a solution that involves a subprocess call? > > > > wmctrl -ir {id} -b add,sticky > > > > Now, the only problem is... figuring out y

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-28 Thread Chris Angelico
On Tue, 29 Mar 2022 at 02:56, Skip Montanaro wrote: > > > I might be misguided, but on modern desktops that should be possible > > with a few mouseclicks. E.g. in KDE, there is a little pin icon > > displayed in every title bar of a toplevel window on the left side. > > Correct, and that's what I'

Re: for convenience

2022-03-24 Thread Chris Angelico
On Fri, 25 Mar 2022 at 10:44, Avi Gross wrote: > But would it be helpful? Maybe. I am thinking back to decades ago when I > did C and C++ programming and how we used it. It was way more that just: > > #DEFINE TIMEZONE 5 > > The above use is sort of to create a constant. What we often used was ways

Re: for convenience

2022-03-24 Thread Chris Angelico
On Fri, 25 Mar 2022 at 06:05, Grant Edwards wrote: > > On 2022-03-24, Chris Angelico wrote: > > > No, I would say that a preprocessor of that sort isn't necessary to a > > Python-like language. If you really want one, it's honestly not that > > hard to do; r

Re: for convenience

2022-03-24 Thread Chris Angelico
On Fri, 25 Mar 2022 at 04:15, Avi Gross via Python-list wrote: > Python made lots of choices early on and then tried to graft on ever more > features, sometimes well and sometimes not optimally. The same is true > for so many other languages. A carefully designed new language built now > might ana

Re: asyncio+tkinter

2022-03-21 Thread Chris Angelico
On Tue, 22 Mar 2022 at 10:52, Skip Montanaro wrote: > > Given that both asyncio & tkinter are modules in the standard lib and both > have event loops, I would have expected to find some "best practice" > solution to mixing the two. I've not used asyncio, but might find it useful > with the pynput

Re: for convenience

2022-03-21 Thread Chris Angelico
On Tue, 22 Mar 2022 at 08:13, Paul St George wrote: > > > When I am writing code, I often do things like this: > > context = bpy.context # convenience > > then whenever I need bpy.context, I only need to write context > > > Here’s my question: > > When I forget to use the convenient shorter form

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Chris Angelico
On Sat, 19 Mar 2022 at 14:06, Greg Ewing wrote: > > On 19/03/22 9:40 am, Rathmann wrote: > > The other challenge/question would be to see if there is a way to implement > > this basic approach with lower overhead. > > My original implementation of yield-from didn't have this problem, > because it

Re: Best practice for caching hash

2022-03-16 Thread Chris Angelico
On Wed, 16 Mar 2022 at 18:48, Cameron Simpson wrote: > > On 16Mar2022 16:58, Chris Angelico wrote: > >On Wed, 16 Mar 2022 at 14:00, Cameron Simpson wrote: > >> On 16Mar2022 10:57, Chris Angelico wrote: > >> A significant difference is that tuples have no keys, u

Re: Best practice for caching hash

2022-03-15 Thread Chris Angelico
On Wed, 16 Mar 2022 at 14:00, Cameron Simpson wrote: > > On 16Mar2022 10:57, Chris Angelico 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 m

Re: Best practice for caching hash

2022-03-15 Thread Chris Angelico
On Wed, 16 Mar 2022 at 10:42, Cameron Simpson wrote: > > On 12Mar2022 21:45, Marco Sulla wrote: > >I have a custom immutable object, and I added a cache for its hash > >value. The problem is the object can be composed of mutable or > >immutable objects, so the hash can raise TypeError. > > Is it

Re: Weird strace of #! python script

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 08:28, Dan Stromberg wrote: > > Hi folks. > > First off, I know, python2 is ancient history. Porting to 3.x is on my > list of things to do (though I'm afraid it's not yet at the top of the > list), and the same thing happens with python3. > > So anyway, I'm strace'ing a #!

Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 10:41, Jen Kris wrote: > > > Thanks for PySequence_InPlaceConcat, so when I need to extend I'll know what > to use. But my previous email was based on incorrect information from > several SO posts that claimed only the extend method will work to add tuples > to a list.

Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 10:30, Jen Kris wrote: > > > Chris, you were right to focus on the list pDictData itself. As I said, > that is a list of 2-tuples, but I added each of the 2-tuples with > PyList_Append, but you can only append a tuple to a list with the extend > method. However, there

Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 08:54, Jen Kris wrote: > > > pDictData, despite the name, is a list of 2-tuples where each 2-tuple is a > dictionary object and a string. > Ah, gotcha. In that case, yeah, slicing it will involve referencing the tuples all the way down the line (adding to their refcounts,

Re: Problem slicing a list with the C API

2022-03-12 Thread Chris Angelico
On Sun, 13 Mar 2022 at 08:25, Jen Kris via Python-list wrote: > PyObject* slice = PySlice_New(PyLong_FromLong(0), half_slice, 0); > PyObject* subdata_a = PyObject_GetItem(pDictddata, slice); > > On the final line (subdata_a) I get a segfault. I know that the second > parameter of PyObject_GetIt

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

2022-03-11 Thread Chris Angelico
On Fri, 11 Mar 2022 at 19:57, Roel Schroeven wrote: > > Op 11/03/2022 om 3:50 schreef Chris Angelico: > > On Fri, 11 Mar 2022 at 09:51, Cousin Stanley > > wrote: > > > The following will display a list of lxqt packages > > > that are in the

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

2022-03-10 Thread Chris Angelico
On Fri, 11 Mar 2022 at 16:39, Dan Stromberg wrote: > Some folks say the desktop environment matters more than the distribution, > when choosing what OS to install. Matters more to the choice? Impossible to say. Matters more to the UI? Without a doubt. ChrisA -- https://mail.python.org/mailman/

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

2022-03-10 Thread Chris Angelico
On Fri, 11 Mar 2022 at 09:51, Cousin Stanley wrote: > > Marco Sulla wrote: > > >> > >> Maybe Debian itself? > > > > I tried Debian on a VM, but I found it too much basical. A little > > example: it does not have the shortcut ctrl+alt+t to open a terminal > > that Ubuntu has. I'm quite sure it's si

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

2022-03-10 Thread Chris Angelico
On Fri, 11 Mar 2022 at 00:05, Marco Sulla wrote: > > 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

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Chris Angelico
On Tue, 8 Mar 2022 at 04:13, Jen Kris wrote: > > > The PyObject str_sentence is a string representation of a list. I need to > convert the list to a string like "".join because that's what the library > call takes. > What you're doing is the equivalent of str(sentence), not "".join(sentence).

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Chris Angelico
On Tue, 8 Mar 2022 at 04:06, Jen Kris via Python-list wrote: > But with the C API it looks like this: > > PyObject *pSentence = PySequence_GetItem(pSents, sent_count); > PyObject* str_sentence = PyObject_Str(pSentence); // Convert to string > > PyObject* repr_str = PyObject_Repr(str_sentence); Y

Re: Behavior of the for-else construct

2022-03-06 Thread Chris Angelico
On Mon, 7 Mar 2022 at 09:51, Avi Gross via Python-list wrote: > > >>> > Pascal versus PASCAL versus pascal (not versus paschal) and > Perl versus PERL versus perl (not versus pearl) > > seems to be a topic. > <<< > > The nitpickers here are irrelevant. I happen to know how things are formally > s

Re: Execute in a multiprocessing child dynamic code loaded by the parent process

2022-03-06 Thread Chris Angelico
On Mon, 7 Mar 2022 at 07:37, Martin Di Paola wrote: > > > > > > >The way you've described it, it's a hack. Allow me to slightly redescribe it. > > > >modules = loader() > >objs = init(modules) > > > >def invoke(mod, func): > ># I'm assuming that the loader is smart enough to not load > >#

Re: Execute in a multiprocessing child dynamic code loaded by the parent process

2022-03-06 Thread Chris Angelico
On Sun, 6 Mar 2022 at 23:43, Martin Di Paola wrote: > > Hi everyone. I implemented time ago a small plugin engine to load code > dynamically. > > So far it worked well but a few days ago an user told me that he wasn't > able to run in parallel a piece of code in MacOS. > > He was using multiproces

Re: Behavior of the for-else construct

2022-03-04 Thread Chris Angelico
On Sat, 5 Mar 2022 at 10:28, Peter J. Holzer wrote: > > On 2022-03-04 11:34:07 +1100, Chris Angelico wrote: > > On Fri, 4 Mar 2022 at 10:09, Avi Gross via Python-list > > wrote: > > > The drumbeat I keep hearing is that some people hear/see the same > > > word

Re: Behavior of the for-else construct

2022-03-04 Thread Chris Angelico
On Sat, 5 Mar 2022 at 07:52, Avi Gross wrote: > > Chris, > > My example was precisely what to do when it is an empty closet: Does it correctly handle a closet with shirts in it, though? There's not a lot of point demonstrating an alternate use for the "else" clause when it is *absolutely identic

Re: Behavior of the for-else construct

2022-03-04 Thread Chris Angelico
On Sat, 5 Mar 2022 at 03:44, Avi Gross via Python-list wrote: > > Dieter, > > Your use is creative albeit it is not "needed" since all it does is make sure > your variable is initialized to something, specifically None. > > So would this not do the same thing? > > eye = None > > for eye in ra

Re: Behavior of the for-else construct

2022-03-04 Thread Chris Angelico
On Sat, 5 Mar 2022 at 02:02, Tim Chase wrote: > > On 2022-03-04 11:55, Chris Angelico wrote: > > In MS-DOS, it was perfectly possible to have spaces in file names > > DOS didn't allow space (0x20) in filenames unless you hacked it by > hex-editing your filesystem (whic

Re: Behavior of the for-else construct

2022-03-04 Thread Chris Angelico
On Fri, 4 Mar 2022 at 21:02, gene heskett wrote: > That makes the logic work, but who then cleans up the trash on the stack. > Thats a memory leak. > Not sure I follow? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 18:13, Dieter Maurer wrote: > > Rob Cliffe wrote at 2022-3-4 00:13 +: > >I find it so hard to remember what `for ... else` means that on the very > >few occasions I have used it, I ALWAYS put a comment alongside/below the > >`else` to remind myself (and anyone else unfort

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 14:37, Avi Gross via Python-list wrote: > > That is one way to look at it, Jach. Of course, a particular loop may have > multiple break statements each meaning something else. The current > implementation makes all of them jump to the same ELSE statement so in one > sense,

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 14:05, Avi Gross via Python-list wrote: > To answer something Chris said and was also mentioned here, I do not consider > language design to be easy let alone implementing it. Not at all. BUT I think > some changes can be straightforward. Having a symbol like a curly brace

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 11:39, Avi Gross via Python-list wrote: > > Rob, > > I regularly code with lots of comments like the one you describe, or mark the > end of a region that started on an earlier screen such as a deeply nested > construct. > > I have had problems though when I have shared such

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 11:14, Rob Cliffe via Python-list wrote: > > I find it so hard to remember what `for ... else` means that on the very > few occasions I have used it, I ALWAYS put a comment alongside/below the > `else` to remind myself (and anyone else unfortunate enough to read my > code) wh

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 10:09, Avi Gross via Python-list wrote: > > The drumbeat I keep hearing is that some people hear/see the same word as > implying something else. ELSE is ambiguous in the context it is used. > What I'm hearing is that there are, broadly speaking, two types of programmers [1]

Re: Timezone jokes (was: All permutations from 2 lists)

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 03:29, Tim Chase wrote: > > On 2022-03-03 06:27, Grant Edwards wrote: > > On 2022-03-03, Chris Angelico wrote: > > > Awww, I was going to make a really bad joke about timezones :) > > > > As opposed to all the really good jokes about timez

Re: Behavior of the for-else construct

2022-03-03 Thread Chris Angelico
On Fri, 4 Mar 2022 at 00:25, computermaster360 wrote: > > I want to make a little survey here. > > Do you find the for-else construct useful? Have you used it in > practice? Do you even know how it works, or that there is such a thing > in Python? Yes, yes, and yes-yes. It's extremely useful. >

Re: All permutations from 2 lists

2022-03-02 Thread Chris Angelico
On Thu, 3 Mar 2022 at 13:05, gene heskett wrote: > I take it back, kmail5 had decided it was a different thread. My bad, no > biscuit. > Awww, I was going to make a really bad joke about timezones :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: All permutations from 2 lists

2022-03-02 Thread Chris Angelico
On Wed, 2 Mar 2022 at 19:34, Peter Otten <__pete...@web.de> wrote: > > On 02/03/2022 01:32, Rob Cliffe via Python-list wrote: > > > itertools.product returns an iterator (or iterable, I'm not sure of the > > correct technical term). > > There's a simple test: > > iter(x) is x --> True # iterator >

Re: Timezone for datetime.date objects

2022-03-01 Thread Chris Angelico
On Tue, 1 Mar 2022 at 22:52, Morten W. Petersen wrote: > Yep. Well, as I said, I could create some range objects myself, and even > create a little module and put it up on pypi, if I couldn't find any existing > module I could use. > > As we're discussing this, it is clear that different point

Re: Timezone for datetime.date objects

2022-02-28 Thread Chris Angelico
On Tue, 1 Mar 2022 at 09:28, Morten W. Petersen wrote: > > Hi Chris, Cameron. > > Well, let's say I specify the datetime 2022-02-22 02:02 (AM). I think > everyone could agree that it also means 2022-02-22 02:02:00:00, to 2022-02-22 > 02:02:59:59. > Not sure how many :59s you want there :) I'm g

Re: Timezone for datetime.date objects

2022-02-27 Thread Chris Angelico
On Mon, 28 Feb 2022 at 08:51, Cameron Simpson wrote: > > On 27Feb2022 11:16, Morten W. Petersen wrote: > >I was initially using the date object to get the right timespan, but > >then > >found that using the right timezone with that was a bit of a pain. So I > >went for the datetime object instea

Re: One-liner to merge lists?

2022-02-27 Thread Chris Angelico
On Mon, 28 Feb 2022 at 03:24, MRAB wrote: > > On 2022-02-27 08:51, Barry Scott wrote: > > > > > >> On 22 Feb 2022, at 09:30, Chris Angelico wrote: > >> > >> On Tue, 22 Feb 2022 at 20:24, Frank Millman >> <mailto:fr...@chagford.com>> wr

Re: One-liner to merge lists?

2022-02-26 Thread Chris Angelico
On Sun, 27 Feb 2022 at 16:35, Dan Stromberg wrote: > > > On Fri, Feb 25, 2022 at 3:15 PM Chris Angelico wrote: >> >> But ultimately, that's still the same as sum(), and it's no more >> readable than chain(), so I'd still be inclined to go with chain and

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 15:39, Avi Gross via Python-list wrote: > Take interpreted languages including Python and R that specify all kinds of > functions that may be written within the language at first. Someone may > implement a function like sum() (just an example) that looks like the sum of >

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 14:35, Avi Gross via Python-list wrote: > But with numpy and more available anyway, it may not be necessary to reinvent > much of that. I was just wondering if it ever made sense to simply include it > in the base python, perhaps as a second executable with a name like pyt

Re: One-liner to merge lists?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 10:05, Albert-Jan Roskam wrote: >Was also thinking about reduce, though this one uses a dunder method: >from functools import reduce >d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} >print(reduce(list.__add__, list(d.values( If you don't want to use th

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 09:58, Richard Damon wrote: > > On 2/25/22 2:47 PM, Chris Angelico wrote: > > On Sat, 26 Feb 2022 at 05:49, Richard Damon > > wrote: > >> On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: > >>> Hi, > >>> a lot of people

<    1   2   3   4   5   6   7   8   9   10   >