C# and Python

2007-08-21 Thread subeen
Hi,
I am a newcomer in Python.  I am going to write a small Python
application that will run in windows xp. This application needs to
have GUI. Is it possible to make a C# application using visual studio
2005 that will call the python scripts? Let me explain more here:
My program will generate a text file of 100 - 10 random integers,
and sort those using various sorting methods. Now I have written
separate sorting scripts in Python (quick sort, insertion sort etc.).
But I want to write the GUI and number generation program in C#.net.
When the user clicks Quick Sort button, the quicksort.py will be
called and it will sort the numbers.

regards,
Subeen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C# and Python

2007-08-21 Thread subeen
On Aug 21, 7:24 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 8/21/07, Ant <[EMAIL PROTECTED]> wrote:
>
> > On Aug 21, 11:01 am, subeen <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > ...
> > > But I want to write the GUI and number generation program in C#.net.
> > > When the user clicks Quick Sort button, the quicksort.py will be
> > > called and it will sort the numbers.
>
> > Probably worth looking at IronPython, the Python implementation for
> > the .Net platform.
>
> > --
>
> Also Pythonnet (see the recent announce on this ML), which is a
> .NET/CPython bridge and supports embedding CPython as well as calling
> .NET code from CPython.

Thanks everyone for your valuable suggestions. I shall let you know my
status.

Regards,
Subeen.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C# and Python

2007-08-23 Thread subeen
On Aug 21, 5:00 pm, Bikal KC <[EMAIL PROTECTED]> wrote:
> subeenwrote:
> > When the user clicks Quick Sort button, the quicksort.py will be
> > called and it will sort the numbers.
>
> One way to do this:
> In your C# app, have the mouse click event handler call python
> interpreter "/path/to/python /path/to/quicksort.py". Make quicksort.py
> write to a file the result. After the quicksort.py finishes, read the
> file from your normal C# app.
>
> Cheers.

Hi, what's the C# function to call python interpreter?

regards,
Subeen.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 5 queens

2007-12-22 Thread subeen
Hi,

The problem you are trying to solve is a very famous and common
problem which can be solved by backtracking. Please try google with 8
queens problem or n queens problem.

>
> I designed in JavaScript a small program on my website called 5
> queens.
> (http://www.cf29.com/design/dame5_eng.php)
>
> The goal is to control all the chess board with five queens that do
> not attack each other. I found "manually" many solutions to this
> problem (184 until now) and wanted to create a Python script to find
> them all. As I am new to Python, I struggle a lot.
>
> I found a way to create:
> - a board where each square is defined by its row, column and if it is
> controlled or not
> - a function that tells which squares are controlled by a queen on a
> particular square
> - a function that counts how many squares are controlled
> - a function that can reset all squares control to 0
> - a function that can place 5 queens safely on the board
> - I can find the first solution and register it in a list
>
> My problem starts now. How can I find the next solution and append it
> to the list? Has anyone tried to do a such script? If anyone is
> interested to help I can show what I've done so far.

Try to generate the next permutation and check if it's a valid
solution. Need to use recursion for this.

regards,
Subeen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Useful site for beginners

2008-02-10 Thread subeen
This website can be helpful for Python newbies: http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regarding html source code

2008-02-11 Thread subeen
Another way:

import urllib2

usock = urllib2.urlopen('http://abc.com')
data = usock.read()
usock.close()

print data




On Feb 12, 12:05 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> shashank jain top-posted:
>
>
>
> > On Feb 11, 2008 11:15 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> >> jainshasha wrote:
> >>> well i have create a program which can read out the html source code
> >>> files or any other web page source code files through my program so
> >> Like this?
>
> >>  >>> from lxml import html
> >>  >>> page = html.parse("http://www.google.com";)
> >>  >>> print page.find("//title").text
> >>  Google
>
> >>http://codespeak.net/lxml
>
> > well i would like to know how python can help me in doing this or if u think
> > any other language please help me out
>
> What I showed you was Python code that reads an HTML file. What else do you 
> need?
>
> Stefan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a web visitor counter available in Python ...

2008-02-12 Thread subeen
Well, you don't need to worry about code, you can just copy paste the
code of the hit counters available for free.

In my blog, http://love-python.blogspot.com/ I am using two type of
hit counters (both are free). You can try them. They generate code
that you just paste in the source code of your website.


Regards,
Subeen.



On Feb 12, 11:37 am, "W. Watson" <[EMAIL PROTECTED]> wrote:
> PHP. Well, that's a new one on me. Google gave me some idea of what it's
> about, and I found some code on how to do it. It requires yet another
> "programming language", which means finding the editor, etc.
>
>
>
> Jon "Fluffy" Saul wrote:
> > On Feb 11, 2008 9:21 PM, W. Watson <[EMAIL PROTECTED]> wrote:
> >> ... that is free for use without advertising that I can use on my web 
> >> pages?
> >> I have no idea is suitable for this. My knowledge of Python is somewhat
> >> minimal at this point. Maybe Java is better choice.
>
> >> --
> >>   Wayne Watson (Nevada City, CA)
>
> >> Web Page: 
> >> --
> >>http://mail.python.org/mailman/listinfo/python-list
>
> > PHP would be the best choice.
> > Simple and advanced PHP hit counters can be found with a search of Google.
> > "PHP hit counter", etc.
>
> --
>   Wayne Watson (Nevada City, CA)
>
> Web Page: 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

2008-02-13 Thread subeen
hmm... interesting

here is another way you can find prime numbers
http://love-python.blogspot.com/2008/02/find-prime-number-upto-100-nums-range2.html



On Feb 13, 9:31 pm, [EMAIL PROTECTED] wrote:
> I was reading up on this site [http://www.noulakaz.net/weblog/
> 2007/03/18/a-regular-expression-to-check-for-prime-numbers/] of an
> interesting way to work out prime numbers using Regular Expression.
>
> However my attempts to use this in Python keep returning none
> (obviously no match), however I don't see why, I was under the
> impression Python used the same RE system as Perl/Ruby and I know the
> convert is producing the correct display of 1's...Any thoughts?
>
> def re_prime(n):
> import re
> convert = "".join("1" for i in xrange(n))
> return re.match("^1?$|^(11+?)\1+$", convert)
>
> print re_prime(2)
>
> Also on a side note the quickest method I have come across as yet is
> the following
>
> def prime_numbers(n):
> if n < 3: return [2] if n == 2 else []
> nroot = int(n ** 0.5) + 1
> sieve = range(n + 1)
> sieve[1] = 0
> for i in xrange(2, nroot):
> if sieve[i]:
> sieve[i * i: n + 1: i] = [0] * ((n / i - i) + 1)
> return [x for x in sieve if x]
>
> Damn clever whoever built this (note sieve will produce a list the
> size of your 'n' which is unfortunate)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ROUNDING???

2008-02-18 Thread subeen
You can use the round() function. And if you want to print, use %0.2f


regards,
Subeen.
http://love-python.blogspot.com/


On Feb 19, 9:36 am, [EMAIL PROTECTED] (Aahz) wrote:
> In article <[EMAIL PROTECTED]>,
> katie smith  <[EMAIL PROTECTED]> wrote:
>
>
>
> >in python im doing the problem 255/494
>
> >it keeps giving me 0 instead of .51
> >what am i doing wrong?
> >>> from __future__ import division
> >>> 2/5
>
> 0.40002
>
> In addition:
>
> >>> division
>
> _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
>
> Therefore this works in Python 2.2 and higher.
> --
> Aahz ([EMAIL PROTECTED])   <*>http://www.pythoncraft.com/
>
> "All problems in computer science can be solved by another level of
> indirection."  --Butler Lampson

-- 
http://mail.python.org/mailman/listinfo/python-list


firefox cache & Python

2008-02-19 Thread subeen
Hi,

I have got into an interesting problem. Today I found that if I type
"about:cache?device=disk" (without the quotes) in the address bar of
firefox, it displays disk cache information. Now I am thinking to
write a Python program that will read this cache info. My initial idea
is to somehow save the page in a file and parse it. But how to save
the page without human intervention (pressing ctrl+s) :) ?

Hope I could make it clear what I am trying to do...

Any clue?

regards,
Subeen.
http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: firefox cache & Python

2008-02-20 Thread subeen
Searching for FF automation but still no luck.

Any other idea on how to locate the cache directory and then read the
directory ?

regards,
Subeen
http://love-python.blogspot.com/

On Feb 20, 3:20 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
>
> Search for "firefox automation"
>
> --
> Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is this data structure build-in or I'll have to write my own class?

2008-02-20 Thread subeen
I think you should go for 'dictionary' that is a built-in data
structure of Python.


regards,
Subeen
http://love-python.blogspot.com/


On Feb 20, 7:32 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
> 2008/2/20 Jarek Zgoda <[EMAIL PROTECTED]>:> Jorge Vargas napisa³(a):
>
> > > - attribute access (or index)
> > > - maintain the order (for iter and print)
> > > - be mutable.
>
> > These are all attributes of standard Python lists.
>
> probably I confused you with the "or index" part. I want to be able to
> do item.value1 or item['value1'] the list can't do this.
>
> > > in case there isn't one. I was thinking having a base class like Bunch
> > >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308and on
> > > top of that keeping a list of the keys and pop/push to the list when
> > > adding/deleting items. I don't like this idea because I'll have to
> > > keep each key twice. (in the list and in __dict__, is this the only
> > > way of doing it?
>
> > What is your objective? From the description of this recipe I cann't get
> > your use case.
>
> I got an xml object which feed me in data. in a simple format
> 
> foo
> bar
> baz
> bal
> 
>
> I want to turn this into a datastructure I can manipulate in my
> program for example.
>
> >>> print myItem.property1
> >>> if myItem.property1[value1] > 0:
>
>print 'ok'
>
> >>> print myItem
>
> {'property1':'value1','property2,'value2'}
>
>
>
>
>
> > --
> > Jarek Zgoda
> > Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101
>
> > "We read Knuth so you don't have to." (Tim Peters)
> > --
> >http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie in python

2008-02-21 Thread subeen
Dive into Python is a very good book but it's for people who have
experience in other languages. I liked the book.
Whatever book you read, please take a look at the Python Tutorial:
http://docs.python.org/tut/tut.html, it will help.

regards,
Subeen.
http://love-python.blogspot.com/



On Feb 21, 6:01 pm, 7stud <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hi anyone
>
> > I'm very interesed to learn python and really willing to do so,but
> > unfortunately dont know where to start, or what programs need to
> > install to start.
>
> > Can someone help me to get in the right track, and get a good move?
>
> > Thanks for all help
>
> If you're a good student or you have prior programming experience, get
> the book 'Learning Python', which just came out with a 3rd edition, so
> it is the most up to date book.
>
> If you are not such a good student or have no prior programming
> experience, and you want a gentler introduction to python, check out
> the book 'Python Programming for the Absolute Beginner(2nd Ed.)'

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: global variables: to be or not to be

2008-02-22 Thread subeen
Another way to avoid using global variables is to return more than one
values from the function.

Here is an example that may help you to understand it:

def foo(a, b, c):
a += c
b += c
return a, b

a = 5
b = 10
c = 2
print a, b
a, b = foo(a, b, c)
print a, b


regards,
Subeen.
http://love-python.blogspot.com/


On Feb 23, 9:11 am, icarus <[EMAIL PROTECTED]> wrote:
> I've read 'global variables' are bad.  The ones that are defined as
> 'global' inside a function/method.
>
> The argument that pops up every now and then is that they are hard to
> keep track of.  I don't know Python well enough to argue with that.
> Just started learning it a few days ago, so I won't get into
> philosophical questions such as "why this? Why not that?".  I'll take
> it as it is, just like I take 1 + 1 = 2 for granted.
>
> So..."global variables taste bad.  Avoid them."
>
> But how do I get around it? How do I update and access a variable
> anytime I want? Any easy-to-follow examples? Thanks in advance.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent of system()?

2008-02-23 Thread subeen
This link may help: 
http://love-python.blogspot.com/2008/02/execute-linux-commands-in-python.html

On Feb 23, 10:44 am, Max <[EMAIL PROTECTED]> wrote:
> Is there a Python equivalent of C++'s system()?
>
> TIA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: most loved template engine on python is?

2008-02-24 Thread subeen
On Feb 25, 1:01 am, Tamer Higazi <[EMAIL PROTECTED]> wrote:
>
> Question:
> Which is the most loved template engine for python?
>


I am learning MAKO and I think it's good. But can't tell that it's the
best as I didn't try others. :)

regards,
Subeen.
http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: buliding log files

2008-02-26 Thread subeen
On Feb 26, 3:58 pm, Thinker <[EMAIL PROTECTED]> wrote:
> diljeet kaur wrote:
> > hi
> > im working on pyqt environment
> > i want to know how to take log or how to build log files of the output
>
> > 
> > Looking for last minute shopping deals? Find them fast with Yahoo!
> > Search.
> > <http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newse...>
>
> Please check module logging.
>http://docs.python.org/lib/module-logging.html
> It provides facility of system log of UN*X like systems.


This tutorial will also help: 
http://www.onlamp.com/pub/a/python/2005/06/02/logging.html


regards,
Subeen
http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: rstrip error python2.4.3 not in 2.5.1?

2008-02-28 Thread subeen
rstrip() works fine in python 2.4.3. May be the problem lies in
somewhere else.

I tried it in FC6 with Python 2.4.3:
>>> url = "abc.com\n"
>>> url.rstrip()
'abc.com'


regards,
Subeen.
http://love-python.blogspot.com/

On Feb 29, 2:30 am, dirkheld <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I wrote some python code that retrieves urls from a txt file. In this
> code I use .rstrip() for removing the '\n' at the end of every url.
> While this code works on my mac (leopard) with python 2.5.1, this same
> code fails to work on an ubuntu server with python 2.4.3
>
> I was wondering if there is a problem with .rstrip() in that python
> version?
>
> error :
> Traceback (most recent call last):
>   File "delgraph.py", line 62, in ?
> url_metadata = d.get_url(site.rstrip())

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recomendations

2008-03-01 Thread subeen
On Mar 2, 6:56 am, Ira Solomon <[EMAIL PROTECTED]> wrote:
> I am an experienced programmer (40 years).  I've done Algol (if you've
> heard of that you must be old too), PL/1, VB,VBA, a little C, and a
> few other odd languages (e.g. Taskmate).
> I'm interested in learning Python and have downloaded a slew of books.
> Too many.
> I'd like a recommendation as to which books are considered to be the
> cream of the crop.
> I know there are tutorials on the web, but, again, I don't know the
> quality.  I would appreciate recommendations on those as well.
>
> Thanks
>
> Ira


I have found that 'Dive into Python' is a good book for people who
have experience with other languages. It's available free here:
http://www.diveintopython.org/

regards,
Subeen
http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Delete hidden files on unix

2008-03-03 Thread subeen
On Mar 3, 6:13 pm, Philipp Pagel <[EMAIL PROTECTED]>
wrote:
> loial <[EMAIL PROTECTED]> wrote:
> > How can I delete hidden files on unix with python, i.e I want to do
> > equivalent of
> > rm  .lock*
>
> Here is one way to do it:
>
> import os, glob
> for filename in glob.glob('.lock*'):
> os.unlink(filename)
>
> Alternatively, you could also do this:
>
> import os
> os.system('rm .lock*')
>
> cu
> Philipp
>
> --
> Dr. Philipp Pagel
> Lehrstuhl f. Genomorientierte Bioinformatik
> Technische Universität Münchenhttp://mips.gsf.de/staff/pagel

Another way is to execute the linux command directly :)
Check here: 
http://love-python.blogspot.com/2008/02/execute-linux-commands-in-python.html

regards,
subeen.
http://love-python.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a python program as main...

2008-03-26 Thread subeen
On Mar 26, 8:12 pm, waltbrad <[EMAIL PROTECTED]> wrote:
> Stumbling through Mark Lutz's "Programming Python 3rd",  he gives an
> example of a program that will automatically configure environment
> settings and launch other programs.  Then he gives an example of
> running this program. On  his command line he types:
>
> C:\...\PP3E>Launcher.py
>
> and this begins the program.  Doesn't work for me. I have to type:
>
> C:\...\PP3E>python Launcher.py
>
> Is this a typo on his part or has he configured his settings in such a
> way that the command line will automatically associate the extension
> with the program? (If so, he didn't mention this in his book).

You have to set the path in your run time environment.

regards,
Subeen.
http://love-python.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do *you* use Python in non-GUI work?

2008-05-18 Thread subeen
On May 19, 7:52 am, "Kam-Hung Soh" <[EMAIL PROTECTED]> wrote:
> On Mon, 19 May 2008 08:20:22 +1000, John Salerno
>
> <[EMAIL PROTECTED]> wrote:
> > Hey all. Just thought I'd ask a general question for my own interest.
> > Every time I think of something I might do in Python, it usually
> > involves creating a GUI interface, so I was wondering what kind of work
> > you all do with Python that does *not* involve any GUI work. This could
> > be any little scripts you write for your own benefit, or what you do at
> > work, if you feel like talking about that! :)
>
> > Thanks.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> - Enhancing existing products by scripting new features.
> - Interface between databases, Excel and text files.
> - Convert data between flat files and XML.
> - Manage files for build processes.
> - Automating processes (e.g. checkout, builds, FTP).
>
> Wish I had some reasons to make a GUI application in Python.
>
> --
> Kam-Hung Soh http://kamhungsoh.com/blog";>Software Salariman

I also haven't used GUI in python yet. I basically write web crawlers/
spiders in Python where GUI is not essential.

regards,
Subeen
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: python blogs

2008-06-02 Thread subeen
On Jun 3, 8:43 am, Benjamin <[EMAIL PROTECTED]> wrote:
> On Jun 2, 1:49 pm, [EMAIL PROTECTED] wrote:
>
> > Hello!
>
> > It seems like Python blogs are gaining popularity. It seems to me that
> > they play a crucial role in promoting Python as a language.
> > Do you agree with that?
>
> > Just a few days ago I've finished setting up a dedicated Python
> > blogging environment at:http://www.pythonblogs.com
> > Do you think it will be useful for Python community?
> > By the way, everyone is welcome to join.
>
> Thanks very much, but the extension says it's written in PHP!
>
>
>
> > Sincerely yours,
> > ~pyblog

A separate place for python blog - the idea is good. I also think that
python blog will help python to be more popular.
You can also take a look at my blog: http://love-python.blogspot.com/
and suggest me how to make it better.

regards,
Subeen.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Keep a script running in the background

2008-06-03 Thread subeen
On Jun 3, 10:07 pm, Guillermo <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need a script to keep running in the background after it's loaded
> some data. It will make this data available to the main program in the
> form of a dictionary, but I don't want to reload the calculated data
> every time the user needs it via the main program.
>
> I won't be working with an UI, hope that can be made easily in Python
> somehow.
>
> Cheers,
>
> Guillermo

You can try this command: nohup python script.py &

regards,
Subeen.
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to send a POST request?

2008-06-06 Thread subeen
On Jun 7, 6:17 am, "Jeff McNeil" <[EMAIL PROTECTED]> wrote:
> The original urllib module will do it too, if you pass a data keyword
> argument to urllib.urlopen:
>
> u = urllib.urlopen('http://www.domain.com/cgi-bin/cgi.py',
> data=urllib.urlencode({'name': 'pythonguy'}))
>
> On Fri, Jun 6, 2008 at 6:04 PM, kj <[EMAIL PROTECTED]> wrote:
> > In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes:
>
> >>Hi.  Sorry for this very clueless question, but how does one write
> >>in Python an HTTP client that can send a POST request?  The modules
> >>I've found (e.g. urllib, urllib2), as far as I can tell, seem to
> >>be limited to GET requests.  (I could be wrong though; please
> >>correct me if this is so.)
>
> > Sorry, my mistake.  I now see that urllib2 handles POSTs too.
>
> > kynn
>
> > --
> > NOTE: In my address everything before the first period is backwards;
> > and the last period, and everything after it, should be discarded.
> > --
> >http://mail.python.org/mailman/listinfo/python-list

check this link for http post:
http://love-python.blogspot.com/2008/04/get-content-html-source-of-url-by-http.html

regards,
Subeen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web Crawler - Python or Perl?

2008-06-09 Thread subeen
On Jun 9, 11:48 pm, [EMAIL PROTECTED] wrote:
> Hi all,
> I am currently planning to write my own web crawler. I know Python but
> not Perl, and I am interested in knowing which of these two are a
> better choice given the following scenario:
>
> 1) I/O issues: my biggest constraint in terms of resource will be
> bandwidth throttle neck.
> 2) Efficiency issues: The crawlers have to be fast, robust and as
> "memory efficient" as possible. I am running all of my crawlers on
> cheap pcs with about 500 mb RAM and P3 to P4 processors
> 3) Compatibility issues: Most of these crawlers will run on Unix
> (FreeBSD), so there should exist a pretty good compiler that can
> optimize my code these under the environments.
>
> What are your opinions?

It really doesn't matter whether you use Perl or Python for writing
web crawlers. I have used both for writing crawlers. The scenarios you
mentioned (I/O issues, Efficiency, Compatibility) don't differ two
much for these two languages. Both the languages have fast I/O. You
can use urllib2 module and/or beautiful soup for developing crawler in
Python. For Perl you can use Mechanize or LWP modules. Both languages
have good support for regular expressions. Perl is slightly faster I
have heard, though I don't find the difference myself. Both are
compatible with *nix. For writing a good crawler, language is not
important, it's the technology which is important.

regards,
Subeen.
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web Crawler - Python or Perl?

2008-06-09 Thread subeen
On Jun 10, 12:15 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> subeen wrote:
> > can use urllib2 module and/or beautiful soup for developing crawler
>
> Not if you care about a) speed and/or b) memory efficiency.
>
> http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/
>
> Stefan

ya, beautiful soup is slower. so it's better to use urllib2 for
fetching data and regular expressions for parsing data.


regards,
Subeen.
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web Crawler - Python or Perl?

2008-06-22 Thread subeen
On Jun 13, 1:26 am, Chuck Rhode <[EMAIL PROTECTED]> wrote:
> On Mon, 09 Jun 2008 10:48:03 -0700, disappearedng wrote:
> > I knowPythonbut notPerl, and I am interested in knowing which of
> > these two are a better choice.
>
> I'm partial to *Python*, but, the last time I looked, *urllib2* didn't
> provide a time-out mechanism that worked under all circumstances.  My
> client-side scripts would usually hang when the server quit
> responding, which happened a lot.
>

You can avoid the problem using the following code:
import socket

timeout = 300 # seconds
socket.setdefaulttimeout(timeout)

regards,
Subeen.
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python to run SSH commands on a remote server

2008-06-23 Thread subeen
On Jun 24, 3:51 am, John Salerno <[EMAIL PROTECTED]> wrote:
> Jeffrey Froman wrote:
> > Also note that "all .py files on my web server" is not necessarily
> > restricted to CGI scripts -- and therein lies the real gist of my
> > cautionary note.
>
> Yeah, I realized that afterwards. Good point. I was assuming all my
> executable files would be CGI, but that's not a good assumption to make! :)

You can execute ssh using os.system(). Look at
http://love-python.blogspot.com/2008/02/execute-linux-commands-in-python.html
If you want non-interactive ssh (so that your script doesn't need to
enter password), look at: 
http://speed-dev.blogspot.com/2008/06/non-interactive-ssh-in-linux.html

regards,
Subeen.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Not necessarily related to python Web Crawlers

2008-07-06 Thread subeen
On Jul 5, 2:31 pm, [EMAIL PROTECTED] wrote:
> Hi
> Does anyone here have a good recommendation for an open source crawler
> that I could get my hands on? It doesn't have to be python based. I am
> interested in learning how crawling works. I think python based
> crawlers will ensure a high degree of flexibility but at the same time
> I am also torn between looking for open source crawlers in python vs C
> ++ because the latter is much more efficient(or so I heard. I will be
> crawling on very cheap hardware.)
>
> I am definitely open to suggestions.
>
> Thx

You can check my python blog. There are some tips and codes on
crawlers.
http://love-python.blogspot.com/

regards,
Subeen
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to set proxy for a python script to run

2008-04-18 Thread subeen
On Apr 18, 12:31 pm, Adam <[EMAIL PROTECTED]> wrote:
> Hi, everyone, I am using /usr/share/system-config-language/
> language_gui.py in Python.
> For some reason I have to bypass the firewall using a proxy. I read
> the urllib reference and set http_proxy="my proxy". But it didn't
> work. Is there anyway that we can set the proxy?

Check the link: 
http://love-python.blogspot.com/2008/03/use-proxy-in-your-spider.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python

2008-09-06 Thread subeen
On Sep 6, 3:17 pm, James Pilling <[EMAIL PROTECTED]> wrote:
> Hi im currently starting to learn python in sixth form at school any tips?
>

Just pickup a good book and make sure you code all the examples and
exercises yourself, even if it seems easy.
Have fun with Python!

regards,
Subeen.
http://love-python.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Trouble sending / receiving compressed data (using zlib) as HTTP POST to server (in django)

2009-10-03 Thread subeen
Hi,

I am trying to send compressed data to a server written in django. But
it shows error while decompressing the data in the server. After some
experiment I found that the server is not receiving the exact data I
am sending.

data = 'hello, this is a test message this is another message'
data = zlib.compress(data)
# now it looks like: x��HQ(��,V�D���T�p^~IFjL�e
# length is 45

in django (view) I receive it:
data = request.POST['data']
# now it looks like: xQ(�,V�D���^~IFjL�e
# length is 34

Can anybody help me understand the issue and how to get over?


thanks,
Subeen.
http://love-python.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble sending / receiving compressed data (using zlib) as HTTP POST to server (in django)

2009-10-05 Thread subeen
Thanks for your response.
> How did you post the data? If you post binary data you should indicate
> this with a proper mime type, like application/octet-stream. Otherwise
> it might be interpreted as text which it isn't.
> --
I am trying to send the data using following code:
...
opener = urllib2.build_opener()

opener.addheaders = [

 ('User-Agent', 'python'),
 ('Content-Type', 'application/octet-stream'),
]
data = zlib.compress(data)
params = urllib.urlencode({'uid': uid, 'reqid': rid, 'data':
data})
usock = opener.open(url, params)
resp = usock.read()

usock.close()
...

regards,
Subeen.
-- 
http://mail.python.org/mailman/listinfo/python-list