Re: [Tutor] Subclassing vs. stand alone functions
[EMAIL PROTECTED] wrote: Let's say you want to load a dictionary. Do I create a function that accepts some argument (say a file name) and returns a dictionary, or do I subclass dict and override the __init__ and __setitem__ functions to make 'self-loading' dictionary? It seems the end result is the same. I am not understanding, what you mean by loading a dictionary or a value in python. You mean creating a custom dictionary? Then, a) obj = Dict(list_of_tuples) b) obj = mydict{} c) def fun(): # process it and store in dict. return mydict These are are various ways. Now, the question is when do you subclass? Only when you want to extend the behaviour of particular class. For e.g, you want to extend the Exception class to define your own Exception, then you will subclass it. Class MyException(Exception): def __init__(self): pass def __str__(self): return My Exception, Hurray! The same, can applied to dictionary, say you want extend the behaviour of dictionary with a get a random key-value pair. Next is, what if you want different instances of a class. Well, those are the Objects. In the class you define a property which can be variable and set those property values when you create the objects from that Class. Do you subclass WebPage for each particular page you want (because you can customize it with load functions for each piece of data) or do you just use it as is, and create separate functions outside the class that load the data and Objects. (I can send code samples if it will help). Sure, please do. I might not check the email on sat/sun. But others here are ofcourse very helpful. I hope my explaination help u a bit. Thanks, -- Senthil Your own mileage may vary. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] #!/usr/bin/env python vs #!/usr/local/bin/python
Okay, I guess, people are missing points here. When do you #!/usr/local/bin/python You are specifying the location to the python executable in your machine, that rest of the script needs to be interpreted with. You are pointing to python is located at /usr/local/bin/python Consider the possiblities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, the above #! will fail. For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly. Thus, #/usr/bin/env python Will figure out the correct location of python ( /usr/bin/python or /bin/python from $PATH) and make that as the interpreter for rest of the script. - ( env is almost always located in /usr/bin/ so one need not worry what is env is not present at /usr/bin) Hope this helps. -- Senthil The price of seeking to force our beliefs on others is that someday they might force their beliefs on us. -- Mario Cuomo From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Duncan Sent: Thursday, June 14, 2007 19:44 To: tutor@python.org Subject: Re: [Tutor] #!/usr/bin/env python vs #!/usr/local/bin/python On 6/14/07, Ezra Taylor [EMAIL PROTECTED] wrote: I think Emilia means what's the difference. From what little I know, #!/usr/bin/env python will choose the first python that's in your path. Were as the second option, you explicitly choose which instance of python you want. I'm using using python from Activestate. So my shebang is to the Activestate directory for python. If I'm wrong, please correct. Ezra On 6/14/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi list, how to choose between #!/usr/bin/env python and #!/usr/local/bin/python in the beginning of the script ? e. - SCENA - Ĺäčíńňâĺíîňî ÁĹÇĎËŔŇÍÎ ńďčńŕíčĺ çŕ ěîáčëíč ęîěóíčęŕöčč č ňĺőíîëîăčč. http://www.bgscena.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Ezra Taylor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor The real difference here is that by using the env command, you have the option to input many different settings preferences before calling the python of your choice. The statement above, is a very simple choice of the python based upon the current environment, but it could be augmented very easily. I suggest that you check out the man page for the command env. -- David Duncan Registered Linux User #279425 http://counter.li.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urlencode
From: Lee Jones Subject: [Tutor] urlencode Hello, I am trying to urlencode a string. In python the only thing I can see is the urllib.urlencode(). But this takes a dictionary, and returns key=value, which is not what I want. I only want to url-encode a string. Does any one know how to do this in python Are you looking for urllib.quote() ? import urllib url = urllib.quote('http://puggy.symonds.net/~senthil') print url http%3A//puggy.symonds.net/%7Esenthil -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ActivePython and CPython
What are the difference between ActiveState's Python distributions and the standard Python distribution from python.org http://python.org , and which is better? Answer: Python from python.org is Open Source Software developed under OSI compatible license. Bunch of Python Developers are working on fixing bugs and releasing next version of python on various platforms. ActiveState provides a commertial distribution of same python with support options. They have a custom built installer, which will install extra modules like Python Windows Extensions and Documentation like regex tutorials and Mark Pilgrim's excellent work Dive Into Python. All these are available for download from web however. I dont think there is a question of which is better. Both are better, check with your requirements. If you willing to contribute back to python community and raise bugs against Python software, download and use the latest from python.org Also, what IDE will give a user the ability to view HTML designs of a web application as well as the code view (like Dreamweaver does with PHP pages)? Answer: PyDev for Eclipse turns Eclipse into a pretty good IDE for Python. You may figure out similar extension for Eclipse for HTML development as well. That would satisfy your need. As it said, Eclipse is an IDE for any thing in general and nothing in particular. HTH. Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] a very simple question
Carson Wendy wrote: ok, i just started python and i'm stuck on this, could use some help :D a='test' def f(): a=a+'gg' Look for the definition of 'global' And try this: a = 'test' def f() global a a = a + 'gg' print a f() -- Senthil Dish of the Day: Good evening, madame and gentlemen. I am the main dish of the day. May I interest you in parts of my body? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Best IDE for Python
Dick Moores wrote: Hi, I am using vim editor to code my project in python.Is there a good IDE where in I type the name of the class object and then dot then all the attributes of the object are displayed so on. I believe IPython does this. Check out http://ipython.scipy.org/moin/. Vim 7.0 has the omni complete facility, which will help you complete.. --- object.c-xc-nattributes. Also, python 2.5 IDLE and (Mark Hammonds) PythonWin Editor supports command completion. -- Senthil Capitalism is the astounding belief that the most wickedest of men will do the most wickedest of things for the greatest good of everyone. Keynes ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Use Python to learn kids (9 yr) to program
Hi, Playing with Guido Van Robot http://gvr.sf.net is another good option to teach programming to young ones. Rurple is just another graphic representation of the gvr. -- Senthil From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andre Roberge Sent: Wednesday, November 29, 2006 8:26 PM To: [EMAIL PROTECTED] Cc: bp Subject: Re: [Tutor] Use Python to learn kids (9 yr) to program HI- I think Python is a great choice. You may want to have a look, as a first step, at rur-ple http://rur-ple.sourceforge.net . Then, as a next step (although it might be a bit steep), you may want to have a look at livewires http://www.livewires.org.uk/python/ . This will provide a good introduction to pygame http://www.pygame.org . André On 11/29/06, Anders Persson [EMAIL PROTECTED] wrote: Hi! I have looked around for som language to use to learn my 9 year son programming. There is a KPL - Kids Programming Language but my son diden't grasp the OO, GUI and everyting around this, maby becurse English is not his spoken language, and for a beginner i think the inviroment was to complex. So my plan is to use Python, has anyone try to learn kids this way, and could giv som ide how-to. I witch way to introduce every part of the language,,, best regards Anders ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Use Python to learn kids (9 yr) to program
Andre Roberge wrote: On 11/29/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, Playing with Guido Van Robot http://gvr.sf.net is another good option to teach programming to young ones. Rurple is just another graphic representation of the gvr. Not quite. GvR uses a Python-like notation and has no OOP support. Rur-ple uses standard Python and has OOP support. André Thanks for clarifying Andre. Infact, myself and my young friends started with GVR, after completing it. I analyzed rur-ple. On the surface, I found it similar (if not the same). We were more interested with programming than python. For the purpose of introduction to programming to young ppl, does GVR or Rurple really make a difference? We are trying to play with squeak now, but little progress so far. You might like to know about my friend Avi, we tried gvr and trying squeak and trying to understand freeciv: http://puggy.symonds.net/~senthil/Phoenix/Avi_Quiz.ppt -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT: Vim was: free IDE for Python?
William O'Higgins Witteman wrote: On Fri, Nov 17, 2006 at 11:02:18AM +0530, [EMAIL PROTECTED] wrote: What the settings of ppl using vim for python? A few Python-specific things that I have in my .vimrc are as follows: Thanks for sharing William. I think ppl in this list , might also be interested in this _vimrc ( I am on windows) snippet, which on pressing Alt+D over a module name will take us to its documentation. function! OnlineDoc() if ft =~ python let s:urlTemplate = http://docs.python.org/lib/module-%.html; else return endif let s:browser = \C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\ let s:wordUnderCursor = expand(cword) let s:url = substitute(s:urlTemplate, %, s:wordUnderCursor, g) let s:cmd = silent !start . s:browser . . s:url execute s:cmd endfunction online doc search map silent M-d :call OnlineDoc()CR - It is written with modifications from vim tips page. Thanks, -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT: Vim was: free IDE for Python?
Hi Alan, Greetings. Alan Gauld wrote: I have to chuckle when you recommend Vim for ease of use. Me too, and I've been a vi/elvis/viper/vim user for over 20 years(*). vi/vim could never be described as easy to learn, but... I too use vim for a variety of editing tasks. From xml, python to normal text editing, not a power user yet. Do you have any tips/tricks to share for python on vim. Your vimrc file or any plugins you use. How would you run the python script from vim? - !python % OR any other way? I dislike the command line window popup to execute the scripts. (and press Enter key twice). I kindda wish, that Hot-Key for !python % should :split the window and display the results for non-interactive run. If interactive session, the cmd.exe could stay open.. What the settings of ppl using vim for python? -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] documentation/sourceforge bug help
C or L Smith wrote: I know this is off topic, but can anyone give me a hand? I have a sourceforge account. I want to make a correction to the python documentation. I click on the appropriate link at the bottom of the documentation page and then the bug tracker link on the page that I am sent to which takes me to http://sourceforge.net/bugs/?group_id=5470 1) Log in to http://sf.net with your account. 2) Click the above link to submit a bug. 3) There you go! I was able do it. Thanks, -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying tio emulate diff command of UNIX - please help
Hi, Your program does not emulate the diff command of Unix. Please do a diff in unix and experience yourselves. Where is cmp_res = stringcmp(string1[i],string2[i]) stringcmp() function written? Moreover, if you Python Documentation install (orpython.org accessible) search for difflib and Differ Example. That should give you a good start. Thanks, -- Senthil From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Asrarahmed KadriSent: Friday, October 06, 2006 6:09 PMTo: tutor@python.orgSubject: [Tutor] Trying tio emulate "diff" command of UNIX - please help # This program emulates the diff command of UNIX import sysfrom stringCompare import stringcmp # this is a module which has stringcmp function that compares two strings fname1 = raw_input("Enter a file name to be read:\t") fname2 = raw_input("Enter a file name to be read:\t") fd1 = open(fname1,"r")fd2 = open(fname2,"r") done = 0line_counter = 0 while not done: aLine1 = fd1.readline() aLine2 = fd2.readline() if (aLine1 == "" or aLine2 == ""): # test whether you have reached the end of file done = 1 else: line_counter += 1# get the line number string1 = aLine1.split() # split the line into a listcontaining words string2 = aLine2.split () len1 = len(string1) len2 = len(string2) if len1 len2: t = len1 else: t = len2 i = 0 while (i t): cmp_res = stringcmp(string1[i],string2[i]) if cmp_res != 0: column = i done = 1 print "The difference is lies in the ", line_counter ,"line and column ", column Can someone help me with what is wrong in this code; when I am running it gets stuck. thanks in anticipation. Regards, Asrar -- To HIM you shall return. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Inverse range
I am playing with Python. Playing as in learning. Is it possible to reverse a range sequence? If, for instance, I call: for f in range( 1,5 ): print f Is it possible to reverse it? As in: 4 3 2 1 Yes, there is a normally unused third parameter to range used to control the step size. It can bew negative so: range(4,0,-1) And then there is also this reversed() call: for f in reversed(range(1,5)): print f 4 3 2 1 Thanks, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] program-code dilemma
-Original Message- From: Damian Sent: Wednesday, July 05, 2006 12:36 PM To: tutor@python.org Subject: [Tutor] program-code dilemma Although, from what I've found I been able to get this conclusions. Program.- A sequence of instructions that can be executed by the computer. Code.- Just the instructions of the program. The problem is that it seems too complicated for a definition so important and essential to start learning to program (that without getting account of what is missing for the completeness of the definition). ___ Damian: I don't understand how much 'programming' will you learn by understanding the difference between the terminologies of 'code' and 'program'. My suggestion will be ignore that, see them as one and the same and carry forward with learning other things and concepts. I doubt, you will be confused with any concept which is exaplained using either of the terminologies. Frankly speaking, I don't know the difference between 'code' and the 'program'. For me, its synonymous. I write Code. I do programming.I program. Do you get it? -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need python 2.4 rpm for Suse 9.1
try at rpmfind.net or google it. but the immediate thought which comes up in my mind is: "use the source, luke" -- Senthil From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Akanksha GovilSent: Wednesday, June 21, 2006 5:36 PMTo: tutor@python.orgSubject: [Tutor] Need python 2.4 rpm for Suse 9.1 Hi,I searched the sites but was unable to find Python 2.4 rpm for Suse 9.1.Please send me a link where I can download this.ThanksAkanksha Yahoo! Sports Fantasy Football 06 - Go with the leader. Start your league today! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] C++ tutor
I am a grad student at Berkeley looking for a C++ tutor. Might you offer any suggestions? Thank you, http://groups.google.com/group/alt.comp.lang.learn.c-c++?lnk=li Is a list fot c,c++ similar to what this list serves for python. So, there u go. Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problems with the shebang line and linux
bash: ./testerlybar.py: /usr/bin/python^M: bad interpreter: No such file or directory [EMAIL PROTECTED]:/media/windata$ Note the ^M the additional fileformat character inserted. That is causing the problem. Instead of copying and pasting try to use cp file1 file2. Else, open the copied file and try to remove ^M from it. Under vim, it is :%s/\r//g ( this removed the additional line break character which your editor or something had introduced. -- Senthil -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brian van den Broek Sent: Thursday, February 16, 2006 7:06 PM To: Tutor Subject: [Tutor] problems with the shebang line and linux Hi all, I've switched to Linux fairly recently and am still at the fumbling about stage :-) I'm having a devil of a time with the shebang line and running a py file from a command line. I wrote the following little test script with IDLE 1.1.2 under Python 2.4.2 on Ubuntu 5.10: code #!/usr/bin/python print Working! /code I then C P'ed it to another .py file. testerlyfoo.py is the original, testerlybar.py is the pasted copy. Here's my command line results: [EMAIL PROTECTED]:~$ which python /usr/bin/python [EMAIL PROTECTED]:~$ cd /media/windata/ [EMAIL PROTECTED]:/media/windata$ ./testerlyfoo.py Working! [EMAIL PROTECTED]:/media/windata$ ./testerlybar.py bash: ./testerlybar.py: /usr/bin/python^M: bad interpreter: No such file or directory [EMAIL PROTECTED]:/media/windata$ I even retyped the testerlybar.py file, but I end up with the same results as when the small script was copied and pasted. Likewise, I got the same results after saving the two files to my Home directory on the hail mary thought that perhaps the fact I'd save the originals on a FAT32 mounted drive might be making things goofy. I'm stumped. Any steps I can take to work out what's going on? Best to all, Brian vdB ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Change files
David, in getfiles, the os.getcwd() points the main programs cwd only and so shutil.copy() fails. so changing toname = os.path.join(root,name) helps us get the file in the directory we checked against. def getfiles(file1,file2,top): for root, dirs, files in os.walk(top): for dirname in dirs: print dirname for name in files: if name == file1: name = os.path.join(root,name) print "the name is" + name shutil.copy(file2,name) print "copied one file" print os.getcwd() import osimport shutil#maintop = r'c:\temp'a = os.getcwd()filename = 'some.txt'file1 = filenamefile2 = a+ os.sep +filenameprint file2getfiles(filename, file2,top)print "finished" thanks! --Senthil From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David HollandSent: Sunday, February 12, 2006 3:40 AMTo: BruceCc: tutor pythonSubject: Re: [Tutor] Change files Bruce,Thanks but is was not the solution. It goes through all the directories but does not seem to work.Here is the modified code :-def getfiles(file1,file2,top): for root, dirs, files in os.walk(top): for name in dirs: print name for name in files: if name == file1: name = os.getcwd()+'/'+name print "the name is" + name shutil.copy(file2,name) print "copied one file" print os.getcwd()import osimport shutil#maintop = '/home'a = os.getcwd()filename = 'abcde'file1 = filenamefile2 = a+'/'+filenameprint file2getfiles(filename, file2,top)print "finished"DavidBruce [EMAIL PROTECTED] wrote: I guess that you need to fix two things:1 the indentaion error after for name in files:2 specify full path for the destination arg in shutil.copyOn 2/10/06, David Holland wrote: I wrote a little program that replaces all files called 'abcde' with the file in the directory from which you riun the program. However it does not find them (there is another one). What have I done wrong :- #this program copies the file x to all other places in the directory. #however it does not go to the right places def getfiles(file1,file2,top): for root, dirs, files in os.walk(top): for name in dirs: for name in files: if name == file1: shutil.copy(file2,name) print "copied one file" import os import shutil #main top = '/home' a = os.getcwd() filename = 'abcde' file1 = filename file2 = a+'/'+filename getfiles(file1, file2,top) print "finished" To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Yahoo! Photos NEW, now offering a quality print service from just 8p a photo. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor