Function name limit in Python ?

Paul McGuire ptmcg at austin.rr.com
Sat Feb 14 10:13:42 EST 2009


On Feb 14, 8:45 am, Linuxguy123 <linuxguy... at gmail.com> wrote:
> Excuse my ignorance, but is there a limit to the size of function names
> in Python ?
>
> I named a function getSynclientVersion() and I got an error when I
> called it.  I renamed the same function to getSCVersion() and it called
> fine.
>
> Why ?
>

Hello again, Linuxguy123!  I see you are forging ahead in your quest
for Python knowledge.

Here is a small snippet that refutes your assertion that function name
length is a problem (but surely, you could have written this small a
test and answered your own question...):

def getSynclientVersion():
    return "1.2.3.4"

print getSynclientVersion()

prints:
1.2.3.4

Let's try something a bit longer:
def
abcdefghijklmnopqrstuvwxyz_1234567890_abcdefghijklmnopqrstuvwxyz_1234567890
():
    return "Howdy!"

print
abcdefghijklmnopqrstuvwxyz_1234567890_abcdefghijklmnopqrstuvwxyz_1234567890
()

prints:
Howdy!

So I don't think the problem you are having is the length of your
method name.

Your quest will be much more productive if, in the future, you post a
little more information with these questions:

- Post the code that you wrote - this is trickier than it sounds.  The
best post is the smallest possible extract of your code that
reproduces the error in question.

But please, DONT try to send in fresh code that you feel represents
your problem without first verifying that it does.  Many people post a
summary of their code because they don't want to post their secret
source code, or their 3000 lines of code - and then in their summary,
they fix the problem they were having.  Then c.l.py readers spend a
lot of time going "wha...?" because the posted code has no error.

- Post the exception that was returned

Probably even more helpful than posting code.  What exactly was the
problem?  Python is not really that bad at giving some informative
messages.  Perhaps you misspelled your method name:

print getSynClientVersion()

gives this error:
NameError: name 'getSynClientVersion' is not defined

It's not defined because I named it "getSynclientVersion" - with a
little 'c', not a big 'C'.

Or maybe you misused the value returned from the method:

print getSynclientVersion().length

gives:

AttributeError: 'str' object has no attribute 'length'

An error, surely, but it has nothing to do with the length of the
method name I called.


Help us help you, Linuxguy123!
-- Paul



More information about the Python-list mailing list