This code is supposed to get a string value from a an excel file. The value is how ever not being recognized as a string. How can I get query as a string? str(string) doesn't seem to work.
def main():
file_location = "/Users/ronald/Desktop/Twitter/TwitterData.xlsx"
workbook = xlrd.open_workbook(file_location) #open work book
worksheet = workbook.sheet_by_index(0)
num_rows = worksheet.nrows - 1
num_cells = worksheet.ncols - 1
curr_row = 0
curr_cell = 3
count = 0
string = 'tweet'
tweets = []
while curr_row < num_rows:
curr_row += 1
tweet = worksheet.cell_value(curr_row, curr_cell)
tweet.encode('ascii', 'ignore')
#print tweet
query = str(tweet)
if (isinstance(query, str)):
print "it is a string"
else:
print "it is not a string"
This is the error i keep getting.
UnicodeEncodeError: 'ascii' codec can't encode characters in position 102-104: ordinal not in range(128)