我有一个我想要使用的程序框架:
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吗?
我想在lambda中使用print.像这样的东西:
lambda x: print x
Run Code Online (Sandbox Code Playgroud)
我明白,在Python 2.7中打印不是一个功能.所以,基本上,我的问题是:在Python 2.7中使用print作为函数是否有一种漂亮的方法?
我在Python中有一些代码:
repost_pid = row[0]
repost_permalink = row[1]
repost_domain = row[2]
repost_title = row[3]
repost_submitter = row[4]
Run Code Online (Sandbox Code Playgroud)
是否有一种单行方式来分配这些变量?
另外,如果我想跳过一个值,我该怎么办?
我上线了 Python 2.7 (x86) ,Open CV 3.1.0, Windows 7 (x64)
在 Open CV 上尝试一些简单的模板匹配
图片
编码
dark_elixir_sample = cv2.imread('dark_elixir_sample.png')
w, h = dark_elixir_sample.shape[::-1]
Run Code Online (Sandbox Code Playgroud)
我试图w,h在我的脚本中进一步使用,但是脚本返回以下错误。
错误
ValueError: too many values to unpack
Run Code Online (Sandbox Code Playgroud) 所以,我有以下代码:
half= 1/2.0
print(half)
for x in range(1,1075):
half=half/2.0
print(half)
Run Code Online (Sandbox Code Playgroud)
但是在循环的最后部分,python决定一半现在是0.0
1.265e-321
6.3e-322
3.16e-322
1.6e-322
8e-323
4e-323
2e-323
1e-323
5e-324
0.0
Run Code Online (Sandbox Code Playgroud)
我达到了python的限制吗?我是否需要安装一个包装才能更远?我不确定为什么会发生这种情况,但我认为python刚刚达到极限
我正在编写一些python代码(与ArcGIS结合使用),我有一个简单的语句运行良好,完全按照我的要求去做,我只是从我的脚本软件(PyCharm)得到一个"警告"我:
我知道它没有被使用,因为它不需要.这是唯一的方法(我个人知道)计算表中存在多少行.
有人能告诉我是否有更好的(更正确的)写作方式?
cursor = arcpy.SearchCursor(my_table)
for row in cursor:
count += 1
print count
Run Code Online (Sandbox Code Playgroud)
干杯
我在 stackoverflow 上找到了这个,它完全符合我的要求:
>>> k = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]]
>>> import itertools
>>> k.sort()
>>> list(k for k,_ in itertools.groupby(k))
[[1, 2], [3], [4], [5, 6, 2]]
Run Code Online (Sandbox Code Playgroud)
我不明白这里的列表理解。如果无法设法将其翻译为for iteration. 我总是使用以下语法:
[k for k in smthiterable (if condition)]
Run Code Online (Sandbox Code Playgroud)
我试图将下划线更改_为其他内容,它仍然有效。但如果我删除它,它不会。它有什么用?
我试图从一些 tensorflow 代码中理解这行代码
_, l = session.run([optimizer, loss], feed_dict=feed_dict)
Run Code Online (Sandbox Code Playgroud)
这一行的上下文来自
with tf.Session(graph=graph) as session:
tf.global_variables_initializer().run()
print('Initialized')
average_loss = 0
for step in range(num_steps):
batch_data, batch_labels = generate_batch(
batch_size, num_skips, skip_window)
feed_dict = {train_dataset : batch_data, train_labels : batch_labels}
_, l = session.run([optimizer, loss], feed_dict=feed_dict)
average_loss += l
if step % 2000 == 0:
if step > 0:
average_loss = average_loss / 2000
# The average loss is an estimate of the loss over the last 2000 batches.
print('Average loss at …Run Code Online (Sandbox Code Playgroud) 我试图在 opencv 4.4.0 版上使用 cv2.findContours()。(我使用的是 Python 3.8.5 版)但它抛出了一个错误,我无法弄清楚。我不确定代码有什么问题。这是一些背景:
根据 OpenCV, cv2.findContours() 的语法如下: Python: contours, hierarchy = cv.findContours( image, mode, method[, contours[, hierarchy[, offset]]] )
我找了一些例子来确保如何正确实现它,这是我发现的:example 1 _, contours, _ = cv2.findContours(binary_image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
示例 2 (_, cnts, _) = cv2.findContours(thresholded.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
这些是我在网上找到的工作项目,有很多这样的例子。所以,我试图实现我从视频中获得的一些代码,以对该主题有一些了解,但它似乎对我不起作用,我找不到原因。代码如下:
import cv2
import numpy as np
imagen =cv2.imread('lettuce.jpg')
gray = cv2.cvtColor(imagen,cv2.COLOR_BGR2GRAY)
_,binary = cv2.threshold(gray,100,255,cv2.THRESH_BINARY)
image,contours,hierarchy = cv2.findContours(binary,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(image,contours, -1, (0,255,0),3)
Run Code Online (Sandbox Code Playgroud)
错误:回溯(最近一次调用):第 8 行,在图像、轮廓、层次结构 = cv2.findContours(binary,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE) ValueError:没有足够的值来解包(预期 3,得到 2)
python ×10
opencv ×2
python-3.x ×2
arcpy ×1
division ×1
list ×1
python-2.7 ×1
syntax ×1
tensorflow ×1
tkinter ×1