how the respective tab and unchecking should hide
> it.
[...]
Hi Amresh,
I suggest you try asking on the wxPython list,
[EMAIL PROTECTED] (you will probably have to
subscribe first).
The people on that list are both very knowledgable and very
oice
>if human.choice == computer.choice:
>print "Draw!"
>elif human.choice == 'rocks' and computer.choice ==
> 'paper':
>print "Computer wins!"
>computer.points = compute
d by reference if several people log in at once and run the code.
Hope I have explained myself so people can understand what I mean.
Looking forward to the light of understanding.
Regards
John Aherne
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
xt entry box.
Is there a way to catch the key_press (in this case the 'a') and check
to see if it is a number. If it is not a number, ignore it. If it is a
number accept it.
Why does the 'a' appear in 'atest'. It is like the code works first,
sets the text to
Sandro,
That's exactly what I need.
Thanks,
John.
> def callback3(self,data,widget):
>
> input = data.get_text()
> print input
> data.set_text("test")
If you don't return True, default callback will be called that ins
On 15/08/06, anil maran <[EMAIL PROTECTED]> wrote:
> hi luke
> i tried to do this for 2 weeks using the regexps
> i couldnt find it
> and hence i was asking you guys
> thanks
> anil
What have you tried? What problems we
>
> in fermat:
>
> fac = strongfac(z)
> print fac
>
> prints [0,0,0]
>
> And most of the time it does not misbehave like this.
Can you post actual code to illustrate the problem? Don't post your
entire module; just show us the functions involved, the input t
read):
def run(self):
self.running = True
while(self.running):
# do stuff
def stop(self):
self.running = False
In this case, the you call .stop() on your Worker object, and the
thread will exit when it next gets to the top of th
On 18/08/06, Amadeo Bellotti <[EMAIL PROTECTED]> wrote:
> thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to fix
> it?
Why not -- what goes wrong? Is there an error message?
--
John.
___
Tutor maillist - Tutor@pyt
l, but I expect that you can fix this by
installing a package called something like "python-tkinter".
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ong type.
I've only just started playing with it myself, but it looks pretty nifty :-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
t;
Have you tried implementing __getitem__ and __setitem__ for slice objects?
(see http://docs.python.org/ref/sequence-methods.html and
http://docs.python.org/ref/sequence-types.html#l2h-231)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
this handled by list?
Should be handled by the list. For instance if x is a list, then
list(x) is a copy of x (y=list(x) is equivalent to y=x[:]). But you
should be able to test this easily enough..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
#x27; ## ']
def getWidth(self):
return max(len(s) for s in self.rows)
def getRow(self, i):
return self.rows[i]
Then to print a string:
s = 'John Fouhy'
letters = [Letter(c) for c in s]
for i in range(HEIGHT):
for letter in letters:
print
What does the python interpreter tell you when you run the code?
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ystem variables
list control. Click "Edit" and make the changes you want...
Remember the days when information like this was actually _documented_? :-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
s where the syntax error is, sure enough. Your editor told
you; you didn't need to ask us.
In order to fix this bug, you need to figure out what you want to
achieve with this line of code, and then look at the documentation or
tutorials to figure out how to write the code correctly.
--
John.
_
ead throughout each chapter. Also,
creating good problems seems to me like it would be a difficult thing
to do, without plagiarising existing works.
Have you tried looking at programming books, or online tutorials (eg,
Alan Gauld's? Or I think "How to think like a computer scient
w, s)
will be the string s, padded to width w.
(I always forget whether it gets padded on the left or on the right,
but you can always reverse it by adding a -: '%-*s' )
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
gt;>> z
'1 2 3 4 5'
If you want to put one number on each row, you can use the newline
character '\n' as a separator instead:
>>> '\n'.join(y)
'1\n2\n3\n4\n5'
>>> print '\n'.join(y)
1
2
3
4
5
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
hing goes wrong),
especially if you can find someone to throw a sample setup.py at you.
There are people on this list who can help..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
tually used global grab before (it's pretty bad manners!),
but I think it will restrict all input to itself, and refuse attempts
to let anything else have focus. Not certain, though. But it may be
worth a try.
--
John.
___
Tutor maillist - Tutor@pytho
int and understand what
it does, but they won't know exactly what "rand" does without looking
through the rest of your code.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ld get something written in the traditional,
C++ style. Until you learn to recognise the latter and transform it
to the former, you may find learning from the web difficult.
Both Tkinter and wxpython should work across all platforms.
--
John.
_
- Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
What he said!
John Purser
--
Be careful! Is it classified?
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ling to accept
the odd error.
I'm not sure how you want to go about colourizing things, though. If
you have a postscript printer, you could generate your own postscript,
maybe..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
uot;, "r")
> TypeError: an integer is required
Looks like you're redefining 'open' somewhere. Look through your
code; do you have anything like:
def open(...):
or
open =
or
from ... import open
or
from ... import *
?
--
John.
__
etter way to achieve my objective (ie. a list method
> for generating the cleaned list?)
cleanedlist = list(set(mylist))
If you don't have python 2.4+, you will need to import the sets module.
Also, depending on what you are doing with cleanedlist, you could just
leave it as a set
",))
for row in c.fetchall():
print row
row = str(row)
c.close()
Is there a way to format the date so that the Select statement works?
Thanks,
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
_weekst >= date(?) and
rt_weekst <= date(?) and rt_type == ?', (c,d,"R",))
ProgrammingError: ('37000', 229, '[Microsoft][ODBC Visual FoxPro
Driver]Too few arguments.', 4579)
Thanks for any suggestions.
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
(a,b,"R",)
db = mx.ODBC.Windows.DriverConnect('DSN=tnt')
c = db.cursor()
c.execute(sql)
As you rightly pointed out, I needed to get my sql string formatted and
working before putting it anywhere near the c.execute command.
Many thanks,
John.
__
Will there be internal blanks? You could just scan for Cells(row,
col).Value in (None, '').
Otherwise, run makepy.py (if you haven't already) on Excel, and then
look through the code it generates. It will show you all the methods
you can call, and what arguments they expe
do this
(one-time only), your code should run faster. Also, you will get
meaningful help(), and you can look at the code it produces to get a
quick list of all the available methods, and what arguments they
expect.
You can run it from the command line, or you can run it from the menu
of the pythonwin
self.x = 1
self._y = 2
self.__z = 3
f = Foo()
print f.x
print f._y
print f.__z
> I'm 'trying' to write clear pythonic code since in all reality it gives
> a nice polish to the code when compared to writing c style.
I don't think you'll find many here who disagree with that :-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
do you get? What do you think it means?
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ain because it can't find one with
that name. If you write:
def increment():
self.value = self.value + 1
then you're referring to this variable called "self", but where is it
coming from? There's no global variable "self", it's not one of the
p
open('/Users/timothy/Desktop/t' , 'r')
for line in input:
# ...
So, in the body of the for loop, all you would need to do is decide
what to call the new file, open the file, write line to it, and then
close it.
--
John.
___
ave an earlier version of python, you can define your own
comparison function:
def myCmp(x, y):
return cmp(keyToInt(x), keyToInt(y))
arr.sort(myCmp)
You can also use the decorate-sort-undecorate idiom, which may be
faster than a custom comparison function if the list is very large.
decorated =
Generally, you should use a tuple when you have different things that
you want to clump together to make one data structure. Whereas you
should use a list when you have multiple things that are the same,
that you want to iterate over.
--
John
o see evidence before committing to that
statement :-) )
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
hon.org/mailman/listinfo/tutor
Hello Max,
my_file = open('c:\\path\to\file\file.txt', 'r')
my_file.readlines()
my_file.close()
Really, it's so simple it's hard to come up with directions. Just do
it.
John Purser
___
t;, "credits" or "license" for more information.
>>> raise SystemExit
Morpork:~ repton$
>From IDLE:
IDLE 1.1.3
>>> raise SystemExit
Traceback (most recent call last):
File "", line 1, in -toplevel-
raise SystemExit
SystemExit
>>&
#x27;tails'])
'tails'
>>> [random.choice(['heads', 'tails']) for i in range(10)]
['tails', 'tails', 'heads', 'tails', 'tails', 'tails', 'heads',
'heads', 'heads', 'heads']
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
; for i in range(10):
... break
... else:
... print 'foo'
...
>>> for i in range(10):
... pass
... else:
... print 'foo'
...
foo
>>>
There was a discussion of for..else linked in Dr Dobb's Python URL
recently:
http://grou
ss', which is python's
do-nothing statement. So the loop will exit normally, and the else:
clause will execute (resulting in the string 'foo' being printed).
Does this help?
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
e should tell people
to use random.randrange instead of random.randint!
(random.randrange takes up to 3 arguments with exactly the same
meanings as range())
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
.py or the old
> code will be used instead.
The python interpreter should check the timestamps on foo.py vs
foo.pyc, and recompile if it thinks things have changed.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Advice requested Thanks Joseph John
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
(MBPro, Tiger)
Remember that macs have a universal menu bar. If you click on the
window it created, the menubar at the top should change appropriately.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
/wiki/Double_precision
and here: http://en.wikipedia.org/wiki/IEEE_floating-point_standard
Basically, floating point numbers are of the form "x times 2**y",
where x is a binary number between 1 and 10 (that's binary 10, decimal
2). 53 bits means 53 binary digits of precision (
to seed from current time).
"""
g = Random(firstseed)
result = [g]
for i in range(num - 1):
laststate = g.getstate()
g = Random()
g.setstate(laststate)
g.jumpahead(delta)
result.
random.py before I found those, though.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
;t include the 'L':
>>> str(999L)
'999'
>>> repr(999L)
'999L'
I think the answer is "approximately, yes". But you have to be a bit
careful with talking about floating point nu
On 11/10/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
> shouldn't you mainloop your root?
By convention, you should, but you don't have to. mainloop is
mainloop; calling it on root just makes it easy to find.
--
John.
___
Tutor
the search
bar, and go straight to
http://www.python.org/doc/current/lib/module-random.html. Nifty :-)
(more quick searches here:
http://wormus.com/leakytap/Internet/CustomKeywordspython )
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
f.write('Hello ')
>>> f.close()
>>> f = open('foo', 'a')
>>> f.write('world!')
>>> f.close()
>>> f = open('foo', 'r')
>>> f.read()
'Hello world!'
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
>From the python_dev LiveJournal community ---
Predict the outcome of the following code:
##
from random import *
seed()
[choice(dict((x+1,0) for x in range(1000))) for x in range(693)][0]
##
--
John.
___
Tutor maillist - Tutor@python.org
h
eAsButton.Bind(wx.EVT_BUTTON, saveas)
You could also modify save() to automatically call saveas() if
self.filename is not set.
(just be careful of recursion if the user clicks cancel!)
Loading is the same except in the opposite direction. Look at
wx.Text
1])], zip(map((1).__add__,
lst[1:]), lst[2:]))
...
>>> pairs(a)
[(10, 15), (16, 18), (19, 20), (21, 25), (26, 30), (31, 40)]
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 17/10/06, Pine Marten <[EMAIL PROTECTED]> wrote:
>
> Thank you John for the code but I still can't get it to work and to simply
> save the contents of the text box to a file. Here is the code I have which
> just makes a panel with a text control and two buttons, "
On 18/10/06, Terry Carroll <[EMAIL PROTECTED]> wrote:
> On Sat, 14 Oct 2006, John Fouhy wrote:
>
> > >From the python_dev LiveJournal community ---
> >
> > Predict the outcome of the following code:
> >
> > ##
> > from random import *
> > s
bject. So, you can do this:
for line in contents:
m = re.search('something', line)
if m:
print line[m.start():m.end()]
match objects become more powerful when you start using groups or
named groups in your regular expressions. See the documentation for
more :-)
--
John
tion.
Um, I'm still a bit confused.
Suppose item == list2[10]. Does that mean you want to print item and list2[10]?
Won't that just mean you print item twice?
You can find the position of an element in a list by using the
list.index() method, but I'm still not sur
On 19/10/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
> The point of this script is to read a text file that has a bunch of code
> that calls external files. Then read the directory where all the files are..
> I build a list from the text file (this works correct), and I build a list
> from the dire
t '%20s%20s%20s' % ('Fail!', item, '')
You can modify near_match if you have some other definition of what
you want it to return.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
prizes for writing the shortest code possible, or for
using the fewest language features you can..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
There's also a good point made here:
http://www.artima.com/forums/flat.jsp?forum=122&thread=119914
Basically, if you want a read-only attribute, you _can_ create it by
using the built-in property as a decorator:
@property
def x(self):
return self.__x
equivalent to
def
x27;, say 'frequencies'
instead of 'item' say 'word'
So you could end up with:
textfile = open(fname, 'r')
for line in textfile:
for word in line.split():
# do something with word
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 23/10/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> or for that matter
>return range(some_var:some_var+5)
[nit-pick]
That would be
range(some_var, some_var+5)
:-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mai
__init__?
Then to use:
gadflyDB = GadflyConnection(...)
I'm not sure what you want to do with your database, so I can't really
give you a bigger use example. But do you see what is going on? In
createDB(), you create a new gadfly connection, and then assign it to
'self.d
randomList(1, 9, 9)) == range(1, 10)
>>> randomList(1, 10, 0) == []
>>> randomList(4, 3, 2)
AssertionError
>>> randomList(7, 8, 5)
AssertionError
>>> randomList(-5, 7, 9)
AssertionError
"""
(those things at the end
.FieldStorage()
widget = Widget()
for form_field in form_field_object_map:
setattr(widget, form_field_object_map[form_field],
form.getvalue(form_field))
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
t;> 'I want to strip words.'
.strip() only removes text from the beginning and end of the string.
eg:
>>> myStr = 'my words are what I want to strip'
>>> print myStr.strip('my')
words are what I want to strip
You can use
sec per loop
Morpork:~ repton$ python -m timeit -s 'import re' -s 'r =
re.compile("[0-9A-Za-z_.-]")' 'r.match("J")'
100 loops, best of 3: 1.16 usec per loop
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
h("J")'
-s means "startup code". So, 'import re' and 're.compile(...)' happen
only once, before the main test starts.
You can read help on timeit by typing 'import timeit; help(timeit)' in
the python console.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
:
PEP3099 (http://www.python.org/dev/peps/pep-3099/) makes this seem unlikely..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
structure -- perhaps:
Bill Gates
Steve Jobs
Larry Wall
That way, you could do:
>>> founderElements = companiesByName['ndtv'].findall('founder')
>>> founders = [f.text for f in founderElements]
and that would give you the founder names in a list, regar
nge.
Which part are you having trouble with?
To convert a string into a Date or Datetime object, use
time.strptime(), and then build a Datetime from the resulting
time_tuple.
(in Python2.5, I think, the datetime module has its own strptime()
function, w
Since this is a common thing to do, there is a function in the
operator module that you can use, instead of defining your own:
import operator
a.sort(key=operator.itemgetter(4))
(operator.itemgetter(4) will return a function that is basically
equivalent to item4() above)
HTH!
--
John.
___
orate:
Morpork:~/offlode repton$ python -m timeit -s 'import math' -s 'import
operator' -s 'a = [(i, math.sin(i)) for i in range(1)]' 'b =
[(e[1], e) for e in a]' 'b.sort()' '[e[1] for e in b]'
10 loops, best of 3: 33.9 msec per loop
Ho hum..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
(x0+w, y0) (x0+w, y0+h) (x0, y0+h)
I suggest experimenting to figure out which...
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
t; what is the difference between
> #!/usr/bin/python
> and
> #!/usr/bin/env python
> ?
>
> thanks
>
> ___
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/t
t;z" key press and
assign a "Down" key press but I can't get the "Down" key press to
register on the Treeview in the GUI.
Any thoughts greatly appreciated.
Thanks,
John.
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf
agine
the Tkinter mainloop() does something like:
try:
callback()
except:
# print trace to stderr
This is the only possibility I can think of at the moment. But there
could be other things going on, which is why we'd like to see an
example.
--
John.
s opposed
to, say, part of the interpreter), it's just not code that you've
written yourself.
Different GUIs might do things differently..
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 27/11/06, Dick Moores <[EMAIL PROTECTED]> wrote:
> Well, I'm having a terrible time with grid(). I do have the 6 buttons
> in the same row, but they're a real mess. Someone please run this and
> tell me how to get them looking better.
I'm not certain exactly what layout you want, but have a loo
as well, but it will lack the
mac-specific features. macports will make installing some modules
easy, though.
For what it's worth, I am using python on a mac and I am not using the
macports version.
Hope this helps.
--
John.
___
Tutor maillist
. Process events ==> call "exit" button callback.
7. Python exits.
So, you can see why clicking your exit button won't interrupt the
calculation in progress. The only way you can do that is if you can
get the event loop to start looking for events again before the
callback finish
.
The root window Tk(), and any windows you create using Toplevel(),
will display themselves. Other widgets need to be put inside a frame
and pack()ed or grid()ded (or place()d).
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
# Ctrl-S
> 0x14: 'tree', # Ctrl-T
> ord('0'): 'bookmark_0',
> ord('1'): 'bookmark_1',
> ...
>
>
> with such a keytable I am able to bind different 'def's to every
> existing
the same frame.
> Well thanks anyway. The pdf has really confused me.
> Is there an official tkinter.org doc reference or something?
Um, not really. There are official Tk docs (at http://tcl.tk), and a
few sites around with Tkinter docs (effbot, New Mexico Tech), but
nce reasons i want to run this
> entire process within the physical memory!
Have a look at the StringIO module:
http://www.python.org/doc/current/lib/module-StringIO.html
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
n.org/pipermail/tutor/2005-May/038059.html
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
('myworddoc.doc').read()
>>> t = ''.join(c for c in s if c in
string.letters+string.digits+string.punctuation+string.whitespace)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
fact, you can think of a set as a dictionary where the values are
always True (or something), and you only care about the keys.
eg:
>>> import itertools
>>> list1 = ['1', '1', '2', '3', '4']
>>> list2 = dict(zip(list1, itertools.repeat(True))).keys()
>>> list2
['1', '3', '2', '4']
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 05/12/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> The docs for os.startfile() say it is available on Windows only.
Hmm, well you could do a basic Mac version of startfile like this:
def startfile(fn):
os.system('open %s
depending on exactly what you mean by "integer".
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
After quite a while away from Python, I have decided to re-study Python. I
am interested to learn Python to support my love for Cryptography. I have a
first very easy question (did some search on Google but could not find
anything helpful). I realise that this is very basic so be gentle with me.
lem]))
return lst
According to timeit, this is over five times slower than the one-line solution:
def nodupes2(lst):
return [list(y) for y in set(tuple(x) for x in lst)]
Finally, neither of these are order-preserving...
--
John.
___
Tutor maillis
by cvs?
What about this:
cvs_header='''
###
#
# @Header:@
#
# @Revision:@
# @Author:@
# @Date:@
#
'''.replace('@', '$')
?
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
701 - 800 of 1089 matches
Mail list logo