Re: >>> CIA Squashes Democracy in Pakistan <<
In article <[EMAIL PROTECTED]>, Ivar Rosquist <[EMAIL PROTECTED]> wrote: > On Mon, 05 Nov 2007 21:43:09 +, zionist.news wrote: What has this to do with mathematics? -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] IPython 0.13 is officially out!
On 01-Jul-2012 13:56, Leo wrote: On 2012-07-01 01:55 +0800, Fernando Perez wrote: - ~6 months of work. - 373 pull requests merged. - 742 issues closed (non-pull requests). - contributions from 62 authors. - 1760 commits. - a diff of 114226 lines. Thank you for the hard work. Leo I have tried to update 0.12 in Ubuntu 12.04 but as of now it can not find 0.13. Any suggestions on how to get it into Ubuntu 12.04 would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
On 20-Jul-2012 10:27, Steven D'Aprano wrote: On Fri, 20 Jul 2012 08:20:57 +1000, Chris Angelico wrote: Since the current evidence indicates the universe will just keep expanding, it's more of a "deep freeze death..." Heat death means *lack* of heat. The second law of thermodynamics states that energy tends to go from higher states to lower, with heat being the very lowest. It's possible to do work using (say) kinetic energy, and in the process, some of that energy becomes heat. It's also possible to do work with any difference in temperature (eg Stirling engines), so the state of the universe in which it's no longer possible to do any work will be one in which all energy is heat and everything's at the same temperature. That doesn't mean a lack of heat; in fact, it implies that there'll be rather more heat than there now is, because we currently have a whole lot of chemical energy available to be used. Yes, but the point is, that heat will be *incredibly* diffuse, essentially spread over the entire universe, which will be MUCH bigger than it is now, and hence the temperature will be low even though the total amount of heat will be high. The average temperature of the universe now is about 2.7 degrees above absolute zero (i.e. 2.7 K, -270.45 C or -454.81 F), with individual hotspots reaching into millions of degrees or higher. By the time the last of the stars burn out, the average temperature will be a minuscule fraction of a degree above absolute zero, and the only hotspots will be the slowly cooling neutron stars. But in any case, that's a long way off... I once went to an astronomy lecture where the lecturer was talking about the eventual death of the sun. He said, "In about 10 billion years, the sun will consume almost all of its fuel. It will cool and expand into a red giant, and the earth will be engulfed by the expanded sun and destroyed." This fellow sitting next to me got all agitated, stood up and cried out, "Does the government know about this? We have to do something!" The lecturer said "Don't worry sir, there's no need to panic, this won't happen for billions of years." The fellow looked relived and said "Oh thank god, I thought you said *million*!" How does this relate to the python list? "This mailing list is a general discussion list for the Python programming language." --- from http://mail.python.org/mailman/listinfo/python-list/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior
On 2012-08-14 17:38, [email protected] wrote: Hi, I am migrating from PHP to Python and I am slightly confused. I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. If I comment out 'startingList.remove(str);' the code runs with both strings beginning with 'x' being put in the xOnlyList. Using the print statement I noticed that the second string that begins with 'x' isn't even identified by the function. Why does this happen? def testFunc(startingList): xOnlyList = []; for str in startingList: if (str[0] == 'x'): print str; xOnlyList.append(str) startingList.remove(str) #this seems to be the problem print xOnlyList; print startingList testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) #Thanks for your help! You might find the following useful: def testFunc(startingList): xOnlyList = []; j = -1 for xl in startingList: if (xl[0] == 'x'): xOnlyList.append(xl) else: j += 1 startingList[j] = xl if j == -1: startingList = [] else: del startingList[j:-1] return(xOnlyList) testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] xOnlyList = testFunc(testList1) print 'xOnlyList = ',xOnlyList print 'testList = ',testList1 xOnlyList = testFunc(testList2) print 'xOnlyList = ',xOnlyList print 'testList = ',testList2 xOnlyList = testFunc(testList3) print 'xOnlyList = ',xOnlyList print 'testList = ',testList3 xOnlyList = testFunc(testList4) print 'xOnlyList = ',xOnlyList print 'testList = ',testList4 And here is another version using list comprehension that I prefer testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] def testFunc2(startingList): return([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) xOnlyList,testList = testFunc2(testList1) print xOnlyList print testList xOnlyList,testList = testFunc2(testList2) print xOnlyList print testList xOnlyList,testList = testFunc2(testList3) print xOnlyList print testList xOnlyList,testList = testFunc2(testList4) print xOnlyList print testList -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Re: Strange behavior
Original Message Subject:Re: Strange behavior Date: Tue, 14 Aug 2012 21:32:16 +0200 From: Virgil Stokes To: [email protected] On 2012-08-14 17:38, [email protected] wrote: Hi, I am migrating from PHP to Python and I am slightly confused. I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. If I comment out 'startingList.remove(str);' the code runs with both strings beginning with 'x' being put in the xOnlyList. Using the print statement I noticed that the second string that begins with 'x' isn't even identified by the function. Why does this happen? def testFunc(startingList): xOnlyList = []; for str in startingList: if (str[0] == 'x'): print str; xOnlyList.append(str) startingList.remove(str) #this seems to be the problem print xOnlyList; print startingList testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) #Thanks for your help! You might find the following useful: def testFunc(startingList): xOnlyList = []; j = -1 for xl in startingList: if (xl[0] == 'x'): xOnlyList.append(xl) else: j += 1 startingList[j] = xl if j == -1: startingList = [] else: del startingList[j:-1] return(xOnlyList) testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] xOnlyList = testFunc(testList1) print 'xOnlyList = ',xOnlyList print 'testList = ',testList1 xOnlyList = testFunc(testList2) print 'xOnlyList = ',xOnlyList print 'testList = ',testList2 xOnlyList = testFunc(testList3) print 'xOnlyList = ',xOnlyList print 'testList = ',testList3 xOnlyList = testFunc(testList4) print 'xOnlyList = ',xOnlyList print 'testList = ',testList4 And here is another version using list comprehension that I prefer testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] def testFunc2(startingList): return([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) xOnlyList,testList = testFunc2(testList1) print xOnlyList print testList xOnlyList,testList = testFunc2(testList2) print xOnlyList print testList xOnlyList,testList = testFunc2(testList3) print xOnlyList print testList xOnlyList,testList = testFunc2(testList4) print xOnlyList print testList -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior
On 15-Aug-2012 02:19, Steven D'Aprano wrote:
On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote:
You might find the following useful:
def testFunc(startingList):
xOnlyList = []; j = -1
for xl in startingList:
if (xl[0] == 'x'):
That's going to fail in the starting list contains an empty string. Use
xl.startswith('x') instead.
Yes, but this was by design (tacitly assumed that startingList was both a list
and non-empty).
xOnlyList.append(xl)
else:
j += 1
startingList[j] = xl
Very cunning, but I have to say that your algorithm fails the "is this
obviously correct without needing to study it?" test. Sometimes that is
unavoidable, but for something like this, there are simpler ways to solve
the same problem.
Sorry, but I do not sure what you mean here.
if j == -1:
startingList = []
else:
del startingList[j:-1]
return(xOnlyList)
And here is another version using list comprehension that I prefer
def testFunc2(startingList):
return([x for x in startingList if x[0] == 'x'], [x for x in
startingList if x[0] != 'x'])
This walks over the starting list twice, doing essentially the same thing
both times. It also fails to meet the stated requirement that
startingList is modified in place, by returning a new list instead.
This can meet the requirement that startingList is modified in place via the
call to this function (see the attached code).
Here's an example of what I mean:
py> mylist = mylist2 = ['a', 'x', 'b', 'xx', 'cx'] # two names for one
list
py> result, mylist = testFunc2(mylist)
py> mylist
['a', 'b', 'cx']
py> mylist2 # should be same as mylist
['a', 'x', 'b', 'xx', 'cx']
Yes, I had a typo in my original posting --- sorry about that!
Here is the obvious algorithm for extracting and removing words starting
with 'x'. It walks the starting list only once, and modifies it in place.
The only trick needed is list slice assignment at the end.
def extract_x_words(words):
words_with_x = []
words_without_x = []
for word in words:
if word.startswith('x'):
words_with_x.append(word)
else:
words_without_x.append(word)
words[:] = words_without_x # slice assignment
return words_with_x
Suppose words was not a list --- you have tacitly assumed that words is a list.
The only downside of this is that if the list of words is so enormous
that you can fit it in memory *once* but not *twice*, this may fail. But
the same applies to the list comprehension solution.
But, this is not the only downside if speed is important --- it is slower than
the list comprehension method (see results that follows).
Here is a summary of three algorithms (algorithm-1, algorithm-2, algorithm-2A)
that I tested (see attached code). Note, algorithm-2A was obtained by removing
the slice assignment in the above code and modifying the return as follows
def extract_x_words(words):
words_with_x = []
words_without_x = []
for word in words:
if word.startswith('x'):
words_with_x.append(word)
else:
words_without_x.append(word)
#words[:] = words_without_x # slice assignment
return words_with_x, words_without_x
Of course, one needs to modify the call for "in-place" update of startingList as
follows:
xOnlyList,startingList = extract_x_words(startingList)
Here is a summary of my timing results obtained for 3 different algorithms for
lists with 100,000 strings of length 4 in each list:
Method
average (sd) time in seconds
algorithm-1 (list comprehension)
0.11630 (0.0014)
algorithm-2 (S. D'Aprano)
0.17594 (0.0014)
algorithm-2A (modified S. D'Aprano)
0.18217 (0.0023)
These values were obtained from 100 independent runs (MC simulations) on lists
that contain 100,000 strings. Approximately 50% of these strings contained a
leading 'x'. Note, that the results show that algorithm-2 (suggested by S.
D'Aprano) is approximately 51% slower than algorithm-1 (list comprehensions) and
algorithm-2A (simple modification of algorithm-2) is approximately 57% slower
than algorithm-1. Why is algorithm-2A slower than algorithm-2?
I would be interested in seeing code that is faster than algorithm-1 --- any
suggestions are welcomed. And of course, if there are any errors in my attached
code please inform me of them and I will try to correct them as soon as
possible. Note, some of the code is actually irrelevant for the original
"Strange behavior" post.
Have a good day!
'''
Purpose: Time three different algorithms for the same task
Author: V. Stoke
Re: Strange behavior
On 16-Aug-2012 15:02, Peter Otten wrote:
Virgil Stokes wrote:
def testFunc(startingList):
xOnlyList = []; j = -1
for xl in startingList:
if (xl[0] == 'x'):
That's going to fail in the starting list contains an empty string. Use
xl.startswith('x') instead.
Yes, but this was by design (tacitly assumed that startingList was both a
list and non-empty).
You missunderstood it will fail if the list contains an empty string, not if
the list itself is empty:
words = ["alpha", "", "xgamma"]
[word for word in words if word[0] == "x"]
Traceback (most recent call last):
File "", line 1, in
IndexError: string index out of range
The startswith() version:
[word for word in words if word.startswith("x")]
['xgamma']
Also possible:
[word for word in words if word[:1] == "x"]
['xgamma']
def testFunc1(startingList):
'''
Algorithm-1
Note:
One should check for an empty startingList before
calling testFunc1 -- If this possibility exists!
'''
return([x for x in startingList if x[0] == 'x'],
[x for x in startingList if x[0] != 'x'])
I would be interested in seeing code that is faster than algorithm-1
In pure Python? Perhaps the messy variant:
def test_func(words):
nox = []
append = nox.append
withx = [x for x in words if x[0] == 'x' or append(x)]
return withx, nox
Very nice Peter,
Here are the new results for timing with your method added (algorithm-3).
Method
average (sd) time in seconds
algorithm-1 (list comprehension)
0.11774 (0.002968)
algorithm-2 (S. D'Aprano)
0.17573 (0.003385)
algorithm-2A (modified S. D'Aprano)
0.18116 (0.003081)
algorithm-3 (improved list comprehension)
0.06639 (0.001728)
Algorithm-3 is 43% faster than algorithm-1. Again, the code used to obtain
these results is attached.
Thanks Peter for your contribution
'''
Purpose: Time four different algorithms for the same task
Author: V. Stokes ([email protected], 2012-08-16 (15:46), 2012-08-16)
Refs:
[email protected] list
* Strange behavior, 14-Aug-2012 17:38, [email protected]
* Re: Strange behavior, 14-Aug-2012 21:40, Stokes, Virgil
* Re: Strange behavior, 15-Aug-2012 02:19, Steven D'Aprano
* Re: Strange behavior, 16-Aug-2012 15:02, Peter Otten
Notes:
1. The mean and standard deviation over the runs (MC simulations)
are estimated using recursive equations.
2. A seed (syd) is used with the RNG for repeatability. Each run is
started with a new seed to force the generation of independent
random sequences.
3. Warning! No checks are made on the parameters passed to
the functions (this was by design).
4. No effort has been made to make this code elegant. My focus was
to make the code clear and easy to understand.
5. This was executed on a Windows Vista 32-bit platform with Python 2.6.6
Processor: Intel(R) core(TM)2 Duo CPU [email protected] 3.17GHz
6. The estimated time to completion is displayed after each run.
'''
import random as random
import math as math
from time import clock # clock gives good resolution on MS Windows
def testFunc1(startingList):
'''
Algorithm-1
Note:
One should check for an empty startingList before
calling testFunc1 -- If this possibility exists!
'''
return([x for x in startingList if x[0] == 'x'],
[x for x in startingList if x[0] != 'x'])
def testFunc2(words):
'''
Algorithm-2
'''
words_with_x = []
words_without_x = []
for word in words:
if word.startswith('x'):
words_with_x.append(word)
else:
words_without_x.append(word)
words[:] = words_without_x # slice assignment
return words_with_x
def testFunc2A(words):
'''
Algorithm-2A
'''
words_with_x = []
words_without_x = []
for word in words:
if word.startswith('x'):
words_with_x.append(word)
else:
words_without_x.append(word)
#words[:] = words_without_x # slice assignment
return words_with_x, words_without_x
def testFunc3(words):
'''
Algorithm-3 (from: Peter Otten)
'''
nox = []
append = nox.append
withx = [x for x in words if x[0] == 'x' or append(x)]
return withx, nox
def genStrList(NChar,NStrng,Alph,leadChr):
'''
Purpose: Generate a list of NStrng elements with each element a string
of length NChar and constrained such that approx. 50% of the
strings will b
Re: Strange behavior
On 16-Aug-2012 19:40, Steven D'Aprano wrote:
On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote:
On 15-Aug-2012 02:19, Steven D'Aprano wrote:
On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote:
You might find the following useful:
def testFunc(startingList):
xOnlyList = []; j = -1
for xl in startingList:
if (xl[0] == 'x'):
That's going to fail in the starting list contains an empty string. Use
xl.startswith('x') instead.
Yes, but this was by design (tacitly assumed that startingList was both
a list and non-empty).
As Peter already pointed out, I said it would fail if the list contains
an empty string, not if the list was empty.
xOnlyList.append(xl)
else:
j += 1
startingList[j] = xl
Very cunning, but I have to say that your algorithm fails the "is this
obviously correct without needing to study it?" test. Sometimes that is
unavoidable, but for something like this, there are simpler ways to
solve the same problem.
Sorry, but I do not sure what you mean here.
In a perfect world, you should be able to look at a piece of code, read
it once, and see whether or not it is correct. That is what I mean by
"obviously correct". For example, if I have a function that takes an
argument, doubles it, and prints the result:
def f1(x):
print(2*x)
that is obviously correct. Whereas this is not:
def f2(x):
y = (x + 5)**2 - (x + 4)**2
sys.stdout.write(str(y - 9) + '\n')
because you have to study it to see whether or not it works correctly.
Not all programs are simple enough to be obviously correct. Sometimes you
have no choice but to write something which requires cleverness to get
the right result. But this is not one of those cases. You should almost
always prefer simple code over clever code, because the greatest expense
in programming (time, effort and money) is to make code correct.
Most code does not need to be fast. But all code needs to be correct.
[...]
This can meet the requirement that startingList is modified in place via
the call to this function (see the attached code).
Good grief! See, that's exactly the sort of thing I'm talking about.
Without *detailed* study of your attached code, how can I possibly know
what it does or whether it does it correctly?
Very strange question? Perhaps, you should work on understanding code that you
have not written, or maybe you should learn more about Python, or I really
don't know how to help you with this question.
Your timing code calculates the mean using a recursive algorithm. Why
don't you calculate the mean the standard way: add the numbers and divide
by the total? What benefit do you gain from a more complicated algorithm
when a simple one will do the job just as well?
A lot of questions that suggest you have not made much of an effort to answer
them yourself. Try a little numerical analysis/research before asking such
questions (This is how you often respond to others on this list who would like
help --- try apply your advice to other to yourself. I will give you a start:
* Knuth, D. E. (1998) /The Art of Computer Programming vol. 2: Seminumerical
Algorithms/ /(3rd edition)/. Addison-Wesley, Boston.
[hint: study p. 232]
* Welford, B. P. (1962) Note on a method for calculating sums of squares and
products. T/echnometrics/ *4*(3).
[hint: pp. 419-420]
You have spent a lot of effort creating a complicated, non-obvious piece
of timing code, with different random seeds for each run, and complicated
ways of calculating timing statistics... but unfortunately the most
important part of any timing test, the actually *timing*, is not done
correctly. Consequently, your code is not correct.
How do you know how much effort I used? Code "non-obvious" and "complicated" for
you does not mean that this is also true for others. Could you please be more
specific --- saying code is not correct without providing details is not very
useful. I did say in an earlier email in reference to my code "if there are any
errors in my attached code please inform me of them and I will try to correct
them as soon as possible".
With an average time of a fraction of a second, none of those timing
results are trustworthy, because they are vulnerable to interference from
other processes, the operating system, and other random noise.
Please explain what you mean by the timing results not being trustworthy and how
this vulnerability works --- in detail please.
You spend
a lot of time processing the timing results, but it is Garbage In,
Garbage Out -- the results are not trustworthy, and if they are correct,
it is only by accident.
Fantastic --- a lot of criticism but little that can be helpful. What
specifically is the "Garbage In"?
Later in your post, you run some tests, and are surprised by the result:
Why is
Re: Books?
On 22-Aug-2012 16:04, Steven D'Aprano wrote: On Tue, 21 Aug 2012 18:36:50 -0700, Anonymous Group wrote: What books do you recomend for learning python? Preferably free and/or online. Completely by coincidence, I have just discovered, and I mean *literally* just a few minutes ago, this book: http://www.springer.com/mathematics/computational+science+%26+engineering/book/978-3-642-30292-3 http://codingcat.com/knjige/python/A%20Primer%20on%20Scientific%20Programming%20with%20Python.pdf I wish it had existed when I was a beginner! I haven't read the whole thing, but dammit it looks like exactly the sort of book I would have adored as a newbie. (Your mileage may vary.) I second this --- this is a very good book IMHO. I have the first edition (2009) and have found it very useful. Good tip! -- http://mail.python.org/mailman/listinfo/python-list
Installation of yappi (timing module)
I have been doing some experiments with different modules for the timing of functions and code segments. One module I would like to test is yappi (thread aware timer) which is listed at PyPI. However, I have been unable to install it on Windows Vista and Windows 7 (Python 2.7 on both). I have tried both easy_install and pip (as suggested at http://code.google.com/p/yappi/). Here is what happens with easy_install C:\Users\Virgil>easy_install yappi Searching for yappi Reading http://pypi.python.org/simple/yappi/ Reading http://yappi.googlecode.com/ Best match: yappi 0.62 Downloading http://yappi.googlecode.com//files/yappi-0.62.tar.gz Processing yappi-0.62.tar.gz Writing c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\setup.cfg Running yappi-0.62\setup.py -q bdist_egg --dist-dir c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\egg-dist-tmp-t3qodo In file included from D:\python27\include\Python.h:8, from config.h:4, from _yappi.c:10: D:\python27\include\pyconfig.h:68: io.h: No such file or directory D:\python27\include\pyconfig.h:296: stdio.h: No such file or directory In file included from config.h:4, from _yappi.c:10: D:\python27\include\Python.h:19: limits.h: No such file or directory D:\python27\include\Python.h:22: #error "Something's broken. UCHAR_MAX should be defined in limits.h." D:\python27\include\Python.h:26: #error "Python's source code assumes C's unsigned char is an 8-bit type." D:\python27\include\Python.h:33: stdio.h: No such file or directory D:\python27\include\Python.h:35: #error "Python.h requires that stdio.h define NULL." D:\python27\include\Python.h:38: string.h: No such file or directory D:\python27\include\Python.h:40: errno.h: No such file or directory D:\python27\include\Python.h:42: stdlib.h: No such file or directory D:\python27\include\Python.h:49: stddef.h: No such file or directory D:\python27\include\Python.h:56: assert.h: No such file or directory In file included from D:\python27\include\Python.h:58, from config.h:4, from _yappi.c:10: D:\python27\include\pyport.h:306: stdlib.h: No such file or directory D:\python27\include\pyport.h:312: math.h: No such file or directory D:\python27\include\pyport.h:325: time.h: No such file or directory D:\python27\include\pyport.h:377: sys\stat.h: No such file or directory In file included from D:\python27\include\Python.h:85, from config.h:4, from _yappi.c:10: D:\python27\include\unicodeobject.h:4: stdarg.h: No such file or directory D:\python27\include\unicodeobject.h:57: ctype.h: No such file or directory D:\python27\include\unicodeobject.h:120: wchar.h: No such file or directory In file included from D:\python27\include\Python.h:94, from config.h:4, from _yappi.c:10: D:\python27\include\stringobject.h:10: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:98, from config.h:4, from _yappi.c:10: D:\python27\include\bytearrayobject.h:9: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:121, from config.h:4, from _yappi.c:10: D:\python27\include\pyerrors.h:319: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:126, from config.h:4, from _yappi.c:10: D:\python27\include\modsupport.h:10: stdarg.h: No such file or directory In file included from _yappi.c:10: config.h:15: stdint.h: No such file or directory In file included from _yappi.c:23: timing.h:8: windows.h: No such file or directory error: Setup script exited with error: command 'gcc' failed with exit status 1 And pip fails with similar problems (same pyconfig errors where C++ header files are not found). In both cases yappi-0.62.tar.gz was downloaded.Note: 1) I also tried to install from the source which also failed with similar problems, 2) I have both cygwin and MinGW gcc compilers on my systems and they do contain in their include folder these "missing" header files. Any suggestions on how yappi can be installed would be appreciated. --V :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Installation of yappi (timing module)
On 24-Aug-2012 12:28, Virgil Stokes wrote: I have been doing some experiments with different modules for the timing of functions and code segments. One module I would like to test is yappi (thread aware timer) which is listed at PyPI. However, I have been unable to install it on Windows Vista and Windows 7 (Python 2.7 on both). I have tried both easy_install and pip (as suggested at http://code.google.com/p/yappi/). Here is what happens with easy_install C:\Users\Virgil>easy_install yappi Searching for yappi Reading http://pypi.python.org/simple/yappi/ Reading http://yappi.googlecode.com/ Best match: yappi 0.62 Downloading http://yappi.googlecode.com//files/yappi-0.62.tar.gz Processing yappi-0.62.tar.gz Writing c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\setup.cfg Running yappi-0.62\setup.py -q bdist_egg --dist-dir c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\egg-dist-tmp-t3qodo In file included from D:\python27\include\Python.h:8, from config.h:4, from _yappi.c:10: D:\python27\include\pyconfig.h:68: io.h: No such file or directory D:\python27\include\pyconfig.h:296: stdio.h: No such file or directory In file included from config.h:4, from _yappi.c:10: D:\python27\include\Python.h:19: limits.h: No such file or directory D:\python27\include\Python.h:22: #error "Something's broken. UCHAR_MAX should be defined in limits.h." D:\python27\include\Python.h:26: #error "Python's source code assumes C's unsigned char is an 8-bit type." D:\python27\include\Python.h:33: stdio.h: No such file or directory D:\python27\include\Python.h:35: #error "Python.h requires that stdio.h define NULL." D:\python27\include\Python.h:38: string.h: No such file or directory D:\python27\include\Python.h:40: errno.h: No such file or directory D:\python27\include\Python.h:42: stdlib.h: No such file or directory D:\python27\include\Python.h:49: stddef.h: No such file or directory D:\python27\include\Python.h:56: assert.h: No such file or directory In file included from D:\python27\include\Python.h:58, from config.h:4, from _yappi.c:10: D:\python27\include\pyport.h:306: stdlib.h: No such file or directory D:\python27\include\pyport.h:312: math.h: No such file or directory D:\python27\include\pyport.h:325: time.h: No such file or directory D:\python27\include\pyport.h:377: sys\stat.h: No such file or directory In file included from D:\python27\include\Python.h:85, from config.h:4, from _yappi.c:10: D:\python27\include\unicodeobject.h:4: stdarg.h: No such file or directory D:\python27\include\unicodeobject.h:57: ctype.h: No such file or directory D:\python27\include\unicodeobject.h:120: wchar.h: No such file or directory In file included from D:\python27\include\Python.h:94, from config.h:4, from _yappi.c:10: D:\python27\include\stringobject.h:10: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:98, from config.h:4, from _yappi.c:10: D:\python27\include\bytearrayobject.h:9: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:121, from config.h:4, from _yappi.c:10: D:\python27\include\pyerrors.h:319: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:126, from config.h:4, from _yappi.c:10: D:\python27\include\modsupport.h:10: stdarg.h: No such file or directory In file included from _yappi.c:10: config.h:15: stdint.h: No such file or directory In file included from _yappi.c:23: timing.h:8: windows.h: No such file or directory error: Setup script exited with error: command 'gcc' failed with exit status 1 And pip fails with similar problems (same pyconfig errors where C++ header files are not found). In both cases yappi-0.62.tar.gz was downloaded.Note: 1) I also tried to install from the source which also failed with similar problems, 2) I have both cygwin and MinGW gcc compilers on my systems and they do contain in their include folder these "missing" header files. Any suggestions on how yappi can be installed would be appreciated. --V :-) Problem solved! The ordering of the gcc compilers in my PATH statement caused this failure. I have ordered these compilers such that the first one contains the required header files and the installation of yappi is now successful. --V -- http://mail.python.org/mailman/listinfo/python-list
Re: OT Questions
On 17-Oct-2012 11:31, Chris Angelico wrote: On Wed, Oct 17, 2012 at 5:27 PM, Dwight Hutto wrote: On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht wrote: I can't ascertain what your strengths are as I don't work with you on a daily basis (one of the many benefits of working with people smarter than you ;)). Doubt that, unless they have 160+ I.Q.'s(been seeing psychiatrists since I was 13). I'm very secure in my childlike intellectualism. A high IQ just proves ability to score well on IQ tests. On the whole, your statement strikes me as reminiscent of Sheldon Cooper's insistence that "I'm not crazy, my mother had me tested!". Personally, I've never taken an IQ test, so I don't know how well I'd score. But I'm a school dropout, never went to college/uni/TAFE/etc/etc, don't have any certifications of any sort. I'm a pretty uneducated fella, according to my résum&htmlentitiesdontworkhere; (that's "resume" when folded into ASCII). So according to how most people think about intelligence, I probably have a sub-par IQ. On the flip side, I'm a professional programmer, I run a server where people play Dungeons and Dragons, and I'm a well-respected wordsmith as Dungeon Master. Plus, I work in theatre (in fact, at the moment I'm posting from the bio box, sitting next to the follow spot that I'll be operating for the next two weeks). So I think I have enough muscle upstairs to get through life... But Dwight (and I'll continue to address you as such until you change your mail headers), a LOT of what you're saying is coming across as over-inflated ego. Maybe you are a majorly interdisciplinary learner; but boasting that you're "the most interdisciplinary learner [we] might have ever encountered" just comes across poorly. One thing I've learned from various groups is that, no matter how X you are, there's someone else who's even more X - for any X. Maybe it isn't true somewhere, maybe you really are the peak - but more than likely you aren't, and it's much more pleasant to be proved better than your claim than to be proved worse. (There are exceptions, of course. I have absolutely no doubt that I am the person most familiar with the RosMud++ code and thus the person best positioned to maintain that project. This is because I wrote it. But I am not claiming to be the best C++ programmer in the world, because there are a lot of other C++ programmers among the seven billion here.) ChrisA An excellent response Chris :-) -- http://mail.python.org/mailman/listinfo/python-list
Fast forward-backward (write-read)
I am working with some rather large data files (>100GB) that contain time series data. The data (t_k,y(t_k)), k = 0,1,...,N are stored in ASCII format. I perform various types of processing on these data (e.g. moving median, moving average, and Kalman-filter, Kalman-smoother) in a sequential manner and only a small number of these data need be stored in RAM when being processed. When performing Kalman-filtering (forward in time pass, k = 0,1,...,N) I need to save to an external file several variables (e.g. 11*32 bytes) for each (t_k, y(t_k)). These are inputs to the Kalman-smoother (backward in time pass, k = N,N-1,...,0). Thus, I will need to input these variables saved to an external file from the forward pass, in reverse order --- from last written to first written. Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 23-Oct-2012 18:09, Tim Chase wrote: On 10/23/12 09:31, Virgil Stokes wrote: I am working with some rather large data files (>100GB) that contain time series data. The data (t_k,y(t_k)), k = 0,1,...,N are stored in ASCII format. I perform various types of processing on these data (e.g. moving median, moving average, and Kalman-filter, Kalman-smoother) in a sequential manner and only a small number of these data need be stored in RAM when being processed. When performing Kalman-filtering (forward in time pass, k = 0,1,...,N) I need to save to an external file several variables (e.g. 11*32 bytes) for each (t_k, y(t_k)). These are inputs to the Kalman-smoother (backward in time pass, k = N,N-1,...,0). Thus, I will need to input these variables saved to an external file from the forward pass, in reverse order --- from last written to first written. Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? Am I missing something, or would the fairly-standard "tac" utility do the reversal you want? It should[*] be optimized to handle on-disk files in a smart manner. Not sure about "tac" --- could you provide more details on this and/or a simple example of how it could be used for fast reversed "reading" of a data file? Otherwise, if you can pad the record-lengths so they're all the same, and you know the total number of records, you can seek to Total-(RecSize*OneBasedOffset) and write the record,optionally padding if you need/can. At least on *nix-like OSes, you can seek into a sparse-file with no problems (untested on Win32). The records lengths will all be the same and yes seek could be used; but, I was hoping for a faster method. Thanks Tim! :-) -tkc [*] Just guessing here. Would be disappointed if it *wasn't*. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 23-Oct-2012 18:17, Paul Rubin wrote: Virgil Stokes writes: Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? Seeking backwards in files works, but the performance hit is significant. There is also a performance hit to scanning pointers backwards in memory, due to cache misprediction. If it's something you're just running a few times, seeking backwards the simplest approach. If you're really trying to optimize the thing, you might buffer up large chunks (like 1 MB) before writing. If you're writing once and reading multiple times, you might reverse the order of records within the chunks during the writing phase. I am writing (forward) once and reading (backward) once. You're of course taking a performance bath from writing the program in Python to begin with (unless using scipy/numpy or the like), enough that it might dominate any effects of how the files are written. I am currently using SciPy/NumPy Of course (it should go without saying) that you want to dump in a binary format rather than converting to decimal. Yes, I am doing this (but thanks for "underlining" it!) Thanks Paul :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 23-Oct-2012 18:35, Dennis Lee Bieber wrote: On Tue, 23 Oct 2012 16:31:17 +0200, Virgil Stokes declaimed the following in gmane.comp.python.general: Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? Stuff them into an SQLite3 database and retrieve using a descending sort? Have never worked with a database; but, could be worth a try (at least to compare I/O times). Thanks Dennis :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 23-Oct-2012 19:56, Tim Chase wrote: On 10/23/12 12:17, Virgil Stokes wrote: On 23-Oct-2012 18:09, Tim Chase wrote: Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? Am I missing something, or would the fairly-standard "tac" utility do the reversal you want? It should[*] be optimized to handle on-disk files in a smart manner. Not sure about "tac" --- could you provide more details on this and/or a simple example of how it could be used for fast reversed "reading" of a data file? Well, if you're reading input.txt (and assuming it's one record per line, separated by newlines), you can just use tac < input.txt > backwards.txt which will create a secondary file that is the first file in reverse order. Your program can then process this secondary file in-order (which would be backwards from your source). I might have misunderstood your difficulty, but it _sounded_ like you just want to inverse the order of a file. Yes, I do wish to inverse the order, but the "forward in time" file will be in binary. --V -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 00:36, David Hutto wrote:
Don't forget to use timeit for an average OS utilization.
I'd suggest two list comprehensions for now, until I've reviewed it some more:
forward = ["%i = %s" % (i,chr(i)) for i in range(33,126)]
backward = ["%i = %s" % (i,chr(i)) for i in range(126,32,-1)]
for var in forward:
print var
for var in backward:
print var
You could also use a dict, and iterate through a straight loop that
assigned a front and back to a dict_one = {0 : [0.100], 1 : [1.99]}
and the iterate through the loop, and call the first or second in the
dict's var list for frontwards , or backwards calls.
But there might be faster implementations, depending on other
function's usage of certain lower level functions.
Missed the part about it being a file. Use:
forward = ["%i = %s" % (i,chr(i)) for i in range(33,126)]
backward = ["%i = %s" % (i,chr(i)) for i in range(126,32,-1)]
print forward,backward
Interesting approach for small data sets (or blocks from a much larger data
set).
Thanks David :-)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 02:06, Oscar Benjamin wrote:
On 23 October 2012 15:31, Virgil Stokes wrote:
I am working with some rather large data files (>100GB) that contain time
series data. The data (t_k,y(t_k)), k = 0,1,...,N are stored in ASCII
format. I perform various types of processing on these data (e.g. moving
median, moving average, and Kalman-filter, Kalman-smoother) in a sequential
manner and only a small number of these data need be stored in RAM when
being processed. When performing Kalman-filtering (forward in time pass, k =
0,1,...,N) I need to save to an external file several variables (e.g. 11*32
bytes) for each (t_k, y(t_k)). These are inputs to the Kalman-smoother
(backward in time pass, k = N,N-1,...,0). Thus, I will need to input these
variables saved to an external file from the forward pass, in reverse order
--- from last written to first written.
Finally, to my question --- What is a fast way to write these variables to
an external file and then read them in backwards?
You mentioned elsewhere that you are using numpy. I'll assume that the
data you want to read/write are numpy arrays.
Numpy arrays can be written very efficiently in binary form using
tofile/fromfile:
import numpy
a = numpy.array([1, 2, 5], numpy.int64)
a
array([1, 2, 5])
with open('data.bin', 'wb') as f:
... a.tofile(f)
...
You can then reload the array with:
with open('data.bin', 'rb') as f:
... a2 = numpy.fromfile(f, numpy.int64)
...
a2
array([1, 2, 5])
Numpy arrays can be reversed before writing or after reading using;
a2
array([1, 2, 5])
a2[::-1]
array([5, 2, 1])
Assuming you wrote the file forwards you can make an iterator to yield
the file in chunks backwards like so (untested):
def read_backwards(f, dtype, chunksize=1024 ** 2):
dtype = numpy.dtype(dtype)
nbytes = chunksize * dtype.itemsize
f.seek(0, 2)
fpos = f.tell()
while fpos > nbytes:
f.seek(fpos, 0)
yield numpy.fromfile(f, dtype, chunksize)[::-1]
fpos -= nbytes
yield numpy.fromfile(f, dtype)[::-1]
Oscar
Ok Oscar,
Thanks for the tip and I will look into this more.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 00:57, Demian Brecht wrote: This is a classic example of why the old external processing algorithms of the 1960s and 70s will never be obsolete. No matter how much memory you have, there will always be times when you want to process more data than you can fit into memory. But surely nobody will *ever* need more than 640k… Right? Demian Brecht @demianbrecht http://demianbrecht.github.com Yes, I can still remember such quotes --- thanks for jogging my memory, Demian :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 00:53, Steven D'Aprano wrote: On Tue, 23 Oct 2012 17:50:55 -0400, David Hutto wrote: On Tue, Oct 23, 2012 at 10:31 AM, Virgil Stokes wrote: I am working with some rather large data files (>100GB) [...] Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? Don't forget to use timeit for an average OS utilization. Given that the data files are larger than 100 gigabytes, the time required to process each file is likely to be in hours, not microseconds. That being the case, timeit is the wrong tool for the job, it is optimized for timings tiny code snippets. You could use it, of course, but the added inconvenience doesn't gain you any added accuracy. Here's a neat context manager that makes timing long-running code simple: http://code.activestate.com/recipes/577896 Thanks for this link I'd suggest two list comprehensions for now, until I've reviewed it some more: I would be very surprised if the poster will be able to fit 100 gigabytes of data into even a single list comprehension, let alone two. You are correct and I have been looking at working with blocks that are sized to the RAM available for processing. This is a classic example of why the old external processing algorithms of the 1960s and 70s will never be obsolete. No matter how much memory you have, there will always be times when you want to process more data than you can fit into memory. Thanks for your insights :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 23-Oct-2012 22:03, Cousin Stanley wrote: Virgil Stokes wrote: Not sure about "tac" --- could you provide more details on this and/or a simple example of how it could be used for fast reversed "reading" of a data file ? tac is available as a command under linux $ whatis tac tac (1) - concatenate and print files in reverse $ whereis tac tac: /usr/bin/tac /usr/bin/X11/tac /usr/share/man/man1/tac.1.gz $ man tac SYNOPSIS tac [OPTION]... [FILE]... DESCRIPTION Write each FILE to standard output, last line first. With no FILE, or when FILE is -, read standard input. I only know that the tac command exists but have never used it myself Unfortunately, I may be forced to process the data on a Windows platform; but, thanks Cousin for the Linux tip. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 17:11, rusi wrote: On Oct 23, 7:52 pm, Virgil Stokes wrote: I am working with some rather large data files (>100GB) that contain time series data. The data (t_k,y(t_k)), k = 0,1,...,N are stored in ASCII format. I perform various types of processing on these data (e.g. moving median, moving average, and Kalman-filter, Kalman-smoother) in a sequential manner and only a small number of these data need be stored in RAM when being processed. When performing Kalman-filtering (forward in time pass, k = 0,1,...,N) I need to save to an external file several variables (e.g. 11*32 bytes) for each (t_k, y(t_k)). These are inputs to the Kalman-smoother (backward in time pass, k = N,N-1,...,0). Thus, I will need to input these variables saved to an external file from the forward pass, in reverse order --- from last written to first written. Finally, to my question --- What is a fast way to write these variables to an external file and then read them in backwards? Have you tried gdbm/bsddbm? They are meant for such (I believe). Probably needs to be installed for windows; works for linux. If I were you I'd try out with the giant data on linux and see if the problem is solved, then see how to install for windows Thanks Rusi :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 01:46, Paul Rubin wrote: Virgil Stokes writes: Yes, I do wish to inverse the order, but the "forward in time" file will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performance with reordering tricks but that's the first thing to try. Thanks Paul, I am working on this approach now... -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 28-Oct-2012 12:18, Dave Angel wrote: On 10/24/2012 03:14 AM, Virgil Stokes wrote: On 24-Oct-2012 01:46, Paul Rubin wrote: Virgil Stokes writes: Yes, I do wish to inverse the order, but the "forward in time" file will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performance with reordering tricks but that's the first thing to try. Thanks Paul, I am working on this approach now... If you're using mmap to map the whole file, you'll need 64bit Windows to start with. I'd be interested to know if Windows will allow you to mmap 100gb at one stroke. Have you tried it, or are you starting by figuring how to access the data from the mmap? Thanks very much for pursuing my query, Dave. I have not tried it yet --- temporarily side-tracked; but, I will post my findings on this issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 2012-10-28 19:21, Oscar Benjamin wrote:
On 28 October 2012 14:20, Virgil Stokes wrote:
On 28-Oct-2012 12:18, Dave Angel wrote:
On 10/24/2012 03:14 AM, Virgil Stokes wrote:
On 24-Oct-2012 01:46, Paul Rubin wrote:
Virgil Stokes writes:
Yes, I do wish to inverse the order, but the "forward in time" file
will be in binary.
I really think it will be simplest to just write the file in forward
order, then use mmap to read it one record at a time. It might be
possible to squeeze out a little more performance with reordering tricks
but that's the first thing to try.
Thanks Paul,
I am working on this approach now...
If you're using mmap to map the whole file, you'll need 64bit Windows to
start with. I'd be interested to know if Windows will allow you to mmap
100gb at one stroke. Have you tried it, or are you starting by figuring
how to access the data from the mmap?
Thanks very much for pursuing my query, Dave.
I have not tried it yet --- temporarily side-tracked; but, I will post my
findings on this issue.
If you are going to use mmap then look at the numpy.memmap function.
This wraps pythons mmap so that you can access the contents of the
mapped binary file as if it was a numpy array. This means that you
don't need to handle the bytes -> float conversions yourself.
import numpy
a = numpy.array([4,5,6], numpy.float64)
a
array([ 4., 5., 6.])
with open('tmp.bin', 'wb') as f: # write forwards
... a.tofile(f)
... a.tofile(f)
...
a2 = numpy.memmap('tmp.bin', numpy.float64)
a2
memmap([ 4., 5., 6., 4., 5., 6.])
a2[3]
4.0
a2[5:2:-1] # read backwards
memmap([ 6., 5., 4.])
Oscar
Thanks Oscar!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Obnoxious postings from Google Groups
On 04-Nov-2012 12:13, Jamie Paul Griffin wrote: / [email protected] wrote on Fri 2.Nov'12 at 11:39:10 -0700 / (I also hope I haven't just been suckered by a troll attempt, windows/unix is better then unix/windows being an age-old means of trolling.) No, i'm not a "troll". I was just adding my opinion to the thread, I assumed that was allowed. I didn't say UNIX is better than Windows, did I; I just feel that Windows is not -- for me anyway -- the most suitable plaform for learning about the science of computing and coding, etc... being a computer science student that's the view i have and share with those I learn with and from. Why must people be accused of trolling everytime they make a statement that conveys a preference over one platform or language, for example, than the other. Provoking someone by labeling them a troll or implying they might be is a bit childish really. Well stated Jamie --- I agree. I don't believe that all members of this list label you as a troll. --V -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Tutorials
On 18-Jan-2013 15:47, Rik wrote: Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. www.usingpython.com You have done well Rik. I like your approach to passwords for solutions and your selection of topics is quite good for a "jump start" with Python. However, I suggest that in your menu you change several of your items to lower case (for consistency with the Python language): For -> for, While -> while, if-Else -> if-else, Elif -> elif. I am curious --- what software did you use to create your nice web pages for this tutorial? In summary --- good work Rik :-) --V -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatting a column's value output
On 27-Jan-2013 17:12, [email protected] wrote: On 01/27/2013 02:04 AM, Ferrous Cranus wrote: [...] data = cur.fetchall() for row in data: print ( "" ) for item in row: print( ''' %s ''' % (item, item) ) [...] Okey, so far BUT i want the url linking to happen only for the URL column's value, and not for the hits column too. How do i apply the url link to the URL column's value only? Ferrous, 'row' has two items (the url and the hit count) in it, right? So print each separately rather than in a loop: data = cur.fetchall() for row in data: url = row[0] hits = row[1] print ( "" ) print( " %s : % (url, hits) ) It is nice to see some constructive feedback to Ferrous from the python-list. This will hopefully help to get Ferrous on the right track. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading data from 2 different files and writing to a single file
On 28-Jan-2013 15:49, Chris Angelico wrote: On Tue, Jan 29, 2013 at 1:37 AM, Dave Angel wrote: What you want is the zip() function for l,s in zip(f1, f2): #you now have one line from each file, # which you can then validate and process Note, this assumes that when a line is "bad" from either file, you're going to also ignore the corresponding line from the other. If you have to accommodate variable misses in the lining up, then your work is *much* harder. Much harder? Not really - see my solution above with a simple 'break'. Much less clear what's going on, though, it is. Iterating together over both files with zip is much cleaner. ChrisA Nice example of the power of zip, Chris :-) -- http://mail.python.org/mailman/listinfo/python-list
Fast file data retrieval?
I have a rather large ASCII file that is structured as follows header line 9 nonblank lines with alphanumeric data header line 9 nonblank lines with alphanumeric data ... ... ... header line 9 nonblank lines with alphanumeric data EOF where, a data set contains 10 lines (header + 9 nonblank) and there can be several thousand data sets in a single file. In addition,*each header has a* *unique ID code*. Is there a fast method for the retrieval of a data set from this large file given its ID code? -- http://mail.python.org/mailman/listinfo/python-list
PyOpenCV -- help?
I have tried to install PyOpenCV without success (error occurs during the installation procedure). I reported the problem to the opencv user group (http://groups.google.com/group/ctypes-opencv) but this group has not been active since June of last year. Anyone know of how to get help with PyOpenCV? -- http://mail.python.org/mailman/listinfo/python-list
How to schedule execution of code?
Suppose that I have some Python code (vers. 2.6) that has been converted into an *.exe file and can be executed on a Windows (Vista or 7) platform. What can one do to have this *.exe executed at a set of specific times each day? In addition, if a day is missed (e.g. computer on which it resides goes down), then it will be executed the next time the computer is successfully started up. It might be useful to know that the purpose of this code is to collect data from a set of RSS feeds. Any suggestions would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Processing a key pressed in Python 3.6
I would appreciate help on finding a solution to following problem. This
is the general structure of the "problem" code:
while True
# Get some data from the web and process it
...
...
# Write these data to a file
...
...
# Check if a_key has been pressed in the command window
...
...
if a_key_pressed:
# Perform some pre-termination tasks
...
...
# Close the output data file
...
...
raise SystemExit('Exit')
I am running the code with Python 3.6 on a windows 10 platform. I have
tried many approaches (mainly those posted on stackoverflow) but I have
yet to find an approach that works for this structure.
Note:
1) The code is executed in the windows 10 command window
2) I am not using wxPython, IDLE, or pyGame in this application.
3) The time to get the data, process it and write it to a file can
take from 0.5 sec to 1.5 sec
4) The key hit need not be echoed to the command window
--
https://mail.python.org/mailman/listinfo/python-list
Re: Processing a key pressed in Python 3.6 🦉
Thanks very much Chris,
This code worked perfectly for "Enter". Your knowledge of Python and
more specifically this elegant solution are greatly appreciated. I now
know that I need to learn more about threads. :-)
On 2018-01-23 20:15, Chris Angelico wrote:
On Wed, Jan 24, 2018 at 5:50 AM, Virgil Stokes wrote:
I would appreciate help on finding a solution to following problem. This is
the general structure of the "problem" code:
while True
# Get some data from the web and process it
...
...
# Write these data to a file
...
...
# Check if a_key has been pressed in the command window
...
...
if a_key_pressed:
# Perform some pre-termination tasks
...
...
# Close the output data file
...
...
raise SystemExit('Exit')
I am running the code with Python 3.6 on a windows 10 platform. I have tried
many approaches (mainly those posted on stackoverflow) but I have yet to
find an approach that works for this structure.
Note:
1) The code is executed in the windows 10 command window
2) I am not using wxPython, IDLE, or pyGame in this application.
3) The time to get the data, process it and write it to a file can
take from 0.5 sec to 1.5 sec
4) The key hit need not be echoed to the command window
Are you okay with demanding a specific key, rather than simply "press
any key"? Even better, key combination? Handle Ctrl-C by catching
KeyboardInterrupt and you can take advantage of Python's existing
cross-platform handling of the standard interrupt signal.
If Ctrl-C won't work for you, how about stipulating that it be Enter?
"Press Enter to quit" isn't too much worse than "Press any key to
quit" (plus you have less chance of accidentally terminating the
program when you don't want to). Spin off a thread to wait for enter.
I've tested this only on Linux, but it ought to work:
import threading
import time
shutdown = False
def wait_for_enter():
print("Hit Enter to quit.")
input()
global shutdown; shutdown = True
threading.Thread(target=wait_for_enter).start()
while "more work to do":
print("Getting data...")
time.sleep(1)
print("Saving data to file...")
time.sleep(1)
if shutdown:
print("Pre-termination...")
time.sleep(1)
raise SystemExit("exit")
If it doesn't, try switching around which is the secondary thread and
which is the primary - spin off a thread to do the work, then call
input() in the main thread.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Processing a key pressed in Python 3.6
Another follow-up question:
How would this code be modified to handle using the "Esc" key instead of
the "Enter" key?
On 2018-01-23 20:15, Chris Angelico wrote:
On Wed, Jan 24, 2018 at 5:50 AM, Virgil Stokes wrote:
I would appreciate help on finding a solution to following problem. This is
the general structure of the "problem" code:
while True
# Get some data from the web and process it
...
...
# Write these data to a file
...
...
# Check if a_key has been pressed in the command window
...
...
if a_key_pressed:
# Perform some pre-termination tasks
...
...
# Close the output data file
...
...
raise SystemExit('Exit')
I am running the code with Python 3.6 on a windows 10 platform. I have tried
many approaches (mainly those posted on stackoverflow) but I have yet to
find an approach that works for this structure.
Note:
1) The code is executed in the windows 10 command window
2) I am not using wxPython, IDLE, or pyGame in this application.
3) The time to get the data, process it and write it to a file can
take from 0.5 sec to 1.5 sec
4) The key hit need not be echoed to the command window
Are you okay with demanding a specific key, rather than simply "press
any key"? Even better, key combination? Handle Ctrl-C by catching
KeyboardInterrupt and you can take advantage of Python's existing
cross-platform handling of the standard interrupt signal.
If Ctrl-C won't work for you, how about stipulating that it be Enter?
"Press Enter to quit" isn't too much worse than "Press any key to
quit" (plus you have less chance of accidentally terminating the
program when you don't want to). Spin off a thread to wait for enter.
I've tested this only on Linux, but it ought to work:
import threading
import time
shutdown = False
def wait_for_enter():
print("Hit Enter to quit.")
input()
global shutdown; shutdown = True
threading.Thread(target=wait_for_enter).start()
while "more work to do":
print("Getting data...")
time.sleep(1)
print("Saving data to file...")
time.sleep(1)
if shutdown:
print("Pre-termination...")
time.sleep(1)
raise SystemExit("exit")
If it doesn't, try switching around which is the secondary thread and
which is the primary - spin off a thread to do the work, then call
input() in the main thread.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Processing a key pressed in Python 3.6
Ok Dennis,
You were correct. The following also works in the Windows 10 command window.
import time
import msvcrt
while "more work to do":
print("Getting data...")
time.sleep(1)
print("Saving data to file...")
time.sleep(1)
key = msvcrt.getwch()
#print('key: %s'%key) # just to show the result
if key == chr(27):
print("Pre-termination...")
time.sleep(1)
raise SystemExit("exit")
Note, I am using the "Esc" key to exit, which is one answer to my last
posting on this topic.
On 2018-01-23 20:37, Dennis Lee Bieber wrote:
On Tue, 23 Jan 2018 19:50:57 +0100, Virgil Stokes declaimed
the following:
I am running the code with Python 3.6 on a windows 10 platform. I have
tried many approaches (mainly those posted on stackoverflow) but I have
yet to find an approach that works for this structure.
Note:
1) The code is executed in the windows 10 command window
2) I am not using wxPython, IDLE, or pyGame in this application.
3) The time to get the data, process it and write it to a file can
take from 0.5 sec to 1.5 sec
4) The key hit need not be echoed to the command window
And none of your searching found
https://docs.python.org/3/library/msvcrt.html
which is part of the standard library (and documented in the library
manual). The module IS Windows specific, you'd have to rewrite the code to
run on Linux.
Now, if your requirement was to detect a keypress WHILE the data
fetch/processing was happening, the solution will be different.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Processing a key pressed in Python 3.6
Yes, I am aware of this Dennis. However, but, on my system I actually
had it running without the msvcrt.kbhit()
This occurred during testing while trying different options. And I was
able to reproduce this several times. Why? I do not have an answer. This
is one reason why I posted the code. It would be interesting to know if
anyone else has obtained the same results.
Note: 1) 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64
bit (AMD64)]
2) msvcrt is built-in (at least on my system)
On 2018-01-24 18:28, Dennis Lee Bieber wrote:
On Wed, 24 Jan 2018 02:13:35 +0100, Virgil Stokes *declaimed* ?
the following:
key = msvcrt.getwch()
NOTE: per documentation, that is a blocking read... It won't return
unless a key (any key) has been pressed. That means your "more work to do"
loop requires a key press for each loop.
Recommendation would be to use kbhit() first.
if msvcrt.kbhit():
key = msvcrt.getwch()
...
Consider
-=-=-=-=-
import msvcrt as ms
import time
ESCAPE = chr(27)
workPending = True
cycle = 0
while workPending:
print("Getting imaginary data %s..." % cycle)
time.sleep(1.5)
print("\tSaving imaginary data %s..." % cycle)
time.sleep(1.5)
if ms.kbhit():
key = ms.getwch()
if key == ESCAPE:
print("Pre-termination on cycle %s..." % cycle)
break
else:
print("Random keypress %r found on cycle %s..." % (key, cycle))
cycle += 1
time.sleep(1.5)
print("Termination")
-=-=-=-=-
C:\Users\Wulfraed\Documents\Python Progs>kbhit
Getting imaginary data 0...
Saving imaginary data 0...
Getting imaginary data 1...
Saving imaginary data 1...
Random keypress u'd' found on cycle 1...
Getting imaginary data 2...
Saving imaginary data 2...
Getting imaginary data 3...
Saving imaginary data 3...
Random keypress u'a' found on cycle 3...
Getting imaginary data 4...
Saving imaginary data 4...
Pre-termination on cycle 4...
Termination
C:\Users\Wulfraed\Documents\Python Progs>
--
https://mail.python.org/mailman/listinfo/python-list
Installation of tensorflow via pip -- messages?
First I upgraded my pip *C:\Python36>python -m pip install --upgrade pip* Collecting pip Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB) 100% || 1.3MB 685kB/s Installing collected packages: pip Found existing installation: pip 9.0.3 Uninstalling pip-9.0.3: Successfully uninstalled pip-9.0.3 Successfully installed pip-10.0.1 Then I upgraded tensorflow *C:\Python36>python -m pip install --upgrade tensorflow* ... ... ... The script tensorboard.exe is installed in 'C:\Python36\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. ... ... The scripts freeze_graph.exe, saved_model_cli.exe, tensorboard.exe, toco.exe and toco_from_protos.exe are installed in 'C:\Python36\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. However, this directory is in my PATH *C:\Python36>path* PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Python36\Scripts\;C:\Python36\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\; ... ... Why am I getting this message, that I need to consider adding this directory to PATH when it is already in PATH? Note, all of these *.exe files are in C:\Python36\Scripts. -- https://mail.python.org/mailman/listinfo/python-list
Re: Installation of tensorflow via pip -- messages?
Thanks Paul for the prompt reply, However, each entry in this Windows 10 path has a trailing backslash. If my memory is correct, this is the default for path directories. IMHO it would have been useful to have "warning" somewhere in these messages. On 2018-04-26 20:52, Paul Moore wrote: On 26 April 2018 at 19:33, Virgil Stokes wrote: Why am I getting this message, that I need to consider adding this directory to PATH when it is already in PATH? Note, all of these *.exe files are in C:\Python36\Scripts. The PATH entry ends with a backslash, which is confusing the check done by pip. It's a known issue and has been fixed in the development version of pip, so it'll be resolved in the next release. In the meantime, you can either remove the redundant trailing backslash from your PATH, or just ignore the warning. Paul -- https://mail.python.org/mailman/listinfo/python-list
Leading 0's syntax error in datetime.date module (Python 3.6)
Module info: Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] C:\Python36>pip show datetime Name: DateTime Version: 4.2 Summary: This package provides a DateTime data type, as known from Zope 2. Unless you need to communicate with Zope 2 APIs, you're probably better off using Python's built-in datetime module. Home-page: http://pypi.python.org/pypi/DateTime Author: Zope Foundation and Contributors Author-email: [email protected] License: ZPL 2.1 Location: c:\python36\lib\site-packages Requires: zope.interface, pytz I tried first to use Python's built-in datetime module as follows: from datetime import date, timedelta d0 = date(2018,02,01) This gave the following error: Syntax Error: invalid token: C:\Users\Virgil Stokes\Desktop\Important Notes_Files\CheckProcessingDate_02.py, line 7, pos 17 d0 = date(2018,02,01) Then I used pip to install the datetime module and the same error occurred! However, when I removed the leading 0's no syntax error was reported and the correct result was returned. d0 = date(2018,2,1) Why does the datetime.date module (both built-in and site-package) not accept leading 0's? -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything good about Python except GUI IDE?
On 2016-Feb-27 19:13, [email protected] wrote: On Saturday, 27 February 2016 18:08:36 UTC+2, Dietmar Schwertberger wrote: On 27.02.2016 12:18, [email protected] wrote: Isn't there any good GUI IDE like Visual Basic? I hope there are some less well known GUI IDEs which I did not come across. Thanks. As of today, there's no Python GUI builder comparable to VB 6. Thanks for stating this clearly. Everyone here has been trying to show me various ways to do the kind of things I will want to, but nobody clearly admits the limitations I will have to accept if I start with Python. I am starting to wonder if VB.net would be a better solution for the time being. I have learnt enough VB.net to manage my work but it is bloated and Microsoft dependent. There are some like QtDesigner or wxGlade, but they either don't generate Python code directly or they can only be used if you know the underlying toolkit good enough to create the GUI yourself. You may try out some, but I can almost guarantee you that you will come to the same result. If you want a GUI, create it yourself using either wxPython or PyQt. I will check it. I got the impression that you can create a GUI but that has to be converted to Python, and then you need a wrapper to put these forms in, and then they can be compiled or converted to *.exe with py2exe. Not a good way for development/debugging. For engineering applications that's probably the weakest point that Python has. It's holding back a lot of people... Well, for most measurement or control software a GUI is not really needed, but still people want it. In the 1980s everyone was happy with inputs from the command line on a line editor, but today people expect GUIs with graphics and often even animations. It is surprising that a language which seems very popular does not have GUI development infrastructure in place these many years after it got into common use. Regards, Dietmar I agree (at least largely) with the author of this email, in response to Dietmar. I have been working with Python for several years and often a GUI is needed, not by me; but, for users of my software where my target is usually numerical and image processing with a "don't make me think too much" GUI. I have mainly used wxPython (which is rather good, with good support); but, I find it rather awkward in practice and making an *.exe for users that includes wxPython is often a tedious process (at least from my own experiences). Perhaps my skills with wxPython and its API are lacking :-( . After re-reading some of the postings that are connected to GUI problems in the python-list, wxPython-users, and PyQT, it seems to me that an "improved IDLE" for Python might have helped to solve some of their problems. I am quite sure such a development would be well received by Python beginners and those migrating to Python from other languages (e.g. VB). While working on my first wxPython GUI project, I actually switched to VB to test my GUI design and to create an *.exe for the project --- this went rather fast, considering that I had no previous experience with VB. Only afterwards, did I return to wxPython, for implementation in Python 2.7, which took much longer with extensive refactoring. And Dietmar, please don't take this the wrong way, I also agree with some of the points that you have made. And I do like wxPython :-) -- https://mail.python.org/mailman/listinfo/python-list
Saving a file "in the background" -- How?
While running a python program I need to save some of the data that is being created. I would like to save the data to a file on a disk according to a periodical schedule (e.g. every 10 minutes). Initially, the amount of data is small (< 1 MB) but after sometime the amount of data can be >10MB. If a problem occurs during data creation, then the user should be able to start over from the last successfully saved data. For my particular application, no other file is being saved and the data should always replace (not be appended to) the previous data saved. It is important that the data be saved without any obvious distraction to the user who is busy creating more data. That is, I would like to save the data "in the background". What is a good method to perform this task using Python 2.7.8 on a Win32 platform? -- https://mail.python.org/mailman/listinfo/python-list
Re: Loading a module from a subdirectory
On 10-Mar-14 21:31, Virgil Stokes wrote:
I have the following folder-file structure:
C:/PythonCode/VideoPlayerSimulator/
+-- __init__.py (empty file)
+-- GlbVars.py (contains the single
class Glb)
C:/PythonCode/VideoPlayerSimulator/RubberBanding/
+-- __init__.py
+-- ImportDemo.py
where, ImportDemo.py contains the following code (a single line):
from VideoPlayerSimulator.GlbVars import Glb as G
gives the following error when I execute it:
*ImportError: No module named VideoPlayerSimulator.GlbVars*
Note:
1. My sys.path contains:
['C:\\PythonCode\\VideoPlayerSimulator', ...]
2. Python 2.7.5 on a Window 7 platform
3. The same ImportDemo.py file when executed on my Window Vista platform
with the same folder-file structure, *DOES NOT* give an error and
works
as expected.
Why does the error occur, and why does it not occur on the Windows
Vista platform?
After searching for more on this topic I found that the following did
work on Windows 7:
import imp
G = imp.load_source('foo',
'C:/PythonCode/VideoPlayerSimulator/GlbVars.py').Glb
But, I am still unable to determine why my first method does not work on
Window 7.
--
https://mail.python.org/mailman/listinfo/python-list
Loading a module from a subdirectory
I have the following folder-file structure: C:/PythonCode/VideoPlayerSimulator/ +-- __init__.py (empty file) +-- GlbVars.py (contains the single class Glb) C:/PythonCode/VideoPlayerSimulator/RubberBanding/ +-- __init__.py +-- ImportDemo.py where, ImportDemo.py contains the following code (a single line): from VideoPlayerSimulator.GlbVars import Glb as G gives the following error when I execute it: *ImportError: No module named VideoPlayerSimulator.GlbVars* Note: 1. My sys.path contains: ['C:\\PythonCode\\VideoPlayerSimulator', ...] 2. Python 2.7.5 on a Window 7 platform 3. The same ImportDemo.py file when executed on my Window Vista platform with the same folder-file structure, *DOES NOT* give an error and works as expected. Why does the error occur, and why does it not occur on the Windows Vista platform? -- https://mail.python.org/mailman/listinfo/python-list
Re: Sudoku solver
On 27-Mar-2015 15:09, Dave Angel wrote: On 03/27/2015 09:56 AM, Marko Rauhamaa wrote: "Frank Millman" : So what I am talking about is called a "satisfactory" puzzle, which is a subset of a "proper" puzzle. That is impossible to define, though, because some people are mental acrobats and can do a lot of deep analysis in their heads. What's satisfactory to you may not be satisfactory to me. Besides, looking for "satisfactory" patterns can involve a truckload of trial and error. I know, let's use "regular expressions" If you are interested, I have written a python (wxPython GUI) for solving Sudoku problems. It even has a "hint" mode that can be used to lead you to a solution. I have tested it on the world's hardest Sudoku (published by a Finish mathematician) and it solves it very fast. I have also written another version that finds ALL the solutions to any Sudoku problem (that has a solution) using an LP approach --- this is non-trivial. However, I have not been able to give a strict mathematical proof that it does indeed find all solutions. If you wish to really understand the mathematics behind Sudoku then I suggest the book "Taking Sudoku Seriously" by Jason Rosenhouse and Laura Taalman (Oxford University Press, 2011). Unfortunately, they do not consider the LP approach in this book (an oversight IMHO). --V. Stokes -- https://mail.python.org/mailman/listinfo/python-list
An improved version of the main snippet
I have attached what I believe to be an improved version of my main snippet for testing. --V :-) ''' Purpose: get current bid, ask and rate for currency exchanges (FOREX trading) Note: 1. yahoo seems to give the best estimates for the currency exchange rates 2. Not sure where the "bid" and "ask" values come from. 3. Not sure how often updates to currencies occur during weekdays; but very fast (real-time?) during weekdays Author: [email protected] Vesion: 2015.05.05.2 ''' import pytz from yahoo_finance import Currency from datetime import datetime import time #from time import clock # clock gives good resolution in MS Windows NUM_TICS = 500# number of values to be downloaded CURRENCY_PAIR = 'EUR/SEK' MY_TIME = "Europe/Stockholm" OTHER_TIME= "America/New_York" FILE_OT = 'CurrencyInfo.txt' PRINT_TIMEZONES = True PRINT_TIMEZONES = False if PRINT_TIMEZONES: for tz in pytz.all_timezones: time.sleep(0.5) print (tz) def updateMeanVar(x,k,mu,vr): ''' Purpose: Update the estimates for the mean and variance (recursive mean,variance) Inputs: x -- new value (x_k) k -- counter (index) for new value (1,2,...) mu -- previously estimated mean (x_k not included) vr -- previously estimated variance (x_k not included) Otputs: mu -- updated mean (with x_k included) vr -- updated variance (with x_k included) ''' delta = x - mu mu += delta/k vr += delta*(x - mu) return mu,vr def get_Times(myTimeZone=MY_TIME,otherTimeZone=OTHER_TIME): fmt = '%Y-%m-%d %H:%M:%S %Z%z' Mine = pytz.timezone(myTimeZone) Other= pytz.timezone(otherTimeZone) nowMine = datetime.now(Mine) nowOther = datetime.now(Other) return nowMine.strftime(fmt) + ' ('+nowOther.strftime(fmt)+')' DateTimeStr = get_Times() def InitFile(file=FILE_OT,currencyPair=CURRENCY_PAIR,dateTimeStr=DateTimeStr): f = open(file,'a') f.write('Currency Pair: %s, TimeStamp; %s\n'%(currencyPair,dateTimeStr)) f.write(' bid ask ratedatetime\n') return f def SaveToFile(f,Bid,Ask,Rate,dateTime): f.write('%s %s %s %s\n'%(Bid,Ask,Rate,dateTime)) pass currency_Ex = Currency(CURRENCY_PAIR.replace('/','')) fOt = InitFile() print ('Currency pair: %s'%CURRENCY_PAIR) print (' bid ask ratedatetime') prev_dateTime = currency_Ex.get_trade_datetime() NMax = NUM_TICS mu = 0.0; va = 0.0 for k in range(1,NUM_TICS+1): t0 = time.clock() currency_Ex.refresh() Bid = currency_Ex.get_bid() if Bid == None: continue Ask = currency_Ex.get_ask() if Ask == None: continue Rate = currency_Ex.get_rate() if Rate == None: continue dateTime = currency_Ex.get_trade_datetime() if dateTime == None: continue print ('%s %s %s %s'%(Bid,Ask,Rate,dateTime)) if dateTime[:16] != prev_dateTime[:16]: # Save currency exchange info when minute changes SaveToFile(fOt,Bid,Ask,Rate,dateTime) prev_dateTime = dateTime # Estimate Time To Completion (ETTC) with recursive mean of 'loop' time dt= time.clock() - t0 mu,va = updateMeanVar(dt,k,mu,va) ETTC = mu*(NMax-k) m,s = divmod(ETTC,60) h,m = divmod(m,60) print ('ETTC = %d:%02d:%03d'%(h,m,s)) fOt.close() -- https://mail.python.org/mailman/listinfo/python-list
Questions on Pickle and Shelve
Here is snippet of Python (vers. 2.7.10) code that bothers me.
import cPickle as pickle
print "Pickle lists:"
dogs = ['Rover','King','Spot','Rufus']
cats = ['Mimi','Misty','Sasha']
with open('pickle.dat', 'wb') as pfile:
pickle.dump(dogs, pfile)
pickle.dump(cats,pfile)
del(dogs); del(cats)
with open('pickle.dat', 'rb') as pfile:
dogs = pickle.load(pfile)
cats = pickle.load(pfile)
print dogs, '\n', cats, '\n'
import shelve
# Note! __exit__ attribute undefined for shelve
sfile = shelve.open('shelve.dat')
sfile['dogs'] = dogs
sfile['cats'] = cats
sfile.close()
print "Shelve entries:"
del(cats); del(dogs)
sfile = shelve.open('shelve.dat')
#print sfile
for key in sfile.keys():
print key,' - ',sfile[key]
sfile.close()
1) Which (the pickle or shelve code) takes less total RAM, if dogs and cats
were very large?
2) When the last shelve.open is given, is the entire contents of shelve.data
transferred to RAM? Note, if the print sfile is uncommented then the entire
contents of shelve.data is printed out.
I was under the impression that the entire contents of a shelved file was not
transferred to RAM when it was opened.
--
https://mail.python.org/mailman/listinfo/python-list
Test for an empty directory that could be very large if it is not empty?
Suppose I have a directory C:/Test that is either empty or contains more
than 200 files, all with the same extension (e.g. *.txt). How can I
determine if the directory is empty WITHOUT the generation of a list of
the file names in it (e.g. using os.listdir('C:/Test')) when it is not
empty?
--
https://mail.python.org/mailman/listinfo/python-list
Butterflow installation on windows
The butterflow package (https://pypi.python.org/pypi/butterflow/0.1.4a1) has recently been released. I would like to know if anyone has been able to install it on a windows platform. -- https://mail.python.org/mailman/listinfo/python-list
Execute code after Shut Down command given --- How?
I would like to execute some Python code (popup message to be displayed) when Windows Vista/7 is shut down. That is, this code should execute after "Shut Down" is given from the "Shut Down Windows" popup, but before the actual shut down sequence starts. How to write Python code to accomplish this task? -- http://mail.python.org/mailman/listinfo/python-list
Agent-based modeling
Python seems like a good language to use for agent-based modeling. However, before starting to work on a Python package for this, I would be very interested in knowing about any existing Python code for agent-based modeling. --V -- http://mail.python.org/mailman/listinfo/python-list
Re: Agent-based modeling
On 10-Nov-2011 16:16, Jerry Zhang wrote: 2011/11/10 Virgil Stokes mailto:[email protected]>> Python seems like a good language to use for agent-based modeling. However, before starting to work on a Python package for this, I would be very interested in knowing about any existing Python code for agent-based modeling. I am assuming you are talking about the pattern design -- agent pattern, right? --V -- http://mail.python.org/mailman/listinfo/python-list Sorry Jerry if my email was unclear. I am referring to agent-based modeling as defined at http://en.wikipedia.org/wiki/Agent-based_model -- http://mail.python.org/mailman/listinfo/python-list
Module msvcrt for Python
I am running Python 2.6.6 on a Windows Vista platform and for some reason the module msvcrt is not present. How can I install the msvcrt module in my Python 2.6.6? God Jul :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Module msvcrt for Python
On 18-Dec-2011 11:31, Virgil Stokes wrote: I am running Python 2.6.6 on a Windows Vista platform and for some reason the module msvcrt is not present. How can I install the msvcrt module in my Python 2.6.6? God Jul :-) I found the problem! My code was using Python 2.5 (inside cygwin) by default and there it was unable to import msvcrt. But, when I ran the same code in my Python 2.6 installation it worked as it should (msvcrt module was imported). Sorry for the "noise". Best :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is Python in the scheme of things?
On Oct 4, 4:21 pm, "gord" <[EMAIL PROTECTED]> wrote: > As a complete novice in the study of Python, I am asking myself where this > language is superior or better suited than others. For example, all I see in > the tutorials are lots of examples of list processing, arithmetic > calculations - all in a DOS-like environment. > > What is particularly disappointing is the absence of a Windows IDE, > components and an event driven paradigm. How does Python stand relative to > the big 3, namely Visual C++, Visual Basic and Delphi? I realize that these > programming packages are quite expensive now while Python is free (at least > for the package I am using - ActivePython). > > Please discuss where Python shines. > Gord Delphi, one of the big 3? Since Borland abandoned it, it can only go downward (How do you call delphi 8, 2005 and 2006, if not *downwards*?) Java is much more of a big 3 than Delphi. Use Python for a little while (let's say 1000 lines of code), and if you're not convinced after that, go back to the big 3, happily telling yourself you're not missing anything... "What's with this weird python community anyway, speaking of code 'elegance' and 'readability'? There is no such thing!" -- http://mail.python.org/mailman/listinfo/python-list
Re: Names changed to protect the guilty
MonkeeSage wrote:
> On Oct 6, 6:27 pm, [EMAIL PROTECTED] (Aahz) wrote:
> > The following line of lightly munged code was found in a publicly
> > available Python library...
>
> Yes, this violates the Holy, Inspired, Infallible Style Guide (pbuh),
> which was written by the very finger of God when the world was still in
> chaotic darkness. But I guess I'm an atheist when it comes to PEP 8. If
> it is clearer to you to make the condition explicit ("blah not False"),
> rather than implicit ("not blah"), then use the former. I say write the
> code the way *you* (and your team if applicable) are best able to read,
> write and maintain it. Then when other people tell you that it isn't
> good style, or isn't "pythonic," just stab them in the face with
> soldering iron ala Chris Walken. :)
>
> Regards,
> Jordan
I don't think it's even a matter of "If it's clearer to *you*", it's a
matter of not writing code while drunk. Isn't something like "key not
in schema.elements" universally clearer than the above mess? (If
elements has a "has_key()" method, it probably is or acts like a dict)
But I don't blame the autor of this line (The drunk thing was a joke),
I can see how it can happen: editing. You write something, and the
oops, it doesn't quite work, make a quick fix, then another, then
another. You end up with something that works, but don't notice the
ugly line you left. It happens.
However, it can *also* happen when you write code while drunk...
--
http://mail.python.org/mailman/listinfo/python-list
Re: reduce to be removed?
Dustan wrote: > According to the following page on Wikipedia: > http://en.wikipedia.org/wiki/Python_%28programming_language%29#Future_development > reduce is going to be removed in python 3.0. It talks of an > accumulation loop; I have no idea what that's supposed to mean. So, > > === > >>> x =\ > [[1,2,3], > [4,5,6], > [7,8,9]] > >>> reduce(lambda a,b:a+b, x, []) > [1, 2, 3, 4, 5, 6, 7, 8, 9] > === > > What's an accumulation loop, and how would I convert this code so it's > compatible with the future 3.0 (preferably in a short sweet expression > that I can embed in a list comprehension)? itertools.chain or sum(x,[]) -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
MonkeeSage wrote: > OK, so the devil always loses. ;P > > Regards, > Jordan Huh? The devil always loses? *turns TV on, watches the news, turns TV off* Nope, buddy. Quite the contrary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting device addresses into parts
Fabian Steiner wrote:
> I often have to deal with strings like "PCI:2:3.0" or "PCI:3.4:0" and
> need the single numbers as tuple (2, 3, 0) or (3, 4, 0). Is there any
> simple way to achieve this? So far I am using regular expressions but I
> would like to avoid them ...
>
> Regards,
> Fabian Steiner
I would personally go for regex, but what about a quick and dirty:
s.replace('.',':').split(':')[1:]
--
http://mail.python.org/mailman/listinfo/python-list
Re: About the 79 character line recommendation
Steve Bergman wrote: > As I study Python, I am trying to develop good, Pythonic, habits. For > one thing, I am trying to keep Guido's the style guide in mind. > > And I know that it starts out saying that it should not be applied in > an absolute fashion. > > However, I am finding that the 79 character line prescription is not > optimal for readability. > > Certainly, cutting back from the length of lines that I used to use has > *helped* readability. But if I triy very hard to apply 79, I think > readability suffers. If this were just something that was an issue > occasionally, I would just put it off to "know when to break the > rules". However, find myself going to 90 to 100 characters very > frequently. Now, if it were just me, I'd shoot for < 100. However, > the Python philosophy includes making code easier for others to read, > as well. > > So, I was wondering what more accomplished Python programmers thought > about this. > > While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? > > Thanks, > Steve Bergman I also think that limiting code to 80 columns often hinders readability. I personally try to limit my code to 100 columns. The end result is pretty nice. However, I'm all for the "flat is better than nested" philosophy, even when nested is under 100 columns. -- http://mail.python.org/mailman/listinfo/python-list
Refactoring test units after an extract method
This is not strictly python related, but it's not strictly TDD related either. Anyway, here it goes. There's something that I was never quite sure how to handle with test units: How to handle the test unit refactoring after a method extraction. Let's say that you have a function foo() that does A and B. You have tests for foo() that check that A and B are executed properly. Then, you add another function, bar(), that needs to do B, so you add a third function, baz() that does B and make foo() and bar() call baz(). How to you handle the tests? Copy over the tests you had for foo() and apply them to bar()? I don't like copy and pasting code. Move the B related tests to baz()'s tests? Then your tests wouldn't fail if you stopped calling baz() in foo() and bar(). What I do right now is that I mock baz() and verify that it is called in foo() and bar(), with the right arguments. Then I move the B related tests to baz(). It kind of works, but somehow, it doesn't feel like the ideal solution to me. But then again, it's kind of the same thing as if baz() was a third party function: You have to mock it to test foo() and bar() properly without testing the third party code. What do you people think? -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorating class member functions
On May 3, 9:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote:
> Okay does anyone know how to decorate class member functions?
>
> The following code gives me an error:
>
> Traceback (most recent call last):
> File "decorators2.py", line 33, in
> s.update()
> File "decorators2.py", line 13, in __call__
> retval = self.fn.__call__(*args,**kws)
> TypeError: update() takes exactly 1 argument (0 given)
>
> --
>
> #! /usr/bin/env python
>
> class Bugger (object):
> def __init__ (self, module, fn):
> self.module = module
> self.fn = fn
>
> def __call__ (self,*args, **kws):
> ret_val = self.fn(*args,**kws)
> return ret_val
>
> def instrument (module_name):
> ret_val = lambda x: Bugger(module_name, x)
> return ret_val
>
> class Stupid:
> def __init__(self):
> self.val = 1
>
> @instrument("xpd.spam")
> def update(self):
> self.val += 1
>
> s = Stupid()
> s.update()
A decorator is a function that takes one single parameter: a function.
"instrument" must return a decorator.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Decorating class member functions
On May 3, 9:33 pm, Virgil Dupras <[EMAIL PROTECTED]> wrote:
> On May 3, 9:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote:
>
>
>
> > Okay does anyone know how to decorate class member functions?
>
> > The following code gives me an error:
>
> > Traceback (most recent call last):
> > File "decorators2.py", line 33, in
> > s.update()
> > File "decorators2.py", line 13, in __call__
> > retval = self.fn.__call__(*args,**kws)
> > TypeError: update() takes exactly 1 argument (0 given)
>
> > --
>
> > #! /usr/bin/env python
>
> > class Bugger (object):
> > def __init__ (self, module, fn):
> > self.module = module
> > self.fn = fn
>
> > def __call__ (self,*args, **kws):
> > ret_val = self.fn(*args,**kws)
> > return ret_val
>
> > def instrument (module_name):
> > ret_val = lambda x: Bugger(module_name, x)
> > return ret_val
>
> > class Stupid:
> > def __init__(self):
> > self.val = 1
>
> > @instrument("xpd.spam")
> > def update(self):
> > self.val += 1
>
> > s = Stupid()
> > s.update()
>
> A decorator is a function that takes one single parameter: a function.
> "instrument" must return a decorator.
Oh wait, I just embarrassed myself. Nevermind my last post.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Decorating class member functions
On May 3, 9:21 pm, Andy Terrel <[EMAIL PROTECTED]> wrote:
> Okay does anyone know how to decorate class member functions?
>
> The following code gives me an error:
>
> Traceback (most recent call last):
> File "decorators2.py", line 33, in
> s.update()
> File "decorators2.py", line 13, in __call__
> retval = self.fn.__call__(*args,**kws)
> TypeError: update() takes exactly 1 argument (0 given)
>
> --
>
> #! /usr/bin/env python
>
> class Bugger (object):
> def __init__ (self, module, fn):
> self.module = module
> self.fn = fn
>
> def __call__ (self,*args, **kws):
> ret_val = self.fn(*args,**kws)
> return ret_val
>
> def instrument (module_name):
> ret_val = lambda x: Bugger(module_name, x)
> return ret_val
>
> class Stupid:
> def __init__(self):
> self.val = 1
>
> @instrument("xpd.spam")
> def update(self):
> self.val += 1
>
> s = Stupid()
> s.update()
Second attempt. After some fuss around, I think it's just not possible
to have a class instance as a decorator. the self gets lost in
translation.
#! /usr/bin/env python
class Caller(object):
def __init__ (self, fn):
self.fn = fn
def __call__(self, *args, **kwargs):
print 'Caller calling!', repr(args)
return self.fn(*args, **kwargs)
def mydecorator(f):
return Caller(f)
class Stupid:
def __init__(self):
self.val = 1
@mydecorator
def update(self):
self.val += 1
s = Stupid()
s.update()
Caller calling! ()
Traceback (most recent call last):
File "/Users/hsoft/Desktop/foo.py", line 22, in ?
s.update()
File "/Users/hsoft/Desktop/foo.py", line 8, in __call__
return self.fn(*args, **kwargs)
TypeError: update() takes exactly 1 argument (0 given)
But why do you want to use a class? If you want to have a decorator
with argument, you only need to have something like:
def instrument(module):
def decorator(f):
def wrapper(*args, **kwargs):
print module
return f(*args, **kwargs)
return wrapper
return decorator
--
http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3131: Supporting Non-ASCII Identifiers
On May 13, 11:44 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > PEP 1 specifies that PEP authors need to collect feedback from the > community. As the author of PEP 3131, I'd like to encourage comments > to the PEP included below, either here (comp.lang.python), or to > [EMAIL PROTECTED] > > In summary, this PEP proposes to allow non-ASCII letters as > identifiers in Python. If the PEP is accepted, the following > identifiers would also become valid as class, function, or > variable names: Löffelstiel, changé, ошибка, or 売り場 > (hoping that the latter one means "counter"). > > I believe this PEP differs from other Py3k PEPs in that it really > requires feedback from people with different cultural background > to evaluate it fully - most other PEPs are culture-neutral. > > So, please provide feedback, e.g. perhaps by answering these > questions: > - should non-ASCII identifiers be supported? why? > - would you use them if it was possible to do so? in what cases? > > Regards, > Martin > > PEP: 3131 > Title: Supporting Non-ASCII Identifiers > Version: $Revision: 55059 $ > Last-Modified: $Date: 2007-05-01 22:34:25 +0200 (Di, 01 Mai 2007) $ > Author: Martin v. Löwis <[EMAIL PROTECTED]> > Status: Draft > Type: Standards Track > Content-Type: text/x-rst > Created: 1-May-2007 > Python-Version: 3.0 > Post-History: > > Abstract > > > This PEP suggests to support non-ASCII letters (such as accented > characters, Cyrillic, Greek, Kanji, etc.) in Python identifiers. > > Rationale > = > > Python code is written by many people in the world who are not familiar > with the English language, or even well-acquainted with the Latin > writing system. Such developers often desire to define classes and > functions with names in their native languages, rather than having to > come up with an (often incorrect) English translation of the concept > they want to name. > > For some languages, common transliteration systems exist (in particular, > for the Latin-based writing systems). For other languages, users have > larger difficulties to use Latin to write their native words. > > Common Objections > = > > Some objections are often raised against proposals similar to this one. > > People claim that they will not be able to use a library if to do so > they have to use characters they cannot type on their keyboards. > However, it is the choice of the designer of the library to decide on > various constraints for using the library: people may not be able to use > the library because they cannot get physical access to the source code > (because it is not published), or because licensing prohibits usage, or > because the documentation is in a language they cannot understand. A > developer wishing to make a library widely available needs to make a > number of explicit choices (such as publication, licensing, language > of documentation, and language of identifiers). It should always be the > choice of the author to make these decisions - not the choice of the > language designers. > > In particular, projects wishing to have wide usage probably might want > to establish a policy that all identifiers, comments, and documentation > is written in English (see the GNU coding style guide for an example of > such a policy). Restricting the language to ASCII-only identifiers does > not enforce comments and documentation to be English, or the identifiers > actually to be English words, so an additional policy is necessary, > anyway. > > Specification of Language Changes > = > > The syntax of identifiers in Python will be based on the Unicode > standard annex UAX-31 [1]_, with elaboration and changes as defined > below. > > Within the ASCII range (U+0001..U+007F), the valid characters for > identifiers are the same as in Python 2.5. This specification only > introduces additional characters from outside the ASCII range. For > other characters, the classification uses the version of the Unicode > Character Database as included in the ``unicodedata`` module. > > The identifier syntax is `` *``. > > ``ID_Start`` is defined as all characters having one of the general > categories uppercase letters (Lu), lowercase letters (Ll), titlecase > letters (Lt), modifier letters (Lm), other letters (Lo), letter numbers > (Nl), plus the underscore (XXX what are "stability extensions" listed in > UAX 31). > > ``ID_Continue`` is defined as all characters in ``ID_Start``, plus > nonspacing marks (Mn), spacing combining marks (Mc), decimal number > (Nd), and connector punctuations (Pc). > > All identifiers are converted into the normal form NFC while parsing; > comparison of identifiers is based on NFC. > > Policy Specification > > > As an addition to the Python Coding style, the following policy is > prescribed: All identifiers in the Python standard library MUST use > ASCII-only identifiers, and SHOULD use English words wherever feasible. > > As an option, this specificati
Re: Good Python style?
On May 31, 3:59 am, Andreas Beyer <[EMAIL PROTECTED]> wrote: > Hi, > > I found the following quite cryptic code, which basically reads the > first column of some_file into a set. > In Python I am used to seeing much more verbose/explicit code. However, > the example below _may_ actually be faster than the usual "for line in ..." > Do you consider this code good Python style? Or would you recommend to > refrain from such complex single-line code?? > > Thanks! > Andreas > > inp = resource(some_file) > # read first entries of all non-empty lines into a set > some_set = frozenset([line.split()[0] for line in \ > filter(None, [ln.strip() for ln in inp])]) I think it would be more readable if you would take the filter out of the list comprehension, and the list comprehension out of the set. inp = resource(some_file) stripped_lines = (ln.strip() for ln in inp) splitted_lines = (line.split()[0] for line in stripped_lines if line) some_set = frozenset(splitted_lines) -- http://mail.python.org/mailman/listinfo/python-list
Re: Flatten a two-level list --> one liner?
On Mar 7, 7:14 pm, "Sergio Correia" <[EMAIL PROTECTED]> wrote: > Hi, > > I'm looking for an easy way to flatten a two level list like this > > spam = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] > > Into something like > eggs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] > > There are *no* special cases (no empty sub-lists). > > I have found two ways: > > 1) Accumulator > eggs = [] > for x in eggs: >eggs.extend(x) > > 2) Reduce > eggs = reduce(lambda x, y: x+y, spam) > > I feel the 1st way is too cumbersome (three lines), and although I > like the 2nd way (except for the lambda part), I understand reduce is > discouraged by Guido so I want to know if there is a "Better Way"(TM) > ? > > Any ideas? > > Thanks, > Sergio > > PS: Why does `sum` works only with numbers? A search in the python group should get you all the details you need. Quick answer: "sum(eggs, [])", but the "correct" way is to have a flatten() function, with those 3 lines. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 idea: reversing the order of chained assignments
On Mar 21, 9:24 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Marcin Ciura wrote: > > Steven D'Aprano wrote: > > x, y, z = 1, 2, 3 > > x = y = z > > x, y, z > >> (3, 3, 3) > > >> I certainly wouldn't expect to get (2, 3, 3). > > > Neither would I. I must have expressed myself not clearly enough. > > Currently > > x = y = z > > is roughly equivalent to > > x = z > > y = z > > I propose to change it to > > y = z > > x = z > > Cheers, > >Marcin > > The difference being ... ? > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenwebhttp://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com I think I see what Marcin means. The 'node' is changed too fast in the chain, and next is assigned to 'nextnode' instead of being assigned to node. >>> class Node: ... pass ... >>> node = Node() >>> nextnode = Node() >>> backup_node = node >>> node = node.next = nextnode >>> node.next is node True >>> hasattr(backup_node,'next') False -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 idea: reversing the order of chained assignments
On Mar 21, 10:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Virgil Dupras wrote: > > On Mar 21, 9:24 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > >> Marcin Ciura wrote: > >>> Steven D'Aprano wrote: > >>>>>>> x, y, z = 1, 2, 3 > >>>>>>> x = y = z > >>>>>>> x, y, z > >>>> (3, 3, 3) > >>>> I certainly wouldn't expect to get (2, 3, 3). > >>> Neither would I. I must have expressed myself not clearly enough. > >>> Currently > >>> x = y = z > >>> is roughly equivalent to > >>> x = z > >>> y = z > >>> I propose to change it to > >>> y = z > >>> x = z > >>> Cheers, > >>>Marcin > >> The difference being ... ? > >> -- > >> Steve Holden +44 150 684 7255 +1 800 494 3119 > >> Holden Web LLC/Ltd http://www.holdenweb.com > >> Skype: holdenwebhttp://del.icio.us/steve.holden > >> Recent Ramblings http://holdenweb.blogspot.com > > > I think I see what Marcin means. The 'node' is changed too fast in the > > chain, and next is assigned to 'nextnode' instead of being assigned to > > node. > > >>>> class Node: > > ... pass > > ... > >>>> node = Node() > >>>> nextnode = Node() > >>>> backup_node = node > >>>> node = node.next = nextnode > >>>> node.next is node > > True > >>>> hasattr(backup_node,'next') > > False > > So we should take the already well-defined semantics of assignment and > change them because it seems more obvious to J. Random User? I think I > might be a little concerned about potential code breakage there. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenwebhttp://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com I totally agree. This assignment is way too ambiguous anyway. Readability first. I just wanted to enlighten the readers on what the problem actually was since it wasn't obvious in the original post. -- http://mail.python.org/mailman/listinfo/python-list
Re: Matching Directory Names and Grouping Them
>From your example, if you want to group every path that has the same
last 9 characters, a simple solution could be something like:
groups = {}
for path in paths:
group = groups.setdefault(path[-9:],[])
group.append(path)
I didn't actually test it, there ight be syntax errors.
J wrote:
> Steve-
>
> Thanks for the reply. I think what I'm trying to say by similar is
> pattern matching. Essentially, walking through a directory tree
> starting at a specified root folder, and returning a list of all
> folders that matches a pattern, in this case, a folder name containing
> a four digit number representing year and a subdirectory name
> containing a two digit number representing a month. The matches are
> grouped together and written into a text file. I hope this helps.
>
> Kind Regards,
> J
>
> Steve Holden wrote:
> > J wrote:
> > > Hello Group-
> > >
> > > I have limited programming experience, but I'm looking for a generic
> > > way to search through a root directory for subdirectories with similar
> > > names, organize and group them by matching their subdirectory path, and
> > > then output their full paths into a text file. For example, the
> > > contents of the output text file may look like this:
> > >
> > > \Input1\2001\01\
> > > \Input2\2001\01\
> > > \Input3\2001\01\
> > >
> > > \Input1\2002\03\
> > > \Input2\2002\03\
> > > \Input3\2002\03\
> > >
> > > \Input2\2005\05\
> > > \Input3\2005\05\
> > >
> > > \Input1\2005\12\
> > > \Input3\2005\12\
> > >
> > > I tried working with python regular expressions, but so far haven't
> > > found code that can do the trick. Any help would be greatly
> > > appreciated. Thanks!
> > >
> > Define "similar".
> >
> > regards
> > Steve
> > --
> > Steve Holden +44 150 684 7255 +1 800 494 3119
> > Holden Web LLC/Ltd http://www.holdenweb.com
> > Skype: holdenweb http://del.icio.us/steve.holden
> > Blog of Note: http://holdenweb.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Inheriting str object
On Feb 5, 5:48 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I want to have a str with custom methods, but I have this problem:
>
> class myStr(str):
> def hello(self):
> return 'hello '+self
>
> s=myStr('world')
> print s.hello() # prints 'hello world'
> s=s.upper()
> print s.hello() # expected to print 'hello WORLD', but s is no longer
> myStr, it's a regular str!
>
> What can I do?
To prevent operations with your myStr class to return a simple str
instance, you will have to override pretty much all str method, as
well as magic methods, such as __add__, __radd__ etc.. Major pain in
perspective. You might want to reconsider you developing strategy.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nested Parameter Definitions
On Feb 25, 1:00 pm, "Paddy" <[EMAIL PROTECTED]> wrote:
> I blogged on finding a new-to-me feature of Python, in that you are
> allowed to nnest parameter definitions:
>
> >>> def x ((p0, p1), p2):
>
> ... return p0,p1,p2
> ...>>> x(('Does', 'this'), 'work')
>
> ('Does', 'this', 'work')
>
>
>
> Ruben commented that there was a poll on this features continued
> existence taken at PyCon and it could go.
>
> Just as I found it, it could go
>
> I wondered if those of you with some Python experience new of nested
> parameters and don't use them; or just forgot/don't know it is
> possible?
>
> - Paddy.
>
> Oh - the blog entry is
> athttp://paddy3118.blogspot.com/2007/02/pythons-function-nested-paramet...
I didn't know about it either. Without the call example, I would have
had a hard time to try to figure out what these extra brackets are
for. For this reason, I think that an explicit unpack is more
readable, and thus better.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Any simpler way to do this
On Dec 7, 9:37 am, Lars Johansen <[EMAIL PROTECTED]> wrote: > I have a function that looks like this: > > def Chooser(color): > > if color == "RED": > x = term.RED > elif color == "BLUE": > x = term.BLUE > elif color == "GREEN": > x = term.GREEN > elif color == "YELLOW": > x = term.YELLOW > elif color == "CYAN": > x = term.CYAN > elif color == "MAGENTA": > x = term.MAGENTA > return x > > Wouldn there been easier if I could just skip all the "*if's" and just > "return term.color", however this gives a syntax error, are there any > clever way to do this ? > -- > Lars Johansen <[EMAIL PROTECTED]> "return getattr(term, color)" should do the trick. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary instantiation?
On Dec 7, 9:05 am, Matt_D <[EMAIL PROTECTED]> wrote:
> Hello there, this is my first post to the list. Only been working with
> Python for a few days. Basically a complete newbie to programming.
>
> I'm working with csv module as an exercise to parse out a spreadsheet
> I use for work.(I am an editor for a military journalism unit) Not
> trying to do anything useful, just trying to manipulate the data.
> Anyway, here's the code I've got so far:
>
> import csv
> import string
> import os
>
> #Open the appropriate .csv file
> csv_file = csv.reader(open("D:\\Python25\\BNSR.csv"))
>
> #Create blank dictionary to hold {[author]:[no. of stories]} data
> story_per_author = {}
>
> def author_to_dict(): #Function to add each author to the dictionary
> once to get initial entry for that author
> for row in csv_file:
> author_count = row[-1]
> story_per_author[author_count] = 1
>
> #Fetch author names
> def rem_blank_authors(): #Function to remove entries with '' in the
> AUTHOR field of the .csv
> csv_list = list(csv_file) #Convert the open file to list format
> for e-z mode editing
> for row in csv_list:
> author_name = row[-1]
> if author_name == '': #Find entries where no author is listed
> csv_list.remove(row) #Remove those entries from the list
>
> def assign_author_to_title(): #Assign an author to every title
> author_of_title = {}
> for row in csv_file:
> title = row[3]
> author = row[-1]
> author_of_title[title] = author
>
> assign_author_to_title()
> print author_of_title
>
> --
>
> Ok, the last two lines are kind of my "test the last function" test.
> Now when I run these two lines I get the error:
>
> Traceback (most recent call last):
> File "D:\Python25\Lib\SITE-P~1\PYTHON~1\pywin\framework
> \scriptutils.py", line 310, in RunScript
> exec codeObject in __main__.__dict__
> File "D:\Python25\csv_read.py", line 33, in
> print author_of_title
> NameError: name 'author_of_title' is not defined
>
> I am guessing that the author_of_title dict does not exist outside of
> the function in which it is created? The concept of instantiation is
> sort of foreign to me so I'm having some trouble predicting when it
> happens.
>
> If I call the assign_author_to_title function later, am I going to be
> able to work with the author_of_title dictionary? Or is it best if I
> create author_of_title outside of my function definitions?
>
> Clearly I'm just stepping through my thought process right now,
> creating functions as I see a need for them. I'm sure the code is
> sloppy and terrible but please be gentle!
As you said, author_of_title doesn't exist outside of
assign_author_to_title() because it has been instantiated in the
function, and thus belong to the local scope. You could instantiate
your dictionary outside of the function, but the nicest way to handle
this would be to add a line "return author_of_title" at the end of
assign_author_to_title() and have "print assign_author_to_title()"
instead of the 2 last lines.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can I embed Windows Python in C# or VC++?
On Dec 7, 9:03 am, grbgooglefan <[EMAIL PROTECTED]> wrote:
> On Dec 7, 3:07 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>
>
>
> > En Fri, 07 Dec 2007 01:24:57 -0300, grbgooglefan <[EMAIL PROTECTED]>
> > escribió:
>
> > > On Dec 7, 12:17 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > > wrote:
> > >> En Thu, 06 Dec 2007 23:27:15 -0300, grbgooglefan <[EMAIL PROTECTED]>
> > >> escribió:
>
> > >> > I want to use Python's Windows (python25.dll) version to embed in my
> > >> > C# (or atleast VC++) program for performing syntax checks on the
> > >> > Python expressions which are later supposed to be evaluated at runtime
> > >> > by another C++ program [...]> Can I start doing the development using
> > >> the include, lib & the
> > >> > python25.dll files availale after installing this MSI?
>
> > >> Yes. You don't require the source package to embed Python and use the
> > >> API in your programs.
>
> > > Does it mean, I can embed Python in C# as well with the same APIs?
>
> > No; you can use the Python API in a native C++ application (the Python
> > code is plain C, but all the include files have the 'extern "C" {}'
> > declarations). For .NET there are IronPython and PythonNet, but I cannot
> > comment on them, surely someone else may help. See
> > http://www.python.org/about/
>
> > --
> > Gabriel Genellina- Hide quoted text -
>
> > - Show quoted text -
>
> Hello, Anybody else out there has used Python from C#?
Yes. I use Python for .Net to embed python code in my applications,
and it works pretty well.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Best way to protect my new commercial software.
On Dec 10, 8:15 am, farsheed <[EMAIL PROTECTED]> wrote: > I wrote a software and I want to protect it so can not be cracked > easily. I wrote it in python and compile it using py2exe. what is the > best way in your opinion? Don't. This is a fight you already lost. Besides, people who crack software are either students with no money or people who never buy software. Students who crack your software today might be your customers tomorrow. If your software is a real hassle to crack, they will crack your competitor's app and use it. Wouldn't you rather have them use your app? They might be talking about it to their friends. -- http://mail.python.org/mailman/listinfo/python-list
Re: a Python person's experience with Ruby
On Dec 9, 1:15 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Richard Jones a écrit : > > > > > Bruno Desthuilliers wrote: > > >>class A(object): > >> @apply > >> def a(): > >> def fget(self): > >> return self._a > >> def fset(self, val): > >> self._a = val > >> return property(**locals()) > >> def __init__(self): > >> self.a = "foo" > > > That property setup seems overly complicated. As far as I can see, it only > > avoids defining the setter in the class namespace, > > Yes. That's mosly the point. > > > yet is more complicated > > and obfuscated to boot ;) > > Well, that's your POV, so what can I say ? It's indeed a bit hackish, > and requires a couple minutes of attention the first time you see it. > And you just have to learn it once !-) > > Now I'd certainly prefer something like: > > class A(object): > @propget > def a(self): > return self._a > @propset > def a(self, val): > self._a = val > > But until there's something similar *builtin*, I'll stick to the @apply > trick. I like Guido's proposal for read/write properties. http://mail.python.org/pipermail/python-dev/2007-November/075182.html It works pretty well and is readable. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to protect my new commercial software.
On Dec 10, 9:55 am, farsheed <[EMAIL PROTECTED]> wrote: > Thanks. But I ask this question technically, I mean I know nothing is > uncrackable and popular softwares are not well protected. But my > software is not that type and I don't want this specific software > popular. > It is some kind of in house tool and I want to copy protect it. this > is very complicated tool and not useful for > many people. indeed this is an animation manging tool I wrote for my > company. So if you have any idea that what is the best way to do it, > I'll appreciate that. Oh, then sorry, I never gave much thought to it. If you're not afraid of legal troubles, you could have it silently phone home so you can know how many apps are in use at any moment. Given the scale of your app, it should be feasible for you to simply contact users who didn't pay and kindly ask them to pay. The fact that pyc files are so easily de-compiled makes app protection pretty hard... -- http://mail.python.org/mailman/listinfo/python-list
Re: Test driven development
On Jan 24, 7:37 am, [EMAIL PROTECTED] wrote: > Hi > > Sorry if this is a bit off topic but as unit testing is such a > cornerstone of python development I thought a few of you may be able > to share your knowledge/experiences. > > I like the concept of TDD but find it difficult to put into practice > most of the time. I think this primarily because I tend to like top- > down development and functional/object decomposition and TDD feels > more like a bottom-up approach. > > So my question is when approaching a project that you want to employ > test driven development on how and where do you start? And also if > anyone uses top-down design with TDD I would be interested in how you > do it (does it involve lots of mock objects/ is the first test you > write the last one to pass)? > > Thanks > > Andy I know what you mean by top-down vs. bottom-up and I used to have the same dilemma, but now I would tend to agree with Albert. Your issue with top-down or bottom-up is not relevant in TDD. The only thing that is relevant is to reach your current milestone as soon as possible, without caring about what you're going to do in the milestone after that. Not so long ago, I took the "bottom-up" approach to TDD, which was a mistake because it leads to over-engineering (the end result is not so bad since it's over-engineering that has good test coverage :) ) Roy: While mocking is good to have tests well organized (instead of having a huge pile of tests at the highest level), "over- mocking" (mocking everything, early) leads to, I think, a design that is too rigid. What if a new spec reveals that the current design of a large subset of your classes has to be re-done? All your mocking and the test below them, they all have to be "brought up" to the highest level of tests so you can re-organize your code. Since doing this is a lot of work, and usually messing with tests is a lot more dangerous than messing with the code itself, you would tend to stay with your old design, even if it's not the optimal design for the task you need to do. Virgil -- http://mail.python.org/mailman/listinfo/python-list
Re: Test driven development
On Jan 24, 1:30 pm, Roel Schroeven <[EMAIL PROTECTED]> wrote: > Virgil Dupras schreef: > > > I know what you mean by top-down vs. bottom-up and I used to have the > > same dilemma, but now I would tend to agree with Albert. Your issue > > with top-down or bottom-up is not relevant in TDD. The only thing that > > is relevant is to reach your current milestone as soon as possible, > > without caring about what you're going to do in the milestone after > > that. > > > Not so long ago, I took the "bottom-up" approach to TDD, which was a > > mistake because it leads to over-engineering (the end result is not so > > bad since it's over-engineering that has good test coverage :) ) > > I don't regularly use TDD yet, and one of the reasons is that in many > cases I'm unsure exactly how to use it in practice. I read "Test-driven > development - A practical guide" (and I should re-read), but I feel it > doesn't help my much in everyday situations. Somehow the examples in the > book don't match very well with how I code (and I admit that perhaps the > problem is more with me than with the book). > > One of the problems I have is something like what Andy describes: I need > a function spam(), so I write tests for it. Then I start implementing > the function and see that I need to write functions ham() and eggs(). > Should I write unit tests for ham() and eggs(), or do I rely on the > tests for spam()? If I don't write them, doesn't that make it more > difficult to find out why the tests for spam() fail? > > Speaking about over-engineering, when I do TDD along the lines of the > book I mentioned, I always feel that I'm over-engineering the tests. It > all feels very unnatural though I'm convinced it shouldn't be like that. > > Can someone suggest other books to read about the subject, ideally > something more focused on Python or C++ rather than Java? > > -- > The saddest aspect of life right now is that science gathers knowledge > faster than society gathers wisdom. > -- Isaac Asimov > > Roel Schroeven I also have a book about TDD and it never was of much help either. All techniques come from the initial workflow: Red - Green - Refactor. The problem you describe is a tricky problem. The way I feel it should be solved is: - Write spam() (and its tests, of course). - Then, at some point, in the re-factor phase, you split extract the function ham() from spam(). Alright, do it and keep the tests as is (all on spam()). - Then at some other point, you extract eggs(). same thing. - After a while (I don't know, 3 or 4 milestones), when it becomes clear that ham() and eggs() are there to stay, start moving your tests away from spam() by just mocking ham() and eggs() and just make sure that spam() call them with the right arguments. The tests you had on spam() that were relevant to ham() and eggs() are just performed directly on them now. What I've been saying in my other message is: Don't do that too early, because if it turns out that ham() and eggs() is not the optimal way to do it, but foo() bar() and baz() is, it is *much* easier to do a safe re-factoring with high level tests. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] "as" keyword woes
On 06 Dec 2008, at 20:38, Warren DeLano wrote: Date: Fri, 05 Dec 2008 22:22:38 -0800 From: Dennis Lee Bieber <[EMAIL PROTECTED]> Subject: Re: "as" keyword woes To: [email protected] Message-ID: <[EMAIL PROTECTED]> I'm still in the dark as to what type of data could even inspire the use of "as" as an object name... A collection of "a" objects? In which case, what are the "a"s? Please let me clarify. It is not "as" as a standalone object that we specifically miss in 2.6/3, but rather, the ability to use ".as" used as a method or attribute name. In other words we have lost the ability to refer to "as" as the generalized OOP-compliant/syntax-independent method name for casting: new_object = old_object.as(class_hint) # For example: float_obj = int_obj.as("float") # or float_obj = int_obj.as(float_class) # as opposed to something like float_obj = int_obj.asFloat() # which requires a separate method for each cast, or float_obj = (float)int_obj # which required syntax-dependent casting [language-based rather than object-based]. Of course, use of explicit casting syntax "(float)" is fine if you're restricting yourself to Python and other languages which support casting, but that solution is unavailable inside of a pure OOP message-passing paradigm where object.method(argument) invocations are all you have to work with. Please note that use of object.asClassname(...) is a ubiqitous convention for casting objects to specific classes (seen in ObjectiveC, Java, SmallTalk, etc.). There, I assert that 'object.as(class_reference)' is the simplest and most elegant generalization of this widely-used convention. Indeed, it is the only obvious concise answer, if you are limited to using methods for casting. Although there are other valid domain-specific uses for "as" as either a local variable or attribute names (e.g. systematic naming: as, bs, cs), those aren't nearly as important compared to "as" being available as the name of a generalized casting method -- one that is now strictly denied to users of Python 2.6 and 3. As someone somewhat knowledgable of how parsers work, I do not understand why a method/attribute name "object_name.as(...)" must necessarily conflict with a standalone keyword " as ". It seems to me that it should be possible to unambiguously separate the two without ambiguity or undue complication of the parser. So, assuming I now wish to propose a corrective PEP to remedy this situation for Python 3.1 and beyond, what is the best way to get started on such a proposal? Cheers, Warren As long as "as" is widely known as a keyword, I don't see the problem. Every python developer knows that the convention is to add a trailing underscore when you want to use a reserved word in your code. Besides, your examples are quite abstract. I'm sure it's possible to find good examples for "while", "with", "import", "from" (I often use "from_") or "try" as well. Or perhaps that the python keywords should be "as_" so we leave "as" free for eventual methods? As for the implicit proposition of allowing keywords only for methods, I agree with Guido about it being a slippery slope. So we would end up with a language where it is allowed to name methods after keywords, but not functions (they can be declared in the local scope)? Yikes! Oh well, maybe it's possible for an intelligent parser to distinguish between keywords and function references, but think of the poor grammar highlighters in all source editors! What a nightmare it will be for them. Anyway, is there any language that does this, allowing keywords as method names? I don't know, but if not, there's probably a reason for it. Your views on code elegance are also rather Javaish. I'd go for "class_reference(object)" (and why the heck would you "be limited to using method for casting"?). Ciao, Virgil -- http://mail.python.org/mailman/listinfo/python-list
CAB files
I would appreciate python code for creating *.cab files. --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking a file's time stamp -- followup
Christian Heimes wrote:
William Purcell wrote:
Hi all,
I am wanting to check to see the last time a file was edited. For
example, I
have a directory containing two text files, file1.txt and
file2.txt. I
want to be able to process these files but only if they have been
edited
since the last time they were processed. I think that I want to be
able to
check the time stamp of each file. Can anyone tell me how to do that or
point me in a better direction of checking the last time a file was
edited?
>>> import os
>>> stat = os.stat("/etc/passwd")
>>> print stat
(33188, 362259, 2053L, 1, 0, 0, 1690, 1218550501, 1218118498,
1218118498)
>>> dir(stat)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__',
'__getslice__', '__gt__', '__hash__', '__init__', '__le__',
'__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__str__',
'n_fields', 'n_sequence_fields', 'n_unnamed_fields', 'st_atime',
'st_blksize', 'st_blocks', 'st_ctime', 'st_dev', 'st_gid', 'st_ino',
'st_mode', 'st_mtime', 'st_nlink', 'st_rdev', 'st_size', 'st_uid']
>>> stat.st_mtime
1218118498.0
use these shortcuts, IMHO they are easier than os.stat.
os.path.getmtime() - get modified time
os.path.atime()- get last accessed time (careful some admins turn
this
off on their servers for performance reasons)
os.path.ctime()- get creation time
-Larry
Is it possible to change the time stamp of a file (Win2K platform)? If
yes, how?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Class Inheritance - What am I doing wrong?
On Apr 24, 10:22 pm, Brian Munroe <[EMAIL PROTECTED]> wrote:
> My example:
>
> class A(object):
>
> def __init__(self, name):
> self.__name = name
>
> def getName(self):
> return self.__name
>
> class B(A):
>
> def __init__(self,name=None):
> super(A,self).__init__()
>
> def setName(self, name):
> self.__name = name
>
> if __name__ == '__main__':
>
> a = A('class a')
> print a.getName()
>
> b = B('class b')
> print b.getName()
>
> b.setName('class b, reset')
> print b.getName()
>
> I get the following error:
>
> mtinky:~ brian$ python teste.py
> class a
> Traceback (most recent call last):
> File "teste.py", line 23, in
> print b.getName()
> File "teste.py", line 7, in getName
> return self.__name
> AttributeError: 'B' object has no attribute '_A__name'
>
> Am I *not* using super() correctly? Also, did I define my the class B
> constructor correctly?
Exactly, you used it wrong. It's super(B, self).
But before you start using super() everywhere, read this:
http://fuhm.net/super-harmful/
I love Python, but super() is one of those tricky things...
--
http://mail.python.org/mailman/listinfo/python-list
Re: Subclassing list the right way?
On Apr 25, 4:03 pm, Kirk Strauser <[EMAIL PROTECTED]> wrote: > I want to subclass list so that each value in it is calculated at call > time. I had initially thought I could do that by defining my own > __getitem__, but 1) apparently that's deprecated (although I can't > find that; got a link?), and 2) it doesn't work. > > For example: > > >>> class Foo(list): > > ... def __getitem__(self, index): > ... return 5 > ...>>> a = Foo([1, 2, 3, 4, 5]) > >>> print a > [1, 2, 3, 4, 5] > >>> print a[2:4] > [3, 4] > >>> print a[3] > > 5 > > I first expected that to instead behave like: > > >>> print a > [5, 5, 5, 5, 5] > >>> print a[2:4] > > [5, 5] > > Is there a "right" way to do this? > -- > Kirk Strauser I'm not totally sure, but I think you have to implement __getslice__ as well, even if it is a deprecated magic function. My guess for this is that list implements __getslice__ and when you ask for a slice, Python checks for __getslice__ first, and then, if you don't have it, calls __getitem__. And since list has it, it's what is called. As for "print a", you have to override __str__ and __repr__ too. As a side note, the second argument to __getitem__ is not index, it's key, because this argument can either be an int index or a slice() object. -- http://mail.python.org/mailman/listinfo/python-list
Java-to-Python?
I have a rather large Java package for the analysis of networks that I would like to convert to Python. Many of the classes in the Java package are "Serializable". Any recommendations on Java-to-Python (2.6) would be appreciated. --V -- http://mail.python.org/mailman/listinfo/python-list
Re: Sikuli: the coolest Python project I have yet seen...
On 25-Jan-2010 04:18, Ron wrote: Sikuli is the coolest Python project I have ever seen in my ten year hobbyist career. An MIT oepn source project, Sikuli uses Python to automate GUI tasks (in any GUI or GUI baed app that runs the JVM) by simply drag and dropping GUI elements into Python scripts as function arguments. Download at http://sikuli.csail.mit.edu/ I also did this This link is broken! --V -- http://mail.python.org/mailman/listinfo/python-list
Web servers
Any suggestions on using Python to connect to Web servers (e.g. to access financial time series data)? --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
Accessing a Web server --- how?
If one goes to the following URL: http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html it contains a link (click on "Current courses NBD AT99 3113A") to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29&; and if you now click on the tab labeled "history and compare" this will take you to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29&; Finally...This is where I would like to "connect to" the data on a daily basis or to gather data over different time intervals. I believe that if I can get some help on this, then I will be able to customize the code as needed for my own purposes. It should be clear that this is financial data on a fond managed by Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. Note, that I do have some experience with Python (2.6 mainly), and find it a very useful and powerful language. However, I have no experience with it in the area of Web services. Any suggestions/comments on how to set up this financial data service project would be greatly appreciated, and I would be glad to share this project with any interested parties. Note, I posted a similar message to the list pywebsvcs; but, received no responses. -- V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
A web site using Python
I would like to design a web site that can be used to help people to find a cat that they can adopt. Note, this is a non-profit project, but one that I believe to be quite important. Here are some of my initial thoughts on this project. /Site purpose:/ *To provide a web site for anyone to look at information on cats at this home, and how they can adopt one or more of these homeless cats.* /Some features of the site:/ 1. A cat database that I as the web site designer would create. This database would contain an entry for each cat available for adoption. It would include such things as the name, sex, age, paths to image(s) and/or video(s) of the cat, health status, etc (see below). 2. Anyone accessing this site should be able to easily navigate around it and to examine entries in this database. The client (designated person at the home where the cats are kept for adoption) would be given privileges to modify the database (add, delete, and modify entries). The user interface for the client to update the database should be very easy to use. This GUI provided to the client for modification of the database would be written in Python. 3. There would be no inputs to this web site. There would be an embedded link for a potential customer to send an email to the responsible person (bringing up their email client). 4. Track number of visitors to the site. /Preliminary notes on the database/ Fields: - ID code (key) - Name - Sex (M / F) - Neutered / Not neutered - Age (estimated) - Type (breed) - Tagged (chip or ear marking)/ Not tagged - Checked In date (yy/mm/dd) - Checked Out date (yy/mm/dd) - Status (needs home / has home) - Social state (1,2,3,4,5) - Health state (1,2,3,4,5) - Companion state (1,2,3,4,5) - Image (file name) % multiple files allowed - Video (file name) % multiple files allowed - Medical/vet data (text on vaccinations, etc.) - General information (text on cat that includes comments, observations, etc.) --- Notes on database: * state = 1, Best 5, Worst Examples: Social state = 5, very unfriendly, afraid, etc. 3, can touch if careful 1, very friendly, unafraid Health state = 5, not in good health (e.g. infection) 3, only minor health problems 1, in very good health Companion state = 5, must have another cat or cats as company 3, could be with other cat(s) company 1, does not need the company of another cat Now, with this initial information (granted this is very rough), my question: *How, armed with Python 2.6 (or 2.7) and all of the Python packages available, should I attack the problem of getting this web site up and running on a Windows platform?* Please keep in mind that do have some experience with Python and HTML; but, this would be my first web site project using Python. Any suggestions, study plan, references, etc. would be welcomed. --V -- http://mail.python.org/mailman/listinfo/python-list
Universal Feed Browser problem in feedparser.py
I am running Python 2.6 on a Windows Vista (32-bit) platform. I recently
installed the Universal Feed Parser package (feedparser-5-0). When I try to
execute the following commands:
>>> import feedparser
>>> d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml";)
which is given at http://www.feedparser.org/
I get an Assertion error in the following function in feedparser.py
def __getattr__(self, key):
try:
return self.__dict__[key]
except KeyError:
pass
try:
assert not key.startswith('_') <--- Error occurs when this
statement is executed.
return self.__getitem__(key)
except:
raise AttributeError, "object has no attribute '%s'" % key
Why does the error occur and how should he be corrected?
--
http://mail.python.org/mailman/listinfo/python-list
Re: random number including 1 - i.e. [0,1]
John Yeung wrote: On Jun 10, 1:52 am, Steven D'Aprano wrote: On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: Therefore, to me the most up-to-date docs (which say that uniform(a, b) returns a float in the closed interval [a, b]) is closer to correct than before, but still fails to point out the full subtlety of the behavior. Which is? That uniform(a, b) will return a random float in the semi-open interval [a, b) for certain values of a and b; and in the closed interval [a, b] for other values of a and b. (Swap a and b if a > b.) To me, the fact that you sometimes get a semi-open interval and sometimes a closed interval is worth noting in the docs. John I took the following direct from "The Python Library Reference (Release 2.6.2)" , Guido van Rossum, Fred L. Drake, Jr. editor, June 10, 2009. On p. 216, Almost all module functions depend on the basic function random(), which generates a random float uniformly in the semi-open range [0.0, 1.0). Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. The underlying implementation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence. However, being completely deterministic, it is not suitable for all purposes, and is completely unsuitable for cryptographic purposes. The notation above means that 0 is included but 1 is not (as pointed out by Esmail). I agree with Esmail, that it is important to know if this is correct, since the "drawing" of pseudo RVs from other distributions can depend on this function. The following is taken from MatLab (R2007b), The rand function now supports a method of random number generation called the Mersenne Twister. The algorithm used by this method, developed by Nishimura and Matsumoto, generates double precision values in the closed interval [2^(-53), 1-2^(-53)], with a period of (2^19937-1)/2. Note, that it will not generate a 0 or 1; i.e., the interval for the pseudo RV can be written as (0,1) or [2^(-53), 1-2^(-53)], where the latter is more informative. For a full description of the Mersenne twister algorithm, see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html. If indeed Python 2.6.2 is using the Mersenne twister algorithm as defined by the creators of this algorithm (go to the link given above), then IMHO the documentation should be corrected. I hope that this helps. --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
matplotlib installation
Any suggestions on installing matplotlib for Python 2.6.2 on a Windows Vista platform? --V -- http://mail.python.org/mailman/listinfo/python-list
On the property function
Does anyone have a good example (or examples) of when "property(...)" can be useful? Thank you, --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
PyODE
Does anyone have PyODE running on Python 2.6.2? --V -- http://mail.python.org/mailman/listinfo/python-list
On out-of-date Python Applications
I am not a heavy user of Python; but, I do work with it and some of its application packages (e.g. PyODE), in an academic setting. Many of these applications packages have a Windows installer which usually works fine. However, I also try to keep up with the latest release of Python, and this is where I often have problems. That is, the latest Windows installer provided for some of these applications will not install on the latest version of Python. I do understand that there can be a time lag between the release of Python applications and the latest Python. I also appreciate the work of the people that are responsible for these applications. My question is --- Is there anything I, as a user of an application package that is out-of-date with respect to the latest Python, can do to help in this process of bringing an application up-to-date? --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
Re: On out-of-date Python Applications
David Robinow wrote: On Mon, Jul 20, 2009 at 7:24 AM, John Machin wrote: ... The next step would be to try to compile ODE 0.7 or 0.8 with VS9 -- however this would require "project files" for ODE for VS9, and there aren't any on the ODE website; it has only those for VS3 and VS5. The ODE site is a mess. Go to http://www.ode.org/svn.html and click on: Instructions for accessing the repository Scroll down to the section "Building with Premake" (Note that there is no directory "ode/build" -- you want the "build" directory, which contains premake4.exe) I used "premake4 --with-demos --with-tests vs2008" I have successfully compiled ode-0.11.1 using these instructions. I have not yet run the tests or demos or tried to compile PyODE. Thanks for this information David. Now that you have successfully compiled ode-0.11.1, how can one finish this process --- compile PyODE? --V -- http://mail.python.org/mailman/listinfo/python-list
"Deprecated sets module" with Python 2.6
I would appreciate help on correcting a problem when trying to create an *.exe file using py2exe via GUI2exe with Python 2.6.2. When using GUI2exe to create an *.exe I always get the following warning during the compile process: C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated import sets and this results in the creation of an *.exe file that can not be executed. On the other hand, if I use the same procedure (on the same Python code) with Python 2.5, there are no warnings and the *.exe works fine. The procedure used is that given in the example "Less simpler one" at http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin Any suggestions, help, ... would be greatly appreciated. Thanks, --V. -- http://mail.python.org/mailman/listinfo/python-list
Re: "Deprecated sets module" with Python 2.6
Diez B. Roggisch wrote: Virgil Stokes schrieb: I would appreciate help on correcting a problem when trying to create an *.exe file using py2exe via GUI2exe with Python 2.6.2. When using GUI2exe to create an *.exe I always get the following warning during the compile process: C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated import sets and this results in the creation of an *.exe file that can not be executed. On the other hand, if I use the same procedure (on the same Python code) with Python 2.5, there are no warnings and the *.exe works fine. The procedure used is that given in the example "Less simpler one" at http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin Any suggestions, help, ... would be greatly appreciated. If you don't need your app running on python2.3 and earlier, just remove the sets-module and replace it with the builtin "set". Of course Diez, this is a good suggestion. However, in this case the Python code that I am trying to convert into an *.exe file does not refer to sets directly; i.e, the use of this module is buried within a package that is imported (wxPython) which is not under my control. --V Diez -- http://mail.python.org/mailman/listinfo/python-list
