version

Mike McClain mike.junk.46 at att.net
Fri Jun 1 21:34:07 EDT 2018


On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote:
> On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote:
> <snip>
> > Is there a way in a script to know which version of python is being
> > run so I can write:
> >     If (version == 2.7):
> >         do it this way
> >     elsif (version == 3.2):
> >         do it another way
> >
>
> Thanks for the responses,

Those responses were sys.version_info.major and the module 'six'.
The first works here:
    if( sys.version_info.major == 3 ):
        choice = input("<CR> to continue, or <ESC> to abort")
    else:
        choice = raw_input("<CR> to continue, or <ESC> to abort")   #  OK in 2.7
but not here:
    if( sys.version_info.major == 3 ):
        print( row, sep=', ')
    else:
        print ', '.join(row)    #   failing in 3.2

Both of the above print statements throw syntax errors, one under 2.7
the other under 3.2.

I looked at 'six' and it putting wrappers around calls would mean a
rewrite of what is basically just a playground for exploring what
python is and certainly not worth the trouble to rewrite much.

It looks like what I was wanting is something like 'C's #if, a
compiler conditional.

Does python have anything like that to tell the interpreter to ignore
a line that is not a comment or a quoted string?

Thanks,
Mike
--
The depression won't end till we grow a generation that knows how to
live on what they got.
    - Will Rogers



More information about the Python-list mailing list