Re: [Tutor] FW: query
Hey guys can anybody tell me what's wrong with this code: The code is below?Actually the point is that when we put "34h4" type of value it's an valueerror but here no handling is been performed by the python ??? while 1: number=int(input("Enter the number which u want to check for odd and even :")) try : if number%2==0: print("The number",number ," is Even") else: print("The number ",number ," is Odd") except ValueError: print("Invalid Input") On Tuesday, 23 June 2015 11:32 PM, Alan Gauld wrote: On 23/06/15 18:13, Gupta, Manaswini Kat wrote: > I need to fetch the records of count(*)>3 can you please tell me the logic in > python Sorry, but that's not very clear. What do you mean? It looks like a bit of SQL so, are you asking how to execute that SQL from within Python? If so on what database? Or are you trying to convert SQL logic into pure Python code? If so that depends on how you are storing your records. Are they in a list, a dictionary, a flat file? Also count(*)>3 is a boolean expression so it will return True or False and no records. What do you mean by fetching the records? Which records? You probably need to show us an example of your data and the results you want. Maybe show us the full SQL query you are trying to execute or emulate. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ 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
Re: [Tutor] FW: query
On 6/24/2015 5:58 AM, abhijeet...@yahoo.in wrote: Hey guys can anybody tell me what's wrong with this code: The code is below? Actually the point is that when we put "34h4" type of value it's an valueerror but here no handling is been performed by the python ??? while 1: number=int(input("Enter the number which u want to check for odd and even :")) You're probably seeing the error here, which is outside your try/except block, hence the except not working as you expect. try : Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FW: query
On 24/06/15 13:58, abhijeet...@yahoo.in wrote: Hey guys can anybody tell me what's wrong with this code: The code is below? Please in future 1) start a new thread with a new post, do not hijack somebody else's query. It messes up the archive and threaded mail/newsreaders 2) Use plain text for posting code, your post is all messed up by the mail system so we can't see the code clearly. It is all on one line... Actually the point is that when we put "34h4" type of value > it's an valueerror but here no handling is been performed The handling only happens if it occurs inside a try block. It looks as if your type conversion (int(...)) happens outside the try block. The error is raised by the type conversion. while 1:number=int(input("Enter the number which u want to check for odd and even :"))try :if number%2==0: print("The number",number ," is Even")else:print("The number ",number ," is Odd") except ValueError:print("Invalid Input") Finally, handling an error by simply printing a bland error message is usually not a good idea. You effectively hide a lot of valuable debugging information. You would be better to just let Python print out its usual, much more helpful, error message. (The exception is where it's the top level of an end-user program where the Python trace might scare the users. But that should only be after you have thoroughly debugged it and handled most of the likely problem scenarios, and hopefully logged the error data into a logfile or sent it as an email to your support desk.) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Help
Hi, my name is Nirav. I have a question about my code. I am a student at a university that does research using a program called VisIt. We use VisIt to help our learning in computational fluid dynamics and using the information, we study the turbulence of scramjets. One simple thing I am trying to do is using python to call a command that processes all the files that exist within the directory by having visit access the files. I have started to code below, but every time the code is executed, I get an error that says, "u-name command not found" along with an error that says, "VisIt is not supported by platform." I know my information is hard to follow or comprehend, but I really need to find a way to get this code working. Thank you in advance! import osos.environ["PATH"]= '/Applications/VisIt.app/Contents/Resources/bin/'files = os.listdir('/Users/niravpatel/Desktop/Visit /plotfiles')print filesfor file in files: if '.py' in file: import subprocess subprocess.call(['visit', '-nowin', '-cli']) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Help
On 24/06/15 20:25, Nirav Patel via Tutor wrote: > ... research using a program called VisIt. One simple thing I am trying to do is using python to call a command that processes all the files that > exist within the directory by having visit access the files. I have started to code below, but every time the code > is executed, I get an error that says, "u-name command not found" along with an error that says, "VisIt is not supported by platform." Can you post the actual print out from your console in full? Also can you tell us what 'platform' you are using - OS, and VisIT and Python versions import osos.environ["PATH"]= '/Applications/VisIt.app/Contents/Resources/bin/'files = os.listdir('/Users/niravpatel/Desktop/Visit /plotfiles')print filesfor file in files: if '.py' in file:import subprocesssubprocess.call(['visit', '-nowin', '-cli']) Please post code in plain text, this is all in one line making it very hard to read. I'll try to unscramble it... > import os > os.environ["PATH"]= '/Applications/VisIt.app/Contents/Resources/bin/' > files = os.listdir('/Users/niravpatel/Desktop/Visit /plotfiles') > print files Looks like Python v2? I'm not sure why you are setting the PATH environment variable unless VisIT reads it? If so you do realize that setting it like this will wipe out all the existing entries? Finally is there supposed to be a space in the last folder name? > for file in files: > if '.py' in file: You are looping over the python files? Is that really what you want? > import subprocess Its usual to put all imports at the top of the file in one place. Not necessary but conventional. > subprocess.call(['visit', '-nowin', '-cli']) You are not specifying any input files/paths to visit so you just repeat the same command over and over. Do the commands PATH='/Applications/VisIt.app/Contents/Resources/bin/' visit -nowin -cli work at the command line? Or do you get different error messages? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor