小编use*_*351的帖子

在Python中打印多个参数

这只是我的代码片段:

print("Total score for %s is %s  ", name, score)
Run Code Online (Sandbox Code Playgroud)

但我希望它打印出来:

"(姓名)总分为(得分)"

where name是列表中的变量,score是一个整数.这是Python 3.3,如果这有帮助的话.

python printing arguments python-3.x

283
推荐指数
10
解决办法
84万
查看次数

主机密钥验证失败

所以我正试图通过我的电脑上的Cygwin进入我的UBUNTU.我可以毫不费力地使用WINSCP,但是当我通过命令行ssh时,它会出现这个错误:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
5d:84:de:4e:a8:81:df:22:06:23:98:34:cd:26:f5:1a.
Please contact your system administrator.
Add correct host key in /home/Trevor/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/DIRECTORY
ECDSA host key …
Run Code Online (Sandbox Code Playgroud)

ssh ubuntu host

13
推荐指数
3
解决办法
3万
查看次数

Skimage Python33 Canny

长话短说,我只是想简单地想要获得一个精明的形象image.jpg.

文档很乱,所以我很困惑.如果有人可以提供帮助,那将非常感激.

from scipy import misc
import numpy as np
from skimage import data
from skimage import feature
from skimage import io


im=misc.imread('image1.jpg')
edges1 = feature.canny(im)
...
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

ValueError: The parameter `image` must be a 2-dimensional array
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释如何从图像文件创建2D数组?谢谢!

numpy python-3.x python-3.3 scikit-learn

4
推荐指数
1
解决办法
3556
查看次数

比较文本文件内容的最快方法

我有一个问题可以帮助简化我的编程.所以我有这个文件text.txt,在其中我想查看它并将其与单词列表进行比较words,每次找到单词时它都会添加1一个整数.

words = ['the', 'or', 'and', 'can', 'help', 'it', 'one', 'two']
ints = []
with open('text.txt') as file:
    for line in file:
        for part in line.split():
            for word in words:
                if word in part:
                    ints.append(1)
Run Code Online (Sandbox Code Playgroud)

我只是想知道是否有更快的方法来做到这一点?文本文件可能会更大,单词列表会更大.

python string count python-3.x

4
推荐指数
1
解决办法
1210
查看次数

按Enter键而不是单击按钮

我有一个我想要使用的程序框架:

from tkinter import *
import urllib
import urllib.request
import xml.etree.ElementTree as ET
root = Tk()

def program():
    print('Hello')

tex=Text(root)
tex.pack(side='right')
inputfield = Entry(root)
inputfield.pack(side='bottom')
text = inputfield.get()
but = Button(root,text="Enter", command = program) 
but.pack(side='bottom')

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

好吧如此重新编程,程序只是一个框架,带有文本字段,输入字段和一个按钮Enter.我想调用程序按钮调用而不实际按下按钮.我想在输入字段中输入文本,然后按Enter我的键盘来调用该函数.

这可能通过tkinter吗?

python tkinter python-3.x

3
推荐指数
1
解决办法
2731
查看次数

比If Else更聪明

我正在尝试切换(各种)命令.

if 'Who' in line.split()[:3]:
    Who(line)   
elif 'Where' in line.split()[:3]:
    Where(line)
elif 'What' in line.split()[:3]:
    What(line)
elif 'When' in line.split()[:3]:
    When(line)
elif 'How' in line.split()[:3]:
    How(line)
elif "Make" in line.split()[:3]:
    Make(line)
elif "Can You" in line.split()[:3]:
    CY(line)
else:
    print("OK")
Run Code Online (Sandbox Code Playgroud)

所以解释.如果Who,What等等在命令的前3个字中,则它执行相应的功能.我只是想知道除了很多之外是否有更聪明的方法来做到这一点if,elif并且else

python if-statement

3
推荐指数
1
解决办法
160
查看次数

在Python中从文本文件中获取属性

所以我正在制作一个Yu-Gi-Oh数据库程序.我将所有信息存储在一个大文本文件中.每个怪物都通过以下方式进行了分类:

|Name|NUM 1|DESC 1|TYPE|LOCATION|STARS|ATK|DEF|DESCRIPTION
Run Code Online (Sandbox Code Playgroud)

这是一个实际的例子:

|A Feather of the Phoenix|37;29;18|FET;YSDS;CP03|Spell Card}Spell||||Discard 1 card. Select from your Graveyard and return it to the top of your Deck.|
Run Code Online (Sandbox Code Playgroud)

所以我创建了一个程序,按名称搜索这个大文本文件,它返回文本文件中没有'|'的信息.这里是:

    with open('TEXT.txt') as fd:
         input=[x.strip('|').split('|') for x in fd.readlines()]
         to_search={x[0]:x for x in input}
         print('\n'.join(to_search[name]))
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试编辑我的程序,以便我可以搜索怪物的名称并选择我想要显示的属性.所以它看起来像

A Feather of the Phoenix 
Description:
Discard 1 card. Select from your Graveyard and return it to the top of your Deck.    
Run Code Online (Sandbox Code Playgroud)

关于我如何做到这一点的任何线索?

python text python-2.7 python-3.x

1
推荐指数
1
解决办法
1282
查看次数