Need help with TCP/IP client access from Windows
Gordon McMillan
gmcm at hypernet.com
Thu Jul 29 18:21:12 EDT 1999
Eric Raymond writes:
> I need a Windows equivalent of this class for a client I'm writing.
[snip]
> The issues here are:
>
> (1) How do I get (at least) line-oriented access to an Internet
> server
> from a Python program running under Windows?
No problem there. (The only difference - when using Python - is that
you can only select on sockets on Windows).
> (2) How does one read and write the Windows equivalent of a dotfile?
> Must this involve the (shudder) registry?
You could, by using Mark's win32 extensions. MS would prefer you
kept this kind of info in the registry, but that doesn't stop
anybody, least of all you <g>.
The issue is really what is meant by a HOME directory. On NT, this
has a certain amount of meaning - there's probably a
%WINDIR%/profiles/%USERNAME% directory tree for that user (where
those funky %...% things are environment vars), but probably it's
safer to get that path out of the registry. On Win9x, it's pretty
meaningless, since a logon and username are pretty much an empty
formality. There's almost no way to keep multiple users on a Win9x
box from stepping on each other. (Of course, I mean multiple serial
users; the only possible kind in Windows).
Probably better just to have a default file, and let the user
override that if need be. Which may well never happen.
> (3) Is there a reliable way for Python programs under Windows to
> point a local
> browser at a specified URL?
The best way is to use WinExec from Mark's win32 extensions. You just
give it the URL and it loads the user's default browser. Using
os.system is harder, because most of the time a browser is not on the
user's path.
However, this worked fine for me:
browse='"C:\\Program Files\\Netscape\\Communicator\\Program\\netscape"
%s'
Note the double quotes around the nowhere-but-Windows <snicker> path
with spaces in it, and that argv[1] is expected to be a URL (same for
IE). Also note that the path doesn't go thru the c runtime lib, so
those wonderful backslashes can't be avoided.
- Gordon
More information about the Python-list
mailing list