我想学习Python.我有一个Python 3课程.但是,我需要主要使用matplotlib和Numpy,这些库还不兼容Python 3.是否值得在Python 3中完成本课程或者浪费时间学习Python 3然后回到Python 2.x?
你会怎么做?
我在PHP中使用反射类,但我没有关于如何在反射实例中获取属性值的线索.有可能的?
代码:
<?php
class teste {
public $name;
public $age;
}
$t = new teste();
$t->name = 'John';
$t->age = '23';
$api = new ReflectionClass($t);
foreach($api->getProperties() as $propertie)
{
print $propertie->getName() . "\n";
}
?>
Run Code Online (Sandbox Code Playgroud)
如何在foreach循环中获取属性值?
最好的祝福,
我在Django Haystack 1.2.5中遇到了一些问题.我需要提升一个领域,但显然它不起作用.我正在使用Solr 1.4.1.
我的索引:
class JobsTextIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
job_title = indexes.CharField(model_attr='job_title', boost=1.50)
job_description = indexes.CharField(model_attr='job_description')
country_ad = indexes.CharField(model_attr='country_ad')
zone_ad = indexes.CharField(model_attr='zone_ad', faceted=True)
location_ad = indexes.CharField(model_attr='location_ad', faceted=True)
date_inserted = indexes.DateTimeField(model_attr='date_inserted')
def index_queryset(self):
"""Used when the entire index for model is updated."""
return JobsadsText.objects.filter(date_inserted__lte=datetime.datetime.now())
Run Code Online (Sandbox Code Playgroud)
我在job_title"boost = 1.50",但这显然不起作用,这是Solr生成的:
INFO: [core0] webapp=/solr path=/select/ params={facet=on&sort=date_inserted+desc&fl=*+score&start=0&q=arquiteto&facet.field=location_ad_exact&facet.field=zone_ad_exact&wt=json&fq=django_ct:(myapp.jobstext)&rows=20} hits=65 status=0 QTime=5
Run Code Online (Sandbox Code Playgroud)
我正在做的查询是这样的:
sqs = SearchQuerySet().facet('zone_ad').facet('location_ad').order_by('-date_inserted')
Run Code Online (Sandbox Code Playgroud)
有人能给我一些线索,让我了解Haystack Boost的工作需求吗?
最好的祝福,
更新1:我需要更加重视"job_title"字段.例如,如果我正在搜索"程序员"这个词,我首先需要显示在"job_title"字段中按"日期"排序的"程序员"的结果,然后是"程序员"字样的结果. "job_description"字段.干草堆增压是实现这一目标的正确工具吗?
我正在开发一个循环/迭代超过10,000次的PHP脚本:
foreach ($array_with_items as $item) {
// Instantiate the object
$obj_car = new CarAds($puk, 'ENG', '5');
$obj_car->detail1 = "Info about detail1";
$obj_car->detail2 = "Info about detail2";
$obj_car->detail3 = "Info about detail3";
$obj_car->detail4 = "Info about detail4";
// Saves to the database
$obk_car->save;
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我的机器内存不足.在这个foreach循环中,我该怎么做才能清理内存?
我已经使用Gunicorn + Nginx + Supervisor部署了一个Django 1.6应用程序.一切正常,但我有Gunicorn error.log一直发送错误.该文件很大,每秒都会向日志文件发送错误.
来自Gunicorn的错误.log:
2014-02-27 14:25:09 [9235] [INFO] Starting gunicorn 18.0
2014-02-27 14:25:09 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000)
2014-02-27 14:25:09 [9235] [ERROR] Retrying in 1 second.
2014-02-27 14:25:10 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000)
2014-02-27 14:25:10 [9235] [ERROR] Retrying in 1 second.
2014-02-27 14:25:11 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000)
2014-02-27 14:25:11 [9235] [ERROR] Retrying in 1 second.
2014-02-27 14:25:12 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000)
2014-02-27 14:25:12 [9235] [ERROR] Retrying …Run Code Online (Sandbox Code Playgroud) Update1:使用完整的源代码:
$html1 = '<div class="pubanunciomrec" style="background:#FFFFFF;"><script type="text/javascript"><!--
google_ad_slot = "9853257829";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';
$doc = phpQuery::newDocument($html1);
$html1 = $doc->remove('script');
echo $html1;
Run Code Online (Sandbox Code Playgroud)
源代码就是上面这个.我还读到存在一个错误,http://code.google.com/p/phpquery/issues/detail?id = 150我不知道它是否已经解决.
有关如何从此HTML中删除< script >的任何线索?
最好的祝福,
嗨,
我需要使用PhpQuery从HTML文档中删除所有< script >标记.
我做了以下事情:
$doc = phpQuery::newDocument($html);
$html = $doc['script']->remove();
echo $html;
Run Code Online (Sandbox Code Playgroud)
它不会删除< script >标记和内容.使用PhpQuery可以做到这一点吗?
最好的祝福,
我是PHPUnit的新手,我在单元测试HTML输出方面遇到了一些麻烦.
我的测试如下:
/**
* @covers Scrap::removeTags
*
*/
public function testRemoveTags() {
// Variables
$simple_parameter = 'script';
$array_parameter = array('script', 'div');
$html = '<div class="pubanunciomrec" style="background:#FFFFFF;"><script type="text/javascript"><!-- google_ad_slot = "9853257829"; google_ad_width = 300; google_ad_height = 250; //--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div><table></table>';
// Expected HTML
$expected_html_whitout_script = new DOMDocument;
$expected_html_whitout_script->loadHTML('<div class="pubanunciomrec" style="background:#FFFFFF;"></div><table></table>');
$expected_html_without_script_div = new DOMDocument;
$expected_html_without_script_div->loadHTML('<table></table>');
// Actual HTML
$actual_whitout_script = new DOMDocument;
$actual_whitout_script->loadHTML($this->scrap->removeTags($html, $simple_parameter));
$actual_without_script_div = new DOMDocument;
$actual_without_script_div->loadHTML($this->scrap->removeTags($html, $array_parameter));
// Test
$this->assertEquals($expected_html_whitout_script, $actual_whitout_script);
$this->assertEquals($expected_html_without_script_div, $actual_without_script_div);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是DOMDocument对象生成一些HTML代码,我无法比较它.如何打印DOMDocument对象以查看输出?有关如何比较HTML的任何线索?
对不起,我的英语不好.
最好的祝福,
我正在设计一个数据库,我对在关系数据库中使用Hierarchical数据模型有一些疑问.
如果我想处理类别,子类别和父类别,是否可以不在关系数据库中使用分层数据模型?换句话说,可以使用关系做事方式处理类别,子类别和父类别?
顺便说一下,我正在使用PostgreSQL.
对不起,我的英语不好.
最好的祝福,
我正在使用Django 1.4而我正在努力使用Formsets.我已经阅读了文档和很多SO问题.我已经找不到他们如何工作的线索了.
- Fomsets应该像这样配置/ dclared?
我如何在forms.py和views.py中设置formset.
forms.py :(我已经声明了一个forms.Form)
class BicycleAdItemKindPropertyValueForm(forms.Form):
bicycleaditemkindpropertyvalue = forms.ChoiceField()
Run Code Online (Sandbox Code Playgroud)
views.py:
def submit_ad_view(request):
# This class is used to make empty formset forms required
class BicycleAdItemKindPropertyValueFormSet(BaseFormSet):
def __init__(self, *args, **kwargs):
super(BicycleAdItemKindPropertyValueFormSet, self).__init__(*args, **kwargs)
for form in self.forms:
form.empty_permitted = False
def clean(self):
pdb.set_trace()
for form in self.forms:
None
#form.fields['bicycleaditemkindpropertyvalue']
formsetBicycleAdItemKindPropertyValue = formset_factory(BicycleAdItemKindPropertyValueForm, formset=BicycleAdItemKindPropertyValueFormSet)
if request.method == 'POST':
model_main = Main()
model_main.section = Section.objects.get(pk=request.POST['section'])
model_main.user = request.user
model_bicyclead = BicycleAd()
model_bicyclead.bicycleadtype = BicycleAdType.objects.get(pk=2) #1-Ad Link, 2-Ad Insite. Em …Run Code Online (Sandbox Code Playgroud) 我已经用纯 python 编写了一些类,但现在我需要在 django 视图中使用这些类。
my_custom_classes.py
class RetryException(Exception):
...
...
class Trade():
def __init__(self):
...
...
def some_other(self, id):
...
...
Run Code Online (Sandbox Code Playgroud)
例如,我需要调用“some_other(self, id)”内的 django 模型。
组织这些自定义类以在 Django 视图中使用的最佳方式是什么?
此致,
django ×4
html ×2
php ×2
python ×2
django-forms ×1
django-views ×1
get ×1
gunicorn ×1
matplotlib ×1
nginx ×1
numpy ×1
phpquery ×1
phpunit ×1
postgresql ×1
python-3.x ×1
reflection ×1
solr ×1
solr-boost ×1
supervisord ×1
unit-testing ×1