diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1996-07-18 16:07:05 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1996-07-18 16:07:05 (GMT) |
commit | 024a387f89cd4c08b67ffca0d8df311a34cc8a49 (patch) | |
tree | c1ec0a777e2c6b02596ddeb54cdb0e3fa7e02653 /Mac/Demo/example0 | |
parent | a547dcaff09fa530871a0405b146c6bf958b48b4 (diff) | |
download | cpython-024a387f89cd4c08b67ffca0d8df311a34cc8a49.zip cpython-024a387f89cd4c08b67ffca0d8df311a34cc8a49.tar.gz cpython-024a387f89cd4c08b67ffca0d8df311a34cc8a49.tar.bz2 |
- Added a file dialog example
- Added pointers to library documentation
Diffstat (limited to 'Mac/Demo/example0')
-rw-r--r-- | Mac/Demo/example0/checktext.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Mac/Demo/example0/checktext.py b/Mac/Demo/example0/checktext.py new file mode 100644 index 0000000..93a814d --- /dev/null +++ b/Mac/Demo/example0/checktext.py @@ -0,0 +1,39 @@ +"""checktext - Check that a text file has macintosh-style newlines""" + +import macfs +import sys +import EasyDialogs +import string + +def main(): + fsspec, ok = macfs.PromptGetFile('File to check end-of-lines in:', 'TEXT') + if not ok: + sys.exit(0) + pathname = fsspec.as_pathname() + fp = open(pathname, 'rb') + try: + data = fp.read() + except MemoryError: + EasyDialogs.Message('Sorry, file is too big.') + sys.exit(0) + if len(data) == 0: + EasyDialogs.Message('File is empty.') + sys.exit(0) + number_cr = string.count(data, '\r') + number_lf = string.count(data, '\n') + if number_cr == number_lf == 0: + EasyDialogs.Message('File contains no lines.') + if number_cr == 0: + EasyDialogs.Message('File has unix-style line endings') + elif number_lf == 0: + EasyDialogs.Message('File has mac-style line endings') + elif number_cr == number_lf: + EasyDialogs.Message('File probably has MSDOS-style line endings') + else: + EasyDialogs.Message('File has no recognizable line endings (binary file?)') + sys.exit(0) + +if __name__ == '__main__': + main() + + |