Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As part of a larger program, I am using git to check the program itself for updates. Of course, the user will need git installed to do so. I've created a small bit of python3 code to check if the user has git installed, but it does not seem to work:

import linecache
import time
import os

git = linecache.getline('info.txt', 2)
if git == 'no':
               git-ask=input('Is Git Installed? <y/n>\n')
               if git-ask == 'n':
                                 print('Installing Git.')
                                 os.system('apt-get install git-core')
               elif git-ask == 'y':
                                   print("Checking For Updates...")
elif git == "yes":
                 print("Checking For Updates...")
     print("Error: 'GitInfoError'")
     print("Please Contact Eden About This Error:")
     print("Skipping Updates...")

The program always reverts to else clause, which should NEVER happen! Here is the contents of info.txt:


Thanks For Any Advice You Can Offer!

share|improve this question
up vote 3 down vote accepted

Yes it could happen (computers tend to make very few mistakes ;-)

Your variable git most likely has a newline character attached to it. So it's neither 'no' nor 'yes' but rather 'no\n'

You can either query for git.rstrip()=='no' which would chop off any whitespace (space, newline tabs) or you can try to check by some other route for the presence of git. Maybe issue 'git --version' and see whether it gets back with something reasonable or not.

Let us know if you need help with the latter approach.

share|improve this answer
git.rstrip() works perfectly! Thanks! – Eden Crow Apr 15 '11 at 18:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.