Опубликовано pushkin в Втр, 05/01/2010 - 21:03
Просмотр конференции fido7.ru.python:
Предыдущее Следующее
Дата: 28 Apr 2020, 00:32:08
От: Vitold Sedyshev @ 2:5030/1081.102
Кому: Denis Mosko
Тема: RE: Example
--- Golden/Linux-amd64 1.2.12 2020-04-24 04:20 MSK (master)
Origin: Yo Adrian, I Did It! (c) Rocky II (2:5030/1081.102)
Предыдущее Следующее
К списку сообщений
К списку конференций
Предыдущее Следующее
Дата: 28 Apr 2020, 00:32:08
От: Vitold Sedyshev @ 2:5030/1081.102
Кому: Denis Mosko
Тема: RE: Example
DM> How to change program with BASIC's "GOSUB"-operator?
GOSUB jumps to a subroutine at the indicated label. This call is placed onto the stack. The subroutine finalizes using a RETURN command.
You may provide GOSUB equivalent on Python by function. See more on https://www.w3schools.com/python/python_functions.asp
Let's I show you how to use OOP with refactor you simple example.
```
class Application(object):
""" Program For tea-pot
"""
def __init__(self):
pass
def step1(self):
print('WHISPER DOG FOOD')
for i in range(10):
pass
#i = 5
def step2(self):
print('IS GOOD AND')
for i in range(10):
print(i)
#i = 5
def step3(self):
print('MEALY AND CHEAP.')
for i in range(10):
print(i)
#i = 5
def step4(self):
print('IT HAS LOTS OF VITAMINS,')
for i in range(10):
print(i)
#i = 5
def step5(self):
print('LOTS OF BOUNCE')
for i in range(10000000):
pass
#i = 5000000
def step6(self):
print('AND SEND YOUR DOG TO SLEEP')
for i in range(10):
print(i)
#i = 5
def run(self):
self.step1()
self.step2()
self.step3()
self.step4()
self.step5()
self.step6()
if __name__ == "__main__":
app = Application()
app.run()
```
As you can see in source below I split you code on steps and you may reuse pice of code simple by invoke ```self.stepN()``` a few times.
Or you try to broke Python virtual machine by change ```i``` variable?
I think that in that case you should make you own mutable iterator with state. But no idea why you does not use ```while``` statement.
--- Golden/Linux-amd64 1.2.12 2020-04-24 04:20 MSK (master)
Origin: Yo Adrian, I Did It! (c) Rocky II (2:5030/1081.102)
Предыдущее Следующее
К списку сообщений
К списку конференций
Последние комментарии
7 года 44 недели назад
7 года 45 недели назад
8 года 31 недели назад
8 года 49 недели назад
8 года 49 недели назад
8 года 49 недели назад
8 года 49 недели назад
8 года 49 недели назад
8 года 49 недели назад
9 года 1 неделя назад