Python Detect End Of String