小编Kar*_*and的帖子

vba是否关心自动过滤器?

如果我在输入表上应用自动过滤并运行vba代码,则代码不关心自动过滤器.

但有时在自动过滤的工作表上运行vba代码,会弄乱结果.那么vba关心自动过滤器

例如.

Sub check()
    Dim rng as range
    Set rng = Sheets("input").Range("A1")
    row = 0
    Do until rng.offset(row,0) = ""
        row = row + 1
    Loop
End Sub
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,vba并不关心autofilter是否应用于A列并且仍然遍历所有行,但是如果我尝试在应用自动加载器的特定单元格上进行写入,则会混乱.

excel vba

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

xdotool - 为什么在运行命令之前睡眠?

我正在使用xdotool自动化运行命令,打开新标签等。

问题是在当前窗口上执行此操作时,我必须专门睡眠一段时间或xdotool keyup Return在做任何事情之前使用,否则xdotool不会按回车键。

kartik@kartikpc:~/junk/xdotool$ cat automate 
#!/bin/bash

# Release the Return key
# xdotool keyup Return
# Or sleep 1

xdotool type --delay 1 --clearmodifiers "clear"
xdotool key --clearmodifiers Return

kartik@kartikpc:~/junk/xdotool$ source automate 
clearkartik@kartik-lappy:~/junk/xdotool$ clear
Run Code Online (Sandbox Code Playgroud)

我从很少的来源读到的是

% 睡眠 1; xdotool type "$(printf "hello\nworld\n")"(睡眠是为了让我在输入之前释放我的实际'返回'键)

我知道当我通过按键盘上的“Enter”专门调用我的脚本时会按下“返回”键。但是为什么不自动发布呢?

即使在xdotool输入内容xdotool type时,也不应该在此之前释放“返回”键,或者每个字母都应该一行接一行,而不是出现在同一行

bash terminal xdotool

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

装饰器如何标记一个函数?

我正在学习基本的 Flask 教程,其中包含以下代码:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()
Run Code Online (Sandbox Code Playgroud)

我还从许多网站(包括Stackoverflow Decorators)了解了 Python 装饰器的基础知识

我假设在前面的代码中,函数hello将被更改和修饰,并且为了运行应用程序,我需要hello()在某处调用该函数。Flask 如何确定它必须调用的函数的名称。

仅用装饰器包装函数定义是否会以某种方式标记该函数?如果是这样,怎么办?

例如,在下面的代码中,我正在调用我装饰过的函数:

def decorate(foo):
    print("I'm doing a lot of important stuff right now")

    def inner():
        print("Some stuff 1")
        foo()
        print("Some stuff 2")

    return inner

@decorate
def hello():
    print("Hello")

hello()
Run Code Online (Sandbox Code Playgroud)

python decorator flask python-decorators

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

为什么在分配DerivedClass.prototype时使用Object.create而不是new Super

我一直在阅读使用Javascript的面向对象编程的MDN指南,其中在一个示例中显示继承,提到以下内容:

// Create a Student.prototype object that inherits from Person.prototype.
// Note: A common error here is to use "new Person()" to create the
// Student.prototype. That's incorrect for several reasons, not least 
// that we don't have anything to give Person for the "firstName" 
// argument. The correct place to call Person is above, where we call 
// it from Student.
Student.prototype = Object.create(Person.prototype); // See note below
Run Code Online (Sandbox Code Playgroud)

我也研究了其他答案,但他们没有具体说明使用时会遇到什么问题 Student.prototype = new Person()

上面提到的一个问题涉及传球firstName,但这只是一个场景.

在任何人将此标记为重复之前.这里的问题使用"Object.create"而不是"new"处理通常使用 …

javascript inheritance

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

没有迁移的Django迁移应用程序

我创建了一个由单个应用程序组成的新 Django 项目。我认为 Django 只会在迁移存在的情况下迁移应用程序。

我第一次运行时python manage.py migrate,Django 也会为我的应用程序创建表(我已经为我的应用程序创建了 models.py)

我还没有跑python manage.py makemigrations apppython manage.py makemigrations直到这个时候。

我会在运行时得到以下输出python manage.py migrate

Synchronizing apps without migrations:
  Creating tables...
    Creating table app_model
Run Code Online (Sandbox Code Playgroud)

这不是我想要的,因为下次我实际为应用程序进行迁移并运行 migrate 时,Django 会抱怨这些表已经存在。

python django

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

长时间打印负数int会产生错误的结果

我正在编译以下C代码:

#include <stdio.h>

int main()
{
    int nEndIndex = -1;
    printf("nEndIndex : %ld\n", nEndIndex);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在用GCC 4.2.4编译它如下:

[kartika@alto ~/junk]$ gcc -o test test.c
[kartika@alto ~/junk]$ ./test
nEndIndex : 4294967295
[kartika@alto ~/junk]$ gcc --version
gcc (GCC) 4.2.4
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)

我认为既然long大于int它应该不是一个问题使用%ld.既然这两个都是signed为什么我得到这个输出?

c

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

Python类和对象

我对Oops有点新意,我对Python课程感到困惑.虽然我在高中学习过C++,但我知道我当时学的不是C++(它有点类C,没有模板, STL或命名空间)

如果我错了,请纠正我,但对我而言,课程只是对象的蓝图,对吗?

现在,如果我想在C++中创建一个类的实例(例如,我的类名是"animal")

我会这样做: animal lion; 或者如果我有一个构造函数(带参数),那么我只会这样做animal tiger(4,5);

我面临的问题是:

class animal:
    val = 5
Run Code Online (Sandbox Code Playgroud)

它只是一个基本类,没有任何构造或方法:

现在使用python我能够引用动物,而不创建它的任何实例(我不能在C++中这样做,对吧?)

animal.val = 7
Run Code Online (Sandbox Code Playgroud)

我面临的另一个问题是,我需要在创建实例时始终使用括号,否则它将引用类本身.

例如;

lion = animal
lion.val = 6
tiger = animal
print tiger.val
Run Code Online (Sandbox Code Playgroud)

它打印6,当我想要创建一个我要使用paranthesis的实例时,即使我没有指定任何构造函数(在C++中不是必需的),任何特殊原因或只是语言语法的问题?

python

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

char*上的分段错误++运算符

可能重复:
为什么这个Seg Fault?

在char*上使用++运算符时收到分段错误

#include<stdio.h>

int main()
{
    char *s = "hello";
    printf("%c ", ++(*s));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但如果我做以下事情:

#include<stdio.h>

int main()
{
    char *s = "hello";
    char c = *s;
    printf("%c ", ++c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后代码编译完美,上面的代码有什么问题?

c segmentation-fault

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

Makefile第一个规则目标

我正在尝试make使用简单的三个文件.

foo.h中

#ifndef __foo_H_
#define __foo_H_

void print();

#endif
Run Code Online (Sandbox Code Playgroud)

foo.c的

#include <stdio.h>
#include "foo.h"


void print()
{
    printf("Hello World !");
}
Run Code Online (Sandbox Code Playgroud)

main.c中

#include "foo.h"

int main()
{
    print();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我使用以下makefile时,一切运行正常

生成文件

CC = gcc
CFLAGS = -I.
DEPS = foo.h
OBJ = foo.o main.o 

.PHONY: clean

main: $(OBJ)
        gcc -o $@ $^ $(CFLAGS)

%.o: %.c $(DEPS)
        $(CC) -c -o $@ $< $(CFLAGS)

clean:
        rm *.o
Run Code Online (Sandbox Code Playgroud)

上面的工作是因为make默认运行第一个目标(我基本上到处读取).

如果我使用下面的makefile

CC = gcc
CFLAGS = -I.
DEPS …
Run Code Online (Sandbox Code Playgroud)

c c++ makefile

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