# What do you think about an "indent" command?

**URL:** <https://discuss.python.org/t/what-do-you-think-about-an-indent-command/109005>\
**Category:** Python Help\
**Created:** [September 11, 2026, 1:48pm UTC](https://discuss.python.org/t/what-do-you-think-about-an-indent-command/109005 "2026-09-11T13:48:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crichard222](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@Crichard222](https://discuss.python.org/u/Crichard222)\
**Post date:** [September 11, 2026, 1:48pm UTC](https://discuss.python.org/t/what-do-you-think-about-an-indent-command/109005/1 "2026-09-11T13:48:11Z")

</div>

I am currently coding an RPG. I was working on the enemy attack system, and there were 2+ enemies. I was trying to see if there was a purely organizational-purpose command to create a valid indent. Apparently, there isn’t.

So, I was thinking the `indent` command, if added, would work like this:

```python
indent()
    # enemy 1
    attack = random.randint(1, 3)
    if attack == 1:
        # attack code

indent()
    # enemy 2
    attack = random.randint(1, 3)
    if attack == 2:
        # attack code

```

Or you could use it for something like that.

**As an optional, separate feature related to this idea:** inside the parentheses, you could type either `"global"` or `"local"`, which could control the scope of variables inside the indent block.

If you do `global`:

```python
example = 1

indent(global)
    print(example)
    # This will work, because you selected global.

```

If you do `local`:

```python
example = 1

indent(local)
    print(example)
    # This will NOT work, because it was set to local,
    # and "example" was not defined in the indent block.

```

The main purpose of the `indent` command would be **organizational** : allowing programmers to create visually separated, properly indented sections of code without needing the indentation to represent a conventional Python control structure. The `global`/`local` feature would be an optional related addition rather than the main purpose of the command.  
if the `global`/`local` feature were to be added, if there were no text in the parentheses, it would act like if you did `indent(global)`.

---

<div class="post-metadata">

**Author:** ![duncathan](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/duncathan/32/25521_2.png) [@duncathan](https://discuss.python.org/u/duncathan)\
**Post date:** [September 11, 2026, 2:01pm UTC](https://discuss.python.org/t/what-do-you-think-about-an-indent-command/109005/2 "2026-09-11T14:01:25Z")

</div>

If you really need a block, you can always do `if True:`. Though I think you’ll find that in practice, people are more likely to look for ways to _eliminate_ indents rather than to add them.

For your enemy attack example, you would much likely be better off creating an attack function.

```py
def try_attack(enemy_number):
    attack = random.randint(1, 3)
    if attack == enemy_number:
        ... # attack code

# enemy 1
try_attack(1)
# enemy 2
try_attack(2)

```

---

<div class="post-metadata">

**Author:** ![timhoffm](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/timhoffm/32/19468_2.png) [@timhoffm](https://discuss.python.org/u/timhoffm)\
**Post date:** [September 11, 2026, 9:00pm UTC](https://discuss.python.org/t/what-do-you-think-about-an-indent-command/109005/3 "2026-09-11T21:00:05Z")

</div>

I don’t think that pure indent is a reasonable concept for structuring. No offense meant, but I rather suspect that the desire for stronger grouping comes from inexperience to use other established mechanisms for structuring. I’ll list a few different ways how to organize the code, and relatedly think about your problem.

In a plain code sequence we can use blank lines and comments for structuring

```python
# enemy 1
attack = random.randint(1, 3)
if attack == 1:
    # attack code

# enemy 2
attack = random.randint(1, 3)
if attack == 2:
    # attack code

```

That’s ok, readable and established practice. If it get’s too long, it’s very likely that the code contains underlying logic structure. That can be extracted in a function, which gives it a name and defined inptus and outputs. It may even be that the concept can be applied multiple times. - This is the case explained by @duncathan above.

You might also want to encapsulate data and related functionality into classes, which could look like this:

```python
class Warrior:
   def __init__ (self, health):
       self.health = health

   def attack_enemy(enemies: list[Warrior]):
       """Attack a random enemy."""
       enemy = random.choice(enemies)
       # attack code - reduce self.health and/or enemy.health
       
enemy_healths = [5, 7, 6]
enemies = [Warrior(health) for health in enemy healths]

hero = Warrior(health=10)
hero.attack_enemy(enemies)

```

* * *

For academic interest, I believe the closet thing to a non-functional indent would be a no-op context manager - under the assumtion you don’t want any namespacing and `if True:` is too ulgy. This technically works, but I would strongly discourage using it:

```python
import contextlib

@contextlib.contextmanager
def indent():
    yield

a = 1

with indent():
    b = 2

with indent():
   print(a + b)

```
