我该如何解决这个问题:TypeError:/:'tuple'和'float'的不支持的操作数类型?

时间:2016-01-14 12:28:59

标签: python typeerror

我正在尝试使用行值来获取C_vel值。

代码:

wb = op.load_workbook('Canopy\Scripts\De Velliers.xlsx')
ws = wb ['Sheet1']                         
for row in ws.rows:
    for cell in row:
        print(cell.value)
        print "----------"
        C_vel = ws.rows / (A_c * rho)
        print "C_vel: ", C_vel

错误消息:

TypeError                      
Traceback (most recent call last)
C:\Users\Fraixxer Fraiz\Canopy\scripts\franis 1.py in <module>()
     26         print(cell.value)
     27         print "----------"
---> 28         C_vel = ws.rows / (A_c * rho)
     29         print "C_vel: ", C_vel
     30 

TypeError: unsupported operand type(s) for /: 'tuple' and 'float' 

1 个答案:

答案 0 :(得分:1)

你不能对元组进行数学运算。使用numpy,您可以先将元组转换为数组。可以在numpy数组上执行数学运算。

    import numpy as np
    wb = op. load _ workbook ('Canopy\Scripts\De Velliers.xlsx')
    ws = wb ['Sheet1']                            
    for row in ws . rows:
        for cell in row:
            print(cell. value)
            print "----------"
            C_vel = np.array(ws. rows)/ (A_c * rho)
            print "C_vel:",C_vel