Re: Couldn't install numpy on Python 2.7
On 13/06/24 4:31 am, avi.e.gr...@gmail.com wrote: It seems Microsoft is having a problem where something lik 2/3 of Windows users have not upgraded from Windows 10 after many years At least Python 3 is a clear improvement over Python 2 in many ways. Whereas the only thing Microsoft seems to have done with Windows in recent times is change it in ways that nobody wants, so there is understandable resistance to upgrading even if it's possible. On 13/06/24 10:09 am, Chris Angelico wrote: > So if anyone > actually does need to use pip with Python 2.7, they probably need to > set up a local server You should also be able to download a .tar.gz from PyPI and use pip to install that. Although you'll have to track down the dependencies yourself in that case. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Use of statement 'global' in scripts.
On 8/05/24 1:32 pm, Popov, Dmitry Yu wrote: The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, statement 'global' is used exactly the same way as in modules? The 'global' statement declares a name to be module-level, so there's no reason to use it at the top level of either a script or a module, since everything there is module-level anyway. You only need it if you want to assign to a module-level name from within a function, e.g. spam = 17 def f(): global spam spam = 42 f() # spam is now 42 A script is a module, so everything that applies to modules also applies to scripts. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: xkcd.com/353 ( Flying with Python )
On 30/03/24 7:21 pm, HenHanna wrote: https://xkcd.com/1306/ what does SIGIL mean? I think its' a Perl term, referring to the $/@/# symbols in front of identifiers. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: GIL-Removal Project Takes Another Step (Posting On Python-List Prohibited)
On 20/03/24 4:14 pm, Lawrence D'Oliveiro wrote: not to mention the latency when there isn’t quite enough memory for an allocation and you have to wait until the next GC run to proceed. Run the GC a thousand times a second, and the latency is still 1 millisecond. That's not the way it usually works. If you run out of memory, you run a GC there and then. You don't have to wait for GCs to occur on a time schedule. Also, as a previous poster pointed out, GCs are typically scheduled by number of allocations, not by time. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
On 26/02/24 12:45 pm, Lawrence D'Oliveiro wrote: def score(candidate, answer) : return \ ( sum(a == b for a, b in zip(candidate, answer)), sum ( i != j and a == b for i, a in enumerate(candidate) for j, b in enumerate(answer) ) ) This is not correct. score((1,1,1), (1,1,2)) gives (2,4). According to the usual rules of Mastermind, it should be (2, 0). -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Await expressions (Posting On Python-List Prohibited)
On 27/01/24 10:46 am, Stefan Ram wrote: But your explanation seems to have no mention of the "something" / "the awaitable object" part following the preposition "on". Shouldn't this awaitable object play a rôle in the explanation of what happens? If it helps at all, you can think of an async function as being very similar to a generator, and "await" as being very similar to "yield from". In the current implementation they're almost exactly the same thing underneath. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about garbage collection
On 17/01/24 1:01 am, Frank Millman wrote: I sometimes need to keep a reference from a transient object to a more permanent structure in my app. To save myself the extra step of removing all these references when the transient object is deleted, I make them weak references. I don't see how weak references help here at all. If the transient object goes away, all references from it to the permanent objects also go away. A weak reference would only be of use if the reference went the other way, i.e. from the permanent object to the transient object. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about garbage collection
On 17/01/24 4:00 am, Chris Angelico wrote: class Form: def __init__(self): self.elements = [] class Element: def __init__(self, form): self.form = form form.elements.append(self) If you make the reference from Element to Form a weak reference, it won't keep the Form alive after it's been closed. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 16/01/24 11:55 am, Mats Wichmann wrote: Windows natively has something called python.exe and python3.exe which is interfering here I'm wondering whether py.exe should be taught to recognise these stubs and ignore them. This sounds like something that could trip a lot of people up. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 15/01/24 9:07 pm, Chris Angelico wrote: The grammar *can't* specify everything. If it did, it would have to have rules for combining individual letters into a NAME and individual characters into a string literal. The lexical level of a grammar can be, and often is, described formally using regular expressions. Although some might consider that this doesn't contradict your statement about readability. :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 15/01/24 1:54 pm, dn wrote: Soon after, Wirth simplified rather than expanded, and developed Pascal. Before Pascal there was Algol-W, which Wirth invented as a rebellion against how complicated Algol 68 was becoming. When I first saw this I was stunned, then attracted to its simplicity, but then steered-away once realised that it needed 'more' to cope with 'the outside world'. Pascal was intended as a teaching language, and as such it was lacking in practicality in a few spots. But it didn't need much tweaking to make it a very useful language. UCSD Pascal, Turbo Pascal, Delphi, etc. enjoyed a lot of popularity. A variant of UCSD was the main language for Macintosh application development for a number of years. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 15/01/24 1:28 am, Left Right wrote: Python isn't a context-free language, so the grammar that is used to describe it doesn't actually describe the language Very few languages have a formal grammar that *fully* describes the set of strings that constitute valid programs, including all the rules about things having to be declared, types matching up, etc. The only one I know of which attempted that is Algol 68, and it seems to be regarded as a technical success but a practical failure. ... so, it's a "pretend grammar" that ignores indentation. Indentation isn't ignored, it appears in the grammar by means of INDENT and DEDENT lexical tokens. It's true that the meaning of these tokens is described informally elsewhere, but that's true of all the lexical features. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 13/01/24 11:34 pm, Left Right wrote: To make this shorter, Python allows: for in ... : ... Um, no, it doesn't. An assignment target is not, on its own, a statement. It's hard to make sense of what you're saying. You seem to be surprised by the fact that Python doesn't require variables to be declared separately from their use. But this is a very common feature of dynamic languages generally. As language oddities go, it hardly rates a mention. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 13/01/24 3:14 pm, Chris Angelico wrote: On Sat, 13 Jan 2024 at 13:11, Left Right via Python-list wrote: Very few languages allow arbitrary complex expressions in the same place they allow variable introduction. What do you mean by this? Most languages I've worked with allow variables to be initialized with arbitrary expressions, and a lot of languages allow narrowly-scoped variables. I think he means that in some languages the for-loop target serves as the declaration of a new variable, and as such has to be a bare name. Python isn't like that -- the target of a for-statement is treated exactly the same way as the lhs of an assignment. It's not scoped to the loop. BTW, the equivalent thing is valid in C too, so anyone familiar with C is unlikely to be surprised by this either. #include int x[10]; int i; int main() { i = 5; for (x[i] = 0; x[i] < 10; x[i]++) printf("%d\n", x[i]); } Output: 0 1 2 3 4 5 6 7 8 9 -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 13/01/24 1:45 pm, Left Right wrote: I use the term "destructuring" in the same way Hyperspec uses it. It's not a Python term. I don't know what you call the same thing in Python. I'm not sure what you understand from it. I thought you meant what is usually called "unpacking" in Python. I don't know anything about Hyperspec, so I don't know what it means there. The fact that i was being printed inside the loop made me think that some deeper level of surprise was being intended, such as the value of i somehow getting changed by the assignment. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 13/01/24 12:11 am, Left Right wrote: x = [...] for x[i] in x: print(i) I suspect you've misremembered something, because this doesn't do anything surprising for me: >>> x = [1, 2, 3] >>> for x[i] in x: print(i) ... Traceback (most recent call last): File "", line 1, in NameError: name 'i' is not defined There's no destructuring going on here, just assignment to a sequence item. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: mypy question
On 31/12/23 10:06 am, Thomas Passin wrote: my suggestion above does work, *except* that you cannot mix-and-match different DictTypex types Have you tried declaring the argument as a Mapping instead of a dict? Seeing as Thomas Passin's Sequence experiment worked, it seems like this should work too. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: mypy question
On 31/12/23 8:05 am, Chris Angelico wrote: Ah, I think you've hit on the problem there. Consider this: def add_item(stuff: dict[str: str | int]): stuff["spam"] = "ham" stuff["vooom"] = 1_000_000 Yep, that's it exactly. It's not the union itself that's the problem, but the fact that there's a *mutable container* containing that type. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: mypy question
On 30/12/23 4:02 am, Karsten Hilbert wrote: def run_rw_queries ( link_obj:_TLnkObj=None, queries:list[dict[str, str | list | dict[str, Any]]]=None, Given that I would have thought that passing in list[dict[str, str]] for "queries" ought to be type safe. dict[str, str] is not a subtype of dict[str, str | something_else] because you can assign a value of type something_else to the latter but not the former. In this case it happens to be okay because the function is (presumably) treating the dict passed in as immutable, but MyPy has no way to be sure of that. You could try declaring it as a collections.Mapping, which is immutable. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
RE: Subject: Are there any easy-to-use Visual Studio C# WinForms-like GUI designers in the Python world for Tk?
> I'm used to C# WinForms, which has an easy-to-use drag-and-drop GUI designer in Visual Studio. Is there anything similar for Tk? How about Qt? What do you recommend as the easiest way to create GUI programs in Python, similar to the ease of use of C# WinForms? I can't say much for Qt other than there is a GUI designer for it, but I don't know much about it. As to the portion of your question about Python and Tkinter, YES! The project is called PAGE and it is a drag and drop designer using the Tk and ttk toolkits (basically Tkinter). It's been around for many years, is completely FREE and open source, the source code is included and works on Windows, Linux and Mac OS. The current version is 7.6 and you can find it at https://sourceforge.net/projects/page/ and it has been downloaded over 2000 times just in December, and over 26,000 times in 2023. There is a TONNE of examples, full documentation and a number of tutorials. The Sourceforge acts as the main help site, but there is also a Discord site dedicated to help and support. I sincerely hope this helps! Greg Walters -- *My memory check bounced* Greg Walters -- https://mail.python.org/mailman/listinfo/python-list
Re: How/where to store calibration values - written by program A, read by program B
First, one of the posters got it right. Nothing is REALLY ever "written" to the file. Consider it a global variable that isn't a global variable. Assume you have two modules, A and B. Both modules import config. Furthermore, let's assume that Module B 'writes' a variable called "font"... shared.font="TkDefaultFont" That information is immediately available to Module A. All Module A has to do is (assuming that it has been initialized previously) do something like this... myFont=shared.font Now, myFont has the value "TkDefaultFont" in both modules A and B. Further, let's assume that we need to pass a ttk::Theme to Module B... Module A does a shared.currentTheme = "clam" Anytime Module B wants to check the value of the shared variable, it can do... MyCurrentTheme = shared.currentTheme. You can also use a similar variable that will hold a flag boolean "saying" something like shared.UpdatedInfo = True This can be tested at any time via any timer check, including a Tkinter root.after type timer. If the timer is true, simply go through your list of shared variables (You should keep them in a list just to be sure) then they can be checked on a timed basis. Or just use ... MyVariable=shared.VariableName anytime you need to make sure it's updated. If the value is the same, it only wastes a few clock cycles. However if it has been updated, then you got the latest version. This can work for any number of modules. You aren't limited to just two. I hope this helps. Greg -- *My memory check bounced* Greg Walters -- https://mail.python.org/mailman/listinfo/python-list
How/where to store calibration values - written by program A, read by program B
Many years ago, Fredrik Lundh provided an answer for this question on his website effbot.org. Unfortunately that site has gone, but luckily, it has been preserved in the "wayback machine"... https://web.archive.org/web/20200724053442/http://effbot.org:80/pyfaq/how-do-i-share-global-variables-across-modules.htm In short, create an empty file named something like 'config.py' or 'shared.py' in a folder that both scripts can use. Import the file in both scripts. import shared Then when you want to share a value, use... shared.variablename=3.14159 The file can then be accessed by both scripts. The biggest caveat is that the shared variable MUST exist before it can be examined or used (not surprising). I sincerely hope this helps. Greg -- *My memory check bounced* Greg Walters -- https://mail.python.org/mailman/listinfo/python-list
Re: Context without manager
On 27/11/23 5:03 pm, Grant Edwards wrote: I should probably have written "how to fool that into working when he's not using a 'with' statement" It should be possible to run the context protocol yourself. Something like (warning, untested): class MyDeviceWrapper: def __init__(self): self.cm = device_open() self.device = self.cm.__enter__() # Other methods here for doing things with # self.device def close(self): self.cm.__exit__(None, None, None) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Context without manager
On 27/11/23 9:03 am, Stefan Ram wrote: Above, "have" is followed by another verb in "have been", so it should be eligible for a contraction there! Yes, "been" is the past participle of 'to be", so "I've been" is fine. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: on a tail-recursive square-and-multiply
On 8/11/23 2:26 pm, Julieta Shem wrote: For the first time I'm trying to write a tail-recursive square-and-multiply and, even though it /seems/ to work, I'm not happy with what I wrote and I don't seem to understand it so well. Stepping back a bit, why do you feel the need to write this tail-recursively? Is it just an exercise? Note that Python doesn't optimise tail calls, so anything that can be done tail-recursively is probably better done iteratively. --8<---cut here---start->8--- def sam(b, e, m, acc = 1): if e == 0: return acc if is_even(e): return sam(remainder(b * b, m), e//2, m, acc) else: return sam(b, e - 1, m, remainder(b * acc, m)) --8<---cut here---end--->8--- You see, I tried to use an accumulator, but I'm only accumulating when the exponent is odd. When it's even, I feel I'm forced to change the base into b * b mod m and leave the accumulator alone. This feels so unnatural to me. I feel I broke some symmetry there. I'm having to think of two cases --- when I change the accumulator and when I change the base. That seems too much for my small head. Can you help? Well, there are inherently two cases, and they're different, so I don't think you're doing anything wrong here. It was asymmetrical to begin with. If you were doing it iteratively you would also be leaving the accumulator alone when the exponent is even. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: fCONV_AUSRICHTG is not defined - Why?
On 8/11/23 8:10 am, MRAB wrote: Something to do with how scoping is implemented in comprehensions? Yes, together with the way class scopes work during class construction. Behind the scenes, the body of a listcomp happens to be implemented as a nested function. Usually you don't notice this, but while a class is being built, its scope doesn't count as an enlosing scope for functions defined within the class. This is necessary, otherwise all of a class's attributes would be visible inside its methods, which isn't what we want. However, it leads to some odd corner cases, such as this one. There are various ways you could work around this. I would suggest moving the offending code outside the class and qualifying the constants it uses with the class name. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 6/11/23 6:34 pm, rbowman wrote: We've found even if you directly ask the user often the answer is 'I dunno' or some mythology they have constructed to explain the problem. This seems to apply to hardware issues as well. Louis Rossmann has a philosophy of "Never believe what the customer tells you." -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 7/11/23 7:45 am, Mats Wichmann wrote: Continuing with the example, if you have a single phone number field, or let a mobile number be entered in a field marked for landline, you will probably assume you can text to that number. But if the site can detect that you've entered a mobile number into the landline field or vice versa and reject it, then it can figure out whether it can text to a given numner or not without you having to tell it! -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Question(s)
On 25/10/23 2:32 pm, Chris Angelico wrote: Error correcting memory, redundant systems, and human monitoring, plus the ability to rewrite the guidance software on the fly if they needed to. Although the latter couldn't actually be done with the AGC, as the software was in ROM. They could poke values into RAM to change its behaviour to some extent, and that got them out of trouble a few times, but they couldn't patch the code. It might have been possible with the Gemini computer, since it loaded its code from tape. I don't know if it was ever done, though. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: type annotation vs working code
On 4/10/23 5:25 pm, dn wrote: The first question when dealing with the Singleton Pattern is what to do when more than one instantiation is attempted My preferred way of handling singletons is not to expose the class itself, but a function that creates an instance the first time it's called, and returns that instance subsequently. The problem then doesn't arise. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Dynamically modifying "__setattr__"
On 28/09/23 10:44 pm, Stefan Ram wrote: class A: def __init__( self ): self.__setattr__ = self.setattr def setattr( self, key, value ): print( 'setattr called.' ) Any idea how to achieve something like this? class A: def __init__(self): self.x = 17 self.setattr = self.custom_setattr def __setattr__(self, key, value): self.setattr(key, value) def setattr(self, key, value): object.__setattr__(self, key, value) def custom_setattr(self, key, value): print('custom_setattr:', key, '=', value) a = A() a.x = 1 print('a.x =', a.x) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: error of opening Python
On 27/09/23 3:30 pm, Chris Roy-Smith wrote: surely running a 64 bit version of python in a 23mbit version of windows will cause significant problems! 23 millibits? I don't think you'd be able to run much at all with that few bits! :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: []=[]
On 23/09/23 4:51 am, Stefan Ram wrote: []=[] (Executes with no error.) # []=[] ( 1 ) #\_/# (Executes with no error.) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Getty fully qualified class name from class object
On 23/08/23 2:45 am, Ian Pilcher wrote: How can I programmatically get 'logging.Handler' from the class object? Classes have a __module__ attribute: >>> logging.Handler.__module__ 'logging' -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: GNU gettext: Print string translated and untranslated at the same time
On 17/08/23 7:10 pm, c.bu...@posteo.jp wrote: def foobar(translate): if not translate: # I try to mask the global _() builtins-function def _(txt): return txt return _('Hello') This causes _ to become a local that is left undefined on one branch of the if. You need to ensure it's always defined. Here's one way that should work: gttran = _ def foobar(translate): def _(txt): if translate: return gttran(txt) else: return txt return _('Hello') -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance and a broken super() chain
On 5/07/23 10:33 am, Alan Gauld wrote: (*) C++ is the odd one out because it doesn't have GC, but then neither does it have an Object superclass so very often MI in C++ does not involve creating diamonds! And especially if the MI style is mixin based. Even if all your mixins have empty constructors, in C++ there is still a diamond problem if they have any data members, because you end up with multiple copies of them. But C++ has the concept of virtual base classes, which avoids the diamond problem, albeit at the expense of making you explicitly call all the base class constructors in your ancestry. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Should NoneType be iterable?
On 20/06/23 7:36 pm, Barry wrote: I have some APIs that do return None or a list. The None says that a list is not available and that the caller is responsible with dealing in a application-domain specific with with that situation. In that case, the caller should probably be checking for None rather than blindly trying to iterate over the result. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Should NoneType be iterable?
I would question the wisdom of designing an API that can return either a sequence or None. If it normally returns a sequence, and there are no items to return, it should return an empty sequence. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Match statement with literal strings
On 8/06/23 10:18 am, Jason Friedman wrote: SyntaxError: name capture 'RANGE' makes remaining patterns unreachable The bytecode compiler doesn't know that you intend RANGE to be a constant -- it thinks it's a variable to bind a value to. To make this work you need to find a way to refer to the value that isn't just a bare name. One way would be to define your constants using an enum: class Options(Enum): RANGE = "RANGE" MANDATORY = "MANDATORY" match stuff: case Options.RANGE: ... case Options.MANDATORY: ... -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Why does IDLE use a subprocess?
On 29/05/23 8:10 am, James Schaffler wrote: However, some minimal testing of InteractiveInterpreter leads me to believe that the Interpreter object has its own view of local/global variables and therefore shouldn't be able to affect the calling interpreter Globals you create by executing code in the REPL have their own namespace. But everything else is shared -- builtins, imported Python modules, imported C extension modules, etc. etc. There's a long-running project to make it possible to have multiple fully-isolated Python interpreters in one process, but the way CPython is structured makes that very difficult to achieve, and as far as I know it's not there yet. In the case of IDLE, there's really no reason not to use a subprocess[1]. It's easy and guarantees 100% isolation. [1] Well, mostly. There used to be a small hitch on Windows with the default firewall settings not letting you connect to a local socket (nice one, Microsoft). I don't know whether that's still an issue. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: What to use instead of nntplib?
On 31/05/23 8:44 am, aapost wrote: Even if I did partake in the modern github style of code distribution, how many packages have issues where the "maintainers" inherited the package and really haven't dug deep enough in to the code to see how it really works. They have issues that sit around for YEARS, and when someone says "this sucks, this is broken and could be better", and the githubian response is typically a dismissive "Nothing is stopping you from making a PR". Also, "nothing is stopping you from making a fork." Which is what you would have to do in the face of inactive maintainers regardless of where or how the project was hosted. This is not a github problem or a big-corporation problem, it's a people problem. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Does os.path relpath produce an incorrect relative path?
On 25/05/23 7:49 pm, BlindAnagram wrote: The first of these three results produces an incorrect relative path because relpath does not strip off any non-directory tails before comparing paths. It has no way of knowing whether a pathname component is a directory or not. It's purely an operation on strings, it doesn't look in the file system. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Addition of a .= operator
On 21/05/23 9:18 am, Richard Damon wrote: This just can't happen (as far as I can figure) for .= unless the object is defining something weird for the inplace version of the operation, Indeed. There are clear use cases for overriding +=, but it's hard to think of one for this. So it would just be syntactic sugar, which is harder to justify. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Addition of a .= operator
On 21/05/23 5:54 am, Alex Jando wrote: hash.=hexdigest() That would be a very strange and unprecedented syntax that munges together an attribute lookup and a call. Keep in mind that a method call in Python is actually two separate things: y = x.m() is equivalent to f = x.m y = f() But it would not be possible to break down your .= syntax in that way. Another oddity is that these are equivalent: x += y x += (y) i.e. the RHS is evaluated as usual before doing the +=. But these would not be equivalent: hash .= hexdigest() hash .= (hexdigest()) In fact the latter would probably have to be disallowed, as it's not at all clear what it should mean. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: An "adapter", superset of an iterator
On 4/05/23 9:29 am, Chris Angelico wrote: So you're asking for map to be able to return an iterator if given an iterator, or an adapter if given an adapter. That makes it quite complicated to use and reason about. Also a bit slower, since it would need to inspect its argument and decide what to do with it. Currently it can just get on with its job and rely on duck typing to do the right thing. Maybe there could be a parallel set of functions "enumerated", "mapped", etc. that take sequences and return sequence views. Although that naming convention would suggest that reversed() itself should return a sequence view rather than an iterator. That would require restricting it to working on sequences, which would be an incompatible change. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: How to 'ignore' an error in Python?
On 30/04/23 2:43 am, jak wrote: Maybe I expressed myself badly but I didn't mean to propose alternatives to the EAFP way but just to evaluate the possibility that it is not a folder. If it's not a folder, you'll find out when the next thing you try to do to it fails. You could check for it earlier, but there's still the possibility of a race condition -- someone could delete the folder and replace it with a file in the meantime. Or just delete it and not replace it with anything. So you need to be prepared to deal with failures at any point. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Incomplete sys.path with embeddable python (Windows)!?
On 23/04/23 10:04 am, Ralf M. wrote: I thought about that, but for that to work all local modules across all script locations must have unique names, otherwise import might get hold of a module from the wrong directory. You could put all the local modules belonging to a particular script into a package named after the script, e.g. put the local modules used by foo.py into a package called foolib. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Incomplete sys.path with embeddable python (Windows)!?
How are you invoking your script? Presumably you have some code in your embedding application that takes a script path and runs it. Instead of putting the code to update sys.path into every script, the embedding application could do it before running the script. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Weak Type Ability for Python
On 14/04/23 4:55 am, avi.e.gr...@gmail.com wrote: While we are at it, why stop with imaginary numbers when you can imagine extensions thereof? Unfortunately, it has been proven there are and can only be two additional such constructs. You can go beyond that if you broaden your horizons enough. There are Clifford algebras, Lie algebras, ... Not sure what any of those should do to strings, though. :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Small lament...
On 4/04/23 2:09 pm, avi.e.gr...@gmail.com wrote: Sadly, between Daylight Savings time and a newer irrational PI π Day, I am afraid some April Foolers got thrown off albeit some may shower us with nonsense in May I. Pi day isn't responsible, but it is because of changes to daylight saving. The International Bureau of Weights and Measures announced that, in order to gain a few more days of summer weather, all clocks would be put back by 96 hours at midnight on 31 March 2023. So April 1 is now occurring on what would have been April 4. Expect the usual torrent of silliness to arrive shortly. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: How to add clickable url links to 3D Matplotlib chart ?
On 30/03/23 8:39 am, a a wrote: How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? It seems that matplotlib can be made to generate SVG images with hyperlinks in them: https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: What kind of "thread safe" are deque's actually?
On 30/03/23 6:13 am, Chris Angelico wrote: I'm not sure what would happen in a GIL-free world but most likely the lock on the input object would still ensure thread safety. In a GIL-free world, I would not expect deque to hold a lock the entire time that something was iterating over it. That would require holding the lock as long as an iterator object existed referencing it, which could be a long time, even longer than the caller expects (no reference counting, remember!) So for future-proofing I would recommend using deque's copy() method to copy it before doing anything that iterates over it. Hopefully that would be implemented in a thread-safe way (although the docs don't currently promise that). -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: What kind of "thread safe" are deque's actually?
On 28/03/23 2:25 pm, Travis Griggs wrote: Interestingly the error also only started showing up when I switched from running a statistics.mean() on one of these, instead of what I had been using, a statistics.median(). Apparently the kind of iteration done in a mean, is more conflict prone than a median? It may be a matter of whether the GIL is held or not. I had a look at the source for deque, and it doesn't seem to explicitly do anything about locking, it just relies on the GIL. So maybe statistics.median() is implemented in C and statistics.mean() in Python, or something like that? -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get get_body() to work? (about email)
On 20/03/23 7:07 am, Jon Ribbens wrote: Ah, apparently it got removed in Python 3, which is a bit odd as the last I heard it was added in Python 2.2 in order to achieve consistency with other types. As far as I remember, the file type came into existence with type/class unification, and "open" became an alias for the file type, so you could use open() and file() interchangeably. With the Unicode revolution in Python 3, file handling got a lot more complicated. Rather than a single file type, there are now a bunch of classes that handle low-level I/O, encoding/decoding, etc, and open() is a function again that builds the appropriate combination of underlying objects. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: We can call methods of parenet class without initliaze it?
On 15/03/23 10:57 pm, scruel tao wrote: How can I understand this? Will it be a problem? I can't remember any details offhand, but I know I've occasionally made use of the ability to do this. It's fine as long as the method you're calling doesn't rely on anything you haven't initialised yet. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 4:00 pm, 2qdxy4rzwzuui...@potatochowder.com wrote: My ~/.pythonrc contains the following: import readline import rlcompleter readline.parse_and_bind( 'tab: complete' ) I don't have a ~/.pythonrc, so that's not what's doing it for me. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 2:57 pm, Chris Angelico wrote: import sys; "readline" in sys.modules Is it? Yes, it is -- but only when using the repl! If I put that in a script, I get False. My current theory is that it gets pre-imported when using Python interactively because the repl itself uses it. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 1:46 pm, Grant Edwards wrote: That's not how it acts for me. I have to "import readline" to get command line recall and editing. Maybe this has changed? Or is platform dependent? With Python 3.8 on MacOSX I can use up arrow with input() to recall stuff I've typed before, without having to import anything. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 12:43 pm, Grant Edwards wrote: When a computer dies, I generally just cp -a (or rsync -a) $HOME to a new one. Same here, more or less. My current machine has multiple archaeological layers going back about 5 generations of technology... -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 11:43 am, Chris Angelico wrote: import readline print("Pseudo-prompt: ", end="") msg1 = input() msg2 = input("Actual prompt: ") print(repr(msg1)) print(repr(msg2)) At each of the prompts, type a bit of text, then backspace it all the way. The actual prompt will remain, but the pseudo-prompt will get cleared off. There'll be other small differences too. Hmmm, so it seems that merely importing readline does change things a little bit. This is rather nasty. I'd go so far as to call it a bug in gnu readline -- it shouldn't be erasing something that the user didn't type in. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 10:59 am, Cameron Simpson wrote: I think this might be the common case of a module which wraps another library It's not quite the same thing, though -- the library it wraps is already hooked into things behind the scenes in ways that may not be obvious. (Unless you're Dutch?) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Baffled by readline module
On 10/03/23 10:08 am, Grant Edwards wrote: It finally dawned on me after seeing an example I found elsewhere that you don't call some module method to fetch the next user-entered line. You call the input() built-in. Having a module modify the behavior of a built-in makes me cringe. Importing the module is not modifying the built-in. If your Python has been compiled with gnu readline support, input() *already* provides recall and editing facilities. You only need to import the readline module if you want to change the configuration. Yes, it would be helpful if the docs for the readline module explained this. At present they seem to assume that you already know what the readline module is for and just want a summary of the API. It *is* mentioned briefly in the docs for input(), but again somebody wanting line editing functionality wouldn't necessarily think of looking there. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Feature migration
On 9/03/23 8:29 am, avi.e.gr...@gmail.com wrote: They seem to be partially copying from python a feature that now appears everywhere but yet strive for some backwards compatibility. They simplified the heck out of all kinds of expressions by using INDENTATION. It's possible this was at least parttly inspired by functional languages such as Haskell. Haskell has always allowed indentation as one way of expressing structure. Python wasn't the first language to use indentation semantically. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast full-text searching in Python (job for Whoosh?)
On 7/03/23 6:49 am, avi.e.gr...@gmail.com wrote: But the example given wanted to match something like "V6" in middle of the text and I do not see how that would work as you would now need to search 26 dictionaries completely. It might even make things worse, as there is likely to be a lot of overlap between entries containing "V" and entries containing "6", so you end up searching the same data multiple times. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast full-text searching in Python (job for Whoosh?)
On 7/03/23 4:35 am, Weatherby,Gerard wrote: If mailing space is a consideration, we could all help by keeping our replies short and to the point. Indeed. A thread or two of untrimmed quoted messages is probably more data than Dino posted! -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Cutting slices
On 6/03/23 11:43 am, Stefan Ram wrote: A user tries to chop of sections from a string, but does not use "split" because the separator might become more complicated so that a regular expression will be required to find it. What's wrong with re.split() in that case? -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Bug 3.11.x behavioral, open file buffers not flushed til file closed.
On 6/03/23 1:02 pm, Cameron Simpson wrote: Also, fsync() need not expedite the data getting to disc. It is equally valid that it just blocks your programme _until_ the data have gone to disc. Or until it *thinks* the data has gone to the disk. Some drives do buffering of their own, which may impose additional delays before the data actually gets written. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast full-text searching in Python (job for Whoosh?)
On 5/03/23 5:12 pm, Dino wrote: I can do a substring search in a list of 30k elements in less than 2ms with Python. Is my reasoning sound? I just did a similar test with your actual data and got about the same result. If that's fast enough for you, then you don't need to do anything fancy. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Which more Pythonic - self.__class__ or type(self)?
On 4/03/23 7:51 am, avi.e.gr...@gmail.com wrote: I leave you with the question of the day. Was Voldemort pythonic? Well, he was fluent in Parseltongue, which is not a good sign. I hope not, otherwise we'll have to rename Python to "The Language That Shall Not Be Named" and watch out for horcruxes during code reviews. I'll note that he was fluent in Parseltongue, which is not a good sign. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Which more Pythonic - self.__class__ or type(self)?
On 3/03/23 9:54 am, Ian Pilcher wrote: I haven't found anything that talks about which form is considered to be more Pythonic in those situations where there's no functional difference. In such cases I'd probably go for type(x), because it looks less ugly. x.__class__ *might* be slightly more efficient, as it avoids a global lookup and a function call. But as always, measurement would be required to be sure. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.10 Fizzbuzz
On 2/03/23 10:59 am, gene heskett wrote: Human skin always has the same color Um... no? -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: one Liner: Lisprint(x) --> (a, b, c) instead of ['a', 'b', 'c']
On 28/02/23 4:24 pm, Hen Hanna wrote: is it poss. to peek at the Python-list's messages without joining ? It's mirrored to the comp.lang.python usenet group, or you can read it through gmane with a news client. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.10 Fizzbuzz
On 28/02/23 5:08 am, Thomas Passin wrote: On 2/27/2023 11:01 AM, Mats Wichmann wrote: If you intend to run Black on your code to ensure consistent formatting, you may as well learn to prefer double quotes, because it's going to convert single to double I prefer single quotes because they are easier to type. I tend to use the convention of double quotes for strings seen by the outside world, and single quotes for internal constants (such as enumerated types that happen to be represented by strings). I guess this means I can't use Black. :-( -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and
On 28/02/23 7:40 am, avi.e.gr...@gmail.com wrote: inhahe made the point that this may not have been the original intent for python and may be a sort of bug that it is too late to fix. Guido has publically stated that it was a deliberate design choice. The merits of that design choice can be debated, but it wasn't a bug or an accident. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and
On 27/02/23 10:07 pm, Roel Schroeven wrote: I'm guessing you're thinking about variables leaking out of list comprehensions. I seem to remember (but I could be wrong) it was a design mistake rather than a bug in the code, but in any case it's been fixed now (in the 2 to 3 transition, I think). The semantics of list comprehensions was originally defined in terms of nested for loops. A consequence was that the loop variables ended up in the local scope just as with ordinary for loops. Later it was decided to change that. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: TypeError: can only concatenate str (not "int") to str
On 26/02/23 10:53 am, Paul Rubin wrote: I'm not on either list but the purpose of the tutor list is to shunt beginner questions away from the main list. There's a fundamental problem with tutor lists. They rely on experienced people, the ones capable of answering the questions, to go out of their way to read the tutor list -- something that is not of personal benefit to them. Also, pointing people towards tutor lists, if not done carefully, can give the impression of saying "newcomers are not welcome here". That's not a message we want to send to Python newcomers at all. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: semi colonic
On 24/02/23 9:26 am, avi.e.gr...@gmail.com wrote: Python One-Liners: Write Concise, Eloquent Python Like a Professional Illustrated Edition by Christian Mayer (Author) I didn't know there were any Professional Illustrated Editions writing Pythom. You learn something every day! :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and
On 23/02/23 9:37 am, Hen Hanna wrote: for the first several weeks... whenever i used Python... all i could think ofwas this is really Lisp (inside) with a thin veil of Java/Pascal syntax.. - that everything is first converted (macro-expanded) into (intermediated) Lisp code, and then. I once toyed with the idea of implementing a Python compiler by translating it into Scheme and then feeding it to a Scheme compiler. But I quickly realised that, although Scheme and Python are both dynamically-typed languages, Python is way *more* dynamic than Scheme. So without doing some very serious static analysis, the best I could do would be just putting together calls to runtime support routines that implement all the dynamic dispatching that Python does for its operators, etc., and the result wouldn't be much better than an interpreter. There are some similarities between Python and Lisp-family languages, but really Python is its own thing. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: semi colonic
On 23/02/23 1:58 pm, avi.e.gr...@gmail.com wrote: Would anything serious break if it was deprecated for use as a statement terminator? Well, it would break all the code of people who like to write code that way. They might get a bit miffed if we decide that their code is not serious. :-) On the other hand, if they really want to, they will still be able to abuse semicolons by doing this sort of thing: a = 5; pass b = 7; pass c = a * b; pass Then everyone will know it's some really serious code! -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Introspecting the variable bound to a function argument
On 23/02/23 9:12 am, Hen Hanna wrote: On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev wrote: def f(a): print(black_magic(a))# or black_magic('a') f(v1)# prints: v1 f(v2)# prints: v2 the term [call by name] suggests this should be possible. But Python doesn't use call-by-name or anything remotely like it. (Even if it did, the word "name" in that context doesn't mean what it sounds like it means. The Algol docs used some words in weird ways.) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Precision Tail-off?
On 18/02/23 7:42 am, Richard Damon wrote: On 2/17/23 5:27 AM, Stephen Tucker wrote: None of the digits in RootNZZZ's string should be different from the corresponding digits in RootN. Only if the storage format was DECIMAL. Note that using decimal wouldn't eliminate this particular problem, since 1/3 isn't exactly representable in decimal either. To avoid it you would need to use an algorithm that computes nth roots directly rather than raising to the power 1/n. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: ChatGPT Generated news poster code
For a moment I thought this was going to be a script that uses ChatGPT to generate a random news post and post it to Usenet... Which would also have been kind of cool, as long as it wasn't overused. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Organizing modules and their code
On 6/02/23 4:23 am, Weatherby,Gerard wrote: Well, first of all, while there is no doubt as to Dijkstra’s contribution to computer science, I don’t think his description of scientific thought is correct. The acceptance of Einstein’s theory of relativity has nothing to do with internal consistency or how easy or difficult to explain but rather repeatedly experimental results validating it. I don't think Dijkstra was claiming that what he was talking about was a *complete* description of scientific thought, only that the ability to separate out independent concerns is an important part of it, and that was something he saw his colleagues failing to do. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Organizing modules and their code
On 5/02/23 11:18 am, transreductionist wrote: This analogy came to me the other day. For me, I would rather walk into a grocery store where the bananas, apples, and oranges are separated in to their own bins, instead of one common crate. On the other hand, if the store has an entire aisle devoted to each fruit, but only ever one crate of fruit in each aisle, one would think they could make better use of their shelf space. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: evaluation question
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 complete rewrite and that costs a lot of time and money. A possible strategy in that case would have been to incrementally rewrite it in such a way that the code would run in both 2.7 and 3.x (various features were added to 2.7 to make that possible). When that point is reached, you can then switch to running it with Python 3 and start using the new features. Also, if you're a company whose business is totally reliant on some piece of code, it would be prudent to plan ahead and budget for rewriting or replacing it at some point. People seem to think that because code doesn't wear out like hardware, you don't have to budget for replacing it. But you can't expect third party software to be maintained forever -- particularly when, as with Python, the maintenance is mainly being done by *volunteers*. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Licensing?
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 probably a bit extreme; somewhere between "exactly the same" and "completely different" there will be a borderline case, although exactly where the border lies would require a court case to determine. When in doubt, the sensible and courteous thing would be to include the original copyright notice as requested, maybe with a "based on work by..." attribution. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: evaluation question
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 easier to write code that would work in both versions. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: evaluation question
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 function -- pass it as an argument, wrap it with another function, define your own function with a similar signature for duck-typing purposes, etc. It would still be possible to have a special syntax for the outermost expression of an expression statement that would allow one to omit the parentheses, That's only one of the syntactic oddities of the old print statement, thogh. There was also the >> thing, special treatment of trailing commas, etc. Also, introducing a paren-less call syntax would be a very big and controversial change that would be way out of proportion to the problem. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: evaluation question
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 cease to execute. No, but it was decided that Python 3 would have to be backwards incompatible, mainly to sort out the Unicode mess. Given that, the opportunity was taken to clean up some other mistakes as well. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: evaluation question
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 syntax in the language. Functions don't need to return things to justify their existence, and in fact the usual convention is that functions whose purpose is to have an effect just return None. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: bool and int
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 of 256. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?
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 argument out of argv directly. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Improvement to imports, what is a better way ?
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 every file, to avoid having to think about which ones were actually needed. If you're looking for advice, I would suggest: * Only import what you use in a particular file (this doesn't have much effect on efficiency, but there's less clutter for the reader.) * Only use short names for modules that are *very* frequently referenced. Use full unabbreviated names for everything else. * Don't 'import foo as foo', just 'import foo'. * Don't try to line the code up in columns, it doesn't really help readability IMO. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast lookup of bulky "table"
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 will be very fast. If it has to fall back on a linear search, it probably won't be significantly faster than your existing Python implementation. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: To clarify how Python handles two equal objects
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 that block of memory, then of course you will see the change through either pointer. Here's a rough C translation of some of your Python code: /* mx1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] */ int **mx1 = (int **)malloc(3 * sizeof(int *)); mx1[0] = (int *)malloc(3 * sizeof(int)); mx1[0][0] = 1; mx1[0][1] = 2; mx1[0][2] = 3; mx1[1] = (int *)malloc(3 * sizeof(int)); mx1[1][0] = 4; mx1[1][1] = 5; mx1[1][2] = 6; mx1[2] = (int *)malloc(3 * sizeof(int)); mx1[2][0] = 7; mx1[2][1] = 8; mx1[2][2] = 9; /* arr1 = mx1[2] */ int *arr1 = mx[2]; /* arr1 = [ 10, 11, 12 ] */ arr1 = (int *)malloc(3 * sizeof(int)); arr1[0] = 10; arr1[1] = 11; arr1[2] = 12; Does that help your understanding? -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: NoneType List
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 and non-mutating methods, and to help catch mistakes resulting from mixing them up. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: String to Float, without introducing errors
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 * sqrt(2 * s * r**2 / (G * (M + m)**3)) which, since m is much smaller than M, is approximately -0.5 * sqrt(2 * s * r**2 / (G * M**3)) So >>> G = 6.6743015E-11 >>> r = 6.371E6 >>> M = 5.9722E24 >>> dtdm = -0.5 * sqrt(2*s*(r**2) / (G * M**3)) >>> dtdm * (1/1000 - 10/1000) 3.4004053539917275e-28 which agrees with your Decimal calculation to 3 digits, and should be as precise as the input numbers (about 4 digits in this case). This is a good example of why it's important to choose an appropriate numerical algorithm! -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: String to Float, without introducing errors
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 aware of what goes on under the bonnet. When you convert a string to a float, you're already getting the closest possible value in binary floating point. For things like physics simulations, you need to design your algorithms so that they're tolerant of small inaccuracies in the representation of your numbers. If those are causing you problems, it sounds like there is some kind of numerical instability in your algorithm that needs to be addressed. It's also possible that there is just a bug somewhere in your code, and the problem really has nothing to do with floating point inaccuracies. If you can post some code we might be able to help you further. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
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 are for. I wouldn't like the core interpreter to be producing a bunch of warnings for things like this. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
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://mail.python.org/mailman/listinfo/python-list