从文档中可以看出,它include指定了要包含在程序中(即在编译过程中)的文件名或模式数组。同样,rootDir是包含要包含在编译过程中的应用程序源代码的文件夹的路径。
"include": ["./src/"],
"exclude": ["node_modules/*", "test/*"],
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"rootDir": "./src",
"outDir": "./dist/",
}
Run Code Online (Sandbox Code Playgroud)
那他们有什么区别呢?
我试图弄清楚如何制作迭代器,下面是一个工作正常的迭代器.
class DoubleIt:
def __init__(self):
self.start = 1
def __iter__(self):
self.max = 10
return self
def __next__(self):
if self.start < self.max:
self.start *= 2
return self.start
else:
raise StopIteration
obj = DoubleIt()
i = iter(obj)
print(next(i))
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将16传递给iter()中的第二个参数时(我希望迭代器在返回16时停止)
i = iter(DoubleIt(), 16)
print(next(i))
Run Code Online (Sandbox Code Playgroud)
它抛出TypeError:iter(v,w):v必须是可调用的因此,我尝试这样做.
i = iter(DoubleIt, 16)
print(next(i))
Run Code Online (Sandbox Code Playgroud)
它返回< main .DoubleIt对象0x7f4dcd4459e8>.这不是我的预期.我检查了programiz的网站,https://www.programiz.com/python-programming/methods/built-in/iter 其中说可调用对象必须在第一个参数中传递,以便使用第二个参数,但它未提及可以在其中传递用户定义的对象以使用第二个参数.
所以我的问题是,有没有办法这样做?第二个参数可以与"自定义对象"一起使用吗?
I was told that if an obj's __str__ method isn't created but __repr__ is created then printing the obj will invoke __repr__. That appears to be true for normal class, but when I try it on Exception's subclass, it is weird that __repr__ doesn't get invoked, could anyone explain why?
Here's an example
class BoringError(Exception):
def __init__(self):
self.purpose = "Demonstration"
self.boringLevel = 10
def __repr__(self):
return "I'm a message for developer"
try:
if 1 != 2:
raise BoringError
except …Run Code Online (Sandbox Code Playgroud) 有谁知道为什么我们可以在此处(在subsetOf方法中)遍历“ this”关键字?据我所知,这表示一个JAVA对象。欢迎进行一些广泛的解释,以了解为什么“ this”可以这种方式工作。
public class ArrayListSet<E> implements Set<E> {
private ArrayList<E> elements;
public ArrayListSet() {
elements = new ArrayList<>();
}
@Override
public void add(E e) {
if (!elements.contains(e))
elements.add(e);
}
@Override
public void remove(E e) {
elements.remove(e);
}
@Override
public boolean contains(Object e) {
return elements.contains(e);
}
@Override
public int size() {
return elements.size();
}
@Override
public boolean subsetOf(Set<?> other) {
for (E e : this) {
if (!other.contains(e))
return false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)