Re: [Tutor] new to python
> for line in file: This line is not required as the you have opened your file to 'f'. 'file' is a built-in class. Type - help(file) on the interpreter to know more about it. > for line in f: > print(line.rstripe()) > f.close() Are you sure that you need to close the file after reading each line? > > I want to try the different methods of opening files and reading them. and processing the data. from there I will then start with writing to files. Bonus : read about the 'with' keyword. > any idea why that does not work? When you say the code does not work, you should provide the exact error or stacktrace that you see. Thanks, Anish ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python Queue
> AttributeError: Queue instance has no attribute 'taskdone' Method name is task_done (not taskdone) https://docs.python.org/2/library/queue.html#Queue.Queue.task_done ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] infix to postfix eval
On Sun, Aug 2, 2015 at 9:39 AM, Quiles, Stephanie wrote: > > hello again! > > I have to unify these methods so that i can enter an infix, convert it to a > postfix and then solve. Here are the methods At the end of your code I added this - inFixExpr = raw_input("Enter infix string : ") postFixExpr = infixToPostfix(inFixExpr) print("The postfix string is: " + postFixExpr) value = postfixEval(postFixExpr) print("The final result is: " + str(value)) And this gives me output - $ python postfix.py 5 3 4 2 - ^ * A B + C * D E - F G + * - Enter infix string : ( 8 + 2 ) * ( 2 + 4 ) The postfix string is: 8 2 + 2 4 + * The final result is: 60 > if token in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" or token in "0123456789": Instead of the above line, you can do this - if token in string.uppercase or token in string.digits: Import string module first. >>> import string >>> string.uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> string.digits '0123456789' >>> Thanks, Anish ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python GPIO Code Help Needed
On Sun, Oct 26, 2014 at 6:35 AM, Bill Bright wrote: > I have been working on a piece of code that I got from another tutorial. > The code polls the GPIO pins on a Raspberry Pi. When it detects a switch > being flipped, it plays a corresponding audio file. My problem is, if the > switch remains flipped, the audio repeats again and again. What I would > like to do is when a switch is flipped have the audio play, then have the > code pause until the switch is returned to normal (not repeating the > audio), and then return to the while loop to poll for the next switch flip. > I am apparently not smart enough to figure out the correct code. I really > need some help with this and I would appreciate any assistance. > > Here is the code I'm working with. > > #!/usr/bin/env python > from time import sleep > import os > import RPi.GPIO as GPIO > GPIO.setmode(GPIO.BCM) > GPIO.setup(23, GPIO.IN) > GPIO.setup(24, GPIO.IN) > GPIO.setup(25, GPIO.IN) > while True: > if ( GPIO.input(23) == False ): > os.system('mpg321 -g 95 a.mp3') > if ( GPIO.input(24) == False ): > os.system('mpg321 -g 95 b.mp3') > if ( GPIO.input(25)== False ): > os.system('mpg321 -g 95 c.mp3') > sleep(1.1); > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > Using callbacks instead of polling might help. You can do something like this - def play(channel) : #your action here if channel == 23 : os.system('mpg321 -g 95 a.mp3') GPIO.add_event_detect(23, GPIO.RISING, callback=play) and similarly for the other pins. Check the "Events and Callback Functions" section of this tutorial - http://makezine.com/projects/tutorial-raspberry-pi-gpio-pins-and-python/ Cheers, Anish Tambe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with running an API
The usage of the api as documented here - https://github.com/zachwill/fred - suggests : >>> import fred # Save your FRED API key. >>> fred.key('my_fred_api_key') # Interact with economic data categories. >>> fred.category() ... Cheers, Anish Tambe On 26 Oct 2014 00:23, "Joel Goldstick" wrote: > On Sat, Oct 25, 2014 at 12:08 PM, Mark Meanwell > wrote: > > Hi Folks - new to python and trying to run an API. Running version > 2.7.3. on > > Windows 7 machine. > > > > Here is the scenario for the given API (FRED API in this case): > > > > easy_install Fred from C:\ - this installs to C:\site packages > > > > then I fire up the python shell and run file created for fred api: > > > > from fredapi import Fred > > fred = Fred(api_key='my api key') > > data = fred.get_series('SP500') > > > > keep getting below error message: > > ImportError: cannot import name Fred > > > > thanks for any suggestions! > > I'm not familiar with FRED, but a quick look on stackoverflow used the > lowercase name to import > > > > > > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > > > > > > -- > Joel Goldstick > http://joelgoldstick.com > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor