Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual brackets in Python

Tags:

python

linux

(Warning: Potential flame-war starter. This is however not my goal, the point here is not to discuss the design choices of Python, but to know how to make the best out of it).

Is there a program, script, method (Unix-based, ideally), to display "virtual" brackets around blocs of code in Python, and to keep them where they are so that the code can still be executed even if indenting is broken ?

I realize that Python only uses indentation to define blocks of code, and that the final program may not contain brackets.

However, I find it very annoying that your program can stop functioning just because of an unfortunate and undetected carriage-return.

So, ideally I would be looking for a plugin in a text editor (kate, gedit...) that would:

  • Display virtual brackets around blocks of code in my Python program
  • Keep them in place
  • Generate dynamically the "correct" Python code with the indentation corresponding to where the brackets belong.

(no flame-war, please !)

like image 258
calvin tiger Avatar asked Jun 05 '12 12:06

calvin tiger


People also ask

What do [] brackets mean in Python?

Index brackets ([]) have many uses in Python. First, they are used to define "list literals," allowing you to declare a list and its contents in your program. Index brackets are also used to write expressions that evaluate to a single item within a list, or a single character in a string.

Can we use brackets in Python?

Lists. Lists, as mutable collections, are one of the basic data types inside Python. You use square brackets to create lists for both empty lists and those that have items inside them.

How many types of brackets are there in Python?

They are parentheses, square brackets, curly brackets, and angle brackets. Of these four, parentheses are by far the most commonly used and are the punctuation marks that most writers are likely most familiar with.


1 Answers

I used an editor that does code rollups and understood Python syntax, then I looked for rollups that are in unexpected locations. I don't remember if Kate does that. It's not obvious that there is an issue, but it makes it easier when you are looking for an issue.

like image 89
JerseyMike Avatar answered Oct 01 '22 11:10

JerseyMike