Control: tags -1 + moreinfo
Control: retitle -1 program not importing ‘platform’ from standard library

On 17-Sep-2014, Edward Welbourne wrote:
> <quote>
> import platform
> ...
> class MarkerEvaluation(object):
>     values = {
>         'os_name': lambda: os.name,
>         'sys_platform': lambda: sys.platform,
>         'python_full_version': platform.python_version,
>         'python_version': lambda: platform.python_version()[:3],
> ...
> </quote>
> presumes that the module platform has python_version as an attribute
> (that is, no less, callable returning a sequence).

Yes, the standard library ‘platform’ module does have that API. See
<URL:https://docs.python.org/2/library/platform.html#platform.python_version>
<URL:https://docs.python.org/3/library/platform.html#platform.python_version>.

In a regular Python 2 session::

    $ python2
    Python 2.7.12+ (default, Sep  1 2016, 20:27:38)
    [GCC 6.2.0 20160927] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import platform
    >>> platform
    <module 'platform' from '/usr/lib/python2.7/platform.pyc'>
    >>> platform.python_version()[:3]
    '2.7'

In a regular Python 3 session::

    $ python3
    Python 3.5.2+ (default, Sep 22 2016, 12:18:14)
    [GCC 6.2.0 20160927] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import platform
    >>> platform
    <module 'platform' from '/usr/lib/python3.5/platform.py'>
    >>> platform.python_version()[:3]
    '3.5'

> A quick python session:
> <quote>
> Python 2.7.8 (default, Sep  9 2014, 23:55:56) 
> [GCC 4.9.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import platform
> >>> platform.python_version
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'python_version'

I suspect you have not imported the standard library's ‘platform’
module. You can verify, by using the same Python statements I tried
above.

If you do find that ‘platform’ was imported from the wrong place, that
indicates a bug in the ‘slimit’ program for not importing from the
standard library.

-- 
 \        “Good morning, Pooh Bear”, said Eeyore gloomily. “If it is a |
  `\   good morning”, he said. “Which I doubt”, said he. —A. A. Milne, |
_o__)                                                _Winnie-the-Pooh_ |
Ben Finney <bign...@debian.org>

Attachment: signature.asc
Description: PGP signature

Reply via email to