Script Discussion & Critique
hokiegal99 at hotmail.com
Thu Aug 28 15:23:42 CEST 2003
Peter Otten wrote:
> Factor out reusable code, e.g:
> def replaceTokenInTree(rootFolder, searchToken, replaceToken,
> def replaceTokenInFile(filename, searchToken, replaceToken, backupFile=None)
> This will pay off as your scripts grow (or your script grows:-), so make it
> a habit as soon as possible.
I don't fully understand how functions work yet. This is something that
I'm studying in my spare time. I dislike using something when I don't
fully understand how it works, thus my scripts are really very simple
right now. That's one reason I like Python so well, it has milk for
babies like me and meat for adults like you. It's useful and productive
for both of us at different stages in our knowledge.
> Some observations that are not directly code-related:
> You can change - and possibly corrupt - *many* files in one run of you
> script. So you might add a confirmation prompt repeating searchToken,
> replaceToken and the root directory (resolved to an absolute path) and -
> somewhat more ambitious - a means to generate backups.
This is very good. I will add the confirmation check soon. Thank you for
the suggestion. The backup idea is good too, not 100% necessary, but
> Last but most important:
> Take time to build a test file tree, and include all special cases you can
> think of (including those you consider irrelevant) e. g. files
> starting/ending with search token, zerolength file, file with readonly
Yes, I do this a lot, but it's just me and I'm limited to my world view
of things. This is why I like this forum, you guys point things out that
I miss entirely.
More information about the Python-list