What is Python zoneinfo.TZPATH?
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
zoneinfomodule is included in Python version 3.9 or later.
Syntax
zoneinfo.TZPATH
Code
Example 1
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)
Example 2
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)
Understanding the paths
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/zoneinfocontains onlyAmerica/Los_Angeles
and:
/etc/zoneinfocontains bothAmerica/Los_AngelesandAsia/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.