<?xml version="1.0" encoding="UTF-8" ?>
<xs:result count="4528" total="48543" cost="0.013776063919067" xmlns:xs="http://www.xunsearch.com">
  <doc index="1" percent="100%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/2724348/should-i-use-import-os-path-or-import-os]]>
    </url>
    <subject>
      <![CDATA[Should I use `import os.path` or `import os`?]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200929</publishtime>
    <updatetime>20200929</updatetime>
    <content>
      <![CDATA[According to the  official documentation ,  os.path  is a module. Thus, what is the preferred way of importing it?

                    
                    
                        
                            
                                
                                        6 Answer...]]>
    </content>
  </doc>
  <doc index="2" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/2860153/how-do-i-get-the-parent-directory-in-python]]>
    </url>
    <subject>
      <![CDATA[How do I get the parent directory in Python?]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200929</publishtime>
    <updatetime>20200929</updatetime>
    <content>
      <![CDATA[...someone tell me how to get the parent directory of a path in Python in a cross platform way. E.g.

                    
                    
                        
                            
                                
                                        19 Answers
             ...]]>
    </content>
  </doc>
  <doc index="3" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/11968976/list-files-only-in-the-current-directory]]>
    </url>
    <subject>
      <![CDATA[List files ONLY in the current directory]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20201009</publishtime>
    <updatetime>20201009</updatetime>
    <content>
      <![CDATA[...  

    
        



        

        


    
    
Just use os.listdir and os.path.isfile instead of os.walk.

Example:

import os
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
    # do something




But be careful while applying this to other directory, li...]]>
    </content>
  </doc>
  <doc index="4" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory]]>
    </url>
    <subject>
      <![CDATA[How do I list all files of a directory?]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200929</publishtime>
    <updatetime>20200929</updatetime>
    <content>
      <![CDATA[...           

    
        



        

        


    
    
os.listdir() will get you everything that's in a directory - files and directories.

If you want just files, you could either filter this down using os.path:

from os import listdir
from os.path import isfile, join
onlyfiles ...]]>
    </content>
  </doc>
  <doc index="5" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/141291/how-to-list-only-top-level-directories-in-python]]>
    </url>
    <subject>
      <![CDATA[How to list only top level directories in Python?]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200929</publishtime>
    <updatetime>20200929</updatetime>
    <content>
      <![CDATA[...     



        

        


    
    
Filter the result using os.path.isdir() (and use os.path.join() to get the real path):

&gt;&gt;&gt; [ name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name)) ]
['ctypes', 'distutils', 'encodings', 'lib-tk', 'config', 'idlel...]]>
    </content>
  </doc>
  <doc index="6" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/2422798/python-os-path-join-on-windows]]>
    </url>
    <subject>
      <![CDATA[Python os.path.join on Windows]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200929</publishtime>
    <updatetime>20200929</updatetime>
    <content>
      <![CDATA[...n python and am making a program that will output a script.  I want to use os.path.join, but am pretty confused.  According to the  docs  if I say:

                    
                    
                        
                            
                                
               ...]]>
    </content>
  </doc>
  <doc index="7" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/973473/getting-a-list-of-all-subdirectories-in-the-current-directory]]>
    </url>
    <subject>
      <![CDATA[Getting a list of all subdirectories in the current directory]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200929</publishtime>
    <updatetime>20200929</updatetime>
    <content>
      <![CDATA[...ories, or every directory right down the tree? 

Either way, you could use os.walk to do this:

os.walk(directory)


will yield a tuple for each subdirectory. Ths first entry in the 3-tuple is a directory name, so

[x[0] for x in os.walk(directory)]


should give you all of the subdirectories, recur...]]>
    </content>
  </doc>
  <doc index="8" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/16924471/difference-between-os-getenv-and-os-environ-get]]>
    </url>
    <subject>
      <![CDATA[Difference between os.getenv and os.environ.get]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20201009</publishtime>
    <updatetime>20201009</updatetime>
    <content>
      <![CDATA[...        

        


    
    
One difference observed (Python27):

os.environ raises an exception if the environmental variable does not exist.
os.getenv does not raise an exception, but returns None
    
    
        
            
            
                


    share
        |...]]>
    </content>
  </doc>
  <doc index="9" percent="99%">
    <url>
      <![CDATA[https://www.tsingfun.com/it/tech/1141.html]]>
    </url>
    <subject>
      <![CDATA[php 获取操作系统、浏览器版本信息（持续更新） - 更多技术 - 清泛网 - 专注C/C++及内核技术]]>
    </subject>
    <ctype>1</ctype>
    <lang>1</lang>
    <insite>1</insite>
    <publishtime>20151130</publishtime>
    <updatetime>20240401</updatetime>
    <content>
      <![CDATA[...版本，以及用户使用何种浏览器等信息，本文主要提供getOS、getBrowser、getBrowserVer三个方法，对网上各方法进行测试汇总整理，持续更新希望能成为最佳实现，欢迎大家多提意见。一、获取操作系统信息：

/**
 * 获取os信息
 *
...]]>
    </content>
  </doc>
  <doc index="10" percent="99%">
    <url>
      <![CDATA[https://stackoverflow.com/questions/11235614/how-to-detect-the-current-os-from-gradle]]>
    </url>
    <subject>
      <![CDATA[How to detect the current OS from Gradle]]>
    </subject>
    <ctype>2</ctype>
    <lang>2</lang>
    <insite>2</insite>
    <publishtime>20200930</publishtime>
    <updatetime>20200930</updatetime>
    <content>
      <![CDATA[... Ant's existing structure:

import org.apache.tools.ant.taskdefs.condition.Os

task checkWin() &lt;&lt; {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        println "*** Windows "
    }
}


I found this in the following Gradle branch, and it seems to work nicely. gradle/gradle-core/branches/RB-0.3/bu...]]>
    </content>
  </doc>
</xs:result>
