本文介绍了尝试导入时可以在Python文件中使用破折号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,当我有一个类似python的文件时:

Basically when I have a python file like:

python-code.py

并使用:

import (python-code)

解释器给我语法错误.

关于如何解决它的任何想法? python文件名中的破折号是非法的吗?

Any ideas on how to fix it? Are dashes illegal in python file names?

推荐答案

您应该查看 PEP 8 ,Python代码样式指南:

You should check out PEP 8, the Style Guide for Python Code:

由于模块名称已映射到文件名,并且某些文件系统不区分大小写,并且截断了长名称,因此,将模块名称选择为相当短是很重要的-在Unix上这不是问题,但是将代码传输到较旧的Mac或Windows版本或DOS时可能会出现问题.

Since module names are mapped to file names, and some file systems are case insensitive and truncate long names, it is important that module names be chosen to be fairly short -- this won't be a problem on Unix, but it may be a problem when the code is transported to older Mac or Windows versions, or DOS.

换句话说:重命名文件:)

In other words: rename your file :)

这篇关于尝试导入时可以在Python文件中使用破折号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:55
查看更多