Mar-22-2019, 07:26 AM
Very strange error of indentation
Very strange error of indentation
|
Mar-22-2019, 09:32 AM
If you have a Python script with tabs in source code, the script is broken.
I guess there are tools available to check for this problem. But it makes fun, to write an own checker, which shows lines with tabs in your console. from pathlib import Path import sys import click import colorama def tab_pos(line): return [idx for (idx, char) in enumerate(line) if char == '\t'] def scan(script): script = Path(script) with script.open() as fd: for line_no, line in enumerate(fd, 1): tabs = tab_pos(line) if tabs: yield line_no, line, tabs def print_matches(results): RED = colorama.Back.RED RESET = colorama.Style.RESET_ALL for line_no, line, tabs in results: line = list(line.rstrip('\n')) for tab in tabs: line[tab] = RED + '<\t>' + RESET line = ''.join(line) print(f'{line_no:>4} -> {line}') @click.command() @click.argument('script') def main(script): """ This program detects tabs in source code and will print the result to console. """ results = list(scan(script)) if not results: print('File has no tabs') return 0 else: print_matches(results) return 1 if __name__ == '__main__': sys.exit(main()) You need click and colorama.A tabulator is replaced with RED + '<\t>' + RESET
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Hi Verb Conjugator!
If you get a glance to the source (uploaded into the opening post) http://reionization.org/wp-content/uploa...st2ra.html you may note that the mismatch is created by in [4] piece of code, undoubtely coming from Mathematica editor. So, for future applications I'll be careful to take Python codes from such sources, which could conflict with my preferred editor (geany). Thank you, and cheers |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Strange argument count error | rowan_bradley | 3 | 1,641 |
Aug-06-2023, 10:58 AM Last Post: rowan_bradley |
|
Strange error ValueError: dimension mismatch | Anldra12 | 0 | 2,601 |
Aug-17-2021, 07:54 AM Last Post: Anldra12 |
|
Strange syntax error with f-strings | Askic | 6 | 6,980 |
Oct-16-2020, 10:40 AM Last Post: Askic |
|
Indentation Error With If Else Statement | JoeDainton123 | 3 | 3,492 |
Aug-02-2020, 08:29 PM Last Post: deanhystad |
|
Indentation error... lol | ironfelix717 | 8 | 5,070 |
Apr-02-2020, 02:31 PM Last Post: buran |
|
Getting error message for indentation | Shafla | 5 | 3,793 |
May-07-2019, 08:56 PM Last Post: Yoriz |
|
Help please - indentation error | bil007 | 1 | 2,524 |
Mar-24-2019, 11:41 AM Last Post: Yoriz |
|
Indentation error in Python code | ErnestTBass | 5 | 4,660 |
Feb-28-2019, 04:26 PM Last Post: samsonite |
|
Strange Pandoc Error | AreebSooYasir | 0 | 2,392 |
Jul-24-2018, 04:30 AM Last Post: AreebSooYasir |
|
Class - Error Message (Indentation) | tkj80 | 3 | 5,351 |
Jan-20-2017, 07:48 AM Last Post: wavic |
Users browsing this thread: 1 Guest(s)