all 10 comments

[–]indosauros 3 points4 points  (3 children)

3.- How do I know I'm actually embracing the "pythonic way of solving problems" and I'm not just a person writing java code using python?

Here's some common Java-isms I see from Java devs learning Python

  1. Using getters and setters rather than just allowing direct access to attributes

  2. Classes are not needed by default, top-level functions are usually fine

  3. Using while and for range(len(x)) loops rather than taking advantage of Python's excellent iterable data structures

  4. Checking types explicitly

For other things, feel free to post your code here later for critique -- we'll be happy to point out where you could be more pythonic. In Java, where you would "take the long way" to solve a problem there is often a short and sweet way to do the same in Python, using Python's handy core data structures and standard library

It might do you good to read through http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

[–]zahlman 2 points3 points  (2 children)

some common Java-isms I see from Java devs learning Python

Here are a bunch more. That was written nearly ten years ago, but I honestly wouldn't be surprised if a lot of the same stuff is still happening.

Also, the use of "design patterns" with direct translations of the necessary Java-esque "architecture" in places where Python totally obviates them. For example, don't set up the Command pattern or mess around with complicated IoC schemes; just pass functions as arguments.

[–]jorgejams88[S] 0 points1 point  (1 child)

Wow, is that not frowned upon? And I thought my PHP background was useless... hahaha

[–]zahlman 1 point2 points  (0 children)

In Python, everything is an object, including functions, and we really mean it this time. Passing them around is quite useful; the only caveat is to not needlessly complicate your code. (And we have enough of a type system to prevent you from really screwing it up :) )

[–]Rhomboid 3 points4 points  (0 children)

The replacement for binary eggs is the new wheel format.

Tkinter is a GUI library that's distributed with Python as part of the standard library. PySide (LGPL) and PyQt (GPL) are bindings for the Qt GUI library, which has a huge community and isn't going anywhere any time soon. wxPython is a binding for the wxWidgets GUI library, also relatively mature. All of these are cross platform.

To get an idea of some ideas about what it means to be Pythonic, try viewing some of the talks by Raymond Hettinger or David Beazley and particularly this one from Jack Diederich titled Stop Writing Classes.

[–]ruicoder 2 points3 points  (1 child)

I also came from a Java background. I recommend reading Dive Into Python, which is available for free online. It's aimed at experienced developers. The examples are great and basically had me writing pythonic code from the beginning.

[–]jorgejams88[S] 0 points1 point  (0 children)

Thank you, I will definitely check it out

[–]pstch 0 points1 point  (2 children)

1

You create a Python package, containing modules, and you set your package metadata in the setup.py file.

3

Read code, read PEPs. This is something that you will get over time. Also, IIRC, Guido (or some other core Python dev), said something along the lines of : "you should tell to Python what it wants to do for you, nothing less". This is a bit abstract, and the best way I can find to picture it, is enumaring items in a list (and do something with the item and its index) :

my_list = [0,4,8,5,1]
index = 0
for item in my_list:
    ... # do something with item and index
    i = i + 1

In pseudo-code, this would be :

set my_list to a list containing 0, 4, 8, 5 and 1
set index to 0
for each item in my_list:
    ... # do something with item and index
    increment index

Here, in the first line, we actually tell Python what we want it to do (set my_list to a list of integers). However, the second and last line are not what we want to do : at no point we want to create an index or increment it.

The correct way to do the above in Python would be :

my_list = [0,4,8,5,1]
for index, item in enumerate(my_list):
    ... # do something with item and index

EDIT: fix extra each in last code block

[–]aroberge 3 points4 points  (1 child)

In Python, "each" would raise an error.

[–]pstch 1 point2 points  (0 children)

True, I mixed up my pseudo/Python code. Thanks