首页 \ 问答 \ emacs和python更新模块(emacs and python updating modules)

emacs和python更新模块(emacs and python updating modules)

atm我正在使用emacs编写一些python代码,到目前为止它工作得很好,除了一个真的有点烦人的问题。

总是当我在自编写模块中更新内容时,我重新评估缓冲区并且emacs内部的python shell中的模块不会更新。 我总是必须结束python进程并再次启动它以获得更改。 我发现emacs将一些东西复制到tmp目录来执行它们,所以我猜它与此有关。

也许有人在那里有同样的问题,并已解决它,所以帮助将不胜感激


atm i'm using emacs to write some python code, so far it works quite fine except one problem that is really a bit annoying.

Always when I update something inside a self written module i reevaluate the buffer and the module in the python shell inside emacs doesn't get updated. i always have to end the python process and start it again to get the change. I figured out that emacs copies some things to a tmp dir to execute them, so i guess it has something to do with this.

Maybe someone out there had the same problem and solved it already so help would be appreciated


原文:https://stackoverflow.com/questions/6942627
更新时间:2024-04-22 16:04

最满意答案

这是一个完整的例子。

模型:

public class MyViewModel
{
    public int Year { get; set; }
    public IEnumerable<SelectListItem> Years
    {
        get
        {
            return Enumerable.Range(1980, 40).Select(x => new SelectListItem
            {
                Value = x.ToString(),
                Text = x.ToString()
            });
        }
    }

    public IList<TheData> Data { get; set; }
}

public class TheData
{
    public int Year { get; set; }
    public string Foo { get; set; }
    public string Bar { get; set; }
}

控制器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        var model = new MyViewModel();
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(int year)
    {
        var model = new[]
        {
            new TheData { Year = year, Foo = "foo 1", Bar = "bar 1" },
            new TheData { Year = year, Foo = "foo 2", Bar = "bar 2" },
            new TheData { Year = year, Foo = "foo 3", Bar = "bar 3" },
        };
        return PartialView("_data", model);
    }
}

Index.cshtml查看:

@model MyViewModel

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('#yearsddl').change(function () {
            $(this).closest('form').trigger('submit');
        });
    });
</script>

@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "data" }))
{
    @Html.DropDownListFor(x => x.Year, Model.Years, new { id = "yearsddl" })
}

<table>
    <thead>
        <tr>
            <th>Year</th>
            <th>Foo</th>
            <th>Bar</th>
        </tr>
    </thead>
    <tbody id="data">
        @Html.Partial("_data", Model.Data ?? Enumerable.Empty<TheData>())
    </tbody>
</table>

例如, jquery.unobtrusive-ajax.js脚本包含移出布局中的索引视图,并且订阅下拉列表更改事件的自定义js应移至单独的js文件中,并从布​​局中包含。 我只是把它们放在这里来说明视图工作所需的完整示例。

_Data.cshtml部分:

@model IList<TheData>

@for (int i = 0; i < Model.Count; i++)
{
    <tr>
        <td>@Html.DisplayFor(x => x[i].Year)</td>
        <td>@Html.DisplayFor(x => x[i].Foo)</td>
        <td>@Html.DisplayFor(x => x[i].Bar)</td>
    </tr>
}

Here's a full example.

Model:

public class MyViewModel
{
    public int Year { get; set; }
    public IEnumerable<SelectListItem> Years
    {
        get
        {
            return Enumerable.Range(1980, 40).Select(x => new SelectListItem
            {
                Value = x.ToString(),
                Text = x.ToString()
            });
        }
    }

    public IList<TheData> Data { get; set; }
}

public class TheData
{
    public int Year { get; set; }
    public string Foo { get; set; }
    public string Bar { get; set; }
}

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        var model = new MyViewModel();
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(int year)
    {
        var model = new[]
        {
            new TheData { Year = year, Foo = "foo 1", Bar = "bar 1" },
            new TheData { Year = year, Foo = "foo 2", Bar = "bar 2" },
            new TheData { Year = year, Foo = "foo 3", Bar = "bar 3" },
        };
        return PartialView("_data", model);
    }
}

Index.cshtml view:

@model MyViewModel

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('#yearsddl').change(function () {
            $(this).closest('form').trigger('submit');
        });
    });
</script>

@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "data" }))
{
    @Html.DropDownListFor(x => x.Year, Model.Years, new { id = "yearsddl" })
}

<table>
    <thead>
        <tr>
            <th>Year</th>
            <th>Foo</th>
            <th>Bar</th>
        </tr>
    </thead>
    <tbody id="data">
        @Html.Partial("_data", Model.Data ?? Enumerable.Empty<TheData>())
    </tbody>
</table>

The jquery.unobtrusive-ajax.js script inclusion should be moved out of the index view inside the layout for example and the custom js that subscribes for the change event of the dropdownlist should be moved into a separate js file and included from the Layout. I just put them here to illustrate a full example of what's required for the view to work.

_Data.cshtml partial:

@model IList<TheData>

@for (int i = 0; i < Model.Count; i++)
{
    <tr>
        <td>@Html.DisplayFor(x => x[i].Year)</td>
        <td>@Html.DisplayFor(x => x[i].Foo)</td>
        <td>@Html.DisplayFor(x => x[i].Bar)</td>
    </tr>
}

相关问答

更多
  • 我个人更喜欢jQuery,原因如下: - 插件社区更加多样化,吸引了广泛背景的开发人员(而不仅仅是MS堆栈)。 对于MS-AJAX,你现在几乎受限于客户端的用于UI小部件的AJAX控件工具包。 我发现jQuery API远比MS AJAX提供的更适用于常见的客户端任务 鉴于缺乏WebForms MVC中的烟雾和镜像,您有时需要对DOM进行严格的控制才能做某些事情,jQuery提供的CSS选择器引擎确实可以帮助您做到这一点。 就MS AJAX在MVC中提供的内容而言,它可以为您提供一种快速“AJAXify”表 ...
  • 如果我理解你正在尝试做的事情,我的第一个答案将是否定的,你不能使用模型状态,因为它是通过和Ajax请求。 也许你可以模拟ModelState行为,以显示错误: 通过JSON传递List> (属性,消息)(这将要求您将modelErrors从modelState传递到新结构),并通过JS / jQuery完成Validation Summary的HTML构造我认为是杀死解决方案)。 如果您要访问服务器,并且出现任何错误,只需执行Html.Validati ...
  • 您可以在ASP.NET MVC中使用部分视图来获取类似的行为。 部分视图仍然可以在服务器上构建HTML,您只需要将HTML插入适当的位置(实际上,如果您愿意包含MSFT Ajax库,则MVC Ajax帮助者可以为您设置此选项)。 在主视图中,您可以使用Ajax.Begin窗体来设置异步请求。 <% using (Ajax.BeginForm("Index", "Movie", new AjaxOptions { ...
  • 简单示例:带有文本框和搜索按钮的表单。 如果您将“名称”写入textbox并提交表单,那么将为患者带来“名称”。 视图: @using (Ajax.BeginForm("GetPatients", "Patient", new AjaxOptions {//GetPatients is name of method in PatientController InsertionMode = InsertionMode.Replace, //target element(#patientList) wi ...
  • 不要在模型中存储ALL标签列表,只需存储已选择的列表。 将该模型绑定到您的视图。 使用表示标记的字符串参数向控制器添加post方法。 做一些逻辑。 然后将javascript或jquery ajax调用写入该方法,在该方法中传入标记的名称。 如果您的视图需要更新,则可能需要使用ajax调用替换html。 或者你可以通过常规帖子完成所有这些。 这取决于您的需求。 Instead of storing a list of ALL tags in your model, just store a list of ...
  • 这是一个完整的例子。 模型: public class MyViewModel { public int Year { get; set; } public IEnumerable Years { get { return Enumerable.Range(1980, 40).Select(x => new SelectListItem { ...
  • 嗯,最明显的问题是,您是否已将脚本添加到您尝试执行此操作的页面中? 其次,如果您要发布到HTTPS(您是,对吗?),您的脚本也必须是HTTPS,否则您将收到安全错误。 This post helped me: http://weblogs.asp.net/owscott/archive/2010/11/17/mvc-3-ajax-redirecting-instead-of-updating-div.aspx
  • 斯蒂芬沃尔特刚刚在博客上写了这篇文章: http : //weblogs.asp.net/stephenwalther/archive/2008/09/22/asp-net-mvc-application-building-forums-6-ajax.aspx Stephen Walter just blogged about this: http://weblogs.asp.net/stephenwalther/archive/2008/09/22/asp-net-mvc-application-buil ...
  • 正如Stephen Muecke所说,您应该在View中更改控制器以传递模型并显示它: 控制器: public PartialViewResult GetExhibitorDataById(int? Id) { List exhibitors = new List() { new Exhibitor() { Id=1, ...
  • 当您发布时,您只发送单个ID而不是整个模型,所以基本上这个 public ActionResult Button(MasterM model) will be empty 并且由于您返回空集,因此不会更新文本框。 您可以在此处执行以下操作:1)将接收类型修改为 Public ActionResult Button(int Id) { MasterM model = new MasterM(); model.Id = Id; if (!ModelState.IsVa ...

相关文章

更多

最新问答

更多
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 高考完可以去做些什么?注意什么?
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 怎么在《我的世界》游戏里面编程
  • .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
  • 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
  • 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
  • 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
  • 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
  • 如何使用变量值创建参数类(How to create a parameter class with variant value)
  • 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
  • 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
  • rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
  • 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
  • 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
  • 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
  • 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
  • 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
  • Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
  • 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
  • 函数调用可以重新排序(Can function calls be reordered)
  • 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
  • 如何解释SBT错误消息(How to interpret SBT error messages)
  • 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)