My goal is to ask a user for a date, then scan through the cell values of a spreadsheet column and return any cells that start with that date.
I have a spreadsheet in which the first column is a list of timestamps (e.g., 10/29/2012 “9:10:12”). I’m using Python and gpsread to access the Google spreadsheet.
import gspread
import re
gc = gspread.login('username', 'password') # login
wks = gc.open('googleSpreadsheet').sheet1 # open spreadsheet
I’m trying to ask the user for a date input like this:
dateInput = str(raw_input('Date? (MM/DD/YYYY) '))
I then want to take that input and use it in a regular expression to find all the cells that start with it:
amount_re = re.compile(r'(^dateInput)')
cell_list = wks.findall(amount_re)
but that returns an empty array.
So, how do I take a user input and return any cells that start with that input? Ultimately, I want to be able to find any cells in the spreadsheet that have a given date, then copy and paste the corresponding rows to a different spreadsheet. This first part of parsing through the data and storing the cells is where I’m hung up.
If you’re actually pulling the user input in the way you’ve presented, the problem might be a trailing newline. Try: