from SF动漫资讯
近日,漫画家甲斐谷忍先生通过其个人推特帐号表示,其漫画著作《LIAR GAME》即将连载再开。尽管日期尚未确定,但已经让各位粉丝翘首以盼,网上众多粉丝通过推特表示支持及期待,可见该作品人气之高。
《LIAR GAME》从2005年开始在漫画杂志周刊《YOUNG JUMP》上不定期连载,至今已经发售十六卷单行本,系列销售量突破五百万部。故事正如标题所言,主要讲述骗与被骗的故事,作品通过一场“欺诈游戏淘汰赛”着重从心理学和谈判手段的角度描写人性的黑暗面。该作品还曾经在日本富士电视台上两度改编为电视连续剧,电视剧男女主角分别由男星松田翔太及女星户田惠梨香饰演。不仅如此,还于2010年和2012年两度被搬上电影大荧幕,收视、票房、人气俱佳。
169话在13年2月出的,过了一两个月我发现Liar Game并且看完了169话。当时还以为不会重开连载要像猎人一样坑掉了呢,总之能重开连载实在太好了!
对于没有看过《欺诈游戏》的人,我强烈推荐去看,绝对不会后悔。这是一部适合所有人,尤其是智商较高喜欢思考的人的漫画。
NOTE: After writing this article several months ago, I gradually realized that despite this solution works, it is error-prone, and too verbose. I'll write a new article explaing how I deal with it now.
When I started wirting my blog, one thing that confused me is different versions of settings.py
. As we know, different settings.py
should be kept for developement and deployment, however when it comes to using Git, things get messy. The main difficulties lies on two things:
- Should I upload
settings.py
from developement environment to Git server? If I did, does that mean I have to change the file every time after doing Git pull
on deployment server?
- If I choose not to upload
settings.py
, there is a risk of losing data.
My purpose is to keep different versions of settings.py
. Here's what I did:
- First, on the computer I do developing,
commit
and push
everything as you normally do, including settings.py
.
- Create a new branch called
deploy
on Github.
- Then, on deployment server,
git pull
from branch master
.
- checkout
deploy
branch, Modify settings.py
for deployment, e.g. set DEBUG=False
, change MEDIA_ROOT
, STATIC_ROOT
, etc. The ONLY file you should change is settings.py
, DO NOT TOUCH OTHER FILES !
commit
and push
to branch deploy
.
- Back to developing environment, type this command:
bash
git update-index --assume-unchanged my_blog/settings.py
Done :)
The key part is step 5. First you should understand what git update-index --assume-unchanged
is doing, basically it assumes that the file does not change. From git-scm:
--[no-]assume-unchanged
When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, Git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
So next time you commit
your work, though settings.py
may has been changed, those changes won't get uploaded to Git server, which means there is no confict when you pull
from master branch on deployment server no matter how many times your settings.py
has been edited there. You could also achieve this by adding my_blog/settings.py
to .git/info/exclude
.
Finally, workflow is like this:
Coding, Push to master
—> On deployment server, pull from master
Edit settings.py
on deployment server (if needed) —> Push to deploy
Be careful, NEVER push to branch master
from deployment server.
Now you've pushed some new commits to Github and want to apply it on your server. Here are the steps:
# step 1
make sure you're on master branch, if not, git checkout master
# step 2
$ git pull
# step 3
$ git checkout deploy
# step 4
$ git rebase master
# step 5
$ git push origin deploy
I'm open to changes and suggestions, if you have better ideas, feel free to comment.
用途
1. 多个文件作为输入, 遍历文件每一行
2. 在原处修改文件
用途1
如果我们有如下的文件夹结构:
test/
|_____ 1.txt content:
| 1_line1
| 1_line2
|_____ 2.txt content:
| 2_line1
| 2_line2
|_____ test_fileinput.py
import fileinput
import sys
for line in fileinput.input(sys.argv[1:]):
print(fileinput.filename(), fileinput.filelineno(), line)
在 Linux 下执行
$ python test_fileinput.py *.txt
输出
1_line1
1_line2
2_line1
2_line2
在Windows下直接用*.txt, 系统不认
所以修改成
import glob
all_files = [f for files in sys.argv[1:] for f in glob(files)]
for line in fileinput.input(all_files):
print(fileinput.filename(), fileinput.filelineno(), line)
这样兼容Linux/Windows, 两种形式 *.txt
和 1.txt 2.txt
都可以作为输入。
总之最后提供一个 filelist 给 input 就行。也可以这样:
甚至并不一定是多个文件, 也可以是多个文件的内容, 例如
$ cat *.py | python fileinput_grep.py fileinput
也能正常工作, 会遍历"所有.py文件的每一行"。以上的用法对单个文件/文件内容也同样适用。
用途2: 在原处(inplace)修改文件
for line in fileinput.input('file.txt', inplace=True):
line = ... # edit line
print line, # stdout is redirected to the file
Note:
fileinput 能够提供很多元数据信息, 例如上面看到的fileinput.filename()
, fileinput.filelineno()
,还有fileinput.isfirstline()
, fileinput.isstdin()
等, 更多内容参考官方文档
fileinput 支持 context manager
例如在原处修改文件最好写成
with fileinput.input('file.txt', inplace=True) as f:
for line in f:
...
否则最后还得调用 fileinput.close()
一个常见的任务是,如果某一行满足某个条件,那么修改/删除这一行。这时候不要忘记原样输出别的行!
如果单纯地print
会多出一些空白行,这是因为print
的时候末尾自带一个换行符。解决方法有两种
(1) Python2.X
去掉末尾的换行,strip
默认删除空白符(包括'\n', '\r', '\t', ' ')
(2) Python3.X
print()
函数有个参数是end
,代表以什么结尾,默认是\n
,我们用空字符做结尾