[MERGE] Using NetworkManager
Robert Collins
robertc at robertcollins.net
Sun Feb 4 08:48:40 GMT 2007
On Sat, 2007-02-03 at 18:37 +0100, Wouter van Heyst wrote:
>
> > +try:
> > + import dbus
> > + import dbus.glib
> > + bus = dbus.SystemBus()
> > + proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
> > + '/org/freedesktop/NetworkManager')
> > + dbus_iface = dbus.Interface(proxy_obj,
> 'org.freedesktop.NetworkManager')
> > + have_nm = True
> > +except ImportError:
> > + have_nm = False
> > +
A better way of writing this is:
try:
import dbus.glib
except ImportError:
have_nm = False
else:
bus = dbus.SystemBus()
proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
'/org/freedesktop/NetworkManager')
dbus_iface = dbus.Interface(proxy_obj, 'org.freedesktop.NetworkManager')
have_nm = True
this way, only the import statements are in the 'except ImportError' guard.
Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070204/a6eca045/attachment.pgp
More information about the bazaar
mailing list