English 中文(简体)
cx_Oracle - encoding query result to Raw
原标题:cx_Oracle - encoding query result to Raw

http://www.un.org。

下面的印刷显示了我的预期价值。

(sys.stdout.encoding and sys.stdin.encoding are UTF-8 )。

为什么变量价值不同于其印刷价值? 我需要将原材料变成一个变量。

>>username =  Joxc3xa3o 
>>username.decode( utf-8 ).encode( latin-1 )
 Joxe3o 
>>print username.decode( utf-8 ).encode( latin-1 )
João

www.un.org/Depts/DGACM/index_spanish.htm

I m 有一个问题,质疑BD,把价值分解成Avre。

我确认了我的行文—— 变式

select property_value from database_properties 地点 property_name= NLS_CHARACTERSET ;

   AL32UTF8 stores characters beyond U+FFFF as four bytes (exactly as Unicode defines 
UTF-8). Oracle’s “UTF8” stores these characters as a sequence of two UTF-16 surrogate
characters encoded using UTF-8 (or six bytes per character)   

os.environ["NLS_LANG"] = ".AL32UTF8"

....
conn_data = str( %s/%s@%s ) % (db_usr, db_pwd, db_sid)

sql = "select user_name apex.users 地点 user_id =  %s " % userid

...

cursor.execute(sql)
ldap_username = cursor.fetchone()
...

地点

print ldap_username
>> Joxc3xa3o 

我把这两人都进行了审判(回过来)。

ldap_username.decode( utf-8 )
>>u Joxe3o 
unicode(ldap_username,  utf-8 )
>>u Joxe3o 

地点

u João .encode( utf-8 )
>> Joxc3xa3o 

如何回答问题?

最佳回答

你们已经有了适当的João ,见面人。 <代码>>>> Joxc3xa3o 和>>>text Joxc3xa3o 之间的区别是,以前的电话<代码>repr对标的,而后一电话str(或大概unicode,就你而言)。 这恰恰是扼杀的体现。

某些例子可能会使这一点更加明确:

>>> print  Joxc3xa3o .decode( utf-8 )
João
>>>  Joxc3xa3o .decode( utf-8 )
u Joxe3o 
>>> print repr( Joxc3xa3o .decode( utf-8 ))
u Joxe3o 

通知第二和第三次结果如何相同。 原始<代码>ldap_username目前为ASCII string。 我们可以从速看到这一点:在显示ACSII物体时,它显示为。 缩略语 www.un.org/Depts/DGACM/index_french.htm

因此,正如您的<代码>ldap_username, 原文为, 并作为ASCII的载体,适用如下:

>>>  Joxc3xa3o .decode( utf-8 )
u Joxe3o 
>>> print  Joxc3xa3o .decode( utf-8 ) # To Unicode...
João
>>> u João .encode( utf-8 )             # ... back to ASCII
 Joxc3xa3o 

概述:你需要确定在无证情况下的扼杀类型(使用<条码> 类型),并在此基础上确定统法协会编码或编码为ASCII。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签