Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed6.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'problem:': 0.07; 'ugly': 0.07; 'python': 0.09; 'convention,': 0.09; 'objects.': 0.09; 'underscore': 0.09; '(but': 0.15; 'oct': 0.16; 'subject:interfaces': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'this:': 0.23; 'user.': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'language.': 0.27; 'c++': 0.27; 'joe': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'dictionary': 0.29; 'methods.': 0.29; 'restricted': 0.29; "i'm": 0.29; 'classes': 0.30; 'function': 0.30; 'header:Received:8': 0.30; 'received:74.125.82': 0.33; 'instances': 0.33; 'to:addr:python- list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'created': 0.36; 'but': 0.36; 'received:74.125': 0.36; '(i.e.': 0.36; 'does': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'some': 0.38; 'sure': 0.38; 'there,': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'think': 0.40; 'leading': 0.61; 'enforced': 0.84; 'notion': 0.84; 'subject:Nice': 0.84 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=iRJEzQ8N74E4nrqPIHOYu9guwAhvj1THVPQNWWU60dc=; b=GxKD2d9XpJIxeCAOFT0WL/zyUgtPiHplgpglQimXuXolIKxkl2LUgFCbP6GlvftC54 EgYFgXmeJNNWpIAvQLGCqS1JDXZw18g2Kb6ntoOeHmnFZEC1xnJOnRy6HRwMsmBr35GJ nDdgQMD3KWtAU9/PC9VkY+8IvTehW1I7+WIA/3bRmtDIUsVc8t6a9Db7QOvwfgrI1IG1 3dPCYrA9ogHQDXxruPk2XcAZgr1DRk4LMD+EIlaj0Is9arJ3pi2GZj615GgVnX3N+gmr kaES3sd1mRNcbNvJSahx6EcO0bfOek6YNf6yFXxPIW3x2vS/cleaFnkXpdf7aWv5tdcJ iMCg== MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 29 Oct 2012 09:41:56 -0700 Subject: Re: Nice solution wanted: Hide internal interfaces From: Benjamin Kaplan To: python-list@python.org Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQmWeA6cW5+bRJawvC3+B1SNe1G+qQ2Vo4Jyy1KpyuNWS/g+DjwtmPtgXH/R/vr94VwhsjYuUvZPOBMWZpAF+IQnTstBmIHbE2YuIpFIjww9M1p1FpqmswSJlv1UA69R97DsaQLiFmAHFc7NYWDsf76FEHIiFA== X-Junkmail-Whitelist: YES (by domain whitelist at mpv1.tis.cwru.edu) 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351529114 news.xs4all.nl 6950 [2001:888:2000:d::a6]:55574 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32395 On Mon, Oct 29, 2012 at 9:33 AM, Johannes Bauer wrote: > Hi there, > > I'm currently looking for a good solution to the following problem: I > have two classes A and B, which interact with each other and which > interact with the user. Instances of B are always created by A. > > Now I want A to call some private methods of B and vice versa (i.e. what > C++ "friends" are), but I want to make it hard for the user to call > these private methods. > > Currently my ugly approach is this: I delare the internal methods > private (hide from user). Then I have a function which gives me a > dictionary of callbacks to the private functions of the other objects. > This is in my opinion pretty ugly (but it works and does what I want). > > I'm pretty damn sure there's a nicer (prettier) solution out there, but > I can't currently think of it. Do you have any hints? > > Best regards, > Joe > What do you mean "declare the internal methods private"? Python doesn't have this notion of restricted access. By convention, names starting with a leading underscore are private, but it's not enforced by the language.