On 08/04/2011 10:03 PM, Chris Angelico wrote:
On Fri, Aug 5, 2011 at 1:34 AM, Steven D'Aprano
wrote:
Especially for a tool aimed at programmers (who else would be interested in
PyWhich?)
The use that first springs to my mind is debugging import paths etc.
If you have multiple pythons install
Hey c.l.p.,
I wrote a little python script that finds the file that a python module
came from. Does anyone see anything wrong with this script?
#!/usr/bin/python
import sys
if __name__ == '__main__':
if len(sys.argv) > 1:
try:
m = __import__(sys.argv[1])
On 08/02/2011 10:15 AM, Steven D'Aprano wrote:
So you say, but I don't believe it. Given fibo, the function you provided
earlier, the error increases with N:
fibo(82) - fib(82) # fib returns the accurate Fibonacci number
160.0
fibo(182) - fib(182)
2.92786721937918e+23
Hardly "arbitrarily s
On 08/02/2011 08:45 AM, Alain Ketterlin wrote:
produce integers. And it will fail with overflow for big values.
If it would make you feel better I can use decimal.
Also, perhaps I can name my function billy_fibo(n), which is defined as
billy_fibo(n) +error(n) = fibo(n), where error(n) can be
On 08/01/2011 06:06 PM, Steven D'Aprano wrote:
Does your definition of "fixed" mean "gives wrong results for n>= 4 "?
fibo(4) == 3
False
Well, I don't know if you're trolling or just dumb:
http://en.wikipedia.org/wiki/Fibonacci_number
In [2]: for i in range(10):
...: print fibo(i)
On 08/01/2011 05:11 AM, jc wrote:
# Get Fibonacci Value
#Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2)
#
# n = 900 is OK
# n = 1000 is ERROR , Why
#
# What Wrong?
#
I have fixed the problem for you:
def fibo(n):
phi = (1+5**.5)/2; iphi = 1-phi;
return (phi**n - iphi**n) / (5**.5)
On 7/29/2011 11:25 PM, Andrew Berg wrote:
In case you want to see the code (not complete by a long shot, and they
need to be refactored):
Module -
http://elucidation.hg.sourceforge.net/hgweb/elucidation/elucidation/file/f8da0b15ecca/elucidation.py
CLI app -
http://disillusion-cli.hg.sourceforge.n
Is xrange not a generator? I know it doesn't return a tuple or list, so
what exactly is it? Y doesn't ever complete, but x does.
x = (i for i in range(10))
y = xrange(10)
print "===X==="
while True:
for i in x:
print i
break
else:
break
print "===Y==="
while T
On 07/28/2011 11:39 AM, Ethan Furman wrote:
Traceback (most recent call last):
File "", line 3, in
TypeError: cannot create 'NoneType' instances
Why is NoneType unable to produce a None instance? I realise that None
is a singleton, but so are True and False, and bool is able to handle
returnin
On 7/27/2011 11:50 PM, harrismh777 wrote:
No one cares and don't spam the list.
--
http://mail.python.org/mailman/listinfo/python-list
On 07/27/2011 08:35 AM, Chris Angelico wrote:
On Wed, Jul 27, 2011 at 10:27 PM, Dave Angel wrote:
As Chris pointed out, you probably aren't getting the script's directory
right. After all, how can the scheduler guess where you put it? The
obvious answer is to use a full path for the script's
On 07/26/2011 11:19 AM, Eldon Ziegler wrote:
Is there a way to have the Python processor look only for bytecode
files, not .py files? We are seeing huge numbers of Linux audit messages
on production system on which only bytecode files are stored. The audit
subsystem is recording each open failure
On 07/26/2011 08:42 AM, Sells, Fred wrote:
I'm tring to unzip a buffer that is uploaded to django/python. I can
unzip the file in batch mode just fine, but when I get the buffer I get
a "BadZipfile exception. I wrote this snippet to try to isolate the
issue but I don't understand what's going o
On 07/26/2011 08:10 AM, Olenka Subota wrote:
If anyone of you can help, please do it..
Thanks!
You would probably get a better answer asking on one of the mailing
lists here: http://new.scipy.org/mailing-lists.html
--
http://mail.python.org/mailman/listinfo/python-list
On 07/25/2011 05:48 AM, Steven D'Aprano wrote:
But if you're calling a function in both cases:
map(int, data)
[int(x) for x in data]
I am aware the premature optimization is a danger, but its also
incorrect to ignore potential performance pitfalls.
I would favor a generator expression here
On 07/25/2011 10:16 AM, Archard Lias wrote:
On Jul 25, 2:03 pm, Ian Collins wrote:
On 07/26/11 12:00 AM, Archard Lias wrote:
Hi,
Still I dont get how I am supposed to understand the pipe and its task/
idea/influece on control flow, of:
return|
??
It's simply a bitwise OR.
--
Ian Col
On 7/24/2011 2:27 PM, SigmundV wrote:
On Jul 21, 10:31 am, "Frank Millman" wrote:
Is there a short cut, or must I do this every time (I have lots of them!) ?
I know I can write a function to do this, but is there anything built-in?
I'd say that we have established that there is no shortcut, n
On 7/23/2011 2:28 PM, rantingrick wrote:
On Jul 23, 1:53 am, Frank Millman wrote:
--
The problem with that is that it will silently ignore any non-zero
digits after the point. Of course int(float(x)) does the same, which I
had overlooked.
---
On 7/23/2011 3:42 AM, Chris Angelico wrote:
int(s.rstrip('0').rstrip('.'))
Also, it will (in?)correct parse strings such as:
'16500'
to 165.
--
Bill
--
http://mail.python.org/mailman/listinfo/python-list
On 07/22/2011 10:58 AM, Grant Edwards wrote:
On 2011-07-22, Billy
Mays<81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com> wrote:
Properly formatted means that Python would accept the string as an
argument to float() without raising an exception.
Then you can't assume
On 07/22/2011 10:21 AM, Grant Edwards wrote:
While that may be clear to you, that's because you've made some
assumptions. "Convert a properly formatted string representation of a
floating point number to an integer" is not a rigorous definition.
What does "properly formatted" mean? Who says t
On 7/21/2011 10:40 PM, Thomas 'PointedEars' Lahn wrote:
Billy Mays wrote:
On 07/21/2011 08:46 AM, Web Dreamer wrote:
If you do not want to use 'float()' try:
int(x.split('.')[0])
This is right.
Assuming that the value of `x' is in the proper format, of
On 07/21/2011 01:41 PM, Gary Herron wrote:
On 07/21/2011 10:23 AM, Billy Mays wrote:
On 07/21/2011 01:02 PM, Gary wrote:
Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the
directory.
I made up an empty file a.txt file with nothing
On 07/21/2011 01:02 PM, Gary wrote:
Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the directory.
I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks
total =
On 07/21/2011 08:46 AM, Web Dreamer wrote:
If you do not want to use 'float()' try:
int(x.split('.')[0])
This is right.
But, the problem is the same as with int(float(x)), the integer number is
still not as close as possible as the original float value.
I would in fact consider doing this:
On 07/19/2011 02:24 PM, Chess Club wrote:
Hello,
I used sys.path.append() to add to the path directory, but the changes
made are not saved when I exit the compiler. Is there a way to save
it?
Thank you.
Since python is running in a child process, it only affects its own
environment variables
On 07/19/2011 01:14 PM, Xah Lee wrote:
I added other unicode brackets to your list of brackets, but it seems
your code still fail to catch a file that has mismatched curly quotes.
(e.g.http://xahlee.org/p/time_machine/tm-ch04.html )
LOL Billy.
Xah
I suspect its due to the file mode being o
On 07/19/2011 01:02 PM, Terry Reedy wrote:
You did not answer Ben's question about the allowed values of self.tok
and whether you really want to clobber all 'false' values. The proper
code depends on that answer.
NULL is an enumerated value I have defined above. The idea is for
peekToken to re
On 07/19/2011 01:00 PM, Micah wrote:
That sounds artificially backwards; why not let getToken() reuse peekToken()?
def peek(self):
if self.tok is None:
try:
self.tok = self.gen.next()
except StopIteration:
self.tok = NULL
return self.tok
def
On 07/19/2011 09:43 AM, Ben Finney wrote:
Billy Mays
<81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com> writes:
I have a method getToken() which checks to see if a value is set, and
if so, return it. However, it doesn't feel pythonic to me:
Clearly that's beca
I have a method getToken() which checks to see if a value is set, and if
so, return it. However, it doesn't feel pythonic to me:
def getToken(self):
if self.tok:
t = self.tok
self.tok = None
return t
# ...
Is there a way to trim the 'if' block to reset self.tok
On 7/18/2011 7:56 PM, Steven D'Aprano wrote:
Billy Mays wrote:
On 07/17/2011 03:47 AM, Xah Lee wrote:
2011-07-16
I gave it a shot. It doesn't do any of the Unicode delims, because
let's face it, Unicode is for goobers.
Goobers... that would be one of those new-fangled s
On 07/17/2011 03:47 AM, Xah Lee wrote:
2011-07-16
I gave it a shot. It doesn't do any of the Unicode delims, because
let's face it, Unicode is for goobers.
import sys, os
pairs = {'}':'{', ')':'(', ']':'[', '"':'"', "'":"'", '>':'<'}
valid = set( v for pair in pairs.items() for v in pair
On 07/15/2011 03:47 PM, Josh English wrote:
I remember reading that file locking doesn't work on network mounted
drives (specifically nfs mounts), but you might be able to simply create
a 'lock' (mydoc.xml.lock or the like) file for the XML doc in question.
If that file exists you could ei
On 07/15/2011 10:28 AM, Thomas Rachel wrote:
Am 15.07.2011 14:52 schrieb Billy Mays:
Also, in the python docs, file.next() mentions there
being a performance gain for using the file generator (iterator?) over
the readline function.
Here, the question is if this performance gain is really
On 07/15/2011 08:39 AM, Thomas Rachel wrote:
Am 14.07.2011 21:46 schrieb Billy Mays:
I noticed that if a file is being continuously written to, the file
generator does not notice it:
Yes. That's why there were alternative suggestions in your last thread
"How to write a file gener
On 07/15/2011 04:01 AM, bruno.desthuilli...@gmail.com wrote:
On Jul 14, 9:46 pm, Billy Mays wrote:
I noticed that if a file is being continuously written to, the file
generator does not notice it:
def getLines(f):
lines = []
for line in f:
lines.append(line)
return
On 07/14/2011 04:00 PM, Ian Kelly wrote:
On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote:
def getLines(f):
lines = []
for line in f:
lines.append(line)
return lines
with open('/var/log/syslog', 'rb') as f:
lines = getLines(f)
# do some p
I noticed that if a file is being continuously written to, the file
generator does not notice it:
def getLines(f):
lines = []
for line in f:
lines.append(line)
return lines
with open('/var/log/syslog', 'rb') as f:
lines = getLines(f)
# do some processing with lines
On 07/14/2011 11:00 AM, Christian wrote:
Hi,
I get some problem when i like to set the table name dynamic.
I'm appreciate for any help.
Christian
### works
newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s);
""" , (rs[1],rs[2]))
### works not
newcur.execute ( """ INSE
On 07/12/2011 11:52 AM, Thomas Jollans wrote:
On 07/12/2011 04:46 PM, Billy Mays wrote:
I want to make a generator that will return lines from the tail of
/var/log/syslog if there are any, but my function is reopening the file
each call:
def getLines():
with open('/var/log/syslog&
I want to make a generator that will return lines from the tail of
/var/log/syslog if there are any, but my function is reopening the file
each call:
def getLines():
with open('/var/log/syslog', 'rb') as f:
while True:
line = f.readline()
if line:
On 07/11/2011 02:59 PM, Elias Fotinis wrote:
On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel
wrote:
Just a quick suggestion regarding the way you posed your question. It's
usually better to ask if anyone knows a good tool to do a specific job
(which you would describe in your post), instead
On 07/08/2011 04:18 PM, Andrew Berg wrote:
Is it bad practice to use this
logger.error(self.preset_file + ' could not be stored - ' +
sys.exc_info()[1])
Instead of this?
logger.error('{file} could not be stored -
{error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
Other than th
On 07/08/2011 10:14 AM, TheSaint wrote:
Billy Mays wrote:
It worked surprisingly well even
with just the 64bit hash it produces.
I'd say that comparing 2 images reduced upto 32x32 bit seems too little to
find if one of the 2 portrait has a smile referred to the other.
I think it's
On 07/08/2011 07:29 AM, TheSaint wrote:
Hello,
I came across the problem that Gwenview moves the photo from the camera
memory by renaming them, but later I forgot which where moved.
Then I tought about a small script in python, but I stumbled upon my
ignorance on the way to do that.
PIL can fin
On 07/06/2011 04:02 PM, Ian Kelly wrote:
On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote:
I was looking through the python source and noticed that long multiplication
is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n
log n). I was wondering if there was a reason the
On 07/06/2011 04:05 PM, Christian Heimes wrote:
Am 06.07.2011 21:30, schrieb Billy Mays:
I was looking through the python source and noticed that long
multiplication is done using the Karatsuba method (O(~n^1.5)) rather
than using FFTs O(~n log n). I was wondering if there was a reason the
I was looking through the python source and noticed that long
multiplication is done using the Karatsuba method (O(~n^1.5)) rather
than using FFTs O(~n log n). I was wondering if there was a reason the
Karatsuba method was chosen over the FFT convolution method?
--
Bill
--
http://mail.python.
I have always found that iterating over the indices of a list/tuple is
not very clean:
for i in range(len(myList)):
doStuff(i, myList[i])
I know I could use enumerate:
for i, v in enumerate(myList):
doStuff(i, myList[i])
...but that stiff seems clunky.
Are there any better ways to
I'm trying to shorten a one-liner I have for calculating the standard
deviation of a list of numbers. I have something so far, but I was
wondering if it could be made any shorter (without imports).
Here's my function:
a=lambda d:(sum((x-1.*sum(d)/len(d))**2 for x in d)/(1.*(len(d)-1)))**.5
On 6/1/2011 12:42 PM, Ian Kelly wrote:
On Wed, Jun 1, 2011 at 7:03 AM, Billy Mays wrote:
I read this when it was on HN the other day, but I still don't see what is
special about super(). It seems (from your post) to just be a stand in for
the super class name? Is there something spec
On 5/31/2011 10:44 PM, Raymond Hettinger wrote:
I've tightened the wording a bit, made much better use of keyword
arguments instead of kwds.pop(arg), and added a section on defensive
programming (protecting a subclass from inadvertently missing an MRO
requirement). Also, there is an entry on how
53 matches
Mail list logo