1

I am creating a program for Raspberry Pi where, in Command Line, the program displays the date and time as shown below and I want to add a repeat or update so the date and time are current after the program begins. This code came off a online tutorial and I want to mess around with it and hit a dead end. I am currently learning Python.

#!/usr/bin/python

import time
now = time.strftime("%c")
print "current date and time " + time.strftime("%c")
WickedJDG
  • 21
  • 1
  • 8

3 Answers3

2

The following code will print time in the same place every second:

import time

while True:
    time.sleep(1.0)
    print("\r" + str(time.time()), end="")
mirosval
  • 6,671
  • 3
  • 32
  • 46
0

You could use datetime module:

import datetime
datetime.datetime.now()

In [5]: datetime.datetime.now()
Out[5]: datetime.datetime(2015, 12, 11, 11, 0, 37, 518511)

EDIT

Try to use following script

#!/usr/bin/python
import datetime
import time

a = datetime.datetime.now()
time.sleep(1)
b = datetime.datetime.now()
print(b-a)
Anton Protopopov
  • 30,354
  • 12
  • 88
  • 93
0

I think this has been answered before here:

You can use a trailing comma to avoid a newline being printed:

print "this should be",
print "on the same line"
Community
  • 1
  • 1
Johannes Jander
  • 4,974
  • 2
  • 31
  • 46