[Python] Come si fa ad importare una variabile di un file localizzato in un'altra directory?

Nicola Larosa nico a tekNico.net
Lun 10 Feb 2014 12:20:35 CET


Dario Bertini wrote:
> visto che nessuno l'ha ancora menzionato, ci tengo comunque
> a ricordare che gli __init__.py sono necessari solo se volete
> essere compatibili con vecchie versioni di Python
> 
> con la pep 0420 infatti sono stati aggiunti i namespace modules
> 
> http://www.python.org/dev/peps/pep-0420/

Non č esatto. La definizione dei package tramite la presenza di un file
__init__.py non č deprecata, non verrā rimossa, e rimane il meccanismo
statico di base.

Dalla PEP citata:

"There is no intention to remove support of regular packages. If a
developer knows that her package will never be a portion of a namespace
package, then there is a performance advantage to it being a regular
package (with an __init__.py). Creation and loading of a regular package
can take place immediately when it is located along the path. With
namespace packages, all entries in the path must be scanned before the
package is created."

<http://www.python.org/dev/peps/pep-0420/#discussion>

-- 
Nicola Larosa - http://www.tekNico.net/

In the years after 9/11, so many people chose to drive instead of
fly that the resulting deaths dwarfed the deaths from the terrorist
attack itself, because cars are much more dangerous than airplanes.
 - Bruce Schneier, September 2013


Maggiori informazioni sulla lista Python