Go to Post I WANT to see teams succeed. - Steve W [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Spotlight this post!  
Unread 04-02-2013, 18:02
tux tux is offline
Registered User
AKA: Lee Harr
FRC #3842 (Shock-a-Bots)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Rochester, NY
Posts: 91
tux is an unknown quantity at this point
Re: Announcing a new RobotPy tool: fake-wpilib!

Quote:
Originally Posted by virtuald View Post
I am curious why you're not using a class-based approach, however.
None of our students have any programming experience. I think it is simpler to start with a function-based system.

I have introduced a decorator that sets up static variables (sort of like in C) which helps to alleviate the need for global variables that the functional style sometimes requires.


Code:
def static(**kw):
    '''
    Used to create a decorator function that will add an
    attribute to a function and initialize it.

    >>> @static(foo=5)
    ... def bar():
    ...     print(bar.foo)
    ...     bar.foo += 1
    ...
    >>> bar()
    5
    >>> bar()
    6
    '''

    def decorator(f):
        f.__dict__.update(kw)
        return f
    return decorator
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:24.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi