Search the web
Sign In
New User? Sign Up
PhillyPug · Python Users Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Two beginner questions about paths and running programs in Python:   Message List  
Reply | Forward Message #328 of 350 |
Re: Two beginner questions about paths and running programs in Python:



I know I'm not getting how the relative directory structure from python
works... If I'm using python at c:\python26 and my module files are at
c:\python26\pydocs

what is the correct syntax for importing them from within the interpreter?

what if I wanted to import a file from c:\user\shawn\documents\pydocs

no matter what syntax I use to try and import it gives me

Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
import chap03.py
ImportError: No module named chap03.py

kind of error.


--- In PhillyPug@yahoogroups.com, "Shawn Moffit" <shawnmoffit@...> wrote:
>
>
> --- In PhillyPug@yahoogroups.com, Erik Osheim <erik@> wrote:
> >
> > On Tue, Jun 09, 2009 at 09:03:40PM -0000, Shawn Moffit wrote:
> > > so - once I get to the python command prompt, I should be able to
> open
> > > .py files - right?
> >
> > Well, from python, you can import python modules (to import foo.py,
> > you'd write "import foo"). You can't run python scripts from within
> > python--or at least, you can't do what you're expecting to do.
> > Importing a Python module and running a Python program are two
> > different things.
> >
> > > or is the point that you are making is that the book reference I
> > > described from what you can see indicates that I should be calling
> the
> > > files using the cmd.exe terminal, not the python terminal.
> >
> > I guess I was implying that if you are following the book examples you
> > should run the script ("call the files") from cmd.exe
> >
> > > I'd like to be able to just run the files through the python
> terminal,
> > > but you are right, I'm definitely confused as I grew up on windows
> not
> > > dos and am fairly new to programming in general.
> >
> > If you see an example like:
> >
> > $ python foo.py
> >
> > Then to follow along exactly you need to use cmd.exe, because that is
> > what they are doing in that example. If you see an example like:
> >
> > >>> for i in range(0, 10):
> > ... print i
> >
> > Then you should use the python interpreter window. It's also fair to
> > note that running a script from IDLE (assuming there is a "Run Script"
> > menu option) is equivalent to typing "python script.py" in cmd.exe
> >
> > > I can't import the functions because my environment is screwed up or
> I'm
> > > doing something wrong.
> >
> > The importing and stuff can all take place from within the Python
> > interpreter; you can tell this because those lines begin with ">>>"
> > (rather than "$").
> >
> > Good luck,
> >
> > -- Erik
> >
>





Wed Jun 10, 2009 3:42 am

shawnmoffit
Offline Offline
Send Email Send Email

Forward
Message #328 of 350 |
Expand Messages Author Sort by Date

I am running Python 2.6.2 on my windows 7 RC 1 x64 laptop and attempting to learn python as a beginner programmer on my own, but I'm having difficulty...
Shawn Moffit
shawnmoffit
Offline Send Email
Jun 9, 2009
8:14 pm

So, I've never used IDLE or Windows. That said, I think you are getting confused between the Python shell (which uses ">>>" as the prompt, and probably runs...
Erik Osheim
erik@...
Send Email
Jun 9, 2009
8:24 pm

so - once I get to the python command prompt, I should be able to open .py files - right? and am I doing that incorrectly or is that, from within python you ...
Shawn Moffit
shawnmoffit
Offline Send Email
Jun 9, 2009
9:05 pm

... Well, from python, you can import python modules (to import foo.py, you'd write "import foo"). You can't run python scripts from within python--or at...
Erik Osheim
erik@...
Send Email
Jun 9, 2009
9:52 pm

... open ... the ... terminal, ... not ... I'm...
Shawn Moffit
shawnmoffit
Offline Send Email
Jun 10, 2009
12:53 am

I know I'm not getting how the relative directory structure from python works... If I'm using python at c:\python26 and my module files are at...
Shawn Moffit
shawnmoffit
Offline Send Email
Jun 10, 2009
3:43 am

... In general, if you type "import foo" then either there should be a "foo.py" installed in one of the "system locations" (on linux this might be...
Erik Osheim
erik@...
Send Email
Jun 10, 2009
4:01 am

If that still doesn't work then you likely need to add python to windows path. For Windows 7 right-click on the "Computer" (aka My Computer) and choose...
Dave Teske
teskepython
Offline Send Email
Jun 9, 2009
9:20 pm

Thanks Dave - I made the changes and now it works from the command line as well. Very helpful....
Shawn Moffit
shawnmoffit
Offline Send Email
Jun 10, 2009
2:12 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help