Re: [Tutor] PyVISA GPIB
Hi Mark, On Fri, Apr 1, 2011 at 11:42 AM, markri...@gsoftcon.com wrote: I would like to control electronic instruments with PyVISA. I have downloaded PyVISA and unpacked the files into the Python27/lib/site-packages dir and in the IDLE GUI I run import visa' for a quick check and I get this error: import visa Traceback (most recent call last): File pyshell#25, line 1, in module import visa ImportError: No module named visa I'm scratching my head. Help Mark R Rivet, Genesis Software Consulting ASCT(Computer Technologies), BSIT/SE(Software Engineering) Electrical Engineering Technician Member IEEE, Computer Society Do or do not; there is no try. Could this be the problem? PyVISA doesn’t implement VISA itself. Instead, PyVISA provides bindings to the VISA library (a DLL or “shared object” file). This library is usually shipped with your GPIB interface or software like LabVIEW. Alternatively, you can download it from your favourite equipment vendor (National Instruments, Agilent, etc). quote from this document: http://pyvisa.sourceforge.net/pyvisa.pdf ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PyVISA GPIB
Sorry, On Fri, Apr 1, 2011 at 1:00 PM, Donald Bedsole drbeds...@gmail.com wrote: Hi Mark, On Fri, Apr 1, 2011 at 11:42 AM, markri...@gsoftcon.com wrote: I would like to control electronic instruments with PyVISA. I have downloaded PyVISA and unpacked the files into the Python27/lib/site-packages dir and in the IDLE GUI I run import visa' for a quick check and I get this error: import visa Traceback (most recent call last): File pyshell#25, line 1, in module import visa ImportError: No module named visa I'm scratching my head. Help Mark R Rivet, Genesis Software Consulting ASCT(Computer Technologies), BSIT/SE(Software Engineering) Electrical Engineering Technician Member IEEE, Computer Society Do or do not; there is no try. Could this be the problem? PyVISA doesn’t implement VISA itself. Instead, PyVISA provides bindings to the VISA library (a DLL or “shared object” file). This library is usually shipped with your GPIB interface or software like LabVIEW. Alternatively, you can download it from your favourite equipment vendor (National Instruments, Agilent, etc). quote from this document: http://pyvisa.sourceforge.net/pyvisa.pdf I read the document a little better and visa is supposed to be part of the function. But maybe something else in the document might help you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Guessing Game Program
Hi folks, This is a little program I've written to bring together some things I've been trying to learn (not an attempt, of course, to make an interesting game).. I've been working my way through a beginner's tutorial, and except for a very basic program I wrote in C++ one time, I think this is the first program I've ever done from scratch. Of course, I've incorporated ideas I've learned from folks on the Internet, my tutorial, and this list. Im sure I've broken some rules along the way, but it does work without any errors (that I have found). So, how could I improve it? Is it readable to you, or a mess? Thanks for your time, Don #Author D.Bedsole #drbedsole at gmail.com #3/24/10 #License: Public Domain import random from sys import exit #A guessing game where user must guess a number between 1 and 10 def start_up(): print Hello, and welcome to the Guessing Game. Here are the rules:\n print Try to guess the correct number. It is between 1 and 10. print You have ten chances. print To quit the game just type 'quit' (w/o the quotes) at the prompt.\n print Here we go!\n def ran_num(): the_number = random.randint(1,10) return the_number def guess_loop(the_number): start_number = 0 while start_number 10: print Please guess a number between 1-10. Enter your guess at the prompt. guess = (raw_input( )) if exit in guess: #Give user a chance to exit w/o finishing game print Thanks for playing. Goodbye! exit() if guess.isdigit(): #validate input guess = int(guess) else: print You didn't enter a number. continue #Return to top of the loop so user can enter number if guess the_number: print Sorry. You guessed too high. start_number += 1 attempt_counter(start_number, the_number)#warn user of remaining tries elif guess the_number: print Sorry. That was too low.\n start_number += 1 attempt_counter(start_number, the_number)#warn user of remaining tries else: print Congratulations. You guessed it!\n print Do you want to play again? Type 'y' for yes and 'n' for no response = raw_input( ) if 'y' in response: start_up(guess_loop(ran_num())) else: print Thanks for playing. Goodbye. exit() #Track guesses attempted and warn of end of game when chances exhausted def attempt_counter(start_number, the_number): print That was attempt #%d. % (start_number) if start_number == 10: print That was your last chance. The correct answer was %d. % (the_number) print Do you want to start a new game. Type 'y' for yes and 'n' for no. answer = raw_input( ) if 'y' in answer: start_up(guess_loop(ran_num())) else: print Thanks for playing. Goodbye. exit() #function calls to start program start_up() guess_loop(ran_num()) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Guessing Game Program
On Fri, Mar 25, 2011 at 12:53 AM, Donald Bedsole drbeds...@gmail.com wrote: Hi Malcolm :-) On Fri, Mar 25, 2011 at 12:37 AM, Malcolm Newsome malcolm.news...@gmail.com wrote: Hey Don! I posted an eerily similar request to another python group about two weeks ago! I, too, am very new to programming and the guessing game was my first shot at writing a script from scratch! I got interested in writing a guessing game because I was trying to fix a C++ program that wouldn't compile with g++ because they were using a non-standard randomizer() function. (I really don't know C++, but I thought trying to fix the problems with someone else's program might help me to learn). I didn't make much headway in understanding how to generate random numbers in C++, but it made me curious about how to do it in Python. Python seems much easier! Below is my code (improved with some help from others). I still would like to make some improvements to it also. But, perhaps there will be some ideas in it that can help you as well! Looking forward to learning and growing! All the best! Malcolm Thanks for posting your code. I will look at it later (closing in on 1:00 AM here) to see what I can learn from it. Tutorials are great, but it seems looking at code makes it easier for me to learn. Thanks for taking the time to post, and I hope you're successful in your programming studies. Don ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error in programming
Hi Lea, On Fri, Mar 25, 2011 at 1:27 AM, Lea Parker lea-par...@bigpond.com wrote: Hello Just wondering if you have some time to cast your eyes over another basic program. # Prompt user for data def main(): print 'This program is to calculate your ticket sales to the softball game' print #blank line # Value of each level of seat a_seat = 15.00 b_seat = 12.00 c_seat = 9.00 # Obtain data sales_a = int (raw_input('Enter the number of class A tickets sold ')) sales_b = int (raw_input('Enter the number of class B tickets sold ')) sales_c = int (raw_input('Enter the number of class C tickets sold ')) income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c) # Obtain data to determine income generated from sales def income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c): total_sales = times the seat value by the number of seats sold for each seat and add totals togeter(sale_a * a_seat) + (sale_b * b_seat) + (sale_c * c_seat) #Display result to user print int ('Your total sales for the softball game are: $ ', total_sales) # Call the main function main() I get the following errors: RESTART This program is to calculate your ticket sales to the softball game Enter the number of class A tickets sold 5 Enter the number of class B tickets sold 5 Enter the number of class C tickets sold 10 Traceback (most recent call last): File F:/Backups/MY Documents26.2.11/Documents/Lea University/CSU/ITC10 - Programming Principles/2011/Assessment Tasks/Assessment 1b and 1c/Stadium_Seating.py, line 29, in module main() File F:/Backups/MY Documents26.2.11/Documents/Lea University/CSU/ITC10 - Programming Principles/2011/Assessment Tasks/Assessment 1b and 1c/Stadium_Seating.py, line 18, in main income_generated(a_seat, b_seat, c_seat, sales_a, sales_b, sales_c) File F:/Backups/MY Documents26.2.11/Documents/Lea University/CSU/ITC10 - Programming Principles/2011/Assessment Tasks/Assessment 1b and 1c/Stadium_Seating.py, line 23, in income_generated and add totals togeter(sale_a * a_seat) + (sale_b * b_seat) + (sale_c * c_seat) NameError: global name 'sale_a' is not defined My way of thinking is firstly I need to fix line 29 which is main(), I tried to do this by adding the brackets around text output in line 26. This seemed to allow me to type main against margin rather than it wanting to indent but didn’t fix the problem. Your suggestions would be appreciated. Thank Lea Don't know if it's the only problem, but : NameError: global name 'sale_a' is not defined I think this comes from the fact that you spelled one variable name sale_a in one place, and up where you originally assigned it you spelled it, sales_a. Don ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] help with user input
I'm going through a tutorial called Learn Python the Hard Way by Zed Shaw. At the end of his lessons he has Extra Credit sessions, and I'm stuck on one. I'm on lesson 35, here is a link to it: http://blamcast.net/python/ex35.html The lesson involves creating a very simple text based game. One of the functions accepts user input: def gold_room(): print This room is full of gold. How much do you take? next = raw_input( ) if 0 in next or 1 in next: how_much = int(next) else: dead(Man, learn to type a number.) if how_much 50: print Nice, you're not greedy, you win! exit(0) else: dead(You greedy bastard!) The instruction from the Extra Credit section reads: The gold_room has a weird way of getting you to type a number. What are all the bugs in this way of doing it? Can you make it better than just checking if 1 or 0 are in the number? Look at how int() works for clues. I have read the documentation for int() and done some googling, but no lights have come on. :-) Here is what I have so far: def gold_room(): print This room is full of gold. How much do you take? next = raw_input( ) if next = 50: how_much = int(next) else: dead(You were too greedy.) if how_much 50: print Nice, you're not greedy, you win! exit(0) else: dead(Man, learn to type a number!) This works fine as long as the user enters a number. However, if they enter anything else, they just get the first :else statement, You were too greedy. My googling found solutions using an exception, but that hasn't been introduced yet in the tutorial. How would you solve this without using an exception? Thanks for any help, Don ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help with user input
Thank you, Marc On Mon, Mar 21, 2011 at 4:47 PM, Marc Tompkins marc.tompk...@gmail.com wrote: On Mon, Mar 21, 2011 at 1:12 PM, Donald Bedsole drbeds...@gmail.com wrote: This works fine as long as the user enters a number. However, if they enter anything else, they just get the first :else statement, You were too greedy. I think that's because you're trying to do a string comparison, rather than a numeric comparison. (if next = 50:) You need to convert 'next' to an int FIRST, then compare to 50, not 50. My googling found solutions using an exception, but that hasn't been introduced yet in the tutorial. How would you solve this without using an exception? If you don't want to use an exception, check the entered value first (note: I haven't checked my code, so caveat lector) - next = raw_input() if next.isdigit(): if int(next) 50: print Nice, you're not greedy, you win! else: dead(You were too greedy.) else: dead(Man, learn to type a number!) isdigit() returns True if every character is a digit; False otherwise. http://docs.python.org/library/stdtypes.html Using an exception: next = raw_input() try: if int(next) 50: print Nice, you're not greedy, you win! else: dead(You were too greedy.) except ValueError: dead(Man, learn to type a number!) Note that I specified ValueError - you want to make your exception handling as specific as possible, so that if really unforeseen things go wrong, your program doesn't blindly treat them as normal. In other words, if any exception other than ValueError were to pop up here, you would want the program to terminate and show you a traceback so you could fix it. It'll take me awhile to digest this. Thanks for your time and your help. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python.py with no console
Hi folks, On Fri, Mar 18, 2011 at 3:16 PM, Alan Gauld alan.ga...@btinternet.com wrote: sihong lin linsihong2...@yahoo.com wrote Those days the idle couldn't open in windows 7. Today I found the type of file python.py(c:\Python27\lib\idlelib) is no console. what is it means? that is why the idle couldn't open, right? No, that just means you don't get a black DOS window in the background. But since I don't have Win 7 I can't comment on the reason you have an IDLE problem, but I believe it should work OK in Windows 7. Can anyone else confirm? -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ IDLE opens ok for me on Windows 7. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python.py with no console
Hello, On Fri, Mar 18, 2011 at 12:46 PM, sihong lin linsihong2...@yahoo.comwrote: hi, Those days the idle couldn't open in windows 7. Today I found the type of file python.py(c:\Python27\lib\idlelib) is no console. what is it means? that is why the idle couldn't open, right? thanks Sharon Can you start Python from a command prompt? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New to programming
Hi, Welcome to the list: On Fri, Mar 18, 2011 at 7:48 PM, Savyn - OpenERP Mail openerpm...@gmail.com wrote: Dear Everyone I am new to programming (a passion mainly). I have no background in programming. The python.org beginner tutorial seems hard after a few chapters or not sure how to merge requirement with the tutorials. Where and how should I start programming with python for complete beginner? Many thanks Sav Here's the tutorial I'm doing now. It's for complete programming beginners: http://learnpythonthehardway.org/index Allen Gault (a member of this list) also has a tutorial for beginners at his site: http://www.alan-g.me.uk/ Don ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Hi Jack, On Wed, Mar 16, 2011 at 1:50 AM, Jack Trades jacktradespub...@gmail.com wrote: On Wed, Mar 16, 2011 at 12:22 AM, Donald Bedsole drbeds...@gmail.com wrote: not (False and True) Python evaluates it as True 1)You evaluate what's in the parentheses first. A thing can not be false and true at the same time, so the answer is false. Yes, the expression in the parenthesis is evaluated first. However it's not just one thing being evaluated. 'and' evaluates one argument at a time and returns immediately if the argument is False. In this case there are 2 distinct 'things'. False and True. False, obviously, evaluates to False, which causes 'and' to stop and return False. This reduces the expression to... not False 2)However, the not outside the parentheses flips the meaning of what is inside the parentheses, so false becomes True. ? Correct, the expression not False evaluates to True. Ok, so, as another example: not(True and False) is True because: the first argument True is true, and the second argument False when returned is negated by not becomes not False which evaluates to True? Thanks for the help! Btw, you're blog looks interesting; I'm going to have to check it our more closely later. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Hi Allen, Boolean algebra can be a weird thing to get your head around the first time you come across it :-) Yes, :-) Here are some of the standard rules: True and thing = thing False and thing = False True or thing = True False or thing = thing Thanks for your response and for the rules, but for some reason I'm not understanding. In the above quote, what is meant by thing? Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
On Wed, Mar 16, 2011 at 5:53 PM, bob gailer bgai...@gmail.com wrote: Thing in this context means 'anything. could be a string, number, list, any Python object. Ok, thanks Bob. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Boolean question
Hi Jack, On Wed, Mar 16, 2011 at 1:55 AM, Jack Trades jacktradespub...@gmail.com wrote: 'and' evaluates one argument at a time and returns immediately if the argument is False. And or works in the inverse manner? It evaluates one argument at a time and returns immediately if the argument is [True]. ? For example, not (True or False) False The first argument was True, so True was returned and negated by the not with a final result of False for the expression. Is this correct? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] first steps
Hi Ryan, Also, when it works correctly, IDLE won't run the program again via the chaos.main() statement. I get this: Traceback (most recent call last): File pyshell#1, line 1, in module chaos.main() NameError: name 'chaos' is not defined I think IDLE is looking for a file name to run. If your file name is chaos.py, use that. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] first steps
Ryan, Did you enter it like this at the prompt: chaos.main() statement If so, that's a problem. Your function was called: main(), so if you type chaos.main(), Python doesn't know what you're talking about. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor