小编dop*_*man的帖子

命令行与IDLE中的dir()函数

我试过在IDLE中运行以下代码:

import sys
dir(sys)
Run Code Online (Sandbox Code Playgroud)

没有结果:

>>>
Run Code Online (Sandbox Code Playgroud)

但是当我在命令行中运行它时,我得到了这个:

>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']
Run Code Online (Sandbox Code Playgroud)

有人能解释我所做的不同吗?

python

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

如何将字符串转换为可读流?

我正在尝试将字符串流式传输到另一个流:

streamer = new stream.Transform objectMode: true
stringer = (string) ->
    streamer._transform = (chunk, encoding, done) ->
        @push string.split('').shift()
        done()

    return streamer

streamer.on 'readable', ->
    console.log 'readable'

stringer('hello').pipe process.stdout
Run Code Online (Sandbox Code Playgroud)

但是控制台中没有任何日志。我究竟做错了什么?

node.js coffeescript

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

haskell - 无法解析data/newtype声明中的数据构造函数:[Int Int Int]

我正在尝试声明一个类型列表的数据Either类型.

data EitherInts = [Either Int Int]
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译这种类型时,我收到一个错误:

Cannot parse data constructor in a data/newtype declaration: [Either Int Int]
Run Code Online (Sandbox Code Playgroud)

我不知道为什么.我究竟做错了什么?

haskell

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

尝试从低级套接字服务器发送 HTTP 响应

这是我的代码:

# Process connections

print('Listening on port', port)
while True:
    c, addr = s.accept()
    print("Got connection from", addr)
    msg = "<html></html>"

    response_headers = {
        'Content-Type': 'text/html; encoding=utf8',
        'Content-Length': len(msg.encode(encoding="utf-8")),
        'Connection': 'close',
    }

    response_headers_raw = ''.join('%s: %s\n' % (k, v) for k, v in response_headers.items())

    response_proto = 'HTTP/1.1'
    response_status = '200'
    response_status_text = 'OK' # this can be random

    # sending all this stuff
    r = '%s %s %s' % (response_proto, response_status, response_status_text)
    c.send(r.encode(encoding="utf-8"))
    c.send(response_headers_raw.encode(encoding="utf-8"))
    c.send('\n'.encode(encoding="utf-8")) # to separate headers from …
Run Code Online (Sandbox Code Playgroud)

python sockets http python-sockets

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

Go Web服务器自动重定向POST请求

我一直试图解决一个奇怪的问题很长一段时间了.在单步执行大量角度代码后,我注意到在通过Charles将请求记录到我的服务器时有些奇怪.

当我发布到网址时/myurl,请求永远不会真正命中我的服务器.相反,它得到301响应,然后GET请求hite我的服务器.

这令人难以置信的令人费解.有没有其他人遇到这个问题?我已经上传了我感兴趣的查尔斯日志的截图.

在此输入图像描述

作为参考,这是我的服务器的样子:

type FormStruct struct {
    Test string
}

func PHandler(w http.ResponseWriter, r *http.Request) {
    var t FormStruct

    req, _ := httputil.DumpRequest(r, true)

    log.Println(string(req))
    log.Println(r.Method) // GET
    log.Println(r.Body)

    decoder := json.NewDecoder(r.Body)
    err := decoder.Decode(&t)
    log.Println("Decoding complete")
    if err != nil {
        log.Println("Error")
        panic(err.Error()+"\n\n")
    }
    log.Println(t.Test)

    w.Write([]byte("Upload complete, no errors"))
}

func main() {
    http.HandleFunc("/myurl/", PHandler)    
    fmt.Println("Go Server listening on port 8001")
    http.ListenAndServe(":8001", nil)
}
Run Code Online (Sandbox Code Playgroud)

http go

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

[Vue 警告]:无法解析组件

这是我的代码:

window.onload = function () {
var main = new Vue({
    el: '#main',
    data: {
        currentActivity: 'home'
    }
});
Vue.component('home', {
    template: '#home-template'
});
};
Run Code Online (Sandbox Code Playgroud)

这是我的模板:

<head>
     <script type="text/x-template" id="home-template">
      <div class="banner dark">
        <div class="content">says some shit</div>
      </div>
      <div class="banner light">
        <div class="content">says some other shit</div>
      </div>
    </script>
</head>
Run Code Online (Sandbox Code Playgroud)

当我加载页面时,我收到此警告:

[Vue warn]: Failed to resolve component: home
Run Code Online (Sandbox Code Playgroud)

和这个错误:

Uncaught TypeError: Cannot read property '_refID' of undefined
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

javascript vue.js

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

psci 中的未知模块 Data.List

我用 brew 安装了 purescript

$ brew install purescript
Run Code Online (Sandbox Code Playgroud)

没有问题。当我启动 PSCI repl 并执行以下操作时:

import Data.List
Run Code Online (Sandbox Code Playgroud)

我得到

Error in module $PSCI:
Unknown module Data.List
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

更新

我开始了pscipulp

$ pulp psci
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试导入时,Data.List我得到:

  Cannot unify type
    Control.Monad.Eff.Eff
  with type
    Prim.Function
Run Code Online (Sandbox Code Playgroud)

哇?

更新

用 npm 重新安装 purescript

$ npm install -g purescript pulp
Run Code Online (Sandbox Code Playgroud)

同样的问题。帮助。

purescript

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

有人可以解释这个懒惰的斐波那契解决方案吗?

这是代码:

fibs = 0 : 1 : zipWith (+) fibs (drop 1 fibs)
Run Code Online (Sandbox Code Playgroud)

评估时,fibs是一个无限的Fibonacci数列表.我不明白的是列表是如何连接的.

zipWith返回一个列表,所以压缩fibs会产生这个:

0 : 1 : [1] : [1,2] : [1,2,3]
Run Code Online (Sandbox Code Playgroud)

因为0 : 1 : zipWith (+) [0,1] [1]产量[1]zipWith (+) [0,1,1] [1,1]产量[1,2]等).

但是,当我运行代码时,我得到了正确的结果.

我在这里不理解什么?

haskell stream fibonacci lazy-evaluation lazy-sequences

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

派生类型类和创建实例之间的区别

假设我有这种数据类型:

data TrafficLight = Red | Yellow | Green deriving (Eq)
Run Code Online (Sandbox Code Playgroud)

它与创建Eq类似的实例有何不同:

data TrafficLight = Red | Yellow | Green

instance Eq TrafficLight where
    Red == Red = True  
    Green == Green = True  
    Yellow == Yellow = True  
    _ == _ = False 
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

注意

这个问题与假定的副本不同,因为我正在寻找derivinginstance关键字之间的对比.假定的欺骗没有提到instance关键字.

haskell

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

混合deps.get失败,{:failed_connect,[{:to_address,{'repo.hex.pm',443}},{:inet,[:inet],{:option,:server_only,:honor_cipher_order}}}}

我正在尝试获取我的elixir项目的依赖项。我无法确定Hex是否掉线(今天早上我可以很好地获取数据)。当我跑步

$ mix deps.get
Run Code Online (Sandbox Code Playgroud)

我看到了:

    Failed to fetch record for 'hexpm/phoenix_live_reload' from registry (using cache)
{:failed_connect, [{:to_address, {'repo.hex.pm', 443}}, {:inet, [:inet], {:option, :server_only, :honor_cipher_order}}]}
    Failed to fetch record for 'hexpm/phoenix_ecto' from registry (using cache)
{:failed_connect, [{:to_address, {'repo.hex.pm', 443}}, {:inet, [:inet], {:option, :server_only, :honor_cipher_order}}]}
    Failed to fetch record for 'hexpm/phoenix' from registry (using cache)
{:failed_connect, [{:to_address, {'repo.hex.pm', 443}}, {:inet, [:inet], {:option, :server_only, :honor_cipher_order}}]}
    Failed to fetch record for 'hexpm/phoenix_pubsub' from registry (using cache)
{:failed_connect, [{:to_address, {'repo.hex.pm', 443}}, {:inet, [:inet], {:option, :server_only, …
Run Code Online (Sandbox Code Playgroud)

elixir-mix elixir hex-pm

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