小编She*_*nta的帖子

python3字典具有重复的键但不同的值

我需要提交一个如下所示的表单数据:

evt: 2001
evt: 1024001
src: mstrWeb.my.fbb.fb.2001
src: mstrWeb.my.fbb.1024001
Run Code Online (Sandbox Code Playgroud)

当我创建 python3 时dict

Dict = {'evt': '2001',
    'evt': '1024001',
    'src': 'mstrWeb.my.fbb.fb.2001',
    'src': 'mstrWeb.my.fbb.1024001'}
Run Code Online (Sandbox Code Playgroud)

它按顺序删除重复的键。我得到:

>>> print (Dict)
{'evt': '1024001', 'src': 'mstrWeb.my.fbb.1024001'}
Run Code Online (Sandbox Code Playgroud)

有什么办法可以让我的 Dict 中的重复键完好无损吗?

python dictionary python-3.x python-requests

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

增加 tkSimpleDialog 窗口大小

如何增加或定义 tkSimpleDialog 框的窗口大小?

import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text")
print test
Run Code Online (Sandbox Code Playgroud)

python tkinter python-2.7 tkinter-canvas

4
推荐指数
2
解决办法
4284
查看次数

Python正则表达式从字符串中提取电话号码

我是regex的新手,我想使用python re从下面的以下多行字符串文本中提取电话号码:

 Source = """<p><strong>Kuala Lumpur</strong><strong>:</strong> +60 (0)3 2723 7900</p>
        <p><strong>Mutiara Damansara:</strong> +60 (0)3 2723 7900</p>
        <p><strong>Penang:</strong> + 60 (0)4 255 9000</p>
        <h2>Where we are </h2>
        <strong>&nbsp;Call us on:</strong>&nbsp;+6 (03) 8924 8686
        </p></div><div class="sys_two">
    <h3 class="parentSchool">General enquiries</h3><p style="FONT-SIZE: 11px">
     <strong>&nbsp;Call us on:</strong>&nbsp;+6 (03) 8924 8000
+ 60 (7) 268-6200 <br />
 Fax:<br /> 
 +60 (7) 228-6202<br /> 
Phone:</strong><strong style="color: #f00">+601-4228-8055</strong>"""
Run Code Online (Sandbox Code Playgroud)

所以当我编译模式时,我应该能够找到使用

phone = re.findall(pattern,source,re.DOTALL)

 ['+60 (0)3 2723 7900',
  '+60 (0)3 2723 7900',
  '+ 60 (0)4 255 9000',
  '+6 (03) 8924 …
Run Code Online (Sandbox Code Playgroud)

regex pattern-matching python-2.7 python-3.x

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

如何使用python selenium缩小页面

我发现这是为java: -

WebElement html = driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));
Run Code Online (Sandbox Code Playgroud)

但是如何使用Python做到这一点?我想在获取请求后缩小一个级别.

python selenium selenium-webdriver

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

电话号码的 Python 正则表达式

我对正则表达式很陌生,正在寻求帮助从 HTML 文本中解析出电话号码

在源站点,html 标签非常扭曲,并且没有任何我可以使用的唯一选择器。下面是我要解析的可能性列表。

raw = """+49 39291 55-217
02102 7007064
0152 01680970
+49 39291 55-216
02102 3802 22
0800 333004 451-100
+49 221 9937 26950
02151-47974510
+49(0)6105 937 -539
0211/409 2268
+49(0)6105 937 -539
+49211/584-623
0211 58422 2012
+49 (9131) 7-35335
+49 521 9488 2470
+ 49-40-70 70 84 - 0
0211 17 95 99 04
02151-47974327
+49 203 28900 1121
0211 9449-2555
+49 (5 41) 9 98 -2268"""
Run Code Online (Sandbox Code Playgroud)

我试过这种模式,但无法从中了解更多

import re, requests

Phones = re.findall(re.compile(r'.*?(\(?\d{3}\D{0,3}\d{3}\D{0,3}\d{4}).*?'),raw)

phones
['102 …
Run Code Online (Sandbox Code Playgroud)

python regex python-3.x regex-greedy

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

使用Python写入谷歌电子表格

我想知道是否有办法使用Python写入谷歌电子表格.找到了python-gdata-client库,安装了所有依赖项.使用下面的代码,但它不起作用

import time
import gdata.spreadsheet.service

email = 'email@gmail.com'
password = 'pwd'
weight = '180'
# Find this value in the url with 'key=XXX' and copy XXX below
spreadsheet_key = 'pRoiw3us3wh1FyEip46wYtW'
# All spreadsheets have worksheets. I think worksheet #1 by default always
# has a value of 'od6'
worksheet_id = 'Sheet1'

spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = email
spr_client.password = password
spr_client.source = 'Example Spreadsheet Writing Application'
spr_client.ProgrammaticLogin()

# Prepare the dictionary to write
dict = {}
dict['date'] = …
Run Code Online (Sandbox Code Playgroud)

python api google-docs google-docs-api python-2.7

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