2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonで文字列入力を受付け、入力内容を出力するだけのコード

Last updated at Posted at 2017-10-22

やってることはまったくもって大したことはないんだけど、input()の仕様がPython 2とPython 3で違ってたため、最初「??」という状態に。
Python 2ではraw_input()を、Python 3ではinput()を使うというようにした。
で、バージョンの判別はsix.PY2の結果を使うことで実現。

echo.py
#
# coding: utf-8

import six

def main():
    PyVer2 = six.PY2
    if (PyVer2 == True):
        a = raw_input()
    else:
        a = input()

    print(a)


if __name__ == '__main__':
    main()
2
2
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?