¡@

Home 

python Programming Glossary: io

Reading binary file in Python

http://stackoverflow.com/questions/1035340/reading-binary-file-in-python

file and loop over each byte of that file python file io binary share improve this question f open myfile rb try.. that file python file io binary share improve this question f open myfile rb try byte f.read 1 while byte # Do stuff.. stuff with byte. byte f.read 1 finally f.close By suggestion of chrispy with open myfile rb as f byte f.read 1 while byte..

IOError when trying to open existing files

http://stackoverflow.com/questions/10802418/ioerror-when-trying-to-open-existing-files

with a python program that I wrote to extract some information from a special text file. What I'm trying to do is merge together.. merged list. The loop code below needs to execute my function extract_zcoords over 500 files 1 file gives one list so that.. CODE # usr local bin import os string from sys import version # def extract_zcoord filename ''' collect z coordinates of..

How might I remove duplicate lines from a file?

http://stackoverflow.com/questions/1215208/how-might-i-remove-duplicate-lines-from-a-file

How to delete repeated lines in a file python text file io share improve this question On Unix Linux use the uniq command.. in a file python text file io share improve this question On Unix Linux use the uniq command as per David Locke's answer.. line outfile.close Update The sort uniq combination will remove duplicates but return a file with the lines sorted..

Get last n lines of a file with Python, similar to tail

http://stackoverflow.com/questions/136168/get-last-n-lines-of-a-file-with-python-similar-to-tail

to tail I'm writing a log file viewer for a web application and for that I want to paginate through the lines of the log.. way to tail log files with offsets python file file io tail logfiles share improve this question This may be quicker.. file file io tail logfiles share improve this question This may be quicker than yours. Makes no assumptions about..

Python recursive folder read

http://stackoverflow.com/questions/2212643/python-recursive-folder-read

toWrite f.close folderOut.close python scripting file io share improve this question Make sure you understand the.. python scripting file io share improve this question Make sure you understand the three return values of os.walk..

How to write a multidimensional array to a text file?

http://stackoverflow.com/questions/3685265/how-to-write-a-multidimensional-array-to-a-text-file

to write a multidimensional array to a text file In another question other users offered.. a multidimensional array to a text file In another question other users offered some help if I could supply the array I.. on others. Edit So I've tried the numpy.savetxt function. Strangely it gives the following error TypeError float argument..

Non-blocking read on a subprocess.PIPE in python

http://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python

stdout subprocess.PIPE str p.stdout.readline python io subprocess nonblocking share improve this question fcntl.. python io subprocess nonblocking share improve this question fcntl select asyncproc won't help in this case. Reliable..

Find all files in directory with extension .txt with python

http://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt-with-python

all files in directory with extension .txt with python How can I find all files in directory with.. How can I find all files in directory with the extension .txt in python python file io share improve this question.. directory with the extension .txt in python python file io share improve this question you can use glob import glob..

python close file descriptor question

http://stackoverflow.com/questions/4599980/python-close-file-descriptor-question

close file descriptor question I think this question is more of a coding style rather than.. close file descriptor question I think this question is more of a coding style rather than technical issue. Said.. not closed what is the prefer way to close it python file io coding style share improve this question If you assign the..

Python: open multiple files using “with open”?

http://stackoverflow.com/questions/4617034/python-open-multiple-files-using-with-open

'b' 'w' as b do_something except IOError as e print 'Operation failed s' e.strerror If that's not possible what would an elegant.. If that's not possible what would an elegant solution to this problem look like python file io share improve this.. an elegant solution to this problem look like python file io share improve this question As of Python 2.7 or 3.1 respectively..

Editing specific line in text file in python

http://stackoverflow.com/questions/4719438/editing-specific-line-in-text-file-in-python

in text file in python This may sound like a dumb question but I looked at python's IO and my last question. Let's say.. dumb question but I looked at python's IO and my last question. Let's say I have a text file containing Dan Warrior 500 1.. question. Let's say I have a text file containing Dan Warrior 500 1 0 is there a way I can edit a specific line in that text..

Unicode (utf8) reading and writing to files in python

http://stackoverflow.com/questions/491921/unicode-utf8-reading-and-writing-to-files-in-python

What does one type into text files to get proper conversions. Edit What I'm truly failing to grok here is what the point.. to grok here is what the point of the UTF 8 representation is if you can't actually get Python to recognize it when it.. use that instead since that has an asciiable representation More to the point is there an ascii representation of this..

In Python, is read() , or readlines() faster?

http://stackoverflow.com/questions/5076024/in-python-is-read-or-readlines-faster

this. How about the loop for line in fileHandle python io share improve this question For a text file just iterating.. line in fileHandle python io share improve this question For a text file just iterating over it with a for loop is.. go. Never mind about speed it is the cleanest. In some versions of python readline really does just read a single line while..

Lazy Method for Reading Big File in Python?

http://stackoverflow.com/questions/519633/lazy-method-for-reading-big-file-in-python

pieces I would love to have a lazy method . python file io generator share improve this question To write a lazy function.. . python file io generator share improve this question To write a lazy function just use yield def read_in_chunks.. share improve this question To write a lazy function just use yield def read_in_chunks file_object chunk_size 1024..

Correct way to write line to file in Python

http://stackoverflow.com/questions/6159900/correct-way-to-write-line-to-file-in-python

specific IE should I be doing r n on Windows python file io share improve this question You should use the new print.. r n on Windows python file io share improve this question You should use the new print statement available with Python.. with Python 2.6 from __future__ import print_function print hi there file f The alternative would be to use f open..

Speed comparison with Project Euler: C vs Python vs Erlang vs Haskell

http://stackoverflow.com/questions/6964392/speed-comparison-with-project-euler-c-vs-python-vs-erlang-vs-haskell

exercise and to compare my surely not optimal implementations in C Python Erlang and Haskell. In order to get some higher.. Erlang and Haskell. In order to get some higher execution times I search for the first triangle number with more than.. that C has a big advantage as it uses long for the calculations and not arbitrary length integers as the other three. Also..

what exactly the python's file.flush() is doing?

http://stackoverflow.com/questions/7127075/what-exactly-the-pythons-file-flush-is-doing

file.flush is doing I found this in the Python documentation for File Objects flush does not necessarily write the file.. disk. Use flush followed by os.fsync to ensure this behavior. So my question is what exactly is Python's flush doing I thought.. followed by os.fsync to ensure this behavior. So my question is what exactly is Python's flush doing I thought that it forces..

Python: Write a list to a file

http://stackoverflow.com/questions/899103/python-write-a-list-to-a-file

there would be a standard way... python file list file io newline share improve this question Personally I'd use a.. python file list file io newline share improve this question Personally I'd use a loop for item in thelist thefile.write.. thelist print thefile item If you're keen on a single function call at least remove the square brackets so that the strings..

Usage of sys.stdout.flush() method

http://stackoverflow.com/questions/10019456/usage-of-sys-stdout-flush-method

PyAudio Input overflowed

http://stackoverflow.com/questions/10733903/pyaudio-input-overflowed

564 in read return pa.read_stream self._stream num_frames IOError Errno Input overflowed 9981 I can't understand this buffer... I can't understand this buffer. I want to use blocking IO mode so if chunks not available i want to wait for those chunks...

Processing single file from multiple processes in python

http://stackoverflow.com/questions/11196367/processing-single-file-from-multiple-processes-in-python

and it depends on whether your work is cpu bound or IO bound. Basic multiprocessing.Pool example Here is a really basic..

catching stdout in realtime from subprocess

http://stackoverflow.com/questions/1606795/catching-stdout-in-realtime-from-subprocess

3.1 now since I heard it should be better at handling IO. import subprocess time os sys cmd rsync.exe vaz P source dest..

Python thread pool similar to the multiprocessing Pool?

http://stackoverflow.com/questions/3033952/python-thread-pool-similar-to-the-multiprocessing-pool

the GIL. However in my usecase the function will be an IO bound C function for which the python wrapper will release the..

How can I speed up fetching pages with urllib2 in python?

http://stackoverflow.com/questions/3490173/how-can-i-speed-up-fetching-pages-with-urllib2-in-python

For example he said 1 for suggesting threads. This is IO bound threads are useless here. This contrary to evidence as..

Image library for Python 3

http://stackoverflow.com/questions/3896286/image-library-for-python-3

pythonlibs #pil Pygame works on Python 3 and has image IO and processing capabilities based on SDL . It is also relatively..

socket.shutdown vs socket.close

http://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close

a difference this socket is being used for non blocking IO. python sockets asynchronous share improve this question..

python library for splitting video

http://stackoverflow.com/questions/4580576/python-library-for-splitting-video

OpenCV has Python wrappers . As you're interested in video IO have a look at QueryFrame and its related functions there. In..

Editing specific line in text file in python

http://stackoverflow.com/questions/4719438/editing-specific-line-in-text-file-in-python

may sound like a dumb question but I looked at python's IO and my last question. Let's say I have a text file containing.. open 'stats.txt' 'a' myfile.writelines 'Mage' 1 except IOError myfile.close finally myfile.close Yes I know that myfile.writelines..

Python subprocess get children's output to file and terminal?

http://stackoverflow.com/questions/4984428/python-subprocess-get-childrens-output-to-file-and-terminal

stderr sys.stderr for t in threads t.join # wait for IO completion return p.wait outf errf open 'out.txt' 'w' open 'err.txt'..

Python code performance decreases with threading

http://stackoverflow.com/questions/6821477/python-code-performance-decreases-with-threading

versions of the parsing code to see if my program is IO bound. It doesn't seem to be just reading in the file takes.. processing the file is almost all of it. If I don't do the IO and process an already read version of a file I adding a second..

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

object f as an iterable which automatically uses buffered IO and memory management so you don't have to worry about large..

Is it possible to speed-up python IO?

http://stackoverflow.com/questions/849058/is-it-possible-to-speed-up-python-io

it possible to speed up python IO Consider this python program import sys lc 0 for line in open..

Using a simple python generator as a co-routine in a Tornado async handler?

http://stackoverflow.com/questions/8812715/using-a-simple-python-generator-as-a-co-routine-in-a-tornado-async-handler

generator as a co routine and passing off control to the IOLoop after every chunk. However I can't make heads or tails of.. To avoid blocking you can pass your generator to the IOLoop via a callback function. The trick here is since you are.. here is since you are not using a process that does actual IO and so has no os level process file handler to add to the IOLoop..

Why is splitting a string slower in C++ than Python?

http://stackoverflow.com/questions/9378500/why-is-splitting-a-string-slower-in-c-than-python

time NULL cin.sync_with_stdio false disable synchronous IO while cin getline cin input_line spline.clear empty the vector.. time NULL cin.sync_with_stdio false disable synchronous IO while cin getline cin input_line spline.clear empty the vector..

Python Global Interpreter Lock (GIL) workaround on multi-core systems using taskset on Linux?

http://stackoverflow.com/questions/990102/python-global-interpreter-lock-gil-workaround-on-multi-core-systems-using-task

backfire on multi core systems and you end up with IO intensive threads being heavily blocked by CPU intensive threads..

NumPy vs. multiprocessing and mmap

http://stackoverflow.com/questions/9964809/numpy-vs-multiprocessing-and-mmap

if you can live with extra memory copies is to do all IO in one process and then send things out to a pool of worker..