473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IndentationError: expected an indented block

Getting the following error. But I cannot figure out why. Could someone please alter my code and explain where I am going wrong?


./checkprocess2.py
File "./checkprocess2.py", line 19
else:
^
IndentationError: expected an indented block

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import os
  5. import commands
  6.  
  7. def state():
  8.                output = commands.getoutput('ps -A')
  9.                if 'amun_server.py' in output:
  10.                        return false
  11.                else:
  12.                        return true
  13.  
  14. status = false
  15.  
  16. while true:
  17.     if state():
  18.  
  19.         else:
  20.                  os.system("/root/amun/amun_server.py &")
Jun 21 '10 #1
3 4458
bvdet
2,851 Expert Mod 2GB
@cwggenius
The error message says it all! There must be a statement or some action after the if statement. Your indentation is wrong also. You don't need the else statement in function state().

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import os
  5. import commands
  6.  
  7. def state():
  8.     output = commands.getoutput('ps -A')
  9.     if 'amun_server.py' in output:
  10.         return false
  11.     return true
  12.  
  13. status = false
  14.  
  15. while true:
  16.     if state():
  17.         pass # there must be some action or statement
  18.     else:
  19.         os.system("/root/amun/amun_server.py &")
Jun 22 '10 #2
BVDET. Thank you for your reply...

I am now getting :

./checkprocess2.py
Traceback (most recent call last):
File "./checkprocess2.py", line 13, in <module>
status = false
NameError: name 'false' is not defined

...still a bit confused.
Jun 22 '10 #3
bvdet
2,851 Expert Mod 2GB
Python is case-sensitive.

Expand|Select|Wrap|Line Numbers
  1. >>> false
  2. Traceback (most recent call last):
  3.   File "<interactive input>", line 1, in ?
  4. NameError: name 'false' is not defined
  5. >>> False
  6. False
  7. >>> 
Jun 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
5
by: beliavsky | last post by:
How do you keep Python code properly indented as you modify it? I use an Emacs-type editor that has a Python mode, so the initial indenting is easy. If I later want to put a 'for' loop (or an 'if'...
0
by: Mr. Magoo | last post by:
Why does py_compile print IndentationError in a different format than SyntaxError? It makes it harder to parse the output in a non-python program. Sorry: IndentationError: ('unindent does not...
3
by: David Ross | last post by:
I sometimes place a sidebar on a Web page, using the following: ..sideright { float: right; background-color: #fff; width: 40%; font-size: 90%; text-align: justify; margin-left: 1em;...
0
by: Bart Lateur | last post by:
This seems so basic, but the common browsers (in particular Firefox and MSIE on Windows) succeed to mess it up. The basic HTML is this: <!-- an image floating on the left --> <img...
39
by: eruanion | last post by:
Hi, I've been working on this for a while now and I can't seem to find out what is wrong with my code. I have 2 files one c3common.js which only contains javascript functions for my main html page...
7
by: kagard | last post by:
Greetings: I'm brand new to Python and decided to write a syllogism solver for a class I'm taking. At the start of the program, I define a function that classifies the type of each statement in...
5
by: casioculture | last post by:
Haha. How can I fix this!
3
by: Paddy3118 | last post by:
Not python: but python type indented text Notice the blank line above. It could have several spaces or tabs, and still be a part of the block beginning 'Not python:': The block ends at the
6
by: Harlan Messinger | last post by:
Please take a look at http://www.gavelcade.com/list_next_to_float.html How can I style a list so that if it appears next to a left-floated box as the first list does in this example, the list...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.