|
|
|
Returns a safe copy of a variable
10
Returns a safe copy if the value argument is mutable, otherwise returns the original argument. If the feedback keyword argument is True, then a tuple is returned containing the resulting argument, and whether or not is was mutable.
#Author: Keven Dangoor
#Project: TurboGears
#File: util.py
def copy_if_mutable(value, feedback=False):
if isinstance(value, dict):
mutable = True
value = value.copy()
elif isinstance(value, list):
mutable = True
value = value[:]
else:
mutable = False
if feedback:
return (value, mutable)
else:
return value
Comments
Voting
Votes Up
ASmith
bertheymans
bobbyrward
dannyboy
elsevero
i_kenneth
Pio
RatNuShock
sundaramkumar
wiz1705




There are currently no comments for this snippet.