Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure interactive python to allow blank lines inside methods

Tags:

python

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

like image 962
WestCoastProjects Avatar asked May 16 '13 17:05

WestCoastProjects


People also ask

Are Blank lines forbidden in Python?

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".

How many blank lines should be before and after method definitions inside a class method definitions inside a class are just another term for functions in a class?

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.

How many blank lines should be before and after top-level functions and class definitions?

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.


1 Answers

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))
like image 70
FogleBird Avatar answered Sep 20 '22 18:09

FogleBird