小编skr*_*sme的帖子

Python open()vs. .close()

关于Python中的语法

我们为什么要用它open("file")来打开而不是"file".close()关闭呢?
为什么不是"file".open()或反过来close("file")

python

8
推荐指数
2
解决办法
2051
查看次数

为什么在STL映射中用作值的类需要...中的默认构造函数?

下面是用作地图中值的类:

class Book
{
    int m_nId;
public:
    // Book() { }  <----- Why is this required?
    Book( int id ): m_nId( id ) { }

};
Run Code Online (Sandbox Code Playgroud)

在main()内:

map< int, Book > mapBooks;

for( int i = 0; i &lt 10; ++i )
{
    Book b( i );
    mapBooks[ i ] = b;
}
Run Code Online (Sandbox Code Playgroud)

导致错误的声明是:

mapBooks[ i ] = b;
Run Code Online (Sandbox Code Playgroud)

如果我添加默认构造函数,则不会出现错误.但是,我不明白为什么需要.谁能解释一下?如果我使用insert(),问题不会出现.

顺便说一句,我正在使用Visual C++ 2008进行编译.

c++ dictionary stl default-constructor

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

Haskell中的两个无限数据结构之间是否可以进行相等测试?

在我正在研究的项目中,某种类型的数据有时可能包含在其中.例如,

data Example = Apple Int
             | Pear Int Example

a = Pear 10 a
b = Pear 10 b
Run Code Online (Sandbox Code Playgroud)

作为程序员,我知道a并且b是相同的,但是当我实际测试它们之间的相等时,它将无限循环,因为它们的值需要进行评估以进行比较.

有没有其他方法可以在这些数据之间进行相等测试?或者有没有办法避免像这样的问题?

haskell infinite lazy-evaluation

7
推荐指数
2
解决办法
422
查看次数

在多处理池中使用时,不会正确引发自定义异常

我正在观察Python 3.3.4中我希望帮助理解的行为:为什么在正常执行函数时正确引发异常,而不是在函数池中执行函数时?

import multiprocessing

class AllModuleExceptions(Exception):
    """Base class for library exceptions"""
    pass

class ModuleException_1(AllModuleExceptions):
    def __init__(self, message1):
        super(ModuleException_1, self).__init__()
        self.e_string = "Message: {}".format(message1)
        return

class ModuleException_2(AllModuleExceptions):
    def __init__(self, message2):
        super(ModuleException_2, self).__init__()
        self.e_string = "Message: {}".format(message2)
        return

def func_that_raises_exception(arg1, arg2):
    result = arg1 + arg2
    raise ModuleException_1("Something bad happened")

def func(arg1, arg2):

    try:
        result = func_that_raises_exception(arg1, arg2)

    except ModuleException_1:
        raise ModuleException_2("We need to halt main") from None

    return result

pool = multiprocessing.Pool(2)
results = pool.starmap(func, [(1,2), (3,4)])

pool.close()
pool.join() …
Run Code Online (Sandbox Code Playgroud)

python exception python-3.x

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

在graph_tool中添加边权重和缩放绘制的边长

我正在使用图形工具,我找不到定义边缘权重的方法.如何在图表中添加边缘权重?

另外,我想在使用时graph_draw,图表将根据重量绘制边距.我怎么能做到这一点?

python visualization graph graph-tool

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

字符驱动程序与循环缓冲区

我正在学习设备驱动程序编程,我创建了一个简单的字符驱动程序,我从用户空间应用程序传递数据并将其存储在内核空间循环缓冲区中,然后从另一个用户空间应用程序再次读取此循环缓冲区.

我使用的是linux内核版本3.3.6

我的驱动程序代码是:

/* A simple character driver program to pass some data from user space and storing that on kernel circular buffer and reading back it on user space */

#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/module.h>
#include<linux/vmalloc.h>
#include<linux/fs.h>
#include<linux/major.h>
#include<linux/cdev.h>
#include<asm/uaccess.h>
#include<linux/slab.h>
#include<linux/device.h>
#include<linux/types.h>
#include<linux/kdev_t.h>
#include<linux/wait.h>
#include<linux/sched.h>
#include<linux/circ_buf.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("C-DAC");
#define MAX_DEVICE 2
#define KERN_BUFF_SIZE 1
#define DRIVER_NAME "ass3q1" 

int my_open(struct inode *inode, struct file *filp);
ssize_t my_write(struct file *filp, const char __user *usr_buff, size_t count, loff_t *ppos);
ssize_t my_read(struct file *filp, …
Run Code Online (Sandbox Code Playgroud)

c kernel linux-device-driver linux-kernel

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

我如何审核git rerere的决议?

背景

我目前正在解决与启用git rerere的合并冲突.git status显示一条未合并的路径.当我查看文件时,没有<<<<<<< HEAD>>>>>>> <SHA>标记识别冲突,这告诉我rerere已经完成了它的工作并根据我过去的方式解决了冲突.

我想确认rerere的决议是正确的.

我正在进行的合并过程非常复杂,涉及到Linux内核的多个遥控器.我昨天做了几个遥控器的测试合并,目的是识别冲突,通知维护者,然后丢弃最终的(肯定已损坏的)内核.在这样做的时候,我做了几个不小心的冲突解决方案,只是为了继续下一个遥控器,并且git rerere forget <pathspec>在我完成之后调用了所有冲突的路径,包括我正在处理的那个.因为我告诉rerere忘记这条路径,我不知道为什么它在这次运行中解决了任何问题,我担心它应用了我昨天做的修复,当时我不在乎结果是否正确.

问题

是否有任何方法可以查看在已经应用解决方案后重新解决的冲突?

我想避免重新启动合并,因为这是一个漫长的过程,我们还没有完全自动化.此外,因为我试图告诉rerere昨天忘记了这条路,但它今天仍然应用了一个解决方案,我想如果我不知道为什么git rerere forget <pathspec>先失败,我会最终处于相同的位置.

相关问题
撤消在rebase中完成的git rerere解决 方案< - 解决方案需要重新启动合并
启用git rerere是否有任何缺点?< - 只讨论git rerere forget <pathspec>

跟进注意/问题
我刚尝试输入git rerere forget没有pathspec,我知道这是不赞成的,但如果我理解正确,应该让rerere忘记所有的决议.我重新合并,它仍然对文件应用了一个解决方案.我也完全禁用了rerere并且第三次运行合并,所以我可以看到冲突,而rerere确实应用了我昨天所做的半心半意的决议.为什么forget不正确地丢弃我不想重用的解决方案?

git git-merge git-rerere

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

Leaflet:从 GeoJSON 属性设置 GeoJSON 层的图标

我正在使用 GeoJSON 数据构建传单地图。尝试根据 GeoJSON 属性设置我使用的图标时遇到问题。我认为我的错误与使用字符串调用对象有关,但我无法弄清楚它到底是什么。

这是我的代码:

GeoJSON 中的每个项目都有一个 iconcategory 属性,如下所示:

{"type":"Feature",
    "properties":{
        "iconcategory": "iconGreyHouse",
            ...
Run Code Online (Sandbox Code Playgroud)

对于每个图标类别,都有一个图标变量,如下所示:

var iconGreyHouse = L.icon({
    iconUrl: "/markerIcons/house_icon_grey.png",
    iconSize: [20, 20]
});
Run Code Online (Sandbox Code Playgroud)

最后,当我加载 GeoJSON 文件时,我从 GeoJSON 属性中获取“iconcategory”,希望能够选择相应的图标变量...

$.getJSON("/GeoJSON/housemarkers.geojson", function (houses) {
    L.geoJson(houses, {
        pointToLayer: function (feature, latlng) {
            return L.marker(latlng, {
                icon: feature.properties.iconcategory
            });
        }
    }).addTo(housemarkers);
});
Run Code Online (Sandbox Code Playgroud)

这就是不行的地方!如果我使用完全相同的代码但直接指定图标变量名称,则一切正常;只有当我尝试通过 feature.property 设置图标时才会失败。

javascript geojson leaflet

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

当我尝试使用update-database命令EF6 MYSQL时AlterProcedureException

我正在尝试使用mysql连接器更改Entity Framework 6中的表.

错误是:

PM> update-database -verbose
Using StartUp project 'Facade'.
Using NuGet project 'DAL'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'GiveAndGet' (DataSource: localhost, Provider: MySql.Data.MySqlClient, Origin: Configuration).
Applying explicit migrations: [201602122108206_2].
Applying explicit migration: 201602122108206_2.
System.NotImplementedException: AlterProcedureOperation
   en MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
   en System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList`1 operations, String migrationId)
   en System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId)
   en System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   en System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration …
Run Code Online (Sandbox Code Playgroud)

mysql entity-framework ef-migrations

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

基于浏览器语言重定向用户(不在PHP中)

我的网站将使用3种语言.法语(fr)是默认语言.该网站的结构如下:

根目录(注意:我不使用php文件,只是简单的html)

/fr/
    Index.html
    About-us.html
    Contact.html

/en/
    Index.html
    About-us.html
    Contact.html

/de/
    Index.html
    About-us.html
    Contact.html
Run Code Online (Sandbox Code Playgroud)

我有疑问:

  • 根据用户的Web浏览器语言重定向用户的最佳做法是什么?通过htaccess?
  • 我是否需要根级别的index.html页面(出于SEO原因或任何其他原因)?也许法国index.html?

html .htaccess redirect

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