Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'historically': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; 'arithmetic.': 0.16; 'did:': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'peters': 0.16; 'sender:addr:gmail.com': 0.17; 'module': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'subject:time': 0.33; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'became': 0.64; 'to:addr:gmail.com': 0.65; 'world': 0.66; 'direct': 0.67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=TTDdAFY8ffFEs5iuiBlu864/Mc6cyW6ArvyAgTXIUME=; b=RQgsGp5uDTgApUf1TOEZiF9sB8ynJEh8+LbJOHzRIIJUSUXx57GaBXIoxFmJpQt+Dp JxS2P7saLO73SzoHXOQ/9K9oC28A+ziuLCw4Iuba4TOjHKu/utK525u8m5EDXhGjzIKS mmkphJ80c8tc1Rs6noPlu8KfS4o4SWIUKdS9G4XsrNR6a9ycmhylTERejHGijQ+5D9Vx 4sIPuBPB+8Tj+PDT6SUd3LL+Wod6+nvezMDBFeSPWMOygZ8NQ3lzqv4JRaEGC+bxCfgj 49UqoJHc3z3CHE5s/rlVHIN4qjSLe57IMMo4mAP1/UKHpXtOF/skory52xhdoVTWFiKP egHA== MIME-Version: 1.0 X-Received: by 10.58.248.40 with SMTP id yj8mr2894793vec.40.1375963411823; Thu, 08 Aug 2013 05:03:31 -0700 (PDT) Sender: skip.montanaro@gmail.com In-Reply-To: <32a94a22-107c-4575-8808-d9355d635e83@googlegroups.com> References: <07f6b1c7-069d-458b-a9fe-ff30c09f2f2d@googlegroups.com> <32a94a22-107c-4575-8808-d9355d635e83@googlegroups.com> Date: Thu, 8 Aug 2013 07:03:31 -0500 X-Google-Sender-Auth: -DHQLCs6oUraqpP4QeAFPFJrthM Subject: Re: outputting time in microseconds or milliseconds From: Skip Montanaro To: matt.doolittle33@gmail.com Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375963829 news.xs4all.nl 15910 [2001:888:2000:d::a6]:58892 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52193 > i did: > > from time import strftime, time > from datetime import datetime > > now = datetime.now() > > self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) > self.logfile.write('%s\t'%(now.strftime("%H:%M:%S.%f",))) Note that you don't need the time module here. Datetime objects have what you need all by themselves: from datetime import datetime now = datetime.now() self.logfile.write('%s\t%s\n' % (now.strftime("%Y-%m-%d"), now.strftime("%H:%M:%S.%f"))) The time module was historically the way Python did time, but it wasn't at all object-oriented and provided no direct support for date arithmetic. When Tim Peters wrote datetime, the world became a better place. Cozy up to the datetime documentation and put the time module aside. Skip Skip