小编Bar*_*Bar的帖子

如何为joda DateTime对象指定时区?

我有一个函数将字符串转换为joda时间对象并格式化它.

public static String getFormattedDatetime(String someDate) {
    DateTime newDate = DateTime.parse(someDate, DateTimeFormat.forPattern("yy-MM-dd HH:mm:ss.SSS")).minusHours(7);
    String formattedDate = newDate.toString("dd-MMM-yy hh:mm a");

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

该函数接受字符串并返回格式化的DateTime就好了,但是我遇到了为它分配TimeZone的麻烦.我传入的字符串表示我需要转换为PST/PDT的数据库的UTC时间.我无法想办法1)为新的DateTime对象分配一个时区,2)将该对象的时区转换为PST/PDT.现在我用.minusHours处理这个问题.当然不理想.

java jodatime

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

git svn clone在OSX上死于信号11

我正在尝试将项目从svn迁移到git.我使用的是osx svn软件包,但我也尝试使用自制软件安装.我一直得到同样的错误.

git svn clone http://myserver/myrepo
error: git-svn died of signal 11
Run Code Online (Sandbox Code Playgroud)

版本信息:

git --version
git version 2.2.1

svn --version
svn, version 1.7.17 (r1591372)
   compiled Sep 18 2014, 13:06:44
Run Code Online (Sandbox Code Playgroud)

我正在运行优胜美地.

svn git git-svn osx-yosemite

13
推荐指数
2
解决办法
5602
查看次数

ImageMagick魔杖没有识别pdf图像?

我正在尝试使用博客文章将一个pdf转换为jpg,但是每当我尝试运行这个简单的脚本时,我都会遇到此异常wand.exceptions.WandError: wand contains no images MagickWand-56' @ error/magick-image.c/MagickWriteImage/13001

from wand.image import Image

with Image(filename="myFile.pdf") as img:
    img.save(filename="myFile.png")
Run Code Online (Sandbox Code Playgroud)

我正在使用最新版本的Wand和Python 3.4.2.我唯一能想到的可能是版本兼容性问题.

python imagemagick python-3.x wand

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

从本地 python 脚本运行 AWS cli 命令?

我正在尝试运行此 aws s3 ls 命令:

aws s3 ls s3://path/to/my/bucket/12434 --recursive --human-readable --summarize
Run Code Online (Sandbox Code Playgroud)

用这个蟒蛇:

command = 'aws s3 ls s3://path/to/my/bucket/12434 --recursive --human-readable --summarize'
s3_folder_data  = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
print s3_folder_data
Run Code Online (Sandbox Code Playgroud)

但它因以下错误而失败:

subprocess.CalledProcessError: Command 'aws s3 ls s3://path/to/my/bucket/12434 --recursive --human-readable --summarize' returned non-zero exit status 1
Run Code Online (Sandbox Code Playgroud)

当我运行该命令时,该命令本身会起作用。python 脚本由同一台计算机上的同一用户调用。是什么赋予了?

python amazon-s3 amazon-web-services aws-cli

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

使用 Flask Jinja2 和 WTForms 隐藏表单组

我正在尝试根据表单另一部分中复选框的状态显示或隐藏表单字段。我认为我可以相对轻松地使用 jQuery .show() 或 .hide() 做到这一点,但到目前为止我运气不佳。有什么想法吗?

表单类:

class MyForm(Form):
    checked = BooleanField('Check this box:')
    date = DateField('Date:', format='%Y-%m-%d', id="dates")
    submit = SubmitField('Submit')
Run Code Online (Sandbox Code Playgroud)

模板:

{% import "bootstrap/wtf.html" as wtf %}

{% block content %}

{{ form.hidden_tag() }}
{{ wtf.form_field(form.checked) }}
{{ wtf.form_field(form.date) }}
{{ wtf.form_field(form.submit) }}

{% endblock %}

{% block scripts %}

<script type="text/javascript">
jQuery(document).ready(function() {
  $("#checked").change(function() {
    if(this.checked) {
        $('#dates').show();
    } else {
      $('#dates').hide();
    }
  });
});
</script>

{% endblock %}
Run Code Online (Sandbox Code Playgroud)

jquery jinja2 flask flask-wtforms

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

如何将lua字符串转换为C char*?

我已经使用luajit ffi库来包装一个C库,其中包含一个在ppm文件上绘制文本的函数:

void drawText(frameBuffer *fb, int px, int py, char* text, pixel color) 
Run Code Online (Sandbox Code Playgroud)

当我尝试使用字符串从lua调用它时,我收到此错误bad argument #4 to 'drawText' (cannot convert 'string' to 'char *').它看起来不像lua字符串库有任何东西可以将整个字符串转换为字节数组或任何我可以充分操作的东西.

有关如何在没有修改C代码的情况下在lua端执行此操作的任何提示?

c lua ffi luajit

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

python中的stdin和sys.argv有什么区别?

我在编码挑战中停靠点,指定我需要从STDIN读取.这是我的输入法:

def __init__(self, input):
    self._dictionary = {}
    with open(input, 'r') as f:
        reader = csv.reader(f, delimiter='\t')
        for row in reader:
          if self._dictionary.__contains__(row[0]):
            self._dictionary[row[0]].append(row[1])
          else:
            self._dictionary.update({row[0]: row[1].split()})
Run Code Online (Sandbox Code Playgroud)

并在脚本的末尾

if __name__ == "__main__":
    script = Script(sys.argv[1])
    for line in script.output_method():
      print line
Run Code Online (Sandbox Code Playgroud)

在要求从标准输入读取的挑战中使用sys.argv是错误的吗?有什么不同?我应该怎样做才能满足要求?

python

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

使用Flask生成word文档?

我正在尝试启动单页烧瓶应用程序,允许用户下载word文档.我已经想出了如何使用python-docx制作/保存文档,但现在我需要在响应中提供文档.有任何想法吗?

这是我到目前为止所拥有的:

from flask import Flask, render_template
from docx import Document
from cStringIO import StringIO

@app.route('/')
def index():
    document = Document()
    document.add_heading("Sample Press Release", 0)
    f = StringIO()
    document.save(f)
    length = f.tell()
    f.seek(0)
    return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)

python flask python-docx

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

我该怎么用而不是.__ getslice__?

我正在将一个库移植到Python 3.我找到了这个方法:

def __getslice__(self, index, listget=list.__getslice__):
    self._resolve()
    return listget(self, index)
Run Code Online (Sandbox Code Playgroud)

.__getslice__弃用而引发错误.我查看了文档,似乎.__getitem__是大多数人用来替换的东西.__getslice__.唯一的问题是这个库有一个与上面方法完全相同的方法,除了它被称为__getitem__listget=list.__getitem__).我不知道他们为什么在代码中做出这种区分,但似乎图书馆的原始设计者想要保留两种方法的独特功能.移植到Python 3时有什么方法可以保留这个吗?

python python-2.x python-3.x

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