App engine NDB: how to access verbose_name of a property

2024/10/6 5:44:46

suppose I have this code:

class A(ndb.Model):prop = ndb.StringProperty(verbose_name="Something")m = A()
m.prop = "a string value"

Now of course if I print m.prop, it will output "a string value" while in fact it's a StringProperty instance. So verbose_name can't be accessed the "normal" way, i.e m.prop._verbose_name.
I read the code and found a way to access it: m._properties["prop"]._verbose_name, it works, but it looks hacky o_o.
So tell me, is there another way to do it?
Note: I'm talking about the NDB API, not the old one

Answer

Use a class attribute: A.prop._verbose_name. Or m.__class__.prop._verbose_name.

https://en.xdnf.cn/q/73214.html

Related Q&A

How do I load specific rows from a .txt file in Python?

Say I have a .txt file with many rows and columns of data and a list containing integer values. How would I load the row numbers in the text file which match the integers in the list?To illustrate, sa…

How to check in python if Im in certain range of times of the day?

I want to check in python if the current time is between two endpoints (say, 8:30 a.m. and 3:00 p.m.), irrespective of the actual date. As in, I dont care what the full date is; just the hour. When I c…

Python __class__()

In Pythons documentation __class__ is described as an attribute. In the object type (the metaclass), __class__ appears to be a method.If we do:>>> class Foo:pass>>> a = Foo() >>…

how to handle ever-changing password in sqlalchemy+psycopg2?

I inherited some code that uses sqlalchemy with psycopg2, which needs to run on AWS. RDS Postgres supports iam-based authentication, but the way it does it is rather kludgy: you request a temporary pas…

How to determine which compiler was requested

My project uses SCons to manage the build process. I want to support multiple compilers, so I decided to use AddOption so the user can specify which compiler to use on the command line (with the defaul…

Does pytest have anything like google tests non-fatal EXPECT_* behavior?

Im more familiar with the google test framework and know about the primary behavior pair they support about ASSERT_* vs EXPECT_* which are the fatal and non-fatal assert modes.From the documentation:Th…

Radon transformation in python

Here is a dummy code:def radon(img):theta = np.linspace(-90., 90., 180, endpoint=False)sinogram = skimage.transform.radon(img, theta=theta, circle=True)return sinogram # end defI need to get the sinogr…

Librosa raised OSError(sndfile library not found) in Docker

Im trying to write the Dockerfile for a small python web project and there is something wrong with the dependencies. Ive been doing some search on the internet and it said that Librosa library requires…

Implementing Tags using Django rest framework

TDLR : what is the best way to implement tags in django-rest-framework. where the tags has a created_by field which is the currently authenticated user.I am trying to achieve a very simple/common thing…

Python audiolab install, unable to install (or find) libsndfile on Mac OSX

Trying to install scikits.audiolab-0.11.0 on Mac, bit it requires libsndfile: http://www.mega-nerd.com/libsndfile/. I did install libsndfile supposedly, using libsndfile_python-1.0.0-py2.7-macosx10.5.m…