Germany, however, insists on restrictions on the import of Polish coal. To import from Russia, a Ukrainian firm needs Russian roubles. "the lead role was played by an import from Sweden", "they are descendants of indentured importees", "the significance of a red traffic light", "the signification of Chinese characters", "the import of his announcement was ambigtuous", "the significance of his remark became clear only later", "the expectation was spread both by word and by implication", "decisions of great consequence are made by the president himself", 1. The implication is a sharp decline in global trade, which has plunged partly because oilproducing nations can't afford to import as much as they used to. Can you interpret the import of what he remarked at the end of the meeting? We import an incredible amount of cheese from the Continent. "the lead role was played by an import from Sweden" "they are descendants of indentured importees" 3. the message that is intended or expressed or signified; "what is the meaning of this sentence" "the significance of a red traffic light" "the signification of Chinese characters" "the import of his announcement was ambigtuous" Many countries import wool from Australia. It reflects Americans' preference for imported goods. Python用了快两年了吧,其中有些东西一直是稀里糊涂地用,import便是我一直没有明白的东西。曾经有过三次解决它的机会,我都因得过且过、一拖再拖而没能化敌为友。今天下午,它又给了我一次机会,我想我还是从了它的心愿吧。, 故事是从这篇台湾同胞的博客(Python 的 Import 陷阱)开始的,然后又跳到了Python社区的PEP 328提案(PEP 328 -- Imports: Multi-Line and Absolute/Relative),再结合过去的经验以及一些测试,我想我大概懂了吧。下面是我的总结,希望内容能够言简意赅、易于理解。, import语句有什么用?import语句用来导入其他python文件(称为模块module),使用该模块里定义的类、方法或者变量,从而达到代码复用的目的。为了方便说明,我们用实例来说明import的用法,读者朋友可以跟着尝试(尝试时建议使用python3,python2和python3在import的表现有差异,之后会提到)。, 首先,先建立一个文件夹Tree作为工作目录,并在其内建立两个文件m1.py和m2.py,在m1.py写入代码:, 打开命令行,进入到Tree目录下,敲下python m1.py运行,发现没有报错,且打印出In m2,说明这样使用import没有问题。由此我们总结出import语句的第一种用法。, 用上述方法导入原有的sys.path中的库没有问题。但是,最好不要用上述方法导入同目录下的文件!因为这可能会出错。演示这个错误需要用到import语句的第二种写法,所以先来学一学import的第二种写法。在Tree目录下新建一个目录Branch,在Branch中新建文件m3.py,m3.py的内容如下:, 现在我们来说明为什么不要用import的第一种写法来导入同目录下的文件。在Branch目录下新建m4.py文件,m4.py的内容如下:, 这时候运行m1.py就会报错了,说没法导入m4模块。为什么呢?我们来看一下导入流程:m1使用from Branch import m3导入m3,然后在m3.py中用import m4导入m4。看出问题了吗?m4.py和m1.py不在同一目录,怎么能直接使用import m4导入m4呢。(读者可以试试直接在Tree目录下新建另一个m4.py文件,你会发现再运行m1.py就不会出错了,只不过导入的是第二个m4.py了), 面对上面的错误,使用python2运行m1.py就不会报错,因为在python2中,上面提到的import的两种写法都属于相对导入,而在python3中,却属于绝对导入。话说到了这里,就要牵扯到import中最关键的部分了——相对导入和绝对导入。, 我们还是谈论python3的import用法。上面提到的两种写法属于绝对导入,即用于导入sys.path中的包和运行文件所在目录下的包。对于sys.path中的包,这种写法毫无问题;导入自己写的文件,如果是非运行入口文件(上面的m1.py是运行入口文件,可以使用绝对导入),则需要相对导入。, 不知道你有没有留神上面的一句话——“上面的m1.py是运行入口文件,可以使用绝对导入”,这句话是没问题的,也和我平时的做法一致。那么,运行入口文件可不可以使用相对导入呢?比如m1.py内容改成:, 答案是可以,但不能用python m1.py命令,而是需要进入到Tree所在的目录,使用python -m Tree.m1来运行。为什么?关于前者,PEP 328提案中的一段文字好像给出了原因:, 意思是如果运行了当前文件,则__name__变量会置为__main__,然后会执行main函数,如果当前文件是被其他文件作为模块导入的话,则__name__为模块名,不等于__main__,就不会执行main函数。比如对于上述更改后的m1.py,执行python m1.py命令后,会报如下错误:, 据此我猜测执行python m1.py命令后,当前目录所代表的包'. To what extent are Americans really willing to endure the environmental impacts of domestic energy production in order to cut back imports. importとは意味:1import n.(1) 意義, 意味; 重大.【動詞+】 His experiments bear great import for the future of thermodynamics.彼の実験は熱力學の將來にとって重要な意味をもつものである His remarks clearly conveyed that import. Whether it is a transition from imported to domestic oil or from coal-powered electricity production to natural-gas power plants, politicians love to talk big. Import your scanned images from the scanner and save as a JPG file. I have already spoken about the import of his speech. Python用了快两年了吧,其中有些东西一直是稀里糊涂地用,import便是我一直没有明白的东西。曾经有过三次解决它的机会,我都因得过且过、一拖再拖而没能化敌为友。今天下午,它又给了我一次机会,我想我还是从了它… The import of cotton goods went up sharply. ", transfer (electronic data) into a database or document. That sign says they are against importing luxury goods from Europe. The rising numbers signify growing vitality in foreign markets – when we import more stuff, it puts more cash in the hands of people around the world, and U.S. exports are rising because more foreigners have the ability to buy the things we produce and market. You can import files from Microsoft Word 5.1 or MacWrite II. By changing its supplier, the company saved thousands of pounds in import duty. Who leads Canada is also of some import to the rest of the world. The country's only supplies are those it can import by lorry from Vietnam. By 1973, domestic US sources of oil were peaking, and the nation was importing more of its oil, depending on a constant flow from abroad to keep cars on the road and machines running. Consumers who favor imported goods and services. To import more cheap goods from developing countries. A restricted import quota was set for meat products. import as改變的是被匯入模組在當前模組的名稱,而不是sys.modules中的名稱,以上例來說,sys.modules中的名稱仍然是some。 上例比較像是: import some The biggest gains go to countries that import most of their oil like China, Japan, and India. They value the environmental quality they preserve over their oil imports from abroad. If export and import demand is elastic, then the change in trade volumes will operate to remove the surplus. an import restriction called {residual quantitative import restriction}発音を聞く 例文帳に追加 残存輸入制限という輸入制限 - EDR日英対訳辞書 a policy aimed at import - substitution 発音を聞く 例文帳に追加 To justify America's dependence on oil imports. The most import advantage of the school meeting is that it shows the children that the school is really their's. Why does America rely heavily on oil imports. import duties 進口稅。 an import surplus 入超。 an import quota 進口限額。 the import of his remarks 他說話的含意。 a matter of great import大事情。, commodities (goods or services) bought from a foreign country, having important effects or influence; "decisions of great consequence are made by the president himself"; "virtue is of more moment than security"; "that result is of no consequence", a meaning that is not expressly stated but can be inferred; "the significance of his remark became clear only later"; "the expectation was spread both by word and by implication", the message that is intended or expressed or signified; "what is the meaning of this sentence"; "the significance of a red traffic light"; "the signification of Chinese characters"; "the import of his announcement was ambiguous", an imported person brought from a foreign country; "the lead role was played by an import from Sweden"; "they are descendants of indentured importees", indicate or signify; "I''m afraid this spells trouble! Well before the arrival of freezers, there was a demand for ice for food preservation and catering, malcolm will explain the history of importing natural ice and the technology of building ice wells, and how London's ice trade grew. The painting was returned to Spain on a temporary import licence. ,解释器并不知道是哪一个package。使用python -m Tree.m1,解释器就知道.对应的是Tree这个package。, 那反过来,如果m1.py使用绝对导入(from Branch import m3),能使用python -m m1运行吗?我试了一下,如果当前目录是Tree就可以。如果在其他目录下运行,比如在Tree所在的目录(使用python -m Tree.m1运行),就不可以。这可能还是与绝对导入相关。, (之前看到了一个大型项目,其运行入口文件有一大堆的相对导入,我还傻乎乎地用python直接运行它。之后看到他给的样例运行命令是带了-m参数的。现在才恍然大悟。), 理解import的难点差不多就这样了。下面说一说import的其他简单但实用的用法。, 说到这感觉import的核心已经说完了。再跟着上面的博客说一说使用import可能碰到的问题吧。, 问题1描述:ValueError: attempted relative import beyond top-level package。直面问题的第一步是去了解熟悉它,最好是能复现它,让它躺在两跨之间任我们去践踏蹂躏。仍然是上面四个文件,稍作修改,四个文件如下:, 运行python m1.py,就会出现该问题。问题何在?我猜测,运行m1.py后,m1代表的模块就是顶层模块(参见上面PEP 328的引用),而m3.py中尝试导入的m2模块所在的包(即Tree目录代表的包)比m1的层级更高,所以会报出这样的错误。怎么解决呢?将m1.py的所有导入改为相对导入,然后进入m1.py的上层目录,运行python -m Tree.m1即可。, PEP 328 -- Imports: Multi-Line and Absolute/Relative. A small gasoline tax would help free America from its dependence on oil imports and create incentives for green energy development. We must produce more food for ourselves and import less. =part/divide,表示"部分,分开"; 2. to introduce a strict import quota on grain. Most people would probably say that they want to be independent from imported oil. They suspend import of necessities from overseas. Before the War, much of Britain's food was imported and when German U-boats began attacking ships bringing food to the country, Britain went on rations (配给). There is no question that the United States imports a great deal of energy and, in fact, relies on that steady flow to maintain its economy. Over the past two years, the figures on imports and exports seem not to signal a double-dip recession – a renewed decline in the broad level of economic activity in the United States – but an economic expansion. =carry,表示"拿,运", proportion比例;均衡+al……的→adj.比例的, 成比例的, 相称的, 均衡的, dis不+proportion[n.比例;部分;均衡,相称]+al……的→adj.&n.不均衡, 不成比例 v.使不均衡, 使不对称, receiveimportanceadmitimplicationsignificancebringmeaninginsubstanceeffecttakeintroduce, By changing its supplier, the company saved thousands of pounds in, The government has imposed strict reins on the, We must produce more food for ourselves and, The country's only supplies are those it can, The painting was returned to Spain on a temporary, Germany, however, insists on restrictions on the, Such moves may eliminate the fears of those living in the exporting countries, but they are creating panic in, The implication is a sharp decline in global trade, which has plunged partly because oilproducing nations can't afford to, Most people would probably say that they want to be independent from, They value the environmental quality they preserve over their oil, To what extent are Americans really willing to endure the environmental impacts of domestic energy production in order to cut back, There is no question that the United States, Before the War, much of Britain's food was, The implication is a sharp decline in global trade, which has plunged partly because oil-producing nations can't afford to, These included developing additional domestic sources (such as those on Alaska's North Slope), resuming extraction at sites that had been shut down because of cost inefficiency, capping the price that domestic producers could charge for oil, and beginning to, By 1973, domestic US sources of oil were peaking, and the nation was, They develop green energy to avoid dependence on oil, A small gasoline tax would help free America from its dependence on oil, The rising numbers signify growing vitality in foreign markets – when we, Well before the arrival of freezers, there was a demand for ice for food preservation and catering, malcolm will explain the history of. '变成了__main__。, 即不把m1.py当作运行入口文件,而是也把它当作被导入的模块,这就和非运行入口文件有一样的表现了。, 注意,在Tree目录下运行python -m m1是不可以的,会报 ImportError: attempted relative import with no known parent package的错误。因为m1.py中的from .Branch import m3中的. The report notes that export and import volumes picked up in leading economies. Import controls were extended to the paper industry. Tamlyn says that besides importing ingredients from Britain once a week, his restaurant also buys vegetables from the local markets. These included developing additional domestic sources (such as those on Alaska's North Slope), resuming extraction at sites that had been shut down because of cost inefficiency, capping the price that domestic producers could charge for oil, and beginning to import oil from a greater diversity of nations. They develop green energy to avoid dependence on oil import. The government has imposed strict reins on the import of luxury goods. The implication is a sharp decline in global trade, which has plunged partly because oil-producing nations can't afford to import as much as they used to. One solution is obviously to import foreign workers via immigration. Such moves may eliminate the fears of those living in the exporting countries, but they are creating panic in importing countries that must rely on what is then left for export.