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
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)
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=
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 stdin, line 1, in module
TypeError: 'fieldnames' is an invalid keyword argument for this function
2)
for x in csvr:
...
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
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:
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
.
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.
___
Tutor
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.
code
def p(a):
s=open(a,'rb')
for x in s:
On 8/29/09, Geneviève DIAGORN g...@teamlog.com 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
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 corresponding
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.
code
def sc(adir):
import os,myfiles
dest=open('C:/scripts.txt','w')
s=myfiles.myfiles(adir)
for x in s:
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.
code
def sc(adir):
import os,myfiles
dest=open('C:/scripts.html','w')
s=myfiles.myfiles(adir)
dest.write('html')
for x
But I think you want the pre tag, which means the text is
pre-formatted. And you could put that around the whole sorce file, instead
of doing p for each line.
See http://www.w3schools.com/tags/tag_pre.asp
Thank you Dave.
I put in tag pre and it worked. But at one particular line in a
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
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
On 7/30/09, Rich Lovely roadier...@googlemail.com 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
On 7/30/09, Dave Angel da...@ieee.org 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 in empty file.
Yes .I should compare with a string.Hope I will get
hello
I removed the bugs.But still getting error report.
import mcript
Traceback (most recent call last):
File pyshell#6, line 1, in module
import mcript
File C:\Python26\mcript.py, line 78, in module
a.main()
File C:\Python26\mcript.py, line 58, in main
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:
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():
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:
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 pyshell#10, line 2, in module
if sys.x is
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 module .
I
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 Regards,
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?
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 if
Alan G
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
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.
code
def myforrmat(source,desty):
so=open(source)
de=open(desty,'w')
for line in so:
? if len(line)60:de.write(line)
? if
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
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:
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
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:
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(Button-1, callback)
frame.pack()
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('Button-1',self.callback)
frame.pack()
self.event=event
self.button=Button(root,text='quit',fg='red',command=frame.quit)
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 pyshell#5, line 1, in module
pp()
File pyshell#4, line 18,
hi I modified my function ' vertical' by adding a few characters to
eliminate
the division problem.
def vertical(columns):
if columns7:
columns=7
import string
v=string.printable
v=v.replace('\n','')
v=v.replace('\t','')
if len(v)%columns !=0:
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
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
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
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
hiRight 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
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
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
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),\
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
. 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)
...return
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)
print
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
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
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
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
Thanks for help.
http://svn.python.org/view/python/trunk/Objects/listobject.c?rev=67498view=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!
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 for
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)
for
55 matches
Mail list logo