A few tips - Python on unix based OSes (vim)

3
2

If you are using an OS like Linux,BSD or OSX these tips may help you.

If you are using vim as your text editor add these lines to .vimrc in you home folder (~/.vimrc)

set tabstop=4
set shiftwidth=4
set expandtab

If the file does not exist simple create it.

This sets your tab length to 4 and converts the tab into spaces. Python will accepts tabs or spaces as indentation but not a mixture of both.

These settings will ensure that your indents are always 4 spaces. If you open a file that already has tabs for indents then type :retab to change the tabs to spaces.

Add #!/usr/bin/python (path to the python binary) to the top of you python scripts and you will be able to run them directly from the shell. (run which python from the shell to get the path of the binary if it is in your systems search path)

Next make sure the file is executable by running chmod +x sudoku and finally to run the script ./sudoku

asked 15 Mar '12, 10:04

Carel%20Jansen's gravatar image

Carel Jansen
3451519
accept rate: 0%


One Answer:

Add #!/usr/bin/python (path to the python binary)

A more cross platform way of working with that is to use #!/bin/env python as it will pick up the first python instance in the path of the process that called it.

A lot of editors can convert tabs to spaces, as to a good number of IDE's since it is better to use spaces than tabs. It's a setting that should be looked for, not just in vim.

link

answered 15 Mar '12, 10:26

mhurron's gravatar image

mhurron
2.6k11135

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,273
×52
×34
×4
×3

Asked: 15 Mar '12, 10:04

Seen: 221 times

Last updated: 15 Mar '12, 10:26