File tests in Python
Joakim Hove
hove at phys.ntnu.no
Fri Oct 13 13:52:37 EDT 2000
Hello,
I have just bought "Learning Python" by Mark Lutz and David Ascher,
and browsed quickly through it. I like both the book and my first
impression of Python very good.
Previously I have used Perl quite a lot - but I never really got the
hang of more "complex" datastructures in Perl. Writing
List = [1,2,["List","in","List"]]
in Python is just the way it _should_ be, really nice!
However, there are two (at least right now) things I have enjoyed in
Perl which I have not found equivalents of in Python.
First Perl has an assorted set of file-test like this:
$file = "myfile";
if (-x $file) {
print "The file \"$file\" is executable \n";
} else {
print "Sorry - can't run \"$file\" \n";
}
How would I do this and related (is a directory/symbolic
link/binary/..) tests in Python?
Secondly a correct Perl-installation comes with a very neat program
called perldoc - which is used to access the Perl
documentation. Typing for instance:
bash% perldoc -f localtime
gives you the documentation for the localtime() function - very
convenient! I know this is not a property of Perl - the programming
language, but nevertheless, do I have access to something like this
from python? [Standard Linux install of Python - using emacs as
editor].
Joakim Hove
--
=== Joakim Hove www.phys.ntnu.no/~hove/ ======================
# Institutt for fysikk (735) 93637 / E3-166 | Skøyensgate 10D #
# N - 7491 Trondheim hove at phys.ntnu.no | N - 7030 Trondheim #
================================================ 73 93 31 68 ========
More information about the Python-list
mailing list