小编sta*_*ion的帖子

通过使用shell脚本替换文件名中的特定模式来重命名多个文件

编写一个简单的脚本,自动重命名一些文件.作为一个例子,我们希望将文件*001.jpg重命名为用户定义的字符串+ 001.jpg(例如:MyVacation20110725_001.jpg)此脚本的用法是让数码相机照片具有合理的文件名.

我需要为此编写一个shell脚本.有人可以建议如何开始吗?

shell

119
推荐指数
5
解决办法
12万
查看次数

Python地图对象不可订阅

为什么以下脚本会出错:

payIntList[i] = payIntList[i] + 1000
TypeError: 'map' object is not subscriptable

payList = []
numElements = 0

while True:
        payValue = raw_input("Enter the pay amount: ")
        numElements = numElements + 1
        payList.append(payValue)
        choice = raw_input("Do you wish to continue(y/n)?")
        if choice == 'n' or choice == 'N':
                         break

payIntList = map(int,payList)

for i in range(numElements):
         payIntList[i] = payIntList[i] + 1000
         print payIntList[i]
Run Code Online (Sandbox Code Playgroud)

python python-3.x

59
推荐指数
2
解决办法
9万
查看次数

是否有一个python模块来解决线性方程?

我想用三个或更多变量求解线性方程.在python中有一个很好的库来做吗?

python

40
推荐指数
4
解决办法
6万
查看次数

如何从解码的JSON对象中删除"u"?

我在Python中有一本字典词典:

d = {"a11y_firesafety.html":{"lang:hi": {"div1": "http://a11y.in/a11y/idea/a11y_firesafety.html:hi"}, "lang:kn": {"div1": "http://a11y.in/a11ypi/idea/a11y_firesafety.html:kn}}}
Run Code Online (Sandbox Code Playgroud)

我在JSON文件中有这个,我用它编码json.dumps().现在,当我使用json.loads()Python 解码它时,我得到一个这样的结果:

temp = {u'a11y_firesafety.html': {u'lang:hi': {u'div1': u'http://a11y.in/a11ypi/idea/a11y_firesafety.html:hi'}, u'lang:kn': {u'div1': u'http://a11y.in/a11ypi/idea/a11y_firesafety.html:kn'}}}
Run Code Online (Sandbox Code Playgroud)

我的问题在于"u",它表示我的temp(字典词典)中每个项目前面的Unicode编码.如何摆脱那个"你"?

python

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

什么是次线性算法?

我的一位同事问我以下问题.

Which of the following expressions is not sublinear?
O(log log n)
O(n)
O(logn)
O(root(n))
Run Code Online (Sandbox Code Playgroud)

我已经浏览了https://en.wikipedia.org/wiki/Time_complexity#Sub-linear_time但不能,但我不确定我是否完全了解它.有人能指出我正确的方向.

algorithm limits asymptotic-complexity

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

从python列表中删除"u"

我有一个列表的python列表如下.我想把它压平成一个列表.

l = [u'[190215]']
Run Code Online (Sandbox Code Playgroud)

我在尝试.

l = [item for value in l for item in value]
Run Code Online (Sandbox Code Playgroud)

它将列表转换为 [u'[', u'1', u'9', u'0', u'2', u'1', u'5', u']']

如何u从列表中删除.

python

10
推荐指数
3
解决办法
3万
查看次数

为什么Linux中的Makefile如此有用?

我想知道为什么Linux中的makefile非常有用(我的意思是在实际意义上).为什么我们不能以正常方式编译所有程序?

c linux makefile

8
推荐指数
4
解决办法
4571
查看次数

python中的scrapy Crawler无法跟踪链接?

我使用python的scrapy工具在python中编写了一个爬虫.以下是python代码:

from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
#from scrapy.item import Item
from a11ypi.items import AYpiItem

class AYpiSpider(CrawlSpider):
        name = "AYpi"
        allowed_domains = ["a11y.in"]
        start_urls = ["http://a11y.in/a11ypi/idea/firesafety.html"]

        rules =(
                Rule(SgmlLinkExtractor(allow = ()) ,callback = 'parse_item')
                )

        def parse_item(self,response):
                #filename = response.url.split("/")[-1]
                #open(filename,'wb').write(response.body)
                #testing codes ^ (the above)

                hxs = HtmlXPathSelector(response)
                item = AYpiItem()
                item["foruri"] = hxs.select("//@foruri").extract()
                item["thisurl"] = response.url
                item["thisid"] = hxs.select("//@foruri/../@id").extract()
                item["rec"] = hxs.select("//@foruri/../@rec").extract()
                return item
Run Code Online (Sandbox Code Playgroud)

但是,抛出的错误不是跟随链接,而是:

Traceback (most recent call last):
  File …
Run Code Online (Sandbox Code Playgroud)

python scrapy

7
推荐指数
1
解决办法
5114
查看次数

使用python nltk查找两个网页之间的相似性?

我想找出两个网页是否相似.有人可以建议如果python nltk与wordnet相似性功能有用,如何?在这种情况下使用的最佳相似度函数是什么?

python nlp nltk wordnet

7
推荐指数
1
解决办法
5985
查看次数

如何删除mongodb中列表中的重复值

我有一个mongodb系列.当我做.

db.bill.find({})
Run Code Online (Sandbox Code Playgroud)

我明白了

{ 
    "_id" : ObjectId("55695ea145e8a960bef8b87a"),
    "name" : "ABC. Net", 
    "code" : "1-98tfv",
    "abbreviation" : "ABC",
    "bill_codes" : [  190215,  44124,  190215,  147708 ],
    "customer_name" : "abc"
}
Run Code Online (Sandbox Code Playgroud)

我需要一个操作来从bill_codes中删除重复的值.最后它应该是

{ 
    "_id" : ObjectId("55695ea145e8a960bef8b87a"),
    "name" : "ABC. Net", 
    "code" : "1-98tfv",
    "abbreviation" : "ABC",
    "bill_codes" : [  190215,  44124,  147708 ],
    "customer_name" : "abc"
}
Run Code Online (Sandbox Code Playgroud)

如何在mongodb中实现这一目标.

mongodb pymongo mongodb-query aggregation-framework

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