有没有办法同时使用两只海龟在一个窗口中同时画两个圆?我试过这段代码,但两只海龟在分开的窗口中绘制
from multiprocessing import Process
import turtle
t1=turtle.Turtle()
t2=turtle.Turtle()
def tes1():
t1.speed(0)
i=0
while i < 360:
t1.forward(1)
t1.left(1)
i+=1
def tes2():
t2.speed(0)
i=0
while i < 360:
t2.forward(1)
t2.right(1)
i+=1
if __name__ == '__main__':
p1 = Process(target=tes1)
p1.start()
p2 = Process(target=tes2)
p2.start()
p1.join()
p2.join()
Run Code Online (Sandbox Code Playgroud)
但是有人告诉我尝试多线程但是这段代码有一个糟糕的语义错误!!
import threading
import turtle
t1=turtle.Turtle()
t2=turtle.Turtle()
def tes1():
t1.speed(0)
i=0
while i < 360:
t1.forward(1)
t1.left(1)
i+=1
def tes2():
t2.speed(0)
i=0
while i < 360:
t2.forward(1)
t2.right(1)
i+=1
t = threading.Thread(target=tes1)
t.daemon = True …
Run Code Online (Sandbox Code Playgroud) 我正试图在Debug=False
模式下在VPS上午餐.Debug=True
工作正常,但当我将其更改为false时,我收到此错误.我正在使用Apache来渲染python页面,使用Nginx来提供我的静态文件.我尝试使用这个[回答]:调试Apache/Django/WSGI错误请求(400)错误,但它至少对我不起作用.这是我的wsgi配置:
#wsgi.py
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
path = '/var/www/example'
if path not in sys.path:
sys.path.append(path)
Run Code Online (Sandbox Code Playgroud)
我还在下面的代码中添加了以下代码:
ALLOWED_HOSTS = [
'.example.com', # Allow domain and subdomains
'.example.com.', # Also allow FQDN and subdomains
]
Run Code Online (Sandbox Code Playgroud) 有没有办法在python中使用多个异常?像下面的代码:
try:
#mycode
except AttributeError TypeError ValueError:
#my exception
Run Code Online (Sandbox Code Playgroud)
我的意思是如何相互使用 AttributeError
TypeError
ValueError
?
我有一些像这样的css类:
.ft-*{
font-size: .*px;
}
Run Code Online (Sandbox Code Playgroud)
无论如何,每当我调用类似<div class="ft-16">hello</div>
某些属性(如字体大小更改为16)时定义css ?我的意思是可以输入一些东西而不是*
像数字那样的标记,...?
我正在尝试使用python生成器实现一种合并排序,以找到生成的数字中的最小数字并生成下一个数字,这是我的示例代码:
class GeneratorSort():
def __init__(self, *args):
self.values = [(arg.next(), i) for i, arg in enumerate(args)]
self.generators = args
def generate(self):
r, index = min(self.values)
self.values[index] = self.generators[index].next()
yield r
def t(l):
for each in l:
yield each
l1 = [2, 5, 6, 8]
l2 = [1, 4, 5, 7]
l3 = [0, 3, 9, 10]
a = GeneratorSort(t(l1), t(l2), t(l3))
Run Code Online (Sandbox Code Playgroud)
但是当我尝试打印排序结果时,我只得到了0
下一次错误:
>>> for i in a.generate():
print i
0
Run Code Online (Sandbox Code Playgroud)
这是错误:
>>> a.generate()
<generator object generate at 0x7fa7bcc37a00>
>>> …
Run Code Online (Sandbox Code Playgroud) 我需要一个包含1000个十进制数字的类来计算一系列的pi数字.花时间并不重要.如何定义__add__
&...函数来执行此操作?比如我需要一个值可以保存这个数字:3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113
:))
使用此数字decimal.Decimal
显示如下:
from decimal import Decimal as dc
>>> x=dc(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113)
>>> x
Decimal('3.141592653589793115997963468544185161590576171875')
Run Code Online (Sandbox Code Playgroud)
但是我需要一个包含所有DIGITS的新类,我可以在其中使用添加,分割和...功能,如2 + 1和pi数字就是一个例子,我不需要计算我想要计算的pi数超大十进制数!
我已经阅读了有关切换集合以保存文档的mongoengine文档.并测试此代码并成功运行:
from mongoengine.context_managers import switch_db
class Group(Document):
name = StringField()
Group(name="test").save() # Saves in the default db
with switch_collection(Group, 'group2000') as Group:
Group(name="hello Group 2000 collection!").save() # Saves in group2000 collection
Run Code Online (Sandbox Code Playgroud)
但问题是当我想在交换机集合switch_collection
中找到保存的文件时根本不起作用.
with switch_collection(Group, 'group2000') as GroupT:
GroupT.objects.get(name="hello Group 2000 collection!") # Finds in group2000 collection
Run Code Online (Sandbox Code Playgroud) 在mongoengine
有一个集合中查询对象(文件)的方法有两种:
Test.object(category="blabla")
Run Code Online (Sandbox Code Playgroud)
和
Test.object.filter(category="blabla")
Run Code Online (Sandbox Code Playgroud)
他们返回相同的结果。但问题是有什么区别?表现?或者他们只是彼此的别名?
我正在尝试使用pyorient
驱动程序创建类,但有时如果类存在,我有类存在消息.有没有办法检查OrientDB python驱动程序中是否存在类?以下是我创建类的示例代码的一部分......
@classmethod
def create(cls):
cls._cluster_id = OrientEngine.client.command("CREATE CLASS %s EXTENDS V" % cls.__name__)
return cls._cluster_id
Run Code Online (Sandbox Code Playgroud) 我想在python之前打印的另一个文本旁边打印一些文本
print("Hello")
a="This is a test"
print(a)
Run Code Online (Sandbox Code Playgroud)
我的意思是打印像这样的"HelloThis是一个测试"不在下一行我知道我应该使用print("Hello",a)但我想使用分离的打印命令!!!!
我尝试使用进行编译,py_compile
但出现以下错误:SyntaxError:(unicode错误)“ unicodeescape”编解码器无法解码位置2-3中的字节:截断的\ UXXXXXXXX转义
这是我的编译代码:
py_compile.compile("D:\University Project\Python\Examples\XO Game\XO.py")
Run Code Online (Sandbox Code Playgroud)
这是相关代码:
#difining libraries
import turtle
from tkinter import messagebox as msgbox
#defining constants
osc=xsc=asc=0#scores vars
np="n.gif"
op="o.gif"
xp="x.gif"
pturn=xp
turtle.register_shape(np)
turtle.register_shape(op)
turtle.register_shape(xp)
t=[turtle.Turtle() for x in range(10)]
for i in range(9):
t[i].ht()
arra=[[0]*3 for x in range(3)]#array for holding scores
tempa=[[0]*3 for x in range(3)]#array for holding scores
temparray=[[0]*3 for x in range(3)]#array for holding scores
def tur0(x,y):
tclick(0)
def tur1(x,y):
tclick(1)
def tur2(x,y):
tclick(2)
def tur3(x,y):
tclick(3)
def tur4(x,y): …
Run Code Online (Sandbox Code Playgroud) 我有一个问题,使用GNU g ++一起编译多个文件,所以请帮助我.
我们假设有五个文件:
main.cpp : the main function
a.h : the header file of class A
a.cpp : the definition of class A
b.h : the header file of class B
b.cpp : the definition of class B
Run Code Online (Sandbox Code Playgroud)
在程序中,main.cpp
使用类A(因此包括a.h
),类A使用类B(因此包括b.h
).
那么,如何编译该程序以生成执行文件?
我尝试使用以下命令,但它反馈了错误:
undefined reference to ~(objects in class A and B)".
command: g++ -Wall -O2 -s main.cpp
Run Code Online (Sandbox Code Playgroud)
我的操作系统是ubuntu 12.04.我知道如果我用dev c ++之类的东西创建一个项目,它会自动将文件链接在一起,但我不想使用它.我也看过其他链接和来源,但我找不到对自己有用的东西.
我正在 Golang 中开发一个网络应用程序。我有一个 IP 地址片段。每次收到请求时,我都会用来net.LookupIP(host)
查找返回net.IP
. 比较这些的最佳方法是什么?
顺便说一句,在 Python 中我们有一个set
数据结构,这使得上面的问题很容易解决,但是 Go 呢?
python ×10
python-3.x ×5
python-2.7 ×4
mongodb ×2
mongoengine ×2
apache ×1
arrays ×1
bigdecimal ×1
c++ ×1
class ×1
css ×1
django ×1
exception ×1
g++ ×1
generator ×1
go ×1
header ×1
header-files ×1
html ×1
ip ×1
nginx ×1
orientdb ×1
orm ×1
printing ×1
pyorient ×1
python-3.3 ×1
slice ×1
sorting ×1
text ×1