Re: problem with eval and time
Thanks. I fetch data from social networking sites and want to mark the time of access. I store all the information in a redis database, which converts everything into strings and I need to convert those strings back to original python objects when analyzing the data. Best Regards On Tuesday, November 6, 2012 12:22:44 PM UTC+8, alex23 wrote: > On Nov 6, 1:32 pm, Wincent wrote: > > > Dear all, I would like to convert tstr to representation > > > of time, but encounter the following error. Is there a > > > simple way to get what I want? Thanks. > > > > > > >>> import time > > > >>> tstr = str(time.localtime()) > > > >>> eval(tstr) > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > File "", line 1, in > > > TypeError: structseq() takes at most 2 arguments (9 given)>>> sys.version > > > > The problem is that the repr of `time.struct_time` isn't its > > constructor, so you won't be able to do this without parsing the > > string, I believe. > > > > What are you trying to achieve here? You already have a > > time.struct_time object, why turn it into a string if what you want is > > the object? > > > > If you're wanting to pass time values around as strings, maybe > > `time.strptime` will be more useful. -- http://mail.python.org/mailman/listinfo/python-list
problem with eval and time
Dear all, I would like to convert tstr to representation of time, but encounter the following error. Is there a simple way to get what I want? Thanks. >>> import time >>> tstr = str(time.localtime()) >>> eval(tstr) Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: structseq() takes at most 2 arguments (9 given) >>> sys.version '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' Wincent -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i use Spread Sheet as Data Store
If you want to write to a csv file, the other option is savetxt in NumPy module. Best On May 19, 7:29 am, John Machin wrote: > On May 19, 5:12 am, Terry Reedy wrote: > > > Kalyan Chakravarthy wrote: > > > Hi All, > > > I have data in Spread Sheet ( First Name and Last Name), > > > how can i see this data in Python code ( how can i use Spread Sheet as > > > Data Store ) . > > > I you have a choice, a plain text file is MUCH easier. > > for line in open('guff.txt'): > first, last = line.rstrip('\n').split('\t') > > > Or, you can output a plain text data.csv (comma-separated variable) file > > from the spreadsheet and read that with the csv module. > > import csv > for row in csv.reader(open('guff.csv', 'rb')): > first, last = row > > Or, if you have an Excel XLS file, use xlrd: > > import xlrd > book = xlrd.open_workbook('guff.xls') > sheet = book.sheet_by_index(0) > for rowx in xrange(sheet.nrows): > first, last = sheet.row_values(rowx) > > So far I don't see "MUCH" easier ... than what? Perhaps much easier > than using odfpy, which states right up front """Odfpy aims to be a > complete API for OpenDocument in Python. Unlike other more convenient > APIs, this one is essentially an abstraction layer just above the XML > format.""" Perhaps much easier than using COM? -- http://mail.python.org/mailman/listinfo/python-list