注意:这是Python 3,没有urllib2.此外,我已经尝试使用json.loads(),我收到此错误:
TypeError: can't use a string pattern on a bytes-like object
Run Code Online (Sandbox Code Playgroud)
如果我使用json.loads()并从响应中删除.read(),我会收到此错误:
TypeError: expected string or buffer
Run Code Online (Sandbox Code Playgroud)
>
import urllib.request
import json
response = urllib.request.urlopen('http://www.reddit.com/r/all/top/.json').read()
jsonResponse = json.load(response)
for child in jsonResponse['data']['children']:
print (child['data']['title'])
Run Code Online (Sandbox Code Playgroud)
不起作用......我不明白为什么.
我想制作一个JPEG图像文件,其中包含一些部分透明或完全透明的像素,类似于带有alpha通道的PNG文件.这可能吗?如果是这样,我该怎么做呢?
我想在网站上使用该图像.如果我尝试这样做,它会在任何或所有流行的浏览器(IE 7 +,Firefox,Safari)中工作吗?假设它是可能的,它会起作用,还是需要任何技巧或黑客来使其工作?
编辑:一些回复说我不能这样做.但是,我发现此页面描述了具有透明度的JPEG图像.有谁知道是否有一种方便的方式来生成这种格式的文件?它得到广泛支持吗?
git log 揭示以下内容:
commit 1abcd[...]
Author: [...]
Date: [...]
[Useful commit]
commit 2abcd[...]
Author: [...]
Date: [...]
Merge branch [...] of [etc. etc.]
commit 3abcd[...]
Author: [...]
Date: [...]
[Useful commit]
Run Code Online (Sandbox Code Playgroud)
那个合并提交对我来说没用 - 它不代表一个有意义的分支状态,而是从远程拉动生成的,所以我有远程历史的真实提交 - 不需要提交来标记我拉的事实.我想压缩这个合并提交.我常用的壁球技术是:
git rebase --interactive HEAD~2 (或者我需要去的远方)
然后我会把它压成邻近的提交.我做了一些这样的事情,例如我做了一个提交,意识到我错过了一个很小的重要细节(单个文件,或者没有更改其中一个文件中的一行),并做了另一个提交,基本上只是一个快速的oops.这样,当我将我的更改推回到遥控器时,一切都很干净,并且讲述了一个有凝聚力的叙述.
但是,在这种情况下,当我运行git rebase ...命令时,提交2abcd不会出现!它似乎跳过了正确的2abcd显示1abcd和3abcd.合并提交有什么特别之处可以阻止它出现git rebase --interactive吗?我可以用什么其他技术来压缩合并提交?
UPDATE每@蛋糕的要求:
输出git log --graph --oneline --decorate看起来像这样:
* 1abcd (useful commit)
* 2abcd (merge)
| \ <-- from remote …Run Code Online (Sandbox Code Playgroud) 是否有方法或方法链来检查lodash中可用的对象中是否存在密钥数组,而不是使用以下内容?
var params = {...}
var isCompleteForm = true;
var requiredKeys = ['firstname', 'lastname', 'email']
for (var i in requiredKeys) {
if (_.has(params, requiredKeys[i]) == false) {
isCompleteForm = false;
break;
}
}
if (isCompleteForm) {
// do something fun
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
谢谢大家的精彩解决方案!如果您有兴趣,这里是不同解决方案的jsPerf.
ECMAScript 2015规范提到关键字(或单词?)new.target正好3次 - 在14.2.3中 1次:
通常,Contains不会查看大多数函数表单但是,Contains用于检测ArrowFunction中的new.target,this和super用法.
在14.2.16中两次:
ArrowFunction不为arguments,super,this或new.target定义本地绑定.对ArrowFunction中的参数,super,this或new.target的任何引用 都必须解析为词汇封闭环境中的绑定
MDN提到它,但非常模糊,页面不完整.
巴别塔似乎不支持它.尝试在函数(箭头或其他)中使用new.target时出现语法错误.
它是什么,它应该如何使用?
我想检查MySQL中的日志以查看我的应用程序正在运行的查询.我怎样才能做到这一点?我使用的是XAMPP,MySQL的目录是C:\ xampp\mysql.
这就是我做的事情 show variables like '%log%';
mysql> show variables like '%log%';
+---------------------------------+------------------------------------+
| Variable_name | Value |
+---------------------------------+------------------------------------+
| back_log | 50 |
| binlog_cache_size | 32768 |
| binlog_format | STATEMENT |
| expire_logs_days | 0 |
| general_log | OFF |
| general_log_file | C:/xampp/mysql/data/mysql.log |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_buffer_size | 8388608 |
| innodb_log_file_size | 5242880 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | C:\xampp\mysql\data\ |
| …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何插件允许我重命名Sublime Text 3中打开的文件?
重命名将包括以不同的名称创建当前打开的文件并在旧名称下删除.
我有一个main.py用以下代码命名的文件:
#!/usr/bin/env python3
import utils.stuff
if __name__ == "__main__":
print("hi from main.py")
utils.stuff.foo()
Run Code Online (Sandbox Code Playgroud)
在目录中main.py,我有一个名为的子目录utils,其子文件名为stuff.py以下代码:
print("hi from stuff.py")
def foo():
print("foo")
Run Code Online (Sandbox Code Playgroud)
如果我从命令行运行./main.py,我得到以下输出:
hi from stuff.py
hi from main.py
foo
Run Code Online (Sandbox Code Playgroud)
这正是我所期待的.但是,如果我运行pylint main.py,我会得到以下输出:
No config file found, using default configuration
************* Module main
C: 1, 0: Missing module docstring (missing-docstring)
E: 3, 0: No name 'stuff' in module 'utils' (no-name-in-module)
E: 3, 0: Unable to import 'utils.stuff' (import-error)
E: 7, 4: …Run Code Online (Sandbox Code Playgroud) 通过string.translate功能说:
删除deletechars中的所有字符(如果存在),然后使用表转换字符,该表必须是256个字符的字符串,为每个字符值提供转换,并按其序号索引.如果table为None,则仅执行字符删除步骤.
dict包含映射吗?string.maketrans?我尝试使用该功能(尝试下面)只是为了看它是如何工作但是没能成功使用它.
>>> "abcabc".translate("abcabc",{ord("a"): "d", ord("c"): "x"})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: translation table must be 256 characters long
Run Code Online (Sandbox Code Playgroud)
>>> "abcabc".translate({ord("a"): ord("d"), ord("c"): ord("x")}, "b")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected a character buffer object
Run Code Online (Sandbox Code Playgroud)
>>> "abc".translate({"a": "d", "c": "x"}, ["b"])
Traceback (most recent call last):
File "<stdin>", line 1, in …Run Code Online (Sandbox Code Playgroud) 我需要一种方法来表示一个可以是无限的整数.我不想使用浮点类型(double.PositiveInfinity),因为数字永远不会是小数,这可能会使API混乱.做这个的最好方式是什么?
编辑:我还没有看到的一个想法是使用int?null表示无穷大.有没有充分的理由不这样做?
python ×3
javascript ×2
alpha ×1
arrays ×1
c# ×1
ecmascript-6 ×1
git ×1
infinity ×1
jpeg ×1
lodash ×1
logging ×1
mysql ×1
opacity ×1
pylint ×1
python-2.7 ×1
python-3.x ×1
string ×1
sublimetext ×1
sublimetext3 ×1
transparency ×1
urllib ×1