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

Резултати

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

Пребарај: #seti

当前筛选 #seti清除筛选
Universe Mysteries 🪐

@cosmomyst · Post #490 · 10.11.2025 г., 22:21

🪐 On the outskirts of our galaxy, astronomers have detected a mysterious radio signal from the direction of the dwarf galaxy Leo I, which sits about 820,000 light-years away. While this signal is not evidence of aliens, its unusual features have made Leo I a target for SETI (Search for Extraterrestrial Intelligence) researchers who are carefully studying its properties to rule out natural sources—demonstrating how real cosmic signals from known galaxies push the boundaries of the scientific search for life beyond Earth. ✨ #aliens⚡#SETI⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #527 · 29.11.2025 г., 12:21

🪐 In 2017, astronomers detected a possible candidate for an extraterrestrial signal known as BLC1 from the direction of Proxima Centauri, the closest star system to our Sun. Follow-up studies showed the signal was likely human-made interference, but the discovery led to months of careful investigation and demonstrated how scientists search for alien technology by sifting through real, named stars for artificial-looking radio waves. ✨ #aliens⚡#SETI⚡#exoplanets⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #306 · 21.09.2025 г., 12:21

🪐 In 2020, astronomers using the Breakthrough Listen initiative scanned 1327 nearby stars up to 160 light-years away—including known exoplanet systems like Epsilon Eridani and Tau Ceti—for artificial radio signals that could hint at advanced alien technology. Although the search revealed over 9 million candidate signals, all were traced back to Earth-made sources, highlighting both the challenge and the rigor of the scientific hunt for extraterrestrial intelligence. ✨ #aliens⚡#exoplanets⚡#SETI⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Universe Mysteries 🪐

@cosmomyst · Post #249 · 10.09.2025 г., 00:11

🪐 Scientists at the SETI Institute used the MeerKAT radio telescope in South Africa to scan the star system HD 164595, located about 94 light-years from Earth, after an unexplained radio signal was detected there in 2016. While no follow-up signals were found and natural or human-made origins are possible, the search highlights how carefully astronomers investigate even the faintest hints of possible alien technology from real, named stars in our galaxy. ✨ #aliens⚡#SETI⚡#radio⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Universe Mysteries 🪐

@cosmomyst · Post #694 · 25.02.2026 г., 22:21

🪐 Between 1960 and 1998, the Arecibo radio telescope in Puerto Rico transmitted several powerful messages toward star clusters like M13 in the hope that intelligent aliens, if they exist, might detect and respond. These "active SETI" attempts used coded radio signals aimed at real star systems—making the search for extraterrestrial life not just a matter of listening, but also of sending greetings out into the galaxy with real, named astronomical targets. ✨ #aliens⚡#SETI⚡#radioastronomy⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #757 · 01.05.2026 г., 22:21

🪐 The SETI Institute's ongoing Breakthrough Listen project regularly targets the region around the star Proxima Centauri—our solar system’s closest neighbor—searching for unusual radio signals that could hint at alien technology. By scanning billions of radio frequencies from Proxima Centauri and other nearby stars, scientists are using real astronomy to explore whether advanced extraterrestrial civilizations might exist within our interstellar neighborhood. ✨ #aliens⚡#ProximaCentauri⚡#SETI⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #668 · 08.02.2026 г., 22:21

🪐 The SETI Institute regularly scans the region near the star Ross 128, about 11 light-years away, after unusual radio signals were detected from its direction in 2017. Although those signals were later traced to Earth-based interference, the careful monitoring of Ross 128 shows how scientists use real stars as targets in the ongoing search for signs of life beyond our solar system. ✨ #aliens⚡#SETI⚡#Ross128⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #626 · 19.01.2026 г., 12:21

🪐 One of the most famous searches for alien life involves listening for signals from the direction of Tabby’s Star (KIC 8462852), a real star in the constellation Cygnus known for its strange, unpredictable dips in brightness. Scientists at the SETI Institute have pointed sensitive radio telescopes at Tabby’s Star, searching for artificial signals that could suggest advanced technology, but so far, no evidence of extraterrestrial messages has been found—leaving the nature of the star’s odd behavior a true cosmic mystery. ✨ #aliens⚡#SETI⚡#Tabby⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​