python Programming Glossary: fileinput
How do I concatenate files in Python? http://stackoverflow.com/questions/1001538/how-do-i-concatenate-files-in-python one file. What's the best way to do this in Python Use fileinput module to loop through each line of each file and write it to..
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 pseudo inplace changes to a file in Python is with the fileinput module from the standard library import fileinput processing_foo1s.. with the fileinput module from the standard library import fileinput processing_foo1s False for line in fileinput.input '1.txt' inplace.. 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 This is something I learned from StackOverflow import fileinput for line in fileinput.input pass fileinput will loop through.. I learned from StackOverflow import fileinput for line in fileinput.input pass fileinput will loop through all the lines in the.. import fileinput for line in fileinput.input pass fileinput will loop through all the lines in the input specified as file..
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 What's the right way to do it # usr bin env python import fileinput math log2 math.log 2 def getBin x return int math.log x 1 log2.. 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..
Add columns to CSV while writing the CSV http://stackoverflow.com/questions/20224912/add-columns-to-csv-while-writing-the-csv file with same permissions # borrowed extensively from the fileinput module if set mode set 'wa ' raise ValueError 'Only read only..
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 and outputs an error if the input is not a number. import fileinput import sys for line in txt.strip for txt in fileinput.input.. fileinput import sys for line in txt.strip for txt in fileinput.input if not line.isdigit sys.stderr.write ERROR not a number..
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 0.5 seconds # usr bin env python3.1 import collections fileinput textwrap chars ch for word in fileinput.input for ch in word.rstrip.. import collections fileinput textwrap chars ch for word in fileinput.input for ch in word.rstrip # faster 0.4s but less flexible..
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 unicode diacritics share improve this question Use the fileinput module to loop over standard input or a list of files decode.. like this # usr bin env python2.6 # coding utf 8 import fileinput table 0xe4 u'ae' ord u'ΓΆ' u'oe' ord u'ΓΌ' u'ue' ord u' ' None.. 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..
Python and csv help http://stackoverflow.com/questions/2930673/python-and-csv-help AND RETURN UID #REPLACE VALUE IN FILE WITH UID #import fileinput #for line in fileinput.FileInput filetoreplace inplace 1 # line.. VALUE IN FILE WITH UID #import fileinput #for line in fileinput.FileInput filetoreplace inplace 1 # line line.replace replacethistext..
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 your project folder import os from glob import glob import fileinput import sys def apply_pth_files scriptfilename at_beginning False.. 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 lines It can be simulated using a backup file as stdlib's fileinput module does. Here's an example script that removes lines that.. stdin # usr bin env python # grep_some_condition.py import fileinput for line in fileinput.input inplace True if some_condition line.. # grep_some_condition.py import fileinput for line in fileinput.input inplace True if some_condition line print line # this..
Merging and sorting log files in Python http://stackoverflow.com/questions/6653371/merging-and-sorting-log-files-in-python share improve this question You can do this import fileinput import re from time import strptime f_names '1.log' '2.log'.. 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..
Python and User input http://stackoverflow.com/questions/70797/python-and-user-input want to input files to your script behold the power of fileinput . The Python library reference is your friend . share improve..
Insert string at the beginning of each line http://stackoverflow.com/questions/7633485/insert-string-at-the-beginning-of-each-line question Python comes with batteries included import fileinput import sys for line in fileinput.input '. ampo.txt' inplace.. batteries included import fileinput import sys for line in fileinput.input '. ampo.txt' inplace True sys.stdout.write 'EDF l '.format..
Python equivalent of Perl's while (<>) {…}? http://stackoverflow.com/questions/807173/python-equivalent-of-perls-while input python stdin share improve this question The fileinput module in the standard library is just what you want import.. in the standard library is just what you want import fileinput for line in fileinput.input ... share improve this answer..
|