seek

What is the most efficient way to get first and last line of a text file?

喜你入骨 提交于 2019-12-17 03:28:09
问题 I have a text file which contains a time stamp on each line. My goal is to find the time range. All the times are in order so the first line will be the earliest time and the last line will be the latest time. I only need the very first and very last line. What would be the most efficient way to get these lines in python? Note: These files are relatively large in length, about 1-2 million lines each and I have to do this for several hundred files. 回答1: docs for io module with open(fname, 'rb'

resuming file upload seeking a stream

懵懂的女人 提交于 2019-12-13 20:33:44
问题 I am uploading files from clients to server... when the server program receives the stream, property Length is not supported and CanSeek comes false, how would seeking be possible?? I can get the length if I read it in the client and send as a message header in the message contract but don't know how to seek. Ideas?? 回答1: WCF is not technology for file transfers. Moreover seek is not supported by StreamFormatter used internally because the whole idea of seek in distributed application is

How to translate this Python code to Node.js

China☆狼群 提交于 2019-12-13 14:01:38
问题 I got a very nice answer on here about how to clear a line / delete a line in a file without having to truncate the file or replace the file with a new version of the file, here's the Python code: #!/usr/bin/env python import re,os,sys logfile = sys.argv[1] regex = sys.argv[2] pattern = re.compile(regex) with open(logfile,"r+") as f: while True: old_offset = f.tell() l = f.readline() if not l: break if pattern.search(l): # match: blank the line new_offset = f.tell() if old_offset > len(os

How to enable seeking in Azure Blob stream

做~自己de王妃 提交于 2019-12-13 06:26:15
问题 I have a BlobStream that is created from the method OpenWriter. var blob = CloudContainer.GetBlobReference(name)); if (blob == null) { return null; } return blob.OpenWrite(); Using this stream i would like to seek or set the position, but each time i do this i get a NotSupportedException. After doing some research i found that the canSeek is set to false, which causes this problem. But, the CanSeek is false only if the length is unknown. But the length is known when i run the debugger. Why is

seek on flowplayer is not right

天大地大妈咪最大 提交于 2019-12-13 02:57:18
问题 I'm trying to seek video with no steaming. this is my page: <html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="flowplayer-3.2.13.min.js"></script> <title>Flowplayer test</title> </head><body> <a style="display:block;width:640px;height:360px" id="player"></a> <script> flowplayer("player","flowplayer/flowplayer-3.2.18.swf",{ clip: {url:'sp/gailun640x360.mp4'}}); function vgoto(val) {$f(0).seek(val);} </script> <a href="javascript

Python - ZipFile' object has no attribute 'seek'

僤鯓⒐⒋嵵緔 提交于 2019-12-13 02:51:48
问题 got a problem with my code here. I am trying to get a script working that can make an ePub file. They are compressed zip files that are deflated (i.e. without compression) and have to be done in order. This current script will create a .zip but it is unusable a creates errors both in Python Shell and on the Terminal app when running the zip -t command. The error in question is as follows on the Python shell: Traceback (most recent call last): File "/Users/Hal/Documents/GitHub/Damore-essay

Netstream and step() or seek()?

此生再无相见时 提交于 2019-12-12 16:17:06
问题 I'm on an AS3 project, playing a video (H264). I want, for some special reasons, to go to a certain position. a) I try it with NetStream.seek(). There it only goes to keyframes. In my current setting, this means, i can find a position every 1 second. (for a better resolution, i'd have to encode the movie with as many keyframes as possible, aka every frame a keyframe) this is definetly not my favourite way, because I don't want to reencode all the vids. b) I try it with NetStream.step(). This

Audio/Video Playback with seeking in XNA

做~自己de王妃 提交于 2019-12-12 12:28:02
问题 I'm developing an XNA rhythm game in C# and because it's a rhythm game it's gonna need a song editor, which is going to need precise video & audio seeking & resuming for the songs. I tried MediaPlayer and VideoPlayer classes but both of them cannot seek a specific position, as PlayPosition is read only. Does anyone know a good way to achieve this? Also, it needs to be able to play .mp3 files, so I can't use XACT. The rhythm game osu! is also coded in XNA and somehow it plays mp3 files and

How to seek a string variable (an html files source code)

落花浮王杯 提交于 2019-12-12 06:52:06
问题 How can I seek this sb string variable to get those variables:IMKB's value: 64882,72 how can I get it please show the seek idea using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.Net; using System.IO; public partial class Run2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // used to build entire input StringBuilder sb = new StringBuilder(); //

File object methods write() or writelines() start writing at unexpected position in buffer [Python 3.4.3]

↘锁芯ラ 提交于 2019-12-12 03:46:28
问题 Suppose I want to change the first two characters of the second line of the text file text_file to XX . Say text_file has contents: line1 line2 line3 I wrote the following script to accomplish the task: f = open('text_file', 'r+') f.readline() f.write('XX') f.close() # this flushes changes to disk implicitly When I run this code in Python 2.7.9, this works fine, altering text_file so that it becomes: line1 XXne2 line3 However, when I run it in Python 3.4.3, text_file ends up having these