Very dumb question

Rocco Moretti roccomoretti at hotpop.com
Wed Oct 12 10:03:29 EDT 2005


Laszlo Zsolt Nagy wrote:
> Laszlo Zsolt Nagy wrote:
> 
>> I have a program with this code fragment:
>>
>>    print len(data)
>>    print data[:50]
>>    raise SystemExit
>>
>> This prints:
>>
>> 20381
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
>>
>> But if I change 50 to 51
>>
>>    print len(data)
>>    print data[:51]
>>    raise SystemExit
>>
>> then it prints
>>
>> 20381
>> !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
>>
>> After all, only the last 50 bytes are printed. The string is the same 
>> (length 20381) in both cases.
>>  
>>
> Hmm, I checked on Windows now and it is working. But it is bad on 
> FreeBSD/Python 2.4.1
> Very strange. len(data[:100]) returns 100, but if I try to print it, 
> only the first 50 characters printed.
> 
>   Les

Is 'data' a Unicode string, or do you have some terminal control 
charachters in the string? Most printable ASCII charachters are between 
32 and 126. What does this print?:

print [i for (i,c) in enumerate(data) if not (32 <= ord(c) <= 126)]



More information about the Python-list mailing list