Apr-29-2017, 09:36 PM
Hi people,
I was just checking out some code from the standard library from python 3.6.1. This specific piece of code is ftplib.py and is meant to replace some piece of a string. From the function I understand the string should be something like "pass yourpasswordhere". Every letter from "yourpasswordhere" should be replaced with an *, pretty clear. Only thing I wonder about is what's the reason for the s[i:] in the and at the last s = statement? Seems to me it has no function? Thank you for reading :)
I was just checking out some code from the standard library from python 3.6.1. This specific piece of code is ftplib.py and is meant to replace some piece of a string. From the function I understand the string should be something like "pass yourpasswordhere". Every letter from "yourpasswordhere" should be replaced with an *, pretty clear. Only thing I wonder about is what's the reason for the s[i:] in the and at the last s = statement? Seems to me it has no function? Thank you for reading :)
# Internal: "sanitize" a string for printing def sanitize(self, s): if s[:5] in {'pass ', 'PASS '}: i = len(s.rstrip('\r\n')) s = s[:5] + '*'*(i-5) + s[i:] return repr(s)