DIGIT-ARC read-only archive · snapshot: July 23, 2026

Help in python

4 posts · originally from https://geek.digit.in/community/threads/help-in-python.125543/

A
abhijangda Original post #1
Apr 4, 2010 at 1:06 AM
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
Apr 4, 2010 at 11:45 AM
EDIT: Works for me in both Python 2.x and 3.x
You may have incorrectly indented somewhere
A
Apr 4, 2010 at 2:33 PM
I m working in Python 2.6.5. Thats what i want to know where is the problem.
O
Apr 9, 2010 at 12:06 PM
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