0
因此,我現在正在進行圖像解析,並且有一段糟糕的時間。Python在分析時意外的EOF 4
這是我的代碼:
import urllib.request
import turtle
import drawing
# define a location for our file
url = 'http://i5.nyu.edu/~cmk380/pythondata/'
# open a connection to the URL
response = urllib.request.urlopen(url)
# read data from URL as a string
data = response.read().decode('utf-8')
image = input('Enter an image filname:')
newurl = url+image+'.txt'
if int(image[5]) <= 0:
print('Sorry,',newurl,'doesn\'t exist.')
else:
print('Success! I was able to find ',newurl)
# define a location for our file
newurl2 = newurl
# open a connection to the URL
response = urllib.request.urlopen(newurl2)
# read data from URL as a string
data = response.read().decode('utf-8')
#obtain data
print(data)
#turn data into a string and convert to float
string = data
splitstring = string.split(',')
splitstring[0]=float(splitstring[0])
splitstring[1]=float(splitstring[1])
splitstring[2]=float(splitstring[2])
for index in range (4,len(splitstring)):
if splitstring[index] == 'b':
print('\n')
else:
drawing.draw_box(float(splitstring[0]),float(splitstring[1],float(splitstring[2]), float(splitstring[index]), float(splitstring[index]), float(splitstring[index])
這是我的函數:
# draw a box at position x, y
# width and height will be w & h
# r, g and b will be the color
def draw_box(x, y, w, h, r, g, b):
turtle.penup()
turtle.goto(x,y)
turtle.setheading(0)
turtle.pendown()
turtle.pencolor(float(r), float(g), float(b))
turtle.fillcolor(float(r),float(g),float(b))
turtle.begin_fill()
for x in range(4):
turtle.forward(w)
turtle.right(90)
turtle.end_fill()
的問題就在節目的最後出現,我一直用它擺弄的年齡。請幫忙!