Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 04-04-2010, 01:06 AM   #1 (permalink)
Alpha Geek
 
Join Date: Jan 2007
Location: In your hearts
Posts: 828
Default Help in python


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. Pls frnds help me.
abhijangda is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 04-04-2010, 11:45 AM   #2 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: Help in python

EDIT: Works for me in both Python 2.x and 3.x
You may have incorrectly indented somewhere
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.

Last edited by Liverpool_fan; 04-04-2010 at 12:03 PM.
Liverpool_fan is offline  
Old 04-04-2010, 02:33 PM   #3 (permalink)
Alpha Geek
 
Join Date: Jan 2007
Location: In your hearts
Posts: 828
Default Re: Help in python

I m working in Python 2.6.5. Thats what i want to know where is the problem.
abhijangda is offline  
Old 09-04-2010, 12:06 PM   #4 (permalink)
Right Off the Assembly Line
 
Join Date: Aug 2007
Posts: 32
Default Re: Help in python

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
ojha_riddhish is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a multidimensional list in python bharat_r Programming 1 09-04-2010 12:24 PM
Python Query Thread The Unknown Programming 1 27-08-2008 12:41 PM
Wannabe Python Programmer - Please Help ! MetalheadGautham Programming 22 13-08-2008 11:27 AM
One Giant Command Line MetalheadGautham Open Source 23 24-05-2008 02:31 AM
Valuable Sites for Techies sreedevi Tutorials 15 04-10-2005 10:35 PM

 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2