Linked Questions
17 questions linked to/from Defining private module functions in python
1
vote
2
answers
4k
views
How do you correctly use private functions in Python? [duplicate]
I'm new to Python and I'm facing some issues when it comes to private functions. I want to call two of them inside a public method, just for the sake of making the code look clear, but I cannot ...
1
vote
2
answers
3k
views
Is there a way to disable some function in python class so that it cannot be used except using it in inside its class? [duplicate]
for example i have myClassFile.py file with code as follow:
class myClass:
def first(self):
return 'tea'
def second(self):
print(f'drink {self.first()}')
then i have run.py ...
1
vote
1
answer
2k
views
How to allow python file to export specific functions that can be imported later? [duplicate]
Suppose I have 2 functions and one global variable in a python file. How do I allow to export only one function?
g = 47
def A():
print('a')
def B():
print('b')
Suppose the above file is ...
0
votes
1
answer
985
views
how to not expose methods in python [duplicate]
how can we not expose methods in Python and make them private as in Java?
specifically, my scenario involves functions that the user should not be using.
1
vote
0
answers
173
views
How to create a non-callable method from class? [duplicate]
I have a class which has two methods(m_1 and m_2). The method m_1 makes a call to method m_2. Now i want to make sure that only m_1 can be called using a class insance and not m_2. How can i do that ?
...
0
votes
0
answers
104
views
Function visible to the module classes but not outside [duplicate]
I have various class in a module that execute some operation.
Since all of them require to connect to a remote server to execute these operation, I thought that is not convenient to have a ton of ...
1788
votes
10
answers
724k
views
What does __all__ mean in Python?
I see __all__ in __init__.py files. What does it do?
855
votes
12
answers
619k
views
Why are Python's 'private' methods not actually private?
Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like this: __myPrivateMethod(). How, then, can one explain this
>&...
18
votes
5
answers
8k
views
Is it legal to redefine a C++ keyword?
In this article from Guru of the week, it is said: It is illegal to #define a reserved word. Is this true? I can’t find anything in the norm, and I have already seen programmers redefining new, for ...
4
votes
4
answers
3k
views
Python code/function layout
I am learning Python and am trying to figure out the best way to structure my code.
Lets say I have a long function, and want to break it up into smaller functions. In C, I would make it a 'static' ...
7
votes
1
answer
1k
views
Python import statements in complex package structures?
Consider the following hierarchy of three regular packages and their
contents:
quick
├── brown
│ ├── fox.py
│ └── __init__.py
├── lazy
│ ├── dog.py
│ └── __init__.py
└── __init__.py
Now ...
0
votes
1
answer
2k
views
How to avoid importing module private functions?
I am asking about module privates, not class privates.
Suggested in here, a module private starts with one underscore, such a element is not copied along when using the from <module_name> import ...
1
vote
1
answer
905
views
How to make a method ONLY accessible by other methods of same class and not outer world [in python]? [duplicate]
I have a class definition with two methods defined in it.
The layout somewhat looks like below:
class Sample:
def calling-Method(self):
print "Hi"
calledMethod()
def called-...
0
votes
1
answer
454
views
Python: How to define variables in global space without defining them as globals
I am declaring a global list, and as part of the list element definition, I need to reference some obscure data from other modules. I would like to declare some simple short-hand references to these ...
1
vote
1
answer
120
views
Looking for a way to count the number of XML element appearances up to a certain point
I am new to python and xml, so maybe I'm not using the correct terms to find what I need but I looked around for a while on stackoverflow, and also tried reading the documentation for dom and mini-dom,...