I’ve always thought that composers have a radio in their heads. They hear a tune playing, then quickly grab a guitar or piano to work out the arrangement before they lose it.
You can see a glimpse of that at work here, as McCartney hums his arrangement of For No One live in the studio.
UPDATE: Reader Marek Bell points out that this is likely a scene from Give My Regards to Broad Street, made in 1984. I wonder if there’s any footage of McCartney playing this in 1966. Was this song in any of the early Beatles movies?
UPDATE2: This remains a mystery. The Broad Street version of this song is clearly different than this one. Different shirt, and in this one, McCartney’s guitar strings that emerge from the tuning pegs are uncut (wrapped in a circle). Any other clues? Leave a comment.