Latest Entries »

http://wliao.name

Lethe has been moved to http://wliao.name

rock!

The behaviour may be counterintuitive.

One might expect that “x == False” is equivalent to “not x”. Sometimes it is, sometimes it isn’t.

E.g. 0 and 0.0 are equal to False and are equivalent to False when converted to booleans:

> 0 == False
True
> not 0
True

> 0.0 == False
True
> not 0.0
True

[], “” and None aren’t equal to False but are equivalent to False when converted to booleans:

> [] == False
False
> not []
True

> “” == False
False
> not “”
True

> None == False
False
> not None
True

The boolean conversions are what’s relevant for “if x …”, “while x …”, etc.

If you want to test specifically for True, False or None, use “is” rather than an equality check. This eliminates the warning and doesn’t risk misleading someone reading the code.

只要dict在两次调用之间没有发生改变, keys()和values()将返回相应的列表, 否则无法保证序列的顺序.

Power control through Dbus

* Suspend and Hibernate are handled by DeviceKit-power

** Suspend

dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.DeviceKit.Power /org/freedesktop/DeviceKit/Power org.freedesktop.DeviceKit.Power.Suspend

** HIbernate

dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.DeviceKit.Power /org/freedesktop/DeviceKit/Power org.freedesktop.DeviceKit.Power.Hibernate

* Logout, Reboot and Shutdown are handled by gnome-session

** Logout

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1

** Reboot

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestReboot

** Shutdown

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestShutdown

** If some application is inhibiting logout/reboot/shutdown, no action will be performed and gnome-session will show a confirmation dialog.

Follow

Get every new post delivered to your Inbox.