'AWS S3 SDK creates folders with trailing forward slash
I have googled this extensively and not found any post commenting on this problem. Using the code below I upload a file to a path in AWS S3 which creates the new path and adds the file: BucketName + NewFolderName + FileName
However, it adds a forward slash in the path as shown below.
The screenshot below shows the code I’m using and as you can see the “BucketName” property which contains the target path does not have the trailing forward slash. Can someone please tell me why it adds this slash and how to prevent it?
Thank you.
Solution 1:[1]
Set update would update the set it was invoked on and returns None.
Solution 2:[2]
That is because python set.update() method return None. Read documentation for more details: https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset
if you want to get the addition, what you can do is,
firstset.update(secondset)
print(firstset)
because from the update function, the firstset is the set that is updated with the new values.
Solution 3:[3]
Because Python's built-in container classes mostly use command-query separation, so that methods that mutate a set return None. (An exception to this rule is pop(), which both removes and returns a set element.)
So instead of
thirdset = firstset.update(secondset)
you can write:
firstset.update(secondset)
thirdset = firstset
Or if you want to leave firstset alone, use the set union operator |:
thirdset = firstset | secondset
Solution 4:[4]
It updates the firstset. You can use | as well
firstset = {1, 2, 3}
secondset = {5, 2, 4}
firstset |= secondset
print(firstset)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simon Hawe |
| Solution 2 | user9544610 |
| Solution 3 | dan04 |
| Solution 4 | Erfun |


