我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用platform.python_version()。
def default_environment(): if hasattr(sys, 'implementation'): iver = format_full_version(sys.implementation.version) implementation_name = sys.implementation.name else: iver = '0' implementation_name = '' return { "implementation_name": implementation_name, "implementation_version": iver, "os_name": os.name, "platform_machine": platform.machine(), "platform_release": platform.release(), "platform_system": platform.system(), "platform_version": platform.version(), "python_full_version": platform.python_version(), "platform_python_implementation": platform.python_implementation(), "python_version": platform.python_version()[:3], "sys_platform": sys.platform, }
def build_user_agent(): """Build a Mozilla/5.0 compatible User-Agent string""" global USER_AGENT if USER_AGENT: return USER_AGENT ua_tuple = ( 'Mozilla/5.0', '(%s; U; %s; en-us)' % (platform.system(), platform.architecture()[0]), 'Python/%s' % platform.python_version(), '(KHTML, like Gecko)', 'speedtest-cli/%s' % __version__ ) USER_AGENT = ' '.join(ua_tuple) printer(USER_AGENT, debug=True) return USER_AGENT
def helpAbout(self, copyrightDate, about, version=1.0): """ This is a helper method for easily adding a generic help messageBox to self Creates a about MessageBox :param copyrightDate : string , the copyright date for the tool :param about : string, the about information """ __version__ = version QtWidgets.QMessageBox.about(self, "About" + self.objectName(), "<b>'About {0}</b> v {1}Copyright © 2007,{2}.All rights reserved.\ <p>Python {3} - Qt {4} - PyQt {5} on {6}".format(copyrightDate, about, __version__, platform.python_version(), QtCore.QT_VERSION_STR, QtCore.PYQT_VERSION_STR, platform.system()))
def _parse(self, parser): options, args = parser.parse_args() if not options.allow_root and self._is_root(): parser.error( "running as root - " + "run as a different user or specify the --allow-root " + "command line option") if options.python is not None: os.execlp(options.python, options.python, sys.argv[0], *args) if sys.version_info < (2, 6): version = platform.python_version() parser.error( "this tool requires python >= 2.6 " + "(you are running python " + version + "), " + "use the option -p/--python to define a suitable python " + "executable") return options, args
def __init__(self, base_dir, config, backup_time, seed_uri, argv=None): StateBase.__init__(self, base_dir, config) self.base_dir = base_dir self.state['backup'] = True self.state['completed'] = False self.state['name'] = backup_time self.state['method'] = config.backup.method self.state['path'] = base_dir self.state['cmdline'] = argv self.state['config'] = config.dump() self.state['version'] = config.version self.state['git_commit'] = config.git_commit self.state['host'] = { 'hostname': platform.node(), 'uname': platform.uname(), 'python': { 'build': platform.python_build(), 'version': platform.python_version() } } self.state['seed'] = { 'uri': seed_uri.str(), 'replset': seed_uri.replset } self.init()
def __call__(self, parser, namespace, values, option_string=None): print("%s version: %s, git commit hash: %s" % ( mongodb_consistent_backup.prog_name, mongodb_consistent_backup.__version__, mongodb_consistent_backup.git_commit )) import platform print("Python version: %s" % platform.python_version()) print("Python modules:") import fabric.version print("\t%s: %s" % ('Fabric', fabric.version.get_version())) modules = ['pymongo', 'multiprocessing', 'yaml', 'boto', 'filechunkio'] for module_name in modules: module = __import__(module_name) if hasattr(module, '__version__'): print("\t%s: %s" % (module_name, module.__version__)) sys.exit(0)
def pytest_sessionstart(self, session): self._sessionstarttime = time.time() if not self.showheader: return self.write_sep("=", "test session starts", bold=True) verinfo = platform.python_version() msg = "platform %s -- Python %s" % (sys.platform, verinfo) if hasattr(sys, 'pypy_version_info'): verinfo = ".".join(map(str, sys.pypy_version_info[:3])) msg += "[pypy-%s-%s]" % (verinfo, sys.pypy_version_info[3]) msg += ", pytest-%s, py-%s, pluggy-%s" % ( pytest.__version__, py.__version__, pluggy.__version__) if self.verbosity > 0 or self.config.option.debug or \ getattr(self.config.option, 'pastebin', None): msg += " -- " + str(sys.executable) self.write_line(msg) lines = self.config.hook.pytest_report_header( config=self.config, startdir=self.startdir) lines.reverse() for line in flatten(lines): self.write_line(line)
def get_items(self): upMinionCount = Host.objects.filter(minion_status=1).count() downMinionCount = Host.objects.filter(minion_status=0).count() # ?????? item_info = Item( html_id='SysInfo', name='??????', display=Item.AS_TABLE, value=( ('??', '%s, %s, %s' % ( platform.system(), ' '.join(platform.linux_distribution()), platform.release())), ('??', ' '.join(platform.architecture())), ('???', platform.processor()), ('Python??', platform.python_version()), ('??????', Host.objects.count()), ('????', Project.objects.count()), ('???????', '??? %s,??? %s' % (upMinionCount, downMinionCount)), ), classes='table-bordered table-condensed ' 'table-hover table-striped' ) return [item_info]
def check_installed_python_version(logfile, print_log_name): """ Returns version of python that Warrior is running on. :Arguments: 1. print_log_name (str) = Name of the print_log file 2. logfile (file object) = Contains the file object for the console_log file. This file object is the 'opened' console_log file with mode set to 'a' :Returns: str = python version """ print_info("The current python version installed is: " + platform.python_version(), logfile, print_log_name) return platform.python_version()
def determine_user_agent(config): """ Set a user_agent string in the config based on the choice of plugins. (this wasn't knowable at construction time) :returns: the client's User-Agent string :rtype: `str` """ # WARNING: To ensure changes are in line with Certbot's privacy # policy, talk to a core Certbot team member before making any # changes here. if config.user_agent is None: ua = ("CertbotACMEClient/{0} ({1}; {2}{8}) Authenticator/{3} Installer/{4} " "({5}; flags: {6}) Py/{7}") ua = ua.format(certbot.__version__, cli.cli_command, util.get_os_info_ua(), config.authenticator, config.installer, config.verb, ua_flags(config), platform.python_version(), "; " + config.user_agent_comment if config.user_agent_comment else "") else: ua = config.user_agent return ua
def test_gapic(self): headers = metrics.fill(collections.OrderedDict(( ('gl-python', platform.python_version()), ('gapic', '1.0.0'), ))) # Assert that the headers are set appropriately. self.assertEqual(headers['gl-python'], platform.python_version()) self.assertEqual(headers['gapic'], '1.0.0') self.assertEqual(headers['gax'], gax.__version__) self.assertEqual(headers['grpc'], GRPC_VERSION) # Assert that the headers are in the correct order. self.assertEqual( [k for k in headers.keys()], ['gl-python', 'gapic', 'gax', 'grpc'], )
def test_with_ordered_argument(self): headers = collections.OrderedDict() headers['gl-python'] = platform.python_version() headers['gapic'] = '1.0.0' headers['gax'] = gax.__version__ headers['grpc'] = GRPC_VERSION string = metrics.stringify(headers) # Check for the exact string, order and all. expected = 'gl-python/{python} gapic/{gapic} gax/{gax} grpc/{grpc}' self.assertEqual(string, expected.format( gapic='1.0.0', gax=gax.__version__, grpc=GRPC_VERSION, python=platform.python_version(), ))
def TestPlatform(): print ("----------Operation System--------------------------") # Windows will be : (32bit, WindowsPE) # Linux will be : (32bit, ELF) print(platform.architecture()) # Windows will be : Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600 # Linux will be : Linux-2.6.18-128.el5-i686-with-redhat-5.3-Final print(platform.platform()) # Windows will be : Windows # Linux will be : Linux print(platform.system()) print ("--------------Python Version-------------------------") # Windows and Linux will be : 3.1.1 or 3.1.3 print(platform.python_version())