我想在javascript中创建一个Date对象,它表示0001年,2014年前.
我试过了
d = new Date(); d.setYear(1);
console.log(d);
Run Code Online (Sandbox Code Playgroud)
但它给了1901年
同
d = new Date(1,1,1)
console.log(d);
Run Code Online (Sandbox Code Playgroud)
没门.
我该如何创建这个日期?
我有一个GraphQL查询.我不明白为什么它不起作用.
{
repositoryOwner(login: "Naramsim") {
login
repositories(first: 3, isFork: true, orderBy: {field: CREATED_AT}) {
edges {
node {
description
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Python 2中,有两种方法可以调用从父类继承的方法。with superwhere 明确表明这些方法来自父类,而没有super.
class Parent(object):
def greet(self):
print('Hello from Parent')
class Child(Parent):
def __init__(self):
super(Child, self).__init__()
def hello(self):
print('Hello from Child')
self.greet()
super(Child, self).greet()
child = Child()
child.hello()
Run Code Online (Sandbox Code Playgroud)
输出:
Hello from Child
Hello from Parent
Hello from Parent
Run Code Online (Sandbox Code Playgroud)
哪一个是首选?我看到社区建议通过 进行调用super,但如果没有 super ,调用会更加简洁。
该问题仅适用于 Python 2。
我遇到一个问题,我似乎无法在我的 React 前端显示神奇宝贝图像,这是 api: https: //pokeapi.co/
import React, { Component } from 'react';
class Card extends Component {
state = {
name: "",
imageUrl: "",
pokemonIndex: "",
}
componentDidMount() {
const {name, url} = this.props;
const pokemonIndex = url.split('/')[url.split('/').length - 2];
const imageUrl = `http://pokeapi.co/media/sprites/pokemon/${pokemonIndex}.png`
this.setState({name, imageUrl, pokemonIndex})
}
render() {
return (
<div className="card" >
<img src= {this.state.imageUrl}/>
<h3> {this.state.name} </h3>
</div>
);
}
}
export default Card;Run Code Online (Sandbox Code Playgroud)
假设我得到了:
first_var = 1
second_var = 5
interval = 2
Run Code Online (Sandbox Code Playgroud)
我想要一个second_var的间隔second_var ± interval(从3到7).我想知道first_var是否在那段时间内.所以在这种特殊情况下,我想要,False
如果first_var = 4,我想要True
我可以做这个:
if (first_var > second_var-interval) and (first_var < second_var+interval):
#True
Run Code Online (Sandbox Code Playgroud)
是否有更多的pythonic方式来做到这一点?
在 Docker Compose 中,有没有办法用自己的 CPU 创建容器?我不希望他们共享我分配给他们的 CPU。
假设我允许 Docker 访问 3 个 CPU:我希望我的三个容器中的每一个都有自己的 CPU。
是否可以?
谢谢
python ×2
coding-style ×1
cpu ×1
date ×1
datetime ×1
docker ×1
github ×1
graphql ×1
inheritance ×1
intervals ×1
javascript ×1
pokeapi ×1
python-2.7 ×1
range ×1
reactjs ×1