-1
str = "a b c"
eval(str) # throws error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
a b c
^
SyntaxError: invalid syntax
しかし2つの条件の違いは何であるPythonでのevalの入力フォーマット
str = "\'a b c\'"
eval(str) # prints
'a b a'
を理解します。なぜキャラクターが必要ですか? ?
Pythonシェルで 'a b c'と入力してみてください。それから '' a b c ''を試してください。 – miradulo
1つは文字列リテラル(動作するもの)ですが、もう1つは構文エラーです...あなたは正確に何を得ていませんか? 'eval'はどうしていると思いますか? –
また、 'eval(" 'a b c' ")'は完全に愚かです。単に '' 'a b c' "' –