Edgardomanuelleanna's Profile

270
Points

Questions
52

Answers
34

  • Asked on July 17, 2020 in Python.

    The attrib property of the element is a dictionary of all attributes.

    from xml.etree import ElementTree   tree = ElementTree.parse('sample.xml')  for el in tree.getiterator():     _, _, tag = el.tag.rpartition('}')     for att in el.attrib:         print(f"{tag} ({el.attrib.get(att)})") 

    Yields the following from your sample (which needs a closing </xmi:XMI> to be valid):

    XMI (2.0) Class (AcademicInstitution) Class (false) attrs (name) attrs (true) attrs (/11) 
    • 53 views
    • 1 answers
    • 0 votes
  • I just made a function to do this for me; it only grabs the first result though. Your mileage may vary.

    function query_attribute($xmlNode, $attr_name, $attr_value) {   foreach($xmlNode as $node) {      if($node[$attr_name] == $attr_value) {         return $node;     }   } } 

    Usage:

    echo query_attribute($MySimpleXmlNode->Customer, "type", "human")->Name; 

    (For the XML below)

    <Root><Customer type="human"><Name>Sam Jones</name></Customer></Root> 
    • 46 views
    • 2 answers
    • 0 votes
  • It means that the variable in question is pointed at nothing. I could generate this like so:

    SqlConnection connection = null; connection.Open(); 

    That will throw the error because while I’ve declared the variable “connection“, it’s not pointed to anything. When I try to call the member “Open“, there’s no reference for it to resolve, and it will throw the error.

    To avoid this error:

    1. Always initialize your objects before you try to do anything with them.
    2. If you’re not sure whether the object is null, check it with object == null.

    JetBrains’ Resharper tool will identify every place in your code that has the possibility of a null reference error, allowing you to put in a null check. This error is the number one source of bugs, IMHO.

    • 104 views
    • 28 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    DECLARE statement must be placed immediately after BEGIN keyword, before any other statement.

    Variant 1. Move declaration.

    CREATE TRIGGER customerquote_def_num  BEFORE INSERT  ON customerquote  FOR EACH ROW BEGIN DECLARE p_seq VARCHAR(12); IF NEW.quotenumber IS NULL THEN     SELECT get_sequence('quote') INTO p_seq;     SET NEW.quotenumber = p_seq; END IF; END; 

    Variant 2. Add nested block.

    CREATE TRIGGER customerquote_def_num  BEFORE INSERT  ON customerquote  FOR EACH ROW BEGIN IF NEW.quotenumber IS NULL THEN   BEGIN     DECLARE p_seq VARCHAR(12);     SELECT get_sequence('quote') INTO p_seq;     SET NEW.quotenumber = p_seq;   END; END IF; END; 

    Variant 3. Do not use variable at all.

    CREATE TRIGGER customerquote_def_num  BEFORE INSERT  ON customerquote  FOR EACH ROW SET NEW.quotenumber = CASE WHEN NEW.quotenumber IS NULL                            THEN get_sequence('quote')                            ELSE NEW.quotenumber                            END; 
    • 40 views
    • 1 answers
    • 0 votes
  • The best approach I’ve come up with is

    1. Use lineage to store\sort\trace trees. That’s more than enough, and works thousands times faster for reading than any other approach. It also allows to stay on that pattern even if DB will change(as ANY db will allow that pattern to be used)
    2. Use function that determines lineage for specific ID.
    3. Use it as you wish (in selects, or on CUD operations, or even by jobs).

    Lineage approach descr. can be found wherever, for example Here or here. As of function – that is what enspired me.

    In the end – got more-or-less simple, relatively fast, and SIMPLE solution.

    Function’s body

    -- -------------------------------------------------------------------------------- -- Routine DDL -- Note: comments before and after the routine body will not be stored by the server -- -------------------------------------------------------------------------------- DELIMITER $$  CREATE DEFINER=`root`@`localhost` FUNCTION `get_lineage`(the_id INT) RETURNS text CHARSET utf8     READS SQL DATA BEGIN   DECLARE v_rec INT DEFAULT 0;   DECLARE done INT DEFAULT FALSE;  DECLARE v_res text DEFAULT '';  DECLARE v_papa int;  DECLARE v_papa_papa int DEFAULT -1;  DECLARE csr CURSOR FOR    select _id,parent_id -- @n:=@n+1 as rownum,T1.*    from      (SELECT @r AS _id,         (SELECT @r := table_parent_id FROM table WHERE table_id = _id) AS parent_id,         @l := @l + 1 AS lvl     FROM         (SELECT @r := the_id, @l := 0,@n:=0) vars,         table m     WHERE @r <> 0     ) T1     where T1.parent_id is not null  ORDER BY T1.lvl DESC;  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;     open csr;     read_loop: LOOP     fetch csr into v_papa,v_papa_papa;         SET v_rec = v_rec+1;         IF done THEN             LEAVE read_loop;         END IF;         -- add first         IF v_rec = 1 THEN             SET v_res = v_papa_papa;         END IF;         SET v_res = CONCAT(v_res,'-',v_papa);     END LOOP;     close csr;     return v_res; END 

    And then you just

    select get_lineage(the_id) 

    Hope it helps somebody 🙂

    • 104 views
    • 15 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    tf.keras.applications.inception_resnet_v2 is a module. I think you need tf.keras.applications.InceptionResNetV2

    and as mentioned in the docs:

    tf.keras.applications.InceptionResNetV2(     include_top=True, weights='imagenet', input_tensor=None, input_shape=None,     pooling=None, classes=1000, classifier_activation='softmax', **kwargs ) 
    • 55 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Your import should be: import matplotlib.pyplot as plt

    • 50 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    This behaviour is correct with schedule library because once you execute while loop, it will loop around that task define with schedule library for eternity.

    The best way to avoid this is by using python Threading. I have worked with Qt and Tkinter GUI toolkit and I always prefer Threading to avoid the deadlock.

    • 35 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    How about this:

    df1 = pandas.DataFrame(data = {'col1' : [1, 2, 3, 4, 5],                                 'col2' : [10, 11, 12, 13, 14]})  df2 = pandas.DataFrame(data = {'col1' : [1, 2, 3],                                 'col2' : [10, 11, 12]}) records_df2 = set([tuple(row) for row in df2.values]) in_df2_mask = np.array([tuple(row) in records_df2 for row in df1.values]) result = df1[~in_df2_mask] 
    • 65 views
    • 12 answers
    • 0 votes
  • Asked on July 16, 2020 in HTML.

    No need to add the "/" or "./" because your app.css file is in your current directory.

    • 39 views
    • 2 answers
    • 0 votes