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

Discussion in 'Python' started by Chris Rebert, Nov 18, 2009.

  1. Chris Rebert

    Chris Rebert Guest

    On Tue, Nov 17, 2009 at 7:25 PM, <> 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
    Chris Rebert, Nov 18, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Koekenberg
    Replies:
    3
    Views:
    1,308
    Martin Koekenberg
    Aug 26, 2004
  2. Brett C.
    Replies:
    2
    Views:
    2,848
    Martin Koekenberg
    Aug 30, 2004
  3. Jordan Harry
    Replies:
    1
    Views:
    476
    Sean DiZazzo
    May 2, 2008
  4. Replies:
    0
    Views:
    598
  5. Íßêïò Ãêñ33ê
    Replies:
    14
    Views:
    1,451
    Íßêïò Ãêñ33ê
    May 28, 2013
Loading...

Share This Page