473,499 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11291
>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
3809
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
1256
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
2217
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
2584
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
3796
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
3504
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
1840
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
2489
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
7134
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
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
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
7395
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
5485
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
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.