Re: object.enable() anti-pattern

2013-05-09 Thread Greg Ewing
Cameron Simpson wrote: You open a file with "0" modes, so that it is _immediately_ not writable. Other attempts to make the lock file thus fail because of the lack of write, I don't think that's quite right. You open it with O_CREAT+O_EXCL, which atomically fails if the file already exists. The

Re: object.enable() anti-pattern

2013-05-12 Thread Greg Ewing
Wayne Werner wrote: On Fri, 10 May 2013, Gregory Ewing wrote: f = open("myfile.dat") f.close() data = f.read() To clarify - you don't want a class that has functions that need to be called in a certain order with *valid input* in order to not crash. Exactly what does happen - a Value

Re: Multi-dimensional list initialization

2012-11-07 Thread Greg Ewing
On 08/11/12 12:06, Oscar Benjamin wrote: On 7 November 2012 22:16, Joshua Landau wrote: That said, losing: [0] * (2, 3) == [0] * [2, 3] would mean losing duck-typing in general. There are precedents for this kind of thing; the string % operator treats tuples specially, for example. I don't t

ANN: PyGUI 2.5

2011-06-17 Thread Greg Ewing
PyGUI 2.5 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Lots of new stuff in this version. Highlights include: - Improved facilities for customising the standard menus. - Functions for creating PyGUI Images from PIL images and numpy arrays. - ListButton - a pop

ANN: PyGUI 2.5.3

2011-07-16 Thread Greg Ewing
PyGUI 2.5.3 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Clipboard access now implemented on MacOSX, plus a few bug fixes. What is PyGUI? -- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewin

ANN: PyGUI 2.4

2011-03-19 Thread Greg Ewing
PyGUI 2.4 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Highlights of this release: * Python 3 Compatible on MacOSX and Windows. * ScrollableView has been overhauled on Windows and should now work with all builds of pywin32 as far as I know. What is PyGUI? ---

Re: Feature suggestion -- return if true

2011-04-17 Thread Greg Ewing
D'Arcy J.M. Cain wrote: On Sun, 17 Apr 2011 16:21:53 +1200 Gregory Ewing wrote: def get_from_cache(x): y = cache.get(x) if not y: y = compute_from(x) cache[x] = y return y I prefer not to create and destroy objects needlessly. How does that create objects needless

ANN: SuPy 1.6 for Snow Leopard and Python 2.7

2011-04-24 Thread Greg Ewing
for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ew...@canterbury.ac.nz -- http://mail.python.org/mailman/listinfo/python-list

Re: "help( pi )"

2017-11-19 Thread Greg Ewing
Cameron Simpson wrote: Unless one had a misfortune and wanted another docstring. Good point. I guess having differing docstrings should make otherwise equal objects ineligible for merging. mod1.py: MAX_BUFSIZE = 8192 MAX_BUFSIZE.__doc__ = 'Size of the hardware buffer used for I/O on t

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

2022-04-16 Thread Greg Ewing
On 17/04/22 9:17 am, Karsten Hilbert wrote: Take this medication for 1 month ! is quite likely to mean "take it for 28 days". Except when your doctor prescribes 90 days worth of tablets, they come boxes of 84 (6 cards * 14 tablets), and the pharmacist dutifully opens a box, cuts off an

Re: Why no list as dict key?

2022-04-20 Thread Greg Ewing
On 21/04/22 6:22 am, Abdur-Rahmaan Janhangeer wrote: Using Python3.9, i cannot assign a list [1, 2] as key to a dictionary. Why is that so? If the contents of the list were to change after using it as a key, its hash value would no longer match its position in the dict, so subsequent lookups co

Re: Why no list as dict key?

2022-04-20 Thread Greg Ewing
On 21/04/22 8:18 am, Avi Gross wrote: I am thinking as an example about a program I wrote ages ago that deals with equations in symbolic form and maintains a collection of forms of the equation it is trying to take a derivative or integral of by applying an assortment of typographic rules. I

Re: code issue

2022-04-21 Thread Greg Ewing
On 22/04/22 5:09 am, Chris Angelico wrote: This can't be your complete code, because it won't run like this. Also, the output you showed contains blank lines and lines with hyphens, and there is nothing in the code you posted which does that. If I had to guess, I'd say you have a loop which is

Re: Enums and nested classes

2022-04-21 Thread Greg Ewing
On 20/04/22 10:57 pm, Sam Ezeh wrote: Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) That's a pretty open-ended question. Is there something about

Re: Python/New/Learn

2022-05-06 Thread Greg Ewing
On 7/05/22 12:27 pm, Stefan Ram wrote: But when you read descriptions in books about phonology about how the mouth and tongue is positioned to produce certain sounds and see pictures of this, your faulty ears are bypassed and you get a chance to produce the correct sounds of the fo

Re: Seeking deeper understanding of python equality (==)

2022-05-06 Thread Greg Ewing
On 7/05/22 12:22 am, Jonathan Kaczynski wrote: Stepping through the code with gdb, we see it jump from the compare operator to the dunder-eq method on the UUID object. What I want to be able to do is explain the in-between steps. Generally what happens with infix operators is that the interpret

Re: tail

2022-05-09 Thread Greg Ewing
On 9/05/22 7:47 am, Marco Sulla wrote: It will fail if the contents is not ASCII. Why? For some encodings, if you seek to an arbitrary byte position and then read, it may *appear* to succeed but give you complete gibberish. Your method might work for a certain subset of encodings (those that

Re: Changing calling sequence

2022-05-15 Thread Greg Ewing
On 16/05/22 1:20 am, 2qdxy4rzwzuui...@potatochowder.com wrote: IMO, classmethods were/are a bad idea (yes, I'm probably in the minority around here, but someone has to be). I don't think class methods are a bad idea per se, but having them visible through instances seems unnecessary and confusi

Re: min, max with position

2022-06-04 Thread Greg Ewing
On 5/06/22 10:07 am, dn wrote: On 05/06/2022 09.50, Chris Angelico wrote: min(enumerate(l), key=lambda x: x[1]) (0, 1.618033) But, but, but which of the above characters is an 'el' and which a 'one'??? (please have pity on us old f...s and the visually-challenged!) ell = l one = 1 min(enum

Re: How to replace characters in a string?

2022-06-08 Thread Greg Ewing
On 8/06/22 10:26 pm, Jon Ribbens wrote: Here's a head-start on some characters you might want to translate, Another possibility that might make sense in this case is to simply strip out all punctuation before comparing. That would take care of things being spelled with or without hyphens, comma

Re: How to replace characters in a string?

2022-06-08 Thread Greg Ewing
On 9/06/22 5:55 am, Dennis Lee Bieber wrote: There are no mutable strings in Python. If you really want a mutable sequence of characters, you can use array.array, but you won't be able to use it directly in place of a string in most contexts. -- Greg -- https://mail.python.org/mailma

Re: fill out bulletins

2022-06-13 Thread Greg Ewing
Another possibility is to use reportlab to generate a pdf. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: mapLast, mapFirst, and just general iterator questions

2022-06-14 Thread Greg Ewing
On 15/06/22 7:49 am, Chris Angelico wrote: If it does need to be used as a module as well as a script, sure. But (a) not everything does, and (b) even then, you don't need a main() I think this is very much a matter of taste. Personally I find it tidier to put the top level code in a function,

Re: "CPython"

2022-06-21 Thread Greg Ewing
On 21/06/22 2:52 pm, Avi Gross wrote: This leads to the extremely important question of what would an implementation of Python, written completely in C++, be called? (Pronounced with a comical stutter) "C-p-p-python!") -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: "CPython"

2022-06-21 Thread Greg Ewing
On 21/06/22 2:38 pm, Paulo da Silva wrote: Notice that they are, for example, Jython and not JPython. Jython *was* originally called JPython, but that was judged to be a trademark violation and they were made to change it. I don't know how MicroPython has escaped the same fate to date. -- Gre

Re: "CPython"

2022-06-21 Thread Greg Ewing
On 21/06/22 2:56 pm, Paulo da Silva wrote: Let's say they reimplement "reference python" CPython in Rust. What is better? Change the "reference python" CPython name to RPython, for example, or let it as CPython? The C implementation would still be called CPython, and the new implementation mig

Re: "CPython"

2022-06-21 Thread Greg Ewing
On 21/06/22 9:27 pm, Paul Rubin wrote: What? I never heard of such a dispute. The PSF got after someone about it? Sheesh. Upon further research, it seems it wasn't the *Python* trademark that was at issue. From the Jython FAQ page: 1.2 How does Jython relate to JPython? Jython is the su

Re: "CPython"

2022-06-21 Thread Greg Ewing
On 21/06/22 8:37 pm, Christian Gollwitzer wrote: Am 20.06.22 um 22:47 schrieb Roel Schroeven: "CPython is a descendant of Pyscript built on Pyodide, a port of CPython, or a Python distribution for the browser and Node.js that is based on Webassembly and Emscripten." To me, this sentence is so

Re: "CPython"

2022-06-21 Thread Greg Ewing
On 22/06/22 4:42 am, MRAB wrote: On 2022-06-21 03:52, Avi Gross via Python-list wrote: This leads to the extremely important question of what would an implementation of Python, written completely in C++, be called? C++Python CPython++ C+Python+ DPython SeaPython? SeeSeaSiPython CincPython?

Re: Question about learning Python

2022-09-09 Thread Greg Ewing
On 8/09/22 6:57 am, Chris Angelico wrote: Not as detrimental as starting with BASIC, and then moving on to x86 assembly language, and trying to massage the two together using CALL ABSOLUTE in order to get mouse input in your GW-BASIC programs. Or starting with hand-assembled SC/MP machine code

Re: PyObject_CallFunctionObjArgs segfaults

2022-09-30 Thread Greg Ewing
On 1/10/22 8:18 am, MRAB wrote: It's OK to INCREF them, provided that you DECREF them when you no longer need them, and remember that if it's a "new reference" you'd need to DECREF it twice. Which means there would usually be no point in doing the extra INCREF/DECREF. You still need to know wh

Re: Changing 'Scripts/*.exe'

2022-10-04 Thread Greg Ewing
On 4/10/22 10:49 pm, 2qdxy4rzwzuui...@potatochowder.com wrote: (I could even move the file to another folder on the original Mac, but that didn't mean much, because those old file systems were entirely flat (directories and folders were an illusion maintained by the Finder) That was only true i

Re: an oop question

2022-11-02 Thread Greg Ewing
On 2/11/22 9:54 am, Julieta Shem wrote: But we've left behind a more basic requirement --- the Stack class wishes for all the methods already written in some class called Pair, Is that *really* what you want, though? To my way of thinking, a Stack and a Pair are quite different data structures

Re: an oop question

2022-11-02 Thread Greg Ewing
On 3/11/22 1:37 pm, Julieta Shem wrote: The code for computing the length of a Pair (which is really a linked list) happens to be the same for computing the length of a Stack. I would question whether that should be a method of Pair at all, since it's not the length of the pair itself, but the

Re: an oop question

2022-11-04 Thread Greg Ewing
On 4/11/22 1:29 am, Julieta Shem wrote: Perhaps I can reduce the class Pair to just being a pair as we know it, made of two things, then we create a class called Sequence, which is really a composition of Pairs, comes with a length method and we derive Stack from it. That sounds better. But be

Re: an oop question

2022-11-04 Thread Greg Ewing
On 4/11/22 12:50 am, Chris Angelico wrote: In Python, everything is an object. Doesn't that equally mean that Python is purely OOP? Depends on what you mean by "purely oop". To me it suggests a language in which dynamically-dispatched methods are the only form of code. Python is not one of thos

Re: an oop question

2022-11-04 Thread Greg Ewing
r...@zedat.fu-berlin.de (Stefan Ram) writes [that Barbara Liskov said]: |If for each object o1 of type S there is an object o2 of |type T such that for all programs P defined in terms of T, |the behavior of P is unchanged when o1 is substituted for o2 |then S is a subtype of T. That seems over

Re: an oop question

2022-11-04 Thread Greg Ewing
On 4/11/22 7:51 am, Julieta Shem wrote: (The empty documentation seems to satisfy the principle.) All the more reason to document your classes! More seriously, there's always at least a (possibly fuzzily) implied contract, because of the names you choose for things if nothing else. -- Greg -

Re: an oop question

2022-11-04 Thread Greg Ewing
On 5/11/22 4:25 am, Chris Angelico wrote: Maybe it's one of those terms that is useless for actual coding (because practicality beats purity), but good for discussions? I'm not sure it's much good for discussions, either. I don't really care whether a language is "purely OO" or not, whatever th

Re: In code, list.clear doesn't throw error - it's just ignored

2022-11-13 Thread Greg Ewing
On 14/11/22 1:31 pm, Jon Ribbens wrote: On 2022-11-13, DFS wrote: But why is it allowed in the first place? Because it's an expression, and you're allowed to execute expressions. To put it a bit more clearly, you're allowed to evaluate an expression and ignore the result. -- Greg -- https

Re: In code, list.clear doesn't throw error - it's just ignored

2022-11-13 Thread Greg Ewing
On 14/11/22 3:13 pm, MRAB wrote: But if it's an expression where it's expecting a statement and it's not a call, then it's probably a bug. The key word there is "probably". If there's any chance it could be not a bug, it can't be an error. At most it should be a warning, and that's what linters

Re: String to Float, without introducing errors

2022-12-18 Thread Greg Ewing
On 19/12/22 6:35 am, Paul St George wrote: So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We want to illustrate the paper with animations. Because there is a problem, I am investigating in all areas. ... I would like to be in control of or fully aw

Re: String to Float, without introducing errors

2022-12-19 Thread Greg Ewing
On 19/12/22 9:24 am, Stefan Ram wrote: So what's the time until a mass of one gram arrives at the ground versus a mass of ten grams? I think one needs "Decimal" to calculate this! Or you can be smarter about how you calculate it. Differentiating t with respect to m gives dt/dm = -0.5 * sqr

Re: NoneType List

2022-12-31 Thread Greg Ewing
On 1/01/23 11:36 am, avi.e.gr...@gmail.com wrote: And, of course, we had the philosophical question of why the feature was designed to not return anything ... rather than return the changed object. My understanding is that Guido designed it that way to keep a clear separation between mutating a

Re: To clarify how Python handles two equal objects

2023-01-10 Thread Greg Ewing
On 11/01/23 11:21 am, Jen Kris wrote: where one object derives from another object (a = b[0], for example), any operation that would alter one will alter the other. I think you're still confused. In C terms, after a = b[0], a and b[0] are pointers to the same block of memory. If you change tha

Re: Fast lookup of bulky "table"

2023-01-15 Thread Greg Ewing
On 16/01/23 2:27 am, Dino wrote: Do you have any idea about the speed of a SELECT query against a 100k rows / 300 Mb Sqlite db? That depends entirely on the nature of the query and how the data is indexed. If it's indexed in a way that allows sqlite to home in directly on the wanted data, it wi

Re: Improvement to imports, what is a better way ?

2023-01-18 Thread Greg Ewing
On 19/01/23 10:40 am, Dan Kolis wrote: I guess I don't full understand what bothers me about the repetition of the imports so much. It's doubtful that every module uses every one of those imports. It looks like someone had a standard block of imports that they blindly pasted at the top of ever

Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-23 Thread Greg Ewing
On 2023-01-22 at 18:19:13 -0800, Jach Feng wrote: 1) Modify the sys.argv by inserting an item '--' before parsing it, ie. sys.argv.insert(1, '--') args = parser.parse_args() If you do that, you'll never be able to have any actual options, so using argparse seems like overkill. Just pull the ar

Re: bool and int

2023-01-27 Thread Greg Ewing
On 26/01/23 6:10 am, Chris Angelico wrote: And that's a consequence of a system wherein there is only one concept of "success", but many concepts of "failure". Whoever devised that system was clearly a pessimist :) Murphy's Law for Unix: If something can go wrong, it will go wrong 255 times out

Re: evaluation question

2023-01-30 Thread Greg Ewing
On 30/01/23 10:41 pm, mutt...@dastardlyhq.com wrote: What was the point of the upheaval of converting the print command in python 2 into a function in python 3 if as a function print() doesn't return anything useful? It was made a function because there's no good reason for it to have special s

Re: evaluation question

2023-01-31 Thread Greg Ewing
On 31/01/23 10:24 pm, mutt...@dastardlyhq.com wrote: All languages have their ugly corners due to initial design mistakes and/or constraints. Eg: java with the special behaviour of its string class, C++ with "=0" pure virtual declaration. But they don't dump them and make all old code suddenly ce

Re: evaluation question

2023-01-31 Thread Greg Ewing
On 1/02/23 7:33 am, Stefan Ram wrote: Thomas Passin writes: Some people say it is a function now so that you can redefine it. Well, that's one benefit, but I wouldn't say it's the main one. The point is really that you can do *anything* with it now that you can do with a regular functio

Re: evaluation question

2023-01-31 Thread Greg Ewing
On 1/02/23 1:17 pm, dn wrote: 1 nothing "ceased to execute" and Python 2 was maintained and developed for quite some time and in-parallel to many Python 3 releases. And a lot of effort was put into making the transition as easy as possible, e.g. 2to3, and the features added to 2.7 to make it ea

Re: Licensing?

2023-02-02 Thread Greg Ewing
On 3/02/23 6:38 am, Jon Ribbens wrote: If you change someone else's code then you have created a derived work, which requires permission from both the original author and you to copy. (Unless you change it so much that nothing remains of the original author's code, of course.) "Nothing" is prob

Re: evaluation question

2023-02-02 Thread Greg Ewing
On 3/02/23 5:09 am, mutt...@dastardlyhq.com wrote: What if its 10s of thousands of lines of core production code? If the company it belongs to wants to add new Python 3 features it can't just plug them into the code because it won't run under Python 3, they have to do a full overhaul or even comp

Re: argparse presence of switch

2021-01-12 Thread Greg Ewing
On 13/01/21 7:13 am, Chris Angelico wrote: This is what different actions are for. I'd probably use action="store_true" here; that should mean that args.register will be set to True if "-r" was passed, or False if it wasn't. Yes, otherwise it expects another argument following -r containing a

Re: A beginning beginner's question about input, output and . . .

2021-01-12 Thread Greg Ewing
On 13/01/21 4:18 am, Grant Edwards wrote: AFAIK, Python can't be used to write device drivers for any popular OS At least not until some crazy person embeds Python in the Linux kernel... -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: A beginning beginner's question about input, output and . . .

2021-01-13 Thread Greg Ewing
On 13/01/21 7:57 pm, Christian Gollwitzer wrote:  What do you mean, "until" ? https://medium.com/@yon.goldschmidt/running-python-in-the-linux-kernel-7cbcbd44503c He's using Micropython. That's cheating! :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: A beginning beginner's question about input, output and . . .

2021-01-13 Thread Greg Ewing
On 14/01/21 11:09 am, Grant Edwards wrote: Perhaps I need to recalibrate my adjectives, but with 256KB+ of flash and 32KB+ of RAM, I wouldn't call them "small" It's small by today's standards, when you consider that multiple GB of RAM is commonplace now in most "real" computers. -- Greg -- htt

Re: Application window geometry specifier

2021-01-13 Thread Greg Ewing
On 14/01/21 1:58 pm, Chris Angelico wrote: On Thu, Jan 14, 2021 at 11:53 AM Python wrote: I believe it is or was quite common for large, integrated applications like DAWs, graphical design software, etc. to remember where you placed your various floating toolbars and add-ons Not just large,

Re: why sqrt is not a built-in function?

2021-01-14 Thread Greg Ewing
Aother thing to consider is that math.sqrt is not the only sqrt function in Python. There is also one in cmath, and in the wider ecosystem, another one in numpy. Being explicit about which one you're using is a good thing. Concerning exponentiation, it can be used to achieve the same thing as sqr

Re: conceptual problem (was: A beginning beginner's question about input, output and . . .

2021-01-14 Thread Greg Ewing
On 14/01/21 11:49 am, Cameron Simpson wrote: The "pure" OOP approach, where method calls are used as messages to set or fetch aspects of the object, is usually does with getter and setter methods like: x = o.getX() o.setX(9) People use get and set methods, not because it's somehow mo

Re: Exploring terminfo

2021-01-15 Thread Greg Ewing
On 16/01/21 7:33 am, Grant Edwards wrote: Starting in Python 3., python's stdio file objects are _not_ on top of the libc FILE streams: they're directly on top of the file descriptor. This sounds like rather a bad situation, because it means that any C library using stdio is going to interact b

Re: why sqrt is not a built-in function?

2021-01-15 Thread Greg Ewing
On 16/01/21 10:14 am, Michael F. Stemper wrote: I had no idea that syntax existed, and find it completely at odds with The Zen of Python. It's not an *obvious* way, so there's no Zen conflict. As for why it exists, it's part of the mechanism that implements imports -- 'import' statements get c

Re: Exploring terminfo

2021-01-15 Thread Greg Ewing
On 16/01/21 3:37 pm, Chris Angelico wrote: Surely it should be the other way around? If you use the C stdio streams, flush them after use. 1. You might not know that you're (implicitly) using C stdio. 2. There doesn't seem to be an easy way to flush C stdio from Python any more. -- Greg -- ht

Re: Exploring terminfo

2021-01-16 Thread Greg Ewing
On 16/01/21 4:17 pm, Chris Angelico wrote: But somewhere along the way, you're finding that there's a problem, which implies that SOMETHING is calling on C stdio. That thing, surely, should be the thing responsible for flushing? The C library using stdio has no way of knowing that something els

Re: Exploring terminfo

2021-01-16 Thread Greg Ewing
On 17/01/21 12:40 pm, Chris Angelico wrote: This is true. However, at some point, the boundary is crossed from Python into the C library. Something, at that point, knows. It's very common to have a flush option available, so it should be used. I'm wondering whether the problem in this particula

Re: Exploring terminfo

2021-01-17 Thread Greg Ewing
On 18/01/21 3:34 am, Alan Gauld wrote: The problem is terminfo is not really part of curses. Curses is built on top of terminfo. As far as I can tell from the man pages, terminfo itself is just a file format. The only programmatic interfaces I can find for it *are* part of curses: del_curterm(

Re: Exploring terminfo

2021-01-18 Thread Greg Ewing
On 19/01/21 2:34 pm, Alan Gauld wrote: To be fair that's a limitation of the C curses library. putp() is a wrapper around tputs() even there, and you can't change what it does. The gap in the curses module is that it doesn't offer the tputs() option as an alternative. Seems to me it would be us

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Greg Ewing
On 3/02/21 9:24 am, Dan Stromberg wrote: But how do you know what exceptions could be raised? Mostly I find that it's not really necessary to know precisely which exceptions could be raised. The way I usually deal with exceptions is: 1. If it descends from OSError, I assume it results from s

Re: super() in injected methods

2021-02-11 Thread Greg Ewing
On 12/02/21 7:05 am, Andras Tantos wrote:     a = B()     a.m(41)     a.m = MethodType(method, a)     a.m(42) Are you sure you really need to inject methods into instances like this? What problem are you trying to solve by doing so? There's almost certainly a better way to approach it. --

Re: New Python implementation

2021-02-11 Thread Greg Ewing
On 12/02/21 11:33 am, Mr Flibble wrote: neos isn't a Python package so that isn't a problem. It might be a bit confusing if it ever becomes part of the wider Python ecosystem, though. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: super() in injected methods

2021-02-11 Thread Greg Ewing
On 12/02/21 3:39 pm, Andras Tantos wrote: Now, when a Port gets assigned a NetType, it needs to gain all sorts of new features. It for example should have a 'length' attribute that tells how many bits are needed to represent its possible values. The way I would probably approach this is to hav

Re: weirdness with list()

2021-02-28 Thread Greg Ewing
On 28/02/21 1:17 pm, Cameron Simpson wrote: [its length in bytes] is presented via the object's __len__ method, BUT... It also has a __iter__ value, which like any Box iterates over the subboxes. You're misusing __len__ here. If an object is iterable and also has a __len__, its __len__ shoul

Re: Why assert is not a function?

2021-03-02 Thread Greg Ewing
On 3/03/21 12:24 pm, Chris Angelico wrote: if PRODUCTION: def assert(*a, **kw): pass would work if it were a function :) But would cost you a useless function call for every assert in production mode. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Canonical conversion of dict of dicts to list of dicts

2021-03-31 Thread Greg Ewing
On 31/03/21 7:37 pm, dn wrote: Python offers mutable (can be changed) and immutable (can't) objects (remember: 'everything is an object'): https://docs.python.org/3/reference/datamodel.html?highlight=mutable%20data While that's true, it's actually irrelevant to this situation. $ a = "bob"

Re: Horrible abuse of __init_subclass__, or elegant hack?

2021-04-02 Thread Greg Ewing
On 3/04/21 10:36 am, Chris Angelico wrote: It means exactly what you'd expect. The tricky part comes when you try to knife the block of chocolate, and it makes for a hilarious party game. A guillotine could be useful in the case of Whittaker's. IMO they don't make the grooves deep enough, makin

Re: Friday Finking: initialising values and implied tuples

2021-04-04 Thread Greg Ewing
On 5/04/21 11:47 am, dn wrote: I think I've read that the compiler is smart-enough to realise that the RHS 'literal-tuples'?'tuple-literals' are being used as a 'mechanism', and thus the inits are in-lined. It does indeed seem to do this in some cases: >>> def g(i, j, k): ... a, b, c = i, j,

Re: Yield after the return in Python function.

2021-04-05 Thread Greg Ewing
On 6/04/21 4:02 am, Terry Reedy wrote: *Any* use of 'yield' in a function makes the function a generator function.  ...  If there were a 'dead (unreachable) code' exception, a reader or compiler would have to analyze each use of 'yield' and decide whether it is reachable or not. It would als

Re: Unsubscribe/can't login

2021-05-05 Thread Greg Ewing
On 6/05/21 12:58 am, Peter Otten wrote: Does that happen with all my messages? I've seen two pairs of duplicate messages from you in this thread so far, with the same content but slightly different line wrapping. Looks like a gateway somewhere isn't recognising them as the same message. Readin

Re: Proposal: Disconnect comp.lang.python from python-list

2021-05-06 Thread Greg Ewing
My opinion on all this: The volume in this newsgroup is nowhere near high enough to be worth changing anything. This thread itself now contains more messages than the recent neopython trollage that prompted it. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: learning python ...

2021-05-24 Thread Greg Ewing
On 25/05/21 9:27 am, Cameron Simpson wrote: On 24May2021 16:17, hw wrote: > Or it doesn't forget about the old one and the old one becomes inaccessible (unless you have a reference to it, if there is such a thing in python). How do you call that? You're conflating values (objects, such as a

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 25/05/21 2:59 pm, hw wrote: Then what is 'float' in the case of isinstance() as the second parameter, and why can't python figure out what 'float' refers to in this case? You seem to be asking for names to be interpreted differently when they are used as parameters to certain functions.

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 25/05/21 5:56 pm, Avi Gross wrote: Var = read in something from a file and make some structure like a data.frame Var = remove some columns from the above thing pointed to by Var Var = make some new calculated columns ditto Var = remove some rows ... Var = set some kind of grouping on the above

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 26/05/21 3:33 am, Dennis Lee Bieber wrote: the OBJECTS have a type and can not change type. Well... built-in types can't, but... >>> class A: ... pass ... >>> class B: ... pass ... >>> a = A() >>> type(a) >>> a.__class__ = B >>> type(a) -- Greg -- https://mail.python.org/mailman/listi

Re: imaplib: is this really so unwieldy?

2021-05-25 Thread Greg Ewing
On 26/05/21 5:21 am, hw wrote: On 5/25/21 11:38 AM, Cameron Simpson wrote: You'll need to import "sys". aving to import another library just to end a program might not be ideal. The sys module is built-in, so the import isn't really loading anything, it's just giving you access to a namespa

Re: learning python ...

2021-05-25 Thread Greg Ewing
On 2021-05-24, Alan Gauld via Python-list wrote: Although wouldn't it be "expected boolean expression" rather than conditional expression? Python doesn't care how the argument to 'if' is arrived at so long as it's a boolean. This isn't really true either. Almost every object in Python has an

Re: learning python ...

2021-05-26 Thread Greg Ewing
On 26/05/21 7:15 pm, hw wrote: it could at least figure out which, the type or the variable, to use as parameter for a function that should specify a variable type when the name is given.  Obviously, python knows what's expected, so why not chose that. It knows, but not until *after* the func

Re: Turtle module

2021-05-26 Thread Greg Ewing
On 27/05/21 4:17 am, Chris Angelico wrote: Worst case, it is technically available as the ._fullcircle member, but I would advise against using that if you can help it! If you're worried about that, you could create your own turle subclass that tracks the state how you want. -- Greg -- https:/

(OT) Re: Applying winpdb_reborn

2021-05-29 Thread Greg Ewing
On 30/05/21 1:46 pm, dn wrote: We always referred to it as an "oh-two-nine" ("029"). I had the privilege of helping to dismantle a couple of those when they were decommissioned at the University of Canterbury. Amazing pieces of technology -- purely electromechanical, no electronics in sight. E

Re: Definition of "property"

2021-05-31 Thread Greg Ewing
On 31/05/21 8:20 am, Alan Gauld wrote: That's a very Pythonic description. If it's a book about Python, it needs to be. The word "property" has a very specialised meaning in Python. In some other languages it's used the way we use "attribute" in Python. So a Python-specific definition is nece

Re: Definition of "property"

2021-05-31 Thread Greg Ewing
On 31/05/21 4:57 am, Irv Kalb wrote: Perhaps the best I've found so far is from the Python documentation: A property object has getter, setter, and deleter methods usable as decorators that create a copy of the property with the corresponding accessor function set to the decorated function.

Re: Definition of "property"

2021-05-31 Thread Greg Ewing
On 31/05/21 9:13 am, Jon Ribbens wrote: No, I said it pretends to be a *data* attribute. I don't think it's pretending to be anything. From the outside, it's just an attribute. Data attributes are more common than non-data attributes, so we tend to assume that an attribute is a data attribute

Re: Definition of "property"

2021-06-01 Thread Greg Ewing
On 1/06/21 2:34 am, Jon Ribbens wrote: From the outside, it's just a *data* attribute. Which, from the inside, it isn't. Hence "pretending". But what is it about the external appearance that would make you think it's a data attribute, rather than some other kind of attribute? (I'm assuming th

Re: Definition of "property"

2021-06-01 Thread Greg Ewing
On 1/06/21 7:01 am, Alan Gauld wrote: That was the point, the OP said it was a book about OOP. Not a book about "OOP in Python". In that case it would be best to avoid the word, or give a definition of the way he's using it, making it clear that it's not a universal definition. Python's definit

Re: Behaviour of pop() for dictionaries

2021-06-14 Thread Greg Ewing
On 14/06/21 4:19 am, BlindAnagram wrote: Am I missing the obvious way to obtain the value (or the key) from a dictionary that is known to hold only one item? v = d.popitem()[1] More importantly, is there a good reason why we don't have d.pop() for dictionaries? My guess is because it's not

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Greg Ewing
On 14/06/21 4:15 am, Elena wrote: Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this rule-based function. I know an operator g that can calculate a real value from Y: e = g(Y) g is too complex to be written analytically. I would like to find a set of rules f able to minim

Re: Terminology: EU language skills, and Master to Main (or ...)

2021-06-14 Thread Greg Ewing
On 13/06/21 3:21 pm, dn wrote: Will referring to skilled professionals as 'masters (of their profession/craft)' transgress (international or at least US-instigated) 'Political Correctness'? And what about all the university degrees with the word "master" in their names? Worst of all, will epis

Re: optimization of rule-based model on discrete variables

2021-06-14 Thread Greg Ewing
On 15/06/21 12:51 am, Elena wrote: I see what you mean, so I try to explain it better: Y is a vector say [y1, y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ... x10i] 1<=i<=n. All yi and xji assume discrete values. I already have a dataset of X={Xi} and would like to find

Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-15 Thread Greg Ewing
On 15/06/21 3:18 pm, Jach Feng wrote: From a user's point, I don't really care how Python creates thoseinstances, > either using an already exist one or create a new one, as long as each element (and its sub-element) are independent from each other so a modification of one will not influence the

  1   2   3   4   5   >