我想用新名称重命名/替换部分字符串。
我有一个表示文件的字符串,包括其路径和文件扩展名,如下所示。
source_file = 'images/filename.jpg'
Run Code Online (Sandbox Code Playgroud)
下面显示了我到目前为止所尝试的内容。但是,它有效,有没有更好的方法来产生相同的结果?我通过更短的语法和更高效来定义“更好”。
import uuid
source_file = 'images/filename.jpg'
split = source_file.rsplit('/', 1)
path, filename = split[0], split[1]
ext = filename.rsplit('.', 1)[1]
# rebuild
renamed = path + str(uuid.uuid4()) + ext
Run Code Online (Sandbox Code Playgroud) 在Django中使用查询集(在视图中)我只想获得所述行51-100.即我只希望它返回这些行.
这是可能的,如何在内.
objectQuerySet = Recipient.objects.filter(incentiveid=incentive).order_by('fullname')
Run Code Online (Sandbox Code Playgroud)
我不想使用任何寻呼系统等这只是一次性的事情?
谢谢
我今天早上遇到重大问题,试图在Mac上安装mysql-python连接器.
问题归结于xcode 5.1的最新更新:
http://bruteforce.gr/installing-mitmproxy-os-x-maverics-bypassing-clang-error-unknown-argument.html
http://forums.getpebble.com/discussion/11862/installation-error-perhaps-due-to-xcode-5-1
但是,我已经尝试了当前的解决方法,我仍然得到错误:
这是我尝试过的:
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future sudo pip install mysql-python
Run Code Online (Sandbox Code Playgroud)
这是错误:
cc -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.9-intel-2.7/_mysql.o -Os -g -fno-strict-aliasing -arch x86_64
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit …Run Code Online (Sandbox Code Playgroud) 我的类需要一个称为资源的扩充:
> AClass(resource="123")
Run Code Online (Sandbox Code Playgroud)
类:
class AClass(Base):
def __init__(self, resource):
super(AClass, self).__init__(self)
Run Code Online (Sandbox Code Playgroud)
这将在它扩展的Base类中设置.
class BaseHTTP(object):
def __init__(self, resource, data=None):
self.resource = resource
Run Code Online (Sandbox Code Playgroud)
在Python 2.7中我应该做些什么来确保基类获取这些参数,这是好的......
super(Get, self).__init__(self, resource)
Run Code Online (Sandbox Code Playgroud) 这个神奇的函数是如何工作的(如下),即hex = '%032x' % self.int由于某种原因它会变成以下值......
265631021230191344138857284998518456
进入....
0033289ed88646a64b9fc63c808fd6b8
def __str__(self):
hex = '%032x' % self.int
return hex
Run Code Online (Sandbox Code Playgroud)
但据我所知,这一切实际上应该是附加032x到字符串的末尾265631021230191344138857284998518456,那么发生了什么?它是如何做它所做的事情的?
我有以下字符串:
2016-04-29T00:00:00 + 01:00
我想使用Python将其转换为Unix日期时间戳.
我试过这个把它转换成日期对象:
dt = datetime.datetime.strptime(validated_data.get('scheduled_datetime', None), '%Y-%m-%dT%H:%M:%SZ')
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
time data '2016-04-29T00:00:00+01:00' does not match format '%Y-%m-%dT%H:%M:%S'
Run Code Online (Sandbox Code Playgroud) 如果这些可能的字符串我想要获取页码:
$scope.projects.next 可以等于......
我试过这个:
$scope.projects.next.split('=')[1].indexOf("page")
Run Code Online (Sandbox Code Playgroud)
但是,这仅适用于字符串2.如何更改此项以确保它找到页码,无论可以添加哪个位置或将来的参数?
我也尝试过:
$scope.projects.next.indexOf("page")
Run Code Online (Sandbox Code Playgroud)
但这52不知道为什么.