如何在Python中将字符串转换为“命令”?

1 投票
1 回答
1677 浏览
提问于 2025-04-15 19:50

我该怎么把这个转换成可以执行的呢?

Traceback (most recent call last):
  File "C:\Users\Shady\Desktop\tet.py", line 14, in <module>
    exec test
  File "<string>", line 1
    print "hello world"
   ^
IndentationError: unexpected indent

来源:

test = ''.join(clientIp.split("test6")[1:])

1 个回答

3

在把字符串传给 exec 之前,你可能需要用 lstrip() 来去掉字符串开头的空格。

撰写回答