def connect(userid,password): global client#we need to define client to global client=SpreadsheetsService() client.email=userid client.password=password client.source = 'Spreadsheets GData Sample' client.ProgrammaticLogin() def clientConnect(): userCredentials() if "@" not in _id: print"----RUN AS: python spreadsheets_connect.py --user [username] and enter valid username" sys.exit() else: promptForPassword() connect(_id,_password) print "----connection established------" return client if __name__=="__main__": a=clientConnect() mycrud=CRUD(a) mycrud.run()