473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Very dumb question

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.
Surprisingly, I can print more than 50 characters, this works:

print "0123456789012345678901234567890123456789012345678 90123456789A"

I'm sure it is my mistake, but I don't know what am I doing wrong. Do
you have an idea?
Thanks,

Les

Oct 12 '05 #1
4 1255
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. (snip
I'm sure it is my mistake, but I don't know what am I doing wrong. Do
you have an idea?


I assume the code snippets are exact copy/paste so this is not a typo
(like print data[51:] ...) - and I can't reproduce it here... even with
a string of 20381 characters.

mmm...

type(data) ???

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 12 '05 #2
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"


The closest I can get to your situation is

[on linux]
print "abc\rx"[:4] abc print "abc\rx"[:5]

xbc

i. e. a character after a 'carriage return' ('\r') overwrites part of the
string which therefore doesn't seem to grow. Try

print repr(data[:51])

to see what's really in your data string.

Peter

Oct 12 '05 #3

I assume the code snippets are exact copy/paste so this is not a typo
(like print data[51:] ...) - and I can't reproduce it here... even with
a string of 20381 characters.

Yes, they were cut out. type(data) returns '<type str>'.
The data was downloaded from a website, it starts with

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Even if it had special control characters in it, I do not understand the
effect (printing only the first 50 chars).
But probably it is an issue with the terminal, since it is working fine
on Windows.

Les

Oct 12 '05 #4
i. e. a character after a 'carriage return' ('\r') overwrites part of the
string which therefore doesn't seem to grow. Try

print repr(data[:51])

to see what's really in your data string.

Yes, that was it! Thanks for you help. I thought it will be something
obvious.
The server returned carriage returns in the HTML source code, and I
tried to print that. :-)

Les

Oct 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: squash | last post by:
a dumb question i had on my mind: Say you have a dynamically created web page . Isn't it more secure to write it in php since a visitor will not be able to tell it is dynamically created? But...
15
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
4
by: Raymond Arthur St. Marie II of III | last post by:
very Very VERY dumb ? about the new Set( ) 's Please be kind and read this like you know I've been up 33-34 hours reading PEP's but... Doc\ref 2.6 Delimiters show's three unused characters "@...
2
by: Charles Alexander | last post by:
This is a really, really elementary (almost dumb) question. I have a php script I picked up elsewhere that I want to use to query my MySQL DB. I have phpMyAdmin. I'd like to somehow run this...
2
by: Alex | last post by:
Hello I am interested learn more about .NET but am uncertain of exactly what niche it fills in the world of programming. (The more I read the more I am confused). What I am looking for is the...
3
by: ed | last post by:
I've just started working with .Net, so appologize for what is probably a really dumb question. Did Windows XP originally come with the .Net framework installed, and if so which version? ...
2
by: InvisibleMan | last post by:
Hi, I feel a little dumb for asking this (considering im writing TSQL) but there doesn't seem to be any definitive answers on the search engines... Okay I understand that if you open the ADO...
4
by: Piedro | last post by:
Hi group, as I was browsing the web and checking out w3schools.com I read that the font tag was deprecated and that I should use css styles for formatting like for example <p class="p1"> Text...
2
by: Bill Nguyen | last post by:
I would like to add a new VB.NET project using the same folder being used by another project so that I can share several forms already creaded by the other project. However, .NET created a new...
6
by: Robert Dufour | last post by:
What is the meaning of the word marshal and unmarshal in plain english as applied to an exe file? Does it mean the application has started and ended? Thanks for any help, Happy new year, Bob
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.