在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/ Python問答
失心人 回答

flock的是建議鎖,因此不適合題主的需求

不二心 回答

for line in f:
是在調(diào)用 f.next().
f.next() 方法被調(diào)用的時(shí)候,f.tell() 方法不可以被調(diào)用

如果需要返回當(dāng)前指針位置,可以這樣
pos = 0
with open(r'My Daily', 'r+') as f:

for line in f:
    pos += len(lien)
    #print f.tell()
    print(post)
眼雜 回答

寫個(gè)腳本自動(dòng)啟動(dòng)運(yùn)行,就可以

我甘愿 回答

感覺類似于用完之后初始化,貌似刪了也沒啥影響。

短嘆 回答

源代碼 Parser/Tokenizer.c 進(jìn)行詞法分析。首先是依照編碼進(jìn)行解碼。然后通過tok_get 函數(shù)進(jìn)行詞法分析。

首先處理縮進(jìn);
然后是消除空白字符、注釋以及空白行;
再然后是標(biāo)識(shí)符、數(shù)字、字符串;
再然后是續(xù)行符('\'+直接輸入換行);
最后是操作符。

static int
tok_get(struct tok_state *tok, char **p_start, char **p_end)
{
    int c;
    int blankline, nonascii;

    *p_start = *p_end = NULL;
  nextline:
    tok->start = NULL;
    blankline = 0;

    /* Get indentation level */
    if (tok->atbol) {
        int col = 0;
        int altcol = 0;
        tok->atbol = 0;
        for (;;) {
            c = tok_nextc(tok);
            if (c == ' ') {
                col++, altcol++;
            }
            else if (c == '\t') {
                col = (col/tok->tabsize + 1) * tok->tabsize;
                altcol = (altcol/tok->alttabsize + 1)
                    * tok->alttabsize;
            }
            else if (c == '\014')  {/* Control-L (formfeed) */
                col = altcol = 0; /* For Emacs users */
            }
            else {
                break;
            }
        }
        tok_backup(tok, c);
        if (c == '#' || c == '\n') {
            /* Lines with only whitespace and/or comments
               shouldn't affect the indentation and are
               not passed to the parser as NEWLINE tokens,
               except *totally* empty lines in interactive
               mode, which signal the end of a command group. */
            if (col == 0 && c == '\n' && tok->prompt != NULL) {
                blankline = 0; /* Let it through */
            }
            else {
                blankline = 1; /* Ignore completely */
            }
            /* We can't jump back right here since we still
               may need to skip to the end of a comment */
        }
        if (!blankline && tok->level == 0) {
            if (col == tok->indstack[tok->indent]) {
                /* No change */
                if (altcol != tok->altindstack[tok->indent]) {
                    if (indenterror(tok)) {
                        return ERRORTOKEN;
                    }
                }
            }
            else if (col > tok->indstack[tok->indent]) {
                /* Indent -- always one */
                if (tok->indent+1 >= MAXINDENT) {
                    tok->done = E_TOODEEP;
                    tok->cur = tok->inp;
                    return ERRORTOKEN;
                }
                if (altcol <= tok->altindstack[tok->indent]) {
                    if (indenterror(tok)) {
                        return ERRORTOKEN;
                    }
                }
                tok->pendin++;
                tok->indstack[++tok->indent] = col;
                tok->altindstack[tok->indent] = altcol;
            }
            else /* col < tok->indstack[tok->indent] */ {
                /* Dedent -- any number, must be consistent */
                while (tok->indent > 0 &&
                    col < tok->indstack[tok->indent]) {
                    tok->pendin--;
                    tok->indent--;
                }
                if (col != tok->indstack[tok->indent]) {
                    tok->done = E_DEDENT;
                    tok->cur = tok->inp;
                    return ERRORTOKEN;
                }
                if (altcol != tok->altindstack[tok->indent]) {
                    if (indenterror(tok)) {
                        return ERRORTOKEN;
                    }
                }
            }
        }
    }

    tok->start = tok->cur;

    /* Return pending indents/dedents */
    if (tok->pendin != 0) {
        if (tok->pendin < 0) {
            tok->pendin++;
            return DEDENT;
        }
        else {
            tok->pendin--;
            return INDENT;
        }
    }

    if (tok->async_def
        && !blankline
        && tok->level == 0
        /* There was a NEWLINE after ASYNC DEF,
           so we're past the signature. */
        && tok->async_def_nl
        /* Current indentation level is less than where
           the async function was defined */
        && tok->async_def_indent >= tok->indent)
    {
        tok->async_def = 0;
        tok->async_def_indent = 0;
        tok->async_def_nl = 0;
    }

 again:
    tok->start = NULL;
    /* Skip spaces */
    do {
        c = tok_nextc(tok);
    } while (c == ' ' || c == '\t' || c == '\014');

    /* Set start of current token */
    tok->start = tok->cur - 1;

    /* Skip comment */
    if (c == '#') {
        while (c != EOF && c != '\n') {
            c = tok_nextc(tok);
        }
    }

    /* Check for EOF and errors now */
    if (c == EOF) {
        return tok->done == E_EOF ? ENDMARKER : ERRORTOKEN;
    }

    /* Identifier (most frequent token!) */
    nonascii = 0;
    if (is_potential_identifier_start(c)) {
        /* Process the various legal combinations of b"", r"", u"", and f"". */
        int saw_b = 0, saw_r = 0, saw_u = 0, saw_f = 0;
        while (1) {
            if (!(saw_b || saw_u || saw_f) && (c == 'b' || c == 'B'))
                saw_b = 1;
            /* Since this is a backwards compatibility support literal we don't
               want to support it in arbitrary order like byte literals. */
            else if (!(saw_b || saw_u || saw_r || saw_f)
                     && (c == 'u'|| c == 'U')) {
                saw_u = 1;
            }
            /* ur"" and ru"" are not supported */
            else if (!(saw_r || saw_u) && (c == 'r' || c == 'R')) {
                saw_r = 1;
            }
            else if (!(saw_f || saw_b || saw_u) && (c == 'f' || c == 'F')) {
                saw_f = 1;
            }
            else {
                break;
            }
            c = tok_nextc(tok);
            if (c == '"' || c == '\'') {
                goto letter_quote;
            }
        }
        while (is_potential_identifier_char(c)) {
            if (c >= 128) {
                nonascii = 1;
            }
            c = tok_nextc(tok);
        }
        tok_backup(tok, c);
        if (nonascii && !verify_identifier(tok)) {
            return ERRORTOKEN;
        }
        *p_start = tok->start;
        *p_end = tok->cur;

        /* async/await parsing block. */
        if (tok->cur - tok->start == 5) {
            /* Current token length is 5. */
            if (tok->async_def) {
                /* We're inside an 'async def' function. */
                if (memcmp(tok->start, "async", 5) == 0) {
                    return ASYNC;
                }
                if (memcmp(tok->start, "await", 5) == 0) {
                    return AWAIT;
                }
            }
            else if (memcmp(tok->start, "async", 5) == 0) {
                /* The current token is 'async'.
                   Look ahead one token.*/

                struct tok_state ahead_tok;
                char *ahead_tok_start = NULL, *ahead_tok_end = NULL;
                int ahead_tok_kind;

                memcpy(&ahead_tok, tok, sizeof(ahead_tok));
                ahead_tok_kind = tok_get(&ahead_tok, &ahead_tok_start,
                                         &ahead_tok_end);

                if (ahead_tok_kind == NAME
                    && ahead_tok.cur - ahead_tok.start == 3
                    && memcmp(ahead_tok.start, "def", 3) == 0)
                {
                    /* The next token is going to be 'def', so instead of
                       returning 'async' NAME token, we return ASYNC. */
                    tok->async_def_indent = tok->indent;
                    tok->async_def = 1;
                    return ASYNC;
                }
            }
        }

        return NAME;
    }

    /* Newline */
    if (c == '\n') {
        tok->atbol = 1;
        if (blankline || tok->level > 0) {
            goto nextline;
        }
        *p_start = tok->start;
        *p_end = tok->cur - 1; /* Leave '\n' out of the string */
        tok->cont_line = 0;
        if (tok->async_def) {
            /* We're somewhere inside an 'async def' function, and
               we've encountered a NEWLINE after its signature. */
            tok->async_def_nl = 1;
        }
        return NEWLINE;
    }

    /* Period or number starting with period? */
    if (c == '.') {
        c = tok_nextc(tok);
        if (isdigit(c)) {
            goto fraction;
        } else if (c == '.') {
            c = tok_nextc(tok);
            if (c == '.') {
                *p_start = tok->start;
                *p_end = tok->cur;
                return ELLIPSIS;
            }
            else {
                tok_backup(tok, c);
            }
            tok_backup(tok, '.');
        }
        else {
            tok_backup(tok, c);
        }
        *p_start = tok->start;
        *p_end = tok->cur;
        return DOT;
    }

    /* Number */
    if (isdigit(c)) {
        if (c == '0') {
            /* Hex, octal or binary -- maybe. */
            c = tok_nextc(tok);
            if (c == 'x' || c == 'X') {
                /* Hex */
                c = tok_nextc(tok);
                do {
                    if (c == '_') {
                        c = tok_nextc(tok);
                    }
                    if (!isxdigit(c)) {
                        tok->done = E_TOKEN;
                        tok_backup(tok, c);
                        return ERRORTOKEN;
                    }
                    do {
                        c = tok_nextc(tok);
                    } while (isxdigit(c));
                } while (c == '_');
            }
            else if (c == 'o' || c == 'O') {
                /* Octal */
                c = tok_nextc(tok);
                do {
                    if (c == '_') {
                        c = tok_nextc(tok);
                    }
                    if (c < '0' || c >= '8') {
                        tok->done = E_TOKEN;
                        tok_backup(tok, c);
                        return ERRORTOKEN;
                    }
                    do {
                        c = tok_nextc(tok);
                    } while ('0' <= c && c < '8');
                } while (c == '_');
            }
            else if (c == 'b' || c == 'B') {
                /* Binary */
                c = tok_nextc(tok);
                do {
                    if (c == '_') {
                        c = tok_nextc(tok);
                    }
                    if (c != '0' && c != '1') {
                        tok->done = E_TOKEN;
                        tok_backup(tok, c);
                        return ERRORTOKEN;
                    }
                    do {
                        c = tok_nextc(tok);
                    } while (c == '0' || c == '1');
                } while (c == '_');
            }
            else {
                int nonzero = 0;
                /* maybe old-style octal; c is first char of it */
                /* in any case, allow '0' as a literal */
                while (1) {
                    if (c == '_') {
                        c = tok_nextc(tok);
                        if (!isdigit(c)) {
                            tok->done = E_TOKEN;
                            tok_backup(tok, c);
                            return ERRORTOKEN;
                        }
                    }
                    if (c != '0') {
                        break;
                    }
                    c = tok_nextc(tok);
                }
                if (isdigit(c)) {
                    nonzero = 1;
                    c = tok_decimal_tail(tok);
                    if (c == 0) {
                        return ERRORTOKEN;
                    }
                }
                if (c == '.') {
                    c = tok_nextc(tok);
                    goto fraction;
                }
                else if (c == 'e' || c == 'E') {
                    goto exponent;
                }
                else if (c == 'j' || c == 'J') {
                    goto imaginary;
                }
                else if (nonzero) {
                    /* Old-style octal: now disallowed. */
                    tok->done = E_TOKEN;
                    tok_backup(tok, c);
                    return ERRORTOKEN;
                }
            }
        }
        else {
            /* Decimal */
            c = tok_decimal_tail(tok);
            if (c == 0) {
                return ERRORTOKEN;
            }
            {
                /* Accept floating point numbers. */
                if (c == '.') {
                    c = tok_nextc(tok);
        fraction:
                    /* Fraction */
                    if (isdigit(c)) {
                        c = tok_decimal_tail(tok);
                        if (c == 0) {
                            return ERRORTOKEN;
                        }
                    }
                }
                if (c == 'e' || c == 'E') {
                    int e;
                  exponent:
                    e = c;
                    /* Exponent part */
                    c = tok_nextc(tok);
                    if (c == '+' || c == '-') {
                        c = tok_nextc(tok);
                        if (!isdigit(c)) {
                            tok->done = E_TOKEN;
                            tok_backup(tok, c);
                            return ERRORTOKEN;
                        }
                    } else if (!isdigit(c)) {
                        tok_backup(tok, c);
                        tok_backup(tok, e);
                        *p_start = tok->start;
                        *p_end = tok->cur;
                        return NUMBER;
                    }
                    c = tok_decimal_tail(tok);
                    if (c == 0) {
                        return ERRORTOKEN;
                    }
                }
                if (c == 'j' || c == 'J') {
                    /* Imaginary part */
        imaginary:
                    c = tok_nextc(tok);
                }
            }
        }
        tok_backup(tok, c);
        *p_start = tok->start;
        *p_end = tok->cur;
        return NUMBER;
    }

  letter_quote:
    /* String */
    if (c == '\'' || c == '"') {
        int quote = c;
        int quote_size = 1;             /* 1 or 3 */
        int end_quote_size = 0;

        /* Find the quote size and start of string */
        c = tok_nextc(tok);
        if (c == quote) {
            c = tok_nextc(tok);
            if (c == quote) {
                quote_size = 3;
            }
            else {
                end_quote_size = 1;     /* empty string found */
            }
        }
        if (c != quote) {
            tok_backup(tok, c);
        }

        /* Get rest of string */
        while (end_quote_size != quote_size) {
            c = tok_nextc(tok);
            if (c == EOF) {
                if (quote_size == 3) {
                    tok->done = E_EOFS;
                }
                else {
                    tok->done = E_EOLS;
                }
                tok->cur = tok->inp;
                return ERRORTOKEN;
            }
            if (quote_size == 1 && c == '\n') {
                tok->done = E_EOLS;
                tok->cur = tok->inp;
                return ERRORTOKEN;
            }
            if (c == quote) {
                end_quote_size += 1;
            }
            else {
                end_quote_size = 0;
                if (c == '\\') {
                    tok_nextc(tok);  /* skip escaped char */
                }
            }
        }

        *p_start = tok->start;
        *p_end = tok->cur;
        return STRING;
    }

    /* Line continuation */
    if (c == '\\') {
        c = tok_nextc(tok);
        if (c != '\n') {
            tok->done = E_LINECONT;
            tok->cur = tok->inp;
            return ERRORTOKEN;
        }
        tok->cont_line = 1;
        goto again; /* Read next line */
    }

    /* Check for two-character token */
    {
        int c2 = tok_nextc(tok);
        int token = PyToken_TwoChars(c, c2);
        if (token != OP) {
            int c3 = tok_nextc(tok);
            int token3 = PyToken_ThreeChars(c, c2, c3);
            if (token3 != OP) {
                token = token3;
            }
            else {
                tok_backup(tok, c3);
            }
            *p_start = tok->start;
            *p_end = tok->cur;
            return token;
        }
        tok_backup(tok, c2);
    }

    /* Keep track of parentheses nesting level */
    switch (c) {
    case '(':
    case '[':
    case '{':
        tok->level++;
        break;
    case ')':
    case ']':
    case '}':
        tok->level--;
        break;
    }

    /* Punctuation character */
    *p_start = tok->start;
    *p_end = tok->cur;
    return PyToken_OneChar(c);
}
風(fēng)畔 回答

__init__() 應(yīng)該叫做 初始化函數(shù),是類創(chuàng)建新實(shí)例后默認(rèn)調(diào)用的函數(shù),跟普通函數(shù)的執(zhí)行沒什么區(qū)別.
__init__(self, url) 分別對 5 個(gè)實(shí)例屬性進(jìn)行了賦值, 其中調(diào)用了三個(gè)實(shí)例方法, 這些實(shí)例方法又各自引用了實(shí)例屬性作為參數(shù)

那你只能js判斷了,當(dāng)在6后面的時(shí)候,動(dòng)態(tài)設(shè)置box-item的橫向滾動(dòng)值

款爺 回答
INSERT INTO dede_addonarticle VALUES (12345,3,"This is the content","http://url.com","xxx","yyy")

慢慢拼吧,建議活用str.format語句。

話寡 回答

獲取文本內(nèi)容使用.text或者.text()

別硬撐 回答

numpy 的 random 機(jī)制和 Python 標(biāo)準(zhǔn)庫的 random 模塊機(jī)制是一樣的,當(dāng)我們設(shè)置相同的 seed,每次生成的隨機(jī)數(shù)相同。
如果不設(shè)置 seed,則每次會(huì)生成不同的隨機(jī)數(shù)。
這里引用 stackoverflow 上的最高票解答

>>> numpy.random.seed(0) ; numpy.random.rand(4)
array([ 0.55,  0.72,  0.6 ,  0.54])
>>> numpy.random.seed(0) ; numpy.random.rand(4)
array([ 0.55,  0.72,  0.6 ,  0.54])
胭脂淚 回答

我在 stack overflow 找到了前人問題程答案:
https://stackoverflow.com/que...

"When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. ......."
上面錯(cuò)誤已刪
已作修改:
所以我想,可能因?yàn)樵趓''中,反斜杠后面的 ' 被當(dāng)作字符保留了而且是一般字符,因而是失去了功能。
又或者是因?yàn)?,例如r"abc" , 先生成"abc" 字符串,然後才加上r再處理, 如果r"反斜杠"就出現(xiàn)生成字符串失敗。

Doc. Python 里面建意r"反斜杠""

抱歉,反斜杠不見了,希望你
https://docs.python.org/2.0/r...
Doc.python 有陳述

尛曖昧 回答

跟你5px的scrollbar 有關(guān)。頁面比較高的時(shí)候,scrollbar會(huì)占個(gè)位置。

寫榮 回答
假設(shè)一個(gè)model為A 有 a,b兩個(gè)字段
class A(models.Model):
    a = models.CharField(max_length=1)
    b = models.CharField(max_length=1)
test_json = {
    'a':'test'
    'b':'test'
}
如果你json里的key 和 model里的字段名是相符的(不需要數(shù)量相符,只要對應(yīng)的字段名和key名相同就行) 可以這樣寫
A.objects.update(**test_json)
離殤 回答
import numpy as np


def num(i=[0]):
    i[0] += 1
    return i[0]


shu_ru = int(input("shu ru "))
a = np.zeros((shu_ru, shu_ru))
k = 1
all = []

while k < shu_ru * 2:
    lst = []
    for i in range(k):
        for j in range(k):
            if i + j == k - 1 and i < shu_ru and j < shu_ru:
                lst.append((i, j))
    if k % 2 == 0:
        lst.reverse()
    k += 1
    all.append(lst_p)

for i in all:
    for j in i:
        a[j] = num()

當(dāng)a = 3,輸出

Out[1]: 
array([[1., 3., 4.],
       [2., 5., 8.],
       [6., 7., 9.]])

當(dāng)a = 4,輸出

Out[2]: 
array([[ 1.,  3.,  4., 10.],
       [ 2.,  5.,  9., 11.],
       [ 6.,  8., 12., 15.],
       [ 7., 13., 14., 16.]])

當(dāng)a = 1,輸出

Out[2]: array([[1.]])

代碼寫的比較直白,沒有優(yōu)化,大概就是從下標(biāo)跟你的輸入值的關(guān)系著手分析。

突然不給返回?cái)?shù)據(jù)了,只能把正則匹配出來的東西寫成變量了


import requests
import re
import json

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 \
    (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36"
}

url = "http://s8-static.jjwxc.net/getnovelclick.php?novelid=3601&jsonpcall\
back=novelclick"
web_data = requests.get(url, headers=headers)
web_data.encoding = "gzip"
result = web_data.content.decode()
string = re.findall(r'({.*?})', result)[0]


# string = '{"1":"82686","2":"73363","3":"52320","4":"49171","5":"46838","6":"\
# 43687","7":"36339","8":"36067","9":"35917","10":"35570","11":"32912","12":"34\
# 357","13":"33653","14":"31370","15":"33803","16":"32647","17":"30681","18":"32\
# 163","19":"29455","20":"31213","21":"30199","22":"28536","23":"30041","24":"\
# 28862","25":"29439","26":"29469","27":"29378","28":"29678","29":"31427","\
# 30":"53411"}'

tmp_dict = json.loads(string)
for k, v in tmp_dict.items():
    print(k, v)
# 1 82686
# 2 73363
# 3 52320
# 4 49171
# 5 46838
# 6 43687
# 7 36339
短嘆 回答

python3, 直接改成list1_name.append(elements[0])就可以了:

ftele1=open('a.txt', 'r', encoding='utf-8')
ftele2=open('b.txt', 'r', encoding='utf-8')

ftele1.readline() #跳過第一行
ftele2.readline()
lines1 = ftele1.readlines()
lines2 = ftele2.readlines()

list1_name = []
list1_tele = []
list2_name = []
list2_email = []

for line in lines1: #獲取第一個(gè)文本中的姓名和電話信息
    elements = line.split()
    print(elements[0])

    list1_name.append(elements[0])
    list1_tele.append(elements[1])


for line in lines2:  #獲取第二個(gè)文本中的姓名和郵箱信息
    elements = line.split()

    list2_name.append(elements[0])
    list2_email.append(elements[1])

#開始處理
lines = []
lines.append('姓名\t    電話\t     郵箱\n')

#按索引方式遍歷姓名列表1
for i in range(len(list1_name)):
    s=''
    if list1_name[i] in list2_name:
        j = list2_name.index(list1_name[i]) #找到姓名列表1對應(yīng)列表2中國年的姓名索引位置
        s = '\t'.join([list1_name[i], list1_tele[i], list2_email[j]])
        s += '\n'
    else:
        s = '\t'.join([list1_name[i], list1_tele[i], str(' ----- ')])
        s += '\n'
    lines.append(s)
#處理姓名列表2中剩余的姓名
for i in range(len(list2_name)):
    s=''
    if list2_name[i] not in list1_name:
        s = '\t'.join([list2_name[i], str(' ----- '), list2_email[i]])
        s += '\n'
    lines.append(s)

ftele3 = open('AddrBook.txt', 'w')
ftele3.writelines(lines)
ftele3.close()
ftele1.close()
ftele2.close()

print('The AddressBooks are merged!')

python2 類似,但是頭上加個(gè)# encoding=utf-8:

# encoding=utf-8
ftele1=open('a.txt', 'rb')
ftele2=open('b.txt', 'rb')

ftele1.readline()
ftele2.readline()
lines1 = ftele1.readlines()
lines2 = ftele2.readlines()

list1_name = []
list1_tele = []
list2_name = []
list2_email = []

for line in lines1:
    elements = line.split()
    print(elements[0])

    list1_name.append(elements[0])
    list1_tele.append(elements[1])


for line in lines2:
    elements = line.split()
    #print(elements)
    list2_name.append(elements[0])
    list2_email.append(elements[1])


lines = []
lines.append('姓名\t    電話\t     郵箱\n')


for i in range(len(list1_name)):
    s=''
    if list1_name[i] in list2_name:
        j = list2_name.index(list1_name[i])
        s = '\t'.join([list1_name[i], list1_tele[i], list2_email[j]])
        s += '\n'
    else:
        s = '\t'.join([list1_name[i], list1_tele[i], str(' ----- ')])
        s += '\n'
    lines.append(s)

for i in range(len(list2_name)):
    s=''
    if list2_name[i] not in list1_name:
        s = '\t'.join([list2_name[i], str(' ----- '), list2_email[i]])
        s += '\n'
    lines.append(s)

ftele3 = open('AddrBook.txt', 'w')
ftele3.writelines(lines)
ftele3.close()
ftele1.close()
ftele2.close()

print('The AddressBooks are merged!')
巫婆 回答

requests源碼里面提到,響應(yīng)頭content-type里面如果有text的話,返回類型是ISO-8859-1,所以你可以這樣試試(親測好用)。

response = requests.request('GET', url)  
response.encoding=None
response.text

祈歡 回答

Bus error 表示程序要讀不可能存在的內(nèi)存地址,檢查mongod引用了什么so文件,編譯和執(zhí)行時(shí)的so文件要一樣。