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,709
  • 4
  • 24
  • 30

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
  • 16,341
  • 7
  • 39
  • 70
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
  • 5,246
  • 4
  • 23
  • 35
Nizam Mohamed
  • 8,751
  • 24
  • 32