[Tutor] Copy file function works, but not with adding the date copied
cclpianos at comcast.net
cclpianos at comcast.net
Fri Feb 13 17:47:58 CET 2009
Hello,
I am modifying a simple program "copy file" from the tutorials Alan
Gauld wrote. In it's first simpler instance (W/O date) it works
beautifully. But I wanted to
add the date the file was copied. I've kept it simple by pointing to
a single file.
The problem lies somewhere in how the program modifies the
information. It creates the new copied file, but can't open with the
application TextEdit. However, I can
read the file from the shell interpreter and do see the date the file
was copied:
The date this file was copied Friday February 13
{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf440
{\fonttbl\f0\fnil\fcharset77 LucidaGrande;\f1\fnil\fcharset77 Verdana;
\f2\fmodern\fcharset77 Courier;
\f3\fswiss\fcharset77 Helvetica;\f4\fnil\fcharset77 LucidaGrande-Bold;
\f5\fswiss\fcharset77 ArialMT;
}
{\colortbl;\red255\green255\blue255;\red249\green249\blue249;\red51
\green51\blue51;}
\margl1440\margr1440\vieww14060\viewh10300\viewkind0
\deftab720
\pard\pardeftab720\sl320\ql\qnatural
\f0\fs24 \cf0 \
tcpdump -q -ien1 lists tcp activity reatime\
\
ps axc -U root Lists processes by "root" users\
\
\
I'm using 2.61 on OS X 10.4.11. My apologies in advance for the
indention format.
TIA,
Pat
below is the file:
# this is a simple tool to copy a file from the console (modified to
show the date it was copied).
import time
inp = open( "/Users/pw/Desktop/Terminal_commands.rtf","r") # file to
be opened using the path
outp = open( "/Users/pw/Desktop/Terminalback_commands.rtf","w") #
Copied file modified name
today = time.localtime(time.time()) #Using the time function to
output the date file was copied
theDate = time.strftime("%A %B %d", today)
outp.write( "The date this file was copied %s\n\n" % theDate)
for line in inp:
outp.write(line)
print "This copied file has now been modified only by the date copied."
inp.close()
outp.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090213/4db5392c/attachment.htm>
More information about the Tutor
mailing list