Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help me with this code : (
#1
import sys
import os
import random

exam = sys.argv[1]
folder = sys.argv[2]

questions = []
for bank, number in zip(sys.argv[3::2], map(int, sys.argv[4::2])):
    qfiles = [
        os.path.join(dirpath, fname) 
        for dirpath, dirnames, filenames in os.walk(os.path.join(folder, bank)) 
        for fname in filenames 
        if os.path.splitext(fname)[-1].lower() == '.tex'
        ]
    for qfile in random.sample(qfiles, number):
        with open(qfile, 'r') as qfh:
            questions.append(qfh.read())

with open(exam, 'w') as efh:
    for question in questions:
        print(question, file=efh)
Reference: https://tex.stackexchange.com/questions/...710#499710

everytime I try to run it, it tells me index error or population size too large/negative.

Any advice or guidance will be greatly appreciated :)
Reply


Messages In This Thread
help me with this code : ( - by Alice112233445566771122 - Jul-13-2019, 12:18 PM
RE: help me with this code : ( - by ichabod801 - Jul-13-2019, 12:32 PM
RE: help me with this code : ( - by ichabod801 - Jul-13-2019, 12:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020