Python程序员资源 [英] Resources for Python Programmer

查看:145
本文介绍了Python程序员资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Python写了很多代码,因此我非常习惯Python的语法,对象结构等.

I have written a lot of code in Python, and I am very used to the syntax, object structure, and so forth of Python because of it.

什么是向我提供基础知识的最佳在线指南或资源站点,以及具有VBA与Python等效功能/特性的比较或查找指南.

What is the best online guide or resource site to provide me with the basics, as well as a comparison or lookup guide with equivalent functions/features in VBA versus Python.

例如,我在将Python中的简单列表等同于VBA代码时遇到麻烦.我还遇到数据结构(例如字典等)的问题.

For example, I am having trouble equating a simple List in Python to VBA code. I am also have issues with data structures, such as dictionaries, and so forth.

有哪些资源或教程可以为我提供将python功能移植到VBA的指南,还是仅是从强大的OOP语言背景适应VBA语法的指南?

What resources or tutorials are available that will provide me with a guide to porting python functionality to VBA, or just adapting to the VBA syntax from a strong OOP language background?

推荐答案

VBA与Python完全不同,因此,您至少应阅读要使用的应用程序提供的"Microsoft Visual Basic帮助"(Excel,访问...).

VBA is quite different from Python, so you should read at least the "Microsoft Visual Basic Help" as provided by the application you are going to use (Excel, Access…).

通常来说,VBA具有与Python模块等效的功能;它们被称为库",创建起来不像Python模块那么容易.我之所以提及它们,是因为图书馆会为您提供可以使用的更高级别的类型.

Generally speaking, VBA has the equivalent of Python modules; they're called "Libraries", and they are not as easy to create as Python modules. I mention them because Libraries will provide you with higher-level types that you can use.

作为启动微调,有两种类型可以代替listdict.

As a start-up nudge, there are two types that can be substituted for list and dict.

VBA的类型为Collection.默认情况下可用(位于库VBA中).所以你只要做一个
dim alist as New Collection
从那时起,您可以使用其方法/属性:

VBA has the type Collection. It's available by default (it's in the library VBA). So you just do a
dim alist as New Collection
and from then on, you can use its methods/properties:

  • .Add(item)(list.append(item)),
  • .Count(len(list)),
  • .Item(i)(list [i])和
  • .Remove(i)(del list [i]).很原始,但是就在那里.
  • .Add(item) ( list.append(item) ),
  • .Count ( len(list) ),
  • .Item(i) ( list[i] ) and
  • .Remove(i) ( del list[i] ). Very primitive, but it's there.

您还可以使用VBA数组类型,就像python数组是相同类型项的列表一样,并且与python数组不同,您需要执行ReDim来更改其大小(即,您不能只添加和删除)项)

You can also use the VBA Array type, which like python arrays are lists of same-type items, and unlike python arrays, you need to do ReDim to change their size (i.e. you can't just append and remove items)

要拥有类似字典的对象,应将脚本库添加到VBA项目¹.之后,您可以
Dim adict As New Dictionary
然后使用其属性/方法:

To have a dictionary-like object, you should add the Scripting library to your VBA project¹. Afterwards, you can
Dim adict As New Dictionary
and then use its properties/methods:

  • .Add(key, item)(dict [key] = item),
  • .Exists(key)(dict.has_key [key]),
  • .Items()(dict.values()),
  • .Keys()(dict.keys()),
    以及其他将在对象浏览器"²中找到的内容.
  • .Add(key, item) ( dict[key] = item ),
  • .Exists(key) ( dict.has_key[key] ),
  • .Items() ( dict.values() ),
  • .Keys() ( dict.keys() ),
    and others which you will find in the Object Browser².

¹打开VBA编辑器(Alt + F11).转到工具→参考,然后检查列表中的"Microsoft脚本运行时".

¹ Open VBA editor (Alt+F11). Go to Tools→References, and check the "Microsoft Scripting Runtime" in the list.

²要查看对象浏览器,请在VBA编辑器中按F2(或视图"→对象浏览器").

² To see the Object Browser, in VBA editor press F2 (or View→Object Browser).

这篇关于Python程序员资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆