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>
}

相关问答

更多

ASP.NET AJAX与ASP.NET MVC中的jQuery(ASP.NET AJAX vs jQuery in ASP.NET MVC)

我个人更喜欢jQuery,原因如下: - 插件社区更加多样化,吸引了广泛背景的开发人员(而不仅仅是MS堆栈)。 对于MS-AJAX,你现在几乎受限于客户端的用于UI小部件的AJAX控件工具包。 我发现jQuery API远比MS AJAX提供的更适用于常见的客户端任务 鉴于缺乏WebForms MVC中的烟雾和镜像,您有时需要对DOM进行严格的控制才能做某些事情,jQuery提供的CSS选择器引擎确实可以帮助您做到这一点。 就MS AJAX在MVC中提供的内容而言,它可以为您提供一种快速“AJAX...

在ASP.Net MVC中,ModelState可以与ajax更新一起使用吗?(In ASP.Net MVC, can ModelState be used with an ajax update?)

如果我理解你正在尝试做的事情,我的第一个答案将是否定的,你不能使用模型状态,因为它是通过和Ajax请求。 也许你可以模拟ModelState行为,以显示错误: 通过JSON传递List<KeyValuePair<string,string>> (属性,消息)(这将要求您将modelErrors从modelState传递到新结构),并通过JS / jQuery完成Validation Summary的HTML构造我认为是杀死解决方案)。 如果您要访问服务器,并且出现任何错误,只需执行Html.Val...

如何在ASP.NET MVC中制作更新面板(How to make update panel in ASP.NET MVC)

您可以在ASP.NET MVC中使用部分视图来获取类似的行为。 部分视图仍然可以在服务器上构建HTML,您只需要将HTML插入适当的位置(实际上,如果您愿意包含MSFT Ajax库,则MVC Ajax帮助者可以为您设置此选项)。 在主视图中,您可以使用Ajax.Begin窗体来设置异步请求。 <% using (Ajax.BeginForm("Index", "Movie", new AjaxOptions { ...

如何在Asp.net MVC 4中使用简单的Ajax Beginform?(How to use Simple Ajax Beginform in Asp.net MVC 4? [closed])

简单示例:带有文本框和搜索按钮的表单。 如果您将“名称”写入textbox并提交表单,那么将为患者带来“名称”。 视图: @using (Ajax.BeginForm("GetPatients", "Patient", new AjaxOptions {//GetPatients is name of method in PatientController InsertionMode = InsertionMode.Replace, //target element(#patientLis...

ASP.NET MVC AJAX操作模型(ASP.NET MVC AJAX manipulating model)

不要在模型中存储ALL标签列表,只需存储已选择的列表。 将该模型绑定到您的视图。 使用表示标记的字符串参数向控制器添加post方法。 做一些逻辑。 然后将javascript或jquery ajax调用写入该方法,在该方法中传入标记的名称。 如果您的视图需要更新,则可能需要使用ajax调用替换html。 或者你可以通过常规帖子完成所有这些。 这取决于您的需求。 Instead of storing a list of ALL tags in your model, just store a lis...

在asp.net MVC 3中简单的Ajax,更新模型并重新渲染部分(Simple Ajax in asp.net MVC 3, update the model and rerender part)

这是一个完整的例子。 模型: public class MyViewModel { public int Year { get; set; } public IEnumerable<SelectListItem> Years { get { return Enumerable.Range(1980, 40).Select(x => new SelectListItem { ...

在asp.net mvc中使用ajax进行更新(Update using ajax in asp.net mvc)

嗯,最明显的问题是,您是否已将脚本添加到您尝试执行此操作的页面中? 其次,如果您要发布到HTTPS(您是,对吗?),您的脚本也必须是HTTPS,否则您将收到安全错误。 This post helped me: http://weblogs.asp.net/owscott/archive/2010/11/17/mvc-3-ajax-redirecting-instead-of-updating-div.aspx

使用Ajax的ASP.net MVC(ASP.net MVC with Ajax)

斯蒂芬沃尔特刚刚在博客上写了这篇文章: 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...

如何在asp.net mvc中使用Ajax更新View?(How to update View using Ajax in asp.net mvc?)

正如Stephen Muecke所说,您应该在View中更改控制器以传递模型并显示它: 控制器: public PartialViewResult GetExhibitorDataById(int? Id) { List<Exhibitor> exhibitors = new List<Exhibitor>() { new Exhibitor() { Id=1, ...

模型没有用asp.net mvc中的ajax帖子更新?(Model is not updated with ajax post in asp.net mvc?)

当您发布时,您只发送单个ID而不是整个模型,所以基本上这个 public ActionResult Button(MasterM model) will be empty 并且由于您返回空集,因此不会更新文本框。 您可以在此处执行以下操作:1)将接收类型修改为 Public ActionResult Button(int Id) { MasterM model = new MasterM(); model.Id = Id; if (!ModelState...

相关文章

更多

顶 Hadoop、Pig、Hive、Storm、NOSQL 学习资源收集【Updating】

(一)hadoop 相关安装部署 1、hadoop在windows cygwin下的部署: ht ...

fw:Hadoop、Pig、Hive、Storm、NOSQL 学习资源收集【Updating】

转自:http://m.oschina.net/blog/81771 Hadoop、Pig、Hive、 ...

探索 Python,第 1 部分: Python 的内置数值类型

Python 编程语言具有很高的灵活性,它支持多种编程方法,包括过程化的、面向对象的和函数式的。但最重 ...

Python资源索引 【转载】

原文地址:http://blog.chinaunix.net/uid-25525723-id-3630 ...

python下载pps视频

思路 视频播放地址提取 直接解析一下原网页的源文件,利用正则就可以得到所有视频的播放地址,下面的 ...

python字典操作

python里的字典就像java里的HashMap,以键值对的方式存在并操作,其特点如下:通过键来存取 ...

python top project of 2013

Hi Pythonistas! 测试和调试 Testing &amp; Debuggi ...

Mod_python: The Long Story

mod_python: the long story - Grisha Trubetskoy ...

【转帖】Python 资源索引

原文地址:http://wiki.woodpecker.org.cn/moin/ObpLovelyPy ...

(转)Python WEB应用框架纵览

原文链接:http://wiki.woodpecker.org.cn/moin/PyWebFrameL ...

最新问答

更多

python的访问器方法有哪些

使用方法: class A(object): def foo(self,x): #类实例方法 print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): #类方法 print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): #静态方法 print "executing static_foo(%s)"%x调用方法: a =

使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)

我认为你必须将两个TableGetway传递给UserTable构造。 你必须改变Module.php看看: public function getServiceConfig() { return array( 'factories' => array( 'User\Model\UserTable' => function($sm) { $userTableGateway = $sm->get('UserTable

透明度错误IE11(Transparency bug IE11)

这是一个渲染错误,由使用透明度触发,使用bootstrap用于在聚焦控件周围放置蓝色光环的box-shadow属性。 可以通过添加以下类覆盖来解决它。 .form-control:hover { -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); box-shadow: 0px 0px 4px 0px rgba(0,0,255,1)

linux的基本操作命令。。。

ls 显示目录 mkdir 建立目录 cd 进入目录

响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)

将z-index设置为.main-nav这将解决您的重叠问题 .main-nav { position:relative; z-index:9; } set z-index to .main-nav This will fix your overlaping issue .main-nav { position:relative; z-index:9; }

在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)

这是因为模式规范"a"打开一个文件以便追加,文件指针在末尾。 如果您尝试从此处读取,则由于文件指针位于EOF,因此没有数据。 您应该打开"r+"进行阅读和写作。 如果在写入之前读取整个文件,则在写入更多数据时,文件指针将正确定位以追加。 如果这还不够,请探索ftell()和fseek()函数。 That is because the mode spec "a" opens a file for appending, with the file pointer at the end. If you

NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)

支持空中接口的数据速率是一回事。 在消除协议开销,等待eeprom写入以及所有需要时间的其他内容之后,您看到的数据速率是完全不同的故事。 长话短说,从标签读取或进行对等传输时的实际数据速率峰值约为2.5千字节/秒。 取决于具体的标签或对等技术,它可能比这慢很多。 The supported data-rates of the air-interface are one thing. The data-rate that you see after removing protocol overhe

元素上的盒子阴影行为(box-shadow behaviour on elements)

它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂

Laravel检查是否存在记录(Laravel Checking If a Record Exists)

这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found

设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)

$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640