小编par*_*axi的帖子

Python 3.2在csv.DictReader中跳过一行

使用DictReader时如何跳过CSV中的一行记录?

码:

import csv
reader = csv.DictReader(open('test2.csv'))
# Skip first line
reader.next()
for row in reader:
    print(row)
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "learn.py", line 3, in <module>
    reader.next()
AttributeError: 'DictReader' object has no attribute 'next'
Run Code Online (Sandbox Code Playgroud)

python csv python-3.x

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

在Python请求get或post方法上干净地设置max_retries

与旧版本的请求相关问题:我可以为requests.request设置max_retries吗?

我还没有看到一个例子,干净地结合max_retries在一个requests.get()requests.post()通话.

会爱一个

requests.get(url, max_retries=num_max_retries))
Run Code Online (Sandbox Code Playgroud)

履行

python python-requests

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

如何在Python中为特定模块实现不同的级别

从这个stackoverflow问题,如何实现以下配置文件?

[logger_qpid]
level=NOTSET
handlers=nullHandler
qualname=qpid
propagate=0
Run Code Online (Sandbox Code Playgroud)

我正在使用logging.basicConfig:

# Configure parser.
parser = argparse.ArgumentParser(description = 'Allow for debug logging mode.')
parser.add_argument('--debug', action = 'store_true',
                    help = 'Outputs additional information to log.')
c_args = parser.parse_args()
# Configure logging mode.
if c_args.debug:
    # Enable debug level of logging.
    print "Logging level set to debug."
    logging.basicConfig(filename = LOG_FILENAME, format = '%(asctime)s %(message)s',
                        level = logging.DEBUG)
else:
    logging.basicConfig(filename = LOG_FILENAME, format = '%(asctime)s %(message)s',
                        level = logging.INFO)
Run Code Online (Sandbox Code Playgroud)

logging module python-2.x

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

如何创建自定义Google协作平台主题?

我想创建一个自定义主题.可以应用其他人的自定义主题(http://www.gethemes.com/free-themes),但我找不到有关如何创建Google协作平台主题的文档.

themes google-sites

12
推荐指数
1
解决办法
4万
查看次数

将excel或电子表格列字母转换为Pythonic方式的数字

是否有更多pythonic方式将excel样式列转换为数字(从1开始)?

最多两个字母的工作代码:

def column_to_number(c):
    """Return number corresponding to excel-style column."""
    number=-25
    for l in c:
        if not l in string.ascii_letters:
            return False
        number+=ord(l.upper())-64+25
    return number
Run Code Online (Sandbox Code Playgroud)

代码运行:

>>> column_to_number('2')
False
>>> column_to_number('A')
1
>>> column_to_number('AB')
28
Run Code Online (Sandbox Code Playgroud)

三个字母不起作用.

>>> column_to_number('ABA')
54
>>> column_to_number('AAB')
54
Run Code Online (Sandbox Code Playgroud)

参考: C#中回答的问题

python excel python-2.x google-sheets

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

在PyPI上更改包名称的大小写

我最近使用带有大小写字母QualysAPI的名称将一个包上传到PyPI.回想起来,我认为让每个PEP 8的包名全部小写会更好.有没有办法可以改变它?

这是当我尝试在Pypi上手动编辑包名称时发生的情况:

被禁止

包名称与现有包'QualysAPI'冲突

这是当我尝试通过以下方式编辑包名时发生的情况python setup.py sdist upload:

上传失败(403):您不能编辑'qualysapi'包信息

python package pypi

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

计算 Google 表格单元格中的换行符数量

单元格值代表一个列表。单元格中的换行符表示列表中的项目数 需要识别列表中的项目数。

count line-breaks google-sheets

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

Python中的IP地址列表到CIDR列表

如何将IP地址列表转换为CIDR列表? Google的ipaddr-py库有一个名为summarize_address_range(first,last)的方法,它将两个IP地址(开始和结束)转换为CIDR列表.但是,它无法处理IP地址列表.

Example:
>>> list_of_ips = ['10.0.0.0', '10.0.0.1', '10.0.0.2', '10.0.0.3', '10.0.0.5']
>>> convert_to_cidr(list_of_ips)
['10.0.0.0/30','10.0.0.5/32']
Run Code Online (Sandbox Code Playgroud)

python ip cidr

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

python-requests 相当于 curl 的 --data-binary?

Curl 可以使用--data-binary 选项发送文件。

测试Qualys WAS API 时,以下 curl 命令有效:

curl -u "username:password" -H "content-type: text/xml" -X "POST" --data-binary @- "https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp" < post.xml
Run Code Online (Sandbox Code Playgroud)

帖子.xml:

<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>
Run Code Online (Sandbox Code Playgroud)

使用 Python 的请求模块,我不断收到 HTTPError: 415 Client Error: Unsupported Media Type。

import requests
url = 'https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp'
payload = '<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>'
headers = {'X-Requested-With': 'Python requests', 'Content-type': 'application/json'}
r = requests.post(url, data=payload, headers=headers, auth=('username', 'password'))
Run Code Online (Sandbox Code Playgroud)

当尝试提交文件 files 参数时,它也以 415 错误结束。

import requests
url = 'https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp'
payload = …
Run Code Online (Sandbox Code Playgroud)

python rest python-requests

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

如何使用json对象输入来记录swagger查询参数

如何为in: query(不in: body)请求参数定义JSON对象值?

示例如下:

paths:
  /schedules:
    get:
      summary: Gets the list of schedules
      description: |
        The schedules endpoint returns information about the configured schedules.
      parameters:
        - name: filter
          in: query
          description: >
          Returns whether alert runs on matching schedule.


          Example request:


              {
                "type": "a",
                "start" : "b",
                "stop" : "c"
              }
          required: true
          type: string
Run Code Online (Sandbox Code Playgroud)

因为它不是in: body,我不能使用schema.

http-request-parameters jsonobject swagger-2.0

5
推荐指数
0
解决办法
278
查看次数