我知道microsoft word文档对象模式,想使用python作为开发语言 win32com 和 pywin32 之间有什么区别。我尝试过但找不到答案。请指导我如何使用 python 3.X。
这就是我尝试定义模型的方式models.py
from django.db import models
class Country(models.Model):
class Countries(models.TextChoices):
US = 'US', 'United States'
EP = 'EP', 'Europe'
IND = 'IN', 'India'
name = models.CharField(max_length=2,
choices=Countries.choices,
blank=True)
def __str__(self):
return getattr(self.Countries, self.name)
Run Code Online (Sandbox Code Playgroud)
str调用仅给出两个字母的国家/地区代码。我如何获得完整信息,例如US (United states)或US, United States
当我手动添加国家/地区时,admin它会显示全名。它一定是从某种方式得到的。
我想根据 url 将 html 保存到文件中。
为 url 获取唯一名称我正在使用 uuid。
>>> url = "https://www.google.co.in/?gfe_rd=cr&ei=-koUWPf4HqzT8ge2g6HoBg&gws_rd=ssl"
>>> uuidstring = str(uuid.uuid5(uuid.NAMESPACE_DNS, url))
Run Code Online (Sandbox Code Playgroud)
但我想进一步缩短名称。有什么方法可以将字符串缩短为唯一的小字符串。
我尝试过 base64,但我无法弄清楚。
>>> uuid.UUID(uuidstring).bytes.encode('base64').rstrip('=\n').replace('/', '_')
>>> AttributeError: 'bytes' object has no attribute 'encode'
Run Code Online (Sandbox Code Playgroud)
数据帧有两列A和B整数。
a b
1 3
4 2
2 0
6 1
...
Run Code Online (Sandbox Code Playgroud)
我需要通过以下方式交换:
if df.a > df.b:
temp = df.b
df.b = df.a
df.a = temp
Run Code Online (Sandbox Code Playgroud)
预期输出:
a b
1 3
2 4 <----
0 2 <----
1 6 <----
Run Code Online (Sandbox Code Playgroud)
基本上总是在 A 列中具有两者中较小的值。
我觉得我应该使用,loc但我还没有找到正确的方法。
我昨天刚刚学习了 python 3.5 的异步。
这就是我今天想要完成的任务。
import asyncio
import time
import requests
async def foo():
"""Some Long Running Taks"""
requests.get("http://stackoverflow.com/questions/41301031/asyncio-on-long-running-task")
print("foo")
async def bar():
"""Some Quick Task"""
print("bar")
while True:
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(foo(), bar()))
loop.close()
time.sleep(2)
#Expected output
"""
>>>bar
>>>bar
>>>bar
>>>bar
>>>bar
>>>foo
and so on
"""
Run Code Online (Sandbox Code Playgroud)
使用 python async/await 可以吗?
我找不到任何从 python playwright 返回外部 html 的方法 page.locator(selector, **kwargs)。我错过了什么吗?
locator.inner_html(**kwargs)确实存在。但是,我尝试使用 pandas.read_html ,但它在表定位器内部 html 上失败,因为它触发了表标记。
我目前正在做的是使用 bs4 来解析 page.content()。就像是:
soup = BeautifulSoup(page.content(), 'lxml')
df = pd.read_html(str(soup.select('table.selector')))
Run Code Online (Sandbox Code Playgroud) from openpyxl import Workbook
book = Workbook()
for country in "IN US JP UK".split():
book.create_sheet(title=country)
Run Code Online (Sandbox Code Playgroud)
这将创建5张纸,而第一张纸是不需要的。
我知道我可以这样做:
book = Workbook()
us_ws = book.active
us_ws.title = "IN"
for country in "US JP UK".split():
book.create_sheet(title=country)
Run Code Online (Sandbox Code Playgroud)
有捷径吗?
我有numpy 2d数组有重复值.
我正在搜索这样的数组.
In [104]: import numpy as np
In [105]: array = np.array
In [106]: a = array([[1, 2, 3],
...: [1, 2, 3],
...: [2, 5, 6],
...: [3, 8, 9],
...: [4, 8, 9],
...: [4, 2, 3],
...: [5, 2, 3])
In [107]: num_list = [1, 4, 5]
In [108]: for i in num_list :
...: print(a[np.where(a[:,0] == num_list)])
...:
[[1 2 3]
[1 2 3]]
[[4 8 9]
[4 2 3]]
[[5 2 3]]
Run Code Online (Sandbox Code Playgroud)
输入是具有与列0值类似的数字的列表.我想要的最终结果是任何格式的结果行,例如array,list或tuple …
我正在尝试依次打印 2 个列表中的内容。
ls1 = ['Apple', 'Orange', 'Banana', 'Morty']
ls2 = ['Pineapple', 'Carrot', 'Rick', 'Tangelo']
Run Code Online (Sandbox Code Playgroud)
我通常会这样做:
for fruit in ls1:
print(fruit)
for fruit in ls2
print(fruit)
Run Code Online (Sandbox Code Playgroud)
但这将循环遍历一个列表,然后再循环另一个列表。我希望输出按顺序在列表之间交替:
Apple
Pineapple
Orange
...etc...
Run Code Online (Sandbox Code Playgroud)
或者
ls1[0]
ls2[0]
ls1[1]
ls2[1]
...etc...
Run Code Online (Sandbox Code Playgroud) 当我运行my时dockerfile,我得到正确的输出:
Performing system checks...
System check identified no issues (0 silenced).
July 31, 2017 - 11:00:32
Django version 1.11.3, using settings 'tufleur.settings'
Starting development server at http://127.0.0.1:8002/
Quit the server with CONTROL-C.
Run Code Online (Sandbox Code Playgroud)
这是我的dockerfile
FROM django:onbuild
# Install Python dependencies
RUN pip install django
#CMD ["pwd"]
RUN ./manage.py makemigrations
RUN ./manage.py migrate
#RUN ./manage.py collectstatic
EXPOSE 8002
#Run Server
CMD ./manage.py runserver 127.0.0.1:8002
Run Code Online (Sandbox Code Playgroud)
但是在浏览器中,django的欢迎页面没有显示,
您能帮我找到问题吗,因为我找不到任何问题
python ×10
django ×2
arrays ×1
docker ×1
dockerfile ×1
list ×1
numpy ×1
openpyxl ×1
pandas ×1
playwright ×1
python-3.x ×1
pywin32 ×1
win32com ×1