Getting started with Python

View: New views
5 Messages — Rating Filter:   Alert me  

Getting started with Python

by ppaarrkk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I can't.


>>> import file.py


is all very well if the interpreter knows where file.py is.


I want to do this :

>>> import /directory1/directory2/file.py


Is this not possible ?

Parent Message unknown Re: Getting started with Python

by Moishy Gluck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, May 16, 2008 at 11:20 AM, Moishy Gluck <moishyyehuda@...> wrote:
You need to place a "__init__.py" file in a directory you want to reference in an import statement.

I don't believe the content of the file is important but you can place code in the file that will affect how files are imported.

The import syntax is a such.Place "__init__.py" in both "directory1" and "directory2"

Good luck simon.


On Fri, May 16, 2008 at 8:16 AM, ppaarrkk <simon_ecc@...> wrote:

I can't.


>>> import file.py


is all very well if the interpreter knows where file.py is.


I want to do this :

>>> import /directory1/directory2/file.py


Is this not possible ?

--
View this message in context: http://www.nabble.com/Getting-started-with-Python-tp17273337p17273337.html
Sent from the Python - tutor mailing list archive at Nabble.com.

_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor

Re: Getting started with Python

by jay-73 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have you tried this ?

import sys
sys.path.append('/directory1/directory2')
import file.py

j

On Fri, May 16, 2008 at 10:20 AM, Moishy Gluck <moishyyehuda@...> wrote:


On Fri, May 16, 2008 at 11:20 AM, Moishy Gluck <moishyyehuda@...> wrote:
You need to place a "__init__.py" file in a directory you want to reference in an import statement.

I don't believe the content of the file is important but you can place code in the file that will affect how files are imported.

The import syntax is a such.Place "__init__.py" in both "directory1" and "directory2"

Good luck simon.


On Fri, May 16, 2008 at 8:16 AM, ppaarrkk <simon_ecc@...> wrote:

I can't.


>>> import file.py


is all very well if the interpreter knows where file.py is.


I want to do this :

>>> import /directory1/directory2/file.py


Is this not possible ?

--
View this message in context: http://www.nabble.com/Getting-started-with-Python-tp17273337p17273337.html
Sent from the Python - tutor mailing list archive at Nabble.com.

_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor

Re: Getting started with Python

by Hansen, Mike :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Isn't it
 
import file
 
not
 
import file.py
 
or has that changed in recent versions?
 
Mike


From: tutor-bounces@... [mailto:tutor-bounces@...] On Behalf Of jay
Sent: Friday, May 16, 2008 9:44 AM
To: tutor@...
Subject: Re: [Tutor] Getting started with Python

Have you tried this ?

import sys
sys.path.append('/directory1/directory2')
import file.py

j

On Fri, May 16, 2008 at 10:20 AM, Moishy Gluck <moishyyehuda@...> wrote:


On Fri, May 16, 2008 at 11:20 AM, Moishy Gluck <moishyyehuda@...> wrote:
You need to place a "__init__.py" file in a directory you want to reference in an import statement.

I don't believe the content of the file is important but you can place code in the file that will affect how files are imported.

The import syntax is a such. Place "__init__.py" in both "directory1" and "directory2"

Good luck simon.


On Fri, May 16, 2008 at 8:16 AM, ppaarrkk <simon_ecc@...> wrote:

I can't.


>>> import file.py


is all very well if the interpreter knows where file.py is.


I want to do this :

>>> import /directory1/directory2/file.py


Is this not possible ?

--
View this message in context: http://www.nabble.com/Getting-started-with-Python-tp17273337p17273337.html
Sent from the Python - tutor mailing list archive at Nabble.com.

_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor

Re: Getting started with Python

by jay-73 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your right, typo :-)

On Fri, May 16, 2008 at 10:57 AM, Hansen, Mike <Mike.Hansen@...> wrote:
Isn't it
 
import file
 
not
 
import file.py
 
or has that changed in recent versions?
 
Mike


From: tutor-bounces@... [mailto:tutor-bounces@...] On Behalf Of jay
Sent: Friday, May 16, 2008 9:44 AM
To: tutor@...
Subject: Re: [Tutor] Getting started with Python

Have you tried this ?

import sys
sys.path.append('/directory1/directory2')
import file.py

j

On Fri, May 16, 2008 at 10:20 AM, Moishy Gluck <moishyyehuda@...> wrote:


On Fri, May 16, 2008 at 11:20 AM, Moishy Gluck <moishyyehuda@...> wrote:
You need to place a "__init__.py" file in a directory you want to reference in an import statement.

I don't believe the content of the file is important but you can place code in the file that will affect how files are imported.

The import syntax is a such. Place "__init__.py" in both "directory1" and "directory2"

Good luck simon.


On Fri, May 16, 2008 at 8:16 AM, ppaarrkk <simon_ecc@...> wrote:

I can't.


>>> import file.py


is all very well if the interpreter knows where file.py is.


I want to do this :

>>> import /directory1/directory2/file.py


Is this not possible ?

--
View this message in context: http://www.nabble.com/Getting-started-with-Python-tp17273337p17273337.html
Sent from the Python - tutor mailing list archive at Nabble.com.

_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@...
http://mail.python.org/mailman/listinfo/tutor
LightInTheBox - Buy quality products at wholesale price