That’s a pain, but I guess that “begin experiment” code needs to be about there so it can refer to variables that have been entered in the info dialog box.
Rather than using
datetime from the Python standard library, you could actually use the same PsychoPy function that Builder uses to automatically populate the date, but specify your own format string. This function is already imported for you, so no issues with code ordering. Here is the doc string for that
Uses ``time.strftime()``_ to generate a string of the form
2012_Apr_19_1531 for 19th April 3.31pm, 2012.
This is often useful appended to data filenames to provide unique names.
To include the year: getDateStr(format="%Y_%b_%d_%H%M")
returns '2011_Mar_16_1307' depending on locale, can have unicode chars
in month names, so utf_8_decode them
For date in the format of the current localization, do:
Agreed, the numerical
yyyy-mm-dd format is the recommended standard for most data science applications. Maybe it confuses some Americans due to their non-standard date traditions, but as you say, has the immense value of being sensibly sortable. The
data.getDateStr() function allows you to specify whatever format you want if you call it in code. I guess it is just sort of an accident that the default format is baked in to Builder, and it might be tricky to change now?
But maybe it would be worth suggesting a pull request to change it for future releases, as it would be better practice, and compatibility-wise, people shouldn’t be upgrading PsychoPy mid-experiment any way. There would need to be changes in a couple of places in the code base:
i.e. where the function should be called with a specified format string, rather than relying on the default.