Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Harbey Leke
Create a class called BankAccount

.Create a constructor that takes in an integer and assigns this to a `balance` 
property.

.Create a method called `deposit` that takes in cash deposit amount and updates 
the balance accordingly.

.Create a method called `withdraw` that takes in cash withdrawal amount and 
updates the balance accordingly. if amount is greater than balance return 
`"invalid transaction"`

.Create a subclass MinimumBalanceAccount of the BankAccount class

Please i need help on this i am a beginer into python programming.


Also below is a test case given for this project 


import unittest
class AccountBalanceTestCases(unittest.TestCase):
  def setUp(self):
self.my_account = BankAccount(90)

  def test_balance(self):
self.assertEqual(self.my_account.balance, 90, msg='Account Balance Invalid')

  def test_deposit(self):
self.my_account.deposit(90)
self.assertEqual(self.my_account.balance, 180, msg='Deposit method 
inaccurate')

  def test_withdraw(self):
self.my_account.withdraw(40)
self.assertEqual(self.my_account.balance, 50, msg='Withdraw method 
inaccurate')

  def test_invalid_operation(self):
self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", 
msg='Invalid transaction')
  
  def test_sub_class(self):
self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No 
true subclass of BankAccount')
  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Chris Angelico
On Sat, Dec 12, 2015 at 8:05 PM, Harbey Leke  wrote:
> Create a class called BankAccount
>
> .Create a constructor that takes in an integer and assigns this to a 
> `balance` property.
>
> .Create a method called `deposit` that takes in cash deposit amount and 
> updates the balance accordingly.
>
> .Create a method called `withdraw` that takes in cash withdrawal amount and 
> updates the balance accordingly. if amount is greater than balance return 
> `"invalid transaction"`
>
> .Create a subclass MinimumBalanceAccount of the BankAccount class
>
> Please i need help on this i am a beginer into python programming.

Start by creating a text file in which you will store your code. Then
create a class called BankAccount, and start adding methods to it.

Which part of this do you need help with?

If you're taking a course on Python programming, you should have met
these concepts. Go and read the course text and see if you can find
the information you need.

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


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Harbey Leke
i need help with every part of the project, like a complete text of scripts for 
it, thrn i can practise with it on my own and then u can give me assignments to 
improve on 
thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Chris Angelico
On Sat, Dec 12, 2015 at 9:09 PM, Harbey Leke  wrote:
> i need help with every part of the project, like a complete text of scripts 
> for it, thrn i can practise with it on my own and then u can give me 
> assignments to improve on
> thanks

No.

You're the one taking the course; you write the code. If you get to
the point of having code that ought to do everything but, for reasons
you don't understand, doesn't, then you can post it here and ask for
help figuring things out. But we're not going to do your homework for
you.

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


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Harbey Leke
oh oh okay start it for me please
thanks or guide me about it then.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Harbey Leke
oh oh okay start it for me please
thanks or guide me about it then.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Chris Warrick
On 12 December 2015 at 11:29, Harbey Leke  wrote:
> oh oh okay start it for me please
> thanks or guide me about it then.
> --
> https://mail.python.org/mailman/listinfo/python-list

class BankAccount(object):
# your code goes here

Seriously: read the materials you got with your course, or the Python
tutorial and documentation at https://docs.python.org/ .

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread Steven D'Aprano
On Sat, 12 Dec 2015 08:05 pm, Harbey Leke wrote:

> Create a class called BankAccount


class BankAccount:
pass


That's easy. Unfortunately, that class does nothing, but at least it exists!
Now all you have to do is create *methods* of the class that do the work.

Here I give it a method called "display_balance" which prints the balance of
the account:

class BankAccount:
def display_balance(self):
bal = self.balance
print(bal)


Notice that the method is indented inside the class.

Unfortunately, that method doesn't work yet. The problem is, the account
doesn't yet have a balance, so obviously trying to print it will fail.
First you need to do the next part of the assignment:


> .Create a constructor that takes in an integer and assigns this to a
> `balance` property.

A "constructor" is a special method that Python automatically used to create
new instances. (I hope you understand what instances are!) Python classes
have two constructor methods:

__new__

__init__

Notice that they both start and end with TWO underscores.

Chances are, you won't need to use __new__, you will probably use __init__
instead. (Technically, __init__ is an initializer method, not a
constructor, but most people don't care about the difference.) So you have
to write a method called "__init__" that takes an integer argument (don't
forget the "self" argument as well!) and assigns that to a balance
property.


Here is how you assign a value to a attribute called "name":

self.name = "Harbey"


And an attribute called "number":

self.number = 23


And an attribute called "address":


self.address = "742 Evergreen Terrace Springfield"


See the pattern? How would you assign to an attribute called "balance"? Put
that *inside* the constructor method inside the class.



> .Create a method called `deposit` that takes in cash deposit amount and
> updates the balance accordingly.
> 
> .Create a method called `withdraw` that takes in cash withdrawal amount
> and updates the balance accordingly. if amount is greater than balance
> return `"invalid transaction"`


Again, you need to create two new methods. Remember, you create a method
with "def ..." and indent it inside the class. They must have a "self"
argument, plus whatever extra arguments the instructions above demand.

Here is how you would triple an attribute called "total":


self.total = 3 * self.total


How would you add or subtract from "balance" instead?


I've given you most of the pieces you need to solve this problem. You just
need to assemble them into working code. Off you go, write some code, and
if you have any problems, show us what code you have written and ask for
help. Just don't ask us to do your assignment for you.




-- 
Steven

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


Re: python unit test frame work

2015-12-12 Thread Ganesh Pal
On Thu, Dec 10, 2015 at 9:20 PM, Peter Otten <__pete...@web.de> wrote:
> Ganesh Pal wrote:
>

> I recommend that you reread the unittest documentation.
>
> setUpClass() should be a class method, and if it succeeds you can release
> the ressources it required in the corresponding tearDownClass() method. As
> written the flags and the setUp()/tearDown() seem unnecessary.
>

Thanks to peter , Cameron and  Ben Finney , for replying to my various
question post . I needed a hint  on the below


1. If there is a setUpClass exception or failure , I don't want the
unittest to run ( I don't have teardown ) how do I handle this  ?
The traceback on the console  looks very bad  it repeats for all
the test cases  , that means if I have 100 testcases if setup fails .
I will get the failure for all the test cases

#c_t.py

==
ERROR: test01: test_01_inode_test
--
Traceback (most recent call last):
  File "c_t.py", line xx, in setUp
self.setupClass()
  File "c_t.py", line xxx, in TestSetup
self.TestSetup()
  File "c_t.py", line xx, in corruptSetup
sys.exit("/tmp is not mounted ...Exiting !!!")
SystemExit: /tmp is not mounted ...Exiting !!!
==
ERROR: test02
--
Traceback (most recent call last):
  File "c_t.py", line 162, in  test_02_hardlink_test
self.inject_failures['test02']))
KeyError: 'test02'

Ran 2 tests in 0.003s
FAILED (errors=2)
-- 
https://mail.python.org/mailman/listinfo/python-list


XMPP pub sub setup and working

2015-12-12 Thread satish
I am using xmpppy python library to connect with XMPP server(ejabberd2) but 
unable to connect and actually don't have clarity on how to connect, 
authenticate and send a message to the server.  

Please help me to make it working  

If possible please provide some code snippet using XMPPPY.

This is what I have tried:

In [1]: from xmpp import Client

In [2]: cl = Client(server='176.9.18.111', 5280)

  File "", line 1

cl = Client(server='176.9.18.111', 5280)

SyntaxError: non-keyword arg after keyword arg


In [3]: cl = Client(server='176.9.18.111', port =5280)

Invalid debugflag given: always

Invalid debugflag given: nodebuilder

DEBUG: 

DEBUG: Debug created for 
/Users/gathole/.virtualenvs/driveu/lib/python2.7/site-packages/xmpp/client.py

DEBUG:  flags defined: always,nodebuilder

In [4]: cl.connect()

DEBUG: socket   start Plugging  into 

DEBUG: socket   warn  An error occurred while looking up 
_xmpp-client._tcp.176.9.18.111

DEBUG: socket   start Successfully connected to remote host 
('176.9.18.111', 5280)

DEBUG: dispatcher   start Plugging  into 

DEBUG: dispatcher   info  Registering namespace "unknown"

DEBUG: dispatcher   info  Registering protocol "unknown" as (unknown)

DEBUG: dispatcher   info  Registering protocol "default" as (unknown)

DEBUG: dispatcher   info  Registering namespace 
"http://etherx.jabber.org/streams";

DEBUG: dispatcher   info  Registering protocol "unknown" as (http://etherx.jabber.org/streams)

DEBUG: dispatcher   info  Registering protocol "default" as (http://etherx.jabber.org/streams)

DEBUG: dispatcher   info  Registering namespace "jabber:client"

DEBUG: dispatcher   info  Registering protocol "unknown" as (jabber:client)

DEBUG: dispatcher   info  Registering protocol "default" as (jabber:client)

DEBUG: dispatcher   info  Registering protocol "iq" as (jabber:client)

DEBUG: dispatcher   info  Registering protocol "presence" as (jabber:client)

DEBUG: dispatcher   info  Registering protocol "message" as (jabber:client)

DEBUG: dispatcher   info  Registering handler > for "error" type-> ns->(http://etherx.jabber.org/streams)

DEBUG: dispatcher   warn  Registering protocol "error" as (http://etherx.jabber.org/streams)

DEBUG: socket   sent  

  http://etherx.jabber.org/streams"; >


DEBUG: socket   error Socket error while receiving data

DEBUG: client   stop  Disconnect detected

DEBUG: socket   error Socket operation failed

Out[4]: ''
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python unit test frame work

2015-12-12 Thread Peter Otten
Ganesh Pal wrote:

> On Thu, Dec 10, 2015 at 9:20 PM, Peter Otten <__pete...@web.de> wrote:
>> Ganesh Pal wrote:
>>
> 
>> I recommend that you reread the unittest documentation.
>>
>> setUpClass() should be a class method, and if it succeeds you can release
>> the ressources it required in the corresponding tearDownClass() method.
>> As written the flags and the setUp()/tearDown() seem unnecessary.
>>
> 
> Thanks to peter , Cameron and  Ben Finney , for replying to my various
> question post . I needed a hint  on the below
> 
> 
> 1. If there is a setUpClass exception or failure , I don't want the
> unittest to run ( I don't have teardown ) how do I handle this  ?
> The traceback on the console  looks very bad  it repeats for all
> the test cases  , that means if I have 100 testcases if setup fails .
> I will get the failure for all the test cases
> 
> #c_t.py
> 
> ==
> ERROR: test01: test_01_inode_test
> --
> Traceback (most recent call last):
>   File "c_t.py", line xx, in setUp
> self.setupClass()
>   File "c_t.py", line xxx, in TestSetup
> self.TestSetup()
>   File "c_t.py", line xx, in corruptSetup
> sys.exit("/tmp is not mounted ...Exiting !!!")
> SystemExit: /tmp is not mounted ...Exiting !!!
> ==
> ERROR: test02
> --
> Traceback (most recent call last):
>   File "c_t.py", line 162, in  test_02_hardlink_test
> self.inject_failures['test02']))
> KeyError: 'test02'
> 
> Ran 2 tests in 0.003s
> FAILED (errors=2)

Don't invoke sys.exit(), raise a meaningful exception instead. Then in 
setUpClass() you can catch the expected exceptions and raise a SkipTest. 
Example:

$ cat mayfail.py
import os
import unittest

def setup_that_may_fail():
if "FAIL" in os.environ:
1/0

class MyTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
try:
setup_that_may_fail() # placeholder for your actual setup
except Exception as err:
raise unittest.SkipTest(
"class setup failed") # todo: better message

def test_one(self):
pass

def test_two(self):
pass

if __name__ == "__main__":
unittest.main()

When the setup succeeds:

$ python mayfail.py
..
--
Ran 2 tests in 0.000s

OK

Now let's pretend a failure by setting the FAIL environment variable.
(In your actual code you won't do that as you get a "real" failure)
$ FAIL=1 python mayfail.py
s
--
Ran 0 tests in 0.000s

OK (skipped=1)

There's one oddity with this approach -- only one skipped test is reported 
even though there are two tests in the class, neither of which is run.

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


2to3 translation problem

2015-12-12 Thread Tony van der Hoff

Debian Jessie, python 2.7; python 3.4

I have an application, using pygame for graphics, that works fine under 
python2.7. I have run it through 2to3, but when running the result under 
python 3.4, I get the error :


Traceback (most recent call last):
  File "ppm304.py", line 9, in 
import pygame
ImportError: No module named 'pygame'

So, python 3.4 can't find the library, whilst python 2.7 can.
How do I track down/fix the missing dependency.
--
https://mail.python.org/mailman/listinfo/python-list


Re: 2to3 translation problem

2015-12-12 Thread Mark Lawrence

On 12/12/2015 14:42, Tony van der Hoff wrote:

Debian Jessie, python 2.7; python 3.4

I have an application, using pygame for graphics, that works fine under
python2.7. I have run it through 2to3, but when running the result under
python 3.4, I get the error :

Traceback (most recent call last):
   File "ppm304.py", line 9, in 
 import pygame
ImportError: No module named 'pygame'

So, python 3.4 can't find the library, whilst python 2.7 can.
How do I track down/fix the missing dependency.


This isn't a 2to3 translation problem.  You've installed pygame under 
2.7 at some point, repeat the process for 3.4.  I've no idea how you'd 
do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".


--
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: 2to3 translation problem

2015-12-12 Thread Tony van der Hoff

On 12/12/15 15:09, Mark Lawrence wrote:

On 12/12/2015 14:42, Tony van der Hoff wrote:

Debian Jessie, python 2.7; python 3.4

I have an application, using pygame for graphics, that works fine under
python2.7. I have run it through 2to3, but when running the result under
python 3.4, I get the error :

Traceback (most recent call last):
   File "ppm304.py", line 9, in 
 import pygame
ImportError: No module named 'pygame'

So, python 3.4 can't find the library, whilst python 2.7 can.
How do I track down/fix the missing dependency.


This isn't a 2to3 translation problem.  You've installed pygame under
2.7 at some point, repeat the process for 3.4.  I've no idea how you'd
do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".

Thanks, Mark, for the pointer. I'm pretty sure I installed Pygame from 
Debian's repository, via apt-get install python-pygame. I believe that 
should be effective for any version of Python.


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


Re: 2to3 translation problem

2015-12-12 Thread Mark Lawrence

On 12/12/2015 16:31, Tony van der Hoff wrote:

On 12/12/15 15:09, Mark Lawrence wrote:

On 12/12/2015 14:42, Tony van der Hoff wrote:

Debian Jessie, python 2.7; python 3.4

I have an application, using pygame for graphics, that works fine under
python2.7. I have run it through 2to3, but when running the result under
python 3.4, I get the error :

Traceback (most recent call last):
   File "ppm304.py", line 9, in 
 import pygame
ImportError: No module named 'pygame'

So, python 3.4 can't find the library, whilst python 2.7 can.
How do I track down/fix the missing dependency.


This isn't a 2to3 translation problem.  You've installed pygame under
2.7 at some point, repeat the process for 3.4.  I've no idea how you'd
do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".


Thanks, Mark, for the pointer. I'm pretty sure I installed Pygame from
Debian's repository, via apt-get install python-pygame. I believe that
should be effective for any version of Python.

Thanks anyway,
Tony


My belief is that every package has to be installed in the site-packages 
directory for each version of Python.


--
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: 2to3 translation problem

2015-12-12 Thread Peter Otten
Tony van der Hoff wrote:

> On 12/12/15 15:09, Mark Lawrence wrote:
>> On 12/12/2015 14:42, Tony van der Hoff wrote:
>>> Debian Jessie, python 2.7; python 3.4
>>>
>>> I have an application, using pygame for graphics, that works fine under
>>> python2.7. I have run it through 2to3, but when running the result under
>>> python 3.4, I get the error :
>>>
>>> Traceback (most recent call last):
>>>File "ppm304.py", line 9, in 
>>>  import pygame
>>> ImportError: No module named 'pygame'
>>>
>>> So, python 3.4 can't find the library, whilst python 2.7 can.
>>> How do I track down/fix the missing dependency.
>>
>> This isn't a 2to3 translation problem.  You've installed pygame under
>> 2.7 at some point, repeat the process for 3.4.  I've no idea how you'd
>> do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".
>>
> Thanks, Mark, for the pointer. I'm pretty sure I installed Pygame from
> Debian's repository, via apt-get install python-pygame. I believe that
> should be effective for any version of Python.

No, that is the version for Python 2. If there is a Python 3 version it will 
be called

python3-pygame

but no such package seems to be available:

https://packages.debian.org/search?suite=jessie&arch=any&searchon=names&keywords=python3-pygame

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


Re: 2to3 translation problem

2015-12-12 Thread Laura Creighton
In a message of Sat, 12 Dec 2015 16:31:54 +, Tony van der Hoff writes:
>On 12/12/15 15:09, Mark Lawrence wrote:
>> On 12/12/2015 14:42, Tony van der Hoff wrote:
>>> Debian Jessie, python 2.7; python 3.4
>>>
>>> I have an application, using pygame for graphics, that works fine under
>>> python2.7. I have run it through 2to3, but when running the result under
>>> python 3.4, I get the error :
>>>
>>> Traceback (most recent call last):
>>>File "ppm304.py", line 9, in 
>>>  import pygame
>>> ImportError: No module named 'pygame'
>>>
>>> So, python 3.4 can't find the library, whilst python 2.7 can.
>>> How do I track down/fix the missing dependency.
>>
>> This isn't a 2to3 translation problem.  You've installed pygame under
>> 2.7 at some point, repeat the process for 3.4.  I've no idea how you'd
>> do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".
>>
>Thanks, Mark, for the pointer. I'm pretty sure I installed Pygame from 
>Debian's repository, via apt-get install python-pygame. I believe that 
>should be effective for any version of Python.

You are mistaken here.
python-pygame is only a python 2.7 pygame.

you want python3-pygame.
https://packages.debian.org/search?keywords=python3-pygame

Speaking as a debian user are going to have a _whole lot of this_.
If you don't know about apt-cache search  
let me recommend it to you.

This on debian unstable:

lac@smartwheels:~$  apt-cache search pygame
lightyears - single player real-time strategy game with steampunk sci-fi
psychopy - environment for creating psychology stimuli in Python
python-pygame - SDL bindings for games development in Python
python-pyglet - cross-platform windowing and multimedia library
pyntor - flexible and componentized presentation program
solarwolf - Collect the boxes and don't become mad
python-soya - high level 3D engine for Python
python-soya-dbg - high level 3D engine for Python - debug extension
python-soya-doc - high level 3D engine for Python
python3-pygame - SDL bindings for games development in Python (Python 3)

So, too many hits, alas, but it does tend to find such things.

Laura

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


Re: 2to3 translation problem

2015-12-12 Thread Laura Creighton
In a message of Sat, 12 Dec 2015 17:59:52 +0100, Peter Otten writes:
>Tony van der Hoff wrote:
>
>> On 12/12/15 15:09, Mark Lawrence wrote:
>>> On 12/12/2015 14:42, Tony van der Hoff wrote:
 Debian Jessie, python 2.7; python 3.4

 I have an application, using pygame for graphics, that works fine under
 python2.7. I have run it through 2to3, but when running the result under
 python 3.4, I get the error :

 Traceback (most recent call last):
File "ppm304.py", line 9, in 
  import pygame
 ImportError: No module named 'pygame'

 So, python 3.4 can't find the library, whilst python 2.7 can.
 How do I track down/fix the missing dependency.
>>>
>>> This isn't a 2to3 translation problem.  You've installed pygame under
>>> 2.7 at some point, repeat the process for 3.4.  I've no idea how you'd
>>> do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".
>>>
>> Thanks, Mark, for the pointer. I'm pretty sure I installed Pygame from
>> Debian's repository, via apt-get install python-pygame. I believe that
>> should be effective for any version of Python.
>
>No, that is the version for Python 2. If there is a Python 3 version it will 
>be called
>
>python3-pygame
>
>but no such package seems to be available:
>
>https://packages.debian.org/search?suite=jessie&arch=any&searchon=names&keywords=python3-pygame

There is one in unstable, I forgot to check for jessie, sorry about that.

Laura

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


Re: 2to3 translation problem

2015-12-12 Thread Tony van der Hoff

On 12/12/15 17:09, Laura Creighton wrote:

In a message of Sat, 12 Dec 2015 17:59:52 +0100, Peter Otten writes:

Tony van der Hoff wrote:


On 12/12/15 15:09, Mark Lawrence wrote:

On 12/12/2015 14:42, Tony van der Hoff wrote:

Debian Jessie, python 2.7; python 3.4

I have an application, using pygame for graphics, that works fine under
python2.7. I have run it through 2to3, but when running the result under
python 3.4, I get the error :

Traceback (most recent call last):
File "ppm304.py", line 9, in 
  import pygame
ImportError: No module named 'pygame'

So, python 3.4 can't find the library, whilst python 2.7 can.
How do I track down/fix the missing dependency.


This isn't a 2to3 translation problem.  You've installed pygame under
2.7 at some point, repeat the process for 3.4.  I've no idea how you'd
do that on Debian Jessie but on Windows it'd be "pip3.4 install pygame".


Thanks, Mark, for the pointer. I'm pretty sure I installed Pygame from
Debian's repository, via apt-get install python-pygame. I believe that
should be effective for any version of Python.


No, that is the version for Python 2. If there is a Python 3 version it will
be called

python3-pygame

but no such package seems to be available:

https://packages.debian.org/search?suite=jessie&arch=any&searchon=names&keywords=python3-pygame


There is one in unstable, I forgot to check for jessie, sorry about that.

Laura

Thanks, Laura, and others who have replied. You're right; 
python-3-pygame exists in unstable, but has not yet made it to jessie, 
even in backports.


So, I'll stick with python 2.7 for the time being; really no hardship :)

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


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-12 Thread mkatietola
Thank you so much Steven 
you've given me a really great head start 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 2to3 translation problem

2015-12-12 Thread Chris Angelico
On Sun, Dec 13, 2015 at 4:30 AM, Tony van der Hoff  wrote:
> Thanks, Laura, and others who have replied. You're right; python-3-pygame
> exists in unstable, but has not yet made it to jessie, even in backports.
>
> So, I'll stick with python 2.7 for the time being; really no hardship :)

The easiest solution is simply:

python3 -m pip install pygame

Don't worry about it not being in the Jessie repo - you can always
grab things using pip.

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


Re: 2to3 translation problem

2015-12-12 Thread Laura Creighton
In a message of Sun, 13 Dec 2015 04:50:43 +1100, Chris Angelico writes:
>On Sun, Dec 13, 2015 at 4:30 AM, Tony van der Hoff  wrote:
>> Thanks, Laura, and others who have replied. You're right; python-3-pygame
>> exists in unstable, but has not yet made it to jessie, even in backports.
>>
>> So, I'll stick with python 2.7 for the time being; really no hardship :)
>
>The easiest solution is simply:
>
>python3 -m pip install pygame
>
>Don't worry about it not being in the Jessie repo - you can always
>grab things using pip.
>
>ChrisA

What Chris said. :)

If you are about to move your life from being python2.7 based to 
being 3.x, you are not going to be able to depend on things getting
to jessie in a timely fashion.  So you will be doing this a whole lot.

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


tkinter: Switch between two grids

2015-12-12 Thread sms

Hello all,

I'm sorry to ask this question, but I am a very beginer.

What I need:
1. Fullscreen application
2. On the home screen: Three row
3. When I click on the main screen, it switches to one row only.

Actually, I am not able to switch from Window1 to Window2, Window2 comes 
under Window1


Any help would be greatly appreciated.

Please, find my shameful code :

import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk


def destroy(e): sys.exit()

class Window1():
def __init__(self, master):
self.frame=Tk.Frame(master, bg="Green", borderwidth=10)

sticky=Tk.N+Tk.S+Tk.E+Tk.W
self.frame.grid(sticky=sticky)

self.frame.columnconfigure(0, weight=1)
self.frame.rowconfigure(0, weight=1)
self.frame.rowconfigure(1, weight=1)
self.frame.rowconfigure(2, weight=1)

self.v = Tk.StringVar()
text = Tk.Label(self.frame, text="Text1")
text.grid(column=0, row=0, sticky=sticky)

self.h = Tk.StringVar()
text = Tk.Label(self.frame, text="Text2")
text.grid(column=0, row=1, sticky=sticky)

self.d = Tk.StringVar()
text = Tk.Label(self.frame, text="Text3")
text.grid(column=0, row=2, sticky=sticky)


class Window2:
def __init__(self, master):

self.frame = Tk.Frame(master, bg="black", borderwidth=10)
sticky=Tk.N+Tk.S+Tk.E+Tk.W
self.frame.grid(sticky=sticky)

self.v = Tk.StringVar()
text = Tk.Label(self.frame, text="Prout")
text.grid(column=0, row=0, sticky=sticky)

class VGui:
def __init__(self):
self.root = Tk.Tk()
self.root.attributes("-fullscreen", True)
Tk.Grid.rowconfigure(self.root, 0, weight=1)
Tk.Grid.columnconfigure(self.root, 0, weight=1)
self.Window1 = Window1(self.root)
self.Window2 = Window2(self.root)

self.root.bind("", self.Callback)

def Start(self):
Tk.mainloop()

def Callback(self, event):
self.Window2.frame.tkraise()

if __name__ == '__main__' :
gui=VGui()
gui.Start()

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


codecs.StreamRecoder not doing what I expected.

2015-12-12 Thread D'Arcy J.M. Cain
More Unicode bafflement.  What I am trying to do is pretty simple I
think.  I have a bunch of files that I am pretty sure are either utf-8
or iso-8859-1.  I try utf-8 and fall back to iso-8859-1 if it throws a
UnicodeError.  Here is my test.

#! /usr/pkg/bin/python3.4
# Running on a NetBSD 7.0 server
# Installed with pkgsrc

import codecs
test_file = "StreamRecoder.txt"

def read_file(fn):
try: return open(fn, "r", encoding='utf-8').read()
except UnicodeError:
return codecs.StreamRecoder(open(fn),
codecs.getencoder('utf-8'),
codecs.getdecoder('utf-8'),
codecs.getreader('iso-8859-1'),
codecs.getwriter('iso-8859-1'), "r").read()

# plain ASCII
open(test_file, 'wb').write(b'abc - cents\n')
print(read_file(test_file))

# utf-8
open(test_file, 'wb').write(b'abc - \xc2\xa2\n')
print(read_file(test_file))

# iso-8859-1
open(test_file, 'wb').write(b'abc - \xa2\n')
print(read_file(test_file))

I expected all three to return UTF-8 strings but here is my output:

abc - cents

abc - ¢

Traceback (most recent call last):
  File "./StreamRecoder_test", line 9, in read_file
try: return open(fn, "r", encoding='utf-8').read()
  File "/usr/pkg/lib/python3.4/codecs.py", line 319, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 6:
invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./StreamRecoder_test", line 27, in 
print(read_file(test_file))
  File "./StreamRecoder_test", line 15, in read_file
codecs.getwriter('iso-8859-1'), "r").read()
  File "/usr/pkg/lib/python3.4/codecs.py", line 798, in read
data = self.reader.read(size)
  File "/usr/pkg/lib/python3.4/codecs.py", line 489, in read
newdata = self.stream.read()
  File "/usr/pkg/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa2 in position 6:
ordinal not in range(128)

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 2to3 translation problem

2015-12-12 Thread Terry Reedy

On 12/12/2015 12:30 PM, Tony van der Hoff wrote:


Thanks, Laura, and others who have replied. You're right;
python-3-pygame exists in unstable, but has not yet made it to jessie,
even in backports.

So, I'll stick with python 2.7 for the time being; really no hardship :)


pygame itself was ported to 3.x years ago and the port is quite stable.

--
Terry Jan Reedy

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


Re: 2to3 translation problem

2015-12-12 Thread Tony van der Hoff

On 12/12/15 17:54, Laura Creighton wrote:

In a message of Sun, 13 Dec 2015 04:50:43 +1100, Chris Angelico writes:

On Sun, Dec 13, 2015 at 4:30 AM, Tony van der Hoff  wrote:

Thanks, Laura, and others who have replied. You're right; python-3-pygame
exists in unstable, but has not yet made it to jessie, even in backports.

So, I'll stick with python 2.7 for the time being; really no hardship :)


The easiest solution is simply:

python3 -m pip install pygame

Don't worry about it not being in the Jessie repo - you can always
grab things using pip.

ChrisA


What Chris said. :)

If you are about to move your life from being python2.7 based to
being 3.x, you are not going to be able to depend on things getting
to jessie in a timely fashion.  So you will be doing this a whole lot.


No:
tony@tony-lx:~$ python3 -m pip install pygame
/usr/bin/python3: No module named pip

Hmm, apt-get install python3-pip: OK

tony@tony-lx:~$ python3 -m pip install pygame
Downloading/unpacking pygame
  Could not find any downloads that satisfy the requirement pygame
  Some externally hosted files were ignored (use --allow-external 
pygame to allow).

Cleaning up...
No distributions at all found for pygame
Storing debug log for failure in /home/tony/.pip/pip.log

I really can't be bothered...

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


Re: tkinter: Switch between two grids

2015-12-12 Thread Terry Reedy

On 12/12/2015 1:24 PM, sms wrote:


What I need:
1. Fullscreen application


Not directly relevant to the below.


2. On the home screen: Three row
3. When I click on the main screen, it switches to one row only.


Create homescreen Frame(master=root) or subclasses thereof. Pack the 
homescreen.  When click, homescreen.pack_forget(), then create and and 
pack the other screen (with root as master).


--
Terry Jan Reedy

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


Re: codecs.StreamRecoder not doing what I expected.

2015-12-12 Thread Peter Otten
D'Arcy J.M. Cain wrote:

> More Unicode bafflement.  What I am trying to do is pretty simple I
> think.  I have a bunch of files that I am pretty sure are either utf-8
> or iso-8859-1.  I try utf-8 and fall back to iso-8859-1 if it throws a
> UnicodeError.  Here is my test.
> 
> #! /usr/pkg/bin/python3.4
> # Running on a NetBSD 7.0 server
> # Installed with pkgsrc
> 
> import codecs
> test_file = "StreamRecoder.txt"
> 
> def read_file(fn):
> try: return open(fn, "r", encoding='utf-8').read()
> except UnicodeError:
> return codecs.StreamRecoder(open(fn),

A recoder converts bytes to bytes, so you have to open the file in binary 
mode. However, ...

> codecs.getencoder('utf-8'),
> codecs.getdecoder('utf-8'),
> codecs.getreader('iso-8859-1'),
> codecs.getwriter('iso-8859-1'), "r").read()
> 
> # plain ASCII
> open(test_file, 'wb').write(b'abc - cents\n')
> print(read_file(test_file))
> 
> # utf-8
> open(test_file, 'wb').write(b'abc - \xc2\xa2\n')
> print(read_file(test_file))
> 
> # iso-8859-1
> open(test_file, 'wb').write(b'abc - \xa2\n')
> print(read_file(test_file))

...when the recoder kicks in read_file() will return bytes which is probably 
not what you want. Why not just try the two encodings as in

def read_file(filename):
for encoding in ["utf-8", "iso-8859-1"]:
try:
with open(filename, encoding=encoding) as f:
return f.read()
except UnicodeDecodeError:
pass
raise AssertionError("unreachable")

> 
> I expected all three to return UTF-8 strings but here is my output:
> 
> abc - cents
> 
> abc - ¢
> 
> Traceback (most recent call last):
>   File "./StreamRecoder_test", line 9, in read_file
> try: return open(fn, "r", encoding='utf-8').read()
>   File "/usr/pkg/lib/python3.4/codecs.py", line 319, in decode
> (result, consumed) = self._buffer_decode(data, self.errors, final)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 6:
> invalid start byte
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "./StreamRecoder_test", line 27, in 
> print(read_file(test_file))
>   File "./StreamRecoder_test", line 15, in read_file
> codecs.getwriter('iso-8859-1'), "r").read()
>   File "/usr/pkg/lib/python3.4/codecs.py", line 798, in read
> data = self.reader.read(size)
>   File "/usr/pkg/lib/python3.4/codecs.py", line 489, in read
> newdata = self.stream.read()
>   File "/usr/pkg/lib/python3.4/encodings/ascii.py", line 26, in decode
> return codecs.ascii_decode(input, self.errors)[0]
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xa2 in position 6:
> ordinal not in range(128)
> 


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


Re: 2to3 translation problem

2015-12-12 Thread Laura Creighton
In a message of Sat, 12 Dec 2015 20:24:10 +, Tony van der Hoff writes:
>On 12/12/15 17:54, Laura Creighton wrote:
>> In a message of Sun, 13 Dec 2015 04:50:43 +1100, Chris Angelico writes:
>>> On Sun, Dec 13, 2015 at 4:30 AM, Tony van der Hoff  
>>> wrote:
 Thanks, Laura, and others who have replied. You're right; python-3-pygame
 exists in unstable, but has not yet made it to jessie, even in backports.

 So, I'll stick with python 2.7 for the time being; really no hardship :)
>>>
>>> The easiest solution is simply:
>>>
>>> python3 -m pip install pygame
>>>
>>> Don't worry about it not being in the Jessie repo - you can always
>>> grab things using pip.
>>>
>>> ChrisA
>>
>> What Chris said. :)
>>
>> If you are about to move your life from being python2.7 based to
>> being 3.x, you are not going to be able to depend on things getting
>> to jessie in a timely fashion.  So you will be doing this a whole lot.
>
>No:
>tony@tony-lx:~$ python3 -m pip install pygame
>/usr/bin/python3: No module named pip
>
>Hmm, apt-get install python3-pip: OK
>
>tony@tony-lx:~$ python3 -m pip install pygame
>Downloading/unpacking pygame
>   Could not find any downloads that satisfy the requirement pygame
>   Some externally hosted files were ignored (use --allow-external 
>pygame to allow).
>Cleaning up...
>No distributions at all found for pygame
>Storing debug log for failure in /home/tony/.pip/pip.log
>
>I really can't be bothered...
>
>Thanks for the hints.

Sorry, I forgot to warn you.  Debian, in its wisdom breaks python
up into several pieces, and so if you install python as a debian
package, you have to install the ability to use pip separately.

apt-get install python-pip  (for 2.x)
apt-get install python3-pip (for 3.x)

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


appending a line to a list based off of a string found in a previous list

2015-12-12 Thread Pedro Vincenty
Hello, I'm wondering how to append a line from a file onto a list(easy part) 
provided that the line contains strings specific to a previous list I've 
already made(hard part).  I have this right now, 
for line in satellite_dataread:
if any(i in line for i in list2):
line= line.strip()
satellite, country= line.split(',')
satellite_origin_list.append(country)

the statement if statement seems to work as I take it out of the for loop, but 
not as I have it presented. Thanks a bunch!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: appending a line to a list based off of a string found in a previous list

2015-12-12 Thread Terry Reedy

On 12/12/2015 4:48 PM, Pedro Vincenty wrote:

Hello, I'm wondering how to append a line from a file onto a list(easy part) 
provided that the line contains strings specific to a previous list I've 
already made(hard part).  I have this right now,
for line in satellite_dataread:
 if any(i in line for i in list2):
 line= line.strip()
 satellite, country= line.split(',')
 satellite_origin_list.append(country)

the statement if statement seems to work as I take it out of the for loop, but 
not as I have it presented. Thanks a bunch!!


You question and example are incomplete.  Read 
https://stackoverflow.com/help/mcve and follow it by adding in the 
missing definitions and printing the result.  For example:


satellite_origin_list = []
satellite_dataread = '''\
hooray, usa
salud3, ussr
panda 33, china
'''.splitlines()
list2 = ['ray', 'and']

for line in satellite_dataread:
if any(i in line for i in list2):
line= line.strip()
satellite, country= line.split(',')
satellite_origin_list.append(country)

print(satellite_origin_list)

# prints
[' usa', ' china']

Now tell us what you think is wrong with this result, which is exactly 
what I expected.


Note: you might want to unpack lines first and then test either 
satellete or country separately.


--
Terry Jan Reedy

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


Re: appending a line to a list based off of a string found in a previous list

2015-12-12 Thread Erik

Hi Pedro,

It would be _really useful_ if you included code that could be pasted
into an interpreter or file directly to show your problem. You are
referencing several data sources ("satellite_dataread" and "list2") that
we can only guess at.

On 12/12/15 21:48, Pedro Vincenty wrote:

Hello, I'm wondering how to append a line from a file onto a
list(easy part) provided that the line contains strings specific to a
previous list I've already made(hard part).


The following is a complete version of your example with some guessed-at 
data:


"""
satellite_dataread = (
"spam ham eggs,ctry0\n",
"spam ham eggs foo,ctry1\n",
"spam ham,ctry2\n",
"spam bar ham eggs,ctry3\n",
)

list2 = ['foo', 'bar']
satellite_origin_list = []

for line in satellite_dataread:
if any(i in line for i in list2):
line = line.strip()
satellite, country= line.split(',')
satellite_origin_list.append(country)

print (satellite_origin_list)
"""

When I put that in a file and run it, I get:

$ python foo.py
['ctry1', 'ctry3']

$ python3 foo.py
['ctry1', 'ctry3']

So, it seems to work as you describe already - what is it that I am 
missing? Please explain what you expect to see (or change the guessed-at 
input data to an example of what you actually have).


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


Re: appending a line to a list based off of a string found in a previous list

2015-12-12 Thread Pedro Vincenty
On Saturday, December 12, 2015 at 4:48:46 PM UTC-5, Pedro Vincenty wrote:
> Hello, I'm wondering how to append a line from a file onto a list(easy part) 
> provided that the line contains strings specific to a previous list I've 
> already made(hard part).  I have this right now, 
> for line in satellite_dataread:
> if any(i in line for i in list2):
> line= line.strip()
> satellite, country= line.split(',')
> satellite_origin_list.append(country)
> 
> the statement if statement seems to work as I take it out of the for loop, 
> but not as I have it presented. Thanks a bunch!!
I was able to get it it you guys were right.  Thanks a bunch!
-- 
https://mail.python.org/mailman/listinfo/python-list


Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Robert
Hi,

I want to use pydoc as some online tutorial shows, but it cannot run as 
below. What is wrong?


Thanks,




>>> import pydoc
>>> pydoc

>>> pydoc sys
SyntaxError: invalid syntax
>>> import sys
>>> pydoc sys
SyntaxError: invalid syntax
>>> help(pydoc)
Help on module pydoc:
..
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Robert
On Saturday, December 12, 2015 at 6:02:11 PM UTC-5, Robert wrote:
> Hi,
> 
> I want to use pydoc as some online tutorial shows, but it cannot run as 
> below. What is wrong?
> 
> 
> Thanks,
> 
> 
> 
> 
> >>> import pydoc
> >>> pydoc
> 
> >>> pydoc sys
> SyntaxError: invalid syntax
> >>> import sys
> >>> pydoc sys
> SyntaxError: invalid syntax
> >>> help(pydoc)
> Help on module pydoc:
> ..

In fact, I wanted to run the following code. When it failed, I moved to
the original question above.

Anyone can help? Thanks,

//
It also changes what pydoc will show:

module1.py

a = "A"
b = "B"
c = "C"
module2.py

__all__ = ['a', 'b']

a = "A"
b = "B"
c = "C"
$ pydoc module1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Erik

Hi Robert,

On 12/12/15 23:01, Robert wrote:

I want to use pydoc as some online tutorial shows, but it cannot run as
below. What is wrong?


"some online tutorial"?


import pydoc
pydoc




Correct - in the interactive interpreter, typing the name of an object 
prints its value. You have imported a module and then typed its name.



pydoc sys

SyntaxError: invalid syntax

import sys
pydoc sys

SyntaxError: invalid syntax


In both of these, there  is no operator after "pydoc", so what does it mean?


help(pydoc)

Help on module pydoc:
..


Instead of omitting the result of that, read it!


FWIW, The relevant part based on what I _think_ you're trying to do (as 
you didn't include the URL of your "some online tutorial") is probably 
this part:


"""
DESCRIPTION
In the Python interpreter, do "from pydoc import help" to provide 
online

help.  Calling help(thing) on a Python object documents the object.

Or, at the shell command line outside of Python:

Run "pydoc " to show documentation on something.
"""

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Ben Finney
Robert  writes:

> I want to use pydoc as some online tutorial shows

Which online tutorial? Please give the URL to the page that instructs
you to use ‘pydoc’ in that manner.

> >>> import pydoc

Allows you to use, in Python code, the ‘pydoc’ module by name.

> >>> pydoc
> 

Accesses the ‘pydoc’ name. Because this is the interactive Python shell,
it displays the result of that access: a module object.

> >>> pydoc sys
> SyntaxError: invalid syntax
> >>> import sys
> >>> pydoc sys
> SyntaxError: invalid syntax

Yes, using two names in a row like that is invalid Python syntax.

> >>> help(pydoc)
> Help on module pydoc:
> ..

Gives help from the module object you access through the name ‘pydoc’.


I suspect the tutorial instructs you to invoke the ‘pydoc’ *command* on
your operating system, not use it within Python.

But I can only guess, until you show us which page from which tutorial
you're referring to.

-- 
 \“Technology is neither good nor bad; nor is it neutral.” |
  `\   —Melvin Kranzberg's First Law of Technology |
_o__)  |
Ben Finney

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Erik

On 12/12/15 23:08, Robert wrote:

In fact, I wanted to run the following code. When it failed, I moved to
the original question above.


How did it fail? Tell us what _did_ happen.

It works fine for me:

$ pydoc module1
Help on module module1:

NAME
module1

FILE
/tmp/robert/module1.py

DATA
a = 'A'
b = 'B'
c = 'C'


$ pydoc module2
Help on module module2:

NAME
module2

FILE
/tmp/robert/module2.py

DATA
__all__ = ['a', 'b']
a = 'A'
b = 'B'

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Robert
On Saturday, December 12, 2015 at 6:24:25 PM UTC-5, Erik wrote:
> On 12/12/15 23:08, Robert wrote:
> > In fact, I wanted to run the following code. When it failed, I moved to
> > the original question above.
> 
> How did it fail? Tell us what _did_ happen.
> 
> It works fine for me:
> 
> $ pydoc module1
> Help on module module1:
> 
> NAME
>  module1
> 
> FILE
>  /tmp/robert/module1.py
> 
> DATA
>  a = 'A'
>  b = 'B'
>  c = 'C'
> 
> 
> $ pydoc module2
> Help on module module2:
> 
> NAME
>  module2
> 
> FILE
>  /tmp/robert/module2.py
> 
> DATA
>  __all__ = ['a', 'b']
>  a = 'A'
>  b = 'B'
> 
> E.

Excuse me for the incomplete information on previous posts.
Here is the message when I run it on Canopy (module1.py and module2.py 
are in the current folder):

Welcome to Canopy's interactive data-analysis environment!
 with pylab-backend set to: qt
Type '?' for more information.

In [1]: pydoc module1
  File "", line 1
pydoc module1
^
SyntaxError: invalid syntax
 

In [2]: 


The above code snippet is from here:
http://stackoverflow.com/questions/44834/can-someone-explain-all-in-python

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Erik

Hi Robert,

On 13/12/15 00:04, Robert wrote:

Excuse me for the incomplete information on previous posts.
Here is the message when I run it on Canopy (module1.py and module2.py
are in the current folder):

Welcome to Canopy's interactive data-analysis environment!
  with pylab-backend set to: qt
Type '?' for more information.


I don't have any experience with "Canopy", but it looks to me like it is 
providing you with an interactive Python environment.



In [1]: pydoc module1
   File "", line 1
 pydoc module1
 ^
SyntaxError: invalid syntax


As this is an interactive Python environment, then Python syntax is 
required. Remember what "help(pydoc)" told you:


"""
In the Python interpreter, do "from pydoc import help" to provide online
help.  Calling help(thing) on a Python object documents the object.
"""

So, instead of "pydoc module1" (which is not good Python syntax), do 
what the help document tells you to do within a Python interpreter:


import module1
pydoc.help(module1)

import module2
pydoc.help(module2)

Does that work better?

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Robert
On Saturday, December 12, 2015 at 7:05:39 PM UTC-5, Robert wrote:
> On Saturday, December 12, 2015 at 6:24:25 PM UTC-5, Erik wrote:
> > On 12/12/15 23:08, Robert wrote:
> > > In fact, I wanted to run the following code. When it failed, I moved to
> > > the original question above.
> > 
> > How did it fail? Tell us what _did_ happen.
> > 
> > It works fine for me:
> > 
> > $ pydoc module1
> > Help on module module1:
> > 
> > NAME
> >  module1
> > 
> > FILE
> >  /tmp/robert/module1.py
> > 
> > DATA
> >  a = 'A'
> >  b = 'B'
> >  c = 'C'
> > 
> > 
> > $ pydoc module2
> > Help on module module2:
> > 
> > NAME
> >  module2
> > 
> > FILE
> >  /tmp/robert/module2.py
> > 
> > DATA
> >  __all__ = ['a', 'b']
> >  a = 'A'
> >  b = 'B'
> > 
> > E.
> 
> Excuse me for the incomplete information on previous posts.
> Here is the message when I run it on Canopy (module1.py and module2.py 
> are in the current folder):
> 
> Welcome to Canopy's interactive data-analysis environment!
>  with pylab-backend set to: qt
> Type '?' for more information.
> 
> In [1]: pydoc module1
>   File "", line 1
> pydoc module1
> ^
> SyntaxError: invalid syntax
>  
> 
> In [2]: 
> 
> 
> The above code snippet is from here:
> http://stackoverflow.com/questions/44834/can-someone-explain-all-in-python
> 
> Thanks again.

Hi,
It turns out that Enthought does not allow pydoc as the link said:
http://stackoverflow.com/questions/12063718/using-help-and-pydoc-to-list-python-modules-not-working

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Erik

On 13/12/15 00:19, Robert wrote:

It turns out that Enthought does not allow pydoc as the link said:
http://stackoverflow.com/questions/12063718/using-help-and-pydoc-to-list-python-modules-not-working


I don't think that's what the article is telling you. Try what I said in 
my previous message.


Other than that, I think I'm probably out of ideas on this one ...

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Peter Otten
Robert wrote:

> On Saturday, December 12, 2015 at 7:05:39 PM UTC-5, Robert wrote:
>> On Saturday, December 12, 2015 at 6:24:25 PM UTC-5, Erik wrote:
>> > On 12/12/15 23:08, Robert wrote:
>> > > In fact, I wanted to run the following code. When it failed, I moved
>> > > to the original question above.
>> > 
>> > How did it fail? Tell us what _did_ happen.
>> > 
>> > It works fine for me:
>> > 
>> > $ pydoc module1
>> > Help on module module1:
>> > 
>> > NAME
>> >  module1
>> > 
>> > FILE
>> >  /tmp/robert/module1.py
>> > 
>> > DATA
>> >  a = 'A'
>> >  b = 'B'
>> >  c = 'C'
>> > 
>> > 
>> > $ pydoc module2
>> > Help on module module2:
>> > 
>> > NAME
>> >  module2
>> > 
>> > FILE
>> >  /tmp/robert/module2.py
>> > 
>> > DATA
>> >  __all__ = ['a', 'b']
>> >  a = 'A'
>> >  b = 'B'
>> > 
>> > E.
>> 
>> Excuse me for the incomplete information on previous posts.
>> Here is the message when I run it on Canopy (module1.py and module2.py
>> are in the current folder):
>> 
>> Welcome to Canopy's interactive data-analysis environment!
>>  with pylab-backend set to: qt
>> Type '?' for more information.
>> 
>> In [1]: pydoc module1
>>   File "", line 1
>> pydoc module1
>> ^
>> SyntaxError: invalid syntax
>>  
>> 
>> In [2]:
>> 
>> 
>> The above code snippet is from here:
>> http://stackoverflow.com/questions/44834/can-someone-explain-all-in-python
>> 
>> Thanks again.
> 
> Hi,
> It turns out that Enthought does not allow pydoc as the link said:
> http://stackoverflow.com/questions/12063718/using-help-and-pydoc-to-list-python-modules-not-working

This is completely unrelated.

>>> help("modules")

for the specific string "modules" triggers a scan for all available modules. 
For other strings like "module1" that represent a module name

>>> help("module1")

should work unless

>>> import module1

fails, too.

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Laura Creighton
In a message of Sat, 12 Dec 2015 15:01:54 -0800, Robert writes:
>Hi,
>
>I want to use pydoc as some online tutorial shows, but it cannot run as 
>below. What is wrong?
>
>
>Thanks,
>
>
>
>
 import pydoc
 pydoc
>
 pydoc sys
>SyntaxError: invalid syntax
 import sys
 pydoc sys
>SyntaxError: invalid syntax
 help(pydoc)
>Help on module pydoc:
>..
>-- 
>https://mail.python.org/mailman/listinfo/python-list

You aren't supposed to type 
pydoc sys
from __inside__ your python command interpreter.

You type this at a command prompt.

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


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Robert
On Saturday, December 12, 2015 at 7:36:21 PM UTC-5, Peter Otten wrote:
> Robert wrote:
> 
> > On Saturday, December 12, 2015 at 7:05:39 PM UTC-5, Robert wrote:
> >> On Saturday, December 12, 2015 at 6:24:25 PM UTC-5, Erik wrote:
> >> > On 12/12/15 23:08, Robert wrote:
> >> > > In fact, I wanted to run the following code. When it failed, I moved
> >> > > to the original question above.
> >> > 
> >> > How did it fail? Tell us what _did_ happen.
> >> > 
> >> > It works fine for me:
> >> > 
> >> > $ pydoc module1
> >> > Help on module module1:
> >> > 
> >> > NAME
> >> >  module1
> >> > 
> >> > FILE
> >> >  /tmp/robert/module1.py
> >> > 
> >> > DATA
> >> >  a = 'A'
> >> >  b = 'B'
> >> >  c = 'C'
> >> > 
> >> > 
> >> > $ pydoc module2
> >> > Help on module module2:
> >> > 
> >> > NAME
> >> >  module2
> >> > 
> >> > FILE
> >> >  /tmp/robert/module2.py
> >> > 
> >> > DATA
> >> >  __all__ = ['a', 'b']
> >> >  a = 'A'
> >> >  b = 'B'
> >> > 
> >> > E.
> >> 
> >> Excuse me for the incomplete information on previous posts.
> >> Here is the message when I run it on Canopy (module1.py and module2.py
> >> are in the current folder):
> >> 
> >> Welcome to Canopy's interactive data-analysis environment!
> >>  with pylab-backend set to: qt
> >> Type '?' for more information.
> >> 
> >> In [1]: pydoc module1
> >>   File "", line 1
> >> pydoc module1
> >> ^
> >> SyntaxError: invalid syntax
> >>  
> >> 
> >> In [2]:
> >> 
> >> 
> >> The above code snippet is from here:
> >> http://stackoverflow.com/questions/44834/can-someone-explain-all-in-python
> >> 
> >> Thanks again.
> > 
> > Hi,
> > It turns out that Enthought does not allow pydoc as the link said:
> > http://stackoverflow.com/questions/12063718/using-help-and-pydoc-to-list-python-modules-not-working
> 
> This is completely unrelated.
> 
> >>> help("modules")
> 
> for the specific string "modules" triggers a scan for all available modules. 
> For other strings like "module1" that represent a module name
> 
> >>> help("module1")
> 
> should work unless
> 
> >>> import module1
> 
> fails, too.

Thanks Peter and others. It previously may not be at the right directory.
After that, import pydoc, it works. Great thanks with the following command.


pydoc.help('module1')
Help on module module1:

NAME
module1

FILE
c:\users\rj\pyprj\module1.py

DATA
a = 'A'
b = 'B'
c = 'C'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't response pydoc on my Python 2.7?

2015-12-12 Thread Steven D'Aprano
On Sun, 13 Dec 2015 01:31 pm, Robert wrote:

> pydoc.help('module1')
> Help on module module1:


You don't need to do all that. help() has been a built-in command for Python
for, oh, probably a decade or more. Technically, it is added to the
built-ins on startup, so if you mess about with the site.py script or
disable it, it won't be available. But by default, help() should always be
available at the interactive prompt.

Enter this at the interactive Python prompt (by default you will see >>> as
the prompt):

help('sys')


and you will see help for the built-in module sys.

The only time you need to import pydoc is if you wish to use it
programmatically. You don't need it just to view help.

Alternative, at your operating system's command prompt (terminal, shell, DOS
prompt, command line, etc), you may be able to call pydoc as if it were a
program. The shell will probably have a dollar sign $ as the prompt. Enter
this:

pydoc sys

and you will see the help for the sys module. But beware that since you are
using the shell, not python, the syntax rules are different. For example:

Inside Python, [] means an empty list, and you can say help([]) to see help
about lists; but in the system shell, [] is a globbing pattern, and the
result you get will be somewhat different (and platform-dependent).

If the command "pydoc" doesn't work at your shell (remember: the shell has
the $ prompt, Python has the >>> prompt) you can try something like this
instead:

python -m pydoc sys


And last but not least, try calling pydoc without any arguments to see some
extra options.



-- 
Steven

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


Re: Problem with sqlite3 and Decimal

2015-12-12 Thread Frank Millman

"Frank Millman"  wrote in message news:n4gigr$f51$1...@ger.gmane.org...


I have found a workaround for my problem, but first I needed to understand
what was going on more clearly. This is what I have figured out.


[...]


The reason for the '#' in the above function is that sqlite3 passes the
current value of 'balance' into my function, and it has a bad habit of
trying to second-guess the data-type to use. Even though I store it as a
string, it passes in an integer or float. Prefixing it with a '#' forces
it to remain as a string.


Well that theory did not last very long!

As soon as I applied this to my live app, I found that I am using the 
database to perform arithmetic all over the place - calculating tax, 
exchange rates, etc. I always round the result once it arrives from the 
database, so there was no rounding problem.


With the prefix of '#' the calculations all just crash, and return null 
values.


My new solution is to pass a 'scale' factor into my aggregate function. The 
function uses the Decimal quantize method to round the result before 
returning. So far it seems to be working.


Frank


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


Re: Problem with sqlite3 and Decimal

2015-12-12 Thread Chris Angelico
On Sun, Dec 13, 2015 at 4:00 PM, Frank Millman  wrote:
> My new solution is to pass a 'scale' factor into my aggregate function. The
> function uses the Decimal quantize method to round the result before
> returning. So far it seems to be working.

So, effectively, you're using fixed point arithmetic. As long as
you're restricting yourself to adding values together, that's easy; be
careful of multiplying by tax percentages, as you might flick to
float.

Really, you'd do a lot better to move to PostgreSQL.

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


Re: Problem with sqlite3 and Decimal

2015-12-12 Thread Frank Millman
"Chris Angelico"  wrote in message 
news:CAPTjJmrfw-qNx-a=3q2qj244fgvxz3mpe4wa-wdusmchxuf...@mail.gmail.com...


On Sun, Dec 13, 2015 at 4:00 PM, Frank Millman  wrote:
> My new solution is to pass a 'scale' factor into my aggregate function. 
> The

> function uses the Decimal quantize method to round the result before
> returning. So far it seems to be working.

So, effectively, you're using fixed point arithmetic. As long as
you're restricting yourself to adding values together, that's easy; be
careful of multiplying by tax percentages, as you might flick to
float.

Really, you'd do a lot better to move to PostgreSQL.


Thanks for the warning, but I think I am safe.

There is only one exceptional case where I use my 'aggregate' function. It 
is a substitute for the following SQL statement -


   UPDATE table SET balance = balance + ? WHERE date > ?

Normally it works fine. However, I wanted to populate my database with some 
real-world values, so I wrote a program to generate a few thousand 
transactions, and that triggered the rounding errors that caused me to start 
this thread.


I have replaced the statement with -

   UPDATE table SET balance = aggregate(balance, ?, ?) WHERE date > ?

This prevents rounding errors from creeping in.

In all other cases, I use unadorned SQL to calculate a scalar value, which I 
round to the appropriate scaling factor before storing the result.


Regarding PostgreSQL, I have mentioned before that I offer my users a choice 
of 3 databases - PostgreSQL, Sql Server, and sqlite3 - so I have to make 
sure that my app works with all of them. I agree that for serious database 
work one should use PostgreSQL or Sql Server. But I think that sqlite3 is 
perfect for demos and for one-man businesses. It is fast, lightweight, and 
very 'standards compliant'. It does have some quirks, but these are clearly 
documented and the mailing list is very responsive.


Frank


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


Re: codecs.StreamRecoder not doing what I expected.

2015-12-12 Thread D'Arcy J.M. Cain
On Sat, 12 Dec 2015 21:35:36 +0100
Peter Otten <__pete...@web.de> wrote:
> def read_file(filename):
> for encoding in ["utf-8", "iso-8859-1"]:
> try:
> with open(filename, encoding=encoding) as f:
> return f.read()
> except UnicodeDecodeError:
> pass
> raise AssertionError("unreachable")

I replaced this in my test and it works.  However, I still have a
problem with my actual code.  The point of this code was that I expect
all the files that I am reading to be either ASCII, UTF-8 or LATIN-1
and I want to normalize my input.  My problem may actually be elsewhere.

My application is a web page of my wife's recipes.  She has hundreds of
files with a recipe in each one.  Often she simply typed them in but
sometimes she cuts and pastes from another source and gets non-ASCII
characters.  So far they seem to fit in the three categories above.

I added test prints to sys.stderr so that I can see what is happening.
In one particular case I have this "73 61 75 74 c3 a9" in the file.
When I open the file with
"open(filename, "r", encoding="utf-8").read()" I get what appears to be
a latin-1 string.  I print it to stderr and view it in the web log.
The above string prints as "saut\xe9".  The last is four actual
characters in the file.

When I try to print it to the web page it fails because the \xe9
character is not valid ASCII.  However, my default encoding is utf-8.
Other web pages on the same server display fine.

I have the following in the Apache config by the way.

SetEnv PYTHONIOENCODING utf8

So, my file is utf-8, I am reading it as utf-8, my Apache server output
is set to utf-8.  How is ASCII sneaking in?

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list