Importing modules

  • Thread starter Anthony Papillion
  • Start date
A

Anthony Papillion

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
 
C

Chris Rebert

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
 
A

Anthony Papillion

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
 
C

Chris Rebert

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
 
A

Anthony Papillion

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

Hi Ben,

Thanks for the help! I'd misread the thread and thanked Chris while
ignoring you. Much thanks to you for the help. Worked like a charm.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,871
Messages
2,569,919
Members
46,171
Latest member
A.N.Omalum

Latest Threads

Top