Domanda

this is pretty trivial, but it's bugging me and I thought I'd throw it out there.

the python netaddr library is great. I'm using it for a bunch of things, including IP address validation. To do that, I use something like

try: 
    ddd = IPRange(split[0], split[1])
except:
    return False

And that works great but PEP8 hates that I'm creating 'ddd' but never using it. Is there another, better, cleaner way to do this? Thanks

È stato utile?

Soluzione

If you don't need the "ddd" variable, then don't declare/assign it. If it's a module variable that could be used from another modules, you can not really avoid it. I would advise you to add a comment to explain why this variable is alone in the module.

Moreover it's considered bad practice to have a bare except:, you should use at least except Exception:

It's in PEP8 too:

When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top