Python builtins 模块,print() 实例源码

我们从Python开源项目中,提取了以下28个代码示例,用于说明如何使用builtins.print()

项目:core-workflow    作者:python    | 项目源码 | 文件源码
def test(*args):
    """
Run unit tests.  Only works inside source repo, not when installed.
    """
    # unittest.main doesn't work because this isn't a module
    # so we'll do it ourselves

    print("-" * 79)

    for clsname, cls in sorted(globals().items()):
        if clsname.startswith("Test") and isinstance(cls, type):
            o = cls()
            for fnname in sorted(dir(o)):
                if fnname.startswith("test"):
                    fn = getattr(o, fnname)
                    if callable(fn):
                        fn()
    print()
    print(tests_run, "tests passed.")
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def download_rtmp_url(url,title, ext,params={}, total_size=0, output_dir='.', refer=None, merge=True, faker=False):
    assert url
    if dry_run:
        print('Real URL:\n%s\n' % [url])
        if params.get("-y",False): #None or unset ->False
            print('Real Playpath:\n%s\n' % [params.get("-y")])
        return

    if player:
        from .processor.rtmpdump import play_rtmpdump_stream
        play_rtmpdump_stream(player, url, params)
        return

    from .processor.rtmpdump import has_rtmpdump_installed, download_rtmpdump_stream
    assert has_rtmpdump_installed(), "RTMPDump not installed."
    download_rtmpdump_stream(url,  title, ext,params, output_dir)
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def download_url_ffmpeg(url,title, ext,params={}, total_size=0, output_dir='.', refer=None, merge=True, faker=False):
    assert url
    if dry_run:
        print('Real URL:\n%s\n' % [url])
        if params.get("-y",False): #None or unset ->False
            print('Real Playpath:\n%s\n' % [params.get("-y")])
        return

    if player:
        launch_player(player, [url])
        return

    from .processor.ffmpeg import has_ffmpeg_installed, ffmpeg_download_stream
    assert has_ffmpeg_installed(), "FFmpeg not installed."

    global output_filename
    if output_filename:
        dotPos = output_filename.rfind(".")
        title = output_filename[:dotPos]
        ext = output_filename[dotPos+1:]

    title = tr(get_filename(title))

    ffmpeg_download_stream(url, title, ext, params, output_dir)
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def download_rtmp_url(url,title, ext,params={}, total_size=0, output_dir='.', refer=None, merge=True, faker=False):
    assert url
    if dry_run:
        print('Real URL:\n%s\n' % [url])
        if params.get("-y",False): #None or unset ->False
            print('Real Playpath:\n%s\n' % [params.get("-y")])
        return

    if player:
        from .processor.rtmpdump import play_rtmpdump_stream
        play_rtmpdump_stream(player, url, params)
        return

    from .processor.rtmpdump import has_rtmpdump_installed, download_rtmpdump_stream
    assert has_rtmpdump_installed(), "RTMPDump not installed."
    download_rtmpdump_stream(url,  title, ext,params, output_dir)
项目:core-workflow    作者:python    | 项目源码 | 文件源码
def test_files(self):
        global tests_run
        with pushd(self.directory):
            for filename in glob.glob("*"):
                self.filename_test(filename)
                print(".", end="")
                sys.stdout.flush()
                tests_run += 1
项目:core-workflow    作者:python    | 项目源码 | 文件源码
def export():
    """
Removes blurb data files, for building release tarballs/installers.
    """
    os.chdir("Misc")
    shutil.rmtree("NEWS.d", ignore_errors=True)



# @subcommand
# def arg(*, boolean=False, option=True):
#    """
#    Test function for blurb command-line processing.
#    """
#    print("arg: boolean {} option {}".format(boolean, option))
项目:transpyler    作者:Transpyler    | 项目源码 | 文件源码
def print(*args, **kwargs):
    """
    Prints the object or text provided on the screen.

    If called with multiple arguments, prints them in sequence, separating
    them with a white space.

    Examples:
        >>> print("Hello world!")
        Hello World!
    """

    _print(*args)
项目:transpyler    作者:Transpyler    | 项目源码 | 文件源码
def print_formatted(text, *args, **kwargs):
    """
    Displays a string after applying the provided formatting arguments.
    """

    print(_format_string(text, *args, **kwargs))
项目:transpyler    作者:Transpyler    | 项目源码 | 文件源码
def _alert(*args):
    print(*args)
项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def generate_op_post(self, op):
        # exop = self.exop
        # self.append("print('{{}}'.format('{}'))", op.name)
        # for input_decl in exop.input.decls:
        #     input_decl_name = 'a_'+input_decl.tensor.tensor_name
        #     self.append("print('   arg {} = {{}}'.format({}))", input_decl_name, arg_name)
        # for val in exop.output_decls:
        #     output_decl_name = 'a_'+val.tensor.tensor_name
        #     self.append("#    output_decl {}", output_decl_name)
        #     self.append("print('   output_decl {} = {{}}'.format({}))", \
        #            output_decl_name, output_decl_name)
        if is_tracing_enabled():
            self.append("self.__profiler_stop__.append(monotonic())")
项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def generate_op(self, op, out, x):
        if op.prefix is not None:
            self.append("""print({prefix} + ':', {x})
{out}[()] = {x}""", out=out, x=x, prefix=repr(op.prefix))
        else:
            self.append("""print({x})
{out}[()] = {x}""", out=out, x=x)
项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def initialize_module(self, module):
        module.execute("""from __future__ import print_function
from builtins import print
import os
import numpy as np
import ctypes as ct
import numpy.ctypeslib as npct
import itertools as itt
from monotonic import monotonic as monotonic
from ngraph.op_graph import axes
from ngraph.transformers.cpu.cpuengine import fprop_lut, update_lut
from ngraph.transformers.cpu.cpuengine import Mkldnn
from ngraph.transformers.cpu.cpuengine import ConvLocals
from ngraph.transformers.cpu.ctc import ctc_cpu
from ngraph.transformers.cputransform import align_ndarray
        """)

        if use_mlsl:
            module.execute("""
from ngraph.transformers.cpu.hetr import HetrLocals
            """)

        mkldnn_path = os.path.join(os.path.dirname(__file__), "..", "..")
        mkldnn_engine_path = os.path.join(mkldnn_path, 'mkldnn_engine.so')
        module.execute("mkldnn = Mkldnn(r'{}')".format(mkldnn_engine_path))
        module.execute("mkldnn.open()")
        self.mkldnn = module['mkldnn']
项目:2017    作者:busybus    | 项目源码 | 文件源码
def print(*args, **kwargs):
    x = __builtin__.print(*args, **kwargs)
    sys.__stdout__.flush()
    return x
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def maybe_print(*s):
    try: print(*s)
    except: pass
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def done(self):
        if self.displayed:
            print()
            self.displayed = False
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def done(self):
        if self.displayed:
            print()
            self.displayed = False
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def google_search(url):
    keywords = r1(r'https?://(.*)', url)
    url = 'https://www.google.com/search?tbm=vid&q=%s' % parse.quote(keywords)
    page = get_content(url, headers=fake_headers)
    videos = re.findall(r'<a href="(https?://[^"]+)" onmousedown="[^"]+">([^<]+)<', page)
    vdurs = re.findall(r'<span class="vdur _dwc">([^<]+)<', page)
    durs = [r1(r'(\d+:\d+)', unescape_html(dur)) for dur in vdurs]
    print("Google Videos search:")
    for v in zip(videos, durs):
        print("- video:  %s [%s]" % (unescape_html(v[0][1]),
                                     v[1] if v[1] else '?'))
        print("# you-get %s" % log.sprint(v[0][0], log.UNDERLINE))
        print()
    print("Best matched result:")
    return(videos[0][0])
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def maybe_print(*s):
    try: print(*s)
    except: pass
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def done(self):
        if self.displayed:
            print()
            self.displayed = False
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def done(self):
        if self.displayed:
            print()
            self.displayed = False
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def print_more_compatible(*args, **kwargs):
    import builtins as __builtin__
    """Overload default print function as py (<3.3) does not support 'flush' keyword.
    Although the function name can be same as print to get itself overloaded automatically,
    I'd rather leave it with a different name and only overload it when importing to make less confusion. """
    # nothing happens on py3.3 and later
    if sys.version_info[:2] >= (3, 3):
        return __builtin__.print(*args, **kwargs)

    # in lower pyver (e.g. 3.2.x), remove 'flush' keyword and flush it as requested
    doFlush = kwargs.pop('flush', False)
    ret = __builtin__.print(*args, **kwargs)
    if doFlush:
        kwargs.get('file', sys.stdout).flush()
    return ret
项目:acmpv    作者:Vayn    | 项目源码 | 文件源码
def google_search(url):
    keywords = r1(r'https?://(.*)', url)
    url = 'https://www.google.com/search?tbm=vid&q=%s' % parse.quote(keywords)
    page = get_content(url, headers=fake_headers)
    videos = re.findall(r'<a href="(https?://[^"]+)" onmousedown="[^"]+">([^<]+)<', page)
    vdurs = re.findall(r'<span class="vdur _dwc">([^<]+)<', page)
    durs = [r1(r'(\d+:\d+)', unescape_html(dur)) for dur in vdurs]
    print("Google Videos search:")
    for v in zip(videos, durs):
        print("- video:  %s [%s]" % (unescape_html(v[0][1]),
                                     v[1] if v[1] else '?'))
        print("# you-get %s" % log.sprint(v[0][0], log.UNDERLINE))
        print()
    print("Best matched result:")
    return(videos[0][0])
项目:gtao-python-module    作者:Hexaflexagon    | 项目源码 | 文件源码
def print(message):
    __orange__.Print(message)
项目:aiostream    作者:vxgmichel    | 项目源码 | 文件源码
def print(source, template=None, **kwargs):
    """Print each element of an asynchronous sequence without modifying it.

    An optional template can be provided to be formatted with the elements.
    All the keyword arguments are forwarded to the builtin function print.
    """
    def func(value):
        if template:
            value = template.format(value)
        builtins.print(value, **kwargs)
    return action.raw(source, func)
项目:pycon2017-closures    作者:besnik    | 项目源码 | 文件源码
def person():
    name = "peter" # local scope
    print(name)
项目:pycon2017-closures    作者:besnik    | 项目源码 | 文件源码
def person():
    global name
    name = "tomas-modified" # modified global var
    print(name)
项目:pycon2017-closures    作者:besnik    | 项目源码 | 文件源码
def person():
    print(name)
    name = "richard"
    print(name)

#person() # throws
项目:core-workflow    作者:python    | 项目源码 | 文件源码
def release(version):
    """
Move all new blurbs to a single blurb file for the release.

This is used by the release manager when cutting a new release.
    """
    if version == ".":
        # harvest version number from dirname of repo
        # I remind you, we're in the Misc subdir right now
        version = os.path.basename(root)

    existing_filenames = glob_blurbs(version)
    if existing_filenames:
        error("Sorry, can't handle appending 'next' files to an existing version (yet).")

    output = "Misc/NEWS.d/{}.rst".format(version)
    filenames = glob_blurbs("next")
    blurbs = Blurbs()
    date = current_date()

    if not filenames:
        print("No blurbs found.  Setting {} as having no changes.".format(version))
        body = "There were no new changes in version {}.\n".format(version)
        metadata = {"no changes": "True", "bpo": "0", "section": "Library", "date": date, "nonce": nonceify(body)}
        blurbs.append((metadata, body))
    else:
        no_changes = None
        count = len(filenames)
        print('Merging {} blurbs to "{}".'.format(count, output))

        for filename in filenames:
            if not filename.endswith(".rst"):
                continue
            blurbs.load_next(filename)

        metadata = blurbs[0][0]

    metadata['release date'] = date
    print("Saving.")

    blurbs.save(output)
    git_add_files.append(output)
    flush_git_add_files()

    print("Removing {} 'next' files from git.".format(len(filenames)))
    git_rm_files.extend(filenames)
    flush_git_rm_files()

    # sanity check: ensuring that saving/reloading the merged blurb file works.
    blurbs2 = Blurbs()
    blurbs2.load(output)
    assert blurbs2 == blurbs, "Reloading {} isn't reproducible?!".format(output)

    print()
    print("Ready for commit.")