您可以使用 typing.typing.typevar
typing 使用参数BOND
模拟:
from random import randint
from typing import TypeVar, Type
Self = TypeVar('Self', bound='Person')
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
@classmethod
def get_random_person(cls: Type[Self]) -> Self:
return cls("Random Guy", randint(18, 65))
class Player(Person):
pass
def welcome_player(player: Player):
print(f"Welcome {player.name}")
player: Player = Player.get_random_person()
welcome_player(player)
Python 3.11将添加 self code> self code> 但尚未正式发布。
键入 - 延迟
在较旧版本中可以访问,尽管mypy
会抱怨错误:变量“ typing_extensions.self”无效作为类型)。
from random import randint
from typing_extensions import Self
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
@classmethod
def get_random_person(cls) -> Self:
return cls("Random Guy", randint(18, 65))
class Player(Person):
pass
def welcome_player(player: Player):
print(f"Welcome {player.name}")
player = Player.get_random_person()
welcome_player(player)
改变如果event.type == pygame.quit():
到如果event.type == pygame.quit:
您可以在每个节点中添加一个onclick处理程序,然后在节点视图中单击此处理程序。
在ONCLICK处理程序中的父组件中,您可以根据需要调用PreparEnode。
useEffect(() => {
setElements(
elements.map(item => {
...item,
onClick: (i) => {
console.log(i);
prepareNode();
},
})
)},
[]);
看来,计算机中安装的spark
的版本与pyspark
的版本不匹配。
使用以下命令检查Spark的版本:
<path-to-spark-bin>/spark-submit --version
# example output
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 3.1.3
/_/
现在正如示例输出所显示的那样,已安装的Spark版本为3.1.3,因此您需要通过执行同一版本安装Spark(Pyspark)的Python库(Pyspark)以下命令:
pip install pyspark==<the-version-of-your-spark>
# Example
pip install pyspark==3.1.3
在某些国家,港口5060被ISP阻止
我了解您在虚拟机中打开了端口。
您还需要在VPS主机面板安全组中打开端口。
只需作为新用户运行任何过程。
这是新用户并关闭powershell提示的东西。
这将创建用户配置文件夹,而不会与当前会话断开您的连接。
# Name credentials
$username = 'NewUsername'
$password = 'NewProfilePassword' | ConvertTo-SecureString -AsPlainText -Force
$credential = [PSCredential]::New($username,$password)
Start-Process powershell.exe -Credential $Credential -ArgumentList "-Command","Write-host 'Hello Profile'"
问题中定义的字符串不是char **
,它是带有嵌入式新线的单个C字符串。
您可以使用简单的迭代来计算其包含的行的长度:
#include <stdio.h>
int main() {
char arr[] = "x xxxx\n" // length 9
"x xx\n" // length 4
"\n" // length 0
"x xxx\n"; // length 6
size_t i, start, line = 1;
for (i = start = 0; arr[i] != '\0'; i++) {
if (arr[i] == '\n') {
printf("The length of line %zu is %zu.\n", line, i - start);
start = i + 1;
line++;
}
}
/* special case if the last line does not end with a newline */
if (i > start) {
printf("The length of line %zu is %zu.\n", line, i - start);
}
return 0;
}
您可以使用strchr()
或strcspn()
来简化循环,该 strcspn()接受一个分隔器的字符串:
#include <stdio.h>
#include <string.h>
int main() {
char arr[] = "x xxxx\n" // length 9
"x xx\n" // length 4
"\n" // length 0
"x xxx\n"; // length 6
char *p, *start;
size_t line = 1;
for (start = arr; (p = strchr(start, '\n')) != NULL; start = p + 1) {
printf("The length of line %zu is %td.\n", line, p - start);
line++;
}
/* special case if the last line does not end with a newline */
if (*start) {
printf("The length of line %zu is %zu.\n", line, strlen(start));
}
return 0;
}
使用strcspn()
允许将特殊情况折叠到主循环中:
#include <stdio.h>
#include <string.h>
int main() {
char arr[] = "x xxxx\n" // length 9
"x xx\n" // length 4
"\n" // length 0
"x xxx\n"; // length 6
char *p = arr;
size_t line = 1;
while (*p != '\0') {
size_t len = strcspn(p, "\n");
printf("The length of line %zu is %zu.\n", line, len);
line++;
p += len + (p[len] != '\0');
}
return 0;
}
您可以根据订购(create_on desc
)在上使用在上只能产生每组的第一行(per car_id
)。然后,过滤是微不足道的。
例如:
select *
from (
select distinct on (car_id) *
from car_wash
order by car_id, created_on desc
) x
where next_clean <= now() and end_at is null
您是在通过HTTPS/SSL访问网站吗?如果没有,那可能就是问题。 Chrome不久前对Cookie处理进行了一些更改,当SharePoint发布更新以处理它们时,它破坏了通过没有SSL登录的能力。所有最新的SharePoint更新都要求该网站由SSL托管以进行FBA登录工作。
根据应用程序的部署目标,您可以考虑使用组合
传播Websocket事件:
联合收割机框架为随着时间的推移处理值提供了声明的Swift API。这些值可以代表多种异步事件。将声明的发布者结合在一起,以揭示可以随时间变化的值,并从发布者那里接收这些值。
https://develoveling.apple.apple.apple.com/documentation/combine
尝试此软件包
https://pub.dev/packages/packages/flutter_background_background
请求在后台运行,
bool hasPermissions = await FlutterBackground.hasPermissions;
然后在后台运行它背景使用
bool success = await FlutterBackground.enableBackgroundExecution();
请注意,此功能仅在Android中起作用
最好的解决方案可能是将您的listCreator()
函数用作client> client function
(您称为启动器函数
)。从listCreator()
中,您可以生成列表并将其传递到andestrator
。最后,从编排器中,将列表传递到活动
函数并运行它。
代码草图:
# inside the client function call the orchestrato
client = df.DurableOrchestrationClient(starter)
instance_id = await client.start_new("yourorchestrator", None, [1,2,3,4])
#inside orchestrator
data = context.get_input()
context.call_activity("activity", data)
问题在于,当您通过所有网格正方形进行发作时,可以通过查找播放器找到您不断发挥作用的播放器。因此,找到并移动了玩家,然后搜索带有玩家的下一个区域,因此再次移动(直到到达墙壁)。该修复程序只是在按键功能中添加返回语句。我将在此处添加一个可行的代码块。
let grid = [];
var player;
var w = 40;
var dir,
nivel = 1;
let up, down, right, left;
function setup() {
createCanvas(400, 400);
for (var i = 0; i < width / w; i++) {
grid[i] = [];
for (var j = 0; j < height / w; j++) {
grid[i][j] = new Cell(i * w, j * w, i, j);
}
}
up = createButton("⬆");
up.position(70, height + 10);
down = createButton("⬇");
down.position(70, height + 70);
right = createButton("➡");
right.position(130, height + 40);
left = createButton("⬅");
left.position(10, height + 40);
reset = createButton("RESET")
reset.position(260, height + 40)
level(nivel);
}
function draw() {
background(220);
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
grid[i][j].show();
}
}
up.mousePressed(botonUp);
down.mousePressed(botonDown);
right.mousePressed(botonRight);
left.mousePressed(botonLeft);
reset.mousePressed(resetear)
}
function resetear() {
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
grid[i][j].reset();
}
}
}
function botonUp() {
dir = 0;
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
if (grid[i][j].player) {
grid[i][j].move();
}
}
}
}
function botonRight() {
dir = 1;
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
if (grid[i][j].player) {
grid[i][j].move();
}
}
}
}
function botonDown() {
dir = 2;
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
if (grid[i][j].player) {
grid[i][j].move();
}
}
}
}
function botonLeft() {
dir = 3;
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
if (grid[i][j].player) {
grid[i][j].move();
}
}
}
}
function keyPressed() {
for (var i = 0; i < width / w; i++) {
for (var j = 0; j < height / w; j++) {
if (keyCode == 82) {
resetear();
}
if (grid[i][j].player) {
if (keyCode === UP_ARROW) {
dir = 0;
}
if (keyCode === RIGHT_ARROW) {
dir = 1;
}
if (keyCode === DOWN_ARROW) {
dir = 2;
}
if (keyCode === LEFT_ARROW) {
dir = 3;
}
grid[i][j].move();
return;
}
}
}
}
function level(n) {
for (var i = 0; i < width / w; i++) {
grid[0][i].wall = true;
grid[width / w - 1][i].wall = true;
}
for (var j = 0; j < height / w; j++) {
grid[j][0].wall = true;
grid[j][height / w - 1].wall = true;
}
if (n == 1) {
grid[4][4].caja = true;
grid[4][7].player = true;
grid[2][4].wall = true;
grid[3][5].wall = true;
grid[7][6].spot = true;
} else if (n == 2) {
}
}
class Cell {
constructor(x, y, i, j) {
this.x = x;
this.y = y;
this.i = i;
this.j = j;
this.w = w;
this.caja = false;
this.player = false;
this.wall = false;
this.spot = false;
this.time = 0;
}
show() {
if (this.caja) {
fill("brown");
stroke(57, 0, 8);
strokeWeight(3);
rect(this.x + 2.5, this.y + 2.5, w - 5, w - 5);
line(this.x + 2.5, this.y + 2.5, this.x + w - 2.5, this.y + w - 2.5);
line(this.x + w - 2.5, this.y + 2.5, this.x + 2.5, this.y + w - 2.5);
} else {
fill(255);
strokeWeight(1);
stroke(0, 50);
rect(this.x, this.y, w, w);
}
if (this.player) {
ellipseMode(CORNER);
fill(0);
circle(this.x + 3, this.y + 3, w - 6);
} else if (this.spot) {
if (this.time % 45 > 15) {
fill(104, 252, 3);
noStroke();
circle(this.x + 2, this.y + 2, w - 4);
}
} else if (this.wall) {
fill(130);
rect(this.x, this.y, w, w);
}
if (this.caja && this.spot) nivel++;
this.time++;
if (this.time == 4500) {
this.time = 0;
}
}
move() {
if (dir == 0 && !grid[this.i][this.j - 1].wall) {
if (grid[this.i][this.j - 1].caja) {
if (!grid[this.i][this.j - 2].wall && !grid[this.i][this.j - 2].caja) {
this.player = false;
grid[this.i][this.j - 1].player = true;
grid[this.i][this.j - 2].caja = true;
grid[this.i][this.j - 1].caja = false;
}
} else {
this.player = false;
grid[this.i][this.j - 1].player = true;
}
}
if (dir == 1 && !grid[this.i + 1][this.j].wall) {
if (grid[this.i + 1][this.j].caja) {
if (!grid[this.i + 2][this.j].wall && !grid[this.i + 2][this.j].caja) {
this.player = false;
grid[this.i + 1][this.j].player = true;
grid[this.i + 2][this.j].caja = true;
grid[this.i + 1][this.j].caja = false;
}
} else {
this.player = false;
grid[this.i + 1][this.j].player = true;
}
}
if (dir == 2 && !grid[this.i][this.j + 1].wall) {
if (grid[this.i][this.j + 1].caja) {
if (!grid[this.i][this.j + 2].wall && !grid[this.i][this.j + 2].caja) {
this.player = false;
grid[this.i][this.j + 1].player = true;
grid[this.i][this.j + 2].caja = true;
grid[this.i][this.j + 1].caja = false;
}
} else {
this.player = false;
grid[this.i][this.j + 1].player = true;
}
}
if (dir == 3 && !grid[this.i - 1][this.j].wall) {
if (grid[this.i - 1][this.j].caja) {
if (!grid[this.i - 2][this.j].wall && !grid[this.i - 2][this.j].caja) {
this.player = false;
grid[this.i - 1][this.j].player = true;
grid[this.i - 2][this.j].caja = true;
grid[this.i - 1][this.j].caja = false;
}
} else {
this.player = false;
grid[this.i - 1][this.j].player = true;
}
}
}
reset() {
this.caja = false;
this.player = false;
this.wall = false;
this.spot = false;
this.time = 0;
level(nivel);
}
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
我还开始了一个真正简化的新移动功能:
move() {
let m = 0;
switch(dir){
case 0: m = -1; break;
case 1: m = 1; break;
case 2: m = 1; break;
case 3: m = -1; break;
default: throw new Error("dir not 0 - 3");
}
let d = (dir == 0 || dir == 2);
if (!grid[this.i + !d * m][this.j + d * m].wall) {
if (grid[this.i + !d * m][this.j + d * m].box) {
if (!grid[this.i + !d * m * 2][this.j + d * m * 2].wall && !grid[this.i + !d * m * 2][this.j + d * m * 2].box) {
this.player = false;
grid[this.i + !d * m][this.j + d * m].player = true;
grid[this.i + !d * m * 2][this.j + d * m * 2].box = true;
grid[this.i + !d * m][this.j + d * m].box = false;
}
} else {
this.player = false;
grid[this.i + !d * m][this.j + d * m].player = true;
}
}
}
尽管我无法使盒子相撞工作。我不太了解它应该如何工作(在代码中)。
您已经回答了您的问题;)
是的,您可以。
组成一个可以存储所有输入字段状态的类,并通过
state -provider
将其公开。为了有效地这样做What-are-its-use-cases“>
copywith
可以手动编写或生成的方法。可能的方法之一是使用freezed
。You already answered your question ;)
Yes, you can.
Make a class that will store the state of all the input fields and expose it through
StateProvider
.To do it effectively you will probably need a
copyWith
method which can be written manually or generated. One of the possible approaches is to usefreezed
.Riverpod颤音:一个屏幕的多个提供商