+ 1
Python indentation
I am having python 2.7... what I am doing is that I wrote set of statements in notepad++ file having extension .py... for indentation, I m using four spaces.. when I copy statements from .py file and paste it into python exe, it gives me indentation error.. any idea would be of great help.
5 Respuestas
+ 4
If you can show your code then that would be great. As most of those who describe their problems, it sounds like they did nothing wrong.
By "paste into python exe", do you mean running the code directly in the interpreter?
+ 3
Ketan, when you paste your code into your IDE, what product do you use? Have you tested it in SoloLearn playground, or do you use a windows, linux or ios environment?
+ 3
it worked now... yes i was trying to put into python interpreter... environment is windows 10...
what I did was copy one line and paste it into interpreter... don't copy spaces and provide one or two tab required as per indentation... completed all lines on interpreter...copy all lines from interpreter and pasted it into .py file..
thanks guys for responding on this
+ 3
Mixing up tabs and spaces in python code for indentation is not a good idea. If you create your code all in the same environment / IDE you should not run in problems. Python recommends to use 4 spaces for indent, but if you have to remove indent you have to press Del or Backspace 4 times. This is the reason why many coders use tabs. IDE allows to define what 1 tab means in number of spaces. Some can handle so called soft tabs. This means if you use in a case number of spaces (as defined), you can delete them just with one click. IDE can also check ( and this is a very helpful feature) if you paste some code from whatever source into the code esitor against spaces and tabs. If the data you want to insert does not match the rules of your editor, it will ask to convert tabs / spaces before performing the action.
+ 2
it sounded very strange, maybe it happened because there was a lost TAB instead of four spaces in your code, I would suggest using the find replace tool to substitute any TAB into spaces.
Since you already solve this, this might help others