小编Mic*_*unn的帖子

vim中的正则表达式unicode字符

我是个白痴.

有人将微软单词中的一些文字剪切并粘贴到我可爱的html文件中.

我现在有这些unicode字符而不是常规引号符号(即引号在文本中显示为<92>)

我想做一个正则表达式替换,但我在选择它们时遇到了麻烦.

:%s/\u92/'/g
:%s/\u5C/'/g
:%s/\x92/'/g
:%s/\x5C/'/g
Run Code Online (Sandbox Code Playgroud)

......都失败了.我的google-fu让我失望了.

regex unicode vim

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

修复太平洋中心(0°-360°经度)显示的地图库数据

我正在使用R maps包在世界地图上绘制一些点,例如:

世界地图,-180°至180°经度

绘制基本地图的命令是:

map("world", fill=TRUE, col="white", bg="gray", ylim=c(-60, 90), mar=c(0,0,0,0))
Run Code Online (Sandbox Code Playgroud)

但我需要显示太平洋中心地图.我使用map("world2",etc来使用maps包中的太平洋中心底图,并将我的dataframe(df)中数据点的坐标转换为:

df$longitude[df$longitude < 0] = df$longitude[df$longitude < 0] + 360
Run Code Online (Sandbox Code Playgroud)

如果我不使用该fill选项,但是使用fill交叉0°的多边形会导致问题.

世界地图,0°至360°经度

我想我需要以maps某种方式从库中转换多边形数据来对其进行排序,但我不知道如何解决这个问题.

我理想的解决方案是绘制一个左边界为-20°,右边界为-30°(即330°)的地图.以下内容将正确的点和海岸线放到地图上,但是交叉零问题是相同的

df$longitude[df$longitude < -20] = df$longitude[d$longitude < -20] + 360
map("world", fill=TRUE, col="white", bg="gray", mar=c(0,0,0,0),
  ylim=c(-60, 90), xlim=c(-20, 330))
map("world2", add=TRUE, col="white", bg="gray", fill=TRUE, xlim=c(180, 330))
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

maps r

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

如何在django中为DeleteView添加取消按钮

在Django中为"基于类"的通用视图添加"取消"按钮的最佳方法是什么?

在下面的示例中,我希望取消按钮将您带到success_url不删除对象.我试过<input type="submit" name="cancel" value="Cancel" />在模板上添加一个按钮.我可以通过覆盖类的post方法来检测是否按下了这个按钮AuthorDelete,但我无法弄清楚如何从那里重定向.

示例myapp/views.py:

from django.views.generic.edit import DeleteView
from django.core.urlresolvers import reverse_lazy
from myapp.models import Author

class AuthorDelete(DeleteView):
    model = Author
    success_url = reverse_lazy('author-list')

    def post(self, request, *args, **kwargs):
        if request.POST["cancel"]:
            return ### return what? Can I redirect from here?
        else:
            return super(AuthorDelete, self).post(request, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

示例myapp/author_confirm_delete.html:

<form action="" method="post">{% csrf_token %}
    <p>Are you sure you want to delete "{{ object }}"?</p>
    <input type="submit" value="Confirm" />
    <input type="submit" name="cancel" value="Cancel" /> …
Run Code Online (Sandbox Code Playgroud)

django django-class-based-views

13
推荐指数
3
解决办法
8947
查看次数

从纬度/经度坐标计算像素值(使用matplotlib底图)

我需要将地图坐标转换为像素(以便在html中制作可点击的地图).

这是一个示例映射(使用matplotlib中的Basemap包制作).我在其上放了一些标签,并尝试以像素为单位计算标签的中点:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

## Step 0: some points to plot
names = [u"Reykjavík", u"Höfn", u"Húsavík"]
lats = [64.133333, 64.25, 66.05]
lons = [-21.933333, -15.216667, -17.316667]

## Step 1: draw a map using matplotlib/Basemap
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

M = Basemap(projection='merc',resolution='c',
            llcrnrlat=63,urcrnrlat=67,
            llcrnrlon=-24,urcrnrlon=-13)

x, y = M(lons, lats) # transform coordinates according to projection
boxes = []
for xa, ya, name in zip(x, y, names):
    box = plt.text(xa, ya, name,
        bbox=dict(facecolor='white', …
Run Code Online (Sandbox Code Playgroud)

python matplotlib geospatial

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

在R中绘制没有边距的地图

我正试图摆脱使用R中的'maps'包生成的地图边缘.我通过par(mar=c(0,0,0,0))map()函数中设置和使用border = 0选项获得了一些方法.但与例如散射图相比,mar=c(0,0,0,0)仍然有很多额外的空间.以下是生成示例地图的一些代码,以及用于比较的常规散点图.

library(maps)
x <- sample(360, 10)-180
y <- sample(160, 10)-80
x.boundary <- c(-180, 180, 0, 0)
y.boundary <- c(0, 0, -80, 80)

pdf("map.tmp.pdf", width=9, height=4)
par(mar=rep(0,4))
map("world", border=0, ylim=c(-80, 80), fill=TRUE, bg="gray", col="white")
points(x, y, pch=19, col="blue")
points(x.boundary, y.boundary, pch=19, col="red")
# map.axes()
dev.off()

pdf("scatter.tmp.pdf", width=9, height=4)
par(mar=rep(0,4))
plot(x, y, xlim=c(-180, 180), ylim=c(-80, 80), pch=19, col="blue")
points(x.boundary, y.boundary, pch=19, col="red")
dev.off()
Run Code Online (Sandbox Code Playgroud)

如果取消注释该map.axes()功能,您可以看到即使边缘被概念性地抑制,也为轴保留了空间.

任何想法都非常感激,这已经困扰了我多年.

maps r

7
推荐指数
1
解决办法
4488
查看次数

在Django/South HOWTO中,在DataMigration期间从不同的应用程序创建模型的实例

我需要在应用程序问题中执行模型答案的数据迁移.在该脚本中存在依赖性,因此我需要创建应用程序日记中的模型的实例.所以,我把它编码如下:

def forwards(self, orm):
    for answer_object in orm.Answer.objects.all():

        #This Works.
        blog, is_created = orm['blog.Post'].objects.get_or_create(title=answer_object.answer[:100])
        blog.save()

        #This DOES NOT work
        chapter, is_created = orm['journal.Chapter'].objects.get_or_create(content_object=blog)
        chapter.save()
        #cleanup task, not relevant to this question below
        answer_object.chapter_ptr = chapter
        answer_object.save()
Run Code Online (Sandbox Code Playgroud)

但正如预期的那样,这会在"orm ['journal.Chapter']上引发错误.objects.get_or_create(content_object = blog)"

django.core.exceptions.FieldError: Cannot resolve keyword 'content_object' into field.
Run Code Online (Sandbox Code Playgroud)

这可能是由于content_object是GenericForeignKey,因此不允许进行某些操作.但我也尝试了其他替代方法来创建"章节"对象,比如

chapter = orm['journal.Chapter'](content_object=blog)
ERROR > TypeError: 'content_object' is an invalid keyword argument for this function
Run Code Online (Sandbox Code Playgroud)

chapter = orm.journal.Chapter(content_object=blog)
 ERROR > AttributeError: The model …
Run Code Online (Sandbox Code Playgroud)

django data-migration instantiation django-south generic-foreign-key

7
推荐指数
1
解决办法
3415
查看次数

如何从过滤的有序查询集中获取上一个和下一个对象?

我有一个基于模型对象的页面,我想要链接到上一页和下一页.我不喜欢我当前的解决方案,因为它需要评估整个查询集(以获取ids列表),然后再需要两个get查询.当然有一些方法可以一次完成吗?

def get_prev_and_next_page(current_page):
    ids = list(Page.objects.values_list("id", flat=True))
    current_idx = ids.index(current_page.id)
    prev_page = Page.objects.get(id=ids[current_idx-1])
    try:
        next_page = Page.objects.get(id=ids[current_idx+1])
    except IndexError:
        next_page = Page.objects.get(id=ids[0])
    return (prev_page, next_page)
Run Code Online (Sandbox Code Playgroud)

排序顺序在模型中定义,因此不必在此处理,但请注意,您不能假设ID是顺序的.

django django-models django-queryset

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

具有单元和集成测试的 python 项目的典型文件夹结构?

使用的典型结构和路径/导入约定是什么?有没有人有代表性的python项目的链接?

project.scratch/
    project/
        scratch/
            __init__.py
            dostuff.py
            tests/
                unit/
                    test_dostuff.py
                integration/
                    test_integration.py
Run Code Online (Sandbox Code Playgroud)

python unit-testing

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

根据2个不同变量的值从矩阵中进行选择

假设我有一个矩阵,其响应变量的值为一列,两个特征,如性别和位置,作为另外两列.

如何根据性别和位置的具体值选择响应的特定值?

例如,我知道

数据集$响应[性别=="男"]

将选择所有男性.但是我想要从位置=='SE'的男性中选择响应值.我不知道该怎么做.

非常感谢!

ps(我尝试在互联网上寻找这个,但很难找到[]运营商的帮助)

r matrix selection logical-operators

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

按组python连接字符串

我想将一个字符串列表连接成一个按列表中的值分组的新字符串.这是我的意思的一个例子:

输入

key = ['1','2','2','3']
data = ['a','b','c','d']
Run Code Online (Sandbox Code Playgroud)

结果

newkey = ['1','2','3']
newdata = ['a','b c','d']
Run Code Online (Sandbox Code Playgroud)

我理解如何加入文字.但我不知道如何正确迭代列表的值以聚合相同键值共有的字符串.

任何帮助或建议表示赞赏.谢谢.

python string group-by string-concatenation

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

尝试在iOS 7上的集合视图中加载图像时出现内存警告

在iOS7上的Collection View中加载图像时,我收到此警告

警告: failed to set breakpoint site at 0x11428984c for breakpoint 1.1: Unable to read memory at breakpoint address.

这就是我加载图像的方式

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView1
              cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
cellDesign* newCell = [collectionView1 dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
NSString *str = [combinedArrays[indexPath.section] objectAtIndex:indexPath.row];
newCell.templateName.text = str
newCell.displayTemplate.image = [UIImage imageNamed:str];
return newCell;
}
Run Code Online (Sandbox Code Playgroud)

memory-leaks objective-c uiimage uicollectionview ios7

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