Thursday, August 22, 2013

From Java to Burma

Hands on Python


This month at our local Python user group (PYPTUG), I'll do a hands on session. Could have been in a workshop, code dojo or project night, but it'll be part of the normal monthly meeting.

Attributes, Properties and Descriptors


A lot of people learned C++ or Java in school and some of the normal patterns for these languages are regularly seen in the wild in languages such as C# and Python. Having coded in all of these, and many more, I appreciate greatly some of the features of a given programming language. And when it comes to Python (as Roger Sessions said, paraphrasing Einstein), that "everything should be as simple as it can be, but no simpler".

 The hands on will focus on attributes, and how to keep it simple. And of course, how to get out of trouble, because you have to do something not so simple later, using properties and descriptors.

I will be posting to my bitbucket pyptug repository some material related to the talk, including a log of the interactive session we will be doing.

Audience will be ranging from people who have never coded, to people who have programmed in other languages, to python experts. I love a challenge.

François
@f_dion

Monday, August 19, 2013

Nouvelle version de Brython: 20130817-141536

Téléchargement de Brython


Une nouvelle version de Brython, Brython-20130817-141536, est maintenant disponible sur la page des téléchargement
 

Changements

Depuis la version précédente :

- import amélioré , on peux utiliser les packages : "import X.Y", "from X.Y import Z [as A]", "from . import X" (corrige le bogue 123)
- le protocole des itérateurs utilise maintenant les méthodes __iter__() et __next__() pour tous les types
- "for" les utilisent aussi
- implémentation des compréhensions améliorée : utilise les dictionnaires global et local (corrige le bogue 129)
- améliorations a la console interactive : http://brython.info/tests/interactive_mode.html
- ajout du type "bytes" (incomplet)
- ajout de balises HTML5 et événements DOM manquants
- ajouts a la documentation en français, ajout d'une section pour les modules spécifiques a Brython ; autres parties traduites
- Bouton sur la page de tests pour exécuter tout les tests et retourner les erreurs
- amélioration du module markdown : les _ et * génèrent du HTML différent, tout comme __ et **
- le mot clé del : utilise la méthode __del__() si elle existe


Bogues

  • - Corrections :
. #78 : map() and filter() return iterator objects, not lists
. #124 : support of CSS attribute "float"
. #125 : add methods copy() and clear() to lists
. #126 : escaped quotes inside strings
. #127 : DOMNode instances comparison methods (__eq__ and __ne__)
. #128 : class inheritance
. conversion des JS objects dans json.js et $JS2Py
. problème avec les itérations sur instances DOMNode



Autres


  • réorganisation : déplacement de JSObject du fichier py_dom.js au fichier py_utils.js
  • galerie : ajout d'un jeu de solitaire qui utilise SVG et le glisser - déposer


Vos retours


L’équipe Brython espère vos retours sur cette version, autant pour nous laisser savoir si vous trouvez  des bogues mais aussi au niveau de votre expérience avec Brython, en joignant et participant aux forums Brython.

De plus nous aimerions entendre parler de vos projets (actuels ou futurs) avec Brython sur appareils mobiles (tablettes, etc) et informatique embarquée (Raspberry Pi, Beaglebone black, Cubieboard, etc), surtout au niveau des écrans tactiles, car nous y travaillons en ce moment. Alors, n’hésitez pas a joindre le forum ou a me contacter directement sur mon blog ou sur twitter.

François
@f_dion

Sunday, August 18, 2013

200000th visitor




Raspberrypi and Python


In February 2013, this blog reached the 100,000th visitor milestone. Tonight, it just past the 200,000th.

This little experiment has been ongoing for almost a year now. As I had mentioned before, I didn't expect a lot of visitors due to the specificity of the blog, but it was something I had to do. Most projects I do for business, I cant talk about, so I've made up some projects specifically for this blog.

The Raspberry Pi has continued on the road to popularity, and this has exposed many people to embedded computing, to software development and electronics, and that is a good thing. Some other subjects that have been popular over the year have been Brython, ZFS and dtrace.

I've seen people I've introduced to the Pi, to electronics or to replicators (ie. CNC, 3D printers, laser cutters), to Python or Brython come up with some really cool stuff in the past year, and that is ultimately quite rewarding.


The visitor 

So, where is this 200,000th visitor from? Surprisingly from the town of Sanford, NC. I say surprisingly because it is only an hour and a half away from Winston Salem by car.

Sanford, NC


François
@f_dion

Saturday, August 17, 2013

Brython 20130817-141536 published

Download Brython


A new version of Brython, Brython-20130817-141536, has just been published on the downloads page



Changes

Here are the main changes since the previous version :

- improved implementation of import, now supports packages : "import X.Y", "from X.Y import Z [as A]", "from . import X" (fixes issue 123)
- the iterator protocol now uses the standard methods __iter__() and __next__() on all types, including built-in types
- the "for" loop implementation has been changed to use these methods
- improved implementation of comprehensions : now uses global and local dictionaries (fixes issue 129)
- improved interactive console : http://brython.info/tests/interactive_mode.html
- partial support of built-in type "bytes"
- add missing HTML5 tags and DOM events
- change documentation in French, add a section for Brython-specific modules ; updated translation of documentation
- add a button on the Tests page to run all the tests in a row and report errors
- improvement to the markdown module : tags _ and * generate different HTML tags, as well as __ and **
- change implementation of the del keyword : now uses the method __del__() if it is defined

Bugs

  • - bug fixes :
. issue #78 : map() and filter() return iterator objects, not lists
. issue #124 : support of CSS attribute "float"
. issue #125 : add methods copy() and clear() to lists
. issue #126 : escaped quotes inside strings
. issue #127 : DOMNode instances comparison methods (__eq__ and __ne__)
. issue #128 : class inheritance
. bugs in conversion of JS objects in json.js and $JS2Py
. bug with iteration on DOMNode instances



Other


  • package organisation : move JSObject from py_dom.js to py_utils.js
  • gallery : add a demo of a solitaire game using SVG drag and drop


Feedback


As always, the Brython team looks forward to your feedback, particularly in terms of bug reports and also in sharing how you are using Brython, by joining and participating in the Brython forum.

We are quite interested in your experience on mobile devices (tablets etc) and embedded devices (Raspberry Pi, Beaglebone black, Cubieboard etc), particularly in conjunction with touchscreens, as we are about to bring further enhancements to Brython. So don't be shy and join the forum. Or at least contact me through my blog or on twitter.

François
@f_dion

Friday, August 2, 2013

A python interactive console in my blog

Brython modes

I had prepped a presentation on Brython for a Python conference and didn't want that to go to waste, so now, dear reader, you get to see all kinds of exclusive material I had made for it. (Don't worry, I'll have plenty more material for PyCarolinas 2013).

The difference is that this is a blog, not a talk, so it will be a good bit more non linear. I'm starting tonight with something very hands on, one of Brython's mode of deployment.

The Brython interactive mode

The brython.js script itself is not included in this page, so it is a hosted interactive mode. We will simply include an iframe to load an interactive console directly from brython.info. This is still quite experimental, as it is found under the tests/ section. It is now using most of my iframe box (was fixed some days back). But it does work pretty well already.

This is basically a zero install, just add the following in your web page and you'll get a brython interactive session (Edited 3-26-2014 to point to new location):  

<iframe src="http://www.brython.info/console.html" width="98%" height="400">Sorry... your browser doesn't support iframe. Time to upgrade or go to <a href="http://www.brython.info/console.html">http://www.brython.info/console.html</a> in a separate tab.</iframe>






So you should see a console above (wont work trough news aggregators). At the >>> | prompt, type:

x = input("yo")

Type the word me in the prompt dialog that will open. Make sure you type exactly that. So what do we have in x? Type the following:

print(x)

me - Ok, that's all nice, but not very exciting. So it does behave like a console. What else can we do?

import webbrowser

So now we have loaded the module webbrowser from the brython standard library (we will come back to that in a future article). Yeah, I know, mind bending, since we are client side. Let's use the module. Type the following:


webbrowser.open("http://en.wikipedia.com/wiki/internet_" + x*2)

Nice! All your base are belong to us, obviously. So, it does take a minute to get the brain wrapped around this concept, but once you do, the world's your oyster. You just have to:

doc <= "think"
:)

Alright, enough geek puns, but it is a friday night afterall. So go and check it all out at http://brython.info . There is documentation in english, french, spanish and portuguese. Feel free to contribute your own translations in markdown format through bitbucket.

If you've been following my blog, you already know about the <= (left arrow) operator. If not, check it out here: http://raspberry-python.blogspot.com/2012/12/brython-browser-python.html

In the early days, brython didn't have a print() keyword. So I had cooked up a quick webprint() that used the <= operator. Of course, 8 months later, we no longer need webprint(). Print works like it should, with stdout. For the interactive mode, it is redirected. Look at the (python) code to see how you can do that by right clicking on the iframe and doing a view frame source (hint, lines 48 to 51).


François
@f_dion