The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by kp]

Is it so that you cannot specify the full pathname of a mod file with the
import command? i tried it many times import foo:bar:foo /foo/bar foo,etc.
I know that if you set the env variable it looks down that path also in the
current working dir, but not being able to explicitly use the path is, well,
dumb aint it?
import-bot (20211) [Avatar] Offline
#2
Re: import
[Originally posted by daryl harms]

Hi Kevin,

> Is it so that you cannot specify the full pathname of a mod file with the
> import command? i tried it many times import foo:bar:foo /foo/bar foo,etc.
Yes, I believe this is true.

> I know that if you set the env variable it looks down that path also in the
> current working dir, but not being able to explicitly use the path is, well,
> dumb aint it?

The mechanisms for setting up sys.path (as described in section 11.4.1 of the
book) are flexible enough that you should be able to get functionality that
works well for you without needing set explicit paths on individual import
statements. If you use the ".pth" file(s) on a Unix system, it would probably
be good if you looked in the documentation for the "site" module for more
details than is presented in that section.

The dynamic location independence provided by this implementation can be a
very nice feature to have. However, it does mean that the module namespace is
flat, and pushes one to uniquely define all modules. If you want to use
explicit (albeit still relative) pathnames on individual import statements,
you might want to look into the packages mechanism introduced in chapter 18
where you could set up the capability to specify individual imports using the
"." notation (i.e. import foo.bar.foo)

Daryl