[IPython-user] Not breaking a block on an indented line
Joshua Gilbert
joshuacgilbert at gmail.com
Sun Oct 16 03:59:20 CDT 2005
I think that this is a wishlist item, but I'd love to hear that it's
already possible.
The goal is to be able to imput blocks that have indented lines
without breaking the block. Example code:
--------------------------------------------------------------------------------------------------------------------------
class foo:
def __init__(self):
self.data = range(10)
def printData(self):
print self.data
--------------------------------------------------------------------------------------------------------------------------
This is good Python, it follows PEP 8. The problem is that ipython
doesn't recognize it:
--------------------------------------------------------------------------------------------------------------------------
In [1]: class foo:
...: def __init__(self):
...: self.data = range(10)
...:
In [2]: def printData(self):
------------------------------------------------------------
File "<console>", line 1
def printData(self):
^
SyntaxError: invalid syntax
In [3]: print self.data
------------------------------------------------------------
File "<console>", line 1
print self.data
^
SyntaxError: invalid syntax
In [4]:
--------------------------------------------------------------------------------------------------------------------------
The reason is pretty clear, ipython breaks the current block when it
receives a line with only whitespace. I think that this is incorrect
behaviour. The rule should be that a block ends when there is a
following line with less indenting than the block requires.
python, on the other hand, does the right thing:
--------------------------------------------------------------------------------------------------------------------------
jgilbert at carthage:~/dev/prototypeGP/trunk$ python
Python 2.3.5 (#2, Aug 30 2005, 15:50:26)
[GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class foo:
... def __init__(self):
... self.data = range(10)
...
... def printData(self):
... print self.data
...
>>>
--------------------------------------------------------------------------------------------------------------------------
Now, I'm happy to contribute code that implements the required
functionality if it is not currently possible. To do so I will need a
pointer as to where the changes need to be made.
- Joshua Gilbert
More information about the IPython-user
mailing list