小编Ray*_*y Y的帖子

使用substringWithRange提取字符串:给出"索引越界"

当我尝试从较大的字符串中提取字符串时,它会给出范围或索引超出范围的错误.我可能会忽略一些非常明显的东西.谢谢.

NSString *title = [TBXML textForElement:title1];
TBXMLElement * description1 = [TBXML childElementNamed:@"description" parentElement:item1];
NSString *description = [TBXML textForElement:description1];
NSMutableString *des1 = [NSMutableString stringWithString:description];

//search for <pre> tag for its location in the string
NSRange match;
NSRange match1;
match = [des1 rangeOfString: @"<pre>"];
match1 = [des1 rangeOfString: @"</pre>"];
NSLog(@"%i,%i",match.location,match1.location);
NSString *newDes = [des1 substringWithRange: NSMakeRange (match.location+5, match1.location-1)]; //<---This is the line causing the error

NSLog(@"title=%@",title);
NSLog(@"description=%@",newDes);
Run Code Online (Sandbox Code Playgroud)

更新:范围的第二部分是长度,而不是端点.D'哦!

cocoa objective-c nsstring nsrange

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

Python多个用户同时附加到同一文件

我正在研究一个可以通过网络访问的python脚本,因此会有多个用户试图同时附加到同一个文件.我担心这可能导致竞争条件,如果多个用户同时写入同一文件,它可能会损坏文件.

例如:

#!/usr/bin/env python

g = open("/somepath/somefile.txt", "a")
new_entry = "foobar"
g.write(new_entry)
g.close
Run Code Online (Sandbox Code Playgroud)

我是否必须使用锁定文件,因为此操作看起来很危险.

python concurrency simultaneous text-files simultaneous-calls

24
推荐指数
3
解决办法
2万
查看次数

AFNetworking包括标题

我正在尝试从ASIHttpRequest转换为AFNetworking,但我似乎在我班级的以下行中有"使用未声明的标识符AFURLSessionManager"错误.

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
Run Code Online (Sandbox Code Playgroud)

我在标题中包含以下内容:

#import "AFNetworking.h"
#import "AFURLSessionManager.h"
Run Code Online (Sandbox Code Playgroud)

它必须是非常明显的东西,但现在脑屁不好.

objective-c afnetworking-2

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

Traefik的原木在哪里?

您是否知道Traefik日志位于何处?我阅读了Traefik上的文档,并说它将输出到stdout,但是当docker-compose up -d我尝试使用域名并拉出多个链接的docker容器后,当我使用它启动docker容器时,stdout中没有显示任何内容。

我也尝试指定这些:

[traefikLog]
  filePath = "./traefik.log" #<--Tried this but It doesn't work, file empty and permissions set to 777

[accessLog]
  filePath = "./access.log" #<--Tried this but doesn't work, file empty and permissions set to 777
Run Code Online (Sandbox Code Playgroud)

我很困惑,我错过了什么吗?还是Traefik应该这么安静?

当我运行它时,这就是我所看到的,此后什么也没有。

# docker-compose up
Creating traefik ... done
Attaching to traefik
Run Code Online (Sandbox Code Playgroud)

附件是我的配置。谢谢。

traefik / traefik.toml:

logLevel = "DEBUG"
defaultEntryPoints = ["http","https"]

[api]
  address = ":8080"

[traefikLog]
  filePath = "./traefik.log" #<--Tried this but It doesn't work

[accessLog]
  filePath = "./access.log" #<--Tried …
Run Code Online (Sandbox Code Playgroud)

docker traefik

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