PEP-ping Python Examples


(IVELIN PEYCHEV) #1

Is it just me or other also think <> in IronPython examples in RhinoCommon to be very weird looking.

I’m not a programmer but I’ve always used != and if I haven’t used DS scripting language EKL I wouldn’t have ever known what <> is.

e.g.: (I’ll skip focusing on the two space_char indentation cuz that was already discussed)
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_RhinoObject_DuplicateGeometry.htm


from System import *
from Rhino import *
from Rhino.Commands import *
from Rhino.DocObjects import *
from Rhino.Input import *
from scriptcontext import doc

def RunCommand():

  rc, obj_ref = RhinoGet.GetOneObject("Select object to duplicate", False, ObjectType.AnyObject)
  if rc <> Result.Success:
    return rc
  rhino_object = obj_ref.Object()

  geometry_base = rhino_object.DuplicateGeometry()
  if geometry_base <> None:
    if doc.Objects.Add(geometry_base) <> Guid.Empty:
      doc.Views.Redraw()

  return Result.Success

if __name__ == "__main__":
  RunCommand()

(Steve Baer) #2

Can you point me to the pep that you are referring to?


(IVELIN PEYCHEV) #3

I’m a script kiddie, my PEP is all the code snippets I’ve read and used my entire scripting life.

I have never seen <> used in Python. I’ve used it in DS.EKL because that’s the only (Not equal) sign there.


(IVELIN PEYCHEV) #4

Another thing here in this example Steve.

from System import *
from Rhino import *
from Rhino.Commands import *
from Rhino.DocObjects import *
from Rhino.Input import *
from scriptcontext import doc

def RunCommand():

    rc, obj_ref = RhinoGet.GetOneObject("Select object to duplicate", False, ObjectType.AnyObject)

Can you tell me where RhinoGet.GetOneObject() is coming from when libraries are imported with * (asterisk)


(IVELIN PEYCHEV) #5

Little research in stack overflow:


It was taken from ABC (python’s predecessor) see here:
“”
I believe ABC took it from Pascal, a language Guido began programming with.

It has now been removed in Python 3. Use != instead.
“”

So in Python examples there are notations taken from Pascal -> one of the dead languages.


#6

Basically it’s coming from Rhino.Input*… * means import ALL the modules in this class.

This also makes me scream, it’s totally counterproductive, it’s difficult to learn anything from the examples that way. :rage:

–Mitch


#7

Not quite…
<> is used in vbscript/vb.net/Rhinoscript to designate not equal to…

so in this case it’s probably just a bad “translation”.


(IVELIN PEYCHEV) #8

Yeah I know what it means but because I use it with another language. Never seen it in Python examples, ever.


(Steve Baer) #9

I added this to our bugtracker at
https://mcneel.myjetbrains.com/youtrack/issue/RH-49811


#10

100%. Never use wildcard imports unless you know every variable name which is now occupied. Writing out the full namespace may look like its more typing, but you get autocomplete and learn where the used methods are located. I think the reason why the help is using this is that it was easier to port the code from C# to Python.

_
c.


#11

Well, unfortunately, this means that someone needs to go through every method that has an example and fix the stuff if necessary - that sounds like days and days worth of work. Who’s going to do it?


#12

Sounds scriptable :wink:

_
c.


(IVELIN PEYCHEV) #13

In the previous thread that I created about the two-spaced indentation I think Alain was up to the task and he said there was an automated way to do that.


(Alain Cormier) #14

I did clean up the indentation problem in the rss api samples with the help of a script. This will be more work but I’ll take the same approach