473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Syntax Problem with strptime in Python 2.4

Apparently, use of strptime of datetime needs a workaround in Python 2.4 to
work properly. The workaround is d =
datetime.datetime(*(time.strptime(date_string, format)[0:5])). However, when
I try to use it, or even use it the regular way, it fails with
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'.
From the following code code segment:

format = '%Y%m%d_%H%M%S'
#d=datetime.strptime('20080321_113405', format)-- typical use
print time.strptime('20080321_113405', format)[0:5]
d = datetime.datetime(*time.strptime('20080321_113405' , format)[0:5])

Does anyone know how to make this work in 2.4? If not, is there a way to
achieve the same result?
--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>

Sep 8 '08 #1
3 11288
>Apparently, use of strptime of datetime needs a workaround in Python
2.4 to work properly. The workaround is d =
datetime.datetime(*(time.strptime(date_string,
format)[0:5])). However, when I try to use it, or even use it the
regular way, it fails with AttributeError: type object
'datetime.datetime' has no attribute 'datetime'.
Works for me:
>>import datetime
format = '%Y%m%d_%H%M%S'
import time
print time.strptime('20080321_113405', format)[0:5]
(2008, 3, 21, 11, 34)
>>d = datetime.datetime(*time.strptime('20080321_113405' , format)[0:5])
d
datetime.datetime(2008, 3, 21, 11, 34)

Python 2.4.4, Mac OS X 10.5.4.

Skip
Sep 8 '08 #2
W. eWatson wrote:
Apparently, use of strptime of datetime needs a workaround in Python 2.4
to work properly. The workaround is d =
datetime.datetime(*(time.strptime(date_string, format)[0:5])). However,
when I try to use it, or even use it the regular way, it fails with
AttributeError: type object 'datetime.datetime' has no attribute
'datetime'.
From the following code code segment:

format = '%Y%m%d_%H%M%S'
#d=datetime.strptime('20080321_113405', format)-- typical use
print time.strptime('20080321_113405', format)[0:5]
d = datetime.datetime(*time.strptime('20080321_113405' , format)[0:5])

Does anyone know how to make this work in 2.4? If not, is there a way to
achieve the same result?
This is not what you think it is. All your problem is that you do

from datetime import datetime

which imports the datetime-class, but then try to access

datetime.datetime

as if you had done

import datetime.
This actually is a wart in the datetime-module - it would be better if the
classes in there would follow PEP-8.

Diez
Sep 8 '08 #3
Diez B. Roggisch wrote:
W. eWatson wrote:
>Apparently, use of strptime of datetime needs a workaround in Python 2.4
to work properly. The workaround is d =
datetime.datetime(*(time.strptime(date_string, format)[0:5])). However,
when I try to use it, or even use it the regular way, it fails with
AttributeError: type object 'datetime.datetime' has no attribute
'datetime'.
From the following code code segment:

format = '%Y%m%d_%H%M%S'
#d=datetime.strptime('20080321_113405', format)-- typical use
print time.strptime('20080321_113405', format)[0:5]
d = datetime.datetime(*time.strptime('20080321_113405' , format)[0:5])

Does anyone know how to make this work in 2.4? If not, is there a way to
achieve the same result?

This is not what you think it is. All your problem is that you do

from datetime import datetime

which imports the datetime-class, but then try to access

datetime.datetime

as if you had done

import datetime.
This actually is a wart in the datetime-module - it would be better if the
classes in there would follow PEP-8.

Diez
That's it. Thanks.

--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>

Sep 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

75
by: David MacQuigg | last post by:
Seems like we need a simple way to extend Python syntax that doesn't break existing syntax or clash with any other syntax in Python, is easy to type, easy to read, and is clearly distinct from the...
0
by: Neal D. Becker | last post by:
I'm using boost::python to transform various C++ classes and functions to python. It is all working quite well, but now I'm having trouble with documentation tools. I hope someone can tell me...
8
by: Alec Wysoker | last post by:
I need to be able to access mySQL 4.0 and 4.1 databases from python. I was hoping to find mysql-python 1.2.0 already built for Sparc, but no such luck. I've been struggling trying to get it...
3
by: devendra_k | last post by:
I want to intigrate the PyGame module with my Python exe, means i DONT want to generate .PYD files separtely rather than that want to put PyGame "c" src with Python workspace of VC project...
7
by: Katja Süss | last post by:
Hi! maybe somebody can give me an hint to my problem setting up PyUNO on my Mac to work with my Python not the Python delivered with OpenOffice. As said in installation instructions I've set...
3
by: akbar | last post by:
I googled and searched in archive. All I can find is finding resolution with Tkinter and pygame. Any idea to find monitor resolution with standard python module? I can check from output of: xprop...
3
Colloid Snake
by: Colloid Snake | last post by:
Hey- I am running Python 2.5 on XP SP1, and am running into a problem with my script. I beleive I have formatted a regex properly that will pull a date from an xml file, and I then want to convert...
7
by: braver | last post by:
Greetings -- as a long time user of both Python and Ruby interpreters, I got used to the latter's syntax-coloring gem, wirble, which colorizes Ruby syntax on the fly. Is there anything similar for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.