Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
how to reuse class deinitions?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sam  
View profile  
 More options Oct 1 2006, 6:27 pm
Newsgroups: comp.lang.python
From: "sam" <python....@googlemail.com>
Date: 1 Oct 2006 15:27:52 -0700
Local: Sun, Oct 1 2006 6:27 pm
Subject: how to reuse class deinitions?
hello all,

pretty straightforward question here, i think. i'm experimenting with
classes and have written a File class that looks like it's worth
keeping for future use. however, i cannot work out where to put it for
this purpose or how to get it in.

i figured i'd try a bit of (un)inspired guesswork by putting it in my
module folder, appending sys.path to tell the interpreter where this
was, and importing it like a module. probably don't need to tell you
that that didn't work, but i'm drawing a blank in the tutorial and not
getting any luck in the archives here. maybe i'm just not searching
with the right words. it's late here and my brain's switching off...

cutting and pasting it into the interpreter is a bit of a bore. any
help?

much appreciated in advance,

sam

PS i've just reached first base with classes, and i think i'm starting
to see what the big deal is about OOP. it's like someone's turned a
light on.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sam  
View profile  
 More options Oct 1 2006, 6:29 pm
Newsgroups: comp.lang.python
From: "sam" <python....@googlemail.com>
Date: 1 Oct 2006 15:29:52 -0700
Local: Sun, Oct 1 2006 6:29 pm
Subject: Re: how to reuse class deinitions?
should read 'definitions', of course. i hate stupid typos.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott David Daniels  
View profile  
 More options Oct 1 2006, 6:48 pm
Newsgroups: comp.lang.python
From: Scott David Daniels <scott.dani...@acm.org>
Date: Sun, 01 Oct 2006 15:48:48 -0700
Local: Sun, Oct 1 2006 6:48 pm
Subject: Re: how to reuse class deinitions?

sam wrote:
> pretty straightforward question here, i think. i'm experimenting with
> classes and have written a File class that looks like it's worth
> keeping for future use. however, i cannot work out where to put it for
> this purpose or how to get it in.

What I do:

For each new major version of python, in .../site-packages I make a
directory "sdd" (my initials).  In it I put an empty file named
"__init__.py".  When I have things I want to reuse, I put them in
files named things like ".../site-packages/sdd/goodidea.py", and
I get use of them in python programs like:

     from sdd.goodidea import File
     ...
     <code that uses File>
     ...

or (actually my current style):
     from sdd import goodidea
     ...
     <code that uses goodidea.File>
     ...

--Scott David Daniels
scott.dani...@acm.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Stroud  
View profile  
 More options Oct 1 2006, 7:04 pm
Newsgroups: comp.lang.python
From: James Stroud <jstr...@mbi.ucla.edu>
Date: Sun, 01 Oct 2006 23:04:35 GMT
Local: Sun, Oct 1 2006 7:04 pm
Subject: Re: how to reuse class deinitions?

Here's how I do it. This seems to work pretty well for me. More seasoned
programmers may have better ways.

1. Develop modules (packages) in a folder called something
    like "~/Code".

2. Name the directory the same name as the module or package.

3. See this for packages and modules how-to:

    http://docs.python.org/tut/node8.html

    You basically will want to think in terms of packages if you use
    my method.

4. Now, set up your $PYTHONPATH environment variable to point at
    the "~/Code" directory. Here's how you do it in UNIX (ask a DOS
    guru for how to do it DOS). This if for your ~/.tcshrc file or
    ~/.cshrc file (whichever you use):

        setenv PYTHONPATH /path/to/Code

    This is for a ~/.bashrc file:

        PYTHONPATH=/path/to/Code
        export PYTHONPATH

    If you have already set $PYTHONPATH somewhere else, then you probably
    don't need me to tell you how to include "/path/to/Code" in it.

5. Open a new shell so the $PYTHONPATH gets set correctly for your rc
    file.

6. Now, start python in that shell and import your packages.

Congratulations! You have now setup an environment where all the code
you write becomes packages and re-usable. Why a similar recipe isn't in
every tutorial or beginning python book, I haven't a clue because it
saves hella time figuring out exactly what you have asked here.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sam  
View profile  
 More options Oct 1 2006, 7:15 pm
Newsgroups: comp.lang.python
From: "sam" <python....@googlemail.com>
Date: 1 Oct 2006 16:15:03 -0700
Local: Sun, Oct 1 2006 7:15 pm
Subject: Re: how to reuse class deinitions?

this is basically what i was trying to do. i just tried it again, with
a class_defs.py file in a folder i appended to the system path, itself
containing the class definition for File. then:

from class_defs import File

works fine.

nice to know i was on the right lines. thanks for the pointer!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google