GVKun编程网logo

使用cProfile时返回值(cp命令返回值)

13

对于想了解使用cProfile时返回值的读者,本文将是一篇不可错过的文章,我们将详细介绍cp命令返回值,并且为您提供关于/profiles/user-profile/UserProfile上的Dids

对于想了解使用cProfile时返回值的读者,本文将是一篇不可错过的文章,我们将详细介绍cp命令返回值,并且为您提供关于/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询、/etc/profile 和 ~/.profile 区别是全部用户,和单一用户、/etc/profile和~/.bash_profile等文件的区别和联系、asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型的有价值信息。

本文目录一览:

使用cProfile时返回值(cp命令返回值)

使用cProfile时返回值(cp命令返回值)

我正在尝试分析实例方法,所以我做了类似的事情:

import cProfileclass Test():    def __init__(self):        pass    def method(self):        cProfile.runctx("self.method_actual()", globals(), locals())    def method_actual(self):        print "Run"if __name__ == "__main__":    Test().method()

但是现在,当我希望“方法”返回由“ method_actual”计算出的值时,就会出现问题。我真的不想两次调用“ method_actual”。

还有另一种方法可以使线程安全吗?(在我的应用程序中,cProfile数据保存到以args之一命名的数据文件中,因此它们不会被破坏,以后我可以将它们组合起来。)

答案1

小编典典

我发现您可以执行以下操作:

prof = cProfile.Profile()retval = prof.runcall(self.method_actual, *args, **kwargs)prof.dump_stats(datafn)

缺点是它没有记录。

/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询

/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询

它将呈现末尾的空格。因此,模板应如下所示:

#                                                                 no space ↓
<input type='hidden' name='username' value="{% if username %}{{ username }}{% else %}{{ testuser }}{% endif %}">

/etc/profile 和 ~/.profile 区别是全部用户,和单一用户

/etc/profile 和 ~/.profile 区别是全部用户,和单一用户

bashrcprofile的区别
要搞清 bashrc profile 的区别,首先要弄明白什么是 交互式 shell 和非交互式 shell ,什么是 login shell non-login shell
交互式模式就是 shell 等待你的输入,并且执行你提交的命令。这种模式被称作交互式是因为 shell 与用户进行交互。这种模式也是大多数用户非常熟悉的:登录、执行一些命令、签退。当你签退后, shell 也终止了。 shell 也可以运行在另外一种模式:非交互式模式。在这种模式下, shell 不与你进行交互,而是读取存放在文件中的命令 , 并且执行它们。当它读到文件的结尾, shell 也就终止了。
bashrc profile 都用于保存用户的环境信息, bashrc 用于交互式 non-login shell ,而 profile 用于交互式 login shell 。系统中存在许多 bashrc profile 文件,下面逐一介绍:
/etc/pro 此文件为系统的每个用户设置环境信息 , 当第一个用户登录时 该文件被执行 .
并从 /etc/profile.d 目录的配置文件中搜集 shell 的设置 .
/etc/bashrc: 为每一个运行 bash shell 的用户执行此文件 . 被打开时 该文件被读取。有些 linux 版本中的 /etc 目录下已经没有了 文件。
~/. pro 每个用户都可使用该文件输入专用于自己使用的 信息 当用户登录时
文件仅仅执行一次 ! 默认情况下 它设置一些环境变量 然后执行用户的 .bashrc 文件 .
~/.bashrc: 该文件包含专用于某个用户的 bash 当该用户登录时以及每次打开新的 该文件被读取 .
另外 中设定的变量 ( 全局 ) 的可以作用于任何用户 ~/.bashrc 等中设定的变量 局部 只能继承 /etc/profile 中的变量 他们是 " 父子 关系 .



/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置.

英文描述为:

# /etc/profile

# System wide environment and startup programs,for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you kNow what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment,as this
# will prevent the need for merging in future updates.

所以如果你有对/etc/profile有修改的话必须得重启你的修改才会生效,此修改对每个用户都生效。

/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.

英文描述为:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you kNow what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment,as this
# will prevent the need for merging in future updates.

如果你想对所有的使用bash的用户修改某个配置并在以后打开的bash都生效的话可以修改这个文件,修改这个文件不用重启,重新打开一个bash即可生效。

~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.

此文件类似于/etc/profile,也是需要需要重启才会生效,/etc/profile对所有用户生效,~/.bash_profile只对当前用户生效。

~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该文件被读取.(每个用户都有一个.bashrc文件,在用户目录下)

此文件类似于/etc/bashrc,不需要重启生效,重新打开一个bash即可生效,/etc/bashrc对所有用户新打开的bash都生效,但~/.bashrc只对当前用户新打开的bash生效。

~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件.

另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系.

~/.bash_profile 是交互式、login 方式进入bash 运行的;
~/.bashrc是交互式 non-login 方式进入bash 运行的; 通常二者设置大致相同,所以通常前者会调用后者。

/etc/profile和~/.bash_profile等文件的区别和联系

/etc/profile和~/.bash_profile等文件的区别和联系

对比说明:
/etc/profile:为系统的每个用户设置环境信息和启动程序,当用户第一次登录时,该文件被执行,其配置对所有登录的用户都有效。当被修改时,必须重启才会生效。英文描述:”System wide environment and startup programs, for login setup.”

/etc/environment:系统的环境变量,/etc/profile是所有用户的环境变量,前者与登录用户无关,后者与登录用户有关,当同一变量在两个文件里有冲突时,以用户环境为准。

/etc/bashrc:为每个运行 bash shell 的用户执行该文件,当 bash shell 打开时,该文件被执行,其配置对所有使用bash的用户打开的每个bash都有效。当被修改后,不用重启只需要打开一个新的 bash 即可生效。英文描述:”System wide functions and aliases.”

~/.bash_profile:为当前用户设置专属的环境信息和启动程序,当用户登录时该文件执行一次。默认情况下,它用于设置环境变量,并执行当前用户的 .bashrc 文件。理念类似于 /etc/profile,只不过只对当前用户有效,也需要重启才能生效。(注意:Centos7系统命名为.bash_profile,其他系统可能是.bash_login或.profile。)

~/.bashrc:为当前用户设置专属的 bash 信息,当每次打开新的shell时,该文件被执行。理念类似于/etc/bashrc,只不过只对当前用户有效,不需要重启只需要打开新的shell即可生效。

~/.bash_logout:为当前用户,每次退出bash shell时执行该文件,可以把一些清理工作的命令放进这个文件。

/etc/profile.d/:此文件夹里是除/etc/profile之外其他的”application-specific startup files”。英文描述为”The /etc/profile file sets the environment variables at startup of the Bash shell. The /etc/profile.d directory contains other scripts that contain application-specific startup files, which are also executed at startup time by the shell.” 同时,这些文件”are loaded via /etc/profile which makes them a part of the bash “profile” in the same way anyway.” 因此可以简单的理解为是/etc/profile的一部分,只不过按类别或功能拆分成若干个文件进行配置了(方便维护和理解)。

注意事项
以上需要重启才能生效的文件,其实可以通过source xxx暂时生效。

文件的执行顺序为:当登录Linux时,首先启动/etc/environment和/etc/profile,然后启动当前用户目录下的~/.bash_profile,执行此文件时一般会调用~/.bashrc文件,而执行~/.bashrc时一般会调用/etc/bashrc,最后退出shell时,执行~/.bash_logout。简单来说顺序为:

登录时)/etc/environment –> /etc/profile(以及/etc/profile.d/里的文件) –> ~/.bash_profile –> (打开shell时)~/.bashrc –> /etc/bashrc –> (退出shell时)~/.bash_logout
————————————————
版权声明:本文为CSDN博主「siberiawolf61」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010048823/article/details/51871825

asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型

asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型

我看到这个错误:

无法将类型为“System.Web.Profile.DefaultProfile”的对象强制转换为“ProfileCommon”.

在以下代码:

ProfileCommon p =(ProfileCommon)ProfileCommon.Create(TextUsername.Text,true);

我不确定为什么……

解决方法

同意theChrisKent.它看起来像web.config中的问题

查看以下示例,如何在asp.net中获取ProfileCommon对象

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="GetProfile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        User Name:<asp:TextBox ID="txtUserName" runat="server"/>
        <asp:Button ID="cmdGet" runat="server" OnClick="cmdGet_Click" Text="Get Profile" /><br />
        <asp:Label ID="lbl" runat="server" Text=""/>
    </div>
    </form>
</body>
</html>

文件:Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GetProfile : System.Web.UI.Page
{
  protected void cmdGet_Click(object sender,EventArgs e)
  {
    ProfileCommon profile = Profile.GetProfile(txtUserName.Text);
        if (profile.LastUpdatedDate == DateTime.MinValue)
        {
            lbl.Text = "No user match found.";
        }
        else
        {
            lbl.Text = "This user lives in " + profile.FirstName;
        }
  }
}

文件:Web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <profile>
      <properties>
        <add name="FirstName" type="String" serializeAs="Binary"/>
        <add name="LastName" type="String" serializeAs="Xml"/>
        <add name="DateOfBirth" type="DateTime" serializeAs="String"/>
      </properties>
    </profile>
  </system.web>
</configuration>

编辑

此示例仅在项目类型为website时才有效.如果要在Web应用程序中使用ProfileCommon对象,请通过以下链接

Converting Profile Object Code

编辑-II

根据您的评论,以下链接可能会对您有所帮助

ASP.NET Profiles in Web Application Projects

关于使用cProfile时返回值cp命令返回值的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询、/etc/profile 和 ~/.profile 区别是全部用户,和单一用户、/etc/profile和~/.bash_profile等文件的区别和联系、asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型的相关信息,请在本站寻找。

本文标签: