0

if I have a python script as below:

import time
for i in range(10):
    print(i)
    time.sleep(60)

When it is running to count 3 now, is it possible to change to upper limit from 10 to 20?


To make it clear, I mean without stopping the running process. I want to change it to make it run to 20.

Say, maybe modify /dev/mem or /proc/pid/something ?

CSJ
  • 2,539
  • 4
  • 20
  • 29

2 Answers2

1

Another name for a for loop is fixed repetition. Fixed means that you can not change constraints.

var = 0
cap = 10

while var < cap:
    var += 1
    action()

    if var == 3:
        cap = 20
Malik Brahimi
  • 15,933
  • 5
  • 33
  • 65
0

range returns a list in Python 2, so if it's stored which can be extended.

range_list = range(10)
for i in range_list:
    print(i)
    if i == 3:
        range_list.extend(range(10,20))
    time.sleep(60)
Ismael Padilla
  • 4,666
  • 4
  • 23
  • 33
Nizam Mohamed
  • 7,594
  • 19
  • 31