[Tutor] endless loop

2010-07-05 Thread prasad rao
hi I am trying problem 6 in projecteuler.org. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? def rr(z,m=1): q=lambda n:m%n==0 s=lambda False : 0 a=filter(s,map(q,range(1,z))) if not a: m+=1

Re: [Tutor] Doubts galore.

2010-06-10 Thread prasad rao
> Never NEVER compare for equality with None. > > What you want is: > if doc is None and data is None: > > Also, what is "sys.agv1"? Did you mean sys.argv[1]? yes > >elif doc: > > data=open(doc,'r').read() > > data_c= binascii.hexlify(data) > >else:data_c= bina

[Tutor] Doubts galore.

2010-06-10 Thread prasad rao
Hi def cript(doc=None,data =None): if doc==None and data==None:doc=sys.agv1 elif doc: data=open(doc,'r').read() data_c= binascii.hexlify(data) else:data_c= binascii.hexlify(data) if doc: q=tempfile.TemporaryFile() q.write(data_c) os.rename(q,doc

[Tutor] writing csv files

2010-05-22 Thread prasad rao
Thanks I got it. I reached the old PEP document by searching the keyword 'excel' Thanks or the help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] writing csv files

2010-05-22 Thread prasad rao
hello! I got a problem writing csv file. 1) csvw=csv.writer(open('/home/prasad/kkm','w'), dialect='excel',fieldnames=names) Traceback (most recent call last): File "", line 1, in TypeError: 'fieldnames' is an invalid keyword argument for this function 2) for x in csvr: ...y=lambda x: '

[Tutor] parsing pyc files

2010-03-23 Thread prasad rao
Hi . If you want to see what is in a pyc file,just type od pycfile at bash command prompt. You can see only rows of numbers. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tu

[Tutor] ex-ftp

2009-09-21 Thread prasad rao
hello friends I am trying to write a class to save a url.page. But it is not working.It is saving the html.page.But not getting images.I am unable to show the list (object.links). Please take a look at it and show me how to rectify it. import urllib2,ftplib,re class Collect: def __init__(se

Re: [Tutor] How to convert binary files back to text files?

2009-08-30 Thread prasad rao
> . > > >I don't understand what you are trying to do. Do you mean compiled > >Python files, e.g. .pyc files? > > ?Kent > Yes I want to examine pyc files.(ex:itertools). itertools.py is not available inPython26. pyc files are binaryfiles.Isn't it. ___ Tu

Re: [Tutor] How to convert binary files back to text files?

2009-08-29 Thread prasad rao
>On 8/29/09, Geneviève DIAGORN wrote: > > >Bonjour, > >Je suis absente jusqu'au 02/09 inclus. > >En cas d'urgence Soprane, contacter notre adresse générique > >projet.sopr...@teamlog.com. > >Cordialement. > > >Geneviève I dont know your language.Please communicate in English. I am using the cod

[Tutor] How to convert binary files back to text files?

2009-08-29 Thread prasad rao
Hello! I want to convert compiled files to text files. I believe compiled files are binary files. I am able to convert a given string to binary and back to text. But when it comes to a file it is proving to be impossible. def p(a): s=open(a,'rb') for x in s: d=map(lambda y

Re: [Tutor] To write data in two different fonts?

2009-08-12 Thread prasad rao
> >xml.sax.saxutils.escape(/data/[, /entities/]) > > > Escape '&', '<', and '>' in a string of data. > > > You can escape other strings of data by passing a dictionary as the > >optional /entities/ parameter. The keys and values must all be > >strings; each key will be replaced with its corre

Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread prasad rao
> > But I think you want the tag, which means the text is > pre-formatted. And you could >put that around the whole sorce file, instead > of doing for each line. > > >See http://www.w3schools.com/tags/tag_pre.asp Thank you Dave. I put in tag and it worked. But at one particular line in a mo

Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread prasad rao
Hello I modified my code.But I am gettingmy my lines stripped of indentation. What should I do to avoid it?Sorry if it is not about Python. def sc(adir): import os,myfiles dest=open('C:/scripts.html','w') s=myfiles.myfiles(adir) dest.write('') for x in s:

[Tutor] To write data in two different fonts?

2009-08-11 Thread prasad rao
Hello I am wtriting some dat on to a file in which headings should be of different size than other data. Is it possible?If possible please tell me how to do it. def sc(adir): import os,myfiles dest=open('C:/scripts.txt','w') s=myfiles.myfiles(adir) for x in s:

[Tutor] How to pass arguments to struct.pack()?

2009-08-03 Thread prasad rao
Hello I am finding it difficult to pass arguments to struct.pack(). Please some one tell me how to do it. >>> def structpack(alist): import struct a='%di'%len(alist) print a b=[a] print alist print b

[Tutor] flag to call methods on objects?

2009-07-30 Thread prasad rao
hello I removed the bugs.But still getting error report. >>import mcript Traceback (most recent call last): File "", line 1, in import mcript File "C:\Python26\mcript.py", line 78, in a.main() File "C:\Python26\mcript.py", line 58, in main nl=__compress(__digi(__lengthen(lin

Re: [Tutor] flag to call methods on objects?

2009-07-30 Thread prasad rao
On 7/30/09, Dave Angel wrote: > > prasad rao wrote: > >> hello >> >> >"it is not working." is not very descriptive. >> >> >> DaveA >> >Hello! Sorry, I forgot to mention the problem. It simply wipes clean the file,resulting

Re: [Tutor] flag to call methods on objects?

2009-07-30 Thread prasad rao
On 7/30/09, Rich Lovely wrote: > > 2009/7/30 prasad rao prasadarao...@gmail.com: >I'm sure there are modules available for PGP that are either part of > >the stdlib, or available from a quick google. PGP (or GPG) encryopts > I never know there is an encryption

[Tutor] flag to call methods on objects?

2009-07-30 Thread prasad rao
hello I wanted to prevent other users of my computers to read my files. So tried to creat a module to achieve it. I used a flag to deside which methods to be called on the object. somehow it is not working.I realise after 2 days of struggle that as it is usuel , I am blind to my faults. I test

Re: [Tutor] my first gui

2009-06-03 Thread prasad rao
Hello Thanks I will implement your suggestions. True .Names and parameters are not descriptive. There are no comments(docstrings) in the program . There is scope to reduce number of functions. Thank you Prasad ___ Tutor maillist - Tutor@python.org

[Tutor] my first gui

2009-06-03 Thread prasad rao
Hello. I made my first mager gui program.I need your openions suggestions and improvements. #! usr\\bin\\env python from Tkinter import * def myfiles (n='',m=''): import os mf=[os.path.join(x,i)for x,y,z in os.walk(n) for i in z if i.endswith(m)] return mf def fshow(): tclear(

[Tutor] Text.insert()

2009-06-03 Thread prasad rao
Hello >> I created a gui app.I am finding it impossible to >> use Text.insert().please some one give an example of using it. >Look in my tutorial at event driven programming and the Case >study. Both use the Text widget. >For more detailed info try this introduction: >http://www.linuxjournal.c

[Tutor] Text.index()

2009-06-02 Thread prasad rao
Hello I created a gui app.I am finding it impossible to use Text.insert().please some one give an example of using it. def fshow(): x=entry1.get() try: value1,value2=x.split(',') text.insert(len(myfiles(value1,value2)),myfiles(value1,value2)) except: text.insert(

Re: [Tutor] ?????

2009-05-25 Thread prasad rao
>for attrib in dir(sys): > > if callable('sys.%s' % attrib): > >print 'Callable: sys.%s' % attrib > > else: > >print 'Not Callable: sys.%s' % attrib > > Any particular reason why you need to be able to do this, just wondering > about the use case for such automation ? > > -- > Kind R

Re: [Tutor] ?????

2009-05-25 Thread prasad rao
> > >Any particular reason why you need to be able to do this, just wondering > about the use case for >such automation ? > > -- > Kind Regards, > Christian Witts > > > Thank you Christian for the prompt repply. I am learning python. I am just examining what are all the available items in each modu

[Tutor] ?????

2009-05-25 Thread prasad rao
hello I get a problem while trying to print non callable items in dir(module).May be as the items are strings. for x in dir(sys): ?? if sys.x is callable: print sys.x() ?? else:print sys.x Traceback (most recent call last): File "", line 2, in if sys.x is callable: Attribut

Re: [Tutor] Is it syntactic,semantic or runtime?

2009-04-25 Thread prasad rao
hellothanks .After inserting back slashes and de.close it is working well thanks for the help prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Is it syntactic,semantic or runtime?

2009-04-25 Thread prasad rao
helloI wrote a function to fetch data using urllib and displaying the data using internet Explorer. it is not preparing the html file So opening blank Explorer after complaining th html file not found. Where is the problem? Can I display the data read from a site without preparing a html file?

[Tutor] re Format a file

2009-02-28 Thread prasad rao
Hello >> for line in so: >> if len(line)<70:de.write(line+'\n') >> if len(line)>70: >> da=textwrap.fill(line,width=60) >> de.write(da+'\n') >What happens if the line is exactly 70 characters long? >I think you want an else instead of the second i

[Tutor] re Format a file

2009-02-27 Thread prasad rao
HelloFinally I managed to writ a function to format a file. Thank to everybody for their tips. def mmm(a): import os,textwrap so=open(a) d=os.path.dirname(a)+os.sep+'temp.txt' de=open(d,'w') import textwrap for line in so: if len(line)<70:de.write(line+'\n'

[Tutor] re Format a file

2009-02-26 Thread prasad rao
HelloI don't know why, but this I think going into infinite loop. I cant see anything wrong in it. Please show me where the problem is. def myform(s): import os so=open(s) d=os.path.dirname(s)+os.sep+'temp.txt' de=open(d,'w') for line in so: while len(line)>60: ?

[Tutor] re.format a file

2009-02-26 Thread prasad rao
helloThank you Lie and Kent. I forgot about newline character and the fact that string can be sliced. Thanks for your timely help BTW I have gone through the Python library reference and find no examples in fileinput module. z=fileinput.input(file,inplace=1) for line in z: ???if len(line)<60:pa

[Tutor] format a file

2009-02-26 Thread prasad rao
hello I find it difficult to use horizontal scroll bar to read text documents. So I want to split lines in the text file in to two lines. def myforrmat(source,desty): so=open(source) de=open(desty,'w') for line in so: ? if len(line)<60:de.write(line) ? if len(line)

[Tutor] Formatting

2009-02-25 Thread prasad rao
hi for license in licenses: m = licenseRe.search(license) print m.group(1, 2) ('ABTA', 'No.56542') ('ATOL', None) ('IATA', None) ('ITMA', None) Yes It is working Thank you Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.or

[Tutor] re Formating

2009-02-25 Thread prasad rao
hi >>> licenseRe = re.compile(r'\(([A-Z]+)\)\s*(No.\d+)?') >>> for license in licenses: m = licenseRe.search(license) print m.group(1, 3) Traceback (most recent call last): File "", line 3, in print m.group(1, 3) IndexError: no such group Something wrong with this code. _

[Tutor] Formatting

2009-02-24 Thread prasad rao
hi. s = 'Association of British Travel Agents (ABTA) No.56542\nAir Travel Organisation Licence (ATOL)\nAppointed Agents ofIATA (IATA)\nIncentive Travel & Meet. Association (ITMA)' licenses = re.split("\n+", s) licenseRe = re.compile(r'\(([A-Z]+)\)( No. (\d+))?') >>> for license in licenses:

[Tutor] re Binding Event

2009-02-10 Thread prasad rao
HelloI changed the code as follows.But still the callback function is not working. The he() is working well but clicking on the frame has no result. class app: def __init__(self,root): frame=Frame(root) frame.bind("", callback) frame.pack() self.button=Button(root,text='quit',fg='red',command=f

[Tutor] re.Binding Events

2009-02-09 Thread prasad rao
HelloI tried various permutations of the code.Nothing worked. I am mixing 2 examples given in "an-introduction-to- tkinter " by Fredrik Lundh.(and got this code) Today I got this error message Traceback (most recent call last): File "", line 1, in pp() File "", line 18, in pp xx=app(r

[Tutor] Binding Events

2009-02-09 Thread prasad rao
Hi I am unable to bind an event to a widget despite of my best efforts. Some one please help me. class app: def __init__(self,root): frame=Frame(root) frame.bind('',self.callback) frame.pack() self.event=event self.button=Button(root,text='quit',fg='red',command=frame.quit) self.button.pack(sid

[Tutor] re division problem

2009-02-04 Thread prasad rao
hi I modified my function ' vertical' by adding a few characters to eliminate the division problem. def vertical(columns): if columns>7: columns=7 import string v=string.printable v=v.replace('\n','') v=v.replace('\t','') if len(v)%columns !=0:

[Tutor] re division problem

2009-02-03 Thread prasad rao
hi>Right now you skip by x+((len(v))/columns) >which will be different for each row. How is it possible. len(v)=98.A constant. Is it not. Does len(v) changes with each iteration? Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailm

[Tutor] re weird bool

2009-02-03 Thread prasad rao
helloyes.you are right. >>> 2==True False It is an unexpected result to me. I thought any value other than 0 is True. And the solution provided by you(bool(a/1)) is useful to me. Thank you Prasad ___ Tutor maillist - Tutor@python.org http://mail.pytho

[Tutor] re division problem

2009-02-03 Thread prasad rao
> I wrote a function named vertical to print string .printable characters and .>> ASCII values in a table. >> 1)It is swallowing some characters. >> 2)It output some characters 2 or 3 times. >> 3)It prints one column more than what I asked for. >> def vertical(columns): >> import string >

[Tutor] weird bool

2009-02-03 Thread prasad rao
hi >>> a=2.1 >>> a%1==True False >>> a%1==False False >>> b=3.8 >>> b%1==True False >>> b%1==False False If it gives correct bool, it could be put to good use. Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Division problems

2009-02-03 Thread prasad rao
HelloI wrote a function named vertical to print string .printable characters and ASCII values in a table. 1)It is swallowing some characters. 2)It output some characters 2 or 3 times. 3)It prints one column more than what I asked for. It may be a division problem(floating point). Its sibling call

[Tutor] Thank you

2009-01-31 Thread prasad rao
Hello Thanks .Today I learned to use operator.itemgetter() to set key. Thank you prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] set key to sort

2009-01-31 Thread prasad rao
hellI got a problem sorting a list of lists. ml= [[112, 'p'], [114, 'r'], [97, 'a'], [115, 's'], [97, 'a'], [100, 'd'], [97, 'a'], [114, 'r'], [97, 'a'], [111, 'o']] sorted(ml,key=?) How can I formulate a key to sort based on the first element of each list. sorting list of lists might have been d

[Tutor] Thanks

2009-01-10 Thread prasad rao
Hello Your code is concise and neat.It will take some time for me to understand how it is doing the job. Thank you >You have a lot of duplicated code. You can reduce the duplication by >using functions and loops. >The first step is to put all the print code into a function rather >than repe

[Tutor] multiplication table

2009-01-10 Thread prasad rao
HiI tried to print multiplication table using (*args) to pass parameters.and tried to print tables side by side.But the code looks messy .Is there a better way to do it. def mtab(*arg): for x in range(1,11): print '%3d'%(x),'x','%3d'%(arg[0]),'=','%3d'%(x*arg[0]),(' '*5),\ '%3d'%(x),'x','%3d'%(a

[Tutor] re

2009-01-07 Thread prasad rao
Hello I am trying to get a value as integer and a string. >>> class Value: def __init__(self,inte='',stri=''): self.inte=inte self.stri=stri def setvalue(self,inte='',stri=''): self.stri=str(self.inte) self.inte=int(self.stri) >>> v=Value(45) >>>

Re: [Tutor] Convert values in a list back and forth from ints

2009-01-07 Thread prasad rao
. class Value:def __init__(self, vs = ""): >... self.vs = vs >... self.v = self.asInt() >...def asInt(self): >... try: self.v = int(self.vs) >... except: self.v = None >... return self.v >...def asString(self): >...vs = str(self.vs) >...

[Tutor] repply

2009-01-04 Thread prasad rao
hi I got it right. >>> z=[] >>> for x in range(1000): if divmod(x,3)[1]==0:z.append(x) if divmod(x,5)[1]==0:z.append(x) >>> sum(set(z)) 233168 I am sorry if this is outside the perimeter of this list. ___ Tutor maillist - Tutor@python.org http://

[Tutor] project euler

2009-01-04 Thread prasad rao
hello! I got it 266333. My code== t=0 for x in range(1000): if divmod(x,3)[1]==0:t+=x if divmod(x,5)[1]==0:t+=x t=266333 Am I correct in comprehention of the problem? Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/

[Tutor] reply

2008-12-30 Thread prasad rao
Hello. Thank you.Just a small change at the optional parameter made all the difference. It seems to be a mirracle.It is an enlitenment to me. Thank you. Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] optional parameter in list comprehension

2008-12-29 Thread prasad rao
hello!I am a novice looking up to the tutor as my Guide. I got a problem while using optional parameter. #! user/bin/env python import os def myfiles(directory,extension=None): for x in [os.path.join(x,i) for x,y,z in os.walk(directory)\ for i in z if i.endswith(extension)]:prin

[Tutor] Repply

2008-12-26 Thread prasad rao
Thanks for help. > http://svn.python.org/view/python/trunk/Objects/listobject.c?rev=67498&view=markup Kent ! This is grek and latin to me.From the presence of header files it looks C++.But headerfiles are not between '<' and '>' . >But why are you trying to sort in this fashion? Alan Gauld!

[Tutor] to sort

2008-12-25 Thread prasad rao
hello I am trying to sort a list(I know there is a builtin sort method). a=[21,56,35,47,94,12] b=[] for x in a: b.append (min(a)) a.remove (min(a)) >>> a [56, 47, 94] >>> b [12, 21, 35] It is not Compleating .Doing only 3 rounds.Why? By the way how can I view the builtin code

[Tutor] To print docstrings

2008-12-04 Thread prasad rao
Hello friends. I am new to programing.I am learning Python. I failed in my attempts to retrive doc strings of methods in a module. """ for x in dir(logging): print x,x.__doc__ = for x in dir(collections): print x,collections.x.__doc__ == >>> def dd(o): zx=dir (o)