Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 12-01-2009, 11:50 PM   #1
Omnicide now.
 
foothead's Avatar
 
Join Date: May 2009
Location: My own personal hell
Posts: 10,014
Default quick python question

I have this simple python program I wrote a while back to help study that basically does flashcards, but I can't do more than about 20 because I get an error that I have too many statically nested blocks. Exactly how many can I have? I havent ever heard of python having a limit. All they are being used to do is to hold all the questions and potential answers, etc. Can someone help me to maybe put them as like a .txt or something? I'm a total n00b at programming. thx.
__________________

foothead is offline   Reply With Quote
Old 12-02-2009, 07:08 AM   #2
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: quick python question

Quote:
I have this simple python program I wrote a while back to help study that basically does flashcards, but I can't do more than about 20 because I get an error that I have too many statically nested blocks. Exactly how many can I have?
From looking around a bit it seems that the answer is indeed 20. Any more and python won't like it!

However, if you find yourself using this many nested blocks something has gone seriously wrong in your design process - I end up uncomfortable if I have to use more than 3 or 4 nested blocks, any more than that and it's time for a rethink on the best way to do things. 20 is rather ridiculous!

I can't say how best to approach the problem without seeing your code, but it sounds like the "nice" way of doing this would be to farm them out into an XML file and then read them in from there. As a general design principle the questions / answers shouldn't really be hardcoded anyway.
__________________

berry120 is offline   Reply With Quote
Old 12-04-2009, 01:19 PM   #3
Solid State Member
 
Magnie's Avatar
 
Join Date: Dec 2009
Posts: 7
Default Re: quick python question

There are ways to read and write text files, maybe you could do it with that.

line = 1
questions = []
file = open("questions.txt","r")
while line <= file:
questions.append(file.read(line))
line += 1
file.close()
line = 1
answers = []
file = open("answers.txt","r")
while line <= file:
answers.append(file.read(line))
line += 1
file.close()

that may help...
Magnie is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 05:30 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0