Aug-16-2017, 04:39 PM
Without knowing what
Also, I added a count parameter to service.ref.replace, so that only the first 4097 found will be replaced. That way, if the tag happens to look like "4097:1:4097:23", it won't be changed to "1:1:1:23".
service
is, we should assume it's an object, and ref
is just a property of that object. We can fake it like so:>>> class Service: ... def __init__(self, tag): ... self.ref = tag ... >>> service = Service("4097:1:5:23") >>> service.ref '4097:1:5:23'If that's true (...and it might not be), then we could take the fact that strings are immutable in python, and work with it directly...
>>> service.ref.startswith("4097:") True >>> new_tag = service.ref.replace("4097:", "1:", 1) >>> service.ref '4097:1:5:23' >>> new_tag '1:1:5:23'Because strings are immutable, we have the new tag that we wanted (with 4097 replaced with 1), while service.ref is left unchanged.
Also, I added a count parameter to service.ref.replace, so that only the first 4097 found will be replaced. That way, if the tag happens to look like "4097:1:4097:23", it won't be changed to "1:1:1:23".