首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析4时Python意外EOF

解析4时Python意外EOF
EN

Stack Overflow用户
提问于 2013-12-10 19:33:25
回答 1查看 267关注 0票数 0

所以,我现在正在做图像解析,并且经历了很糟糕的一段时间。

这是我的密码:

代码语言:javascript
复制
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])

这是我的职责:

代码语言:javascript
复制
# 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()

这个问题在节目结束时就出现了,我已经摆弄了很久了。请帮帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-10 19:36:58

在最后一次调用drawing.draw_box时,您的括号没有关闭。因此,在查找函数调用的末尾时,它正在命中文件的末尾。

另外,传递的第二个值未关闭,float(splitstring[1] <--

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20503584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档