小编Chr*_*son的帖子

在Python的列表中对__str__感到困惑

来自Java背景,我明白__str__这就像是toString的Python版本(虽然我确实认识到Python是较旧的语言).

所以,我已经定义了一个小类以及__str__如下方法:

class Node:

    def __init__(self, id):
        self.id = id
        self.neighbours = []
        self.distance = 0


    def __str__(self):
        return str(self.id)
Run Code Online (Sandbox Code Playgroud)

然后我创建了一些它的实例:

uno = Node(1)    
due = Node(2)    
tri = Node(3)    
qua = Node(4)
Run Code Online (Sandbox Code Playgroud)

现在,尝试打印其中一个对象时的预期行为是打印相关值.这也发生了.

print uno
Run Code Online (Sandbox Code Playgroud)

产量

1
Run Code Online (Sandbox Code Playgroud)

但是当我做以下事情时:

uno.neighbours.append([[due, 4], [tri, 5]])
Run Code Online (Sandbox Code Playgroud)

然后

print uno.neighbours
Run Code Online (Sandbox Code Playgroud)

我明白了

[[[<__main__.Node instance at 0x00000000023A6C48>, 4], [<__main__.Node instance at 0x00000000023A6D08>, 5]]]
Run Code Online (Sandbox Code Playgroud)

在哪里我期待

[[2, 4], [3, 5]]
Run Code Online (Sandbox Code Playgroud)

我错过了什么?还有什么其他令人讨厌的东西我在做什么?:)

python printing string list tostring

113
推荐指数
5
解决办法
18万
查看次数

Android Studio"无法解析符号字符串"

我有一个在Eclipse中启动的小项目.然后我将其导出到gradle文件,并将其导入AS(0.5.7).

起初,似乎没有多少工作,但在"build => make project"之后,我似乎没有得到任何突出显示的错误.

所以我尝试将应用程序运行到模拟设备.好吧,该设备从未启动,现在我在"String","ArrayList"等提及下得到红色波浪线,称它"无法解析符号".

什么f?

我尝试过清理和重建,以及"使用gradle文件同步项目".

我从哪里开始?我想继续在AS开发这么糟糕!

编辑:项目设置的屏幕截图:http://i.imgur.com/ycNyPaT.png

build.gradle的内容:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the …
Run Code Online (Sandbox Code Playgroud)

android android-studio

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

完全从Visual Studio 2013中删除Resharper Ultimate

我使用Resharper 8运行Visual Studio 2013,一切都很好,花花公子,直到我试图安装Jetbrain的Dottrace试用版.它带来了一个名为Resharper Ultimate的东西,它反过来确保我的Intellisense或Resharper功能都不起作用.

所以我使用Windows卸载功能卸载了Resharper Ultimate.但Visual Studio似乎仍然认为它已安装,因为它的选项出现在程序的首选项对话框中.更不用说顶级菜单选择了.

我也尝试重新安装Resharper 8,希望它能清除我的Ultimate机器,但它没有检测到以前的安装.所以现在,我正在为Resharper和Resharper Ultimate获得选项对话框.并没有任何功能.

另外,在使用Resharper激活解决方案时,我收到此错误消息:

在此输入图像描述

我查看了上面提到的XML文件,但我不知道该怎么做.

resharper uninstall visual-studio-2013

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

为什么Java的RoundingMode HALF_UP在-2.5到-3之间?

RoundingMode允许程序员指定以什么方式舍入浮点数.这很好,但是有一件事我觉得很奇怪.也许我只是误解了学校的一些基本知识.

但这种舍入模式被描述为我在学校教授的那种,"总是四舍五入到最接近的数字,当死在中心时,总是向上舍入.",但为什么它在-2.5到-3之间?

我总结说它在绝对值方面是四舍五入的,但对于我来说,-2肯定是从-2.5"上升".

java rounding

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

Android Studio中的Gradle执行错误(Ubuntu)

我全新安装了Ubuntu和Android Studio.我已经安装了open jdk7(出于某种原因,它最终出现在后缀为"amd64"的目录中,即使我运行的是Intel CPU,但我想这只是一个名字?)以及一些SDK文件.

然后我创建了一个空项目,现在我在窗口底部附近显示错误.我想这是一个Gradle错误(对AS来说很新)

Error:Execution failed for task ':app:mergeDebugResources'.
> /root/AndroidStudioProjects/HockeyGame/app/build/exploded-aar/com.android.support/appcompat-v7/19.1.0/res/drawable-xxhdpi/abc_ic_voice_search.png: Error: Cannot run program "/opt/android-studio/sdk/build-tools/android-4.4.2/aapt": error=2, No such file or directory
Run Code Online (Sandbox Code Playgroud)

我想也许这是一个文件权限问题(因为aapt确实存在),所以我将权限设置为775递归.我也开始使用sudo(sudo sh studio.sh).

有任何想法吗?我在Android中部分尝试AS,因为我在使用混乱的Windows安装(以及它的乐趣)下运行时遇到了问题,所以这是令人失望的.

编辑:事实证明,64位Ubuntu不适合运行开箱即用的32位可执行文件.

ubuntu android gradle android-studio

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

多线程C#拆分循环

我有一个任务,该任务本质上循环遍历一个集合,并成对地对它们进行操作(对于int i = 0; i <limit; i + = 2等),因此,我在线程循环上看到的大多数建议都使用某种foreach机制。但这对我来说似乎有点棘手,因为我是如何使用这种成对操作的方法的。

所以我想做的基本上是替换:

DoOperation(list.Take(numberToProcess));
Run Code Online (Sandbox Code Playgroud)

Thread lowerHalf = new Thread(() => => DoOperation(list.Take(numberToProcess/2)));

Thread lowerHalf = new Thread(() => => DoOperation(list.getRange(numberToProcess/2, numberToProcess));

lowerHalf.Start();
upperHalf.Start();
Run Code Online (Sandbox Code Playgroud)

这似乎可以完成工作,但是非常慢。每次迭代都比上一次慢,并且在我调试时,“线程”视图显示越来越多的“线程”列表。

但是我给人的印象是线程在完成时就终止了?是的,线程确实完成了。DoOperation()方法几乎只是一个for循环。

那我在这里不明白什么呢?

c# parallel-processing multithreading

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

Viisual Studio 2015在更新2后未在范围内查找变量

我在一个解决方案中有一个.NET核心项目和一个Xunit项目,我突然遇到调试问题.这似乎与昨天安装更新2同时发生.

在调试和命中断点时,只有少数几个参数显示在本地,汽车,监视或从即时窗口可以访问.我认为,但尚未100%验证,我可以访问的变量是全局变量,并且作为参数传递给函数.

例如,看看这个测试的一部分:

 public void UniTest4()
        {
            var s = @"{
                ""id"": ""0001"",

                ""type"": ""donut"",
                ""name"": ""Cake"",
                ""ppu"": 0.55,
                ""batters"":
                    {
                            ""batter"":
                            [
                                { ""id"": ""1001"", ""type"": ""Regular"" },
                                { ""id"": ""1002"", ""type"": ""Chocolate"" },
                                { ""id"": ""1003"", ""type"": ""Blueberry"" },
                                { ""id"": ""1004"", ""type"": ""Devil's Food"" }
                            ]
                    },
                ""topping"":
                    [
                        { ""id"": ""5001"", ""type"": ""None"" },
                        { ""id"": ""5002"", ""type"": ""Glazed"" },
                        { ""id"": ""5005"", ""type"": ""Sugar"" },
                        { ""id"": ""5007"", ""type"": ""Powdered Sugar"" },
                        { ""id"": ""5006"", …
Run Code Online (Sandbox Code Playgroud)

debugging visual-studio visual-studio-2015

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

读取空间分隔整数

我要从stdin读取一堆空格分隔的整数(35 33 2 3 251等).输入可以是数百万英镑,所以我想确保尽可能快地读取.目前,我很确定这不是这种情况:)

这就是我所拥有的:

string[] stringArr = Console.ReadLine().Split(' ');
var len = stringArr.Length;
int[] intArr = new int[len];
for (int i = 0; i < len; i++)
    intArr[i] = Convert.ToInt32(stringArr[i]);     
Run Code Online (Sandbox Code Playgroud)

以上就是诀窍,但对我来说似乎很笨拙.我过去在C#中并没有真正使用stdin,但我想有更快的方法可以做到这一点?

c# performance input

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

启动 WCG 服务时出现 System.Configuration.ConfigurationErrorsException

此刻有些慌张。我正在尝试为客户安装软件更新,但不知何故我的 WCF 服务失败并给我一条我以前从未见过的错误消息。有没有人有任何想法?

日志名称:应用程序
来源:.NET 运行时
日期:2014-01-03 16:03:36
事件 ID:1026
任务类别:无
级别:错误
关键词:经典
用户:不适用
计算机:SERVER.NM.LOCAL
描述:
应用程序:MyApp.Web.Trading.WindowsServiceHost.exe
框架版本:v4.0.30319
描述:进程因未处理的异常而终止。
异常信息:System.Configuration.ConfigurationErrorsException
堆:
   在 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
   在 System.Configuration.BaseConfigurationRecord.GetSection(System.String)
   在 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
   在 System.Configuration.ConfigurationManager.GetSection(System.String)
   在 System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetSectionFromConfigurationManager(System.String)
   在 System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetConfigurationSection(System.String)
   在 System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(System.Configuration.ContextInformation, System.String)
   在 System.ServiceModel.Description.ConfigLoader.LookupService(System.String)
   在 System.ServiceModel.ServiceHostBase.ApplyConfiguration()
   在 System.ServiceModel.ServiceHostBase.InitializeDescription(System.ServiceModel.UriSchemeKeyedCollection)
   在 System.ServiceModel.ServiceHost.InitializeDescription(System.Type, System.ServiceModel.UriSchemeKeyedCollection)
   在 System.ServiceModel.ServiceHost..ctor(System.Type, System.Uri[])
   在 MyApp.Web.Trading.ServiceImplementations.Wcf.Start()
   在 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   在 System.Threading.ThreadHelper.ThreadStart()

.net wcf

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