小编kma*_*729的帖子

解释gitignore模式匹配

我有以下目录树:

> #pwd is the repo   
> tree -a
.
??? .git
?   |.....
??? .gitignore
??? README.md
??? f1.html
??? f2.html ... and some more html
??? images
?   ??? river.jpg
>
Run Code Online (Sandbox Code Playgroud)

我也有以下内容.gitignore:

> cat .gitignore
*
!*.html
!images/*.*
>
Run Code Online (Sandbox Code Playgroud)

我希望images目录中的所有文件都包含在repo中.但那并没有发生.我在gitignore中使用以下内容工作:

*
!*.html
!images*
!*.jp*g
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?是否有一种万无一失的测试gitignore的方法.我检查了文档.这是它不理解的一点(这是在模式格式标题下):

否则,Git将模式视为适合fnmatch(3)使用FNM_PATHNAME标志消耗的shell glob:模式中的通配符与路径名中的/不匹配.例如,"Documentation/*.html"匹配"Documentation/git.html",但不匹配"Documentation/ppc/ppc.html"或"tools/perf/Documentation/perf.html".

regex git gitignore

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

理解python3函数中的'*'"仅关键字"参数表示法

当与partial一起使用时,我在python3中遇到关键字唯一参数功能的一些困难行为.关于仅关键字参数的其他信息.

这是我的代码:

def awesome_function(a = 0, b = 0, *, prefix):
    print('a ->', a)
    print('b ->', b)
    print('prefix ->', prefix)
    return prefix + str(a+b)
Run Code Online (Sandbox Code Playgroud)

以下是我对部分的理解:

>>> two_pow = partial(pow, 2)
>>> two_pow(5)
32
>>>
Run Code Online (Sandbox Code Playgroud)

我在上面的例子中理解的是,partial使第二个参数pow作为唯一的参数two_pow.

我的问题是为什么以下工作:

>>> g = partial(awesome_function, prefix='$')
>>> g(3, 5)
a -> 3
b -> 5
prefix -> $
'$8'
>>>
Run Code Online (Sandbox Code Playgroud)

但我得到的错误是:

>>> awesome_function(prefix='$', 3, 5)
  File "<stdin>", line 1
SyntaxError: non-keyword arg after …
Run Code Online (Sandbox Code Playgroud)

python keyword-argument python-3.x

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

命令前的 Bash 变量赋值

前几天我遇到一个命令

AWS_ACCESS_KEY="foo" AWS_SECRET_KEY="bar" aws list iam
Run Code Online (Sandbox Code Playgroud)

我看到在命令之前设置变量会在命令的环境中添加这些变量:

#make sure there is no environment variable "foo"
$ echo $foo

#mimic-ing above command
$ foo=bar printenv | grep foo
foo=bar

#or trying from python environment
$foo=bar python -c "import os; print(os.getenv('foo', None))"
bar

#foo is destroyed now
$ echo $foo  
#<<NOTHING
Run Code Online (Sandbox Code Playgroud)

我试图使用这个技巧根据今天的日期动态创建一个新目录:

$ dname=$(date +%d_%m_%y) mkdir ${dname} && cd ${dname}
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

mkdir: missing operand
Try 'mkdir --help' for more information.
Run Code Online (Sandbox Code Playgroud)

dname=$(date +%d_%m_%y) echo $dname返回空!

我究竟做错了什么?如何在 bash 的同一行动态创建和使用变量?

bash environment-variables

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

在 C++ 中将 memset 设置为 INT_MAX

我有以下代码:

int board[5][5];

memset(board, INT_MAX, sizeof(board));
//printing out INT_MAX
cout << INT_MAX << endl;

for(int r = 0; r < 5; r++) {
        for(int c = 0; c < 5; c++) {
            cout << setw(3) << board[r][c];
        }   
        cout << endl;
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我-1在我的数组中获取了所有s:

2147483647
 -1 -1 -1 -1 -1
 -1 -1 -1 -1 -1
 -1 -1 -1 -1 -1
 -1 -1 -1 -1 -1
 -1 -1 -1 -1 -1
Run Code Online (Sandbox Code Playgroud)

我该如何解释?为什么不是所有元素都设置为 INT_MAX?当我打印时,INT_MAX它打印得很好。

c c++ memset

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