这些os.popen调用有什么区别?

时间:2016-07-23 07:44:50

标签: python

我有两个脚本:

第一个效果很好:

  //Get Method

public ActionResult Add()
{
 PopulateDivisionDropDownList();
 return View();
}  

//Post Method
[httpPost]
[ValidateAntiForgeryToken]
 public ActionResult Add([Bind(Include = "ID,Code,Name,Department,CreatedDateandTime")] DivisionViewModel divisionViewModel)
{


        if (ModelState.IsValid)
        {
            db.DivisionViewModels.Add(divisionViewModel);
            db.SaveChanges();
            return RedirectToAction("List");
        }

        //below line for finder
        ViewBag.Name = new SelectList(db.DivisionViewModels, "ID", "Name", divisionViewModel.Name);
        PopulateDivisionDropDownList(divisionViewModel.ID);
        db.SaveChanges();            
        return View(divisionViewModel);
     }
    //below method for finder
    private void PopulateDivisionDropDownList(object selectedDepartment = null)
    {
        var departmentquery = from dept in db.DepartmentViewModels
                           orderby dept.Name
                           select dept;
        db.SaveChanges();
        ViewBag.ID = new SelectList(departmentquery, "ID", "Name", selectedDepartment);
        //db.SaveChanges();
    }

第二个不起作用:

import os
os.popen(‘grep abc filename’)

但这样做:

import os
os.popen(‘grep abc’ + ’filename’)

所以,我无法理解其中的区别。第二个版本有什么问题?

1 个答案:

答案 0 :(得分:1)

您忘记了第二个版本中abc之后的空格。它应该是

import os
os.popen(‘grep abc ’ + ’filename’)

即。 abc˽' vs abc'