1

How can I convert this so it could execute?

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

source:

test = ''.join(clientIp.split("test6")[1:])
3
  • 1
    Can you please post the actual code you're trying to run? BTW, it's also a bad idea to be 'exec'ing a string provided by a user without running it through some sort of validation. Commented Mar 1, 2010 at 3:41
  • There are prettymuch no reasons to use exec. Commented Mar 1, 2010 at 5:18
  • 1
    @Make Graham: I disagree. There are uses for exec. No uses for an inexperienced programmer, but exec is a tool to be used for the times when no other tool will work. Commented Mar 13, 2010 at 14:09

1 Answer 1

3

You might need to use lstrip() on the string to get rid of any leading whitespace before passing it to exec.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.