tags:

views:

261

answers:

4

My dynamic language experience is solely PHP. I want to learn Python now to broaden my career opportunities and just because I like programming. :)

When learning Java, I used a site (lost the URL/real name now), something like "Java for PHP developers" that had all on one side of the page the PHP code, and on the other side the Java code to do the same thing. Is there a website like that for Python?

Any other recommendations/advice?

Thanks

+2  A: 

I'm not sure such a thing exists but Python is generally an easy language to learn. Python documentation is generally very clear and easy to follow. From the Python interpreter you can also use the dir() and help() methods to view methods, attributes and documentation which makes it easy to explore what options are available to you in Python.

A few examples of differences between PHP and Python:

Python:

x = [1, 2, 3, 4, 5]
for a in x:
    print x
print "Loop is over"

PHP:

$x = array(1, 2, 3, 4, 5);
foreach($x as $a) {
    echo $a . PHP_EOL
}
echo "Loop is over" . PHP_EOL;

As you can see, Python does away with using '{' and '}' and instead uses indentation to see when the for-loop is complete.

Python:

x = {'spam':'hello', 'eggs':'world'}
if x.get('spam'):
    print x['spam']

PHP:

$x = array('hello'=>'spam', 'world'=>'eggs');
if array_key_exists('hello', $x) {
    echo $x['hello'] . PHP_EOL;
}
thetaiko
Not to hijack @Coronatus's question but what also would be interesting is tutorials on higher-level stuff like how to organize a scalable web application, how to build a basic class framework etc. etc. essentially, how do you do "xyz" in Python when you already know what it is, and how it's done in PHP? the basic syntax, I'm sure, is easy to learn when you come from another language.
Pekka
A lot of concepts transfer right over between PHP and Python. A lot of initial confusion comes from the fact that indentation is important in Python. Also, looping and if statements are a bit different. I'll edit my answer above to include some examples.
thetaiko
+3  A: 

I recommend you this free book Dive Into Python

Felipe Cardoso Martins
Damn I was pipped to the post again :)
Neil Aitken
A: 

http://diveintopython3.org/ has a good introduction to the language.

It doesn't dwell too much on basic programming concepts and allows you to concentrate on what's different in Python

Neil Aitken
+4  A: 

The OP's question is simple enough, but as @Pekka mentioned (or hijacked), this could be a much deeper question (requiring a more substantial answer). Yes, Python's syntax is easy enough to learn without a book, but like any other language, it still takes quite a bit of time to master.

The suggest of Dive Into Python is valid, although the Python 3 version is only for newbies with no baggage (meaning no existing Python code, no libraries/dependencies that haven't been ported to Python 3 yet, etc.). Yes, Python 3 is here, but most of the industrial world still runs on Python 2, so if you do need to build a complex app to run today, you should start with Python 2 version at http://diveintopython.org ... it is a very good high-level introduction to the language by immersing you into coding bits right away.

If you are looking for something slightly more comprehensive, I wrote Core Python Programming specifically targeted towards programmers already literate in another high-level language like Java, C/C++, PHP, Ruby, etc., who need to learn Python as quickly and as in-depth as possible... it's more like a "deep dive" than a "quick dive." For pure reference books that you can pull off the shelf as necessary, I would suggest either Beazley's Python Essential Reference or Martelli's Python in a Nutshell... both are excellent, altho Alex's book is not rev'd to the latest Python releases yet. I'm sure he's working on it tho. ;-)

Back on hijacked topic, there are several options when it comes to developing web apps on Python, the most popular currently is Django. That is a full-stack web framework that is the closest thing that Python has to Ruby on Rails. It has templating, an ORM, can run on various core components (RDBMSs, webservers, JavaScript libraries, etc.), comes with an amazing admin interface, and a whole lot more. For even more functionality, also take a look at Pinax. An alternative to Django is TurboGears. Instead of a single monolithic framework, TG acts more like glue, tying together best-of-breed components, i.e., Genshi for templating, SQLAlchemy for the ORM, MochiKit as the JS library, etc. The 3rd option, primarily for high-trafficked, low-latency, scalable apps is Google App Engine. You write your apps in Python (or Java) and upload to Google to run your app on their infrastructure. Most of the development will be similar to developing web apps on a standard LAMP stack, except for the datastore. Based on Google's BigTable, it's a non-relational distributed object database, so the largest hurdle is overcoming thinking in a relational DB way. However, the word "shard" won't even have to enter your vocabulary. :-)

hope this helps!

ps. if you're looking for an upcoming comprehensive 3-day course in Python, talk to me. :-)

wescpy
Yet another great example of pythonist nice.
Hugo Estrada