小编mu *_*u 無的帖子

Python中数组数组中字符串的拆分值

我调用了一个数组数组arr,我想分割每个数组的第二个值.这意味着,如果我0-6想将其修改为'0','6'

是)我有的:

arr = [['PROVEEDOR', '0-6', '11111'], ['tiempo ida pulidor', '6-14', '33333']]
Run Code Online (Sandbox Code Playgroud)

我想拥有什么:

arr = [['PROVEEDOR', '0', '6', '11111'], ['tiempo ida pulidor', '6', '14', '33333']]
Run Code Online (Sandbox Code Playgroud)

我该怎么做这个转换?它始终是第二个值,并且总是有两个数字.我知道我要使用,.split('-')但我知道不知道让它在这里进行替换,因为我要在包含的所有数组之间进行迭代arr.

提前致谢.

python arrays

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

Gem :: LoadError:耙?

我正在尝试在rake db:migrate本地运行,但我收到以下错误:

Gem::LoadError: You have already activated rake 10.2.2, but your Gemfile requires rake 10.1.1. Using bundle exec may solve this.
Run Code Online (Sandbox Code Playgroud)

不知道为什么会这样?它出来的没有.

知道如何解决这个问题吗?

干杯

ruby-on-rails ruby-on-rails-4

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

在字典中使用'if in'

我无法相信,但我被一项非常简单的任务所困扰.

我需要检查,如果值是在字典中的任何键或值.我可以找到密钥使用if 'A' in dictionary,但我似乎无法让它工作values.我意识到我可以使用for循环来做这个,我可以诉诸于此但我想知道是否有内置的方法.

python dictionary

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

.gitignore不适用于子目录中的文件

这是我的.gitignore文件的内容,它位于我的存储库的根目录:

# grails stuff to ignore
target
*.iml
*.ipr
.idea
*.log
*.swp   # vi swap files
.DS_Store  # OS X Finder cache files

# cocoapods stuff to ignore
Pods
Podfile.lock
Run Code Online (Sandbox Code Playgroud)

.DS_Store我的项目根目录中的文件被正确忽略,但git status给出:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ios/.DS_Store

nothing added to commit but untracked files present (use "git …
Run Code Online (Sandbox Code Playgroud)

git macos gitignore

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

git显示文件更改为0插入(+),0删除(-)

很多时候我运行“ git diff --shortstat”命令,它输出以下内容:

17 files changed, 0 insertions(+), 0 deletions(-)
Run Code Online (Sandbox Code Playgroud)

即使没有插入或删除操作,文件怎么可能更改?

git

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

使用单个 git 存储库而不是子模块管理不同的代码库

在阅读了关于子模块的这篇文章后,它们似乎只是为了从您自己的内部链接到外部 git 存储库而存在。但是,我希望子模块能够让您从一个存储库中管理多个单独的提交历史记录。

是否可以拥有非外部 git 存储库?我想在一个存储库下管理我所有的厨师食谱,每个库都有单独的提交历史,而无需创建一堆 git 存储库

编辑:我认为我没有明确说明我的用例。我的意思是我想在唯一可寻址的地方为我的每个服务器提供食谱列表;并不是我想要一个单独的食谱的子模块。在这种情况下,mu 的回答非常有效地解决了这个问题。

git github git-submodules chef-infra

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

JSON字符串索引必须为整数

关于这个主题有很多问题,但是大多数似乎是人们忘记打电话的问题json.loads

这是我的示例:

import json

json_input = '{ "ar": { "articles": { "12345": {"title": "first title" } , "67890": {"title": "another title" } } } } '

data = json.loads(json_input)

for article in data['ar']['articles']:
    print(article['title'])
Run Code Online (Sandbox Code Playgroud)

打印调用失败,并显示以下错误:

TypeError:字符串索引必须是整数

我该如何解决?

python json python-3.x

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

将github提交/拉取请求应用为补丁

如何从github应用补丁?

我试着编译minisat,但是我遇到了两个来自clang编译的问题.

第一个问题是在这个github提交中解决的,它是从原来的github派生出来的.由于变化很小,我可以轻松地修补代码以手动工作.

第二个问题在这个github(https://github.com/niklasso/minisat/pull/17)中解决,但补丁不适用于原始源.我可以通过复制修改后的文件手动更新代码,但如果我可以将此补丁拉入我的本地目录会更好.用github可以做到吗?如果是这样,怎么办?

git github git-patch pull-request

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

MD5返回不同的哈希码 - Python

我正在尝试确定某些文件的数据一致性.但是,MD5的变化不同.当我执行时md5sum,哈希是相等的:

import hashlib
import os
import sys

def hash_file_content(path):
    try:
        if not os.path.exists(path):
            raise IOError, "File does not exist"
        encode = hashlib.md5(path).hexdigest()
        return encode
    except Exception, e:
        print e

def main():
    hash1 = hash_file_content("./downloads/sample_file_1")
    hash2 = hash_file_content("./samples/sample_file_1")

    print hash1, hash2

if __name__ == "__main__":
   main()
Run Code Online (Sandbox Code Playgroud)

输出意外地不同:

baed6a40f91ee5c44488ecd9a2c6589e 490052e9b1d3994827f4c7859dc127f0
Run Code Online (Sandbox Code Playgroud)

现在md5sum:

md5sum ./samples/sample_file_1
9655c36a5fdf546f142ffc8b1b9b0d93  ./samples/sample_file_1

md5sum ./downloads/sample_file_1 
9655c36a5fdf546f142ffc8b1b9b0d93  ./downloads/sample_file_1
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况,我该如何解决这个问题呢?

python hash md5

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

新的repo命令(1.22)可用

当我这样做时,我开始在我的回购中突然收到以下警告信息repo init.我花了足够的时间在论坛上搜索它,但没有运气!

A new repo command ( 1.22) is available.
... You should upgrade soon:
Run Code Online (Sandbox Code Playgroud)

它是什么意思?

git repo

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