To my horror, someone pointed out to me yesterday that a web app I
wrote has been prominently displaying a misspelled word. The word was
buried in my code.
Is there a utility out there that will help spell-check literal
strings entered into Python source code? I don't mean spell-check
strings en
On May 16, 11:21 am, Lisa <[EMAIL PROTECTED]> wrote:
> I am reading in data from a text file. I want to enter each value on
> the line into a list and retain the order of the elements. The number
> of elements and spacing between them varies, but a typical line looks
> like:
>
> ' SRCPARAM 1
On May 16, 2:17 am, [EMAIL PROTECTED] wrote:
> Hi,
> Suppose i have a list v which collects some numbers,how do i
> remove the common elements from it ,without using the set() opeartor.
> Thanks
Submit this as your homework answer -- it wi
On Apr 18, 8:32 pm, [EMAIL PROTECTED] wrote:
> Instead of starting IDLE as I normally do, I started the Python
> interpreter and tried to run a program. I got a Python prompt (>>>),
> and then tried unsuccessfully to run a Python script named Script1.py
> that runs perfectly well in IDLE. Here's wh
On Apr 15, 9:30 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> I'm reading a logfile with a timestamp at the begging of each line, e.g.,
>
> Mar 29 08:29:00
>
> I want to call datetime.datetim() whose arg2 is a number between 1-12 so I
> have to convert the month to an integer.
> I wrote this, bu
Perhaps it is not as severe a security risk, but pure Python programs
can run into similar problems if they don't check user input for %
codes. Example:
>>> k = raw_input("Try to trick me: ")
Try to trick me: How about %s this?
>>> j = "User %s just entered: " + k
>>> print j % "John"
Traceback (
Yup, join is better. The problem with using form.values() is that it
will break if the HTML changes and adds some sort of new field that this
function does not care about, or if an attacker introduces bogus fields
into his query.
John Machin wrote:
> On 16/04/2006 1:43 PM, John Zenger wr
Try this:
if form.get("delete_id","") != "" and form.get("delete_data","") != ""
and...
the "get" method lets you have an optional second argument that gets
returned if the key is not in the dictionary.
Also, am I reading your code right? If I enter some fields but not all,
you print a messa
Martin v. Löwis wrote:
> As for *learning* the languages: never learn a language without a
> specific inducement. If you know you are going to write a Python
> extension, an Apache module, or a Linux kernel module in the
> near future, start learning C today. If you don't know what you
> want to u
Your list probably contains several references to the same object,
instead of several different objects. This happens often when you use a
technique like:
list = [ object ] * 100
..because although this does make copies when "object" is an integer, it
just makes references in other cases.
[E
A quick fix: change your last two functions to:
def generateNotMatching(A,n,P):
for g in gen(A,n,P,[]):
for x in g:
yield x
def gen(A,n,P,acc):
if any(imap((lambda p: allStar(p) and notNullOrZero(p,n)), P)):
yield []
else:
if n==0:
Rather than a list comprehension, it would be faster and more
memory-efficient to use a generator comprehension. Just change the
square brackets to parentheses:
for j in (i*2 for i in c if ):
print j
Grant Edwards wrote:
> On 2006-03-26, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrot
Caleb Hattingh wrote:
> Hi everyone
>
> [Short version: I put a some code below: what changes can make it run
> faster?]
On my slow notebook, your code takes about 1.5 seconds to do my
C:\Python24 dir. With a few changes my code does it in about 1 second.
Here is my code:
import os, os.path,
orangeDinosaur wrote:
> I wrote up a script in my preferred text editor. It contains maybe ten
> lines of code. I want to be able to execute those code lines with a
> single command either from the inline mode or from IDLE. How do I do
> this? I saved the file (myscript.py) in a folder that I'
Franz Steinhaeusler wrote:
>
> Thank you all for the replies.
> But I still don't have a solution.
>
> Of course with more lines it is possible,
> but it would be fine to have a "oneliner".
re.sub(r"\s+[\n\r]+", lambda x: x.expand("\g<0>"). \
lstrip(" \t\f\v"),text).rstrip()
...where "tex
How about r"\s+[\n\r]+|\s+$" ?
Franz Steinhaeusler wrote:
> Hello, I need a regularexpression, which trims trailing whitespaces.
>
> While with unix line endings, it works;
> but not with Window (Dos) CRLF's:
>
>
import re
retrailingwhitespace = re.compile('(?<=\S)[ \t]+$', re.MULTILI
wes weston wrote:
>Looping is easier with:
> for x in range(100):
>if random.randint(0,1) == 0:
> heads += 1
>else:
> tails += 1
Also, with the functional programming tools of map, filter, and lambda,
this code can be reduced to just six lines:
import random
flips = map(
If you have already read the string into memory and want a convenient
way to loop through it 3 characters at a time, check out the "batch" recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279
It uses itertools to make an iterator over the string, returning 3
characters at a ti
Steven D'Aprano wrote:
> John Zenger wrote:
>
>> I strongly agree that Python should promote range or xrange to syntax.
>> I favor [0..10] rather than [0:10] because 0..10 is inherently easier
>> to understand.
>
> "Inherently"?
>
> You
Colin J. Williams wrote:
> Bryan Cole wrote:
>
>>>
>>> First, I think the range() function in python is ugly to begin with.
>>> Why can't python just support range notation directly like 'for a in
>>> 0:10'. Or with 0..10 or 0...10 syntax. That seems to make a lot more
>>> sense to me tha
I know of no built-in way, but you could probably code this in a few
lines using print "%.1f" and so on.
(Some of us, by the way, are in the camp that believes a kilobyte is
1024 bytes, not 1000, so 103803 bytes for us is about 101.4 kilobytes).
abcd wrote:
> is there a built-in way of printing
import cgi
import cgitb; cgitb.enable() # Optional; for debugging only
print "Content-Type: text/html"
print
f = cgi.FieldStorage()
for i in f.keys():
print "",i,":",f[i].value
abcd wrote:
> i want to create a CGI script which simply prints out values given via
> the URL (such as when a GE
Tab is \t . As in:
print "coke\tpepsi"
tsvline.split("\t")
[EMAIL PROTECTED] wrote:
> How do I make a tab character in code to split a line read with tabs in
> it?
>
>
> Thanks.
>
> Tom
>
--
http://mail.python.org/mailman/listinfo/python-list
Don't overly concern yourself with your course being 100% up to date.
When learning programming, the concepts are what is important, not the
syntax or libraries you happen to be using. Even if they were to teach
you the latest and greatest features of 2.4.2, that would be out of date
in a few
It works fine for me. You must be having an indentation problem.
Also, get rid of the comma at the end of that last print statement.
Brian Blais wrote:
> Hello,
>
> I have an odd kind of Heisenbug in what looks like a pretty simple
> program. The program is a progress bar code I got at the Py
This should be just a matter of determining how your string is encoded
(ASCII, UTF, Unicode, etc.) and checking the ord of each character to
see if it is in the contiguous range of English characters for that
encoding. For example, if you know that the string is ASCII or UTF-8,
you could check
S Borg wrote:
> print >> mytextfile, '\n' #new line
Wouldn't this print two line breaks--the one you specify in the string,
plus the one always added by print if there is no comma at the end of
the statement?
--
http://mail.python.org/mailman/listinfo/python-list
As mentioned in the thread, it makes sense to build the desired output
you want from the tuple, rather than converting the tuple to a string
and then doing replace operations on the string.
If you do want to go the replace route, you don't need the power of
regex substitutions for what you are
import os, os.path
path_to_nethack_logfile = ""
for root, dirs, files in os.walk("c:\\"):
if 'nethackdir' in root:
logs = [x for x in files if 'logfile' in x]
if len(logs) > 0:
path_to_nethack_logfile = os.path.join(root, logs[0])
exit
Ron Rogers J
[EMAIL PROTECTED] wrote:
> Also I noticed if I initialize a variable
> as 0 , then I can only do integer math not floating math. this just
> seems kind of backward as I am used to php and perl which dont require
> such strict rules.
>
Not quite:
>>> foo = 0
>>> foo += 122
>>> print foo
122
>
raj wrote:
> How can I find ... if it's a file,
> whether it is an image file or not?
Assuming you are running on an operating system that uses file
extensions to indicate a file is an image (like Windows or Linux),
something like this will work:
import os.path
def isImage(filename):
retu
31 matches
Mail list logo