Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36057

Re: Can't seem to start on this

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <darcy@druid.net>
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; 'argument': 0.04; 'none,': 0.05; 'none:': 0.05; '-0500': 0.07; 'none):': 0.07; 'python': 0.09; '"a"': 0.09; '425': 0.09; 'imported': 0.09; 'subclass': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'static': 0.13; '"b"': 0.16; '"d",': 0.16; 'all"': 0.16; 'im:': 0.16; 'instantiate': 0.16; 'length,': 0.16; 'subject:start': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'jan': 0.18; 'module': 0.19; 'file.': 0.20; 'import': 0.21; 'voting': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'cc:no real name:2**0': 0.24; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'setting': 0.26; 'instead.': 0.27; 'coded': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'this.': 0.29; 'maybe': 0.29; 'classes': 0.30; 'code': 0.31; 'file': 0.32; 'could': 0.32; 'likely': 0.33; 'another': 0.33; 'changed': 0.34; 'something': 0.35; 'there': 0.35; 'except': 0.36; 'but': 0.36; 'wanted': 0.36; 'modules': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.37; 'ok,': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'gives': 0.39; 'notice': 0.39; 'called': 0.39; 'your': 0.60; 'most': 0.61; 'stay': 0.61; 'provide': 0.62; 'different': 0.63; 'within': 0.64; 'started.': 0.65; 'sounds': 0.71; 'subject:this': 0.84; '"stop"': 0.84; '2013': 0.84; 'democracy': 0.84; 'etc,': 0.84; 'received:98.158': 0.84; 'ideas.': 0.91
Date Thu, 3 Jan 2013 08:20:31 -0500
From "D'Arcy J.M. Cain" <darcy@druid.net>
To Kene.Meniru@illom.org
Subject Re: Can't seem to start on this
In-Reply-To <kc31l4$27v$1@ger.gmane.org>
References <kc31l4$27v$1@ger.gmane.org>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.14; x86_64--netbsd)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.34.1357219805.2939.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357219805 news.xs4all.nl 6878 [2001:888:2000:d::a6]:45521
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36057

Show key headers only | View raw


On Wed, 02 Jan 2013 23:32:33 -0500
Kene Meniru <Kene.Meniru@illom.org> wrote:
> This sounds so simple but being new to python I am finding it hard to
> get started. I want to create a module which I will call "B". There
> will be other modules called "C", "D", etc, which will most likely be
> imported in "B". Then I want the user to import "B" ONLY into another
> file I will call "A" in which commands such as the following will be
> entered:
> 
> snap_size = 10
> LinearMark(name)
> LinearMark.put(name, length, rotation, (x,y,z))

Sounds messy.

> The file "A" allows the user to enter commands that provide global
> variables as well as to use classes provided in modules "C", "D",

OK, "global variables" is the clue that you need to rethink this.  Try
to stay away from global variables as much as possible except for maybe
some simple setup variables within the same file.  Consider something
like this instead.

In file B:

class TopClass(object):
  def __init__(self, snap_size, var1 = None, var2 = None):
    self.snap_size = snap_size
    self.var1 = var1
    if var2 is None: self.var2 = 7
    self.var3 = "GO"
    self.var4 = "Static string"

    *add class methods here*

In file A:

class MyClass(TopClass):
    def __init__(self, var1):
        TopClass.__init__(self, 10, var1, 8)
        self.var3 = "STOP"

x = MyClass(42)
x.var4 = "Not so static after all"

In this (untested) example you create your top class in B and then
subclass it in A.  Notice the different way of setting variables here.
In MyClass we hard code snap_size to 10, we set var1 from the argument
when we instantiate it, var2 is hard coded to 8 but could be left out
if we wanted the default of 7, var3 is overwritten in MyClass and var4
is changed after the class is instantiated.

Hope this gives you some ideas.

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
IM: darcy@Vex.Net

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Can't seem to start on this "D'Arcy J.M. Cain" <darcy@druid.net> - 2013-01-03 08:20 -0500

csiph-web