TypeError: unsupported operand types for +: 'NoneType' and 'str'

Chris Rebert clp2 at rebertia.com
Tue Nov 17 23:11:32 EST 2009


On Tue, Nov 17, 2009 at 7:25 PM,  <aurfalien at gmail.com> wrote:
<snip>
> The error I get;
>
> File "myscript.py", Line 18, in ?
> projectpath = ourHome+"/etc/TEMPLATE"
> TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>
> Python 2.4.3
>
> I've read were when passing a string to exec may need to end with a '\n'
>
> I've tried a few diff variations on the below line 18 w/o luck.  Any one
> mind helping out a bratha from anatha ... planet that is?
>
> line 18;
>
> projectpath = ourHome+"/etc/TEMPLATE"
>
> line 17;
> ourHome = os.environ.get('some_env')

>From the `os` docs:
os.environ
    A mapping object representing the string environment.

>From the `dict` docs (`dict` being the built-in and prototypical mapping class):
    D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.

>From this, I conclude that the environment variable `some_env` does
not exist for you, thus .get() returns None, thus causing an error
when you try and concatenate it with a string.

Solution: Either fix things so the environment variable does exist or
add code to handle the case of the environment variable not existing.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list