clach04 / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

Add date formatting for datetime etc instances #57

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It's useful to be able to specify a format for datetime values. I've attached a 
diff that provides this functionality, basically by copying the float and int 
formatting. It's applied to any object with a "strftime" method, which catches 
date, time and datetime.

The validation of the format is pretty minimal, because you can put basically 
anything in a strftime format. I wondered whether it was worth it, but I left 
it as it's easier to extend the checks in the future if needed.

Original issue reported on code.google.com by p.f.mo...@gmail.com on 28 Aug 2014 at 1:31

Attachments:

GoogleCodeExporter commented 8 years ago
This is actually an enhancement request, but I couldn't see a way of setting 
the type :-(

Original comment by p.f.mo...@gmail.com on 28 Aug 2014 at 1:32

GoogleCodeExporter commented 8 years ago
Hey, just want to let you know I've seen your request, and I'll take a look at 
it this weekend. Thanks for your work!

Original comment by john.fil...@gmail.com on 9 Sep 2014 at 11:39

GoogleCodeExporter commented 8 years ago

Original comment by john.fil...@gmail.com on 9 Sep 2014 at 11:42

ayushiagarwal commented 6 years ago

Datetime.datetime is not supported by pretty table . When I try to use datetime.datetime in pretty table it gives an error:

anaconda3/lib/python3.5/site-packages/prettytable.py in get_html_string(self, *kwargs) 1184 string = self._get_formatted_html_string(options) 1185 else: -> 1186 string = self._get_simple_html_string(options) 1187 1188 return string anaconda3/lib/python3.5/site-packages/prettytable.py in _get_simple_html_string(self, options) 1214 1215 # Data -> 1216 rows = self._get_rows(options) 1217 formatted_rows = self._format_rows(rows, options) 1218 for row in formatted_rows: anaconda3/lib/python3.5/site-packages/prettytable.py in _get_rows(self, options) 924 925 # Make a copy of only those rows in the slice range --> 926 rows = copy.deepcopy(self._rows[options["start"]:options["end"]]) 927 # Sort if necessary 928 if options["sortby"]: anaconda3/lib/python3.5/copy.py in deepcopy(x, memo, _nil) 153 copier = _deepcopy_dispatch.get(cls) 154 if copier: --> 155 y = copier(x, memo) 156 else: 157 try: anaconda3/lib/python3.5/copy.py in _deepcopy_list(x, memo) 216 memo[id(x)] = y 217 for a in x: --> 218 y.append(deepcopy(a, memo)) 219 return y 220 d[list] = _deepcopy_list anaconda3/lib/python3.5/copy.py in deepcopy(x, memo, _nil) 153 copier = _deepcopy_dispatch.get(cls) 154 if copier: --> 155 y = copier(x, memo) 156 else: 157 try: anaconda3/lib/python3.5/copy.py in _deepcopy_list(x, memo) 216 memo[id(x)] = y 217 for a in x: --> 218 y.append(deepcopy(a, memo)) 219 return y 220 d[list] = _deepcopy_list anaconda3/lib/python3.5/copy.py in deepcopy(x, memo, _nil) 180 raise Error( 181 "un(deep)copyable object of type %s" % cls) --> 182 y = _reconstruct(x, rv, 1, memo) 183 184 # If is its own copy, don't memoize. lib/python3.5/copy.py in _reconstruct(x, info, deep, memo) 289 dictiter = None 290 if deep: --> 291 args = deepcopy(args, memo) 292 y = callable(args) 293 memo[id(x)] = y anaconda3/lib/python3.5/copy.py in deepcopy(x, memo, _nil) 153 copier = _deepcopy_dispatch.get(cls) 154 if copier: --> 155 y = copier(x, memo) 156 else: 157 try: anaconda3/lib/python3.5/copy.py in _deepcopy_tuple(x, memo) 221 222 def _deepcopy_tuple(x, memo): --> 223 y = [deepcopy(a, memo) for a in x] 224 # We're not going to put the tuple in the memo, but it's still important we 225 # check for it, in case the tuple contains recursive mutable structures.anaconda3/lib/python3.5/copy.py in (.0) 221 222 def _deepcopy_tuple(x, memo): --> 223 y = [deepcopy(a, memo) for a in x] 224 # We're not going to put the tuple in the memo, but it's still important we 225 # check for it, in case the tuple contains recursive mutable structures. anaconda3/lib/python3.5/copy.py in deepcopy(x, memo, _nil) 180 raise Error( 181 "un(deep)copyable object of type %s" % cls) --> 182 y = _reconstruct(x, rv, 1, memo) 183 184 # If is its own copy, don't memoize. anaconda3/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo) 290 if deep: 291 args = deepcopy(args, memo) --> 292 y = callable(*args) 293 memo[id(x)] = y 294 TypeError: init() missing 3 required positional arguments: 'sign', 'hours', and 'minutes'

Any solutions or work around for the problem?