[FAQTS] Python Knowledge Base Update -- May 17th, 2000

Fiona Czuczman fiona at sitegnome.com
Wed May 17 09:54:43 EDT 2000


Greetings!

I've entered the below entries into http://python.faqts.com

Now I must sleep...

Regards to all, and a special wish to 'Steve the Pythonoholic' who came 
out yesterday :-)

'night, Fiona Czuczman


## New Entries #################################################


-------------------------------------------------------------
How can I use a proxy (I'm behind a firewall) to get HTML pages from the net?
http://www.faqts.com/knowledge-base/view.phtml/aid/2971
-------------------------------------------------------------
Fiona Czuczman
Charlie Derr, Graham Bleach

You have to set an environment variable.

It is http_proxy

# this usually works
import os, urllib
os.environ["http_proxy"]="http://firewall.bad.com:9999"
urllib.urlretrieve('http://www.python.org/')
#

This should put a copy of said page into a temp file.


-------------------------------------------------------------
Is it possible for a program to bind to a socket when that socket is already bound to another application to monitor i/o?
http://www.faqts.com/knowledge-base/view.phtml/aid/2976
-------------------------------------------------------------
Fiona Czuczman
Oleg Broytmann, Warren Postma

It is impossible.

But, why not write a Python program to be a server on port 25, which 
just opens another port and relays the data. Then reconfigure your 
original server (say SMTP) to go somewhere else, like 8881, and your 
Python program can redirect (with a small delay) as well as dumping out 
what comes in?

You can't leave your server app on the port and let anyone else use it, 
but you can fake it with a relay+dumping program. You could also (on 
Windows NT/2000 but not on Unix) "hook" the Winsock DLL functions. For 
more on how to build DLL hooks, go to the Microsoft Research web page 
and look for "DLL hooks".


-------------------------------------------------------------
Is there somewhere that I can download some introductory Tkinter documentation?
http://www.faqts.com/knowledge-base/view.phtml/aid/2975
-------------------------------------------------------------
Fiona Czuczman
Paul Magwene

The stuff at Pythonware (<http://www.pythonware.com/library.htm>) is 
great for viewing online, but I can't find any way of downloading it 
en-masse, so it's no good for reading on the tube...

Check out websucker.py in the /Tools/webchecker directory of your python
distribution.  This is great for downloading sights en-masse.  Just do
something like:

python websucker.py http://www.pythonware.com/library.htm

And it goes to work..


-------------------------------------------------------------
How can I import a library and source written in c into python?
http://www.faqts.com/knowledge-base/view.phtml/aid/2977
-------------------------------------------------------------
Fiona Czuczman
Tamer Fahmy, Roger Hansen

There are actually 2 possibilities I know of:
1. write a wrapper Python module to your C library.
   The document on http://www.python.org/doc/current/ext/ext.html
   should provide you with information how to do this.

2. write a C program, that uses your library in all needed aspects
   and call it with os.popen() with the parameters provided you need.

I would consider number 2 a rude hack but maybe it is quicker to do. ;)

This is a good solution if you only have to wrap a few functions.
However if it's a library I would suggest SWIG 
<Url: http://swig.sourceforge.net/ >
since wrapping lots of functions are boring and error-prone. But you
should look at the "Extending ..." document above to get the feeling
of things.


-------------------------------------------------------------
What's the best way to automate a PBEM (Play By E-Mail) game?
http://www.faqts.com/knowledge-base/view.phtml/aid/2974
-------------------------------------------------------------
Fiona Czuczman
richard

The following is needed:
* Run a game on regular times (1 to 5 times a week) by starting an 
executable and send some on hard disk stored files to the players (email 
address can be put into the name of the file or as first line in the 
file)
* Get mail from a Pop3 account and look for a certain subject: 'orders' 
when found this message must be saved to disk and a executable has to be
started with this file as parameter; as a result a file has to be sent 
to the sender of the orders.

This is all pretty straight forward in python.

You need to get some basic knowledge of your subject though, so peruse
www.python.org/doc

You should be looking at files, perhaps re or if it's really simple you
could just use the string module, and then the email libraries (perhaps
poplib and smtplib) in the standard librarie to work with mail. You even 
get some nice examples.







More information about the Python-list mailing list