sigurdsk
Posts: 1
Joined: Tue May 10, 2016 5:49 pm

Code editor

Tue May 10, 2016 6:05 pm

I was wondering what code editor i would use for my Python script, since the only Python tool i found in Raspbian was the intrepeter and not any good for working With larger scripts.

qwertyuiopzxcvbnm
Posts: 13
Joined: Fri May 01, 2015 7:23 pm

Re: Code editor

Tue May 10, 2016 7:12 pm

nano is a simple command-line code editor. It's accessed by typing

Code: Select all

nano myscript.py
where 'myscript.py' is the name of your python file (doesn't have to exist beforehand). If on the other hand you're using the desktop GUI, then you should be able to use the standard Python IDLE, which will be in the menu (under programming, I think). To create a Python script from IDLE, click on File, then New File.

KCarscadden
Posts: 56
Joined: Sat Jun 09, 2012 9:00 pm
Location: Canada

Re: Code editor

Tue May 10, 2016 11:53 pm

EMACS is a great editor. Get it with sudo apt-get emacs, and it will show up on the windows system under Menu, Accessories, GNU Emacs 24.

Alternately, you could check http://www.raspberryconnect.com/raspbia ... an-editors


Keith

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Code editor

Wed May 11, 2016 3:19 am

sigurdsk wrote:I was wondering what code editor i would use for my Python script, since the only Python tool i found in Raspbian was the intrepeter and not any good for working With larger scripts.
The proper way to build python scripts these days is IDLE; the python interactive development environment. IDLE is has a REPL in the main window, a console if you will, and can be used just like the REPL in a terminal... but that's where the similarity ends. The IDLE is completely configurable, has path editors, allows multiple file windows to be open at the same time, and is perfect for building large scripts.

IDLE is a built-in on Raspbian Jessie; both python2 IDLE and python3 IDLE, in the programming menu.
marcus
:ugeek:

tom.slick
Posts: 190
Joined: Wed Jan 06, 2016 9:23 pm

Re: Code editor

Wed May 11, 2016 6:51 am

Use any text editor that has syntax highlighting and optionally code completion. Vi, Emacs, Nano, etc.. from the command line or if you are running a linux desktop then look at Leafpad, Kwirte, Kate, Gedit, Geany, Jedit, etc... All will do you fine for small to medium projects. That and a terminal window are all you really need.

If you have a large project then you might want to look at an IDE like PyCharm, Wing, Eclipse, Netbeans, Komodo, Ninja, or even Python Tools for Visual Studio. All have their pluses and minuses.

Your best bet is to find a text editor you like.
Example, your using Winblows, excuse me Windows.
Setup samba on your RPI and a network share on windows. Install a good text editor like Notepad++.
Open your python files in Notepad++ through the share (you are editing the files on your RPI with Notepad++). And then save the changes.
Open another window ssh (putty) or vnc to the RPI, then you can run them as normal scripts.

The only thing to add is DO NOT use IDLE. IDLE is the worst ide (one of the worst) in the history of programming. Use anything else for a week and then use IDLE and you will see what is wrong with it. It's okay for small simple scripts, it's an ide for small simple scripts, more of an example of what can be done with python, but not something that should be used as a real ide. An ide should work for small or large projects, but if you don't need an ide then don't use one. A really good text editor is better for small scripts and medium sized projects then a great ide. An ide only comes into use for multiple files and lots of lines of code. And IDLE fails for medium sized scripts and multiple medium sized files.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Code editor

Wed May 11, 2016 2:55 pm

tom.slick wrote: The only thing to add is DO NOT use IDLE. IDLE is the worst ide (one of the worst) in the history of programming. Use anything else for a week and then use IDLE and you will see what is wrong with it. It's okay for small simple scripts, it's an ide for small simple scripts ...
Asinine flap-doodle, poppycock and balderdash!

... do as you wissh... I use IDLE everyday, for everything Python (works great)

PS... to be fair, your statements were true about four-five years ago... you obviously haven't driven an IDLE lately!
marcus
:ugeek:

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: Code editor

Wed May 11, 2016 3:47 pm

I'm also one of those that have had many bad experiences with IDLE in the past. Every problem was because there was one or another problematic interaction between IDLE and the Python interpreter that was running my code. I don't know if IDLE was running itself on the same instance of the Python interpreter as it was executing the code I was working on, but that was it seemed like.

I have not used IDLE in maybe 10 years, but posts I have read on this forum tells me that something like that is still happening. (Execute a script from IDLE or directly from the terminal and you get different results - that should not happen in my opinion: viewtopic.php?f=32&t=111905)

Also, IDLE's Tkinter based user interface was always uglier than other program's user interfaces that was using other toolkits.

I have used Geany without any problems for many years on my x86 computers. It should run fine on a Pi, at least on a Pi2 or a Pi3.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Code editor

Wed May 11, 2016 4:05 pm

Sleep Mode zZ wrote: I have not used IDLE in maybe 10 years, but posts I have read on this forum tells me that something like that is still happening.
That is like saying, "The last Ford Galaxy I drove was the one my father owned in 1967, but I've heard that Fords still work that way today!" Poppycock.
Sleep Mode zZ wrote:(Execute a script from IDLE or directly from the terminal and you get different results - that should not happen in my opinion: viewtopic.php?f=32&t=111905)
The problem (noted in the thread above) is not a problem with IDLE, but rather a problem with the OPs code.... he wasn't handling threads correctly, and the symptom of 'his own' problem was different in IDLE (not because IDLE is problematic) because IDLE kept his threads alive. The real problem was that the main code incorrectly exited with child threads hanging out there which had not yet completed. Don't blame IDLE for poor inter-process communication nor bad thread management (synchronous/asynchronous).
Sleep Mode zZ wrote: Also, IDLE's Tkinter based user interface was always uglier than other program's user interfaces that was using other toolkits.
Yes, Tkinter is simple... I would not go so far as to call it ugly... but yes, its clean, straight-forward and simple.
marcus
:ugeek:

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: Code editor

Wed May 11, 2016 4:44 pm

MarkHaysHarris777 wrote:
Sleep Mode zZ wrote:(Execute a script from IDLE or directly from the terminal and you get different results - that should not happen in my opinion: viewtopic.php?f=32&t=111905)
The problem (noted in the thread above) is not a problem with IDLE, but rather a problem with the OPs code.... he wasn't handling threads correctly, and the symptom of 'his own' problem was different in IDLE (not because IDLE is problematic) because IDLE kept his threads alive. The real problem was that the main code incorrectly exited with child threads hanging out there which had not yet completed. Don't blame IDLE for poor inter-process communication nor bad thread management (synchronous/asynchronous).
But still, the program did quit but IDLE did keep a thread alive, while the Python interpreter, when run from a terminal do not act like that. That is wrong behavior from IDLE, in my opinion.

My old problem from years back, probably not relevant any more, had to do with using Finnish (Nordic) characters in my code.* I did everything like Python documentation told me to do but did run into errors - until I ran the program directly the Python interpreter and it worked fine. I was a beginner then and it was really frustrating to stumble into a problem that was not my fault but the fault of the recommended Python editor for beginners. I have not used IDLE since.

At the root of the problem was something similar to this pygame audio example: There is some interaction between IDLE and the Python program run from it that can change the way the interpreter handles the program. In the pygame audio example the program did keep a thread alive to play a sound while the program should be exited at that point. In my example from years back, my program did not run when executed from IDLE while it did run fine, as it should have, when executed directly with Python.

* not as variable or function names but in comments or inside strings, I don't remember which anymore.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Code editor

Wed May 11, 2016 5:12 pm

Sleep Mode zZ wrote: My old problem from years back, probably not relevant any more, had to do with using Finnish (Nordic) characters in my code.* I did everything like Python documentation told me to do but did run into errors - until I ran the program directly the Python interpreter and it worked fine. I was a beginner then and it was really frustrating to stumble into a problem that was not my fault but the fault of the recommended Python editor for beginners. I have not used IDLE since..
You are correct, its not relevant any longer. The problem you ran into back then had nothing to do with IDLE either; it had to do with the fact the unicode was new, and was as yet not built-in to python (at all).

Today ONE of the major features of Python3 is that unicode is completely built-in (inherent) from the ground up. Python3 fixed a lot of things... but the most important was unicode, in my opinion; another was a rework of IDLE. The IDLE changed hands (as it were) and got refreshed. If you have not used it in ten years, well, you haven't used it... just saying. :)
marcus
:ugeek:

tom.slick
Posts: 190
Joined: Wed Jan 06, 2016 9:23 pm

Re: Code editor

Wed May 11, 2016 5:19 pm

Sleep Mode zZ wrote:
MarkHaysHarris777 wrote:
Sleep Mode zZ wrote:(Execute a script from IDLE or directly from the terminal and you get different results - that should not happen in my opinion: viewtopic.php?f=32&t=111905)
The problem (noted in the thread above) is not a problem with IDLE, but rather a problem with the OPs code.... he wasn't handling threads correctly, and the symptom of 'his own' problem was different in IDLE (not because IDLE is problematic) because IDLE kept his threads alive. The real problem was that the main code incorrectly exited with child threads hanging out there which had not yet completed. Don't blame IDLE for poor inter-process communication nor bad thread management (synchronous/asynchronous).
This is a problem with IDLE. IDLE has been and is still problematic.
example
From a terminal

Code: Select all

Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import threading
>>> print(threading.activeCount())
1
From IDLE

Code: Select all

Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import threading
>>> print(threading.activeCount())
2
WHY is the active thread count 2 in IDLE? It should be one. The problem is that IDLE is using a thread and that causes problems if you want to use threading. (Same difference in python3)

Also IDLE can screw with namespaces.
example
viewtopic.php?f=32&t=145672&p=960056&hilit=idle#p960056

So to
MarkHaysHarris777 wrote:The proper way to build python scripts these days is IDLE
the response is "Asinine flap-doodle, poppycock and balderdash!" ;)

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: Code editor

Wed May 11, 2016 6:10 pm

MarkHaysHarris777 wrote:
Sleep Mode zZ wrote: My old problem from years back, probably not relevant any more, had to do with using Finnish (Nordic) characters in my code.* I did everything like Python documentation told me to do but did run into errors - until I ran the program directly the Python interpreter and it worked fine. I was a beginner then and it was really frustrating to stumble into a problem that was not my fault but the fault of the recommended Python editor for beginners. I have not used IDLE since..
You are correct, its not relevant any longer. The problem you ran into back then had nothing to do with IDLE either; it had to do with the fact the unicode was new, and was as yet not built-in to python (at all).

Today ONE of the major features of Python3 is that unicode is completely built-in (inherent) from the ground up. Python3 fixed a lot of things... but the most important was unicode, in my opinion; another was a rework of IDLE. The IDLE changed hands (as it were) and got refreshed. If you have not used it in ten years, well, you haven't used it... just saying. :)
You're right that Unicode with Python 3 has probably solved this particular problem with IDLE. (Although there have lots of bug reports concerning Python 3 and IDLE3 tripping on Unicode characters.) I most probably was using Python 2 at the time, but like I already said, the issue was not a problem with Python 2 - my code ran just fine on it. It really was a problem manifesting only when executing the code from IDLE - whatever the exact details were at the time.

IDLE should run the executed programs in a separate Python interpreter without any interference that makes the program run differently compared to the program run from a terminal. The pygame example was just an example to show that IDLE still can interfere with the interpreter executing the code when it is executed from IDLE. So, I won't be using it, and I won't recommend it to others, although problems like these resulting from interaction with IDLE and the code run from it might not be common. There are lots of other options.

Return to “Python”