head

Read first N lines of a file in python

南楼画角 提交于 2019-11-26 11:34:33
We have a large raw data file that we would like to trim to a specified size. I am experienced in .net c#, however would like to do this in python to simplify things and out of interest. How would I go about getting the first N lines of a text file in python? Will the OS being used have any effect on the implementation? John La Rooy Python 2 with open("datafile") as myfile: head = [next(myfile) for x in xrange(N)] print head Python 3 with open("datafile") as myfile: head = [next(myfile) for x in range(N)] print(head) Here's another way (both Python 2 & 3) from itertools import islice with open

inject a javascript function into an Iframe

隐身守侯 提交于 2019-11-26 08:56:19
问题 This link (archived version) describes how to inject code from a script into an iframe: function injectJS() { var iFrameHead = window.frames[\"myiframe\"].document.getElementsByTagName(\"head\")[0]; var myscript = document.createElement(\'script\'); myscript.type = \'text/javascript\'; myscript.src = \'myscript.js\'; // replace this with your SCRIPT iFrameHead.appendChild(myscript); } That\'s ok, but what if I want to insert a function object into an iframe and get it executed in the iframe

Making HTTP HEAD request with urllib2 from Python 2

送分小仙女□ 提交于 2019-11-26 08:22:55
问题 I\'m trying to do a HEAD request of a page using Python 2. I am trying import misc_urllib2 ..... opender = urllib2.build_opener([misc_urllib2.MyHTTPRedirectHandler(), misc_urllib2.HeadRequest()]) with misc_urllib2.py containing class HeadRequest(urllib2.Request): def get_method(self): return \"HEAD\" class MyHTTPRedirectHandler(urllib2.HTTPRedirectHandler): def __init__ (self): self.redirects = [] def http_error_301(self, req, fp, code, msg, headers): result = urllib2.HTTPRedirectHandler.http

One or more resources has the target of 'head' but not 'head' component has been defined within the view

余生长醉 提交于 2019-11-26 04:53:19
问题 I\'m using NetBeans 7.3.1 and PrimeFaces 3.5 on GlassFish 3.2. I created a JSF page with PrimeFaces components. The project runs fine, but the PrimeFaces UI look\'n\'feel is completely missing. I\'m only noticing below message in server log: One or more resources has the target of \'head\' but not \'head\' component has been defined within the view What does this mean and how can I fix the PrimeFaces UI look\'n\'feel? 回答1: This means that you're using plain HTML <head> instead of JSF <h:head>

Read first N lines of a file in python

点点圈 提交于 2019-11-26 03:29:48
问题 We have a large raw data file that we would like to trim to a specified size. I am experienced in .net c#, however would like to do this in python to simplify things and out of interest. How would I go about getting the first N lines of a text file in python? Will the OS being used have any effect on the implementation? 回答1: Python 2 with open("datafile") as myfile: head = [next(myfile) for x in xrange(N)] print head Python 3 with open("datafile") as myfile: head = [next(myfile) for x in