###前提・実現したいこと
python2系で出来ていることを3系でも実装したい。
###発生している問題・エラーメッセージ
Traceback (most recent call last): File "./code", line 24, in <module> main() File "./code", line 12, in main a0.append('1') NameError: name 'a0' is not defined
###該当のソースコード
#!/usr/bin/env python import fileinput def main(): for i in fileinput.input(): a = i.strip() for i in range(0,int(a)): exec("a{}".format(i) + " = []") a0.append('1') a0.append('2') a0.append('3') a1.append('4') a1.append('5') a1.append('6') print(a0) print(a1) if __name__ == '__main__': main()
###試したこと
2to3というpythonの2系から3系にするため?の便利なツールがあるとのことでしたので、試してみました。
[root@theo]# 2to3 pytest.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: No changes to pytest.py RefactoringTool: Files that need to be modified: RefactoringTool: pytest.py
###補足情報(言語/FW/ツール等のバージョンなど)
2系実行時 (2.7.5)
[root@theo]# ./pytest.py 2 ['1', '2', '3'] ['4', '5', '6']
3系実行時 (3.5.0)
[root@theo]# ./pytest.py 2 Traceback (most recent call last): File "./code", line 24, in <module> main() File "./code", line 12, in main a0.append('1') NameError: name 'a0' is not defined
何か足りない情報等ございましたらおっしゃってください。
追加でお伝え致します。
よろしくお願い致します。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/07 04:54