Object copies...
DP
pennedinil at excite.com
Mon Dec 23 02:21:48 EST 2002
Hi all,
Please help me clear my confusion here. I'm running the script below.
I'm expecting to get a listing of my original object and the new
object created by 'getdates'. Instead I'm seeing the function
'getdates' changing my original object, 'mydates'.
Q1: Why does 'getdates' not create a copy of 'mydates' instead of
operating on the original object? I.e., how do I change this behavior?
Q2: [Unrelated] I'm trying to parse these dates into d, m, y and can't
think of any other way but on a per-case basis. Any suggestions on a
better aproach? I tried -
try:
d. m, y = Dates[i].split("/")
except: ValueError ...<etc>
but there are too many exceptions to the rule, which brings me back to
a case-based algorithm.
Thanks in advance.
Dinil.
# -----------------------------------------------------------------------
def indexedList(list):
return map(None, range(len(list)), list)
def getdate(Dates):
for i, j in indexedList(Dates):
j = j.replace(".", "/")
j = j.replace("-", "/")
j = j.replace(" ", "/")
Dates[i] = j
return Dates
if __name__ == "__main__":
mydates = ['31082002','31.08.2002','31.08.2002',
'30092002','30.09.2002','30.09.2002',
'309 2' ,'30-09-2002','30-09-2002',
'318 2' ,'31.08.2002','31/08/2002',
'30092002','30-09-2002','30-09-2002',
'31082002','31-08-2002','31-08-2002',
'309 2002','30.09.2002','30.09.2002',
'318 2002','31.08.2002','31.08.2002',
'30092002','30.09.2004','' ,
'31082002','31.08.02' ,'' ,
'30092002','30.09.02' ,'30.09.2002',
'31082002','31.08.02' ,'31.08.2002',
'30092002','30.09.2002','30/9/2002' ,
'31082002','31/8/2002' ,'31/8/2002' ,
'31082002','31082002' ,'' ,
'30092002','30092002' ,'30092002' ,
'31082002','31.08.2002','31.08.2002'
]
newdates = getdate(mydates)
print newdates
print mydates
More information about the Python-list
mailing list