赞
踩
在阅读下面的代码之前,我建议您尝试自己找到解决方案.即使你没有成功,尝试也是最重要的,因为你会学到比预期更多的东西.
因此,下次发布问题时,您至少应该向我们展示一些代码,以显示您所做的一些努力.
考虑到您的问题,我建议您关注以下内容:
>尝试学习Python的基础知识(例如:如何创建/使用变量,结构如简单数组,如何读取文件,如何打印内容):Python非常容易学习,你肯定会发现它易于使用: ).另外,您可以在线找到许多免费课程,文档等.您可以查看此链接,例如:http://docs.python.org/tutorial/index.html
>如果您对HTML一无所知,请快速了解如何创建HTML表
>在阅读我之前尝试编码!!!
>如果您阅读我的代码,我建议您关注我所做的评论,并对您不理解的潜在部分进行一些研究,或者哪些部分看起来不太清楚
代码:
import sys
# Create 2 arrays which will contain independently the subjects and the marks:
# 1 - Initialize your array containing your 'subjects'
subjects = []
# 2 - Initialize your array containing your 'marks'
marks = []
# Opening file for reading. The path of the file is given in argument
open_file = open(sys.argv[1], 'r')
for line in open_file:
# 'line' is a line in your file
# We make sure that 'line' is non-empty
if line:
# for each line in your file, we read something like this:
# subject---marks
# We need to split the different information, which are separated by '---'
information = line.split('---')
# 'information' is an array containing 2 values:
# 'information[0]' contains the subject
# 'information[1]' contains the mark
# We store each separate information in our arrays 'subjects' and 'marks':
subjects.append(information[0])
marks.append(information[1])
# When finishing reading the file, we close it
open_file.close()
# Now that all the data inside the file has been read, and store in our arrays
# we have to use it to create / print it in an HTML table
# Print opening HTML tags -------------------------
print "
# Print the content of the table, line by line ----
for i in range(0, len(subjects)):
print "
"+subjects[i]+""+marks[i]+""# Print closing HTML tags -------------------------
print "
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。