(with-input-file (in "myfile.txt") (do-something in))
In Python, this might look like
withInputFile in "myfile.txt": doSomething(in)
(hey, I told you I was rusty on my Python...especially my totally made up Python!)
So maybe the feature came built-in to Python, in which case you're lucky--Guido happened to decide to implement this feature. But what if he hadn't? Well, just write your own abstraction. Obviously, Python can open files and do stuff with the file's contents. So it seems logical that you should be able to create an abstraction which saves you from writing the same boilerplate that you do every time you open an input file. Unfortunately, there are some abstractions that *you just can't write* in most languages (including Python). This file open example is a good one. Here's another example, in the form of a programming challenge:
In Python, create an abstraction called "debugExpr" that consumes an expression E, and then does two things: 1) prints "Expression E = V", where E is the given expression, and V is the value E evaluates to. 2) returns the value V.
For example,
%python% 6 * debugExpr(2+3)
Expression 2+3 = 5
30
I'm betting you can't implement debugExpr in Python. So assuming Guido didn't extend the language to implement this feature, you're pretty much SOL. It's a shame because debugExpr, I think, is pretty darn useful. It means that you can take any expression in your code and "inspect it", without worrying about adjusting the structure of your program, and without affecting its semantics. Without debugExpr, I'd have to change my example code to be something like this to get the same result:
print "Expression 2+3 ="
tmp = 2+3
print tmp
6 * tmp
YUCK!
def foo(x): return 2 times (x + 3)
> foo(1)
8
(not a full version of debugExpr, but enough to test:)
def debugExpr(expr): print "Expr is " + expr return eval(expr)
def bar(x): return 2 times debugExpr('x + 3')
> bar(1)
Expr is x + 3
Traceback (most recent call last):
File "", line 1, in ?
File "", line 2, in bar
File "", line 3, in debugExpr
File "", line 0, in ?
NameError: name 'x' is not defined
PS: I couldn't use the asterisk symbol in the post, so I used 'times' instead.