Pythonic命名约定 [英] Pythonic Naming conventions
问题描述
我想知道以下类型的变量/序列我们可以遵循哪些命名约定:
变量:
-------------
整数
Float
Boolean
序列:
--------------
Strings
List
Dictionary
元组
文件
我理解Python变量是动态类型的。 ,这是它的一个特点。但是开发人员如何区分他正在使用的不同序列或变量。
提前谢谢
PSB
Hi,
I would like to know what naming conventions we can follow for the following types of variables/sequences :
Variables :
-------------
Integer
Float
Boolean
Sequences :
--------------
Strings
List
Dictionary
Tuples
File
I understand that Python variables are "Dynamically Typed" ,that is one of the feature of it.But how the developer differentiate with different sequences or variables he is working with.
Thanks in advance
PSB
推荐答案
我想知道命名约定我们可以遵循以下类型的变量/序列:
变量:
-------------
整数
浮点数
布尔值
序列:
--------------
Strings
List
Dictionary
元组
文件
我理解Python变量是动态类型的,这是它的一个特点。但是开发人员如何区分他正在使用的不同序列或变量。
提前谢谢
PSB
Hi,
I would like to know what naming conventions we can follow for the following types of variables/sequences :
Variables :
-------------
Integer
Float
Boolean
Sequences :
--------------
Strings
List
Dictionary
Tuples
File
I understand that Python variables are "Dynamically Typed" ,that is one of the feature of it.But how the developer differentiate with different sequences or variables he is working with.
Thanks in advance
PSB
当我在阅读你的帖子时,单词Dynamically Typed在我脑海里奔跑。我很高兴你有这种理解。因为函数不关心它的参数的类型,所以我已经确定了nameType(有时是long_nameType)命名的约定。为了我自己。但这主要适用于类对象的实例。我不会以你的方式区分多功能和非多功能。作为一项规则,我使用:
class:ThisClassName
def:ThisFuncName
useofThisClass = ThisClassName()
thisType = ThisFuncName()
整数
Float
我只使用描述性名称,如
loopCount,distance等等。只需等待,直到你遇到Decimal和其他非内置但非常常用的。
布尔
conditionFlag
Strings
whateverStr
List
listofList >
字典
describeDict
元组
samehereTuple
文件
alwaysFile
我希望这对你有用。谢谢发帖。坚持下去。
As I was reading your post, the words "Dynamically Typed" were running through my mind. I''m glad that you have that understanding. Because a function don''t care about the type of it''s arguments, I''ve settled on a nameType (sometimes long_nameType) naming "convention" for myself. But that mostly applies to instances of class objects. I don''t differentiate between mutibles and non-mutibles the way that you have. As a rule, I use:
class: ThisClassName
def: ThisFuncName
useofThisClass = ThisClassName()
thisType = ThisFuncName()
Integer
Float
I just use descriptive names like
loopCount, distance, etc. Just wait ''til you meet Decimal and others that are not built in, but are very commonly used.
Boolean
conditionFlag
Strings
whateverStr
List
listofList
Dictionary
describeDict
Tuples
samehereTuple
File
alwaysFile
I hope that is useful to you. Thanks for posting. Keep it up.
当我在阅读你的帖子时,单词Dynamically Typed在我脑海里奔跑。我很高兴你有这种理解。因为函数不关心它的参数的类型,所以我已经确定了nameType(有时是long_nameType)命名的约定。为了我自己。但这主要适用于类对象的实例。我不会以你的方式区分多功能和非多功能。作为一项规则,我使用:
class:ThisClassName
def:ThisFuncName
useofThisClass = ThisClassName()
thisType = ThisFuncName()
整数
Float
我只使用描述性名称,如
loopCount,distance等等。只需等待,直到你遇到Decimal和其他非内置但非常常用的。
布尔
conditionFlag
Strings
whateverStr
List
listofList >
字典
describeDict
元组
samehereTuple
文件
alwaysFile
我希望这对你有用。谢谢发帖。保持。
As I was reading your post, the words "Dynamically Typed" were running through my mind. I''m glad that you have that understanding. Because a function don''t care about the type of it''s arguments, I''ve settled on a nameType (sometimes long_nameType) naming "convention" for myself. But that mostly applies to instances of class objects. I don''t differentiate between mutibles and non-mutibles the way that you have. As a rule, I use:
class: ThisClassName
def: ThisFuncName
useofThisClass = ThisClassName()
thisType = ThisFuncName()
Integer
Float
I just use descriptive names like
loopCount, distance, etc. Just wait ''til you meet Decimal and others that are not built in, but are very commonly used.
Boolean
conditionFlag
Strings
whateverStr
List
listofList
Dictionary
describeDict
Tuples
samehereTuple
File
alwaysFile
I hope that is useful to you. Thanks for posting. Keep it up.
此外,对于可以在几行中看到计数器整个生命周期的短循环,i,j,k,做得很好。对于很多方法共享的长寿命实例变量,我使用了最后可能不需要Type的use_very_descriptive_names。这只是个人风格,我看到了惯例。多年来的变化。如果你看一下Tkinter所写的风格,你会发现我认为是一种非常常见的pythonic。命名事物的方式。另一方面,wxPython ToolKit使用C命名约定,因为底层实现并且是我喜欢的样式。
Also, for short loops where the whole life of a counter can be seen in just a few line, i, j, k, do just fine. And for long life instance variablea shared by many methods, I use_very_descriptive_names which may not need the Type at the end. This is all just personal style and I have seen "conventions" change over the years. If you look at the style that Tkinter was written in, you''ll see what I think is a very common "pythonic" way of naming things. On the other hand, wxPython ToolKit uses C naming conventions because of the underlieing implementation and is the style that I prefer.
我想知道我们可以遵循以下类型的变量/序列的命名约定:
变量:
-------------
整数
Float
布尔>
序列:
--------------
Strings
List
字典
元组
文件
我明白了Python变量是动态类型 ,这是它的一个特点。但是开发人员如何区分他正在使用的不同序列或变量。
提前谢谢
PSB
Hi,
I would like to know what naming conventions we can follow for the following types of variables/sequences :
Variables :
-------------
Integer
Float
Boolean
Sequences :
--------------
Strings
List
Dictionary
Tuples
File
I understand that Python variables are "Dynamically Typed" ,that is one of the feature of it.But how the developer differentiate with different sequences or variables he is working with.
Thanks in advance
PSB
看看这个: http://www.python.org/doc/essays/styleguide/
以下是我使用的一些指导原则:
Take a look at this: http://www.python.org/doc/essays/styleguide/
Following are some guidelines I use:
单个字母的名称类实例('''',''b'',''c'')
打开文件的单个字母名称(''f'')如果包含在一小块代码
''我'(整数)执行范围迭代时
LineLineIntersect3D,Plane3D - 类定义
clip_hole,add_weld,radius_cut, data_Defaults_path,import_data,trueAngleBetweenMembers,formatDict,formatPtList - 函数的描述性名称
PointRotate3D - 具有主要功能的函数的描述性名称
pt_list或ptList - 点数列表
bm_list或bmList - 梁列表
dd1,dd2,memDict,conn_dict - 词典
rot_arg - 元组(我主要使用列表)
ptWP,pt1,p1 - 点对象
mem1 - 第一个选定的成员对象
m,bm,col,mem,key - 迭代列表:
材料
beam
columns
成员
字典键
类似于列表的描述性名称 - 字符串,整数和浮点数
no_spa(空格数),left_dist(距离左端的距离)
我还在2.3 - 还没有使用套装
single letter names for class instances (''a'', ''b'', ''c'')
single letter name (''f'') for an open file if contained in a small block of code
''i'' (integer) when executing a range iteration
LineLineIntersect3D, Plane3D - class definitions
clip_hole, add_weld, radius_cut, data_Defaults_path, import_data, trueAngleBetweenMembers, formatDict, formatPtList - descriptive names for functions
PointRotate3D - descriptive names for functions with major functionality
pt_list or ptList - a list of points
bm_list or bmList - a list of beams
dd1, dd2, memDict, conn_dict - dictionaries
rot_arg - tuple (I mostly use lists)
ptWP, pt1, p1 - point objects
mem1 - the first selected member object
m, bm, col, mem, key - iteration on a list of:
material
beams
columns
members
dictionary keys
A descriptive name similar to lists - strings, integers, and floats
no_spa (number of spaces), left_dist (the distance from the left end)
I am still in 2.3 - not using sets yet
这篇关于Pythonic命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!