从 PHP 学习 Python

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2561362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 00:55:30  来源:igfitidea点击:

Learning Python coming from PHP

phppython

提问by Amy B

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

我的动态语言经验完全是 PHP。我现在想学习 Python 以拓宽我的职业机会,因为我喜欢编程。:)

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?

在学习 Java 时,我使用了一个站点(现在丢失了 URL/真实姓名),类似于“Java for PHP 开发人员”之类的站点,页面的一侧是 PHP 代码,另一侧是 Java 代码来执行一样。有没有类似 Python 的网站?

Any other recommendations/advice?

还有其他建议/建议吗?

Thanks

谢谢

采纳答案by wescpy

The OP's question is simple enough, but as @Pekka mentioned (or hiHymaned), 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.

OP 的问题很简单,但正如@Pekka 提到的(或被劫持的),这可能是一个更深层次的问题(需要更实质性的答案)。是的,Python 的语法很容易学习,无需书本,但与任何其他语言一样,掌握它仍然需要相当多的时间。

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.

Dive Into Python 的建议是有效的,尽管 Python 3 版本仅适用于没有包袱的新手(意味着没有现有的 Python 代码,没有尚未移植到 Python 3 的库/依赖项等)。可悲的是,马克已经删除了他的大部分在线内容。这是他的 Python 3 书籍的一个档案:http: //www.diveintopython3.net...通过立即让您沉浸在编码位中,这是对该语言的非常好的高级介绍。

If you are looking for something slightly more comprehensive, I wrote Core Python Programmingspecifically 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 Referenceor 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. ;-)

如果你正在寻找更全面的东西,我写了Core Python Programming专门针对那些已经掌握另一种高级语言(如 Java、C/C++、PHP、Ruby 等)的程序员,他们需要尽可能快地学习 Python尽可能深入……与其说是“快速潜水”,不如说是“深潜”。对于您可以根据需要从书架上取下的纯参考书,我建议 Beazley 的Python Essential Reference或 Martelli 的Python in a Nutshell……两者都很棒,尽管 Alex 的书还没有更新到最新的 Python 版本。我确定他正在努力。;-)

[UPDATED Jun 2015] Back on hiHymaned 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., Jinja2for templating, SQLAlchemyfor the ORM, MochiKitas 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, exceptfor 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 SQLshould 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?!? :-)

[2015 年 6 月更新] 回到被劫持的话题,在 Python 上开发 Web 应用程序时有多种选择,目前最流行的是Django。这是一个全栈 Web 框架,是 Python 与 Ruby on Rails 最接近的东西。它具有模板、ORM,可以在各种核心组件(RDBMS、Web 服务器、JavaScript 库等)上运行,带有令人惊叹的管理界面,等等。如需更多功能,还可以查看Pinax。Django 的替代品是Pyramid。Pyramid/Pylons 不是一个单一的整体框架,而是更像粘合剂,将同类最佳的组件捆绑在一起,即用于模板的Jinja2、用于 ORM 的SQLAlchemyMochiKit作为 JS 库等。第三个选项,主要用于高流量、低延迟、可扩展的应用程序是Google App Engine。您使用 Python(或 Java、PHP 或 Go)编写您的应用程序并上传到 Google 以在其基础架构上运行您的应用程序。除了数据存储之外,大部分开发都类似于在标准 LAMP 堆栈上开发 Web 应用程序。基于Google的BigTable,它是一个非关系型分布式对象数据库,所以最大的障碍是克服用关系型DB的方式思考;还作为Google Cloud Datastore独立发布。还有一个与 MySQL 兼容的关系替代方案,称为Google Cloud SQL如果您更喜欢它而不是 NoSQL 解决方案。BigTable 也可作为 App Engine 的独立技术提供,并作为Google Cloud Bigtable 提供。你有足够的选择吗?!?:-)

Hope this helps!

希望这可以帮助!

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

附:如果您正在寻找即将开始的为期 3 天的 Python 综合课程,请与我联系。:-)

回答by thetaiko

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.

我不确定这样的事情是否存在,但 Python 通常是一种易于学习的语言。Python 文档通常非常清晰且易于遵循。在 Python 解释器中,您还可以使用 dir() 和 help() 方法来查看方法、属性和文档,这使得您可以轻松探索 Python 中可用的选项。

A few examples of differences between PHP and Python:

PHP 和 Python 之间差异的几个示例:

Python:

Python:

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

PHP:

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 不再使用“{”和“}”,而是使用缩进来查看 for 循环何时完成。

Python:

Python:

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

PHP:

PHP:

$x = array('hello'=>'spam', 'world'=>'eggs');
if array_key_exists('hello', $x) {
    echo $x['hello'].PHP_EOL;
}

回答by Manquer

This basic intro with PHP references is a place to start

这个带有 PHP 参考的基本介绍是一个开始

IBM Developer Works:Python Basics for PHP Programmers

IBM Developer Works:面向 PHP 程序员的 Python 基础知识