编写一个简单的脚本,自动重命名一些文件.作为一个例子,我们希望将文件*001.jpg重命名为用户定义的字符串+ 001.jpg(例如:MyVacation20110725_001.jpg)此脚本的用法是让数码相机照片具有合理的文件名.
我需要为此编写一个shell脚本.有人可以建议如何开始吗?
为什么以下脚本会出错:
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中有一本字典词典:
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编码.如何摆脱那个"你"?
我的一位同事问我以下问题.
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但不能,但我不确定我是否完全了解它.有人能指出我正确的方向.
我有一个列表的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从列表中删除.
我想知道为什么Linux中的makefile非常有用(我的意思是在实际意义上).为什么我们不能以正常方式编译所有程序?
我使用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 nltk与wordnet相似性功能有用,如何?在这种情况下使用的最佳相似度函数是什么?
我有一个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中实现这一目标.