我有一个大约 100 万个地址的列表,以及一个查找它们的纬度和经度的函数。由于某些记录格式不正确(或出于任何原因),有时该函数无法返回某些地址的纬度和经度。这将导致 for 循环中断。因此,对于成功检索到纬度和经度的每个地址,我想将其写入输出 CSV 文件。或者,也许不是逐行写入,以小块大小写入也可以。为此,我df.to_csv在“追加”模式 ( mode='a') 中使用,如下所示:
for i in range(len(df)):
place = df['ADDRESS'][i]
try:
lat, lon, res = gmaps_geoencoder(place)
except:
pass
df['Lat'][i] = lat
df['Lon'][i] = lon
df['Result'][i] = res
df.to_csv(output_csv_file,
index=False,
header=False,
mode='a', #append data to csv file
chunksize=chunksize) #size of data to append for each loop
Run Code Online (Sandbox Code Playgroud)
但问题在于,它正在为每个附加打印整个数据帧。因此,对于n行,它将写入整个数据帧n^2时间。如何解决这个问题?
在这个源代码http://man7.org/tlpi/code/online/dist/sysinfo/procfs_pidmax.c.html中,/proc/sys/kernel/pid_max首先简单地读取该文件(使用read系统调用),然后简单地写入(使用write系统调用).
lseek在写作之前为什么没有必要到头开始?我认为文件偏移指针对于读取和写入是相同的(这是相关书籍的作者所说的).
用户右键单击Finder中的目录并查找自定义MenuItem.单击该项将告诉我的应用程序打开一个用户可以完成其工作的窗口.完成后,需要通过右键单击将文件写入他选择的文件夹.
我现在一切都工作了,但最后一部分.扩展程序无法写入所选文件夹.
选择他想与之交互的文件夹的用户似乎不属于Powerbox的一部分 - 我的理解方式 - 只能用openPanel和激活savePanel.如何获得与用户通过菜单项选择的文件夹进行交互的权限?我无法在开发人员库中找到对该问题的任何可能解决方案的引用.不在沙盒指南中,而不在扩展指南中.
如果无法使用所选文件和文件夹,添加自定义菜单项的可能性将毫无用处,因此我确信必须有一种方法来访问它们.
也许我试图写的方式是错的.我的主应用程序将临时文件写入共享组文件夹.之后,它会发送扩展程序监听的通知:
func copyFile(notification:NSNotification)
{
NSLog("write file")
if let target = tmpTarget
{
let secureContainer = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.de.enie.Nu")
let contents = NSFileManager.defaultManager().contentsOfDirectoryAtURL(secureContainer!, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions.SkipsHiddenFiles | NSDirectoryEnumerationOptions.SkipsPackageDescendants | NSDirectoryEnumerationOptions.SkipsSubdirectoryDescendants , error: nil)
for content in contents as! [NSURL]
{
NSLog("tmp data: \(content.path!)")
if content.lastPathComponent!.stringByDeletingPathExtension == "SharedData"
{
NSLog("found shared file")
NSFileManager.defaultManager().copyItemAtURL(content, toURL: target.URLByAppendingPathComponent(content.lastPathComponent!), error: nil)
NSFileManager.defaultManager().removeItemAtURL(content, error: nil)
}
}
tmpTarget = nil
}
}
Run Code Online (Sandbox Code Playgroud)
尝试编写文件会导致这些控制台通知:
背景:
我正在开发一个与数据库相关的程序,我需要按顺序将脏元数据从内存刷新到磁盘./ dev/sda1是volumn格式,因此将逐块访问/ dev/sda1上的数据,如果按顺序访问,则块在物理上相邻.我使用直接I/O,因此I/O将绕过文件系统的缓存机制并直接访问磁盘上的块.
问题:
在打开/ dev/sda1之后,我将读取一个块,更新块并将块重新写回/ dev/sda1开头的相同偏移量.
代码如下 -
//block_size = 256KB
int file = open("/dev/sda1", O_RDWR|O_LARGEFILE|O_DIRECT);
for(int i=0; i<N; i++) {
pread(file, buffer, block_size, i*block_size);
// Update the buffer
pwrite(file, buffer, block_size, i*block_size);
}
Run Code Online (Sandbox Code Playgroud)
我发现如果我不做pwrite,读取吞吐量是125 MB/s.
如果我执行pwrite,读取吞吐量将为21 MB/s,写入吞吐量为169 MB/s.
如果我在pwrite之后pread,写吞吐量是115 MB/s,读吞吐量是208 MB/s.
我也试过read()/ write()和aio_read()/ aio_write(),但问题仍然存在.我不知道为什么在读取文件的相同位置后写入会使读取吞吐量如此之低.
如果一次访问更多的块,就像这样
pread(file, buffer, num_blocks * block_size, i*block_size);
Run Code Online (Sandbox Code Playgroud)
问题会缓解,请参阅图表.
我试图找出是否可以使用默认系统应用程序从Progressive Web App中打开文件。
这个想法是PWA将存储一些文件供脱机使用(例如.docx文件),并且用户可以打开它们而无需(重新)下载它们。
理想的情况是PWA能够将文件加载到内存中,使该文件类型的默认系统应用程序可以访问该文件(例如,Word for .docx文件),监视更改(即用户保存编辑),以及然后将其存储回PWA存储中。即使是只读的解决方案也将很棒。
由于隐含着严重的安全问题,并且由于从Google搜索中未发现任何问题,因此,我最好的选择是尚不支持此操作。但是,我希望可能有一种我不知道的方法,并且该方法不需要用户下载文件的副本。
我想写/读一个哈希表到/从磁盘,但它不是一个(print)能够对象.我不会知道关键名称,所以我想不出手动方式.我读到可能有特定于发行版的方法来做到这一点; 在SBCL有什么事吗?
我没有在SBCL手册或Google上找到任何内容.
如果没有,是否有另一种可存储的方法来保持绑定到字符串的整数列表,能够有效地修改这些列表,并且具有恒定或至少快于访问时间的访问时间?
二进制搜索树是否足以用alist实现,这对于创建基本数据库是一个好主意吗?
我正在读一个由第三方程序定期写入的文件.我正在使用下面的FileStream阅读:
using (FileStream fs = new FileStream(
FullPath,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
Run Code Online (Sandbox Code Playgroud)
但是第三方程序正在写入文件,但正在使用 FileShare.None
因此,当第三方程序尝试以独占访问权限打开文件但失败时,我偶尔会打开文件进行阅读.
如何在不引起第三方程序问题的情况下读取此文件?我不介意发布我的阅读以优先考虑另一个应用程序.有什么办法吗?
我将如何阻止对文件的访问,直到涉及该文件的读写过程的特定函数返回?
我经常想创建某种中央注册表,并且可能有多个R进程参与读取和写入该注册表(以"穷人的并行化"设置为例,其中不同的进程彼此独立地运行,除非尊重到注册表访问).
我不喜欢依赖任何DBMS,例如SQLite的,PostgreSQL的,MongoDB的等早在devel的过程.即使我后来可能使用DBMS,基于文件系统的解决方案仍可能是一个方便的后备选项.因此,我很好奇我如何通过基本R功能实现它(充其量).
我知道,与DBMS解决方案相比,在并行设置中对文件系统进行大量读写操作并不是非常有效.
我在MS Windows 8.1(64位)上运行
当两个或多个R进程同时尝试写入或读取文件时,究竟发生了什么?操作系统是否自动找出"访问顺序"并执行"第二次"进程等待或是否会触发错误,因为第一个进程可能会阻止文件访问?我怎么能阻止第二个进程返回错误,而是"等待"直到轮到他?
除了rredis包之外:MS Windows上还有其他共享内存选项吗?
注册表文件的路径:
path_registry <- file.path(tempdir(), "registry.rdata")
Run Code Online (Sandbox Code Playgroud)
注册事件的示例函数:
registerEvent <- function(
id=gsub("-| |:", "", Sys.time()),
values,
path_registry
) {
if (!file.exists(path_registry)) {
registry <- new.env()
save(registry, file=path_registry)
} else {
load(path_registry)
}
message("Simulated additional runtime between reading and writing (5 seconds)")
Sys.sleep(5)
if (!exists(id, envir=registry, inherits=FALSE)) {
assign(id, values, registry)
save(registry, file=path_registry)
message(sprintf("Registering with ID %s", id)) …Run Code Online (Sandbox Code Playgroud) 我正在阅读和写入文本文件.有一个实例,我想删除文件的内容(但不是文件)作为一种重置.我怎样才能做到这一点?
if ((dirs) != nil) {
var dir = dirs![0]; //documents directory
let path = dir.stringByAppendingPathComponent("UserInfo.txt");
println(path)
let text = "Rondom Text"
//writing
text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil)
//reading
let text2 = String(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil)
println(text2)
Run Code Online (Sandbox Code Playgroud) I'm currently reading and writing .EPS file to manipulate/add metadata (Keywords and Tags) in the file.
PS: File encoding is Windows-1251 or Cp1251 -Russian-
I'm reading EPS file like this: (String lines; is a global variable)
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "Cp1251"))) {
String line;
while((line = br.readLine()) != null) {
if(line.contains("</xmpTPg:SwatchGroups>")) {
lines.add(line);
lines.add(descriptionKwrds);
}
else
lines.add(line);
System.out.println(line);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex); …Run Code Online (Sandbox Code Playgroud) read-write ×10
file ×3
c ×2
.net ×1
c# ×1
common-lisp ×1
disk-io ×1
eps ×1
filestream ×1
filesystems ×1
findersync ×1
hashtable ×1
ioexception ×1
java ×1
javascript ×1
linux ×1
lisp ×1
locking ×1
lseek ×1
macos ×1
metadata ×1
pandas ×1
performance ×1
pwa ×1
python ×1
r ×1
sandbox ×1
sbcl ×1
swift ×1
throughput ×1
writetofile ×1