Hey all,
I would like to expand the "visual" representation of a tree
hierarchy, given below, where child-ness is defined by indentation,
and folder-ness is highlighted with a trailing '/'
Input (test.txt):
dir1/
file1
file2
1-1/
file3
file4
> The list comp is fine but I don't think you need it
> at all, since you strip() the string before you
> add it to stack.
Ahh yes. I used the rstrip() in development, printing intermediary
output to stdout, so I could see what my input file-to-list looked
like (and it looked ugly with all those E
On 3/21/06, stv <[EMAIL PROTECTED]> wrote:
>
> import string
>
> def expand_tree(filetree):
> indent = '\t'
> stack = []
> for f in filetree:
> indents = f.count(indent)
> while len(stack) > indents: stack.pop()
> stack.append(f.st
# So I figure out inner classes while typing the
# first draft of this email, at least mostly
# How do I access the "outer" class attributes from
# the inner class?
class GroupLocation(list): ### Note subclass of list
class _Sublocation(object):
def __init__(self, sublocation, action):
Hmmm, so every Sublocation object has a copy of the grouplocation
data? What happens if I come around & change something:
group.grouplocation = differentGroupLocationID
Would I need to (forgive me here if I get some terms wrong) use a
property (or a setter) & then loop over all the affected sublo
> The problem appears to be that you need to read a bit more
> about Pythons handling of variable names and objects. :-)
Or learn to spend a bit more time digesting the helpful advice given
here ... between this & the searching between two lists thread the
quality of advice has been excellent.
I
If you're a bookish type, I found Magnus Lie Hetland's "Beginning
Python" excellent. It's really more than a beginners books. I came to
Python with a scripting background--mostly lightweight OS stuff
(Applescript, DOS) as well as a lot of lightweight application
programming (Filemaker, SQL, VBA for
I just thumped my head against the wall for a few hours on something,
and I was wondering if it's just my green-ness in Python, or if I'm
doing something unsavory.
I had several list comprehensions that I was mucking with; these lists
are working on a simple subclass of the built-in list object. T
> So don't write:
> [adds.add_changes('foo', path) for path in filelist]
> but:
> for path in filelist: adds.add_changes('foo', path)
Excellent point; new toy, got carrid away :) I feel silly on that one.
And now that I've made the
return list.extend(foo)
mistake, I'll surely neve- ... er, wa
> "Beginning Python: From Novice to Professional", by
> Magnus Lie Hetland
> Publisher: Apress (September 26, 2005)
> ISBN: 159059519X
I would heartily second this recommendation. Different folks have
different learning styles, and having a good overview can make weeding
out the internet informati
d. I'll read Pilgrim's book in
the near future.
In general (with the notable exception of the Plone book) I've found
the Apress materials excellent. (Both books happen to be Apress, no
I'm not affiliated in any way).
--stv
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
11 matches
Mail list logo