473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Pythonic Naming conventions

440 256MB
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
Feb 20 '07 #1
18 3255
bartonc
6,596 Expert 4TB
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
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.
Feb 20 '07 #2
bartonc
6,596 Expert 4TB
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.
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.
Feb 20 '07 #3
bvdet
2,851 Expert Mod 2GB
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
Take a look at this: http://www.python.org/doc/essays/styleguide/

Following are some guidelines I use:
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
Feb 20 '07 #4
bartonc
6,596 Expert 4TB
Take a look at this: http://www.python.org/doc/essays/styleguide/
Thanks BV. I hadn't read that before. I am amazed how much of THE MAN's style I have picked up over the years just by reading library modules. My whitespace thinking exactly matches his. Great link (I bookmarked it).
Feb 20 '07 #5
psbasha
440 256MB
Hi,

What naming conventions has to be followed for the Class Variables and Methods?.How to differentiate the Private ,Protected and Public Class Variables and Methods?Is there any conventions has to be followed.


Thankls & REgards
PSB
Feb 23 '07 #6
bartonc
6,596 Expert 4TB
Hi,

What naming conventions has to be followed for the Class Variables and Methods?.How to differentiate the Private ,Protected and Public Class Variables and Methods?Is there any conventions has to be followed.


Thankls & REgards
PSB
Guess you haven't found this yet.
Feb 23 '07 #7
psbasha
440 256MB
Hi ,

I am not able to decide the Naming conventions for the following.

Variables :
--------------

Float
Integer
String
List
Dictionary
Tuples
File

Class Names

Private,Protected and Public
Class Variables

Class Methods

Functions

I have looked for various material in Internet .I am not able to get the consistency naming conventions.

Each one is following thier own naming conventions.

Thanks in advacne
PSB
Feb 23 '07 #8
bartonc
6,596 Expert 4TB
Hi ,

I am not able to decide the Naming conventions for the following.

Variables :
--------------

Float
Integer
String
List
Dictionary
Tuples
File

Class Names

Private,Protected and Public
Class Variables

Class Methods

Functions

I have looked for various material in Internet .I am not able to get the consistency naming conventions.

Each one is following thier own naming conventions.

Thanks in advacne
PSB
It really comes down to a matter of personal style.
BV gave a great link. I gave suggestions. Please try to keep one post per topic so that all info ends up in one place. Thanks.
Feb 23 '07 #9
psbasha
440 256MB
Hi ,

The naming conventions for UI in Python are similar to that of Application.

UI Variables and Methods

- Handlers
- Control Variables ( ID's,EDIT Box,Combo Box)
- Class Variables
- Call back names
- Event Handlers
- Other


Thanks in Advacne
PSB
Feb 23 '07 #10
psbasha
440 256MB
Hi,

I am confused which naming conventions to be followed for Variables ,Classes and Functions.In www.Python.org ,the naming conventions looks fine.When I refer the .py files of the Python4.2.I am confused with different mixture of naming conventions used in different (.py) files for the variables,Classes,Methods,function etc.

Could anybody help me in better understanding of which naming has to be used and when it has to be used.

Thanks in advacne
PSB
Feb 23 '07 #11
bartonc
6,596 Expert 4TB
Hi ,

The naming conventions for UI in Python are similar to that of Application.

UI Variables and Methods

- Handlers
- Control Variables ( ID's,EDIT Box,Combo Box)
- Class Variables
- Call back names
- Event Handlers
- Other


Thanks in Advacne
PSB
Let's try to keep a topic in a single thread, please.
Feb 24 '07 #12
bartonc
6,596 Expert 4TB
Hi,

I am confused which naming conventions to be followed for Variables ,Classes and Functions.In www.Python.org ,the naming conventions looks fine.When I refer the .py files of the Python4.2.I am confused with different mixture of naming conventions used in different (.py) files for the variables,Classes,Methods,function etc.

Could anybody help me in better understanding of which naming has to be used and when it has to be used.

Thanks in advacne
PSB
The Father of Python clearly states:
"Naming Conventions
The naming conventions of Python's library are a bit of a mess, so we'll never get this completely consistent -- nevertheless, here are some guidelines."
Feb 24 '07 #13
psbasha
440 256MB
Let's try to keep a topic in a single thread, please.
Thanks for the reply

Still I need the clarification for the UI variables as mentioned in the discusiion.

Could you please clarifyit in more elaborately,so that I Can start working on my applications using the standard conventions.

-PSB
Feb 24 '07 #14
bartonc
6,596 Expert 4TB
Thanks for the reply

Still I need the clarification for the UI variables as mentioned in the discusiion.

Could you please clarifyit in more elaborately,so that I Can start working on my applications using the standard conventions.

-PSB
I use mixedCaseWords for all class instances, like GUI elements. The prefixed word is the name followed by TheClassOfTheElement. BTW, You shouldn't (although Tkinter allows it) do things like:
Expand|Select|Wrap|Line Numbers
  1. myClass[attribute] = value
. Always call the setters of GUI objects (or any class for that matter).
Feb 24 '07 #15
psbasha
440 256MB
How to differentiate the Class variables/Methods?.Whether we have to use the same variable names as ordinary variable names.

Private:
Protected:
Public:


Thanks in advance
PSB
Feb 25 '07 #16
bartonc
6,596 Expert 4TB
Quoting from http://www.python.org/doc/essays/styleguide/#names

Method Names
Hmm, the story is largely the same as for functions. When using ILU, here's a good convention: use CapWords for methods published via an ILU interface. Use lowercase for methods accessed by other classes or functions that are part of the implementation of an object type. Use one leading underscore for "internal" methods and instance variables when there is no chance of a conflict with subclass or superclass attributes or when a subclass might actually need access to them. Use two leading underscores (class-private names, enforced by Python 1.4) in those cases where it is important that only the current class accesses an attribute. (But realize that Python contains enough loopholes so that an insistent user could gain access nevertheless, e.g. via the __dict__ attribute. Only ILU or Python's restricted mode will XXX
Feb 25 '07 #17
psbasha
440 256MB
Quoting from http://www.python.org/doc/essays/styleguide/#names

Method Names
Hmm, the story is largely the same as for functions. When using ILU, here's a good convention: use CapWords for methods published via an ILU interface. Use lowercase for methods accessed by other classes or functions that are part of the implementation of an object type. Use one leading underscore for "internal" methods and instance variables when there is no chance of a conflict with subclass or superclass attributes or when a subclass might actually need access to them. Use two leading underscores (class-private names, enforced by Python 1.4) in those cases where it is important that only the current class accesses an attribute. (But realize that Python contains enough loopholes so that an insistent user could gain access nevertheless, e.g. via the __dict__ attribute. Only ILU or Python's restricted mode will XXX
What is this ILU stands for ?
Feb 28 '07 #18
bartonc
6,596 Expert 4TB
What is this ILU stands for ?
Check it out here.
Mar 2 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Cristof Falk | last post by:
I wanted to get a feel. The documentation gives naming conventions for public/protected members. Is this truly widely adopted? And what about using the same conventions for private members and...
7
by: cmiddlebrook | last post by:
Hi there, I keep finding myself getting inconsistent with naming conventions for things like member variables, class names etc and I just want to find something that suits me and stick to it. I...
1
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
3
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
5
by: rastaman | last post by:
Hi all, I know of the existence of Object Naming Conventions for Visual Basic 6. Now I'm reading some books about VB .NET, but the names used for the objects are button1, picturebox1, etc. I...
4
by: Patrick | last post by:
what are the general naming conventions for vb.net controls. esp txtUserName, lblPassword, btnSubmit What are the prefixes for the controls???? I've tried to search hi and low on the net, but...
9
by: kevininstructor | last post by:
Greetings, I am in the process of creating naming conventions for VB.NET controls i.e. CheckBox -> chkShowThisOnStartup ListBoxt -> lstSomeList What I am looking for other developers...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
1
by: Philipp Post | last post by:
Marcello, Not a big surprise as naming conventions have a lot to do with personal prefernces. There are a lot of threads in comp.databases and the other database groups. Just do a search for...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.