Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24907
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'function,': 0.07; 'wrapper': 0.07; 'arg': 0.09; 'underscore': 0.09; 'def': 0.10; '"private': 0.16; 'class:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:already': 0.16; 'subject:instance': 0.16; 'subject:when': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance': 0.17; 'package.': 0.17; 'thu,': 0.17; '>>>': 0.18; 'received:209.85.214.174': 0.21; 'linux': 0.24; 'header:In-Reply-To:1': 0.25; 'creating': 0.26; 'common': 0.26; 'convention': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'chris': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'created': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'leading': 0.61; 'jul': 0.65 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=fKsM6E3GqOSgkVQeBrbbT9/f6L52uIovTYv1o+KbF9o=; b=I/jjR4CmXrNqDRiYsUvTe+2C2VPRaMOZbTieydYMwDfKia5ElgY9lUUoNjYF/aRZgu hH1SXhwaqyCsSf6unwPpEweyZZkapGQfHRhoVQkVLN4lg05hEmtXRa2Ux8lX1dc8NiII QPmxGH2jOZcP2pomRQbMN+n6m5nnjBksMsNgNKTg7mIP4asgj+GRvAB6kzVS9cxP/dk+ wm4kOVCInjV9k7hM+iWN40B961HVHb1rATRVDxCr0vwH0PF8apaVhrI8DEXtdAHKikw+ AnMipTXNgVEiSV6wGiK3dTGRAw2SHEid/qmi/11t7aQNAWX7f5DzBN5esNDRUUBOhuum m9Bw== |
| MIME-Version | 1.0 |
| In-Reply-To | <20120705122924.481a546b@bigfoot.com> |
| References | <20120705122924.481a546b@bigfoot.com> |
| Date | Thu, 5 Jul 2012 20:47:52 +1000 |
| Subject | Re: Creating an instance when the argument is already an instance. |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.1820.1341485274.4697.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1341485274 news.xs4all.nl 6981 [2001:888:2000:d::a6]:40301 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:24907 |
Show key headers only | View raw
On Thu, Jul 5, 2012 at 8:29 PM, Olive <diolu@bigfoot.com> wrote:
> I am creating a new class: package (to analyse the packages database in
> some linux distros). I have created a class package such that
> package("string") give me an instance of package if string is a correct
> representation of a package. I would like that if pack is already an
> instance of package then package(pack) just return pack.
One way would be to make the name "package" actually a wrapper
function, not the class itself:
>>> class _package:
def __init__(self,arg):
# blah blah
self.asdf=arg
>>> def package(arg):
if isinstance(arg,_package): return arg
return _package(arg)
>>> a=package("Test")
>>> b=package(a)
>>> a is b
True
The leading underscore is a common convention meaning "private
implementation detail".
Chris Angelico
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Creating an instance when the argument is already an instance. Olive <diolu@bigfoot.com> - 2012-07-05 12:29 +0200
Re: Creating an instance when the argument is already an instance. Chris Angelico <rosuav@gmail.com> - 2012-07-05 20:47 +1000
Re: Creating an instance when the argument is already an instance. Hans Mulder <hansmu@xs4all.nl> - 2012-07-05 16:43 +0200
Re: Creating an instance when the argument is already an instance. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-05 11:55 +0000
Re: Creating an instance when the argument is already an instance. Olive <diolu@bigfoot.com> - 2012-07-06 16:01 +0200
csiph-web