CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sat, 19 Jul 2025 07:41:59 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071208094508
location: https://web.archive.org/web/20071208094508/https://wiki.python.org/moin/EnumerationProgramming
server-timing: captures_list;dur=0.501409, exclusion.robots;dur=0.017034, exclusion.robots.policy;dur=0.007855, esindex;dur=0.010092, cdx.remote;dur=87.118683, LoadShardBlock;dur=146.271920, PetaboxLoader3.datanode;dur=86.100962, PetaboxLoader3.resolve;dur=37.482709
x-app-server: wwwb-app215
x-ts: 302
x-tr: 259
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app215; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Sat, 19 Jul 2025 07:42:00 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Sat, 08 Dec 2007 09:45:07 GMT
x-archive-orig-server: Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 08 Dec 2007 09:45:08 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 06 May 2006 22:15:09 GMT", ; rel="prev memento"; datetime="Sat, 24 Mar 2007 11:21:10 GMT", ; rel="memento"; datetime="Sat, 08 Dec 2007 09:45:08 GMT", ; rel="next memento"; datetime="Thu, 11 Aug 2011 05:43:58 GMT", ; rel="last memento"; datetime="Sat, 13 Jul 2024 11:02:06 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_1_20071208084132_crawl105-c/52_1_20071208094005_crawl107.arc.gz
server-timing: captures_list;dur=0.516541, exclusion.robots;dur=0.017762, exclusion.robots.policy;dur=0.008540, esindex;dur=0.011368, cdx.remote;dur=6.646415, LoadShardBlock;dur=265.237864, PetaboxLoader3.datanode;dur=84.944498, PetaboxLoader3.resolve;dur=203.588888, load_resource;dur=96.742544
x-app-server: wwwb-app215
x-ts: 200
x-tr: 419
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
EnumerationProgramming - PythonInfo Wiki
EnumerationProgramming
Enumeration Programming
Why, When
This Implementation is really near to the UML description of <<Enumeration>>. It uses new style class.
Code
1 # code is public domain
2 import sets
3
4 class Enumeration(object):
5
6 def __new__(cls, arg):
7 if hasattr(cls, arg):
8 return getattr(cls,arg)
9 else:
10 return object.__new__(cls, arg)
11
12 def __init__(self, name):
13 self._name = name
14 setattr(self.__class__, name, self)
15
16 def __str__(self):
17 return '#%s' % str(self._name)
18
19 def __repr__(self):
20 return "%s('%s')" % (self.__class__.__name__, self._name)
21
22 def getEnumerationSet(cls):
23 result = sets.Set()
24 for attr in dir(cls):
25 attr = getattr(cls, attr)
26 if isinstance(attr, Enumeration):
27 result.add(attr)
28 return result
29 getEnumerationSet = classmethod(getEnumerationSet)
Example
1 class PrimaryColorKind(Enumeration):
2 pass
3 PrimaryColorKind('Rouge')
4 PrimaryColorKind('Vert')
5 PrimaryColorKind('Bleu')
6
7 print str(PrimaryColorKind.Rouge), str(PrimaryColorKind.Vert), str(PrimaryColorKind.Bleu)
8 print PrimaryColorKind.getEnumerationSet()
9
10 class ColorKind(PrimaryColorKind):
11 pass
12 ColorKind('Violet')
13
14
15 print str(ColorKind.Rouge), str(ColorKind.Violet)
16 print ColorKind.getEnumerationSet()
17 print repr(ColorKind.Rouge), repr(ColorKind.Violet)
18 assert(ColorKind.Rouge is ColorKind('Rouge'))
output is :
#Rouge #Vert #Bleu Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), PrimaryColorKind('Bleu')]) #Rouge #Violet Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), ColorKind('Violet'), PrimaryColorKind('Bleu')]) PrimaryColorKind('Rouge') ColorKind('Violet') mirville Python 79 % python Enumeration.py #Rouge #Vert #Bleu Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), PrimaryColorKind('Bleu')]) #Rouge #Violet Set([PrimaryColorKind('Vert'), PrimaryColorKind('Rouge'), ColorKind('Violet'), PrimaryColorKind('Bleu')]) PrimaryColorKind('Rouge') ColorKind('Violet')
EditText (last edited 2004-04-14 10:03:08 by mirville)
DeleteCache (cached 2007-11-21 12:25:28)- Login
- Navigation
- Actions
- Your recent pages