0

I believe my question has been asked before but i don't know how to explain what i want to do

I basically have this code that i want to stop the execution at a spisific line

  #embed
  embed_var = discord.Embed(
    title= ''' title ''', 
    description= ''' description ''', 
    color= discord.Color.red())
  embed_var.set_footer(text=''' footer ''')
  embed_var.add_field(name=''' name ''', value=''' value ''', inline=True)

  #stop here

  print(''' don't print this ''')

Edit: sorry i guess i didn't phrase it currectly, i want the program to keep going but to not to keep executing the rest of the cod

omar
  • 293
  • 3
  • 13
  • Simply use `raise SystemExit` or `sys.exit()`. – Junitar Jul 21 '21 at 08:58
  • sorry i guess i didn't phrase it currectly, i want the program to keep going but to not to keep executing the rest of the code – omar Jul 21 '21 at 09:01
  • just comment it out then? – Guddi Jul 21 '21 at 09:02
  • Put that code in a function and use ```return``` where you want to stop. Post your code completely for us to help. – Ram Jul 21 '21 at 09:06
  • Then comment out the code you don't want to run as suggested by @Guddi or add an `if` statement. E.g. `run = False` then `if run: # code not to run`. – Junitar Jul 21 '21 at 09:09

2 Answers2

1

If this is in a loop, break and continue might be what you are looking for: link

If this is a function, you can use return: link

If you wish your program to exit entirely, use sys.exit(): link

If this is for debug purposes, you can always comment out the code using a # sign: link

Almog-at-Nailo
  • 1,152
  • 1
  • 4
  • 20
  • 1
    thanks for the multiple solutions, i wanted to do this for debugging reasons of which i found using "function" to be the easiest in practice. there is another good solution @Guddi mentioned which is to just comment the rest of the code – omar Jul 21 '21 at 11:18
  • For debugging purposes, I would recommend using a debugger like [pdb](https://docs.python.org/3/library/pdb.html). – Junitar Jul 21 '21 at 12:12
  • I've added comments to the answer, good call – Almog-at-Nailo Jul 26 '21 at 07:07
-2

There are several ways to interrupt Python execution process.

You may check it here Python exit commands - why so many and when should each be used?

For your case,

import sys 

  #embed
  embed_var = discord.Embed(
    title= ''' title ''', 
    description= ''' description ''', 
    color= discord.Color.red())
  embed_var.set_footer(text=''' footer ''')
  embed_var.add_field(name=''' name ''', value=''' value ''', inline=True)
  
  sys.exit() # to exit from execution process
  #stop here

  print(''' don't print this ''')

It is better to have a condition why the program should skip some script, you can use if or if you are in a loop, you can use continue

Rizquuula
  • 578
  • 5
  • 15