python re.sub

sub(pattern, repl, string, count=0, flags=0)
    Return the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in string by the
    replacement repl.  repl can be either a string or a callable;
    if a string, backslash escapes ...
more ...

python const

  • python 没有const 这样的语法,但是在项目中可能会有这样的需求?
  • 自己动手丰衣足食!!!

const.py

  • 首先创建一个const.py文件,代码如下
# -*- coding: UTF-8 -*-

'''
Last modified time: 2015-06-09 09:49:29
Edit time: 2015-06-09 09:55:07
File name: const.py
Edit by caimaoy
'''

__author__ = 'caimaoy'

class _const(object):
    class ConstError(TypeError): pass
    class ConstCaseError(TypeError): pass

    def __setattr__(self, name, value ...
more ...

python split

str.split

Help on method_descriptor:

split(...)
    S.split([sep [,maxsplit]]) -> list of strings

    Return a list of the words in the string S, using sep as the
    delimiter string.  If maxsplit is given, at most maxsplit
    splits are done. If sep is not specified or is None, any
    whitespace string ...
more ...

VIM 去掉重复行

不难理解的方法

  • 先想想思路:
    • 先排序
    • 然后去掉重复的行
  • 看看具体命令
:sort u
g/^\(.*\)\n\1$/d

下面讲解一下:

:sort u             <-- 排序
g/^\(.*\)\n\1$/d    <-- kjkj
g/            /d    <-- g命令delete 满足要求的行
  ^\(.*\)\n         <-- 一行的开始到换行
           \1$      <-- \1 是前面(.*\)的内容,也就是说和前面的行内容相等
             $      <-- 结束符,两行相等是匹配条件

一些高级vim语法的操作

参考博文

  • 先看一下命令
g/\%(^\1\n\)\@<=\(.*\)$/d
g/\v%(^\1\n)@<=(.*)$/d

看一下原本博客中的解释

g/\%(^\1\n\)\@<=\(.*\)$/d ...
more ...

pyinstaller生成exe中文路径无法运行解决方案

pyinstaller生成的exe中文路径不能运行,错误信息如下:

D:\测试>"D:\测试\caimaoy_tool.exe"
Traceback (most recent call last):
  File "<string>", line 21, in <module>
  File "D:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line
 507, in install
  File "D:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line
 156, in __init__
ImportError: Can't load frozen ...
more ...

PyQt 创建新窗口

PyQt 如何新建一个窗口

# -*- coding: UTF-8 -*-

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *


class mainWindow(QWidget):
    def __init__(self, parent=None):
        super(mainWindow, self).__init__(parent)
        button = QPushButton(u'弹出新窗口', self)
        self.slavewindow = slaveWindow()
        self.connect(button, SIGNAL('clicked()'), self.slavewindow.show)


class slaveWindow(QWidget):
    def __init__(self, parent ...
more ...

pelican 如何添加404页面

pelican 已经挂在了github上面了但是如何挂上一个404 页面

Title: Not Found
Status: hidden
Save_as: 404.html

<script type="text/javascript" src="http://www.qq.com/404/search_children.js" charset="utf-8" homePageUrl="http://www.caimaoy.com" homePageName="Back to Home Page"></script>

源码里面要说的几点

  • 添加Status: hidden这个元信息
  • Save_as为404.html,这样的话就满足了github的要求
  • 挂上这一段js,出自我旁边的鹅厂这样的事业还是要支持一下的
  • 最后看一看:效果图

TODO

  • 当然也是因为我没有找到pelican直接挂原始页面的办法 ...
more ...