06.关于split函数的应用

做完了初级的爬虫学习,想着做一个独立的小案例,根据名单表去批量查成绩,在分析过程后第一步就卡住了,想了一晚上,如何把名单的姓名和学号分别赋值给变量name和number,没想到这么简单一个问题就卡住了半天。百度了许多资料,最终是第二天睡醒后思路清晰的情况下,找了类似的案例,copy过来才明白原理的。

复述一下过程,split可以把一段str按需求拆分成字符串列表,除非拆分后的结果为1个元素,则不得再拆分。可以再拆分的前提是拆分后每个元素变成几个单元,则提供几个变量值。

这里记录一个不错的案例:


str=”hello boy<[www.doiido.com]>byebye”
print (str.split(‘[‘)[1].split(‘]’)[0].split(‘.’))

还有:

with open(“source.txt”, encoding=“utf-8”) as f:
    for line in f.read().split(\n):
            name, number = line.split(”    “)

86 thoughts on “06.关于split函数的应用

  1. Reading your article has greatly helped me, and I agree with you. But I still have some questions. Can you help me? I will pay attention to your answer. thank you.

  2. After reading your article, it reminded me of some things about gate io that I studied before. The content is similar to yours, but your thinking is very special, which gave me a different idea. Thank you. But I still have some questions I want to ask you, I will always pay attention. Thanks.

  3. Your article made me suddenly realize that I am writing a thesis on gate.io. After reading your article, I have a different way of thinking, thank you. However, I still have some doubts, can you help me? Thanks.

  4. I may need your help. I’ve been doing research on gate io recently, and I’ve tried a lot of different things. Later, I read your article, and I think your way of writing has given me some innovative ideas, thank you very much.

  5. Good day! I simply wish to offer you a big thumbs up for the great information you’ve got right here on this post.
    I am returning to your blog for more soon.

  6. An outstanding share! I’ve just forwarded this onto a co-worker who was conducting a little
    research on this. And he in fact bought me breakfast due to the fact that I stumbled upon it for him…

    lol. So allow me to reword this…. Thank YOU for the meal!!
    But yeah, thanx for spending some time to discuss this matter here on your internet site.

  7. Hey there! I just wanted to ask if you ever have any trouble
    with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no data backup.
    Do you have any solutions to prevent hackers?

  8. I’m not sure where you are getting your information, but great topic.
    I must spend a while finding out much more or figuring out more.
    Thank you for excellent info I was looking for this information for my mission.

  9. Your article gave me a lot of inspiration, I hope you can explain your point of view in more detail, because I have some doubts, thank you.

  10. It is appropriate time to make some plans for the long run and it is time to be happy.
    I have read this post and if I could I desire to counsel you few fascinating issues
    or suggestions. Perhaps you can write subsequent articles
    regarding this article. I want to read more things
    about it!

  11. I was recommended this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty.
    You’re amazing! Thanks!

  12. I am currently writing a paper and a bug appeared in the paper. I found what I wanted from your article. Thank you very much. Your article gave me a lot of inspiration. But hope you can explain your point in more detail because I have some questions, thank you. 20bet

  13. I am currently writing a paper that is very related to your content. I read your article and I have some questions. I would like to ask you. Can you answer me? I’ll keep an eye out for your reply. 20bet

  14. When someone writes an article he/she maintains the thought of a user in his/her brain that how a
    user can know it. Thus that’s why this article is outstdanding.

    Thanks!

  15. No matter if some one searches for his required thing, so he/she wishes
    to be available that in detail, therefore that thing is
    maintained over here.

  16. I’m amazed, I must say. Seldom do I come across a blog
    that’s both equally educative and engaging, and let me tell you,
    you have hit the nail on the head. The issue is something which too
    few folks are speaking intelligently about. I am very happy that I found this during my hunt for something relating to this.

  17. Have you ever considered publishing an ebook or guest authoring on other
    websites? I have a blog based upon on the same information you discuss and would really like to have you share
    some stories/information. I know my audience
    would enjoy your work. If you are even remotely interested, feel free
    to send me an e mail.

  18. I believe everything published made a ton of sense.
    However, what about this? suppose you added a little content?
    I ain’t saying your content is not good, but what if you added
    something that makes people desire more? I mean 06.关于split函数的应用 – 乌黑秀发程序员百川 is kinda vanilla.
    You might peek at Yahoo’s home page and watch how they create
    article headlines to grab people to open the links.
    You might add a related video or a pic or two to get people excited about
    what you’ve got to say. In my opinion, it would make
    your posts a little bit more interesting.

  19. Today, I went to the beach with my kids. I found a sea shell and gave it to my 4 year
    old daughter and said “You can hear the ocean if you put this to your ear.” She
    placed the shell to her ear and screamed. There was a hermit crab inside and it
    pinched her ear. She never wants to go back! LoL I know this is completely off topic
    but I had to tell someone!

  20. A person necessarily help to make seriously posts I would state.
    This is the very first time I frequented your web page and thus far?
    I amazed with the research you made to create this particular post extraordinary.
    Excellent activity!

  21. Oh my goodness! Impressive article dude! Thanks, However I
    am going through difficulties with your RSS. I
    don’t know the reason why I am unable to join it. Is there anybody
    else having the same RSS issues? Anyone that knows the answer will you kindly respond?
    Thanx!!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注