tags:

views:

433

answers:

9

Hi, I've got a junior starting who's coming from a Java background. As a company we're now focused on Python development(albeit with some legacy systems in Java hanging around).

I'm looking around for tips and resources to help the transition and wondered if you guys here had any useful tips for a newbie.

Cheers.

+3  A: 

I'm in a somewhat similar position to you, as I know Java fairly well but I'm just starting to use Python.

The Python tutorial is a pretty good place to start.

The Python Style Guide tells you everything you need to know about what your code should look like (and this matters in Python - whitespace is important).

And remember that if and for always have a : after them :-)

David Johnstone
+17  A: 

Make him read

Beginner's Guide to Python

Python for Java Programmers

Consider reading the accepted answer to this question to point these things out to him

Java -> Python list some features java doesn't have

Two articles discussing the general different approaches

Python is Not Java

Java is Not Python, either

A partial side by side comparison of java and python code

Python/Java A Side-by-Side

Give him pointers how/where to find documentation similar to the Java JDK API

The Python Language Reference

The Python Standard Library

Global Module Index

jitter
+1 for Python for Java Programmers.
e-satis
+1 for Python is Not Java
orip
+2  A: 

I've found dive into python to be the best remedy against the culture shock, that is sure to happen when moving from another lesser (just kidding, of course) language to python. It has almost no "Hello world" programs, but instead it shows you python ways of, say, working with xml, writing unit tests and so on. It was extremely useful to me.

shylent
+1  A: 

What about http://python.computersci.org/?

I think that with a guide like that, plus mentoring on Python idioms (list comps, and so on) while converting some Java code to Python as an exercise would be enough

Vinko Vrsalovic
+4  A: 

For students coming from pure Java background and want to conduct their thesis involving some Python-based software I have found the best way is to just let them start writing code after having some first tutorials read.

Then from time to time I screen their code and suggest code fragments that smell too Java-ish to migrate to a more Pythonic style.

Most often this is

  • for-loops that can be changed to list comprehensions
  • over-use of classes, where 1) modules, tuples or dictionaries work just fine or 2) interfaces are not needed explicitly
  • too complex conditions used in if-statements (1<x && x<=y && y<10) that can be simplified (1 < x <= y < 10)
  • reinvented functionality, which could be easily imported from scipy or the Python standard libs
  • glue code for experiments in bash that can now be implemented much more reader-friendly in Python itself
wr
+7  A: 

I would say that one problem when moving from any language in which you are comfortable is the lost feeling of suddenly not knowing how anything works!

I would advise to fill in the background for them first in terms of the following:

  1. How do you structure projects? (remember Java is 'usually' one class per file and in package 'directories'; is Python similar?)
  2. How do you build projects? (what are the Python versions of ant, classpath etc?)
  3. How do you configure and deploy your code? (what are the Python versions of Spring, guice etc?)
  4. Where are the good community sites to look for help?
  5. What are some of the most useful 3rd party tools

I think that the language differences (like of getting used to lambdas) will be easy enough and take a few weeks at the developer's own pace but not understanding the above points will slow down the familiarization process.

oxbow_lakes
+1 - A terrific answer.
duffymo
+1  A: 

Seconding oxbow_lakes, how do project teams document their stuff ?
Although good doc is largely language-independent, can people comment on doc standards, tools, browsers ?
Examples of good Python / good Java doc would be useful.

Denis
A: 

There's a lot of good advice here already, but I should call attention to the more interactive nature of Python versus Java. Python unlike Java offers you a classic "Read-Eval-Print-Loop" (REPL) which allows you to experiment with the language quickly. Rather than guess as to how a particular statement would perform in real-life, the answer can be had by typing the expression into the interpreter and seeing the result right away. This is one reason I recommend Python to beginning programmers, you get more immediate feedback than the traditional edit-compile-run cycle of other languages.

In particular I use ipython for much of my interacting with Python. Among other things, it allows you to type '?' after any identifier to get some help on an identifier, which gives you more information than the standard help() function, and is less keystrokes.

Also, to turn learning Python into a game, I personally learned a lot of my Python by solving puzzles at the PythonChallenge . (Disclaimer: I am not affiliated with PythonChallenge). Admittedly, solving the challenges requires more than just Python knowledge (small hint: do "view source" a lot), but the desire to solve a puzzle will give you motivation to learn new bits of Python. It did for me at least. Best of luck.

Anton I. Sipos
A: 

Python is a language that can be described as:

"rules you can fit in the palm of your hand with a huge bag of hooks".

Nearly everything in python follows the same simple standards. Everything is accessible, changeable, and tweakable. There are very few language level elements.

Take for example, the len(data) builtin function. len(data) works by simply checking for a data.__len__() method, and then calls it and returns the value. That way, len() can work on any object that implements a __len__() method.


Start by learning about the types and basic syntax:

  1. Dynamic Strongly Typed Languages
  2. bool, int, float, string, list, tuple, dict, set
  3. statements, indenting, "everything is an object"
  4. basic function definitions

Then move on to learning about how python works:

  1. imports and modules (really simple)
  2. the python path (sys.path)
  3. the dir() function
  4. __builtins__

Once you have an understanding of how to fit pieces together, go back and cover some of the more advanced language features:

  1. iterators
  2. overrides like __len__ (there are tons of these)
  3. list comprehensions and generators
  4. classes and objects (again, really simple once you know a couple rules)
  5. python inheritance rules

And once you have a comfort level with these items (with a focus on what makes them pythonic), look at more specific items:

  1. Threading in python (note the Global Interpreter Lock)
  2. context managers
  3. database access
  4. file IO
  5. sockets
  6. etc...


And never forget The Zen of Python (by Tim Peters)

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
gahooa