[Tutor] Variable name containing '-'

Steven D'Aprano steve at pearwood.info
Fri Sep 1 20:04:06 EDT 2017


On Fri, Sep 01, 2017 at 01:48:06PM -0700, ramakrishna reddy wrote:
> Hi there,
> 
> I am implementing a soap webservice where a method which has keyword
> parameter(named:abc-xyz) needs to be used to call third party app.

Just because your webservice offers a parameter called "foo" doesn't 
mean your Python code has to use the same name "foo". Pick a different 
name.

Or change your webservice to use abc_xyz instead.

> eg: obj.method(abc-xyz=10)
> 
> As python does not support '-' in variable names, I am a bit confused.
> I know in case of methods we can use getattr(self.object, 'method-name')()
> can be used. But in case of variable how we can use ?

It is an accident that getattr(self.object, 'method-name') works. You 
cannot rely on it, it is not supported by the language, and although it 
works today it may not work in the future.



-- 
Steve


More information about the Tutor mailing list