小编ary*_*ard的帖子

getenv()Linux/Ubuntu返回NULL

我正在尝试使用用户主目录getenv("$HOME"),但它返回NULL.我究竟做错了什么?

int main(void)
{
    char * path;
    path = getenv("$HOME");
    printf ("The current path is: %s",path);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c unix linux ubuntu-12.04

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

捕获jira-python异常

我试图处理jira-python异常,但我的尝试,除了似乎没有抓住它.我还需要添加更多行才能发布此内容.他们就是那些线条.

try:
    new_issue = jira.create_issue(fields=issue_dict)
    stdout.write(str(new_issue.id))
except jira.exceptions.JIRAError:
    stdout.write("JIRAError")
    exit(1)
Run Code Online (Sandbox Code Playgroud)

以下是引发异常的代码:

import json


class JIRAError(Exception):
    """General error raised for all problems in operation of the client."""
    def __init__(self, status_code=None, text=None, url=None):
        self.status_code = status_code
        self.text = text
        self.url = url

    def __str__(self):
        if self.text:
            return 'HTTP {0}: "{1}"\n{2}'.format(self.status_code, self.text, self.url)
        else:
            return 'HTTP {0}: {1}'.format(self.status_code, self.url)


def raise_on_error(r):
    if r.status_code >= 400:
        error = ''
        if r.text:
            try:
                response = json.loads(r.text)
                if 'message' in response:
                    # JIRA 5.1 errors
                    error …
Run Code Online (Sandbox Code Playgroud)

python jira python-3.3 python-jira

4
推荐指数
3
解决办法
6775
查看次数

pythonic处理嵌套for循环的方法

我有以下代码,为了学习,我希望看到一个更加pythonic的方法来实现这个:

for value in response.values():
    for encod in encodings:
        if encod.lower() in value.lower():
            return(encod)
Run Code Online (Sandbox Code Playgroud)

python python-3.3

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

标签 统计

python ×2

python-3.3 ×2

c ×1

jira ×1

linux ×1

python-jira ×1

ubuntu-12.04 ×1

unix ×1