小编Pro*_*man的帖子

Haskell`randoms`功能在我的库中表现不佳

我正在尝试编写一个用于加密安全随机数的Haskell库.代码如下:

module URandom (URandom, initialize) where

import qualified Data.ByteString.Lazy as B
import System.Random
import Data.Word

newtype URandom = URandom [Word8]

instance RandomGen URandom where
  next (URandom (x : xs)) = (fromIntegral x, URandom xs)
  split (URandom l) = (URandom (evens l), URandom (odds l))
    where evens (x : _ : xs) = x : evens xs
          odds (_ : x : xs) = x : odds xs
  genRange _ = (fromIntegral (minBound :: Word8), fromIntegral (maxBound :: Word8))

initialize :: …
Run Code Online (Sandbox Code Playgroud)

random haskell

10
推荐指数
1
解决办法
126
查看次数

Python邮件每171个字符插入一次空格

我正在尝试编写一个python脚本来发送一个使用HTML格式的电子邮件,并涉及许多不间断的空格.但是,当我运行它时,一些字符串被每171个字符出现的空格打断,这个例子可以看出:

#!/usr/bin/env python
import smtplib
import socket
from email.mime.text import MIMEText

emails = ["my@email.com"]
sender = "test@{0}".format(socket.gethostname())

message = "<html><head></head><body>"
for i in range(20):
        message += "&nbsp;" * 50
        message += "<br/>"
message += "</body>"
message = MIMEText(message, "html")
message["Subject"] = "Test"
message["From"] = sender
message["To"] = ", ".join(emails)
mailer = smtplib.SMTP("localhost")
mailer.sendmail(sender, emails, message.as_string())
mailer.quit()
Run Code Online (Sandbox Code Playgroud)

该示例应该生成一个仅包含空格的空白电子邮件,但最终看起来像这样:

         &nbsp ;                                    


                       &nb sp;                      


                                     & nbsp;        






             &nbs p;                                


                           &n bsp;          
Run Code Online (Sandbox Code Playgroud)

编辑:如果它很重要,我正在运行带有Postfix的Ubuntu 15.04用于smtp客户端,并使用python2.6.

python email whitespace

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

当变量超出范围时,Python 不会删除变量

考虑以下代码:

import random                                                                   

class Trie:                                                                     
    def __init__(self, children, end):                                          
        self.children = children                                                
        self.end = end                                                          

def trie_empty():                                                               
    return Trie(dict(), False)                                                  

def trie_insert(x, t):                                                          
    if not x:                                                                   
        t.end = True                                                            
        return                                                                  
    try:                                                                        
        t2 = t.children[x[0]]                                                   
    except KeyError:                                                            
        t2 = trie_empty()                                                       
        t.children[x[0]] = t2                                                     
    trie_insert(x[1:], t2)                                                      

def fill_dict(root):                                                            
    memo = dict()                                                               
    def fill(pfx='', depth=0):                                                  
        try:                                                                    
            memo[pfx]                                                           
        except KeyError:                                                        
            pass                                                                
        else:                                                                   
            return                                                              
        if depth > 6:                                                           
            return                                                              
        for ci in range(ord('a'), ord('d') + 1):                                
            fill(pfx + chr(ci), depth + 1)                                      
        bw = None …
Run Code Online (Sandbox Code Playgroud)

python

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

标签 统计

python ×2

email ×1

haskell ×1

random ×1

whitespace ×1