Re: compute the double square...... :(
On Jan 9, 6:14 pm, Gary Herron wrote:
> On 01/08/2011 10:10 PM, aregee wrote:
>
> > Double Squares
> > A double-square number is an integer X which can be expressed as the
> > sum of two perfect squares. For example, 10 is a double-square because
> > 10 = 32 + 12. Your task in this problem is, given X, determine the
> > number of ways in which it can be written as the sum of two squares.
> > For example, 10 can only be written as 32 + 12 (we don't count 12 + 32
> > as being different). On the other hand, 25 can be written as 52 + 02
> > or as 42 + 32.
>
> Huh? In what number system does 10 = 32 + 12?
> And how do either 32 or 12 qualify as perfect squares?
>
> Gary Herron
>
>
>
>
>
>
>
> > Input
> > You should first read an integer N, the number of test cases. The next
> > N lines will contain N values of X.
> > Constraints
> > 0 ≤ X ≤ 2147483647
> > 1 ≤ N ≤ 100
> > Output
> > For each value of X, you should output the number of ways to write X
> > as the sum of two square
>
> > Is the code mention below solution to this question what is the
> > fault...
> > Error :
> > are...@aregee-laptop:~/Desktop$ python pie.py
> > enter a number::10
> > pie.py:3: Deprecation Warning: integer argument expected, got float
> > for b in range(0,(x**0.5)/2):
>
> > #Double square
>
> > x = input("enter a number::")
> > for b in range(0,(x**0.5)/2):
> > a = (x-(b**2))**0.5
> > try:
> > a = int(a)
> > except:
> > print("not an integer")
> > exit(1)
>
> > count = 0;
> > count = count + 1;
> > if (x == a**2 + b**2):
>
> > print "double square"
Well that he means 3(squared)+1(squared) [3 superscript 2 etc]
Owen
--
http://mail.python.org/mailman/listinfo/python-list
Re: compute the double square...... :(
On 1/8/2011 11:10 PM, aregee wrote:
pie.py:3: Deprecation Warning: integer argument expected, got float
for b in range(0,(x**0.5)/2):
I expect you want range(0, int((x / 2) ** 0.5) + 1), no?
for b in range(0,(x**0.5)/2):
a = (x-(b**2))**0.5
try:
a = int(a)
except:
print("not an integer")
exit(1)
Your indentation is confusing. Is the try-except contained inside the
for loop or not?
And what are you actually trying to test for here? The assignment here
of "a = int(a)" will never throw an exception as long as the loop runs.
count = 0;
count = count + 1;
Again, confusing indentation. Is this supposed to be part of the except
block? And what is the purpose of incrementing count if you're going to
set it to 0 immediately before? You might as well just write "count = 1"
if (x == a**2 + b**2):
print "double square"
This also appears to be outside of the loop.
--
http://mail.python.org/mailman/listinfo/python-list
Re: compute the double square...... :(
On Jan 9, 7:10 am, aregee wrote:
> Double Squares
> A double-square number is an integer X which can be expressed as the
> sum of two perfect squares. For example, 10 is a double-square because
> 10 = 32 + 12. Your task in this problem is, given X, determine the
> number of ways in which it can be written as the sum of two squares.
> For example, 10 can only be written as 32 + 12 (we don't count 12 + 32
> as being different). On the other hand, 25 can be written as 52 + 02
> or as 42 + 32.
>
> Input
> You should first read an integer N, the number of test cases. The next
> N lines will contain N values of X.
> Constraints
> 0 ≤ X ≤ 2147483647
> 1 ≤ N ≤ 100
> Output
> For each value of X, you should output the number of ways to write X
> as the sum of two square
>
> Is the code mention below solution to this question what is the
> fault...
> Error :
> are...@aregee-laptop:~/Desktop$ python pie.py
> enter a number::10
> pie.py:3: Deprecation Warning: integer argument expected, got float
> for b in range(0,(x**0.5)/2):
>
> #Double square
>
> x = input("enter a number::")
> for b in range(0,(x**0.5)/2):
> a = (x-(b**2))**0.5
> try:
> a = int(a)
> except:
> print("not an integer")
> exit(1)
>
> count = 0;
> count = count + 1;
> if (x == a**2 + b**2):
>
> print "double square"
aregee,
The problem you had was that you put a division by 2 in the range, if
x would be 25 than x**0.5 = 5.0 than you would feed range with 2.5 and
than you get the warning. Also I don't understand why you use de
division by 2, because if for instance you would take 25 you get 5 and
0 but you mis 3 and 4 as match. I've put in a tried list to
I would try the following:
#Double square
x = input("enter a number::")
for b in range(0,int((x**0.5))):
a = (x-(b**2))**0.5
try:
a = int(a)
except:
print("not an integer")
exit(1)
if a < b:
# when a is smaller than b we already have this match
# and all the following matches we also have
break
if (x == a**2 + b**2):
print "double square %s = %s**2 + %s**2" % (x, a, b)
--
http://mail.python.org/mailman/listinfo/python-list
Re: compute the double square...... :(
hey all thanks for yr help,i got it right .n sorry for
confussions...i m very new to python...just started learning it couple
of days ago...
Ian Kelly wrote:
> On 1/8/2011 11:10 PM, aregee wrote:
> > pie.py:3: Deprecation Warning: integer argument expected, got float
> >for b in range(0,(x**0.5)/2):
>
> I expect you want range(0, int((x / 2) ** 0.5) + 1), no?
>
> > for b in range(0,(x**0.5)/2):
> >a = (x-(b**2))**0.5
> > try:
> >a = int(a)
> > except:
> >print("not an integer")
> >exit(1)
>
> Your indentation is confusing. Is the try-except contained inside the
> for loop or not?
>
> And what are you actually trying to test for here? The assignment here
> of "a = int(a)" will never throw an exception as long as the loop runs.
>
> >
> >count = 0;
> >count = count + 1;
>
> Again, confusing indentation. Is this supposed to be part of the except
> block? And what is the purpose of incrementing count if you're going to
> set it to 0 immediately before? You might as well just write "count = 1"
>
> > if (x == a**2 + b**2):
> >
> >print "double square"
>
> This also appears to be outside of the loop.
--
http://mail.python.org/mailman/listinfo/python-list
Embedded Python static modules
I build python from sources(static version): ./configure --disable-shared Next I build program with this static library. Program work fine on my linux, but when I tried run my program on another linux, I got next message: Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] ImportError: No module named site This message I receive when call Py_Initialize(). How I can build python static library with all required Python modules? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: compute the double square...... :(
aregee wrote: > Double Squares > A double-square number is an integer X which can be expressed as the > sum of two perfect squares. For example, 10 is a double-square because > 10 = 32 + 12. Your task in this problem is, given X, determine the > number of ways in which it can be written as the sum of two squares. > For example, 10 can only be written as 32 + 12 (we don't count 12 + 32 > as being different). On the other hand, 25 can be written as 52 + 02 > or as 42 + 32. There is interesting mathematics involved in "double squares". Such properties are intimately bound up with the factorisation of the number. It can be shown that: (i) a prime number of the form 4n + 1 is a double square in exactly one way. So is 2. E.g. 73 = 64 + 9, 2 = 1 + 1. (ii) a prime number of the form 4n + 3 is not a double square. (iii) The product of m distinct primes, each of the form 4n + 1, is a double square in 2^(m-1) ways. E.g. 5*13 = 65 = 64 + 1 = 49 + 16 (iv) If k = a^2 + b^2, l = c^2 + d^2, then: kl = (ac + bd)^2 + (ad - bc)^2 = (ac - bd)^2 + (ad + bc)^2. (v) if k is a prime of the form 4n + 1, then k^m is a double square in (m + 2) / 2 ways. E.g. 5^4 = 625 = 625 + 0 = 576 + 49 = 400 + 225. (vi) and so on. It's all in the factorisation! -- Alan Mackenzie (Nuremberg, Germany). -- http://mail.python.org/mailman/listinfo/python-list
Help needed with unittest and global
Hi all, I am trying to develop a PyQt application, and I want to unittest it. After three false starts, I am plainly unaware of something rather basic - can some kind person please help me out? This is a log to show what I have so far D:\work\ian>type testAll.py # coding=utf8 # testAll.py - run all tests. import unittest import sys from PyQt4.QtGui import * from testCubic import testCubic global app def main(): suite = unittest.TestLoader() suite.loadTestsFromTestCase(testCubic) unittest.TextTestRunner().run(suite) if __name__=="__main__": global app app = QApplication(sys.argv) # set gloabl app unittest.main() D:\work\ian>type testCubic.py # coding=utf8 #testCubic.py - tests the top level module import unittest global app class testCubic(unittest.TestCase): def test001_walkingSkeleton(self): global app# use global version app.processEvents() # fails D:\work\ian>python testAll.py E == ERROR: test001_walkingSkeleton (testCubic.testCubic) -- Traceback (most recent call last): File "D:\work\ian\testCubic.py", line 8, in test001_walkingSkeleton app.processEvents() # fails NameError: global name 'app' is not defined -- Ran 1 test in 0.001s FAILED (errors=1) D:\work\ian> Thanks Ian -- http://mail.python.org/mailman/listinfo/python-list
Nothing to repeat
Hello everyone, long time no see,
This is probably not a Python problem, but rather a regular expressions
problem.
I want, for the sake of arguments, to match strings comprising any number
of occurrences of 'spa', each interspersed by any number of occurrences of
the 'm'. 'any number' includes zero, so the whole pattern should match the
empty string.
Here's the conversation Python and i had about it:
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:16)
[GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import re
re.compile("(spa|m*)*")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.6/re.py", line 245, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
What's going on here? Why is there nothing to repeat? Is the problem
having one *'d term inside another?
Now, i could actually rewrite this particular pattern as '(spa|m)*'. But
what i neglected to mention above is that i'm actually generating patterns
from structures of objects (representations of XML DTDs, as it happens),
and as it stands, patterns like this are a possibility.
Any thoughts on what i should do? Do i have to bite the bullet and apply
some cleverness in my pattern generation to avoid situations like this?
Thanks,
tom
--
If it ain't broke, open it up and see what makes it so bloody special.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Integrating doctest with unittest
In article <[email protected]>, Steven D'Aprano wrote: > >Is there a way to have unittest.main() find and run doc_test_suite >together with the other test suites? You probably need to use nose or something. (That's what we're doing.) -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand -- http://mail.python.org/mailman/listinfo/python-list
Re: Nothing to repeat
On 09/01/2011 16:49, Tom Anderson wrote:
Hello everyone, long time no see,
This is probably not a Python problem, but rather a regular
expressions problem.
I want, for the sake of arguments, to match strings comprising any
number of occurrences of 'spa', each interspersed by any number of
occurrences of the 'm'. 'any number' includes zero, so the whole
pattern should match the empty string.
Here's the conversation Python and i had about it:
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:16)
[GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import re
re.compile("(spa|m*)*")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.6/re.py", line 245, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
What's going on here? Why is there nothing to repeat? Is the problem
having one *'d term inside another?
Now, i could actually rewrite this particular pattern as '(spa|m)*'.
But what i neglected to mention above is that i'm actually generating
patterns from structures of objects (representations of XML DTDs, as
it happens), and as it stands, patterns like this are a possibility.
Any thoughts on what i should do? Do i have to bite the bullet and
apply some cleverness in my pattern generation to avoid situations
like this?
Thanks,
tom
I think you want to anchor your list, or anything will match. Perhaps
re.compile('/^(spa(m)+)*$/')
is what you need.
Regards
Ian
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nothing to repeat
On 09/01/2011 17:49, Ian wrote:
I think you want to anchor your list, or anything will match. Perhaps
My bad - this is better
re.compile('^((spa)*(m)*)+$')
search finds match in 'spa', 'spaspaspa', 'spammmspa', '' and 'mmm'
search fails on 'spats', 'mats' and others.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nothing to repeat
On Sun, 09 Jan 2011 16:49:35 +, Tom Anderson wrote:
>
> Any thoughts on what i should do? Do i have to bite the bullet and apply
> some cleverness in my pattern generation to avoid situations like this?
>
This sort of works:
import re
f = open("test.txt")
p = re.compile("(spam*)*")
for line in f:
print "input line: %s" % (line.strip())
for m in p.findall(line):
if m != "":
print "==> %s" % (m)
when I feed it
===test.txt===
a line with no match
spa should match
spam should match
so should all of spaspamspammspammm
and so should all of spa spam spamm spammm
no match again.
===test.txt===
it produces:
input line: a line with no match
input line: spa should match
==> spa
input line: spam should match
==> spam
input line: so should all of spaspamspammspammm
==> spammm
input line: and so should all of spa spam spamm spammm
==> spa
==> spam
==> spamm
==> spammm
input line: no match again.
so obviously there's a problem with greedy matching where there are no
separators between adjacent matching strings. I tried non-greedy
matching, e.g. r'(spam*?)*', but this was worse, so I'll be interested to
see how the real regex mavens do it.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nothing to repeat
On 1/9/2011 11:49 AM, Tom Anderson wrote:
Hello everyone, long time no see,
This is probably not a Python problem, but rather a regular expressions
problem.
I want, for the sake of arguments, to match strings comprising any
number of occurrences of 'spa', each interspersed by any number of
occurrences of the 'm'. 'any number' includes zero, so the whole pattern
should match the empty string.
All you sure? A pattern that matches the empty string matches every string.
Here's the conversation Python and i had about it:
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:16)
[GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import re
re.compile("(spa|m*)*")
I believe precedence rule of * tighter than | (not in the doc) makes
this re is the same as "(spa|(m)*)*", which gives same error traceback.
I believe that for this, re compiles first (spa)* and then ((m)*)* and
the latter gives the same traceback. Either would seem to match strings
of 'm's without and 'spa', which is not your spec.
"((spa|m)*)*" does compile, so it is not the nesting itself.
The doc does not give the formal grammar for Python re's, so it is hard
to pinpoint which informal rule is violated, or if indeed the error is a
bug. Someone else may do better.
Now, i could actually rewrite this particular pattern as '(spa|m)*'.
That also does not match your spec.
Any thoughts on what i should do? Do i have to bite the bullet and apply
some cleverness in my pattern generation to avoid situations like this?
Well, it has to generate legal re's according to the engine you are
using (with whatever bugs and limitations it has).
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
Re: Help needed with unittest and global
On 01/-10/-28163 02:59 PM, Ian Hobson wrote: Hi all, I am trying to develop a PyQt application, and I want to unittest it. After three false starts, I am plainly unaware of something rather basic - can some kind person please help me out? This is a log to show what I have so far D:\work\ian>type testAll.py # coding=utf8 # testAll.py - run all tests. import unittest import sys from PyQt4.QtGui import * from testCubic import testCubic global app def main(): suite = unittest.TestLoader() suite.loadTestsFromTestCase(testCubic) unittest.TextTestRunner().run(suite) if __name__=="__main__": global app app = QApplication(sys.argv) # set gloabl app unittest.main() D:\work\ian>type testCubic.py # coding=utf8 # testCubic.py - tests the top level module import unittest global app class testCubic(unittest.TestCase): def test001_walkingSkeleton(self): global app # use global version app.processEvents() # fails D:\work\ian>python testAll.py E == ERROR: test001_walkingSkeleton (testCubic.testCubic) -- Traceback (most recent call last): File "D:\work\ian\testCubic.py", line 8, in test001_walkingSkeleton app.processEvents() # fails NameError: global name 'app' is not defined You have two global variables called app, one is in the testCubic module and the other is in the testAll.py script. They do not automatically refer to the same thing. To use a global from another module, you can either do an import, or you can pass it as an argument. But beware of mutual imports. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed with unittest and global
On 09/01/2011 19:53, Dave Angel wrote: On 01/-10/-28163 02:59 PM, Ian Hobson wrote: Hi all, I am trying to develop a PyQt application, and I want to unittest it. snip D:\work\ian>python testAll.py E == ERROR: test001_walkingSkeleton (testCubic.testCubic) -- Traceback (most recent call last): File "D:\work\ian\testCubic.py", line 8, in test001_walkingSkeleton app.processEvents() # fails NameError: global name 'app' is not defined You have two global variables called app, one is in the testCubic module and the other is in the testAll.py script. They do not automatically refer to the same thing. To use a global from another module, you can either do an import, or you can pass it as an argument. But beware of mutual imports. DaveA Thanks David, I found http://mail.python.org/pipermail/tutor/2002-November/018353.html and created a shared module that both modules can import. Then I refer to shared.app, no use of global and it works as desired. I am on to the next step - actually running my code. Regards Ian -- http://mail.python.org/mailman/listinfo/python-list
What INI config file module allows lists of duplicate same-named options?
Having (possibly) surveyed all the available pypi config file modules, I still haven't seen one that allows an obvious and familiar extension of the strict Windows INI format. Each INI-style config module seems to enforce the strict rule: each option in a section must have a different name - no duplicates. Thus it is impossible to have a simple list, e.g. [pathset uk] pathpair: /bath/* to/london/* pathpair: /bath/upload/** to/london/* pathpair: /firth/*to/forth/* pathpair: /firth/upload/**to/forth/* Rather you must give each line a separate name, e.g. [pathset uk] pathpair001: /bath/* to/london/* pathpair002: /bath/upload/** to/london/* pathpair003: /firth/* to/forth/* pathpair004: /firth/upload/** to/forth/* | | | | | | pathpair068: /glasgow/* to/edinburgh/* pathpair069: /glasgow/upload/** to/edinburgh/* | | | | | | This is not ideal for a number of reasons. Do you know of a library module that has the (optional?) ability to handle duplicate-named options, returning them as a list? If instead someone can point me to a reasonable Apache-style config module, that might also serve. I've looked for such and the few found seemed to be either bare bones or clumsily stripped out of something much larger. -- I'm a pessimist about probabilities; I'm an optimist about possibilities. Lewis Mumford (1895-1990) -- http://mail.python.org/mailman/listinfo/python-list
Re: What INI config file module allows lists of duplicate same-named options?
On 01/09/2011 03:43 PM, Thomas L. Shinnick wrote: > Having (possibly) surveyed all the available pypi config file modules, I > still haven't seen one that allows an obvious and familiar extension of > the strict Windows INI format. > > Each INI-style config module seems to enforce the strict rule: each > option in a section must have a different name - no duplicates. Thus it > is impossible to have a simple list, e.g. > > [pathset uk] > pathpair: /bath/* to/london/* > pathpair: /bath/upload/** to/london/* > pathpair: /firth/*to/forth/* > pathpair: /firth/upload/**to/forth/* > > Rather you must give each line a separate name, e.g. > > [pathset uk] > pathpair001: /bath/* to/london/* > pathpair002: /bath/upload/** to/london/* > pathpair003: /firth/* to/forth/* > pathpair004: /firth/upload/** to/forth/* > | | | | | | > pathpair068: /glasgow/* to/edinburgh/* > pathpair069: /glasgow/upload/** to/edinburgh/* > | | | | | | > > This is not ideal for a number of reasons. Do you know of a library > module that has the (optional?) ability to handle duplicate-named > options, returning them as a list? > > If instead someone can point me to a reasonable Apache-style config > module, that might also serve. I've looked for such and the few found > seemed to be either bare bones or clumsily stripped out of something > much larger. > > > -- > I'm a pessimist about probabilities; I'm an optimist about possibilities. > Lewis Mumford (1895-1990) > Seems to me to be a standard enforced by Windows itself, not any an issue with the modules. What exactly are you doing? ~Corey Richardson -- http://mail.python.org/mailman/listinfo/python-list
Re: What INI config file module allows lists of duplicate same-named options?
Am 09.01.2011 21:43, schrieb Thomas L. Shinnick:
Having (possibly) surveyed all the available pypi config file modules,
I still haven't seen one that allows an obvious and familiar extension
of the strict Windows INI format.
Each INI-style config module seems to enforce the strict rule: each
option in a section must have a different name - no duplicates. Thus
it is impossible to have a simple list, e.g.
[pathset uk]
pathpair: /bath/* to/london/*
pathpair: /bath/upload/** to/london/*
pathpair: /firth/*to/forth/*
pathpair: /firth/upload/**to/forth/*
Rather you must give each line a separate name, e.g.
[pathset uk]
pathpair001: /bath/* to/london/*
pathpair002: /bath/upload/** to/london/*
pathpair003: /firth/* to/forth/*
pathpair004: /firth/upload/** to/forth/*
| | | | | |
pathpair068: /glasgow/* to/edinburgh/*
pathpair069: /glasgow/upload/** to/edinburgh/*
| | | | | |
This is not ideal for a number of reasons. Do you know of a library
module that has the (optional?) ability to handle duplicate-named
options, returning them as a list?
If instead someone can point me to a reasonable Apache-style config
module, that might also serve. I've looked for such and the few found
seemed to be either bare bones or clumsily stripped out of something
much larger.
--
I'm a pessimist about probabilities; I'm an optimist about possibilities.
Lewis Mumford (1895-1990)
I've let ini style files alone some time ago.
Whenever possible I use JSON based files.
Your example could then look like this:
{
"pathpairs":{
"uk":[
["/bath/*","/london/*"],
["/bath/upload/**","/london/*"],
["/firth/*,"/forth/*"],
["/firth/upload/**","/forth/*"]
]
}
}
Since Python 2.7, json is in the standard library.
--
http://mail.python.org/mailman/listinfo/python-list
Re: What INI config file module allows lists of duplicate same-named options?
At 02:47 PM 1/9/2011, Corey Richardson wrote: On 01/09/2011 03:43 PM, Thomas L. Shinnick wrote: > Having (possibly) surveyed all the available pypi config file modules, I > still haven't seen one that allows an obvious and familiar extension of > the strict Windows INI format. > > Each INI-style config module seems to enforce the strict rule: each > option in a section must have a different name - no duplicates. Thus it > is impossible to have a simple list, e.g. > > [pathset uk] > pathpair: /bath/* to/london/* > pathpair: /bath/upload/** to/london/* > pathpair: /firth/*to/forth/* > pathpair: /firth/upload/**to/forth/* > > Rather you must give each line a separate name, e.g. > > [pathset uk] > pathpair001: /bath/* to/london/* > pathpair002: /bath/upload/** to/london/* > pathpair003: /firth/* to/forth/* > pathpair004: /firth/upload/** to/forth/* > | | | | | | > pathpair068: /glasgow/* to/edinburgh/* > pathpair069: /glasgow/upload/** to/edinburgh/* > | | | | | | > > This is not ideal for a number of reasons. Do you know of a library > module that has the (optional?) ability to handle duplicate-named > options, returning them as a list? > > If instead someone can point me to a reasonable Apache-style config > module, that might also serve. I've looked for such and the few found > seemed to be either bare bones or clumsily stripped out of something > much larger. > > > -- > I'm a pessimist about probabilities; I'm an optimist about possibilities. > Lewis Mumford (1895-1990) > Seems to me to be a standard enforced by Windows itself, not any an issue with the modules. What exactly are you doing? Windows established the format, established the 'rules', then people adopted the format and rules, but often with 'adaptions' and extensions. I see many variations in the various modules found in pypi, such as variable interpolation, but none that violate the 'rule' "no duplicates". Here, I need to list multiple file/dir path pairs. A list of multiple items to be acted upon in a common way. It is a list. Simple. Except I can't find a library/pypi module with the obvious extension. Full disclosure: I'm familiar with $lang which has many such possible modules, which has me rather puzzled here. ~Corey Richardson -- http://mail.python.org/mailman/listinfo/python-list
Re: What INI config file module allows lists of duplicate same-named options?
At 02:52 PM 1/9/2011, Stefan Sonnenberg-Carstens wrote:
Am 09.01.2011 21:43, schrieb Thomas L. Shinnick:
Having (possibly) surveyed all the available pypi config file
modules, I still haven't seen one that allows an obvious and
familiar extension of the strict Windows INI format.
Each INI-style config module seems to enforce the strict rule: each
option in a section must have a different name - no
duplicates. Thus it is impossible to have a simple list, e.g.
[pathset uk]
pathpair: /bath/* to/london/*
pathpair: /bath/upload/** to/london/*
pathpair: /firth/*to/forth/*
pathpair: /firth/upload/**to/forth/*
Rather you must give each line a separate name, e.g.
[pathset uk]
pathpair001: /bath/* to/london/*
pathpair002: /bath/upload/** to/london/*
pathpair003: /firth/* to/forth/*
pathpair004: /firth/upload/** to/forth/*
| | | | | |
pathpair068: /glasgow/* to/edinburgh/*
pathpair069: /glasgow/upload/** to/edinburgh/*
| | | | | |
This is not ideal for a number of reasons. Do you know of a
library module that has the (optional?) ability to handle
duplicate-named options, returning them as a list?
If instead someone can point me to a reasonable Apache-style config
module, that might also serve. I've looked for such and the few
found seemed to be either bare bones or clumsily stripped out of
something much larger.
--
I'm a pessimist about probabilities; I'm an optimist about possibilities.
Lewis Mumford (1895-1990)
I've let ini style files alone some time ago.
Whenever possible I use JSON based files.
Your example could then look like this:
{
"pathpairs":{
"uk":[
["/bath/*","/london/*"],
["/bath/upload/**","/london/*"],
["/firth/*,"/forth/*"],
["/firth/upload/**","/forth/*"]
]
}
}
Since Python 2.7, json is in the standard library.
A reasonable response, if your only audience is computer folk. And
used internally already. But in trying to be simple as can be for
those installing and maintaining a package, INI-style configurations
are a familiar format. As Apache-style configs would be. So, JSON
is concise and flexible and easily handled by programs. But I was
hoping for something easier for the poor soul coming back to a config
after 2 months and wondering how to add something ... --
http://mail.python.org/mailman/listinfo/python-list
Re: Embedded Python static modules
I made frozen modules and link this modules with my program. PyImport_FrozenModules = frozen_modules; Py_Initialize(); I got next message: Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Traceback (most recent call last): File "site.py", line 553, in File "site.py", line 535, in main File "site.py", line 268, in addusersitepackages File "site.py", line 243, in getusersitepackages File "site.py", line 233, in getuserbase File "sysconfig.py", line 535, in get_config_var File "sysconfig.py", line 434, in get_config_vars File "sysconfig.py", line 287, in _init_posix IOError: invalid Python installation: unable to open /usr/local/lib/ python2.7/config/Makefile (No such file or directory) How I can fix this problem? -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedded Python static modules
I found solution:
Py_NoSiteFlag = 1;
Py_FrozenFlag = 1;
Py_IgnoreEnvironmentFlag = 1;
Py_SetPythonHome("");
Py_SetProgramName("");
--
http://mail.python.org/mailman/listinfo/python-list
Re: Integrating doctest with unittest
On Sun, 09 Jan 2011 08:56:52 -0800, Aahz wrote: > In article <[email protected]>, Steven > D'Aprano wrote: >> >>Is there a way to have unittest.main() find and run doc_test_suite >>together with the other test suites? > > You probably need to use nose or something. (That's what we're doing.) Thanks for the reply Aahz, even though it wasn't what I wanted to hear :( -- Steven -- http://mail.python.org/mailman/listinfo/python-list
