所以我做了我的研究,但我仍然无法弄清楚为什么我得到这个错误:
TypeError: int is not callable
继承我的代码:
count = []
for row in Matrix:
count.append(row[0][0].Value)
results = map(int, count)
print max(results)
Run Code Online (Sandbox Code Playgroud)
count列表包含一个字符串整数列表,我将这些转换为纯整数然后我想找到最大数字,但我得到了错误.
我在这里看不到什么?
顺便说一句,print min(count)工作正常....
问题是我想用C#语言获取音频语音的音素.假设你有一个像"x.wav"这样的音频文件,上面写着"你好亲爱的Shamim".我想提取演讲的所有音素和他们的相对时间.如下图所示:

我使用了System.Speech库(两者recognition和synthesis命名空间),但我找不到我想要的东西.现在别搞错了!我不想要句子的语句"亲爱的Shamim",我想从未知的音频输入中提取音素和英语句子.我试过System.Speech.Recognition但它试图从音频文件中提取出来的话,而不是手机!正如你可能猜到的那样,30%的错误!;)
我想知道是否有一种更简单/ pythonic的方式来修剪python中字典的"大小/长度".如果我有一个包含10个键值对(元素)的dict,并且我想将大小限制为5.在循环中删除元素是最佳解决方案(顺序/标识无关紧要)
def _trim_search_results(self):
MAX_RESULTS = 5
# a big dict
results_to_be_trimmed = {result_1 ... result_n}
# dict with length MAX_RESULTS
trimmed_results = {}
for index, key in enumerate(results_to_be_trimmed):
if index == MAX_RESULTS:
break
else:
trimmed_results[key] = results_to_be_trimmed[key]
results_to_be_trimmed = trimmed_results
Run Code Online (Sandbox Code Playgroud)
我认为必须有更好的解决方案......
到目前为止,这是我的代码。No results found如果MySQL没有返回结果,我正在尝试打印,但是我无法弄清楚。也许我使用了不正确的参数。谁能给我一个例子?非常感激!
def movie_function(film):
connection = mysql connection info
cursor = connection.cursor()
sql = "SELECT * FROM film_database WHERE film_name = '"+film+"' ORDER BY actor"
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
print row[1]
Run Code Online (Sandbox Code Playgroud) 我正在尝试将包含(自然语言)时间的字符串解析为hh:mm时间对象?例如:
"ten past five"
"quarter to three"
"half past noon"
"15 past 3"
"13:35"
"ten fourteen am"
Run Code Online (Sandbox Code Playgroud)
我已经研究过Chronic for Ruby和Natty for Java(以及其他一些库),但两者似乎都专注于解析日期.像"十点五分"这样的字符串也没有正确解析.
有谁知道一个适合我需求的图书馆?或者我应该开始使用自己的解析器吗?
如果您使用下面的代码在通知区域中创建TrayTips(BaloonTips),您会注意到它只允许一条消息,然后卡住并出错.
代码来自这里:
# -- coding: utf-8 --
from win32api import *
from win32gui import *
import win32con
import sys, os
import struct
import time
class WindowsBalloonTip:
def __init__(self, title, msg):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
}
# Register the Window class.
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow( classAtom, "Taskbar", …Run Code Online (Sandbox Code Playgroud) 我 在项目euler尝试了问题10并且通过但是我决定,如果我将所有低于200万的素数用于文本(.txt)文件,那么我继续并且因此对主函数进行了一些小的调整以解决问题因此,如果不将其添加到变量(tot),我将生成器生成的素数写入文本文件,并且它最初工作但忘记在每个素数后添加空格,因此输出有点乱码
357111317192329313741434753
所以我修改了我txt.write(str(next_prime))的txt.write(str(next_prime) + ' ')
在稍作修改后,输出完全是胡言乱语
"`‷ㄱㄠ"㜱ㄠ<㌲㈠<ㄳ㌠‷ㄴ㐠"
这是我的功能完整代码:
def solve_number_10():
total = 2
txt = open("output.txt","w")
for next_prime in get_primes(3):
if next_prime < 2000000:
txt.write(str(next_prime) + ' ')
#total += next_prime
else:
print "Data written to txt file"
#print total
txt.close()
return
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,我怎样才能使输出像
3 5 7 11 13 17 19
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pip安装numpy.当我pip install numpy在命令提示符下键入它时,它将继续工作,但不会安装该文件并返回错误代码1.我正在使用Windows 8 64位和python 2.7.这是错误消息的最后一位
Cleaning up...
Removing temporary dir c:\users\pim\appdata\local\temp\pip_build_Pim...
Command python setup.py egg_info failed with error code 1 in c:\users\pim\appdata\local\temp\pip_build_Pim\numpy
Exception information:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\basecommand.py", line 134, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\commands\install.py", line 236, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "C:\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py", line 1134, in prepare_files
req_to_install.run_egg_info()
File "C:\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py", line 259, in run_egg_info
command_desc='python setup.py egg_info')
File "C:\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\util.py", line 670, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: …Run Code Online (Sandbox Code Playgroud) ListA = [1,2,3]
ListB = [10,20,30]
Run Code Online (Sandbox Code Playgroud)
我想将列表的内容添加到一起(1+10,2+20,3+30)创建以下列表:
ListC = [11,22,33]
Run Code Online (Sandbox Code Playgroud)
是否有以这种方式专门合并列表的函数?
我正在编写一个程序,一直要求用户输入名称,直到输入单词END,此时它会打印出名称列表.
代码:
import getpass
import time
import sys
print("Welcome " + getpass.getuser() + "...")
time.sleep(0.25)
print("This program, powered by Python, it will ask you to enter names...")
time.sleep(0.5)
print("...once you have finished, enter END to print off your list")
names = []
for i in names:
name = input("Please enter a name: ")
if name == "END":
print(names)
sys.exit()
names.append(name)
Run Code Online (Sandbox Code Playgroud)
问题是程序在尝试执行for循环之前退出.
为什么会发生这种情况,我该如何解决?