我正在使用此代码:
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(myusername, mypassword)
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
result, data = mail.search(None, "ALL")
ids = data[0] # data is a list.
id_list = ids.split() # ids is a space separated string
latest_email_id = id_list[-1] # get the latest
result, data = mail.fetch(latest_email_id, "(RFC822)") # fetch the email body (RFC822) for the given ID
raw_email = data[0][1] # here's the body, which is raw text of …Run Code Online (Sandbox Code Playgroud) 我知道有关于此的其他帖子,但我的运动系统与我找到的有点不同,所以随后我问这个问题.
我的移动系统基于一个名为的元组,Move(up,left,right,down)
然后就是:
def update(self, move, blocks):
# check if we can jump
if move.up and self.on_ground:
self.yvel -= self.jump_speed
# simple left/right movement
if move.left:
self.xvel = -self.move_speed
if move.right:
self.xvel = self.move_speed
# if in the air, fall down
if not self.on_ground:
self.yvel += 0.3
# but not too fast
if self.yvel > max_gravity: self.yvel = max_gravity
# if no left/right movement, x speed is 0, of course
if not (move.left or move.right):
self.xvel = 0
# …Run Code Online (Sandbox Code Playgroud) 我不知道我是否遗漏了什么,但我似乎无法弄清楚如何进行这项工作,并且无法在网上找到答案。
假设我有两个类,A 类和 B 类。(存储在单独的文件中)
A 类有一个函数setName(),它在 A 类对象中设置一个变量。
B 类有一个函数setOtherName()来设置 A 类对象名称的值。
所以我像这样设置setOtherName():
void setOtherName(ClassA& cla)
{
*cla.setName("foobar");
}
Run Code Online (Sandbox Code Playgroud)
然后我的主脚本看起来像这样:
Class A burger;
Class B fries;
fries.setOtherName(*burger);
Run Code Online (Sandbox Code Playgroud)
这在我的原始脚本中不起作用,我收到以下错误:
error: no matching function for call to 'ClassB::setOtherName(ClassA*&)
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!(抱歉有任何混淆)
实际代码:main.cpp:
#include <iostream>
#include "quests.h"
#include "player.h"
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
quests GameQuests;
player Player;
GameQuests.quest1(Player);
Player.main();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
quests.cpp:
#include "quests.h"
#include "player.h"
#include <iostream>
#include <string>
#include …Run Code Online (Sandbox Code Playgroud) 我可能对Flask会话的工作原理不太了解,但我正在尝试使用带有授权代码流的SpotiPY生成 Spotify API 访问令牌,并将其存储在 Flask 的会话存储中。
该程序似乎无法存储它,因此稍后在尝试调用它时遇到错误。这是带有图像和标题的视觉解释:https : //imgur.com/a/KiYZFiQ
这是主要的服务器脚本:
from flask import Flask, render_template, redirect, request, session, make_response,session,redirect
import spotipy
import spotipy.util as util
from credentz import *
app = Flask(__name__)
app.secret_key = SSK
@app.route("/")
def verify():
session.clear()
session['toke'] = util.prompt_for_user_token("", scope='playlist-modify-private,playlist-modify-public,user-top-read', client_id=CLI_ID, client_secret=CLI_SEC, redirect_uri="http://127.0.0.1:5000/index")
return redirect("/index")
@app.route("/index")
def index():
return render_template("index.html")
@app.route("/go", methods=['POST'])
def go():
data=request.form
sp = spotipy.Spotify(auth=session['toke'])
response = sp.current_user_top_artists(limit=data['num_tracks'], time_range=data['time_range'])
return render_template("results.html",data=data)
if __name__ == "__main__":
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
这是两个 html 文件: …
所以我在pygame中编写了一个小平台游戏,在那里你可以放置块并在其中跳转它们.但是,游戏仅限于窗口的边界(显然).那么我怎么能添加一个用A和D键滚动"相机"的方法呢?
这是游戏的代码:
import pygame,random
from pygame.locals import *
from collections import namedtuple
pygame.init()
clock=pygame.time.Clock()
screen=pygame.display.set_mode((640,480))
pygame.display.set_caption("PiBlocks | By Sam Tubb")
max_gravity = 100
blocksel="texture\\dirt.png"
curs = pygame.image.load("texture\\cursor.png").convert()
curs.set_colorkey((0,255,0))
class Block(object):
def __init__(self,x,y,sprite):
self.sprite = pygame.image.load(sprite).convert_alpha()
self.rect = self.sprite.get_rect(centery=y, centerx=x)
class Player(object):
sprite = pygame.image.load("texture\\playr.png").convert()
sprite.set_colorkey((0,255,0))
def __init__(self, x, y):
self.rect = self.sprite.get_rect(centery=y, centerx=x)
# indicates that we are standing on the ground
# and thus are "allowed" to jump
self.on_ground = True
self.xvel = 0
self.yvel = 0
self.jump_speed = …Run Code Online (Sandbox Code Playgroud) 我正在制作一个小平台游戏,你可以在其中放置块来制作关卡,然后播放它.
我有重力,跳跃,左右移动..但我不知道如何让玩家在向左或向右移动时与墙壁碰撞.
我想要它的工作方式是这样的 -
if key[K_LEFT]:
if not block to the left:
move to the left
我将如何做到这一点(相对于这个来源):
import pygame,random
from pygame.locals import *
import itertools
pygame.init()
screen=pygame.display.set_mode((640,480))
class Block(object):
sprite = pygame.image.load("texture\\dirt.png").convert_alpha()
def __init__(self, x, y):
self.rect = self.sprite.get_rect(centery=y, centerx=x)
class Player(object):
sprite = pygame.image.load("texture\\playr.png").convert()
sprite.set_colorkey((0,255,0))
def __init__(self, x, y):
self.rect = self.sprite.get_rect(centery=y, centerx=x)
blocklist = []
player = []
colliding = False
while True:
screen.fill((25,30,90))
mse = pygame.mouse.get_pos()
key=pygame.key.get_pressed()
if key[K_LEFT]:
p.rect.left-=1
if key[K_RIGHT]:
p.rect.left+=1
if key[K_UP]:
p.rect.top-=10
for …Run Code Online (Sandbox Code Playgroud) 只是这个问题的序言:我不知道我在做什么,所以请原谅任何愚蠢.
我正在制作一个基于插座的聊天室,我想在本地网络上使用(我父亲的电脑和我的同一个wifi连接).
这是服务器代码:
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
sock.listen(1)
while True:
# Find connections
connection, client_address = sock.accept()
try:
data = connection.recv(999)
print data
except:
connection.close()
Run Code Online (Sandbox Code Playgroud)
这是客户:
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10000)
print >>sys.stderr, 'connecting to %s port %s' % server_address
while True:
try:
sock …Run Code Online (Sandbox Code Playgroud) 我正在开发一款类似 RPG 的游戏,你的最大生命值可以在整个过程中得到提高。
我正在尝试制作一个脚本,该脚本将绘制一个 100 像素宽、值超过 100 的健康栏。
随着您的健康状况提高,健康栏的单位会变小。
这是我能想到的最好的:
#Draw Bar
import pygame
def SingleColorBar(surface,color,x,y,value,maxvalue):
xx=0
for hp in range(value):
pygame.draw.rect(surface, color, (x+xx,y,1,32), 0)
xx+= value/100
Run Code Online (Sandbox Code Playgroud)
这根本没有按预期工作!
我将如何设置 pygame 形状的 alpha 值: pygame.draw.circle()
我尝试使用 RGBA 值,但无济于事..这是绘制代码:
pygame.draw.circle(screen, ((0,255,0,alpha)), (px,py), 15)
Run Code Online (Sandbox Code Playgroud)
px和py是玩家(圆圈)的位置。alpha只是我认为是 alpha 值的占位符。
有人有任何想法吗?
我不知道我是否只是使用了错误的关键字......但我在谷歌上找不到答案。我不能将我虚弱的头脑包裹在我的错误上。
这是错误的简单演示:
#include <iostream>
//std::cout << "hello";
int main()
{
std::cout << "hello";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译/运行时,我收到此错误:
main.cpp:3:6: 错误:命名空间“std”中的“cout”未命名类型
但是,如果我删除第一cout行,并且只允许程序执行 main 函数中的那一行,它就可以正常工作。
有人有任何想法吗?
是否有算法更改一组坐标以使其向另一组坐标移动?
就像,如果我有ax,ay=(20,30)和bx,by=(40,60)
我似乎无法绕过这个.我如何改变ax和ay(随着时间的推移)平等bx和by?(最好是在python中可实现的算法.)
所以我有一个已在程序退出时导出的已定义类的列表..它看起来像这样:
<__main__.Block object at 0x02416B70>,
<__main__.Block object at 0x02416FF0>,
<__main__.Block object at 0x0241C070>,
<__main__.Block object at 0x0241C0D0>,
<__main__.Block object at 0x0241C130>,
<__main__.Block object at 0x0241C190>,
<__main__.Block object at 0x02416DF0>,
<__main__.Block object at 0x0241C250>,
<__main__.Block object at 0x0241C2B0>,
<__main__.Block object at 0x0241C310>,
<__main__.Block object at 0x0241C370>,
<__main__.Block object at 0x0241C3D0>,
<__main__.Block object at 0x0241C430>,
<__main__.Block object at 0x0241C490>,
<__main__.Block object at 0x0241C4F0>,
<__main__.Block object at 0x0241C550>,
<__main__.Block object at 0x0241C5B0>,
<__main__.Block object at 0x0241C610>
Run Code Online (Sandbox Code Playgroud)
完善!对?现在我应该可以轻松地将其转换为列表..所以我使用这个:
x=x.split(",")
Run Code Online (Sandbox Code Playgroud)
它将它转换为列表是,但它将类转换为字符串!使它们无法使用.
基本上我需要的是在文件关闭时"暂停"游戏状态,然后在打开文件时重新加载它.
那么如何在不将类名转换为字符串的情况下完成此操作呢?
在我的游戏中有一个地形生成器,随后导致许多实例..但我实现了一个代码:
for b in blocklist:
if b.rect.left>=0:
if b.rect.right<=640:
screen.blit(b.sprite, b.rect)
Run Code Online (Sandbox Code Playgroud)
因此它只在scree(400-500)块内渲染事物,并且它仍然运行,好像它渲染全部2000左右.那么我做错了什么?它有什么关系吗?
pygame.display.update() #or
pygame.display.flip()
Run Code Online (Sandbox Code Playgroud)
他们的差别是什么?
这是代码:
#Init stuff
import pygame,random
from pygame.locals import *
from collections import namedtuple
import time, string
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=500)
f=open('texdir.txt','r')
texdir=f.read()
f.close()
f=open(texdir+"\\splash.txt",'r')
splash=f.read()
splash=splash.replace('(','')
splash=splash.replace(')','')
splash=splash.split(',')
f.close()
splashlen=len(splash)
chc=random.randint(0,int(splashlen))
splash=splash[chc-1]
f=open(texdir+"//backcolor.txt")
pygame.init()
clock=pygame.time.Clock()
screen=pygame.display.set_mode((640,480))
pygame.display.set_caption("PiBlocks | By Sam Tubb")
max_gravity = 100
blocksel=texdir+"\\dirt.png"
btype='block'
backimg = pygame.image.load(texdir+"\\menu.png").convert()
backimg = pygame.transform.scale(backimg, (640,480))
clsimg = pygame.image.load("clear.bmp").convert()
clsimg = pygame.transform.scale(clsimg, (640,480))
ingame=0
sbtn=pygame.image.load("startbtn.png").convert()
qbtn=pygame.image.load("quitbtn.png").convert()
tbtn=pygame.image.load("texbtn.png").convert() …Run Code Online (Sandbox Code Playgroud)