TZPATH
is a read-only global variable that is of datatype tuple
in the zoneinfo
module.
TZPATH
holds paths to search for timezone files in the IANA timezone database during the creation of a zoneinfo.ZoneInfo
object.
TZPATH
only contains an absolute path and can be changed with the reset_tzpath()
function.
Note: The
zoneinfo
module is included in Python version 3.9 or later.
zoneinfo.TZPATH
In the code snippet below, we import the zoneinfo
module and print the TZPATH
with zoneinfo.TZPATH
to the console. This outputs the tuple that contains the paths.
import zoneinfoprint(zoneinfo.TZPATH)
Since TZPATH
returns a tuple, we loop through zoneinfo.TZPATH
in the code below and individually print it to the console.
import zoneinfofor path in zoneinfo.TZPATH:print(path)
When a ZoneInfo
instance is created from a key, the zone file is constructed from the “first data source on the path where the key exists.” The key is joined to each entry in the TZPATH
.
Note: Run the code above to understand the paths provided in this example.
Let’s say:
/usr/lib/zoneinfo
contains only America/Los_Angeles
and:
/etc/zoneinfo
contains both America/Los_Angeles
and Asia/Tokyo
In this scenario:
ZoneInfo("America/Los_Angeles")
would be satisfied by this path: /usr/lib/zoneinfo/America/Los_Angeles
, while:
ZoneInfo("Asia/Tokyo")
would be satisfied by /etc/zoneinfo/Asia/Tokyo
this time zone path.