Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 03:42, Grant Edwards via Python-list wrote: > > On 2024-03-08, Chris Angelico via Python-list wrote: > > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > > wrote: > > > >> One might argue that "global" isn't a good choice for what to call the > >> scope in questi

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-08, Chris Angelico via Python-list wrote: > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > wrote: > >> One might argue that "global" isn't a good choice for what to call the >> scope in question, since it's not global. It's limited to that source >> file. It doesn't make s

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Chris Angelico via Python-list
On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list wrote: > One might argue that "global" isn't a good choice for what to call the > scope in question, since it's not global. It's limited to that source > file. It doesn't make sense to me to call a binding "global", when > there can be mul

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-08 Thread Grant Edwards via Python-list
On 2024-03-07, Cameron Simpson via Python-list wrote: > Yes. Note that the "global" namespace is the module in which the > function is defined. One might argue that "global" isn't a good choice for what to call the scope in question, since it's not global. It's limited to that source file. It d

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Cameron Simpson via Python-list
On 06Mar2024 15:12, Jacob Kruger wrote: So, this does not make sense to me in terms of the following snippet from the official python docs page: https://docs.python.org/3/faq/programming.html "In Python, variables that are only referenced inside a function are implicitly global. If a variable

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Jacob Kruger via Python-list
Thanks again, all. I think the python -i scoping2.py would have given me a good beginning as well - will archive that one for use. And, to maybe explain how I work - not an excuse at all - but, I am actually 100% blind, so a lot of the IDE's, or their common means/methods of interaction do

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Grant Edwards via Python-list
On 2024-03-07, dn via Python-list wrote: > The idea of importing a module into the REPL and then (repeatedly) > manually entering the code to set-up and execute is unusual (surely type > such into a script (once), and run that (repeatedly). As you say, most > of us would be working from an IDE

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread dn via Python-list
s that there are different 'environments' and different ways of building the environment in which the code will run. That's a valuable lesson, and full of subtlety! Glad to see that comparing id()s was useful - for diagnosis but not solution. Other tools might include the locals() and g

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Grant Edwards via Python-list schreef op 6/03/2024 om 18:59: On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Grant Edwards via Python-list
On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple > reasons, one of which is to prevent problems like this. Unfortun

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >>> from scoping2 import * Ah yes, that explains what's happening. After that statement, the name dt_expiry in the current namespace is bound to the same object that the name dt_expiry in the namespace of module scoping2 is bound to. F

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Ok, Ethan, that makes sense - I generally work with modules in folders, etc., but, this was just test code, but, 'see' if I instead import scoping2 as sc2, and then refer to sc2.dt_expiry and sc2.do_it, then it does operate as it should - thanks, again. Jacob Kruger +2782 413 4791 "Resistance

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Ethan Furman via Python-list
On 3/6/24 08:28, Jacob Kruger via Python-list wrote: > C:\temp\py_try>python > Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from scoping2 import * And it becomes c

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
You'll see more details in other mail, but, here I am firing up standard python interpreter from within windows terminal, and then executing following line: from scoping2 import * And, this is under windows 11 windows terminal, which is where I generally interact with my python code, via com

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
it, then it will also not retain it's new/additional child items after the function exits, and will just revert back to [1, 2, 3] each and every time. In other words, with some of the variable/object types, if you use a function that manipulates the contents of a variable, before the

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
retain it's new/additional child items after the function exits, and will just revert back to [1, 2, 3] each and every time. In other words, with some of the variable/object types, if you use a function that manipulates the contents of a variable, before then re-assigning it a new value, it s

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 16:39 schreef Roel Schroeven via Python-list: Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list: If you import the contents of that file into the python interpreter, [...] What exactly to you mean by "import the contents of that file into the python interpreter"? Othe

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Roel Schroeven via Python-list
Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list: If you import the contents of that file into the python interpreter, [...] What exactly to you mean by "import the contents of that file into the python interpreter"? Other people have put your code in a script, executed it, and saw

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Thomas Passin via Python-list
re-assigning it a new value, it seems like it might then actually update/manipulate the global variable, but, either just calling purely content retrieval functions against said objects, or assigning them new values from scratch seems to then ignore the global scope specified in the first line

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Thomas Passin via Python-list
On 3/6/2024 5:59 AM, Alan Gauld via Python-list wrote: On 05/03/2024 22:46, Grant Edwards via Python-list wrote: Unfortunately (presumably thanks to SEO) the enshittification of Google has reached the point where searching for info on things like Python name scope, the first page of links are to

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Mats Wichmann via Python-list
types, if you use a function that manipulates the contents of a variable, before then re-assigning it a new value, it seems like it might then actually update/manipulate the global variable, but, either just calling purely content retrieval functions against said objects, or assigning them new values f

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
t types, if you use a function that manipulates the contents of a variable, before then re-assigning it a new value, it seems like it might then actually update/manipulate the global variable, but, either just calling purely content retrieval functions against said objects, or assigning them

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
you use a function that manipulates the contents of a variable, before then re-assigning it a new value, it seems like it might then actually update/manipulate the global variable, but, either just calling purely content retrieval functions against said objects, or assigning them new values

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Alan Gauld via Python-list
On 05/03/2024 22:46, Grant Edwards via Python-list wrote: > Unfortunately (presumably thanks to SEO) the enshittification of > Google has reached the point where searching for info on things like > Python name scope, the first page of links are to worthless sites like > geeksforgeeks. And not just

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Grant Edwards via Python-list
On 2024-03-05, Cameron Simpson via Python-list wrote: > Because there are no variable definitions in Python, when you write > a function Python does a static analysis of it to decide which > variables are local and which are not. If there's an assignment to a > variable, it is a local variable.

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Cameron Simpson via Python-list
On 05Mar2024 20:13, Jacob Kruger wrote: Now, what almost seems to be occurring, is that while just manipulating the contents of a referenced variable is fine in this context, the moment I try to reassign it, that's where the issue is occurring . Because there are no variable definitions in Py

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread dn via Python-list
initiate the existence of a list variable to make use of later: # code snippet l_servers = [] # end of first code snippet Then, lower down, inside a couple of different functions, the first line inside the functions includes the following: # code snippet     global l_servers # end code snippet

Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Jacob Kruger via Python-list
a list variable to make use of later: # code snippet l_servers = [] # end of first code snippet Then, lower down, inside a couple of different functions, the first line inside the functions includes the following: # code snippet     global l_servers # end code snippet That should, in theory

Re: Using my routines as functions AND methods

2024-01-06 Thread Peter J. Holzer via Python-list
On 2024-01-03 23:17:34 -0500, Thomas Passin via Python-list wrote: > On 1/3/2024 8:00 PM, Alan Gauld via Python-list wrote: > > On 03/01/2024 22:47, Guenther Sohler via Python-list wrote: > > > Hi, > > > > > > In my cpython i have written quite some functions

Re: Using my routines as functions AND methods

2024-01-04 Thread Guenther Sohler via Python-list
24 at 11:47 PM Guenther Sohler wrote: > Hi, > > In my cpython i have written quite some functions to modify "objects". > and their python syntax is e.g.\ > > translate(obj, vec). e.g whereas obj is ALWAYS first argument. > > on c side this functions looks like: >

Re: Using my routines as functions AND methods

2024-01-04 Thread Alan Gauld via Python-list
On 04/01/2024 04:17, Thomas Passin via Python-list wrote: >> I'm probably missing something obvious here but can't you >> just assign your function to a class member? >> >> def myFunction(obj, ...): ... >> >> class MyClass: >> myMethod = myFunction > > That works if you assign the function t

Re: Using my routines as functions AND methods

2024-01-04 Thread Thomas Passin via Python-list
On 1/3/2024 8:00 PM, Alan Gauld via Python-list wrote: On 03/01/2024 22:47, Guenther Sohler via Python-list wrote: Hi, In my cpython i have written quite some functions to modify "objects". and their python syntax is e.g.\ translate(obj, vec). e.g whereas obj is ALWAYS firs

Re: Using my routines as functions AND methods

2024-01-03 Thread Guenther Sohler via Python-list
ite prone to crash. Which are my alertnatives ? On Wed, Jan 3, 2024 at 11:47 PM Guenther Sohler wrote: > Hi, > > In my cpython i have written quite some functions to modify "objects". > and their python syntax is e.g.\ > > translate(obj, vec). e.g whereas obj is ALWAYS

Re: Using my routines as functions AND methods

2024-01-03 Thread Thomas Passin via Python-list
On 1/3/2024 11:17 PM, Thomas Passin wrote: On 1/3/2024 8:00 PM, Alan Gauld via Python-list wrote: On 03/01/2024 22:47, Guenther Sohler via Python-list wrote: Hi, In my cpython i have written quite some functions to modify "objects". and their python syntax is e.g.\ translate(obj,

Re: Using my routines as functions AND methods

2024-01-03 Thread Alan Gauld via Python-list
On 03/01/2024 22:47, Guenther Sohler via Python-list wrote: > Hi, > > In my cpython i have written quite some functions to modify "objects". > and their python syntax is e.g.\ > > translate(obj, vec). e.g whereas obj is ALWAYS first argument. > However, I also

Using my routines as functions AND methods

2024-01-03 Thread Guenther Sohler via Python-list
Hi, In my cpython i have written quite some functions to modify "objects". and their python syntax is e.g.\ translate(obj, vec). e.g whereas obj is ALWAYS first argument. on c side this functions looks like: PyObject *python_translate(PyObject *self, PyObject *args, PyObject *kwa

Re: Persisting functions typed into the shell

2022-11-12 Thread Chris Angelico
On Sun, 13 Nov 2022 at 05:48, Stefan Ram wrote: > So much for the topic of "In Python, /everything/ is an > object"! There seem to be first and second-class objects: > Shelveable and non-shelveable objects. > That's a bit unfair. Everything IS an object, but not all objects can be treated t

Re: Persisting functions typed into the shell

2022-11-12 Thread Weatherby,Gerard
Sounds like Jupyter Notebooks: https://jupyter.org From: Python-list on behalf of Stefan Ram Date: Saturday, November 12, 2022 at 1:48 PM To: python-list@python.org Subject: Persisting functions typed into the shell *** Attention: This is an external email. Use caution responding, opening

Re: Persisting functions typed into the shell

2022-11-12 Thread dn
On 13/11/2022 05.05, Stefan Ram wrote: Wayne Harris writes: Wow. Could the dis module help at all? Thank you for this idea! I think this should work, but only under CPython and not necessarily across different Python versions. Still, I might use dis. Was constructing a two-part tu

Re: Persisting functions typed into the shell

2022-11-12 Thread Wayne Harris via Python-list
(it excludes certain > standard names and certain other names from my software) and > save them using the "shelve" package from the standard library. > > I you know "shelve" or have read the subject line, you can > guess what comes now:

Re: Asynchronous execution of synchronous functions

2022-09-26 Thread Inada Naoki
On Tue, Sep 27, 2022 at 3:19 AM Axy via Python-list wrote: > > > Did you check the ThreadPoolExecutor or the ProcessPoolExecutor? They > > won't give you atomic writes unless you add a Lock or a Condition, but > > they will execute your code in another thread or process. > > Yes, I did, but they a

Re: Asynchronous execution of synchronous functions

2022-09-26 Thread Jon Ribbens via Python-list
On 2022-09-26, Stefan Ram wrote: > So, I wanted to try to download all pages in parallel with > processes to avoid any GIL effect, while I don't understand > what the GIL actuall is. But processes didn't work here, so > I tried threads. This worked and now the total run time is > down to

Re: Asynchronous execution of synchronous functions

2022-09-26 Thread Axy via Python-list
Did you check the ThreadPoolExecutor or the ProcessPoolExecutor? They won't give you atomic writes unless you add a Lock or a Condition, but they will execute your code in another thread or process. Yes, I did, but they are too complicated to use. I'd like something for humans, such as asynch

RE: Asynchronous execution of synchronous functions

2022-09-26 Thread Diego Souza
de Janeiro - Brasil On Mon, Sep 26, 2022 at 1:01 PM wrote: > From: Axy > To: Python List > Date: Mon, 26 Sep 2022 12:17:47 +0100 > Subject: Asynchronous execution of synchronous functions > Hi there, > > is there a library to call functions in context of a thread? For > exam

Asynchronous execution of synchronous functions

2022-09-26 Thread Axy via Python-list
Hi there, is there a library to call functions in context of a thread? For example, as in asyncsqlite which has a thread and a queue I mean has anyone generalized such an approach already? If not, I'll do it myself, no problem. It's a kind of tiny stuff, like atomicwrites, whic

Re: Why does not Python accept functions with no names?

2022-02-21 Thread Abdur-Rahmaan Janhangeer
> BTW, this is not what is usually meant by the term "anonymous function". An anonymous function is one that is not bound to *any* name. The thing you're proposing wouldn't be anonymous -- it would have a name, that name being the empty string. Thanks for clarifying this point 👍👍👍 -- https://mai

Re: Why does not Python accept functions with no names?

2022-02-21 Thread Avi Gross via Python-list
ot;()" which creates and then (after the print) ignores an empty tuple.  Anonymous functions arguably have an important place in many languages and I keep seeing languages adding some version of them or new syntax for them, as R recently did. But they are best used when made deliberately

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Eryk Sun
On 2/20/22, Greg Ewing wrote: > > BTW, this is not what is usually meant by the term "anonymous > function". An anonymous function is one that is not bound > to *any* name. The thing you're proposing wouldn't be > anonymous -- it would have a name, that name being the empty > string. Sorry. I rea

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Chris Angelico
th any named > function. The kind of anonymous function we are more used to might be > something you can create as say elements of a list so you have a list of > functions you can access as in f[0] but in a sense that has a name as it can > be accessed as a component of the data structure

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Avi Gross via Python-list
something you can create as say elements of a list so you have a list of functions you can access as in f[0] but in a sense that has a name as it can be accessed as a component of the data structure called f.  I am not sure if python would trivially let you create that. But the point is if you want to

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Grant Edwards
On 2022-02-20, Christian Gollwitzer wrote: >> For the same reason an empty sequence of characters cannot >> be a variable name. Do you know any language (or formal >> theory) that allows that? > > Tcl allows that: Interesting to know, but the fact that Tcl does something differnt is more of an a

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Chris Angelico
On Mon, 21 Feb 2022 at 14:36, Python wrote: > > Barry wrote: > > > > > >> On 20 Feb 2022, at 15:35, Abdur-Rahmaan Janhangeer > >> wrote: > >> > >> Greetings list. > >> > >> Out of curiosity, why doesn't Python accept > >> def (): > >> return '---' > >> > >> () > >> > >> Where the function n

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Greg Ewing
On 21/02/22 6:27 am, Abdur-Rahmaan Janhangeer wrote: Well Python deliberately throws an exception if we do not pass in a function name. Just wanted to know why it should. As the above case is a 100% pure anonymous function. The syntax for a function definition is defined in the grammar as requi

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Python
Barry wrote: On 20 Feb 2022, at 15:35, Abdur-Rahmaan Janhangeer wrote: Greetings list. Out of curiosity, why doesn't Python accept def (): return '---' () Where the function name is ''? Because there is no variable that is holding a ref to the code. So it’s pointless. Fun fact, i

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Python
Abdur-Rahmaan Janhangeer wrote: Greetings list. Out of curiosity, why doesn't Python accept def (): return '---' () Where the function name is ''? For the same reason an empty sequence of characters cannot be a variable name. Do you know any language (or formal theory) that allows that?

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Christian Gollwitzer
Am 20.02.22 um 16:48 schrieb Python: Abdur-Rahmaan Janhangeer wrote: Greetings list. Out of curiosity, why doesn't Python accept def (): return '---' () Where the function name is ''? For the same reason an empty sequence of characters cannot be a variable name. Do you know any languag

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Chris Angelico
On Mon, 21 Feb 2022 at 09:38, Eryk Sun wrote: > > On 2/20/22, Abdur-Rahmaan Janhangeer wrote: > > > > Out of curiosity, why doesn't Python accept > > def (): > > return '---' > > The `def` keyword is compiled as an assignment statement, not an > expression that evaluates anonymously on the st

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Eryk Sun
On 2/20/22, Abdur-Rahmaan Janhangeer wrote: > > Out of curiosity, why doesn't Python accept > def (): > return '---' The `def` keyword is compiled as an assignment statement, not an expression that evaluates anonymously on the stack. Using `def` as an expression would require new syntax. For

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Avi Gross via Python-list
Not really. Anonymous functions are anonymous in name only, so to speak. When you call a function and pass it an argument that is an anonymous function definition, it is bound to a variable within the function and used mostly in a non-anonymous way. You did not bother giving it a name but it is

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Dieter Maurer
Abdur-Rahmaan Janhangeer wrote at 2022-2-20 19:32 +0400: >Out of curiosity, why doesn't Python accept >def (): >return '---' > >() > >Where the function name is ''? Python knows about (somewhat restricted) anonymous functions: it calls them `la

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Abdur-Rahmaan Janhangeer
Yes I know about lambdas but was just an introspection about the reasoning behind ^^ Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius -- https://mail.python.org/mailman/li

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Abdur-Rahmaan Janhangeer
Thanks for the answers. @Chris Well Python deliberately throws an exception if we do not pass in a function name. Just wanted to know why it should. As the above case is a 100% pure anonymous function. Kind Regards, Abdur-Rahmaan Janhangeer about | blog

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Chris Angelico
On Mon, 21 Feb 2022 at 02:33, Abdur-Rahmaan Janhangeer wrote: > > Greetings list. > > Out of curiosity, why doesn't Python This is often the wrong question. The question is more: Why should Python? Python doesn't do things just because there's no reason not to. ChrisA -- https://mail.python.or

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Dan Stromberg
On Sun, Feb 20, 2022 at 7:33 AM Abdur-Rahmaan Janhangeer < arj.pyt...@gmail.com> wrote: > Greetings list. > > Out of curiosity, why doesn't Python accept > def (): > return '---' > > () > > Where the function name is ''? > () is already an empty tuple. It would break code to change this. --

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Barry
> On 20 Feb 2022, at 15:35, Abdur-Rahmaan Janhangeer > wrote: > > Greetings list. > > Out of curiosity, why doesn't Python accept > def (): >return '---' > > () > > Where the function name is ''? Because there is no variable that is holding a ref to the code. So it’s pointless. Barr

Why does not Python accept functions with no names?

2022-02-20 Thread Abdur-Rahmaan Janhangeer
Greetings list. Out of curiosity, why doesn't Python accept def (): return '---' () Where the function name is ''? Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius -

Re: Can Python call and use FME modules and functions such as StreamOrderCalculator?

2021-12-23 Thread Mats Wichmann
On 12/23/21 09:38, Shaozhong SHI wrote: > Can we do something like import an fme.something and make use of FME > modules and functions? And what, pray tell, is FME? -- https://mail.python.org/mailman/listinfo/python-list

Can Python call and use FME modules and functions such as StreamOrderCalculator?

2021-12-23 Thread Shaozhong SHI
Can we do something like import an fme.something and make use of FME modules and functions? Regards, David -- https://mail.python.org/mailman/listinfo/python-list

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-23 Thread Chris Angelico
On Wed, Nov 24, 2021 at 3:04 AM ast wrote: > > Le 19/11/2021 à 21:17, Chris Angelico a écrit : > > On Sat, Nov 20, 2021 at 5:08 AM ast wrote: > >> > >> Le 19/11/2021 à 03:51, MRAB a écrit : > >>> On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > On 2021-11-18 at 23:16:32 -0300

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-23 Thread ast
Le 19/11/2021 à 21:17, Chris Angelico a écrit : On Sat, Nov 20, 2021 at 5:08 AM ast wrote: Le 19/11/2021 à 03:51, MRAB a écrit : On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-11-18 at 23:16:32 -0300, René Silva Valdés wrote: >>> 0.3 + 0.3 + 0.3 == 0.9 False

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Greg Ewing
On 22/11/21 4:58 am, Grant Edwards wrote: Yep, IIRC, it was a 4 bit processor because 4 bits is what it takes to represent one decimal digit. That was the Saturn, first used in the HP-71B. The original architecture (known as the "Nut")was weirder than that. It operated serially on 56 bit words

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-22 05:43:48 +1100, Chris Angelico wrote: > On Mon, Nov 22, 2021 at 5:42 AM Peter J. Holzer wrote: > > (I think I used Math::BigRat in Perl, but I've been > > programming in Perl for a lot longer.) > > Rodents Of Unusual Size? I don't think they exist... https://www.girlgeniusonline.co

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-21 10:57:55 +1100, Chris Angelico wrote: > And if decimal floating point were common, other "surprise" behaviour > would be cited, like how x < y and (x+y)/2 < x. Yup. Took me a bit to find an example, but this can happen. My HP-48 calculator uses a mantissa of 12 decimal digits. 6

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Chris Angelico
On Mon, Nov 22, 2021 at 5:42 AM Peter J. Holzer wrote: > (I think I used Math::BigRat in Perl, but I've been > programming in Perl for a lot longer.) > Rodents Of Unusual Size? I don't think they exist... ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-20 03:25:53 +, Ben Bacarisse wrote: > Chris Angelico writes: > > > It does mean exactly what it meant in grade school, just as 1/3 means > > exactly what it meant in grade school. Now try to represent 1/3 on a > > blackboard, as a decimal fraction. If that's impossible, does it mea

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Peter J. Holzer
On 2021-11-19 12:43:07 +0100, ast wrote: > Le 19/11/2021 à 03:51, MRAB a écrit : > > On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote: > > > On 2021-11-18 at 23:16:32 -0300, > > > René Silva Valdés wrote: > > > > Hello, I would like to report the following issue: > > > > > > > > Work

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Grant Edwards
On 2021-11-21, Greg Ewing wrote: > On 21/11/21 2:18 pm, Grant Edwards wrote: >> My recollection is that it was quite common back in the days before FP >> hardware was "a thing" on small computers. CPM and DOS compilers for >> various languages often gave the user a choice between binary FP and >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Greg Ewing
On 21/11/21 2:18 pm, Grant Edwards wrote: My recollection is that it was quite common back in the days before FP hardware was "a thing" on small computers. CPM and DOS compilers for various languages often gave the user a choice between binary FP and decimal (BCD) FP. It's also very common for

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, November 20, 2021 8:03 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On Sun, Nov 21, 2021 at 11:39 AM Avi Gross via Python-list wrote: > > Can I suggest a

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 1:20 PM Rob Cliffe via Python-list wrote: > > > > On 21/11/2021 01:02, Chris Angelico wrote: > > > > If you have a number with a finite binary representation, you can > > guarantee that it can be represented finitely in decimal too. > > Infinitely repeating expansions come

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
languages had a similar concept. Yes, you can have URL with more complex comparison functions needed including when something lengthens them or whatever. In one weird sense, as in you GET TO THE SAME PAGE, any URL that redirects you to another might be considered synonymous even if the two look nothi

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 21/11/2021 01:02, Chris Angelico wrote: If you have a number with a finite binary representation, you can guarantee that it can be represented finitely in decimal too. Infinitely repeating expansions come from denominators that are coprime with the numeric base. Not quite, e.g. 1/14 is

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
with care. Calculus is > NOT on a firm footing when any of the ideas in it are violated. A quantum > Mechanical universe at a deep level does not have continuity so continuous > functions may not really exist and there can be no such thing as an > infinitesimal smaller than any epsilo

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
continuous functions may not really exist and there can be no such thing as an infinitesimal smaller than any epsilon and so on. Much of what we see at that level includes things like a probabilistic view of an electron cloud forming the probability that an electron (which is not a mathematical

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-21, Chris Angelico wrote: >> I think there have been attempts to use a decimal representation in some >> accounting packages or database applications that allow any decimal numbers >> to be faithfully represented and used in calculations. Generally this is not >> a very efficient proce

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 11:39 AM Avi Gross via Python-list wrote: > > Can I suggest a way to look at it, Grant? > > In base 10, we represent all numbers as the (possibly infinite) sum of ten > raised to some integral power. Not infinite. If you allow an infinite sequence of digits, you create num

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
om: Python-list On Behalf Of Grant Edwards Sent: Saturday, November 20, 2021 5:24 PM To: python-list@python.org Subject: Re: Unexpected behaviour of math.floor, round and int functions (rounding) On 2021-11-20, Ben Bacarisse wrote: > You seem to be agreeing with me. It's the floating

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 10:55 AM Ben Bacarisse wrote: > > Grant Edwards writes: > > > On 2021-11-20, Ben Bacarisse wrote: > > > >> You seem to be agreeing with me. It's the floating point part that is > >> the issue, not the base itself. > > > > No, it's the base. Floating point can't represent

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Ben Bacarisse
Grant Edwards writes: > On 2021-11-20, Ben Bacarisse wrote: > >> You seem to be agreeing with me. It's the floating point part that is >> the issue, not the base itself. > > No, it's the base. Floating point can't represent 3/10 _because_ it's > base 2 floating point. Floating point in base 10

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 10:01 AM Avi Gross via Python-list wrote: > Computers generally use finite methods, sometimes too finite. Yes, the > problem is not Mathematics as a field. It is how humans often generalize or > analogize from one area into something a bit different. I do not agree with > a

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 20/11/2021 22:59, Avi Gross via Python-list wrote: there are grey lines along the way where some mathematical proofs do weird things like IGNORE parts of a calculation by suggesting they are going to zero much faster than other parts and then wave a mathematical wand about what happens when

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
n floats but on the design not accommodating the precision needed or perhaps on the algorithm used not necessarily being expected to reach a certain level. -Original Message- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, November 20, 2021 5:17 PM To: python-list@python.or

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 9:22 AM Grant Edwards wrote: > > On 2021-11-20, Chris Angelico wrote: > > > But you learn that it isn't the same as 1/3. That's my point. You > > already understand that it is *impossible* to write out 1/3 in > > decimal. Is it such a stretch to discover that you cannot wr

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-20, Ben Bacarisse wrote: > You seem to be agreeing with me. It's the floating point part that is > the issue, not the base itself. No, it's the base. Floating point can't represent 3/10 _because_ it's base 2 floating point. Floating point in base 10 doesn't have any problem represent

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Grant Edwards
On 2021-11-20, Chris Angelico wrote: > But you learn that it isn't the same as 1/3. That's my point. You > already understand that it is *impossible* to write out 1/3 in > decimal. Is it such a stretch to discover that you cannot write 3/10 > in binary? For many people, it seems to be. There ar

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 8:32 AM Avi Gross via Python-list wrote: > > This discussion gets tiresome for some. > > Mathematics is a pristine world that is NOT the real world. It handles > near-infinities fairly gracefully but many things in the real world break > down because our reality is not infi

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Chris Angelico
On Sun, Nov 21, 2021 at 6:51 AM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse > >> > wrote: > >> >> > >> >> Chris Angelico writes: > >> >>

RE: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Avi Gross via Python-list
This discussion gets tiresome for some. Mathematics is a pristine world that is NOT the real world. It handles near-infinities fairly gracefully but many things in the real world break down because our reality is not infinitely divisible and some parts are neither contiguous nor fixed but in some

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Ben Bacarisse
Chris Angelico writes: > On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: >> >> Chris Angelico writes: >> >> > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse >> > wrote: >> >> >> >> Chris Angelico writes: >> >> >> >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse >> >> > wrote: >> >>

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-19 Thread Chris Angelico
On Sat, Nov 20, 2021 at 3:41 PM Ben Bacarisse wrote: > > Chris Angelico writes: > > > On Sat, Nov 20, 2021 at 12:43 PM Ben Bacarisse wrote: > >> > >> Chris Angelico writes: > >> > >> > On Sat, Nov 20, 2021 at 9:07 AM Ben Bacarisse > >> > wrote: > >> >> > >> >> Chris Angelico writes: > >> >>

  1   2   3   4   5   6   7   8   9   10   >