Results 1 to 3 of 3

Thread: Python: repr() of Slice structs/classes

  1. #1
    cebix is offline Registered User
    Name: Christian Bauer
    Organization: AREVA NP
    Project: Diagnostics frontend for industrial I&C
    Join Date
    Jun 2007
    Location
    Erlangen, Germany
    Posts
    10

    Python: repr() of Slice structs/classes

    Consider this Slice definition:
    Code:
    struct Employee {
      long number;
      string firstName;
      string lastName;
    };
    In Python, the repr() of an object of this type yields
    Code:
    {
        number = 42
        firstName = Christian
        lastName = Bauer
    }
    which looks nice (apart from the fact that the structure type name is not included) but can't be fed into eval() as it should be. I would expect something like
    Code:
    Employee(42, 'Christian', 'Bauer')
    or
    Code:
    Demo.Employee(number=42, firstName='Christian', lastName='Bauer')
    Same for Slice classes.

  2. #2
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    Hi Christian,

    Welcome to the forum.

    Technically you're right, the Python docs indicate that repr should return a valid Python expression "if at all possible". We currently do not follow this guideline because of the complexity that would be involved in handling object graphs, and in particular circular references.

    Is the current Ice behavior having an adverse impact on your application?

    Best regards,
    Mark

  3. #3
    cebix is offline Registered User
    Name: Christian Bauer
    Organization: AREVA NP
    Project: Diagnostics frontend for industrial I&C
    Join Date
    Jun 2007
    Location
    Erlangen, Germany
    Posts
    10
    Quote Originally Posted by mes View Post
    Is the current Ice behavior having an adverse impact on your application?
    We do not depend on repr()-eval()-consistency, but having classes show up in the same way as they are input is less confusing for users writing scripts who know about Python but not about Slice (they're not supposed to). Plus, it's super-convenient to be able to copy-and-paste output to input in an interactive Python session.

    My current workaround is to overwrite the __repr__() methods of the (relevant) classes in a wrapper module.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mapping Slice structs to C# structs
    By kwaclaw in forum Comments
    Replies: 4
    Last Post: 09-10-2007, 10:42 PM
  2. Feature Request: partial classes / structs in .net
    By programmerdad in forum Comments
    Replies: 2
    Last Post: 08-09-2006, 10:24 PM
  3. Latency: structs vs. classes
    By n2503v in forum Help Center
    Replies: 7
    Last Post: 10-09-2005, 12:08 AM
  4. C#: Attributes with Ice generated classes and structs
    By DeepDiver in forum Help Center
    Replies: 2
    Last Post: 07-23-2005, 02:16 AM
  5. Replies: 1
    Last Post: 01-25-2005, 07:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •