236
236
os.chmod(file, stat.S_IRUSR | stat.S_IWUSR)
238
def query_user(default, prompt):
239
"""Prompts the user for a string, which is read from a line of stdin.
240
Exits silently if EOF is encountered. Returns the string, with spaces
241
removed from the beginning and end.
243
Returns default if a 0-length line (after spaces removed) was read.
246
# A default of None means the value will be computed specially, so we
247
# can't really tell you what it is
248
defaultstr = "computed"
249
elif isinstance(default, basestring):
250
defaultstr = '"%s"' % default
252
defaultstr = repr(default)
253
sys.stdout.write('%s\n (default: %s)\n>' % (prompt, defaultstr))
255
val = sys.stdin.readline()
256
except KeyboardInterrupt:
258
sys.stdout.write("\n")
260
sys.stdout.write("\n")
262
if val == '': sys.exit(1)
263
# If empty line, return default
265
if val == '': return default
268
238
def filter_mutate(function, list):
269
239
"""Like built-in filter, but mutates the given list instead of returning a
270
240
new one. Returns None."""