What’s the difference between io.open() and os.open() on Python?

io.open() is the preferred, higher-level interface to file I/O. It wraps the OS-level file descriptor in an object that you can use to access the file in a Pythonic manner. os.open() is just a wrapper for the lower-level POSIX syscall. It takes less symbolic (and more POSIX-y) arguments, and returns the file descriptor (a number) … Read more

IO 101: Which are the main differences between TextWriter, FileStream and StreamWriter?

Streams handle bytes, Writers handle characters. Bytes != characters. A character may take more than one byte to represent. The mapping from characters to bytes is called an encoding. A FileStream refers to the bytes being written to a file, similar to how a MemoryStream refers to the bytes written to an in-memory buffer. In … Read more

Non-blocking console input C++

Example using C++11: #include <iostream> #include <future> #include <thread> #include <chrono> static std::string getAnswer() { std::string answer; std::cin >> answer; return answer; } int main() { std::chrono::seconds timeout(5); std::cout << “Do you even lift?” << std::endl << std::flush; std::string answer = “maybe”; //default to maybe std::future<std::string> future = std::async(getAnswer); if (future.wait_for(timeout) == std::future_status::ready) answer = … Read more

Haskell program involving `read` is much slower than an equivalent Python one

read is slow. For bulk parsing, use bytestring or text primitives, or attoparsec. I did some benchmarking. Your original version ran in 23,9 secs on my computer. The version below ran in 0.35 secs: import qualified Data.ByteString.Char8 as B import Control.Applicative import Data.Maybe import Data.List import Data.Char main = print . sum =<< getIntList getIntList … Read more

How do you open a file in C++?

You need to use an ifstream if you just want to read (use an ofstream to write, or an fstream for both). To open a file in text mode, do the following: ifstream in(“filename.ext”, ios_base::in); // the in flag is optional To open a file in binary mode, you just need to add the “binary” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)