 			 (format "python-%d-%d" sn pid)
 		       (format "python-%d" sn)))
 		 (make-temp-name "python-")))
-	 (file (expand-file-name temp py-temp-directory))
+	 (file (concat (expand-file-name temp py-temp-directory) ".py"))
 	 (cur (current-buffer))
-	 (buf (get-buffer-create file)))
+	 (buf (get-buffer-create file))
+	 shell)
     ;; Write the contents of the buffer, watching out for indented regions.
     (save-excursion
       (goto-char start)
       (let ((needs-if (/= (py-point 'bol) (py-point 'boi))))
 	(set-buffer buf)
+	(python-mode)
+	(setq shell py-which-shell)
 	(when needs-if
 	  (insert "if 1:\n"))
 	(insert-buffer-substring cur start end)))

	     ;; TBD: a horrible hack, but why create new Custom variables?
	     (arg (if (string-equal py-which-bufname "Python")
		      "-u" "")))
	(start-process py-which-bufname buf py-which-shell arg file)
	(pop-to-buffer buf)
	(py-postprocess-output-buffer buf)
	;; TBD: clean up the temporary file!


;; pdbtrack support contributed by Ken Manheimer, April 2001.

;; Please use the SourceForge Python project to submit bugs or
;; patches:
;;
;;     http://sourceforge.net/projects/python

