mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
Add note
This commit is contained in:
parent
a85dd823a0
commit
fb833a6592
@ -4,7 +4,7 @@ tags:
|
||||
- basic
|
||||
- coding-language
|
||||
- MOC
|
||||
date: 2024-03-13
|
||||
date: 2024-03-18
|
||||
---
|
||||
|
||||
# Python
|
||||
@ -15,6 +15,8 @@ date: 2024-03-13
|
||||
* [Assert in Python](computer_sci/coding_knowledge/python/assert_in_python.md)
|
||||
* [Package in Python](computer_sci/coding_knowledge/python/package_in_python.md)
|
||||
* [Python Namespace Pollution](computer_sci/coding_knowledge/python/python_namespace_pollution.md)
|
||||
* [About Private and Public, Python as example](computer_sci/coding_knowledge/python/about_private_and_public.md)
|
||||
* [Python Import for different level folders](computer_sci/coding_knowledge/python/python_import_different_folder.md)
|
||||
# HTML
|
||||
|
||||
* [HTML Double Curly Braces](computer_sci/coding_knowledge/web/html_double_curly_braces.md)
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
---
|
||||
title: About Private and Public, Python as Example
|
||||
tags:
|
||||
- python
|
||||
- coding-language
|
||||
date: 2024-03-18
|
||||
---
|
||||
|
||||
# A good answer
|
||||
|
||||
In Python, "privacy" depends on "consenting adults'" levels of agreement - you can't _force_ it. A single leading underscore means you're not **supposed** to access it "from the outside" -- **two** leading underscores (w/o trailing underscores) carry the message even more forcefully... but, in the end, it still depends on social convention and consensus: Python's introspection is forceful enough that you can't **handcuff** every other programmer in the world to respect your wishes.
|
||||
|
||||
((Btw, though it's a closely held secret, much the same holds for C++: with most compilers, a simple `#define private public` line before `#include`ing your `.h` file is all it takes for wily coders to make hash of your "privacy"...!-))
|
||||
|
||||
# Reference
|
||||
|
||||
* https://stackoverflow.com/questions/1547145/defining-private-module-functions-in-python
|
||||
@ -0,0 +1,59 @@
|
||||
---
|
||||
title: Python import 异级目录
|
||||
tags:
|
||||
- python
|
||||
date: 2024-03-18
|
||||
---
|
||||
|
||||
# Learn by Example
|
||||
|
||||
## 主程序和模块程序在同一目录下
|
||||
|
||||
```python
|
||||
'''
|
||||
-- src
|
||||
|-- mod1.py
|
||||
|-- main.py
|
||||
'''
|
||||
|
||||
import mod1
|
||||
from mod1 import *
|
||||
```
|
||||
|
||||
## 模块程序在父辈目录
|
||||
|
||||
```python
|
||||
'''
|
||||
-- src
|
||||
|-- mod1
|
||||
|-- __init__.py
|
||||
|-- mod1.py
|
||||
|-- main.py
|
||||
'''
|
||||
|
||||
import mod1.mod1
|
||||
from mod1 import mod1
|
||||
```
|
||||
|
||||
|
||||
## 其他目录下的模块
|
||||
|
||||
```python
|
||||
'''
|
||||
-- src
|
||||
|-- mod1
|
||||
|-- __init__.py
|
||||
|-- mod1.py
|
||||
|-- sub
|
||||
|-- main.py
|
||||
'''
|
||||
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
import mod1.mod1
|
||||
```
|
||||
|
||||
|
||||
# Reference
|
||||
|
||||
* https://blog.csdn.net/vitaminc4/article/details/78134508
|
||||
Loading…
Reference in New Issue
Block a user