小编Ste*_*liu的帖子

Python嵌套函数变量作用域

我已经阅读了关于该主题的几乎所有其他问题,但我的代码仍然不起作用.

我想我错过了一些关于python变量范围的东西.

这是我的代码:

PRICE_RANGES = {
                64:(25, 0.35),
                32:(13, 0.40),
                16:(7, 0.45),
                8:(4, 0.5)
                }

def get_order_total(quantity):
    global PRICE_RANGES
    _total = 0
    _i = PRICE_RANGES.iterkeys()
    def recurse(_i):
        try:
            key = _i.next()
            if quantity % key != quantity:
                _total += PRICE_RANGES[key][0]
            return recurse(_i) 
        except StopIteration:
            return (key, quantity % key)

    res = recurse(_i)
Run Code Online (Sandbox Code Playgroud)

我明白了

"全局名称'_total'未定义"

我知道问题在于_total作业,但我不明白为什么.不recurse()应该访问父函数的变量?

有人可以向我解释一下我对python变量范围缺少什么吗?

python variables scope

82
推荐指数
6
解决办法
7万
查看次数

无法使用节点npm安装任何软件包

我试图通过npm安装一些节点包,但它不会去.我已经尝试过安装/ unistall/update节点,但似乎没什么用.

我正在使用ubuntu 12.04 - 这是我试图安装包的方式:

npm install underscore

npm http GET http://registry.npmjs.org/underscore
npm http 404 http://registry.npmjs.org/underscore
npm ERR! registry error parsing json
npm ERR! SyntaxError: Unexpected token <
npm ERR! <html>
npm ERR!   <head>
npm ERR!     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
npm ERR!     <script type="text/javascript" language="JavaScript" src="http://img.sedoparking.com/registrar/dopark.js"></script>
npm ERR!   </head>
npm ERR!   <body style="display: none;">
npm ERR!     <script type="text/javascript">
npm ERR! var reg = 'sedonewreg';
npm ERR! document.write( '<scr'+'ipt type="text/javascript" language="JavaScript"' + 'src="http://sedoparking.com/' + window.location.host + '/' + reg + …
Run Code Online (Sandbox Code Playgroud)

node.js npm ubuntu-12.04

46
推荐指数
8
解决办法
13万
查看次数

我可以通过facebook连接获取特定区域设置中的Facebook用户信息吗?

我正在使用facebook connect让用户轻松登录我的应用程序.它运作良好,但是,在用户允许我将他们的Facebook信息作为电子邮件,生日,性别等获取后,facebook会在用户的特定区域设置中返回这些数据.

所以,如果一个用户有英文版的facebook,我会得到{"性别":"男性"},如果用户有意大利语的facebook,我会得到{"性别":"uomo"}.Facebook使用用户的语言环境翻译价值.问题是我必须使用这些用户信息在我的应用程序上进行一些搜索,而且我不可能说,例如,"选择所有'男性'用户".

有没有办法让Facebook返回特定区域的用户信息?所以我将能够知道如何使用这些数据,而不仅仅是显示这些数据.

谢谢

facebook localization

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

标签 统计

facebook ×1

localization ×1

node.js ×1

npm ×1

python ×1

scope ×1

ubuntu-12.04 ×1

variables ×1