简体   繁体   English

我究竟做错了什么? -输出到python 3.x中的文件

[英]What am I doing wrong? - Output to file in python 3.x

Here is some of the code I have - My issue is in the generateTable() function: 这是我拥有的一些代码-我的问题在generateTable()函数中:

I have created a Huffman Code tree and I want to output each node's location so that it appears like so: 我已经创建了一个霍夫曼代码树,我想输出每个节点的位置,使其看起来像这样:

10 111100
32 110
33 1010110110
34 10101111
38 01100110110101110011
39 1110101011
40 1010110111011101
41 011001101101010

Why won't that function write to the file properly? 为什么该功能无法正确写入文件? (I ask because that code was provided to me by my professor and I don't understand the problem.) When I open the file it is empty. (我问是因为该代码是我的教授提供给我的,所以我不明白问题所在。)当我打开文件时,它是空的。

If this is the exact code that was provided to you, then you should probably implement the orderNodes and readFileIn functions. 如果这是提供给您的确切代码,则您可能应该实现orderNodesreadFileIn函数。 They currently do nothing besides returning the empty ArrayHeap that is created in the line before they are called. 除了返回在调用之前在该行中创建的空ArrayHeap之外,它们目前不执行任何操作。

Also, I'm surprised that HTree.generateTable(...) even works, as it is not instantiated as an instance of HuffManNode (as far as I can see) 另外,令我惊讶的是HTree.generateTable(...)甚至可以工作,因为它没有作为HuffManNode的实例实例化(据我所知)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM