Py学习  »  Python

仅使用Internet导入Python模块

liam12808 • 4 年前 • 287 次点击  

对于一门编程课程,我将通过一本叫做Zybooks的在线教科书来完成我们所有的工作。对于一个关于模块的任务,我必须创建一个程序,它接收一堆数据,然后使用一个模块将其打印为表,该模块将为我创建表。我似乎不知道如何通过Internet导入该模块,因为如果我在计算机上下载该模块,代码将无法在Web浏览器中工作,因为当网站对其进行分级时,它找不到该模块。有没有什么方法可以让我输入一个url或者使用另一个程序来导入模块并打印出数据表?

我遇到的另一个小问题是我们应该检查输入中的错误,我们应该查找的一个错误是输入中的多个逗号。我以为我有正确的解决办法,但并不总是奏效。关于如何解决这个问题的任何想法都将不胜感激。我引用的代码在第27-29行。

print("Enter a title for the data:")
t = input()
print("You entered:", t)
print()

print("Enter the column 1 header:")
c1 = input()
print("You entered:", c1)
print()

print("Enter the column 2 header:")
c2 = input()
print("You entered:", c2)
print()

s = []
i = []

while 1>0:
    print("Enter a data point (-1 to stop input):")
    o = input()
    if o == '-1':
        break
    if ',' not in o:
        print('Error: No comma in string.')
        continue
    if ',,' in o:
        print("Error: Too many commas in input.")
        continue

    x, y = o.split(",", 1)
    try:
        val = int(y)
    except ValueError:
        print("Error: Comma not followed by an integer.")
        continue
    s.append(x)
    i.append(y)
    print("Data string:", x)
    print("Data integer:", y)


import texttable as tt
tab = tt.Texttable()
headings = ['Author Name', 'Number of Novels']
tab.header(headings)

for row in zip(s,i):
    tab.add_row(row)

z = tab.draw()
print (z)

按要求这里是一个样本输入和输出从程序,因为它是 enter image description here

这是分级机期望模块产生的结果 enter image description here

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39654
 
287 次点击