0

In python 2.7.10, sys.version_info from the sys module is:

sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)

What python type is this? It appears to be some sort of a tuple with named elements, and you can refer to either

sys.version_info[0]

or

sys_version_info.major

The type command returns

<type 'sys.version_info'>

which is somewhat unhelpful. I know it is not a named tuple, and it's not a plain tuple, but what is it? How does one construct such an item?

3
  • Please clarify - you know about collections.namedtuple already and want to know what sys.version_info is and how it differs from collections.namedtuple? Commented Aug 26, 2015 at 10:46
  • It's a built-in type, I don't think you can create custom instances of it. Commented Aug 26, 2015 at 10:47
  • I was unable to find a description of what this object is in the 2.7 documentation for sys.version_info. I was puzzled as to how a tuple could have named elements, and was asking how to make a tuple like this. Now I know it is a built-in type, is there a name for this sort of thing? Commented Aug 26, 2015 at 10:58

2 Answers 2

4

sys.version_info is actually a C struct object defined in structseq.c. As the comment at the top of that code indicates, it's primarily intended as an implementation tool for modules:

/* Implementation helper: a struct that looks like a tuple.  See timemodule
   and posixmodule for example uses. */

If you want a similar Python object, this is a little bit like collections.namedtuple. In fact the doc string for sys.version_info uses "named tuple" to describe the object:

>>> print sys.version_info.__doc__
sys.version_info

Version information as a named tuple.

Alternatively, you might be able to use the structseq object directly at C level with the Python C API.

Sign up to request clarification or add additional context in comments.

Comments

1

According to the sys module documentation:

Static objects:

[...]

version_info -- version information as a named tuple

[...]

1 Comment

I referred to 2.7 in my post. The 2.7 doc has only: Changed in version 2.7: Added named component attributes No mention of named tuples.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.