Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44635 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-05-03 00:59 +1000 |
| Last post | 2013-05-03 00:59 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: help to code... Chris Angelico <rosuav@gmail.com> - 2013-05-03 00:59 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-03 00:59 +1000 |
| Subject | Re: help to code... |
| Message-ID | <mailman.1247.1367506746.3114.python-list@python.org> |
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
Back to top | Article view | comp.lang.python
csiph-web