小编sri*_*ram的帖子

以递归方式删除python中的文件夹

我在删除空目录时遇到问题.我有这样的代码:

for dirpath, dirnames, filenames in os.walk(dir_to_search):
    //other codes

    try:
        os.rmdir(dirpath)
    except OSError as ex:
        print(ex)
Run Code Online (Sandbox Code Playgroud)

这个论点dir_to_search是我传递工作需要关闭的目录.该目录如下所示:

test/20/...
test/22/...
test/25/...
test/26/...
Run Code Online (Sandbox Code Playgroud)

请注意,以上所有文件夹都是空的.当我运行该脚本的文件夹20,25单独被删除!但文件夹2526没有删除,即使它们是空文件夹.

编辑:

我得到的例外是:

[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test'
[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012'
[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10'
[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10/29'
[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10/29/tmp'
[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10/28'
[Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10/28/tmp'
[Errno 39] Directory not …
Run Code Online (Sandbox Code Playgroud)

python directory

172
推荐指数
6
解决办法
12万
查看次数

如何在bash中获取grep结果之前/之后的行?

嗨,我很擅长bash编程.我想要一种在给定文本中搜索的方法.为此,我使用grep功能:

grep -i "my_regex"
Run Code Online (Sandbox Code Playgroud)

这样可行.但鉴于data这样:

This is the test data
This is the error data as follows
. . . 
. . . .
. . . . . . 
. . . . . . . . .
Error data ends
Run Code Online (Sandbox Code Playgroud)

一旦我找到了单词error(使用grep -i error data),我希望找到跟随这个单词的10行error.所以我的输出应该是:

    . . . 
    . . . .
    . . . . . . 
    . . . . . . . . .
    Error data …
Run Code Online (Sandbox Code Playgroud)

bash shell ubuntu

130
推荐指数
4
解决办法
17万
查看次数

在rails中执行Http基本身份验证

嗨我来自Grails背景和Rails的新手.我希望在rails中进行http基本身份验证.

我有grails中的代码,它执行基本身份验证,如下所示:

def authString = "${key}:".getBytes().encodeBase64().toString()
def conn = "http://something.net".toURL().openConnection()
conn.setRequestProperty("Authorization", "Basic ${authString}")
Run Code Online (Sandbox Code Playgroud)

是否可以使用rails完成相同的操作?

提前致谢.

ruby ruby-on-rails

27
推荐指数
4
解决办法
3万
查看次数

使用boto python以递归方式从s3下载文件.

我在s3中有一个存储桶,它具有深层目录结构.我希望我能一次下载所有内容.我的文件看起来像这样:

foo/bar/1. . 
foo/bar/100 . . 
Run Code Online (Sandbox Code Playgroud)

有没有办法在python中使用boto lib从s3存储桶中递归下载这些文件?

提前致谢.

python amazon-s3 boto amazon-web-services

20
推荐指数
3
解决办法
3万
查看次数

getActivity()在哪里定义?

我是android的新手,我正在关注这个例子.

代码说我们需要执行以下步骤来获取对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(R.string.dialog_message)
       .setTitle(R.string.dialog_title);

// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();
Run Code Online (Sandbox Code Playgroud)

但是这个getActivity()方法在哪里定义?

我找不到那种方法.

methods android android-alertdialog

20
推荐指数
1
解决办法
6万
查看次数

给定值,在地图中查找关键字

嗨我有这样的地图:

[this:0, is:1, a:2, file:3, anotherkey:4, aa:5]
Run Code Online (Sandbox Code Playgroud)

我希望我能找到key给定的value一个地图.例如,如果5给出了值,我需要aa从地图返回.

那可能吗?

groovy map

9
推荐指数
3
解决办法
1万
查看次数

将Map <String,String>转换为json

Map<String,String>在java中有这样的:

{card_switch=Master, issuing_bank=ICCI, card_Type=DebitCard}
Run Code Online (Sandbox Code Playgroud)

我正在使用简单的json解析器将此映射解析为json对象.

我试过了 :

Object json = JSONValue.parse(entry.getKey());
Run Code Online (Sandbox Code Playgroud)

但是我收到一条错误消息:

Object json = JSONValue.parse(entry.getKey());
                      ^
method JSONValue.parse(String) is not applicable
  (actual argument Map<String,String> cannot be converted to String by method invocation conversion)
method JSONValue.parse(Reader) is not applicable
  (actual argument Map<String,String> cannot be converted to Reader by method invocation conversion)
Run Code Online (Sandbox Code Playgroud)

这有可能转换Map<String,String>成json吗?

java json

7
推荐指数
2
解决办法
4万
查看次数

Java中的关联与聚合与组合

我试图理解这些术语的含义.我带来了一些例子:

聚合:Facebook 有一个用户

组成:facebook 中的每个用户都有一个会话.

协会:人们使用浏览器

但是我却越来越困惑与拥有使用地雷的例子.为什么不能用户使用 Facebook帐户或Facebook 使用会话来验证用户?

在OOP方面是错误的吗?我在哪里错过这个概念?

java oop

7
推荐指数
1
解决办法
2万
查看次数

当我使用float时,为什么java强迫我添加f?

我对编程很新.我有以下代码:

float f = 18.45f;
Run Code Online (Sandbox Code Playgroud)

这很好用.如果我改为:

float f = 18.45;
Run Code Online (Sandbox Code Playgroud)

java说这是错误:

error: possible loss of precision
Run Code Online (Sandbox Code Playgroud)

但它的可选性方面double.但是long我再次遇到同样的问题.

为什么java强迫我这样做,但不是以防万一double

java

7
推荐指数
1
解决办法
1733
查看次数

在perl中自动安装perl依赖项

我对perl很新.我希望我可以从perl安装一些软件包,我是这样做的:

perl -MCPAN -e 'install VM::EC2'
Run Code Online (Sandbox Code Playgroud)

由于我的依赖,它失败了,它表明:

Result: FAIL
Failed 8/8 test programs. 9/9 subtests failed.
  LDS/VM-EC2-1.20.tar.gz
one dependency not OK (XML::Simple); additionally test harness failed
  ./Build test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
  reports LDS/VM-EC2-1.20.tar.gz
Running Build install
  make test had returned bad status, won't install without force
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如何XML::Simple自动询问perl安装和其他依赖?

提前致谢.

installation perl

6
推荐指数
1
解决办法
3451
查看次数