Python Tutorial: double single quotes?
Jonadab the Unsightly One
jonadab at bright.net
Fri Sep 8 04:46:34 EDT 2000
# Not sure what possessed a guy writing[3] an otherwise good
# tutorial on Python to use doubled single quotes, but
# anyway the annoyance factor finally pushed me over the
# edge[1], and I wrote a script to change them all. I
# probably could have written it in Python except that I'm
# only just now reading the Python tutorial, so I don't know
# enough Python to do this yet. So I wrote it in another
# language[2]. But anyway, in case anyone else is suffering
# the same malady, here it is... run it once from the
# directory where the tutorial files are, and it fixes the
# ``stupid quotes'' to "regular quotes" (using, of course,
# the proper HTML entity).[4]
#
# Fix stupid ``quotes'' in HTML documents. I got tired of
# seeing the double single quotation marks, (doubled single
# quotes -- WHY?) in the Python documentation, so I decided
# to FIX it. Here we go...
sub mungfile {
$filecontents =~ s/\`\`/"/g;
$filecontents =~ s/\'\'/"/g; }
sub slurpfile {
$filecontents = "";
open INFILE, $filename;
while (<INFILE>)
{ $filecontents .= $_; } }
sub writefile {
open OUTFILE, ">" . $filename;
# NOTE: Overwrites the original file!
print OUTFILE $filecontents; }
opendir THISDIR, "."; @filelist = readdir THISDIR; closedir THISDIR;
@filelist = grep /.html?$/, @filelist;
if ($debug) { print "Filtered filelist: @filelist"; }
foreach $filename ( @filelist ) {
slurpfile();
mungfile();
writefile(); }
# Anyway, now I can get back to reading the tutorial
# without going crazy... I feel better about that now.
# [1] Yes, maybe I *am* neurotic, but it was driving me nuts.
#
# [2] Specifically, Perl. I could have written it in elisp,
# but I didn't. I also could have written it in QBasic,
# but that would have taken me an hour instead of a minute.
#
# [3] Or perhaps it was the guy translating it into HTML.
#
# [4] If you run it again from the directory where the library
# reference is, it'll fix the quotes in that, too :-)
More information about the Python-list
mailing list