Python .local()
Published Jun 3, 2022
Contribute to Docs
The .local() method returns a local thread object with data that is specific to that thread. This data can be anything from arbitrary numbers to session-specific information like usernames.
Syntax
threading.local()
No parameters are used in the .local() method.
Example
Data can be locally stored as a property in a specific thread, as shown in the example below:
The output would look like this:
12
Codebyte Example
Additionally, the object returned by .local() can be assigned to a variable, which is then stored in memory. Any stored data can be found in the local thread’s predefined __dict__ attribute:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours