[Tutor] some questions - from a complete newbie

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 14 Dec 2001 13:52:44 -0800 (PST)


On Fri, 14 Dec 2001 vip333d@yahoo.com wrote:

> I'm a newbie, and there are some things that I want to
> do with python, that aren't in the basic web tutorials
> I have read. My OS is win95. I:
> a) cannot execute the os.access(c:\.....) or the
> os.path.exists. the arrow points on the "c". I tried
> it without the c:\ and the arrow pointed on the "s" of
> "my documents.

Can you show us the error message in more detail?  Usually, the error
underneath shows where Python starts getting confused, but the message
itself is also an important debugging tool.

As a wild guess, I'm guessing that you're trying:

    os.access(c:\foobar.txt)


Python allows things like:

###
>>> def square(x): return x * x
... 
>>> square(square(square(10)))
100000000
###

That is, we can call functions within functions --- we can call commands
within commands.  One consequence about this is that Python will assume
that something like "c:\foobar.txt" looks like a command that should be
executed.  To get it to not try to execute "c:\foobar.txt", we have to
quote it:

    os.access("c:\\foobar.txt")

Quoting in Python is somewhat analogous to quoting in a human language: we
use quotes to make sure no one tries to interpret them as our own words.  
Same principle.



> b) I'd like some strings that open other windows files, documents and
> web pages etc.

Not quite sure about this one.  There's a module called "webbrowser":

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

that will automatically get either IE or Netscape to open an url that you
give it, so that might be useful.  I haven't played with it too much yet.



> c) I'd be happy to get a list of orders that get me parts of web
> pages, for example the headlines of the NYTimes.

This is possible --- many websites support a protocol called RSS:

    http://www.purplepages.ie/rss/

and I'm very sure that there are Python modules out there that can handle
RSS.



> d) It would be great to get a list of web-oriented orders, but if it's
> too much to ask - it's too much to ask.

You might be interested in Useless Python:

    http://www.lowerstandard.com/python/

There should be some scripts there that demonstrate CGI programming.


Good luck to you!