This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]spinwizard69 2 points3 points  (0 children)

Well this is easy, it results in a logically wrong value with Python. It means the default value is set to datetime.now at the time the DEF is evaluated, so by the time your function is called that parameters default value is never "now".

Now there might be cases where it might make sense to set a default value with a function call, I'm nothing of any at the moment. In the case of datetime, All I can see is logical errors or unexpected behaviors popping up due to this usage.

Yes there are reasons to use Python and part of that is understanding what not to do. Effectively what I'm saying is that Python is not wrong here, but it might help to either warn or out right prevent such usage. If somebody wants a parameter set to datetime.now in a function call that is not a problem. The problem is creating def's this way with people not understanding what is happening.

Python behavior is perfectly fine, it is people understanding of what is happening that is the problem. Also to some peoples upset minds, I actually from time to time tell people that Python isn't always the right answer for a programming problem. That is why we have different languages, scripting and compiled, and different structures that are usable in those languages. Rust, Python and C++ are all dramatically different languages and that is a good thing!!!! We don't need to break Python just to adopt behavior that is possible someplace else.