Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44638
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'causing': 0.04; 'from:addr:yahoo.co.uk': 0.04; 'syntax': 0.04; 'subject:help': 0.08; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; "'/'": 0.16; 'delimiters': 0.16; 'formatted': 0.16; 'line),': 0.16; 'messy': 0.16; 'printing.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'strftime': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; 'community,': 0.19; 'thu,': 0.19; 'import': 0.22; 'separate': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; 'url:moin': 0.24; 'this:': 0.26; 'header:X -Complaints-To:1': 0.27; '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:wiki': 0.31; 'url:python': 0.33; 'could': 0.34; '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; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'read': 0.60; "you're": 0.61; 'first': 0.61; 'complete': 0.62; 'dear': 0.65; 'charset:windows-1252': 0.65; 'american': 0.66; 'invalid': 0.68; 'line,': 0.68; "it'd": 0.84; 'nice,': 0.84; 'received:2': 0.84; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: help to code... |
| Date | Thu, 02 May 2013 16:26:17 +0100 |
| References | <1F2E5209-2F0F-4DE2-88BC-DB9C2267B0F3@icloud.com> <CAPTjJmpvAmG_wFnz-6OWELi6C8cYj-2Cgmn_GyR=BsC4=aD1SQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | host-2-98-196-142.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| In-Reply-To | <CAPTjJmpvAmG_wFnz-6OWELi6C8cYj-2Cgmn_GyR=BsC4=aD1SQ@mail.gmail.com> |
| X-Antivirus | avast! (VPS 130502-0, 02/05/2013), Outbound message |
| X-Antivirus-Status | Clean |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| 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.1250.1367508400.3114.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1367508400 news.xs4all.nl 15977 [2001:888:2000:d::a6]:57039 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44638 |
Show key headers only | View raw
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'))
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: help to code... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-02 16:26 +0100
csiph-web