TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #22 · 19 јан.

Заметка начинающим, которые часто сталкиваются с подобной непоняткой. Ситуация следующая, есть список файлов: names = [ 'image.bmp', 'second.txt.bkp', 'data.db', '.config.cfg', 'file.ext.bkp' ] И мы хотим убрать у них окончание ".bkp". Не знаю зачем, пример довольно надуманный) Но суть он показывает, а это главное. Те, кто еще не очень знаком с библиотекой os.path или pathlib, вероятно решат обработать имена как строки. И тут вполне подойдет метод строки strip(). Что делает этот метод? Он отрезает указанные символы по обеим сторонам строки. Если ничего не указать, то убирает невидимые символы (пробелы, табуляции и переносы строк). В нашем случае будет выглядеть вот так: >>> name.strip('.bkp') То есть просим удалить строку '.bkp' по краям имени файла, если таковая есть. Можно применить аналогичный метод rstrip(), чтобы отрезать только справа, но для этого примера используем обычный. >>> for name in names: >>> print(name.strip('.bkp')) image.bm second.txt data.d config.cfg file.ext Хм, что-то не то с нашими именами! Что случилось??? Видим нежелательное переименование в именах, где и близко не было указанной строки '.bkp' А дело всё в том, что данный метод ищет не указанную строку, а указанные символы, и не важно в каком порядке. Для метода strip() строка '.bkp' это не паттерн для поискаа список символов. Потому он отрезал симовол 'p' от '.bmp' и удалил точку из файла '.config.cfg'. Как тогда правильно заменить именно паттерн? Для начинающего можно посоветовать метод строки replace(), который как раз использует для замены указанную строку целиком. В нашем примере заменим её на пустую строку. >>> for name in names: >>> print(name.replace('.bkp', '')) image.bmp second.txt data.db .config.cfg file.ext Уже лучше, но помните, это лишь пример про strip(). Для работы с именами файлов есть способы и более "правильные", дающие однозначно верный результат. Я взял файлы только в качестве примера. Даже replase() тут может сделать не то что ожидаем. Просто впредь будьте внимательны с этим strip(). #basic

Hashtags

Резултати

Пронајдени 93 слични објави

Пребарај: #learnenglish

当前筛选 #learnenglish清除筛选
BBC Learning English

@english_bbc_learning · Post #3698 · 28.09.2025 г., 09:41

🙄 Do you ever want to tell someone that you just don’t care? 🤷‍♂️🤷‍♀️ This expression is for you! 🐵⚠️Use it carefully though – it’s VERY informal! Write your answer in the comments and don’t forget to give this post a like! Do you have a similar expression in your language?⁣ ⁣ #learnenglish

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #131 · 18.02.2023 г., 10:23

🔰🔰🔰 Questions without inversion In informal conversation a question can sometimes have the same word order as in a statement. The question has a rising intonation • The machine gives change? ~ No, it doesn't. • You're travelling tomorrow?~ Yes. • The car is blue?~ That's right. • The car is what colour? ~ Blue. • They went which way?~ That way. We use this kind of question only when it follows on from what was said before. I need a return ticket to Paddington • You're travelling when?~ Tomorrow. #learnenglish#vocabulary 👉@wallstreetenglish_WSE

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #67 · 09.02.2023 г., 07:45

🔰When Someone Is Insistent/Pressuring You🔰 • I’d love to, but I really can’t/have to go/don’t have the time. • It’s been a pleasure, but I really have to go. • This simply isn’t the right time, unfortunately. • I would love to help you, but I’m already overcommitted as it is. • I wish I could be of more help to you, but I can’t. • I must respectfully decline. • I’m sorry, but I can’t help you. • I don’t have time for this at the moment. • Please leave me alone/stop pushing. • This conversation is unnecessary. • Maybe this is the way you get things done, but I don’t like it. • It’s useless; you’re wasting your efforts on me. • You’ll be wasting your time if you keep talking to me/pushing me. • Why don’t you take this up with someone who actually has the time? • You really should put your energy elsewhere. • If I need your help, I’ll ask for it. • The answer is no. • No is a complete sentence. • You’re pushing too hard—stop it! • Go bother somebody else! #learnenglish#vocabulary @wallstreetenglish_WSE @wallstreetenglish_WSE @wallstreetenglish_WSE

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #58 · 07.02.2023 г., 13:22

**🔰Air Lane VS Airline🔰** • Air lane (Also: airway ) a regular route of travel for aircraft: - This will enable controllers to squeeze an extra 20 percent traffic into the crowded air lanes. • Airline 1. Company that carries passengers and cargo by airplane: - The airline has announced it will run daily service to Florida. 2. A tube through which air is passed under pressure: - Any big truck lives and dies, steers and brakes, on its air-lines. #learnenglish#vocabulary @wallstreetenglish_WSE @wallstreetenglish_WSE @wallstreetenglish_WSE

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #51 · 06.02.2023 г., 09:15

🔰Adapted For Something VS Adapted To Something🔰 Adapted For Something —(of things) made suitable for a new use, situation, etc.: • The book was adapted for television as a four-part series screened by the BBC. Adapted To Something —(of people) accustomed or suitable to smth.: • I am not adapted to this business. • I was bred a farmer, and ought not to have left that occupation. #learnenglish#vocabulary

English Language

@Englishdaybyday · Post #6254 · 22.07.2025 г., 20:21

✈️ Conversations on the plane 🤣#english#learnenglish ▬▬▬▬▬▬▬▬▬▬▬▬ ➠@PhrasalCards ➠@SlangWords ➠@IdiomsLand ➠@Vocabulix ➠@GrammarCards ➠@EnglishGate ➠@StoryPage

Espresso English

@EspressoEnglish · Post #3922 · 17.08.2025 г., 19:16

😂At the dentist with Mike🩷 Comment Preply and I'll send you the link! ✨#english#learnenglish ▬▬▬▬▬▬▬▬▬▬▬▬ ➠@PhrasalCards ➠@SlangWords ➠@IdiomsLand ➠@Vocabulix ➠@GrammarCards ➠@EnglishGate ➠@StoryPage

Espresso English

@EspressoEnglish · Post #3867 · 07.07.2025 г., 19:56

😂At the dentist with Mike🩷 Comment Preply and I'll send you the link! ✨#english#learnenglish ▬▬▬▬▬▬▬▬▬▬▬▬ ➠@PhrasalCards ➠@SlangWords ➠@IdiomsLand ➠@Vocabulix ➠@GrammarCards ➠@EnglishGate ➠@StoryPage

123•••78
ПретходнаСтраница 1 од 8Следна