小编Cos*_*uee的帖子

如何使用Paramiko从SFTP服务器下载最新文件?

我想编写连接到我的大学SFTP服务器的脚本,并通过练习下载最新的文件.到目前为止,我已经改变了Paramiko示例中的代码,但我不知道如何下载最新文件.

这是我的代码:

import functools
import paramiko 

class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy):
    def missing_host_key(self, client, hostname, key):
        return

adress = 'adress'
username = 'username'
password = 'password'

client = paramiko.SSHClient()
client.set_missing_host_key_policy(AllowAnythingPolicy())
client.connect(adress, username= username, password=password)

def my_callback(filename, bytes_so_far, bytes_total):
    print ('Transfer of %r is in progress' % filename) 

sftp = client.open_sftp()
sftp.chdir('/directory/to/file')
for filename in sorted(sftp.listdir()):
    if filename.startswith('Temat'):
        callback_for_filename = functools.partial(my_callback, filename)
        sftp.get(filename, filename, callback=callback_for_filename)

client.close() 
Run Code Online (Sandbox Code Playgroud)

python sftp paramiko

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

Haskell powerset函数 - 如何避免无法将期望类型`IO t0'与实际类型`[[Integer]]'匹配

我有一个我试图在这里运行的powerset实现:http://rextester.com/runco​​de .我仍然遇到这个错误,无法弄清楚如何使它正确.我试图尽可能多地阅读有关哈希尔的IO,但这对我来说太难了.

import Control.Monad (filterM)
powerset = filterM (const [True, False])

main =  powerset[1,2]
Run Code Online (Sandbox Code Playgroud)

haskell

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

Haskell IO - 从标准输入直接读取到列表

Haskell IO系统对我来说是超级难以理解所以我有疑问:如何从标准输入读取到列表?我知道有函数getLine :: IO String和交互.但我不知道如何将输入转换为列表,所以我可以在这三个函数中使用它:

powerset []     = [[]]
powerset (x:xs) = xss ++ map (x:) xss
                               where xss = powerset xs
main = print $ powerset([1,2])

import Control.Monad(filterM)
p = filterM(const[True,False])
main = p[1,2]

main = subsequences([1,2])
Run Code Online (Sandbox Code Playgroud)

我希望能够写入1 2 3并将此值传递给函数.你能说/怎么做?

额外的问题

Haskell充满了魔力,所以我想知道是否有可能直接在函数中使用输入,如下所示:

main = subsequences(some input magic here)
Run Code Online (Sandbox Code Playgroud)

haskell

-1
推荐指数
1
解决办法
412
查看次数

Python正则表达式-当它在html标签中时不匹配单词

如果它在 html 标签中,我需要编写与单词不匹配的正则表达式。

这是文本示例:

asdd qwe <a href="http://example.com" title="Some title with word qwe" class="external-link" rel="nofollow">  qwe 
Run Code Online (Sandbox Code Playgroud)

我的正则表达式现在看起来像这样:

(?!(\<.+))[^a-zA-Z?????ó????????Ó???](<class="bad-word"(?: style="[^"]+")?>)?(qwe)(<>)?[^a-zA-Z?????ó????????Ó???](?!.+\>)
Run Code Online (Sandbox Code Playgroud)

这有点复杂,但everythink 的工作期望当我在 regex101.com 和 regexr.com 上测试它时,它只匹配 html 标签之后的单词。

知道为什么吗?

编辑:

我不想使用 html 解析器或 DOM 操作,我不想更改这么多代码。

def test_tagged_word_present(self):
    input = 'words <a href="example.com" title="title with word qwe" class="external-link" rel="nofollow"> qwe some other words'
    expected = 'words <a href="example.com" title="title with word qwe" class="external-link" rel="nofollow"><strong class="bad-word" style="color:red">qwe</strong> some other words'
    parser = self.get_test_parser(input, search_word='qwe')
    text = parser.mark_words()
    self.assertEqual(text, expected)
Run Code Online (Sandbox Code Playgroud)

一切正常,除了正则表达式仍然缓存qwe在标题中。

python regex

-1
推荐指数
1
解决办法
1120
查看次数

标签 统计

haskell ×2

python ×2

paramiko ×1

regex ×1

sftp ×1