Subject: 23.3; python.el code execution does not add the buffers directory to the pythonpath.

From: Arne Babenhauserheide <[email-masked]>
Date: Wed, 30 Nov 2011 11:39:24 +0100

When calling python-send-buffer, the behaviour of the code differs
from actual code execution, because the parent directory of the file is
not in the PYTHONPATH. 

To change this, the sending of a buffer can be adapted to the following: 

;; pymacs with in-folder module loading for buffers which have assossiated files.
(defun python-send-buffer ()
  "Send the current buffer to the inferior Python process."
  (interactive)
  (python-send-string (concat "__file__ = '" (buffer-file-name) "'
import sys
import os.path
sys.path.append(os.path.dirname(__file__))
"))
  (python-send-region (point-min) (point-max)))

Better would be to check first if there is an assossiated filename and
only send the path-adaption in that case.

Best wishes, 
Arne

In GNU Emacs 23.3.3 (x86_64-pc-linux-gnu, GTK+ Version 2.24.4)
 of 2011-09-30 on imknbabb
Windowing system distributor `The X.Org Foundation', version 11.0.11004000
configured using `configure  '--prefix=/usr' '--build=x86_64-pc-linux-gnu' '--host=x86_64-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' '--libdir=/usr/lib64' '--program-suffix=-emacs-23' '--infodir=/usr/share/info/emacs-23' '--with-crt-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../lib64' '--with-gameuser=games' '--without-hesiod' '--with-kerberos' '--with-kerberos5' '--with-gpm' '--with-dbus' '--with-sound' '--with-x' '--without-ns' '--without-gconf' '--with-toolkit-scroll-bars' '--with-gif' '--with-jpeg' '--with-png' '--with-rsvg' '--with-tiff' '--with-xpm' '--with-xft' '--with-libotf' '--with-m17n-flt' '--with-x-toolkit=gtk' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=x86_64-pc-linux-gnu' 'CFLAGS=-march=native -O2 -pipe -fno-strict-aliasing' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: C
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: de_DE.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8
  default enable-multibyte-characters: t

Major mode: Tm5rc

Minor modes in effect:
  shell-dirtrack-mode: t
  display-time-mode: t
  kde-default-keys-minor-mode: t
  global-ethan-wspace-mode: t
  real-global-auto-complete-mode: t
  global-auto-complete-mode: t
  auto-complete-mode: t
  nyan-mode: t
  global-rudel-minor-mode: t
  savehist-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  global-visual-line-mode: t
  visual-line-mode: t
  transient-mark-mode: t

Recent input:
<next> <next> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <up> <up> <right> <right> <return> C-x C-s C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-x 
C-s <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> C-x C-s C-s s e a r C-g b f C-g 
C-g b f m e t <return> C-s e <backspace> s e a r C-s 
C-s C-s C-g C-g b f c o l <return> C-s s e a r <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <end> <prior> <down> <down> <up> <up> 
<C-right> <C-right> <C-right> <right> <right> <right> 
<right> <right> <right> <right> $ { m e . m e t e o 
. d i r } SPC C-x C-s <up> <up> <up> <up> <up> <up> 
<right> <up> <up> <up> <up> <end> <left> <left> <left> 
C-SPC <M-left> <M-left> <M-right> <M-right> <M-left> 
M-w b f <return> <next> <prior> <prior> <prior> C-r 
c o a r i C-g C-g c <backspace> z s b f <right> <right> 
<return> <up> <up> <up> <up> <home> <help-echo> C-s 
m e . m e t C-s C-s C-s C-g C-g x 1 b f <right> <return> 
C-s <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <left> <backspace> y s z a <backspace> 
z s <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <end> C-SPC <home> C-w 
<backspace> C-x C-s <down-mouse-1> <mouse-1> M-x r 
e p o <tab> r <tab> <return>

Recent messages:
Saving file /scpc:[email-masked]:/home/ws/babenhau/TM5_cycle3/proj/remotec/rc/include/common_folders.rc...
Tramp: Encoding region using function `base64-encode-region'...done
Tramp: Decoding region into remote file /scpc:[email-masked]:/home/ws/babenhau/TM5_cycle3/proj/remotec/rc/include/common_folders.rc...done
Wrote /scpc:[email-masked]:/home/ws/babenhau/TM5_cycle3/proj/remotec/rc/include/common_folders.rc
Mark set
Saving file /scpc:[email-masked]:/home/ws/babenhau/TM5_cycle3/proj/remotec/rc/include/common_folders.rc...
Tramp: Encoding region using function `base64-encode-region'...done
Tramp: Decoding region into remote file /scpc:[email-masked]:/home/ws/babenhau/TM5_cycle3/proj/remotec/rc/include/common_folders.rc...done
Wrote /scpc:[email-masked]:/home/ws/babenhau/TM5_cycle3/proj/remotec/rc/include/common_folders.rc
Making completion list...

Load-path shadows:
~/.emacs.d/libs/bbdb-vcard/vcard hides ~/.emacs.d/libs/vcard
/usr/share/emacs/site-lisp/semi/pgg hides /usr/share/emacs/23.3/lisp/pgg
/usr/share/emacs/site-lisp/flim/sha1 hides /usr/share/emacs/23.3/lisp/sha1
/usr/share/emacs/site-lisp/cedet/speedbar/dframe hides /usr/share/emacs/23.3/lisp/dframe
/usr/share/emacs/site-lisp/cedet/speedbar/speedbar hides /usr/share/emacs/23.3/lisp/speedbar
/usr/share/emacs/site-lisp/semi/pgg-gpg hides /usr/share/emacs/23.3/lisp/pgg-gpg
/usr/share/emacs/site-lisp/semi/pgg-parse hides /usr/share/emacs/23.3/lisp/pgg-parse
/usr/share/emacs/site-lisp/cedet/speedbar/sb-image hides /usr/share/emacs/23.3/lisp/sb-image
/usr/share/emacs/site-lisp/semi/pgg-pgp5 hides /usr/share/emacs/23.3/lisp/pgg-pgp5
/usr/share/emacs/site-lisp/semi/pgg-def hides /usr/share/emacs/23.3/lisp/pgg-def
/usr/share/emacs/site-lisp/flim/hex-util hides /usr/share/emacs/23.3/lisp/hex-util
/usr/share/emacs/site-lisp/semi/pgg-pgp hides /usr/share/emacs/23.3/lisp/pgg-pgp
/usr/share/emacs/site-lisp/cedet/common/ezimage hides /usr/share/emacs/23.3/lisp/ezimage
/usr/share/emacs/site-lisp/flim/md4 hides /usr/share/emacs/23.3/lisp/md4
/usr/share/emacs/site-lisp/remember/remember hides /usr/share/emacs/23.3/lisp/textmodes/remember
/usr/share/emacs/site-lisp/org-mode/org-vm hides /usr/share/emacs/23.3/lisp/org/org-vm
/usr/share/emacs/site-lisp/org-mode/org-crypt hides /usr/share/emacs/23.3/lisp/org/org-crypt
/usr/share/emacs/site-lisp/org-mode/org-mobile hides /usr/share/emacs/23.3/lisp/org/org-mobile
/usr/share/emacs/site-lisp/org-mode/org-agenda hides /usr/share/emacs/23.3/lisp/org/org-agenda
/usr/share/emacs/site-lisp/org-mode/org-freemind hides /usr/share/emacs/23.3/lisp/org/org-freemind
/usr/share/emacs/site-lisp/org-mode/org-publish hides /usr/share/emacs/23.3/lisp/org/org-publish
/usr/share/emacs/site-lisp/org-mode/org-jsinfo hides /usr/share/emacs/23.3/lisp/org/org-jsinfo
/usr/share/emacs/site-lisp/org-mode/org-timer hides /usr/share/emacs/23.3/lisp/org/org-timer
/usr/share/emacs/site-lisp/org-mode/org-colview hides /usr/share/emacs/23.3/lisp/org/org-colview
/usr/share/emacs/site-lisp/org-mode/org-docbook hides /usr/share/emacs/23.3/lisp/org/org-docbook
/usr/share/emacs/site-lisp/org-mode/org-indent hides /usr/share/emacs/23.3/lisp/org/org-indent
/usr/share/emacs/site-lisp/org-mode/org-id hides /usr/share/emacs/23.3/lisp/org/org-id
/usr/share/emacs/site-lisp/org-mode/org-exp hides /usr/share/emacs/23.3/lisp/org/org-exp
/usr/share/emacs/site-lisp/org-mode/org-plot hides /usr/share/emacs/23.3/lisp/org/org-plot
/usr/share/emacs/site-lisp/org-mode/org-wl hides /usr/share/emacs/23.3/lisp/org/org-wl
/usr/share/emacs/site-lisp/org-mode/org-mouse hides /usr/share/emacs/23.3/lisp/org/org-mouse
/usr/share/emacs/site-lisp/org-mode/org-archive hides /usr/share/emacs/23.3/lisp/org/org-archive
/usr/share/emacs/site-lisp/org-mode/org-macs hides /usr/share/emacs/23.3/lisp/org/org-macs
/usr/share/emacs/site-lisp/org-mode/org-inlinetask hides /usr/share/emacs/23.3/lisp/org/org-inlinetask
/usr/share/emacs/site-lisp/org-mode/org-icalendar hides /usr/share/emacs/23.3/lisp/org/org-icalendar
/usr/share/emacs/site-lisp/org-mode/org-latex hides /usr/share/emacs/23.3/lisp/org/org-latex
/usr/share/emacs/site-lisp/org-mode/org-table hides /usr/share/emacs/23.3/lisp/org/org-table
/usr/share/emacs/site-lisp/org-mode/org-list hides /usr/share/emacs/23.3/lisp/org/org-list
/usr/share/emacs/site-lisp/org-mode/org-html hides /usr/share/emacs/23.3/lisp/org/org-html
/usr/share/emacs/site-lisp/org-mode/org-install hides /usr/share/emacs/23.3/lisp/org/org-install
/usr/share/emacs/site-lisp/org-mode/org-w3m hides /usr/share/emacs/23.3/lisp/org/org-w3m
/usr/share/emacs/site-lisp/org-mode/org-gnus hides /usr/share/emacs/23.3/lisp/org/org-gnus
/usr/share/emacs/site-lisp/org-mode/org-protocol hides /usr/share/emacs/23.3/lisp/org/org-protocol
/usr/share/emacs/site-lisp/org-mode/org-ascii hides /usr/share/emacs/23.3/lisp/org/org-ascii
/usr/share/emacs/site-lisp/org-mode/org-xoxo hides /usr/share/emacs/23.3/lisp/org/org-xoxo
/usr/share/emacs/site-lisp/org-mode/org-compat hides /usr/share/emacs/23.3/lisp/org/org-compat
/usr/share/emacs/site-lisp/org-mode/org-datetree hides /usr/share/emacs/23.3/lisp/org/org-datetree
/usr/share/emacs/site-lisp/org-mode/org-habit hides /usr/share/emacs/23.3/lisp/org/org-habit
/usr/share/emacs/site-lisp/org-mode/org-feed hides /usr/share/emacs/23.3/lisp/org/org-feed
/usr/share/emacs/site-lisp/org-mode/org-faces hides /usr/share/emacs/23.3/lisp/org/org-faces
/usr/share/emacs/site-lisp/org-mode/org-exp-blocks hides /usr/share/emacs/23.3/lisp/org/org-exp-blocks
/usr/share/emacs/site-lisp/org-mode/org-info hides /usr/share/emacs/23.3/lisp/org/org-info
/usr/share/emacs/site-lisp/org-mode/org-footnote hides /usr/share/emacs/23.3/lisp/org/org-footnote
/usr/share/emacs/site-lisp/org-mode/org-rmail hides /usr/share/emacs/23.3/lisp/org/org-rmail
/usr/share/emacs/site-lisp/org-mode/org-bbdb hides /usr/share/emacs/23.3/lisp/org/org-bbdb
/usr/share/emacs/site-lisp/org-mode/org-attach hides /usr/share/emacs/23.3/lisp/org/org-attach
/usr/share/emacs/site-lisp/org-mode/org-mhe hides /usr/share/emacs/23.3/lisp/org/org-mhe
/usr/share/emacs/site-lisp/org-mode/org-mew hides /usr/share/emacs/23.3/lisp/org/org-mew
/usr/share/emacs/site-lisp/org-mode/org-mac-message hides /usr/share/emacs/23.3/lisp/org/org-mac-message
/usr/share/emacs/site-lisp/org-mode/org-clock hides /usr/share/emacs/23.3/lisp/org/org-clock
/usr/share/emacs/site-lisp/org-mode/org-bibtex hides /usr/share/emacs/23.3/lisp/org/org-bibtex
/usr/share/emacs/site-lisp/org-mode/org-irc hides /usr/share/emacs/23.3/lisp/org/org-irc
/usr/share/emacs/site-lisp/org-mode/org-remember hides /usr/share/emacs/23.3/lisp/org/org-remember
/usr/share/emacs/site-lisp/org-mode/org-src hides /usr/share/emacs/23.3/lisp/org/org-src
/usr/share/emacs/site-lisp/org-mode/org hides /usr/share/emacs/23.3/lisp/org/org
/usr/share/emacs/site-lisp/flim/ntlm hides /usr/share/emacs/23.3/lisp/net/ntlm
/usr/share/emacs/site-lisp/flim/hmac-def hides /usr/share/emacs/23.3/lisp/net/hmac-def
/usr/share/emacs/site-lisp/flim/sasl-digest hides /usr/share/emacs/23.3/lisp/net/sasl-digest
/usr/share/emacs/site-lisp/flim/sasl-ntlm hides /usr/share/emacs/23.3/lisp/net/sasl-ntlm
/usr/share/emacs/site-lisp/flim/sasl-cram hides /usr/share/emacs/23.3/lisp/net/sasl-cram
/usr/share/emacs/site-lisp/flim/sasl hides /usr/share/emacs/23.3/lisp/net/sasl
/usr/share/emacs/site-lisp/flim/hmac-md5 hides /usr/share/emacs/23.3/lisp/net/hmac-md5
/usr/share/emacs/site-lisp/wl/rfc2368 hides /usr/share/emacs/23.3/lisp/mail/rfc2368
~/.emacs.d/private/gnus hides /usr/share/emacs/23.3/lisp/gnus/gnus
/usr/share/emacs/site-lisp/semi/smime hides /usr/share/emacs/23.3/lisp/gnus/smime
/usr/share/emacs/site-lisp/wl/utf7 hides /usr/share/emacs/23.3/lisp/gnus/utf7
/usr/share/emacs/site-lisp/cedet/eieio/eieio-base hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio-base
/usr/share/emacs/site-lisp/cedet/eieio/eieio-speedbar hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio-speedbar
/usr/share/emacs/site-lisp/cedet/eieio/eieio-opt hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio-opt
/usr/share/emacs/site-lisp/cedet/eieio/chart hides /usr/share/emacs/23.3/lisp/emacs-lisp/chart
/usr/share/emacs/site-lisp/emms/tq hides /usr/share/emacs/23.3/lisp/emacs-lisp/tq
/usr/share/emacs/site-lisp/cedet/eieio/eieio-comp hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio-comp
/usr/share/emacs/site-lisp/cedet/eieio/eieio-custom hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio-custom
/usr/share/emacs/site-lisp/cedet/eieio/eieio hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio
/usr/share/emacs/site-lisp/cedet/eieio/eieio-datadebug hides /usr/share/emacs/23.3/lisp/emacs-lisp/eieio-datadebug
/usr/share/emacs/site-lisp/cedet/common/pulse hides /usr/share/emacs/23.3/lisp/cedet/pulse
/usr/share/emacs/site-lisp/cedet/common/cedet-idutils hides /usr/share/emacs/23.3/lisp/cedet/cedet-idutils
/usr/share/emacs/site-lisp/cedet/srecode/srecode hides /usr/share/emacs/23.3/lisp/cedet/srecode
/usr/share/emacs/site-lisp/cedet/common/inversion hides /usr/share/emacs/23.3/lisp/cedet/inversion
/usr/share/emacs/site-lisp/cedet/ede/ede hides /usr/share/emacs/23.3/lisp/cedet/ede
/usr/share/emacs/site-lisp/cedet/common/cedet-global hides /usr/share/emacs/23.3/lisp/cedet/cedet-global
/usr/share/emacs/site-lisp/cedet/common/data-debug hides /usr/share/emacs/23.3/lisp/cedet/data-debug
/usr/share/emacs/site-lisp/cedet/common/cedet hides /usr/share/emacs/23.3/lisp/cedet/cedet
/usr/share/emacs/site-lisp/cedet/common/cedet-cscope hides /usr/share/emacs/23.3/lisp/cedet/cedet-cscope
/usr/share/emacs/site-lisp/cedet/semantic/semantic hides /usr/share/emacs/23.3/lisp/cedet/semantic
/usr/share/emacs/site-lisp/cedet/common/mode-local hides /usr/share/emacs/23.3/lisp/cedet/mode-local
/usr/share/emacs/site-lisp/cedet/common/cedet-files hides /usr/share/emacs/23.3/lisp/cedet/cedet-files

Features:
(shadow sort mail-extr message idna ecomplete mml mml-sec mm-decode
mm-bodies mm-encode nnheader gmm-utils mailheader canlock sha1 sha1-el
hex-util hashcash mail-utils emacsbug grep thingatpt semantic-find
multi-isearch dired-aux ange-ftp tramp-imap tramp-gw tramp-fish
tramp-smb tramp-cache tramp-ftp tramp-cmds tramp tramp-compat trampver
loadhist eieio-opt help-mode view auth-source gnus-util netrc shell
password-cache ffap semantic-el semantic-bovine bovine-debug
semantic-debug activate-babenv diary-lib diary-loaddefs cal-iso ispell
org-wl org-w3m org-vm org-rmail org-mhe org-mew org-irc org-jsinfo
org-infojs org-html format-spec org-exp ob-exp org-exp-blocks org-info
org-gnus org-docview org-bibtex bibtex org-bbdb font-lock-tm5rc generic
activate-wanderlust bbdb-wl bbdb-hooks mailcrypt rfc822
activate-private-data private-basic private-wanderlust smtpmail sendmail
fortran-tools time activate-python python-21 python stenochords
key-chord activate-kde-default-keybindings activate-darkroom wc
activate-identica identica-mode url-http tls url-auth mail-parse rfc2231
rfc2047 rfc2045 qp ietf-drums url-gw url url-proxy url-privacy
url-expand url-methods url-history url-cookie mailcap longlines
parse-time xml epa-file epa epg epg-config activate-german-spelling
activate-ethan-wspace ethan-wspace popup-kill-ring pos-tip
activate-auto-complete auto-complete-config auto-complete popup
activate-markdown activate-latex-ide flymake compile
org-location-google-maps org-agenda google-maps google-maps-static
url-util url-parse url-vars mm-util mail-prsvr google-maps-geocode
google-maps-base json nyan-mode semantic-mru-bookmark semanticdb-mode
semantic-idle eldoc senator which-func semantic-imenu semantic-sb imenu
todochiku growl activate-emms emms-cache emms-info-ogginfo
emms-info-mp3info emms-info later-do emms-playlist-mode
emms-player-mplayer emms-player-simple emms-source-playlist
emms-source-file dired emms-setup emms emms-compat edmacro kmacro
control-lock htmlize rudel-mode rudel-display rudel rudel-icons
rudel-interactive rudel-compat rudel-hooks rudel-operators rudel-overlay
rudel-operations rudel-session-initiation rudel-util rudel-errors
rudel-loaddefs rudel-backend goto-chg journal activate-quick-note
remember-bbdb remember ob-R org ob-emacs-lisp ob-tangle ob-ref ob-lob
ob-table org-footnote org-src ob-comint comint ring ob-keys ob ob-eval
org-pcomplete pcomplete org-list org-faces org-compat org-entities
org-macs time-date noutline outline easy-mmode cal-menu calendar
cal-loaddefs bbdb-vcard bbdb-com mailabbrev vcard allout savehist ido
activate-base vc-hg bookmark pp saveplace uniquify site-gentoo
planner-autoloads w3m-load ecb-autoloads mime-setup mail-mime-setup
alist semi-setup path-util poe pym static apel-ver product semi-def
org-install muse-autoloads emms-auto cedet cedet-contrib-load
contrib-loaddefs cogre-load cogre-loaddefs speedbar-load
speedbar-loaddefs ede-load ede-loaddefs ede-speedbar ede-files ede
ede-base ede-auto eieio-speedbar semantic-ia-sb semantic-analyze
semantic-scope semantic-analyze-fcn semantic-sort semanticdb-el
semanticdb semantic-ctxt semantic-format semantic-util-modes
semantic-util semantic semantic-lex semantic-tag working fame speedbar
sb-image ezimage dframe easymenu assoc eieio-custom wid-edit ede-source
eieio-base srecode-load srecode srecode-loaddefs semantic-load
semantic-fw semantic-loaddefs mode-local find-func derived eieio-load
eieio-loaddefs cedet-load cedet-compat cedet-loaddefs eieio warnings
advice help-fns advice-preload byte-opt bytecomp byte-compile cl cl-19
inversion bbdb-autoloads bbdb regexp-opt timezone tex-site auto-loads
tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
font-setting tool-bar dnd fontset image fringe lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mldrag mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev loaddefs button
minibuffer faces cus-face files text-properties overlay md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process dbusbind font-render-setting gtk
x-toolkit x multi-tty emacs)