推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Kakarrot
V2EX  ›  Python

问一个 Pycharm 导入自建 py 文件的问题 强迫症没办法..

  •  
  •   Kakarrot · Aug 22, 2018 · 4361 views
    This topic created in 2998 days ago, the information mentioned may be changed or developed.
    2 个 py 文件在同一级目录
    a.py
    b.py

    在 b.py 里导入 import a
    1.a 下面有红色波浪线,如何消除其语法错误?
    2.调用 a 的方法 A = a.print() 时,在打出 a.时怎么可以把方法名提示在下拉框里?
    14 replies  •  2018-08-24 15:57:38 +08:00
    wsh1108
    wsh1108
    Aug 22, 2018 via Android
    1
    from . import b ?我猜的
    是不是没有加载完模块
    chengxiao
    chengxiao
    Aug 22, 2018
    2
    目录下建一个 __init__.py 的空文件
    Kakarrot
    Kakarrot
    OP
    Aug 22, 2018
    3
    @wsh1108 脚本执行没问题 但是就是强迫症..
    Kakarrot
    Kakarrot
    OP
    Aug 22, 2018
    4
    @chengxiao 还有别的办法吗?
    chengxiao
    chengxiao
    Aug 22, 2018❤️1
    5
    有 把 pycharm 的语法检查 关了......
    huangzhe8263
    huangzhe8263
    Aug 22, 2018 via Android❤️1
    6
    按照惯例。。。重启就好了
    shenbo
    shenbo
    Aug 22, 2018 via Android
    7
    右键
    Trim21
    Trim21
    Aug 22, 2018
    8
    你可能没设置 source root?
    在 ab 的共同文件夹上右键 mark as source root 就行了
    Hilong
    Hilong
    Aug 22, 2018 via Android
    9
    放红线上看是什么原因报错啊
    sw0rd3n
    sw0rd3n
    Aug 22, 2018 via iPhone
    10
    没设置 source root 吧
    shenbo
    shenbo
    Aug 22, 2018 via Android
    11
    左侧文件树里,选中上一级目录文件夹-右键-make direct as root..
    smallseven
    smallseven
    Aug 22, 2018
    12
    关了 pycharm 的语法检查,就不会出现红线了
    aniua
    aniua
    Aug 23, 2018
    13
    Mark directory as source root,文件夹变蓝色,完事。
    anonymous256
    anonymous256
    Aug 24, 2018
    14
    pycharm 没有把你当前的目录设置为项目的根目录, 所以需要楼上说的操作.. 对着项目目录右键, Mark directory as ,
    选择
    Source Root
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1026 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 18:44 · PVG 02:44 · LAX 10:44 · JFK 13:44
    ♥ Do have faith in what you're doing.