小编Ank*_*wal的帖子

有趣的grep匹配在bash中

你能解释一下原因吗?

这个给了$?= 1

echo "uus" | grep -w -o [0123456789]\*
Run Code Online (Sandbox Code Playgroud)

这一个给$?= 0

echo "-uus" | grep -w -o [0123456789]\*
Run Code Online (Sandbox Code Playgroud)

linux bash

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

在awk中使用记录分隔符

我有

$ cat awktestf 
a++
b++
c++
Run Code Online (Sandbox Code Playgroud)

我正在做,我得到了

cat  awktestf | awk 'BEGIN { RS="++" ; OFS="@"; ORS="()" } { print $0 } END {print "I am done" }'
a()
b()
c()
()I am done()abc@abc:~$ 
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么我最后得到一个额外的()?

即便这样也行不通:

$ echo 'a++
> b++
> c++' | awk 'BEGIN { RS="++" ; OFS="@"; ORS="()" } { print $0 } END {print "I am done" }'
a()
b()
c()
()I am done()abc@abc:~$ 
Run Code Online (Sandbox Code Playgroud)

bash shell scripting awk

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

如何从C程序调用bash shell脚本中定义的函数

我有

    #!/bin/sh

    func1()
    {
        echo "This is func1 from shell script"
    }

    func2()
    {
        echo "This is func2 from shell script"

    }
Run Code Online (Sandbox Code Playgroud)

我想从C程序调用func1和func2.我能这样做吗?

c c++ linux bash shell

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

内部类问题的一般用法

我没有发布整个代码.我有这个:

public class LinkedList2<T extends Comparable<T>> implements Iterable<T> {

    private Node<T> head;
    private Node<T> tail;
    private int numOfElem;

    private class Node<T> {

        Node<T> next;
        T data;

        Node(Node<T> next, T data) {
            this.next = next;
            this.data = data;
        }
    }

    private class LinkedList2Iterator<T> implements Iterator<T> {
            private int count = LinkedList2.this.numOfElem;
            private Node<T> current = LinkedList2.this.head;
    }
}       
Run Code Online (Sandbox Code Playgroud)

javac -Xlint LinkedList2.java我得到这个错误:

LinkedList2.java:134: incompatible types
found   : LinkedList2<T>.Node<T>
required: LinkedList2<T>.Node<T>
        private Node<T> current = LinkedList2.this.head;
                                              ^
1 error
Run Code Online (Sandbox Code Playgroud)

你能帮我吗?

java generics

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

如何正确检出远程存储库中的分支

我有这个

    abc@abc-ubuntu:~/project1/wh-app-ios$ git branch -a -v -v
    * master                   1d35af1 [origin/master: ahead 2] Adding 123 to hello
      remotes/gitb/gh-pages    e3dad9d boom
      remotes/gitb/integration 1d3fcd5 Adding 55_Glossary chapter
      remotes/gitb/master      86d1d30 Merge remote-tracking branch 'origin/master'
      remotes/gitb/pt_BR       dc9d991 Revisions at 03, 07, 08, 09, 10, 11 and 50
      remotes/origin/HEAD      -> origin/master
      remotes/origin/master    1ae426b Update README.md
Run Code Online (Sandbox Code Playgroud)

我做

    abc@abc-ubuntu:~/project1/wh-app-ios$ git checkout gitb/master
    Note: checking out 'gitb/master'.

    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any …
Run Code Online (Sandbox Code Playgroud)

git

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

从getw无法理解这个输出

我有这个

#include<stdio.h>
#include<stdlib.h>

int main() {

    int a = getw(stdin);

    if(ferror(stdin)) {
        printf("error occurred\n");
        exit(1);
    }        
    printf("%u\n", a);

}
Run Code Online (Sandbox Code Playgroud)

而我得到:

$ ./readstdin 
9876
909588537
Run Code Online (Sandbox Code Playgroud)

你能帮忙解释一下产量吗?

我的机器:Linux abc-ubuntu 3.2.0-65-generic#98-Ubuntu SMP Wed Jun 11 20:27:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

c

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

SyntaxError:关键字不能是表达式

我有

hd.meta(http-equiv='Content-Type', content='text/html;charset=UTF-8')
Run Code Online (Sandbox Code Playgroud)

我得到了:

SyntaxError:关键字不能是表达式

为什么这样 ?

python python-2.7

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

通过python电子邮件发送电子邮件时HTML无法正确呈现

我正在使用我公司的 smtp 服务器使用 python 的电子邮件模块发送电子邮件。当我这样做时,我的电子邮件 html 无法正确呈现。这是我得到的:

  sender = 'abc@abc.com'
  # Create message container - the correct MIME type is multipart/alternative.
  msg = MIMEMultipart('multipart')
  msg['Subject'] = "My Report"
  msg['From'] = sender
  msg['To'] = ", ".join(recipients)

  # Create the body of the message using html in msg_body
  h = unicode(msg_body).encode("utf-8", "ignore")
  # Record the MIME type
  part = MIMEText(h, 'html')

  # Attach parts into message container.
  msg.attach(part)

  pngfiles = ['image.png']  
  for file in pngfiles:
      # Open the files in binary mode. …
Run Code Online (Sandbox Code Playgroud)

html python email smtp python-2.7

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

在python中定义@classmethod lambda

class TestClass(object):
    aa = lambda x: 35
    def __init__(self):
        self.k = self.aa()


o = TestClass()
print o.k
Run Code Online (Sandbox Code Playgroud)

这给了我35,我理解为什么.

但是这个:

class TestClass(object):
    @classmethod
    aa = lambda x: 35
    print type(aa)
    def __init__(self):
        self.k = TestClass.aa()


o = TestClass()
print o.k
Run Code Online (Sandbox Code Playgroud)

这给了我

  File "test1.py", line 3
    aa = lambda x: 35
     ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

为什么这样 ?

python lambda

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

从__iter__返回一个非迭代器

class test(object):
    def __init__(self):
        pass
    def __iter__(self):
        return "my string"

o = test()
print iter(o)
Run Code Online (Sandbox Code Playgroud)

为什么这会追溯?

$ python iter_implement.py
Traceback (most recent call last):
  File "iter_implement.py", line 9, in <module>
    print iter(o)
TypeError: iter() returned non-iterator of type 'str'
Run Code Online (Sandbox Code Playgroud)

我希望__iter__在这种情况下只返回字符串.何时以及为什么检测到返回的对象不是迭代器对象?

python

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

标签 统计

python ×4

bash ×3

c ×2

linux ×2

python-2.7 ×2

shell ×2

awk ×1

c++ ×1

email ×1

generics ×1

git ×1

html ×1

java ×1

lambda ×1

scripting ×1

smtp ×1