我想知道是否有人可以告诉我这段代码有什么问题,当我运行代码时它什么也没有显示,但如果我拿出"elif"它确实有效.
first=input("What is your first name? ");
middle=input("What is your middle name? ");
last=input("What is your last name? ");
test = [first, middle, last];
print ("");
print ("Firstname: " + test[0]);
print ("Middlename: " + test[1]);
print ("Lastname: " + test[2]);
print ("");
correct=input("This is the information you input, correct? ");
if (correct == "Yes" or "yes"):
print ("Good!")
elif (correct == "no" or "No"):
print ("Sorry about that there must be some error!");
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用set():
adjacent = filter(lambda p: p[0] in xp and p[1] in yp, p_data)
adjacent = set(adjacent)
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
Traceback (most recent call last):
File "/home/anarchist/Desktop/python27/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "/home/anarchist/Desktop/BSpaces/BrochureSpaces/imageProcessing/__init__.py", line 60, in findViewPorts
adjacent = set(adjacent)
UnboundLocalError: local variable 'set' referenced before assignment
<Greenlet at 0x15879b0: <bound method rawImage.findViewPorts of <BrochureSpaces.imageProcessing.rawImage instance at 0x7f7177356830>>(image_file='image_t.png')> failed with UnboundLocalError
Run Code Online (Sandbox Code Playgroud)
码:
class rawImage:
def __init__(self, **kwargs):
logging.root.setLevel(logging.DEBUG)
self.p_data = [] # Positions of all non opaque …Run Code Online (Sandbox Code Playgroud) 当数组第三列的元素小于特定数量时,我想删除数组的行.例如:
a=np.array([[2331.13,1944.88,23.1379,7,3.18339,0.482105],
[8168.44,1904.70,19.5025,265,4.12642,0.0376510],
[7389.36,1983.97,14.3581,3937,6.04109,0.713416],
[1765.18,1944.29,22.5495,35,2.30717,0.794432],
[2319.33,1946.68,22.4300,25,3.63676,0.0210690],
[785.666,2090.69,14.7940,1095,2.52823,0.999842],
[4071.24,2186.92,22.6616,31,2.79309,0.0312501],
[7082.51,2191.69,23.0122,19,2.53166,0.687001]])
Run Code Online (Sandbox Code Playgroud)
我想删除满足以下条件的行:
a[:,2]<15.0
Run Code Online (Sandbox Code Playgroud)
干杯.
我正在使用Django 1.5.4
我是Django的新手,我试图显示通过管理面板上传的图像,但遗憾的是图像源代码中的url字段为空,如果我更改{{ article.image.url }}为{{ article.image }},则图像网址显示为
<img src="media/abyss.jpg" alt="" height="450"/>
Run Code Online (Sandbox Code Playgroud)
当我点击图片链接时,它说
TypeError at /media/abyss.jpg
can only concatenate tuple (not "unicode") to tuple
Run Code Online (Sandbox Code Playgroud)
请帮我.
Settings.py文件
MEDIA_ROOT = (os.path.join(os.path.dirname(__file__), '..', 'media').replace('\\','/'),)
MEDIA_URL = '/media/'
Run Code Online (Sandbox Code Playgroud)
Models.py文件
class Article(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=255)
description = models.TextField()
content = models.TextField()
published = models.BooleanField(default=True)
image = models.ImageField(upload_to='media', blank=True)
created = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u'%s' % self.title
class Meta:
ordering = ['-created']
def get_absolute_url(self):
return …Run Code Online (Sandbox Code Playgroud) 将字符串转换'321_1'为'321.1'.
我想创建一个方法将下划线转换为句号.我使用拆分,但它无法工作..任何人都可以帮助我?或者我必须使用while循环
将下划线转换为fullstop
def Convert_toFullStop(text):
x1 = ""
words = text.split()
if words in ("_"):
words = "."
print words
Run Code Online (Sandbox Code Playgroud) 我有一个字符串如下:
>>> a
'0 911 872.9 354.9 901.9 395.0 904.6 414.0 903.8 400.5'
Run Code Online (Sandbox Code Playgroud)
现在我希望将其转换为数组:
>>> b
array([ 0. , 911. , 872.9, 354.9, 901.9, 395. , 904.6, 414. ,
903.8, 400.5])
Run Code Online (Sandbox Code Playgroud)
最恐怖的做法是什么?
我有这个设计,例如:
design = """xxx
yxx
xyx"""
Run Code Online (Sandbox Code Playgroud)
我想将它转换为数组,矩阵,嵌套列表,如下所示:
[['x', 'x', 'x'], ['y', 'x', 'x'], ['x', 'y', 'x']]
Run Code Online (Sandbox Code Playgroud)
请问你会怎么做?
请,我想找到存储在名为'myNumbers.txt'的.txt文件中的数字的方块
myNumbers.txt
2
3
4
5
3
Run Code Online (Sandbox Code Playgroud)
我有这些python脚本:
if __name__=="__main__":
f_in=open("myNumbers.txt", "r")
for line in f_in:
line=line.rstrip()
print float(line)**2
f_in.close()
Run Code Online (Sandbox Code Playgroud)
我尝试了这个并且它工作得非常好,但我想知道是否还有其他方法.
我希望能够交错两个可能长度不等的列表.我有的是:
def interleave(xs,ys):
a=xs
b=ys
c=a+b
c[::2]=a
c[1::2]=b
return c
Run Code Online (Sandbox Code Playgroud)
这适用于长度相等或只有+/- 1的列表.但是如果让我们说xs = [1,2,3]和ys = ["hi,"bye","no","yes","why"]这条消息出现:
c[::2]=a
ValueError: attempt to assign sequence of size 3 to extended slice of size 4
Run Code Online (Sandbox Code Playgroud)
如何使用索引修复此问题?或者我必须使用for循环?编辑:我想要的是让额外的值出现在最后.
我试图理解__call__(python3)的含义。写了这个区分每个方法__init__,__call__以及测试方法。
#!/usr/bin/python3
class thara(object):
def __init__(self):
print("init called")
def __call__(self):
print("call called")
def test(self):
print("test called")
x=thara() ### constructor calling here
x() ## __call__ calling here
x.test() ## test method calling here
Run Code Online (Sandbox Code Playgroud)
我的问题是当我启动时x.test(),为什么不调用__call__?我在想的是,如果我启动 x.test() 将启动实例x(),它应该__call__自动调用该 方法。但根据我的输出__call__只会在启动时调用x()。
有人可以解释一下。