Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Utilities

    Safestruct 1.0

    Download button

    Downloads: 410  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Good (3.0/5)
    3 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Andrew Sterian | More programs
    GPL / FREE
    November 21st, 2007, 20:41 GMT
    ROOT / Utilities

     Read user reviews (0)  Refer to a friend  Subscribe

    Safestruct description

    Safestruct serves as a base class for any class that wants to protect its members from misspelling.

    Safestruct serves as a base class for any class that wants to protect its members from misspelling.

    Since Python allows adding attributes to a class object at runtime, it is a simple mistake to assign to a non-existent attribute somewhere in your code, inadvertently creating a new attribute, and quietly introducing an error that may be very hard to find.

    The Safestruct class traps all accesses to your class and raises an exception when an assignment is made to a non-existent attribute.

    This class traps accesses to attributes and raises an exception when an assignment to a non-previously-existing attribute is performed. The idea is that of a "safe structure", as in C++ where each member of a class is declared at compile time and assignments to non-existent members cannot be made at run time. The safe structure guards against programming errors wherein attribute names are mispelled, leading to quiet runtime errors.

    There are two classes defined here, TrappingStruct and NontrappingStruct. Both present the same interface but the latter does no attribute checking. It is meant to be used once the code is debugged, since it is faster.

    The SafeStruct member is either set equal to TrappingStruct or NontrappingStruct (possibly by the SetDebug function) to easily switch from safe accesses to faster accesses by just changing one thing in one file.

    See the test code at the bottom for example usage.

    Product's homepage

      


    TAGS:

    protect members | misspelling words | Python class | protect | members | misspelling

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM