[Tutor] automatically extending PYTHONPATH?

2005-03-21 Thread Marcus Goldfish
I am using Python 2.4/IDLE on WinXP. I organize my sourcefiles in a directory tree, similar to the convention used in Java. When I create a new subdirectory, though, I have to either (i) manually edit my PYTHONPATH environment variable, or (ii) do a sys.append() in IDLE for the new scripts to be

[Tutor] import statements in functions?

2005-03-21 Thread Marcus Goldfish
Is there a convention to be considered for deciding if import statements should be included in a function body? For example, which of these two module layouts would be preferable: # --- MyModule1.py - import foo1, foo2, foo3 import foo_special # several coherent funct

[Tutor] python console, IDLE startup scripts

2005-03-21 Thread Marcus Goldfish
Is there a special startup script the command-line python IDE and/or IDLE use? As per Liam's response to my previous post, I would like to use os.walk() to automatically set my sys.path() variable... Marcus ___ Tutor maillist - Tutor@python.org http:/

[Tutor] a FIFO with fixed capacity?

2005-03-30 Thread Marcus Goldfish
I need to implement a FIFO with a fixed maximum capacity. Is there a name for such a beast? Also, I read two excellent cookbook recipes on FIFOs: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68436 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/210459 Would limiting the max c

Re: [Tutor] a FIFO with fixed capacity?

2005-03-31 Thread Marcus Goldfish
a few samples get overwritten. Does this make sense? On Thu, 31 Mar 2005 01:19:24 -0800 (PST), Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 30 Mar 2005, Marcus Goldfish wrote: > > > I need to implement a FIFO with a fixed maximum capacity. > > Hi Marcus

Re: [Tutor] a FIFO with fixed capacity?

2005-03-31 Thread Marcus Goldfish
> Let me make sure I understand. Let's imagine that we have such a > CircularQueue, with methods: > >push(element) >pop() >isEmpty() > > [example unittest code] Danny, Yes, it looks like that is a valid unittest for a circular buffer. An enhancement is to modify the accessors:

[Tutor] when to use properties?

2005-04-12 Thread Marcus Goldfish
Are there guidelines for when properties should be used vs. instance variables? For example, it often seems more convenient to directly use instance variables instead of properties, like MyClass2 listed below. Is one class more pythonic than the other? # Example 1: class w/props vs. no-propt cla

Re: [Tutor] Re: when to use properties?

2005-04-13 Thread Marcus Goldfish
Thanks for all of the comments! The general theme of "don't use a property unless you need to" is intuitive, and is what I was hoping the consensus would be. This raised another design issue for me, tho', regarding property validation. In C#/Java, I would typically do validation in all of my set

[Tutor] iterator question for a toy class

2005-04-22 Thread Marcus Goldfish
I'm trying to understand custom iterators in Python, and created the following toy class for sequence comparison, which seems to work: class Foo(object): """A toy class to experiment with __eq__ and __iter__""" def __init__(self, listA, listB): self.head, self.tail = listA, listB de

Re: [Tutor] Tracking URL in browser location bar

2005-04-22 Thread Marcus Goldfish
> > A newbie here..I was wondering if python can help me to track the URL in > > browser (IE6+, FF, Mozilla) location bar. I think browser helper objects may also be useful. ASPN has a thread at: http://aspn.activestate.com/ASPN/Mail/Message/ctypes-users/2263094 Marcus __

Re: [Tutor] iterator question for a toy class

2005-04-23 Thread Marcus Goldfish
> - As Rich pointed out, making Foo into it's own iterator by adding a next() > method is not a good idea. A simple way to define your own iterator is to I see that an iterator is conceptually distinct from the container object it iterates over, but I am confused that both the iterator and containe

[Tutor] a generic table data structure for table / 2d array / lookup table?

2005-05-28 Thread Marcus Goldfish
Before I try to reinvent the wheel, can anyone point me to a data structure suitable for storing non-numeric, 2-d arrays. For instance, something that can store the following: A B C D 1 'cat' 3object 9 J4 [1] 56 where the column and row la

[Tutor] super() and inherited attributes?

2005-06-27 Thread Marcus Goldfish
Hi, The following example doesn't work as I would like-- the child instance doesn't expose the attribute set in the parent. Can someone point out what I am missing? Thanks, Marcus class Parent(object): def __init__(self, name="I am a parent"): self.name = name class Child(Parent):

[Tutor] file io: reading an int32 at the end of a file?

2005-07-06 Thread Marcus Goldfish
Hi, I have a file format that ends in a 4-byte (int32) number. I would like to read this value in python on a WinXP machine with something like: fname = 'somefile' f = open(fname, 'rb') f.seek(-4,2) offset = f.read() ... but this doesn't seem to work. The value that Python returns is: '@\x

[Tutor] tricky eval() problem

2005-07-22 Thread Marcus Goldfish
Here's a noodler I could use some help on: I need a class that can call a user-specified function with arbitrary (unknown) parameter lists. The trick, here, is that the user will dynamically specify the funciton to invoke, and each function may differ in the number of parameters passed during the

[Tutor] stopping threads?

2005-09-28 Thread Marcus Goldfish
I'm a little confused about threading in Python.  Here is a sample class I've written for monitoring for events.  Included in the comments are a couple of questions, specifically:      (1) can I use super() in the constructor, or is direct call to base class preferred?    (2) do I need to sleep in

[Tutor] quirky multiple inheritance example!?

2006-02-08 Thread Marcus Goldfish
Hi,   I ran across a strange problem using mulitple inheritance that I hope someone can explain.  Basically, I am implementing a Publisher pattern, and when I try to add threading, the order I list Base classes matters!  Here is the short sample code-- all help explaining this is appreciated!   Th

[Tutor] quickie: a better dynamic dictionary update?

2006-07-11 Thread Marcus Goldfish
Hi,I need to keep an updated dictionary of pictures in my application.  I have a function which takes snapshots of the current pictures available.  Some of the pictures in my dictionary have been deleted, so their dict entry needs to be removed.  Here is a snippet of very ugly code I have which wor

[Tutor] custom container subclassing list-- slices are lists!?

2006-08-21 Thread Marcus Goldfish
Hi,I'd like to sublcass the built-in list type to create my own container.  How can I make slices of the list be of type myclass-- currently they are lists.  Example:>>> class MyFoo(list):   def __init__(self, inlist):   self = inlist[:]>>> me = MyFoo(range(10))>>> type(me)>

Re: [Tutor] custom container subclassing list-- slices are lists!?

2006-08-21 Thread Marcus Goldfish
On 8/21/06, Marcus Goldfish <[EMAIL PROTECTED]> wrote: I'd like to sublcass the built-in list type to create my own container.  How can I make slices of the list be of type myclass-- currently they are lists.  Example:>>> class MyFoo(list):   def _

[Tutor] __init__.py for running a file from commandline?

2006-11-10 Thread Marcus Goldfish
Hoping someone can help with this...I have a logical python namespace using a directory tree and __init__.py files.  For example, PYTHONPATH points to ~pyroot, and I have the following:~pyroot/~pyroot/utils/ ~pyroot/utils/commands/mygrep.pyWhich makes it nice to code:# some python scriptimport util

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Marcus Goldfish
On 11/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and __init__.py > files. For example, PYTHONPATH points to ~pyroot, and I have the following: >

Re: [Tutor] __init__.py for running a file from commandline?

2006-12-07 Thread Marcus Goldfish
On 11/27/06, Michael P. Reilly <[EMAIL PROTECTED]> wrote: When you type something from the command-line, you are at the whims of the WinXP command shell. You have to follow its rules, not Python's. It would need to have "python" in %PATH%, and then it would need to have to run "python C:\path\

[Tutor] curious struct problem

2007-02-02 Thread Marcus Goldfish
I'm trying to read a binary file using struct. This code works interactively in the IPython shell, but not as a function invoked from a command line (Windows). Can someone point out my error? Thanks! import struct def demux(filename, channel, nchannels): "Demultiplexes a stream of shorts (s

Re: [Tutor] curious struct problem

2007-02-05 Thread Marcus Goldfish
On 2/2/07, Danny Yoo <[EMAIL PROTECTED]> wrote: > I'm trying to read a binary file using struct. This code works > interactively in the IPython shell, but not as a function invoked from a > command line (Windows). Can someone point out my error? Thanks! Hi Marcus, There is something very su

Re: [Tutor] curious struct problem

2007-02-05 Thread Marcus Goldfish
On 2/2/07, Danny Yoo <[EMAIL PROTECTED]> wrote: There is something very suspicious in the code. You don't happen to have any global variables in your program, do you? I think I found the problem: the last chunk read is incomplete, so there is size(chunk) is not sufficient to unpack accordin

[Tutor] class design - base classes with optional properties?

2009-01-22 Thread Marcus Goldfish
I'm trying to design a base class for a hierarchy. The properties I want to specify for the base class depend on the values of other properties of the base class. For instance, in this toy example of a base FoodProcessor class: class FoodProcessor: "Model for a kitchen appliance food processo