【发布时间】:2021-12-26 16:47:15
【问题描述】:
下面的while循环意味着永远重复(因此i=0从未在循环内修改)。循环有一个checkpoint,所以每一个读取行都会从它停止的地方继续。
但是检查点不起作用,有什么办法可以解决这个问题吗?好的,除非完成,否则我不会修改 i var(这是一个很大的建议),因此它会重复,恢复检查点,并写入数据,重复。但是我想说的是检查点被破坏了,程序在读取完所有文件后不会结束。
代码
i = 0
while i == 0:
file1 = open('APPMAKE', 'r')
Lines = file1.readlines()
count = 0
checkpoint = 0
ccount = 1
modeset = 0
# Strips the newline character
for line in Lines:
count += 1
ccount += 1
modeset += 1
if ccount > checkpoint:
checkpoint += 1
if modeset > 2:
modeset == 1
if modeset == 1:
elfexecutable = line
if modeset == 2:
appname = line
checkpoint = count + 1
break
#writing data
file1.close()
file2 = open(appname + ".app", "a") # append mode
file2.write(elfexecutable + "\n")
file2.close()
我把这个放在APPMAKE文件中测试:
elf.elf
ap.app
elf.elf
ap.app
elf.elf
ap.app
elf.elf
ap.app
哦,我制作了一个手册来使用这个 Python 脚本。这可能帮助你理解它:
APP MAKE INSTRUCTIONS
=====================
First, to generate app, create a APPMAKE file. Next, add repeated code scripts
that are like this:
[elf file to link to]
[app file name]
...
Then, you made a APPMAKE file! To make more configs, list more of the scripts above.
Remember yo replace the things in the []s! Also, you can make a app run more than
1 elf you can make more than 1 configuration for each file. Now, how do you
run a APPMAKE file? Well first go copy & paste (do this sentence if your project is
not a template) the elfexepreferences.sh file into the folder with the
APPMAKE file. (do this even if your project is a template -->) Now, edit the file
you just pasted and edit the part that looks like this:
elfexecute () {
[function to execute elf] $1
}
Edit the []s depending on what system your apps are running on. (the elf
exepreferences file needs to be in every dir with a APPMAKE file.) And, getting close
to finished, copy and paste the elfexecuter.sh to your programs's main dir if it is
not already there. Then, in the same dir as the elfexecuter.sh file, add a
appexecute file and add a list of the APP files. Now, wanna make an app? To
execute the APPMAKE file, copy and paste appmake.py to the same dir
as the programs if it is not already there. Execute it and your app is
compiled. NOTICE: appexecute conatins names of .app files! Add the extensions!
So, I obeyed with my manual and tested the first few steps and got this to repeat and write a ENDLESS amount of elf.elf to my app file! Can someone please help!
我的新编辑,但它仍然不起作用:
checkpoint = 0
i = 5
while i == 5:
file1 = open('APPMAKE', 'r')
Lines = file1.readlines()
count = 0
ccount = 0
modeset = 0
# Strips the newline character
for line in Lines:
count += 1
ccount += 1
modeset += 1
if modeset > 2:
modeset == 1
if ccount > checkpoint:
checkpoint += 1
if modeset == 1:
elfexecutable = line
if modeset == 2:
appname = line
checkpoint = count + 1
break
#writing data
file1.close()
file2 = open(appname + ".app", "a") # append mode
file2.write(elfexecutable + "\n")
file2.close()
SOO,以上是我最新的编辑,但它仍然无法正常工作!任何帮助表示赞赏。我听取了新编辑的所有建议。
【问题讨论】:
-
为什么有
i = 0和while 循环?好像没有办法退出。 -
哦,等等,它意味着永远重复,它有一个“检查点”,所以每一个读取的行都会从它停止的地方继续。有什么办法可以解决吗?抱歉,不太清楚。
-
等等,所以你想要它永远重复吗?那有什么问题呢?请描述您的输出与您想要的有何不同。
-
检查点在每个循环开始时不断重置为 0,为什么不一次解析所有字符串并每两行处理一次呢?
if modeset > 2中的modeset == 1也不会将其设置回 1。 -
好的,谢谢大家的帮助!!但是,我仍然有这个问题,我把代码换成了这个:(看帖子。)
标签: python infinite-loop