2017-02-28 05:12:11

Hello Guys.
This is a topic where users can come and write about anything python-related--if they need help with something, or want to show off their skills--this is the place.
So, let me get the ball rolling with a question:
How do you write a high score to a file and return it in some way within a program? Here is my code below. I politely ask that you tell me a way I could do it, but don't put code in for me. Code:
import random
def file_question():
    filename=raw_input("what is the name of the file you want to open?")
    return filename
   
filename = file_question()

def open_file(filename):
    try:
        infile = open(filename, "rb")
    except:
        infile = open('C:\\Users\\234265\\Desktop\\'+filename, 'rb')

   
    trivia={}
    counter=1
    for line in infile:
        if counter%2=1:
            question=line
        elif counter%2=0
            answer = line
        trivia[question]=answer
    infile.close()
    return trivia

trivia = open_file(filename)

def ask_questions()
    counter=0
    questions=trivia.keys()
    random.shuffle(questions)
    for question in questions:
        guess=input(question)
            if guess=trivia[question]
                counter+=1
        counter=str(counter)
        print "You got "+counter +"out of "+len(questions) +"right."
ask_questions()
def play_again():
    asker=raw_input("would you like to play again?")
    if asker=="y":
        file_question()
        ask_questions()
    elif asker=="n":
        print "have a nice day."
        break

2017-03-01 09:32:21

Use can use the pickle module to pack and unpack lists, dictionaries, and other data for writing to a text document. Example:

import pickle

#write data
def write(data,name):
    tmp = open(name,'w')
    pack = pickle.dumps(data)
    tmp.write(pack)
    tmp.close()

#read data
def read(name):
    tmp = open(name,'r')
    pack = tmp.read()
    data = pickle.loads(pack)
    tmp.close()
    return data

shopping = ['green eggs',1234,'ham',5678]
write(shopping,'test.txt')
tmp = read('test.txt')
print tmp
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2017-03-04 03:53:16

thanks. I have 2 more questions:
1. How do you print the items in a list without the brackets that a list usually contains?
2. What would be the best libraries for sound and screen reader usage in Python and sound usage, and what would be a good way to install them with dependencies included?
Thanks.

2017-03-04 07:53:31 (edited by raven 2017-03-04 07:54:29)

for i in list:
    print(i)

For sound, there's libaudioverse at https://github.com/camlorn/libaudioverse

It's just a pip install libaudioverse away

for speech, there's accessible_output2, but you have to have to use the hg+ prefix, like this:

pip install hg+http://hg.q-continuum.net/libloader hg+http://hg.q-continuum.net/platform_utils hg+http://hg.q-continuum.net/accessible_output2

That should get you AO2+the dependencies.

2017-03-04 08:39:53

But keep in mind that libaudioverse does have some audio problems, as i noticed on games that used it like the shooter engine and the new death match. I don't know if the developer fixed it successfully, but if not you could use PyAL.

2017-03-04 08:51:42

To print a list without the brackets you can use this example:

shopping = ['green eggs',1234,'ham',5678]
print ', '.join(str(a) for a in shopping)

Other than the aforementioned accessible_output2, libaudioverse, and [PyAL] , there's also [Pyglet]. For screen readers there's also [Tolk] and [Pyttsx], although Pyttsx only supports native tts.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2017-03-04 17:06:34

okay I installed accessible_output2. I get the error that says that %1 is not a valid win32 application. What do I do to fix this?