Simon Kissane
Simon Kissane

Reputation: 5308

How to get Python version string in exact same format as displayed at startup?

When I start Python it prints a version string, for example:

Python 2.7.10 (default, Jul 23 2015, 09:39:55) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin

Is there an easy way to get that exact string? There are a whole bunch of functions in the platform package which return individual bits of that information, but I was hoping for one function which will tell me this exact info.

(I am not using this information for any sort of version sniffing. Purely to display to the user of a tool written in Python, so they can quote it when seeking support for issues with the tool.)

Upvotes: 0

Views: 63

Answers (1)

Simon Kissane
Simon Kissane

Reputation: 5308

This should generate the exact same output as the Python startup banner:

import sys
print("Python %s on %s" % (sys.version, sys.platform))

Upvotes: 1

Related Questions