Oct-17-2018, 11:26 AM
Hi all! It is not agreable to rewrite a file where indentation was made with tabs. I met this problem on geany and also with vim.
Why interpreter accepts indentation made with spaces and not those by tabs
|
Oct-17-2018, 11:26 AM
Hi all! It is not agreable to rewrite a file where indentation was made with tabs. I met this problem on geany and also with vim.
Oct-17-2018, 11:36 AM
You cannot mix tabs and spaces. You need to select one and be consistent in using it. Recommendation is to use 4 spaces. Also you may configure your IDE to convert 1 tab to 4 spaces. Note that if you have tab indented file and open it in IDE configured to convert tabs, it will not convert existing tabs and you will end with mix of tabs and spaces. Also there might be setting to detect and use whatever indentation is used.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Oct-17-2018, 05:16 PM
For the whole file I used tabs. I used vim. It did not run well.
sylvain@sylvain-HP-Laptop-15-bw0xx:~$ cat new2.py #!/usr/bin/python3 #!/usr/bin/env python3 #new2.py def silly(n, x): m=n stack = [iter(range(m))] total=0 while stack: try: i = stack[-1].__next__() except StopIteration: stack.pop() continue total += i if total >= x: break if i == 5: m -= 1 stack.append(iter(range(m))) return total print(silly(1,2)) print(silly(0,1)) print(silly(2,3)) print(silly(3,4)) sylvain@sylvain-HP-Laptop-15-bw0xx:~$The first is for try: Instead of tabs I use spaces. Error repaired. Next error is for the next line.nd It is really amazing ! How interpreter finds you used tabs and not spaces ???
Oct-18-2018, 04:31 PM
I think that if you have a file like the one above, a good way is to use tabs, once finished your file you copy it, you delete your original file, and at last you paste. Isn't it ??
Oct-18-2018, 05:30 PM
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Oct-18-2018, 05:33 PM
You don't read posts do you.
Quote:Recommendation is to use 4 spacesBuran explained why you should not use tabs, but yet you ignore his advice.
Oct-18-2018, 06:12 PM
I tried again because of you. My way works very well. Please try it yourself and then reply.
Oct-18-2018, 06:16 PM
(Oct-18-2018, 06:12 PM)sylas Wrote: I tried again because of you. My way works very well. Please try it yourself and then reply. I have no intonation to try... do whatever you want, but please show mercy and don't share it with us...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Oct-18-2018, 06:44 PM
The way I give you, using tabs, wins a lot of time. I think many people are interested by that. Maybe someones use it already. I repeat I use Vim (the white one for windows)
. Vim is for me the best tool.
Oct-18-2018, 06:49 PM
for the benefit of others, who may find this thread in the future.
https://howchoo.com/g/m2u0nthkyti/vim-co...-to-spaces
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs |
|