小编it_*_*ure的帖子

使用非默认密钥名称(id_rsa除外)

我已将Github无密码登录设置如下.

ssh-keygen -t rsa  -P ''  
cat .ssh/id_rsa.pub  |xclip 
Run Code Online (Sandbox Code Playgroud)

我将公钥粘贴到Github网站上的ssh和gpg密钥中.

git init  
git config --global user.name "someone"  
git config --global user.email  "sbd@gmail.com"  
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git  
ssh -T git@github.com  
git clone  git+ssh://git@github.com/someone/newstart.git   /tmp/newstart
Run Code Online (Sandbox Code Playgroud)

以上工作.

现在我想为Github使用不同的键名,而不是默认名称id_rsa.

ssh-keygen -t rsa  -P ''  -f  .ssh/id_rsa.github
cat .ssh/id_rsa.github.pub  |xclip 
Run Code Online (Sandbox Code Playgroud)

我将新的pub密钥粘贴到Github网站上的ssh和gpg密钥中.

git init  
git config --global user.name "someone"  
git config --global user.email  "sbd@gmail.com"  
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git  
ssh -T git@github.com 
Run Code Online (Sandbox Code Playgroud)

以上不起作用.

git clone  git+ssh://git@github.com/someone/newstart.git   /tmp/newstart
Run Code Online (Sandbox Code Playgroud)

以上也行不通.

ssh -i .ssh/id_rsa.github …
Run Code Online (Sandbox Code Playgroud)

git ssh github

8
推荐指数
1
解决办法
1269
查看次数

为什么在为python调用标记完成时弹出tcl和c中的关键字?

环境现状:debian8 + vim8.
filetype在.vimrc和vim/runtime/ftplugin/python.vim中都处于启用状态.

cat   .vimrc
execute pathogen#infect()
execute pathogen#helptags()
syntax on
filetype plugin indent on

cat vim/runtime/ftplugin/python.vim
setlocal omnifunc=pythoncomplete#Complete
filetype plugin indent on
"other lines omitted.
Run Code Online (Sandbox Code Playgroud)

有些问题困惑我.
1.on omni completion
1.1模块中
的类名可以完成模块中的类或方法.
在此输入图像描述

1.2内置函数名称

import sys
for key,value in enum
Run Code Online (Sandbox Code Playgroud)

要按ctrlxctrlo,没有enumerate弹出,为什么内置函数名称无法完成ctrlxctrlo

2.tag完成
没有为python文件准备的标记文件,没有ctags -R *为任何python文件执行.
vim从什么时候开始ctrlxctrl]编辑这些关键字test.py

要输入filtest.py并调用omni completion with ctrlxctrlo,不会弹出omni completion菜单.
要输入fil …

python tags vim autocomplete tcl

8
推荐指数
1
解决办法
189
查看次数

如何在lxml中处理编码以正确解析html-string?

我有一个xml文件.请下载并保存为blog.xml.这是我在Google-blogger中的文件列表,我写了一些代码来解析它,有一些东西拧成了lxml.

代码1:

from stripogram import html2text
import feedparser
d = feedparser.parse('blog.xml')
for num,entry in enumerate(d.entries):
    string=entry.content[0]['value'].encode("utf-8")
    print   html2text(string)
Run Code Online (Sandbox Code Playgroud)

它使用code1获得正确的结果.

码2:

import lxml.html
import feedparser
d = feedparser.parse('blog.xml')
for num,entry in enumerate(d.entries):
    string=entry.content[0]['value'] 
    myhtml=lxml.html.document_fromstring(string)
    print  myhtml.text_content()
Run Code Online (Sandbox Code Playgroud)

它使用code2得到错误的输出.

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/lib/python2.7/dist-packages/lxml/html/__init__.py", line 532, in document_fromstring
    value = etree.fromstring(html, parser, **kw)
  File "lxml.etree.pyx", line 2754, in lxml.etree.fromstring (src/lxml/lxml.etree.c:54631)
  File "parser.pxi", line 1569, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:82659)
 ValueError: Unicode strings with …
Run Code Online (Sandbox Code Playgroud)

python lxml

7
推荐指数
1
解决办法
5057
查看次数

如何在vim for xp中将字体设置为DejaVu Sans Mono?

我已经为xp安装了vim,_vimrc在C:\ Vim中有一个文件,我已经设置了字体_vimrc:

set guifont=Bitstream_Vera_Sans_Mono:h11:cANSI
Run Code Online (Sandbox Code Playgroud)

当我打开vim时,设置无法正常工作,当我打开gvim时,设置可以正常工作.有什么事?我在_vimrc中编写的配置在我打开它时可以在gvim中完美地工作,为什么它不能在vim中工作?在我的gvim和cmd中,我可以在屏幕上看到Bitstream_Vera_Sans_Mono字体,而我的活动控制台代码页设置为437,vim不能使用Bitstream_Vera_Sans_Mono字体,为什么?

vim

7
推荐指数
1
解决办法
3328
查看次数

如何在UTF-8编码文件中写入和读取可打印的ASCII字符?

我想写与包含字符UTF-8编码文件 10001100Œ拉丁资本结扎OE在扩展ASCII表,

zz <- file("c:/testbin", "wb")
writeBin("10001100",zz)
close(zz)
Run Code Online (Sandbox Code Playgroud)

当我用office打开文件(encoding = utf-8)时,我可以看到Œ我读不到的是readBin?

zz <- file("c:/testbin", "rb")
readBin(zz,raw())->x
x
[1] c5
readBin(zz,character())->x
Warning message:
In readBin(zz, character()) :
incomplete string at end of file has been discarded
x
character(0)
Run Code Online (Sandbox Code Playgroud)

file-io ascii r utf-8 file-encodings

7
推荐指数
1
解决办法
786
查看次数

如何修复prettytable正确显示汉字

from prettytable import PrettyTable

header="????,??,????".split(",")
x = PrettyTable(header)
x.align["????"]="l"
table='''HuangTianhui,?,1948/05/28
???,?,1952/03/27
???,?,1994/12/09
LuiChing,?,1969/08/02
???,?,1982/03/01
???,?,1983/08/03
YangJiabao,?,1988/08/25
????·???,?,1979/07/10
???,?,1949/10/20
???(??),?,2011/02/25
(??????),?,1985/07/20
'''
data=[row for row in table.split("\n") if row]
for row in data:
    x.add_row(row.strip().split(","))

print(x)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想要的输出格式如下.

在此输入图像描述

在这个例子中,prettytable.py无法显示字符的正确中国暧昧宽度 ·????·??? ,则字符含糊的宽度.如何修复prettytable.py中的错误?

我在prettytable.py的def _char_block_width(char)中添加了两行,但问题仍然存在.

if char == 0xb7:
    return 2 
Run Code Online (Sandbox Code Playgroud)

我已经解决了,文件prettytable.py应该安装在我的电脑d:\ python33\Lib\site-packages中directly not in as the form of d:\python33\Lib\site-packages\prettytable\prettytable.py

有很多中文字符宽度不明确,我们添加两行如下来修复bug是愚蠢的,如果有50个不明确的字符,在prettytable.py中会添加100行,有没有简单的方法要做到这一点?只修一些线来对待所有模棱两可的角色?

if char == 0xb7:
    return 2 
Run Code Online (Sandbox Code Playgroud)

r python-3.x prettytable

7
推荐指数
1
解决办法
720
查看次数

如何在vim中映射long bash命令?

shell命令可以杀死chrome进程.

ps -ef | grep chrome |awk '{print $2}'| xargs kill
Run Code Online (Sandbox Code Playgroud)

现在我想-用上面的bash命令映射字符.

nnoremap  -  :!ps -ef | grep chrome |awk '{print $2}'| xargs kill
Run Code Online (Sandbox Code Playgroud)

它不起作用,如何映射我的bash命令?

vim shell call

7
推荐指数
1
解决办法
451
查看次数

关闭sqlite db cur和con的最佳方法何时使用管道将数据写入sqlite

quotes.py是蜘蛛文件.

import scrapy    
from project.items import ProjectItem    

class QuotesSpider(scrapy.Spider):
    name = 'quotes'
    allowed_domains = ['quotes.toscrape.com']
    start_urls = ['http://quotes.toscrape.com/page/1']

    def parse(self, response):
        item = ProjectItem()
        for quote in response.css('div.quote'):
            item['quote'] = quote.css('span.text::text').extract_first()
            item['author'] = quote.xpath('span/small/text()').extract_first()
            yield item

        next_page = response.css('li.next a::attr("href")').extract_first()
        if next_page is not None:
            yield response.follow(next_page, self.parse)
Run Code Online (Sandbox Code Playgroud)

每个页面中的作者和引用都是在项目中提取的.

使用以下pipelines.py,可以写入item ['author']和item ['quote'] /tmp/test.sqlite.

import sqlite3
import json

class ProjectPipeline(object):
    def __init__(self):
        self.db = r'/tmp/test.sqlite'
        self.table = 'data'
        self.con = sqlite3.connect(self.db)
        self.cur = self.con.cursor()
        self.cur.execute("create table {table} (author TEXT,quote  TEXT)".format(table=self.table)) …
Run Code Online (Sandbox Code Playgroud)

sqlite scrapy

7
推荐指数
1
解决办法
288
查看次数

如何将`\ data\^ Ihello $`加载为两列?

这是我的test-tab.csv如下.

\data\  hello
Run Code Online (Sandbox Code Playgroud)

注意:有一\t\htest-tab.csv,也就是说,在vim显示(组列表).

\data\^Ihello$
Run Code Online (Sandbox Code Playgroud)

准备加载数据.

create table tab(`f1` varchar(10),`f2` varchar(10));
Run Code Online (Sandbox Code Playgroud)

将数据加载到表中tab.

LOAD DATA LOCAL INFILE  "f:/test-tab.csv"
INTO TABLE  tab
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n'  \W;
Run Code Online (Sandbox Code Playgroud)

看看吧.

select * from tab;
+------------+------+
| f1         | f2   |
+------------+------+
| data  hello| NULL |
+------------+------+
1 row in set (0.000 sec)
Run Code Online (Sandbox Code Playgroud)

如何将数据加载到表中tab,如下所示.

select * from tab;
+------------+------+
| f1         | f2   |
+------------+------+
| …
Run Code Online (Sandbox Code Playgroud)

mysql load escaping

7
推荐指数
1
解决办法
110
查看次数

在Scrapinghub上运行Spider时如何保存下载的文件?

stockInfo.py包含:

import scrapy
import re
import pkgutil

class QuotesSpider(scrapy.Spider):
    name = "stockInfo"
    data = pkgutil.get_data("tutorial", "resources/urls.txt")
    data = data.decode()
    start_urls = data.split("\r\n")

    def parse(self, response):
        company = re.findall("[0-9]{6}",response.url)[0]
        filename = '%s_info.html' % company
        with open(filename, 'wb') as f:
            f.write(response.body)
Run Code Online (Sandbox Code Playgroud)

stockInfo在窗口的cmd中执行蜘蛛程序。

d:
cd  tutorial
scrapy crawl stockInfo
Run Code Online (Sandbox Code Playgroud)

现在,该URL中的所有网页都resources/urls.txt将下载到该目录中d:/tutorial

然后将蜘蛛部署进去Scrapinghub,然后运行stockInfo spider

在此处输入图片说明

没有错误发生,下载的网页在哪里?
以下命令行如何执行Scrapinghub

        with open(filename, 'wb') as f:
            f.write(response.body)
Run Code Online (Sandbox Code Playgroud)

如何将数据保存在scrapinghub中,并在作业完成后从scrapinghub下载?

首先要安装scrapinghub。

pip install scrapinghub[msgpack]
Run Code Online (Sandbox Code Playgroud)

重写Thiago Curvelo一下,将其部署在我的scrapinghub中。

Deploy …
Run Code Online (Sandbox Code Playgroud)

python scrapy

7
推荐指数
1
解决办法
167
查看次数

标签 统计

python ×3

vim ×3

r ×2

scrapy ×2

ascii ×1

autocomplete ×1

call ×1

escaping ×1

file-encodings ×1

file-io ×1

git ×1

github ×1

load ×1

lxml ×1

mysql ×1

prettytable ×1

python-3.x ×1

shell ×1

sqlite ×1

ssh ×1

tags ×1

tcl ×1

utf-8 ×1