我有一段代码在Linux中运行,我现在正试图在Windows中运行它,我导入sys但是当我使用sys.exit()时.我收到一个错误,sys没有定义.这是我的代码的开头部分
try:
import numpy as np
import pyfits as pf
import scipy.ndimage as nd
import pylab as pl
import os
import heapq
import sys
from scipy.optimize import leastsq
except ImportError:
print "Error: missing one of the libraries (numpy, pyfits, scipy, matplotlib)"
sys.exit()
Run Code Online (Sandbox Code Playgroud)
为什么sys不工作?
我有一个功能需要取出屏幕上两点之间的等距点(2d).
像这样 -
|--------------|
Run Code Online (Sandbox Code Playgroud)
距离已经确定.例如,我把它当作2这里,然后我需要的点 -
|--.--.--.--.--|
Run Code Online (Sandbox Code Playgroud)
这些点可以在2d平面上的任何位置,这意味着如果我在两个点之间画一条线,它可以是2d平面中的任何方向,即对角线,水平等.
我无法弄清楚如何做到这一点在python中.
我不知道该怎么去谷歌...我14岁所以我不知道任何类型的数学.
我知道如何计算线的距离和斜率,但我不知道如何继续.
提前致谢!
我分叉了一个Github存储库,并在几天内进行了一些更改,没有从原来的repo(我做了一个fork的repo)做了一次拉动.
现在我向原始仓库发出了拉取请求.我发现repo在我分叉之后又得到了另一个提交.
所以我的问题是,如果repo的所有者接受了pull请求,那么他之后做出的提交会保留还是他的repo会成为我的fork的相同副本?
如果是后者,那么你能告诉我怎么不删除他所做的提交?
我试图制作一个Entry小部件,在按下Esc时清除它的内容.
这是我尝试过的 -
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
editor = Gtk.Entry()
self.add(editor)
Run Code Online (Sandbox Code Playgroud)
我不知道将小部件连接到什么.Esc是一个按键,但是当条目成为焦点时应该发生按键.我完全迷失了.
当Esc被按下并且它处于焦点时,请帮我做一个清除的条目.
我正在解决这个问题:
通过列出前六个素数:
2,3,5,7,11 和13,我们可以看到第6个素数是13. 什么是10个第001个素数?
def checkPrime(x):
facs = 0
for i in range(1,x):
if x%i==0:
facs = facs + 1
if facs == 2:
return True
else :
return False
i = 1
noPrime = 0
done = False
while(done==False):
i = i + 1
print "i = {0} and noPrime={1}".format(i,noPrime)
if checkPrime(i)==True:
noPrime = noPrime + 1
if noPrime==10001 :
print i
done=True
Run Code Online (Sandbox Code Playgroud)
但这需要花费很多时间.
我怎样才能加快速度?
我试图取出1到10之间的每个数字,可以被5或3整除.
这是我的代码,直到现在 -
giveList =
[ x
| x <- [1..10] ,
(x `mod` 5 == 0) or (x `mod` 3 == 0)
]
Run Code Online (Sandbox Code Playgroud)
然后我在ghci中加载函数.但它给了我一个错误 -
> [1 of 1] Compiling Main ( problem1.hs, interpreted )
problem1.hs:4:10:
The function `x `mod` 5 == 0' is applied to two arguments,
but its type `Bool' has none
In the expression: (x `mod` 5 == 0) or (x `mod` 3 == 0)
In a stmt of a list comprehension:
(x `mod` 5 == …Run Code Online (Sandbox Code Playgroud) 我有一个具有多个选择字段的表单.它正在通过GET方法.表单生成的请求参数示例:
action=not-strummed&action=not-rewarded&keywords=test&page=2
Run Code Online (Sandbox Code Playgroud)
请注意,有两个"动作"参数.这是因为多重选择而发生的.
我想做的是:
该urllib.urlencode()是没有足够的智慧来从列表中的网址参数.
例如:
{
"action": [u"not-strummed", u"not-rewarded"]
}
Run Code Online (Sandbox Code Playgroud)
urllib.urlencode()将此dict转换为:
action=%5Bu%27not-strummed%27%2C+u%27not-rewarded%27%5D
Run Code Online (Sandbox Code Playgroud)
这是完全错误和无用的.
这就是为什么我写这个迭代代码来重新生成url参数.
Run Code Online (Sandbox Code Playgroud)parameters_dict = dict(self.request.GET.iterlists()) parameters_dict.pop("page", None) pagination_parameters = "" for key, value_list in parameters_dict.iteritems(): for value in value_list: pagination_item = "&%(key)s=%(value)s" % ({ "key": key, "value": value, }) pagination_parameters += pagination_item
它运作良好.但它并没有涵盖所有可能性,它绝对不是非常pythonic.
从列表中创建url参数有没有更好(更pythonic)的想法?
谢谢
我试图使Regexp匹配一个多于或等于两个'1's 的表达式.
这是我到现在所写的 -
puts "Match." if /(1){1,5}/ =~ test_string
Run Code Online (Sandbox Code Playgroud)
这正确匹配'1'大于或等于2的字符串,但如果出现次数'1'大于5 ,它仍然匹配.
如何更正此Regexp以仅匹配出现1到5次的字符串1?
我有一个HTML页面,其中包含以下内容 -
<div class="sidebar">
Some content here....
</div>
<div class="content">
content here too...
</div>
Run Code Online (Sandbox Code Playgroud)
我想要.sidebar position:fixed,但不是.content.这是我在CSS中尝试过的 -
*{box-sizing:border-box;}
.sidebar{
background:rgb(24, 33, 61);
text-align: right;
height: 100% !important;
width:30%;
postion:fixed;
left:0px;
top:0px;
bottom:0;
padding:1em;
color:white;
}
.content{
width:70%;
font-size:1.1em;
font-weight:normal;
position: absolute;
top:0;
right:0;
padding:2em;
}
Run Code Online (Sandbox Code Playgroud)
基本上,我想重现这一点.但是我现在看到的东西看起来很完美,但是当你向下滚动时,.sidebar不会随你移动,它会停留在同一个地方.
Codepen演示
我怎样才能使它工作?