小编Alo*_*lok的帖子

AttributeError:'tuple'对象没有属性

我是python的初学者.我无法理解问题所在?

def list_benefits():

        s1 = "More organized code"
        s2 = "More readable code"
        s3 = "Easier code reuse"
        s4 = "Allowing programmers to share and connect code together"
        return s1,s2,s3,s4

def build_sentence():

        obj=list_benefits()
        print obj.s1 + " is a benefit of functions!"
        print obj.s2 + " is a benefit of functions!"
        print obj.s3 + " is a benefit of functions!"

print build_sentence()
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Traceback (most recent call last):
   Line 15, in <module>
   print build_sentence()
   Line 11, in build_sentence
   print obj.s1 …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

27
推荐指数
4
解决办法
18万
查看次数

在使用HoughCircles和Python OpenCV时,如果缺少模块,我会收到错误

我有一个小的测试代码块试图处理一个带有球的简单照片:

#!/usr/local/bin/python
import cv2
import numpy as np

img = cv2.imread("b.jpg")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray,cv2.CV_HOUGH_GRADIENT)
Run Code Online (Sandbox Code Playgroud)

当我尝试运行时,我得到:

AttributeError:'module'对象没有属性'HOUGH_GRADIENT'

我已经安装并重新安装了两天,试图弄清楚什么是错的.任何帮助或指针将不胜感激!

python opencv

11
推荐指数
2
解决办法
2万
查看次数

为什么zipfile.is_zipfile在xlsx文件中返回True?

is_zipfile在提取它之前用它来检查它是否是一个zipfile.但该方法在StringIO对象的excel文件中返回True.我使用的是Python 2.7.有谁知道如何解决这一问题?使用可靠is_zipfiile吗?谢谢.

python excel zip python-2.7

5
推荐指数
1
解决办法
592
查看次数

索引for循环中的当前值?蟒蛇

所以我有一个for循环.

>>> row = [5, 2, 5, 4, 2, 2, 5, 5, 5, 2]
>>> for i in row:
    if i == 5:
        print(row.index(i))
    if i == 2:
        print(row.index(i))
Run Code Online (Sandbox Code Playgroud)

OUTPUT

0
1
0
1
1
0
0
0
1
Run Code Online (Sandbox Code Playgroud)

我想得到:0 1 2 4 5 6 7 8 9.换句话说,我想得到i我正在for循环中看到的索引,如果它是= 5或2 ...任何简单的方法来做到这一点?

python

3
推荐指数
1
解决办法
76
查看次数

Python(TKinter)中形状的随机填充颜色

我想知道如何从列表中获取随机颜色以在draw_rectangle()

colors = ["red", "orange", "yellow", "green", "blue", "violet"]

canvas.create_rectangle(self.x, self.y, self.x + 60, self.y + 60, fill = random.choice(colors))
Run Code Online (Sandbox Code Playgroud)

这导致我的代码崩溃,我还能尝试什么?

python random tkinter list

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×5

python-2.7 ×2

excel ×1

list ×1

opencv ×1

random ×1

tkinter ×1

zip ×1