Introducing Python to others


P

Paddy O'Loughlin

Hi,
As our resident python advocate, I've been asked by my team leader to
give a bit of a presentation as an introduction to python to the rest
of our department.
It'll be less than an hour, with time for taking questions at the end.

There's not going to be a whole lot of structure to it. First, I'm
going to open up a python terminal and show them how the interpreter
works and a few basic syntax things and then a file .py files (got to
show them that python's indenting structure is not something to be
afraid of :p). I think I'll mostly show things in the order that they
appear in the python tutorial (http://docs.python.org/tutorial/).

My question to you, dear python-list, is what suggestions do you have
for aspects of python that I should show them to make them maybe think
that python is better than what they are using at the moment.
All of the audience will be experienced (4+ years) programmers, almost
all of them are PHP developers (2 others, plus myself, work in C, know
C#, perl, java, etc.).
Because of this, I was thinking of making sure I included exceptions
and handling, the richness of the python library and a pointing out
how many modules there were out there to do almost anything one could
think of.
Anything else you think could make PHP developers starting think that
python is a better choice?
If I were to do a (very) short demonstration one web framework for the
PHP devs, what should I use? CherryPy (seems to be the easiest),
Django (seems to be the "biggest"/most used), or something else?

Any other suggestions for a possible "wow" reaction from an audience like that?

Thanks,
Paddy
 
Ad

Advertisements

N

*nixtechno

Hi,
As our resident python advocate, I've been asked by my team leader to
give a bit of a presentation as an introduction to python to the rest
of our department.
It'll be less than an hour, with time for taking questions at the end.

There's not going to be a whole lot of structure to it. First, I'm
going to open up a python terminal and show them how the interpreter
works and a few basic syntax things and then a file .py files (got to
show them that python's indenting structure is not something to be
afraid of :p). I think I'll mostly show things in the order that they
appear in the python tutorial (http://docs.python.org/tutorial/).

My question to you, dear python-list, is what suggestions do you have
for aspects of python that I should show them to make them maybe think
that python is better than what they are using at the moment.
All of the audience will be experienced (4+ years) programmers, almost
all of them are PHP developers (2 others, plus myself, work in C, know
C#, perl, java, etc.).
Because of this, I was thinking of making sure I included exceptions
and handling, the richness of the python library and a pointing out
how many modules there were out there to do almost anything one could
think of.
Anything else you think could make PHP developers starting think that
python is a better choice?
If I were to do a (very) short demonstration one web framework for the
PHP devs, what should I use? CherryPy (seems to be the easiest),
Django (seems to be the "biggest"/most used), or something else?

Any other suggestions for a possible "wow" reaction from an audience like that?

Thanks,
Paddy

Yeah tell them that they don't have to REWRITE all their code again,
just fix VERY MINOR things when required if there is a drastic
change... I would bite if I learned this a long time ago if I knew
that, and also threading in python is WAYYYYYYYYYYYYYYYYYYYYYYYYY
better, somethings in PHP you can't do like you can within python when
it comes to threading (which I'm stumped on right now in a project of
mine...)

I may add that debugging is a learning curve for sure, how and where
to place what when trying to debug a script in python.... So I would
mostly concentrate on the CORE thing of NO MORE rewriting your WHOLE
library for a change like you have to do with PHP. :)

My opinion.
 
B

Bruno Desthuilliers

Paddy O'Loughlin a écrit :
(snip)
Anything else you think could make PHP developers starting think that
python is a better choice?

The debugger ?-) (debugging PHP code is kind of nightmare).
If I were to do a (very) short demonstration one web framework for the
PHP devs, what should I use? CherryPy (seems to be the easiest),
Django (seems to be the "biggest"/most used), or something else?

AFAICT from lurking on django-users, it seems that quite a few PHP
developpers are switching to Django and really like it.
Any other suggestions for a possible "wow" reaction from an audience like that?

cf Hendrik's suggestions...
 
M

Marco Mariani

Paddy said:
All of the audience will be experienced (4+ years) programmers, almost
all of them are PHP developers (2 others, plus myself, work in C, know
C#, perl, java, etc.).

Show them the same classical design patterns in Java and Python. Explain
how it's much more flexible.
Any other suggestions for a possible "wow" reaction from an audience like that?

SQLAlchemy / SQLSoup, and XML handling with lxml.
 
P

python

Paddy,

I've tried to categorize some ideas for your presentation. Note that the
ideas within each category are ordered by my random "stream of
conscience" vs. prioritized in some logical order.

Good luck with your presentation! (BTW: It would be great if you could
share your final outline with this list so others have a starting point
for similar presentations)

Malcolm

Language basics to reassure developers their favorite capabilities
are present:

1. "Batteries included" examples for web, ftp, smtp, pop3/imap,
zip/gzip/tar, regular expressions

2. A simple database example to show that database access is really no
different than other tools

3. Exception handling example

4. Reading/writing files (iterating through text files)

5. Working with folders and files (os, shutil)

6. A simple class example and a class example showing multiple
inheritance (mixin)

7. Simple string manipulation example (also reinforce Unicode support)

8. Modules (including the ability to reference modules in a zip file)


Unique Python features:

1. Lists, dictionaries and sets

2. Pickling

3. IDLE console

4. Working with command line args (and optionally optparse)

5. Dynamic code evaluation (eval/exec)

6. String constant prefixes (r, b, u) and triple quoted strings that
span multiple lines

7. Indentation as syntax (plus no need for line continuation chars when
bracketed delimiters are in play)

8. Doc string commenting, help( object ), and dir( object )


Advanced Python features:

1. Threading and/or multiprocessing

2. Creating a Python based web server for offline apps/testing

3. A web framework like Django or (simple) web.py

4. A sample templating module

5. Sample parsers (lxml and/or pyparser)

6. Overriding built-in __methods__ so custom classes can support use
with operators (encourages polymorphism)

7. Iterators and generators

8. List and dictionary comprehensions
 
M

Mensanator

David said:
Here's my favorite thing about Python (you'd of course
remark that it's just a toy example, doing everything
in as dumb but easily understood way as possible):

print x+x
class Vector():
  def __init__(self, data):
    self.data = data
  def __repr__(self):
    return repr(self.data)
  def __add__(self, other):
    return Vector([self.data[0]+other.data[0],
                  self.data[1]+other.data[1]])
x = Vector([1,2])
print x+x

that's cute, but if you show them 2.6 or 3 it's even cuter:

...   def __add__(self, other):
...     return map(add, self, other)
...>>> x = Vector([1,2])
[2, 4]

andrew

Mind if I ask a question? In DU's code, both operands have to
be instances of the Vector class?
x = Vector([1,2])
x+x [2, 4]
x+[3,3]

Traceback (most recent call last):
File "<pyshell#60>", line 1, in <module>
x+[3,3]
File "<pyshell#55>", line 7, in __add__
return SV([self.data[0]+other.data[0],self.data[1]+other.data[1]])
AttributeError: 'list' object has no attribute 'data'


Whereas with your version, "other" just has to be an iterable.
x = Vector([1,2])
x+x [2, 4]
x+[3,3] [4, 5]
x+(9,9) [10, 11]
x+{3:4,4:9}
[4, 6]

Although it does require the same number of elements (because that's
required by map and could be changed if necessary).

Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
x+[3,3,3]
File "<pyshell#62>", line 3, in __add__
return map(add,self,other)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'


What would you have to do to make this work?
[2, 4, 1, 2]
 
Ad

Advertisements

P

Peter Otten

Mensanator said:
David said:
Here's my favorite thing about Python (you'd of course
remark that it's just a toy example, doing everything
in as dumb but easily understood way as possible):

print x+x
class Vector():
def __init__(self, data):
self.data = data
def __repr__(self):
return repr(self.data)
def __add__(self, other):
return Vector([self.data[0]+other.data[0],
self.data[1]+other.data[1]])
x = Vector([1,2])
print x+x

that's cute, but if you show them 2.6 or 3 it's even cuter:
from operator import add
class Vector(list):

...   def __add__(self, other):
...     return map(add, self, other)
...>>> x = Vector([1,2])

[2, 4]

andrew

Mind if I ask a question? In DU's code, both operands have to
be instances of the Vector class?
x = Vector([1,2])
x+x [2, 4]
x+[3,3]

Traceback (most recent call last):
File "<pyshell#60>", line 1, in <module>
x+[3,3]
File "<pyshell#55>", line 7, in __add__
return SV([self.data[0]+other.data[0],self.data[1]+other.data[1]])
AttributeError: 'list' object has no attribute 'data'


Whereas with your version, "other" just has to be an iterable.
x = Vector([1,2])
x+x [2, 4]
x+[3,3] [4, 5]
x+(9,9) [10, 11]
x+{3:4,4:9}
[4, 6]

Although it does require the same number of elements (because that's
required by map and could be changed if necessary).

Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
x+[3,3,3]
File "<pyshell#62>", line 3, in __add__
return map(add,self,other)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'


What would you have to do to make this work?
x+x+x # expecting [3,6]
[2, 4, 1, 2]

Use itertools.imap() which stops when the shortest sequence is exhausted and
have Vector.__add__() return a Vector:
.... def __add__(self, other):
.... return Vector(imap(add, self, other))
....
a = Vector([1,2,3])
a + [10, 20] [11, 22]
a + a + a [3, 6, 9]

Peter
 
P

Paddy O'Loughlin

Thanks for all your replies.
A lot of very strong answers :)

2009/3/26 Mensanator said:
What would you have to do to make this work?
x+x+x      # expecting [3,6]
[2, 4, 1, 2]

What's happening is that the call to map() is returning a list object.
So after it calculates the first "x+x", you are left with the equivalent of:
[6, 6] + x
Because the list object is on the left, it's __add__() function is
called, which appends x to [6,6].

Instead, convert the list returned by map to a Vector before returning
it. Like so:.... def __add__(self, other):
.... return Vector(map(add, self, other))
....
 
I

Irmen de Jong

Apart from the other suggestions that have been made already,
it could be very wow-provoking if you have a nice example using ctypes
to interface to existing c libraries.

Python shines as a glue language too :)

--irmen
 
Ad

Advertisements

M

Mensanator

class Vector(list):
...   def __add__(self, other):
...     return map(add, self, other)
...>>> x = Vector([1,2])

I've used the complex type for a similar problem (2D Cartesian points)
in the past, I saw the suggestion
once on the pygame list.

    >>> x = complex(1,2)
    >>> x + x
    (2 + 4j)

But those are floats aren't they?

Don't games use stuff like pixels per parsec? :)
 
A

André

Hi,
As our resident python advocate, I've been asked by my team leader to
give a bit of a presentation as an introduction to python to the rest
of our department.
It'll be less than an hour, with time for taking questions at the end.

There's not going to be a whole lot of structure to it. First, I'm
going to open up a python terminal and show them how the interpreter
works and a few basic syntax things and then a file .py files (got to
show them that python's indenting structure is not something to be
afraid of :p). I think I'll mostly show things in the order that they
appear in the python tutorial (http://docs.python.org/tutorial/).

Shameless plug:

Show them the Python tutorial in a regular browser window ... and then
switch tab to one in which you have the same tutorial loaded from
Crunchy (http://code.google.code/p/crunchy) and go through it
(interpreter and all) right from the browser's window. I've had some
really positive reactions from long-term Pythonistas when I did that
one-on-one two years ago.

Then perhaps use IPython as a terminal window and show them other cool
stuff that people have mentioned.

André
 
Ad

Advertisements

B

BackSeat

If I were to do a (very) short demonstration one web framework for the
PHP devs, what should I use?

No question: use web2py. See the website and the videos that
demonstrate it. You could build a reasonably substantial application
in 2-3 minutes if you practice it first - for example, a wiki.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top