我正在尝试使用python获取上周的日期。
如果日期为:2014年10月10日为
应该打印
10 OCT 2014, 09 OCT 2014, 08 OCT 2014, 07 OCT 2014, 06 OCT 2014, 05 OCT 2014, 04 OCT 2014
Run Code Online (Sandbox Code Playgroud)
我试过了:
today = (10 OCT 2014)
dates = [today + datetime.timedelta(days=i) for i in range(-4 - today.weekday(), 4 - today.weekday())]
print dates
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
exceptions.AttributeError: 'unicode' object has no attribute 'weekday'
Run Code Online (Sandbox Code Playgroud) 我有功能:
imagewidth = 250
y_positions = [65.0, 85.0, 105.0, 125.0, 145.0, 165.0]
numbers_to_show = [20, 30, 40, 50, 60, 70]
def draw_numbers(imagewidth, y_positions, numbers_to_show):
counter = 0
while counter < len(y_positions):
numbers_to_show = str(numbers_to_show[counter])
font = ImageFont.truetype("impact.ttf",20)
img = Image.open("agepyramid.bmp")
draw = ImageDraw.Draw(img)
draw.text(20 , y_positions[counter],numbers_to_show,(0,0,0),font=font)
draw = ImageDraw.Draw(img)
img.save("agepyramid.bmp")
counter = counter + 1
Run Code Online (Sandbox Code Playgroud)
我认为此函数应该给我一张图片,图片的“ y_position”处带有“ numbers_to_show”,但是它给了我这个错误:
draw.text(20 , y_positions[counter],numbers_to_show,(0,0,0),font=font)
TypeError: text() got multiple values for argument 'font'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个文件的路径:
'home/user/directory/filename'
Run Code Online (Sandbox Code Playgroud)
我想得到filename-subpart.主要问题是,我不知道我的字符串的长度,我不知道filename-subpart 的长度.我知道只有文件名放在最后一个斜杠之后的字符串末尾/.字符串中的斜杠数量可以是绝对随机的(因为我想从某些PC上的每个目录中获取文件名).因此,我暂时没有看到索引提取的常用方法,如下所示:
string[number:]
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
嗨,我想在此列表中将"0x"替换为"\ x":
['0x50', '0x0', '0x0', '0x0']
Run Code Online (Sandbox Code Playgroud)
我尝试了这个列表理解:
result = ['0x50', '0x0', '0x0', '0x0']
result = [x.replace("0x","\x") for x in result]
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
(unicode error)"unicodeescape" codex cant decode byte in position 0-1: truncated \xXX escape
Run Code Online (Sandbox Code Playgroud)
我现在如何更改"0x"和"\ x"?