我正在尝试使用用户主目录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) 我试图处理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) 我有以下代码,为了学习,我希望看到一个更加pythonic的方法来实现这个:
for value in response.values():
for encod in encodings:
if encod.lower() in value.lower():
return(encod)
Run Code Online (Sandbox Code Playgroud)