Your code works exactly as it should. In example a, the \n is not treated as a backslash character because it is a newline character. In example b, the extension is .mpg, which is properly removed. A file can never have more than one extension, or an extension containing a period.
To only get the bit before the first period, you could use ntpath.basename(filepath).split('.')[0]
, but this is probably NOT what you want as it is perfectly legal for filenames to contain periods.