ISO to Gregorian, strptime madness

A

Afanasiy

Can I easily convert from ISO to Gregorian calendars in Python 2.3?

For example, what Gregorian date is year 2004, week 1, day 1?

If possible, I'd greatly prefer to do this with the standard library.
I believe the mx.DateTime module provides this functionality, but I've
spent a bit of time converting pre-2.3 code to the new datetime modules.

---

While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both. So, to strptime into a datetime, I am forced to use * like so :

t1tmp = time.strptime(sometext,timeformat)
t1 = datetime.datetime(*t1tmp[0:6])

My question is, is there a better way which might be closer to something
like datetime.strptime? (which doesn't exist strangely).
 
P

Peter Hansen

Afanasiy said:
While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both.

Uh, really?

C:\>python23
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32Traceback (most recent call last):
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'strptime'


Looks to me like strptime and strftime are both in time and not in datetime.

-Peter
 
A

Afanasiy

Uh, really?

Looks to me like strptime and strftime are both in time and not in datetime.

Yeah I didn't remember the specifics, but it's something like that.
Something that I needed to have strptime does not have it, but has
strftime. I am a sorry for that mistake now, because of your reply.

This is not the primary concern of the post, and not even secondary,
so please ignore the silly mistake and help with the other things.
 
A

Afanasiy

Uh, really?

Ok, I checked it out, even though it's not my primary concern.
Looks to me like strptime and strftime are both in time and not in datetime.

datetime the class in the datetime module has strftime but no strptime
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: type object 'datetime.datetime' has no attribute
'strptime'
So... I do this sort of thing :

t1tmp = time.strptime(sometext,timeformat)
t1 = datetime.datetime(*t1tmp[0:6])

-AB
 
P

Peter Hansen

Afanasiy said:
Yeah I didn't remember the specifics, but it's something like that.
Something that I needed to have strptime does not have it, but has
strftime. I am a sorry for that mistake now, because of your reply.

This is not the primary concern of the post, and not even secondary,
so please ignore the silly mistake and help with the other things.

I wish I could help, but I don't know anything about this area. I was
just struck by the seeming irregularity, but upon investigating I didn't
see the same thing you did so I pointed it out.

(To be honest, I don't see the problem with a two-line solution, which
could easily be encapsulated in a simple function if it looks too
ugly for you.)

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top