Reading from a frequently updated file

I would recommend looking at David Beazley’s Generator Tricks for Python, especially Part 5: Processing Infinite Data. It will handle the Python equivalent of a tail -f logfile command in real-time. # follow.py # # Follow a file like tail -f. import time def follow(thefile): thefile.seek(0,2) while True: line = thefile.readline() if not line: time.sleep(0.1) … Read more

fopen deprecated warning

It looks like Microsoft has deprecated lots of calls which use buffers to improve code security. However, the solutions they’re providing aren’t portable. Anyway, if you aren’t interested in using the secure version of their calls (like fopen_s), you need to place a definition of _CRT_SECURE_NO_DEPRECATE before your included header files. For example: #define _CRT_SECURE_NO_DEPRECATE … Read more

Difference between r+ and w+ in fopen()

Both r+ and w+ can read and write to a file. However, r+ doesn’t delete the content of the file and doesn’t create a new file if such file doesn’t exist, whereas w+ deletes the content of the file and creates it if it doesn’t exist.

Writing a new line to file in PHP (line feed)

Replace ‘\n’ with “\n”. The escape sequence is not recognized when you use ‘. See the manual. For the question of how to write line endings, see the note here. Basically, different operating systems have different conventions for line endings. Windows uses “\r\n”, unix based operating systems use “\n”. You should stick to one convention … Read more

PHP – Failed to open stream : No such file or directory

There are many reasons why one might run into this error and thus a good checklist of what to check first helps considerably. Let’s consider that we are troubleshooting the following line: require “/path/to/file” Checklist 1. Check the file path for typos either check manually (by visually checking the path) or move whatever is called … Read more

C fopen vs open

First, there is no particularly good reason to use fdopen if fopen is an option and open is the other possible choice. You shouldn’t have used open to open the file in the first place if you want a FILE *. So including fdopen in that list is incorrect and confusing because it isn’t very … Read more

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