Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is Python zoneinfo.TZPATH?

Gutha Vamsi Krishna

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

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 zoneinfo
print(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 zoneinfo
for 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/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.

RELATED TAGS

python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring