Calling all Python experts

David Bandel david.bandel
Wed Dec 20 08:53:15 PST 2006


On 12/20/06, Michael Hipp <Michael at hipp.com> wrote:
> David Bandel wrote:
> > Folks,
> >
> > OK, well, someone took a perfectly good idea originally coded in Perl
> > and decided he liked Python better :-(.
> >
> > Well, I need to try to figure out how Python handles grabbing
> > arguments to programs.  Specifically, sendmail is calling procmail,
> > which runs a filter in Python (if only this were Perl I could fix it,
> > but I don't feel like learning enough Python to translate the entire
> > program to Perl).
> >
> > The install suggests something like:
> > "/var/mail/%s" % os.environ.get("USER")
> >
> > Geez, what atrocious syntax.  Might as well be Klingon.
> >
> > unfortunately, the above returns a filter error: no such file /var/mail/None.
> > duh. That None is supposed to be the user's name that sendmail passed
> > to procmail.
> >
> > Anyone have any ideas how to code this correctly?  Note that, since
> > most users have /bin/false as their shell, I had to declare:
> > SHELL=/bin/sh
> > in the user's .procmailrc
>
> The guy probably comes from a C++ background and just can't accept that it's
> often possible to write things in a readable fashion. :-)
>
> Anyway, that statement works when run from the Python interpreter on my Ubuntu
> box. I'd have written it this way:
>
>    "/var/mail/" + os.environ.get("USER")
>
> So if it's not working then USER must not be defined in the environment. Or
> else the Python installation is borked.
>

Thanx for the pointers, Michael.  What finally worked:
"/var/mail/" + os.environ.get("LOGNAME")

So apparently, not all environment variables are set when sendmail
calls procmail calls Python.

Ciao,

David A. Bandel
-- 
Focus on the dream, not the competition.
            - Nemesis Air Racing Team motto



More information about the Linux-users mailing list