Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: help to code...

Reply
Thread Tools

Re: help to code...

 
 
MRAB
Guest
Posts: n/a
 
      05-02-2013
On 02/05/2013 16:26, Mark Lawrence wrote:
> On 02/05/2013 15:59, Chris Angelico wrote:
>> On Thu, May 2, 2013 at 11:50 PM, leonardo selmi <(E-Mail Removed)> wrote:
>>> dear python community,
>>>
>>> i wrote the following program:
>>>
>>> print str(current_month) + '/' + str(current_day) + '/' + str(current_year)
>>> +' '+
>>> print str(current_hour) + str(current_minute) + str(current_second)
>>>
>>> SyntaxError: invalid syntax
>>>
>>> how can i write the last two lines correctly?

>>
>> You're doing two separate print statements. Either join them into one
>> (if you want it to be one line), or drop the last + on the first line,
>> which is causing your syntax error. But there's an even easier way to
>> do this: Use formatted printing.
>>
>> print("%d/%d/%d
>> %d%d%d"%(current_month,current_day,current_year,cu rrent_hour,current_minute,current_second))
>>
>> Or, since you're getting those straight from 'now':
>>
>> print("%d/%d/%d
>> %d%d%d"%(now.month,now.day,now.year,now.hour,now.m inute,now.second))
>>
>> I strongly suspect that you want to put delimiters in the time, though
>> (colons, perhaps?). It'd be really nice, by the way, if you'd avoid
>> the messy American format date with the month first; put the year
>> first and it's unambiguous!
>>
>> ChrisA
>>

>
> Better IMHO is to use strftime
> http://docs.python.org/2/library/dat...ptime-behavior
> so the complete code could be
>
> from datetime import datetime
> print(datetime.now().strftime('%m/%Y/%d %H %m %S'))
>

Except, of course, putting the year first, and using "%m" for the
minutes:

print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
HELP - HELP - HELP =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?= ASP .Net 4 03-09-2006 12:46 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments