当前位置: 首页>>代码示例>>Python>>正文


Python io.File方法代码示例

本文整理汇总了Python中java.io.File方法的典型用法代码示例。如果您正苦于以下问题:Python io.File方法的具体用法?Python io.File怎么用?Python io.File使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io的用法示例。


在下文中一共展示了io.File方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_index

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def create_index():

    lucene.initVM()
    if os.path.exists(prm.index_folder):
        shutil.rmtree(prm.index_folder)

    indexDir = SimpleFSDirectory(File(prm.index_folder))
    writerConfig = IndexWriterConfig(Version.LUCENE_4_10_1, StandardAnalyzer())
    writer = IndexWriter(indexDir, writerConfig)
    wk = wiki.Wiki(prm.pages_path)

    print "%d docs in index" % writer.numDocs()
    print "Reading files from wikipedia..."
    n = 0
    for l in wk.get_text_iter():
        doc = Document()
        doc.add(Field("text", l, Field.Store.YES, Field.Index.ANALYZED))
        doc.add(Field("id", str(n), Field.Store.YES, Field.Index.ANALYZED))
        writer.addDocument(doc)
        n += 1
        if n % 100000 == 0:
            print 'indexing article', n
    print "Indexed %d docs from wikipedia (%d docs in index)" % (n, writer.numDocs())
    print "Closing index of %d docs..." % writer.numDocs()
    writer.close() 
开发者ID:nyu-dl,项目名称:dl4ir-webnav,代码行数:27,代码来源:lucene_search.py

示例2: _init_index

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def _init_index(self):

        if not os.path.exists(self.corpus.path):
            os.mkdir(self.corpus.path)
        try:
            searcher = IndexSearcher(SimpleFSDirectory(File(self.corpus.path)), True)
        #except lucene.JavaError:
        except:
            analyzer = self.corpus.analyzer
            writer = IndexWriter(SimpleFSDirectory(File(self.corpus.path)), analyzer, True, IndexWriter.MaxFieldLength.LIMITED)
            writer.setMaxFieldLength(1048576)
            writer.optimize()
            writer.close()

        self.lucene_index = SimpleFSDirectory(File(self.corpus.path))
        self.searcher = IndexSearcher(self.lucene_index, True)
        self.reader = IndexReader.open(self.lucene_index, True)
        self.analyzer = self.corpus.analyzer 
开发者ID:ChristopherLucas,项目名称:txtorg,代码行数:20,代码来源:engine_withlucene.py

示例3: import_csv

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def import_csv(self, csv_file):

        try:
            writer = IndexWriter(SimpleFSDirectory(File(self.corpus.path)), self.analyzer, False,
                                        IndexWriter.MaxFieldLength.LIMITED)
            changed_rows = addmetadata.add_metadata_from_csv(self.searcher, self.reader, writer, csv_file,self.args_dir,
                                                             new_files=True)
            writer.close()
        except UnicodeDecodeError:
            try:
                writer.close()
            except:
                pass
            self.parent.write({'error': 'CSV import failed: file contained non-unicode characters. Please save the file with UTF-8 encoding and try again!'})
            return
        self.parent.write({'message': "CSV import complete: %s rows added." % (changed_rows,)}) 
开发者ID:ChristopherLucas,项目名称:txtorg,代码行数:18,代码来源:engine_withlucene.py

示例4: __init__

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def __init__(self, index_dir, use_ram=False, jvm_ram=None):
        global lucene_vm_init
        if not lucene_vm_init:
            if jvm_ram:
                # e.g. jvm_ram = "8g"
                print "Increased JVM ram"
                lucene.initVM(vmargs=['-Djava.awt.headless=true'], maxheap=jvm_ram)
            else:
                lucene.initVM(vmargs=['-Djava.awt.headless=true'])
            lucene_vm_init = True
        self.dir = SimpleFSDirectory(File(index_dir))

        self.use_ram = use_ram
        if use_ram:
            print "Using ram directory..."
            self.ram_dir = RAMDirectory(self.dir, IOContext.DEFAULT)
        self.analyzer = None
        self.reader = None
        self.searcher = None
        self.writer = None
        self.ldf = None
        print "Connected to index " + index_dir 
开发者ID:hasibi,项目名称:TAGME-Reproducibility,代码行数:24,代码来源:lucene_tools.py

示例5: execute

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def execute( self, cmd ):
        """Execute cmd in a shell, and return the java.lang.Process instance.
        Accepts either a string command to be executed in a shell,
        or a sequence of [executable, args...].
        """
        shellCmd = self._formatCmd( cmd )

        env = self._formatEnvironment( self.environment )
        try:
            p = Runtime.getRuntime().exec( shellCmd, env, File(os.getcwd()) )
            return p
        except IOException, ex:
            raise OSError(
                0,
                "Failed to execute command (%s): %s" % ( shellCmd, ex )
                )

    ########## utility methods 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:20,代码来源:javashell.py

示例6: getatime

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def getatime(path):
    # We can't detect access time so we return modification time. This
    # matches the behaviour in os.stat().
    path = _tostr(path, "getatime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0


# expandvars is stolen from CPython-2.1.1's Lib/ntpath.py:

# Expand paths containing shell variable substitutions.
# The following rules apply:
#       - no expansion within single quotes
#       - no escape character, except for '$$' which is translated into '$'
#       - ${varname} is accepted.
#       - varnames can be made out of letters, digits and the character '_'
# XXX With COMMAND.COM you can use any characters in a variable name,
# XXX except '^|<>='. 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:javapath.py

示例7: __init__

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def __init__(self, dir=None, label=None):
        if not dir: dir = os.getcwd()
        if not label: label = "FileTree"
        dir = File(dir)
        self._dir = dir
        self.this = JPanel()
        self.this.setLayout(BorderLayout())

        # Add a label
        self.this.add(BorderLayout.PAGE_START, JLabel(label))

        # Make a tree list with all the nodes, and make it a JTree
        tree = JTree(self._add_nodes(None, dir))
        tree.setRootVisible(False)
        self._tree = tree

        # Lastly, put the JTree into a JScrollPane.
        scrollpane = JScrollPane()
        scrollpane.getViewport().add(tree)
        self.this.add(BorderLayout.CENTER, scrollpane) 
开发者ID:doyensec,项目名称:inql,代码行数:22,代码来源:filetree.py

示例8: execute

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def execute( self, cmd ):
        """Execute cmd in a shell, and return the java.lang.Process instance.
        Accepts either a string command to be executed in a shell,
        or a sequence of [executable, args...].
        """
        shellCmd = self._formatCmd( cmd )

        env = self._formatEnvironment( self.environment )
        try:
            p = Runtime.getRuntime().exec( shellCmd, env, File(os.getcwdu()) )
            return p
        except IOException, ex:
            raise OSError(
                0,
                "Failed to execute command (%s): %s" % ( shellCmd, ex )
                )

    ########## utility methods 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:20,代码来源:javashell.py

示例9: make_jar_classloader

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def make_jar_classloader(jar):
        import os
        from java.net import URL, URLClassLoader
        from java.io import File

        if isinstance(jar, bytes): # Java will expect a unicode file name
            jar = jar.decode(sys.getfilesystemencoding())
        jar_url = File(jar).toURI().toURL().toString()
        url = URL(u'jar:%s!/' % jar_url)

        if is_jython_nt:
            # URLJarFiles keep a cached open file handle to the jar even
            # after this ClassLoader is GC'ed, disallowing Windows tests
            # from removing the jar file from disk when finished with it
            conn = url.openConnection()
            if conn.getDefaultUseCaches():
                # XXX: Globally turn off jar caching: this stupid
                # instance method actually toggles a static flag. Need a
                # better fix
                conn.setDefaultUseCaches(False)

        return URLClassLoader([url])

# Filename used for testing 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:26,代码来源:test_support.py

示例10: get_candidates

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def get_candidates(qatp):

    if prm.create_index:
        create_index()

    lucene.initVM()
    analyzer = StandardAnalyzer(Version.LUCENE_4_10_1)
    reader = IndexReader.open(SimpleFSDirectory(File(prm.index_folder)))
    searcher = IndexSearcher(reader)
    candidates = []
    n = 0
    for q,a,t,p in qatp:
        if n % 100 == 0:
            print 'finding candidates sample', n
        n+=1

        q = q.replace('AND','\\AND').replace('OR','\\OR').replace('NOT','\\NOT')
        query = QueryParser(Version.LUCENE_4_10_1, "text", analyzer).parse(QueryParser.escape(q))
        hits = searcher.search(query, prm.max_candidates)
        c = []
        for hit in hits.scoreDocs:
            doc = searcher.doc(hit.doc)
            c.append(doc.get("id"))

        candidates.append(c)
        
    return candidates 
开发者ID:nyu-dl,项目名称:dl4ir-webnav,代码行数:29,代码来源:lucene_search.py

示例11: import_csv_with_content

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def import_csv_with_content(self, csv_file, content_field):
        try:
            writer = IndexWriter(SimpleFSDirectory(File(self.corpus.path)), self.analyzer, False, IndexWriter.MaxFieldLength.LIMITED)
            changed_rows = addmetadata.add_metadata_and_content_from_csv(self.searcher, self.reader, writer, csv_file, content_field, self.args_dir)
            writer.close()
        except UnicodeDecodeError:
            try:
                writer.close()
            except:
                pass
            self.parent.write({'error': 'CSV import failed: file contained non-unicode characters. Please save the file with UTF-8 encoding and try again!'})
            return
        self.parent.write({'message': "CSV import complete: %s rows added." % (changed_rows,)}) 
开发者ID:ChristopherLucas,项目名称:txtorg,代码行数:15,代码来源:engine_withlucene.py

示例12: reindex

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def reindex(self):
        writer = IndexWriter(SimpleFSDirectory(File(self.corpus.path)), self.corpus.analyzer, False, IndexWriter.MaxFieldLength.LIMITED)
        indexutils.reindex_all(self.reader, writer, self.corpus.analyzer)
        writer.optimize()
        writer.close()
        self.parent.write({'message': "Reindex successful. Corpus analyzer is now set to %s." % (self.corpus.analyzer_str,)})
        self.parent.write({'status': "Ready!"}) 
开发者ID:ChristopherLucas,项目名称:txtorg,代码行数:9,代码来源:engine_withlucene.py

示例13: dirname

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def dirname(path):
    """Return the directory component of a pathname"""
    path = _tostr(path, "dirname")
    result = asPyString(File(path).getParent())
    if not result:
        if isabs(path):
            result = path # Must be root
        else:
            result = ""
    return result 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:12,代码来源:javapath.py

示例14: basename

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def basename(path):
    """Return the final component of a pathname"""
    path = _tostr(path, "basename")
    return asPyString(File(path).getName()) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:6,代码来源:javapath.py

示例15: exists

# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import File [as 别名]
def exists(path):
    """Test whether a path exists.

    Returns false for broken symbolic links.

    """
    path = _tostr(path, "exists")
    return File(sys.getPath(path)).exists() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:10,代码来源:javapath.py


注:本文中的java.io.File方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。