Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.

alexmojaki/nameof

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nameof

This was a toy project, I recommend using varname instead.

Build Status Supports Python versions 3.4+, including PyPy

Get the name of a variable or attribute, as in C#.

Installation

pip install nameof

Or just copy nameof.py.

Usage

from nameof import nameof
assert nameof(foo) == "foo"
assert nameof(foo.bar) == "bar"

The argument must be a variable or attribute.

Caveats

This is funky and not battle-tested, use it with caution. If anything critical depends on it working correctly the calling code should be tested.

Doesn't work in the presence of some other magic, particularly magic that modifies the AST such as pytest or birdseye.

About

Python function to get the name of a variable or attribute, as in C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages