[Python Wpg] topics i forgot to mention

Dave Gabrielson dave at gabrielson.ca
Tue Dec 20 23:02:36 EST 2005


Hi Syd (& everybody else),

On December 13, 2005 05:42 pm, syd at plug.ca wrote:
> A couple of topics that would be interesting (to me, at least) that I
> forgot to mention:
>
> 1. Python enhanced shells like ipython (very handy for auto completion,
> inspection), emacs python mode, (maybe vi(m) macros if anyone has any that
> they use?)
> 2. Python IDEs - Boa, Stani's Python Editor, Eclipse Python Plug-In (never
> gotten this to work, but i hear it does) (could be combined with #1 as
> "what tools are you using?")

Personally I use anything that supports syntax highlighting. I used to use 
IDLE, way back in the day... I don't know if that's even being shipped 
anymore.

> 3. For people who may be familiar with other object oriented languages but
> want to know how it's done in Python: How do modules, directories, files,
> and classes affect import statements, and how does that in turn affect
> namespaces? What does __init__.py do? How does inheritance work in Python?
> How do I override an inherited method? How do I call an inherited
> constructor? Why the heck would I *want* to call an inherited constructor?
> Kind of a general walk-through of how to take advantage of the
> object-oriented features of Python.

Python is all about namespaces.
Open an interactive shell, import something (say, the os.path module), and do 
a dir(os.path) on it.  (I can do this for over an hour when I'm busy 
procrastinating).

__init__.py imports things for an entire package.
Let's say for example that I have a package called myos, which has a 
myos.path, myos.fsutil, myos.boot and myos.service modules.

At the top level, you'd create a directory called myos.
Inside myos, you'd create the following files: __init__.py, path.py, 
fsutil.py, boot.py and service.py.

__init__.py is the file that defines functions that you call from myos.
For example, it may define fork() and getpid() functions which you would call 
in your code as myos.fork() and myos.getpid().
In another module you might need to deal with services, so you could then
import myos.service
and call functions like myos.service.start('httpd') or 
myos.service.stop('samba') (or whatever).

Speaking of object oriented stuff, I've just done a little program that does 
some OOP stuff and put it on my webpage.  (viewfortune.py)

http://www.gabrielson.ca/~/dave/python/

> Regards,
> Syd

Hope this clears a few things up, or at least doesn't muddle things worse.

--Dave.



More information about the Winnipeg mailing list