On Tuesday, March 26, 2013 7:06:02 PM UTC-4, Steven D'Aprano wrote:
> On Tue, 26 Mar 2013 08:37:00 -0700, rocky wrote:
> 
> 
> 
> > So again I come to import_relative,
> 
> > http://code.google.com/p/pyimport-relative/.  And again, I wish this
> 
> > package didn't have to exist.
> 
> 
> 
> 
> 
> I'm not convinced it does. 

Sure, the package doesn't have to exist. I'm pretty sure the majority of Python 
programmers don't use this. So on that sense it doesn't have to exist. 

I meant that I wished I didn't need it in order to support a development style 
that I use in other programming languages like Ruby, Perl, POSIX shell, or 
Emacs Lisp, among others. 

There, I can run each file/submodule in a large collection such as the dozens 
of files in http://code.google.com/p/python3-trepan/ without having to 
"install" the code. That includes not needing the copying that can go on inside 
say setup.py to put it in a "build" directory. 

With this I can treat each file/module/submodule in the collection as a main 
program or not. This helps me isolate and focus on just that part. I can debug 
it in isolation starting there even though it is a usually submodule of a 
bigger collection.

> 
> to solve. "Provide relative imports" is not that problem, because the use-
> 
> case you give on the project page does not describe relative imports, as 
> 
> they are understood in Python terminology.

If the information above and on that page isn't clear, then please let's just 
drop it. 

This is not a new problem. It's been discussed before, I think on this very 
same newsgroup.

As someone has said, relative imports have been around since 2.5 or so; they've 
been a disappointment to me ever since then too. 

> 
> 
> 
> The error message you get gives the game away:
> 
> 
> 
> ValueError: Attempted relative import in non-package
> 
> 
> 
> In a stand-alone module, you can't do a relative import because there is 
> 
> no package structure, hence there is nothing to import relative to.

So what pyimport-relative does is provide kind of import statement that makes 
it irrelevant whether or not this has been run as a main program or not. And 
yes, I know about Python's '-m' option. 

> 
> 
> 
> As I don't quite understand your use-case, I'm a shooting in the dark 
> 
> here, 


No need to shoot in the dark. If you don't understand the use case, I'm 
probably not explaining it that well. I'm not asking for help, so let's drop 
it, lest I get into another long discussion that ultimately leads nowhere.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to