# Tabs, Spaces, and Scripting

**URL:** <https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396>\
**Category:** Ignition\
**Tags:** python, scripting\
**Created:** [December 8, 2022, 7:43pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396 "2022-12-08T19:43:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Cottengim](https://avatars.discourse-cdn.com/v4/letter/i/48db29/32.png) [@Ian\_Cottengim](https://forum.inductiveautomation.com/u/Ian_Cottengim)\
**Post date:** [December 8, 2022, 7:43pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/1 "2022-12-08T19:43:00Z")

</div>

One of the most common scripting issues I see here and in other python forums is mixed whitespace characters. I prefer spaces myself but won't fault anyone for choosing tabs. It appears to me that the devs also prefer spaces, most of the examples in the docs use spaces for indents. However the script editor uses tabs.  
This wouldn't be a huge issue for me, I'm comfortable using an external text editor like notepad++ which lets you replace tabs with spaces. But using an external editor is painful due to the auto-indent incorrectly indenting.  
Am I missing a simple solution?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 8, 2022, 7:49pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/2 "2022-12-08T19:49:53Z")

</div>

> [@Ian\_Cottengim](#):
>
> However the script editor uses tabs

Huh??? If you want to use spaces, just use spaces?

I have never had an issue using spaces in the script editor or the script console as long as I always use spaces through out the script.

Personally, I prefer Tab's because it's few key strokes, and it's easier to determine by looking if your indentation is off.

---

<div class="post-metadata">

**Author:** ![Troy](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Troy](https://forum.inductiveautomation.com/u/Troy)\
**Post date:** [December 8, 2022, 8:59pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/3 "2022-12-08T20:59:37Z")

</div>

They're referring to the script editor not letting you add 4 spaces when you press tab (a setting on almost any IDE).

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 8, 2022, 9:34pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/4 "2022-12-08T21:34:30Z")

</div>

Like @Troy said. If you need to indent a block of existing code, using spaces in the script editor will make you want to pull your hair out since you would need to manually add the spaces to each line of code you are trying to indent. Or get in the habit of first cutting the block of code, typing in the 4 spaces, and then pasting - it will then put in the spaces for each line...but who would ever want to do that 😅

Edit: I was trying to recall where I ran into an even bigger headache with spaces and then remembered it was with Custom Methods in Vision. The auto generated doc-string uses tabs and there is no way to change them to spaces that I am aware of. So when you try to add lines below with spaces, it will give you an IndentationError that can only be fixed by switching to tabs. The example code in the Extension Functions also use tabs which a lot of people don't realize when they uncomment the code. Power Table example:

 ![Screen Shot 2022-12-08 at 4.50.41 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/5/45485593c588d5ab4e981c6e39cbe6f46014ff1a.png)

 ![Screen Shot 2022-12-08 at 4.40.52 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4d298163bd2bb258fdf73099326714abe27c2462.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 8, 2022, 10:00pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/5 "2022-12-08T22:00:05Z")

</div>

> [@WillMT10](#):
>
> The auto generated doc-string uses tabs and there is no way to change them to spaces that I am aware

In other words, just use tabs.

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [December 8, 2022, 10:01pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/6 "2022-12-08T22:01:48Z")

</div>

Agreed. I just wanted to make sure others know that there are roadblocks to using spaces in certain parts of Ignition that throw the personal preference discussion out the window.

Edit: btw, I just noticed the cake icon, happy forum anniversary @pturmel!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 9, 2022, 12:57am UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/7 "2022-12-09T00:57:42Z")

</div>

Huh, thanks for the clarification.

I have never had the need/desire to look for an option like that. I have always used tabs, to me white space is white space (to the eye, I’m aware there is a difference).

The only exception is when writing code directly in a forum post, since the browser steals the tab key event and moves focus. Otherwise, I just hit the tab key and I get whatI get.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2022, 1:27pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/8 "2022-12-09T13:27:18Z")

</div>

I am a tab user so that I can say I am a few hundred percent more efficient at coding than my space using coworkers.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 9, 2022, 2:03pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/9 "2022-12-09T14:03:30Z")

</div>

If you have ever listened to the Oxide Computer podcast _On The Metal_, they mention tabs versus spaces in an episode. The person they interviewed said that tabs were preferred during a certain era due to a situation where a tab was faster and used less transfer data then multiple spaces. Pretty interesting. I'm a tab guy myself.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 9, 2022, 4:39pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/10 "2022-12-09T16:39:37Z")

</div>

I'm personally in favor of relaxing this behavior, but it's a backwards compatibility _nightmare_, surprisingly. For now, I'll echo the sentiment in this thread: just use tabs.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 9, 2022, 4:58pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/11 "2022-12-09T16:58:27Z")

</div>

> [@paul-griffith](#):
>
> but it's a backwards compatibility _nightmare_, surprisingly

The decision to supply a fixed header and function comment for extension functions is the root cause. Stop doing that. Supply it as a convenience, but don't force it. Just check that the `def something(...):` is unchanged before accepting an edit.

That would make cut-and-paste nicer, and should allow all prior serialized forms to work.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 9, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/12 "2022-12-09T17:18:27Z")

</div>

We already have stopped doing it, in Perspective and everywhere else 'modern'. The problem is everything else in the system.  
Vision, in different areas, serializes either A: the user's script, B: the user's script _plus_ the `def` line, or C: the user's script, the `def` line, _and_ the docstring comment. Some of those areas do and don't count that docstring in the line number for errors, as well. Changing how things are serialized back down without bumping resource versions required some shenanigans; e.g. _right now_ if you copy a Vision component from a post-script-editor-rework version to a pre-script-editor-rework version, it _will compile_, but the docstring will be missing and it'll have a big warning instead.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 9, 2022, 5:20pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/13 "2022-12-09T17:20:25Z")

</div>

> [@paul-griffith](#):
>
> in different areas

Hmm. I only ever noticed "C" when digging around. ):

A missing or different docstring should be tolerated.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 21, 2023, 8:36pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/14 "2023-01-21T20:36:12Z")

</div>

In my search for some comedic relief this week, I encountered the following comic and remembered this conversation:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/92f1d6f99ec7582a283ff17046db63818b9f1c3c.jpeg)

For the record: (I prefer tabs)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 21, 2023, 8:47pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/15 "2023-01-21T20:47:40Z")

</div>

I can't stand spaces! Why would you tap 3 times instead of once?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/16 "2023-01-21T21:01:54Z")

</div>

I'm fine with spaces if I don't have to type them. Which is almost never, so, tabs it is.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 23, 2023, 2:50pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/17 "2023-01-23T14:50:09Z")

</div>

I've been wondering that for a long time. Why the hell would PEP8 recommend using spaces ?

---

<div class="post-metadata">

**Author:** ![Ian\_Cottengim](https://avatars.discourse-cdn.com/v4/letter/i/48db29/32.png) [@Ian\_Cottengim](https://forum.inductiveautomation.com/u/Ian_Cottengim)\
**Post date:** [January 23, 2023, 3:49pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/18 "2023-01-23T15:49:57Z")

</div>

IDEs give you the option to replace the tab key with 3 spaces. Its the same keyboard input.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [January 23, 2023, 7:43pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/19 "2023-01-23T19:43:56Z")

</div>

Backspace, I believe, still only back spaces one space at a time though so you have to backspace 3 times unless you use shift tab. But still, copying the code to other places you'll have to use backspace most of the time. I can't think of anything worse

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 23, 2023, 8:20pm UTC](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396/20 "2023-01-23T20:20:58Z")

</div>

![Screenshot_20230123-141707-754](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/f/9fa495528f7c5ac739af80171c36ddcd0ec9c71d.png)

[Next page](https://forum.inductiveautomation.com/t/tabs-spaces-and-scripting/67396.md?page=2)
