如何使用Tkinter创建Sinus Wave?
我不知道如何将y"放"为矩形.我想用矩形做一个循环.
from tkinter import *
import math
master = Tk()
w = Canvas(master, width=200, height=100)
w.pack()
x = 0
width = 200
for x in range(0, width):
y = int(50 + 50*math.sin(4*((float(x)/width)*(2*math.pi) )))
w.create_rectangle(1, 1, 1, 10, fill="yellow")
mainloop()
Run Code Online (Sandbox Code Playgroud) 我试图将base64图像数据转换为图像文件并保存.
base64_image_str = request.POST.get('base64_image_str')
# it is smthg like: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDA......."
with open("newimage.png", "wb") as f:
f.write(base64_image_str.decode('base64'))
f.close()
Run Code Online (Sandbox Code Playgroud)
还尝试过:
f = open("newimage.png", "wb")
f.write(decodestring(base64_image_str))
f.close()
Run Code Online (Sandbox Code Playgroud)
图像正在保存,但它已损坏,无法打开它.我究竟做错了什么?
试图执行java.exe并获得可爱的错误
>> sh.exe": java.exe: command not found
Run Code Online (Sandbox Code Playgroud)
该命令在普通的命令shell中工作.
我已经检查了两者的路径,它们几乎相同,bash有一些预期的额外目录.我曾经env |grep PATH和set PATH分别检查...
where java.exe
C:\Windows\System32\java.exe
set PATH
Path=C:\Ruby193\bin;C:\Windows\system32;C:\Windows;
env |grep PATH
HOMEPATH=\
PATH=/c/Users/hooksc/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Ruby193/bin:/c/Windows/system32:/c/Windows:
Run Code Online (Sandbox Code Playgroud)
我想我错过了一些微妙的东西,任何人都有什么想法?
我有一个简短的路径片段,使它更容易阅读...但是,至少有一个java.exe的源文件夹在路径中.
我试图在angularjs控制器中创建一个乘法函数.我希望功能返回数量和价格的产品.我正在使用下面的代码段,但它返回了一个错误.我究竟做错了什么?
<!DOCTYPE html> <html>
<head> <script src= "Angular.js"></script> </head>
<body>
<div ng-app="" ng-controller="personController">
<h2>Cost Calculator</h2>
Quantity: <input type="number" ng-model="quantity"> Price: <input type="number" ng-model="price">
<p><b>Total in dollar:</b> {{fullname()}}</p>
</div>
<script> function personController(scope) { var input1 = scope.quantity , var input2 = scope.price ,
$scope.fullName = function() {
return {{input1 * input2}};
} } </script>
</body> </html>
Run Code Online (Sandbox Code Playgroud) 我有这样的文本文件:
asn|prefix|ip|domain
25008|85.192.184.0/21|85.192.184.59|solusi-it.com
25008|85.192.184.0/21|85.192.184.59|samtimes.ru
131755|103.31.224.0/24|103.31.224.58|karosel-ind.com
131755|103.31.224.0/24|103.31.224.58|solusi-it.com
9318|1.232.0.0/13|1.234.91.168|solusi-it.com
9318|1.232.0.0/13|1.234.91.168|es350.co.kr
Run Code Online (Sandbox Code Playgroud)
有没有办法可以使用Linux Bash命令计算唯一域上的唯一ips数量并获得这样的结果?
domain|count_ip
solusi-it.com|3
samtimes.ru|1
karosel-ind.com|1
es350.co.kr|1
Run Code Online (Sandbox Code Playgroud) 我在我的函数中使用max()时遇到问题.当使用整数创建列表时,max函数效果很好.但是当我在我的函数中创建一个列表然后使用max()和我的整数列表时,它会给出" TypeError:'int'对象不可调用 "错误.
我错在哪里,我该如何解决?
>>> a = [1,2,3,4,5] # A simple list
>>> max(a) # It works fine
>>> 5
>>> def palen(num):
... min = 10**(num-1)
... max = (10**num)-1
... a=[] # Another list
... mul=0
... for i in range(max,min-1,-1):
... for j in range (max,min-1,-1):
... mul=i*j
... if str(mul)==str(mul)[::-1]:
... a.append(mul)
... return max(a)
...
>>> palen(2)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 11, in palen
TypeError: …Run Code Online (Sandbox Code Playgroud) 我有一个带有一些数据的JSON对象,我想获得每次出现的特定键名的所有值.是否有任何预定义的方法在JSON对象中搜索所有出现的键或需要编写用户定义的方法?
示例Json
[{"id":"23","name":"sunny","className":"2","class" :{"className":"1","class2" :{"className":"3","class" :{"className":"4"}}}}]
Run Code Online (Sandbox Code Playgroud) 我正在尝试以下代码:
#!/usr/bin/python
import multiprocessing
def f(name):
print 'hello', name
if __name__ == '__main__':
p = multiprocessing.Process(target=f, args=('bob',))
p.start()
p.join()
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
Traceback (most recent call last):
File "a.py", line 9, in <module>
p = multiprocessing.Process(target=f, args=('bob',))
AttributeError: 'module' object has no attribute 'Process'
Run Code Online (Sandbox Code Playgroud) 我已经编写了一个脚本,现在我想通过将我的主脚本的一部分移动到其他文件中来使其更具可读性,但不幸的是我不能。
假设现在我在文件中有以下代码utils.sh:
#!/bin/bash
sayHello ()
{
echo "Hello World"
}
Run Code Online (Sandbox Code Playgroud)
他们从我的主脚本中尝试以下操作,但不起作用:
#!/bin/bash
./utils.sh
sayHello
Run Code Online (Sandbox Code Playgroud)
所以,问题是,如何从 utils.sh 中调用函数?
我收到了这个错误
AttributeError at /admin/user/usermodel/1/
'tuple' object has no attribute 'startswith'
Run Code Online (Sandbox Code Playgroud)
当我尝试将文件加载到管理员时,我真的很新文件上传,无法弄明白
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = '/home/user/project/foo/yesno/static/'
STATICFILES_DIRS = (
'/home/user/project/foo/yesno/static_store',
)
MEDIA_ROOT = '/home/user/project/foo/yesno/static/media',
MEDIA_URL = '/media/'
Run Code Online (Sandbox Code Playgroud)
models.py
def get_upload_file_name(instance, filename):
return "uploaded_files/%s_%s" % (str(time()).replace('.','_'), filename)
filename = ''
# Create your models here.
class UserModel(models.Model):
user = models.OneToOneField(User)
position = models.IntegerField(default=1)
thumbnail = models.FileField(upload_to="uploaded_files", blank=True)
def __unicode__(self):
return self.user.username
Run Code Online (Sandbox Code Playgroud)
forms.py
class ThumbnailForm(forms.Form):
thumbnail = forms.FileField()
Run Code Online (Sandbox Code Playgroud)
views.py
def handle_uploaded_file(f):
with open('some/file/name.txt', 'wb+') as destination:
for chunk in f.chunks(): …Run Code Online (Sandbox Code Playgroud)