博文

目前显示的是 八月, 2016的博文

Quick perl syntax walkthrough

datatype and variables Perl maintains every variable type in a separate namespace. So you can, without fear of conflict, use the same name for a scalar variable, an array, or a hash. This means that $foo and @foo are two different variables. array @names = ("John Paul", "Lisa", "Kumar"); print "$names[0]\n"; @array = (1, 2, 'Hello'); # populate using qw operator @array = qw/This is an array/; hash %data = ('John Paul', 45, 'Lisa', 30, 'Kumar', 40); print "$data{'John Paul'}"; special literal print "File name ". __FILE__ . "\n"; print "Line Number " . __LINE__ ."\n"; print "Package " . __PACKAGE__ ."\n"; perldebug open debugger on command line iwth perl -de1 private variables in sub-routine with 'my' keyword tempoary value to give global variable via local keyword reference to variables and subroutine $s...

How to install pydev on nsight eclipse

You need to have jdk version 1.7 on your machine. You need to manuall install the plugin pydev 2.8.2 version Download pydev from http://sourceforge.net/projects/pydev/files/ and upzip it. Drop the unzipped files in respect eclipse plugin folders. Note PyDev will not appear in Eclipse despite you have Java 7 on your machine. The solution is to run eclipse with -clean argument. On ubuntu, you need to run it with root - sudo nsight -clean with nsight you need /usr/local/cuda-7.0/libnsight $ sudo ./nsight -clean Configure pydev to use correct interpreter and libs from pyenv first use command "pyenv versions" and "which python" to find which python is used in your environment set the interpreter to: ~/.pyenv/shims/python2.7 set the system libs to: ~/.pyenv/versions/2.7.11/envs/DrivePX/lib/python2.7/site-packages/ (if you don't take the pythonpath from virutalenv, you do not have access to these site-packages which are required to run the code) R...

What is the use of code if __name__ == '__main__'?

What is the use of code if __name__ == '__main__'? When the Python interpreter reads a source file, it executes all of the code found in it. Before executing the code, it will define a few special variables. For example, if the python interpreter is running that module (the source file) as the main program, it sets the special __name__ variable to have a value "__main__". If this file is being imported from another module, __name__ will be set to that module's name. In the case of your script, let's assume that it's executing as the main function, e.g. you execute something like python threading_example.py on the command line. After setting up the special variables, it will execute the import statement and load those modules. It will then evaluate the def block, creating a function object and creating a variable called myfunction that points to the function object. It will then read the if statement and see that __name__ does equal "__main__...

What is __init__.py used for?

Files named __init__.py are used to mark directories on disk as Python package directories. For example, suppose you have these files: dir/spam/__init__.py dir/spam/module.py and dir is on your python path, then you can import the module.py as import spam.module or from spam import module If you remove the __init__.py file, Python will no longer look for submodules inside that directory, so attempts to import the module will fail. The __init__.py file is usually empty, but can be used to export selected portions of the package under more convenient name, hold convenience functions, etc. Given the example above, the contents of the init module can be accessed as import spam Reference http://effbot.org/pyfaq/what-is-init-py-used-for.htm