‘@

Home 

python Programming Glossary: fileinput.input

Translating Perl to Python

http://stackoverflow.com/questions/1067060/translating-perl-to-python

where possible . import re fileinput def main for line in fileinput.input process False for nope in 'BEGIN TRANSACTION' 'COMMIT' 'sqlite_sequence'..

How to eliminate last digit from each of the top lines

http://stackoverflow.com/questions/1278664/how-to-eliminate-last-digit-from-each-of-the-top-lines

this question import fileinput import re for line in fileinput.input inplace True backup '.bak' line line.rstrip if line.startswith..

Inserting Line at Specified Position of a Text File in Python

http://stackoverflow.com/questions/1325905/inserting-line-at-specified-position-of-a-text-file-in-python

import fileinput processing_foo1s False for line in fileinput.input '1.txt' inplace 1 if line.startswith 'foo1' processing_foo1s..

How do you read from stdin in python

http://stackoverflow.com/questions/1450393/how-do-you-read-from-stdin-in-python

I learned from StackOverflow import fileinput for line in fileinput.input pass fileinput will loop through all the lines in the input..

How do I write to the middle of a text file while reading its contents?

http://stackoverflow.com/questions/16556944/how-do-i-write-to-the-middle-of-a-text-file-while-reading-its-contents

is to use fileinput module import fileinput for line in fileinput.input r'C Sanity_Automation ....tcl' inplace 1 print line # preserve.. filtering if the keyword argument inplace 1 is passed to fileinput.input or to the FileInput constructor the file is moved to a backup..

Howto bin series of float values into histogram in Python?

http://stackoverflow.com/questions/1721273/howto-bin-series-of-float-values-into-histogram-in-python

x return int math.log x 1 log2 diffCounts 0 5 for line in fileinput.input words line.split diff float words 0 1000 diffCounts str getBin..

Why do I have to press Ctrl+D twice to close stdin?

http://stackoverflow.com/questions/2162914/why-do-i-have-to-press-ctrld-twice-to-close-stdin

fileinput import sys for line in txt.strip for txt in fileinput.input if not line.isdigit sys.stderr.write ERROR not a number s n..

Python - Is a dictionary slow to find frequency of each character?

http://stackoverflow.com/questions/2522152/python-is-a-dictionary-slow-to-find-frequency-of-each-character

import collections fileinput textwrap chars ch for word in fileinput.input for ch in word.rstrip # faster 0.4s but less flexible chars..

How to replace unicode characters by ascii characters in Python (perl script given)?

http://stackoverflow.com/questions/2700859/how-to-replace-unicode-characters-by-ascii-characters-in-python-perl-script-giv

ord u'ΓΆ' u'oe' ord u'ΓΌ' u'ue' ord u' ' None for line in fileinput.input s line.decode 'utf8' print s.translate table And you could use..

How to add file extensions based on file type on Linux/Unix?

http://stackoverflow.com/questions/352837/how-to-add-file-extensions-based-on-file-type-on-linux-unix

do_rename False for filename in line.rstrip for line in fileinput.input output _ Popen 'file' ' bi' filename stdout PIPE .communicate.. import Popen PIPE for filename in line.rstrip for line in fileinput.input output _ Popen 'file' ' bi' filename stdout PIPE .communicate.. os import sys # this version supports only stdin part of fileinput.input functionality lines sys.stdin.read .split ' n' for line in lines..

How to deploy a Python application with libraries as source with no further dependencies?

http://stackoverflow.com/questions/527510/how-to-deploy-a-python-application-with-libraries-as-source-with-no-further-depe

directory ' .pth' if not files return for line in fileinput.input files line line.strip if line and line 0 '#' path os.path.join..

Is it possible to modify lines in a file in-place?

http://stackoverflow.com/questions/5453267/is-it-possible-to-modify-lines-in-a-file-in-place

# grep_some_condition.py import fileinput for line in fileinput.input inplace True if some_condition line print line # this goes to..

append line to beginning of a file

http://stackoverflow.com/questions/5914627/append-line-to-beginning-of-a-file

thefile. and def line_pre_adder filename line_to_prepend f fileinput.input filename inplace 1 for xline in f if f.isfirstline print line_to_prepend.rstrip..

Merging and sorting log files in Python

http://stackoverflow.com/questions/6653371/merging-and-sorting-log-files-in-python

f_names '1.log' '2.log' # names of log files lines list fileinput.input f_names t_fmt ' a b d H M S Y' # format of time stamps t_pat..

Insert string at the beginning of each line

http://stackoverflow.com/questions/7633485/insert-string-at-the-beginning-of-each-line

batteries included import fileinput import sys for line in fileinput.input '. ampo.txt' inplace True sys.stdout.write 'EDF l '.format l..

How to read large file, line by line in python

http://stackoverflow.com/questions/8009882/how-to-read-large-file-line-by-line-in-python

am looking for an alternative Code so far for each_line in fileinput.input input_file do_something each_line for each_line_again in fileinput.input.. input_file do_something each_line for each_line_again in fileinput.input input_file do_something each_line_again Executing this code..

Python equivalent of Perl's while (<>) {…}?

http://stackoverflow.com/questions/807173/python-equivalent-of-perls-while