So I have a csv file that contains full credit-card numbers.. We dont need the full number, and so I am writing a quick script to parse through the csv and replace the cc number with a masked representation. (all *'s except the last four). I am pretty new to python and hacked this up, and it works, but in order to learn I want to know if it could be done easier.
Assume that "str" will be a full creditcard number. But for the sake of my example I am just using the string "CREDITCARDNUMBER".
str = "CREDITCARDNUMBER";
strlength = len(str)
masked = strlength - 4
slimstr = str[masked:]
print "*" * masked + slimstr
The output is exactly what I want
************MBER
But I am sure there is a more elegant solution. :) Thanks!