Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
18dc7165
Commit
18dc7165
authored
Jul 07, 1992
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial revision
parent
db151d67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
Demo/scripts/pp.py
Demo/scripts/pp.py
+48
-0
No files found.
Demo/scripts/pp.py
0 → 100755
View file @
18dc7165
#! /usr/local/python
# Wrapper around Python to emulate the Perl -ae options:
# (1) first argument is a Python command
# (2) rest of arguments are input to the command in an implied loop
# (3) each line is put into the string L with trailing '\n' stripped
# (4) the fields of the line are put in the list F
# (5) also: FILE: full filename; LINE: full line; FP: open file object
# The command line option "-f FS" sets the field separator;
# this is available to the program as FS.
import
sys
import
string
import
getopt
FS
=
''
optlist
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'f:'
)
for
option
,
optarg
in
optlist
:
if
option
==
'-f'
:
FS
=
optarg
command
=
args
[
0
]
if
not
args
[
1
:]:
args
.
append
(
'-'
)
prologue
=
[
\
'for FILE in args[1:]:'
,
\
'
\
t
if FILE ==
\
'
-
\
'
:'
,
\
'
\
t
\
t
FP = sys.stdin'
,
\
'
\
t
else:'
,
\
'
\
t
\
t
FP = open(FILE,
\
'
r
\
'
)'
,
\
'
\
t
while 1:'
,
\
'
\
t
\
t
LINE = FP.readline()'
,
\
'
\
t
\
t
if not LINE: break'
,
\
'
\
t
\
t
L = LINE[:-1]'
,
\
'
\
t
\
t
if FS: F = string.splitfields(L, FS)'
,
\
'
\
t
\
t
else: F = string.split(L)'
\
]
# Note that we indent using tabs only, so that any indentation style
# used in 'command' will come out right after re-indentation.
program
=
string
.
joinfields
(
prologue
,
'
\
n
'
)
for
line
in
string
.
splitfields
(
command
,
'
\
n
'
):
program
=
program
+
(
'
\
n
\
t
\
t
'
+
line
)
program
=
program
+
'
\
n
'
exec
(
program
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment