想出了:
/**
* Create a repo at the specified directory or open one if it already
* exists. Return a {@link Git} object...
*
* @param p
* Path to the repo root (the dir that contains the .git folder)
* @return a "Git" object to run porcelain commands on...
* @throws GitterException
* if the specified path cannot be resolved to a directory, or
* the repository failed to be build (...) or created
*/
public static Git open(Path …Run Code Online (Sandbox Code Playgroud) 我有一个非常大的 JSON (11 gb) 文件,它太大而无法读入我的内存。我想把它分解成更小的文件来分析数据。我目前正在使用 Python 和 Pandas 进行分析,我想知道是否有某种方法可以访问文件的块,以便可以在不使程序崩溃的情况下将其读入内存。理想情况下,我想将数年的数据分解为跨度约为一周的较小的可管理文件,但是没有固定的数据大小,尽管如果它们是设定的间隔并没有那么重要。
这是数据格式
{
"actor" :
{
"classification" : [ "suggested" ],
"displayName" : "myself",
"followersCount" : 0,
"followingCount" : 0,
"followingStocksCount" : 0,
"id" : "person:stocktwits:183087",
"image" : "http://avatars.stocktwits.com/production/183087/thumb-1350332393.png",
"link" : "http://stocktwits.com/myselfbtc",
"links" :
[
{
"href" : null,
"rel" : "me"
}
],
"objectType" : "person",
"preferredUsername" : "myselfbtc",
"statusesCount" : 2,
"summary" : null,
"tradingStrategy" :
{
"approach" : "Technical",
"assetsFrequentlyTraded" : [ "Forex" ],
"experience" : "Novice",
"holdingPeriod" : …Run Code Online (Sandbox Code Playgroud) 我有 n 个按钮最初都标记为“0”。当程序运行时,这些标签或值将更改为不同的整数,例如在某些时候我可能有:'7'、'0'、'2'、...
我有一个将 int 作为参数的函数(或插槽):
void do_stuff(int i);
Run Code Online (Sandbox Code Playgroud)
我想在按下“x”时调用 do_stuff(x)。即:当按下任何按钮时,使用该按钮的值调用 do_stuff。我怎样才能做到这一点?到目前为止,我有类似的东西:
std::vector values; // keeps track of the button values
for (int i = 0; i < n; i++){
values.push_back(0);
QPushButton* button = new QPushButton("0");
layout->addWidget(button);
// next line is nonsense but gives an idea of what I want to do:
connect(button, SIGNAL(clicked()), SLOT(do_stuff(values[i])));
}
Run Code Online (Sandbox Code Playgroud) 在我维护的代码中,我遇到了:
from ctypes.wintypes import MAX_PATH
Run Code Online (Sandbox Code Playgroud)
我想将其更改为:
try:
from ctypes.wintypes import MAX_PATH
except ValueError: # raises on linux
MAX_PATH = 4096 # see comments
Run Code Online (Sandbox Code Playgroud)
但我找不到任何方法从 python ( os, os.path, sys...)获取最大文件系统路径的值- 有标准方法还是我需要外部库?
或者在 linux 中没有类似于 MAX_PATH 的东西,至少不是发行版中的标准?
try:
MAX_PATH = int(subprocess.check_output(['getconf', 'PATH_MAX', '/']))
except (ValueError, subprocess.CalledProcessError, OSError):
deprint('calling getconf failed - error:', traceback=True)
MAX_PATH = 4096
Run Code Online (Sandbox Code Playgroud) 继续从Python float和numpy float32之间的差异开始:
import numpy as np
a = 58682.7578125
print(type(a), a)
float_32 = np.float32(a)
print(type(float_32), float_32)
print(float_32 == a)
Run Code Online (Sandbox Code Playgroud)
印刷品:
<class 'float'> 58682.7578125
<class 'numpy.float32'> 58682.8
True
Run Code Online (Sandbox Code Playgroud)
我完全理解,比较浮点数是否相等不是一个好主意,但还是不应该为False(我们在谈论的是第一个十进制数字的差异,而不是0.000000001)?是否依赖系统?是否在某处记录了这种行为?
编辑:好吧,这是第三位小数:
print(repr(float_32), repr(a))
# 58682.758 58682.7578125
Run Code Online (Sandbox Code Playgroud)
但是我可以相信repr吗?那些如何最终存储在内部?
EDIT2:人们坚持以更高的精度打印float_32会给我它的表示形式。但是,正如我已经根据nympy的文档评论的那样:
%格式运算符要求将其参数转换为标准python类型
和:
print(repr(float(float_32)))
Run Code Online (Sandbox Code Playgroud)
版画
58682.7578125
@MarkDickinson 在这里给出了一个有趣的见解,显然repr应该是忠实的(然后他说这是不忠实的np.float32)。
因此,让我重申如下问题:
float_32afloat和之间进行比较时,上/下转换的确切规则是什么np.float32?我猜想它会将float_32转换为float,尽管@WillemVanOnsem 在评论中建议相反我的python版本:
在Win32上的Python 3.5.2(v3.5.2:4def2a2901a5,Jun 25 2016,22:18:55)[MSC v.1900 64位(AMD64)]
我正在尝试使用tensorflow的每晚1.4,因为我需要Dataset.from_generator将一些可变长度数据集放在一起.这个简单的代码(来自这里的想法):
import tensorflow as tf
Dataset = tf.contrib.data.Dataset
it2 = Dataset.range(5).make_one_shot_iterator()
def _dataset_generator():
while True:
try:
try:
get_next = it2.get_next()
yield get_next
except tf.errors.OutOfRangeError:
continue
except tf.errors.OutOfRangeError:
return
# Dataset.from_generator need tensorflow > 1.3 !
das_dataset = Dataset.from_generator(_dataset_generator,
output_types=(tf.float32, tf.float32))
das_dataset_it = das_dataset.make_one_shot_iterator()
with tf.Session() as sess:
while True:
print(sess.run(it2.get_next()))
print(sess.run(das_dataset_it.get_next()))
Run Code Online (Sandbox Code Playgroud)
失败了,相当神秘:
C:\Dropbox\_\PyCharmVirtual\TF-NIGHTLY\Scripts\python.exe C:/Users/MrD/.PyCharm2017.2/config/scratches/scratch_55.py
0
2017-10-01 12:51:39.773135: W C:\tf_jenkins\home\workspace\tf-nightly-windows\M\windows\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: 0-th value returned by pyfunc_0 is int32, but expects int64
[[Node: PyFunc = PyFunc[Tin=[], Tout=[DT_INT64], …Run Code Online (Sandbox Code Playgroud) 我正在转换一些遗留代码以使用数据集API - 此代码用于feed_dict将一个批次提供给列车操作(实际上是三次),然后使用同一批次重新计算显示的损失.所以我需要一个迭代器,它返回完全相同的批次两(或几次).不幸的是,我似乎无法找到使用张量流数据集的方法 - 它可能吗?
我正在尝试构建一个可以使用鼠标绘制的ScrolledWindow,它也可以正常工作,但是当用户在窗口上绘图而滚动条不在"主页"位置时,我会得到一个令人讨厌的闪烁..
要重现,请运行附加程序,向下滚动(或向右)并按住鼠标左键"涂抹"一下.你应该偶尔看到一个闪烁的..
import wx
class MainFrame(wx.Frame):
""" Just a frame with a DrawPane """
def __init__(self, *args, **kw):
wx.Frame.__init__(self, *args, **kw)
s = wx.BoxSizer(wx.VERTICAL)
s.Add(DrawPane(self), 1, wx.EXPAND)
self.SetSizer(s)
########################################################################
class DrawPane(wx.PyScrolledWindow):
""" A PyScrolledWindow with a 1000x1000 drawable area """
VSIZE = (1000, 1000)
def __init__(self, *args, **kw):
wx.PyScrolledWindow.__init__(self, *args, **kw)
self.SetScrollbars(10, 10, 100, 100)
self.prepare_buffer()
self.Bind(wx.EVT_PAINT, self.on_paint)
self.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
self.Bind(wx.EVT_MOTION, self.on_motion)
def prepare_buffer(self):
self.buffer = wx.EmptyBitmap(*DrawPane.VSIZE)
dc = wx.BufferedDC(None, self.buffer)
dc.Clear()
dc.DrawLine(0, 0, 999, 999) # Draw something to …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 HttpURLConnection 写入图像。
我知道如何编写文本,但在尝试编写图像时遇到了真正的问题
我已经使用ImageIO成功写入本地硬盘:
但我试图通过 ImageIO 在 url 上写入 Image 并失败
URL url = new URL(uploadURL);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "multipart/form-data;
boundary=" + boundary);
output = new DataOutputStream(connection.getOutputStream());
output.writeBytes("--" + boundary + "\r\n");
output.writeBytes("Content-Disposition: form-data; name=\"" + FIELD_NAME + "\";
filename=\"" + fileName + "\"\r\n");
output.writeBytes("Content-Type: " + dataMimeType + "\r\n");
output.writeBytes("Content-Transfer-Encoding: binary\r\n\r\n");
ImageIO.write(image, imageType, output);
Run Code Online (Sandbox Code Playgroud)
uploadURL 是服务器上的 ASP 页面的 url,该页面将使用“content-Disposition:part.txt”中给出的文件名上传图像。
现在,当我发送此信息时,ASP 页面会找到请求并找到文件名。但没有找到要上传的文件。
问题是当 ImageIO 在 URL 上写入时,ImageIO 正在写入的文件的名称是什么,
所以请帮助我 ImageIO 如何在 URLConnection 上写入图像以及我如何知道我必须在 …
java sockets urlconnection image-processing httpurlconnection
我有一个很小的 TCP 应用程序,其中许多客户端连接到服务器,向其发送数据(通过 write() - 它们也发送消息大小),然后退出。我让客户端在发送完成后将 \0\0 发送到服务器 - 我这样做是为了如果服务器从 read() 得到一个零,那么它就知道客户端出了问题(比如 SIGKILL)。我的问题是 - 是否有任何编程方式(某些系统调用)来通知服务器我已完成发送 - 而不是服务器始终检查 \0\0 ?服务器在客户端/侦听套接字上使用 poll() 来检测是否有要读取的内容/新的连接请求,顺便说一句。
我应该发出信号吗?但我如何知道哪个描述符停止轮询呢?
我读过这篇文章,但其中的答案或多或少是我现在使用的