some beginner's questions for python pro's ;)

hi, this is my first posting here.

i’m new to blenders python scripting language and i just want to ask the pro’s here some more or less stupid questions about it… :wink:

how can i comment out multiple lines without using a # each line? just like in c language with /* */.

what’s the best way to slow down a running script, if i want to watch what it does? (in the console for example) is there a function which performs a delay? or what would you do, if you want to follow a fast running program?

is there a function to stop a script such as “break”, “halt” or “return()” in other languages?

is there a goto function?

thx in advance! :slight_smile:

To comment out multiple lines, use either ‘’’ or “”". If you’re confused with what I just wrote, look at it as ’ 3 times or " 3 times.
def OkCode():
return something
def CommentedOutCode():
return somethingElse

Slowing down scripts: NO. You’d be better off putting print statements through the code at different places, then running the program, then checking what it did, what values equaled at certain points in time, etc.

Stopping a script: Control-C in the console.


if you want to slow script down you can do…

import Blender

Blender.sys.sleep(10) # sleeps 10ms

To step through a script add

print ‘press enter to continue’, some_var, someother_var

#Youll need to have theconsole open

how can i comment out multiple lines without using a # each line? just like in c language with /* */.

Just FYI, I don’t know of a single python editor that doesn’t allow you to comment out blocks of code all at once. You should check your editor to see what your options are. In IDLE (the default Python editor), for example, you select the text and hit Alt-3 (uncomment is Alt-4). Check the Format menu. It’s also useful for indenting regions, which is something you’ll want to be able to do in Python.

Scite does Ctrl+Q to toggle comments but it uses teh # - not “”" ~ “”"

whats wrong with using #'s every line?
it’s way easier to read

Edit: 1111 posts

if 0:
  <code to ignore> 
  <more code to ignore>


def dont_run_this_for_now():
  <code to ignore>
  <more code to ignore>

Just remember you have to indent the code within the ‘if’ or ‘def’ blocks.


wow, many nice ideas. thanks! :slight_smile:

for that slow down thingy, i used a simple count loop.

for i in range(1,1000000): pass

works very well. :wink:

yea, maybe it’s not the best solution to slow down scripts, but sometimes i just want to watch if the model is building up correctly or something.