Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '*args,': 0.09; 'http': 0.09; 'part,': 0.09; 'subject:()': 0.09; 'python': 0.11; 'def': 0.12; '**kwargs)': 0.16; '**kwargs):': 0.16; 'behave': 0.16; 'executed.': 0.16; 'name):': 0.16; 'implementing': 0.19; 'this:': 0.26; 'post': 0.26; 'skip:" 20': 0.27; 'idea': 0.28; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'marc': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'classes': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessing': 0.36; 'hi,': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'name': 0.63; 'request.': 0.70; 'subject:skip:o 10': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=IaDAO9a6s4MgSugMqOCpqMsgIjcobc/CzIwqhI6c1JM=; b=LSOVh80/t/QD/1Z0Xy66ztFK7+3mAUy5Pi10BO13VEw8/kPanp6b4KHekCrb/AbNB0 aGftkZ9n5INwqNKFwea22MBYil8A40Rraxig1+bc47OHCCTCYHsVu5tDkczSfZdldvLM 4xexD7ZKhZFfOJdz+G58tp3fXTfa2VUbTfkWFS2CteP5Xw0FoaF89/daR0lOS2O6tkWq vmqzEKTqQ9E+nskp8diR35Z5LOxZGWFN6ODeC6fclfsRa6Bk+t4v5KslDgfJQ2YnoYET BiiyfP+VlKvzJyxcw2ThfWwDxgqwiiUWk3AsurS1UaWHV4plkKoUtOSvIH+gRDxWPIXK TwCg== X-Received: by 10.58.46.18 with SMTP id r18mr21249564vem.4.1385297591725; Sun, 24 Nov 2013 04:53:11 -0800 (PST) MIME-Version: 1.0 From: Marc Aymerich Date: Sun, 24 Nov 2013 13:52:51 +0100 Subject: Implement logic on object.attribute and object.attribute() To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385297594 news.xs4all.nl 15871 [2001:888:2000:d::a6]:46200 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60363 Hi, I'm playing with python internals to make objects behave like this: if I access to "object.attribute" I want to return the result of an HTTP GET request. However if i call "object.attribute()" I want an HTTP POST request to be executed. So far I have been able to do the POST part, using two classes like this: class HTTPAttribute(object): def __init__(self, name): self.name = name def __call__(self, *args, **kwargs): url = BASE_URL + self.name requests.post(url, *args, **kwargs) class HTTPObject(object): def __getattr__(self, name): return HTTPAttribute(name) But I'm stuck implementing the HTTP GET request when accessing "object.attribute", Any idea ?? Thanks!! -- Marc