Every Python source file can essentially be considered as a module. The following rule applies to the name of a module, if it needs to be imported without problems:
(letter|"_") (letter | digit | "_")*
That is, the rule for naming a Python file is the same as naming a variable in it. First character has to be letter or underscore, followed by any number of letters, digits or underscores. No other characters, like dash, are allowed.
If the file is not named correctly, the following error or warning might be generated on importing it:
Invalid name for Python module
Tried with: Python 2.7.6 and Ubuntu 14.04
fread functions can be used to read binary data from a file. Assume, we have stored the values of a matrix of 100 rows and 100 columns in binary format in a file. Such a file could be produced from a C or C++ program. Let us also assume that that data type of the values is
short of 2 bytes.
To read the data from this binary file and reconstruct the original matrix:
> bfile = fopen('matdata.bin');
> bdata = fread(bfile, 'short');
> B = reshape(bdata, 100, 100);
These functions are from Matlab and so will work in it too.
Tried with: Octave 3.8.1 and Ubuntu 14.04
file is one of those Linux utilities that is not popular, but useful to know. It reads the magic pattern of a file and determines the type of the file. It might be useful to try on files that you come across with no extensions or with extensions that you are not familiar with.
Tried with: Ubuntu 12.04 LTS
When you open a program in Ubuntu, it might quit complaining that another process has locked a file or directory it is trying to open.
For example, here is an error of this kind:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
To continue, you might have to find the offending process and stop it. The lsof command can be used for this purpose.
For example, to find out which process has locked the
/var/lib/dpkg directory in the above example:
$ lsof | grep /var/lib/dpkg
Tried with: Ubuntu 12.04.1 LTS
The lsof command can be used to list the open files in Ubuntu. The first leftmost column is the process name and the last rightmost column is the name of the file it has opened. The command is easy to remember as the ls of open files.
Tried with: Ubuntu 12.04.1 LTS
There is no grep or ack on Windows. Windows 7 has a good search engine that can be used to search for text inside files. However, it requires indexing to be turned on for this feature. I do not like the indexing happening in the background nor do I like indexed information to be stored before I search for something.
As a good grep replacement, I like Agent Ransack. It can search for a particular text in text files and files of other formats. It builds the index on the fly and does not store it for future use. It includes support for searching inside popular binary file formats like Microsoft Office, Libre Office and PDF.
Tried with: Agent Ransack (Release Build 762 – 2010.03.29.47911)