Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49578 > unrolled thread

PYTHONPATH and module names

Started byTobiah <tshepard@rcsreg.com>
First post2013-07-01 11:29 -0700
Last post2013-07-01 16:40 -0400
Articles 8 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  PYTHONPATH and module names Tobiah <tshepard@rcsreg.com> - 2013-07-01 11:29 -0700
    Re: PYTHONPATH and module names rusi <rustompmody@gmail.com> - 2013-07-01 11:39 -0700
      Re: PYTHONPATH and module names Tobiah <toby@tobiah.org> - 2013-07-01 12:54 -0700
        Re: PYTHONPATH and module names rusi <rustompmody@gmail.com> - 2013-07-01 14:38 -0700
          Re: PYTHONPATH and module names Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-01 22:05 +0000
            Re: PYTHONPATH and module names Lele Gaifax <lele@metapensiero.it> - 2013-07-02 07:30 +0200
        Re: PYTHONPATH and module names Fábio Santos <fabiosantosart@gmail.com> - 2013-07-01 23:08 +0100
        Re: PYTHONPATH and module names "SpaghettiToastBook ." <spaghettitoastbook@gmail.com> - 2013-07-01 16:40 -0400

#49578 — PYTHONPATH and module names

FromTobiah <tshepard@rcsreg.com>
Date2013-07-01 11:29 -0700
SubjectPYTHONPATH and module names
Message-ID<mailman.4074.1372703671.3114.python-list@python.org>
So today, I created a file called 'formatter.py',
and my program broke.  It turned out that I was
also import 'gluon' from web2py, which in turn,
somewhere, imported the regular python formatter.py
with which I was not familiar.

So the question is: Does one simply always have
to be knowledgeable about existing python library
names, or is having '.' in the python path just
a bad idea?  Is there a way, not having '.' in
the path to explicitly specify the current directory?
Something analogous to import ./foo ?

Thanks,

Tobiah

[toc] | [next] | [standalone]


#49579

Fromrusi <rustompmody@gmail.com>
Date2013-07-01 11:39 -0700
Message-ID<fa971601-b90f-4d1a-81d2-67b0c76e30d1@googlegroups.com>
In reply to#49578
On Monday, July 1, 2013 11:59:35 PM UTC+5:30, Tobiah wrote:
> So today, I created a file called 'formatter.py',
> and my program broke.  It turned out that I was
> also import 'gluon' from web2py, which in turn,
> somewhere, imported the regular python formatter.py
> with which I was not familiar.
> 
> So the question is: Does one simply always have
> to be knowledgeable about existing python library
> names, or is having '.' in the python path just
> a bad idea?  Is there a way, not having '.' in
> the path to explicitly specify the current directory?
> Something analogous to import ./foo ?

Are you familiar with absolute and relative imports:
http://docs.python.org/release/2.5/whatsnew/pep-328.html

[toc] | [prev] | [next] | [standalone]


#49590

FromTobiah <toby@tobiah.org>
Date2013-07-01 12:54 -0700
Message-ID<G7lAt.13847$J_1.8584@newsfe01.iad>
In reply to#49579
> Are you familiar with absolute and relative imports:
> http://docs.python.org/release/2.5/whatsnew/pep-328.html

Doesn't seem to work:

Python 2.7.3 (default, May 10 2012, 13:31:18)
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from __future__ import absolute_import
 >>> import .format
   File "<stdin>", line 1
     import .format
            ^
SyntaxError: invalid syntax
 >>>

[toc] | [prev] | [next] | [standalone]


#49594

Fromrusi <rustompmody@gmail.com>
Date2013-07-01 14:38 -0700
Message-ID<a61cb2f9-bc12-4b25-aa66-4eb901438481@googlegroups.com>
In reply to#49590
On Tuesday, July 2, 2013 1:24:30 AM UTC+5:30, Tobiah wrote:
> > Are you familiar with absolute and relative imports:
> > http://docs.python.org/release/2.5/whatsnew/pep-328.html
> 
> Doesn't seem to work:
> Python 2.7.3 (default, May 10 2012, 13:31:18)
> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> from __future__ import absolute_import
>  >>> import .format
>    File "<stdin>", line 1
>      import .format
>             ^
> SyntaxError: invalid syntax
>  >>>

1. My reading of 
http://www.python.org/dev/peps/pep-0328/
is that this only works for from statements not import statements.
[See the section called Guido's decision]

2. The __future__ is not necessary in python 2.7
[Not necessary or not allowed I not know :-) ]

[toc] | [prev] | [next] | [standalone]


#49595

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-07-01 22:05 +0000
Message-ID<51d1fd2f$0$29973$c3e8da3$5496439d@news.astraweb.com>
In reply to#49594
On Mon, 01 Jul 2013 14:38:50 -0700, rusi wrote:

> On Tuesday, July 2, 2013 1:24:30 AM UTC+5:30, Tobiah wrote:
>> > Are you familiar with absolute and relative imports:
>> > http://docs.python.org/release/2.5/whatsnew/pep-328.html
>> 
>> Doesn't seem to work:
>> Python 2.7.3 (default, May 10 2012, 13:31:18) [GCC 4.2.4 (Ubuntu
>> 4.2.4-1ubuntu4)] on linux2 Type "help", "copyright", "credits" or
>> "license" for more information.
>>  >>> from __future__ import absolute_import import .format
>>    File "<stdin>", line 1
>>      import .format
>>             ^
>> SyntaxError: invalid syntax
>>  >>>
>>  >>>
> 1. My reading of
> http://www.python.org/dev/peps/pep-0328/ is that this only works for
> from statements not import statements. [See the section called Guido's
> decision]


Correct. This would have to be written as:

from . import format


but note that this only work in a package, not from some arbitrary module 
inside a directory.


 
> 2. The __future__ is not necessary in python 2.7 [Not necessary or not
> allowed I not know :-) ]

Not necessary.

__future__ statements are guaranteed to "work" in all future versions, in 
the sense that once a __future__ feature is added, it will never be 
removed. So Python has had "nested scopes" since version 2.2 (by memory), 
but:

from __future__ import nested_scopes

still is allowed in Python 3.3, even though it has been a no-op since 2.2 
or 2.3.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#49609

FromLele Gaifax <lele@metapensiero.it>
Date2013-07-02 07:30 +0200
Message-ID<mailman.4089.1372743030.3114.python-list@python.org>
In reply to#49595
Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> On Mon, 01 Jul 2013 14:38:50 -0700, rusi wrote:
>> 2. The __future__ is not necessary in python 2.7 [Not necessary or not
>> allowed I not know :-) ]
>
> Not necessary.

IIRC that it is needed, to solve the OP problem: one thing is the
syntax, which under Python 2.7 is enabled by default, another thing is
the behaviour, that is whether the interpreter will give priority to the
sys.path.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

[toc] | [prev] | [next] | [standalone]


#49598

FromFábio Santos <fabiosantosart@gmail.com>
Date2013-07-01 23:08 +0100
Message-ID<mailman.4085.1372717015.3114.python-list@python.org>
In reply to#49590

[Multipart message — attachments visible in raw view] — view raw

On 1 Jul 2013 20:58, "Tobiah" <toby@tobiah.org> wrote:
>>
>> Are you familiar with absolute and relative imports:
>> http://docs.python.org/release/2.5/whatsnew/pep-328.html
>
>
> Doesn't seem to work:
>
> Python 2.7.3 (default, May 10 2012, 13:31:18)
> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from __future__ import absolute_import
> >>> import .format
>   File "<stdin>", line 1
>     import .format
>            ^
> SyntaxError: invalid syntax
> >>>

Have you tried

from . import format

?

[toc] | [prev] | [next] | [standalone]


#49619

From"SpaghettiToastBook ." <spaghettitoastbook@gmail.com>
Date2013-07-01 16:40 -0400
Message-ID<mailman.4106.1372749627.3114.python-list@python.org>
In reply to#49590
Relative imports only work with the "from ... import ..." form.

— SpaghettiToastBook


On Mon, Jul 1, 2013 at 3:54 PM, Tobiah <toby@tobiah.org> wrote:
>> Are you familiar with absolute and relative imports:
>> http://docs.python.org/release/2.5/whatsnew/pep-328.html
>
>
> Doesn't seem to work:
>
> Python 2.7.3 (default, May 10 2012, 13:31:18)
> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from __future__ import absolute_import
>>>> import .format
>   File "<stdin>", line 1
>     import .format
>            ^
> SyntaxError: invalid syntax
>>>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web