default

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

ε祈祈猫儿з 提交于 2019-12-05 08:28:37
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 stored in the variable "url" into my browser, there is a default filename given to the file when I

How do I change default directory and index file for Apache (installed via XAMPP) [closed]

江枫思渺然 提交于 2019-12-05 07:45:33
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . How do I change default Directory and index File for Apache (installed via XAMPP) so instead of looking for htdocs and index , it looks for myPath and myFile , respectively? The research link you pasted has the first part of the answer to your question, changing the path you want serve but the second part of your question, making it serve "myFile" as the Index is an additional step. See: http://httpd.apache.org

.NET Default Properties Error [duplicate]

ぐ巨炮叔叔 提交于 2019-12-05 06:22:54
This question already has an answer here: Why can I access an item in KeyCollection/ValueCollection by index even if it doesn't implement IList(Of Key)? 2 answers I have a VB.NET project where I am able to iterate through the keys and values collections of a dictionary object using an index: MyDictionary.Keys(idx) MyDictionary.Values(idx) When this code is taken from the test project and placed into the real project I get the following error: 'System.Collections.Generic.Dictionary(Of Double, String).KeyCollection' cannot be indexed because it has no default property. and 'System.Collections

Scala HashMap of Lists: simpler default?

限于喜欢 提交于 2019-12-05 06:05:54
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! Tomasz Nurkiewicz What about withDefaultValue() ? val lists = new mutable.HashMap[String,List[Int]].withDefaultValue(Nil) lists("dog") ::= 13

Jquery Validate: How To Ignore Placeholder Text (Produce Error on Default/Blank)

丶灬走出姿态 提交于 2019-12-05 05:53:41
问题 I'd like to make jquery validate ignore the default text. The way I have it check for default text is to check if the element.value == the elements alt text Here's my code, but it returns invalid no matter if its blank, default text, or any other text: $.validator.addMethod("notDefaultText", function(value) { if($(this).val()==$(this).attr('alt')) return false; }); rules: { Name: "required notDefaultText", Email: "required notDefaultText email" }, 回答1: I had the same problem and solved it

How to set up Umbraco to default in a subpage?

二次信任 提交于 2019-12-05 05:36:38
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 a rule that does that. Tried inserting a rewrite/redirect rule and it didn't change anything. Please

Symfony2 - Set default value in entity constructor

混江龙づ霸主 提交于 2019-12-05 05:27:00
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? I think you're better to set it inside a PrePersist event. In User.php : use Doctrine\ORM\Mapping as ORM; /** * .. * @ORM

Why must default method parameters be compile-time constants in C# [closed]

我是研究僧i 提交于 2019-12-05 04:11:44
EDIT 1: I know there are alternatives such as telescoping, this was a purely educational question. I know that this is true, but why must it be? It seems like with something like this: public class Foo{ private int bar; public void SetBar(int baz = ThatOtherClass.GetBaz(3)){ this.bar = baz; } } The compiler could change the method to something like this: public void SetBar(int baz){ //if baz wasn't passed: baz = ThatOtherClass.GetBaz(3); this.bar = baz; } Why wouldn't that work, or would it, and it's just a design decision? Because the spec says so: A fixed-parameter with a default-argument is

How to create a default method in SpringMVC using annotations?

夙愿已清 提交于 2019-12-05 03:28:33
I can't find a solution to this, and it's driving me crazy. I have @Controller mapped that responds to several methods using @RequestMapping. I'd like to tag one of those methods as default when nothing more specific is specified. For example: @Controller @RequestMapping("/user/*") public class UserController { @RequestMapping("login") public String login( MapModel model ) {} @RequestMapping("logout") public String logout( MapModel model ) {} @RequestMapping("authenticate") public String authenticate( MapModel model ) {} } So /user/login -> login method, /user/logout -> logout, etc. I'd like

Django model field default from model method

安稳与你 提交于 2019-12-05 02:35:22
I want to give a model field default value from the a model method. How can i do that ? when i try this code Class Person(models.Model): def create_id(self): return os.urandom(12).encode('hex') name = models.CharField(max_length = 255) id = models.CharField(max_length = 255,default = self.create_id) I get NameError: name 'self' is not defined. If i remove the 'self' i get that 'create_id' needs 1 parameter. You can define global method like this: def create_id(): return os.urandom(12).encode('hex') Class Person(models.Model): name = models.CharField(max_length = 255) id = models.CharField(max