python timestamp doesn't update

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








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









share|improve this question























  • You are setting the value of 'future' just once, outside the loop. That's what you must fix.
    – user535733
    Feb 7 at 12:41















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









share|improve this question























  • You are setting the value of 'future' just once, outside the loop. That's what you must fix.
    – user535733
    Feb 7 at 12:41













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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 7 at 12:45









Yaron

8,55271838




8,55271838










asked Feb 7 at 12:33









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

















  • 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











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 by time() is used. ctime(secs) is equivalent to
asctime(localtime(secs)). Locale information is not used by ctime().





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





share|improve this answer






















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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 by time() is used. ctime(secs) is equivalent to
asctime(localtime(secs)). Locale information is not used by ctime().





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





share|improve this answer






















  • 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














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 by time() is used. ctime(secs) is equivalent to
asctime(localtime(secs)). Locale information is not used by ctime().





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





share|improve this answer






















  • 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












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 by time() is used. ctime(secs) is equivalent to
asctime(localtime(secs)). Locale information is not used by ctime().





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





share|improve this answer














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 by time() is used. ctime(secs) is equivalent to
asctime(localtime(secs)). Locale information is not used by ctime().





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






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 8 at 12:40

























answered Feb 7 at 12:43









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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491