我有几个可能保存我的数据的文件; 它们可以以不同的方式压缩,因此要打开它们我需要使用file(),gzip.GzipFile()而其他也返回文件对象(支持with接口).
我想尝试每一个,直到一个成功开放,所以我可以做类似的事情
try:
with gzip.GzipFile(fn + '.gz') as f:
result = process(f)
except (IOError, MaybeSomeGzipExceptions):
try:
with xCompressLib.xCompressFile(fn + '.x') as f:
result = process(f)
except (IOError, MaybeSomeXCompressExceptions):
try:
with file(fn) as f:
result = process(f)
except IOError:
result = "some default value"
Run Code Online (Sandbox Code Playgroud)
如果我有几十个可能的压缩变体,这显然是不可行的.(嵌套将越来越深,代码看起来总是非常相似.)
有没有更好的拼写方法?
编辑:如果可能的话,我希望process(f)除了try/except以外,以避免意外捕获在中提出的异常process(f).
我在Ubuntu VMWare虚拟机上运行Android Studio.问题是,当我尝试使用AVD模拟器运行应用程序时,我在控制台中收到以下错误:
/home/verite/Android/Sdk/tools/emulator -avd Nexus_5_API_22_x86 -netspeed full -netdelay none
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: KVM is not installed on this machine (/dev/kvm is missing).
Run Code Online (Sandbox Code Playgroud)
我试图通过这样做解决问题:
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
sudo adduser `id -un` libvirtd
sudo adduser `id -un` kvm
Run Code Online (Sandbox Code Playgroud)
并重新启动,但它不起作用.当我发出命令时:
sudo kvm-ok
Run Code Online (Sandbox Code Playgroud)
我明白了
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何解决这个问题吗?
谢谢
我RelativeLayout在底部有两个并排的按钮.我的目标是将这些按钮并排放置,但填充屏幕宽度.有人能告诉我怎么做吗?
我的布局文件是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left Button"
android:id="@+id/button"
android:layout_alignParentTop="false"
android:layout_weight="1"
android:layout_marginTop="77dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right Button"
android:id="@+id/button2"
android:layout_weight="1"
android:layout_toRightOf="@id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 当用户点击android街道时google map,是否可以突出显示街道?目前我正致力于app确定可以使用停车位的街道.
android ×2
exception ×1
google-maps ×1
kvm ×1
nested ×1
python ×1
try-except ×1
vmware ×1
xml ×1