使用变量作为函数名和字符串

时间:2020-03-02 21:25:49

标签: python string variables

我有以下代码

Private ROW_SHAPE As Shape
Private COLUMN_SHAPE As Shape
Private Sub AddShapes(ByVal Sh As Object)
    VisibleRangeHeight = ActiveWindow.ActivePane.VisibleRange.Height
    VisibleRangeWidth = ActiveWindow.ActivePane.VisibleRange.Width
    SelectedCellHeight = Selection.Height
    SelectedCellWidth = Selection.Width
    If SelectedCellHeight > VisibleRangeHeight Then
        SelectedCellHeight = VisibleRangeHeight
    End If
    If SelectedCellWidth > VisibleRangeWidth Then
        SelectedCellWidth = VisibleRangeWidth
    End If
    CellPosLeft = Selection.Left
    CellPosTop = Selection.Top
    Set ROW_SHAPE = Sh.Shapes.AddShape(msoShapeRectangle, 1, CellPosTop, _
        VisibleRangeWidth + CellPosLeft, SelectedCellHeight)
    With ROW_SHAPE
        .Name = "row_shape"
        .Line.ForeColor.RGB = RGB(255, 0, 0)
        .Fill.Visible = msoFalse
        With .Shadow
           .Visible = True
           .Blur = 4
           .OffsetX = 1
           .OffsetY = 1
           .ForeColor.RGB = RGB(255, 0, 0)
        End With
    End With
    Set COLUMN_SHAPE = Sh.Shapes.AddShape(msoShapeRectangle, CellPosLeft, 1, _
        SelectedCellWidth, VisibleRangeHeight + CellPosTop)
    With COLUMN_SHAPE
        .Name = "column_shape"
        .Line.ForeColor.RGB = RGB(255, 0, 0)
        .Fill.Visible = msoFalse
        With .Shadow
           .Visible = True
           .Blur = 4
           .OffsetX = 1
           .OffsetY = 1
           .ForeColor.RGB = RGB(255, 0, 0)
        End With
    End With
End Sub

在调用MyCompute函数时是否有避免双RS和双BS的方法?

4 个答案:

答案 0 :(得分:7)

使用属性def MyCompute(srt): df[srt.__name__] = srt() df['1min' + srt.__name__] = 1 - df[srt.__name__] MyCompute(srt=RS) MyCompute(srt=BS)

def MyCompute(srt):
    df[srt.__name__] = srt()
    df['1min' + srt.__name__] = 1-df[srt.__name__]

MyCompute(srt=RS)
MyCompute(srt=BS)

答案 1 :(得分:1)

将函数放入字典中,然后可以按名称查找函数。


    function _setTab(){
        // get current hash value
        var curHash = window.location.hash.substr(1);
        // only continue if hash provided and scoped to member tabs
        if( !curHash || !curHash.match('member-tabs') ){ return false; }

        // split and int val tab num
        curHash = parseInt(curHash.split('|')[1]);

        // ignore if tab is current state
        if( curHash === window._tabSelected ){ return false; }
        // set current tab to window
        window._tabSelected = curHash;

        // add click event to tab selected
        switch(curHash){
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
                jQuery('#member-tabs .et_pb_tab_'+curHash+' a').click();
            break;

            default:
                return false;
            break;
        }

        // scroll to tabs container
        _scrollToTabs();
    }

    // scroll to member tabs container with 50px offset
    function _scrollToTabs(){
        var oTabs = jQuery('#member-tabs');
        if( oTabs.length > 0 ){
            jQuery('html,body').animate({
                scrollTop: (oTabs.offset().top - 50)
            }, 1000);
        }
        return false;
    }

    // set falsey state for tab selected on load
    window._tabSelected = false;

    // we need to attach to window load because the tabs functions are initialized later in document
    jQuery(window).on('load', function(){
        // check for initial hash state
        _setTab();

        // add hash change window listener
        jQuery(window).on('hashchange', function(){
            _setTab()
        });

        // void submenu when we are in member section 
        var curPath = window.location.pathname;
        if( curPath.match('our-members') ){
            // only change hash and do not reload page
            jQuery('#menu-item-98 ul li a').on('click', function(e){
                e.stopImmediatePropagation();
                window.location.hash = jQuery(this).prop('hash');
                return false;
            });
        }
    });

答案 2 :(得分:0)

是的,您可以使用函数的composer-1.8.4-airflow-1.10.3属性,例如n1-standard-1代替__name__

答案 3 :(得分:0)

是的,您只需获取函数的名称即可

var UserMails = result.map(c => c.ID);

    for (let i = 0; i < UserMails.length; i++) {
        var MessageToId = UserMails[i]
      const params = {
        Destination: {
          ToAddresses: [MessageToId] // Email address/addresses that you want to send your email
        },
        //ConfigurationSetName: <<ConfigurationSetName>>,
        Message: {
          Body: {
            Html: {
              // HTML Format of the email
              Charset: "UTF-8",
              Data:
                "<html><body><p style='color:black'>" + BroadCastDesc + "</p>"+
                "</body></html>"
            },
          },
          Subject: {
            Charset: "UTF-8",
            Data: BroadCastTitle
          }
        },
        Source: "hello@outlook.com"
      };
      const sendEmail = ses.sendEmail(params).promise();

      sendEmail
      .then(data => {
        console.log("email submitted to SES", data);
      })
      .catch(error => {
        console.log(error);
      });

      return resolve(response);
相关问题