Unix Network Programming code in Python
Python is more expressive than C
The unit tests cover Python2.7 and Python3.3
Python2.6 is not supported because it lacks lots of good stuff which is available in Python2.7 (things backported from py3k)
In py3k series, only Python3.3 is supported.
Please send a pull request to me. Note: make sure your commits have detailed commit message
pip install -e git+https://github.com/yegle/unp-code-in-python.git#egg=unp
- In the UNP book, you'll find the text under example code, something
like
intro/daytimetcpcli.c
- Run the corresponding code using
unp run intro/daytimetcpcli.py
. - If you need to run code with arguments, add the argument at the end.
e.g.
unp run intro/daytimetcpcli.py 127.0.0.1
This is a small wrapper command for running/editing the Python code provided.
To use the unp
command, you need to specify the action you want and
the target of the action.
Some simple examples of using the command:
- Running code:
unp run intro/byteorder.py
- Running with arguments:
unp run intro/daytimetcpcli.py 127.0.0.1
- Running with arguments:
- Show which script is executed:
unp show intro/byteorder.py
- Editing the script:
unp edit intro/byteorder.py
- It's recommended to install this package in some virtual environment, so editing scripts doesn't need root permission.
- Listing scripts using wildcard or directory name (not yet
implemented):
unp ls intro/
Actually it's hard to run without organizing the code into a package.
But it's possible to run the code without the unp
command. Here's a
simple example code:
import sys
if __name__ == '__main__':
from unp.intro import byteorder
byteorder.main(sys.argv[0], sys.argv[1:])
If you really want to run the code somewhere else, you need to take care of the somewhat complex imports in the code.