[Tutor] What algorithm suits here

2011-07-13 Thread Amit Sethi
I have a list of dictionaries in this form.

{ message : xyz
  parent : 23
  id : 25
}
 or
{ message : abc
parent : None
id : 25
}

{ message : cde
parent : 28
id : 32
}

{ message : cde
parent : 23
id : 35
}

I want to make seperate the lists such that messages in same thread(
The parent message and its child messages } come together . What is
the best algorithm here



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Editing html using python

2010-02-15 Thread Amit Sethi
Well ya I was kind of hoping to know about more tools and recommendations on

how to edit broken html . Their were tags that I wanted to replace using
beautifulSoup
however i saw that the replacewith function was not available for many of
the tags I
wanted to replace . Also BeautifulSoup does not have unicode support .
So in a sense I did want recommendation perhaps I should have put my
question
in a better manner .
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Editing html using python

2010-02-14 Thread Amit Sethi
Hi I need to edit html programmatically . Sadly the html might be broken at
places . I was using BeautifulSoup but there were lots of problems and it is
also not maintained can some one guide me to any tutorials on editing html
using lxml .

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python wsgi

2009-11-18 Thread Amit Sethi
Hi ,

How do I run a python script using wsgi? I am not using any web
framework I just wish to try out running a simple script.

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] idiomatic way of merging two dictionaries

2009-11-03 Thread Amit Sethi
Hi , I am trying to merge(I am not sure if that is the right term)
dictionaries like this

dict1 ={'a':4,'b':3,'v':7,'h':4}
dict2={'a':5,'v':4,'k':3}
dict3 would be {'a':[4,5],'b':[3,4],'v':[7,4],'k':[0,3],'h':[4,0]}

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] java for python programmers

2009-11-03 Thread Amit Sethi
Hi their is a book , python for java programmers is their a book on java for
python programmers for some one who wants to move to java from python

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python zlib problem

2009-10-30 Thread Amit Sethi
Hi , For some weird reason or a huge screw up I did my python zlib library
has been removed . This is part of standard lib(i think!!!) and it is used
by setuptools and many other libraries .What is the safe way in which I can
recover this library on ubuntu. My previous try somehow lead to removal of
ubuntu-desktop...


If this is not the list I should be asking this I am sorry

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Currency conversion module in python

2009-07-29 Thread Amit Sethi
Hi , Does anybody know of any currency conversion module in python

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to force stop a thread

2009-07-24 Thread Amit Sethi
Hi ,

I am trying to implement python threads in a gtk based app . Now the
thing is that in the application I have to fetch a lot of data from
various sources from web. During this time I wish to show a dialog
that indicates it to the user . During the same time I want to fetch
data as well . Now to implement this I have done:

a=Wait_dialog()
gtk.gdk.threads_init()  
lock=thread.allocate_lock()
thread.start_new_thread(show_dialog,(lock,a))
thread.start_new_thread(fetch,(lock,a))


Now I wish to stop the thread that shows the dialog so I can destroy
the dialog and continue with normal app

I am not able to understand how to do that ... Also is this the best
way to do this kind of thing???

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to monitor if their data in a variable/object

2009-07-20 Thread Amit Sethi
Hi , I am writing a python gtk application in which I am required to
fetch a large amount of data from web , now i want to create a wait
dialog for the user to know that I am still fetching data .The
question is how can i monitor that the required data has been fetched
. I could have a variable that is given a particular value when data
has been fetched . But how can I   keep checking if the variable has
got a value or not.

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Very wierd namespace problem

2009-07-17 Thread Amit Sethi
I am not able to understand this , perhaps it is an aspect of python I
do not understand 

Now usually I would think that for a class
class a:
... def __init__(self):
... pass
... def __something__(self):
... pass

>>> b=a()
>>> dir(b)
['__doc__', '__init__', '__module__', '__something__']


This should be correct  so now i can refer one of these functions
from the object of the same class as obj.__something__()
now I have created a class with some functions defined in it but the
thing is that they are named in a completely different manner?(or
so I think)

<__main__.SmPriceWindow instance at 0x9dd448c>
['_SmPriceWindow__add_columns', '_SmPriceWindow__create_model',
'_SmPriceWindow__review_button_click', '_SmPriceWindow__show_all',
'_SmPriceWindow__url_button_click', '__doc__', '__init__',
'__module__', 'model', 'tree', 'window']
Traceback (most recent call last):
  File "smnotebook3.py", line 135, in price_button_pressed
sw.__show_all()
AttributeError: SmPriceWindow instance has no attribute '__show_all'

I have refered to these functions(__add_columns ,__create_model etc
... as self.__add_columns as would be expected in the class itself  )

This functionality is unexpected according to me 

Since I cannot take much of the space here explaining the code I have
pasted here:
http://pastebin.com/mddf7a43


-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] gtk.Notebook error

2009-07-13 Thread Amit Sethi
Hi ,
I am having problem with adding pages to gtk.Notebook :

What I want is to be able to pass a random container widget to a new tab:

thus my code is :

class SmNotebook(gtk.Notebook):
def __init__(self):
gtk.Notebook.__init__(self)
#set the tab properties
self.set_property('homogeneous', True)
#we do not show the tab if there is only one tab i total
self.set_property('show-tabs', True)

def new_tab(self,widget_to_render,title='Page'):
nbpages = self.get_n_pages()
self.append_page(widget_to_render)

Now while creating I do :

def new_tab(widget,widget_render):

notebook.new_tab(widget_render)

  notebook = SmNotebook()
  box.pack_start(notebook)
  box2=gtk.VBox()
  icons = gtk.STOCK_ABOUT
  image = gtk.Image()
  image.set_from_stock(icons, gtk.ICON_SIZE_DIALOG)
  box2.pack_start(image,False)
  button.connect("clicked", new_tab,box2)

* I have deleted the parts of the code that did not seem to be
required . The later part of the code is just for testing..


when I do this I get  a warning :   smnotebook.py:18: GtkWarning:
Can't set a parent on widget which has a parent.


what am I doing wrong here??


-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting image from url

2009-07-10 Thread Amit Sethi
I am sorry, I did not realize the problem was in the location .Ignore
the message

On Fri, Jul 10, 2009 at 9:19 PM, Emile van Sebille wrote:
> On 7/10/2009 8:29 AM Amit Sethi said...
>>
>> Hi , I am trying to get  images from url
>>
>> Their is  a  mail relating to it here :
>> "http://mail.python.org/pipermail/python-list/2001-October/108548.html";
>>
>> but when i followed similar procedure :
>>
>>>>> import urllib
>>>>> fp =
>>>>> urllib.urlopen("http://en.wikipedia.org/wiki/File:Portrait_john_calvin.jpg";)
>>>>> img = cStringIO.StringIO(fp.read())
>
> Right here, try...
>
>    img.read()[:50]
>
> ... and it should become clear what the problem is...
>
> HTH,
>
> Emile
>
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting image from url

2009-07-10 Thread Amit Sethi
Hi , I am trying to get  images from url

Their is  a  mail relating to it here :
"http://mail.python.org/pipermail/python-list/2001-October/108548.html";

but when i followed similar procedure :

>>> import urllib
>>>fp = 
>>>urllib.urlopen("http://en.wikipedia.org/wiki/File:Portrait_john_calvin.jpg";)
>>>img = cStringIO.StringIO(fp.read())
>>> Image.open(img)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1917, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file

what is wrong?? how can I rectify...



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] intefaces in python

2009-06-29 Thread Amit Sethi
well dir(object) , how would that help . All the functions in base
class would automatically be inherited by the objects of plug-in class
... so they would come in the list even if it was not implemented...

On Mon, Jun 29, 2009 at 5:58 PM, Luke
Paireepinart wrote:
> Amit Sethi wrote:
>>
>> I think ideally i want a compile Error just like java ..
>
> Why?  For developers, so they'll know if their plugin meets the interface
> requirements?
> Have you considered just making a unit test that will call all interface
> functions with appropriate parameters?  Then they can just run the test on
> their code and if it passes they will know they implemented the minimum
> required functions (whether they do what they're supposed to do is a
> different story...)  It would provide the same level of interface security
> as Java would, except it would allow them to decide how much of the contract
> they need to enforce for their specific application. That's one of the
> things I like about python... for example, if I want to override stdout so
> all my print statements go to a file, I just have to create a new class that
> has a write() method that writes anything it's passed to a file... I don't
> have to implement all of the other functionality that whatever object
> resides there before has.  So in that case, if I ran your unit test on my
> replacement stdout, it may say "Hey, you failed the writeline() test, your
> object doesn't have this!" but since I know I'm not going to use writeline,
> I can just ignore the warning.  Or if I meant for it to have writeline, I
> can say "oh snap I need to go implement writeline!"  But as I said, that
> wouldn't enforce the interface, just inform them of it if they desired that,
> which I would personally prefer but you may not.
> That's really the idea behind duck typing.  Assume that they wrote
> sufficient code to handle whatever you use it for and if they didn't it'll
> blow up in their face.
>>
>> @Dave Angel
>>
>> You have said
>> "you could arrange that when the plugin is first encountered, you
>> validate that it has all the required methods and data members.  Not
>> by calling them, but by scanning the object for their existence."
>>
>> that would be ideal ... can you enlighten me on this how may one do that.
>>
>>
>
> Not sure if it's what he meant, but you can just do a dir(object) and it
> will return a list with all method / member names.  then you could just
> confirm that the names are there.
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] intefaces in python

2009-06-29 Thread Amit Sethi
wait even in the above example i would have to run all the functions
in __init__ that is plain stupid ... i was just brain storming

On Mon, Jun 29, 2009 at 5:34 PM, Amit Sethi wrote:
> I think ideally i want a compile Error just like java .. but from the
> discussion here ... i wrote this little example:
>
> class a(object):
>     def __init__(self):
>         self.query()
>         try:
>             if self.query_not_implemented==True:
>                 raise NotImplementedError
>         except AttributeError:
>             pass
>     def query(self):
>           self.query_not_implemented=True
>
> At least by this when ever the derived class object is created without
> implementing a particular function ,it raises a NotImplementedError
> which i can later use.
>
>
> @Dave Angel
>
> You have said
> "you could arrange that when the plugin is first encountered, you
> validate that it has all the required methods and data members.  Not
> by calling them, but by scanning the object for their existence."
>
> that would be ideal ... can you enlighten me on this how may one do that.
>
>
> On Mon, Jun 29, 2009 at 5:01 PM, Dave Angel  wrote:
>>
>> Amit Sethi  wrote:
>>
>>> Well I want to implement plug-in like mechanism for an application . I want
>>> to define some minimum functions that any body writing a plugin has to
>>> implement. For that i thought an interface would be best because in a
>>> scenario where the function is not implemented some kind of error would
>>> occur. I would love to hear if you think their is a better way to achieve
>>> this
>>
>> In Java, deriving a class from such an interface, but neglecting to 
>> implement those methods will cause a compile error (if I recall correctly, 
>> it's been several years).  In Python, the error will happen at run time.  
>> But an existing runtime error will occur even without such an interface, so 
>> it wouldn't seem you gain much.  In Python, the interface does two things:
>>
>> 1) it's a comment, a common place to look for certain behavior.
>> 2) it's potentially a source for an IDE to provide tool-tips or code 
>> completion
>> 3) it can generate a different error, which is perhaps more useful to the 
>> developer unsure of how the method is spelled or used.  This way he/she 
>> knows whether to fix the caller or the implementation.
>>
>> #3 seems valid to me.
>>
>>
>>
>> However, for the particular use-case, you might want to stretch a bit 
>> further.  Since you've got one "user" (your code), and many "providers" (the 
>> plug-in writers)  perhaps you could arrange that when the plugin is first 
>> encountered, you validate that it has all the required methods and data 
>> members.  Not by calling them, but by scanning the object for their 
>> existence.
>>
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> A-M-I-T S|S
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] intefaces in python

2009-06-29 Thread Amit Sethi
I think ideally i want a compile Error just like java .. but from the
discussion here ... i wrote this little example:

class a(object):
    def __init__(self):
        self.query()
        try:
            if self.query_not_implemented==True:
                raise NotImplementedError
        except AttributeError:
            pass
    def query(self):
          self.query_not_implemented=True

At least by this when ever the derived class object is created without
implementing a particular function ,it raises a NotImplementedError
which i can later use.


@Dave Angel

You have said
"you could arrange that when the plugin is first encountered, you
validate that it has all the required methods and data members.  Not
by calling them, but by scanning the object for their existence."

that would be ideal ... can you enlighten me on this how may one do that.


On Mon, Jun 29, 2009 at 5:01 PM, Dave Angel  wrote:
>
> Amit Sethi  wrote:
>
>> Well I want to implement plug-in like mechanism for an application . I want
>> to define some minimum functions that any body writing a plugin has to
>> implement. For that i thought an interface would be best because in a
>> scenario where the function is not implemented some kind of error would
>> occur. I would love to hear if you think their is a better way to achieve
>> this
>
> In Java, deriving a class from such an interface, but neglecting to implement 
> those methods will cause a compile error (if I recall correctly, it's been 
> several years).  In Python, the error will happen at run time.  But an 
> existing runtime error will occur even without such an interface, so it 
> wouldn't seem you gain much.  In Python, the interface does two things:
>
> 1) it's a comment, a common place to look for certain behavior.
> 2) it's potentially a source for an IDE to provide tool-tips or code 
> completion
> 3) it can generate a different error, which is perhaps more useful to the 
> developer unsure of how the method is spelled or used.  This way he/she knows 
> whether to fix the caller or the implementation.
>
> #3 seems valid to me.
>
>
>
> However, for the particular use-case, you might want to stretch a bit 
> further.  Since you've got one "user" (your code), and many "providers" (the 
> plug-in writers)  perhaps you could arrange that when the plugin is first 
> encountered, you validate that it has all the required methods and data 
> members.  Not by calling them, but by scanning the object for their existence.
>
>
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor



--
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] intefaces in python

2009-06-29 Thread Amit Sethi
Well I want to implement plug-in like mechanism for an application . I want
to define some minimum functions that any body writing a plugin has to
implement. For that i thought an interface would be best because in a
scenario where the function is not implemented some kind of error would
occur. I would love to hear if you think their is a better way to achieve
this

On Mon, Jun 29, 2009 at 2:49 PM, Alan Gauld wrote:

> "Amit Sethi"  wrote
>
>> class MyInterface(object):
>>  doSomething(line):
>>   raise NotImplementedError
>>  doSomethingElse(line):
>>  raise NotImplementedError
>>
>> I think that is exactly the kind of structure i was looking for ...
>>
>
> As a matter of interest, why? What do you anticipate using this for?
> I have found a few cases where abstract interfaces are useful but they are
> very few and far between.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] intefaces in python

2009-06-29 Thread Amit Sethi
class MyInterface(object):
   doSomething(line):
   raise NotImplementedError
   doSomethingElse(line):
   raise NotImplementedError


I think that is exactly the kind of structure i was looking for ...

On Mon, Jun 29, 2009 at 12:58 PM, Andre Engels wrote:

> On Sun, Jun 28, 2009 at 5:00 PM, Amit Sethi
> wrote:
> > Hi , I don't suppose python has a concept of interfaces. But can somebody
> > tell me if their is a way i can  implement something like a java
> interface
> > in python.
>
> Sure. Interfaces are just Java's compensation for not having multiple
> inheritance. Python does have multiple inheritance, so that's what one
> would use. Although one could also use duck typing, and then use
> 'nothing' as an implementation...
>
> More specific:
>
> 
> Java Interface:
> public interface MyInterface {
>string doSomething(string line);
>string doSomethingElse(string line);
> }
>
> Java Implementation:
> public class MyImplementation {
>   string doSomething(string line) {
>   return "I did something with" + line;
>   }
>   string doSomethingElse(string line) {
>  return "I did something else."
>   }
> }
>
> ==
> Python Interface:
>
> class MyInterface(object):
>doSomething(line):
>raise NotImplementedError
>doSomethingElse(line):
>raise NotImplementedError
>
> Python Implementation:
> class MyImplementation(MyInterface):
>doSomething(line):
>return "I did something with "+line
>doSomethingElse(line):
>return "I did something else."
>
> ==
> Python interface using duck typing:
>
> # Hey guys, when you call something a 'MyInterface', it needs methods
> doSomething and doSomethingElse
>
> Python Implementation using duck typing:
>
> class MyImplementation(object):
># These things implement MyInterface
>doSomething(line):
>return "I did something with "+line
>doSomethingElse(line):
>return "I did something else."
>
>
> --
> André Engels, andreeng...@gmail.com
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] intefaces in python

2009-06-28 Thread Amit Sethi
Hi , I don't suppose python has a concept of interfaces. But can somebody
tell me if their is a way i can  implement something like a java interface
in python.
-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] taking image of gtk.drawing area

2009-06-19 Thread Amit Sethi
Hi ,
I am trying to take image of a gst video playing in the gtk.drawingarea i am
using following code for it :

def snap_shot(self,widget,data=None):
global file_loc   ,pixbuf
self.pipeline.set_state(gst.STATE_PAUSED)
pixbuf = gtk.gdk.Pixbuf( gtk.gdk.COLORSPACE_RGB, False, 8, 640, 480)
pixbuf.get_from_drawable( self.movie_window.window,
self.movie_window.get_colormap(), 0, 0, 0, 0, 640, 480)
file_loc="/tmp/bar%d"%time.time()
pixbuf.save(file_loc,'jpeg', {'quality':'100'})
self.pipeline.set_state(gst.STATE_PLAYING)

but the movie seems to momentarily stop and i am left with a dark image
where i might be going wrong??

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using C in python

2009-03-25 Thread amit sethi
what are the ways in which i can use C in python programs . I know there is
SWIG bindings are there any other . Also Could anyone explain how Swig
bindings work?

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Designing Tools/books

2009-03-05 Thread amit sethi
Although this may not be the most appropriate place to ask this but i
couldn't figure out where else i should be asking this question.I am getting
habitual of starting projects and getting results quickly thanks to python
.But I get stuck in documentation because i haven't asked the design
questions through and through.Although my projects work for college because
they are not large scale and do not require optimum quality control so this
problem only seems to come during documentation but i believe this will be a
pain when i do this professionally.So my question is please guide me to good
internet resources ,books and tools that talk about design especially with
python in mind. Also they follow Agile Software development model or any
other latest development cycle used in the industry .
-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] passing unknown no of arguments

2009-02-06 Thread amit sethi
>> AFAIK MS Silverlight allows you to run .NET languages in your browser,

so for that i guess i would have to use ironpython and not Cpython which is
what i normally use . Are there any big problems porting the code from one
to other that i need to be worried about.


On Fri, Feb 6, 2009 at 12:30 AM, Alan Gauld wrote:

>
> "Kent Johnson"  wrote
>
>>
>>  From the Silverlight FAQ:
>>>
>> Silverlight will support all major browsers on both Mac OS X, Linux
>> and on Windows.
>>
>
> I briefly tried and failed to get it working on MacOS X and lost interest.
> Looks like I might be a bit premature in ignoring it. I'll have another
> go...
>
> Alan G.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] passing unknown no of arguments

2009-02-05 Thread amit sethi
How do you pass arguments of unknown no. of arguments to a function.
Also how can i run my python scripts in a web browser.


-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fetching wikipedia articles

2009-01-23 Thread amit sethi
well thanks ... it worked well ... but robotparser is in urllib isn't there
a module like robotparser in
urllib2

On Fri, Jan 23, 2009 at 3:55 PM, Andre Engels  wrote:

> On Fri, Jan 23, 2009 at 10:37 AM, amit sethi 
> wrote:
> > so is there a way around that problem ??
>
> Ok, I have done some checking around, and it seems that the Wikipedia
> server is giving a return code of 403 (forbidden), but still giving
> the page - which I think is weird behaviour. I will check with the
> developers of Wikimedia why this is done, but for now you can resolve
> this by editing robotparser.py in the following way:
>
> In the __init__ of the class URLopener, add the following at the end:
>
> self.addheaders = [header for header in self.addheaders if header[0]
> != "User-Agent"] + [('User-Agent', '')]
>
> (probably
>
> self.addheaders = [('User-Agent', '')]
>
> does the same, but my version is more secure)
>
> --
> André Engels, andreeng...@gmail.com
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fetching wikipedia articles

2009-01-23 Thread amit sethi
so is there a way around that problem ??

On Fri, Jan 23, 2009 at 2:25 PM, Andre Engels  wrote:

> On Fri, Jan 23, 2009 at 9:09 AM, amit sethi 
> wrote:
> > Well that is interesting but why should that happen in case  I am using a
> > different User Agent because I tried doing
> > status=rp.can_fetch('Mozilla/5.0',
> > "http://en.wikipedia.org/wiki/Sachin_Tendulkar";)
> > but even that returns false
> > Is there something wrong with the syntax , Is there a catch that i don't
> > understand.
>
> The problem is that you are using the standard Python user agent when
> getting the robots.txt. Because the user agent is refused, it cannot
> get the robots.txt file itself to look at.
>
> --
> André Engels, andreeng...@gmail.com
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fetching wikipedia articles

2009-01-23 Thread amit sethi
Well that is interesting but why should that happen in case  I am using a
different User Agent because I tried doing
status=rp.can_fetch('Mozilla/5.0', "
http://en.wikipedia.org/wiki/Sachin_Tendulkar";)
but even that returns false
Is there something wrong with the syntax , Is there a catch that i don't
understand.
On Thu, Jan 22, 2009 at 10:45 PM, Andre Engels wrote:

> On Thu, Jan 22, 2009 at 6:08 PM, amit sethi 
> wrote:
> > hi , I need help as to how i can fetch a wikipedia article i tried
> changing
> > my user agent but it did not work . Although as far as my knowledge of
> > robots.txt goes , looking at en.wikipedia.org/robots.txt it does not
> seem it
> > should block a useragent (*, which is what i would normally use) from
> > accesing a simple article like say
> > "http://en.wikipedia.org/wiki/Sachin_Tendulkar"; but still robotparser
> > returns false
> > status=rp.can_fetch("*", "http://en.wikipedia.org/wiki/Sachin_Tendulkar
> ")
> > where rp is a robot parser object . why is that?
>
> Yes, Wikipedia is blocking the Python default user agent. This was
> done to block the main internal bot in its early days (it was
> misbehaving by getting each page twice); when it got to allowing the
> bot again, it had already changed to having its own user agent string,
> and apparently it was not deemed necessary to unblock the user
> string...
>
>
>
>
> --
> André Engels, andreeng...@gmail.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] fetching wikipedia articles

2009-01-22 Thread amit sethi
hi , I need help as to how i can fetch a wikipedia article i tried changing
my user agent but it did not work . Although as far as my knowledge of
robots.txt goes , looking at en.wikipedia.org/robots.txt it does not seem it
should block a useragent (*, which is what i would normally use) from
accesing a simple article like say "
http://en.wikipedia.org/wiki/Sachin_Tendulkar"; but still robotparser returns
false
status=rp.can_fetch("*", "http://en.wikipedia.org/wiki/Sachin_Tendulkar";)
where rp is a robot parser object . why is that?

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python reverse engineering tools

2008-11-21 Thread amit sethi
Well actually there was an interesting tool i discovered, Lumpy .
http://www.greenteapress.com/thinkpython/swampy/lumpy.html
which was developed with the intention of being a teaching tool.
Although it would be a nice idea if the people in this list evaluate
it and give their response because I as a beginner don't think  can
comment on its effectiveness.


On Sat, Nov 22, 2008 at 6:17 AM, Alan Gauld <[EMAIL PROTECTED]>wrote:

>
> "amit sethi" <[EMAIL PROTECTED]> wrote
>
>  Can somebody tell me about any python to UML reverse engineering tools .
>>
>
> I can't help wit the specific but I can give a word of caution on
> reverse engineering from code to UML - don't expect too much!
>
> The problem is that in a dynamic language it is very hard
> for the reverse engineering to determine types of attributes
> etc so everything tends to end up pointing at object - the
> common superclass. That results in class diagrams that
> are less than meaningful and an unreadable mess of
> spaghetti pointing to one place.
>
> Actually this tends to happen even on well designed
> static language programs too since most OOP interrfaces
> should be defined in terms of superclasses. UML to code
> works well because the designer controls the connectivity
> in the diagram, code to UML  tends to be less successful
> in my experience (Lisp, Smalltalk and C++) and leaves
> almost as much work as manually reverse engineering.
>
> However if you do find something that works please
> let us know!
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python reverse engineering tools

2008-11-21 Thread amit sethi
Can somebody tell me about any python to UML reverse engineering tools . I
was trying pynsource but it uses the old opengl namespace (this is what i
assume the problem is from what i read from the openGL documentation)
and thus it gives an import error
from wxPython.ogl import *
ImportError: No module named ogl
now i tried changing it  to   (again from documentation)

import wx.lib.ogl as ogl
but it still does not work. Can  somebody tell me what the problem might be
.



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 lists to database conversion/ using python variables in sqlite3

2008-11-19 Thread amit sethi
Hi , i am trying to learn python and this is my first time with any
databases . I am using sqlite3 to create a database of my music files and
its
metadata tags so here is what i wanted to do . Two list one of the
attributes and one of their values ,how do i put it in the database.Here is
a simple code i think should work but isn't?
>>> import sqlite3
>>> conn=sqlite3.connect('/tmp/example2')
>>> c = conn.cursor()

>>> list1=['hello','hi']
>>> list2=['a','b']
>>>c.execute('''create table ABC(hello text,hi text)''')
>>> list1_value= ",".join(list1)
>>> list2_value= ",".join(list2)
>>> c.execute('''insert into ABC (%s) values
(%s)''')%(list1_value,list2_value)
This is the error it generates
sqlite3.OperationalError: near "%": syntax error
why doesn't this work . Can someone please explain


A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] XML parsing with SAX

2008-10-22 Thread amit sethi
Sorry , I didn't follow the format of posting to the group. Well I am new to
xml and python . What I basically want to do is to read elements from the
xml which is by the way large ~2GB and read the attributes and make a
decision as to whether i want to keep that element or not . I am told that
xml.sax is good for reading a large xml file because it can read from a
stream but what about writing the xml file back  Thank you for your help.

On Wed, Oct 22, 2008 at 1:49 PM, Alan Gauld <[EMAIL PROTECTED]>wrote:

> "amit sethi" <[EMAIL PROTECTED]> wrote
>
> Please, always use a meaningful subject line when posting!
> and do not reply to an existing thread, changing the subject.
> These things mess up threaded reading tools such as gmane
> and newsreaders. This reduces your chances of a reply.
>
>  Hi can any body give me an example as to how i can use Incremental Parser
>> in
>> xml.sax
>>
>
> If you look in the XML Topic Guide section of the Python web site there
> is a full tutorial on using SAX. This is a good starting point:
>
> http://pyxml.sourceforge.net/topics/docs.html
>
> But frankly I'd strongly advise you to look at ElementTree if you are
> parsing XML. Its much easier to use. The only time I'd use sax nowadays
> is if I was porting code from some other sax based solution.
>
> http://effbot.org/zone/element-index.htm
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-10-21 Thread amit sethi
Hi can any body give me an example as to how i can use Incremental Parser in
xml.sax

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-07-26 Thread amit sethi
hi,
Can somebody tell me about tools to  convert stereo mp3 signal to mono wave
signal . I tried using pymedia but i am not able to understand how to
convert stereo signal to a mono signal .

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-07-19 Thread amit sethi
Hi list ,
Can someone give me an idea about the audio libraries in python . I tried
using pymedia . What are the options available .
-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-06-18 Thread amit sethi
Hi , Could you please tell me , how i can traverse a two dimensional array ,
i am sorry , it must be pretty simple but I am new to python am not able to
understand.

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-06-09 Thread amit sethi
Hi ,
Are there any python bindings for sox(sound Exchange).
-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] handling MIDI in python

2008-06-08 Thread amit sethi
Can someone tell me about the libraries that can handle MIDI files and also
is their a way in which I can convert an mp3 and wav file into a Midi file
within a python program

-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-06-06 Thread amit sethi
Hi,
I  am a student new to python . I had a project idea in mind that I want to
implement in my break using python .
Can anyone give me an idea of libraries available in python for transcribing
music and signal processing.
Good tutorials with examples would also help. If any body has experience in
the field it would be nice if you could give me some guidance . And also
direct me to articles , references ,essays on the subject of pattern
recognition and music summary .
Also I would like to look at open source projects related to the above .
Thank you everyone .
-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor