Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: code blocks in Python

Reply
Thread Tools

Re: code blocks in Python

 
 
root
Guest
Posts: n/a
 
      11-25-2003
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Methods and blocks - not that clear when blocks passed into Steven Taylor Ruby 9 04-27-2009 08:46 AM
Controls that contain code: Code Blocks Not Supported Microsoft ASP .Net Building Controls 1 12-14-2005 03:14 PM
"Building Blocks" are "Application Blocks" Arjen ASP .Net 3 02-27-2005 01:06 AM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM



Advertisments