[Tutor] (no subject)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sat, 15 Dec 2001 13:51:36 -0800 (PST)


On Sat, 15 Dec 2001 vip333d@yahoo.com wrote:

> a) when I type in python - os.access('c:\...')- it points on the ")"
> and says "invalid tolken"

Can you show us the error message verbatim?  You don't have to paraphrase
the few lines of error messages.  When we're catching bugs like this, we
really do need to see everything that Python's saying, even if it looks
ugly.  Think of it as detective work.  *grin*

Don't feel bad by cutting and pasting error messages: we don't mind
looking at them.


For example, if we had done something like this:

##
>>> os.access(c:\hello.world)
###


It becomes very useful if we can see the error in its context:

###
>>> os.access(c:\hello.world)
  File "<stdin>", line 1
    os.access(c:\hello.world)
               ^
SyntaxError: invalid syntax
###


For your bug, I can imagine a few things that might cause a "Token" error
like that:

###
>>> os.access("c:\index.html\"))
  File "<stdin>", line 1
    os.access("c:\index.html\"))
                               ^
SyntaxError: invalid token
###

but I really don't feel comfortable guessing things, just because what I'm
imagining can be pretty wild and wide off the mark.  *grin*



Also, try not to use '...' when you're showing us what you're doing: we
really need to see exactly what you're passing into os.access().


This is particularly important with os.access(), because it takes two
arguments:

###
>>> os.access.__doc__
'access(path, mode) -> 1 if granted, 0 otherwise\nTest for access to a
file.'
>>> os.access(".bash_profile")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: access() takes exactly 2 arguments (1 given)
###

and if we try calling it with just 1, Python corrects us by saying that we
need to give it 2 arguments.


Here's an example call to os.access():

###
>>> os.access(".bash_profile", os.F_OK)
1
>>> os.access("the_princess_and_the_pea", os.F_OK)
0
###


The documentation here shows the modes you can use with os.access to test
certain things (like existance, readibility, writability, or
executability):

    http://www.python.org/doc/lib/os-file-dir.html




> b) i've tried an order that was in
> "www.python.org/doc/lib...": open_new(www...), and it
> said: "name error: open_new is not defined"

I see that you're using the webbrowser.open_new() function in:

    http://www.python.org/doc/lib/module-webbrowser.html#l2h-2158

When we're using module functions like webbrowser.open_new(), we need to
say something like this:

###
>>> webbrowser.open_new("http://python.org")
###


If we see something like this when running the above:

###
>>> webbrowser.open_new("http://python.org")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'webbrowser' is not defined
###

it just means that we need to tell Python in advance to prepare the
webbrowser module for us, by using an 'import' command:

###
>>> import webbrowser
>>> webbrowser.open_new("http://python.org")
###


We can do searches on Tutor from Activestate's search site:

    http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/python-Tutor



Good luck to you, and please feel free to ask questions.