GVKun编程网logo

pathlib.py:在Windows上实例化“ PosixPath”(python中的path怎么用)

26

对于pathlib.py:在Windows上实例化“PosixPath”感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解python中的path怎么用,并且为您提供关于AttributeEr

对于pathlib.py:在Windows上实例化“ PosixPath”感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解python中的path怎么用,并且为您提供关于AttributeError:“ WindowsPath”对象不具有Discord.py、c – 如何在WIndows上使用Cython编译Pyparsing?、delphi-search-path-vs-library-path-vs-browsing-path、Eclipse CDT – 如何将Linuxpath映射到Windowspath?的宝贵知识。

本文目录一览:

pathlib.py:在Windows上实例化“ PosixPath”(python中的path怎么用)

pathlib.py:在Windows上实例化“ PosixPath”(python中的path怎么用)

我从其存储库中克隆了 thefuck
源代码(这是真实的项目名称,是的,我知道…)。尝试通过以下命令将其安装以进行开发:

pip install -r requirements.txtpython setup.py develop

工作正常。之后尝试通过以下方式运行测试:

py.test

出现以下错误:

================================== FAILURES ===================================_______________________________ test_load_rule ________________________________mocker = <pytest_mock.MockFixture object at 0x03275A10>    def test_load_rule(mocker):        match = object()        get_new_command = object()        load_source = mocker.patch(            ''thefuck.main.load_source'',            return_value=Mock(match=match,                              get_new_command=get_new_command,                              enabled_by_default=True,                              priority=900))        assert main.load_rule(Path(''/rules/bash.py'')) \               == Rule(''bash'', match, get_new_command, priority=900)>       load_source.assert_called_once_with(''bash'', ''/rules/bash.py'')tests\test_main.py:20:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _C:\Python34\lib\unittest\mock.py:782: in assert_called_once_with    return self.assert_called_with(*args, **kwargs)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __mock_self = <MagicMock name=''load_source'' id=''52977776''>args = (''bash'', ''/rules/bash.py''), kwargs = {}expected = ((''bash'', ''/rules/bash.py''), {})_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x032A1030>actual = call(''bash'', ''\\rules\\bash.py''), cause = None    def assert_called_with(_mock_self, *args, **kwargs):        """assert that the mock was called with the specified arguments.            Raises an AssertionError if the args and keyword args passed in are            different to the last call to the mock."""        self = _mock_self        if self.call_args is None:            expected = self._format_mock_call_signature(args, kwargs)            raise AssertionError(''Expected call: %s\nNot called'' % (expected,))        def _error_message():            msg = self._format_mock_failure_message(args, kwargs)            return msg        expected = self._call_matcher((args, kwargs))        actual = self._call_matcher(self.call_args)        if expected != actual:            cause = expected if isinstance(expected, Exception) else None>           raise AssertionError(_error_message()) from causeE           AssertionError: Expected call: load_source(''bash'', ''/rules/bash.py'')E           Actual call: load_source(''bash'', ''\\rules\\bash.py'')C:\Python34\lib\unittest\mock.py:771: AssertionError__________________ TestGetRules.test_get[conf_rules0-rules0] __________________self = <tests.test_main.TestGetRules object at 0x03286F50>monkeypatch = <_pytest.monkeypatch.monkeypatch object at 0x03286CD0>glob = <MagicMock name=''glob'' id=''52981200''>, conf_rules = []rules = [''bash'', ''lisp'', ''bash'', ''lisp'']    @pytest.mark.parametrize(''conf_rules, rules'', [        (conf.DEFAULT_RULES, [''bash'', ''lisp'', ''bash'', ''lisp'']),        (types.RulesNamesList([''bash'']), [''bash'', ''bash''])])    def test_get(self, monkeypatch, glob, conf_rules, rules):>       glob.return_value = [PosixPath(''bash.py''), PosixPath(''lisp.py'')]tests\test_main.py:35:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _cls = <class ''pathlib.PosixPath''>, args = (''bash.py'',), kwargs = {}self = PosixPath(''bash.py'')    def __new__(cls, *args, **kwargs):        if cls is Path:            cls = WindowsPath if os.name == ''nt'' else PosixPath        self = cls._from_parts(args, init=False)        if not self._flavour.is_supported:            raise NotImplementedError("cannot instantiate %r on your system">                                     % (cls.__name__,))E           NotImplementedError: cannot instantiate ''PosixPath'' on your systemC:\Python34\lib\site-packages\pathlib-1.0.1-py3.4.egg\pathlib.py:939: NotImplementedError__________________ TestGetRules.test_get[conf_rules1-rules1] __________________self = <tests.test_main.TestGetRules object at 0x032BAB50>monkeypatch = <_pytest.monkeypatch.monkeypatch object at 0x03275A30>glob = <MagicMock name=''glob'' id=''53194576''>, conf_rules = [''bash'']rules = [''bash'', ''bash'']    @pytest.mark.parametrize(''conf_rules, rules'', [        (conf.DEFAULT_RULES, [''bash'', ''lisp'', ''bash'', ''lisp'']),        (types.RulesNamesList([''bash'']), [''bash'', ''bash''])])    def test_get(self, monkeypatch, glob, conf_rules, rules):>       glob.return_value = [PosixPath(''bash.py''), PosixPath(''lisp.py'')]tests\test_main.py:35:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _cls = <class ''pathlib.PosixPath''>, args = (''bash.py'',), kwargs = {}self = PosixPath(''bash.py'')    def __new__(cls, *args, **kwargs):        if cls is Path:            cls = WindowsPath if os.name == ''nt'' else PosixPath        self = cls._from_parts(args, init=False)        if not self._flavour.is_supported:            raise NotImplementedError("cannot instantiate %r on your system">                                     % (cls.__name__,))E           NotImplementedError: cannot instantiate ''PosixPath'' on your systemC:\Python34\lib\site-packages\pathlib-1.0.1-py3.4.egg\pathlib.py:939: NotImplementedError______________________________ test_side_effect _______________________________ssh_error = (''@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!  ...own_hosts'', <function ssh_error.<locals>.reset at 0x033F16F0>, <function ssh_error.<locals>.known_hosts at0x033F1198>)    def test_side_effect(ssh_error):        errormsg, path, reset, known_hosts = ssh_error        command = Command(''ssh user@host'', stderr=errormsg)        side_effect(command, None)        expected = [''123.234.567.890 asdjkasjdakjsd\n'', ''111.222.333.444 qwepoiwqepoiss\n'']>       assert known_hosts(path) == expectedE       assert [''123.234.567...oiwqepoiss\n''] == [''123.234.567....oiwqepoiss\n'']E         At index 1 diff: ''98.765.432.321 ejioweojwejrosj\n'' != ''111.222.333.444 qwepoiwqepoiss\n''E         Left contains more items, first extra item: ''111.222.333.444 qwepoiwqepoiss\n''E         Use -v to get the full difftests\rules\test_ssh_known_host.py:61: AssertionError=============== 4 failed, 122 passed, 2 skipped in 0.56 seconds ===============C:\code\thefuck>

我怀疑该工具仅适用于Linux和类似Unix的命令行。

  • 此错误的原因是什么?
  • 如果它是python库的一部分,而该库尚未为Windows实施,那么是否有任何快速修复方法?

我想开始从事开源项目,以成为更好的开发人员。使用Linux完成我的开发任务不是问题。如果我知道更多有经验的开发人员对此的意见,将会对我有帮助。

答案1

小编典典

此错误的原因是,在WindowsPosixPath上未实现。但是这里有PurePosixPath,您可以在想要PosixPath用于平台独立处理POSIX路径的任何地方使用它。或者,实际上您可能希望拥有依赖于平台的路径(/在Linux和\Windows上),在这种情况下,您应该使用Path

从文档(继承图下方):

在某些特殊情况下,纯路径很有用。例如:

1.
如果要在Unix计算机上操作Windows路径(反之亦然)。在Unix上运行时,无法实例化WindowsPath,但是可以实例化PureWindowsPath。

AttributeError:“ WindowsPath”对象不具有Discord.py

AttributeError:“ WindowsPath”对象不具有Discord.py

尝试一下:

font = ImageFont.truetype(str(font_path),15)

这将确保您的font_path是字符串

c – 如何在WIndows上使用Cython编译Pyparsing?

c – 如何在WIndows上使用Cython编译Pyparsing?

我试图在我的 Windows机器上编译Pyparsing但是遇到以下错误:
python setup.py build_ext --inplace
running build_ext
cythoning pyparsing.pyx to pyparsing.c

Error compiling Cython file:
------------------------------------------------------------
...
       If C{include} is set to true,the matched expression is also parsed (the
skipped text
       and matched expression are returned as a 2-element list).  The C{ignore}
       argument is used to define grammars (typically quoted strings and comment
s) that
       might contain false matches.
    """
    def __init__( self,other,include=False,ignore=None,failOn=None ):
                              ^
------------------------------------------------------------

pyparsing.pyx:2764:31: Expected an identifier,found 'include'

Error compiling Cython file:
------------------------------------------------------------
...
    def __init__( self,failOn=None ):
        super( SkipTo,self ).__init__( other )
        self.ignoreExpr = ignore
        self.mayReturnEmpty = True
        self.mayIndexError = False
        self.includeMatch = include
                           ^
------------------------------------------------------------

pyparsing.pyx:2769:28: Expected an identifier or literal
building 'pyparsing' extension
creating build
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcpyparsing.c /Fobuild\t
emp.win32-2.7\Release\pyparsing.obj
pyparsing.c
pyparsing.c(1) : Fatal error C1189: #error :  Do not use this file,it is the re
sult of a Failed Cython compilation.
error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' fa
iled with exit status 2

我使用Microsoft Visual C 2008 Express版进行了编译,使用的Pyparsing模块是最新版本.请问,有谁知道如何使这项工作?

解决方法

先生,我按照你的说法做了,但仍然有编译时警告:
    python setup.py build_ext --inplace
    running build_ext
    cythoning pyparsing.pyx to pyparsing.c
    warning: pyparsing.pyx:413:8: Unreachable code
    building 'pyparsing' extension
    creating build
    creating build\temp.win32-2.7
    creating build\temp.win32-2.7\Release
    C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
    3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcpyparsing.c /Fobuild\t
    emp.win32-2.7\Release\pyparsing.obj
    pyparsing.c
    C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCRE
    MENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild /EXPORT:initpyp
    arsing build\temp.win32-2.7\Release\pyparsing.obj /OUT:C:\Users\iProsper\Desktop
    \pyparsing\pyparsing.pyd /IMPLIB:build\temp.win32-2.7\Release\pyparsing.lib /MAN
    IFESTFILE:build\temp.win32-2.7\Release\pyparsing.pyd.manifest
       Creating library build\temp.win32-2.7\Release\pyparsing.lib and object build\
    temp.win32-2.7\Release\pyparsing.exp
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe -nologo -manifest build
    \temp.win32-2.7\Release\pyparsing.pyd.manifest -outputresource:C:\Users\iProsper
    \Desktop\pyparsing\pyparsing.pyd;2

警告实际上在第4行:警告:pyparsing.pyx:413:8:无法访问的代码.然后我将该行改为:

    def __getattr__( self,name ):
            if True: #name not in self.__slots__:
                if name in self.__tokdict:
                    if name not in self.__accumNames:
                        return self.__tokdict[name][-1][0]
                    else:
                        return ParseResults([ v[0] for v in self.__tokdict[name] ])
                else:
                    return ""
            else:
                return None

然后重新编译它.我注意到的一件事是,即使我发出警告和编辑,它们都成功编译,但是当我尝试使用以下代码进行测试时:

    from pyparsing import Word,alphas
    greet = Word(alphas) + ',' + Word(alphas) + '!'
    greeting = greet.parseString('Hello,World!')
    print greeting

我收到以下错误:

    Traceback (most recent call last):
      File "C:\nwaomachux\build_pyparsing\checkout.py",line 1,in 
        from pyparsing import Word,alphas
      File "pyparsing.pyx",line 3414,in init pyparsing (pyparsing.c:100064)
    AttributeError: 'builtin_function_or_method' object has no attribute 'ANY_VALUE'

我会进一步修改文件并发送给你检查它,但我只有几个小时的Pyparsing,所以我还没有掌握完整的源代码.

我不知道将withAttribute.ANY_VALUE = object()移动到def withAttribute(args,* attrDict)的开头是什么效果:function表示.请问,它有什么问题?谢谢.

delphi-search-path-vs-library-path-vs-browsing-path

delphi-search-path-vs-library-path-vs-browsing-path

https://stackoverflow.com/questions/812042/delphi-search-path-vs-library-path-vs-browsing-path
 
Delphi 有两种搜索路径:编译搜索路径和Debugger搜索路径。
1.编译搜索路径:
编译器在编译时使用此路径搜索源文件或预编译的Dcu文件。
编译搜索路径又分为两种:
①Project - Project Options - Directories/Conditionals - Search path:
只对当前工程起作用。
②Tools - Enviroment Options - Library - Library path:
对IDE下的所有项目起作用。
2.Debugger搜索路径:
Debug搜索路径也有两种:
①Project - Project Options - Directories/Conditionals - Debug Source path:
仅对项目起作用。
②Tools - Enviroment Options - Library - Browsing path:
对IDE下的所有项目起作用。
如果源文件不在 Library path下时,debugger在breaking/stepping into 源文件时,就会到Debug Source path下查找文件,再则到Browsing Path下查找文件。
例如:你使用了某个第三方组件,你可以把dcu文件放在library path下。编译器会使用这些Dcu来编译工程。这样做的好处时,每次编译工程时,不用编译控件。
但只使用Dcu文件的话,你就无法debug第三方组件。
此时,你可以把组件的源文件放在 browsing path下,这样,你就可以调试组件。
VCL控件就是这样放置的。在library path下存放了 (BSD)\lib,而browsingpath下存放了(BDS)\SOURCE\WIN32…


Eclipse CDT – 如何将Linuxpath映射到Windowspath?

Eclipse CDT – 如何将Linuxpath映射到Windowspath?

我们有一个为Linux环境编写的C代码项目,但是我们也希望能够查看和编辑Eclipse for Eclipse上的代码,并parsing标题。 我们面临的问题是很多头文件都包含在Linux格式的绝对path中,例如:

#include "/path/to/custom/header.h"

我希望能够做的是有Eclipse CDT地图:

/path/to/custom/ – > C:pathtocustom

这可能吗?

如何使用GDI绘制透明文本?

如何将文件放入回收站而不是删除?

使用FILE_ATTRIBUTE_TEMPORARY和FILE_FLAG_DELETE_ON_CLOSE

我应该零分配的内存?

使用DWM后,button的文本变得透明

如何将我的Oracle会话的全球化设置为与.NET中的Windows相同?

对于在另一个模块中定义的符号,insmod会失败,并显示“模块中的未知符号”

fseeko,fseeko64; ftello,ftello64 Visual C等价物

linux系统找不到libexpat

如何测量文件(硬盘)I / O的特性?

我想你应该使用经典的方式,并包含头文件所在的目录,而不是引用源代码中的绝对路径。

#include "header.h"

并添加-Ic:pathtocustom

关于pathlib.py:在Windows上实例化“ PosixPath”python中的path怎么用的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于AttributeError:“ WindowsPath”对象不具有Discord.py、c – 如何在WIndows上使用Cython编译Pyparsing?、delphi-search-path-vs-library-path-vs-browsing-path、Eclipse CDT – 如何将Linuxpath映射到Windowspath?的相关信息,请在本站寻找。

本文标签: