[issue38451] Datetime definition does not work in function definition as list definition

2019-10-12 Thread Steven D'Aprano
Steven D'Aprano added the comment: Oh, I forgot to mention that this is discussed in one of the FAQs: https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects -- ___ Python tracker

[issue38451] Datetime definition does not work in function definition as list definition

2019-10-12 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug, this is the design of function default arguments. Default arguments in Python use *early binding*, which means they are calculated once, when the function is declared, rather than *late binding*, which means they are calculated each time

[issue38451] Datetime definition does not work in function definition as list definition

2019-10-11 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Default arguments are evaluated only once as the function is defined and not per call. This is a common gotcha : https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument --

[issue38451] Datetime definition does not work in function definition as list definition

2019-10-11 Thread Pouria
Pouria added the comment: For example Def a(time=datetime.datetime.today()): Print(time) Output: The output of each run is equal to the first time output For exaple : If you run a() Sleep(10) a() Sleep(10) a() You see one output

[issue38451] Datetime definition does not work in function definition as list definition

2019-10-11 Thread Terry J. Reedy
Terry J. Reedy added the comment: Without more information, we cannot do anything with this. -- nosy: +terry.reedy status: open -> pending versions: -Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8 ___ Python tracker

[issue38451] Datetime definition does not work in function definition as list definition

2019-10-11 Thread Karthikeyan Singaravelan
New submission from Karthikeyan Singaravelan : Can you please add an example of the issue and the actual/expected behavior? -- nosy: +xtreak ___ Python tracker ___

[issue38451] Datetime definition does not work in function definition as list definition

2019-10-11 Thread Pouria
Change by Pouria : -- components: Library (Lib) nosy: Pouria_ff priority: normal severity: normal status: open title: Datetime definition does not work in function definition as list definition type: behavior versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python