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
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
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:/
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
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
> 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:
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
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
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
> > 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
__
> - 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
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
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):
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
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
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
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
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
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)>
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 _
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
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:
>
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\
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
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
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
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
27 matches
Mail list logo