When a module is imported into a program, how to find out the path from where the module is getting picked?
In the Unix world, when a command say ls is executed, the operating system searches in a list of directories for the command executable and once found, executes the command. The list of directories is maintained in the PATH variable.
Similarly, in Python, whenever a module is imported, say "import collections', python also searches in a list of directories to find the module file "collections.py", and once found, includes the module. The list of directories to be searched is maintained in a list, sys.path, from the sys module. Hence, this can be accessed using the sys.path.
Tuesday, July 30, 2013
Friday, July 19, 2013
Perl : Foreach loop variable is an alias
In Perl, when an array is traversed using the foreach loop, the variable holding the element of the array during the iteration is actually an alias to the actual element itself. Due to this, any change done to this variable automatically updates the array itself.
Let us see some examples where every element of an array has to be added by 10:
1. Array elements get updated when updating $_:
Let us see some examples where every element of an array has to be added by 10:
1. Array elements get updated when updating $_:
#!/usr/bin/perl use warnings ; use strict ; $\="\n"; my @arr=(5..8); print "@arr"; foreach (@arr){ $_+=10; } print "@arr";This snippet when run outputs:
5 6 7 8 15 16 17 18As seen above, just by updating the $_, the array elements get updated automatically.
Wednesday, July 17, 2013
Linux For You - A magazine for Open Source techies
Linux For You(LFY) or the OpenSource For You is the magazine which you should be having if you are a techy, especially for the ones working in Unix or Linux flavors. I accidentally got my hands on the magazine once, and made it a point to subscribe to it immediately.
My 5 reasons why it is a must in your shelf:
1. Knowledge on Linux World: Linux is one such technology which has no limits. You keep learning, Linux keeps providing something new for you to satisfy your hunger. However, its not possible to learn everything by ourself through our experiments. It takes lot of time to learn anything by oneself. This magazine is a place wherein you get lot of knowledge, good knowledge, in a short span of time. The topics covered can be of any programming language, scripting language, system administration stuff, apps programming stuff, review of any particular software, etc. Last but not the least, the articles always come with lots of explanation.
My 5 reasons why it is a must in your shelf:
1. Knowledge on Linux World: Linux is one such technology which has no limits. You keep learning, Linux keeps providing something new for you to satisfy your hunger. However, its not possible to learn everything by ourself through our experiments. It takes lot of time to learn anything by oneself. This magazine is a place wherein you get lot of knowledge, good knowledge, in a short span of time. The topics covered can be of any programming language, scripting language, system administration stuff, apps programming stuff, review of any particular software, etc. Last but not the least, the articles always come with lots of explanation.
Subscribe to:
Posts (Atom)