# Using system.date.now() as default parameter

**URL:** <https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [March 13, 2024, 9:57pm UTC](https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306 "2024-03-13T21:57:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_Shoemake](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tyler_shoemake/32/55661_2.png) [@Tyler\_Shoemake](https://forum.inductiveautomation.com/u/Tyler_Shoemake)\
**Post date:** [March 13, 2024, 9:57pm UTC](https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306/1 "2024-03-13T21:57:29Z")

</div>

It seems to me like using system.date.now() as a default parameter in a function is bad practice because...

> [@Kevin.Herron](#):
>
> Python named parameter values are evaluated once, when the function is defined, not every time the function is called.

This is easy to see within the script console, but when you apply this concept to the script library, you could call a function much later than a few seconds and it will use the an earlier value. Saving your project will cause this variable to be re-evaluated. [See this example in the script console.](https://youtu.be/-O5TfZN-bpU)

```auto
from time import sleep

def test(date=system.date.now()):
	return date

for i in range(10):
	sleep(1)
	test() 

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 13, 2024, 10:01pm UTC](https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306/2 "2024-03-13T22:01:52Z")

</div>

This is not a bug, it's working as intended.

Python named parameter values are evaluated once, when the function is defined, not every time the function is called.

---

<div class="post-metadata">

**Author:** ![Tyler\_Shoemake](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tyler_shoemake/32/55661_2.png) [@Tyler\_Shoemake](https://forum.inductiveautomation.com/u/Tyler_Shoemake)\
**Post date:** [March 13, 2024, 10:11pm UTC](https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306/3 "2024-03-13T22:11:31Z")

</div>

Is the garbage collector the only condition that causes this value to need to be reevaluated?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 13, 2024, 10:12pm UTC](https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306/4 "2024-03-13T22:12:17Z")

</div>

No, GC is not relevant.

As far as Ignition goes, saving your project will cause it be re-evaluated because that's when all the script modules get loaded/executed and the function is defined.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 13, 2024, 10:14pm UTC](https://forum.inductiveautomation.com/t/using-system-date-now-as-default-parameter/87306/5 "2024-03-13T22:14:52Z")

</div>

Try this if you really want a named parameter with a default value that is "live" each time:

```python
def test(date=None):
	if not date:
		date = system.date.now()

```
