当我运行main或eqparse文件时,python终端不会显示任何输出,这既适用于命令提示符,也适用于visual studio代码。
这是我在主文件中的代码。为了以防万一,我包含了一些可能不相关的东西。它被标记了,这样你就可以跳过所有可能不相关的东西。
from graphics import *
from eqparse import *
# NOTE: For equation mapping, it will input a string and convert the data to a table.
# After, you take in the table coords and map each point
# dump vars here #
xypm = 0
global patternFind
global count
global indexlist
# profile initialization #
def init(name, nxsize, nysize, noffset, nzoom):
global zoom
zoom = nzoom
global xsize
xsize = nxsize
global eqtype
eqtype = bool(1)
global ysize
ysize = nysize
global win
win = GraphWin(name, nxsize, nysize)
global offset
offset = noffset
global xymark
xymark = (nzoom * -1)/2
global txsize
txsize = nxsize/2
global tysize
tysize = nysize/2
global txymark
txymark = xymark * -1 + 1
global xp1
xp1 = Point(xypm,(txsize) + offset)
global yp1
yp1 = Point((tysize) + offset, xypm)
global xp2
xp2 = Point(xypm,(txsize) - offset)
global yp2
yp2 = Point((tysize) - offset, xypm)
# starting procedure #
def startUp():
# xy lines #
global xymark
global xp1
global xp2
global yp1
global yp2
global xypm
xtrace = Line(Point(0,tysize), Point(xsize,tysize))
ytrace = Line(Point(txsize,0), Point(txsize,ysize))
xtrace.draw(win)
ytrace.draw(win)
# grid drawer #
while xymark < txymark:
txline = Line(xp1, xp2)
tyline = Line(yp1, yp2)
txline.draw(win)
tyline.draw(win)
xypm = xypm + xsize/zoom
xp1 = Point(xypm,(tysize) + offset)
yp1 = Point((txsize) + offset, xypm)
xp2 = Point(xypm,(tysize) - offset)
yp2 = Point((txsize) - offset, xypm)
xymark = xymark + 1
# code for ending mark #
Line(Point(txsize - offset, ysize - 1), Point(txsize + offset, ysize - 1)).draw(win)
Line(Point(xsize - 1,tysize - offset), Point(xsize - 1, tysize + offset)).draw(win)
# point drawing #
def drawCo(nx, ny):
pCircle = Circle(Point(xsize/zoom * (nx) + xsize/2, ysize - (ysize/zoom * (ny) + ysize/2)), 3)
pCircle.setFill("black")
pCircle.draw(win)
# main #
print("Checkpoint 1")
init("test",500, 500, 10, 20)
print("Checkpoint 2")
startUp()
print("Checkpoint 3")
drawCo(3,5)
print("Checkpoint 4")
patternFind("Dung","DungBeatlesbeingadungbeetle")
print("Checkpoint 5")
print(count)
print("Checkpoint 6")
for x in range(len(indexlist)):
print(indexlist[x])
print("Checkpoint 7")
# exit function #
win.getMouse()
win.close()
以及eqparse文件:
# eqparse will look for certain patterns in strings, generate an equation,
# and create a table that a drawing function can read
from main import *
global indexlist
global count
global patternFind
global convStr
# convert string to valid equation data
def convStr(input):
if input[0] == 'y':
print("Linear")
elif input[0] == 'r':
print("Polar")
else:
print("Use Equation type on left side")
# subroutine that will be used to find patterns in a sequence #
def patternFind(pattern, input):
indexlist = []
count = 0
l = len(pattern)
tstr =""
if l > len(input):
pass
else:
i = 0
j = len(input) - len(pattern) + 1
k=0
while j > 0:
tstr = ""
i=0
while len(tstr) < l:
tstr = tstr + input[i + k]
i = i + 1
if tstr == pattern:
count = count + 1
indexlist.append(i+k)
else:
continue
j = j - 1
k=k+1
运行main时的输出:
Checkpoint 1
Checkpoint 2
Checkpoint 3
Checkpoint 4
(also the window that I run lags out)
与此相关的是:当我使用标准的import语法时,什么也没发生。我必须使用from(file)import * 才能让它工作。
1条答案
按热度按时间d7v8vwbk1#
您的问题在
def patternFind()
中在第二个while循环中,计数器
k
和j
永远不会增加,所以你有一个无限循环。您的代码永远不会超出
continue
语句并永远停留在那里。但是也许你可以用一个python内置函数来代替整个函数: