hyphen

30 views
Skip to first unread message

MA07

unread,
Dec 7, 2017, 1:25:14 PM12/7/17
to Python Programming for Autodesk Maya
hello,
I already google it .however.couldn't really understand why people use hypen like this.

sectionWidth=cmds.gettattribute()

cmds.move(-sectionWidth) <---- in this case.

Justin Israel

unread,
Dec 7, 2017, 1:42:17 PM12/7/17
to python_in...@googlegroups.com
It has the same meaning in basic math. It negates a numeric value. 

x = 1
y = -x          # -1
y = -1 * x    # -1

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1fe39550-331d-4945-b7bc-da6a46fdc000%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

MA07

unread,
Dec 9, 2017, 9:13:09 AM12/9/17
to Python Programming for Autodesk Maya


On Thursday, December 7, 2017 at 6:42:17 PM UTC, Justin Israel wrote:


On Fri, Dec 8, 2017, 7:25 AM MA07 <amirahsya...@gmail.com> wrote:
hello,
I already google it .however.couldn't really understand why people use hypen like this.

sectionWidth=cmds.gettattribute()

cmds.move(-sectionWidth) <---- in this case.

It has the same meaning in basic math. It negates a numeric value. 

x = 1
y = -x          # -1
y = -1 * x    # -1

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



no i mean underscore..so sorry  .for example ,    _skyscrapper..      _width    .why & when to they use it ..

Paul Molodowitch

unread,
Dec 9, 2017, 12:53:31 PM12/9/17
to python_in...@googlegroups.com
Underscores at the start of a variable name are a coding / style convention - they generally indicate variables that are supposed to be private or internal.  As an end user, you're not "supposed to" access / use such variables / methods / etc directly - they're there to be used by the class / api writer maintainer for internal tasks.  This generally only applies to class member, variables - so, "self._sectionWidth".  Sometimes you'll see it with module-level variables, though. (There's really no point in doing it with variables inside of a function, though, as they already can't be used outside of that function.)

Having said that, though, since python doesn't have any "formal" privacy levels / protections built into the language itself, you can still use them if you have to.  In general, I would say avoid using them if you can (at the least, try to check if there's other ways to do what you need to do... it, if there's a "_width" data member, see if there's a "width()" or "getWidth()" function, or perhaps a "width" property that you can use instead) - but if there's no other way to do what you need to do, then go for it. Just be aware that if you DO use such variables, though, you're opening yourself up to future breakage - ie, the name / usage of any such members may change abruptly without any notice.

On Sat, Dec 9, 2017 at 6:13 AM MA07 <amirahsya...@gmail.com> wrote:


On Thursday, December 7, 2017 at 6:42:17 PM UTC, Justin Israel wrote:


On Fri, Dec 8, 2017, 7:25 AM MA07 <amirahsya...@gmail.com> wrote:
hello,
I already google it .however.couldn't really understand why people use hypen like this.

sectionWidth=cmds.gettattribute()

cmds.move(-sectionWidth) <---- in this case.

It has the same meaning in basic math. It negates a numeric value. 

x = 1
y = -x          # -1
y = -1 * x    # -1

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
no i mean underscore..so sorry  .for example ,    _skyscrapper..      _width    .why & when to they use it ..

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0409ba95-d7ef-414e-b574-ad8d07e6c555%40googlegroups.com.

Andres Weber

unread,
Dec 9, 2017, 2:46:05 PM12/9/17
to Python Programming for Autodesk Maya
Near the bottom of this PEP you'll see it and maybe it will clear up a few others you might not know about!
https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles



On Saturday, December 9, 2017 at 12:53:31 PM UTC-5, elrond79 wrote:
Underscores at the start of a variable name are a coding / style convention - they generally indicate variables that are supposed to be private or internal.  As an end user, you're not "supposed to" access / use such variables / methods / etc directly - they're there to be used by the class / api writer maintainer for internal tasks.  This generally only applies to class member, variables - so, "self._sectionWidth".  Sometimes you'll see it with module-level variables, though. (There's really no point in doing it with variables inside of a function, though, as they already can't be used outside of that function.)

Having said that, though, since python doesn't have any "formal" privacy levels / protections built into the language itself, you can still use them if you have to.  In general, I would say avoid using them if you can (at the least, try to check if there's other ways to do what you need to do... it, if there's a "_width" data member, see if there's a "width()" or "getWidth()" function, or perhaps a "width" property that you can use instead) - but if there's no other way to do what you need to do, then go for it. Just be aware that if you DO use such variables, though, you're opening yourself up to future breakage - ie, the name / usage of any such members may change abruptly without any notice.

On Sat, Dec 9, 2017 at 6:13 AM MA07 <amirahsya...@gmail.com> wrote:


On Thursday, December 7, 2017 at 6:42:17 PM UTC, Justin Israel wrote:


On Fri, Dec 8, 2017, 7:25 AM MA07 <amirahsya...@gmail.com> wrote:
hello,
I already google it .however.couldn't really understand why people use hypen like this.

sectionWidth=cmds.gettattribute()

cmds.move(-sectionWidth) <---- in this case.

It has the same meaning in basic math. It negates a numeric value. 

x = 1
y = -x          # -1
y = -1 * x    # -1

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
no i mean underscore..so sorry  .for example ,    _skyscrapper..      _width    .why & when to they use it ..

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages