Created
October 25, 2019 19:15
-
-
Save jonmorehouse/2c773e66ba37fc3b324e940a0ad707b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uri = '/httpbin/headers' | |
# we want to strip the `/httpbin` off the front | |
new_uri = uri.lstrip('/httpbin') | |
# this returns 'eaders' because it treats the input into lstrip as a set of characters to strip. So it strips all of | |
# those characters until it finds something that is not in one of those (e) | |
# now, let's try with something more predictable | |
uri = '/httpbin/status' | |
# this returns status, as expected! | |
new_uri = uri.lstrip('/httpbin') | |
# to properly split this, we need to use regex: | |
uri = '/httpbin/headers' | |
new_uri = re.sub(r'^/httpbin', '', uri) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment