boB Stepp | 26 Nov 17:48 2014
Picon

How to change the color of the title bar of the root window in Tkinter?

Python 2.4.4
Solaris 10

--

-- 
boB
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

boB Stepp | 26 Nov 17:46 2014
Picon

Is there an easy way to center the root window (Tkinter) within the display?

Python 2.4.4
Solaris 10

I can accomplish this by getting the screen height and width and
calculating pixel coordinates. But so far I have not found something
equivalent to anchor = 'CENTER' that can be applied to the root
window. Does such an easy attribute, method, or whatever exist in
Tkinter?

--

-- 
boB
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Mohamed Ben Mosbah | 26 Nov 13:57 2014
Picon

Memory management in Python

Hi I'm new to Python and I would like to know how he deals with memory space.
I thought I had understood but I made a test and the results were uncoherenent with my understanding, here is the thing:

>>> a=[1,2]
>>> l=[a,a]
>>> id(a); id(l[0]); id(l[1]);
61659528
61659528
61659528
>>> #All Have the same ID
>>> l[0]=[0,0]
>>> l
[[0, 0], [1, 2]]
>>> #Why didn't l[1] change as well?
>>> id(a); id(l[0]); id(l[1]);
61659528
61390280
61659528
>>> #How come id(l[0]) changed?
>>> a = [4,4]
>>> l
[[0, 0], [1, 2]]
>>> #Why didn't l[1] change? l[1] and a were occupying the same memory adress!


Thank you for answering :)
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
moemedi baboile | 26 Nov 10:29 2014

no longer need this tutor

I want thank you guys for helping me out with python programming.I achieved the best out of this and now am on the next stage of programming, I now don't need this tutor any more...thank you once again..... 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Clayton Kirkwood | 25 Nov 05:28 2014
Picon

ran into a problem with pip install

I was trying to pip install beautifulsoup and ran into the following error. It appears to be 2.x because of the print. I am installing to a python 3.4.2. What do I need to do? I tried to log a bug report to PyPI Bug Reports but that apparently isn’t the cool thing to do. I can’t perceive why the test failed.

 

 

TIA,

 

Clayton

 

 

 

Microsoft Windows [Version 6.0.6002]

Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

 

C:\Users\Dad>pip requests

ERROR: unknown command "requests"

 

C:\Users\Dad>pip requests install

ERROR: unknown command "requests"

 

C:\Users\Dad>pip install requests

Downloading/unpacking requests

Installing collected packages: requests

Successfully installed requests

Cleaning up...

 

C:\Users\Dad>pip install beautiful

Downloading/unpacking beautiful

  Could not find any downloads that satisfy the requirement beautiful

Cleaning up...

No distributions at all found for beautiful

Storing debug log for failure in C:\Windows\system32\config\systemprofile\pip\pi

p.log

 

C:\Users\Dad>pip install beautifulsoup

Downloading/unpacking beautifulsoup

  Downloading BeautifulSoup-3.2.1.tar.gz

  Running setup.py (path:C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\

pip_build_SYSTEM\beautifulsoup\setup.py) egg_info for package beautifulsoup

    Traceback (most recent call last):

      File "<string>", line 17, in <module>

      File "C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\pip_build_SYS

TEM\beautifulsoup\setup.py", line 22

        print "Unit tests have failed!"

                                      ^

    SyntaxError: Missing parentheses in call to 'print'

    Complete output from command python setup.py egg_info:

    Traceback (most recent call last):

 

  File "<string>", line 17, in <module>

 

  File "C:\Windows\system32\config\SYSTEM~1\AppData\Local\Temp\pip_build_SYSTEM\

beautifulsoup\setup.py", line 22

 

    print "Unit tests have failed!"

 

                                  ^

 

SyntaxError: Missing parentheses in call to 'print'

 

----------------------------------------

Cleaning up...

Command python setup.py egg_info failed with error code 1 in C:\Windows\system32

\config\SYSTEM~1\AppData\Local\Temp\pip_build_SYSTEM\beautifulsoup

Storing debug log for failure in C:\Windows\system32\config\systemprofile\pip\pi

p.log

 

C:\Users\Dad>

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
boB Stepp | 24 Nov 19:32 2014
Picon

"Philosophical" question about string slicing from end of a string

Python 2.7.8
Win7Pro

>>> str = "0123456789"
>>> str[-1]
'9'
>>> str[-3:-1]
'78'
>>> str[-3:]
'789'

I understand that the above is "the way it is" in Python, but I am
puzzled why the designers did not choose that str[-3:-1] returns
'789', especially since str[-1] returns '9'. What is the reason for
choosing Python's actual behavior?

--

-- 
boB
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Adam Gold | 24 Nov 15:02 2014
Picon

pexpect interactive password entry for luks device

I'm trying to do something really simply (I think) with pexpect but must
be missing an obvious step.  I want to ssh from host to guest, establish
a CIFS connection on the guest to a share somewhere else on the local
network, open a luks loop device on the share by entering the password
(I don't want this to be non-interactive, either with a key file or by
including the password in the pexpect script) and then mounting the device.

I'm using the following code:

password = getpass.getpass('Enter passphrase for /opt/luks: ')
child = pexpect.spawn('ssh root <at> 192.168.56.101')
child.interact()
child.sendline('mount.cifs -o credentials=/root/cred_f //192.168.56.1/f
/opt')
child.sendline('losetup /dev/loop0 /opt/luks')
child.sendline('cryptsetup luksOpen /dev/loop0 l')
child.expect('Enter passphrase for /opt/luks: ')
child.sendline(password)
child.sendline('mount /dev/mapper/l /opt')
child.sendline('exit')

The best that happens is the CIFS share gets mounted and the program
exits while leaving me in the child terminal.  I've tried varying the
placement of child.interact() but that makes no difference or replacing
the first line which uses getpass with a 'child.expect' line when the
password is required.

Could anyone help me?
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Paul LaBerge | 24 Nov 06:05 2014

attempting to install PIP

Hello,

I’m trying to install PIP on a Mac running Yosemite. I downloaded get-pip.py from https://pip.pypa.io/en/latest/installing.html. I copied it to /usr/local/bin/ then  ran python get-pip.py. It repeatedly downloaded something up to a count of 100. From looking at the debug log it seems it was checking every version of PIP back to 0.2 before selecting version 1.5.6. 

Using version 1.5.6 (newest of versions: 1.5.6, 1.5.6, 0.2)


The result was:

snip

99  Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB): 100  Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB):      Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB): 1.0MB downloaded
Installing collected packages: pip
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/req.py", line 671, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/req.py", line 901, in move_wheel_files
    pycompile=self.pycompile,
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/wheel.py", line 215, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/var/folders/ft/pthcg_6j06zfdp0sl14kn76w0000gn/T/tmp6QIoTv/pip.zip/pip/wheel.py", line 205, in clobber
    os.makedirs(destdir)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip'

Storing debug log for failure in /Users/PaulSan/.pip/pip.log


It seems that PIP was not installed because of the permission’s error. Any light that can be cast on what happened and what I should do next would be appreciated. 

thanks in advance,

Paul

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Albert-Jan Roskam | 23 Nov 23:30 2014

multiprocessing question


Hi

I created some code to get records from a potentially giant .csv file. This implements a __getitem__ method
that gets records from a memory-mapped csv file. In order for this to work, I need to build a lookup table
that maps line numbers to line starts/ends. This works, BUT building the lookup table could be
time-consuming (and it freezes up the app). The (somewhat pruned) code is here:
http://pastebin.com/0x6JKbfh. Now I would like to build the lookup table in a separate process. I used
multiprocessing. In the crude example below, it appears to be doing what I have in mind. Is this the way to do
it? I have never used multiprocessing/threading before, apart from playing around. One specfic
question: __getitem__ is supposed to throw an IndexError when needed. But how do I know when I should
  do this if I don't yet know the total number of records? If there an uever cheap way of doing getting this number?

import multiprocessing as mp
import time

class Test(object):

    """Get records from a potentially huge, therefore mmapped, file (.csv)"""

    def __init__(self):        self.lookup = mp.Manager().dict()
        self.lookup_done = False
        process = mp.Process(target=self.create_lookup, args=(self.lookup,))
        process.start()

    def create_lookup(self, d):
        """time-consuming function that is only called once"""
        for i in xrange(10 ** 7):
            d[i] = i

        process.join()
        self.lookup_done = True

    def __getitem__(self, key):
        """In my app, this returns a record from a memory-mapped file
        The key is the line number, the value is a two-tuple of the start
        and the end byte of that record"""
        try:
            return self.lookup[key]
        except KeyError:
            # what's a cheap way to calculate the number of records in a .csv file?
            self.total_number_of_records = 10 ** 7

            if key > self.total_number_of_records:
                if not self.lookup_done:
                    process.join()
                raise IndexError("index out of range")
            print "One moment please, lookup not yet ready enough"

if __name__== "__main__":
    test = Test()

    # check if it works
    while True:
        k = int(raw_input("enter key: "))
        try:
            print "value is ", test[k]
            time.sleep(1)
        except KeyError:
            print "OOPS, value not yet in lookup"
        print "Max key is now", max(test.lookup.keys())
        if test.lookup and max(test.lookup.keys()) == (10 ** 7 - 1):
            print "Exiting"
            break
    print "Done"

Thank you in advance!

 
Regards,

Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation,
roads, a 

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

John Feleppa | 23 Nov 13:04 2014
Picon

Michael Dawson Chapter 6 Challenge 4

Dear all,

Has anyone solved the fourth challenge in Chapter 6 of Michael Dawson's book, 'Python Programming for the absolute beginner'?

The challenge: 'Write a new computer_move() function for the Tic-Tac-Toe game to plug the hole in the computer's strategy.  See if you can create an opponent that is unbeatable!'

The function is as follows: 

def computer_move(board, computer, human):
    """Make computer move."""
    # make a copy to work with since function will be changing list
    board = board[:]
    # the best positions to have, in order
    BEST_MOVES = (4, 0, 2, 6, 8, 1, 3, 5, 7)

    print("I shall take square number", end=" ")
    
    # if computer can win, take that move
    for move in legal_moves(board):
        board[move] = computer
        if winner(board) == computer:
            print(move)
            return move
        # done checking this move, undo it
        board[move] = EMPTY
    
    # if human can win, block that move
    for move in legal_moves(board):
        board[move] = human
        if winner(board) == human:
            print(move)
            return move
        # done checkin this move, undo it
        board[move] = EMPTY

    # since no one can win on next move, pick best open square
    for move in BEST_MOVES:
        if move in legal_moves(board):
            print(move)
            return move

I believe a solution lies in the final lines, which I put in bold, and in the BEST_MOVES tuple, which is also in bold.  As in, it looks through the list of best moves in order regardless of what move the opponent has made.  So it just dumbly selects the next item in the tuple instead of responding to the opponent's move.  So, for example, the following sequence shows the computer's weakness:

a. the opponent goes first in a corner, in Square 0
b. the computer picks the centre, in Square 5
c. the opponent picks the opposite corner, Square 8
d. the weakness - the computer picks the corner, Square 2, which will be easily countered by the opponent going in Square 6, instead of the smarter Square 1, which will result in a draw, and not a loss.

HAS ANYONE SOLVED THIS?  I'd much appreciate help here.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mitch Raful | 23 Nov 03:28 2014
Picon

How python keeps track of objects

If I have code similar to this:

for object in objects:
    do_something(object)


def do_something(obj):
     other_object = Class( obj.property)
     other_object.method( arg1, arg2)

    do_stuff here with other_object
    if problem:
         print( obj.property )


My concern is that the for loop will wreak havoc with objects created in the function do_something.  Do I need to use Threading for the do_something?  Or does the interpreter keep track of all the 'other_object's as the for loop calls the function?

Thanks,

Mitch
        
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Gmane