Python: Write array values into file

The for loop will ask i to iterate over the values of an iterable, and you’re providing a single int instead of an iterable object You should iterate over range(0,len(highscores)): or better, iterate directly over the array

In C, how should I read a text file and print all strings

The simplest way is to read a character, and print it right after reading: c is int above, since EOF is a negative number, and a plain char may be unsigned. If you want to read the file in chunks, but without dynamic memory allocation, you can do: The second method above is essentially how you will read a file with a dynamically … Read more

Why am I getting a FileNotFoundError?

I’m trying to write a simple program to read a file and search for a word then print how many times that word is found in the file. Every time I type in “test.rtf” (which is the name of my document) I get this error: In class last semester, I remember my professor saying you … Read more

Python list directory, subdirectory, and files

Use os.path.join to concatenate the directory and file name: Note the usage of path and not root in the concatenation, since using root would be incorrect. In Python 3.4, the pathlib module was added for easier path manipulations. So the equivalent to os.path.join would be: The advantage of pathlib is that you can use a variety of useful methods on paths. If you use the concrete Path variant you can also do actual OS … Read more

how to “execute” make file

You don’t tend to execute the make file itself, rather you execute make, giving it the make file as an argument: If your make file is actually one of the standard names (like makefile or Makefile), you don’t even need to specify it. It’ll be picked up by default (if you have more than one of these standard names … Read more