[FAQTS] Python Knowledge Base Update -- July 10th, 2000
Fiona Czuczman
fiona at sitegnome.com
Mon Jul 10 05:24:16 EDT 2000
Hi Guys,
Below are the entries that made it into http://python.faqts.com today.
regards,
Fiona Czuczman
## New Entries #################################################
-------------------------------------------------------------
How can I do this Perl paragraph mode in Python? $/ = ''; # paragraph mode
http://www.faqts.com/knowledge-base/view.phtml/aid/4629
-------------------------------------------------------------
Fiona Czuczman
Harry George
If you use pyperl:
p=pyperl.Pyperl()
p.INPUT_RECORD_SEPARATOR=''
myfile=p.open("< $filename")
lines=myfile.readlines()
-------------------------------------------------------------
Is there anywhere I can get a list of the commands for python?
http://www.faqts.com/knowledge-base/view.phtml/aid/4630
-------------------------------------------------------------
Fiona Czuczman
Peter Schneider-Kamp
Try the library and the language reference at http://www.python.org/doc
-------------------------------------------------------------
How can I ring the PC's bell (ie internal speaker) to alert the operator that an operation has finished running?
http://www.faqts.com/knowledge-base/view.phtml/aid/4632
-------------------------------------------------------------
Fiona Czuczman
David Porter
print "\a"
## Edited Entries ##############################################
-------------------------------------------------------------
Is there a command/function in python to put a delay or wait step into a program?
Does python have a sleep function? e.g. sleep(60) to wait 60 seconds?
http://www.faqts.com/knowledge-base/view.phtml/aid/2609
-------------------------------------------------------------
Nathan Wallace, Fiona Czuczman
Andreas Jung,Greg Fortune, pehr anderson
Try the sleep function in the time module.
import time
time.sleep(60)
And put this in a while loop and a statement will only execute on the
minute... That allows you to run a statement at predefined intervals
regardless of how long the command takes (as long as it takes less than
a minute or 5 or 60 or whatever you set it to) For example, I wanted to
run a ping once a minute. If I just time.sleep(60) or time.sleep(45)
even, the ping will not always take the same amount of time. Here's the
code :)
time.sleep(time.localtime(time.time())[5])
The [5] just pulls the seconds out of the time.localtime()'s return
value.
The great thing about time.sleep is that it supports floating point
numbers!
import time
time.sleep(0.1)
http://python.org/doc/current/lib/module-time.html
-------------------------------------------------------------
What is the best way of setting default options of widgets?
http://www.faqts.com/knowledge-base/view.phtml/aid/4151
-------------------------------------------------------------
Fiona Czuczman
richard_chamberlain,Cameron Laird
You can use an option database. If you create a file called optionDB
with for example the following kind of entries:
*font: Times New Roman
*Button*foreground blue
*foreground black
You can then apply these via
root.option_readfile('optionDB')
For more on this, see
http://www.regularexpressions.com/#options
-------------------------------------------------------------
Why are there no operators equivalent to C's , --, =, etc.?
http://www.faqts.com/knowledge-base/view.phtml/aid/3378
-------------------------------------------------------------
Fiona Czuczman
Fredrik Lundh, Peter Schneider-Kamp, Michael Hudson
if you write things like "var = var + 1" a lot, you might be missing
some important python idioms...
here are a few, in no specific order:
for item in sequence:
...
sequence = map(operation, sequence)
sequence.append(item)
for index in range(size):
...
for item1, item2 in map(None, sequence1, sequence):
...
for index in range(start, stop, step):
...
n = sequence.count(item)
for index in range(len(sequence)):
...
sequence.remove(item)
for index in range(len(sequence)-1, -1, -1):
...
(also note that most basic types are *immutable*, so it's not entirely
clear how things like ++ and += should work.
Michael Hudson wrote a patch for the +=, -=, *=, /= and some other
of these operators.
A patch can be found at:
http://starship.python.net/crew/mwh/aug-patch.html
http://www-jcsu.jesus.cam.ac.uk/~mwh21/aug-patch.html
-------------------------------------------------------------
Is there a utility to convert module docstrings to HTML for nice documentation?
http://www.faqts.com/knowledge-base/view.phtml/aid/4610
-------------------------------------------------------------
Stu D, Fiona Czuczman
Richard Jones
>From http://starship.python.net/crew/danilo/download.html:
Gendoc generates documentation from Python source code in different
formats. Currently it can generate HTML, MIF, MML and plain old ascii
(MIF and MML are FrameMaker formats). If you want to generate HTML
files, I strongly suggest you grab a copy of Robin Friedrich's HTMLgen
package, with which gendoc generates quite nice pages, optionally with
frames.
More information about the Python-list
mailing list