Title: Signature.html
Yes, my posting has become rather odd in that I don't see my own posts, except for the first one. It seems to have started about a week ago.  I asked the owner about that and haven't gotten a reply yet. I hit Reply, Reply to Sender or Reply to All on this message, I only see your address. I would think it should have [EMAIL PROTECTED], somewhere and not only your name. If I use Reply to All on my original post, I get [EMAIL PROTECTED]. Looking at some of the other respondents above, they have [EMAIL PROTECTED].

Looking at an earlier response of yours, if I press Reply All, both you and tutor are shown. It seems weeks ago, I only had to use Reply. A mystery. I forced [EMAIL PROTECTED] into this response.

Yes, your description is about it. I think you meant, strptime at the end, but whatever the simplest way to use datetime to do this is what I'm looking for. Maybe it's not possible. I'm working on a function that I hope will do this.

greg whittier wrote:
It seems like the way to go (and what I think you were trying to do) is create a datetime object from the file name using datetime.datetime.strptime, add a timedelta to that to get a new datetime object, and then use sprtime with that object.

You didn't reply to the list by the way.  I think this will work.  I would post a *complete* example that shows where you run into trouble.  Make a single python file, say foo.py, run that and post the *complete* contents of the file and the output.  I'm pretty sure the problem will be identified quickly if you do that.

On Sun, Sep 7, 2008 at 6:56 PM, Wayne Watson <[EMAIL PROTECTED]> wrote:
I have no idea how the time class module got into this. Possibly it's a remnant of having the (import time)  statement there when I first began, or the time.datetime usage brought it in.

Here's what I'm trying to do. I have a file name with the date-time stamp:
    yyyymmdd_hhmmss
The _ is part of the file name.

I'd like to take that date-time from the file name, and convert it to a legitimate type that one can use in some datetime method to get into a form that can be manipulated by a datetime method.  I'd like to add seconds to the date & time. If I add enough seconds, it's possible that if enough seconds are added that the day might get changed, so both date and time need to be connected. After that's done, I'd like to get the date back to the date-time stamp, as above, to change the file name. It looks like the datetime class methods cannot do that simply by using some str?time method.

If not, I'll just stick with supplementing both the time and datetime classes by continuing to write functions that will do the trick for various situations, e.g, hhmmss to hh:mm:ss, and vice versa.

greg whittier wrote:


On Sun, Sep 7, 2008 at 1:36 PM, Wayne Watson <[EMAIL PROTECTED]> wrote:
Yes, cut and paste directly from the code. Positively a import as seen. Here's the full set of code:
# The effect of adding seconds to date-time to see if day gets changed
import datetime
dt1 = datetime.datetime(2008, 03, 10, 23, 59, 0)
print dt1
delta = datetime.timedelta(seconds = 200)
print dt1+delta


# format conversion of date+time
dt1 = time.strptime("20080421_101145", "%Y%m%d_%H%M%S")
The first code you posted was different.  You had datetime.strptime and not time.strptime.  Your problem is dt1 is a time.struct_time which has no strftime method, producing the error. 

You must have imported time somewhere.  This line makes dt1 a time.struct_time which causes your problem.
 

print "dt1: ",dt1
other = dt1.strftime("%Y%m%d_%H%M%S")
Now dt1 is a time.struct_time and not a datetime.datetime object so it has no strftime method.
 

...
# format conversion of date+time
dt1 = datetime.strptime("20080421_101145", "%Y%m%d_%H%M%S")
I don't see how this works as written because the datetime module doesn't have a strptime function.

This is what you had before.  Note datetime.strptime instead of time.strptime, which confused me because the datetime module doesn't have a strptime function.
 


--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (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
            
          "If voting made any difference they wouldn't let us do it." 
                        -- Mark Twain
            
                    Web Page: <www.speckledwithstars.net/>


--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (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
            
          "If voting made any difference they wouldn't let us do it." 
                        -- Mark Twain
            
                    Web Page: <www.speckledwithstars.net/>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to