File tests in Python
Harry George
hgg9140 at seanet.com
Fri Oct 13 19:23:28 EDT 2000
If you want tor etain perl-ish oidioms, see pyperl at:
http://www.seanet.com/~hgg9140/comp/index.html
Specifically, file operations at:
http://www.seanet.com/~hgg9140/comp/pyperl-0.4.1/doc/manual.html#L008
You do things like:
#---clean out old dir---
if p.d(newdir):
p.system("rm -rf $newdir")
else:
debug(ftn,p("$newdir not found"))
Joakim Hove <hove at phys.ntnu.no> writes:
> 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 ========
--
Harry George
hgg9140 at seanet.com
More information about the Python-list
mailing list