Moving from Java to Python

I have a junior starting with a Java background. As a company, we are now focused on developing Python (albeit with some legacy Java systems that hang around).

I am looking for tips and resources to help the transition, and wondered if you guys have any useful tips for newbies.

Greetings.

+48
java python
Jun 27 '09 at 8:57
source share
9 answers

Make it read

Python Beginner's Guide

Python for Java programmers

Think about how to accept the accepted answer to this question to point it out.

Java -> Python lists some functions. Java does not have

Two articles discussing common different approaches

Python is not Java

Java is not Python either

Partial comparison of java and python code side by side

Python / Java A Side-by-Side

Give him directions on how and where to find documentation similar to the Java JDK API

Python Reference

Python Standard Library

Global module index

+92
Jun 27 '09 at 9:17
source share

I would say that one problem when switching from any language in which you feel comfortable is a lost feeling, suddenly not knowing how everything works!

I would suggest first filling out the background for them as follows:

  • How do you carry out structure projects? (remember that Java is “usually” one class for each file and in the “directories” of the package; is Python similar?)
  • How do you build projects? (what are the versions of Python ant , classpath , etc.?)
  • How do you customize and deploy your code? (what are the versions of Python Spring , guice , etc.?)
  • Where are good community sites looking for help?
  • What are some of the most useful third-party tools.

I think that language differences (for example, getting used to lambdas ) will be quite easy and take several weeks at the developer's own pace, but not understanding the above points will slow down the familiarization process.

+25
Jun 27 '09 at 13:47
source share

For students coming from a pure Java background and wanting to do their dissertation using Python-based software, I found that the best way is to simply let them start writing code after reading some of the first tutorials.

Then, from time to time, I review my code and suggest snippets of code that also smell like Java-ish in order to move to a more pythonic style.

Most often it is

  • for loops that you can change to display a list.
  • excessive use of classes, where 1) modules, tuples or dictionaries work fine or 2) interfaces are not needed explicitly
  • too complex conditions used in the if-statement ( 1<x && x<=y && y<10 ), which can be simplified ( 1 < x <= y < 10 )
  • updated functionality that can be easily imported from scipy or standard Python libraries
  • code for experimenting in bash, which can now be implemented much more reader friendly in Python itself
+7
Jun 27 '09 at 9:32 a.m.
source share

I found an immersion in python to be the best remedy against culture shock that would surely happen when moving from another smaller (just kidding, of course) python language. It has almost no "Hello world" programs, but instead it shows you python methods, say, for working with xml, writing unit tests, etc. It was very helpful to me.

+6
Jun 27 '09 at 9:23
source share

I am a little like you since I know Java pretty well, but I'm just starting to use Python.

The Python tutorial is a very good place to start.

The Python style guide tells you everything you need to know about what your code should look like (and that matters in Python - spaces are important).

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

+4
Jun 27 '09 at 9:14
source share

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

I think with such a guide, plus mentoring Python idioms (list comps, etc.) when converting some Java code to Python as an exercise would be enough

+1
Jun 27. '09 at 9:32 a.m.
source share

Secondary oxbow_lakes, how do project teams document their materials?
Although a good document is heavily language dependent, people can comment on standards, tools, browsers

Examples of good Python / good Java document would be helpful.

+1
Jun 27 '09 at 15:39
source share

Python is a language that can be described as:

"which you can put in the palm of your hand with a huge bag of hooks."

Almost everything in python follows the same simple standards. Everything is accessible, interchangeable and customizable. Very few language level elements.

Take, for example, the built-in len (data) function. len(data) works by simply checking the data.__len__() method, and then calling it and returning a value. Thus, len() can work with any object that implements the __len__() method.




Start by exploring types and basic syntax:

  • Dynamic strongly typed languages
  • bool, int, float, string, list, tuple, dict, set
  • indentation, "everything is an object"
  • definitions of core functions

Then, let's move on to how python works:

  • imports and modules (really simple)
  • python path (sys.path)
  • dir() function
  • __builtins__

Once you understand how to put together the parts, go back and look at some of the more advanced features of the language:

  • iterators
  • overrides how __len__ (there are many)
  • list of concepts and generators
  • classes and objects (again, really simple, as soon as you know a couple of rules)
  • python inheritance rules

And as soon as you have a level of comfort with these elements (with an emphasis on what makes them pythonic), look at more specific items:

  • Threading in python (note the Global Interpreter lock)
  • context managers
  • access to the database
  • IO file
  • sockets
  • etc...



And never forget Zen Python (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 a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let do more of those! 
+1
Aug 04 '09 at 1:38
source share

There is already a lot of good advice here, but I have to pay attention to the more interactive nature of Python and Java. Python, unlike Java, offers you the classic "Read-Eval-Print-Loop" (REPL), which allows you to quickly experiment with the language. Instead of guessing how a particular statement will be executed in real life, an answer can be obtained by entering an expression into the interpreter and immediately seeing the result. This is one of the reasons I recommend Python to beginner programmers, you get more immediate feedback than the traditional editing cycle in other languages.

In particular, I use ipython for most of my interaction with Python. Among other things, it allows you to enter "?" after any identifier, to get some help with an identifier that gives you more information than the standard help () function, and fewer keystrokes.

Also, in order to turn Python learning into a game, I personally learned a lot of my Python by solving puzzles in the PythonChallenge . (Disclaimer: I am not affiliated with the PythonChallenge). Admittedly, solving problems requires more than just knowledge of Python (a little hint: really, “look at the source”), but wanting to solve the puzzle will give you motivation to learn new bits of Python. That was for me, at least. Good luck.

0
Aug 04 '09 at 1:35
source share



All Articles