开发者

Learning Python coming from PHP [closed]

开发者 https://www.devze.com 2022-12-25 15:09 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 3 years ago.

Improve this question

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 li开发者_开发技巧ke that for Python?

Any other recommendations/advice?

Thanks


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.). Sadly Mark has removed most of his online content. Here is one archive of his Python 3 book: http://www.diveintopython3.net ... 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. ;-)

[UPDATED Jun 2015] 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 Pyramid. Instead of a single monolithic framework, Pyramid/Pylons act more like glue, tying together best-of-breed components, i.e., Jinja2 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, PHP, or Go) 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; also released independently as Google Cloud Datastore. There's also a relational MySQL-compatible alternative called Google Cloud SQL should you prefer that instead of a NoSQL solution. BigTable is also available as a standalone technology from App Engine and available as Google Cloud Bigtable. That enough options for you?!? :-)

Hope this helps!

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


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 a
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;
}


This basic intro with PHP references is a place to start

IBM Developer Works:Python Basics for PHP Programmers

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号