Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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...")
else:
     print("Error: 'GitInfoError'")
     print("Please Contact Eden About This Error: [email protected]")
     time.sleep(5)
     print("Skipping Updates...")

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

  GIT:
  no
  REBOOT:
  no

Thanks For Any Advice You Can Offer!

share|improve this question

1 Answer 1

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

 
discard

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.