python timestamp doesn't update
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
my time.ctime()
is not changing when executing my program each 5 second.
How can I fix it?
My program:
import random
import time
n = 1
future = time.time() + 600
for x in range(5): # program execute 5 times
print(n)
print time.ctime(future)
sensor1 = 'ID': 'A', 'float1': ['A' + str(i) for i in range(1, 17)]
print(sensor1)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
sensor2 = 'ID': 'B', 'float1': ['B' + str(i) for i in range(1, 17)]
print(sensor2)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
time.sleep(5) # to wait a second
n = n + 1
python timestamp
add a comment |Â
up vote
1
down vote
favorite
my time.ctime()
is not changing when executing my program each 5 second.
How can I fix it?
My program:
import random
import time
n = 1
future = time.time() + 600
for x in range(5): # program execute 5 times
print(n)
print time.ctime(future)
sensor1 = 'ID': 'A', 'float1': ['A' + str(i) for i in range(1, 17)]
print(sensor1)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
sensor2 = 'ID': 'B', 'float1': ['B' + str(i) for i in range(1, 17)]
print(sensor2)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
time.sleep(5) # to wait a second
n = n + 1
python timestamp
You are setting the value of 'future' just once, outside the loop. That's what you must fix.
â user535733
Feb 7 at 12:41
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
my time.ctime()
is not changing when executing my program each 5 second.
How can I fix it?
My program:
import random
import time
n = 1
future = time.time() + 600
for x in range(5): # program execute 5 times
print(n)
print time.ctime(future)
sensor1 = 'ID': 'A', 'float1': ['A' + str(i) for i in range(1, 17)]
print(sensor1)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
sensor2 = 'ID': 'B', 'float1': ['B' + str(i) for i in range(1, 17)]
print(sensor2)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
time.sleep(5) # to wait a second
n = n + 1
python timestamp
my time.ctime()
is not changing when executing my program each 5 second.
How can I fix it?
My program:
import random
import time
n = 1
future = time.time() + 600
for x in range(5): # program execute 5 times
print(n)
print time.ctime(future)
sensor1 = 'ID': 'A', 'float1': ['A' + str(i) for i in range(1, 17)]
print(sensor1)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
sensor2 = 'ID': 'B', 'float1': ['B' + str(i) for i in range(1, 17)]
print(sensor2)
count = 16 # represents 16 float readings
for i in range(0, count):
r = random.random() # generates random real number between 0 and 1
print(r)
time.sleep(5) # to wait a second
n = n + 1
python timestamp
python timestamp
edited Feb 7 at 12:45
![](https://i.stack.imgur.com/1MIVg.jpg?s=32&g=1)
![](https://i.stack.imgur.com/1MIVg.jpg?s=32&g=1)
Yaron
8,55271838
8,55271838
asked Feb 7 at 12:33
![](https://lh3.googleusercontent.com/-ANq2TO6L6m4/AAAAAAAAAAI/AAAAAAAAAD8/FZDVpL8Aqto/photo.jpg?sz=32)
![](https://lh3.googleusercontent.com/-ANq2TO6L6m4/AAAAAAAAAAI/AAAAAAAAAD8/FZDVpL8Aqto/photo.jpg?sz=32)
Bovarin Boukedy
61
61
You are setting the value of 'future' just once, outside the loop. That's what you must fix.
â user535733
Feb 7 at 12:41
add a comment |Â
You are setting the value of 'future' just once, outside the loop. That's what you must fix.
â user535733
Feb 7 at 12:41
You are setting the value of 'future' just once, outside the loop. That's what you must fix.
â user535733
Feb 7 at 12:41
You are setting the value of 'future' just once, outside the loop. That's what you must fix.
â user535733
Feb 7 at 12:41
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Your problem is that you set a fixed value future, and you are using the same fixed value again and again.
You can print the current time using:
print time.ctime()
You can print the current time + 600 using:
print time.ctime(time.time() + 600)
python time manual specify:
time.ctime([secs])
Convert a time expressed in seconds since the epoch to a string
representing local time. If secs is not provided or None, the current
time as returned bytime()
is used.ctime(secs)
is equivalent to
asctime(localtime(secs))
. Locale information is not used byctime()
.
Example Code (e.g. saved as time_prints.py
):
import time
for x in range(5): # program execute 5 times
print time.ctime()
time.sleep(5)
Example output:
$ python time_prints.py
Thu Feb 8 14:37:41 2018
Thu Feb 8 14:37:46 2018
Thu Feb 8 14:37:51 2018
Thu Feb 8 14:37:56 2018
Thu Feb 8 14:38:01 2018
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Your problem is that you set a fixed value future, and you are using the same fixed value again and again.
You can print the current time using:
print time.ctime()
You can print the current time + 600 using:
print time.ctime(time.time() + 600)
python time manual specify:
time.ctime([secs])
Convert a time expressed in seconds since the epoch to a string
representing local time. If secs is not provided or None, the current
time as returned bytime()
is used.ctime(secs)
is equivalent to
asctime(localtime(secs))
. Locale information is not used byctime()
.
Example Code (e.g. saved as time_prints.py
):
import time
for x in range(5): # program execute 5 times
print time.ctime()
time.sleep(5)
Example output:
$ python time_prints.py
Thu Feb 8 14:37:41 2018
Thu Feb 8 14:37:46 2018
Thu Feb 8 14:37:51 2018
Thu Feb 8 14:37:56 2018
Thu Feb 8 14:38:01 2018
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
add a comment |Â
up vote
0
down vote
Your problem is that you set a fixed value future, and you are using the same fixed value again and again.
You can print the current time using:
print time.ctime()
You can print the current time + 600 using:
print time.ctime(time.time() + 600)
python time manual specify:
time.ctime([secs])
Convert a time expressed in seconds since the epoch to a string
representing local time. If secs is not provided or None, the current
time as returned bytime()
is used.ctime(secs)
is equivalent to
asctime(localtime(secs))
. Locale information is not used byctime()
.
Example Code (e.g. saved as time_prints.py
):
import time
for x in range(5): # program execute 5 times
print time.ctime()
time.sleep(5)
Example output:
$ python time_prints.py
Thu Feb 8 14:37:41 2018
Thu Feb 8 14:37:46 2018
Thu Feb 8 14:37:51 2018
Thu Feb 8 14:37:56 2018
Thu Feb 8 14:38:01 2018
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Your problem is that you set a fixed value future, and you are using the same fixed value again and again.
You can print the current time using:
print time.ctime()
You can print the current time + 600 using:
print time.ctime(time.time() + 600)
python time manual specify:
time.ctime([secs])
Convert a time expressed in seconds since the epoch to a string
representing local time. If secs is not provided or None, the current
time as returned bytime()
is used.ctime(secs)
is equivalent to
asctime(localtime(secs))
. Locale information is not used byctime()
.
Example Code (e.g. saved as time_prints.py
):
import time
for x in range(5): # program execute 5 times
print time.ctime()
time.sleep(5)
Example output:
$ python time_prints.py
Thu Feb 8 14:37:41 2018
Thu Feb 8 14:37:46 2018
Thu Feb 8 14:37:51 2018
Thu Feb 8 14:37:56 2018
Thu Feb 8 14:38:01 2018
Your problem is that you set a fixed value future, and you are using the same fixed value again and again.
You can print the current time using:
print time.ctime()
You can print the current time + 600 using:
print time.ctime(time.time() + 600)
python time manual specify:
time.ctime([secs])
Convert a time expressed in seconds since the epoch to a string
representing local time. If secs is not provided or None, the current
time as returned bytime()
is used.ctime(secs)
is equivalent to
asctime(localtime(secs))
. Locale information is not used byctime()
.
Example Code (e.g. saved as time_prints.py
):
import time
for x in range(5): # program execute 5 times
print time.ctime()
time.sleep(5)
Example output:
$ python time_prints.py
Thu Feb 8 14:37:41 2018
Thu Feb 8 14:37:46 2018
Thu Feb 8 14:37:51 2018
Thu Feb 8 14:37:56 2018
Thu Feb 8 14:38:01 2018
edited Feb 8 at 12:40
answered Feb 7 at 12:43
![](https://i.stack.imgur.com/1MIVg.jpg?s=32&g=1)
![](https://i.stack.imgur.com/1MIVg.jpg?s=32&g=1)
Yaron
8,55271838
8,55271838
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
add a comment |Â
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
ok, but I am still getting a fix time in the loop. I want it to be different each five minute as timesleep (5) second. could you help me to get a good code, please.
â Bovarin Boukedy
Feb 8 at 11:36
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - updated my answer with an example code + output
â Yaron
Feb 8 at 12:40
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
@BovarinBoukedy - did I answer your question?
â Yaron
Feb 9 at 13:50
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1003878%2fpython-timestamp-doesnt-update%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You are setting the value of 'future' just once, outside the loop. That's what you must fix.
â user535733
Feb 7 at 12:41