Perl & Python: Print Version String from Script

Perm url with updates: http://xahlee.org/perl-python/print_version.html

Perl & Python: Print Version String from Script

Xah Lee, 2011-07-22

In perl or python, you can print the version of the interpreter from the command line. e.g. perl --version, python --version. However, often you have several versions installed, and you wanted to know which version your script is actually running from. On the command line, there are aliases, links, path environment variables, various shell init scripts (.rc, .profile, .profile, .bash_profile), and it is often complex to find out the exact steps which version your script running off.

One absolutely accurate way to know is simply have your script print the version string within.

Python

#-*- coding: utf-8 -*-
# python

import sys
print sys.version

# sample output:
# 2.6.5 (r265:79063, Jun 12 2010, 17:07:01) 
# [GCC 4.3.4 20090804 (release) 1]

http://docs.python.org/library/sys.html

Perl

#-*- coding: utf-8 -*-
# perl

print $^V; # prints version string

# sample output: v5.10.1

perldoc perlvar

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs