+ 8

How do I avoid starting all over after a mistake in python console?

Whenever I make a mistake in a line of code in python, it's like I just have to start all over. What do I have to do to avoid this? Again, is there a way to take my cursor to a place or point in the console and add or edit something? Thanks.

5th Jul 2017, 2:37 PM
Bueze
Bueze - avatar
27 Réponses
+ 22
I always recommend PyCharm, especially for beginners - it is a bit heavy, but it does a lot of work for you - manages your modules, gives you hints and autocompletion as you type, etc. How do you access the built-in editor, hmm... Python GUI? http://www.tech-recipes.com/wp-content/uploads/2012/09/3.jpg
5th Jul 2017, 4:26 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 14
The console enables you interactive way of coding, not appropriate if you plan to make a working program. You should create your work in an IDE, like Pycharm, use an external editor like Notepad++ or the default one embedded within your Python installation - IDLE. It has two window types - the shell, which you are probably using and the editor which is way better suited for programming.
5th Jul 2017, 4:07 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 9
@Daniel For mobile there is QPython3 which has both a console and an editor. Plus, it contains several interesting code examples, including those utilizing the sl4a library (Python for Android).
6th Jul 2017, 4:10 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
@Kuba; Right; yes. Maybe it's smaller now? I guess I sortof ignore it on my mobile & simply forget about it on my tablet. Thanks for the reminder / perspective.
7th Jul 2017, 5:56 PM
Kirk Schafer
Kirk Schafer - avatar
+ 6
Pls let me know if that helped :)
5th Jul 2017, 4:57 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
@Kirk Thanks man, I have to try it then. I hear that people complain on DroidEdit, it seemingly has a banner overshadowing the screen in the free version. Is that true?
7th Jul 2017, 5:47 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
@kuba If you mean: pip install -- it's fantastic... IMO because it's a standard linux shell, just like a PC (to shell in QPython (old) I had to trick the interpreter into crashing out). I'm linking my 'fair comparison', written after many long days fixing+fighting QPython's package system... writing package maintainers... even wheels... until I found the unicode defect was known in that version. I'll also try the new QPython version (just noticed!) as a potential breath of fresh air. [[ Aside, credit because Python's package system is known to be tricky: http://lucumr.pocoo.org/2014/1/27/python-on-wheels/ ]] https://www.sololearn.com/discuss/244002/?ref=app
7th Jul 2017, 5:17 PM
Kirk Schafer
Kirk Schafer - avatar
+ 4
@Kirk does it support free module install easily?
7th Jul 2017, 4:03 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
If you develop on your Android device like I do, Termux is a free app that "enhances" the built-in Linux-ish terminal and no root is required, just a lot of space because of apt packages. I purchased the Termux:API (so I can easily copy & paste from the command line) as well as Termux:Float (so I can get a toggleable floating window overlay which allows me to switch quickly between info & code). If you wanted a little more Linux on your Android, there it is. If you do not know the difference between "bash" and the Windows Command Prompt, best stay away for now.
10th Jul 2017, 2:11 PM
Katie (Ctrl-Alt-Cuteness)
Katie (Ctrl-Alt-Cuteness) - avatar
+ 3
@OP: in interactive Python you have to know what it remembers (everything up to the error), then arrow up and press enter on--in order, optionally editing--each line again as it appears. Not too much fun. @Qpython3 users--is fine...I've just no longer been recommending it, even with its advantages. Last one I used had Unicode and pip problems... with confusing (duplicated) source trees and no apparent support. Instead, I install Termux, 'apt install python', then use something like DroidEdit.
7th Jul 2017, 3:32 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
Well I'm not sure in python but in Visual studio that I use for writing C# programs I use F11 to see how my program goes step by step. I'm sure there is something similar in python too.
11th Jul 2017, 4:11 AM
keivan Ipchi
keivan Ipchi - avatar
+ 2
Well there are alot of Editors that can help you code easier one of those are: 1.sublime Text 2.Notepad++ 3.VIM and many more The first two are the most common by programmers
5th Jul 2017, 9:24 PM
Mohamed Raouf
Mohamed Raouf - avatar
11th Jul 2017, 11:57 PM
Prakhar Singh
Prakhar Singh - avatar
+ 1
Thanks Which IDE do you recommend? Also you talked about shell and editor, how do I access the editor?
5th Jul 2017, 4:21 PM
Bueze
Bueze - avatar
+ 1
Usually using a script window to write the code is easier. You can then use incremental development, writing bit by bit to check each piece along the way
7th Jul 2017, 1:28 AM
Nathan Laing
Nathan Laing - avatar
+ 1
Just use notepad to edit your script and then copy it to python console to run the script If you are doing it often, I recommend you to use Jupyter Notebook, it allows you to edit and run python scripts interactively. for more information about jupyter notebook: http://jupyter.org/
8th Jul 2017, 6:36 AM
Fajar Tri Haryanto
Fajar Tri Haryanto - avatar
+ 1
always comment every statement of your code so that it will be easy to debug
8th Jul 2017, 7:35 AM
Ermyas
Ermyas - avatar
+ 1
Its super easy!! work first on your PC or an app and then write it down here
8th Jul 2017, 1:11 PM
CallMeJason
CallMeJason - avatar
+ 1
practice make you better
9th Jul 2017, 9:26 AM
Sameer Samrat
Sameer Samrat - avatar
+ 1
you can also use a python basical IDLE it's very practical
10th Jul 2017, 11:16 PM
Stephcyrille
Stephcyrille - avatar