小编use*_*619的帖子

安装python dateutil

我尝试为我的django tastypie安装python dateutil但是不成功,

http://labix.org/python-dateutil#head-2f49784d6b27bae60cde1cff6a535663cf87497b

我在c:/ python27中下载了tar文件并将其解压缩,

我收到以下错误信息,

**C:\Python27\Scripts>**easy_install dateutil-1.5
Searching for dateutil-1.5
Reading http://pypi.python.org/simple/dateutil-1.5/
Couldn't find index page for 'dateutil-1.5' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for dateutil-1.5
Best match: None
Traceback (most recent call last):
  File "C:\Python27\Scripts\easy_install-script.py", line 8, in <module>
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 171
2, in main
  File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 170
0, in with_ei_usage
  File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 171
6, in …
Run Code Online (Sandbox Code Playgroud)

python django python-dateutil

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

Python反向列表

我正在尝试反转字符串并使用下面的代码,但结果反向列表值为None.

代码:

str_a = 'This is stirng'
rev_word = str_a.split()
rev_word = rev_word.reverse()
rev_word = ''.join(rev_word)
Run Code Online (Sandbox Code Playgroud)

它返回TypeError.为什么?

python

47
推荐指数
4
解决办法
9万
查看次数

序列化django休息框架时的附加字段

我是django rest框架的新手,并创建了一个示例Employee模型.

我的models.py:

class Employees(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
Run Code Online (Sandbox Code Playgroud)

我的serializers.py:

class EmployeeSerializer(serializers.Serializer):
    class Meta:
        model = Employees
        fields = ('first_name','last_name')
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我想要一个额外的字段full_name,这将是first_name + last_name.

如何定义这个全新的领域full_name,我serializers.py

django django-models django-rest-framework

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

从Solr Admin中删除solr文档

如何使用SOLR Admin删除SOLR索引中的所有文档.

我尝试使用网址但它有效,但想知道是否可以使用管理员完成相同的操作.

solr

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

Python:"TypeError:__str__返回非字符串"但仍打印到输出?

我有这段代码创建一个新的笔记..我尝试打印我得到以下错误,即使它打印输出

Error:
C:\Python27\Basics\OOP\formytesting>python notebook.py
Memo=This is my first memo, Tag=example
Traceback (most recent call last):
  File "notebook.py", line 14, in <module>
    print(firstnote)
TypeError: __str__ returned non-string (type NoneType)
Run Code Online (Sandbox Code Playgroud)

note.py

import datetime
class Note:
    def __init__(self, memo, tags):
        self.memo = memo
        self.tags = tags
        self.creation_date = datetime.date.today()

    def __str__(self):
        print('Memo={0}, Tag={1}').format(self.memo, self.tags)


if __name__ == "__main__":
    firstnote = Note('This is my first memo','example')
    print(firstnote)
Run Code Online (Sandbox Code Playgroud)

python

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

ORACLE IIF声明

我在编写IIF stamtement,table和下面给出的声明时遇到错误,

声明:

SELECT IIF(EMP_ID=1,'True','False') from Employee;
Run Code Online (Sandbox Code Playgroud)

错误:00907-错过了正确的parantheses

CREATE TABLE SCOTT.EMPLOYEE
(
  EMP_ID       INTEGER                          NOT NULL,
  EMP_FNAME    VARCHAR2(30 BYTE)                NOT NULL,
  EMP_LNAME    VARCHAR2(30 BYTE)                NOT NULL,
  EMP_ADDRESS  VARCHAR2(50 BYTE)                NOT NULL,
  EMP_PHONE    CHAR(10 BYTE)                    NOT NULL,
  EMP_GENDER   CHAR(1 BYTE)
)
Run Code Online (Sandbox Code Playgroud)

请提供您的意见.

oracle ternary-operator iif

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

如何将python变量设置为true或false?

我想在Python中将变量设置为true或false.但单词truefalse被解释为未定义的变量:

#!/usr/bin/python
a = true; 
b = true;
if a == b:          
  print("same");
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

a = true
NameError: global name 'true' is not defined 
Run Code Online (Sandbox Code Playgroud)

设置变量true或false的python语法是什么?

Python 2.7.3

boolean constants python-2.7

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

Oracle将时间戳与日期进行比较

我有一个时间戳字段,我只想在Oracle的查询中比较它的日期部分

我怎么做,

SELECT *
FROM Table1
WHERE date(field1) = '2012-01-01' 
Run Code Online (Sandbox Code Playgroud)

oracle

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

用于删除最后一个逗号的Python字符串函数

输入

str = 'test1,test2,test3,'
Run Code Online (Sandbox Code Playgroud)

输出继电器

str = 'test1,test2,test3'
Run Code Online (Sandbox Code Playgroud)

剥离','的最后一次出现的要求

python

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

python访问子类中的超类变量

我想在子类中访问self.x的值.我该如何访问它?

class ParentClass(object):

    def __init__(self):
        self.x = [1,2,3]

    def test(self):
        print 'Im in parent class'


class ChildClass(ParentClass):

    def test(self):
        super(ChildClass,self).test()
        print "Value of x = ". self.x


x = ChildClass()
x.test()
Run Code Online (Sandbox Code Playgroud)

python

24
推荐指数
2
解决办法
5万
查看次数