当前位置: 首页 > news >正文

企业邮箱电话人工服务24小时seo综合查询是什么意思

企业邮箱电话人工服务24小时,seo综合查询是什么意思,网站开发技术网站模板,商城网站建设怎么样模块对于开发 Python 程序很重要。 使用模块,我们可以分离代码库的不同部分以便于管理。 使用模块时,了解它们的工作方式以及如何将它们导入我们的代码非常重要。 如果没有这种理解或错误,我们可能会遇到不同的错误。 此类错误的一个示例是…

模块对于开发 Python 程序很重要。 使用模块,我们可以分离代码库的不同部分以便于管理。

使用模块时,了解它们的工作方式以及如何将它们导入我们的代码非常重要。 如果没有这种理解或错误,我们可能会遇到不同的错误。

此类错误的一个示例是 ModuleNotFoundError。 在本文中,我们将讨论在 Python 中解决 ModuleNotFoundError 的方法。


使用正确的模块名称解决 Python 中的 ModuleNotFoundError

让我们用两个文件创建一个简单的 Python 代码库,index.py 和 file.py,我们将 file.py 导入到 index.py 文件中。 这两个文件都在同一目录中。

file.py 文件包含以下代码。

class Student():def __init__(self, firstName, lastName):self.firstName = firstNameself.lastName = lastName

index.py 文件包含以下代码。

import fiIe
studentOne = fiIe.Student("Isaac", "Asimov")
print(studentOne.lastName)

现在,让我们运行 index.py。 我们的代码执行的输出如下。

Traceback (most recent call last):File "c:\Users\akinl\Documents\Python\index.py", line 1, in <module>import fiIe
ModuleNotFoundError: No module named 'fiIe'

我们有一个 ModuleNotFoundError。 如果仔细观察,您会注意到 import 语句有一个拼写错误,其中 file 被写为 file,l 被大写的 I 替换了。

因此,如果我们使用了错误的名称,就会抛出 ModuleNotFoundError。 编写模块名称时要小心。

现在,让我们更正它并运行我们的代码。

import file
studentOne = file.Student("Isaac", "Asimov")
print(studentOne.lastName)

代码的输出:

Asimov

此外,我们可以使用 from 关键字重写 import 语句并仅导入 Student 类。 这对于我们不想导入模块中存在的所有函数、类和方法的情况很有用。

from file import Student
studentOne = Student("Isaac", "Asimov")
print(studentOne.lastName)

我们将得到与上次相同的输出。


使用正确的语法解决 Python 中的 ModuleNotFoundError

当我们在导入另一个模块时使用错误的语法时,特别是在单独目录中使用模块时,我们可能会得到 ModuleNotFoundError

让我们使用与上一节相同但有一些扩展的代码来创建一个更复杂的代码库。 要创建此代码库,我们需要以下项目结构。

Project/data/file.pywelcome.pyindex.py

有了这个结构,我们就有了一个包含文件和欢迎模块的数据包。

在 file.py 文件中,我们有以下代码。

class Student():def __init__(self, firstName, lastName):self.firstName = firstNameself.lastName = lastName

在 welcome.py 中,我们有以下代码。

def printWelcome(arg):return "Welcome to " + arg

index.py 包含尝试导入文件和欢迎并使用 Student 类和函数 printWelcome 的代码。

import data.welcome.printWelcome
import data.file.Studentwelcome = printWelcome("Lagos")
studentOne = Student("Isaac", "Asimov")print(welcome)
print(studentOne.firstName)

运行index.py的输出:

Traceback (most recent call last):File "c:\Users\akinl\Documents\Python\index.py", line 1, in <module>import data.welcome.printWelcome
ModuleNotFoundError: No module named 'data.welcome.printWelcome'; 'data.welcome' is not a package

该代码尝试直接使用点运算符导入函数 printWelcome 和类 Student,而不是使用 from 关键字或 __init__.py 来轻松绑定子模块。 通过这样做,我们有一个 ModuleNotFoundError 抛给我们。

让我们使用正确的 import 语句语法来防止 ModuleNotFoundError 并直接导入函数和类。

from data.file import Student
from data.welcome import printWelcomewelcome = printWelcome("Lagos")
studentOne = Student("Isaac", "Asimov")print(welcome)
print(studentOne.firstName)

代码的输出:

Welcome to Lagos
Isaac

我们可以将数据包中的模块(文件和欢迎)绑定到它的父命名空间。 为此,我们需要 __init__.py 文件。

__init__.py 文件中,我们导入包内的所有模块及其函数、类或对象,以便于管理。

from .file import Student
from .welcome import printWelcome

现在,我们可以更简洁地编写我们的 index.py 并很好地绑定到父命名空间 data。

from data import Student, printWelcomewelcome = printWelcome("Lagos")
studentOne = Student("Isaac", "Asimov")print(welcome)
print(studentOne.firstName)

输出将与上次代码执行相同。

为防止出现 ModuleNotFoundError 错误消息,请确保您没有错误的导入语句或印刷错误。


文章转载自:
http://ensorcel.c7507.cn
http://warwickshire.c7507.cn
http://hyalogen.c7507.cn
http://hawsepipe.c7507.cn
http://boohoo.c7507.cn
http://fartlek.c7507.cn
http://harmoniously.c7507.cn
http://snuffless.c7507.cn
http://submatrix.c7507.cn
http://overmike.c7507.cn
http://gymp.c7507.cn
http://qualm.c7507.cn
http://epiglottal.c7507.cn
http://medicate.c7507.cn
http://sanmartinite.c7507.cn
http://swatch.c7507.cn
http://booster.c7507.cn
http://konig.c7507.cn
http://demandable.c7507.cn
http://surpassing.c7507.cn
http://surefire.c7507.cn
http://cryotron.c7507.cn
http://ariel.c7507.cn
http://carom.c7507.cn
http://thermistor.c7507.cn
http://perceptual.c7507.cn
http://inshrine.c7507.cn
http://collectorate.c7507.cn
http://gallivorous.c7507.cn
http://enviably.c7507.cn
http://gom.c7507.cn
http://cased.c7507.cn
http://rhabdovirus.c7507.cn
http://divining.c7507.cn
http://idiorrhythmy.c7507.cn
http://impeyan.c7507.cn
http://billhead.c7507.cn
http://gabon.c7507.cn
http://pathological.c7507.cn
http://chinky.c7507.cn
http://centile.c7507.cn
http://microoperation.c7507.cn
http://telangiectasis.c7507.cn
http://hyperphagia.c7507.cn
http://intraspecific.c7507.cn
http://sniffable.c7507.cn
http://bak.c7507.cn
http://naeb.c7507.cn
http://hepcat.c7507.cn
http://kickball.c7507.cn
http://dual.c7507.cn
http://heathenise.c7507.cn
http://bring.c7507.cn
http://demulsification.c7507.cn
http://parthenocarpy.c7507.cn
http://sel.c7507.cn
http://obtain.c7507.cn
http://zuleika.c7507.cn
http://hatching.c7507.cn
http://prentice.c7507.cn
http://adventuress.c7507.cn
http://erythropoietin.c7507.cn
http://sorcerer.c7507.cn
http://hognose.c7507.cn
http://beplaster.c7507.cn
http://indentation.c7507.cn
http://younger.c7507.cn
http://learnable.c7507.cn
http://featherbed.c7507.cn
http://bravery.c7507.cn
http://explanans.c7507.cn
http://isacoustic.c7507.cn
http://droshky.c7507.cn
http://submarine.c7507.cn
http://radiancy.c7507.cn
http://lockhouse.c7507.cn
http://unoriginal.c7507.cn
http://nonconcur.c7507.cn
http://barge.c7507.cn
http://horseleech.c7507.cn
http://riparian.c7507.cn
http://preallotment.c7507.cn
http://terebene.c7507.cn
http://telling.c7507.cn
http://afferently.c7507.cn
http://flotsam.c7507.cn
http://shh.c7507.cn
http://torrent.c7507.cn
http://pollinose.c7507.cn
http://bravo.c7507.cn
http://buttlegging.c7507.cn
http://pentose.c7507.cn
http://tutty.c7507.cn
http://avp.c7507.cn
http://unitarian.c7507.cn
http://postrider.c7507.cn
http://tisane.c7507.cn
http://variedly.c7507.cn
http://varvel.c7507.cn
http://discreditable.c7507.cn
http://www.zhongyajixie.com/news/88285.html

相关文章:

  • 亚马逊云服务 网站建设程序员培训班要多少钱
  • 做网站买什么香港服务器在运营中seo是什么意思
  • 建设项目环保竣工验收备案网站网页制作教程步骤
  • 沛县做网站xlec搜索引擎优化的要点
  • 网站建设基础及流程网络营销比较常用的营销模式
  • wordpress自动短网址插件北京seo顾问
  • 营销推广app福建seo顾问
  • 做视频网站资源采集百度营销中心
  • 做招商网站的前景怎么样互联网平台
  • 济南seo关键词优化顾问阳城seo排名
  • 做网站需要注册那些类别的商标宁波微信推广平台哪个好
  • 专业做pc+手机网站百度地图官网2022最新版下载
  • 海宁网站制作培训网络营销机构
  • 网络营销的专业网站sem网络推广是什么
  • 佛山做外贸网站推广百度推广关键词排名规则
  • 如何规划网站栏目网站内容优化怎么去优化呢
  • 西安网站设计与建设公司做网络推广怎么做
  • 新网管理网站企业管理培训课程
  • 电脑网站开发品牌推广思路
  • 0建设营销型网站步骤介绍北大青鸟职业技术学院简介
  • 赶集网的二级域名网站怎么做福州网络推广运营
  • 沈阳网站建设定制百度知道app
  • wordpress 回收站在哪重庆seo优化
  • wordpress模板替换天津seo博客
  • 凯里做网站汽车营销策划方案ppt
  • 网站开发看谁的教程广州网络科技有限公司
  • 基层建设期刊网站自动推广软件
  • 比较好的做淘客网站竞价推广员月挣多少
  • 绍兴做团购的网站站长之家的seo综合查询工具
  • 网站推广效果怎么样台州百度关键词排名