问题标签 [human-readable]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 如何判断文件是否在 C# 中是文本可读的
我正在做的项目列表的一部分是一个小文本编辑器。
在某一时刻,您可以加载给定目录中的所有子目录和文件。该程序会将每个节点添加为 TreeView 中的一个节点。
我想要的功能是只添加普通文本阅读器可读的文件。
此代码当前将其添加到树中:
我知道我可以轻松地创建一个 if 语句,例如:
但我必须扩展该语句以包含它可能的每一个扩展。
有没有更简单的方法来做到这一点?我认为这可能与 mime 类型或文件编码有关。
linux - 在 Unix 上查找人类可读的文件
我想在我的 Linux 机器上找到人类可读的文件,没有文件扩展名限制。这些文件应该是人类感知文件,如文本、配置、HTML、源代码等文件。有没有办法过滤和定位?
ruby - 提高大 attr_accessor 的可读性
attr_accessor
定义非常大的常量或符号时应该怎么做?例如,像这样:
在课堂上是可怕的。这是最好的方法吗?我想知道是否还有其他方法可以提高可读性。
python - 打印字典 (JSON) 人类可读
假设我有一个像这样的(嵌套)字典(注意列表值):
我正在寻找一种正确的方法来打印这本字典,我正在json
这样做:
上面的代码给了我以下输出:
虽然上面的输出非常好,但仍然很难阅读,特别是如果有很多级别和较长的名称。我也试过yaml
给出以下看起来很奇怪的内容:
是否有任何其他库可以产生更好的转储,我认为下面的输出更容易阅读:
我相信上面的内容更容易阅读,并且可能有 python 库可以做到这一点。
python - Is there any support for a Python program to be able to write a human-readable configuration file from which it can restore its state later?
Update:
Based on the responses as of 3/16/2013 (or lack thereof), I get the impression that nothing anything like what I have in mind exists already. Thus I will build such a mechanism for myself using the configparser module which was suggested by John Y and which does look to be helpful.
Original:
I am not talking about a checkpoint or a core dump. I seek help for a solution which provides a portable text file which can be used by instances of the same program running on entirely different machines and OSes.
I am primarily interested in addressing this question in the context of Python. A few years ago I had written a fairly complex Java program for which the user interface was highly configurable. I wanted to make it easy for a user to save whatever state he had configured and be able to make that his default for the next time he used the program. Furthermore, I wanted the file written for this purpose to be human readable and editable, so that alteration of the file itself could be another approach to setting up different configurations for the program. I solved the problem by a rather brute force solution which required writing specific code for each kind of relevant data structure, both to output it and to read it back in. It was a good solution to the problem; but it was tedious to implement. I was recently looking at a Java program written by someone else, and I saw that he had a much more elegant solution to the problem. (Though the underlying data base for describing an instance of his interface was not quite as elaborate as mine was.)
Now I am writing another such program which will be even more configurable. I am writing it in Python. I am but a beginner when it comes to Python; but I must say that I really like it. I have programmed in a great many languages ranging from assembly languages and Fortran to Lisp and APL; and I must say that learning Python has provided the most pleasant experience yet. Nevertheless, I keep running across very nice extensions and capabilities of which I was not yet aware. Most of the times I did a search to answer some question I had about Python, I would discover that the issue had been addressed comprehensively here at stackoverflow. Thus I am hopeful that some folks here will get the idea of what I seek, and, if possible, point me to some tools that will facilitate the process.
We are talking about a configuration file. Instances of it can be used with a distribution to set up different possible default configurations for the first time a person uses the program. The program itself can write such a file, which, when interpreted, will set up the same configuration as when state was saved. (Note that I am not talking about the application data which the program manipulates. That can be treated as a binary file which can be saved and restored rather easily. Different problem.) It is not as simple as saving particular parameters which can be set by using Widgets in the GUI, though that is part of it. (I am using Tkinter.) The problem is further complicated by the fact that the user can freely create additional objects, each with its own window, and each of which has its own configuration to deal with.
So far, I have written quite a bit of the low level code, without getting involved in making the GUI for all the things I want to be configurable. So I am asking the question here now, because the answer may have some impact on how I go about implementing the GUI. E.g., there may be 'things' I can attach to Widgets that say, "This parameter is something that needs to be saved in the configuration file for a state-save operation." And then it happens automatically when such a save is initiated. Furthermore, mechanisms for interpreting the output when the configuration is read back in are automatically created.
If I were to undertake this entirely myself, I am thinking I would have the program write a Python script, which, when interpreted, would restore the state. In some cases, there would be direct assignments to values in some of the modules. In other cases, there would be invocations of functions which would set some things up in the same manner that applied at the time of the save. Such a file could still be interpreted to a great extent and edited to some extent even by persons not really familiar with Python.
Anyway, I am interested in other ideas about how to attack this problem. I am hopeful that some tools may exist to facilitate a solution because I don't think that what I want to accomplish is an unusual thing to want. I apologize for the long-winded explanation; but I thought that there were a number of directions in which it was possible to misinterpret what I seek, and I wanted to be sure that folks understood where I was coming from. I would appreciate any pointers.
Added:
I think that, ideally, what I seek would work like this: I would take responsibility in the code for identifying all those bits of data which constitute configuration information in the sense I have in mind. (E.g., I might have a function that does something like "Add the setting of this Widget to the list of Widget-settable parameters that need to be saved for the configuration." Or the Thingy class on instantiation might want to say "Here is another instance of Thingy in the configuration and these are its attributes which are configurable.") Then, with that knowledge at the time a state-saving operation was requested, a separate tool would take over the task of dumping a description of all the information so-identified to a file. Another separate tool could be used to read that file and restore all the data. I am prepared to write those tools; but I am hoping something like this may already have been done.
responding to luc -
I realized that I had overemphasized the word "GUI" in my description, so I edited the description above to fix that.
I am not concerned with what the Widgets look like or how they are managed geometrically. The program will take care of all that. ptkgen seems more concerned about the appearance of the Widgets and their layout than about what their settings mean from the user's point of view. I am concerned with the settings of things that are configurable via the GUI, and the effects of actions the user has taken which affect things like what windows exist and where they are on the screen.
I do see that Python has support for encoding and decoding JSON, but that seems to be at a low level - a level so low that it does not address the larger issue. You would still have to make the particular calls to dump the particular set of things that constitute the state of the application and know what you are loading at that level when the file was read. At that level, I can invent my own format which would actually be easier to write and interpret than it would be using JSON.
regex - htaccess 人类可读
我有一个站点,它已经定义了 htaccess 以使 url 更好
一切正常(根文件夹中有 cms)。
现在我想在根目录中创建一个文件夹并为其制定另一个规则:
所以我想从 url 重定向所有内容:.../tip/?id=N
->../tip/N
它似乎工作正常,传递了 id,但加载了数据。网站内的所有网址都是错误的(javascript、css)。它们没有加载。
例如,代码:<script defer src="js/filtrify.js"></script>
产生:http://wincode.org/tip/js/filtrify.js
但如果您尝试将其加载到另一个选项卡中,我认为它将js/filtrify.js
作为id
参数传递。如何解决这个问题?
c# - 使大小数字易于阅读
我想以人类友好的方式在 C# 中打印我非常小的数字,例如:
30µ
为3E-5
或456.789n
为0.000000456789
。
我知道 C 中 BSD 的Humanize_number () 函数,但仅与位整数兼容,而不与浮点数和双精度数兼容。C# 中是否有支持这些的等价物?
此外,它在显示数字时应保持一定的精度,例如:
0.003596
应显示为3.596µ
, not 3.6µ
(或更糟的是4µ
)。
此处可能的答案:Formatting Large Numbers with .NET但适用于负 log10 将逗号后的数字截断为 1 位。在我看来,这还远远不够。
我想如何呈现事物的示例:
我无法制定我的问题以在 SO 中找到相关答案,所以如果问题已经得到解答,请开火!
php - php过期日期为字符串
我从 MySQL 获得了“YYYY-MM-DD HH:MM:SS”格式的日期(例如“2013-05-28 12:58:24”)。如何将这样的日期转换为可读的字符串,例如“此文件将在 2 小时 35 分钟后过期”?提前致谢!
php - socket_recv 我想要可读的数据而不是字节数
大家好,如果已经问过,希望你们不要用虚拟枪射击我,但是,就这样吧。
我是 socket_send 到一个 ip/port,我看到服务器接收并回复数据。我的代码接收 xxxx 个字节。我想知道这些字节需要 IE: xml 字符串,以便我可以在我的应用程序中解析和使用数据。cURL 在这种情况下是不可行的,因为服务器接收到标头并且根本不响应。
回复:
TCP/IP 连接正常。好的。正在尝试连接到端口 '9000' 上的 'xxx.xxx.xxx.xxx' ...好的。发送 HTTP HEAD 请求...好的。读取响应:从 socket_recv() 读取 1365 个字节。关闭插座...好的。
java - Java - 将人类可读大小转换为字节
我发现了很多关于将原始字节信息转换为人类可读格式的信息,但我需要做相反的事情,即将字符串“1.6 GB”转换为长值 1717990000。是否有内置/好-定义的方法来做到这一点,还是我几乎必须自己动手?
[编辑]:这是我的第一个刺...