import

Infinite loop with Python imports; looking for Pythonic way

試著忘記壹切 提交于 2020-07-09 05:41:58
问题 My team is working on huge project with Django. For sake of simplicity, here's plain Python to illustrate the problem (original problem has models and apps instead of classes (I know that both are classes) and packages (I know that both are packages as well)). a.py : from b import B1 class A1(object): def __init__(self): print "object A1" class A2(object): def __init__(self): print "object A2" A1() B1() b.py : from a import A2 class B1(object): def __init__(self): print "object B1" A2() When

Infinite loop with Python imports; looking for Pythonic way

若如初见. 提交于 2020-07-09 05:35:03
问题 My team is working on huge project with Django. For sake of simplicity, here's plain Python to illustrate the problem (original problem has models and apps instead of classes (I know that both are classes) and packages (I know that both are packages as well)). a.py : from b import B1 class A1(object): def __init__(self): print "object A1" class A2(object): def __init__(self): print "object A2" A1() B1() b.py : from a import A2 class B1(object): def __init__(self): print "object B1" A2() When

How do I find the name of the file that is the importer, within the imported file?

被刻印的时光 ゝ 提交于 2020-07-09 03:09:20
问题 How do I find the name of the file that is the "importer", within the imported file? If a.py and b.py both import c.py , is there anyway that c.py can know the name of the file importing it? 回答1: In the top-level of c.py (i.e. outside of any function or class), you should be able to get the information you need by running import traceback and then examining the result of traceback.extract_stack(). At the time that top-level code is run, the importer of the module (and its importer, etc.

PaperTrail Manually create version

让人想犯罪 __ 提交于 2020-07-08 06:57:10
问题 I have a spreadsheet of items which I convert to CSV and import using a custom import script into my Rails based application. The spreadsheet contains a row for each record but some rows hold different versions of previous rows. When importing the CSV I currently mark the second row using a "past_version" field but I am now thinking that implementing a full versioning gem would be a much nicer way of going about it. I have been reading through the docs for PaperTrail and it looks perfect for

Python: circular imports needed for type checking

徘徊边缘 提交于 2020-07-04 12:50:31
问题 First of all: I do know that there are already many questions and answers to the topic of the circular imports. The answer is more or less: "Design your Module/Class structure properly and you will not need circular imports". That is true. I tried very hard to make a proper design for my current project, I in my opinion I was successful with this. But my specific problem is the following: I need a type check in a module that is already imported by the module containing the class to check

importing complex XML data into multiple FileMaker tables

六眼飞鱼酱① 提交于 2020-07-04 03:29:05
问题 I understand the basics of import to FileMaker (csv, xml) and I know a little about XSLT. I have a data set containing lists that I need to import into FileMaker. There are 3 tables for this - the main table, the datapoints table and the positions table. My data looks like this: <?xml version="1.0" encoding="ISO-8859-1"?> <result> <data mode="test" ram="on"> 33,869 34,115 46,074 225,233, E 226,122, E 235,763, E 237,408, E 237,722, E 242,503 256,271 273,741 </data> <statistics> <positions>

How to declare global variable in module script

纵然是瞬间 提交于 2020-07-03 09:26:08
问题 I have a module script, in which I import some classes and initialize my app. But module scipts declare var myVar = "my"; in module context, what makes init variables unaccessible to main app code. But I don't know how to declare global variable in module script. 回答1: Instead of var myVar = "my"; use window.myVar = "my"; 来源: https://stackoverflow.com/questions/48612021/how-to-declare-global-variable-in-module-script

cross module variable

风格不统一 提交于 2020-06-28 23:39:47
问题 from here I got an idea about how using variables from other modules. this all works fine with import foo as bar But I don't want to import my modules as "bar" I want to use it without any prefix like from foo import * Using this it´s impossible to modify variables from other modules. reading will work! any idea? suggestions? 回答1: As far as I know, there is no way to import a value from a module and have it readable and writable by the importing scope. When you just import foo in Python, it

how to import tif calibration into DM

那年仲夏 提交于 2020-06-28 09:18:18
问题 We need to treat the SEM images from FEI and Zeiss tools in DigitalMicrograph. They are stored as tif. DigitalMicrograph can read 2D tif but images appear uncalibrated in X,Y directions. Is there any import plugIn that transfers the calibration information ? Alternatively, I can imagine that the calibration can be red directly from a stream. Has anyone a clear idea about the offset where such numbers are stored in a stream of tif? I am not very familiar with organization of tif and I know

How to import my own modules in python 3.6?

ⅰ亾dé卋堺 提交于 2020-06-27 10:41:40
问题 Let's say I have a file like: Project0\pizza.py Project0\make_pizza.py and pizza: def make_pizza(size,*toppings): print("\nMaking a " + str(size) + "-inch pizza with the following toppings:") for topping in toppings: print("- " + topping) and make_pizza: from pizza import make_pizza pizza.make_pizza(16, 'pepperoni') and as shown in the codes, I want to import pizza into make_pizza , but the IDE shows up an error that there is no module named pizza. How can I solve this problem and import