我对Python中的用户定义异常以及如何在完整项目中组织它们有一些疑问.
我有一个相当复杂的python项目,其中包含一些具有以下结构的子包(__init__.py省略):
/docs (Documentation)
/apidocs (generated API documentation)
/askindex (my application package)
/test (Unit tests directory)
test_utils.py
... (more tests)
/workers (various worker classes)
communicators.py
processes.py
threads.py
utils.py
main.py (contains the starting point)
data_objects.py (various objects used all around the application)
settings.py (settings of the application)
README.txt
Run Code Online (Sandbox Code Playgroud)
我想实现我自己的Exception,在'workers'包的模块中使用它们来解决特定的错误.
我应该在哪里放置这些例外?我知道我应该拥有自己的基本异常,它将标准Exception类子类化,并将其子类化为其他异常.我应该在"工人"下创建一个新的"例外"模块吗?将异常类放在它们被引发的模块中?在这种情况下,我应该在哪里放置我的基类?我的申请结构是否适用?
我不熟悉Python中的异常,所以如果答案很明显,请原谅我...
我在应用程序中有一些CPU绑定的任务,我想使用多处理模块来使用多核处理器.我承担了一项重大任务(视频文件分析),并将其拆分为几个较小的任务,这些任务被放入队列并由工作进程完成.我想知道的是如何从这些工作进程向主进程报告进度.例如,我需要他们发送"我在1000分钟的文件1分析".进行此类进度报告的最佳方法是什么?
我正在使用支持库22.1.1.我的目标是为自定义RatingBar着色,以避免在我的APK中包含多个图像.
着色在API 22上正确应用,但在API 19上没有.我希望它能在API> = 16上工作.请注意,我只是尝试着色"进度",而不是完整的条.
这是RatingBar风格:
<style name="customRatingBar" parent="Widget.AppCompat.RatingBar">
<item name="android:progressDrawable">@drawable/custom_ratingbar</item>
<item name="android:minHeight">24dp</item>
<item name="android:maxHeight">24dp</item>
<item name="android:progressTint">@color/md_red_700</item>
<item name="android:secondaryProgressTint">@color/md_red_700</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和custom_ratingbar.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/ic_heart_outline_grey600_24dp" />
<item android:id="@android:id/progress"
android:drawable="@drawable/ic_heart_grey600_24dp" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)
它在我的布局中以这种方式应用,它在一个片段中扩展android.support.v4.Fragment自己在一个活动扩展中android.support.v7.app.AppCompatActivity:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="22dp"
android:id="@+id/checkin_rating"
style="@style/customRatingBar"
android:isIndicator="true"
android:numStars="5"
android:stepSize="1"
android:layout_marginBottom="8dp"/>
Run Code Online (Sandbox Code Playgroud)
我从lint工具得到一个警告,说android:progressTintAPI <21不支持.有没有办法在不使用多个drawable的情况下实现这个目的?
我想在表单元素中有一个来自DB的数据表,如下所示:
+-----+-------------------------+-----------------------+
| | Number | Name |
+-----+-------------------------+-----------------------+
| [ ] | 123 | ABC |
+-----+-------------------------+-----------------------+
| [x] | 456 | DEF |
+-----+-------------------------+-----------------------+
| [x] | 789 | HIJ |
+-----+-------------------------+-----------------------+
Run Code Online (Sandbox Code Playgroud)
它允许选择多行,如MultiCheckBox元素.
这是我想要的标记:
<table>
<thead>
<tr>
<th>Select</th>
<th>Number</th>
<th>Name</th>
</tr>
</thead>
<tr>
<td><input type="checkbox" name="subscribers[]" value="1234"></td>
<td>1234</td>
<td>ABC</td>
</tr>
<tr>
<td><input type="checkbox" name="subscribers[]" value="375950"></td>
<td>375950</td>
<td>DEF</td>
</tr>
<!-- and so on... -->
Run Code Online (Sandbox Code Playgroud)
我可以手工完成,但使用Zend_Form可以填充表单,轻松检索值并进行验证.我的表格中还有其他正常元素.
有关如何使用Zend_Form实现这一点的任何想法?也许是自定义元素和装饰器?
谢谢.如果需要,请询问更多信息.
这个问题似乎是相关的:Zend_Form:带有复选框的HTML表格中的数据库记录
渣