找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2939|回复: 2

[求助] Python小白,求助import疑问

1

主题

1

帖子

1

积分

贫民

积分
1
juri3953 发表于 2021-1-21 22:26:54 | 显示全部楼层 |阅读模式
大家好!
本人小白,目前用的是c#语言,因为想要做一些大数据处理的东西,开始尝试了解python,看了一点点入门的知识,
有点小小疑问 import语句用来导入其他python文件(称为模块module),感觉可以和C#里的using或者 C中的#include的作用类比,
我想知道import的模块的名字,或者命名空间怎么控制的,如果很多人写了同样名字的模块,怎么import?
不知道理解的对不对?谢谢您的回复!
回复

使用道具 举报

0

主题

9

帖子

9

积分

贫民

积分
9
Seven7 发表于 2021-2-2 10:35:02 | 显示全部楼层
一个路径下只能有一个同名的模块名,即.py文件
python是根据搜索路径先后去查找模块的,查看搜索路径
import sys
print(sys.path)
回复 支持 反对

使用道具 举报

0

主题

18

帖子

18

积分

贫民

积分
18
宫崎峻Miyazaki 发表于 2021-7-30 22:40:47 | 显示全部楼层
本帖最后由 宫崎峻Miyazaki 于 2021-7-30 22:41 编辑

我想说的其实和楼上一样,e.g.用
import可以导入
比如说,
import turtle
这个是导入海归模块,如果不知道怎么用这个模块的话,我还有个例子可以看比如说
  1. import turtle as t


  2. t.speed(3)
  3. t.color('chocolate')
  4. t.begin_fill()
  5. for i in range(1):
  6.     t.forward(100)
  7.     t.left(90)
  8.     t.forward(100)
  9.     t.left(90)
  10.     t.forward(100)
  11.     t.left(90)
  12.     t.forward(100)
  13.     t.goto(100,0)
  14. t.end_fill()
  15. t.color('skyblue')
  16. t.begin_fill()
  17. for i in range(1):
  18.     t.left(120)
  19.     t.forward(40)
  20.     t.left(60)
  21.     t.forward(100)
  22.     t.left(120)
  23.     t.forward(40)
  24. t.end_fill()
  25. t.color('red')
  26. t.begin_fill()
  27. for i in range(1):
  28.     t.goto(134,120)
  29.     t.right(30)
  30.     t.forward(100)
  31.     t.left(30)
  32.     t.forward(40)
  33. t.end_fill()
  34. t.penup()
  35. t.goto(3000,-2000)
  36. t.done()
复制代码

还有如果不知道开头的
import turtle as t

里面的t是什么意思,其实就是把这个turtle模块当作t,这样就可以更方便的写代码,我还有一个例子
  1. import ybc_box
  2. import ybc_turtle as t
  3. import ybc_tuya
  4. import random

  5. print('电脑艺术家')

  6. op = ybc_box.buttonbox('请选择你想要的画风',['翩地球', '点和线', '大小球'])

  7. print('正在搭画板')
  8. print('正在找画笔')
  9. print('正在准备颜料')
  10. print('一切准备就绪')

  11. if op == '翩地球':
  12.     i = 1
  13.     while i < 5:

  14.         t.speed(0)

  15.         x = random.randint(0, 250)
  16.         xx = random.randint(0, 250)
  17.         xxx = random.randint(0, 250)
  18.    
  19.         t.penup()
  20.         y = random.randint(-220, 300)
  21.         x = random.randint(-500, 500)
  22.         t.goto(x,y)
  23.         t.color(x,xx,xxx)
  24.         t.begin_fill()
  25.         for i in range(1):
  26.             t.pendown()
  27.             t.circle(10)
  28.         t.end_fill()
  29.         t.penup()
  30.         t.done()  
  31. elif op == '点和线':
  32.     i = 1
  33.     while i < 5:

  34.         t.speed(0)

  35.         x = random.randint(0, 250)
  36.         xx = random.randint(0, 250)
  37.         xxx = random.randint(0, 250)

  38.    
  39.         t.color(x,xx,xxx)
  40.         t.begin_fill()
  41.         for i in range(1):
  42.             t.penup()
  43.             y = random.randint(-220, 300)
  44.             x = random.randint(-500, 500)
  45.             t.goto(x,y)
  46.             t.pendown()
  47.             t.circle(10)
  48.             t.penup()
  49.         t.end_fill()
  50.         t.done()        
  51. elif op == '大小球':
  52.     i = 1
  53.     while i < 5:

  54.         t.speed(0)

  55.         x = random.randint(0, 250)
  56.         xx = random.randint(0, 250)
  57.         xxx = random.randint(0, 250)
  58.         d = random.randint(1, 200)

  59.         t.penup()
  60.         y = random.randint(-220, 300)
  61.         x = random.randint(-500, 500)
  62.         t.goto(x,y)
  63.         t.color(x,xx,xxx)
  64.         t.begin_fill()
  65.         for i in range(1):
  66.             t.pendown()
  67.             t.circle(d)
  68.         t.end_fill()
  69.         t.penup()
  70.         t.done()   
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表