List comparison help please
Simon Forman
rogue_pedro at yahoo.com
Fri Aug 25 15:27:11 EDT 2006
Bucco wrote:
> Simon Forman wrote:
>
> > 1) Don't use "dir", "file", and "list" as variable names, those are
> > already python built in objects (the dir() function, list type, and
> > file type, respectively.)
>
> Thanks. My own stupidity on this one.
>
>
> > 2) 'r' is the default for open(), omit it. "self.flist =
> > open(file).readlines()"
> >
>
> Could you clarify? Show an example. Sorry if I sound newbyish, but I
> am.
Sure, no problem. "open(filename, 'r')" is exactly the same as
"open(filename)". The flag argument is optional and when you leave it
off it defaults to 'r'.
>
>
> > 5) Since you have a list of things you're matching (excluding actually)
> > this part:
> >
> > > for item in self.flist:
> > > if item == fname[:-4]:
> > > pass
> > > else:
> > > self.matches.append(fname)
> >
> > could become:
> >
> > if fname[:-4] not in self.flist: self.matches.append(fname)
>
> Thanks. This was what I was looking for.
Cool! You're welcome. :-)
>
> > 6) Why are you using #~ for comments?
>
> This is just the automatic commenting on scite. I put my cursor on the
> line I want to comment and press ctrl-q ans scite comments out the
> whole line or selection. As for why the lines are commented; I
> commented these lines so I could test out some of the code prior to
> running the next bit.
Ah, right on. I was just wondering.
>
> > Also, check out os.path.splitext()
> > http://docs.python.org/lib/module-os.path.html#l2h-1761
> >
> I will check this out also.
>
> Thank You for your help. You have answered some questions for me.
>
> Thanks:)
>
> SA
You're very welcome. It's a pleasure.
Peace,
~Simon
More information about the Python-list
mailing list