python是否有一些未定义的变量/调试模式,它将输出通知/警告?
PHP允许您修改error_reporting以打开通知警告,这意味着要做
<?php
echo $foo;
Run Code Online (Sandbox Code Playgroud)
将在第2行抛出一个"Undefined variable foo .......
python有类似的东西吗?
我有一个我正在做的错误
db.connect
Run Code Online (Sandbox Code Playgroud)
代替
db.connect()
Run Code Online (Sandbox Code Playgroud)
我希望python会抛出一个未定义的变量连接...
你能提高python中的错误报告级别或类似程度吗?
我得到了这个div ...
<div tabindex="0" class="button-base inline-block button aw-btn button-base-active">
<input type="text" tabindex="-1" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow-x: hidden; overflow-y: hidden; position: absolute; ">
</div>
Run Code Online (Sandbox Code Playgroud)
在我的页面中间,它没有ID,我无法编辑HTML页面,我也无法使用jQuery.还试图用IE7和IE8做到这一点.
梦魇在这里:)
解决方案是document.getElementsByClassName,但不是ie7和ie8兼容.
这个div埋藏在大约10个div中,所有这些都是类似的风格,没有id等等.这个div的类是独一无二的!
我能看到的唯一解决方案是获取所有div并循环查找hasAttriutes类似.
谁有更好的主意?
在这个项目我捅,(我是PHP开发,而不是RoR),在模态上有这个功能.
def task
@task ||= if search_key
Project.trop_fish.tasks.find(:first, :conditions => ["description like ?", "Search key: #{search_key}%"])
else
Project.trop_fish.tasks.find(:first, :conditions => ["(name = ? OR name like ?)","#{task_name}","#{task_name} {%}"])
end
end
Run Code Online (Sandbox Code Playgroud)
所以它试图从名为trop_fish的项目中找到一项任务.但最重要的是@task.
是吗,将if块的查找结果分配给@task?
它是一样的吗?
def task
if search_key
@task = Project.trop_fish.tasks.find(:first, :conditions => ["description like ?", "Search key: #{search_key}%"])
else
@task = Project.trop_fish.tasks.find(:first, :conditions => ["(name = ? OR name like ?)","#{task_name}","#{task_name} {%}"])
end
end
Run Code Online (Sandbox Code Playgroud) 我有一个函数,我称之为progarm,有一些args并希望得到结果.
当我使用以下内容时
proc = subprocess.call(["fetch.py", "--cookies=/tmp/tmp-cookies"], stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
return stdout
Run Code Online (Sandbox Code Playgroud)
该应用程序只是挂起.但是,如果我跑
return subprocess.call(["fetch.py", "--cookies=/tmp/tmp-cookies"])
Run Code Online (Sandbox Code Playgroud)
然后我在屏幕上得到输出,应用程序工作正常,但我需要将输出转换为函数.
我使用的是python 2.6.1,无法使用check_output
使用urllib2并尝试获取https页面,它始终失败
Invalid url, unable to resolve
Run Code Online (Sandbox Code Playgroud)
网址是 https://www.domainsbyproxy.com/default.aspx, 但我在多个https网站上发生了这种情况.
我使用的是python 2.7,下面是我用来设置连接的代码
opener = urllib2.OpenerDirector()
opener.add_handler(urllib2.HTTPHandler())
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
opener.addheaders = [('Accept-encoding', 'gzip')]
fetch_timeout = 12
response = opener.open(url, None, fetch_timeout)
Run Code Online (Sandbox Code Playgroud)
我手动设置处理程序的原因是因为我不想处理重定向(工作正常).以上工作适用于http请求,但https - 失败.
有线索吗?
我得到了一个jpeg图像,其中1020x780,我试图将其调整为111x85(这是比例),但它出现像素化.
我只是尝试过
a)将图像分配给TImage组件并设置Scaled/Resize属性.
b)这里的调整大小代码http://www.delphigroups.info/2/4/313095.html
c)这里的调整大小代码http://www.swissdelphicenter.ch/torry/showcode.php?id=1896
然而,他们都出现像素化.
如果我在Photoshop中调整大小,那就好了.获得好处将是理想的,但是我知道他们花了很多时间/代码来调整大小,所以甚至中间的东西也会很棒.
有什么建议?
使用我的python应用程序,我有40个模块(类),其中包含一些文本的解析器.在我的函数中,我只想实现并使用特定的模块.这些都在数据库中排序.
我现在知道我的解析器,并且有我要导入和创建的python文件名和类
但是......你怎么在python中实际做到这一点?
例如;
file_name = 'lex_parser'
class_name = 'LexParser'
Run Code Online (Sandbox Code Playgroud)
我能怎么做....
from {file_name} import {class_name}
Parser = {class_name}()
Run Code Online (Sandbox Code Playgroud)
按照我的意思?