473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "01234567890123 456789012345678 901234567890123 456789012345678 9A"

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 1256
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*SystemExi t

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*SystemExi t

then it prints

20381
!DOCTYPE*html*P UBLIC*"-//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
2479
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 if you write it in perl, you have to put it in your cgi-bin which automatically means it's a dynamically generated page? security by obscurity . Is...
15
2664
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
1693
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 "@ $ ?". @ sort of looks like and sort of sounds like a set an $ well sort of obvious. I can imagine that the $ would be confused for money and @ is...
2
2096
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 script via phpMyAdmin so I can bookmark this for future reference. How do I do it? The phpMyadmin interface doesn't like the variable...
2
1380
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 ability ot write programs to work on mobile phones, as well as web pages, and to interact with servers. My background is a basic knowledge of...
3
1466
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? thanks in advance, ed
2
2263
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 connection that you close it with: adoCon.Close Set adoCon = Nothing
4
1706
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 goes here </p>
2
2219
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 folder using whatever project name I supplied. Is there a work around for this? Thanks Bill
6
282
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
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.