default

Using urllib2 in Python. How do I get the name of the file I am downloading?

浪尽此生 提交于 2019-12-07 05:51:42
问题 I am a python beginner. I am using urllib2 to download files. When I download a file, I specify a filename to with which to save the downloaded file on my hard drive. However, if I download the file using my browser, a default filename is automatically provided. Here is a simplified version of my code: def downloadmp3(url): webFile = urllib2.urlopen(url) filename = 'temp.zip' localFile = open(filename, 'w') localFile.write(webFile.read()) The file downloads just fine, but if I type the string

JavaScript default parameters for function

a 夏天 提交于 2019-12-07 05:21:15
问题 I can fully understand ECMAScript 6 has created a lot of potential way of handling with functions such as arrow functions. Since I'm not very familiar with the new stuff, when talking about default parameters for a function. How to interpret the differences between the following way of defining functions: Function 1: function m1({x = 0, y = 0} = {}) { return [x, y]; } Function 2: function m2({x, y} = { x: 0, y: 0 }) { return [x, y]; } 回答1: The difference is clear when you try passing

How to set default value while insert null value into not null column SQL Server?

时光怂恿深爱的人放手 提交于 2019-12-07 04:47:12
问题 I have two tables t1 and t2 . Both have id and name columns. The name column of t1 is defined as not null and it has the default value of 'Peter'. I want to insert all the values from t2 into my t1 table. But I have some null values in t2 table. When I try to insert the values: Insert into t1 select * from t2; It throws this error: Msg 515, Level 16, State 2, Line 1 Cannot insert the value NULL into column 'Name', table 'T1'; column does not allow nulls. Is there any possibilities to set the

Class based default value for field in Django model inheritance hierarchy

自闭症网瘾萝莉.ら 提交于 2019-12-07 04:29:39
问题 How can one accomplish class-based default value in following scheme? I mean, I would like to inherited classes set default value for "number" differently: class OrderDocumentBase(PdfPrintable): number = models.PositiveIntegerField(default=self.create_number()) @classmethod def create_number(cls): raise NotImplementedError class Invoice(OrderDocumentBase): @classmethod def create_number(cls): return 1 class CreditAdvice(OrderDocumentBase): @classmethod def create_number(cls): return 2 I have

Cross-platform configuration, options, settings, preferences, defaults

一世执手 提交于 2019-12-07 03:14:55
问题 I'm interested in peoples' views on how best to store preferences and default settings in cross-platform applications. I primarily work in node.js and Perl on *nix and Windows but I'm also interested in the bigger picture. In the *nix world "dotfiles" (and directories) are very common with system-wide or application default settings generally residing in one path and user-specific settings in the home directory. Such files and dirs begin with a dot "." and are hidden by default from directory

Scala HashMap of Lists: simpler default?

陌路散爱 提交于 2019-12-07 03:13:16
问题 I need a HashMap of Lists. Normally I do this: val lists = mutable.HashMap[String,List[Int]]() { override def default(key: String) = { val newList = List[Int]() this(key) = newList newList } } so that I can then simply write things like lists("dog") ::= 14 without having to worry about whether the "dog" List has been initialised yet. Is there a cleaner way to do this? I find myself typing out those five default override lines again and again. Thanks! 回答1: What about withDefaultValue() ? val

Symfony2 - Set default value in entity constructor

耗尽温柔 提交于 2019-12-07 01:43:58
问题 I can set a simple default value such as a string or boolean, but I can't find how to set the defualt for an entity. In my User.php Entity: /** * @ORM\ManyToOne(targetEntity="Acme\DemoBundle\Entity\Foo") */ protected $foo; In the constructor I need to set a default for $foo: public function __construct() { parent::__construct(); $this->foo = 1; // set id to 1 } A Foo object is expected and this passes an integer. What is the proper way to set a default entity id? 回答1: I think you're better to

How to set up Umbraco to default in a subpage?

雨燕双飞 提交于 2019-12-07 01:42:35
问题 I have this question about umbraco structuring and I can't find the answer anywhere. Typically in Umbraco it will default the root site to the first node of the tree. so if we have Home page 1 page 2 the default page will be home (so www.mysite.com will point to home). How do I change this however so that www.mysite.com will point to page1 or page2? What if I have this structure? wrapper index page 1 page 2 and I want www.mysite.com to go straight to www.mysite.com/index.aspx I couldn't find

Default Printer in Unmanaged C++

一曲冷凌霜 提交于 2019-12-07 00:38:33
I'm looking for a way to find the name of the Windows default printer using unmanaged C++ (found plenty of .NET examples, but no success unmanaged). Thanks. Doug T. The following works great for printing with the win32api from C++ char szPrinterName[255]; unsigned long lPrinterNameLength; GetDefaultPrinter( szPrinterName, &lPrinterNameLength ); HDC hPrinterDC; hPrinterDC = CreateDC("WINSPOOL\0", szPrinterName, NULL, NULL); In the future instead of googling "unmanaged" try googling "win32 /subject/" or "win32 api /subject/" Here is how to get a list of current printers and the default one if

Change default package from com.example for Eclipse Android projects

佐手、 提交于 2019-12-06 18:40:27
问题 I am using Eclipse 4.2 with Android SDK. I am wondering if it is possible to change the default package ID com.example that shows in the "New Android Application" wizard as you type the application name? I would like it to default to my own package ID so that I don't need to correct the Package Name field each time. Is this possible to do? Please explain how. 回答1: No, you cannot change the default; it's hardcoded in the plugin sources. (For the curious, it's in com.android.ide.eclipse.adt