Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44639
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'causing': 0.04; 'syntax': 0.04; 'subject:help': 0.08; 'lawrence': 0.09; 'python': 0.11; 'wrote': 0.14; "'/'": 0.16; 'delimiters': 0.16; 'formatted': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'line),': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'messy': 0.16; 'printing.': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'strftime': 0.16; 'syntaxerror:': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'community,': 0.19; 'thu,': 0.19; '>>>': 0.22; 'import': 0.22; 'putting': 0.22; 'separate': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'first,': 0.26; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'skip:p 30': 0.29; 'strongly': 0.30; 'code': 0.31; 'getting': 0.31; 'easier': 0.31; 'lines': 0.31; 'url:python': 0.33; 'could': 0.34; 'received:84': 0.35; 'but': 0.35; 'really': 0.36; 'doing': 0.36; 'url:org': 0.36; 'error.': 0.37; 'two': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; "you're": 0.61; 'first': 0.61; 'complete': 0.62; 'dear': 0.65; 'charset:windows-1252': 0.65; 'american': 0.66; 'header:Reply-To:1': 0.67; 'invalid': 0.68; 'line,': 0.68; 'reply-to:no real name:2**0': 0.71; "it'd": 0.84; 'nice,': 0.84; 'reply-to:addr:python.org': 0.84; '2013': 0.98 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=JsTI8qIC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=7AxPfEIvyrUA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=N659UExz7-8A:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=kXPjS0m1utAA:10 a=v3ZZPjhaAAAA:8 a=CxjpaS-67VgKDugGmeUA:9 a=pILNOxqGKmIA:10 a=BMLu5zkXfFwA:10 a=Kna09Q1u_EMA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Thu, 02 May 2013 16:37:06 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: help to code... |
| References | <1F2E5209-2F0F-4DE2-88BC-DB9C2267B0F3@icloud.com> <CAPTjJmpvAmG_wFnz-6OWELi6C8cYj-2Cgmn_GyR=BsC4=aD1SQ@mail.gmail.com> <klu0io$vss$1@ger.gmane.org> |
| In-Reply-To | <klu0io$vss$1@ger.gmane.org> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1251.1367509015.3114.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1367509015 news.xs4all.nl 15922 [2001:888:2000:d::a6]:34968 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44639 |
Show key headers only | View raw
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 <l.selmi@icloud.com> 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,current_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.minute,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/datetime.html#strftime-and-strptime-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'))
:-)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: help to code... MRAB <python@mrabarnett.plus.com> - 2013-05-02 16:37 +0100
csiph-web