str.partitiondoes not support regular expression, therefore, when you give it a string like - '[0-9]tr', it tries to find this exact string in testStringfor partition based, it does not use any regular expression.
According to the documentation str.partition-
sep 3-, , . , 3-, , .
, head, re.split() re, maxsplit, 1, , , str.partition. -
import re
testString = 'Tre Bröders Väg 6 2tr'
sep = '[0-9]tr'
head = re.split(sep,testString,1)[0]
-
>>> import re
>>> testString = 'Tre Bröders Väg 6 2tr'
>>> sep = '[0-9]tr'
>>> head = re.split(sep,testString,1)[0]
>>> head
'Tre Bröders Väg 6 '