Skip to content

Commit c33dd60

Browse files
committed
Merge pull request Show-Me-the-Code#15 from effyhuihui/master
Minor changes for task 0003, added markdown.
2 parents 562d0d0 + b122b56 commit c33dd60

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

effy/0000/pillow_chesnut.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
>___,<
99
'''
1010
from PIL import Image, ImageDraw
11+
import os
1112
# open the base pic
12-
minion = Image.open("Your_Working_Directory_Path/python/effy/0000/zizi.gif").convert('RGBA')
13+
minion = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)),"zizi.gif")).convert('RGBA')
1314
# new a transparent canvas for the annoying number :)
1415
annoying = Image.new('RGBA', minion.size, (255, 255, 255, 0))
1516
# get the drawing context , note that ImageDraw is the actionable module that will CREATE canvas on the base pic

effy/0003/readme.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
##mongoDB connect with python
2+
3+
###Pre-request:
4+
1. Has mongo installed and running.
5+
2. Has pymongo instaled with pip
6+
7+
###To connect
8+
```python
9+
from pymongo import MongoClient
10+
c = MongoClient()
11+
```
12+
That's it! dead simple -- but you may need to make sure that mongo is **running on the default port-- 27017**
13+
14+
python和mongo的连接出乎意料的简单。
15+
16+
需要的只是一个pymongo中的MongoClient来建立一个live connection!而且最赞的是,由于是nosql,根本不需考虑collection已有的数据是什么类型,key,schema什么的,直接统统insert。之前和relational sql连接的时候(postgres)则需要考虑原来的table里面的PK有没有重复,id是否要被maintain成incremental,之类的问题~炒鸡方便!
17+
18+
### To manipulate mongodb within python
19+
1. to access specific database
20+
21+
```python
22+
db = c['effy_db']
23+
```
24+
2. to access specific collection
25+
26+
```python
27+
cl = db['effy_collection']
28+
```
29+
db, collection acts like a **dict** in python! it actually is. When a live connection is established, *database object* becomes a dictionary with key equals to its name and value equals the object itself.
30+
31+
To access mongo shell command for absolute beginners, see <a href=http://effyhuang.com/2014/12/06/mongo-db-command-ref/> the blog</a>.

effy/0003/readme.txt

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

effy/0004/0004_bad.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
it won't split abbrevations, like "I'd", nor it won't split words
77
concatenated with underscore, like "bad_game"
88
'''
9+
import os
910
import re
1011
def word_count(file_path):
1112
word_dict = {}
@@ -22,7 +23,7 @@ def word_count(file_path):
2223
word_dict[word] = word_dict.get(word,0) + 1
2324
return word_dict
2425

25-
result = word_count("Your_Working_Directory_Path/python/effy/0004/readme.txt")
26+
result = word_count(os.path.join(os.path.dirname(os.path.abspath(__file__)), "sampletext.txt"))
2627

2728
###################################################################################
2829

0 commit comments

Comments
 (0)