A few days ago, because of the excitement of Python, I wrote an article called the beauty of Python 1, and today it was written in a small error.
Also because of my work, the problem is this:
I have a document. A line of information is stored inside
Product Category # Number of items in this category
The product classification does not appear # (so I saved it with a # as a delimiter), and the merchandise always from 1 to the number of goods n number, I get this product number. You will be able to iterate through the call action function (simply remember fun).
Take it for granted, I set the delimiter. To use split, of course.
Then I wrote a few lines of this code.
F=open (' Record.txt ', ' R ') info=f.readlines () [0]f.close () End=info.split (' # ') [ -1]beg=1while beg<=end: Fun ( Beg) Beg+=1
And then I was relieved to give it back to the backstage operation.
Nohup python a.py &
Then I was writing about the other, because of the huge amount of data being processed. So I waited one afternoon and went back to see it. The discovery program is not over yet. No longer in my estimation of the range.
Smart you, you see what the problem?
Then I added a very easy word.
F=open (' Record.txt ', ' R ') info=f.readlines () [0]f.close () End=info.split (' # ') [ -1]beg=1while beg<=end: Print beg# This fun (beg) beg+=1
But. My data volume is very large, and fun operation time is very slow! This is tangled up!
That's a simple result, it's going to go wrong? I have no doubt in the main function, but to see the big piece of fun, but hard to test many times, or not.
Was. I almost suspected that my py was broken, or was teasing me! (the author was so worried that he doubted his compiler.) My fun is a very disgusting bunch of regular.
Later. I use the naked eye to observe, is it my split problem? Then I added another sentence.
F=open (' Record.txt ', ' R ') info=f.readlines () [0]f.close () End=info.split (' # ') [ -1]print end #这句beg =1while beg<=end: Print Beg Fun (Beg) beg+=1
End is still very normal!
This is the trouble, is my program problem. Or is it really not done?
Then, I went to a bathroom.
A careful thought, as if the split after the string is obtained.
String!
However, does the string convert to a few words? That's not going to run out, for example ' 18 ' (if I'm just, it's mostly true.)
)
What is the comparison between a number and a string?
Then I wrote a test function.
Beg=1while beg< ' 1 ': print beg beg+=1
the cycle of death.
。
I took cavity indignation and excitement, changed the program
F=open (' Record.txt ', ' R ') info=f.readlines () [0]f.close () End=int (Info.split (' # ') [-1]) Beg=1while beg<=end: Fun (Beg) beg+=1
The program is finally normal.
All right. was played by Py for an afternoon.
Later. I found that with xrange will direct error, next time or use Xrange bar.
Python! Is you kidding me?