当我打开一个新文件时,有没有让Vim根据文件类型创建一个评论模糊?
我是Vim的新手.这是我正在寻找的功能.当我做:
$ vim hello.py
Run Code Online (Sandbox Code Playgroud)
我希望文件开头:
#Date Created: 24 May 2012
#Last Modified: (This is optional, really)
#Summary: (enter short summary of program here)
#Author: My Name
#License: ...
Run Code Online (Sandbox Code Playgroud)
我已经四处寻找,但我找不到解决办法.
我是numpy的新手,我的语法已经有点不舒服了.
在Octave/matlab中可以这样写的东西
1/(2*m) * (X * theta - y)' * (X*theta -y)
Run Code Online (Sandbox Code Playgroud)
在numpy成为这个
np.true_divide(((X.dot(theta)-y).transpose()).dot((X.dot(theta)-y)),2*m)
Run Code Online (Sandbox Code Playgroud)
这对我来说编写和调试要困难得多.有没有更好的方法来编写上面的矩阵运算,以使生活更轻松?
我想在我的计算机上监控上传和下载速度.一个名为conky的程序已经在conky conf中执行以下操作:
Connection quality: $alignr ${wireless_link_qual_perc wlan0}%
${downspeedgraph wlan0}
DLS:${downspeed wlan0} kb/s $alignr total: ${totaldown wlan0}
Run Code Online (Sandbox Code Playgroud)
它在我浏览时几乎实时显示了我的速度.我希望能够使用python访问相同的信息.
我有一个URL列表,但其中许多已过时,它们重定向到其主页或域中的其他页面。我想从列表中过滤掉这些网址。使用requests,如何过滤出未在原定位置打开的URL?
class ModTool(models.Model):
...
issue = models.OneToOneField(Issue)
priority = models.CharField(max_length=1, choices=PRIORITY, blank=True)
status = models.CharField(max_length=1, choices=STATUS, default='O', blank=True)
Run Code Online (Sandbox Code Playgroud)
网址
url(r'^moderate/(?P<pk>\d+)', ModEdit.as_view(),name='moderation')
Run Code Online (Sandbox Code Playgroud)
视图
class Modedit(UpdateView):
model = ModTool
template_name = 'myapp/moderate.html'
fields = ['priority','status']
Run Code Online (Sandbox Code Playgroud)
此时我无法弄清楚如何设置此视图来编辑具有在pk中给出的问题的onetoonefield的特定ModTool实例.
我有一个我想确认的生成器已经结束(在程序的某一点.我在python 2.7中使用unittest
# it is a generator whould have only one item
item = it.next()
# any further next() calls should raise StopIteration
self.assertRaises(StopIteration, it.next())
Run Code Online (Sandbox Code Playgroud)
但它失败了
======================================================================
ERROR: test_productspider_parse_method (__main__.TestMyMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/myName/tests/__main__.py", line 94, in test_my_method
self.assertRaises(StopIteration, it.next())
StopIteration
----------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud) 所以我试图捕获Webdriver异常,并且不希望它的回溯污染我的日志.这是一些代码
from selenium.common.exceptions import TimeoutException, WebDriverException
try:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '.loading')))
except TimeoutException:
log.msg("Seneium Timeout: {}".format(response.url))
except WebDriverException as e:
log.msg("Selenium Exception: {0} Message: {1}".format("my message", str(e)))
finally:
driver.quit()
Run Code Online (Sandbox Code Playgroud)
但我仍然得到这些:
<full traceback here>
selenium.common.exceptions.WebDriverException: Message: Can not connect to GhostDriver
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在学习 Erlang 并试图理解原子的概念。我知道 Python:用简单的术语或与 Python 类似的方式对这些“原子”有什么好的解释。到目前为止,我的理解是类型就像一个字符串但没有字符串操作?
#!/bin/sh
INTERVAL=1
COUNT=0
while [ $COUNT -le 9 ]
do
(( COUNT++ ))
sleep $INTERVAL
echo "count is $COUNT"
done
Run Code Online (Sandbox Code Playgroud)
执行时.
$ sh ascript
ascript: 9: COUNT++: not found
count is 0
ascript: 9: COUNT++: not found
count is 0
ascript: 9: COUNT++: not found
count is 0
ascript: 9: COUNT++: not found
count is 0
ascript: 9: COUNT++: not found
count is 0
ascript: 9: COUNT++: not found
count is 0
ascript: 9: COUNT++: not found
count is 0 …Run Code Online (Sandbox Code Playgroud) 我正在抓取一个网页,该网页在其html标签中没有使用任何有用的类或ID,因此我不得不废弃所有链接并在链接中查找模式.以下是html示例的样子
<span>Category</span><link href='example.com/link-about-a'>A</a>
Run Code Online (Sandbox Code Playgroud)
在另一页上,我们可能有不同的类别
<span>Category</span><link href='example.com/link-about-b'>B</a>
Run Code Online (Sandbox Code Playgroud)
使用beautifulsoup4,我目前的解决方案看起来像这样
def category(soup):
for x in soup.find_all('a'):
if 'link-about-a' in x['href']:
return 'A'
if 'link-about-b' in x['href']:
return 'B'
Run Code Online (Sandbox Code Playgroud)
等等..但这很难看.
我想知道是否有办法让这个更简洁.
喜欢使用字典
categories = {'A': 'link-about-a', 'B': 'link-about-b'}
Run Code Online (Sandbox Code Playgroud)
并将其减少为单个表达式.