Re: Tie dictionary to database table?

2016-06-10 Thread Peter Heitzer
Michael Selik  wrote:
>On Thu, Jun 9, 2016 at 9:10 AM justin walters 
>wrote:

>> It looks like you might be looking for an ORM. Have you checked out
>> sqlalchemy?
>>

>An ORM might be overkill. If you just want a persistent dictionary, just
>use the shelve module. https://docs.python.org/3/library/shelve.html
That looks like tie in Perl. Unfortunately I have to use mysql as database
and I need concurrent read/write as the table may be modified by other
processes.
Meanwhile I have analized my demans a bit and modified the task so that I
need not read values but rather make updates to the tables.



-- 
Dipl.-Inform(FH) Peter Heitzer, peter.heit...@rz.uni-regensburg.de
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tie dictionary to database table?

2016-06-10 Thread Christian Gollwitzer

Am 10.06.16 um 09:30 schrieb Peter Heitzer:

Michael Selik  wrote:

An ORM might be overkill. If you just want a persistent dictionary, just
use the shelve module. https://docs.python.org/3/library/shelve.html

That looks like tie in Perl. Unfortunately I have to use mysql as database
and I need concurrent read/write as the table may be modified by other
processes.
Meanwhile I have analized my demans a bit and modified the task so that I
need not read values but rather make updates to the tables.


It wouldn't be that difficult to roll your own thing which does that; 
you just need to define __setitem__ and __getitem__ in your class which 
translates between the SQL call and the Python code.


Christian


--
https://mail.python.org/mailman/listinfo/python-list


Re: UserList - which methods needs to be overriden?

2016-06-10 Thread Nagy László Zsolt


2016.06.10. 0:38 keltezéssel, Michael Selik írta:
> On Thu, Jun 9, 2016 at 5:07 AM Nagy László Zsolt  > wrote:
>
> I would like to create a collections.UserList subclass that can notify
> others when the list is mutated.
>
>
> Why not subclass MutableSequence instead? The ABC will tell you which
> methods to override (the abstract ones). The mixin methods rely on
> those overrides.
I'm not sure wich one is the best. Peter wrote that UserList was left in
collections only for backward compatiblity. This might be a point
against using UserList. The thing with MutableSequence is that it is
quite inefficient. For example, it implements clear() by calling pop()
in a loop. It implements extend() by calling append() in a loop. And we
all know that the built-in extend() method of the list object is much
more efficient. It is true that by overriding the abstract methods, I'll
get a functional list like object, but we all know that

 There should be one-- and preferably only one --obvious way to do it.


Which one is that? :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy

2016-06-10 Thread Robin Becker

On 08/06/2016 19:32, rocky wrote:
..


Sorry that should have been 1998 which would make more sense for the 7th  
conference if the 1st one was around 2001. I've corrected the date in [1] 
https://pypi.python.org/pypi/spark_parser/1.3.0

The automated tests in the package just don't  catch stuff like this. But I'm 
sure there are also other mistakes as well in there so feel free to let me know.


not a big deal; I like the spark parser :)
--
Robin Becker

--
https://mail.python.org/mailman/listinfo/python-list


Re: UserList - which methods needs to be overriden?

2016-06-10 Thread Peter Otten
Nagy László Zsolt wrote:

> I'm not sure wich one is the best. Peter wrote that UserList was left in
> collections only for backward compatiblity. This might be a point

I'll take that back. I looked around and found no evidence for my claim. 
Only MutableString was removed during the transition to Python 3. 

Sorry for the confusion.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UserList - which methods needs to be overriden?

2016-06-10 Thread Maxime S
2016-06-10 10:37 GMT+02:00 Peter Otten <__pete...@web.de>:
>
> Nagy László Zsolt wrote:
>
> > I'm not sure wich one is the best. Peter wrote that UserList was left in
> > collections only for backward compatiblity. This might be a point
>
> I'll take that back. I looked around and found no evidence for my claim.
> Only MutableString was removed during the transition to Python 3.
>
> Sorry for the confusion.
>
>

Up to Python 2.6, the docs of UserList had a note stating that:

This module is available for backward compatibility only. If you are
writing code that does not need to work with versions of Python earlier
than Python 2.2, please consider subclassing directly from the built-in
list type.

This was changed in Python 2.7 to:

When Python 2.2 was released, many of the use cases for this class were
subsumed by the ability to subclass list directly. However, a handful of
use cases remain.

So I think the intention was that the ability to subclass list would remove
the need to subclass UserList, but it was later realised that it is not
totally the case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tie dictionary to database table?

2016-06-10 Thread Peter Heitzer
Christian Gollwitzer  wrote:
>Am 10.06.16 um 09:30 schrieb Peter Heitzer:
>> Michael Selik  wrote:
>>> An ORM might be overkill. If you just want a persistent dictionary, just
>>> use the shelve module. https://docs.python.org/3/library/shelve.html
>> That looks like tie in Perl. Unfortunately I have to use mysql as database
>> and I need concurrent read/write as the table may be modified by other
>> processes.
>> Meanwhile I have analized my demans a bit and modified the task so that I
>> need not read values but rather make updates to the tables.

>It wouldn't be that difficult to roll your own thing which does that; 
>you just need to define __setitem__ and __getitem__ in your class which 
>translates between the SQL call and the Python code.
That's a good idea. 



-- 
Dipl.-Inform(FH) Peter Heitzer, peter.heit...@rz.uni-regensburg.de
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-06-10 Thread alister
On Thu, 09 Jun 2016 18:19:23 +1000, Steven D'Aprano wrote:

> On Thursday 09 June 2016 10:34, Lawrence D’Oliveiro wrote:
> 
>> In my undergraduate Comp Sci classes, we used to discuss arbitrary
>> rules like limiting functions to n lines. With real-world experience,
>> it soon became clear that such rules were a waste of time. A function
>> should be just as big as it needs to be, no more, no less. The same
>> with a class, or a module. Or whatever other constructs your language
>> may have.
> 
> The opposite of "arbitrary limits" is not "no limits".
> 
> An arbitrary limit like "500 lines is the maximum size a function may
> be" is clearly arbitrary and not very helpful. (Also too high.)
> 
> Better is to understand that there is no hard cut-off between
> "acceptable" and "too long", but we can still judge that all else being
> equal, long functions are worse than short functions.
> 
> The real problem is complexity of functions. The more complex they are,
> the harder they are to write correctly, and the harder to maintain, and
> the more likely that they have bugs.
> 
> The length of a function is a very crude measure of complexity, but it
> *is* a measure of complexity, and people are right to look at long
> functions as a code smell and a sign that the function probably does too
> much, or is badly written,
> or that it could do with some refactoring to simplify it. Not in *every*
> case, but I've never yet seen a long (> 200 lines) function that wasn't
> improved by refactoring or splitting.



Or more simply a hard fixed RULE (MUST be less than X lines) is Bad.

a flexible GUIDELINE on the other hand is reasonable.

after all an efficient function could be be X=1 lines, abriatrily spliting 
this could make the final function less readable & possibly even longer 
in total.
 


-- 
Puns are little "plays on words" that a certain breed of person loves to
spring on you and then look at you in a certain self-satisfied way to
indicate that he thinks that you must think that he is by far the 
cleverest
person on Earth now that Benjamin Franklin is dead, when in fact what you
are thinking is that if this person ever ends up in a lifeboat, the other
passengers will hurl him overboard by the end of the first day even if 
they
have plenty of food and water.
-- Dave Barry, "Why Humor is Funny"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tie dictionary to database table?

2016-06-10 Thread Peter Otten
Peter Heitzer wrote:

> Christian Gollwitzer  wrote:
>>Am 10.06.16 um 09:30 schrieb Peter Heitzer:
>>> Michael Selik  wrote:
 An ORM might be overkill. If you just want a persistent dictionary,
 just use the shelve module.
 https://docs.python.org/3/library/shelve.html
>>> That looks like tie in Perl. Unfortunately I have to use mysql as
>>> database and I need concurrent read/write as the table may be modified
>>> by other processes.
>>> Meanwhile I have analized my demans a bit and modified the task so that
>>> I need not read values but rather make updates to the tables.
> 
>>It wouldn't be that difficult to roll your own thing which does that;
>>you just need to define __setitem__ and __getitem__ in your class which
>>translates between the SQL call and the Python code.
> That's a good idea.

There's an old recipe for sqlite3

http://code.activestate.com/recipes/576638-draft-for-an-sqlite3-based-dbm/

that you might adapt.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-06-10 Thread Marko Rauhamaa
alister :

> Or more simply a hard fixed RULE (MUST be less than X lines) is Bad.

It's not X lines, it's "you must see the whole function at once."

If your display can show 1,500 lines at once, that's your limit. Mine
shows 70.

> a flexible GUIDELINE on the other hand is reasonable.

There are rare exceptions to every rule.

> after all an efficient function could be be X=1 lines, abriatrily
> spliting this could make the final function less readable & possibly
> even longer in total.

Splitting functions requires taste and skill but, when done properly,
guarantees easier reading and higher quality. As you refactor your
function, you notice clumsy and questionable idioms and end up tidying
the logic up in the process.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-06-10 Thread alister
On Fri, 10 Jun 2016 15:31:11 +0300, Marko Rauhamaa wrote:

> alister :
> 
>> Or more simply a hard fixed RULE (MUST be less than X lines) is Bad.
> 
> It's not X lines, it's "you must see the whole function at once."
> 
> If your display can show 1,500 lines at once, that's your limit. Mine
> shows 70.
> 
>> a flexible GUIDELINE on the other hand is reasonable.
> 
> There are rare exceptions to every rule.
> 
>> after all an efficient function could be be X=1 lines, abriatrily
>> spliting this could make the final function less readable & possibly
>> even longer in total.
> 
> Splitting functions requires taste and skill but, when done properly,
> guarantees easier reading and higher quality. As you refactor your
> function, you notice clumsy and questionable idioms and end up tidying
> the logic up in the process.
> 
> 
> Marko

you think I am arguing?
i am not (excpet possibly on symantics)

your "you must see the whole function on one page" stipulation should be 
treated as guidance & not a rule
preferably it should read "You 'SHOULD' be able to see the whole function 
on one page.

and as you quite rightly state there are always exceptions as enshrined 
in the zen

"Practicality beats Purity"



-- 
Must I hold a candle to my shames?
-- William Shakespeare, "The Merchant of Venice"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UserList - which methods needs to be overriden?

2016-06-10 Thread Michael Selik
On Fri, Jun 10, 2016 at 9:18 AM Michael Selik 
wrote:

>
>
> On Fri, Jun 10, 2016, 4:05 AM Nagy László Zsolt 
> wrote:
>
>> 2016.06.10. 0:38 keltezéssel, Michael Selik írta:
>>
>> On Thu, Jun 9, 2016 at 5:07 AM Nagy László Zsolt 
>> wrote:
>>
>>> I would like to create a collections.UserList subclass that can notify
>>> others when the list is mutated.
>>>
>>
>> Why not subclass MutableSequence instead? The ABC will tell you which
>> methods to override (the abstract ones). The mixin methods rely on those
>> overrides.
>>
>> The thing with MutableSequence is that it is quite inefficient. For
>> example, it implements clear() by calling pop() in a loop. It implements
>> extend() by calling append() in a loop. And we all know that the built-in
>> extend() method of the list object is much more efficient.
>>
>
If you find that extend is indeed a bottleneck, there's an easy fix.

class NoisyList(MutableSequence):
@noisy('extend')
def extend(self, iterable):
self.container.extend(iterable)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UserList - which methods needs to be overriden?

2016-06-10 Thread Michael Selik
On Fri, Jun 10, 2016, 4:05 AM Nagy László Zsolt 
wrote:

> 2016.06.10. 0:38 keltezéssel, Michael Selik írta:
>
> On Thu, Jun 9, 2016 at 5:07 AM Nagy László Zsolt 
> wrote:
>
>> I would like to create a collections.UserList subclass that can notify
>> others when the list is mutated.
>>
>
> Why not subclass MutableSequence instead? The ABC will tell you which
> methods to override (the abstract ones). The mixin methods rely on those
> overrides.
>
> I'm not sure wich one is the best. Peter wrote that UserList was left in
> collections only for backward compatiblity. This might be a point against
> using UserList. The thing with MutableSequence is that it is quite
> inefficient. For example, it implements clear() by calling pop() in a loop.
> It implements extend() by calling append() in a loop. And we all know that
> the built-in extend() method of the list object is much more efficient. It
> is true that by overriding the abstract methods, I'll get a functional list
> like object, but we all know that
>
>  There should be one-- and preferably only one --obvious way to do it.
>
>
> Which one is that? :-)
>

The easiest, most beautiful way that is sufficiently fast. Use
MutableSequence until you discover that extend is actually the bottleneck
in your program.

>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-06-10 Thread Ian Kelly
On Jun 10, 2016 6:37 AM, "Marko Rauhamaa"  wrote:
>
> alister :
>
> > Or more simply a hard fixed RULE (MUST be less than X lines) is Bad.
>
> It's not X lines, it's "you must see the whole function at once."
>
> If your display can show 1,500 lines at once, that's your limit. Mine
> shows 70.

I disagree on that point. For a typical-size display, it's a reasonable
guideline. But just because your 1500-line function fits in a single screen
does not make it readable. In particular, if the function is deeply nested,
then it quickly becomes difficult to discern which code aligns with which.

A similar principle informs us that 70-100 columns is a reasonable line
length limit for readability even if your display can fit much more.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which library has map reduce and how to use it for this case

2016-06-10 Thread Michael Selik
On Thu, Jun 9, 2016, 9:11 PM Ho Yeung Lee  wrote:

> input are these six operators, output is finding full column of 27
> elements add together is 54
>
> i got memory error when searching this,
>
> i have difficulty in understanding map reduce and transforming my program
> into map reduce problem
>

Why do you think you need map-reduce?

You'll need to explain the problem in more detail. Instead of talking about
operators and columns, what is the actual, real-world problem?

>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread Steven D'Aprano
On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:

[snip unreadable code]

I just ran your code, and it almost crashed my computer. I think it is quite
rude to post code without an explanation of what the problem is.


I'm afraid that your code is virtually unreadable to me. It is too verbose,
the indentation is awful (single space indents is impossible for me to
track by eye) and it makes too much work out of simple operations. And none
of the variable names mean anything.

I've started to simplify and clean the code, and got to the following, which
I hope you will agree is easier to read and more compact:



import itertools
M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, 
  '12': 1, '20': 1, '21': 1, '22': 2}
M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, 
  '12': 1, '20': 1, '21': 1, '22': 1}
M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, 
  '12': 1, '20': 0, '21': 1, '22': 2}
M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, 
  '12': 2, '20': 0, '21': 1, '22': 2}
M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, 
  '12': 1, '20': 0, '21': 1, '22': 1}
# Why V instead of M?
V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, 
  '12': 1, '20': 1, '21': 2, '22': 2}

MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
m = 3
b = [str(i)+str(j)+str(k) for i in range(m) 
 for j in range(m) for k in range(m)]
mylist = [MM[i] for i in range(6)]

def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]] for i in range(len(b))]
op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]] for i in range(len(b))]
op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:
path.append([(deep, bb, "xz")])
initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz])
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
level.extend([op1xy, op2xy])
initlist.extend([op1xy, op2xy])
if deep == maxx:
b = []
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
path = DFS(b, deep-1, maxx, sourceoperators, path)
return path

path = []
mresult = DFS(b, 2, 2, mylist, path)



Unfortunate, in cleaning up your code, I have changed something, because my
version and your version do not do the same thing.

After nearly crashing my computer running your version, I am not going to
spend the time trying to debug this. If you want our help, I suggest that
you clean up the code. Currently it is an incomprehensible mess to me. Even
after the cleanup, I have no idea what this piece of code is supposed to do
or what it is calculating.

Can you explain the purpose of the code? What is it calculating? Can you
show the expected results? What does "DFS" mean? Why do you have M1 - M5
but then a mysterious V6?

I can see you are calculating *something* to do with permutations of 0 1 2,
but I don't understand what.

I think I can see one problem: DFS is a recursive function, but it never
ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is
zero. So I expect that you will have an infinite loop that just recurses
over and over, until you run out of memory or hit the recursion limit.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-06-10 Thread Steven D'Aprano
On Sat, 11 Jun 2016 12:00 am, Ian Kelly wrote:

> On Jun 10, 2016 6:37 AM, "Marko Rauhamaa"  wrote:

>> If your display can show 1,500 lines at once, that's your limit. Mine
>> shows 70.
> 
> I disagree on that point. For a typical-size display, it's a reasonable
> guideline. But just because your 1500-line function fits in a single
> screen does not make it readable. 

I disagree. I have a 2000 inch monitor, and by using a narrow proportional
font set to 5pt, I can display the entire Python standard library including
tests on screen at once. Then it's just a matter of using my trusty 4"
reflecting telescope to zoom in on any part of the screen I like. This is
much more convenient than opening a single file at a time, or using a
tabbed interface, it is much more efficient to just swivel the telescope
and jump to the correct part of the code, and it rarely takes me more than
ten or fifteen minutes to find it.

And I can read the code in perfect clarity, provided I don't nudge or touch
the telescope in any way, or breathe too hard. Apart from "rn" which tends
to look like an "m", and its a bit hard to tell the difference between 0
and 0 or 1 I and l, or S and 5, and to be honest periods and commas are
completely invisible, but that's a small price to pay for the extra
efficiency of having all 641 thousand lines of code on screen all at once.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Almost crashing computer, was Re: how to solve memory

2016-06-10 Thread Peter Otten
Steven D'Aprano wrote:

> I just ran your code, and it almost crashed my computer. 

When you suspect that a script may consume a lot of memory (the subject 
might have been a hint)

ulimit (bash internal) 

helps you prevent that your linux machine becomes unresponsive.

$ ulimit -v 20
$ python3 tmp2.py > /dev/null
Traceback (most recent call last):
  File "tmp2.py", line 134, in 
mresult = DFS(b, 2, 2, mylist, path)
  File "tmp2.py", line 125, in DFS
path = DFS(b, deep-1, maxx, sourceoperators, path)
  File "tmp2.py", line 129, in DFS
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
  File "tmp2.py", line 129, in 
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
MemoryError


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread John Gordon
In <4f853aa2-cc00-480b-9fd7-79b05cbd4...@googlegroups.com> meInvent bbird 
 writes:

> https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing

I already responded to your earlier post about this program.  Did you
read it?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread meInvent bbird
i put final part of code inside one more space
and add constraint deep > 0
but still memory error

and print the deep number to see, it do not run infinity again


V6 is just my superstitution, because V is disable 6 is separation

i run your version directly, it has key = '0' error

M1 = {}
M2 = {}
M3 = {}
M4 = {}
M5 = {}
V6 = {}
M1['00']=0
M1['01']=1
M1['02']=2
M1['10']=1
M1['11']=1
M1['12']=2
M1['20']=2
M1['21']=2
M1['22']=2
M2['00']=0
M2['01']=0
M2['02']=2
M2['10']=0
M2['11']=1
M2['12']=2
M2['20']=2
M2['21']=2
M2['22']=2
M3['00']=0
M3['01']=0
M3['02']=0
M3['10']=0
M3['11']=1
M3['12']=2
M3['20']=0
M3['21']=2
M3['22']=2
M4['00']=0
M4['01']=1
M4['02']=0
M4['10']=1
M4['11']=1
M4['12']=1
M4['20']=0
M4['21']=1
M4['22']=2
M5['00']=0
M5['01']=0
M5['02']=0
M5['10']=0
M5['11']=1
M5['12']=2
M5['20']=0
M5['21']=2
M5['22']=2
V6['00']=2
V6['01']=2
V6['02']=2
V6['10']=1
V6['11']=2
V6['12']=2
V6['20']=0
V6['21']=1
V6['22']=2
MM = {}
MM[0] = M1
MM[1] = M2
MM[2] = M3
MM[3] = M4
MM[4] = M5
MM[5] = V6
m = 3
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
import itertools
deep = 3
final = []
mylist = [MM[i] for i in range(0,7-1)]
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
def DFS(b, deep, maxx, sourceoperators, path):
 initlist = []
 if deep > 0:
  print("deep=", deep)
  for aa,bb in itertools.combinations(sourceoperators, 2):
   print(aa,bb)
   if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
  path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
  path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
  path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
  path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
  path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:  
  path.append([(deep, bb, "xz")])
initlist.append(op1xy)
initlist.append(op1yz)
initlist.append(op1xz)
initlist.append(op2xy)
initlist.append(op2yz)
initlist.append(op2xz)
   else:
level = []
for j in range(len(b)):
 op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
 op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
 if sum(op1xy) == 54:
  path.append([(deep, aa, "xy")])
 if sum(op2xy) == 54:
  path.append([(deep, bb, "xy")])
 level.append(op1xy)
 level.append(op2xy)
 initlist.append(op1xy)
 initlist.append(op2xy)
  if deep == maxx:
   if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2): 
 b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path = DFS(b, deep-1, maxx, sourceoperators, path)
  else:
   if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
 b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path = DFS(b, deep-1, maxx, sourceoperators, path)
 return path

path = []
mresult = DFS(b, 2, 2, mylist, path)


On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote:
> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
> 
> [snip unreadable code]
> 
> I just ran your code, and it almost crashed my computer. I think it is quite
> rude to post code without an explanation of what the problem is.
> 
> 
> I'm afraid that your code is virtually unreadable to me. It is too verbose,
> the indentation is awful (single space indents is impossible for me to
> track by eye) and it makes too much work out of simple operations. And none
> of the variable names mean anything.
> 
> I've started to simplify and clean the code, and got to the following, which
> I hope you will agree is easier to read and more compact:
> 
> 
> 
> import itertools
> M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, 
>   '12': 1, '20': 1, '21': 1, '22': 2}
> M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, 
>   '12': 1, '20': 1, '21': 1, '22': 1}
> M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, 
>   '12': 1, '20': 0, '21': 1, '22': 2}
> M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, 
>   '12': 2, '20': 0, '21': 1, '22': 2}
> M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, 
>   '12': 1, '20': 0, '21': 1, '22': 1}
> # Why V instead of M?
> V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, 
>   '12': 1, '20': 1, '21': 2, '22': 2}
> 
> MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
> m = 3
> b = [str(i)+str(j)+str(k) for i in range(m) 
>  for j in range(m) for k in range(m)]
> mylist = [MM[i] for i in range(6)]
> 
> def DFS(b, deep, maxx, sourceoperators, path):
> initlist = []
> if deep > 0:
> print("deep=", deep)
> for aa,bb in it

Re: run code error with numpy and scipy

2016-06-10 Thread meInvent bbird
On Thursday, June 9, 2016 at 9:52:43 PM UTC+8, MRAB wrote:
> On 2016-06-09 07:02, meInvent bbird wrote:
> > when i run code in window has an error not a valid win32 dll
> >
> > then i install scipy first in this site, then install numpy-mkl
> > all python 2.7 and win32
> >
> > http://www.lfd.uci.edu/~gohlke/pythonlibs/
> >
> > then i run code below, got error , and captured screen in this link
> >
> > https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing
> >
> [snip]
> You're entering it at the interactive Python prompt.
> 
> When it sees the blank line, it thinks you've finished entering the 
> function, so it complains when the next line is indented. (Things are 
> slightly different when working interactively than when running from a 
> file.)
> 
> You should put the code into a file and then run that.

thank you i will try it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread meInvent bbird
On Friday, June 10, 2016 at 10:46:43 PM UTC+8, John Gordon wrote:
> In <4f853aa2-cc00-480b-9fd7-79b05cbd4...@googlegroups.com> meInvent bbird 
>  writes:
> 
> > https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing
> 
> I already responded to your earlier post about this program.  Did you
> read it?
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"



sorry i missed your reply post, 
i find post by me and search your name, no this name
is your name changed in previous post?

could you post the link here?
is it an email or google group post?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread meInvent bbird
On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote:
> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
> 
> [snip unreadable code]
> 
> I just ran your code, and it almost crashed my computer. I think it is quite
> rude to post code without an explanation of what the problem is.
> 
> 
> I'm afraid that your code is virtually unreadable to me. It is too verbose,
> the indentation is awful (single space indents is impossible for me to
> track by eye) and it makes too much work out of simple operations. And none
> of the variable names mean anything.
> 
> I've started to simplify and clean the code, and got to the following, which
> I hope you will agree is easier to read and more compact:
> 
> 
> 
> import itertools
> M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, 
>   '12': 1, '20': 1, '21': 1, '22': 2}
> M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, 
>   '12': 1, '20': 1, '21': 1, '22': 1}
> M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, 
>   '12': 1, '20': 0, '21': 1, '22': 2}
> M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, 
>   '12': 2, '20': 0, '21': 1, '22': 2}
> M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, 
>   '12': 1, '20': 0, '21': 1, '22': 1}
> # Why V instead of M?
> V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, 
>   '12': 1, '20': 1, '21': 2, '22': 2}
> 
> MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
> m = 3
> b = [str(i)+str(j)+str(k) for i in range(m) 
>  for j in range(m) for k in range(m)]
> mylist = [MM[i] for i in range(6)]
> 
> def DFS(b, deep, maxx, sourceoperators, path):
> initlist = []
> if deep > 0:
> print("deep=", deep)
> for aa,bb in itertools.combinations(sourceoperators, 2):
> print(aa,bb)
> if deep == maxx:
> finalresult = []
> op1xy = [aa[b[i][0:1]] for i in range(len(b))]
> op1yz = [aa[b[i][1:2]] for i in range(len(b))]
> op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))]
> op2xy = [bb[b[i][0:1]] for i in range(len(b))]
> op2yz = [bb[b[i][1:2]] for i in range(len(b))]
> op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op1yz) == 54:
> path.append([(deep, aa, "yz")])
> if sum(op1xz) == 54:
> path.append([(deep, aa, "xz")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> if sum(op2yz) == 54:
> path.append([(deep, bb, "yz")])
> if sum(op2xz) == 54:
> path.append([(deep, bb, "xz")])
> initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz])
> else:
> level = []
> for j in range(len(b)):
> op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
> op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> level.extend([op1xy, op2xy])
> initlist.extend([op1xy, op2xy])
> if deep == maxx:
> b = []
> for aaa,bbb in itertools.combinations(initlist, 2):
> b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
> path = DFS(b, deep-1, maxx, sourceoperators, path)
> return path
> 
> path = []
> mresult = DFS(b, 2, 2, mylist, path)
> 
> 
> 
> Unfortunate, in cleaning up your code, I have changed something, because my
> version and your version do not do the same thing.
> 
> After nearly crashing my computer running your version, I am not going to
> spend the time trying to debug this. If you want our help, I suggest that
> you clean up the code. Currently it is an incomprehensible mess to me. Even
> after the cleanup, I have no idea what this piece of code is supposed to do
> or what it is calculating.
> 
> Can you explain the purpose of the code? What is it calculating? Can you
> show the expected results? What does "DFS" mean? Why do you have M1 - M5
> but then a mysterious V6?
> 
> I can see you are calculating *something* to do with permutations of 0 1 2,
> but I don't understand what.
> 
> I think I can see one problem: DFS is a recursive function, but it never
> ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is
> zero. So I expect that you will have an infinite loop that just recurses
> over and over, until you run out of memory or hit the recursion limit.
> 
> 
> 
> -- 
> Steven

i recorded a video to show what i am searching for

https://drive.google.com/file/d/0Bxs_ao6uuBDUbjFxbjJReXZoNHc/view?usp=sharing

something i hide because i invented some math, hope your mercy.
-- 
https://m

Re: for / while else doesn't make sense

2016-06-10 Thread Marko Rauhamaa
Ian Kelly :

> On Jun 10, 2016 6:37 AM, "Marko Rauhamaa"  wrote:
>> If your display can show 1,500 lines at once, that's your limit. Mine
>> shows 70.
>
> I disagree on that point. For a typical-size display, it's a
> reasonable guideline.

The point I'm making is that if I'm accusing you for writing functions
that are too long (they don't fit on my editor window), you can counter
that they fit perfectly well on yours.

No-one has 1,500-line editor windows, I suppose. However, screen sizes
have been going up and some people prefer to turn their screens into
portrait mode (tried it, made my neck hurt). Years back, I had 24 lines
on the screen. As screen sizes have gone up, I've allowed for longer
functions as well. Now I'm at 70. Of course, most functions tend to be
much shorter.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread John Gordon
In <8a1c372e-bd6c-4923-8ae1-8f129ec74...@googlegroups.com> meInvent bbird 
 writes:

> > I already responded to your earlier post about this program.  Did you
> > read it?

> sorry i missed your reply post, 
> i find post by me and search your name, no this name
> is your name changed in previous post?

My comment was that the recursive calls weren't indented in the
"if deep > 0" block, therefore DFS was being called infinitely with smaller
and smaller values of deep.  But it appears you have fixed that issue.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


fast dictionary initialization

2016-06-10 Thread maurice
Hi. If I have already a list of values, let's call it valuesList and the 
keysList, both same sized lists, what is the easiest/quickest way to initialize 
a dictionary with those keys and list, in terms of number of lines perhaps?

example:
valuesList = [1,2,3]
keysList   = ['1','2','3']

So the dictionary can basically convert string to int:

dictionary = {'1':1, '2':2, '3':3}

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: fast dictionary initialization

2016-06-10 Thread Random832
pOn Fri, Jun 10, 2016, at 17:07, maurice wrote:
> Hi. If I have already a list of values, let's call it valuesList and the
> keysList, both same sized lists, what is the easiest/quickest way to
> initialize a dictionary with those keys and list, in terms of number of
> lines perhaps?
> 
> example:
> valuesList = [1,2,3]
> keysList   = ['1','2','3']
> 
> So the dictionary can basically convert string to int:
> 
> dictionary = {'1':1, '2':2, '3':3}

dict(zip(keysList, valuesList))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: movie from pictures

2016-06-10 Thread alex wright
I find shlex.split to be most useful to make my arguments a list in these
cases.
On Jun 9, 2016 3:28 PM, "MRAB"  wrote:

> On 2016-06-09 19:58, Peter Otten wrote:
>
>> Nev wrote:
>>
>> Thank you for your reply. I tried something like this in python code:
>>>
>>> from subprocess import call
>>> call(["ffmpeg -framerate 4/1 -start_number 1 -i
>>> C:\\Projects\\data2\\img_%05d.png -c:v libx264 -r 30 -pix_fmt yuv420p
>>> C:\\Projects\\data2\\movie.mp4"])
>>>
>>> But it did not work. I get FileNotFoundError: [WinError 2] The system
>>> cannot find the file specified..
>>>
>>
>> You have to pass the command-line arguments as separate items in the list:
>>
>> call(["ffmpeg",
>>   "-framerate", "4/1",
>>   "-start_number", "1",
>>   "-i", "C:\\Projects\\data2\\img_%05d.png",
>>   ... # and so on
>>   ])
>>
>> You should also give it the full path of ffmpeg.
>
> On the other hand, in-loop solution would be more preferable since it lets
>>> me to use variable names of the images and paths..
>>>
>>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


i'm a python newbie & wrote my first script, can someone critique it?

2016-06-10 Thread mad scientist jr
Is this group appropriate for that kind of thing? 
(If not sorry for posting this here.)

So I wanted to start learning Python, and there is s much information 
online, which is a little overwhelming. I really learn best from doing, 
especially if it's something actually useful. I needed to create a bunch of 
empty folders, so I figured it was a good exercise to start learning Python. 
Now that it's done, I am wondering what kind of things I could do better. 
Here is the code: 

# WELCOME TO MY FIRST PYTHON SCRIPT!
# FIRST OF ALL, IT ***WORKS***!!! YAY!
# I AM A VBA AND JAVASCRIPT PROGRAMMER, 
# SO IT IS PROBABLY NOT VERY "PYTHONIC", 
# SO PLEASE FEEL FREE TO TEAR THE SCRIPT A NEW ONE
# AFTER YOU ARE SHOCKED BY THIS BAD CODE, 
# ALL I ASK IS THAT IF YOU THINK SOMETHING IS BAD, 
# PLEASE POST AN EXAMPLE OF THE "CORRECT" WAY OF DOING IT
# COMING FROM VBA, I KNOW A LITTLE OOP,
# BUT NOT C++ C# JAVA STUFF LIKE "INTERFACES" AND "ABSTRACT BASE CLASSES"
# SO IF YOU GET INTO SUCH TERMINOLOGY MY EYES MIGHT START TO GLAZE OVER
# UNLESS YOU CARE TO EXPLAIN THAT TOO


# GLOBAL VALUES
sForPythonVersion="3"
#sFolderPathTemplate = "c:\\myscripts\\MP3 Disc "
sFolderPathTemplate = "c:\\temp\\MP3 Disc "
iFromCount = 1
iToCount = 250
iCountWidth = 3


# SUPPORT FUNCTIONS

# 
//
def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN 
ENGLISH!)
#PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or 
isinstance(myVar, unicode) )
#PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr)
return isinstance(myVar, str)

# 
//
# THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY STEPS"
def strip_one_space(s):
if s.endswith(" "): s = s[:-1]
if s.startswith(" "): s = s[1:]
return s

# 
//
def get_exact_python_version():
import sys
sVersion = ".".join(map(str, sys.version_info[:3]))
sVersion = sVersion.strip()
return sVersion

# 
//
# TO DO: RETURN TO THE LEFT OF FIRST "."
def get_python_version():
sVersion = get_exact_python_version()
return sVersion[0:1]

# 
//
# CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS UP
# (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!)
# MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT CASE
# TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0
def exit_if_wrong_python_version(sRightVersion):
import os
sCurrentVersion = get_python_version()
if (sCurrentVersion != sRightVersion):
print("" +
  "Wrong Python version (" +
  sCurrentVersion +
  "), this script should be run using Python " +
  sRightVersion +
  ".x. Exiting..."
  )
os._exit(0)

# 
//
def get_script_filename():
import os
return os.path.basename(__file__)

# 
//
def get_timestamp():
import datetime
return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d 
%H:%M:%S')

# 
//

def create_folder(sPath):
import os
import errno
#if not os.path.exists(directory):
#os.makedirs(directory)
try:
os.makedirs(sPath, exist_ok=True)
except OSError as exception:
#if exception.errno != errno.EEXIST:
print("ERROR #" + str(exception.errno) + "IN makedirs")
raise

# 
/

Re: how to solve memory

2016-06-10 Thread meInvent bbird
i put final part of code inside one more space 
and add constraint deep > 0 
but still memory error 

and print the deep number to see, it do not run infinity again 


V6 is just my superstitution, because V is disable 6 is separation 

i run your version directly, it has key = '0' error 

M1 = {}
M2 = {}
M3 = {}
M4 = {}
M5 = {}
V6 = {}
M1['00']=0
M1['01']=1
M1['02']=1
M1['10']=2
M1['11']=2
M1['12']=1
M1['20']=1
M1['21']=1
M1['22']=1
M2['00']=0
M2['01']=1
M2['02']=1
M2['10']=1
M2['11']=2
M2['12']=2
M2['20']=1
M2['21']=1
M2['22']=1
M3['00']=0
M3['01']=1
M3['02']=1
M3['10']=0
M3['11']=1
M3['12']=2
M3['20']=0
M3['21']=2
M3['22']=2
M4['00']=0
M4['01']=1
M4['02']=0
M4['10']=1
M4['11']=2
M4['12']=2
M4['20']=0
M4['21']=1
M4['22']=1
M5['00']=0
M5['01']=1
M5['02']=1
M5['10']=2
M5['11']=1
M5['12']=2
M5['20']=0
M5['21']=2
M5['22']=1
V6['00']=1
V6['01']=1
V6['02']=2
V6['10']=1
V6['11']=1
V6['12']=1
V6['20']=2
V6['21']=2
V6['22']=2
MM = {}
MM[0] = M1
MM[1] = M2
MM[2] = M3
MM[3] = M4
MM[4] = M5
MM[5] = V6
m = 3
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
import itertools
deep = 3
final = []
mylist = [MM[i] for i in range(0,7-1)]
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
def DFS(b, deep, maxx, sourceoperators, path):
 initlist = []
 if deep > 0:
  print("deep=", deep)
  for aa,bb in itertools.combinations(sourceoperators, 2):
   print(aa,bb)
   if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
  path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
  path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
  path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
  path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
  path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:  
  path.append([(deep, bb, "xz")])
initlist.append(op1xy)
initlist.append(op1yz)
initlist.append(op1xz)
initlist.append(op2xy)
initlist.append(op2yz)
initlist.append(op2xz)
   else:
level = []
for j in range(len(b)):
 op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
 op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
 if sum(op1xy) == 54:
  path.append([(deep, aa, "xy")])
 if sum(op2xy) == 54:
  path.append([(deep, bb, "xy")])
 level.append(op1xy)
 level.append(op2xy)
 initlist.append(op1xy)
 initlist.append(op2xy)
  if deep == maxx:
   if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2): 
 b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
  else:
   if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
 b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
 return path

path = []
mresult = DFS(b, 2, 2, mylist, path)



On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote:
> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
> 
> [snip unreadable code]
> 
> I just ran your code, and it almost crashed my computer. I think it is quite
> rude to post code without an explanation of what the problem is.
> 
> 
> I'm afraid that your code is virtually unreadable to me. It is too verbose,
> the indentation is awful (single space indents is impossible for me to
> track by eye) and it makes too much work out of simple operations. And none
> of the variable names mean anything.
> 
> I've started to simplify and clean the code, and got to the following, which
> I hope you will agree is easier to read and more compact:
> 
> 
> 
> import itertools
> M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1, 
>   '12': 1, '20': 1, '21': 1, '22': 2}
> M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1, 
>   '12': 1, '20': 1, '21': 1, '22': 1}
> M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2, 
>   '12': 1, '20': 0, '21': 1, '22': 2}
> M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2, 
>   '12': 2, '20': 0, '21': 1, '22': 2}
> M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2, 
>   '12': 1, '20': 0, '21': 1, '22': 1}
> # Why V instead of M?
> V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2, 
>   '12': 1, '20': 1, '21': 2, '22': 2}
> 
> MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
> m = 3
> b = [str(i)+str(j)+str(k) for i in range(m) 
>  for j in range(m) for k in range(m)]
> mylist = [MM[i] for i in range(6)]
> 
> def DFS(b, deep, maxx, sourceoperators, path):
> initlist = []
> if deep > 0:
>

Re: how to solve memory

2016-06-10 Thread meInvent bbird
it is quite ridiculous, 
this time i am sure that i put correct indentation
and add a else statement to make sure recursive call inside the 
if statement , it still memory error, 

where is the memory error?

is itertools.combinations so big for the list?


  if deep == maxx:
   if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2): 
 b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
   else:
print ""
  else:
   if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
 b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
   else:
print ""
 return path


On Saturday, June 11, 2016 at 12:26:55 AM UTC+8, John Gordon wrote:
> In <8a1c372e-bd6c-4923-8ae1-8f129ec74...@googlegroups.com> meInvent bbird 
>  writes:
> 
> > > I already responded to your earlier post about this program.  Did you
> > > read it?
> 
> > sorry i missed your reply post, 
> > i find post by me and search your name, no this name
> > is your name changed in previous post?
> 
> My comment was that the recursive calls weren't indented in the
> "if deep > 0" block, therefore DFS was being called infinitely with smaller
> and smaller values of deep.  But it appears you have fixed that issue.
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i'm a python newbie & wrote my first script, can someone critique it?

2016-06-10 Thread Christopher Reimer


Sent from my iPhone

> On Jun 10, 2016, at 3:52 PM, mad scientist jr  
> wrote:
> . 
> Now that it's done, I am wondering what kind of things I could do better.

This is Python, not BASIC. Lay off on the CAP LOCK key and delete all the 
comments and separation blocks. No one is going to find your code in all that 
noise.

Chris R.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread MRAB

On 2016-06-11 00:31, meInvent bbird wrote:

it is quite ridiculous,
this time i am sure that i put correct indentation
and add a else statement to make sure recursive call inside the
if statement , it still memory error,

where is the memory error?

is itertools.combinations so big for the list?


[snip]

How long is initlist?

When I ran the code, it said over 100_000 items.

How many combinations would there be?

Over 10_000_000_000.

That's how long the list 'b' would be.

You'll need 10s of gigabytes of memory and a lot of patience!

--
https://mail.python.org/mailman/listinfo/python-list


Re: i'm a python newbie & wrote my first script, can someone critique it?

2016-06-10 Thread Marc Brooks
The structure of your program is really not that Pythonic.  I'd recommend
you take a look at PEP 8.

https://www.python.org/dev/peps/pep-0008/

It's not perfect, but it's a good start to get a feel for how to structure
your Python work.

Marc

On Fri, Jun 10, 2016 at 7:05 PM, Christopher Reimer <
christopher_rei...@icloud.com> wrote:

>
>
> Sent from my iPhone
>
> > On Jun 10, 2016, at 3:52 PM, mad scientist jr <
> mad.scientist...@gmail.com> wrote:
> > .
> > Now that it's done, I am wondering what kind of things I could do better.
>
> This is Python, not BASIC. Lay off on the CAP LOCK key and delete all the
> comments and separation blocks. No one is going to find your code in all
> that noise.
>
> Chris R.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy

2016-06-10 Thread rocky
On Friday, June 10, 2016 at 4:33:28 AM UTC-4, Robin Becker wrote:
> On 08/06/2016 19:32, rocky wrote:
> ..
> >
> > Sorry that should have been 1998 which would make more sense for the 7th  
> > conference if the 1st one was around 2001. I've corrected the date in [1] 
> > https://pypi.python.org/pypi/spark_parser/1.3.0
> >
> > The automated tests in the package just don't  catch stuff like this. But 
> > I'm sure there are also other mistakes as well in there so feel free to let 
> > me know.
> >
> not a big deal; I like the spark parser :)
> -- 
> Robin Becker

It is cool for how small in code size, how general, (more general than LL or 
LR), and how fast it works for well-crafted grammars. Surprisingly little was 
needed to make it work on Python 3 (as well as addition on Python 2).

It has however long been neglected. John stopped working on it around 2002 or 
so without having put it on Pypy. Since it wasn't it's own package, so you had 
to find some other project (with possibly varying versions of the program) and 
copy the spark.py file from that or download the "0.7 pre-alpha" version of 
2002 from John's website and possibly modify it if you have Python 3. 

Ok. So I've got that addressed by putting it in pypy. 

But the other basic area of neglect as documentation. John's paper I find 
woefully inadequate. Most of the projects on John's site that say they use 
SPARK are now dead links. And using the various uncompyle/decompyle programs as 
a tutorial for the parser is a bit whacky too as these are very complicated, 
and not intended as a tutorial.

I've only started to address this by putting together some simple examples. And 
on http://github.com/rocky/python-spark there is now a wiki to try to address 
some of this as well. In the wiki for http://github.com/rocky/python-uncompyle6 
I've extracted the documentation for the table-driven formatting, but more is 
needed here as well.

So if you or other like this and know to to use it, please consider beefing up 
the wiki. Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i'm a python newbie & wrote my first script, can someone critique it?

2016-06-10 Thread Joel Goldstick
On Fri, Jun 10, 2016 at 6:52 PM, mad scientist jr
 wrote:
> Is this group appropriate for that kind of thing?
> (If not sorry for posting this here.)
>
> So I wanted to start learning Python, and there is s much information 
> online, which is a little overwhelming. I really learn best from doing, 
> especially if it's something actually useful. I needed to create a bunch of 
> empty folders, so I figured it was a good exercise to start learning Python.
> Now that it's done, I am wondering what kind of things I could do better.
> Here is the code:
>
> # WELCOME TO MY FIRST PYTHON SCRIPT!
> # FIRST OF ALL, IT ***WORKS***!!! YAY!
> # I AM A VBA AND JAVASCRIPT PROGRAMMER,
> # SO IT IS PROBABLY NOT VERY "PYTHONIC",
> # SO PLEASE FEEL FREE TO TEAR THE SCRIPT A NEW ONE
> # AFTER YOU ARE SHOCKED BY THIS BAD CODE,
> # ALL I ASK IS THAT IF YOU THINK SOMETHING IS BAD,
> # PLEASE POST AN EXAMPLE OF THE "CORRECT" WAY OF DOING IT
> # COMING FROM VBA, I KNOW A LITTLE OOP,
> # BUT NOT C++ C# JAVA STUFF LIKE "INTERFACES" AND "ABSTRACT BASE CLASSES"
> # SO IF YOU GET INTO SUCH TERMINOLOGY MY EYES MIGHT START TO GLAZE OVER
> # UNLESS YOU CARE TO EXPLAIN THAT TOO
>
>
Ditch the uppercase comments.
 

> # GLOBAL VALUES
> sForPythonVersion="3"
> #sFolderPathTemplate = "c:\\myscripts\\MP3 Disc "
> sFolderPathTemplate = "c:\\temp\\MP3 Disc "
> iFromCount = 1
> iToCount = 250
> iCountWidth = 3
>
Python has guidelines for naming things.  Don't use camel case.  Use
lower case and put underscores between words.  Globals are a bad idea.
If you don't know why, they are even a worse idea
> 
> # SUPPORT FUNCTIONS
>
> # 
> //
> def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN 
> ENGLISH!)
> #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or 
> isinstance(myVar, unicode) )
> #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr)
> return isinstance(myVar, str)

I'm not sure why you want to test for type.
>
> # 
> //
> # THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY STEPS"
> def strip_one_space(s):
> if s.endswith(" "): s = s[:-1]
> if s.startswith(" "): s = s[1:]
> return s

This may be from some book, but it could be done:
s.strip()


>
> # 
> //
> def get_exact_python_version():
> import sys
> sVersion = ".".join(map(str, sys.version_info[:3]))
> sVersion = sVersion.strip()
> return sVersion
>
> # 
> //
> # TO DO: RETURN TO THE LEFT OF FIRST "."
> def get_python_version():
> sVersion = get_exact_python_version()
> return sVersion[0:1]
>
> # 
> //
> # CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS UP
> # (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!)
> # MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT CASE
> # TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0
> def exit_if_wrong_python_version(sRightVersion):
> import os
> sCurrentVersion = get_python_version()
> if (sCurrentVersion != sRightVersion):
> print("" +
>   "Wrong Python version (" +
>   sCurrentVersion +
>   "), this script should be run using Python " +
>   sRightVersion +
>   ".x. Exiting..."
>   )
> os._exit(0)
>
> # 
> //
> def get_script_filename():
> import os
> return os.path.basename(__file__)
>
> # 
> //
> def get_timestamp():
> import datetime
> return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d 
> %H:%M:%S')
>
> # 
> //

Re: Want to play with or learn a parser system including a grammar for Python? See spark_parser on pypy

2016-06-10 Thread rocky
On Thursday, June 9, 2016 at 1:36:56 AM UTC-4, Lawrence D’Oliveiro wrote:
> On Wednesday, June 8, 2016 at 10:39:00 PM UTC+12, rocky wrote:
> 
> > In addition to the example programs which give the classic arithmetic
> > expression evaluator, I now include the beginnings of a full Python 2.6
> > language.
> 
> Does anybody bother with LR(k) parsers any more?

I don't understand. Python itself I think does. And By the way, SPARK is an 
Early-Algorithm parser [1], so it is a little more general than LL or LR 
parsers. 

[1] https://en.wikipedia.org/wiki/Earley_parser
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-06-10 Thread Gregory Ewing

Steven D'Aprano wrote:

I have a 2000 inch monitor, and by using a narrow proportional
font set to 5pt, I can display the entire Python standard library including
tests on screen at once. Then it's just a matter of using my trusty 4"
reflecting telescope to zoom in on any part of the screen I like.


You may think you're joking, but this sounds remarkably
similar to microfiche...

http://www.wisegeek.org/what-is-microfiche.htm

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: fast dictionary initialization

2016-06-10 Thread Tim Chase
On 2016-06-10 14:07, maurice wrote:
> example:
> valuesList = [1,2,3]
> keysList   = ['1','2','3']
> 
> So the dictionary can basically convert string to int:
> 
> dictionary = {'1':1, '2':2, '3':3}

A couple similar options:


The most straightforward translation of your description:

  opt1 = dict(zip(keysList, valuesList))
  print(opt1["2"])

And one where you generate the strings on the fly:

  opt2 = dict((str(i), i) for i in range(1, 4))
  print(opt2["2"])

And one where you use the int() function instead of a mapping because
the whole idea of storing a dict worth of string-numbers-to-numbers
seems somewhat silly to me:

  print(int("2"))

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: i'm a python newbie & wrote my first script, can someone critique it?

2016-06-10 Thread Larry Hudson via Python-list

On 06/10/2016 03:52 PM, mad scientist jr wrote:

Is this group appropriate for that kind of thing?
(If not sorry for posting this here.)

So I wanted to start learning Python, and there is s much information 
online, which is a little overwhelming. I really learn best from doing, 
especially if it's something actually useful. I needed to create a bunch of 
empty folders, so I figured it was a good exercise to start learning Python.
Now that it's done, I am wondering what kind of things I could do better.
Here is the code:


It is FAR too complicated -- it's BASIC written Python.  Python is MUCH easier.

First a couple of general comments...

Drop the Hungarian notation!!  Python uses dynamic typing.  Variables do NOT have a type, the 
data they hold have types, but not the variable itself.  ANY variable can hod ANY data type at 
ANY time.  And Python uses duck typing -- get used to it.


Generally you should put all the imports at the beginning of the program, NOT in each function. 
 A possible exception could be if an import is only used in one function.




# GLOBAL VALUES
sForPythonVersion="3"
#sFolderPathTemplate = "c:\\myscripts\\MP3 Disc "
sFolderPathTemplate = "c:\\temp\\MP3 Disc "
iFromCount = 1
iToCount = 250
iCountWidth = 3


Drop the  from the template string.  (More on this below.)



# SUPPORT FUNCTIONS

# 
//
def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN 
ENGLISH!)
 #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or 
isinstance(myVar, unicode) )
 #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr)
 return isinstance(myVar, str)


Not necessary.


# 
//
# THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY STEPS"
def strip_one_space(s):
 if s.endswith(" "): s = s[:-1]
 if s.startswith(" "): s = s[1:]
 return s


???  Is this used anyplace?  Delete it.


# 
//
def get_exact_python_version():
 import sys
 sVersion = ".".join(map(str, sys.version_info[:3]))
 sVersion = sVersion.strip()
 return sVersion

sys.version_info[:3] by itself gives a three-element tuple.  Probably easier to use than the 
string version.


A couple alternatives:
sys.version[:5] or perhaps a bit safer -- sys.version.split()[0] both directly give you the 
string version.  (Note this uses version not version_info.)



# 
//
# TO DO: RETURN TO THE LEFT OF FIRST "."
def get_python_version():
 sVersion = get_exact_python_version()
 return sVersion[0:1]


Probably unnecessary as a function.  A simple sVersion[0] in-line might be 
easier.


# 
//
# CHECK PYTHON VERSION, IF IT'S WRONG THEN GRACEFULLY EXIT BEFORE IT BLOWS UP
# (DAMN, PYTHON 2.x STILL COMPLAINS WITH SYNTAX ERRORS!!)
# MAYBE THIS COULD STILL BE USEFUL FOR CHECKING THE SUB-VERSION, IN THAT CASE
# TO DO: MORE GRANULAR CHECK, EG IF VERSION >= 3.5.0
def exit_if_wrong_python_version(sRightVersion):
 import os
 sCurrentVersion = get_python_version()
 if (sCurrentVersion != sRightVersion):
 print("" +
   "Wrong Python version (" +
   sCurrentVersion +
   "), this script should be run using Python " +
   sRightVersion +
   ".x. Exiting..."
   )
 os._exit(0)


Get used to Python string formatting...
print("Wrong Python version ({}), this script should be run using "
"Python {}.x,  Exiting...".format(sCurrentVersion, sRightVersion))

Notice how I split the long single-line string into two shorter strings on two lines relying on 
the automatic string concatenation in Python.  "string1 " "string2" becomes "string1 string2". 
Any whitespace (spaces, tabs, newlines) are ignored and the two strings are stuck together.


Also the common use is sys.exit() instead of os._exit().


# 

Re: i'm a python newbie & wrote my first script, can someone critique it?

2016-06-10 Thread Matt Wheeler
First of all welcome :)

The other suggestions you've received so far are good so I won't repeat
them... (note that in particular I've reused the names you've chosen in
your program where I've given code examples, but that's purely for clarity
and I agree with the others who've said you should use a more pythonic
naming convention)

On Fri, 10 Jun 2016, 23:52 mad scientist jr, 
wrote:

> Is this group appropriate for that kind of thing?
> (If not sorry for posting this here.)
>
> So I wanted to start learning Python, and there is s much information
> online, which is a little overwhelming. I really learn best from doing,
> especially if it's something actually useful. I needed to create a bunch of
> empty folders, so I figured it was a good exercise to start learning Python.
> Now that it's done, I am wondering what kind of things I could do better.
> Here is the code:
>
> # WELCOME TO MY FIRST PYTHON SCRIPT!
> # FIRST OF ALL, IT ***WORKS***!!! YAY!
> # I AM A VBA AND JAVASCRIPT PROGRAMMER,
> # SO IT IS PROBABLY NOT VERY "PYTHONIC",
> # SO PLEASE FEEL FREE TO TEAR THE SCRIPT A NEW ONE
> # AFTER YOU ARE SHOCKED BY THIS BAD CODE,
> # ALL I ASK IS THAT IF YOU THINK SOMETHING IS BAD,
> # PLEASE POST AN EXAMPLE OF THE "CORRECT" WAY OF DOING IT
> # COMING FROM VBA, I KNOW A LITTLE OOP,
> # BUT NOT C++ C# JAVA STUFF LIKE "INTERFACES" AND "ABSTRACT BASE CLASSES"
> # SO IF YOU GET INTO SUCH TERMINOLOGY MY EYES MIGHT START TO GLAZE OVER
> # UNLESS YOU CARE TO EXPLAIN THAT TOO
>
Don't worry, Python doesn't have "interfaces" like Java (though it does
have multiple inheritance instead, which is more powerful), and it's not
necessary to learn about advanced things like abstract classes until you're
comfortable :)

>
>
> 
> # GLOBAL VALUES
> sForPythonVersion="3"
> #sFolderPathTemplate = "c:\\myscripts\\MP3 Disc "
> sFolderPathTemplate = "c:\\temp\\MP3 Disc "
>
It's possible in Python to use forward slashes in paths, even on Windows,
which would allow you to avoid the double slashes above (and can make your
code more easily ported to other OSes, which pretty universally use a '/'
in paths.
I would also suggest you use python's string formatting capabilities
instead here (see below where I use this FOLDER_TEMPLATE string):

FOLDER_TEMPLATE = 'C:/temp/MP3 Disk {count:03}'

iFromCount = 1
> iToCount = 250
> iCountWidth = 3
>
>
> 
> # SUPPORT FUNCTIONS
>
> #
> //
> def is_string(myVar): # is_string IS MORE READABLE THAN isinstance (PLAIN
> ENGLISH!)
> #PYTHON 3 IS NOT LIKING THIS: return ( isinstance(myVar, str) or
> isinstance(myVar, unicode) )
> #PYTHON 3 IS NOT LIKING THIS: return isinstance(myVar, basestr)
> return isinstance(myVar, str)
>

I know this one's been asked already but I think it deserves expanding on.
In general in Python it's recommended that you don't try too hard (if at
all) to check types of things. Think about what purpose this serves.
Pythonic programs follow what's known as "duck typing". i.e. if it quacks
like a duck then we can treat it like it's a duck.
This lets you write code which expects, for example something like a
string, or a dict or list, but isn't strictly bound to those types. That
allows other programmers to create their own classes, perhaps a subclass of
dict or list, or some unconnected class which just happens to be list-like
enough, and it can just work with your code.

Of course there are places where you do need to check the type of
something, but if you think you need to it's always worth really asking
yourself why you think that.
(I think this is particularly true when it comes to `str`. Most classes can
be represented one way or another as a string, so why not let people pass
you anything if you're going to read it as a string anyway? Refusing to
accept a non-string is more work for you and more work for them for little
benefit)

#
> //
> # THIS IS SOME SAMPLE FUNCTION FROM A BOOK I AM READING "PYTHON IN EASY
> STEPS"
> def strip_one_space(s):
> if s.endswith(" "): s = s[:-1]
> if s.startswith(" "): s = s[1:]
> return s
>
> #
> //
> def get_exact_python_version():
> import sys
>

Imports belong at the top of the file unless there's a good reason you
don't always want the module

Re: how to solve memory

2016-06-10 Thread meInvent bbird
this time i remove redundant which not add full column sum already has beeb 27*2

but it always has syntax error, indentation error, 

where is wrong?

def DFS(b, deep, maxx, sourceoperators, path):
 initlist = []
 if deep > 0:
  print("deep=", deep)
  for aa,bb in itertools.combinations(sourceoperators, 2):
   print(aa,bb)
   if deep == maxx:
 finalresult = []
 op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
 op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
 op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
 op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
 op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
 op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
 if sum(op1xy) == 54:
  path.append([(deep, aa, b, "xy")])
 else:
  initlist.append(op1xy)
 if sum(op1yz) == 54:
  path.append([(deep, aa, b, "yz")])
 else:
  initlist.append(op1yz)  
 if sum(op1xz) == 54:
  path.append([(deep, aa, b, "xz")])
 else:
  initlist.append(op1xz)
 if sum(op2xy) == 54:
  path.append([(deep, bb, b, "xy")])
 else:
  initlist.append(op2xy)
 if sum(op2yz) == 54:
  path.append([(deep, bb, b, "yz")])
 else:
  initlist.append(op2yz)
 if sum(op2xz) == 54:  
  path.append([(deep, bb, b, "xz")])
 else:
  initlist.append(op2xz)
   else:
 level = []
 for j in range(len(b)):
  op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
  op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
  if sum(op1xy) == 54:
   path.append([(deep, aa, b[j], "xy")])
  else:
   initlist.append(op1xy)
  if sum(op2xy) == 54:
   path.append([(deep, bb, b[j], "xy")])
  else:
   initlist.append(op2xy)
  level.append(op1xy)
  level.append(op2xy)
   print("initlist=")
   print(len(initlist)
 if deep == maxx:
   if deep > 0:
 b = []
 for aaa,bbb in itertools.combinations(initlist, 2): 
  b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
 print("deep=")
 print(deep)
 path2 = DFS(b, deep-1, maxx, sourceoperators, path)
 path.append(path2)
   else:
 print("")
   print("path=")
   print(len(path))
 else:
   if deep > 0:
 for aaa,bbb in itertools.combinations(initlist, 2):
  b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
 print("deep=")
 print(deep)
 path2 = DFS(b, deep-1, maxx, sourceoperators, path)
 path.append(path2)
   else:
 print("")
   print("path=")
   print(len(path))
 return path



On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote:
> On 2016-06-11 00:31, meInvent bbird wrote:
> > it is quite ridiculous,
> > this time i am sure that i put correct indentation
> > and add a else statement to make sure recursive call inside the
> > if statement , it still memory error,
> >
> > where is the memory error?
> >
> > is itertools.combinations so big for the list?
> >
> [snip]
> 
> How long is initlist?
> 
> When I ran the code, it said over 100_000 items.
> 
> How many combinations would there be?
> 
> Over 10_000_000_000.
> 
> That's how long the list 'b' would be.
> 
> You'll need 10s of gigabytes of memory and a lot of patience!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread meInvent bbird
i use a version having better indentation,

and then remove redundant which if sum column == 54 , do not add this column
into initlist

and add deep > 0 before recursive call
and print number of initlist is 118,XXX

but it is still running, where it run , and why run a very long time

def DFS(b, deep, maxx, sourceoperators, path): 
initlist = [] 
if deep > 0: 
print("deep=", deep) 
for aa,bb in itertools.combinations(sourceoperators, 2): 
print(aa,bb) 
if deep == maxx: 
finalresult = [] 
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54: 
path.append([(deep, aa, "xy")]) 
else:
initlist.append(op1xy)
if sum(op1yz) == 54: 
path.append([(deep, aa, "yz")]) 
else:
initlist.append(op1yz)
if sum(op1xz) == 54: 
path.append([(deep, aa, "xz")]) 
else:
initlist.append(op1xz)
if sum(op2xy) == 54: 
path.append([(deep, bb, "xy")]) 
else:
initlist.append(op2xy)
if sum(op2yz) == 54: 
path.append([(deep, bb, "yz")]) 
else:
initlist.append(op2yz)
if sum(op2xz) == 54: 
path.append([(deep, bb, "xz")]) 
else:
initlist.append(op2xz)
else: 
level = [] 
for j in range(len(b)): 
op1xy = [aa[b[j][i]] for i in range(len(b[j]))] 
op2xy = [bb[b[j][i]] for i in range(len(b[j]))] 
if sum(op1xy) == 54: 
path.append([(deep, aa, "xy")]) 
else:
initlist.append(op1xy)
if sum(op2xy) == 54: 
path.append([(deep, bb, "xy")]) 
else:
initlist.append(op2xy)
level.extend([op1xy, op2xy]) 
if deep == maxx: 
b = [] 
print("initlist=")
print(len(initlist))
for aaa,bbb in itertools.combinations(initlist, 2): 
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) 
if deep > 0:
path2 = DFS(b, deep-1, maxx, sourceoperators, path) 
path.append(path2)
return path 

path = [] 
mresult = DFS(b, 2, 2, mylist, path) 



On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote:
> On 2016-06-11 00:31, meInvent bbird wrote:
> > it is quite ridiculous,
> > this time i am sure that i put correct indentation
> > and add a else statement to make sure recursive call inside the
> > if statement , it still memory error,
> >
> > where is the memory error?
> >
> > is itertools.combinations so big for the list?
> >
> [snip]
> 
> How long is initlist?
> 
> When I ran the code, it said over 100_000 items.
> 
> How many combinations would there be?
> 
> Over 10_000_000_000.
> 
> That's how long the list 'b' would be.
> 
> You'll need 10s of gigabytes of memory and a lot of patience!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to solve memory

2016-06-10 Thread meInvent bbird
i use sage cloud to run, it killed my program

i checked total memory is large, how much memory it need, 8GB*10, 80GB?

top - 05:55:16 up 10:05,  1 user,  load average: 0.35, 0.63, 0.56
Tasks:  13 total,   1 running,  12 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.5 us,  0.4 sy,  0.0 ni, 99.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:  26755056 total,  6317696 used, 20437360 free,   611836 buffers
KiB Swap: 67108860 total,   468688 used, 66640172 free.  1223512 cached Mem

def DFS(b, deep, maxx, sourceoperators, path): 
initlist = [] 
if deep > 0: 
print("deep=", deep) 
for aa,bb in itertools.combinations(sourceoperators, 2): 
print(aa,bb) 
if deep == maxx: 
finalresult = [] 
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54: 
path.append([(deep, aa, b, "xy")]) 
else:
initlist.append(op1xy)
if sum(op1yz) == 54: 
path.append([(deep, aa, b, "yz")]) 
else:
initlist.append(op1yz)
if sum(op1xz) == 54: 
path.append([(deep, aa, b, "xz")]) 
else:
initlist.append(op1xz)
if sum(op2xy) == 54: 
path.append([(deep, bb, b, "xy")]) 
else:
initlist.append(op2xy)
if sum(op2yz) == 54: 
path.append([(deep, bb, b, "yz")]) 
else:
initlist.append(op2yz)
if sum(op2xz) == 54: 
path.append([(deep, bb, b, "xz")]) 
else:
initlist.append(op2xz)
else: 
level = [] 
for j in range(len(b)): 
op1xy = [aa[b[j][i]] for i in range(len(b[j]))] 
op2xy = [bb[b[j][i]] for i in range(len(b[j]))] 
if sum(op1xy) == 54: 
path.append([(deep, aa, b[j], "xy")]) 
else:
initlist.append(op1xy)
if sum(op2xy) == 54: 
path.append([(deep, bb, b[j], "xy")]) 
else:
initlist.append(op2xy)
level.extend([op1xy, op2xy]) 
if deep == maxx: 
b = [] 
print("initlist=")
print(len(initlist))
for aaa,bbb in itertools.combinations(initlist, 2): 
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) 
if deep > 0:
path2 = DFS(b, deep-1, maxx, sourceoperators, path) 
path.append(path2)
return path 

path = [] 
mresult = DFS(b, 2, 2, mylist, path) 




On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote:
> On 2016-06-11 00:31, meInvent bbird wrote:
> > it is quite ridiculous,
> > this time i am sure that i put correct indentation
> > and add a else statement to make sure recursive call inside the
> > if statement , it still memory error,
> >
> > where is the memory error?
> >
> > is itertools.combinations so big for the list?
> >
> [snip]
> 
> How long is initlist?
> 
> When I ran the code, it said over 100_000 items.
> 
> How many combinations would there be?
> 
> Over 10_000_000_000.
> 
> That's how long the list 'b' would be.
> 
> You'll need 10s of gigabytes of memory and a lot of patience!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: which library has map reduce and how to use it for this case

2016-06-10 Thread meInvent bbird
there are six operator, and a logic table initial in b variable 

aa[b[j][i]] 
[aa[b[i][0:1]+b[i][2:3] 

are just like vlookup to find output of each operator 
acting on first column and second column, second column and third column 
, first column and third column 

and searching a output columns which is result sum is 27*2 
and record the path if succeed, 
it record the path  and output any path which has result is 27*2 described 
before 
op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) 

there are two cases, first cases b are logic table 
later case are for six operators acting on the result column from previous 
result before recursive call 



def DFS(b, deep, maxx, sourceoperators, path): 
initlist = [] 
if deep > 0: 
print("deep=", deep) 
for aa,bb in itertools.combinations(sourceoperators, 2): 
print(aa,bb) 
if deep == maxx: 
finalresult = [] 
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] 
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] 
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] 
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] 
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] 
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] 
if sum(op1xy) == 54: 
path.append([(deep, aa, b, "xy")]) 
else: 
initlist.append(op1xy) 
if sum(op1yz) == 54: 
path.append([(deep, aa, b, "yz")]) 
else: 
initlist.append(op1yz) 
if sum(op1xz) == 54: 
path.append([(deep, aa, b, "xz")]) 
else: 
initlist.append(op1xz) 
if sum(op2xy) == 54: 
path.append([(deep, bb, b, "xy")]) 
else: 
initlist.append(op2xy) 
if sum(op2yz) == 54: 
path.append([(deep, bb, b, "yz")]) 
else: 
initlist.append(op2yz) 
if sum(op2xz) == 54: 
path.append([(deep, bb, b, "xz")]) 
else: 
initlist.append(op2xz) 
else: 
level = [] 
for j in range(len(b)): 
op1xy = [aa[b[j][i]] for i in range(len(b[j]))] 
op2xy = [bb[b[j][i]] for i in range(len(b[j]))] 
if sum(op1xy) == 54: 
path.append([(deep, aa, b[j], "xy")]) 
else: 
initlist.append(op1xy) 
if sum(op2xy) == 54: 
path.append([(deep, bb, b[j], "xy")]) 
else: 
initlist.append(op2xy) 
level.extend([op1xy, op2xy]) 
if deep == maxx: 
b = [] 
print("initlist=") 
print(len(initlist)) 
for aaa,bbb in itertools.combinations(initlist, 2): 
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) 
if deep > 0: 
path2 = DFS(b, deep-1, maxx, sourceoperators, path) 
path.append(path2) 
return path 

path = [] 
mresult = DFS(b, 2, 2, mylist, path) 


On Friday, June 10, 2016 at 10:04:09 PM UTC+8, Michael Selik wrote:
> On Thu, Jun 9, 2016, 9:11 PM Ho Yeung Lee  wrote:
> 
> > input are these six operators, output is finding full column of 27
> > elements add together is 54
> >
> > i got memory error when searching this,
> >
> > i have difficulty in understanding map reduce and transforming my program
> > into map reduce problem
> >
> 
> Why do you think you need map-reduce?
> 
> You'll need to explain the problem in more detail. Instead of talking about
> operators and columns, what is the actual, real-world problem?
> 
> >

-- 
https://mail.python.org/mailman/listinfo/python-list