According to an interview with Moffat, he wrote the episode before the election, but filmed it afterward, and he wrote a note in the script that he didn't know whether the President should be a man or a woman, but they'd know by the time they were shooting.