问题列表 - 第48742页

用python读取一个非常大的文件

处理大小约为500 MB的文本文件的每一行的最佳解决方案是什么?

我曾经想过的建议:

def files(mon_fichier):
    while True:
        data = mon_fichier.read(1024)
        if not data:
            break
        yield data

fichier = open('tonfichier.txt', 'r')
for bloc in files(fichier):
    print bloc
Run Code Online (Sandbox Code Playgroud)

先感谢您

python text file

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

0初始化C++内置类型

假设我有这个结构(或类,我的问题适用于两者):

struct builtin 
{ 
    int a;
    int b; 
    builtin() : a(), b(0) { } 
};
Run Code Online (Sandbox Code Playgroud)

我知道a和b都会被builtin的构造函数初始化为0.我的问题是:一种方法比另一种更快吗?

c++ performance initialization built-in-types

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

在类/函数定义中导入语句 - 这是一个好主意吗?

我创建了一个名为的模块util,它提供了我经常在Python中使用的类和函数.其中一些需要导入功能.在类/函数定义中导入所需内容的优点和缺点是什么?它比import模块文件的开头更好吗?这是个好主意吗?

python import class function

44
推荐指数
2
解决办法
4万
查看次数

在Javascript中查看多页TIFF

我目前有多页TIFF图像,我需要通过Javascript逐页浏览它们.

我对此一无所知.你能帮助我吗?我发现了一些其他问题,但似乎没有与Javascript相关.

谢谢.

javascript tiff

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

从IEnumerable <DateTime>获取最早的日期

我有IEnumerable<DateTime>一些日期.我如何从该系列中获得最早的约会?

谢谢!

戴夫

c# linq generics collections

11
推荐指数
2
解决办法
5665
查看次数

xlib 是否有活动窗口事件?

我正在尝试编写一个使用 Xlib 跟踪活动窗口何时更改的程序。我很难找出最好的方法来做到这一点。到目前为止,这些是我的想法:

  • 每秒使用 _NET_ACTIVE_WINDOW 获取活动窗口,如果它已更改,则运行该事件的相关代码。
  • 获取所有窗口的列表并在事件中监听它们的焦点。不过,我必须弄清楚如何保持最新的打开窗口列表。

他们是更简单/更好的方法吗?我是使用 Xlib 编程的新手。

c linux xlib xorg

4
推荐指数
2
解决办法
3010
查看次数

如何在布局上绘制

我是android的新手.

任何人都可以帮我解决这个问题.

我有一个布局,我有一个imageView.我想要的是我想在这个图像的顶部画一个矩形.矩形的高度是在运行时获得的.

我尝试使用shapeDrawable类和onDraw()方法绘制矩形.但每次我绘制我的布局都会消失,而我得到的是黑色背景中的矩形.

任何人都可以帮我这个.

android

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

使用6个以上的自定义按钮时,UIActionSheet buttonIndex值是否有问题?

我在iPhone(iOS 4.2)上使用UIActionSheet时发现了一个奇怪的问题.考虑以下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                  initWithTitle:@"TestSheet" 
                                  delegate:self 
                                  cancelButtonTitle:@"Cancel" 
                                  destructiveButtonTitle:nil 
                                  otherButtonTitles: nil];

    [actionSheet addButtonWithTitle:@"one"];
    [actionSheet addButtonWithTitle:@"two"];
    [actionSheet addButtonWithTitle:@"three"];
    [actionSheet addButtonWithTitle:@"four"];
    [actionSheet addButtonWithTitle:@"five"];
    [actionSheet addButtonWithTitle:@"six"];
    //uncomment next line to see the problem in action
    //[actionSheet addButtonWithTitle:@"seven"];

    [actionSheet showInView:window];
    [actionSheet release];

    return YES;
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"buttonIndex: %d, cancelButtonIndex: %d, firstOtherButtonIndex: %d",
          buttonIndex, 
          actionSheet.cancelButtonIndex, 
          actionSheet.firstOtherButtonIndex);
}
Run Code Online (Sandbox Code Playgroud)

如果启动此应用程序,则操作表将按预期运行.这意味着cancelButtonIndex始终为0,并且正确报告按钮索引.按钮"1"依次为1,依此类推.如果您在添加第七个按钮的行中注释,则操作表会生成一种tableview,并在额外的行上显示取消按钮.如果在这种情况下我按下"one"按钮,则buttonindex变量为0,但cancelButtonIndex也是如此.无法判断用户是否已点击"取消"或"一个"按钮.这似乎不应该是这样的.有人不同意吗?谢谢你的帮助.

iphone uiactionsheet ios

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

Ruby:仅当非空时才将选项传递给方法

我给了一个哈希self.options(可能是空的)和一个方法名.现在我需要调用方法,传入选项哈希,如下所示:

obj.send(method_name, ...args..., self.options)
Run Code Online (Sandbox Code Playgroud)

但是我想支持调用不期望选项哈希的方法.所以,如果没有给出选项(self.options.empty?),我想没有一个空的哈希值传递给方法.我能想到的最好的是:

obj.send(method_name, ...args..., *(self.options.empty? ? [] : [self.options]))
Run Code Online (Sandbox Code Playgroud)

这有更好的习语吗?

ruby

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

枚举在单独的课堂上

无论如何将这个测试放在一个单独的课程中?我试过但没有成功.

public class TrafficLightprj 
{
    public enum TrafficLight 
    {  
        RED(1),  
        GREEN(2),  
        YELLOW(3);

        private final int duration; 

        TrafficLight(int duration) { 
            this.duration = duration; 
        }  

        public int getDuration() { 
            return this.duration; 
        } 


        public static void main(String[] args) 
        {
            for(TrafficLight light: TrafficLight.values())
            {
               System.out.println("The traffic light value is: " +light);
               System.out.println("The duration of that trafic light value is: " + light.getDuration());
            }
        }   
    }
}
Run Code Online (Sandbox Code Playgroud)

java enums

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