The following command works fine:
sed s/input/raw_input/ p.py >p2.py && mv p2.py p.py
However, the following command turns p.py into an empty file:
sed s/input/raw_input/ p.py >p.py
The following also turns p.py into an empty file:
sed s/input/raw_input/ p.py | cat > p.py
Why don't the last two commands behave as expected? In particular why is p.py empty?