Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae56186

Browse files
committed
recover gh-pages
1 parent 5f892a0 commit ae56186

File tree

11 files changed

+42
-597
lines changed

11 files changed

+42
-597
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_site
2+
.sass-cache
3+
.jekyll-metadata
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
layout: post
3+
title: "[Python] namedtuple"
4+
date: 2018-07-03 14:30:00 +0800
5+
author: Zhang Yu
6+
categories: python
7+
tags: python
8+
---
9+
10+
```python
11+
collections.namedtuple(typename, field_names, *, verbos=False, rename=False, module=False)
12+
```
13+
14+
`verbos: added in 3.1, rename, module: added in 3.6`
15+
16+
example:
17+
```python
18+
Point = namedtuple('Point', ['x', 'y'])
19+
p = Point(11, y=22)
20+
```
21+
22+
23+
**Named tuple are especially useful for assigning field names to result tuples returned by the csv or sqlite3 modules:**
24+
```python
25+
EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade')
26+
27+
import csv
28+
for emp in map(EmployeeRecord._make, csv.reader(open('employees.csv', 'rb'))):
29+
pirint(emp.name, emp.title)
30+
31+
import sqlite3
32+
conn = sqlite3.connect('/companydata')
33+
cursor = conn.cursor()
34+
cursor.execute("SELECT name, age, title, department, paygrade FROM employees')
35+
for emp in map(EmployeeRecord._make, cursor.fetchall()):
36+
print(emp.name, emp.title)
37+
```
38+
39+
`classmethod somenamedtuple._make(iterable)`

_site/assets/css/style.css

Lines changed: 0 additions & 105 deletions
This file was deleted.

_site/assets/images/bkg.png

-1.19 KB
Binary file not shown.

_site/assets/images/blacktocat.png

-268 Bytes
Binary file not shown.

_site/assets/images/bullet.png

-603 Bytes
Binary file not shown.

_site/environment/ubuntu/2018/07/02/Ubuntu_Set_Up.html

Lines changed: 0 additions & 63 deletions
This file was deleted.

_site/index.html

Lines changed: 0 additions & 59 deletions
This file was deleted.

_site/index.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

_site/stylesheets/github-dark.css

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)