小编gad*_*dss的帖子

如何将字符串更改为大写

我在使用Python将字符串更改为大写时遇到问题.在我的研究中,我得到string.ascii_uppercase但它不起作用.

以下代码:

 >>s = 'sdsd'
 >>s.ascii_uppercase
Run Code Online (Sandbox Code Playgroud)

给出此错误消息:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'str' object has no attribute 'ascii_uppercase'
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何在Python中将字符串转换为大写?

python string uppercase

697
推荐指数
6
解决办法
116万
查看次数

django order_by查询集,升序和降序

如何通过按日期降低django中的查询集来订购?

Reserved.objects.all().filter(client=client_id).order_by('check_in')
Run Code Online (Sandbox Code Playgroud)

我只想过滤掉所有保留的check_in日期.

python sorting django

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

错误:无法创建'/usr/local/lib/python2.7/dist-packages/virtualenv_support':权限被拒绝

我正在使用ubuntu 12.04而我正在尝试使用安装virtualenv,但突然间我遇到了这个错误.

samuel@sampc:~$ pip install virtualenv
Downloading/unpacking virtualenv
  Running setup.py egg_info for package virtualenv

    warning: no previously-included files matching '*' found under directory 'docs/_templates'
    warning: no previously-included files matching '*' found under directory 'docs/_build'
Installing collected packages: virtualenv
  Running setup.py install for virtualenv
    error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/samuel/build/virtualenv/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-Z2v_fR-record/install-record.txt:
    running install

running build

running build_py

running install_lib

creating /usr/local/lib/python2.7/dist-packages/virtualenv_support

error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': …
Run Code Online (Sandbox Code Playgroud)

python pip virtualenv ubuntu-12.04

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

如何在python中获取datetime中的日期名称?

如何在python的datetime中获取日期名称(例如:星期一,星期二,星期三,星期四,星期五,星期六和星期日)?...

这是我的handlers.py中的代码

    from django.utils.xmlutils import SimplerXMLGenerator
    from piston.handler import BaseHandler
    from booking.models import *
    from django.db.models import *
    from piston.utils import rc, require_mime, require_extended, validate
    import datetime

    class BookingHandler(BaseHandler):
        allowed_method = ('GET', 'POST', 'PUT', 'DELETE')
        fields = ('id', 'date_select', 'product_name', 'quantity', 'price','totalcost', 'first_name', 'last_name', 'contact', 'product')
        model = Booking

       def read(self, request, id, date_select):
        if not self.has_model():
            return rc.NOT_IMPLEMENTED
        try:   
            prod = Product.objects.get(id=id)
            prod_quantity = prod.quantity
            merge = []
            checkDateExist = Booking.objects.filter(date_select=date_select)
            if checkDateExist.exists():
                entered_date = Booking.objects.values('date_select').distinct('date_select').filter(date_select=date_select)[0]['date_select']
            else: …
Run Code Online (Sandbox Code Playgroud)

python django datetime django-piston

50
推荐指数
2
解决办法
7万
查看次数

如何覆盖css样式

我正在开发页面,现在我的css风格我有这行代码

.flex-control-thumbs li {
    width: 25%;
    float: left;
    margin: 0;
}
Run Code Online (Sandbox Code Playgroud)

对于我的网页.现在,我的一些页面不需要这一行

width: 25%;
float: left;
Run Code Online (Sandbox Code Playgroud)

我可以在页面的内部css中覆盖它,这会导致原始行为被忽略吗?

html css

46
推荐指数
4
解决办法
19万
查看次数

ImportError:没有名为virtualenv的模块

我在windows7上使用Django 1.3.7和python 2.7.6当我在这行代码中执行manage.py时遇到错误

import shutil, sys, virtualenv, subprocess
Run Code Online (Sandbox Code Playgroud)

运行它,我得到了这个错误

C:\Django-Proj\>python manage.py update_ve
Traceback (most recent call last):
  File "manage.py", line 4, in <module>
    import shutil, sys, virtualenv, subprocess
ImportError: No module named virtualenv
Run Code Online (Sandbox Code Playgroud)

有没有人对我的案子有所了解?

python django windows-7

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

如何在django的queryset中查询子查询?

我怎么能在django的查询集中有一个子查询?例如,如果我有:

select name, age from person, employee where person.id = employee.id and
employee.id in (select id from employee where employee.company = 'Private')
Run Code Online (Sandbox Code Playgroud)

这就是我所做的.

Person.objects.value('name', 'age')
Employee.objects.filter(company='Private')
Run Code Online (Sandbox Code Playgroud)

但它没有工作,因为它返回两个输出...

python django

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

用户操作正在等待后台工作完成

我正在使用eclipse junno为我的IDE开发android程序.

我的问题就像这样: 用户操作正在等待"构建工作区"

为什么会这样,我该如何解决?关于这个案子我已经等了很多时间.

现在它看起来像这样.

在此输入图像描述

eclipse android

25
推荐指数
2
解决办法
4万
查看次数

获取django视图中的复选框帖子列表

我在我的模板中有这个代码:

{% for email in emails %}
  {%if email%}
     <input type="checkbox" name="email" value="{{email}}" /> {{email}}<br />
  {% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

所以模板中的输出是:

email1@sample.com
email2@sample.com
email3@sample.com
...
Run Code Online (Sandbox Code Playgroud)

在我看来,我打印了我的请求.关于这个.

print request.POST
print request.POST['email']
for email in request.POST['email']:
 print email
Run Code Online (Sandbox Code Playgroud)

我有这个输出:

<QueryDict: {u'email': [u'email1@sample.com', u'email2@sample.com', u'email3@sample.com'], ..., u'csrfmiddlewaretoken': [u'05e5bdb542c3be7515b87e8160c347a0', u'05e5bdb542c3be7515b87e8160c347a0']}>
email3@sample.com
e
m
a
i
l
3
@
s
a
m
p
l
e
.
c
o
m
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何在我的观点中获取电子邮件列表?我希望输出会像这样..

email1@sample.com
email2@sample.com
email3@sample.com
...
Run Code Online (Sandbox Code Playgroud)

python django django-templates

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

系统找不到java中指定的文件

我正在制作一个打开并读取文件的程序.这是我的代码:

import java.io.*;

public class FileRead{
    public static void main(String[] args){
        try{
            File file = new File("hello.txt");
            System.out.println(file.getCanonicalPath());
            FileInputStream ft = new FileInputStream(file);

            DataInputStream in = new DataInputStream(ft);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strline;

            while((strline = br.readLine()) != null){
                System.out.println(strline);
            }
            in.close();
        }catch(Exception e){
            System.err.println("Error: " + e.getMessage());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时,我收到这个错误:

C:\Users\User\Documents\Workspace\FileRead\hello.txt
Error: hello.txt (The system cannot find the file specified)
Run Code Online (Sandbox Code Playgroud)

FileRead.javahello.txt在同一目录中的位置可以找到:

C:\Users\User\Documents\Workspace\FileRead
Run Code Online (Sandbox Code Playgroud)

我想知道我做错了什么?

java file

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