Python 2.7은 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
Expando 클래스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
참고: 새로운 애플리케이션을 빌드하는 개발자는 NDB 클라이언트 라이브러리를 사용하는 것이 좋습니다. NDB 클라이언트 라이브러리는 이 클라이언트 라이브러리와 비교할 때 Memcache API를 통한 자동 항목 캐싱과 같은 여러 이점이 있습니다. 현재 이전 DB 클라이언트 라이브러리를 사용 중인 경우 DB에서 NDB로의 마이그레이션 가이드를 참조하세요.
Expando 클래스는 속성이 동적으로 결정되는 데이터 모델 정의의 상위 클래스입니다. Expando 모델에서는 런타임 시 항목에 할당되는 동적 속성 및 Model과 유사한 고정 속성을 조합할 수 있습니다.
Expando
는 google.appengine.ext.db
모듈에서 제공됩니다.
Expando는 Model의 서브클래스이며 해당 클래스에서 클래스와 인스턴스 메서드를 상속받습니다. Expando 클래스는 메소드를 정의하거나 재정의하지 않습니다.
소개
Expando 모델에는 고정 속성과 동적 속성이 있을 수 있습니다. 고정 속성은 Model 속성과 유사하게 동작하며 Expando 모델 클래스에서 클래스 속성을 사용하여 유사하게 정의됩니다. 동적 속성은 값이 인스턴스에 할당될 때 생성됩니다. 동일한 Expando 클래스의 두 인스턴스가 서로 다른 동적 속성 집합을 가질 수 있으며, 이름이 같지만 유형은 다른 동적 속성을 가질 수도 있습니다. 동적 속성은 항상 선택사항이며 기본값이 없습니다. 또한 값이 할당될 때까지 존재하지 않습니다.
동적 속성은 속성 인스턴스를 사용하여 검증을 수행하거나, 기본값을 설정하거나, 자동 논리를 값에 적용할 수 없습니다. 동적 속성에는 지원되는 데이터 저장소 유형 값만 저장됩니다. 유형 및 속성 클래스를 참조하세요.
고정 속성과 달리 동적 속성은 클래스 속성과 데이터 저장소 속성 이름으로 다른 이름을 사용할 수 없습니다. 허용되지 않는 속성 이름을 참조하세요.
팁: Property 클래스를 사용하여 동적 속성 값 유효성을 검사하려면 Property 클래스를 인스턴스화하고 값에서 validate() 메서드를 호출하면 됩니다.
Expando 하위 클래스는 Model 클래스와 유사한 고정 속성을 정의할 수 있습니다. Expando의 고정 속성은 Model의 속성과 유사하게 동작합니다. Expando 인스턴스에는 고정 속성과 동적 속성이 모두 있을 수 있습니다.
import datetime
from google.appengine.ext import db
class Song(db.Expando):
title = db.StringProperty()
crazy = Song(title='Crazy like a diamond',
author='Lucy Sky',
publish_date='yesterday',
rating=5.0)
hoboken = Song(title='The man from Hoboken',
author=['Anthony', 'Lou'],
publish_date=datetime.datetime(1977, 5, 3))
crazy.last_minute_note=db.Text('Get a train to the station.')
Expando 인스턴스의 동적(비 고정) 속성을 삭제할 수 있습니다. 동적 속성을 삭제하려면 애플리케이션이 인스턴스 속성을 삭제합니다.
del crazy.last_minute_note
생성자
Expando 클래스 생성자는 다음과 같이 정의됩니다.
- class Expando(parent=None, key_name=None, **kwds)
-
사용하기 전에 클래스에서 속성을 정의할 필요가 없는 모델 클래스입니다. Model과 마찬가지로 Expando 클래스에서 데이터 항목 종류를 정의하려면 하위 클래스로 처리해야 합니다.
Expando는 Model의 하위 클래스이며 해당 메소드를 상속하거나 재정의합니다.
인수
- parent
- 새 항목의 상위 요소인 항목의 모델 인스턴스 또는 키 인스턴스입니다.
- key_name
-
새 항목의 이름입니다. 이름은 기본 키에 포함됩니다. None
인 경우 시스템에서 생성된 ID가 키에 사용됩니다.
key_name 값은 숫자로 시작해서는 안 되고 __*__
형식이 아니어야 합니다. 애플리케이션이 사용자가 제출한 데이터(예: 이메일 주소)를 Datastore 항목 키 이름으로 사용하는 경우 이러한 요구사항을 충족하기 위해 애플리케이션이 먼저 'key:'과 같이 알려진 문자열을 접두사로 추가하여 값을 처리해야 합니다.
key_name
은 ASCII 텍스트로 변환된 str
값이 있는 유니코드 문자열로 저장됩니다.
- **kwds
- 인스턴스 속성의 초기 값이며 키워드 인수로 사용됩니다. 각 이름은 새 인스턴스의 속성과 일치하며 Expando 클래스에서 정의된 고정 속성과 일치하거나 동적 속성일 수 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eDevelopers should prioritize the NDB Client Library over the older DB Client Library for new applications due to benefits like automatic entity caching.\u003c/p\u003e\n"],["\u003cp\u003eThe Expando class allows for the creation of entities with both fixed properties, similar to those in the Model class, and dynamic properties that are assigned at runtime.\u003c/p\u003e\n"],["\u003cp\u003eDynamic properties in Expando are optional, lack default values, and are created when they're assigned a value, and these properties do not support property classes or name aliasing.\u003c/p\u003e\n"],["\u003cp\u003eExpando instances can have a mix of fixed and dynamic properties, with the latter able to be deleted by removing the corresponding attribute from the instance.\u003c/p\u003e\n"],["\u003cp\u003eThe Expando constructor allows setting a parent, key name, and initial property values, supporting both fixed and dynamic properties through keyword arguments.\u003c/p\u003e\n"]]],[],null,["# The Expando Class\n\n**Note:**\nDevelopers building new applications are **strongly encouraged** to use the\n[NDB Client Library](/appengine/docs/legacy/standard/python/ndb), which has several benefits\ncompared to this client library, such as automatic entity caching via the Memcache\nAPI. If you are currently using the older DB Client Library, read the\n[DB to NDB Migration Guide](/appengine/docs/legacy/standard/python/ndb/db_to_ndb)\n\nThe Expando class is a superclass for data model definitions whose properties are determined dynamically. An Expando model can have a combination of fixed properties similar to [Model](/appengine/docs/legacy/standard/python/datastore/modelclass) and dynamic properties assigned to an entity at run-time.\n\n`Expando` is provided by the `google.appengine.ext.db` module.\n\nExpando is a subclass of [Model](/appengine/docs/legacy/standard/python/datastore/modelclass), and inherits its class and instance methods from that class. The Expando class does not define or override any methods.\n\nIntroduction\n------------\n\nAn Expando model can have fixed properties and dynamic properties. Fixed properties behave similar to properties of a [Model](/appengine/docs/legacy/standard/python/datastore/modelclass), and are similarly defined in the Expando model class using class attributes. Dynamic properties are created when they are assigned values on the instance. Two instances of the same Expando class can have different sets of dynamic properties, and can even have dynamic properties with the same name but different types. Dynamic properties are always optional, and have no default value: They don't exist until they are assigned a value.\n\nDynamic properties cannot use [Property](/appengine/docs/legacy/standard/python/datastore/propertyclass) instances to perform validation, set defaults or apply automatic logic to values. Dynamic properties simply store values of the supported datastore types. See [Types and Property Classes](/appengine/docs/legacy/standard/python/datastore/typesandpropertyclasses).\n\nAlso unlike fixed properties, dynamic properties cannot use a different name for the class attribute and the datastore property name. See [Disallowed Property Names](/appengine/docs/legacy/standard/python/datastore/modelclass#Disallowed_Property_Names).\n\n**Tip:** If you want to validate a dynamic property value using a Property class, you can instantiate the Property class and call its [validate()](/appengine/docs/legacy/standard/python/datastore/propertyclass#Property_validate) method on the value.\n\nAn Expando subclass can define fixed properties similar to a [Model](/appengine/docs/legacy/standard/python/datastore/modelclass) class. Fixed properties of an Expando behave similarly to properties of a Model. An Expando instance can have both fixed and dynamic properties. \n\n```python\nimport datetime\n\nfrom google.appengine.ext import db\n\nclass Song(db.Expando):\n title = db.StringProperty()\n\ncrazy = Song(title='Crazy like a diamond',\n author='Lucy Sky',\n publish_date='yesterday',\n rating=5.0)\n\nhoboken = Song(title='The man from Hoboken',\n author=['Anthony', 'Lou'],\n publish_date=datetime.datetime(1977, 5, 3))\n\ncrazy.last_minute_note=db.Text('Get a train to the station.')\n```\n\nAn Expando instance's dynamic (non-fixed) properties can be deleted. To delete a dynamic property, an application deletes the instance's attribute: \n\n```\ndel crazy.last_minute_note\n```\n\nConstructor\n-----------\n\nThe constructor of the Expando class is defined as follows:\n\nclass Expando(parent=None, key_name=None, \\*\\*kwds)\n\n: A model class whose properties do not need to be defined in the class before use. Like [Model](/appengine/docs/legacy/standard/python/datastore/modelclass), the Expando class must be subclassed to define the kind of the data entities.\n\n Expando is a subclass of [Model](/appengine/docs/legacy/standard/python/datastore/modelclass), and inherits or overrides its methods.\n\n Arguments\n\n parent\n : The Model instance or Key instance for the entity that is the new entity's parent.\n\n key_name\n\n : The name for the new entity. The name becomes part of the primary key. If `None`, a system-generated ID is used for the key.\n\n The value for key_name must not start with a number, and must not be of the form `__*__`. If your application uses user-submitted data as datastore entity key names (such as an email address), the application should sanitize the value first, such as by prefixing it with a known string like \"key:\", to meet these requirements.\n\n A `key_name` is stored as a Unicode string, with `str` values converted as ASCII text.\n\n \\*\\*kwds\n : Initial values for the instance's properties, as keyword arguments. Each name corresponds with an attribute of the new instance, and may either correspond with fixed properties defined in the Expando class, or be dynamic properties."]]