convert

Convert xPath to JSoup query

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does anyone know of an xPath to JSoup convertor? I get the following xPath from Chrome: //*[@id="docs"]/div[1]/h4/a and would like to change it into a Jsoup query. The path contains an href I'm trying to reference. 回答1: This is very easy to convert manually. Something like this (not tested) document.select("#docs > div:eq(1) > h4 > a").attr("href"); Documentation: http://jsoup.org/cookbook/extracting-data/selector-syntax Related question from comment Trying to get the href for the first result here: cbssports.com/info/search#q=fantasy%20tom

Convert a byte arry to OpenCV image in C++

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a byte array that represents a .jpg file that I want to convert directly to an OpenCV Mat object. I have something like byte * data ; // Represents a JPG that I don't want to disk and then read. // What goes here to end up with the following line? cv :: Mat * image_representing_the_data ; 回答1: the previously mentioned method will work fine, if it's PIXEL data. if instead, you have a whole jpg FILE in memory, headers, compression, and all, it won't work. in that case you want: Mat img = imdecode ( data ); which will do the

Convert string to Python class object?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given a string as user input to a python function, I'd like to get a class object out of it if there's a class with that name in the currently defined namespace. Essentially, I want the implementation for a function which will produce this kind of result: class Foo: pass str_to_class("Foo") ==> Is this possible? 回答1: This seems simplest. >>> class Foo(object): ... pass ... >>> eval("Foo") 回答2: This could work: import sys def str_to_class(str): return getattr(sys.modules[__name__], str) 回答3: You could do something like: globals()[class_name]

iOS Swift 3 : Convert “yyyy-MM-dd'T'HH:mm:ssZ” format string to date object

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hello i have a dictionary self.publishedAt = dictionary["publishedAt"] as? NSString in which i'm getting date " 2017-01-27T18:36:36Z ". I want to convert it in readable format : dd-MM-yyyy hh:mm:ss . i tried via let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy hh:mm:ss" let date = dateFormatter.date(from: (self.publishedAt as? String)!) print("EXACT_DATE : \(date)") But getting nil. :( What is the correct way to get date in simple format? 回答1: You need an input format to convert the ISO8601 string to date and an

How do I convert a string to a double in Python?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to know how to convert a string containing digits to a double. 回答1: >>> x = "2342.34" >>> float(x) 2342.3400000000001 There you go. Use float (which is almost always a C double). 回答2: The decimal operator might be more in line with what you are looking for: >>> from decimal import Decimal >>> x = "234243.434" >>> print Decimal(x) 234243.434 回答3: Be aware that if your string number contains more than 15 significant digits float(s) will round it.In those cases it is better to use Decimal Here is an explanation and some code

django - convert a list back to a queryset [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Order a QuerySet by aggregate field value 3 answers I have a handful of records that I would like to sort based on a computed value. Got the answer over here ... like so: sorted(Profile.objects.all(), key=lambda p: p.reputation) on a Profile class like this: class Profile(models.Model): ... @property def reputation(self): ... Unfortunately the generic view is expecting a queryset object and throws an error if I give it a list. Is there a way to do this that returns a queryset or... Can I convert a

How can i convert a DBQuery<T> to an ObjectQuery<T>?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a DBQuery<T> which converts to an IQueryable<T> (this bit works fine). But then I'm trying to convert the IQueryable to an ObjectQuery .. which fails :- public void Foo(this IQueryable<T> source) { // ... snip ... ObjectQuery<T> objectQuery = source as ObjectQuery<T>; if (objectQuery != null) { // ... do stuff ... } } This used to work before I changed over to Entity-Framework 4 CTP5 Magic Unicorn blah blah blah . Now, it's not working - ie. objectQuery is null . Now, DBQuery<T> inherits IQueryable<T> .. so I thought this should

How to convert a Hadoop Path object into a Java File object

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to change a valid and existing Hadoop Path object into a useful Java File object. Is there a nice way of doing this or do I need to bludgeon to code into submission? The more obvious approaches don't work, and it seems like it would be a common bit of code void func(Path p) { if (p.isAbsolute()) { File f = new File(p.toURI()); } } This doesn't work because Path::toURI() returns the "hdfs" identifier and Java's File(URI uri) constructor only recognizes the "file" identifier. Is there a way to get Path and File to work together?

How to convert node to image in javafx 2.1?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Java FX and I would like to convert a node to an image. I found this resource, but it does not solve my problem as I want to convert a node to an image, not a whole scene. How to output the content of a Scene graph in JavaFx 2.0 to an Image 回答1: You can use new FX 2.2 snapshot feature: public class TrySnapshot extends Application { @Override public void start(Stage primaryStage) { final VBox vbox = new VBox(2); final Button btn = new Button(); vbox.getChildren().add(btn); btn.setText("Say 'Hello World'"); btn.setOnAction(new

Convert png to jpeg using Pillow in python

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to convert png to jpeg using pillow. I've tried several scrips without success. These 2 seemed to work on small png images like this one. First code: from PIL import Image import os, sys im = Image.open("Ba_b_do8mag_c6_big.png") bg = Image.new("RGB", im.size, (255,255,255)) bg.paste(im,im) bg.save("colors.jpg") Second code: image = Image.open('Ba_b_do8mag_c6_big.png') bg = Image.new('RGBA',image.size,(255,255,255)) bg.paste(image,(0,0),image) bg.save("test.jpg", quality=95) But if I try to convert a bigger image like this one i'm