V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 3966 views
    This topic created in 2808 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
        1
    wsh1108  
       Aug 22, 2018 via Android
    from . import b ?我猜的
    是不是没有加载完模块
    chengxiao
        2
    chengxiao  
       Aug 22, 2018
    目录下建一个 __init__.py 的空文件
    Kakarrot
        3
    Kakarrot  
    OP
       Aug 22, 2018
    @wsh1108 脚本执行没问题 但是就是强迫症..
    Kakarrot
        4
    Kakarrot  
    OP
       Aug 22, 2018
    @chengxiao 还有别的办法吗?
    chengxiao
        5
    chengxiao  
       Aug 22, 2018   ❤️ 1
    有 把 pycharm 的语法检查 关了......
    huangzhe8263
        6
    huangzhe8263  
       Aug 22, 2018 via Android   ❤️ 1
    按照惯例。。。重启就好了
    shenbo
        7
    shenbo  
       Aug 22, 2018 via Android
    右键
    Trim21
        8
    Trim21  
       Aug 22, 2018
    你可能没设置 source root?
    在 ab 的共同文件夹上右键 mark as source root 就行了
    Hilong
        9
    Hilong  
       Aug 22, 2018 via Android
    放红线上看是什么原因报错啊
    sw0rd3n
        10
    sw0rd3n  
       Aug 22, 2018 via iPhone
    没设置 source root 吧
    shenbo
        11
    shenbo  
       Aug 22, 2018 via Android
    左侧文件树里,选中上一级目录文件夹-右键-make direct as root..
    smallseven
        12
    smallseven  
       Aug 22, 2018
    关了 pycharm 的语法检查,就不会出现红线了
    aniua
        13
    aniua  
       Aug 23, 2018
    Mark directory as source root,文件夹变蓝色,完事。
    anonymous256
        14
    anonymous256  
       Aug 24, 2018
    pycharm 没有把你当前的目录设置为项目的根目录, 所以需要楼上说的操作.. 对着项目目录右键, Mark directory as ,
    选择
    Source Root
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2671 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 14:38 · PVG 22:38 · LAX 07:38 · JFK 10:38
    ♥ Do have faith in what you're doing.