Is it possible to test methods inside interactive python and retain blank lines within them?
def f1():
import random
import time
time.sleep(random.randint(1, 4))
This gives the familiar error
IndentationError: unexpected indent
So, yes a workaround is to remove all blank lines inside functions. I'd like to know if that were truly mandatory to be able to run in interactive mode/REPL.
thanks
Blank line is definitely allowed in python functions. All of yours examples (A,B,C,D) should work and the problem probably (sure) is related to "Eclipse and the PyDev plug-in".
Surround top-level function and class definitions with two blank lines. Method definitions inside a class are surrounded by a single blank line. Extra blank lines may be used (sparingly) to separate groups of related functions.
Two blank lines between top-level definitions, be they function or class definitions. One blank line between method definitions and between the class line and the first method. Use single blank lines as you judge appropriate within functions or methods.
Might not be much help, but it works if the blank lines are indented. Dots shown for clarity:
def f1():
....import random
....import time
....
....time.sleep(random.randint(1, 4))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With