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

  • SEARCH
  • Home
  • 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 7824303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:33:16+00:00 2026-06-02T08:33:16+00:00

def __f(): print 1 def _f(): print 1 I tried import and it’s accessible:

  • 0
def __f():
  print 1

def _f():
  print 1

I tried import and it’s accessible:

>>> import test1
>>> test1._f()
1

Does it mean anything? I want to write some helper functions which aren’t class-based. Then I want to hide certain low-level, concrete functions, and leaving only high-level function (view them as APIs) accessible to users to use.

For example:

test1.copy() will call another helper function in the same file which does some extra checking, but I don’t want to expose that to user.

  • 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-06-02T08:33:19+00:00Added an answer on June 2, 2026 at 8:33 am

    The single leading underscore is a Python naming convention. A number of tools rely on that convention. For example help() will ignore single underscored names. Using from somemodule import * will also ignore single underscored names.

    The double leading underscore triggers name mangling (prefixing the name with the class name and a single leading underscore). It is used to create thread-local references. That allows intra-class calls that won’t be accidentally broken by a subclass. There is a nice example of this in the tutorial at http://docs.python.org/tutorial/classes.html#private-variables .

    Lastly, there is the special method naming convention of two leading underscores and two trailing underscores. Those names are used by the interpreter to implement operators and to implement a number of standard protocols (i.e. iterators, context managers, pickling, etc). See http://www.rafekettler.com/magicmethods.html for a nice write-up on the special methods.

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

Sidebar

Related Questions

I implemented a simple state machine in Python: import time def a(): print a()
def log(func): def wraper(*a, **kw): return func(*a, **kw) return wraper @log def f(): print
I am trying to figure out this: c = 1 def f(n): print c
I had a version 1 of a function like: def f(a,b,c): #Some processing return
for this, import os.path def f(data_file_path=os.path.join(os.getcwd(),'temp'),type): ... return data I get this, SyntaxError: non-default
I thought that doing @f def g(): print 'hello' is exactly the same as
So I have the code: def logdata(x, y): try: f = open('multlog.txt', 'a') f.write({0:g}
I want to pass something similar to a member function pointer. I tried the
def getSize(f): print StringIO(f) im = Image.open(StringIO(f)) size = im.size[0], im.size[1] return size def
When I do the following: class C: pass def f( self ): print self

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.