Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.01; 'defines': 0.07; 'am,': 0.12; 'packages.': 0.13; 'blah': 0.16; 'from:addr:tyler': 0.16; 'from:addr:tysdomain.com': 0.16; 'from:name:littlefield, tyler': 0.16; 'message-id:@tysdomain.com': 0.16; 'myclass': 0.16; 'received:69.164': 0.16; 'received:69.164.206': 0.16; 'received:69.164.206.65': 0.16; 'received:tds-solutions.net': 0.16; 'reply-to:addr:tyler': 0.16; 'reply-to:addr:tysdomain.com': 0.16; 'wrote:': 0.16; 'this?': 0.21; 'trying': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'thus': 0.23; 'works.': 0.23; 'up.': 0.26; 'thanks.': 0.26; "i'm": 0.27; 'classes': 0.28; 'import': 0.28; 'looks': 0.29; 'module': 0.30; 'class': 0.30; 'there': 0.33; 'to:addr:python- list': 0.33; 'header:User-Agent:1': 0.34; 'rule': 0.34; 'like:': 0.34; 'supposed': 0.35; 'subject:How': 0.35; 'file': 0.36; 'another': 0.37; 'class.': 0.37; 'but': 0.37; 'could': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'goes': 0.39; "there's": 0.39; 'define': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'url:net': 0.60; 'more': 0.60; 'your': 0.61; 'care,': 0.64; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'promote': 0.81; 'package?': 0.84; 'so:': 0.84 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on wuff X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.1 Date: Wed, 07 Sep 2011 12:11:23 -0600 From: "Littlefield, Tyler" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.22) Gecko/20110902 Lightning/1.0b2 Thunderbird/3.1.14 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to structure packages References: <2a4f542c-a8c1-46c7-9899-a3fad0940cf6@x11g2000yqc.googlegroups.com> In-Reply-To: <2a4f542c-a8c1-46c7-9899-a3fad0940cf6@x11g2000yqc.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: tyler@tysdomain.com 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315419131 news.xs4all.nl 2426 [2001:888:2000:d::a6]:52191 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12908 On 9/7/2011 9:56 AM, bclark76 wrote: > I'm learning python, and was playing with structuring packages. > > Basically I want to have a package called mypackage that defines a > number of classes and functions. > > > so I create: > > mypackage > __init__.py > myfunc.py > MyClass.py > > > my __init__.py is blank. > > my MyClass.py looks like: > > import blah > > class MyClass(blahblah): > blah > blah > blah > > > then I have a run.py that looks like > > from mypackage import MyClass > > > x = MyClass() > > > This doesn't work because MyClass is mypackage.MyClass.MyClass. > There's this MyClass module 'in the way'. > You can use the __init__.py to promote that class up. so: from myclass import myclass So that means that myclass will just be in mypackage.myclass, and thus your from mypackage import myclass would work perfectly. I'm not sure if this is how you're supposed to do it, but it works. > I'm trying to follow the rule that every file defines only one class. > I could define MyClass in __init__.py, but then what if I wanted to > define more classes in the mypackage package? My one class per file > rule goes out the window. > > Is this rule wrongheaded, or is there another way to do this? > > > Thanks. > -- Take care, Ty Web: http://tds-solutions.net Sent from my toaster.