我是shell脚本的新手,有人可以帮忙吗?我想删除文件夹中的脚本,从当前日期回到10天.脚本如下:
2012.11.21.09_33_52.script
2012.11.21.09_33_56.script
2012.11.21.09_33_59.script
Run Code Online (Sandbox Code Playgroud)
该脚本将每隔10天与Crontab一起运行,这就是我需要当前日期的原因.
我有一个导入Pillow库的python文件.我可以打开图像
Image.open(test.png)
Run Code Online (Sandbox Code Playgroud)
但是如何关闭该图像呢?我没有使用Pillow来编辑图像,只是为了显示图像并允许用户选择保存或删除它.
我不知道是否有这样的事情 - 但我正在努力做一个有序的字典理解.但它似乎没有用?
import requests
from bs4 import BeautifulSoup
from collections import OrderedDict
soup = BeautifulSoup(html, 'html.parser')
tables = soup.find_all('table')
t_data = OrderedDict()
rows = tables[1].find_all('tr')
t_data = {row.th.text: row.td.text for row in rows if row.td }
Run Code Online (Sandbox Code Playgroud)
它现在仍然是一个正常的字典理解(我也遗漏了对汤样板的通常要求).有任何想法吗?
我正在尝试缓存静态内容,这些内容基本上位于虚拟服务器配置中的下面路径中.由于某种原因,文件未被缓存.我在缓存目录中看到了几个文件夹和文件,但它总是像20mb那样不高不低.如果它是缓存图像,例如将占用至少500mb的空间.
这是nginx.conf缓存部分:
** nginx.conf **
proxy_cache_path /usr/share/nginx/www/cache levels=1:2 keys_zone=static$
proxy_temp_path /usr/share/nginx/www/tmp;
proxy_read_timeout 300s;
Run Code Online (Sandbox Code Playgroud)
这是默认的虚拟服务器.
**sites-available/default**
server {
listen 80;
root /usr/share/nginx/www;
server_name myserver;
access_log /var/log/nginx/myserver.log main;
error_log /var/log/nginx/error.log;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location ~* ^/(thumbs|images|css|js|pubimg)/(.*)$ {
proxy_pass http://backend;
proxy_cache static;
proxy_cache_min_uses 1;
proxy_cache_valid 200 301 302 120m;
proxy_cache_valid 404 1m;
expires max;
}
location / {
proxy_pass http://backend;
}
}
Run Code Online (Sandbox Code Playgroud) python最近添加了pathlib模块(我非常喜欢!).
只有一件事我正在努力:是否可以规范化不存在的文件或目录的路径?我能完美地做到这一点os.path.normpath.但是,除了应该处理路径相关内容的库以外,还有什么不是荒谬的吗?
我想要的功能是:
from os.path import normpath
from pathlib import Path
pth = Path('/tmp/some_directory/../i_do_not_exist.txt')
pth = Path(normpath(str(pth)))
# -> /tmp/i_do_not_exist.txt
Run Code Online (Sandbox Code Playgroud)
但无需诉诸os.path和不必输入str和返回Path.也pth.resolve()不会为不存在的文件.
有一个简单的方法pathlib吗?
Python的新类型提示功能允许我们输入函数返回的提示None...
def some_func() -> None:
pass
Run Code Online (Sandbox Code Playgroud)
...或者保留未指定的返回类型,PEP规定应该使静态分析器假定任何返回类型都是可能的:
任何没有注释的函数都应该被视为具有最普遍的类型
但是,我应该如何键入一个函数永远不会返回的提示?例如,键入提示这两个函数的返回值的正确方法是什么?
def loop_forever():
while True:
print('This function never returns because it loops forever')
def always_explode():
raise Exception('This function never returns because it always raises')
Run Code Online (Sandbox Code Playgroud)
-> None在这些情况下,指定或保留未指定的返回类型似乎都不正确.
我正在gdb用来调试C++程序.在线
assert(prevId == GetTagIdFromState(maxState));
Run Code Online (Sandbox Code Playgroud)
prevId值是0;GetTagIdFromState(maxState) returns 50;调试时,我收到以下错误.
Assertion `prevId == GetTagIdFromState(maxState)' failed.
Program received signal SIGABRT, Aborted.
0x00007ffff6ecbba5 in raise (sig=<value optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
in ../nptl/sysdeps/unix/sysv/linux/raise.c
Run Code Online (Sandbox Code Playgroud) 所以这是我的设置:
我有一张桌子如:
Id, Lat, Long, GeoPoint, GeomPoint
两个GeoPoint(地理)和GeomPoint(几何)设置为SRID 4326
我有以下查询:
DECLARE @radiiCollection TABLE
( [ID] INT IDENTITY(1, 1) PRIMARY KEY,
[Radius] GEOMETRY,
[RefPoint] GEOMETRY,
[RefAddr] VARCHAR(255),
[MinLat] VARCHAR(255),
[MaxLat] VARCHAR(255),
[MinLng] VARCHAR(255),
[MaxLng] VARCHAR(255))
DECLARE @point GEOMETRY = geometry::Point(-111.84493459999999, 33.3902569, 4326)
DECLARE @gpoint GEOGRAPHY = geography::Point(33.3902569, -111.84493459999999, 4326);
INSERT INTO @radiicollection
(radius,
refpoint,
refaddr,
maxlat,
maxlng,
minlat,
minlng)
VALUES ( @point.MakeValid().STBuffer(16093.40),
@point,
'10 miles of 85210',
33.51734689767781,
-111.6923852740045,
33.26298081643247,
-111.99703818130439 )
SELECT
GeomPoint,
GeoPoint
INTO #temp …Run Code Online (Sandbox Code Playgroud) 这是在wxPython的Phoenix分支中.
为了不阻止GUI,我试图运行一些线程.
我的两个线程工作正常,但另一个线程似乎永远不会达到其绑定结果函数.我可以告诉它正在运行,它似乎没有正确发布事件.
这是主计算线程的结果函数:
def on_status_result(self, event):
if not self.panel.progress_bar.GetRange():
self.panel.progress_bar.SetRange(event.data.parcel_count)
self.panel.progress_bar.SetValue(event.data.current_parcel)
self.panel.status_label.SetLabel(event.data.message)
Run Code Online (Sandbox Code Playgroud)
这是我绑定他们的方式:
from wx.lib.pubsub.core import Publisher
PUB = Publisher()
Run Code Online (Sandbox Code Playgroud)
这是我绑定方法的方式:
def post_event(message, data):
wx.CallAfter(lambda *a: Publisher().sendMessage(message, data=data))
Run Code Online (Sandbox Code Playgroud)
这是线程.第一个不起作用,但后两个做:
class PrepareThread(threading.Thread):
def __init__(self, notify_window):
threading.Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = False
def run(self):
while not self._want_abort:
for status in prepare_collection(DATABASE, self._previous_id, self._current_id, self._year, self._col_type,
self._lock):
post_event('prepare.running', status)
post_event('prepare.complete', None)
return None
def abort(self):
self._want_abort = True
class SetupThread(threading.Thread):
def __init__(self, notify_window):
threading.Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = False
def …Run Code Online (Sandbox Code Playgroud) 如何else在惯用的Python for循环中使用语句?没有else我可以写例如:
res = [i for i in [1,2,3,4,5] if i < 4]
Run Code Online (Sandbox Code Playgroud)
结果是: [1, 2, 3]
上述代码的正常形式是:
res = []
for i in [1,2,3,4,5]:
if i < 4:
res.append(i)
Run Code Online (Sandbox Code Playgroud)
结果与惯用形式相同: [1, 2, 3]
我想要这个:
res = [i for i in [1,2,3,4,5] if i < 4 else 0]
Run Code Online (Sandbox Code Playgroud)
我得到SyntaxError: invalid syntax.结果应该是:[1, 2, 3, 0, 0]
正常的代码是:
res = []
for i in [1,2,3,4,5]:
if i < 4:
res.append(i)
else:
res.append(0)
Run Code Online (Sandbox Code Playgroud)
结果是: [1, …
python ×6
bash ×1
c++ ×1
caching ×1
find ×1
for-loop ×1
gdb ×1
geospatial ×1
idiomatic ×1
if-statement ×1
linux ×1
nginx ×1
pillow ×1
proxy ×1
python-3.4 ×1
python-3.x ×1
shell ×1
sql ×1
sql-server ×1
type-hinting ×1
unix ×1
wxpython ×1