草庐IT

walk_packages

全部标签

python - os.walk 获取目录名

我有这样的文件结构:d:\temp\random1\index.htmld:\temp\random2\index.htmld:\temp\random3\index.html我想获取在python中列出的路径。所以输出将是:files=['path':'d:\temp\random1\index.html','directory':'random1']我正在使用这样的代码:files=[]fordirpath,dirnames,filenamesinos.walk('D:\\temp'):forfnameinfilenames:iffname.endswith(".md"):path

python - 为什么 python 的 os.walk() 不反射(reflect)目录删除?

我正在尝试编写一个Python函数,它将递归地删除所有空目录。这意味着如果目录“a”仅包含“b”,则应删除“b”,然后应删除“a”(因为它现在什么都不包含)。如果一个目录包含任何东西,它就会被跳过。图解:top/a/b/top/c/d.txttop/c/foo/鉴于此,应该删除“b”、“a”和“foo”三个目录,因为“foo”和“b”现在是空的,删除“b”后“a”将变为空".我正在尝试通过os.walk和shutil.rmtree执行此操作。不幸的是,我的代码只删除了第一级目录,而不是在此过程中新清空的目录。我正在使用os.walk的topdown=false参数。documentat

python - "sys-package-mgr*: can' t 创建包缓存目录“当使用 Jython 运行 python 脚本时

我想用Jython运行Python脚本。结果显示正确,但同时出现警告信息,“sys-package-mgr*:can'tcreatepackagecachedir”我该如何解决这个问题?提前致谢~~~ 最佳答案 您可以在启动jython时通过设置“python.cachedir”选项将缓存目录的位置更改为您具有读写权限的位置,例如:jython-Dpython.cachedir=*yourcachedirdirectoryhere*或:java-jarmy_standalone_jython.jar-Dpython.cachedir

python - IPython 笔记本 - ShimWarning : The `IPython.kernel` package has been deprecated

我在将一些包导入IPython-Notebook时收到以下消息:%matplotlibnotebookimportnumpyasnpimportmatplotlibasmplimportmatplotlib.pyplotaspltfromscipy.integrateimportodeint//anaconda/lib/python3.4/site-packages/IPython/kernel/__init__.py:13:ShimWarning:The`IPython.kernel`packagehasbeendeprecated.Youshouldimportfromipyker

android - E : unable to locate package pip

我一直在尝试搭建Python-android环境,一直收到这个错误信息:~$sudoapt-getinstallbuild-essentialpatchgit-coreccacheantpippython-devsudo:/var/lib/sudo/plaixwritablebynon-owner(040777),shouldbemode0700[sudo]passwordforplaix:Readingpackagelists...DoneBuildingdependencytreeReadingstateinformation...DoneE:Unabletolocatepacka

python - 在 FTP 服务器上扩展 Python 的 os.walk 功能

如何让os.walk遍历FTP数据库(位于远程服务器上)的目录树?现在代码的结构方式是(提供注释):importfnmatch,os,ftplibdeffind(pattern,startdir=os.curdir):#findfunctiontakingvariablesforbothdesiredfileandthestartingdirectoryfor(thisDir,subsHere,filesHere)inos.walk(startdir):#eachofthevariableschangeasthedirectorytreeiswalkedfornameinsubsHer

python 3 : Installing gi package with pip

我正在尝试运行this使用Python3的Matplotlib示例。要运行它,我需要先安装gi(我正在使用pyenv):$python--versionPython3.6.1$pip--versionpip9.0.1from/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages(python3.6)$pipinstallgiCollectinggiDownloadinggi-1.2.tar.gzCollectingrequests(fromgi)Downloadingrequests-2.16.0-py2.py3-no

python - virtualenv --system-site-packages 不使用系统站点包

我的印象是在virtualenv中使用--system-site-packages标志将允许虚拟环境使用已经安装的系统包。但是我发现情况并非如此。我正在使用python的自定义编译版本。您可以在以下步骤中看到问题。[user@machinedjango]$whichpython/app/python/bin/python[user@machinedjango]$whichpip/app/python/bin/pip[user@machinedjango]$whichvirtualenv/app/python/bin/virtualenv[user@machinedjango]$pyth

python - 导入错误 : No module named package

我发现在Python中导入模块很复杂,所以我正在做实验来解决这个问题。这是我的文件结构:PythonTest/package/__init__.pytest.py__init__.py的内容:package='Variablepackagein__init__.py'frompackageimporttesttest.py内容:frompackageimportpackageprintpackage当我离开package(在PythonTest中)并执行pythonpackage/test.py时,我得到:Traceback(mostrecentcalllast):File"packa

Python代码组织问题: Eggs + Packages + Buildout + Unit Tests + SVN

我有几个共享通用模块的python项目。直到现在,我一直在……咳咳……保留公共(public)代码的多个副本并手动同步。但我显然更愿意做其他事情。在我看来,zc.Buildout可能就是我所需要的。我想我应该做的是将我系统的每个可重用组件放入一个单独的鸡蛋中,然后使用buildout将它们组装到项目中。我还认为,对于任何特定模块,我应该将单元测试放入单独的包或egg中,这样我就不会在每个项目中都安装组件单元测试的副本。我只想在我的库开发的地方进行单元测试,而不是在它刚刚被使用的地方。所以也许我想要这样的东西projectslib1testscodelib2testscodeapp1te