Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous "IndentationError" with python #23

Closed
ianrose14 opened this issue Jul 2, 2013 · 3 comments
Closed

Erroneous "IndentationError" with python #23

ianrose14 opened this issue Jul 2, 2013 · 3 comments

Comments

@ianrose14
Copy link

Firstly, I admit that I'm not sure if this is more properly a bug in sublime-worksheet or a bug in python's interactive mode, but either way this unfortunately prevents me (and others, I would guess?) from using this tool which otherwise seems pretty cool...

Given code like this:

#!/usr/bin/env python
import sys

def main():
  args = sys.argv[1:]
  for arg in args:
    if '.' in arg:
      print 'great!'

    print arg

if __name__ == '__main__':
  main()

This runs just fine from the command line, but worksheet gives "IndentationError: unexpected indent" on line 10 (print arg). Is there anything that can be done about this? Unfortunately I get the same error if I save this file as foo.py and do:

cat foo.py | python -i
@jcartledge
Copy link
Owner

Hi. I think this is a Python syntax issue.

It looks like the problem is that Python needs whitespace on line 9 (the empty line) to the level of either print statement to indicate that the second print is still inside the for loop, but Sublime Text is automatically stripping it.

If I add whitespace on that line the script runs fine as a worksheet. (Note that it doesn't actually do anything because it is running in REPL mode, not as a command line script.)

Check what you have in your Preferences.sublime-settings for "trim_automatic_white_space".

@ianrose14
Copy link
Author

I agree that's what Python (in -i mode) is expecting and failing on - the problem is that the program is legal Python even without that whitespace indentation on blank lines. In other words, it appears that python in interactive mode is pickier about its input than python is in normal (compiled?) mode. And thus worksheet unfortunately will fail on many files that would otherwise run just fine from the command line. Which is a bummer...

@jcartledge
Copy link
Owner

You're right, sorry. There's a discussion of the issue here (wrt style): http://stackoverflow.com/questions/2727988/python-indentation-in-empty-lines

Maybe I should add a note to the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants