Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1061719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:30:54+00:00 2026-05-16T18:30:54+00:00

I have a module that looks something like this: def __myFunc(): … class MyClass(object):

  • 0

I have a module that looks something like this:

def __myFunc():
    ...

class MyClass(object):
    def __init__(self):
        self.myVar = __myFunc()

and I get the error:

NameError: global name '_MyClass__myFunc' is not defined

How can I call this function from inside the class?

edit: Since posting this, I’ve discovered I can avoid the automatic mangling by using a single underscore instead of double underscores. I was using two as per “Dive Into Python”, which only states a double underscore denotes private functions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:30:55+00:00Added an answer on May 16, 2026 at 6:30 pm

    That is because Python’s compiler replaces method calls (and attribute accesses) inside classes if the name begins with two underscores. Seems like this also applies to functions. A call to a method self.__X would be replaced by self._ClassName__X, for example. This makes it possible to have pseudo-private attributes and methods.

    There is absolutely no reason to use two underscores for functions inside the module. Programmers often follow the convention of putting one underscore in front of the function name if the function shouldn’t be called from outside.

    Using two underscores is only necessary for attributes/methods in classes if you don’t want them to be overwritten by subclasses, for example. But there are few cases in which that is useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Intereting, I think Rails need a patch for this. I… May 16, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer Use source control instead incron can monitor the filesystem and… May 16, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer layoutIfNeeded forces the receiver to layout its subviews immediately if… May 16, 2026 at 11:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a package of plug-in style modules. It looks like this: /Plugins /Plugins/__init__.py
I have a function that looks like the following, with a whole lot of
I have a package that has several components in it that would benefit greatly
I'm hoping to implement something like all of the great plugins out there for
So I have a CSV that contains a filename and a file's contents. The
This is the second time I have got confusing results from the modulo operator,
I have a MEF's CompositionContainer, a contract (say IFoo) and a module (Prism module
I'm having trouble replacing a function from a different module with another function and
I currently have a Python application where newline-terminated ASCII strings are being transmitted to
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.