社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

rusu_ro1

rusu_ro1 最近创建的主题
rusu_ro1 最近回复了

你可以用 reduce

from functools import reduce


def seriesrun(x, n):

    return reduce(lambda c, i: c + x**i*(-1)**i , range(n + 1), 0)

如果要在“(”)之间提取内容,可以执行以下操作:(但首先要注意如何处理内容):

for line in content.split('\n'):
    if 'module' in line:
        line_content = line[line.find('(') + 1: line.find(')')]

如果您的内容不只是一行:

import math 
def find_all(your_string, search_string, max_index=math.inf, offset=0,):
    index = your_string.find(search_string, offset)

    while index != -1 and index < max_index:
        yield index
        index = your_string.find(search_string, index + 1)

s = content.replace('\n', '')

for offset in find_all(s, 'module'):
    max_index = s.find('module', offset=offset + len('module'))
    if max_index == -1:
        max_index = math.inf
    print([s[start + 1: stop] for start, stop in zip(find_all(s, '(',max_index, offset), find_all(s, ')', max_index, offset))])
6 年前
回复了 rusu_ro1 创建的主题 » curl可以工作,但python请求不能

我尝试了curl和requests,得到了相同的错误消息({“status”:0,“msg”:“error-no user data submitted”,“type”:“},下面是我的代码,以便使用请求:

import requests

headers = {
    'Referer': 'https://api3.libcal.com/room_widget.php?gid=4066&iid=1723',
}

params = (
    ('m', 'booking_mob'),
    ('iid', '1723'),
)

data = {
  'gid': '4066',
  'sid[]': '660065516',
  'fname': '<First Name>',
  'lname': '<Last Name>',
  'email': '<School Email>',
  'q1': '<Student ID>',
  'q2': '4-6',
  'q3': 'Engineering',
  'q4': 'CPE',
  'qcount': '4',
  'fid': '2166'
}

response = requests.post('https://api3.libcal.com/process_roombookings.php', headers=headers, params=params, data=data)
5 年前
回复了 rusu_ro1 创建的主题 » python:列表中每2项?[副本]

您可以使用:

for item in items[::2]:
   <your_code>