Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'foo': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'solution,': 0.09; 'subject:files': 0.09; 'def': 0.13; 'question.': 0.15; '(normally': 0.16; 'indent': 0.16; 'narrow': 0.16; 'textually': 0.16; 'wrote:': 0.16; 'please?': 0.18; 'seems': 0.19; "doesn't": 0.22; 'obviously': 0.23; 'long.': 0.23; 'defined': 0.24; 'do,': 0.25; 'code': 0.25; 'import': 0.27; 'work.': 0.28; 'pass': 0.28; 'class': 0.29; 'rarely': 0.30; "isn't": 0.32; 'done': 0.33; 'to:addr:python-list': 0.33; 'searches': 0.34; 'header:X -Complaints-To:1': 0.34; 'file': 0.35; 'google': 0.36; 'but': 0.37; 'received:org': 0.37; 'some': 0.38; 'point': 0.39; 'define': 0.39; 'files': 0.39; 'subject:: ': 0.39; 'move': 0.40; 'to:addr:python.org': 0.40; 'under': 0.40; 'frank': 0.64; 'received:41': 0.70; 'ridiculously': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Distributing methods of a class across multiple files Date: Wed, 25 Jan 2012 10:26:04 +0200 References: <569a94a3-cd84-449b-b0c1-80348014aac6@i10g2000pbl.googlegroups.com> X-Gmane-NNTP-Posting-Host: 41-133-115-42.dsl.mweb.co.za X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327479985 news.xs4all.nl 6924 [2001:888:2000:d::a6]:53596 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19388 "lh" wrote: > Is this possible please? I have done some searching but it is hard to > narrow down Google searches to this question. What I would like to do > is, for example: > 1) define a class Foo in file test.py... give it some methods > 2) define a file test2.py which contains a set of methods that are > methods of class Foo defined in test.py. I can import Foo obviously > but it isn't clear to me how to identify the methods in test2.py to be > methods of class Foo defined in test.py (normally I would just indent > them "def"'s under the class but the class isn't textually in > test2.py). > > In short I would like to distribute code for one class across multiple > files so a given file doesn't get ridiculously long. > I take the point of the other responders that it is not a normal thing to do, but I had a few long but rarely used methods which I wanted to move out of the main file just to keep the main file tidier. I came up with this solution, and it seems to work. In test2.py - def long_method_1(): pass def long_method2(): pass In test.py - import test2 class Foo: long_method_1 = test2.long_method_1 long_method_2 = test2.long_method_2 Then in Foo I can refer to self.long_method_1(). HTH Frank Millman