This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: '\t' Escape Sequence behaving differently.
Type: behavior Stage: resolved
Components: Parser Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BAHADIR, lys.nikolaou, pablogsal, steven.daprano
Priority: normal Keywords:

Created on 2021-07-25 08:50 by BAHADIR, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg398180 - (view) Author: BAHADIR (BAHADIR) Date: 2021-07-25 08:50
While working on several examples I noticed that ASCII Horizontal Tab (TAB) gives different results for different values. When I looked at the rfc documents, I couldn't see any result about its calculation. The calculation method I noticed myself is as follows ((8 -(string from previous "\t"))%8) * a number of spaces(in python IDLE) result change in other IDE or editors.
msg398181 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-07-25 08:56
I'm sorry, I don't understand what "different results for different values" you are talking about.

Can you please copy and paste (not a screen shot) code demonstrating:

- what code you ran
- what result you expected
- why you expected it
- and what result you got instead.
msg398182 - (view) Author: BAHADIR (BAHADIR) Date: 2021-07-25 09:03
>>> print("1\t1")
1	1
>>> print("12\t1")
12	1
>>> print("123\t1")
123	1
>>> print("1234\t1")
1234	1
>>> print("12345\t1")
12345	1
>>> print("123456\t1")
123456	1
>>> print("1234567\t1")
1234567	1
>>> print("12345678\t1")
12345678	1
>>> print("1","12","123","1234","12345","123456","1234567","12345678",sep="\t")
1	12	123	1234	12345	123456	1234567	12345678
space length is always changing
msg398183 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-07-25 09:23
That's not a Python issue, that's a feature of your terminal. That's how tabs are supposed to work.

By default, most terminals set tab stops every 8 columns. Printing a tab character jumps to the next tab stop.

If you are using Linux or Mac, you can use the `tabs` command in the terminal to control where the tab stops are. This is not a Python command, it is part of your OS shell.

https://askubuntu.com/questions/63424/how-to-change-tab-width-in-terminal-in-ubuntu-10-04

https://superuser.com/questions/110421/tab-character-width-in-terminal

I don't know about the Windows Terminal. It is possible it doesn't support changing the tab stops.
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88899
2021-07-25 09:23:32steven.dapranosetstatus: open -> closed
resolution: not a bug
messages: + msg398183

stage: resolved
2021-07-25 09:05:33BAHADIRsetfiles: - IDLE.jpeg
2021-07-25 09:03:18BAHADIRsetmessages: + msg398182
2021-07-25 08:58:18BAHADIRsetfiles: + IDLE.jpeg
2021-07-25 08:56:00steven.dapranosetnosy: + steven.daprano
messages: + msg398181
2021-07-25 08:50:24BAHADIRcreate