Pages

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Tuesday, November 11, 2014

Vim as Python IDE (using Python-Mode)

Install pathogen
wget https://github.com/tpope/vim-pathogen/archive/master.zip
unzip master
cp -a vim-pathogen-master/autoload ~/vim/

Install Python-Mode
wget https://github.com/klen/python-mode/archive/develop.zip
unzip develop.zip
cp -a python-mode-develop/* ~/.vim/

Setup .vimrc
Add following text to your ~/.vimrc :
filetype off

call pathogen#infect()
call pathogen#helptags()

filetype plugin indent on
syntax on

Now, you can open a .py file and try to use command in vim such as ':PymodeLint', ':PymodeLintAuto' ...

For more information, use ':help pymode'


FAQ:

How to auto unfold all while opening .py file?
Add "autocmd Syntax python normal zR" to your ~/.vimrc by following command:
echo "autocmd Syntax python normal zR" >> ~/.vimrc

Folding hotkeys of python-mode:
zf/string creates a fold from the cursor to string .
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zc close a fold at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.

How to disable folding ?
Add "let g:pymode_folding = 0" to your ~/.vimrc by following command:
echo "let g:pymode_folding = 0" >> ~/.vimrc

How to disable highlight on column 80?
Currently, there is only a workaround.
Add "let g:pymode_options_colorcolumn = 0" to your ~./vimrc by following command: echo "let g:pymode_options_colorcolumn = 0" >> ~/.vimrc

Wednesday, October 1, 2014

Create Arbitrary Multi-Dimensional List in Python

#!/usr/bin/python
def AllocateMList(Dim):
    if len(Dim)!=1:
        tmp=[0]*Dim[0]
        for i in range(Dim[0]):
            tmp[i]=AllocateMList(Dim[1:])
        return tmp
    else:
        return [0]*Dim[0]


#Specify Dimensions
PR=[3, 5, 7]
print "PR:", PR

#Allocate Multi-Dimensional List
TL=AllocateMList(PR)
print "TL:", TL

#Write access
TL[0][1][2]=787
print "write 787 to TL[0][1][2]"

#Check result
print "TL:", TL

Tuesday, November 12, 2013

Eclipse Setup for C, C++, Java, Python, PHP, PERL, Shell Scripst, Verilog and VHDL with Vim-Like Editing

General

Install Eclipse
yum install eclipse
Vim-Like Editing
yum install eclipse-vrapper

for C/C++ (using CDT)
Install CDT
yum install eclipse-cdt

for Java (using JDT)

Install JDT
yum install eclipse-jdt

Specify Java VM
http://stackoverflow.com/questions/2030434/eclipse-no-java-jre-jdk-no-virtual-machine

for Python (using Pydev)
Install Pydev
yum install eclipse-pydev

for PHP(using PHP Eclipse)
Install PHP Eclipse
yum ibnstall eclipse-phpeclipse

for PERL (using EPIC)

Install EPIC
yum install eclipse-epic
OR
Install pad-walker for debugging
yum install perl-PadWalker

Launch Eclipse
eclipse &
Add Software Source
Select "Help/Install New Software" from menu bar
Click "Available Software Sites"
Click "Add"
Enter following information:
Name "EPIC"
Location "http://e-p-i-c.sf.net/updates"
Install "EPIC Main Components"
Install "EPIC Main Components" in the available software.
REF: http://www.epic-ide.org/download.php

for Shell Scripts (using Shelled Eclipse)
Install Shelled Eclipse
yum install eclipse-shelled

for Verilog and VHDL (using Veditor)
Install Veditor
yum install eclipse-veditor