小编Ser*_*gey的帖子

如何将文字对齐到左边?

请帮助修复脚本.

from tkinter import *
colors = ['red',  'white',  'blue']

def packbox(root):
    Label(root, text='Pack').pack()
    for color in colors:
        row = Frame(root)
        lab = Label(row, text=color, relief=RIDGE,  width=25)
        ent = Entry(row, bg=color,   relief=SUNKEN, width=50)
        row.pack(side=TOP,   expand=YES, fill=BOTH)
        lab.pack(side=LEFT,  expand=YES, fill=BOTH)
        ent.pack(side=RIGHT, expand=YES, fill=BOTH)

root = Tk()
packbox(root)
mainloop()
Run Code Online (Sandbox Code Playgroud)

我想在左边缘的Label小部件中对齐文本

python tkinter

7
推荐指数
2
解决办法
2万
查看次数

如何替换字符串中的多个字符?

如何替换字符串中的多个字符?

请帮助修复脚本

我需要在行"name"中将特殊字符替换为短语"special char"

newName = replace(name, ['\', '/', ':', '*', '?', '"', '<', '>', '|'], 'special char')
Run Code Online (Sandbox Code Playgroud)

但我收到的消息是:

无效的语法

python string replace python-3.x

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

如何加载BeautifulSoup页面解析器?

求助请下载指定页面并找到id =''login'的元素.必然需要用于查询模块请求

import pprint
import requests

import bs4

url = 'http://forum.saransk.ru/'
html = requests.get(url)
#print(html.text)
soup = bs4.BeautifulSoup(html)
loginForm = soup.find('form', {'id': 'login'})

pprint.pprint(loginForm)
Run Code Online (Sandbox Code Playgroud)

错误信息:

回溯(最近一次调用最后一次):文件"C:\ VINT\OPENSERVER\OpenServer\domains\localhost\python\parse_html\4_auth\q.py",第9行,在汤= bs4.BeautifulSoup(html)文件"C:\Python33\lib\site-packages\bs4__init __.py",第162行,在init elif len(标记)<= 256:TypeError:类型为'Response'的对象没有len()

python beautifulsoup request python-3.x

3
推荐指数
1
解决办法
5224
查看次数

如何找到第一层的后代?

请帮助修复脚本。

import pprint
import requests

import bs4


def get_catalog(url):
    req = requests.get(url)
    if req.status_code != requests.codes.ok:
        print('Error: ', req.status_code)
    else:
        soup = bs4.BeautifulSoup(req.text)
        #print(soup)
        catalogMenu = soup.find('section', {'class': 'catalog'})
        catalogMenuList = catalogMenu.find('ul', {'class': 'topnav'})
        #print(catalogMenuList)

        return catalogMenuList


def parse_catalog_categories(catalogMenuList):
    catalogNames = []
    #li = catalogMenuList.findNext('li', limit=1)   #?????????????????
    pprint.pprint(li)


if __name__ == "__main__":
    url = 'http://first-store.ru/'
    catalogMenuList = get_catalog(url)
    if not catalogMenuList:
        print('Get catalog error')
    else:
        parse_catalog_categories(catalogMenuList)
Run Code Online (Sandbox Code Playgroud)

问题是我找不到li第一层嵌套的所有后代。即:

iphone, ipad, ipod, imac, etc... 
Run Code Online (Sandbox Code Playgroud)

但不是:

iphone, iphone 5s, iphone 5s …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup python-3.x

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

录制后如何关闭文件?

请帮助修复脚本.

import urllib
import re
import os
import pprint

import requests
import bs4


def make_catalog():
    try: 
        os.mkdir('GRAB')
    except FileExistsError:
        print('FileExistsError')
    except PermissionError :
        print('PermissionError ')
    except Exception:
        print(Exception)                


def change_catalog():
    try: 
        os.chdir('GRAB')
    except PermissionError :
        print('PermissionError ')
    except Exception:
        print(Exception)


def download_image(path, name):
    #urllib.URLopener().retrieve(prefix + path, name)
    img = urllib.request.urlopen(prefix + path).read()
    try:
        f = open(name, "wb")
        if f:
            print('open!!!')
        if f.write(img):
            print('write!!!')
    except OSError:
        print('OSError')
    except Exception:
        print(Exception)    
    finally:
        f.close()


beginIndex = 5794
endIndex = 5800
prefix = "http://www.inpic.ru" …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
45
查看次数

如何更改号码类型?

请帮助更改类型编号double - > int.即我需要删除小数部分,但不要使用split()

import time

date = time.ctime(int('1223.435'.split('.')[0]))
Run Code Online (Sandbox Code Playgroud)

python python-3.x

0
推荐指数
1
解决办法
46
查看次数

如何只允许数字?

请帮助修复脚本.

HTML:

<input type="text" ng-model="phone" id="phoneInput" ng-change="apt.changePhoneInput(phone)">
Run Code Online (Sandbox Code Playgroud)

JS:

var app = angular.module('app', []);
app.controller('Appctrl', Appctrl, '$scope');
function Appctrl($scope){
  this.changePhoneInput = function(phone) {
    var result = phone;
    console.log('phone', phone);
    result.replace(/[^+0-9\(\)]/gim,'');
    console.log('result', result);
    $scope.phone = result;
  };
}
Run Code Online (Sandbox Code Playgroud)

的jsfiddle

我想允许只输入数字并遵循符号:'+','(',')',' - '.但输入任何符号后,替换不起作用

javascript angularjs

0
推荐指数
1
解决办法
71
查看次数