From: Anthony Papillion on
Hello Everyone,

I'm brand new to Python and have been finding it really easy to get
into. But I've run into my very first problem that I'm hoping someone
here might be able to help me with.

I'm working with the Google Storage API and all of their Python
library is under a directory called $HOME/gsutils/boto

To begin my Python script, I'm support to import boto but that doesn't
work because boto isn't in my search path (or my PYTHONPATH).

So I tried this:

import os

os.path.append('$HOME/gsutils/boto')

thinking I could then successfully do the import boto statement.
Nope.

Can anyone give me some direction on the correct way to import
modules?

Thanks!
Anthony
From: Ben Finney on
Anthony Papillion <papillion(a)gmail.com> writes:

> import os
>
> os.path.append('$HOME/gsutils/boto')
>
> thinking I could then successfully do the import boto statement.
> Nope.

You'll need to give the literal path. Substitution of environment
variables isn't performed implicitly in strings.

--
\ “When we pray to God we must be seeking nothing — nothing.” |
`\ —Saint Francis of Assisi |
_o__) |
Ben Finney
From: Chris Rebert on
On Sun, Jun 6, 2010 at 8:16 PM, Ben Finney <ben+python(a)benfinney.id.au> wrote:
> Anthony Papillion <papillion(a)gmail.com> writes:
>
>> import os
>>
>> os.path.append('$HOME/gsutils/boto')
>>
>> thinking I could then successfully do the import boto statement.
>> Nope.
>
> You'll need to give the literal path. Substitution of environment
> variables isn't performed implicitly in strings.

Also, that should be sys.path.append(); os.path is an unrelated module
that has no `append` function. You'll need to import sys instead of os
obviously.

Cheers,
Chris
--
http://blog.rebertia.com
From: Anthony Papillion on
On Jun 6, 10:33 pm, Chris Rebert <c...(a)rebertia.com> wrote:
> On Sun, Jun 6, 2010 at 8:16 PM, Ben Finney <ben+pyt...(a)benfinney.id.au> wrote:
> > Anthony Papillion <papill...(a)gmail.com> writes:
>
> >> import os
>
> >> os.path.append('$HOME/gsutils/boto')
>
> >> thinking I could then successfully do the import boto statement.
> >> Nope.
>
> > You'll need to give the literal path. Substitution of environment
> > variables isn't performed implicitly in strings.
>
> Also, that should be sys.path.append(); os.path is an unrelated module
> that has no `append` function. You'll need to import sys instead of os
> obviously.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Hi Chris,
Thanks for saving me (again). I appreciate the help. While the
os.path.append() was a typo (I really had sys.path.append()), the
substitution was what was killing me. Thanks for the help! I owe you
a beer.

Anthon
From: Chris Rebert on
On Sun, Jun 6, 2010 at 10:25 PM, Anthony Papillion <papillion(a)gmail.com> wrote:
> On Jun 6, 10:33 pm, Chris Rebert <c...(a)rebertia.com> wrote:
>> On Sun, Jun 6, 2010 at 8:16 PM, Ben Finney <ben+pyt...(a)benfinney.id.au> wrote:
>> > Anthony Papillion <papill...(a)gmail.com> writes:
>>
>> >> import os
>>
>> >> os.path.append('$HOME/gsutils/boto')
>>
>> >> thinking I could then successfully do the import boto statement.
>> >> Nope.
>>
>> > You'll need to give the literal path. Substitution of environment
>> > variables isn't performed implicitly in strings.
>>
>> Also, that should be sys.path.append(); os.path is an unrelated module
>> that has no `append` function. You'll need to import sys instead of os
>> obviously.
>>
>> Cheers,
>> Chris
>
> Hi Chris,
> Thanks for saving me (again). I appreciate the help. While the
> os.path.append() was a typo (I really had sys.path.append()), the
> substitution was what was killing me.  Thanks for the help! I owe you
> a beer.

Er, in point of fact, the substitution problem was first pointed out
by Ben, not myself.
Not that I could legally have your beer anyway. :)

Cheers,
Chris
--
2 more months!
http://blog.rebertia.com