self-reference

How to get the current script's code in Python?

落花浮王杯 提交于 2019-12-04 09:35:23
I want to get the current script as a string in a variable in Python. I found two sub-optimal ways, but I hope there is a better solution. I found: The inspect import has a getsource method, but that only returns the code of one function (or class or whatever), but not the entire script. I can't find a way to pass the object of the entire script to getsource . I could find the file location of the script file using __file__ or sys.argv[0] and open it to read. But this seems too indirect to me. So: is there a (better) way to access the entire script as a string? If relevant: I'd prefer a Python

aspnet core entity framework 7 self referencing “job” 1 to many table

空扰寡人 提交于 2019-12-04 05:12:52
问题 I have a "Job" table that contains jobs. The fact is Jobs are not always done in one go.. you can have a job that has many visits. I intended to represent that as another job but linked back to the original job via self referencing linkId. I am having trouble representing this using the fluent API. Its a one to many relationship.. one job might have many visits and thus a number of linkId's point back to the orginal job. The link Id would back to the orginal job Id. Its also optional since

Why do i get an stackoverflow error when using jackson even though using @JsonIgnoreProperties

不打扰是莪最后的温柔 提交于 2019-12-04 05:01:54
问题 I am trying to serialize a DefaultMutableTreeNode oject with jackson into a json string. Therefore i need to use a mix-in abstract class that is kind of a proxy to the DefaultMutableTreeNode class. This is probably because of self-reference fields but i am not able to recognize them. Mix-in class: @JsonIgnoreProperties(ignoreUnknown = true) public abstract class DefaultMutableTreeNodeMixIn { @JsonCreator public DefaultMutableTreeNodeMixIn(@JsonProperty Object userObject) {}; @JsonCreator

C++ map — Self referencing iterator

痴心易碎 提交于 2019-12-04 03:55:47
问题 Is there a way to declare a std::map whose value type is an iterator to itself? map<string, map<string, (#)>::iterator> myMap; The above code snippet wouldn't work because the iterator type needs to know the second template argument, marked as (#) . (which would be itself). The intent is to avoid doing unnecessary find operations to access the element that is pointed to by another element — as opposed to using map<string, string> . 回答1: Such definition is not possible, since the value type

Self referential enum with immutable parameters

99封情书 提交于 2019-12-04 03:31:05
Consider the following sscce public enum Flippable A (Z), B (Y), Y (B), Z (A); private final Flippable opposite; private Flippable(Flippable opposite) { this.opposite = opposite; } public Flippable flip() { return opposite; } } This doesn't compile, because Z and Y haven't been declared to be allowed to be arguments of A and B 's constructor. Potential solution 1: Hardcoded Methods public enum Flippable { A { public Flippable flip() { return Z; } }, B { public Flippable flip() { return Y; } }, Y { public Flippable flip() { return B; } }, Z { public Flippable flip() { return A; } }; public

Many-to-many self-referential relationship in sqlalchemy

本秂侑毒 提交于 2019-12-04 00:26:29
I'm trying to make a self-referential many-to-many relationship (it means that Line can have many parent lines and many child lines) in sqlalchemy like this: Base = declarative_base() class Association(Base): __tablename__ = 'association' prev_id = Column(Integer, ForeignKey('line.id'), primary_key=True) next_id = Column(Integer, ForeignKey('line.id'), primary_key=True) class Line(Base): __tablename__ = 'line' id = Column(Integer, primary_key = True) text = Column(Text) condition = Column(Text) action = Column(Text) next_lines = relationship(Association, backref="prev_lines") class Root(Base):

Self-reference for cell, column and row in worksheet functions

南楼画角 提交于 2019-12-03 18:40:28
问题 In a worksheet function in Excel, how do you self-reference the cell, column or row you're in? Note that this is extremely useful for conditional formatting. 回答1: where F13 is the cell you need to reference: =CELL("Row",F13) yields 13; its row number =CELL("Col",F13) yields 6; its column number; =SUBSTITUTE(ADDRESS(1,COLUMN(F13)*1,4),"1","") yields F; its column letter 回答2: For a cell to self-reference itself: INDIRECT(ADDRESS(ROW(), COLUMN())) For a cell to self-reference its column:

What is the best way to empty a self-referential MySQL table?

有些话、适合烂在心里 提交于 2019-12-03 11:25:05
问题 I have a self-referential MySQL table with a recursive parent_id: CREATE TABLE `recursive` ( `id` int(11) NOT NULL auto_increment, `parent_id` int(11) default NULL, `name` varchar(100) NOT NULL, PRIMARY KEY (`id`), KEY `data_categorysource_parent_id` (`parent_id`), CONSTRAINT `parent_id_refs_id_627b4293` FOREIGN KEY (`parent_id`) REFERENCES `data_categorysource` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 During testing, I want to empty it but TRUNCATE fails: TRUNCATE `recursive` /* SQL Error

Python: getting a reference to a function from inside itself

心已入冬 提交于 2019-12-03 09:54:59
If I define a function: def f(x): return x+3 I can later store objects as attributes of the function, like so: f.thing="hello!" I would like to do this from inside the code of the function itself. Problem is, how do I get a reference to the function from inside itself? The same way, just use its name. >>> def g(x): ... g.r = 4 ... >>> g <function g at 0x0100AD68> >>> g(3) >>> g.r 4 If you are trying to do memoization, you can use a dictionary as a default parameter: def f(x, memo={}): if x not in memo: memo[x] = x + 3 return memo[x] Or use a closure: def gen_f(): memo = dict() def f(x): try:

Fluent NHibernate Self Referencing Many To Many

允我心安 提交于 2019-12-03 07:33:30
I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList<Book> RelatedBooks { get; set; } } Here is what the mapping looks like for this relationship HasManyToMany(x => x.RelatedBooks) .ParentKeyColumn("BookId") .ChildKeyColumn("RelatedBookId") .Table("RelatedBooks") .Cascade.SaveUpdate(); Here is a sample of the data that is then generated in the RelatedBooks table: BookId RelatedBookId 1 2 1 3 The problem happens when I Try