小编Nik*_*ntz的帖子

为什么我的PyCharm调试按钮变灰了?

我使用PyCharm进行Google App Engine的开发.现在我正在尝试使用Ubuntu Linux并安装它并运行它但右上角的按钮是灰色的,我不知道该怎么办.可以做些什么来运行该项目?截图

pycharm

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

为什么我要用!在这种情况下重要吗?

我正在学习CSS,我有我想要的结果,但前提是我使用的是! important;规范.我不明白为什么我不能覆盖继承一个类并重写属性的属性.

form button.minor-action,
#profile-left a.action,
.minor-action {
  display: inline-block;
  background: @lightBlue;
  color: white;
  padding: 0 1.2em;
  border-radius: 4px;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  -ms-border-radius: 4px;
  text-decoration: none;
  text-align: center;
  font-weight: bold;
  border: none;
  height: 25px;
  margin-top:1.0em;
  line-height:25px;
  white-space: nowrap;
  &:visited {
    color: white;
  }
  &:hover, &:active, &:focus {
    background-color: darken(@lightBlue, 10%);
    text-decoration: none;
  }

  &.call-to-action {
    background-color: @pink;
    &:hover, &:active, &:focus {
      background-color: darken(@pink, 10%);
      text-decoration: none;
    }
  }
}

.extra-questions {
  margin-top: 0em !important;

}
Run Code Online (Sandbox Code Playgroud)

我想如果我将上面的样式用于按钮:

<button …

css less

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

为什么错了1小时?

斯德哥尔摩(欧洲)时间为 15:0x。但我把本地化时间弄错了 1 小时:

>>> datetime.datetime.now()
datetime.datetime(2015, 12, 17, 15, 2, 42, 633000)
>>> babel.dates.format_datetime(datetime.datetime.now(), 'full', tzinfo=pytz.timezone('Europe/Stockholm'),locale='en')
u'Thursday, December 17, 2015 at 4:02:49 PM Central European Standard Time'
>>>
Run Code Online (Sandbox Code Playgroud)

什么是错误?

python datetime pytz python-babel

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

如何将 GNU readline 与 flex-lexer 一起使用?

我认为使用 GNU Readline 库作为命令行提示符很好,我希望我正在开发的 shell 也能使用该功能。现在 readline 对我有用(我的环境是 CLion、CMake、Ubuntu、BSD、C、flex-lexer 和柠檬解析器),但我还需要 flex 和 yacc 同时工作来扫描和解析输入,但代码似乎“不相容”——他们真的吗?

    params[0] = NULL;
   printf("> ");

    i=1;
    do {
        lexCode = yylex(scanner);

        /*  snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
         Display prompt and read input (NB: input must be freed after use)...*/



        text = strdup(yyget_text(scanner));
        /*
        input = readline(text);

        if (!input)
            break;

        add_history(input);

        free(input);*/
        printf("lexcode %i Text %s\n", lexCode, text);
        if (lexCode == 4) {
            params[i++] = mystring;
            if (strcmp(text, "\'\0")) {
                params[i++] = mystring;
            } …
Run Code Online (Sandbox Code Playgroud)

c readline lemon flex-lexer

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

由于堆栈溢出,C中通常会发生什么?

在Java中会有一个堆栈跟踪,StackOverflowError并且整个系统不会崩溃,只有程序.

在C中,我知道超出范围的数组索引会产生分段错误.对于C中的堆栈溢出是否相同,并且还存在分段错误,即类似问题的错误类型相同?

我没有测试C中有意识的无限复活,看看会发生什么,因为我不知道后果.

或者它有时是更糟糕的事情,C中的堆栈溢出可能会导致操作系统故障并迫使您重新启动电源以便返回?或者更糟糕的是,造成不可逆转的硬件损坏?堆栈溢出错误有多糟糕的影响?

很明显,Java中的保护比C中更好.在C中是否比在汇编/机器代码中更好,或者它在C中作为汇编实际上是否相同(缺乏)保护?

c java stack-overflow error-handling

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

是否有“本地”时间戳?

我可以将 UTC 时间戳(例如 1417392000)转换为包括夏令时在内的本地日期时间对象,但是当我尝试将本地日期时间对象转换为“本地时间戳”时,我会得到与以前相同的 UTC 时间戳。

我是否在循环思考并且它们是相同的?我应该从传入的 UTC 时间戳中保存“本地时间戳”。

这是我的代码

    print("UTC timestamp %d" % hour[0])
    day = self.get_day(hour)
    month = self.get_month(hour)
    year = self.get_year(hour)
    tz = pytz.timezone('Europe/Stockholm')
    utc_dt = datetime.utcfromtimestamp(int(hour[0])).replace(tzinfo=pytz.utc)
    print("UTC datetime %s" % utc_dt)
    dt = tz.normalize(utc_dt.astimezone(tz))
    print("STO datetime %s" % dt.strftime('%Y-%m-%d %H:%M:%S %Z%z'))
    print("STO ts %d" % int(time.mktime(dt.timetuple())))
    print("STO timestamp %d" % utc_dt.astimezone(tz).timestamp())
    day = int(dt.strftime('%d'))
    month = int(dt.strftime('%m'))
    year = int(dt.strftime('%Y'))
Run Code Online (Sandbox Code Playgroud)

输出

UTC timestamp 1417395600
UTC datetime 2014-12-01 01:00:00+00:00
STO datetime 2014-12-01 02:00:00 CET+0100
STO ts 1417395600 …
Run Code Online (Sandbox Code Playgroud)

python time datetime timestamp pytz

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

用geomodel命令(" - modified")

编辑:使用key = lambda解决并了解我实际在做什么.

有像gemodel一样

class A(GeoModel,search.SearchableModel):
Run Code Online (Sandbox Code Playgroud)

我正在尝试按日期使用db.GeoPt来存储谷歌地图坐标与GAE和我可以映射和匹配的地理模型.但订单(" - 修改")不起作用.没有踪影.欢迎所有想法.应该排序的代码是

a = A.proximity_fetch(A.all().filter("modified >",
timeline).filter("published =", True).filter("modified <=",
bookmark ).order("-modified") ,db.GeoPt(lat, lon),max_results=PAGESIZE
+1, max_distance=m)
Run Code Online (Sandbox Code Playgroud)

除订单外,所有参数似乎都有效(" - 修改")

尝试使用lambda排序的建议方法我得到消息"TypeError:lambda()只需1个参数(给定2个)"

a = A.proximity_fetch(A.all().filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark ).order("-modified") ,db.GeoPt(lat, lon),max_results=40, max_distance=m)
a = sorted(a, lambda x: x.modified, reverse=True)
Run Code Online (Sandbox Code Playgroud)

python google-app-engine

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

如何启用reCAPTCHA

我尝试使用标记启用reCAPTCHA

{{capture}}
Run Code Online (Sandbox Code Playgroud)

预期的输出是reCAPTCHA框.相反,我看到这个代码直接显示在页面上的代码看起来像一个bug:

<script type="text/javascript" src="http://api.recaptcha.net/ challenge?k=6LckUsMSAAAAAGcZR3JZw6Dusn4wKBBfZxHXh8w5"></script> <noscript> <iframe src="http://api.recaptcha.net/noscript?k=6LckUsMSAAAAAGcZR3JZw6Dusn4wKBBfZxHXh8w5" height="300" width="500" frameborder="0"></iframe><br /> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></ textarea> <input type='hidden' name='recaptcha_response_field' value='manual_challenge' /> </noscript>
Run Code Online (Sandbox Code Playgroud)

知道怎么办吗?到错误的链接是在这里和我的代码使用的是直接使用的reCAPTCHA API与此文件名为captcha.py:

import urllib2, urllib

API_SSL_SERVER="https://api-secure.recaptcha.net"
API_SERVER="http://api.recaptcha.net"
VERIFY_SERVER="api-verify.recaptcha.net"

class RecaptchaResponse(object):
    def __init__(self, is_valid, error_code=None):
        self.is_valid = is_valid
        self.error_code = error_code

def displayhtml (public_key,
                 use_ssl = False,
                 error = None):
    """Gets the HTML to display for reCAPTCHA

    public_key -- The public api key
    use_ssl -- Should the request be sent over ssl?
    error -- …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine recaptcha

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

显示价格

我得到不同货币的价格,并希望显示巴西R $我的格式不起作用,显示如下:

价格:1.15..000.,00 R $

为了获得良好的灵活性,我将价格存储为字符串: price=db.StringProperty(verbose_name="price")

我试图实现我自己的过滤器,它不起作用: {{ ad.price|separate }}&nbsp;R$

def separate(n, sep='.'):
    ln = list(str(n))
    ln.reverse()
    newn = []
    while len(ln) > 3:
        newn.extend(ln[:3])
        newn.append(sep)
        ln = ln[3:]
    newn.extend(ln)
    newn.reverse()
    return "".join(newn)
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗?我应该删除过滤器吗?我应该对输入执行一些正则表达式吗?我网站的链接是http://www.koolbusiness.com/servead/4252196

更新:我正在考虑使用像这些过滤器之一:

import locale
locale.setlocale(locale.LC_ALL, '')

def currency(value): # doesn't work
    locale.setlocale(locale.LC_ALL, '')
    return locale.currency(value, grouping=True)

register.filter(currency)


def currencyWithoutUsingLocale(value): # needs adjustment
    value=float(value)
    symbol = '$' 
    thousand_sep = ''
    decimal_sep = ''
    # try to use settings if set 
    try:
        symbol = settings.CURRENCY_SYMBOL
    except AttributeError: …
Run Code Online (Sandbox Code Playgroud)

python django currency

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

按名称排序python字典?

我有一个python字典,我想根据名称排序:

location_map_india = {
  101: {'name': 'Andaman & Nicobar Islands', 'lat': 11.96, 'long': 92.69, 'radius': 294200},  
  108: {'name': 'Andhra Pradesh', 'lat': 17.04, 'long': 80.09, 'radius': 294200},
...
}
Run Code Online (Sandbox Code Playgroud)

它并没有像我期望的那样出现.我试过了:

location_map_india = sorted(location_map_india.iteritems(), key=lambda x: x.name)
Run Code Online (Sandbox Code Playgroud)

以上都行不通.我该怎么办?

更新

允许以下内容并按预期运行.谢谢你的帮助.码:

location_map_india = sorted(location_map_india.iteritems(), key=lambda x: x[1]["name"])
Run Code Online (Sandbox Code Playgroud)

模板:

{% for key,value in location_map_india %}<option value="{{key}}" >{{value.name}}</option>{% endfor %}
Run Code Online (Sandbox Code Playgroud)

python sorting dictionary

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