Hi i have some questions :

  1. i want to paste block of function into the python console and got a lot of indentation error. Is this a bug or do i miss something ? i'm using 2.79.

  2. I'm new in coding. What is the best IDE for doing interactive debugging regarding building python code/function for Blender ?

Anyone can help ?

class VIEW3D_MT_edit_mesh_looptools(bpy.types.Menu):
    """    LOOPTOOLS    """
    bl_idname = "loop.tools" 
    bl_label = "LoopTools"

    def draw(self, context):
        layout = self.layout
        layout.operator("mesh.looptools_bridge", text="Bridge").loft = False
        layout.operator("mesh.looptools_bridge", text="Loft").loft = True

enter image description here

  • $\begingroup$ Suggest use spaces rather than tabs for indent. (there is a convert to spaces on the text editor window) Unfortunately the py console sees the blank line as a full unindent. Related $\endgroup$
    – batFINGER
    Commented May 30, 2018 at 11:41
  • $\begingroup$ Thanks , i found the problem. when pasting , Blender won't accept the empty line in the codes (like empty line between that bl_label and def draw). this is strange..... $\endgroup$
    – andio
    Commented May 30, 2018 at 13:11
  • 1
    $\begingroup$ Have a look at script in updated addon link It will use the script stub to run the script from the text editor into the py console. The locals from the script are available in the py console. $\endgroup$
    – batFINGER
    Commented May 30, 2018 at 14:53

4 Answers 4


It's because double newline char forces your class declaration terminated at line 5. So it complains the function draw is a bad indent.

The >>> in the snapshot indicates the problem. however I still don't know how to solve this copy paste class declaration in python console issue.

  • $\begingroup$ Thank you very much for this hint! It's indeed the DOS/Windows (CR+LF) line ending that the console doesn't like. In Notepad++ you can switch the line ending to Unix (LF) (main menu: Edit > EOL Conversion > Unix (LF)). Then you can copy & paste and run snippets in the console without a problem :-) $\endgroup$
    – Blunder
    Commented Mar 13, 2021 at 20:10

There is a solution, usually when I encounter this problem, I replace "TAB"'s with spaces. Here is the interesting thing, you can replace a "TAB" with any number of spaces. You could replace a TAB with a single space, or multiple spaces.

Now, for the second part of your question, any text editor that allows you to set "TAB" to spaces, so in "sublime text 3" which I use you would go to "view"->"indentation"->"Indent Using Spaces".

Here is the fun part, "TAB" with in a python file is not a problem for the python interpreter, it works fine. Its just an issue when you pasting to the command line.

Also, I don't know what your question has to do with Blender, this should be an S O question.

  • 1
    $\begingroup$ Thank you. The only solution which worked for me. On top of it, I have added a package for AutoPep8 package in sublime $\endgroup$ Commented Jun 23, 2020 at 23:12

Sadly, this just won't work. Something about cutting and pasting screws up the indentations, replacing spaces with tabs or visa versa, or with nothing. I'm not sure if it's when the external editor/IDE is copying, when the python console is pasting, or in the general copy-paste mechanism. I'm having this problem today on Windows. I don't know if the same happens on Linux; I haven't done any Python scripting for Blender on Linux in a long time.

What I do is write nicely formatted Python in my favorite editor (Notepad++ today, as I'm on Windows), copy it to a blank document in the same editor, remove all the blank lines and comments, then select and paste that code into the console. It's clumsy, tedious grunt work, but I can at least make progress.

The nicely formatted version of the source gets saved to a file, and used as an external script for Blender projects in the future, when I'm no longer doing the R&D.

  • $\begingroup$ Begs the question. Why not paste and run scripts from the text editor? The example script in the question is panel draw code, can't for the life of me think of any reason to run that by pasting in py console.As noted in comment under question: can run external and internal scripts using this handy addon to have results available in the console's locals. $\endgroup$
    – batFINGER
    Commented Aug 4, 2018 at 14:32

That's no longer the case at least from blender 2.81 (could be also from lower versions) Open the Text Editor and when you want to execute press ALT+P (or in the menu Text > Run Script)

Also, since now it's not the Python Console, all the errors/prints will be in the System Console (Window > Toggle System Console) And make sure you import what's needed (e.g. import bpy)

Tip: You can also turn on Live Edit

  • $\begingroup$ I believe the question is re pasting code into blenders python console. $\endgroup$
    – batFINGER
    Commented May 24, 2020 at 7:51
  • $\begingroup$ Yes, it's about running the code in the scene exactly as I was needed to do when finding this question. And while testing more after coming here I found out this method is a great solution for it. $\endgroup$
    – Ido
    Commented May 24, 2020 at 20:29
  • $\begingroup$ It is still the case in 2.8 that if you paste the script from Q into py console it won't work. $\endgroup$
    – batFINGER
    Commented May 25, 2020 at 7:11
  • $\begingroup$ I'm not you understood my answer $\endgroup$
    – Ido
    Commented May 25, 2020 at 20:09
  • $\begingroup$ I understand your answer thankyou fpr asking.. Whereas, I'm not sure you understand the question. Please re-read. Debugging using prints in text editor, sure, but it's not an interactive py console. ie you have no access to local variables after the script has run. If the blank line is removed from script above it runs when pasted in console. The class is available to tinker with and examine, register and unregister etc. $\endgroup$
    – batFINGER
    Commented May 25, 2020 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .