default

How can I return a default value for an attribute? [duplicate]

和自甴很熟 提交于 2019-11-29 04:56:41
问题 This question already has an answer here: A get() like method for checking for Python attributes 3 answers I have an object myobject , which might return None . If it returns None , it won't return an attribute id : a = myobject.id So when myobject is None , the stament above results in a AttributeError : AttributeError: 'NoneType' object has no attribute 'id' If myobject is None, then I want a to be equal to None . How do I avoid this exception in one line statement, such as: a = default

Default array values if key doesn't exist?

眉间皱痕 提交于 2019-11-29 04:40:20
问题 If I have an array full of information, is there any way I can a default for values to be returned if the key doesn't exist? function items() { return array( 'one' => array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ), 'two' => array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ), 'three' => array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ), ); } And in my code $items = items(); echo $items['one']['a']; // 1 But can I have a default value to be returned if I give a key that doesn't exist like,

java Timezone setDefault effects

☆樱花仙子☆ 提交于 2019-11-29 04:17:20
following How to store date/time and timestamps in UTC time zone with JPA and Hibernate I want to set my application default time zone to UTC. My app runs on tomcat on a linux server along side some other apps. The server has other tomcat instances that run even more apps. Will Timezone.setDefault(tz) affect the other apps on the same tomcat instance? Will it affect other apps on other tomcat instances? Is it possible to set the timezone only for the app? I loosely remember something about security manager settings to allow this. The default timezone setting in java is kind of screwy. by

In NetBeans how do I change the Default JDK? [duplicate]

試著忘記壹切 提交于 2019-11-29 02:48:16
Possible Duplicate: Changing Java platform on which Netbeans runs Here is an image of my default JDK (which is 1.6) and the JDK I want to set as default (which is 1.7) http://tinypic.com/view.php?pic=35ldlye&s=5 Michael If I remember correctly, you'll need to set the netbeans_jdkhome property in your netbeans config file. Should be in your etc/netbeans.conf file. 来源: https://stackoverflow.com/questions/10146819/in-netbeans-how-do-i-change-the-default-jdk

How to disable the default context menu on a text field

一世执手 提交于 2019-11-29 02:27:59
By default the JavaFX TextField has a built in ContextMenu with 'undo', 'copy', 'cut' etc. options. The ComboBox also has the same ContextMenu when it is set as editable (the ComboBox is actually part of the editor which is a TextField ). I want to replace this ContextMenu with a custom one but I'm having a problem with disabling the default one. I have tried consuming the ContextMenu and mouse click events but ComboBox and ComboBox.getEditor() both have a null ContextMenu . Am I missing something? As you have already stated, a call to GetContextMenu() returns null (which is the big clue the

Rails: how to use scope with params and use route with default value of params

对着背影说爱祢 提交于 2019-11-29 00:56:38
问题 I have such lines in routes.rb: scope "/:subdomain/" do resource :order, :only => [:new, :create, :show, :update, :edit, :destroy] do get :cancel, :on => :member put :counter, :on => :member end end And for example, this is typical url: http://mydomain.com/some_subdomain/order/new . This url is mapped to action new of orders controller with params[:subdomain] = "some_subdomain". I want to use named route new_order_url(:subdomain => "some_subdomain"). But I want to map http://mydomain.com

Default parameters in C

早过忘川 提交于 2019-11-28 23:40:40
问题 Is it possible to set values for default parameters in C? For example: void display(int a, int b=10){ //do something } main(){ display(1); display(1,2); // override default value } Visual Studio 2008, complaints that there is a syntax error in -void display(int a, int b=10). If this is not legal in C, whats the alternative? Please let me know. Thanks. 回答1: Default parameters is a C++ feature. C has no default parameters. 回答2: It is not possible in standard C. One alternative is to encode the

Why is a C++ bool var true by default?

江枫思渺然 提交于 2019-11-28 23:21:58
bool "bar" is by default true, but it should be false, it can not be initiliazied in the constructor. is there a way to init it as false without making it static? Simplified version of the code: foo.h class Foo{ public: void Foo(); private: bool bar; } foo.c Foo::Foo() { if(bar) { doSomethink(); } } In fact, by default it's not initialized at all. The value you see is simply some trash values in the memory that have been used for allocation. If you want to set a default value, you'll have to ask for it in the constructor : class Foo{ public: Foo() : bar() {} // default bool value == false //

Method returning default browser as a String?

我的梦境 提交于 2019-11-28 23:18:49
Is there a method that will return a user's default browser as a String? Example of what I am looking for: System.out.println(getDefaultBrowser()); // prints "Chrome" You can accomplish this method by using registries [1] and regular expressions to extract the default browser as a string. There isn't a "cleaner" way to do this that I know of. public static String getDefaultBrowser() { try { // Get registry where we find the default browser Process process = Runtime.getRuntime().exec("REG QUERY HKEY_CLASSES_ROOT\\http\\shell\\open\\command"); Scanner kb = new Scanner(process.getInputStream());

mysql set field default value to other column

99封情书 提交于 2019-11-28 22:51:01
How to set default value for a field to other column in Mysql I have done it oracle with virtual field but I do not know how to do it in Mysql this is my table: create table TSM_TRANSACTION_TBL ( TRANS_ID INT primary key auto_increment, LOCATION_ID INT, TRANS_DATE DATE, RESOURCE_ID INT, TS_ID INT, MAX_VALUE INT, BOOKED_UNITS INT default 0, REMAINING INT default MAX_VALUE - BOOKED_UNITS, BOOKED INT not null, USER_ID INT, TRANS_TIME TIMESTAMP ) eggyal As documented under Data Type Default Values : The DEFAULT value clause in a data type specification indicates a default value for a column. With