Re: Correct type for a simple "bag of attributes" namespace object

2014-08-04 Thread Marko Rauhamaa
Ian Kelly :

> In my experience, 99% of the time when anonymous classes are used,
> they only contain one method. [...]
>
>> def A(x, y, z):
>> d = y * y + z * z
>>
>> class Anonymous:
>> def f(self):
>> return x - d
>>
>> return Anonymous()
>
> And it's the same thing here.  This isn't an interface.  It's a
> function, so just return a function and be done with it.

My one-time classes usually have more than one method:

def query(self, domain_name, record_type, listener, xid = None):
...
client = self
class Operation:
def cancel(self):
if key in client.opmap and client.opmap[key] is self:
del client.opmap[key]
def callback():
client.log('CANCELED')
listener(client.CANCELED, None)
client.mux.schedule(callback)
def notify(self, verdict, records):
client.log('verdict = {}'.format(verdict))
listener(verdict, records)
operation = Operation()
self.opmap[key] = operation
...


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


Re: CodeSkulptor

2014-08-04 Thread Terry Reedy

On 8/3/2014 10:07 PM, Seymore4Head wrote:


I run Win7


Just get 3.4.1 and install it on win 7. works great.


and like to keep it lean


Avoid 25 mb python install is more like keeping it anorexic ;-).

Python will not bite or squeeze your machine.

> so I also have an XP machine that I use for experimenting.

xp is off of MS support, so it is going off of Python support too.


--
Terry Jan Reedy

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


Re: Python Programing for the Absoulte Beginner

2014-08-04 Thread Mark Lawrence

On 04/08/2014 07:30, Bob Martin wrote:

in 726123 20140803 090919 Steven D'Aprano 
 wrote:

Steve Hayes wrote:


I've got too big an investment in books on Python 2, and there are no
books available on Python 3 (I don't regard downloadable PDFs or other
onlines stuff as "books").


I love Python 3, it's way better than Python 2, and there's less and less
reason to stick to Python 2 now. You really should learn Python 3, you
won't be sorry.

But, if you choose not to, there's nothing to be ashamed of. Python 2.7 has
got at least six years of life left in it, and when you're done with it,
migrating to Python 3 isn't like learning a new language. It's more like
the difference between American and British English.


With American English being 2.7 ??
Sorry, but someone had to ask  :-)



American English is Python 4 :)

The original English is Python 0.1.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re:how to call back a method ?

2014-08-04 Thread Dave Angel
elearn  Wrote in message:
> I want to call back a function which is the method of a class .
> 
>  def callback(self.do,x):
>  return(self.do(x))
> 
> That is what i want to write,when i input
> 
>  def callback(self.do,x):
> 
> error message:
> 
> 
>File "", line 1
>  def callback(self.do,x):
>   ^
>  SyntaxError: invalid syntax
> 
> 
> `do` is a method in my class ,how to write the code?
> 

Without some context,  answering the question is a shot in the dark. 

Is callback supposed to be a member function,  and is it always
 going to be calling do () on the same object that it was called
 on ? Then try

def callback (self, x):
return self.do (x)

But there are many other scenarios.  Show us some sample code
 where it's actually being called, and we might have a better
 chance of guessing what you need.

-- 
DaveA

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Terry Reedy

On 8/3/2014 6:52 PM, Wiktor wrote:


Hi,

as OO programming exercise, I'm trying to port to Python one of my favorite
game from early'90 (Atari 65XL/XE) - Kolony (here's video from original
version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's


This appears to be an actual text screen, no graphics.


video from modern rewritten (for Atari emulators) version: Kolony 2106
https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)).


This appears to be text boxes on a graphics screen.


OO Design is one thing, but I want to make it look as near as possible to
the original (those windows-like menus in console window).


Which original? the C64 or Atari.  The important characteristic of both 
is that both have multiple overlapping popup boxes. This means that 
either you or a widget framework much keep track of stacking order and 
how to restore what was hidden when a box goes away or is moved down in 
the stacking order. I would not be surprised if the Atari had at least a 
rudimentary widget framework.


> I tried to use

'standard' Unicode characters (I can see that most of my Windows monospaced
fonts have them) to draw frame around menu. Something like this:

  ┌──╖
  │ Construction ║
  │ Production   ║
  │ Research ║
  │ Exploration  ║
  ├··╢
  │ Next turn║
  ╘══╝

(I like the look of double lines on right and at the bottom)
But when I try to print those characters, I get an error:

| Traceback (most recent call last):
|   File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in 
| """
|   File "C:\Python34\lib\encodings\cp852.py", line 19, in encode
| return codecs.charmap_encode(input,self.errors,encoding_map)[0]
| UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' in 
position 1
| 6: character maps to 


You have two separate problems with running in the windows console.

1. The character issue. If you run a program to just print the above 
from an Idle editor, so that the output is printed to the Idle shell, 
there should be no problem.

>>> print('\u2556'*10)
╖╖
But characters are not your real issue.

2. The random access issue. The MS console in normal use is like a 
serial printer or terminal. Once a line is printed, it cannot be 
changed. I looked at the video and the program randomly accesses a 24 or 
25 line x 80 column screen, overprinting existing characters at will and 
reversing black on white versus white of black at will.  MSDOS screens 
recognized standard ANSI screen control codes once the ANSI.SYS driver 
was installed, which was fairly normal. But cmd.exe is actually a 
regression from MS-DOS in that it apparently will not allow this.  Or it 
is a hugh pain.


You could get a program that emulates a full-screen ANSI terminal, and 
learn to use ANSI control codes.  Or you could use a tkinter (tk) Text 
widget. People have written at least serial terminal emulators for Text, 
but I did not find a full-screen.


Using tkinter, I would try making each box a separate text box placed in 
a frameand let tkinter worry about displaying them correctly and 
detecting which box get a mouse click or  key.


--
Terry Jan Reedy


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


Python Classes

2014-08-04 Thread Shubham Tomar
Hi,

Python is the first programming language that I'm learning.
I'm confused by the idea of classes and intimidated by syntax defining
classes. I understand that you define classes to have re-usable methods and
procedures, but, don't functions serve the same purpose.
Can someone please explain the idea of classes and what *things *like
"__init__", "Object" and "self" mean ?

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


Re: CodeSkulptor

2014-08-04 Thread Chris “Kwpolska” Warrick
On Mon, Aug 4, 2014 at 4:08 AM, Seymore4Head
 wrote:
> I am just going to run 3.3 remotely.

Why and why?  3.3 is an old, outdated version — the most recent
version is v3.4.1.  By running 3.3 you are missing out on some new
features, and bugfixes.  You are better off running v3.4.1.

The other “why” refers to remotely running it on a Windows XP box.
This is a waste of time and resources. You are not going to save much
disk space, you can’t gain a thing, it’s not going to help: it will
just be a burden.  Especially because you’re running the remote box on
Windows (and an ancient version at that) — you are not running away
from all the issues of running in a Windows environment, and add
issues of running in a remote Windows environment.

Please stop, for your own good.

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Chris “Kwpolska” Warrick
On Mon, Aug 4, 2014 at 2:17 AM, Glenn Linderman  wrote:
> For this OP problem, it is mostly a matter of finding a fixed-width font
> that supports the box drawing characters and the Polish characters that are
> desired.  Lucida Console has a fair repertoire, and Consolas has a fair
> repertoire, in the fixed-width font arena. There may be others, documented
> on Polish language web sites that I wouldn't know about, and I don't know
> enough Polish to be sure those I mentioned suffice.

Not really.  We haven’t had to play the “custom fonts for our
language” game for quite some time.  Consolas and Lucida Console work
just fine for Polish (though Consolas sometimes hiccups on capital
characters in some environments).  The characters are:

ĄĆĘŁÓŃŚŹŻ
ąćęłóńśźż

Most fonts — especially the ones included with modern OSes — support
all 18 of them.

So, this is a non-issue.  The real issue is Windows being an idiot
when it comes to CLI, which is oh so surprising to everyone who had to
work with it — considering the choice of the outdated and quirky
cmd.exe interpreter, or PowerShell, which has ultra-verbose
human-unfriendly commands and works in the same cmd.exe window (there
is a thing named PowerShell ISE, which circumvents cmd.exe; I have no
idea whether all the Unicode issues apply to that, too)

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Classes

2014-08-04 Thread Terry Reedy

On 8/4/2014 4:40 AM, Shubham Tomar wrote:

Hi,

Python is the first programming language that I'm learning.
I'm confused by the idea of classes and intimidated by syntax defining
classes. I understand that you define classes to have re-usable methods
and procedures, but, don't functions serve the same purpose.
Can someone please explain the idea of classes and what /things /like
"__init__", "Object" and "self" mean ?


If you have not, read and work examples based on our fine tutorial. 
Classes are intentionally the last chapter about syntax.


If you have read up to and into chapter 9, and are stuck on a particular 
section, tell us.


--
Terry Jan Reedy

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


Re: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix?

2014-08-04 Thread Peter Tomcsanyi
"Kevin Walzer"  wrote in message 
news:lrmc0r$suj$1...@dont-email.me...
New releases of Tcl/Tk 8.5 and 8.6 are due out soon; right now they are 
undergoing final testing as betas/release candidates.


Thanks for the promising news.
Where should I look for the announcement that there is something new?
Is this the correct place?
http://sourceforge.net/projects/tcl/files/Tcl/

But will be the 8.5. branch updated, too?
I need 8.5 because CPython on Mac does not yet use 8.6...
I cannot see there 8.5.15.1 (at least that is how ActiveTcl is numbered) 
which solved some oter Mavericks issues in October 2013 (all 8.5. files are 
older than October 2013)...

So will be there a 8.5.16?

you can download the source tarballs for Tcl and Tk when they are 
released, untar them to a specific directory, cd to the directory, and run 
these commands:


make -C $insert_tcl_dirname_here/macosx
make -C $insert_tk_dirname_here/macosx

and then

sudo make -C $insert_tcl_dirname_here/macosx install
sudo make -C $insert_tk_dirname_here/macosx install


I have some command line skills and I have the command line developer tools 
installed (is that enough?), but I am not sure if I understand which 
directory's name is $insert_tcl_dirname_here (I suppose that the $ sign 
belongs to the name of the "variable", am I right?). Is it the directory 
where I unterd tcl (and which is under the directory where i cd-ed to)?


This will install the updated version of Tcl and Tk in 
/Library/Frameworks, and Python should pick them up.


Well, should...
I will try. But when I followed a similar procedure of installing the tkpng 
package then after "sudo make install" it seemed to be ok, but it was 
apparently added to other version of Tk than CPython is using...
Can somebody else confirm or disconfirm that the above procedure will 
install the new Tcl/Tk to that place where CPython (that is already 
installed) will pick it from? Or do I need to reinstall CPython after this? 
Or...?


Thanks

Peter Tomcsanyi


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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/3/2014 10:06 PM, Andrew Berg wrote:

On 2014.08.03 23:14, Glenn Linderman wrote:

Having read a bit about ConEmu, it seems that it is a "pretty face" built on
top of Windows Console, by screen scraping the real (but hidden) Windows
Console, and providing a number of interesting display features and modes. So
while it adds functionality to the Windows Console interface, it doesn't seem
like it is likely to fix bugs or resolve issues with code pages, font
selection, or Unicode character repertoires, which are the issues of this
thread and the bug I referenced earlier.

Can anyone with ConEmu installed refute this interpretation of its 
functionality?


If you run cmd in it, you will still need to use cp65001.
Or some workaround. The latest workaround in the issue I referenced does 
not require cp65001 either, for output, at least.



This is not necessary
for  (or applicable to) other applications (such as a Python interpreter) run
directly.
How does one "directly run" another application using ConEmu? That 
wasn't clear from what I found to read. It sounded like you run ConEmu, 
run one or more shells within it, and launch programs from those shells? 
And so it was also unclear if a program launched from some batch file 
would have to have the batch file launched from ConEmu, also. Or does 
ConEmu grab the execution association for batch files to make that work 
more automatically?



ConEmu can use any arbitrary font available on the system. As I have
said, I have been able to display Unicode output on it from an application
written in Python. No mojibake, no replacement characters, just the exact
characters one would expect.
I do not know the internals of ConEmu and how it interacts with conhost and
whatever else, but I have not found a need to since it has just worked for me.
So you may not know the internals of ConEmu, but I presume you know the 
internals of your Python applications. What encodings do you use for 
stdout for those applications? Do you set up the Python environment 
variables that specify some particular encoding, in the ConEmu 
environment (or does it)? Because the default Python IO encoding in 
Windows seems to be obtained from the configured code page.


Of course the biggest problem with much free and open source software is 
the documentation; I wasn't able to find specific answers to all my 
questions by reading the ConEmu wiki. Maybe some of it would be clearer 
if I installed it, and your "just worked" comment is certainly 
encouraging me to "just try it", but while trying it may help me figure 
it out, adding another package to separately install for my users gives 
more complexity. See if you can push me over the edge :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/4/2014 1:39 AM, Terry Reedy wrote:

On 8/3/2014 6:52 PM, Wiktor wrote:


Hi,

as OO programming exercise, I'm trying to port to Python one of my 
favorite

game from early'90 (Atari 65XL/XE) - Kolony (here's video from original
version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's


This appears to be an actual text screen, no graphics.


video from modern rewritten (for Atari emulators) version: Kolony 2106
https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)).


This appears to be text boxes on a graphics screen.

OO Design is one thing, but I want to make it look as near as 
possible to

the original (those windows-like menus in console window).


Which original? the C64 or Atari.  The important characteristic of 
both is that both have multiple overlapping popup boxes. This means 
that either you or a widget framework much keep track of stacking 
order and how to restore what was hidden when a box goes away or is 
moved down in the stacking order. I would not be surprised if the 
Atari had at least a rudimentary widget framework.


> I tried to use
'standard' Unicode characters (I can see that most of my Windows 
monospaced

fonts have them) to draw frame around menu. Something like this:

  ┌──╖
  │ Construction ║
  │ Production   ║
  │ Research ║
  │ Exploration  ║
  ├··╢
  │ Next turn║
  ╘══╝

(I like the look of double lines on right and at the bottom)
But when I try to print those characters, I get an error:

| Traceback (most recent call last):
|   File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in 
| """
|   File "C:\Python34\lib\encodings\cp852.py", line 19, in encode
| return codecs.charmap_encode(input,self.errors,encoding_map)[0]
| UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' 
in position 1

| 6: character maps to 


You have two separate problems with running in the windows console.

1. The character issue. If you run a program to just print the above 
from an Idle editor, so that the output is printed to the Idle shell, 
there should be no problem.

>>> print('\u2556'*10)
╖╖
But characters are not your real issue.

2. The random access issue. The MS console in normal use is like a 
serial printer or terminal. Once a line is printed, it cannot be 
changed. I looked at the video and the program randomly accesses a 24 
or 25 line x 80 column screen, overprinting existing characters at 
will and reversing black on white versus white of black at will.  
MSDOS screens recognized standard ANSI screen control codes once the 
ANSI.SYS driver was installed, which was fairly normal. But cmd.exe is 
actually a regression from MS-DOS in that it apparently will not allow 
this.  Or it is a hugh pain.


You could get a program that emulates a full-screen ANSI terminal, and 
learn to use ANSI control codes.  Or you could use a tkinter (tk) Text 
widget. People have written at least serial terminal emulators for 
Text, but I did not find a full-screen.


Using tkinter, I would try making each box a separate text box placed 
in a frameand let tkinter worry about displaying them correctly and 
detecting which box get a mouse click or  key.


I've never used the API from Python but random console access is 
documented at 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx
-- 
https://mail.python.org/mailman/listinfo/python-list


typo correction

2014-08-04 Thread Peter Tomcsanyi

Now I see that I wrote a quite unreadable typo: "unterd".
I meant "untared".

Peter Tomcsanyi


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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Wolfgang Maier

On 08/04/2014 11:53 AM, Glenn Linderman wrote:


I've never used the API from Python but random console access is
documented at
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx



Would using the API from Python involve doing the wrapping yourself or 
do you know about an existing package for the job ?


By the way (and off-topic), how would you do it on Linux?

Wolfgang

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Andrew Berg
On 2014.08.04 04:46, Glenn Linderman wrote:
> How does one "directly run" another application using ConEmu? That wasn't 
> clear
> from what I found to read. It sounded like you run ConEmu, run one or more
> shells within it, and launch programs from those shells? And so it was also
> unclear if a program launched from some batch file would have to have the 
> batch
> file launched from ConEmu, also. Or does ConEmu grab the execution association
> for batch files to make that work more automatically?
When you open a new console, the dialog will ask you to supply a path to an
executable you want to run. Any arbitrary CLI application will work. I don't
understand your question about batch files. If you mean to ask if ConEmu will
snatch a console opened by executing a batch file outside of ConEmu, yes, it
can do that. I highly suggest actually using the program and doing some tests
of your own to see how it works.

>> ConEmu can use any arbitrary font available on the system. As I have
>> said, I have been able to display Unicode output on it from an application
>> written in Python. No mojibake, no replacement characters, just the exact
>> characters one would expect.
>> I do not know the internals of ConEmu and how it interacts with conhost and
>> whatever else, but I have not found a need to since it has just worked for 
>> me.
> So you may not know the internals of ConEmu, but I presume you know the
> internals of your Python applications. What encodings do you use for stdout 
> for
> those applications? Do you set up the Python environment variables that 
> specify
> some particular encoding, in the ConEmu environment (or does it)? Because the
> default Python IO encoding in Windows seems to be obtained from the configured
> code page.
I use UTF-8. Open the Python interpreter directly in ConEmu and see what you 
get.

> Of course the biggest problem with much free and open source software is the
> documentation; I wasn't able to find specific answers to all my questions by
> reading the ConEmu wiki. Maybe some of it would be clearer if I installed it,
> and your "just worked" comment is certainly encouraging me to "just try it",
> but while trying it may help me figure it out, adding another package to
> separately install for my users gives more complexity. See if you can push me
> over the edge :)
It certainly would make things much clearer if you were to actually use the
program. Documentation tends to assume (and reasonably so, IMO) that you intend
to do some hands-on learning.
I can give no advice on deploying this to your users other than to say ConEmu
works well as a tool for command line power users on Windows, but does not
provide much ROI when it is simply an implementation detail for a single
program. If you want to save your users the hassle, I would definitely
recommend a graphical environment. If I had realized that you intended your
application to be widely deployed, I would have simply recommended that from
the start.

On a side note, you would have run into similar issues on *nix systems where a
significant amount of your users would be using the "C" locale and have no idea
what it is, why it causes them problems, or how to change it.
-- 
https://mail.python.org/mailman/listinfo/python-list


testfixtures 4.0.1 Released!

2014-08-04 Thread Chris Withers

Hi All,

I'm pleased to announce the release of testfixtures 4.0.1. This is a 
bugfix release that fixes the following two edge cases:


- Fix bugs when string compared equal and options to compare()
  were used.

- Fix bug when strictly comparing two nested structures containing
  identical objects.

The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


http://www.simplistix.co.uk/software/python/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
https://mail.python.org/mailman/listinfo/python-list


Davis putnam algorithm for satisfiability...

2014-08-04 Thread varun7rs
Hello friends,

I have some trouble understanding the davis putnam algorithm for 
satisfiability. I understood most of the code but I don't know where exactly 
backtracking is happening here. Your assistance would be very helpful to me.

import sys
import math
import copy


final_list = []

def sat(cnf):
while( len(cnf) > 1 ):
in_item = single_clause(cnf) #in_item: the first single_clause 
in cnf
if in_item != None:
del_sat(cnf, in_item)
else:
break

for i in cnf:
if len(i) == 0:
cnf.remove(i)
return

if len(cnf) == 1:
final_list.extend( [cnf[0][0]] ) # like a watchlist
for i in range(0, len(final_list)):
if final_list[i] > 0:
print "Not equivalent!"
sys.exit(0)
return final_list
  
deep_copy = copy.deepcopy(cnf)
list2 = cnf[0][0]
del_sat(deep_copy,list2)  # recursion to delete and then find another 
way and the proceed or delete more like a tree
sat(deep_copy)

del_sat(cnf,-list2)
sat(cnf)
return

def parseXml(file_1, file_2):
global cnf
readfile_1 = open(file_1, "r")
readfile_2 = open(file_2, "r")

sum_a = int(readfile_1.readline())
sum_b = int(readfile_2.readline())

inputs_1 = readfile_1.readline().split()
inputs_1.sort()
inputs_2 = readfile_2.readline().split()
inputs_2.sort()

outputs_1 = readfile_1.readline().split()
outputs_1.sort()
outputs_2 = readfile_2.readline().split()
outputs_2.sort()

inputmap_1 = {}
inputmap_2 = {}
outputmap_1 = []
outputmap_2 = []

while True:
line = readfile_1.readline().strip()
if not line:
break
net,item = line.split()
inputmap_1[item] = int(net)

while True:
line = readfile_2.readline().strip()
if not line:
break
net,item = line.split()
inputmap_2[item] = int(net)

#print inputmap_2

for line in readfile_1.readlines():
inp1 = line.split()
gate = inp1.pop(0)
mapping = map(int, inp1) 
outputmap_1.extend([(gate, mapping)])

print 'outputmap_1'
print outputmap_1

for line in readfile_2.readlines():
inp2 = line.split()
gate = inp2.pop(0)
mapping = map(int, inp2) 
outputmap_2.extend([(gate, mapping)])

return inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, 
outputmap_1, outputmap_2

def single_clause(cnf):
for i in cnf:
if len(i) == 1:
return i[0]
return None

def del_sat(cnf,in_item):
cnf2 = cnf[:]
for k in cnf2:
if k.count(in_item):
cnf.remove(k)
for i in cnf:
if i.count( -in_item):
i.remove(-in_item)


def cnf_out(miter):
miter_len = len(miter)
cnf = []
while (miter_len > 0):
x = miter.pop(0)
if ( x[0] == "and" ):
cnf.extend( [[x[1][0], -x[1][2]]] )
cnf.extend( [[x[1][1], -x[1][2]]] )
cnf.extend( [[-x[1][0], -x[1][1], x[1][2]]] )
elif ( x[0] == "or" ):
cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] )
cnf.extend( [[-x[1][0], x[1][2]]] )
cnf.extend( [[-x[1][1], x[1][2]]] )
elif ( x[0] == "xor" ): 
cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] )
cnf.extend( [[-x[1][0], -x[1][1], -x[1][2]]] )
cnf.extend( [[-x[1][0], x[1][1], x[1][2]]] )
cnf.extend( [[x[1][0], -x[1][1], x[1][2]]] )
else:
cnf.extend( [[x[1][0], x[1][1]]] )
cnf.extend( [[-x[1][0], -x[1][1]]] )
miter_len = miter_len - 1

return cnf

   

inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, 
outputmap_2 = parseXml(sys.argv[1], sys.argv[2])

incoming1=[]
incoming2=[]
outgoing1=[]
outgoing2=[]

for i in inputs_1:
incoming1.extend([inputmap_1[i]])

for j in inputs_2:
incoming2.extend([inputmap_2[j]])

for k in outputs_1:
outgoing1.extend([inputmap_1[k]])

for l in outputs_2:
outgoing2.extend([inputmap_2[l]])

gate_num = 0
for output in outputmap_1:
for j in output[1]:
if gate_num < j:
gate_num = j # gate_num: first line of netlist file. Total number 
of nets always need max no..

map2 = outputmap_2

num = len( map2 ) #No. of gates in netlist 2

for i in range(1, num + 1):

j = len( map2[i-1][1] ) # Total No. of inputs and outputs of a gate
for k in range(0, j):
if map2[i-1][1][k] not in incoming2:
total = 0
for l in incoming2:
if map2[i-1][1][k] > l:
total = total + 1 # Total no. of nets minus tota

Re: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix?

2014-08-04 Thread Kevin Walzer

On 8/4/14, 5:40 AM, Peter Tomcsanyi wrote:

"Kevin Walzer"  wrote in message
news:lrmc0r$suj$1...@dont-email.me...

New releases of Tcl/Tk 8.5 and 8.6 are due out soon; right now they
are undergoing final testing as betas/release candidates.


Thanks for the promising news.
Where should I look for the announcement that there is something new?
Is this the correct place?
http://sourceforge.net/projects/tcl/files/Tcl/


You can check comp.lang.tcl for an announcement.


But will be the 8.5. branch updated, too?
I need 8.5 because CPython on Mac does not yet use 8.6...
I cannot see there 8.5.15.1 (at least that is how ActiveTcl is numbered)
which solved some oter Mavericks issues in October 2013 (all 8.5. files
are older than October 2013)...
So will be there a 8.5.16?


8.5 and 8.6 will be updated.



you can download the source tarballs for Tcl and Tk when they are
released, untar them to a specific directory, cd to the directory, and
run these commands:

make -C $insert_tcl_dirname_here/macosx
make -C $insert_tk_dirname_here/macosx

and then

sudo make -C $insert_tcl_dirname_here/macosx install
sudo make -C $insert_tk_dirname_here/macosx install


I have some command line skills and I have the command line developer
tools installed (is that enough?), but I am not sure if I understand
which directory's name is $insert_tcl_dirname_here (I suppose that the $
sign belongs to the name of the "variable", am I right?). Is it the
directory where I unterd tcl (and which is under the directory where i
cd-ed to)?


$insert_tcl_dirname = something like tcl8.5.16. Just look at the numbering.

In other words, you want a directory with two subdirectories: tcl8.5.16 
and tk8.5.16 (since you are looking at 8.5).



This will install the updated version of Tcl and Tk in
/Library/Frameworks, and Python should pick them up.


Well, should...
I will try. But when I followed a similar procedure of installing the
tkpng package then after "sudo make install" it seemed to be ok, but it
was apparently added to other version of Tk than CPython is using...
Can somebody else confirm or disconfirm that the above procedure will
install the new Tcl/Tk to that place where CPython (that is already
installed) will pick it from? Or do I need to reinstall CPython after
this? Or...?


Where is your current installation of Python? The above instructions 
assume that you are using the standard Python from python.org. As I 
mentioned before, if you have installed things via a package manager 
(brew, Fink or MacPorts) you will have to follow their instructions.


--Kevin


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Will IronPython / WPF work on Mac OS X?

2014-08-04 Thread danwgrace
Hello,
I am thinking of using IronPython to build an Python application. Using WPF in 
Visual Studio to draw the GUI and create the XAML.  Can I then run this Python 
application on a Mac OS X (10.8)?
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CodeSkulptor

2014-08-04 Thread Peter Otten
Chris Angelico wrote:

> On Mon, Aug 4, 2014 at 1:03 PM, Steven D'Aprano
>  wrote:
>I think it's not a bug, but a restriction; since it's letting you run
>code on their server, and since Python sandboxing is a hard problem,
>CodeSkulptor cuts down the available modules. From the docs:
>
>http://www.codeskulptor.org/docs.html#tabs-Python
>>
>> Excluding datetime seems rather extreme to me.
> 
> By the look of their docs, they've actually gone the other way: it's
> not that they've excluded datetime, but that they've carefully vetted
> a specific set of modules (and maybe not all functionality in them)
> and that's all they support. In any case, I think that as soon as you
> hit an ImportError on the sandbox, you should go and download Python
> for your desktop and start working there.
> 
> (Idea, for anyone who runs a sandbox like that: Enumerate all packages
> and modules in the stdlib, and create a little stub for each of them.
> "import blahblah" will still produce ImportError, but "import
> datetime" could report back "This interpreter is working with a small
> subset of the Python standard library" rather than leaving us
> wondering if there was some weird copy/paste error in the import line.
> And yes, I did test for that.)

All nice and dandy, but the site seems to use a Python implementation 
entirely written in javascript:

http://www.skulpt.org/

It's not a sandbox on the server, the code runs in your browser.

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


creating log file with Python logging module

2014-08-04 Thread Arulnambi Nandagoban
Hello all,

 

I am using logging module for my application to log all debug information. I
configured it create a new log file every day with

"TimedRotatingFileHandler".  I display debug message in console as well.
But I didn't see creation of new file. Can someone help me to sort out this
problem. Following is config code:

 

import logging

from logging.handlers import TimedRotatingFileHandler

 

Ffilename = os.path.join(dir_path, 'Pyserverlog')

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s -
%(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG,
filename=Ffilename, filemode='w')

logger = logging.getLogger(__name__)

hdlr = TimedRotatingFileHandler(Ffilename, when='midnight')

logger.addHandler(hdlr)

# define a Handler which writes INFO messages or higher to the sys.stderr

console = logging.StreamHandler()

console.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s')

# tell the handler to use this format

console.setFormatter(formatter)

# add the handler to the root logger

logging.getLogger('').addHandler(console)

 

--

nambi

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


Re: Will IronPython / WPF work on Mac OS X?

2014-08-04 Thread Benjamin Kaplan
On Aug 4, 2014 6:23 AM,  wrote:
>
> Hello,
> I am thinking of using IronPython to build an Python application. Using
WPF in Visual Studio to draw the GUI and create the XAML.  Can I then run
this Python application on a Mac OS X (10.8)?
> Thanks.
> --

Nope. IronPython on Mac runs on top of Mono, so it has access to all the
libraries that Mono supports. That means there's no support for WPF except
for the subset that Silverlight supported (See
http://www.mono-project.com/wpf ).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Will IronPython / WPF work on Mac OS X?

2014-08-04 Thread Kevin Walzer

On 8/4/14, 8:17 AM, danwgr...@gmail.com wrote:

Hello,
I am thinking of using IronPython to build an Python application. Using WPF in 
Visual Studio to draw the GUI and create the XAML.  Can I then run this Python 
application on a Mac OS X (10.8)?
Thanks.



IronPython is a Windows-only product, I believe...doesn't it run on top 
of .NET? I don't see how it would work on the Mac unless it also worked 
with Mono.


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: creating log file with Python logging module

2014-08-04 Thread Peter Otten
Arulnambi Nandagoban wrote:

> I am using logging module for my application to log all debug information.
> I configured it create a new log file every day with
> 
> "TimedRotatingFileHandler".  I display debug message in console as well.
> But I didn't see creation of new file. 

Is the script running continuously? You won't see a rollover if you restart 
it. Working example (with shorter time interval):

$ cat rollover.py 
import logging
import logging.handlers
import time

logger = logging.getLogger()

handler = logging.handlers.TimedRotatingFileHandler("logfile", when='S')

logger.addHandler(handler)
logger.setLevel(logging.INFO)

for i in range(100):
logger.info("message #%s" % i)
time.sleep(.1)

$ ls
rollover.py
$ python rollover.py 
$ ls
logfile  logfile.2014-08-04_15-21-26
logfile.2014-08-04_15-21-21  logfile.2014-08-04_15-21-27
logfile.2014-08-04_15-21-22  logfile.2014-08-04_15-21-28
logfile.2014-08-04_15-21-23  logfile.2014-08-04_15-21-29
logfile.2014-08-04_15-21-24  logfile.2014-08-04_15-21-30
logfile.2014-08-04_15-21-25  rollover.py
$ cat logfile
message #93
message #94
message #95
message #96
message #97
message #98
message #99
$ 


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


Re: creating log file with Python logging module

2014-08-04 Thread Peter Otten
Peter Otten wrote:

> You won't see a rollover if you restart it.

Sorry, I tried it and the above statement is wrong.

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


Re: creating log file with Python logging module

2014-08-04 Thread Peter Otten
Peter Otten wrote:

> Peter Otten wrote:
> 
>> You won't see a rollover if you restart it.
> 
> Sorry, I tried it and the above statement is wrong.

[Arulnambi Nandagoban]

> logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s -
> %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG,
> filename=Ffilename, filemode='w')
> 
> logger = logging.getLogger(__name__)
> 
> hdlr = TimedRotatingFileHandler(Ffilename, when='midnight')

My alternative theory about what might be going wrong: you are using the 
same file in logging.basicConfig() and the TimedRotatingFileHandler.

But I cannot replicate the problem on my (linux) system.

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


Re: CodeSkulptor

2014-08-04 Thread Chris Angelico
On Mon, Aug 4, 2014 at 10:39 PM, Peter Otten <__pete...@web.de> wrote:
>> (Idea, for anyone who runs a sandbox like that: Enumerate all packages
>> and modules in the stdlib, and create a little stub for each of them.
>> "import blahblah" will still produce ImportError, but "import
>> datetime" could report back "This interpreter is working with a small
>> subset of the Python standard library" rather than leaving us
>> wondering if there was some weird copy/paste error in the import line.
>> And yes, I did test for that.)
>
> All nice and dandy, but the site seems to use a Python implementation
> entirely written in javascript:
>
> http://www.skulpt.org/
>
> It's not a sandbox on the server, the code runs in your browser.

It still has to be cut down, at least as regards modules implemented in C.

ImportError: No module named decimal on line 1

So, same applies. Adding a bunch of stubs like "decimal.py" to say
"This has a subset of the Python standard library and does not provide
the decimal module" would be useful.

As that one seems to be hosted on github, I'll drop a tracker issue
down there with the suggestion.

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


Re: Python Programing for the Absoulte Beginner

2014-08-04 Thread Chris Angelico
On Mon, Aug 4, 2014 at 3:30 PM, Bob Martin  wrote:
> With American English being 2.7 ??
> Sorry, but someone had to ask  :-)

A fairer comparison would be American English is IronPython, British
English is PyPy. Mostly compatible, and people call them both Python,
but not strictly identical.

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Wiktor
  Hi,
first, thank you all for responses. I decided to just use single line frame
around menu. Yes, those double+single line corners work fine in ConEmu, but
I don't want this Python script to be dependent on external program. Maybe
one day it will be worth of showing to others, and it's silly to tell them
'It is pure console based game/framework but works only in ConEmu'...


  Now, to Terry's post:

On 8/3/2014 6:52 PM, Wiktor wrote:

>> as OO programming exercise, I'm trying to port to Python one of my favorite
>> game from early'90 (Atari 65XL/XE) - Kolony (here's video from original
>> version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's
> 
> This appears to be an actual text screen, no graphics.
> 
>> video from modern rewritten (for Atari emulators) version: Kolony 2106
>> https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)).
> 
> This appears to be text boxes on a graphics screen.
> 
>> OO Design is one thing, but I want to make it look as near as possible to
>> the original (those windows-like menus in console window).
> 
> Which original? the C64 or Atari.  The important characteristic of both 
> is that both have multiple overlapping popup boxes. This means that 
> either you or a widget framework much keep track of stacking order and 
> how to restore what was hidden when a box goes away or is moved down in 
> the stacking order. I would not be surprised if the Atari had at least a 
> rudimentary widget framework.

  Yes, I'm aware that first link is to the text based game, and second to
graphic based game. I provided both links, because I couldn't find screen
cast from original Atari game (which is also text based, but IMO looks
better than C64's version), and this modern game is translated to English,
so is better for you to understand character of game.
  Yes, I'd like to make text game, that looks like window-based, with popup
boxes, inactive windows grayed out and all this stuff. And all this running
on standard console window (cmd.exe).

  I'm not starting from scratch. I'm using packages 'termcolor', 'colorama'
and 'colorconsole' - they provide functions to print text at desired
position on screen, and change color of foreground/background of this text.
With those packages I already developed some classes that allow me to
construct some simple menus for my console programs. Short demo of silly
program calculating degree of n-th root:
  http://youtu.be/V8ilLhHAT_k
  (I link to the video, because there's too much code lines to paste them
here. Also it's dependent upon those third party packages, and still
work-in-progress).

  So, I'm not worry about randomly access, colors, overprinting existing
characters. At this point I know how to do that. 
  I'm taking next step, so I tried to draw nice frame around menu (that's
why I posted yesterday).
  Next step would be to manage those widgets to draw one over another, to
keep track which one window opens which, and when the other window must be
closed and when only grayed out. At this point I still don't know how to do
this right, but I'm thinking about this very hard. :-) Probably one day
I'll ask it here, if I don't figure it out. :-)

Wiktor

-- 
Best regards, Wiktor Matuszewski
'py{}@wu{}em.pl'.format('wkm', 'ka')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: try/exception - error block

2014-08-04 Thread Grant Edwards
On 2014-08-03, Roy Smith  wrote:
> In article ,
>  Mark Lawrence  wrote:
>
>> How to go about this is at "Short, Self Contained, Correct (Compilable), 
>> Example" at http://sscce.org/
>
> It says there, "most readers will stop reading by 100 lines of code".  I 
> guess I have a short attention span relative to "most readers", because 
> my tl;dnr threshold is a lot shorter than that.

Mine too.  My limit is about one screen full -- how many lines that is
varies, but is rarely more than 40 lines.

> The other advantage to coming up with a minimal example is that often 
> the exercise of cutting your problem down to a minimal example is enough 
> to allow you to figure it out for yourself :-)

That is very true.

-- 
Grant Edwards   grant.b.edwardsYow! I am NOT a nut
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Wolfgang Maier

On 08/04/2014 05:00 PM, Wiktor wrote:

   Hi,
first, thank you all for responses. I decided to just use single line frame
around menu. Yes, those double+single line corners work fine in ConEmu, but
I don't want this Python script to be dependent on external program. Maybe
one day it will be worth of showing to others, and it's silly to tell them
'It is pure console based game/framework but works only in ConEmu'...


   Now, to Terry's post:


   I'm not starting from scratch. I'm using packages 'termcolor', 'colorama'
and 'colorconsole' - they provide functions to print text at desired
position on screen, and change color of foreground/background of this text.


Thanks for pointing out these packages! Since you say you're using all 
three of them: where do colorama and colorconsole differ. From a quick 
look, I can see that termcolor is a bit different, but colorama and 
colorconsole seem pretty similar in scope.


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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Wiktor
On Mon, 04 Aug 2014 17:43:41 +0200, Wolfgang Maier wrote:

>>I'm not starting from scratch. I'm using packages 'termcolor', 'colorama'
>> and 'colorconsole' - they provide functions to print text at desired
>> position on screen, and change color of foreground/background of this text.
> 
> Thanks for pointing out these packages! Since you say you're using all 
> three of them: where do colorama and colorconsole differ. From a quick 
> look, I can see that termcolor is a bit different, but colorama and 
> colorconsole seem pretty similar in scope.

  From colorama I just use one function - init(). Without this
initialization all those ansii escape characters (used by colorama itself,
but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't
make it work.
  All coloring work I make in termcolor.colored() function, because it
returns string, which I can work on (store and/or send it to print_at()
function later).
  And colorconsole is helpful with its screen.print_at() function [where
screen = colorconsole.terminal.get_terminal()].
  
  So, yes, it's matter of (probably bad) design, but now I need all three
packages. Maybe if I resign from storing my colored strings, and color them
just while sending them to printing function, I could get rid of colorama
and termcolor...
  Well, thanks for asking, because now, during writing this response, I see
that maybe redesign is worth of trying...

Wiktor

-- 
Best regards, Wiktor Matuszewski
'py{}@wu{}em.pl'.format('wkm', 'ka')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Chris Angelico
On Tue, Aug 5, 2014 at 2:48 AM, Wiktor  wrote:
>   From colorama I just use one function - init(). Without this
> initialization all those ansii escape characters (used by colorama itself,
> but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't
> make it work.

I dug into colorama's source code, and it seems that "just one
function" is a little dismissive :) When you call colorama's init(),
it replaces stdout with a wrapper that parses ANSI sequences and turns
them into API calls. So, yeah, without that anything that outputs ANSI
sequences isn't going to work.

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Wiktor
On Tue, 5 Aug 2014 03:06:41 +1000, Chris Angelico wrote:

> On Tue, Aug 5, 2014 at 2:48 AM, Wiktor  wrote:
>>   From colorama I just use one function - init(). Without this
>> initialization all those ansii escape characters (used by colorama itself,
>> but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't
>> make it work.
> 
> I dug into colorama's source code, and it seems that "just one
> function" is a little dismissive :) When you call colorama's init(),
> it replaces stdout with a wrapper that parses ANSI sequences and turns
> them into API calls. So, yeah, without that anything that outputs ANSI
> sequences isn't going to work.

  Maybe I didn't write it clear. :-) What I meant was, that even though I
don't use any other functions from colorama (I color all the strings with
termcolor) - I still have to use init() function from colorama. 
  termcolor doesn't want to work alone, even though its described as OS
independent. I guess it works fine on Linux terminal without init()
function from colorama. In cmd.exe I need colorama just for this.

-- 
Best regards, Wiktor Matuszewski
'py{}@wu{}em.pl'.format('wkm', 'ka')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/4/2014 3:33 AM, Andrew Berg wrote:

If you want to save your users the hassle, I would definitely
recommend a graphical environment. If I had realized that you intended your
application to be widely deployed, I would have simply recommended that from
the start.


Graphical environments are good for some things, command line 
environments are good for other things.


Unicode capability is beneficial in both.

Many of the software tools I create and distribute are command line 
utilities, for people that use command lines anyway.  The problems arise 
when they are multilingual, and need to use diverse character repertoires.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/4/2014 3:24 AM, Wolfgang Maier wrote:

On 08/04/2014 11:53 AM, Glenn Linderman wrote:


I've never used the API from Python but random console access is
documented at
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx 





Would using the API from Python involve doing the wrapping yourself or 
do you know about an existing package for the job ?


I haven't used the API from Python. I haven't checked PyWin32 to see if 
it already wraps that API like it wraps so many other APIs. I haven't 
Googled using "python" and "WriteConsoleOutput" to see if other packages 
may exist to do the job. But these are the things that I would do if I 
had a need to write a program like yours, since I know that the console 
does, in fact, support random access.




By the way (and off-topic), how would you do it on Linux?


Off topic? It is still about doing it using Python, no?

I believe that most Unix terminal emulators, which are used for running 
shells and command lines, support cursor controls, and I believe most of 
them have a mode that emulates the DEC VT-52 terminal, one of which I 
had physical access to at the "computer lab" at the university I 
attended so many years ago. The VT-52 defined escape sequences to move 
the cursor around on the screen, providing random access. Text-based, 
screen-oriented programs such as emacs leveraged such capabilities quite 
effectively.


There may be something better today, I haven't used Unix for a dozen 
years now, and the usage at that time was database development not 
text-based graphics. I've used Linux only on my web host, and a little 
experimentation on a local machine I installed it on here, until the 
machine died, and I didn't do any text-based graphics in either of those 
circumstances either.  So probably college was the last time I used 
text-based graphics, but that was using RSTS and DECsystem 20 (forget 
the name of the OS for that machine) on VT-52 terminals. But I've noted 
with amusement that the VT-52 (and later enhanced models) are still 
supported by Unix/Linux terminal emulators and X system.


Unix abstracts that cursor motion using "curses" and I believe there are 
curses implementations for Windows as well, but I've not attempted to 
use curses from Python on either Unix or Windows.





Wolfgang



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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Terry Reedy

On 8/4/2014 11:00 AM, Wiktor wrote:


   Yes, I'd like to make text game, that looks like window-based, with popup
boxes, inactive windows grayed out and all this stuff. And all this running
on standard console window (cmd.exe).


Your problem doing this is that cmd.exe is not a standard since 30 years 
ago full-screen console window, , but is intentionally crippled to stop 
people from doing what you are trying to do. Some as MS would like to 
delete it altogether.



   I'm not starting from scratch. I'm using packages 'termcolor', 'colorama'
and 'colorconsole' -


All on pypi.python.org, I see.

> they provide functions to print text at desired

position on screen, and change color of foreground/background of this text.
With those packages I already developed some classes that allow me to
construct some simple menus for my console programs. Short demo of silly
program calculating degree of n-th root:
   http://youtu.be/V8ilLhHAT_k


I am impressed with what the authors of those packages managed to do.


   I'm taking next step, so I tried to draw nice frame around menu (that's
why I posted yesterday).


Is there no working codepage with ascii text and the line chars? I 
suppose I am not surprised if not.



   Next step would be to manage those widgets to draw one over another, to
keep track which one window opens which, and when the other window must be
closed and when only grayed out. At this point I still don't know how to do
this right, but I'm thinking about this very hard. :-) Probably one day
I'll ask it here, if I don't figure it out. :-)


You may have to settle for using different background colors to 
delineate different boxes.


--
Terry Jan Reedy

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Terry Reedy

On 8/4/2014 6:24 AM, Wolfgang Maier wrote:

On 08/04/2014 11:53 AM, Glenn Linderman wrote:


I've never used the API from Python but random console access is
documented at
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx




Would using the API from Python involve doing the wrapping yourself or
do you know about an existing package for the job ?


The packages Wiktor is using, 'termcolor', 'colorama'
and 'colorconsole' - (all on PyPI), must be using WriteConsoleOutput.

--
Terry Jan Reedy

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Grant Edwards
On 2014-08-04, Glenn Linderman  wrote:

> I believe that most Unix terminal emulators, which are used for running 
> shells and command lines, support cursor controls, and I believe most of 
> them have a mode that emulates the DEC VT-52 terminal,

I'm not aware of any that are in common use, but there may be some
niche VT52 emulators somewhere I don't know about.  All the widely
used terminal emulators are some flavor of ANSI (for you DEC guys,
VT100 and later) rather than VT52.

-- 
Grant Edwards   grant.b.edwardsYow! All of life is a blur
  at   of Republicans and meat!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tcl/Tk alpha channel bug on OSX Mavericks is fixeded, but how/when can I use the fix?

2014-08-04 Thread Peter Tomcsanyi

Many thanks for all the answers.

"Kevin Walzer"  wrote in message 
news:lrntjm$bma$1...@dont-email.me...
Where is your current installation of Python? The above instructions 
assume that you are using the standard Python from python.org. As I 
mentioned before, if you have installed things via a package manager 
(brew, Fink or MacPorts) you will have to follow their instructions.


I use the standard Python.org installation, so I assume that it is "where it 
should be" (I launch IDLE from Launcher or I open .py files by righclicking 
them and choosing "Open in IDLE"). But it does not contain Tcl/Tk, it uses 
"somehow" the version of Tcl/Tk that is installed "somewhere".

Actually the page:
https://www.python.org/download/mac/tcltk
says that it is linked dynamically and it looks at first into 
/Library/Frameworks.
So maybe for now I have enough information and I will try your suggestions 
when the new Tcl/Tk will be available and ask more questions only if it 
would not work.


Thanks

Peter Tomcsanyi


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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Terry Reedy

On 8/4/2014 1:22 PM, Wiktor wrote:

On Tue, 5 Aug 2014 03:06:41 +1000, Chris Angelico wrote:


On Tue, Aug 5, 2014 at 2:48 AM, Wiktor  wrote:

   From colorama I just use one function - init(). Without this
initialization all those ansii escape characters (used by colorama itself,
but also by termcolor.colored()) don't work in cmd.exe. At least I couldn't
make it work.


I dug into colorama's source code, and it seems that "just one
function" is a little dismissive :) When you call colorama's init(),
it replaces stdout with a wrapper that parses ANSI sequences and turns
them into API calls. So, yeah, without that anything that outputs ANSI
sequences isn't going to work.


   Maybe I didn't write it clear. :-) What I meant was, that even though I
don't use any other functions from colorama (I color all the strings with
termcolor) - I still have to use init() function from colorama.
   termcolor doesn't want to work alone, even though its described as OS
independent.


Termcolor says "ANSI Color formatting for output in terminal."
https://pypi.python.org/pypi/termcolor/1.1.0

It is OS-independent but depends on support of standard ANSI screen 
command codes. Microsoft removed that support from cmd.exe. If you look 
at the Terminal properties box on the page above, the only thing 
termcolor can do on Windows, by itself, is reversed text.  Colorama.init 
adds back (at least some of) the ANSI to API translation omitted from 
cmd.exe.



I guess it works fine on Linux terminal without init()


Because linux terminals translate ANSI to whatever api calls are needed.


function from colorama. In cmd.exe I need colorama just for this.


--
Terry Jan Reedy

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Chris Angelico
On Tue, Aug 5, 2014 at 5:17 AM, Terry Reedy  wrote:
> Is there no working codepage with ascii text and the line chars? I suppose I
> am not surprised if not.

That would be codepage 437. I grew up with that on DOS, as the one and
only 256-character set, and then when we moved to OS/2 and actual
codepages, we always configured 437,850 (that is, 437 as primary, with
850 as a secondary if we wanted it). Trouble is, it doesn't have
non-basic letters, and the OP needs to write Polish text. I'd be not
at all surprised if there are characters he needs that aren't in
CP437.

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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Wiktor
On Mon, 04 Aug 2014 15:17:04 -0400, Terry Reedy wrote:

>>I'm taking next step, so I tried to draw nice frame around menu (that's
>> why I posted yesterday).
> 
> Is there no working codepage with ascii text and the line chars? I 
> suppose I am not surprised if not.

  With single line (└┘┌┐─│├┤┬┴┼) and double line (╣║╗╝╚╔╩╦╠═╬) - many
codepages, CP852 for sure.

  With corners/crosses where single and double lines meet (╖╘╡╢╕╜╛╞╟
╧╨╤╥╙╘╒╓╫╪) - I know only one: CP437.
  
  But I can't have both - Polish letters and all those line chars, so I
can't do this fancy frame from first post with Polish strings inside. There
will be simpler version instead.

-- 
Best regards, Wiktor Matuszewski
'py{}@wu{}em.pl'.format('wkm', 'ka')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Christian Gollwitzer

Am 04.08.14 01:08, schrieb Chris Angelico:

On Mon, Aug 4, 2014 at 8:52 AM, Wiktor  wrote:

I have to ask - is there a way to make that original concept work? I know,
that CP437 has symbols "╖", "╢" and "╘", but does not have polish letters -
and I need to display them too.


Yeah, that's exactly the problem with codepages :)

The best way to do it is to use the Unicode codepage,


Agreed.


but cmd.exe just
plain has issues.


It's not cmd.exe, it's the terminal that is shit. You can't even 
interactively resize the width in the standard terminal.



There are underlying Windows APIs for displaying
text that have problems with astral characters (I think that's what it
is), so ultimately, you're largely stuck.

One option would be to render the whole thing graphically, abandoning
cmd.exe altogether. That would be how a lot of telnet and SSH clients
will do the work. Get a proper Unicode-supporting toolkit (Tkinter has
issues with astral characters too, AIUI), and yes, you'll have to do a
lot of work yourself.


Tkinter only supports the BMP currently. But neither Polish nor box 
drawing does require more: All those box drawing symbols are in the BMP:


http://www.unicode.org/charts/PDF/U2500.pdf

So you could use a Tkinter text widget and put your data there - or even 
a simple label would do.


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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread giacomo boffi
Wiktor  writes:

>   I'm not starting from scratch. I'm using packages 'termcolor', 'colorama'
> and 'colorconsole'

the 'urwid' package could be useful for similar projects but 
requires Linux, OSX, Cygwin or other unix-like OS so I guess
it's of no use for you...

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


Re: Python Classes

2014-08-04 Thread John Gordon
In  Shubham Tomar 
 writes:

> classes. I understand that you define classes to have re-usable methods and
> procedures, but, don't functions serve the same purpose.
> Can someone please explain the idea of classes 

If a function simply accepts some data, does some calculations on that
data and then returns a value, then you don't need classes at all.  An
example of this might be the square-root function: pass it any number
and it calculates and returns the square root with no other data needed.

But classes do come in handy for other sorts of uses.  One classic example
is employees at a company.  Each employee has a name, ID number, salary,
date of hire, home address, etc.

You can create an Employee class to store those data items along with
methods to manipulate those data items in interesting ways.  The data
items are specific to each separate Employee object, and the methods are
shared among the entire class.

> Can someone please explain what *things *like "__init__", "Object"
> and "self" mean ?

__init__() is the initializer method, which is called as one step of
creating a class object.

Object is the lowest-level class.  All other classes inherit from Object.

Within a class, self is a reference to the current class instance.

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.


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


Re: Davis putnam algorithm for satisfiability...

2014-08-04 Thread Cameron Simpson

On 04Aug2014 04:51, varun...@gmail.com  wrote:
I have some trouble understanding the davis putnam algorithm for 
satisfiability. I understood most of the code but I don't know where exactly 
backtracking is happening here. Your assistance would be very helpful to me.


At a glance, in the bottom part of the sat(cnf) function.

The top part of the function performs some simple operations and possibly 
returns.


The bottom part, executed if the earlier code does not return, copies cnf to 
deep_copy, removes list2 from deep_copy and -list2 from cnf, and runs the sat() 
function on each.


To my mind, that constitutes a backtrack: back up, and try a different way (on 
the modified cnf and deep_copy).


Cheers,
Cameron Simpson 


import sys
import math
import copy


final_list = []

def sat(cnf):
while( len(cnf) > 1 ):
in_item = single_clause(cnf) #in_item: the first single_clause 
in cnf
if in_item != None:
del_sat(cnf, in_item)
else:
break

   for i in cnf:
   if len(i) == 0:
   cnf.remove(i)
   return

   if len(cnf) == 1:
   final_list.extend( [cnf[0][0]] ) # like a watchlist
   for i in range(0, len(final_list)):
   if final_list[i] > 0:
   print "Not equivalent!"
   sys.exit(0)
   return final_list

   deep_copy = copy.deepcopy(cnf)
   list2 = cnf[0][0]
   del_sat(deep_copy,list2)  # recursion to delete and then find another 
way and the proceed or delete more like a tree
   sat(deep_copy)

   del_sat(cnf,-list2)
   sat(cnf)
   return

def parseXml(file_1, file_2):
   global cnf
   readfile_1 = open(file_1, "r")
   readfile_2 = open(file_2, "r")

   sum_a = int(readfile_1.readline())
   sum_b = int(readfile_2.readline())

   inputs_1 = readfile_1.readline().split()
   inputs_1.sort()
   inputs_2 = readfile_2.readline().split()
   inputs_2.sort()

   outputs_1 = readfile_1.readline().split()
   outputs_1.sort()
   outputs_2 = readfile_2.readline().split()
   outputs_2.sort()

   inputmap_1 = {}
   inputmap_2 = {}
   outputmap_1 = []
   outputmap_2 = []

   while True:
   line = readfile_1.readline().strip()
   if not line:
   break
   net,item = line.split()
   inputmap_1[item] = int(net)

   while True:
   line = readfile_2.readline().strip()
   if not line:
   break
   net,item = line.split()
   inputmap_2[item] = int(net)

   #print inputmap_2

   for line in readfile_1.readlines():
   inp1 = line.split()
   gate = inp1.pop(0)
   mapping = map(int, inp1)
   outputmap_1.extend([(gate, mapping)])

   print 'outputmap_1'
   print outputmap_1

   for line in readfile_2.readlines():
   inp2 = line.split()
   gate = inp2.pop(0)
   mapping = map(int, inp2)
   outputmap_2.extend([(gate, mapping)])

   return inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, 
outputmap_1, outputmap_2

def single_clause(cnf):
for i in cnf:
if len(i) == 1:
return i[0]
return None

def del_sat(cnf,in_item):
cnf2 = cnf[:]
for k in cnf2:
if k.count(in_item):
cnf.remove(k)
for i in cnf:
if i.count( -in_item):
i.remove(-in_item)


def cnf_out(miter):
   miter_len = len(miter)
   cnf = []
   while (miter_len > 0):
   x = miter.pop(0)
   if ( x[0] == "and" ):
   cnf.extend( [[x[1][0], -x[1][2]]] )
   cnf.extend( [[x[1][1], -x[1][2]]] )
   cnf.extend( [[-x[1][0], -x[1][1], x[1][2]]] )
   elif ( x[0] == "or" ):
   cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] )
   cnf.extend( [[-x[1][0], x[1][2]]] )
   cnf.extend( [[-x[1][1], x[1][2]]] )
   elif ( x[0] == "xor" ):
   cnf.extend( [[x[1][0], x[1][1], -x[1][2]]] )
   cnf.extend( [[-x[1][0], -x[1][1], -x[1][2]]] )
   cnf.extend( [[-x[1][0], x[1][1], x[1][2]]] )
   cnf.extend( [[x[1][0], -x[1][1], x[1][2]]] )
   else:
   cnf.extend( [[x[1][0], x[1][1]]] )
   cnf.extend( [[-x[1][0], -x[1][1]]] )
   miter_len = miter_len - 1

   return cnf



inputs_1, inputs_2, outputs_1, outputs_2, inputmap_1, inputmap_2, outputmap_1, 
outputmap_2 = parseXml(sys.argv[1], sys.argv[2])

incoming1=[]
incoming2=[]
outgoing1=[]
outgoing2=[]

for i in inputs_1:
   incoming1.extend([inputmap_1[i]])

for j in inputs_2:
   incoming2.extend([inputmap_2[j]])

for k in outputs_1:
   outgoing1.extend([inputmap_1[k]])

for l in outputs_2:
   outgoing2.extend([inputmap_2[l]])

gate_num = 0
for output in outputmap_1:
   for j in output[1]:
   if gate_num < j:
   gate_num = j # gate_num: first line of netlist file. Total number of 
nets always need max no..

map2 = outputmap_2

num = len( map2 ) #No. of gates in 

Re: Python Classes

2014-08-04 Thread Terry Reedy

On 8/4/2014 6:44 PM, John Gordon wrote:


__init__() is the initializer method, which is called as one step of
creating a class object.


In fact, it is the last step and usually is the main step for 
user-defined classes, and the only step one need be concerned with.



Object is the lowest-level class.  All other classes inherit from Object.


The spelling is 'object', with lowercase 'o'.  'Object' would have been 
less confusing, but all other builtin classes, are lowercase (some 
because they started as functions in Python 1.0 or soon thereafter).



Within a class, self is a reference to the current class instance.


This is only true within a method definition and only when 'self' is 
given as the first parameter name.


class C:
  def meth_standard(self, other): pass
  # 'self' is an object of class C, 'other' to any other object.
  # Using 'self' is not required, but is the standard convention.

  def meth_brief(s, o): pass
  # 's' refers to an instance of class C, 'o' to any other object
  # ok for quick interactive use that one keeps private

  def meth_obnoxious(other, self): pass
  # 'other' is an instance of C, 'self' is any object
  # Anyone who publishes such code, except to illustrate trollish
  # behavior, is fishing for heated responses.

--
Terry Jan Reedy

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


Re: try/exception - error block

2014-08-04 Thread Cameron Simpson

On 03Aug2014 10:39, Roy Smith  wrote:

In article ,
bruce  wrote:

I'm posting the test code I'm using. Pointers/comments would be
helpful/useful.


It would be really helpful if you could post a minimal code example
which demonstrates the problem you're having.  Leave out everything
(including the commented-out code) which isn't necessary to demonstrate
the behavior.


Just FYI, Bruce posted an earlier version of this question to 
us...@lists.fedoraproject.org in late July, wondering why he didn't get a good 
error message in the abrt logs.


I asked then where the stderr of his python subprocess went, but never heard 
back.


Cheers,
Cameron Simpson 

Reality is that which refuses to go away when I stop believing in it.
- Phillip K. Dick
--
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Akira Li
Wiktor  writes:

> On Mon, 04 Aug 2014 15:17:04 -0400, Terry Reedy wrote:
>
>>>I'm taking next step, so I tried to draw nice frame around menu (that's
>>> why I posted yesterday).
>>
>> Is there no working codepage with ascii text and the line chars? I
>> suppose I am not surprised if not.
>
>   With single line (└┘┌┐─│├┤┬┴┼) and double line (╣║╗╝╚╔╩╦╠═╬) - many
> codepages, CP852 for sure.
>
>   With corners/crosses where single and double lines meet (╖╘╡╢╕╜╛╞╟
> ╧╨╤╥╙╘╒╓╫╪) - I know only one: CP437.
>
>   But I can't have both - Polish letters and all those line chars, so I
> can't do this fancy frame from first post with Polish strings inside. There
> will be simpler version instead.

Unicode has line drawing characters [1]. win_unicode_console [2] allows
to print Unicode in cmd.exe. win_unicode_console and colorama will
probably conflict. You could look at the source to see how hard to
combine both functionalities.

[1] http://en.wikipedia.org/wiki/Box-drawing_character
[2] https://pypi.python.org/pypi/win_unicode_console

btw, blessings [3] provides an easy-to-use interface if you need to add
colors and move text in a terminal. It claims that it also supports
colors on Windows if used with colorama.

[3] https://pypi.python.org/pypi/blessings/


--
Akira

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


TypeError: 'bytes' object is not callable error while trying to converting to bytes.

2014-08-04 Thread Satish ML
Hi,


>>>import struct
>>>file = open('data.bin', 'rb')
>>>bytes = file.read()
>>> records = [bytes([char] * 8) for char in b'spam']
Traceback (most recent call last):
  File "", line 1, in 
records = [bytes([char] * 8) for char in b'spam']
  File "", line 1, in 
records = [bytes([char] * 8) for char in b'spam']
TypeError: 'bytes' object is not callable


If we code something like given below, it works.

>>> records = [([char] * 8) for char in b'spam']
>>> records
[[115, 115, 115, 115, 115, 115, 115, 115], [112, 112, 112, 112, 112, 112, 112, 
112], [97, 97, 97, 97, 97, 97, 97, 97], [109, 109, 109, 109, 109, 109, 109, 
109]]

Could you kindly help me resolve this problem of converting to bytes?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes.

2014-08-04 Thread Ben Finney
Satish ML  writes:

> >>>import struct
> >>>file = open('data.bin', 'rb')

Here you re-bind the name ‘file’ to the return value from that call.

> >>>bytes = file.read()

Here you re-bind the name ‘bytes’ to the return value from that call.

> >>> records = [bytes([char] * 8) for char in b'spam']

Here you attempt to call ‘bytes’, which (as the error says) is not
callable.

You should choose names which are not already bound::

in_file = open('data.bin', 'rb')
in_file_content = in_file.read()
records = [bytes([char] * 8) for char in in_file_content]

When choosing names, try to communicate the *purpose* of the value, its
semantic meaning. The type should be of secondary importance, and almost
always should not be part of the name.

-- 
 \“Institutions will try to preserve the problem to which they |
  `\ are the solution.” —Clay Shirky, 2012 |
_o__)  |
Ben Finney

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


Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes.

2014-08-04 Thread Chris Angelico
On Tue, Aug 5, 2014 at 3:47 PM, Satish ML  wrote:
bytes = file.read()

You've just shadowed the built-in type 'bytes' with your own 'bytes'.
Pick a different name for this, and you'll be fine. 'data' would work.

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


Re: Python Classes

2014-08-04 Thread dieter
Shubham Tomar  writes:
> Python is the first programming language that I'm learning.
> I'm confused by the idea of classes and intimidated by syntax defining
> classes. I understand that you define classes to have re-usable methods and
> procedures, but, don't functions serve the same purpose.

As often, you may have building blocks at various levels.
Thinks of a house - you can build it from individual stones or
have large prefabricated parts.
Something similar is true with functions and classes.

A function is a building block at some level.
However, often, you deal not with individual unrelated functions but
with a set of related functions designed together.

In simple cases, those functions can be collected in a library or
a module (Python's "math" module is such an example - containing
many interesting "mathematical" functions).

In other (slightly more complicated) cases, the relation between
the functions is that they all work on the same "object".

Those "object"s can be almost anything. An example would be
a "window" on your desktop screen. It can be closed, resized, moved around, ...
Or a "geometric object" in a drawing application - with operations
"delete", "move", "resized", "extend", ...

In those cases, it can be helpful to view the object (its data)
and the functions operating on it (such as "move", "resize", ...)
as a higher level building block -- and this leads to classes.

A "class" (in Python) is a collection of related functions (called
"method"s) and potentially data definitions (this part is quite
weak for Python classes; unlike in other languages, the data part
of a class is not stated explicitely at the top class level, but
usually indirectly in the so called constructor ("__init__")).
Most of these functions operate on the same data. Data and functions
together are called an "object" and the "class" defines a set
of objects of some common kind: "window"s, "date"s, "server"s,
"geometric object"s ...


This higher level building block can facilitate the construction
of many applications.

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