在没有扩展名的情况下在Python中读取文件

Bry*_*key 1 python

我想在Python 2.6中读取一个没有扩展名的(基本上是文本文件)文件.我尝试了以下代码,但有以下错误..

for infile in glob.glob(os.path.join(path + "Bookmarks",'*')):
    review_file = open(infile,'r').read()
    print review_file
Run Code Online (Sandbox Code Playgroud)

- >未定义全局名称glob

f = open(path, "r")
text = f.readlines()
print text
Run Code Online (Sandbox Code Playgroud)

- >打印"x00\x00\x00\x00\x00 \"等,这不是此文件中的内容.

编辑: - >文件的直接,直接,是我想要的,例如,如果文件中有"023492034blackriver0brydonmccluskey",它会(截至目前)用一堆二进制值提取它,而我只想要exacy内容.我该怎么办?

Fer*_*yer 5

  1. 如果您想使用该glob模块,您必须import先:

    import glob
    for infile in glob.glob(os.path.join(path, '*')):
        review_file = open(infile,'r').read()
        print review_file
    
    Run Code Online (Sandbox Code Playgroud)
  2. 您确定您的文件不包含您获得的二进制数据吗?