Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum length for an attribute name in python?

I'm writing a set of python functions that perform some sort of conformance checking on a source code project. I'd like to specify quite verbose names for these functions, e.g.: check_5_theVersionOfAllVPropsMatchesTheVersionOfTheAutolinkHeader()

Could such excessively long names be a problem for python? Is there a maximum length for attribute names?

like image 943
Alexander Tobias Bockstaller Avatar asked Jun 04 '13 14:06

Alexander Tobias Bockstaller


People also ask

What is the maximum possible length of an attribute in Python?

Answer: An identifier can have a maximum length of 79 characters in Python. Python is one of the most popular programming languages. Guido van Rossum created it, and it was released in 1991.

What is the length of variable name in Python?

Officially, variable names in Python can be any length and can consist of uppercase and lowercase letters ( A-Z , a-z ), digits ( 0-9 ), and the underscore character ( _ ). An additional restriction is that, although a variable name can contain digits, the first character of a variable name cannot be a digit.

Is there a limit to variable name length?

There's no set length which can be said to be the ideal length for a variable name (in Java or in any other language, pretty much).

Is there a limit to the length of a string in Python?

Python strings are length-prefixed, so their length is limited by the size of the integer holding their length and the amount of memory available on your system.


2 Answers

2.3. Identifiers and keywords from The Python Language Reference:

Identifiers are unlimited in length.


But you'll be violating PEP-8 most likely, which is not really cool:

Limit all lines to a maximum of 79 characters.

Also you'll be violating PEP-20 (the Zen of Python):

Readability counts.

like image 69
kirelagin Avatar answered Sep 20 '22 17:09

kirelagin


They could be a problem for the programmer. Keep the function names reasonably short, and use docstrings to document them.

like image 22
Ignacio Vazquez-Abrams Avatar answered Sep 21 '22 17:09

Ignacio Vazquez-Abrams