Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12952
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <egbertum@xs4all.nl> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'correspond': 0.07; '__name__': 0.09; 'argument,': 0.09; 'subclass': 0.09; 'classes,': 0.13; 'def': 0.15; '1016': 0.16; '197': 0.16; '6257991': 0.16; 'bouwman': 0.16; 'egbert': 0.16; 'from:addr:egbertum': 0.16; 'from:addr:xs4all.nl': 0.16; 'from:name:egbert': 0.16; 'instances.': 0.16; 'message-id:@xs4all.nl': 0.16; 'namespace,': 0.16; 'namespace.': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:83.161': 0.16; 'received:83.161.205': 0.16; 'received:83.161.205.148': 0.16; 'received:xs4all.nl': 0.16; 'tried:': 0.16; 'skip:= 70': 0.17; '020': 0.18; 'amsterdam': 0.23; 'classes': 0.28; 'class': 0.30; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'assignment': 0.34; 'object': 0.35; 'charset:us-ascii': 0.36; 'file': 0.36; 'statements': 0.37; 'variables': 0.37; 'several': 0.37; 'but': 0.37; 'something': 0.37; 'two': 0.37; 'move': 0.38; 'itself.': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'eliminate': 0.63; 'phase': 0.82; 'subject:class': 0.84 |
| Date | Thu, 8 Sep 2011 11:55:02 +0200 |
| From | egbert <egbertum@xs4all.nl> |
| To | python-list@python.org |
| Subject | DRY and class variables |
| Mail-Followup-To | egbert <egbertum@xs4all.nl>, python-list@python.org |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-Virus-Scanned | by XS4ALL Virus Scanner |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.870.1315476073.27778.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1315476073 news.xs4all.nl 2420 [2001:888:2000:d::a6]:44956 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12952 |
Show key headers only | View raw
My classes correspond to sql tables.
In these classes I want to have several class variables
that refer to data that are common to all instances.
The assignment statements for the class variables are the same
in all classes, except that of these instructions needs the name
of the class itself. That name is used to read a file with meta-data.
So what I have now is something like this (simplified):
class TableOne(object):
m = Metadata('TableOne')
m.do_something()
def __init__(self):
etc
class TableTwo(object):
m = Metadata('TableTwo')
m.do_something()
def __init__(self):
etc
I have tried:
- to eliminate the class name argument, but in this phase of the
object creation __class__ and __name__ are not available
- to move the two statements to a superclass, but the class variables
come in the superclass namespace, not in the subclass namespace.
Any ideas ?
e
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
========================================================================
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
DRY and class variables egbert <egbertum@xs4all.nl> - 2011-09-08 11:55 +0200
csiph-web