为什么我在非常基本的Python脚本中得到这个错误?这个错误是什么意思?
错误:
Traceback (most recent call last):
File "cab.py", line 16, in <module>
if cab in line:
TypeError: 'in <string>' requires string as left operand, not int
脚本:
import re
import sys
#loco = sys.argv[1]
cab = 6176
fileZ = open(
我是Python的初学者,我正在编写一段代码,询问您的名字,并在程序的其余部分记住它。
print("What will you name yourself?")
name_input = input("> ")
name = name_input
print("Your name is: ") + name
错误跟踪消息是:
Traceback (most recent call last):
File "G:\#######\My Stuff\Deskemon.py", line 16, in <module>
我正在创建自己的复数类(而不是使用Python的内置类),当我试图将零添加到复数时,我遇到了一个问题。作为参考,这是一个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "display.py", line 25, in __init__
t.color(mandelbrot(c).getColor())
File "C:\Users\Joe\Desktop\Python\mandelbrot.py", line
以下是打印和计算加权考试成绩的代码:
def exam(weight,score_earned,score_shift):
if (score_shift==1):
shift_amount=input("What was the shift amount?")
score_earned=int(shift_amount+score_earned)
if (score_earned >100):
score_earned=100
print("Total points = "+st
好的,我正在创建一个vector类(数学向量,如1,3),并且我想将Vector的一个实例与int相乘。首先,我实现了__mul__方法,它工作得很好。然而,这并不能完全解决问题。
a = Vector(4,3) # Creates a vector, [4,3]
a*4 # This works fine, and prints [16,12]
4*a # This, however, creates a TypeError (Unsupported operans type(s)).
现在,这是可用的,但它可以更容易地让它在两种情况下工作。有没有办法做到这一点,在Vect
from fraction.py import *
f1 = Fraction(3,4)
f2 = Fraction(2,3)
f3 = f1 * f2
print(f3)
File "python.4", line 1, in <module>
from fraction import *
File "/home/PYTHON/examples/fraction.py", line 50, in <module>
f3= f1 * f2
TypeError: unsupported operand type(s) f
我正在编写代码,通过GUI输入索引值:
import tkinter as tk
import tkinter.messagebox
#from tkinter import *
from PIL import Image, ImageTk #To display the image of the formulas of the methods
from tkinter.filedialog import askopenfile
root3 = tk.Tk()
root3.geometry('200x300')
info2=tk.Label(root3,text=
考虑一下这个基本的node+ts代码:
import * as express from "express";
function doStuff(app: express.Application) {
if (!(app instanceof express.Application)) throw new TypeError();
// etc...
}
VSCode向我展示了...instanceof express.Application...的错误
类型‘e’上不存在ts属性'Application‘。二三三九
我做错了什么?
我想做:
x %doSomething% y
这对于任何x和任何y来说都很容易(见下面的代码),除非x是str。
是否有任何方法(例如添加特殊方法或引发特定错误)导致旧的字符串格式失败(类似于1%的TypeError失败)并恢复到doSomething对象中定义的__rmod__方法?
class BinaryMessage(object):
def __init__(self, fn):
self._fn = fn
def __rmod__(self, LHS):
return BinaryMessagePartial(self._fn, LHS)
class Bi
我定义了一个新的模数7类:
class mod7:
def __init__(self, n):
self.val = n % 7
def __repr__(self):
return str(self.val)
然后
In [2]: a = mod7(18)
In [3]: a
Out[3]: 4
我希望不仅允许添加mod7对象,还允许在新类中添加整数。所以在课堂上我增加了
def __add__(self, other):
if type(other) is int:
return
所以我想要做的是从常用的库(如子进程、shutil等)中获取一些预先存在的函数.并将它们封装在一个函数中,该函数将输出该函数正在执行的操作以及发生错误时的错误。我目前的代码看起来像这样。
def copytree(self,*args, **kwargs):
self.debug(f":- Copying tree from \"{args[0]}\" to \"{args[1]}\"")
try:
shutil.copytree(*args,**kwargs)
except Exception as e:
我有一本字典,格式是
key1: [list of number]
key2: [list of number]
等等。
密钥是一个数字,其中key1 < key2 < etc...
我正在尝试选择all the last n列表,我想要计算它。
x = 0
for something in dict:
if something >= max(dict.keys()) - n:
x += sum(dict[something]) // len(dict[something])
但我得到的是:
TypeError: unsupported oper
有一个dataframe df
它包含df.date列,键入object。案例2019-01-01
我想把这个值“T07:00:00+0000”添加到每个日期,所以我想要的输出是2019-01-01T07:00:00+0000。
我试过了
df.date + 'T07:00:00+0000', as the type of the column object
但是得到了这个错误
TypeError:不支持的操作数类型为+:'datetime.date‘和'str’
那么,如果是日期时间,让我们转换为string:
df.date.dt.strftime(
我有两个问题,其中涉及一些我认为是不正确的Javascript代码。
以下声明在Javascript中是如何解释的,为什么?
(1,2,3,4)
为什么这两个调用之间有区别:
var a = (1,2,3,4);
a();
导致a等于4和Uncaught TypeError: a is not a function被抛出,并且
(1,2,3,4)();
这导致了Uncaught TypeError: (((1 , 2) , 3) , 4) is not a function