Study from Python official website
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
Glossaries
-
Todo: study
descriptor
. Understanding descriptors is a key to a deep understanding of Python because they are the basis for many features including functions, methods, properties, class methods, static methods, and reference to super classes. -
Metaclass: The class of a class. Class definitions create a class name, a class dictionary, and a list of base classes.
What is a class dictionary
?
-
Packages
are a way of structuring Python’s module namespace by using “dotted module names”. -
function parameters: ```python def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2): pass # ———– ———- ———- # | | | # | Positional or keyword | # | - Keyword only # – Positional only
def cheeseshop(kind, arguments, **keywords): matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ] list(zip(matrix)) # [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
* `list` can be used for `stack` or `queue`, but for `queue`, `pop(0)` is not efficient, so there is a `collections.deque` there for `queue`.
`deque.popleft()` and `deque.appendleft()` are for the purpose. `deque` may mean double-end queue.
* `modules` are files with functions defined in them.
* Without `__init__.py`, modules would not become packages. Packages are for importing purpose and used with `dotted`. like `sys.xxx`.
* A file could be a `module` or a `package`.
* importing a package, the code inside package `__init__()` will only be executed once.
```python
bugs = 'roaches'
count = 13
area = 'living room'
print(f'Debugging {bugs=} {count=} {area=}')
# Debugging bugs='roaches' count=13 area='living room'
- The
str.rjust()
method of string objects right-justifies a string in a field of a given width by padding it with spaces on the left. f = open('workfile', 'w', encoding="utf-8")
,modes
likew
iswrite
,r
isread
(default),a
isappend
.modes
default istext
file, appendb
isbinary
file
with open('workfile', encoding="utf-8") as f:
read_data = f.read()
# This is good practice since f is closed automatically.
# f.closed # test it, it returns True
with open('workfile', 'w', encoding="utf-8") as f:
f.write('You are awesome.')
Counter
```python from collections import Counter note1 = ‘aabbbbc’ c1 = Counter(note1) # Counter({‘b’: 4, ‘a’: 2, ‘c’: 1}) note2 = ‘ab’ c2 = Counter(note2) # Counter({‘b’: 1, ‘a’: 1}) c1 - c2 # Counter({‘b’: 3, ‘a’: 1, ‘c’: 1})
h1 = {‘b’: 3, ‘a’: 1, ‘c’: 1} h2 = {‘b’: 2, ‘c’: 1} Counter(h1) - Counter(h2) # Counter({‘b’: 1, ‘a’: 1})
* `JSON`
```python
import json
x = [1, 'simple', 'list']
k = json.dumps(x) # '[1, "simple", "list"]'
l = json.loads(k) # return list equals to `x`