我想捕获一个特定的ValueError,而不仅仅是任何ValueError.
我试过这样的事情:
try: maquina['WPF'] = macdat(ibus, id, 'WPF')
except: ValueError, 'For STRING = ’WPF’, this machine is not a wind machine.':
pass
Run Code Online (Sandbox Code Playgroud)
但它引发了一个SyntaxError:无法分配给文字.
然后我尝试了:
try: maquina['WPF'] = macdat(ibus, id, 'WPF')
except ValueError, e:
if e != 'For STRING = ’WPF’, this machine is not a wind machine.':
raise ValueError, e
Run Code Online (Sandbox Code Playgroud)
但它提出了例外,即使它是我想要避免的那个.
我曾尝试easy_install install openpyxl和python setup install.都失败了.我也尝试过easy_install openpyxl再次失败.我包括我得到的输出.
当我尝试时easy_install install openpyxl,我得到以下输出:
Searching for install
Reading https://pypi.python.org/simple/install/
Download error on https://pypi.python.org/simple/install/: timed out -- Some pac
kages may not be found!
Couldn't find index page for 'install' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: timed out -- Some packages ma
y not be found!
No local packages or download links found for install
error: …Run Code Online (Sandbox Code Playgroud) 我的scrpt有以下几行:
libro_dia = xlrd.open_workbook(file_contents = libro_dia)
Run Code Online (Sandbox Code Playgroud)
如果libro_dia无效,则会引发以下错误:
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '<!DOCTYP'
Run Code Online (Sandbox Code Playgroud)
我想要处理这个错误,所以我写道:
try:
libro_dia = xlrd.open_workbook(file_contents = libro_dia)
except XLRDError:
no_termina = False
Run Code Online (Sandbox Code Playgroud)
但它引发了以下错误:
NameError: name 'XLRDError' is not defined
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
我正在运行一个脚本,该脚本使用一个模块在屏幕上打印很多东西,而我的RAM用完了.
我不能让模块暂时不写任何东西.
Python Shell存储绝对所有内容,我想清除它.
在类似的问题上,我能找到的唯一答案就是写os.system('cls')(在Windows上),但它不会删除任何内容.
有没有办法清除Python Shell或限制其大小?
谢谢
编辑.
好吧,这个问题被标记为重复,我被要求澄清为什么不是.
我声明这os.system('cls')不起作用,而我提出的重复问题的答案是写os.system('cls').
我正在尝试在Windows上安装setuptools.
文档说我应该运行ez_setup.py.
所以我做了,我得到以下输出:
Extracting in c:\users\ut601039\appdata\local\temp\tmpf6a2mb
Now working in c:\users\ut601039\appdata\local\temp\tmpf6a2mb\setuptools-1.0
Installing Setuptools
Something went wrong during the installation.
See the error message above.
Traceback (most recent call last):
File "D:\Python\Setuptools\ez_setup.py", line 357, in <module>
sys.exit(main())
SystemExit: 2
Run Code Online (Sandbox Code Playgroud)
错误消息不是很有用.查看我发现的代码:
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
# exitcode will be 2
return 2
Run Code Online (Sandbox Code Playgroud)
我去了_python_cmd(),发现:
def _python_cmd(*args):
args = (sys.executable,) + args
return subprocess.call(args) == 0
Run Code Online (Sandbox Code Playgroud)
我发现subprocess.call(args)返回1而不是预期的0.
以下行第一行需要45秒,第二行需要一分半钟.Something.xls大4 MB,变化很小.有什么不对?
something = openpyxl.load_workbook('Something.xlsx')
something.save('Something.xlsx')
Run Code Online (Sandbox Code Playgroud)
一些细节:我在Windwos 7上使用Python 2.7.3,工作簿有2张,其中第一张有67610行,我没有访问任何网络来完成这项工作.
我觉得这个问题很简单但找不到答案.
我有一个长度为2的元组列表.
我想得到一个长度为3的元组列表,其中第三个元素是对其他两个元素进行某些操作的结果.
例:
for val_1, val_2 in list_of_tuples
#...
#some multi line operation
#...
val_3 = result
replace (val_1, val_2) by (val_1, val_2, val_3) in list
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
简单地说,以下代码:
f.write(u'Río Negro')
Run Code Online (Sandbox Code Playgroud)
引发以下错误:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 1: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我能做什么?
我正在使用Python 2.7.3.