[Tutor] upper and lower case input for file name
Kent Johnson
kent37 at tds.net
Fri Dec 14 17:31:28 CET 2007
Bryan Fodness wrote:
>
> Is there an easy way that an input can be upper or lower case?
>
> The file name is TEST.TXT, and I get.
>
> -------------------------------------------------------------------------
>
> Enter File (if not local, enter path): test.txt
>
> Traceback (most recent call last):
> File "test.py", line 52, in <module>
> for line in open(file) :
> IOError: [Errno 2] No such file or directory: 'test.txt'
>
> -------------------------------------------------------------------------
>
> This is a non-issue on Windows, but now I have migrated to Ubuntu.
File names in the Windows file system are not case sensitive; in Linux
they are. In Linux you can actually have two different files called
test.txt and TEST.TXT:
[blogcosm at web8 py]$ cat > test.txt
this is a test
[blogcosm at web8 py]$ cat > TEST.TXT
THIS IS ANOTHER TEST
[blogcosm at web8 py]$ cat test.txt
this is a test
[blogcosm at web8 py]$ cat TEST.TXT
THIS IS ANOTHER TEST
Probably the best solution is to get used to it :-) but you could check
for other files in the dir whose name matches ignoring case and open
that file if there is a unique match.
Kent
More information about the Tutor
mailing list