Re: [Tutor] ftplib.storbinary and using a progress bar

2008-09-07 Thread Alan Gauld

johnf [EMAIL PROTECTED] wrote


the file transfer (it could be a very long transfer).  But
ftplib.storbinary() has no callback like retrbinary() so does anyone 
have a

thought on how I can update my user on the progress of the transfer.


If you don't fancy getting the 2.6 source as Terry suggested then
the other way to do this kind of thing is with a separate thread. 
Start

the new thread which just displays a progress bar (you need to find
how big the file is before hand and check progress as you go too)
Then in the main thread run the transfer and terminate the progress
thread when you finish.

How easy this is depends on your familiarity with threads I guess!
As threading goes its a fairly straighforward use.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Online Scripting

2008-09-07 Thread Omer
Hello.

I started a project with a goal: To have a script read an entire message
board, dedicated to various events,
process this information into an iCalendar file,
and finally- base a Google Calendar on the iCal file.

Now,
The script is done and it works great on my desktop.
The problem is, seeing as I plan this a sort of a service for the forum
people,
It can't be based off of my desktop, which is only available 5 ~ 6 days a
week.

So,

Has anyone a clue as to where might I host my script, so's A: the host
runs my script periodical (Once every Two hours? If I can configure it to
only run during the day than that's even better), and B: The host lets my
script create an iCal file (a single, 1MB file) and C: lets GCal have
access to this file.

I've looked Google App Engine. It's a huge effort: First remodeling my
script to use the GAE way of opening urls, to use the GAE way of storing
information, and I haven't as yet even looked into how do I store the
prepared iCal file, or how do I schedule the runs of my script. The need to
learn an entire platform, (Although I do plan to learn it someday), is too
large for me now. (Although, if there's no choice that's what I'll do.)

Sorry about this message's length,
Help will be appreciated, thank you for your time.
Omer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Support for datetime module

2008-09-07 Thread Johan Geldenhuys
Thanks Kent,

Let me explain what I need it for.

I have a systemUpTime is seconds that I got from a SNMP agent.

I want to work out when the system uptime began and want to put that in ISO
format time to the millisecond.

So my idea is to take a timestamp in seconds when I get the systemUpTime. I
subtract the uptime from my timestamp and then format that into ISO format.
That should give me a fairly accurate UTC-like time of when the systemUpTime
began.
Here is an example: 2008-09-04 22:29:43.221 Z

Do you think it will be difficult to work this out with the datetime module?

Any suggestion would be greatly appreciated.

Thanks

Johan

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent
Johnson
Sent: Saturday, 6 September 2008 23:08 PM
To: [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] Support for datetime module

On Sat, Sep 6, 2008 at 2:42 AM, Johan Geldenhuys [EMAIL PROTECTED]
wrote:
 Hi all,

 I have want to use the datetime module on a system with ver 2.2.3
installed.
 I know it's very old, but that's what I have to deal with and can't
upgrade.
 So please don't suggest that.

 As you know datetime was available from version 2.3.



 I want to know where can I get the datetime module so that I can include
it
 in my package that I use on my device?

datetime is implemented in C so getting the version from 2.3 to work
on 2.2 might be difficult.

Apparently the version in the std lib is derived from a Python version
that was part of Zope, this might be helpful if you can find the
source it refers to:
http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Online Scripting

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 5:25 AM, Omer [EMAIL PROTECTED] wrote:

 Has anyone a clue as to where might I host my script, so's A: the host
 runs my script periodical (Once every Two hours? If I can configure it to
 only run during the day than that's even better), and B: The host lets my
 script create an iCal file (a single, 1MB file) and C: lets GCal have
 access to this file.

Try WebFaction.com or see
http://wiki.python.org/moin/PythonHosting
for many suggestions.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ftplib.storbinary and using a progress bar

2008-09-07 Thread Kent Johnson
On Sat, Sep 6, 2008 at 9:49 PM, johnf [EMAIL PROTECTED] wrote:
 Hi,
 I'm currently using ftplib.storbinary() to upload a file to a FTP server.
 However, I would like to inform the user of the progress being made during
 the file transfer (it could be a very long transfer).  But
 ftplib.storbinary() has no callback like retrbinary() so does anyone have a
 thought on how I can update my user on the progress of the transfer.  BTW  I
 have to use a binary transfer because the file being transfer is not text.

storbinary() is not very complex. You could write your own version
that has a callback function.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Support for datetime module

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 6:17 AM, Johan Geldenhuys [EMAIL PROTECTED] wrote:
 Thanks Kent,

 Let me explain what I need it for.

 I have a systemUpTime is seconds that I got from a SNMP agent.

 I want to work out when the system uptime began and want to put that in ISO
 format time to the millisecond.

 So my idea is to take a timestamp in seconds when I get the systemUpTime. I
 subtract the uptime from my timestamp and then format that into ISO format.
 That should give me a fairly accurate UTC-like time of when the systemUpTime
 began.
 Here is an example: 2008-09-04 22:29:43.221 Z

I think you can do all that with functions in the time module.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ftplib.storbinary and using a progress bar

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 4:13 AM, Alan Gauld [EMAIL PROTECTED] wrote:
 johnf [EMAIL PROTECTED] wrote

 the file transfer (it could be a very long transfer).  But
 ftplib.storbinary() has no callback like retrbinary() so does anyone have
 a
 thought on how I can update my user on the progress of the transfer.

 If you don't fancy getting the 2.6 source as Terry suggested then
 the other way to do this kind of thing is with a separate thread. Start
 the new thread which just displays a progress bar (you need to find
 how big the file is before hand and check progress as you go too)
 Then in the main thread run the transfer and terminate the progress
 thread when you finish.

I don't think threading will help here, the problem is that the
progress information is not available.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ftplib.storbinary and using a progress bar

2008-09-07 Thread johnf
On Saturday 06 September 2008 06:49:39 pm johnf wrote:
 Hi,
 I'm currently using ftplib.storbinary() to upload a file to a FTP server.
 However, I would like to inform the user of the progress being made during
 the file transfer (it could be a very long transfer).  But
 ftplib.storbinary() has no callback like retrbinary() so does anyone have a
 thought on how I can update my user on the progress of the transfer.  BTW 
 I have to use a binary transfer because the file being transfer is not
 text.

Once I took a look at the source for ftplib I decided to subclass the module.  
I then provided my own method with a callback.  For my purpose I just passed 
an integer back (a counter).   But thanks everyone for the help.  It was a 
good lesson anyway.

-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Inserting an Indent in IDLE?

2008-09-07 Thread Wayne Watson
Title: Signature.html




Occasionally I would like to indent 20-30 lines of code. I don't see a
way to do this in IDLE other than brute force. The Replace dialog
doesn't seem to offer a way. Does it by any chance use regular
expressions to do this?
-- 


   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


Re: [Tutor] ftplib.storbinary and using a progress bar

2008-09-07 Thread Alan Gauld
Kent Johnson [EMAIL PROTECTED] wrote 


I don't think threading will help here, the problem is that the
progress information is not available.


If you are transferring from A to B and can find the size of 
the file at A and poll the size at B you can display progress.
OTOH if that is not available you can still use a thread to 
indicate that *something* is happening even if you don't 
know when it will stop. Thus a threaded approach works 
for providing some kind of user feedback even if nothing 
else.


Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Inserting an Indent in IDLE?

2008-09-07 Thread Alan Gauld


Wayne Watson [EMAIL PROTECTED] wrote

Signature.htmlOccasionally I would like to indent 20-30 lines of 
code.

I don't see a way to do this in IDLE other than brute force.


Format-Indent region?

Ctrl-]

Format Dedent region

Ctrl-[

Seems to work for me.

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help with using methods in a base class

2008-09-07 Thread Roy Khristopher Bayot
Hi. I added self to parts of the code. But after making an instance and
using the setData method it gave out an AttributeError.

 from parallel import Parallel
 class LightsHandle(Parallel):
... def __init__(self):
... pass
... def setData(self, data):
... Parallel.setData(self, data)
... def setLatch(self, latch):
... Parallel.setDataStrobe(self, int(latch[0]))
... Parallel.setAutoFeed(self, int(latch[1]))
... Parallel.setInitOut(self, int(latch[2]))
... def generateClockPulse(self):
... Parallel.setSelect(self, 0)
... Parallel.setSelect(self, 1)
...
 a = LightsHandle()
 a.setData(0xF0)
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 5, in setData
  File /usr/lib/python2.5/site-packages/parallel/parallelppdev.py, line
563, in setData
return self.PPWDATA(d)
  File /usr/lib/python2.5/site-packages/parallel/parallelppdev.py, line
465, in PPWDATA
fcntl.ioctl(self._fd, PPWDATA,struct.pack('B',byte))
AttributeError: LightsHandle instance has no attribute '_fd'

Does this mean I have to make '_fd' in class LightsHandle? I thought that it
would be somewhat messy. And there might be other variables that werent
accounted for.

So I did something else.

 class LightsHandle(Parallel):
... def __init__(self):
... Parallel.__init__(self, port = 0)
... def __del__(self):
... Parallel.__del__(self)
... def setData(self, data):
... Parallel.setData(self, data)
... def setLatch(self, latch):
... Parallel.setDataStrobe(self, int(latch[0]))
... Parallel.setAutoFeed(self, int(latch[1]))
... Parallel.setInitOut(self, int(latch[2]))
... def generateClockPulse(self):
... Parallel.setSelect(self,0)
... Parallel.setSelect(self,1)
...
 a = LightsHandle()
 a.setData(0xF0)
 a.setLatch('111')
 a.generateClockPulse()
 a.setLatch('110')
 a.generateClockPulse()
 a.setData(0x0F)
 a.setLatch('111')
 a.generateClockPulse()

There were no errors thrown. But the problem is that it doesnt work. This
was suppose to control 32 LEDs (8 LEDs per latch, 6 latches total). Method
setData() is suppose to control the 8 bits that you want to output on a
specific latch. Method setLatch() will specify the latch. Method
generateClockPulse() will cause the specific latch to take in the data and
retain it there.

But it doesnt work. The LEDs couldnt be controlled.

I already tried using the base class and it works just fine.

 from parallel import Parallel
 p = Parallel()
 p.setData(0xFF)
 p.setDataStrobe(1)
 p.setAutoFeed(1)
 p.setInitOut(1)
 p.setSelect(0)
 p.setSelect(1)

So I thought maybe there was something wrong with setLatch() since elements
of the string were converted to integers. I changed the code again.

 class LightsHandle(Parallel):
... def __init__(self):
... Parallel.__init__(self, port = 0)
... def __del__(self):
... Parallel.__del__(self)
... def setData(self, data):
... Parallel.setData(self, data)
... def setLatch(self, x, y, z):
... Parallel.setDataStrobe(self, x)
... Parallel.setAutoFeed(self, y)
... Parallel.setInitOut(self, z)
... def generateClockPulse(self):
... Parallel.setSelect(self,0)
... Parallel.setSelect(self,1)
...
 a = LightsHandle()
 a.setData(0xF0)
 a.setLatch(1,1,1)
 a.generateClockPulse()
 a.setData(0x0F)
 a.setLatch(1,1,1)
 a.generateClockPulse()

But no LED lights were changing as it was suppose to.

Any ideas on what I dont know or what I've overlooked?


On Sun, Sep 7, 2008 at 6:07 AM, Alan Gauld [EMAIL PROTECTED]wrote:

 Roy Khristopher Bayot [EMAIL PROTECTED] wrote


  ... def generateClockPulse(self):
 ... parallel.Parallel.setSelect(0)
 ... parallel.Parallel.setSelect(1)
 ...

 a = LightsHandle()
 a.setD(0xF0)

 Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 5, in setD
 TypeError: unbound method setData() must be called with Parallel instance
 as
 first argument (got int instance instead)


 The error merssage gives the clue. Sonce you are calling a method
 on a classs not an object you need to pass in the instance reference
 explicitly. Its exactly as in calling the base constructor in __init__

 class C(P):
  def __init__(self):
 P.__init__(self)# need to pass self here

  (Some notes: I changed setData() to setD() so that there wont be a
 confusion. Method setData() is from the base class Parallel. Although I
 think setData() could be overriden.)


 Thats not necessary, each class creates its owen namespace.

  What have I been doing wrong? Why does it say that I need a Parallel
 instance?


 Because the class needs to know where to find the instance variables.
 Since you are calling the class directly, not via an instance you have
 to pass self explicitly.

 

[Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Wayne Watson
Title: Signature.html




I've been writing various functions with datetime to change date-time
formats from one to another. For example, my file names have a time
stamp of mmdd_hhmmss in their names. When I need to convert, say,
time by adding seconds to the hhmmss part of the file name, I have a
function that converts hhmmss to hh:mm:ss, and another to go the other
way. In between, I add seconds. Maybe datetime can do this more easily
without the use of my functions? 
-- 


   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


Re: [Tutor] Sending email as html

2008-09-07 Thread Tim Johnson
On Saturday 06 September 2008, Alan Gauld wrote:
 Tim Johnson [EMAIL PROTECTED] wrote

  since PDF files are not very hard to edit with a simple text
  editor.
  (Never have really.)
 
  Looks like I could make up a PDF template and then put substitutions

 You could although they are not pure text files so you may need
 to use binary mode to edit the file I think.
  :-) vim -b
 There is an interersting looking link here:

 http://www.python.org/workshops/2002-02/papers/17/index.htm
  Yes!
 HTH,
 thanks man -
tj
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread greg whittier
I'm not clear on exactly what you're looking to do, but I think you want the
strftime and strptime methods.  See
http://docs.python.org/lib/datetime-datetime.html

On Sun, Sep 7, 2008 at 11:24 AM, Wayne Watson
[EMAIL PROTECTED]wrote:

  I've been writing various functions with datetime to change date-time
 formats from one to another. For example, my file names have a time stamp of
 mmdd_hhmmss in their names. When I need to convert, say, time by adding
 seconds to the hhmmss part of the file name, I have a function that converts
 hhmmss to hh:mm:ss,  and another to go the other way. In between, I add
 seconds. Maybe datetime can do this more easily without the use of my
 functions?
 --

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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread greg whittier
Is this an actual cut and paste of your code?  The problem seems to be that
you're getting a time.struct_time object instead of a datetime object.  See
below

On Sun, Sep 7, 2008 at 12:52 PM, Wayne Watson
[EMAIL PROTECTED]wrote:

  Yes, that's correct., but that reference isn't doing it for me presently.
 Here's a piece of code that might help explain what I'm trying to do:

 # program to test str... functions
 import datetime

 Are you sure you didn't do from datetime import datetime?



 ...
 # 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.


 print dt1: ,dt1
 other = dt1.strftime(%Y%m%d_%H%M%S)  -- fails, line 11
 print other.replace( , )

 Results:
 dt1:  (2008, 4, 21, 10, 11, 45, 0, 112, -1)


 Traceback (most recent call last):
   File
 C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/BumpSeconds,
 line 11, in ?
 other = dt1.strftime(%Y%m%d_%H%M%S)
 AttributeError: 'time.struct_time' object has no attribute 'strftime'


This is telling you that dt1 is a time.struct_time but I don't see how from
the code you've shown here.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help with using methods in a base class

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 11:07 AM, Roy Khristopher Bayot
[EMAIL PROTECTED] wrote:
 Hi. I added self to parts of the code. But after making an instance and
 using the setData method it gave out an AttributeError.

 from parallel import Parallel
 class LightsHandle(Parallel):
 ... def __init__(self):
 ... pass

This will *prevent* Parallel.__init__() from being called. I guess
this is not what you want, it is probably the cause of your trouble.
Is _fd initialized in Parallel.__init__() ?

 ... def setData(self, data):
 ... Parallel.setData(self, data)

This method is not needed at all. If you omit it, the base class
method will be called automatically when you call setData() on a
LightsHandle instance.

 ... def setLatch(self, latch):
 ... Parallel.setDataStrobe(self, int(latch[0]))
 ... Parallel.setAutoFeed(self, int(latch[1]))
 ... Parallel.setInitOut(self, int(latch[2]))

This could be written more simply and idiomatically as

... def setLatch(self, x, y, z):
... self.setDataStrobe(x)
... self.setAutoFeed(y)
... self.setInitOut(z)

Since you have not overridden these methods you can call them directly.

 ... def generateClockPulse(self):
 ... Parallel.setSelect(self, 0)
 ... Parallel.setSelect(self, 1)

Same here.

 a = LightsHandle()
 a.setData(0xF0)
 Traceback (most recent call last):
   File stdin, line 1, in module
   File stdin, line 5, in setData
   File /usr/lib/python2.5/site-packages/parallel/parallelppdev.py, line
 563, in setData
 return self.PPWDATA(d)
   File /usr/lib/python2.5/site-packages/parallel/parallelppdev.py, line
 465, in PPWDATA
 fcntl.ioctl(self._fd, PPWDATA,struct.pack('B',byte))
 AttributeError: LightsHandle instance has no attribute '_fd'

 Does this mean I have to make '_fd' in class LightsHandle? I thought that it
 would be somewhat messy. And there might be other variables that werent
 accounted for.

Probably it means you have to call the base class __init__().

 a = LightsHandle()
 a.setData(0xF0)

 There were no errors thrown. But the problem is that it doesnt work.

 I already tried using the base class and it works just fine.

 from parallel import Parallel
 p = Parallel()
 p.setData(0xFF)

Note this is a different value than you used above, is that significant?

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sending email as html

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 11:27 AM, Tim Johnson [EMAIL PROTECTED] wrote:
 On Saturday 06 September 2008, Alan Gauld wrote:

 There is an interersting looking link here:

 http://www.python.org/workshops/2002-02/papers/17/index.htm
  Yes!

Did you find the code to go with the article? My google-fu is failing me today.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 1:17 PM, greg whittier [EMAIL PROTECTED] wrote:

 # program to test str... functions
 import datetime

 Are you sure you didn't do from datetime import datetime?

or import time ?

 ...
 # 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.

 print dt1: ,dt1
 other = dt1.strftime(%Y%m%d_%H%M%S)  -- fails, line 11
 print other.replace( , )

 Results:
 dt1:  (2008, 4, 21, 10, 11, 45, 0, 112, -1)

Looks to me like you are confusing the time and datetime modules.
time.strptime() will return a time struct;
datetime.datetime.strptime() returns a datetime.datetime.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Support for datetime module

2008-09-07 Thread Johan Geldenhuys
I can get the time up to the closest second with the time module, but not to
the millisecond.
When I use time.strftime, I don't know how many milliseconds are left over
to use them.



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent
Johnson
Sent: Sunday, 7 September 2008 21:04 PM
To: [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] Support for datetime module

On Sun, Sep 7, 2008 at 6:17 AM, Johan Geldenhuys [EMAIL PROTECTED]
wrote:
 Thanks Kent,

 Let me explain what I need it for.

 I have a systemUpTime is seconds that I got from a SNMP agent.

 I want to work out when the system uptime began and want to put that in
ISO
 format time to the millisecond.

 So my idea is to take a timestamp in seconds when I get the systemUpTime.
I
 subtract the uptime from my timestamp and then format that into ISO
format.
 That should give me a fairly accurate UTC-like time of when the
systemUpTime
 began.
 Here is an example: 2008-09-04 22:29:43.221 Z

I think you can do all that with functions in the time module.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread greg whittier
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.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Support for datetime module

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 3:48 PM, Johan Geldenhuys [EMAIL PROTECTED] wrote:
 I can get the time up to the closest second with the time module, but not to
 the millisecond.
 When I use time.strftime, I don't know how many milliseconds are left over
 to use them.

OK. I guess you can use time.strptime() and strftime() to parse /
format the time to the second and handle the milliseconds separately.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sending email as html

2008-09-07 Thread Tim Johnson
On Sunday 07 September 2008, you wrote:
 On Sun, Sep 7, 2008 at 11:27 AM, Tim Johnson [EMAIL PROTECTED] wrote:
  On Saturday 06 September 2008, Alan Gauld wrote:
  There is an interersting looking link here:
 
  http://www.python.org/workshops/2002-02/papers/17/index.htm
 
   Yes!

 Did you find the code to go with the article? My google-fu is failing me
 today.
  No code. Googling keywords got me nowhere.
  Tim
  Who remembers when google was a number
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Wayne Watson
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:
 mmdd_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 

Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Wayne Watson
Title: Signature.html




Here's as far as I can go with this. The last line of output asks the
question I need an answer for.
(Once again my direct post to tutor@python.org has failed to appear
here (sent 5:42 PDT), as before.)
# Using datetime to do date-time math on a file date-time
stamp and
# the creating the new stamp
import datetime
  
def adjust_ftime(atime, sec):
 # mmdd_hhmmss, seconds in, new mmdd_hhmmss out
 ts = atime[1:-7] # use time stamp portion
 ayear = int(ts[0:4])
 amonth = int(ts[4:6])
 aday = int(ts[6:8])
 ahour = int(ts[9:11])
 aminute = int(ts[11:13])
 asecond = int(ts[13:15])
 print ayear, amonth, aday, asecond
 dt1 = datetime.datetime(ayear, amonth, aday, ahour, aminute,
asecond)
 print dt1, type(dt1)
 delta = datetime.timedelta(seconds = 200)
 dt2 = dt1 + delta
 print dt2, type(dt2) 
 print "what next? I need the result 20080321_113405"
 new_fstamp = "zippo"
 return (new_fstamp)
  
 filename = 'v20080321_113045.27.txt'
 print adjust_ftime(filename, 2.3)

Results: 
2008 3 21 45
2008-03-21 11:30:45 type 'datetime.datetime'
2008-03-21 11:34:05 type 'datetime.datetime'
what next? I need the result 20080321_113405
  

-- 


   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


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread John Fouhy
2008/9/8 Wayne Watson [EMAIL PROTECTED]:
 def adjust_ftime(atime, sec):
 # mmdd_hhmmss, seconds in, new mmdd_hhmmss out
 ts = atime[1:-7]  # use time stamp portion
 ayear   = int(ts[0:4])
 amonth  = int(ts[4:6])
 aday= int(ts[6:8])
 ahour   = int(ts[9:11])
 aminute = int(ts[11:13])
 asecond = int(ts[13:15])
 print ayear, amonth, aday, asecond
 dt1 = datetime.datetime(ayear, amonth, aday, ahour, aminute, asecond)
 print dt1, type(dt1)
 delta = datetime.timedelta(seconds = 200)
 dt2 = dt1 + delta
 print dt2, type(dt2)
 print what next? I need the result 20080321_113405

Hi Wayne,

The functions you are looking for are strptime and strftime.  As follows:

 import datetime
 timeStr = '20080321_113045'
 dt1 = datetime.datetime.strptime(timeStr, '%Y%m%d_%H%M%S')
 dt2 = dt1 + datetime.timedelta(seconds=200)
 print dt2.strftime('%Y%m%d_%H%M%S')
20080321_113405

You can find the format codes for strptime and strftime in the
documentation for the time module.

Hope this helps!

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Kent Johnson
On Sun, Sep 7, 2008 at 9:33 PM, Wayne Watson
[EMAIL PROTECTED] wrote:
 Here's as far as I can go with this. The last line of output asks the
 question I need an answer for.
 (Once again my direct post to tutor@python.org has failed to appear here
 (sent 5:42 PDT), as before.)

It arrived late for some reason.

You can do what you want much more simply using datetime.strptime()
and strftime():
In [2]: from datetime import datetime, timedelta
In [3]: format = '%Y%m%d_%H%M%S'
In [8]: d=datetime.strptime('20080321_113405', format)
In [10]: d
Out[10]: datetime.datetime(2008, 3, 21, 11, 34, 5)
In [13]: d += timedelta(seconds=200)
In [14]: d
Out[14]: datetime.datetime(2008, 3, 21, 11, 37, 25)
In [15]: d.strftime(format)
Out[15]: '20080321_113725'

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Wayne Watson
Title: Signature.html




Yep, I tried strptime and strftime but got stuck too often on something
or other (mostly mixing time, datetime somehow), so simplified matters
to make it clear what I was trying to do.

I'm sure you have the essence below, but I'm not familiar with the In/
Out notation. Apparently, I need to scoop up the In lines into a file
and add some print stmts for the In[x] d lines.

Here's what I think I should put in a py file and the results:
# Using datetime to do date-time math on a file date-time
stamp and
# the creating the new stamp
from datetime import datetime, timedelta
  
format = '%Y%m%d_%H%M%S'
d=datetime.strptime('20080321_113405', format)
print d
datetime.datetime(2008, 3, 21, 11, 34, 5)
d += timedelta(seconds=200)
print d
datetime.datetime(2008, 3, 21, 11, 37, 25)
print d.strftime(format)

Results:
Traceback (most recent call last):
 File
"C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/debugDateTime.py",
line 6, in ?
 d=datetime.strptime('20080321_113405', format)
AttributeError: type object 'datetime.datetime' has no attribute
'strptime

This attribute problem is reminiscent of my problems. IDLE? Python
2.4.x?
Kent Johnson wrote:

  On Sun, Sep 7, 2008 at 9:33 PM, Wayne Watson
[EMAIL PROTECTED] wrote:
  
  
Here's as far as I can go with this. The last line of output asks the
question I need an answer for.
(Once again my direct post to tutor@python.org has failed to appear here
(sent 5:42 PDT), as before.)

  
  
It arrived late for some reason.

You can do what you want much more simply using datetime.strptime()
and strftime():
In [2]: from datetime import datetime, timedelta
In [3]: format = '%Y%m%d_%H%M%S'
In [8]: d=datetime.strptime('20080321_113405', format)
In [10]: d
Out[10]: datetime.datetime(2008, 3, 21, 11, 34, 5)
In [13]: d += timedelta(seconds=200)
In [14]: d
Out[14]: datetime.datetime(2008, 3, 21, 11, 37, 25)
In [15]: d.strftime(format)
Out[15]: '20080321_113725'

Kent

  


-- 


   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


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread John Fouhy
2008/9/8 Wayne Watson [EMAIL PROTECTED]:
 I'm sure you have the essence below, but I'm not familiar with the In/ Out
 notation. Apparently, I need to scoop up the In lines into a file and add
 some print stmts for the In[x] d lines.

Kent uses IPython, which is an enhanced version of the standard python
shell.  That's what the In[] and Out[] bits are from.

 AttributeError: type object 'datetime.datetime' has no attribute 'strptime

 This attribute problem is reminiscent of my problems. IDLE? Python 2.4.x?

Python 2.4, unfortunately.  datetime.strptime only came in with Python
2.5, IIRC.  The Python 2.4 version is:

d = datetime.datetime(*(time.strptime(date_string, format)[0:6]))

(i.e. that corresponds to d = datetime.datetime.strptime(date_string, format))

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formating from hhmms to hh:mm:ss

2008-09-07 Thread Wayne Watson
Title: Signature.html




Well, maybe. Here's the file the change and results:
# Using datetime to do date-time math on a file date-time
stamp and
# the creating the new stamp
from datetime import datetime, timedelta
  
format = '%Y%m%d_%H%M%S'
#d=datetime.strptime('20080321_113405', format)
d = datetime.datetime(*(time.strptime('20080321_113405', format)[0:6]))
print d
datetime.datetime(2008, 3, 21, 11, 34, 5)
d += timedelta(seconds=200)
print d
datetime.datetime(2008, 3, 21, 11, 37, 25)
print d.strftime(format

Results:
Traceback (most recent call last):
 File
"C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/debugDateTime.py",
line 7, in ?
 d = datetime.datetime(*(time.strptime('20080321_113405',
format)[0:6]))
AttributeError: type object 'datetime.datetime' has no attribute
'datetime'
  

>From a PLEAC web:
# The easiest way to convert this to a datetime seems to be; 
now = datetime.datetime(*time.strptime("16/6/1981", "%d/%m/%Y")[0:5])
# the '*' operator unpacks the tuple, producing the argument list.
I tried the [0:6] and it got the same results.

John Fouhy wrote:

  2008/9/8 Wayne Watson [EMAIL PROTECTED]:
  
  
I'm sure you have the essence below, but I'm not familiar with the In/ Out
notation. Apparently, I need to scoop up the In lines into a file and add
some print stmts for the In[x] d lines.

  
  
Kent uses IPython, which is an enhanced version of the standard python
shell.  That's what the In[] and Out[] bits are from.

  
  
AttributeError: type object 'datetime.datetime' has no attribute 'strptime

This attribute problem is reminiscent of my problems. IDLE? Python 2.4.x?

  
  
Python 2.4, unfortunately.  datetime.strptime only came in with Python
2.5, IIRC.  The Python 2.4 version is:

d = datetime.datetime(*(time.strptime(date_string, format)[0:6]))

(i.e. that corresponds to "d = datetime.datetime.strptime(date_string, format)")

  


-- 


   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