[Tutor] Using time.localtime() and files

Kalle Svensson kalle@lysator.liu.se
Fri, 31 May 2002 16:56:35 +0200


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Chris Avery]
> Hi!  I'm writin a script that writes the date, user, and change that
> that person did to a file called CHANGELOG.  This is for a school
> machine with many student admins.  I need the file to look like
> this:
> YYYY-MM-DD	user
> 	* change
> 
> I know that I need to use time.localtime() and pickle, but I can't
> get the date to write to the file correctly.

I don't understand what you're using pickle for here.  The easiest way
would be to use time.strftime() like this:

>>> import time
>>> user = "foo"
>>> change = "bar"
>>> datestring = time.strftime("%Y-%m-%d")
>>> print "%s    %s\n    * %s" % (datestring, user, change)
2002-05-31    foo
    * bar
>>> 

More format codes for strftime are available in the time module
documentation at http://python.org/doc/current/lib/module-time.html

Perhaps I've misunderstood the problem?

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE8948bdNeA1787sd0RAhCPAKCwRPUMxNmM13p+0zJoUatG3uox2wCcCPRK
E/cZiYt6BjADApzIxRe09uA=
=hu17
-----END PGP SIGNATURE-----