Re: [Tutor] how to instantiate a class
@Abhishek, On 2/26/09, Abhishek Kumar wrote: > hello list, > > Below is the sample code of a class. > > > import > > Class ABC: > def __init__(self,a,b,c): > statement 1 > statement 2 > def func(x,y): >statement 1 >statement 2 > > Here is the question: > > how to make an object of this class and how to use the methods listed > in the class. you can make object newobj = ABC() using the methods would be newobj.func() > do i need to create the object in a separate file or in the same file > it can be done ?? It's upto you. You can create the object in the same file or separate file, both works. kindly read the documentation, especially the tutorial section. It's one of the best available resources for learning python. http://docs.python.org/ > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Regards, Arun Tomar blog: http://linuxguy.in website: http://www.solutionenterprises.co.in ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] installation of scipy
hi! Bala. On Mon, Mar 30, 2009 at 3:57 PM, Bala subramanian wrote: > Friends > i installed scipy in fedora10 using yum. when i import stats module in it, i > got the following warning. someone pls englihten me on this. > >>>> from scipy import stats > /usr/lib/python2.5/site-packages/scipy/sparse/linalg/dsolve/linsolve.py:20: > DeprecationWarning: scipy.sparse.linalg.dsolve.umfpack will be removed, > install scikits.umfpack instead > ' install scikits.umfpack instead', DeprecationWarning ) > deprecation is the way in python through which the developers warn the user or the other developers that, a certain feature that has been mentioned, would be removed or not available from the next release. so as of now, just enjoy & ignore the error. by the next release cycle, developers of scipy will need remove the deprecated code or use the suggested packages in the deprecation warning. > Thanks, > Bala > > ___ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- Regards, Arun Tomar blog: http://linuxguy.in website: http://www.solutionenterprises.co.in ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Web crawling!
Hi! Raj. On Wed, Jul 29, 2009 at 9:29 PM, Raj Medhekar wrote: > Does anyone know a good webcrawler that could be used in tandem with the > Beautiful soup parser to parse out specific elements from news sites like > BBC and CNN? Thanks! > -Raj > As i didn't find any good webcrawler as per my clients need, so i wrote one for them, but it's specific for their need only. i can't disclose any more details about it. In short, i'm using my app to crawl the specific sites, then parse it with beautiful soup and extract all the links on that page, then visit the links and search for the keywords on those pages. If the keyword is occurs more than the specified limit then it's a useful link and store it in the database or else leave it. -- Regards, Arun Tomar blog: http://linuxguy.in website: http://www.solutionenterprises.co.in ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python regex help
hi! i've data extracted in the form of list using regex. it looks something like the one below. print reobj ['Jyoti Soni - 0 Year(s) 0 Month(s)\n', 'Tel: 09975610476(M)\n', '\n', 'Minal - 0 Year(s) 0 Month(s)\n', 'Tel: 9890498376(M)\n', '011 02162 250553(R)\n'] i'm trying to use regex to remove the following information 1. - 0 Years * 2. Tel: & (M) 3. (R) & store the remaining portion as a new list. I've been using shell scripting & using sed & pipes i've solved it, but with python, i need to practice more ;). regds, arun. signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python regex help
On Sun, 2008-09-28 at 17:26 +0100, Alan Gauld wrote: > "Arun Tomar" <[EMAIL PROTECTED]> wrote > > > I've been using shell scripting & using sed & pipes i've solved it, > > but with python, i need to practice more ;). > > Can you show us some output as you'd like irt? > Can you show us the sed script that works? sample data: Contact Candidate Jyoti Soni - 0 Year(s) 0 Month(s) MCA Keyskills: C , C + + , Java , JSP , Oracle , S / W Testing B.Sc Pt.Ravishanker University,Raipur MCA Pt.Ravishanker University,Raipur Currently in: Pune CTC(p.a): Not Disclosed Modified: 27 Sep 2007 Tel: 09975610476(M) Account Information Account Information Contact Candidate Minal - 0 Year(s) 0 Month(s) MCA Keyskills: c , c + + , java , ASP . NET , VB , Oracle , Dimploma in Web Designing B.Sc Shivaji University , Maharasthra MCA Shivaji University , Maharashtra Currently in: Pune CTC(p.a): INR 0 Lac(s) 5 Thousand Modified: 27 Jan 2006 Last Active: 06 Sep 2007 Tel: 9890498376(M) 011 02162 250553(R) Account Information Account Information small shell scripts that works: #!/bin/bash print $1 sed -ne '/Contact/,+1p' -e '/Tel/p' $1 |sed -e '/Contact Candidate/d'| sed -e 's/\-//'|sed -e '/^$/d'|sed -e 's/ *$//'|sed -e 's/Tel://g' -e 's/(M)//g' -e 's/0 Year(s) 0 Month(s)//g' -e 's/(R)//g' -e '/> Similar Resumes/d' sample output Jyoti Soni 09975610476 Minal 9890498376 > > Also can you show us the Python code that doesn't work > and what went wrong? Its easier to fix what's broken than > to guess at what might do what you want :-) python code that works, after that i'm a bit lost ;) import re filename = "script.txt" #regex pattern p1 = re.compile("Contact Candidate",re.IGNORECASE) p2 = re.compile ("Tel:", re.IGNORECASE) #open the file fh = open(filename,'r') #read the contents of the file to an array. file_array = fh.readlines() #create an empty array new_array = [] mod_array = [] for i in range(len(file_array)): if p1.search(file_array[i]): new_array.append(file_array[i+1]) if p2.search(file_array[i]): new_array.append(file_array[i]) new_array.append(file_array[i+1]) basically i'm trying my hand with text manipulation with python. i'm thorough with shell scripting, sed & awk. after this data is extracted i would like to convert it to a csv file, then i would like to insert the data into a database etc etc. i hope this gives a good idea of what i'm trying to do. regds, arun. signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python regex help
On Sun, 2008-09-28 at 17:26 +0100, Alan Gauld wrote: > "Arun Tomar" <[EMAIL PROTECTED]> wrote > > > I've been using shell scripting & using sed & pipes i've solved it, > > but with python, i need to practice more ;). ok, i got it. here is the code that needs to be included after code in the last mail ;) sub1 = "(-.*)|(Tel:)|\(M\)|\(R\)" new_reg = re.compile(sub1) for n in range(len(new_array)): mod_array.append(new_reg.sub('',new_array[n])) cheers, arun. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] vim python debugging
hi! I"m trying to setup vim for python debugging mode. But it gives me error. Has anyone succeeded in doing so. link: http://code.google.com/p/vimpdb/ ideally I'm trying to evaluate vim & emacs as command line editors & debugging for python. arun. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] vim python debugging
On Sun, 2008-09-28 at 22:12 -0600, Alec Henriksen wrote: > It would be very helpful to include the error message you received... I > can't help you, but just a thought. > > On Mon, 2008-09-29 at 09:39 +0530, Arun Tomar wrote: > > hi! > > > > I"m trying to setup vim for python debugging mode. But it gives me > > error. Has anyone succeeded in doing so. > > > > link: > > http://code.google.com/p/vimpdb/ > > > > ideally I'm trying to evaluate vim & emacs as command line editors & > > debugging for python. > > error that i get: http://code.google.com/p/vimpdb/issues/detail?id=3 regds, arun. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] list to csv
hi! I've a list new_array = ['n1', 'm1', 'p1', 'n2', 'm2', 'p2', 'n3', 'm3', 'p3'] I am trying to convert this to a csv in 3 columns so that the final output would look something like this "n1","m1","p1" "n2","m2","p2" "n3","m3","p3" regds, arun. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] automatically generate python/pylons documentation
hi! I'm trying to generate documentation for my pylons web application. my personal opinion: 1. pudge: I've reviewed pudge. it was not very useful & hard to know as most of the links are not working on the site and lack of support. 2. epydoc I liked epydoc, the generated document looks more like what is generate by ruby tools, i guess rdoc. if i give it a single python file it works fine. but if i want epydoc to go into a specific folder & generate the documentation for all the files & files in the sub directories, it doesn't automatically do that. any pointers there. 3. sphinx: i've read a little about it. haven't tried it yet. my objective is to automatically generate documentation for my entire pylons webapp or any other python application. regds, arun. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] automatically generate python/pylons documentation
hi! On Sat, Oct 18, 2008 at 5:17 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Fri, Oct 17, 2008 at 10:18 AM, Arun Tomar <[EMAIL PROTECTED]> wrote: >> hi! >> >> I'm trying to generate documentation for my pylons web application. > >> 2. epydoc >> I liked epydoc, the generated document looks more like what is >> generate by ruby tools, i guess rdoc. if i give it a single python >> file it works fine. but if i want epydoc to go into a specific folder >> & generate the documentation for all the files & files in the sub >> directories, it doesn't automatically do that. any pointers there. > > I have used epydoc to create docs for entire packages by giving it the > package name on the command line. The package must be in the current > Python path. > > Looking at epydoc's own makefile it appears that you can also specify > a directory. I've a pylons web application in the directory called helloworld. if i give the command for epydoc to generate the documentation it gives the below mentioned errors: epydoc helloworld/ Error: Directory 'helloworld/' is not a package Error: Nothing left to document! Can you guide me how can i accomplish this task. > Kent > Regds, Arun. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] automatically generate python/pylons documentation
hi! On Sat, Oct 18, 2008 at 10:42 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > "Arun Tomar" <[EMAIL PROTECTED]> wrote >> >> if i give the command for epydoc to generate the documentation it >> gives the below mentioned errors: >> >> epydoc helloworld/ >> Error: Directory 'helloworld/' is not a package >> Error: Nothing left to document! > > What happens if you don;t pass the trainiling slash: > > epydoc helloworld if i do not give a trailing slash, the output is like this epydoc helloworld +--- | In helloworld: | No documentation available! | Error: Import failed: |ImportError: No module named helloworld | Error: Nothing left to document! > > Alrternatively just make it a package by creating an init.py file as > suggested by Marc > > Alan G creating a __init__.py file does the trick but not completely. epydoc helloworld +--- | In /tmp/helloworld/setup.py: | Import failed (but source code parsing was successful). | Error: SystemExit: usage: (imported) [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] | or: (imported) --help [cmd1 cmd2 ...] | or: (imported) --help-commands | or: (imported) cmd --help | |error: no commands supplied (line 30) | +--- | In /tmp/helloworld/helloworld/websetup.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named config.environment (line 7) | +--- | In /tmp/helloworld/helloworld/config/middleware.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named config.environment (line 13) | +--- | In /tmp/helloworld/helloworld/config/environment.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named lib.app_globals (line 6) | +--- | In /tmp/helloworld/helloworld/controllers/template.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named lib.base (line 1) | +--- | In /tmp/helloworld/helloworld/controllers/error.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named lib.base (line 6) | +--- | In /tmp/helloworld/helloworld/tests/__init__.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named config.middleware (line 33) | +--- | In /tmp/helloworld/helloworld/tests/test_models.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named config.middleware (line 33) | +--- | In /tmp/helloworld/helloworld/tests/functional/__init__.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named config.middleware (line 33) | +--- | In /tmp/helloworld/helloworld/lib/base.py: | Import failed (but source code parsing was successful). | Error: ImportError: No module named lib.helpers (line 13) | Warning: No information available for helloworld.helloworld.lib.base.BaseController's base pylons.controllers.WSGIController Warning: 1 markup error was found while processing docstrings. Use the verbose switch (-v) to display markup errors. this creates a directory with the documentation which is working but as you can see there are some import errors. regds, arun ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
hi! On Sun, Nov 23, 2008 at 5:07 PM, David <[EMAIL PROTECTED]> wrote: > Hello everybody, > > I recently came across a book by Prof. Langtangen: Indroduction to Computer > Programming: http://folk.uio.no/hpl/INF1100/INF1100-ebook-Aug08.pdf > > I am trying to solve exercise 1.18 ("Why does the following program not work > correctly?"), but I don't find the mistake: why does the line > > q = sqrt(b*b - 4*a*c) problem here is that the method sqrt doesn't accepts -negative numbers which in this case is the outcome of the expression above. to rectify that u can use the following q = sqrt(math.fabs(b*b - 4*a*c)) basically convert the negative number to absolute number, rest of the stuff will work. > > cause an error? I was playing around with the code, but got nowhere. > > Here the entire code: > > a = 2; b = 1; c = 2 > from math import sqrt > q = sqrt(b*b - 4*a*c) > x1 = (-b + q)/2*a > x2 = (-b - q)/2*a > print x1, x2 > > > Many thanks for a pointer! > > David > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Regards, Arun Tomar blog: http://linuxguy.in ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lists
hi! On Tue, Jan 20, 2009 at 10:30 PM, Kent Johnson wrote: > On Tue, Jan 20, 2009 at 11:30 AM, Norman Khine wrote: >> Hi >> What am I doing wrong >> >>>>> media_list = ['upper_b.wav', 'upper_a.wav'] >>>>> print '%s' % (for x in media_list) >> File "", line 1 >>print '%s' % (for x in media_list) >>^ >> SyntaxError: invalid syntax >>>>> print '%s' % (x for x in media_list) >> >> >> I want to replace %s with the items of the list as individual item string, >> i.e >> >> 'upper_b.wav', 'upper_a.wav' > > I'm not sure what you want, maybe one of these? > > In [1]: media_list = ['upper_b.wav', 'upper_a.wav'] > > In [2]: print ', '.join(media_list) > upper_b.wav, upper_a.wav > > In [3]: print ', '.join(repr(x) for x in media_list) > 'upper_b.wav', 'upper_a.wav' > > Kent may be you want to do it this way: In [10]: for x in media_list: : print "%s" % x : : upper_b.wav upper_a.wav -- Regards, Arun Tomar blog: http://linuxguy.in website: http://www.solutionenterprises.co.in ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor