开发者

why my code print this when i read and write

def sss(request):
    handle=open('b.txt','r+')
    handle.write("I AM NEW FILE")
    var=handle.read();    
    return HttpResponse(var)

urlpatterns = patterns('',
    ('^$',sss),
)

1.my b.txt has nothing

2.when i run my code ,it print this :

I AM NEW FILE7                                                                                                                                                                                                                                            鸸?; ??x 鸸鸸v1鸸pZ€0  鸸鸸燛?鸸8N鸸鸸p 坮 愵) 犭 ?`16鸸鸸 S6鸸鸸榑 鸸? 鸸@ 鸸鸸p叠  {鸸€1鸸鸸 V 鸸鸸 @+ 爏 鸸 职 鑮 鸸鸸鸸`埤   >?) ?鸸鸸@? Z!x`%鸸p?鸸? 鸸鸸鄧鸸鸸@?`7鸸鸸鸸`? 柜 鸸鸸鑎1X 鸸鸸鸸鸸鸸?#鸸餷?鸸€0鸸(Q?鸸H?鸸P?#鸸 ' 鸸(5 ?, 7鸸啵6H宏 0??+噌?  k%8除 `烋 鸸爐"繳`  鸸埻 鸸0?郤 鸸鸸鸸?爛/啊 鸸鸸鸸睾8S1`?`?鸸鸸悀0鸸 ?`??鸸繧爅 鸸餡 鸸些 鸸鸸鸸鸸鸸@]鄡HE,鸸鸸?瘅+?+鸸鸸鸸p戙 @O鸸?? 鸸鸸 37€P6蠯7鸸@= 鸸嘣 囗 ?+xP?x?如?70暡 鸸鸸鸸鸸鸸鸸 €鸸鸸鸸€ h *??x 纙1鸸鸸鸸€K  叠 鸸鹞8? ?鸸  鸸萰 鸸`?辣   @?饆 鸸鸸鸸鸸? 鸸€?鸸鸸鸸鸸鸸鄧鸸8(鸸P⒊  ?鸸? p(0B?鸸鸸嗨鸸鸸鸸鸸李 鸸鸸鸸邪 P?鸸鸸鸫 爛/爦+鸸蜣 9 鸸 楈 ?鸸鸸怱1鸸鸸恏鸸鸸鸸鸸袖 ; 鸸€?鸸€札 `?(?鸸ㄈ 鸸鸸+ 鸸栉0鸸愵 鸸鸸恾谿6 ?1谹,鸸鸸鸸 {0鸸鸸? X?鸸€D 鸸&?€?` 鸸H{ ?鸸葉Xw鸸鸸鸸皢 鸸狑 鸸鄩0缊0堩)€Q 鸸? ?鸸 ④ @?鸸鸸鸸鸸鸸 ?XA6鸸鸸? O 鸸0 h 鸸 鸸鸸李 鸸 ? j鸸鸸鸸鸸0昌  57極7@?H+ 鸸鸩  尛 `?鸸 18戙 鸸P  ?噍6嗤0鸸鸸鸸楧6鸸坆 鸸a 鸸` 鸸鸸鸸鸸鸸鸸鸸惍砾 pG8s鸸鸸鸸@ ?   (, 蠵 ( 鄭? 鸸╒&鸸缞鸸鐽圡7鸸繮!0[ 0m 鸸鸸鸸鸸@?発0鸸鸸鸸鸸鸸?  ?鸸饗 p?pZ爦+鸸@?€\1鸸犎 0如 ?艾 鸸棱? 鸸€;鸸? 鸸鸸`? 褶 ? 鸸鸸鸸给*`7鸸@嵀 6 R 恈鸸鸸鸸鸸p?鸸饇鸸埪00^#燽 鸸鸸8褶 h €,h ? 鸸鸸x+ 鸸鸸€37鸸鸸鸸鸸`+鸸P?鸸 1  杞 鸸鸸鸸鸸惥*鸸郔6鸸李 鸸鸸h: 鸸鸸83 ? 哀犎鸸鸸0s 鸸鸸鸸鸸? 蝎p篆 鸸鸸鸸鸸鸸纞"  s找( ??x                                                                                                                                                                                                                                                                                                                                                                           开发者_StackOverflow社区                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Q s l??x ndies".
    * If value is 1, cand{{ value|pluralize:"y,ies" }} displays "1 candy".
    * If value is 2, cand{{ value|pluralize:"y,ies" }} displays "2 candies".
    u   ,i   u    i   (   RE   RG   R5   R3   R4   (   R    R<   R   t   singular_suffixt
   plural_suffix(    (    s?   D:\Python25\lib\site-packages\django\template\defaultfilters.pyt    pluralize4  s$    

c         C   s   d d k  l } | |  ? S(   sD   Takes a phone number and converts it in to its numerical equivalent.i(   t
   phone2numeric(   Rc   R   (   R    R 

why?

thanks


The only way I can repro this is to open an existing non-empty file using 'r+' (Are you absolutely sure it's empty?). In any event, opening the file in the 'w+' mode truncates it.


What middle-ware are you using? I guess that you have a lot of middle-ware installed, which explains some of the garbage.

For debugging, use a logging module to log what var was. Otherwise you can't isolate the problem, right?

Also, should you convert the string to unicode before sending it off to HttpResponse?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜