Re: code blocks in Python

Discussion in 'Python' started by root, Nov 25, 2003.

  1. root

    root Guest

    Python could perfectly allow this syntax directly into the
    > language, something like:
    >
    > codeblock my_codeblock:
    > x = x + 1
    > y = y + 2
    >
    > so that users won't need to explicitly call the compile() function.


    It occurs to me that you're not thinking through *why* a user uses the compile function. They use it because they have a runtime dynamic string that needs compiling. Using a codeblock as you've defined it would mean that the code pre-existed runtime (was infact programmed before runtime). This may not be true.

    For example, show me how your syntax would fix this:

    def do_functions_on_data(data):
    def mycompile(f):
    return compile(data, 'err.txt', 'exec')
    db = databaseconnection()
    functions = db.fetch_functions("WHERE Type = %d" % data.get_type())
    functions = [ mycompile(function) for function in functions ]
    return [ eval(function, locals()) for function in functions ]

    It makes certain assumptions, but it works (assuming no typos; its from memory) ... fwiw. For the confused, it fetches a list of functions that apply to the current type of data and process it with each, returning the list of results. How would your proposed code-blocks make this simpler or even be useful? That's all I'm wondering.

    --
    Michael T. Babcock
    root, Nov 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    3
    Views:
    426
    Scott Allen
    Feb 27, 2005
  2. Hung Jung Lu

    code blocks in Python

    Hung Jung Lu, Nov 22, 2003, in forum: Python
    Replies:
    20
    Views:
    1,128
    Florian Reiser
    Nov 25, 2003
  3. Microsoft

    Controls that contain code: Code Blocks Not Supported

    Microsoft, Dec 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    401
    Anthony Williams
    Dec 14, 2005
  4. matt
    Replies:
    1
    Views:
    240
    George Ogata
    Aug 6, 2004
  5. Steven Taylor
    Replies:
    9
    Views:
    236
    Brian Candler
    Apr 27, 2009
Loading...

Share This Page