Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62658 > unrolled thread
| Started by | Igor Korot <ikorot01@gmail.com> |
|---|---|
| First post | 2013-12-23 16:30 -0800 |
| Last post | 2013-12-24 11:14 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
How to check the date validity? Igor Korot <ikorot01@gmail.com> - 2013-12-23 16:30 -0800
Re: How to check the date validity? gregor <gregor@ediwo.com> - 2013-12-24 11:14 +0100
| From | Igor Korot <ikorot01@gmail.com> |
|---|---|
| Date | 2013-12-23 16:30 -0800 |
| Subject | How to check the date validity? |
| Message-ID | <mailman.4578.1387845038.18130.python-list@python.org> |
Hi, ALL, I'm working on the python script which reads the data from the csv file. In this file I have 3 different kind of fields: one consist of the sole date, one - sole time and one - datetime. The time includes milliseconds, i.e. "12:55:55.705" All fields of the file including those 3 I am reading as the string. All those strings after validating will go into mySQL table. Now, it looks that the python way of validating the date/time of the string is to call strptime(). However looking at the docs and trying to use the function I didn't find a way to check for the milliseconds. Now the dates can be formatted differently I think according to the locale under which the csv is generated. So, my question is: since there is a simple way of inserting preformatted string into the datetime field of mySQL, how do I validate the date string? I don't want to convert that string to datetime object, just want to check if all those types of dates are good dates and does not contain garbage. I tried to do an RE, but its static validation and so will not work in all cases. Thank you for any hints.
[toc] | [next] | [standalone]
| From | gregor <gregor@ediwo.com> |
|---|---|
| Date | 2013-12-24 11:14 +0100 |
| Message-ID | <20131224111411.7089cda6@florenz> |
| In reply to | #62658 |
Am Mon, 23 Dec 2013 16:30:35 -0800 schrieb Igor Korot <ikorot01@gmail.com>: > > Now, it looks that the python way of validating the date/time of the > string is to call strptime(). However looking at the docs and trying > to use the function I didn't find a way to check for the milliseconds. > Now the dates can be formatted differently I think according to the > locale under which the csv is generated. you can also use an validator package like formencode: http://www.formencode.org/en/latest/Validator.html It has an TimeConverter but it does not understand milliseconds either. But it should be trivial to implement it based on TimeConverter. Using formencode the validation / conversion is seperated and therefore reusable. You also get nice human readable validation messages in different languages. It supports also Schemas to validate complete records. -- Greg
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web