wrapper

Setting an Item in nested dictionary with __setitem__

最后都变了- 提交于 2019-12-05 16:25:18
Here's what I did, trying to create a wrapper for a dict-like database, among other functions: class database(object): def __init__(self, name): self.name = name self.db = anydbm.open(name, 'c') def __getitem__(self, key): key = str(key) try: self.db = anydbm.open(self.name, 'w') except Exception,e: raise e else: return cPickle.loads(self.db[key]) finally: self.db.close() def __setitem__(self, key, value): key = str(key) value = cPickle.dumps(value) try: self.db = anydbm.open(self.name, 'w') except Exception,e: print e else: self.db[key] = value finally: self.db.close() When I try to define a

Why don't the wrapper classes for Primitives have a setter?

北慕城南 提交于 2019-12-05 12:07:15
What is the reason why Wrapper classes (like Integer, Double, etc.) don't have a setter for their inner primitive value ? I am asking this because that kind of functionality would have simplified calculus, and have made the Java language a little more flexible . Let me give you some examples. 1) Let's take the following example: Integer x = new Integer(5); x++; The previous code behind the scenes is performing autoboxing . Something like: int x_tmp = x.intValue(); x_tmp++; x = new Integer(x_tmp); // Yes that's a new memory allocation Because of this problem doing calculus on Wrapper is slower

Block all other input to an application and control it from a wrapper in Java

柔情痞子 提交于 2019-12-05 10:58:12
问题 I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also

C# Ghostscript Wrapper

我的梦境 提交于 2019-12-05 09:11:43
Has anyone encountered a nice wrapper for GhostScript in C#. My specific use is to take postscript and turn it into a pdf AJ. Open-source PDFSharp has a namespace for using GhostScript. Even if you can't directly use it, you can probably graft whatever you need out of the source. Mattygabe Matthew Ephraim has created a pretty simple C# wrapper called GhostScriptSharp that uses P/Invoke to access the unmanaged Ghostscript DLL in your C# application: http://mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/ For completeness, there's also Gouda Ghostscript wrapper . You can also

Using value wrapper and operator() overloading to simplify getter/setter design : a dangerous practice?

不羁岁月 提交于 2019-12-05 06:34:35
Consider the following class: class MyClass1 { public: double x() const {return _x;} // getter double y() const {return _y;} // getter double z() const {return _x*_y;} // getter void x(const double var) {_x = var;} // setter void y(const double var) {_y = var;} // setter void z(const double var) {_x = var; _y = 1;} // setter protected: double _x; double _y; }; As the actual contents of MyClass1 is an implementation detail, the getters and setters provide a unified way to get and set the class contents even if they are interdependant (here _z does not exists internally but for the user, z is a

How to wrap various elements in a div tag with jQuery?

一世执手 提交于 2019-12-05 06:21:43
I have an html structure that looks like this: <h5>Title</h5> <p> Content </p> <ul> <li>Item</li> <li>Item</li> </ul> <p> Content </p> <h5>Title</h5> <p> Content </p> <ul> <li>Item</li> <li>Item</li> </ul> <p> Content </p> In summary it's just some headers with content below them, I just need everything below the header tags in a div like this: <h5>Title</h5> <div> <p> Content </p> <ul> <li>Item</li> <li>Item</li> </ul> <p> Content </p> </div> I've tried using the .wrap function of jQuery but no luck since there can be multiple types elements below the header tags, I found this question:

How to intercept every AJAX request from a webpage

本小妞迷上赌 提交于 2019-12-05 05:49:27
I need the way to intercept all ajax requests maded from page. So i need some wrapper to add my data to all users requests. Andrey Nikishaev Huh... i made this work))) with help of this topic Extending an ActiveXObject in javascript i made script that intercept all ajax requests no matter what framework or browser do user use. You can look at it here: Script I dont think you can get this out of the box . What you need here is a little restructuring of your client side code [ You should have already done that , but it is never too late :) ] . Make a function that has the responsibility of

Wrapping all possible method calls of a class in a try/except block

点点圈 提交于 2019-12-05 04:33:16
问题 I'm trying to wrap all methods of an existing Class (not of my creation) into a try/except suite. It could be any Class, but I'll use the pandas.DataFrame class here as a practical example. So if the invoked method succeeds, we simply move on. But if it should generate an exception, it is appended to a list for later inspection/discovery (although the below example just issues a print statement for simplicity). (Note that the kinds of data-related exceptions that can occur when a method on

Can't find standard C++ includes when using C++ class in Cocoa project

☆樱花仙子☆ 提交于 2019-12-05 02:58:58
I have a Cocoa project (a Mac OS X app), all Objective-C. I pulled in one C++ class (which I know works) from another project, and make an Objective-C wrapper for it. The ObjC wrapper class is using a .mm extension. However, the C++ header file contains #include s to standard C++ header files ( <vector> , for example), and I get errors on those. A minimal example would look like the following. CppClass is the C++ class, and CppWrapper is the ObjC class which wraps it. // CppClass.h #ifndef _CPP_CLASS_H_ #define _CPP_CLASS_H_ #include <vector> class CppClass { public: CppClass() {} ~CppClass()

What is the best way to call into Swift from C?

别说谁变了你拦得住时间么 提交于 2019-12-05 00:32:40
Calling into C from Swift is pretty simple, however I'm looking into making a bi-directional wrapper in C, so my C has to call Swift functions. Right now, I can do this by declaring function pointers in C, and having my C functions call them after the Swift side has set them up to call code in Swift. My C header file: typedef void (*callback_t)(void); void callBackIntoSwift( callback_t cb ); My C implementation file: #include "stuff.h" #include <stdio.h> void callBackIntoSwift( callback_t cb ) { printf( "Will call back into Swift\n" ); cb(); printf( "Did call back into Swift\n" ); } After