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


Python fileinput.input方法代码示例

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


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

示例1: main

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def main():
    # for testing, it extracts PER-ORG relationships from a file, where each line is a sentence with
    # the named-entities tagged
    reverb = Reverb()
    for line in fileinput.input():
        sentence = Sentence(line, "ORG", "ORG", 6, 1, 2, None)
        for r in sentence.relationships:
            pattern_tags = reverb.extract_reverb_patterns_tagged_ptb(r.between)
            # simple passive voice
            # auxiliary verb be + main verb past participle + 'by'
            print(r.ent1, '\t', r.ent2)
            print(r.sentence)
            print(pattern_tags)
            if reverb.detect_passive_voice(pattern_tags):
                print("Passive Voice: True")
            else:
                print("Passive Voice: False")
            print("\n")
    fileinput.close() 
开发者ID:davidsbatista,项目名称:Snowball,代码行数:21,代码来源:ReVerb.py

示例2: copy_scripts

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def copy_scripts(self):
        _build_scripts.copy_scripts(self)

        if "install" in self.distribution.command_obj:
            iobj = self.distribution.command_obj["install"]
            libDir = iobj.install_lib

            if iobj.root:
                libDir = libDir[len(iobj.root):]

            script = convert_path("bin/trelby")
            outfile = os.path.join(self.build_dir, os.path.basename(script))

            # abuse fileinput to replace a line in bin/trelby
            for line in fileinput.input(outfile, inplace = 1):
                if """sys.path.insert(0, "src")""" in line:
                    line = """sys.path.insert(0, "%s/src")""" % libDir

                print line, 
开发者ID:trelby,项目名称:trelby,代码行数:21,代码来源:setup.py

示例3: parseCAMEO

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def parseCAMEO():
    """
    Extracts mapping and reverse mapping of CAMEO codes to/from event labels
    @rtype: dict,dict
    """
    cameo = {}
    oemac = {}
    for line in fileinput.input(os.path.join(os.path.dirname(__file__),'cameo.txt')):
        elements = line.split(':')
        if len(elements) == 2:
            code = int(elements[0])
            event = elements[1].strip()
            cameo[code] = event
            oemac[event] = code
    return cameo,oemac

# Global variables for reference, CAMEO and GDELT formats 
开发者ID:pynadath,项目名称:psychsim,代码行数:19,代码来源:gdelt.py

示例4: on_app_startup

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def on_app_startup(self, app):
        # initiate custom css
        # css stylesheet
        stylesheet = os.path.join(cli.install_dir, "ui", "gtk.css")
        # ...encode() is needed because CssProvider expects byte type input
        with open(stylesheet, "r") as f:
            css = f.read().encode()

        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(css)

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(),
            style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        ) 
开发者ID:encarsia,项目名称:gpt,代码行数:18,代码来源:modules.py

示例5: chwdir

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def chwdir(self):
        """Setting up working directory, default: ~/GP"""
        while 1:
            befehl = input(_("Change working directory? (y/N) "))
            if befehl == "y":
                newdir = input(_("Input path: "))
                if newdir == "":
                    self.show_message(_("No change."))
                    break
                else:
                    self.chkdir(newdir)
                    self.stdir = os.getcwd()
                    self.replace_wdir_config(newdir)
                    break
            elif befehl == "n" or befehl == "":
                self.show_message(_("Everything stays as it is."))
                break
            else:
                self.show_message(_("Invalid input"))

    # function exclusively called by cli 
开发者ID:encarsia,项目名称:gpt,代码行数:23,代码来源:modules.py

示例6: copydir_prompt

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def copydir_prompt(self, default, c):
        """Value returned is name of default or selected subfolder"""
        if c == 0:
            return default
        while 1:
            try:
                prompt = input(_("Choose destination folder (return for default value: {}): ").format(default))
                if prompt == "":
                    return default
                elif int(prompt) > c or int(prompt) < 1:
                    print(_("Invalid input, input must be integer between 1 and {}. Try again...").format(c))
                else:
                    return self.copydirlist[int(prompt)-1][1]
            except ValueError:
                print(_("Invalid input (integer required). Try again..."))

    # Medien kopieren 
开发者ID:encarsia,项目名称:gpt,代码行数:19,代码来源:modules.py

示例7: delfiles

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def delfiles(self, ftype):
        """Dateien bestimmten Typs löschen"""
        while 1:
            print()
            befehl = input(_("Delete (y/n) "))
            if befehl == "y":
                for file in os.listdir(self.dir):
                    if file.endswith(ftype):
                        self.show_message(_("Deleting {}.").format(file))
                        os.remove(file)
                break
            elif befehl == "n":
                break
            else:
                self.show_message(_("Invalid input. Try again..."))

    # Menü 
开发者ID:encarsia,项目名称:gpt,代码行数:19,代码来源:modules.py

示例8: shell

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def shell(self):
        """Input prompt"""
        while 1:
            print()
            befehl = input()
            if befehl == "h" or befehl == "":
                self.help()
            elif befehl == "r":
                self.sortfiles()
            elif befehl == "c":
                self.handlecard()
            elif befehl == "w":
                self.chwdir()
            elif befehl == "d":
                self.confirm_format()
            elif befehl == "v":
                ctl.countvid()
            elif befehl == "i":
                ctl.countimg()
            elif befehl == "k":
                kds.countvid()
            elif befehl == "q":
                break
            else:
                print(_("Invalid input. Try again...")) 
开发者ID:encarsia,项目名称:gpt,代码行数:27,代码来源:modules.py

示例9: choosevid

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def choosevid(self, c):
        """Create and open Kdenlive project file for selected folder"""
        while 1:
            try:
                befehl = int(input(_("Select directory to create and open Kdenlive project (0 to cancel): ")))
                if befehl == 0:
                    break
                elif befehl > c or befehl < 0:
                    print(_("Invalid input, input must be integer between 1 and {}. Try again...").format(c))
                else:
                    message = _("Processing Kdenlive project for {}").format(self.wherevid[befehl-1][1])
                    cli.show_message(message)
                    self.create_project(self.wherevid[befehl-1][1])
                    break
            except ValueError:
                print(_("Invalid input (no integer). Try again...")) 
开发者ID:encarsia,项目名称:gpt,代码行数:18,代码来源:modules.py

示例10: choosemult

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def choosemult(self, path):
        """Specify multiplier for timelapse video."""
        os.chdir(path)
        self.makeldir()
        while 1:
            try:
                mult = float(input(_("Multiplier: ")))
                if mult == 0:
                    break
                elif mult <= 1:
                    print(_("Multiplier must be larger than 1."))
                else:
                    self.ffmpeg_vid(path, mult)
                    break
            except ValueError:
                print(_("Invalid input (no number). Try again...")) 
开发者ID:encarsia,项目名称:gpt,代码行数:18,代码来源:modules.py

示例11: chooseimg

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def chooseimg(self, c):
        """Create timelapse video(s) for all image files in selected directory"""
        while 1:
            try:
                befehl = int(input(_("Select directory to create timelapse video of (0 to cancel): ")))
                if befehl == 0:
                    break
                elif befehl > c or befehl < 0:
                    print(_("Invalid input, input must be integer between 1 and {}. Try again...").format(c))
                else:
                    print(_("Create timelapse for directory {}").format(self.whereimg[befehl-1][1]))
                    self.ldir_img(self.whereimg[befehl-1][1])
                    self.ffmpeg_img(self.whereimg[befehl-1][1])
                    break
            except ValueError:
                print(_("Invalid input (no integer). Try again...")) 
开发者ID:encarsia,项目名称:gpt,代码行数:18,代码来源:modules.py

示例12: in_out

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def in_out(args,multiple_files=False):
    """Open the input/output data streams. If multiple_files is set to
    True, returns an iterator over lines. If set to False, returns an open file.
    This distinction is needed because validator.py checks the newlines property and
    needs to get the input as a file, but the other scripts just need the lines
    so they can work with several files.
    """
    #Decide where to get the data from
    if args.input is None or args.input=="-": #Stdin
        inp=codecs.getreader("utf-8")(os.fdopen(0,"U")) #Switched universal newlines on
    else: #File name given
        if multiple_files:
            inp_raw=fileinput.input(files=args.input,mode="U")
            inp=(line.decode("utf-8") for line in inp_raw)
        else:
            inp_raw=open(args.input,mode="U")
            inp=codecs.getreader("utf-8")(inp_raw)
    #inp is now an iterator over lines, giving unicode strings

    if args.output is None or args.output=="-": #stdout
        out=codecs.getwriter("utf-8")(sys.stdout)
    else: #File name given
        out=codecs.open(args.output,"w","utf-8")
    return inp,out 
开发者ID:UniversalDependencies,项目名称:tools,代码行数:26,代码来源:file_util.py

示例13: _create_combined_bundle_file

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def _create_combined_bundle_file(self):
        leap_ca_bundle = ca_bundle.where()

        if self._ca_cert_path == leap_ca_bundle:
            return self._ca_cert_path  # don't merge file with itself
        elif not self._ca_cert_path:
            return leap_ca_bundle

        tmp_file = tempfile.NamedTemporaryFile(delete=False)

        with open(tmp_file.name, 'w') as fout:
            fin = fileinput.input(files=(leap_ca_bundle, self._ca_cert_path))
            for line in fin:
                fout.write(line)
            fin.close()

        return tmp_file.name 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:19,代码来源:__init__.py

示例14: delnote

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def delnote(self, args):
        self.help = "./notes.py delnote <file_name> <numb_line>"
        if len(sys.argv) < 3:
            sys.exit("[-] Fucking Damn!!\n[?] Use similiar this: " + self.help)

        f_note_out = str(sys.argv[2])
        try:
            for numb, line in enumerate(fileinput.input(f_note_out, inplace=True)): #start index from 0
                if numb == int(sys.argv[3]):
                    continue
                else:
                    sys.stdout.write(line)
            sys.exit("[+] Success delete line <"+sys.argv[3]+"> in file of <"+ f_note_out +">")
        
        except OSError:
            sys.exit("[-] File Doesn't exists!!"+\
                     "\n[?] This your path now: " +str(os.getcwd())+\
                     "\n[?] This files and folders in your path now: " + str(os.listdir('.')) ) 
开发者ID:agusmakmun,项目名称:Some-Examples-of-Simple-Python-Script,代码行数:20,代码来源:notes.py

示例15: main

# 需要导入模块: import fileinput [as 别名]
# 或者: from fileinput import input [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--workers', type=int, default=10)
    parser.add_argument('files', nargs='*', help='input files')
    args = parser.parse_args()

    seen = set()
    with fileinput.input(args.files, mode='rb') as h:
        pool = Pool(args.workers)
        results = pool.imap_unordered(get_hashes_and_lines, h, 1000)
        for i, (hash, raw_line) in enumerate(results):
            if hash not in seen:
                seen.add(hash)
                sys.stdout.buffer.write(raw_line)
            if i % 1000000 == 0:
                print(i, file=sys.stderr, end="", flush=True)
            elif i % 100000 == 0:
                print(".", file=sys.stderr, end="", flush=True)
    print(file=sys.stderr, flush=True) 
开发者ID:pytorch,项目名称:fairseq,代码行数:21,代码来源:deduplicate_lines.py


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