Как я перечисляю все tga файлы в каталоге (не рекурсивный) в Python?

Вы добавляете элемент body и css, как показано ниже:

body{
  position: relative;
  height: 100vh;
  overflow: hidden;
}
#circleTop {
    width: 55rem;
    height: 55rem;
    background-image: linear-gradient(120deg, red, yellow);
    border-radius: 50%;
    position: absolute;
    z-index: -1;
    right: -25rem;
    top: -25rem;
}

#circleBottom {
    position: absolute;
    width: 55rem;
    height: 55rem;
    background-image: linear-gradient(120deg, green, blue);
    border-radius: 50%; 
    z-index: -1;
    left: -25rem;
    bottom: -25rem;
}
<body>
  <div class="header">
    <div id="circleTop"></div>
    <div class="headerBox">
      <h1>Headline</h1>
      <h2>Subheading</h2>
    </div>
  </div>

  <div class="footer">
    <div id="circleBottom"></div>
    <div class="section">
      <a href="#">Link</a>
      <a href="#">Link</a>
    </div>
    <div class="otherLinks">
      <p>Lorem Ipsum Dolor Sit Amet</p>
    </div>
  </div>
</body>

6
задан Joan Venge 18 March 2009 в 21:21
поделиться

3 ответа

При выполнении его на основе расширения файла можно сделать что-то вроде этого:

import os
directory = "C:/"
extension = ".tga"
list_of_files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]

Очевидно, можно опустить ниже (), если можно гарантировать случай файлов. Также существует превосходный path.py (http://pypi.python.org/pypi/path.py) модуль.

Если Вы не знаете расширение файла, можно использовать что-то как PIL (http://www.pythonware.com/products/pil/) для обнаружения типа файла путем декодирования файла.

20
ответ дан 8 December 2019 в 02:27
поделиться

>>> import os
>>> for file in [tga for tga in os.listdir(directory) if tga.endswith(".tga")]:
>>>     print file
1
ответ дан 8 December 2019 в 02:27
поделиться
import glob, os
for filename in glob.glob(os.path.join(yourPath, "*.tga"))
   print(filename)
14
ответ дан 8 December 2019 в 02:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: