Re: [Tutor] What style do you call Python programming?
On Fri, Dec 9, 2011 at 3:54 PM, Sarma Tangirala tvssarma.ome...@gmail.comwrote: On 9 December 2011 20:07, Cranky Frankie cranky.fran...@gmail.com wrote: I'm looking for a term to call the kind of Python programming that ...snip... The keyword you are looking for is 'programming paradigm' and python implements several and not just any specific one such as structured. You could call it a multi-paradigm programming language. http://en.wikipedia.org/wiki/Programming_paradigm ...snip.. The point is its a scripted language. Most of what you want to do should be about a line. Python is derived from the idea of scripted languages wherein constructs like loops and functions were added for more control. The main idea of programming in python is not essentially writing a functions but rather like shell scripting, one line of syntax at a time. Having functions, for example, gives you greater control or rather an abstraction of control for clarity of thought. I actually don't agree at all with your last statements. Since you quote Wikipedia, allow me to do the same: http://en.wikipedia.org/wiki/Python_(programming_language) * * *Python supports multiple programming paradigms, primarily but not limited to object-oriented, imperative and, to a lesser extent, functional programming styles. It features a fully dynamic type system and automatic memory management, similar to that of Scheme, Ruby, Perl, and Tcl. Like other dynamic languages, Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts. Using third-party tools, Python code can be packaged into standalone executable programs. Python interpreters are available for many operating systems.* Keywords, IMHO are: imperative, object oriented, interpreted dynamic programming language. Scripting comes as a bonus of the fact that it is interpreted. My 0.02€ /dario ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to use int and split() simultaneously
oh, yes, no top posting. See below. On Thu, Dec 8, 2011 at 1:33 PM, surya k sur...@live.com wrote: This is something I am trying to do.. Say, we are entering a string 1 2 3 4 5.so, I want to assign the numbers directly as numbers. how can I do it? I could put that numbers as string but not as number.. strNum = raw_input('enter:').split() I can convert the list into numbers by doing this... for i in range(len(strNum)): strNum[i] = int(strNum[i]). but I feel, its a long process. How can I do it in the shortest possible way?? Using a list comprehension is one example of a compact way of doing it: strNum = raw_input(enter numbers, separated by space: ).split() strNum = [int(x) for x in strNum] You would have to assume that the entire string consists of tokens that can be type cast into integers. If not you get an error: strNum = raw_input(enter numbers, separated by space: ).split() enter numbers, separated by space: 1 2 3 4 5 66 asd strNum = [int(x) for x in strNum] Traceback (most recent call last): File stdin, line 1, in ? ValueError: invalid literal for int(): asd In that case a for loop with a try-except would better: strNum = raw_input(enter numbers, separated by space: ).split() num_list = [] for token in strNum: try: num_list.append(int(token)) except ValueError: # Do nothing, fetch the next token continue print repr(num_list) This code gives this result: enter numbers, separated by space: 1 2 3 4 5 66 [1, 2, 3, 4, 5, 66] enter numbers, separated by space: 1 2 3 4 5 66 asd 77 [1, 2, 3, 4, 5, 66, 77] Strictly speaking the continue in the except clause is not necessary in this simple example. Hope this helps! /dario ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IndentationError:
The indentation is indeed off: Original code: def PlotPathway(list1): for i in range(len(list1)): for j in range(len(list1[i])-1): if list1[i][j] != list1[i][j+1]: g.add_edge(list1[i][j], list1[i][j+1]) if list1[i][j]=42: g.node_attr.update(color='deepskyblue',style='filled') if list1[i][j] 42: g.node_attr.update(color='green',style='filled') What I think you meant: def PlotPathway(list1): for i in range(len(list1)): for j in range(len(list1[i])-1): if list1[i][j] != list1[i][j+1]: g.add_edge(list1[i][j], list1[i][j+1]) if list1[i][j]=42: g.node_attr.update(color='deepskyblue',style='filled') if list1[i][j] 42: g.node_attr.update(color='green',style='filled') Notice that I *consistently* use 4 spaces, and *only spaces, not tabs,* for each indentation level. In your code (assuming the copy paste I did was correct) I could see a mixture in the number of spaces for each indentation level. The error was the python interpreted the second and third if statements as being not properly indented, becuase of the lack of consitency: 1. they did not align with the first if statement in side the for loop 2. the did not align with the for-loop either, so there could not be intrepreted as being on the same level as the for loop. Hope this makes sense and helps! Best regards, /dario On Wed, Nov 16, 2011 at 8:52 AM, lina lina.lastn...@gmail.com wrote: Why it keeps on complaining: $ python plot-pathway.py File plot-pathway.py, line 35 if list1[i][j]=42: ^ IndentationError: unindent does not match any outer indentation level def PlotPathway(list1): for i in range(len(list1)): for j in range(len(list1[i])-1): if list1[i][j] != list1[i][j+1]: g.add_edge(list1[i][j], list1[i][j+1]) if list1[i][j]=42: g.node_attr.update(color='deepskyblue',style='filled') if list1[i][j] 42: g.node_attr.update(color='green',style='filled') I checked the indentation very carefully, seems no problems. really no clue, Thanks with best regards, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Cython vs Python-C API
Hi, just a thought - have you looked at NumPy/SciPy? Perhaps there already is an API in C that does what you need, sufficiently well/fast? http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html It is part of the NumPy/SciPy package(s). http://www.scipy.org/ /dario On Tue, Nov 15, 2011 at 9:09 AM, Stefan Behnel stefan...@behnel.de wrote: cubic spline interpolation ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Cython vs Python-C API
On Tue, Nov 15, 2011 at 10:26 AM, Stefan Behnel stefan...@behnel.de wrote: Dario Lopez-Kästen, 15.11.2011 09:33: On Tue, Nov 15, 2011 at 9:09 AM, Stefan Behnel wrote: cubic spline interpolation No, I didn't. Stefan Oops, apologies. My reply was meant for Jaidev (OP), but I got the quoting wrong. /dario ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [OSX] Executable .py or pyc script (stuck at Applescript)
Try PyInstaller http://www.pyinstaller.org/ /dario On Nov 14, 2011 2:43 PM, learner404 learner...@gmail.com wrote: On Fri, Nov 11, 2011 at 12:02 AM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: It is probably easiest to keep myapp.py in the home directory (or subdirectory of it) and say python ~/myapp.py (or python ~/.roadierich/myapp.py) from the applescript I will go with that for now. My python script is using a bunch of relative paths so I added this before the script: if sys.platform==darwin: os.chdir(os.path.expanduser(~/myfolder/)) I will try to see if there's something like inno setup to make an installer. If anyone have something to recommend for this i'm interested. Thanks Ramit and all. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor