Python is a very nice language in many respects: enforced white-spacing promotes readability, extensibility and Python’s inbuilt Read-Eval-Print-Loop interpreter combined with its introspection capabilities provides a very easy way to learn and get to grips with the language.
But that can’t be all, can it? Why Python?
One of the reasons behind the success of our course has been customers wanting a good language for developing automated testing scripts and Python fits the bill brilliantly – it’s fast (enough), approachable and has great support for the embedded platforms of today and tomorrow (read: Linux :))
Lua is nice, I’m honestly a fan of Lua and have used it in previous projects where Python was just too big to embed (adding in Lua is a ‘tiny’ 400kb) but that’s the issue – Python is a general programming language – I can quickly bring in web services, advanced numerical libraries, GUIs and scientific libraries as well as the built-in things like networking and threading but Lua just simply isn’t designed for the vast contexts that Python fits and that’s part of Lua’s design – it’s not a general scripting language.
[nick@zeus ~]$ gjs gjs> +((+!!+)+(!++!!)) 12
One thing that does let down Python, in my opinion, is the lack of a good developer environment. I appreciate that Python is easy to use and the interactivity is a massive boon but showing IDLE to someone who has used Visual Studio and all it’s spoon feeding goodness does make me a little sad.
Line numbers? Stability? A carat that will allow you to type when you misclick? – why do you need those when you can have… Detachable Menus!
It’s easy to make fun but IDLE seems un-maintained and could do with some TLC but it’s still useful as a learning tool to bridge the gap between Visual Studio and the command line. On the plus side, the debugger does bring some good insight into the operation of the code for first-timers.
Whenever I need to script something, mock up an interface, test a design, develop some back-end code or create a full application – Python is always there for me.
Python’s versatility, compatibility and ‘kitchen sink’ approach make Python a fantastic choice for almost everyone, from non-programmers through to the physicists at CERN using it to create black holes. It truly is the everyman’s (and woman’s) language.
So why not learn something new?
[nick@zeus ~]$ python Python 2.7.3 (default, Aug 9 2012, 17:23:58) [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import antigravity
- Disassembling a Cortex-M raw binary file with Ghidra - December 20, 2022
- Using final in C++ to improve performance - November 14, 2022
- Understanding Arm Cortex-M Intel-Hex (ihex) files - October 12, 2022
Co-Founder and Director of Feabhas since 1995.
Niall has been designing and programming embedded systems for over 30 years. He has worked in different sectors, including aerospace, telecomms, government and banking.
His current interest lie in IoT Security and Agile for Embedded Systems.
Check out using the visual studio shell application with python for a familiar ide and debugger
Hey Luke, thanks for reading. I was unaware how good the VS integration was these days - nice to see MS on the bandwagon.
I am predominantly a Linux guy and a lot of our the guys we train are in the same boat so VS sadly. Most Python developers seem to move away from using IDLE so I'd like to see it become more of a learning tool but it's definitely worth mentioning to our delegates if they are already familiar with the VS IDE (it is rather good).
Interesting comparison with Lua, actually I use Lua for all my scripting requirements, and depending on which libraries you embed it can come down to under 200K.
I sort of agree with you though, a lot of the stuff comes pre-bundled with Python, whereas with Lua it is out there but you have to go hunting for it (there are some pre-bundles that include an IDE that make it nearly comparable to the Python offering, and IUP gives lua a GUI, luasocket for sockets, etc).
I've started using Python recently with kids on Raspberry Pi computers in after school computing clubs. It has it's upsides and it's downsides.
One upside is that I describe Python as an "incremental learning language" - you learn just the bits you need to get the job done. This is a huge benefit in a club environment where you don't have much time to go through lots of foundation theory or top'n'tail syntax.
One downside is that with things like pygame, the twitter api, and other interfaces, kids get drawn into OO very quickly and don't have either the foundation knowledge or even the understanding of the problem space to understand the solutions that OO provide. However, it is possible to present most of this as "a load of dots" and hand wave over the rest until later, and just about get away with it.
I'm growing to like Python as a developer, I'm still not completely sure of it as a first learning language, but I think if people steer away from some of the dark corners, it's probably good enough. The interpreter is really great for experimenting before coding, I really like that.
'unittest' in particular works just like I expect it to, having come from a junit V1 heritage myself, and it's easy to do tool assisted TDD using python (but it does suck you into OO so mixed feelings about whether this is accessible to the younger kids).
Of course, read all the work by Michael Kolling at UKC (bluej, greenfoot) for a really good argument of whether you should start with objects or not.
Like any tool, it's good if used properly. If abused, you'll shoot yourself in the foot.
You should checkout ipython, specifically it's notebook interface. It's a browser-based interface (with a local python process serving), and it really does modernize the whole REPL/experimentation part of python wonderfully. It's great at that iterative experimentation process, while also laying out all your work and saving it in a notebook for later reference.
http://nbviewer.ipython.org/ has some pretty examples, though they're mostly all science-related, leaning heavily on the notebook interface's support for displaying matplotlib output directly. But it can be used for general-purpose python too, just look at the first of the tutorial examples shipped with ipython: http://nbviewer.ipython.org/url/github.com/ipython/ipython/raw/master/examples/notebooks/Part%201%20-%20Running%20Code.ipynb
If you then proceed to actual "coding" (e.g. writing .py files), ipython isn't a great help there, you'll still be starting off by copying and pasting functions here and there from your notebook into your favorite text editor, though ipython does have some support for loading, reloading, and running files off the drive. A particularly nice feature is being able to run a python file and then have all of that execution's resulting namespace added to the REPL interpreter's namespace.
If you want an IDE, there is Pydev - http://pydev.org (free), and also PyCharm (commercial).
PyDev is great, though as you'd expect you can't always work out types for code completion in a dynamically typed language.
For interactive / exploratory work, ipython --pydev + pandas is fantastic.
Check out LightTable 0.4 for Python.
Nice to see Lua get a mention. Nick knows that I favour Lua and have embedded it in at least one product where it was far less than 400KB (A quick look at the map file for an ARM926 device shows that everything lua 5.1.4 fits in 151KB, without any tweaking or removing libraries).
Lua turns up in all sorts of places; wireshark for packet dissectors, a Minecraft mod, World of Warcraft and Adobe Lightroom.
However, I tend to use Lua where I can't have python. Two embedded Linux projects had python which was great for exercising device drivers. On one of those, the size python added to the image (30MB?) wasn't justified and it was removed.
In Lua everything is a table, much like everything in python is a dictionary. Great introspection possibilities.
One word of caution, python comes in two flavours - v2.7 and v3. I have repeatedly tried to make the transition to v3 but I repeatedly retreat back to v2.7 because a library I want isn't in v3. A lot of v3 'future' is now part of v2.7 anyway.
If you want a different flavour then there's also .net friendly IronPython and Java friendly Jython too.
Learn the python language once and just keep using it!
Pingback: Sticky Bits » Blog Archive » Rapid Application Development with Python