python爱好者论坛_给Python爱好者的10条省时技巧

python爱好者论坛

Python is a beautiful language, able to inspire love in its users. So if you're looking to get into programming, or if you're a bit tired of C++, Perl, Java and the rest, I recommend you give Python a try.

Python是一门美丽的语言,能够激发用户的爱戴 。 因此,如果您打算开始编程,或者对C ++,Perl,Java和其他内容有点厌倦,建议您尝试一下Python。

Python has many features that make it attractive to programmers. It's easy to learn, object oriented, byte-compiled, free and open-source. It also has run-time type checking, full and fast support, and extensive libraries for performing various tasks.

Python有很多的功能 ,使它对程序员的吸引力。 它易于学习,面向对象,字节编译,免费和开源。 它还具有运行时类型检查,全面和快速的支持,以及用于执行各种任务的大量库。

Python的效率 (Efficiency with Python)

In this article, I want to highlight some of the ways you can save time in Python and thus maximize productivity.

在本文中,我想重点介绍一些可以节省时间并因此最大程度提高生产率的方法。

In preparation, I quizzed several Pythonists on their best time-saving tips. Here are the results …

在准备过程中,我询问了几位Pythonist的最佳省时技巧。 结果如下……

1.不要使用分号 (1. Don’t Use Semicolons)

Since using semicolons is considered optional in Python—as opposed to other object-oriented programming languages—you don’t need to end each statement of your code with a semicolon.

与其他面向对象的编程语言相比,由于在Python中使用分号被认为是可选的,因此您无需在代码的每个语句后加上分号。

This may seem simple and not really time wasting; but once your code stretches into thousands of lines, all these semicolons can get a bit distracting, and it's a lot of unnecessary typing.

这看似简单,但并非真正浪费时间。 但是一旦您的代码扩展到成千上万的行,所有这些分号都可能会让人分神,并且这是很多不必要的输入。

2.获得一个好的代码编辑器 (2. Get a Good Code Editor)

Choosing the right Python editor can be a huge time saver. Many new Python programmers are confused over which code editor to pick—especially with so many available.

选择正确的Python编辑器可以节省大量时间。 许多新的Python程序员对选择哪种代码编辑器感到困惑,尤其是选择了这么多可用的代码编辑器。

It's very disruptive to get used to one editor and then have to change to another, so it's best to start with a good one. Make sure whichever you choose does flake8 and PEP8 in real time.

习惯一个编辑器然后又不得不换另一个编辑器是非常破坏性的,因此最好从一个好的编辑器开始。 确保您选择的任何一个实时地执行flake8PEP8

For guidance on which editor to choose, see my previous article on Which Code Editors Do Pythonists Use?

有关选择哪个编辑器的指南,请参阅我以前的文章“ Pythonists使用哪些代码编辑器?”。

3.遵循Python代码样式 (3. Follow the Python Code Style)

Following the Python code style can enhance the readability of the code, and thus saves time while walking through your code. (The design philosophy of Python emphasizes the issue of code readability.)

遵循Python 代码样式可以增强代码的可读性,从而节省遍历代码的时间。 (Python的设计理念强调了代码可读性的问题。)

4.使用help()函数 (4. Use the help() Function)

Python's help() is a very handy, built-in function that can save a lot of time—for example, when searching for descriptions of other functions. You can simply run this function directly from your interpreter console.

Python的help()是一个非常方便的内置函数,可以节省很多时间,例如,在搜索其他函数的描述时。 您可以直接在解释器控制台中直接运行此功能。

The Python documentation describes the ways you can put this function to good use.

Python文档描述了充分利用此功能的方法。

5.使用图书馆 (5. Use Libraries)

There are lots of Python libraries that save you from reinventing the wheel every time.

有很多Python库可让您不必每次都重新发明轮子。

For example, you can choose from a range of packages offered by PyPI (the Python Package Index), a repository of Python software.

例如,您可以从PyPI (Python软件包索引)(Python软件的存储库)提供的一系列软件包中进行选择。

scikit-image home page

A nice example of a Python library is scikit-image. It enables image processing tasks like blurring, enhancing contrast and zooming—simply by calling functions.

python库的一个很好的例子是scikit-image 。 它只需调用函数即可实现诸如模糊,增强对比度和缩放之类的图像处理任务。

6.使用Cookiecutter (6. Use Cookiecutter)

Cookiecutter is a command-line utility that enables you to create all your Python project boilerplates from project templates, and this can be a big time saver.

Cookiecutter是一个命令行实用程序,使您可以从项目模板创建所有Python项目样板,这可以节省大量时间。

7.严格评论 (7. Comment Rigorously)

Getting in the habit of commenting your code will save you—and others—a lot of time, especially down the track. (Yes, we hear this a lot, but many programmers still need to be reminded, it seems!)

养成注释代码的习惯将为您和其他人节省大量时间,尤其是在过程中。 (是的,我们听到的很多,但是似乎仍然需要提醒许多程序员!)

Python commenting

Commenting is particularly vital when working on teams—especially ones that change a lot.

在团队中工作时,尤其是变化很大的团队时,评论尤其重要。

8.经常测试 (8. Test Often)

Try to test every component in your program. While it may sound time-consuming, testing as you code saves a lot of time in the long run, and reassures you that there are no hidden bugs. It also reinforces your understanding of what each piece of code is actually doing.

尝试测试程序中的每个组件。 虽然这听起来很耗时,但是从长远来看,在编写代码时进行测试可以节省大量时间,并可以确保没有隐藏的bug。 它还加强了您对每段代码实际作用的理解。

A REPL—a read-eval-print loop—is a common means of testing your code as you go, and is often employed by Pythonists.

REPL —读-评估-打印循环—是一种在进行过程中测试代码的常用方法,并且经常被Pythonists使用。

9.专注于专业 (9. Focus and Specialize)

A common recommendation of accomplished Pythonists is to have a specialized focus or area of expertise. There are lots of things you can do with Python—from coding for web cams to dealing with computations and mathematics.

有成就的Python专家通常的建议是具有专门的重点或专业领域。 使用Python可以做很多事情-从为网络摄像头编码到处理计算和数学。

There are great libraries available to help with these tasks, such as SimpleCV, dealing with computer vision; Biopython, a library for biological computation; and SymPy, a library for dealing with symbolic mathematics.

有许多强大的库可帮助完成这些任务,例如处理计算机视觉的SimpleCVBiopython ,一个用于生物计算的库; 和SymPy ,一个用于处理符号数学的库。

Digging into areas like these, and mastering a particular framework, helps you learn Python at a deeper level, master a particular style of coding (mentioned in point 3), and deal with specialized types of problems.

深入研究此类领域并掌握特定的框架,可以帮助您更深入地学习Python,掌握特定的编码风格(在第3点中提到)并处理特殊类型的问题。

10.每天写代码 (10. Write Code Every Day)

When you get in the habit of writing Python code every day, solving problems using Python will start to become second nature. You'll start to think in Python, so to speak, and this ultimately helps you to navigate and solve issues faster.

当您养成每天编写Python代码的习惯时,使用Python解决问题将开始成为第二自然。 可以这么说,您将开始使用Python进行思考,这最终将帮助您更快地导航和解决问题。

结语 (Wrapping Up)

In this brief article, I've listed the main tips I gathered while talking with Pythonists about time-saving tricks. Here are a few others that I could have added to the list.

在这篇简短的文章中,我列出了与Python专家讨论节省时间的技巧时收集到的主要技巧。 这是我可以添加到列表中的其他一些内容。

参加Python活动和聚会 (Attend Python Events and Meetups)

Make sure to attend events and meetups where possible. They're great for sharing experiences, best practices, tools, and other interesting topics.

确保尽可能参加活动和聚会。 它们非常适合分享经验,最佳实践,工具和其他有趣的主题。

It may not be obvious that this is a time-saving strategy, but learning from the experiences of others—through advice, tips and hacks—is another way to avoid reinventing the wheel.

也许这不是一个节省时间的策略,但是通过建议,技巧和黑客从他人的经验中学习是避免重新发明轮子的另一种方法。

A great event to check out is the annual PyConf.

一年一度的PyConf是一项很棒的活动。

在纸上思考 (Think on Paper)

Thinking on paper—before diving straight into code—will give you the flexibility to change. Going straight to code forces you to get involved in implementation details from the outset, which is not always the best use of your time when starting a project. Paper's distraction-free mode is great for brainstorming and problem solving!

在深入研究代码之前(在直接研究代码之前)进行纸上思考将为您提供更改的灵活性。 直接编写代码会迫使您从一开始就参与实现细节,这并不总是在启动项目时最好地利用您的时间。 Paper的无干扰模式非常适合集思广益和解决问题!

掌握基础知识 (Master the Fundamentals)

Lastly, it may seem obvious, but make sure to invest time in learning the fundamentals of Python. This will eventually save you a lot of time, as you'll be better prepared to tackling more complex topics.

最后,它看起来似乎很明显,但是请务必花时间学习Python的基础知识。 最终,这将为您节省大量时间,因为您将更好地准备应对更复杂的主题。

Some good books to help with this include

一些有助于解决此问题的好书包括

It's also important to keep abreast of news as it happens, by reading blogs and articles. A great blog to follow is The Mouse Vs. The Python.

通过阅读博客和文章来及时了解新闻的发​​生也很重要。 一个值得关注的博客是The MouseVs。 Python



Well, I'm sure there are more things that could be added to the list. What are your best time-saving tips when programming Python? Let me know in the comments!

好吧,我确定还有更多可以添加到列表中的内容。 编写Python时,最省时的秘诀是什么? 在评论中让我知道!

翻译自: https://www.sitepoint.com/10-time-saving-tips-pythonists/

python爱好者论坛

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值