Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Javier Collado
Hello, 2011/8/31 T. Goodchild : > But one of the things that bugs me is the requirement that all class > methods have 'self' as their first parameter.  On a gut level, to me > this seems to be at odds with Python’s dedication to simplicity. I think the answer to this question is part of the zen o

Re: parse html rendered by js

2011-02-12 Thread Javier Collado
Hello, 2011/2/11 yanghq : >    but for some pages rendered by js, like: You could use selenium or windmill to help you reproduce the contents of the web page in a browser so you can get the data from the DOM tree once the page has been rendered instead of by parsing the js. Best regards, Jav

Re: os.path.isfile and wildcard for directory name

2010-12-30 Thread Javier Collado
Hello, 2010/12/30 : > How can i do the same thing (wildcard in a directory name) in python please ? You can get the contents of a directory with os.listdir and filter with fnmatch.fnmatch more or less as in the example from the documentation: - import fnmatch import os for f

Re: Parsing markup.

2010-11-25 Thread Javier Collado
Hello, 2010/11/26 Joe Goldthwaite : > I’m attempting to parse some basic tagged markup. > >  Elementree and lxml seem to want a full formatted > page, not a small segment like this one. BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/) could help in the parsing: >>> from BeautifulSou

Re: re.sub unexpected behaviour

2010-07-06 Thread Javier Collado
Thanks for your answers. They helped me to realize that I was mistakenly using match.string (the whole string) when I should be using math.group(0) (the whole match). Best regards, Javier -- http://mail.python.org/mailman/listinfo/python-list

re.sub unexpected behaviour

2010-07-06 Thread Javier Collado
Hello, Let's imagine that we have a simple function that generates a replacement for a regular expression: def process(match): return match.string If we use that simple function with re.sub using a simple pattern and a string we get the expected output: re.sub('123', process, '123') '123' H

Re: fast regex

2010-05-06 Thread Javier Collado
Hello, 2010/5/6 james_027 : > I was working with regex on a very large text, really large but I have > time constrained. Does python has any other regex library or string > manipulation library that works really fast? re2 (http://code.google.com/p/re2/) is suppossed to be faster than the standard

Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?

2010-03-09 Thread Javier Collado
> I'm only aware of Hyde (http://ringce.com/hyde) There are also jekyll and cyrax: http://github.com/mojombo/jekyll/ http://pypi.python.org/pypi/cyrax/0.1.5 I haven't tried any of them, but it looks like cyrax is in active development and its design was inspired in both jekyll and hyde. Best reg

Re: python and http POST

2010-02-12 Thread Javier Collado
Hello, I haven't used httplib2, but you can certainly use any other alternative to send HTTP requests: - urllib/urllib2 - mechanize With regard to how do you find the form you're looking for, you may: - create the HTTP request on your own with urllib2. To find out what variables do you need to po

Re: Help parsing a page with python

2010-01-27 Thread Javier Collado
Hello, You can find some advice here: http://www.packtpub.com/article/web-scraping-with-python-part-2 Best regards, Javier 2010/1/27 mierdatutis mi : > Hello again, > > What test case for Windmill? Can you say me the link, please? > > Many thanks > > 2010/1/27 Javier

Re: Help parsing a page with python

2010-01-27 Thread Javier Collado
Hello, A test case for Windmill might also be used to extract the information that you're looking for. Best regards, Javier 2010/1/27 mierdatutis mi : > Those videos are generated by javascript. > There is some parser with python for javascript??? > > Thanks a lot! > > > 2010/1/27 Simon Brun

Re: scraping with urllib2

2010-01-27 Thread Javier Collado
Hello, To accept cookies, use the HTTPCookieProcessor as explained here: http://www.nomadjourney.com/2009/03/automatic-site-login-using-python-urllib2/ Best regards, Javier 2010/1/27 Andre Engels : > On Wed, Jan 27, 2010 at 6:26 AM, Patrick wrote: >> I'm trying to scrape the attached link f

Re: Python or Ant

2010-01-26 Thread Javier Collado
Hello, One tool that I really like is doit: http://python-doit.sourceforge.net/ If you need to execute jobs remotely, you may like to take a look at STAF: http://staf.sourceforge.net/index.php Best regards, Javier 2010/1/26 Chris Rebert : > On Tue, Jan 26, 2010 at 10:58 AM,   wrote: >> My c

Re: Sikuli: the coolest Python project I have yet seen...

2010-01-25 Thread Javier Collado
Hello, I think the site is under maintenance. I tried a couple of hours ago and it worked fine. As an alternative, I found that this link also worked: http://www.sikuli.org/ Unfortunately, it seems it's not working right now. Best regards, Javier 2010/1/25 Virgil Stokes : > On 25-Jan-2010

Re: subprocess troubles

2010-01-21 Thread Javier Collado
Hello, If you set shell=False, then I think that arg2 should be separated into two different parts. Also, arg3 could be set just to pattern (no need to add extra spaces or using str function). Best regards, Javier 2010/1/21 Tomas Pelka : > Hey all, > > have a problem with following piece of

Re: Symbols as parameters?

2010-01-21 Thread Javier Collado
Hello, I'd say that isn't totally incorrect to use strings instead of symbols. Please note that in other programming languages symbols, atoms and the like are in fact immutable strings, which is what python provides by default. Best regards, Javier 2010/1/21 Alf P. Steinbach : > * Martin Dra

Re: Ignore leading '>>>' and ellipsis?

2010-01-14 Thread Javier Collado
Hello, I think that's exactly what the cpaste magic function does. Type 'cpaste?' in your IPython session for more information. Best regards, Javier 2010/1/14 Reckoner : > > Hi, > > I am studying some examples in a tutorial where there are a lot of > leading >>> characters and ellipsis in th

Re: When to use mechanize and Windmill library during WebScraping ?

2009-12-12 Thread Javier Collado
Hello, If a script that uses mechanize fails to find an html node that has been identified with Firebug, this is probably because that node has been autogenerated (provided that the expression to get the node is correct). As an alternative to verify this, you can try to download the html page and

Re: How to specify Python version in script?

2009-11-11 Thread Javier Collado
Hello, If you are working on linux, you can change the shebang line from: #!/usr/bin/python to: #!/usr/bin/python2.6 Best regards, Javier P.S. If you just want to avoid python 3 while running the latest python 2.x version, this should also work: #!/usr/bin/python2 2009/11/11 Benjamin Kapla

Re: substituting list comprehensions for map()

2009-11-02 Thread Javier Collado
Hello, I'll do the following: [op1+op2 for op1,op2 in zip(operandlist1, operandlist2)] Best regards, Javier 2009/11/2 Jon P. : > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will

Re: the usage of 'yield' keyword

2009-10-14 Thread Javier Collado
Hello, I think that the best information available on the subject is the following: http://www.dabeaz.com/generators/ http://www.dabeaz.com/coroutines/ Best regards, Javier 2009/10/14 Peng Yu : > http://docs.python.org/reference/simple_stmts.html#grammar-token-yield_stmt > > The explanation

Re: Where to find pexpect

2009-10-13 Thread Javier Collado
Hello, Google is your friend: http://sourceforge.net/projects/pexpect/ http://sourceforge.net/projects/pexpect/files/pexpect/Release%202.3/pexpect-2.3.tar.gz/download Best regards, Javier 2009/10/13 Antoon Pardon : > I have been looking for pexpect. The links I find like > http://pexpect.sou

Re: Distributing Python-programs to Ubuntu users

2009-09-25 Thread Javier Collado
Hello, I recommend you to check this: https://wiki.ubuntu.com/PackagingGuide/Complete The best way to release the software to Ubuntu users is by means of a PPA (https://help.launchpad.net/Packaging/PPA) so that people can track your application updates automatically. Before the PPA is created you

Re: lambda functions

2009-08-31 Thread Javier Collado
Hello, This page has some advice about how to avoid some of the lambda functions limitations: http://p-nand-q.com/python/stupid_lambda_tricks.html In particular, it suggests to use map function instead of for loops. Best regards, Javier 2009/8/31 Pierre : > Hello, > > I would like to know i

Re: OptionParser How to: prog [options] [arguments]

2009-08-14 Thread Javier Collado
Hello, I think that this isn't possible with optparse library. However, it's possible with argparse (http://code.google.com/p/argparse/): http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#sub-commands It's not a standard library, but it's worth to take a look at it. Best regards,

Re: Non-blocking read with popen subprocess

2009-07-31 Thread Javier Collado
Hello, According to my experience and from what I've read in other threads, subprocess isn't easy to use for interactive tasks. I don't really know, but maybe it wasn't even designed for that at all. On the other hand, pexpect seems to work fine for interactive use and even provides a method for

string.Template issue

2009-07-30 Thread Javier Collado
Hello, In the string.Template documentation (http://docs.python.org/library/string.html) it's explained that if a custom regular expression for pattern substitution is needed, it's possible to override idpattern class attribute (whose default value is [_a-z][_a-z0-9]*). However, if the custom pat

Re: Config files with different types

2009-07-03 Thread Javier Collado
Hello, Have you considered using something that is already developed? You could take a look at this presentation for an overview of what's available: http://us.pycon.org/2009/conference/schedule/event/5/ Anyway, let me explain that, since I "discovered" it, my favourite format for configuration

Re: packaging apps

2009-06-30 Thread Javier Collado
Hello, Regarding packaging for debian (.deb), the best reference I've found is: https://wiki.ubuntu.com/PackagingGuide/Python However, all that mess probably won't be needed anymore once this is finished: https://blueprints.edge.launchpad.net/ubuntu/+spec/desktop-karmic-automagic-python-build-sys

Making code run in both source tree and installation path

2009-06-29 Thread Javier Collado
Hello, I would like to be able to run the main script in a python project from both the source tree and the path in which it's installed on Ubuntu. The script, among other things, imports a package which in turns makes use of some data files that contains some metadata that is needed in xml format

Re: Calling subprocess with arguments

2009-06-19 Thread Javier Collado
Hello, The problem might be that, aside from creating the Popen object, to get the command run you need to call 'communicate' (other options, not used with the Popen object directly, are 'call' or 'waitpid' as explained in the documentation). Did you do that? Best regards, Javier 2009/6/19 T

Re: Question about None

2009-06-12 Thread Javier Collado
Hello, You're right, types.NoneType is not available in python 3.0, I wasn't aware of that change. Thanks for pointing it out. Best regards, Javier 2009/6/12 Jeff McNeil : > On Jun 12, 10:05 am, Paul LaFollette > wrote: >> Kind people, >> >> Using Python 3.0 on a Gatesware machine (XP). >>

Re: Question about None

2009-06-12 Thread Javier Collado
Hello, This should work for you: In [1]: import types In [2]: isinstance(None, types.NoneType) Out[2]: True Best regards, Javier 2009/6/12 Paul LaFollette : > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that

Re: getop or optparse with option with spaces?

2009-06-10 Thread Javier Collado
Hello, It's strange behaviour. Have you tried argparse (http://code.google.com/p/argparse/)? I've been using it for long time without any problem like that? Best regards, Javier 2009/6/10 David Shapiro : > Hello, > > I have been trying to find an example of how to deal with options that have

Re: Start the interactive shell within an application

2009-06-09 Thread Javier Collado
Take a look either at code.interact or at IPython.ipapi.launch_new_instance. Basically, the only thing that you have to provide is a dictionary object that contains the namespace that you would like to have in your shell once it's launched. Best regards, Javier 2009/6/9 eGlyph : > On Jun 9, 1

Re: PYTHONPATH and multiple python versions

2009-06-05 Thread Javier Collado
Hello, I think that virtualenv could also do the job. Best regards, Javier 2009/6/5 Red Forks : > maybe a shell script to switch PYTHONPATH, like: > start-python-2.5 > start-python-2.4 ... > On Fri, Jun 5, 2009 at 4:56 PM, David Cournapeau wrote: >> >> Hi, >> >> As I don't have admin privil

Re: Global variables from a class

2009-05-29 Thread Javier Collado
You're right. I agree on that it's important to use proper words. Thanks for the correction. Best regards, Javier 2009/5/29 Steven D'Aprano : > On Fri, 29 May 2009 12:04:53 +0200, Javier Collado wrote: > >> Hello, >> >> First thing is a class variable

Re: Global variables from a class

2009-05-29 Thread Javier Collado
Hello, First thing is a class variable (one for every instance) and second one an instance variable (one per instance). For further information, please take a look at: http://diveintopython.org/object_oriented_framework/class_attributes.html Best regards, Javier 2009/5/29 Kless : > I usually

Re: Is there a GUI for informing a user of missing dependencies?

2009-05-12 Thread Javier Collado
Hello, I'm not an expert, but if you use setuptools for your application, then a 'install_requires' argument would do the job. For more information, please take a look at: http://peak.telecommunity.com/DevCenter/setuptools Best regards, Javier 2009/5/12 Jason : > I'm writing a small GUI (Pyt