Help in python

Status
Not open for further replies.

abhijangda

Padawan
hello frnds, i am facing a small problem in PYTHON. I wrote the following code in Python GUI.

def op(path):
with open(path,'r') as f:
f.read()

and if ran successfully without any error. I wrote the same code in notepad and then saved as ff.py file in Python folder. Then i wrote following command to run this module

from ff import *

then it shows the following error in code

Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
from ff import *
File "C:\Python26\ff.py", line 3
f.read()
^
IndentationError: expected an indented block


I cant understand where's the error:x. Pls frnds help me.
 

Liverpool_fan

Sami Hyypiä, LFC legend
EDIT: Works for me in both Python 2.x and 3.x
You may have incorrectly indented somewhere
 
Last edited:

ojha_riddhish

Broken In
Dear abhijangda,
Whenever Python interpreter encounters a Colon :)), it assumes that the following block of code will be indented by consistent white spaces (default 4 spaces). The line with colon and the block of code after colon cannot start from the first character. Please try this:

def op(path):
with open(path,'r') as f:
<tab>f.read()

Please use Notepad ++ and Geany in Windows or Geany in Linux as your editor.
Thanks
 
Status
Not open for further replies.
Top Bottom