小编dan*_*ani的帖子

在python中转换unicode字符串

{u'Status': u'OK', u'City': u'Ciri\xe8', u'TimezoneName': '', u'ZipPostalCode': '', u'CountryCode': u'IT', u'Dstoffset': u'0', u'Ip': u'x.x.x.x', u'Longitude': u'7.6', u'CountryName': u'Italy', u'RegionCode': u'12', u'Latitude': u'45.2333', u'Isdst': '', u'Gmtoffset': u'0', u'RegionName': u'Piemonte'}
Run Code Online (Sandbox Code Playgroud)

这是我的对象的输出.我想访问City,但它是编码的.如何读取所有参数并对其进行解码

>>> data['City']
u'Ciri\xe8'

>>>data['City'].decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 4: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

我想明文不是unicode字符串.谢谢!

python unicode dictionary

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

在lxml中选择html注释之间的div

这是我的html文件

<div>
   <div></div>
   <div></div>
   <!--Comment1-->
   <div>1</div>
   <div>2</div>
   <div>3</div>
   <!--Comment2-->
   <div></div>
   <div></div>
   <div></div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想在Comment 1和Comment 2之间选择div

有了这个xPath ="/ div/comment()",我可以选择 <!--Comment1--><!--Comment2-->

但我想选择这个

   <div>1</div>
   <div>2</div>
   <div>3</div>
Run Code Online (Sandbox Code Playgroud)

html python xml xpath parsing

3
推荐指数
1
解决办法
735
查看次数

Django 1.4定义用户

(pythonanywhere2)bash-3.2$ python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/huksy/Documents/virtualenv/pythonanywhere2/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File …
Run Code Online (Sandbox Code Playgroud)

python sqlite django django-models

3
推荐指数
1
解决办法
1374
查看次数

删除python中字符串开头的一些点

我有一些以点开头的字符串,我想删除它.哪种方式最好.如果下一个字符不是"/"则添加它.我是python中的新手,我一直在尝试做这样的事情来擦除点,但是有一个语法错误.

while (re.match(r'\.*', url[0]).end()) = 0:
   url = url[1:]
Run Code Online (Sandbox Code Playgroud)
  • ..../xxx --->/xxx
  • .xxx --->/xxx
  • ..ab --->/ab
  • / ab --->/ab
  • ca --->/ca.

这就是我想要做的.

python regex string

2
推荐指数
2
解决办法
1680
查看次数

功能参数

我必须把这个作为第二个参数放在这个函数中?我需要理解的含义int (*fn)(const char *, const struct stat *ptr, int flag).

int 
ftw(const char *path, int (*fn)(const char *, const struct stat *ptr, int flag), 
int depth);
Run Code Online (Sandbox Code Playgroud)

谢谢!!

c function-pointers

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

编译C和C++

我有一个用C编写的程序,我需要使用用C++编写的KDIS库.我在KDevelop中使用automake和朋友编译我的C程序.我怎么能一起编译所有东西?因为我想在我的C程序中调用一些KDIS函数.

先感谢您.

c c++ compilation

0
推荐指数
1
解决办法
217
查看次数

通过引用其他函数传递缓冲区

我想将缓冲区和缓冲区长度的指针传递给其他函数,然后使用此数据进行操作并打印它.但是当我尝试在功能上打印它是不可能的.

这是我的代码的一部分:

  void process(KOCTET**bufferlist,KUINT16*lenlist){
        KOCTET * Buffer,*temp;
        KUINT16 BufferSize=5000;
        KUINT16 WritePos=0;
        KUINT16 total_bytes;
        Buffer=(KOCTET*)malloc(5000*sizeof(KOCTET));

        total_bytes = stream.CopyIntoBuffer( Buffer, BufferSize, WritePos);

        bufferlist=(KOCTET**)malloc(sizeof(KOCTET*));
        bufferlist=&Buffer;
        lenlist=(KUINT16*)malloc(sizeof(KUINT16));
        lenlist=&total_bytes;

           //Print Buffer in Hexadecimal
           int z=0;
           temp=Buffer;
           while (z<total_bytes){
              printf(" %02X",(unsigned char)*temp);
              temp++;
              z++;
           }
           printf("\n");
    }


    void function ()
    {
         KOCTET**bufferlist;
         KUINT16*lenlist;

         process(bufferlist,lenlist);

         //Print Buffer in Hexadecimal
           int z=0;
           temp=*bufferlist;
           while (z<(*lenlist)){
              printf(" %02X",(unsigned char)*temp);
              temp++;
              z++;
           }
           printf("\n");
    }
Run Code Online (Sandbox Code Playgroud)

谢谢,

c pointers function

0
推荐指数
1
解决办法
1098
查看次数