Re: Strange crash while running a script with a embedded python interpreter

2016-01-11 Thread Rickard Englund
On Friday, January 8, 2016 at 11:28:53 PM UTC+1, Michael Torrie wrote:
> On 01/08/2016 09:18 AM, Rickard Englund wrote:
> > First, some system info
> > * Windows 7 (also tested on 8 and 10) 
> > * Python 3.5.1 64bit (previously also tested using several 3.x versions)  
> > (also tested with 32 bit, but with 3.4.2) 
> > * Microsoft Visual Studio 2015 (earlier version of python also tested with 
> > Visual Studio 2013)  
> 
> Are you using the same version of Visual Studio that Python itself was
> compiled with?  If not there can be subtle problems with incompatible
> msvcrt dlls.  No idea if this would be contributing to the problem or
> not, though.

I've just downloaded the python source code and build it myself, the compiler 
settings in our project is the same as in the python projects. 


Though, your comment led me in the correct direction. When using the 
libs/binary I built my self it let me see the values of the PyObjects around 
the crash and it seems like it is related to our modules and/or how we expose 
them to the interpreter. When disabling our own modules everything seems to be 
working as it should. 

I think I got it wokring now, used some ugly hacks I need to clean up before I 
certain it works. 

Thanks for the help. 

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


Re: Strange crash while running a script with a embedded python interpreter

2016-01-11 Thread Chris Angelico
On Mon, Jan 11, 2016 at 6:55 PM, Rickard Englund
 wrote:
> On Friday, January 8, 2016 at 11:28:53 PM UTC+1, Michael Torrie wrote:
>> On 01/08/2016 09:18 AM, Rickard Englund wrote:
>> > First, some system info
>> > * Windows 7 (also tested on 8 and 10)
>> > * Python 3.5.1 64bit (previously also tested using several 3.x versions)  
>> > (also tested with 32 bit, but with 3.4.2)
>> > * Microsoft Visual Studio 2015 (earlier version of python also tested with 
>> > Visual Studio 2013)
>>
>> Are you using the same version of Visual Studio that Python itself was
>> compiled with?  If not there can be subtle problems with incompatible
>> msvcrt dlls.  No idea if this would be contributing to the problem or
>> not, though.
>
> I've just downloaded the python source code and build it myself, the compiler 
> settings in our project is the same as in the python projects.
>
>
> Though, your comment led me in the correct direction. When using the 
> libs/binary I built my self it let me see the values of the PyObjects around 
> the crash and it seems like it is related to our modules and/or how we expose 
> them to the interpreter. When disabling our own modules everything seems to 
> be working as it should.
>

Interesting. So somewhere along the way, you have native code (C
code?) that's creating a module, and that's where the trouble starts?
I would first look at all your refcount management; if that goes
wrong, all sorts of craziness could happen (if you still have a
pointer to a block of memory that gets released and reused, hilarity
will ensue - or, something will). Have you considered using Cython?
That might let you do what you need without worrying about all those
annoying internal API details.

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


Re: Which Python editor has this feature?

2016-01-11 Thread Gordon Levi
[email protected] wrote:

>It lets you jump between the current cursor position and the line the upper 
>level indentation start, something like the bracket matching in C editor. 
>Because of Python use indentation as its code block mark, It might be helpful 
>if we can jump between different level of it:-)

Jetbrains Pycharm has "go to start of block" and "go to end of block"
commands .

Unfortunately the free version of Pycharm does not support remote
debugging and my main use for Python is for programming a Raspberry
Pi. I use Visual Studio instead and its "go to end of block" does not
work in the Python editor
.
-- 
https://mail.python.org/mailman/listinfo/python-list


looking for windows testers

2016-01-11 Thread Ulli Horlacher
I have written a Python client for F*EX(*). It is designed for Windows
users, though it runs on UNIX, too. I am now looking for testers. If you
are interested, I will give you an account on my server.


(*) Frams' Fast File EXchange is a service to send files of any size to
any user anywhere in the internet: 
http://fex.rus.uni-stuttgart.de:8080/index.html

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: python unit test framework sample code

2016-01-11 Thread Ganesh Pal
Totally stuck with this
On Jan 10, 2016 7:11 PM, "Ganesh Pal"  wrote:

> Apologies,  looks like I did a reply instead of reply-all. So
> forwarding this email , please provide guidance on the same
>
> -- Forwarded message --
> From: Ganesh Pal 
> Date: Thu, Jan 7, 2016 at 12:26 PM
> Subject: Re: python unit test framework sample code
> To: Terry Reedy 
>
> > Unless you have a large program already in 2.6 and are just adding tests
> > (perhaps so you can more easily upgrade someday), consider upgrading to a
> > newer version.
>
> Sure , but for now Iam limited to use 2.6 , hence I cant upgrade need
> to work with 2.6
>
> >>
> >> class FileSystemTest(unittest2.TestCase):
> >>  block_address = {}
> >>  report = ""
> >>
> >>  @classmethod
> >>  def setUpClass(cls):
> >>  cls.FileSystemSetup()
> >
> >
> > This is senseless.  Put the body of FileSystemSetup here.
>
> I didn't understand  which line is senseless. I was trying to refer
> this example on stack overflow
>
> http://stackoverflow.com/questions/5938517/not-able-call-a-local-method-from-setupclass
>
>
> class TestSystemPromotion(unittest2.TestCase):
>
>   @classmethod
>   def setUpClass(cls):
> cls.setup_test_data()
>
>
>   @classmethod
>   def setup_test_data(cls):
> ...
>
>   def test_something(self):
> ...
>
>
> class FileSystemTest(unittest2.TestCase):
> block_address = {}
> report = ""
>
> @classmethod
> def setUpClass(cls):
> cls.FileSystemSetup()
>
> @classmethod
> def FileSystemSetup(cls):
> """
> Initial setup before unittest is run
> """
> logging.info("SETUP.Started !!!")
>
> >>  def inode_corruption(self):
> >>  """ test_01: inode  corruption """
> >>  self.assertTrue(corrupt.run_query_tool(self.__class__.report,
> >
> >
> > self.block_address['test_01']))
> >
> > Assuming that unittest2 is same as unittest, test methods must be called
> > test_xyz.  So this is not run, hence no error.
>
> Sorry  I have changed this from inode_corruption' to 'test_inode_corruption
>
> >
> >>  @classmethod
> >>  def tearDownClass(cls):
> >>  cls.tearDown()
> >
> >
> > Ditto.  Put real body here.
> >
> >>  @classmethod
> >>  def tearDown(cls):
> >
> >
>
> > The above refers to functions you did not post.  For current unittest, it
> > looks likes you should be using a setUpModule (possible tearDownModule)
> > functions, but I don't know if those are available in the older
> unittest2.
>
>
> we have tearDownClass and setUpClass in python 2.6 and under unittest2
>
> >>> help(unittest2.TestCase.tearDownClass)
> Help on method tearDownClass in module unittest2.case:
>
> tearDownClass(cls) method of __builtin__.type instance
> Hook method for deconstructing the class fixture after running all
> tests in the class.
>
> >>> help(unittest2.TestCase.setUpClass)
> Help on method setUpClass in module unittest2.case:
>
> setUpClass(cls) method of __builtin__.type instance
> Hook method for setting up class fixture before running tests in the
> class.
>
> Regards,
> Ganesh
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Chris Angelico at 2016/1/11  UTC+8 10:59:47AM wrote:
> On Mon, Jan 11, 2016 at 12:59 PM,   wrote:
> > It lets you jump between the current cursor position and the line the upper 
> > level indentation start, something like the bracket matching in C editor. 
> > Because of Python use indentation as its code block mark, It might be 
> > helpful if we can jump between different level of it:-)
> 
> I coded this up as a patch for SciTE/Scintilla at one point, but it
> didn't get accepted. It was used for a while at my work, but never
> really settled in as being useful. Python code tends not to be as big
> and complex as C code often is, so it's not as useful to have a
> feature like this.
> 
> If you want it, I can probably hunt down the patch file somewhere.
> 
> ChrisA

I am studying the PyUSB package now as the learning object of how to write a 
Python program in a "formal" way. In those modules, there are many comment 
inserted between codes to explain what it does. It's good to the user 
comprehension, but also easily makes a Class size expanded to over 100 lines. 
Also many Classes has the same named method such as __getitem__ etc. When 
searching a specific name I usually have to roll back the screen a few times to 
find out what Class I am looking at. That's really annoy.

But, just like you said, this feature may be not so useful to a Python 
programmer. I should try the editor I am using now to see if I can "patch" a 
such feature, just as you had did on SciTE before:-)

--Jach

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


Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Tim Chase at 2016/1/11 UTC+8 11:16:27AM wrote:
> On 2016-01-10 17:59, [email protected] wrote:
> > It lets you jump between the current cursor position and the line
> > the upper level indentation start, something like the bracket
> > matching in C editor. Because of Python use indentation as its code
> > block mark, It might be helpful if we can jump between different
> > level of it:-)
> 
> While not quite what you're asking for, vim offers an "indent text
> object" plugin[1] that allows you to use a block of indentation
> around the cursor as an object.  So you can use vim's grammar to issue
> commands like "dai" to delete the current indentation-defined block;
> or you can use ">ii" to add a level of indentation to the
> indentation-defined block.

Thanks, Tim.
I always admire people who can remember all those detail 
commands/parameters/options which a DOS-style editor as vim has. It's almost 
like a mission impossible to me:-(

> If you want to make a vim mapping that will jump up to the top of the
> previous level of indentation, the following should do the trick
> 
>   :nnoremap  Q '?^'.repeat(' ', (strlen(substitute(getline('.'), 
> '\S.*', '', ''))-&sw)).'\S?e'."\"

But, but... this line??? won't it goes too far for a human being to read?

--Jach

> There might be some edge-cases that I haven't caught there, but, as
> long as you edit with spaces rather than tabs, it should work,
> including the accommodation of your 'shiftwidth', even if it's not
> PEP8 4-spaces-per-indent.
> 
> -tkc
> 
> [1]
> https://github.com/michaeljsmith/vim-indent-object

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


Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Gordon Levi at 2016/1/11 UTC+8 4:41:20PM wrote:
> Jetbrains Pycharm has "go to start of block" and "go to end of block"
> commands .

Thanks, Gordon. But this seems only jump between the current code block's start 
and end, not to the code one level above:-(

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


Re: Which Python editor has this feature?

2016-01-11 Thread Tim Chase
On 2016-01-11 03:08, [email protected] wrote:
> Tim Chase at 2016/1/11 UTC+8 11:16:27AM wrote:
> >   :nnoremap  Q '?^'.repeat(' ',
> > (strlen(substitute(getline('.'), '\S.*', '',
> > ''))-&sw)).'\S?e'."\"
> 
> But, but... this line??? won't it goes too far for a human being to
> read?

Yes, it's a bit obscure.  But it's a mapping that creates a "Q"
command (feel free to map to whatever other key you have available),
so once you've created that mapping (you can put it in your vimrc),
all you have to remember is that "Q", not the whole messy string.

-tkc





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


Re: Which Python editor has this feature?

2016-01-11 Thread Frank Haun
On Sun, 10 Jan 2016 19:49:47 -0800 (PST), Rustom Mody wrote:

> On Monday, January 11, 2016 at 7:30:10 AM UTC+5:30, [email protected] wrote:
>> It lets you jump between the current cursor position and the line the
>> upper level indentation start, something like the bracket matching in
>> C editor. Because of Python use indentation as its code block mark,
>> It might be helpful if we can jump between different level of it:-)
>> 
>> 
>> --Jach Fong
>
> Recent emacs' python mode has all these bunch of python-nav-*
> functions.  You may have (as usual with emacs!) to choose which you
> like best, ie not all are not bound to keys.

Emacs is great for python editing. I use elpy-mode on top of emacs
python-mode. And company-mode for completion.

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


Re: Python 3.4.4 Install

2016-01-11 Thread Colin W .
Steven D'Aprano  pearwood.info> writes:

> 
> On Sun, 10 Jan 2016 09:25 am, Colin J. Williams wrote:
> 
> > The reponse is not understood.
> > 
> > *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec  6 2015, 17:06:10) [MSC
> > v.1600 64 bit (AMD64)] on win32. ***
>    File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1
> > Öü:Vt‡Ö{ZðN)’ƒ2%hóýL"®ÁwÇ,”¿ƾJ
> >  ^
> > SyntaxError: invalid syntax
> 
> That doesn't look anything like Python code to me. It looks like you have
> corrupted files. Who knows how they have been corrupted. Try re-installing
> Pyscripter, or revert from backup. Also, you should make sure you scan your
> system for viruses (possibly you have a randsomware virus encrypting files
> behind your back) and do a disk check in case the disk is dying.
> 

I am now trying o install the binary version, 64 bit, of Python 3.4.4 from
Python.org.  I get the message:
   
Python 3.4.4 (64 bit)

 There is a problem with the Windows [10] Installer Package. A program 
  required for this install to complete could not be run.  Contact your
support personnel or package vendor.

Colin W.

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


Python installation in windows

2016-01-11 Thread navneet bhatele
I have been trying to install the  "python-3.5.1-amd64-webinstall "  many
times and the Set up failed is shown up with named 0*80070002 - file
doesn't exist in dialog box
-- 
https://mail.python.org/mailman/listinfo/python-list


Continously opening modify setup

2016-01-11 Thread Lucifer onetwothree
When ever i open pycharm there is a pop-up opening continously with
modify,repair,unistall options in it.even I've installed python correctly
and specified path correctly.
Please help me to sort this out.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Python 3.4.4 Install

2016-01-11 Thread Emanuel Barry
> Date: Sat, 9 Jan 2016 14:25:40 -0800
> Subject: Python 3.4.4 Install
> From: [email protected]
> To: [email protected]
> 
> The reponse is not understood.
Which response? Obviously Python's, but response to what? More context would be 
useful.
> *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec  6 2015, 17:06:10) [MSC 
> v.1600 64 bit (AMD64)] on win32. ***
> >>>   File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1
> Öü:V�t‡Ö{ZðN)’ƒ2%hóýL"®ÁwÇ,”¿ƾJ
>  ^
> SyntaxError: invalid syntax
>   File "C:\Users\Adm\AppData\Roaming\PyScripter\pyscripter_init.py", line 1
> Öü:V�t‡Ö{ZðN)’t—œ2¢í.�Tûôø«ÄØ´Õ7l‰ˆ(°¢äßÅ
>  ^
> SyntaxError: invalid syntax
What is this file, and where does it come from? What command are you issuing 
that gives you this result?
-- Emanuel

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


can't decompress data; zlib not available

2016-01-11 Thread loial
I am migrating a python script from Red hat linux REL 6.6 to AIX 7.1

I am using python 2.7.10

On AIX I the ror

zipimport.ZipImportError: can't decompress data; zlib not available

Any ideas how to get this to work on AIX?



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


RE: licenses

2016-01-11 Thread Martinez, Jorge Alberto (GE Aviation)
Thank you very much for your reply.

Best Regards


From: Cody Piersall [mailto:[email protected]]
Sent: Sunday, January 10, 2016 1:43 PM
To: [email protected]
Cc: Martinez, Jorge Alberto (GE Aviation)
Subject: Re: licenses

On Fri, Jan 8, 2016 at 1:41 PM, Martinez, Jorge Alberto (GE Aviation) 
mailto:[email protected]>> wrote:
>
> Hello
> We develop applications here with Python and I want to know if there's issues 
> by using.
> We use NumPy, PyDaqMx, Py Visa
>
> How can we cover this licensing?

I am not a lawyer, and this is not legal advice.
* NumPy is BSD-licensed, which means you can use NumPy in a commercial product 
as long as you include its license.
* PyDAQmx is BSD-licensed as well.  (You can find that information in their 
GitHub repository's README, 
https://github.com/clade/PyDAQmx)
* Py Visa is MIT licensed (info on their GitHub: 
https://github.com/hgrecco/pyvisa/blob/master/LICENSE),
 which means you can also use it in your software as long as you include the 
license.

For summaries of lots of licenses, you can look at 
tldrlegal.com.

* BSD license: 
https://tldrlegal.com/license/bsd-3-clause-license-(revised)
* MIT license: 
https://tldrlegal.com/license/mit-license

It's never a bad idea to consult a lawyer.  Since you work for GE, I would 
imagine there is an army of lawyers happy to answer this question at your 
disposal.  Finding out how to talk to them might be the hard part.

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


Re: can't decompress data; zlib not available

2016-01-11 Thread Alister

On 11/01/16 13:24, loial wrote:

I am migrating a python script from Red hat linux REL 6.6 to AIX 7.1

I am using python 2.7.10

On AIX I the ror

zipimport.ZipImportError: can't decompress data; zlib not available

Any ideas how to get this to work on AIX?




install the zlib library's (these are part of the OS & not Python)

on a red hat system try :
yum install  zlib

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


Re: Continously opening modify setup

2016-01-11 Thread Bernardo Sulzbach
This seems to be an issue with your PyCharm installation, not with
Python itself.

Also, this looks a lot like malware to me.

If you are sure it is not a problem with your (almost certainly
Windows) machine, consider contacting JetBrains.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove item from heap efficiently?

2016-01-11 Thread srinivas devaki
On Jan 11, 2016 12:18 AM, "Sven R. Kunze"  wrote:
> Indeed. I already do the sweep method as you suggested. ;)
>
> Additionally, you provided me with a reasonable condition when to do the
sweep in order to achieve O(log n). Thanks much for that. I currently used
a time-bases approached (sweep each 20 iterations).
>
> PS: Could you add a note on how you got to the condition (
2*self.useless_b > len(self.heap_b))?
>

oh that's actually simple,
that condition checks if more than half of heap is useless items.
the sweep complexity is O(len(heap)), so to keep the extra amortized
complexity as O(1), we have to split that work(virtually) with O(len(heap))
operations, so when our condition becomes true we have done len(heap)
operations, so doing a sweep at that time means we splitted that
work(O(len(heap))) with every operation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python installation in windows

2016-01-11 Thread Rustom Mody
On Monday, January 11, 2016 at 6:32:14 PM UTC+5:30, navneet bhatele wrote:
> I have been trying to install the  "python-3.5.1-amd64-webinstall "  many
> times and the Set up failed is shown up with named 0*80070002 - file
> doesn't exist in dialog box

Which windows?
XP and 3.5 are not compatible
For XP use 3.4
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: licenses

2016-01-11 Thread Grant Edwards
On 2016-01-10, Cody Piersall  wrote:

> It's never a bad idea to consult a lawyer.  Since you work for GE, I would
> imagine there is an army of lawyers

That is udoubtedly true.

>  happy to answer this question

Whether you can actually get an answer out of any of them within
before the expiry of the project is another issue entirely.

> at your disposal.  Finding out how to talk to them might be the hard
> part.

-- 
Grant Edwards   grant.b.edwardsYow! RELATIVES!!
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python installation in windows

2016-01-11 Thread Cameron Simpson

On 11Jan2016 07:19, rusi  wrote:

On Monday, January 11, 2016 at 6:32:14 PM UTC+5:30, navneet bhatele wrote:

I have been trying to install the  "python-3.5.1-amd64-webinstall "  many
times and the Set up failed is shown up with named 0*80070002 - file
doesn't exist in dialog box


Which windows?
XP and 3.5 are not compatible
For XP use 3.4


I am not a Windows user, but this question occurs a lot.

Is this cryptic message a missing dependency of the installer or of Python.  
Because if it is Python surely we should be doing potential users a favour and 
mentioning this 3.5 vs XP (and earlier?) issue in nice human friendly prose 
instead of complaining about an obscure missing library file?


As things stand, many users infer that they have a corrupt or broken download, 
not that they needed a different version of Python.


Should this be raised on python-dev?

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


python

2016-01-11 Thread Sean Melville
Hello,

I've downloaded python 3.5.1 but when I try and open it always says that I
have to either uninstall it, repair it or modify it. However, I've tried
all of them and it still doesn't work.

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


Re: python

2016-01-11 Thread Cameron Simpson

On 11Jan2016 19:17, Sean Melville  wrote:

I've downloaded python 3.5.1 but when I try and open it always says that I
have to either uninstall it, repair it or modify it. However, I've tried
all of them and it still doesn't work.


On what operating system are you trying to install it?

If you are using XP you need to download Python 3.4; Python 3.5 is not 
compatible with it.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: python

2016-01-11 Thread Sean Melville
I don't believe it's xp, it's a new laptop 



> On 11 Jan 2016, at 20:33, Cameron Simpson  wrote:
> 
>> On 11Jan2016 19:17, Sean Melville  wrote:
>> I've downloaded python 3.5.1 but when I try and open it always says that I
>> have to either uninstall it, repair it or modify it. However, I've tried
>> all of them and it still doesn't work.
> 
> On what operating system are you trying to install it?
> 
> If you are using XP you need to download Python 3.4; Python 3.5 is not 
> compatible with it.
> 
> Cheers,
> Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python editor has this feature?

2016-01-11 Thread Terry Reedy

On 1/11/2016 6:04 AM, [email protected] wrote:


I am studying the PyUSB package now as the learning object of how to
write a Python program in a "formal" way. In those modules, there are
many comment inserted between codes to explain what it does. It's
good to the user comprehension, but also easily makes a Class size
expanded to over 100 lines. Also many Classes has the same named
method such as __getitem__ etc. When searching a specific name I
usually have to roll back the screen a few times to find out what
Class I am looking at. That's really annoy.


IDLE has an optional 'code context' feature that shows header lines that 
have scrolled up off the top of the screen.  This would let you see 
which class you are in,


In current releases, Code Context is configured in the Extensions tab of 
the Settings dialog.  For previous releases after Aug 2014, it was 
configured in the separate Extensions dialog.


The most important setting is the (fixed) number of lines in the context 
box (default 3).  I would like to make the box re-size as needed, so the 
outermost context (like the class statement) is always visible without 
using more screen space than needed.


The context is currently read-only.  Clicking on context lines does 
nothing.  As a result of this thread, I am thinking that clicking on a 
context line should scroll up the main text window to display that line 
at the top (and remove that line and any below from the context box).  I 
*think* that this should be fairly easy.


--
Terry Jan Reedy

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


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

2016-01-11 Thread homiemusa
On Monday, December 28, 2015 at 12:39:41 PM UTC+3, Won Chang wrote:
> def manipulate_data(kind, data): 
> if kind == 'list': 
> return list(data)[::-1] 
> elif kind == 'set':
> return set(data)
> elif kind == 'dictionary': 
> return dict.keys(data) 
> manipulate_data("list", range(1,6)) 
> manipulate_data("set", {"a", "b", "c", "d", "e",}) 
> manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, 
> "grapes": 45})
> just use a function to add "ANDELA", "TIA", "AFRICA" to the set, the u are don


how con i add a fuction
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python

2016-01-11 Thread Thomas 'PointedEars' Lahn
Sean Melville wrote:

>> On 11 Jan 2016, at 20:33, Cameron Simpson  wrote:
>>> On 11Jan2016 19:17, Sean Melville  wrote:
>>> I've downloaded python 3.5.1 but when I try and open it always says that
>>> I have to either uninstall it, repair it or modify it. However, I've
>>> tried all of them and it still doesn't work.
>> 
>> On what operating system are you trying to install it?
>> 
>> If you are using XP you need to download Python 3.4; Python 3.5 is not
>> compatible with it.
> 
> I don't believe it's xp, it's a new laptop

You can quickly find out by pressing the key combination +.

Please do not top-post.  The bats are reading elsewhere ;-)


-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python

2016-01-11 Thread Terry Reedy

On 1/11/2016 2:17 PM, Sean Melville wrote:


I've downloaded python 3.5.1 but when I try and open it


You need to be more specific.  (Is 'it' the python installer or python 
program?)


1. What version of Windows, including 32/64 bit.  For pre-10, service 
packs matter (you should have the latest).


2. What installer did you download, from where?  There are, I believe, 6 
choices at python.org.


3. How did you run the installer?  Admin or normal user?  What options 
did you select.  Did the installer say 'finished' or 'error'.


4.  How you you try to run Python (if indeed you did)?  Be very specific 
here, as this may be the problem.


> always says that I

have to either uninstall it, repair it or modify it. However, I've tried
all of them and it still doesn't work.


You see this if you open the installer after installing.  You should not 
see this if you run python itself.  You will not see this if python is 
properly installed and you run python and not the installer.


--
Terry Jan Reedy

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


Re: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface"

2016-01-11 Thread Saran Ahluwalia
Hi Steven:

Just as an update - apparently there were bytes in the Windows Command
Terminal that were interrupting the process execution. I didn't realize
this was happening until I dug around Windows' Q&A forum.

Cheers

On Sun, Jan 10, 2016 at 12:53 PM, Saran Ahluwalia <
[email protected]> wrote:

> Hi Steven:
>
> The previous code was a stand along under the " if __name__ ==
> '__main__': ". The full function suite that I have made (and indeed
> includes a try and except block):
>
> import os.path
> import sys
> import csv
> from io import StringIO
> import xml.etree.cElementTree as ElementTree
> from xml.etree.ElementTree import XMLParser
> # import xml
> # import xml.sax
> # from xml.sax import ContentHandler
>
>
> def flatten_list(self, aList, prefix=''):
>
> for i, element in enumerate(aList, 1):
> eprefix = "{}{}".format(prefix, i)
> if element:
> # treat like dict
> if len(element) == 1 or element[0].tag != element[1].tag:
> yield from flatten_dict(element, eprefix)
> # treat like list
> elif element[0].tag == element[1].tag:
> yield from flatten_list(element, eprefix)
> elif element.text:
> text = element.text.strip()
> if text:
> yield eprefix[:].rstrip('.'), element.text
>
>
> def flatten_dict(parent_element, prefix=''):
>
> prefix = prefix + parent_element.tag
> if parent_element.items():
> for k, v in parent_element.items():
> yield prefix + k, v
> for element in parent_element:
> eprefix = element.tag
> if element:
> # treat like dict - we assume that if the first two tags
> # in a series are different, then they are all different.
> if len(element) == 1 or element[0].tag != element[1].tag:
> yield from flatten_dict(element, prefix=prefix)
> # treat like list - we assume that if the first two tags
> # in a series are the same, then the rest are the same.
> else:
> # here, we put the list in dictionary; the key is the
> # tag name the list elements all share in common, and
> # the value is the list itself
> yield from flatten_list(element, prefix=eprefix)
> # if the tag has attributes, add those to the dict
> if element.items():
> for k, v in element.items():
> yield eprefix+k
> # this assumes that if you've got an attribute in a tag,
> # you won't be having any text. This may or may not be a
> # good idea -- time will tell. It works for the way we are
> # currently doing XML configuration files...
> elif element.items():
> for k, v in element.items():
> yield eprefix+k
> # finally, if there are no child tags and no attributes, extract
> # the text
> else:
> yield eprefix, element.text
>
>
>
> def just_xml_data(path):
> with open(path, 'rU', encoding='UTF-8') as data:
> separated = data.read().split('","')
> print(separated)
> try:
> x = ElementTree.XML(separated[3])
> print(x)
> xml.etree.ElementTree.dump(x)
> y = ElementTree.XML(separated[4])
> xml.etree.ElementTree.dump(y)
> # response = ElementTree.XML(separated[4])  # work on the
> Response column
> # root = ElementTree.XML(response) #serialize and parse into
> XML object
> except Exception as e:
> print(e)
> else:
> xml_field = dict(flatten_dict(y))
> return xml_field
>
> def read_data(path):
> headers= set()
> rows = []
> with open(path, 'rU', encoding='utf-8') as data:
> reader = csv.DictReader(data, dialect=csv.excel,
> skipinitialspace=True)
> for row in reader:
> xml_field = row["CLIENT_RESP_DATA"]
> # xml_data = just_xml_data(xml_field) ## function
> if xml_data is not None:
> row.update(xml_data)
> headers.update(row.keys())
> rows.append(row)
> else:
> print("Failure")
> pass
> with open(os.path.splitext(textFile)[0] + '_' + 'parsed' + '.csv',
> "wt", newline='') as output_file:
> wr = csv.writer(output_file)
> csv_headers = list(headers)
> wr.writerow(csv_headers)
> for row in rows:
> values = []
> for field in csv_headers:
> value = row.get(field, None)
> values.append(value)
> wr.writerow(values)
> return output_file
>
>
>
> if __name__ == '__main__':
> Response = "s.csv"
> just_xml_data(Response)
>
>
> Hopefully this will provide you with enough information to emulate
> (apologies for any and all indentation 

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

2016-01-11 Thread homiemusa
On Tuesday, December 29, 2015 at 1:30:18 AM UTC+3, Cameron Simpson wrote:
> On 28Dec2015 01:34, Prince Udoka  wrote:
> >bu i have come up with a solution, that will work but encounter a problem in 
> >the set, giving set not manipulated correctly:
> >
> >def manipulate_data(kind, data):
> >if kind == 'list':
> >return list(data)[::-1]
> >elif kind == 'set':
> >return set(data)
> >elif kind == 'dictionary':
> >return dict.keys(data)
> >manipulate_data("list", range(1,6))
> >manipulate_data("set", {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"})
> >manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, 
> >"grapes": 45})
> >
> >the thing now is the function to use in adding "ANDELA", "TIA", "AFRICA"
> >pls 4give my use of language
> 
> You are very close. Let me remind you of the original task text:
> 
>   add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the 
>   resulting set
> 
> Your previous attempt (with hardwired values inside the function) actually 
> had 
> code to do it.
> 
> While you have pulled out all the hardwired values from the function (good) 
> and 
> put them in the external calls, note that the task explicitly says "add items 
> `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set". So _those_ values _are_ 
> supposed to be hardwired inside the function - they are a fixed part of the 
> task. So move them back in, as in your previous attempt.
> 
> There is some ambiguity in that part of the question: should you return a 
> _new_ 
> set consistint of the original set plus the three new values, or simply add 
> the 
> three values to the original set? Your prior code modified the original set, 
> which may fit the task specification.
> 
> However, it is a common design objective that functions do not, _normally_, 
> modify their arguments. So, consider this code:
> 
>   set1 = {"a", "b", "c", "d", "e"}
>   set2 = manipulate_data("set", set1)
> 
> After running this, set2 should look like this:
> 
>   {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"}
> 
> (in some order -- sets are not ordered). However, what about set1? In your 
> current code, set1 is modified, so it will be the same. But you can imagine 
> that it would be more useful for the caller if set1 were unchanged.
> 
> In python, the convention is usually that if a function returns the new value 
> then it should not modify the original. So you should probably construct a 
> copy 
> of the original set and modify that:
> 
>   data = set(data)
>   ... add the new values ...
>   return data
> 
> Cheers,
> Cameron Simpson 


please help me how can i add a function  to this code am a star
-- 
https://mail.python.org/mailman/listinfo/python-list


Confused by python-dbus weird behavior

2016-01-11 Thread Travis Griggs
This may not be a great list for this question (which would be?); it’s a big 
group, and I’m hoping there’s some people here that cross into these same areas.

I’m new to dbus, it seems it’s a sort of CORBA for the Linux world. :) Python 
seems to be a popular way to interact with it. I’m trying to interact with the 
BlueZ services for Bluetooth LE stuff, and the scant hints I can find seem to 
indicate dbus is the preferred way going forward. The BlueZ distribution even 
provides example code. That said, my question should be independent of whether 
this was BLE or a dbus interface for a Calculator program.

There is a class defined as such:

class Characteristic(dbus.service.Object):
def __init__(self, bus, index, uuid, flags, service):
# … set a bunch of attributes
dbus.service.Object.__init__(self, bus, self.path)

@dbus.service.method(GATT_CHRC_IFACE, in_signature='ay')
def WriteValue(self, value):
print('Default WriteValue called, returning error’)
raise NotSupportedException()

Then I have a subclass of my own:

class MyCharacteristic(Characteristic):
def __init__(self, bus, index, uuid, flags, service):
Characteristic.__init__(self, bus, index, uuid, flags, service)
# … set some of my own attributes

def WriteValue(self, value):
print(‘Got write value:’, value)
self.anotherMethod(value)
print(‘back from anotherMethod’)

def anotherMethod(self, value):
print(‘pondering this value:’, value)

My program does not call WriteValue directly. It seems to be called by the 
bluetooth machinery. The mainloop, or something like that. I don’t honestly 
know. I just know I use some other boilerplate code involving registration and 
the mainloop, to get it all running. And so the MyCharacteristic.WriteValue() 
method DOES get fired. I see the output. But when it gets to the anotherMethod 
call, it just seems to... not. More callbacks may fire later. But that’s the 
end of that one. I’ve tried this under python2 AND python3.

So my basic python-dbus question is: Is this some nuance where a callback 
method, inheriting from what looks like a proxy of some sort 
(dbus.service.Object) should/can not send messages to itself?

Help me python-obis, help me. You’re my only hope.


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


I'm missing something here...

2016-01-11 Thread Skip Montanaro
Here's a dumb little bit of code, adapted from a slightly larger script:

#!/usr/bin/env python

"dummy"

import glob
import os

def compare_prices(*_args):
"dummy"
return set()

def find_problems(cx1, cx2, cx3, prob_dates):
"dummy"
for fff in sorted(glob.glob("/path/to/*.nrm")):
sym = os.path.splitext(os.path.basename(fff))[0]
prob_dates |= compare_prices("E:%s"%sym, cx1, cx2, cx3)

When I run pylint against it, it complains:

junk.py:10: [W0613(unused-argument), find_problems] Unused argument 'prob_dates'

I must be misunderstanding something about the |= operator as applied
to sets. If I read the docs correctly, s1 |= s2 is equivalent to
s1.update(s2). A dumb "test" at the prompt suggests that's true:

>>> s1 = set("abc")
>>> s2 = set("cde")
>>> s1 | s2
set(['a', 'c', 'b', 'e', 'd'])
>>> s1 |= s2
>>> s1
set(['a', 'c', 'b', 'e', 'd'])
>>> s1 = set("abc")
>>> s1.update(s2)
>>> s1
set(['a', 'c', 'b', 'e', 'd'])

If I change the last line of find_problems to call
prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW)
complaining that the prob_dates argument of find_problems is unused
when I use the |= operator?

Thx,

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


Re: When I need classes?

2016-01-11 Thread Travis Griggs

> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach  
> wrote:
> 
> Essentially, classes (as modules) are used mainly for organizational purposes.
> 
> Although you can solve any problem you would solve using classes
> without classes, solutions to some big problems may be cheaper and
> more feasible using classes.

As a long term OO purist practitioner, I would add to this. Obviously, you can 
organize your code any way you want, with or without classes. You could put all 
your functions with an odd number of letters in one class, and all of the even 
numbered ones in another class. 

Having listened to the guy (Alan Kay) who coined the term (Object Oriented 
Programming) quite a bit over the years, I believe that the focus of OO (of 
which classes are a particular implementation approach) is to bind behavior to 
data. In “traditional” programming approaches, one focused on the algorithm 
(behavior) first, and then figured out what data needed to flow where to get 
the job done. Classes provided a mechanism to turn that equation, generally 
speaking, around. One thinks about the data first, and then figures out what 
behavior binds best to that data. And how that data will interact (inter-object 
behavior, often called messages) to get your job done. For some (many) 
problems, this can be a real win. And for some, not so much.

I think, this is often why, for a simple script, OO just kind of gets in the 
way. You have a straightforward procedure that you just want to do. The state 
(data) is not rich enough to make making it the focal point of your program.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm missing something here...

2016-01-11 Thread Erik

On 11/01/16 23:26, Skip Montanaro wrote:

If I change the last line of find_problems to call
prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW)
complaining that the prob_dates argument of find_problems is unused
when I use the |= operator?


Is it complaining about that, or is it because the 'for' loop body might 
be executed zero times?


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


Re: When I need classes?

2016-01-11 Thread Michael Torrie
On 01/11/2016 04:45 PM, Travis Griggs wrote:
> As a long term OO purist practitioner, I would add to this.
> Obviously, you can organize your code any way you want, with or
> without classes. You could put all your functions with an odd number
> of letters in one class, and all of the even numbered ones in another
> class.

And of course in Java you have to use classes for namespaces and
organization.  In python, the equivalent is simply a module.  It's
essentially a singleton object without having to do any boiler plate.  A
module can even keep state, so long as you only need to keep track of
one instance or set of states at a time.

> Having listened to the guy (Alan Kay) who coined the term (Object
> Oriented Programming) quite a bit over the years, I believe that the
> focus of OO (of which classes are a particular implementation
> approach) is to bind behavior to data. In “traditional” programming
> approaches, one focused on the algorithm (behavior) first, and then
> figured out what data needed to flow where to get the job done.
> Classes provided a mechanism to turn that equation, generally
> speaking, around. One thinks about the data first, and then figures
> out what behavior binds best to that data. And how that data will
> interact (inter-object behavior, often called messages) to get your
> job done. For some (many) problems, this can be a real win. And for
> some, not so much.
> 
> I think, this is often why, for a simple script, OO just kind of gets
> in the way. You have a straightforward procedure that you just want
> to do. The state (data) is not rich enough to make making it the
> focal point of your program.

The beauty of Python is that you can program procedurally, and still
work with objects as needed.  Every data type in Python is some kind of
object and you can call appropriate methods on those objects.  Even if
you do no OOP programming yourself.  For example,

some_string = "foo:bar"
(a,b) = some_string.split(':')

The ease with which Python can be used in many programming paradigms is
one reason I like Python so much.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python editor has this feature?

2016-01-11 Thread Chris Angelico
On Tue, Jan 12, 2016 at 8:21 AM, Terry Reedy  wrote:
>
> The context is currently read-only.  Clicking on context lines does nothing.
> As a result of this thread, I am thinking that clicking on a context line
> should scroll up the main text window to display that line at the top (and
> remove that line and any below from the context box).  I *think* that this
> should be fairly easy.

That'd be pretty cool.

Next IDLE feature request: Can you make it so that, across all
platforms, it magically installs PostgreSQL and psycopg2? That would
solve so many of my students' problems...

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


Re: I'm missing something here...

2016-01-11 Thread sohcahtoa82
On Monday, January 11, 2016 at 3:27:21 PM UTC-8, Skip Montanaro wrote:
> Here's a dumb little bit of code, adapted from a slightly larger script:
> 
> #!/usr/bin/env python
> 
> "dummy"
> 
> import glob
> import os
> 
> def compare_prices(*_args):
> "dummy"
> return set()
> 
> def find_problems(cx1, cx2, cx3, prob_dates):
> "dummy"
> for fff in sorted(glob.glob("/path/to/*.nrm")):
> sym = os.path.splitext(os.path.basename(fff))[0]
> prob_dates |= compare_prices("E:%s"%sym, cx1, cx2, cx3)
> 
> When I run pylint against it, it complains:
> 
> junk.py:10: [W0613(unused-argument), find_problems] Unused argument 
> 'prob_dates'
> 
> I must be misunderstanding something about the |= operator as applied
> to sets. If I read the docs correctly, s1 |= s2 is equivalent to
> s1.update(s2). A dumb "test" at the prompt suggests that's true:
> 
> >>> s1 = set("abc")
> >>> s2 = set("cde")
> >>> s1 | s2
> set(['a', 'c', 'b', 'e', 'd'])
> >>> s1 |= s2
> >>> s1
> set(['a', 'c', 'b', 'e', 'd'])
> >>> s1 = set("abc")
> >>> s1.update(s2)
> >>> s1
> set(['a', 'c', 'b', 'e', 'd'])
> 
> If I change the last line of find_problems to call
> prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW)
> complaining that the prob_dates argument of find_problems is unused
> when I use the |= operator?
> 
> Thx,
> 
> Skip

The pipe character on its own also functions as the binary OR operator, with x 
|= y being a shortcut for x = x | y.

If prob_dates is an integer, then it is immutable and the your prob_dates |= 
compare_prices(...) line won't do anything (The variable is being set, but 
never again read outside the function and it doesn't change the function's 
return value), which is probably what pylint is complaining about.  Pylint 
doesn't know that your function is expecting a mutable iterable for the 
prob_dates argument.

If you change it to prob_dates.update(...), does pylint complain?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm missing something here...

2016-01-11 Thread Terry Reedy

On 1/11/2016 6:26 PM, Skip Montanaro wrote:

Here's a dumb little bit of code, adapted from a slightly larger script:

#!/usr/bin/env python

"dummy"

import glob
import os

def compare_prices(*_args):
 "dummy"
 return set()

def find_problems(cx1, cx2, cx3, prob_dates):
 "dummy"
 for fff in sorted(glob.glob("/path/to/*.nrm")):
 sym = os.path.splitext(os.path.basename(fff))[0]
 prob_dates |= compare_prices("E:%s"%sym, cx1, cx2, cx3)

When I run pylint against it, it complains:

junk.py:10: [W0613(unused-argument), find_problems] Unused argument 'prob_dates'

I must be misunderstanding something about the |= operator as applied
to sets. If I read the docs correctly, s1 |= s2 is equivalent to
s1.update(s2). A dumb "test" at the prompt suggests that's true:


s1 = set("abc")
s2 = set("cde")
s1 | s2

set(['a', 'c', 'b', 'e', 'd'])

s1 |= s2
s1

set(['a', 'c', 'b', 'e', 'd'])

s1 = set("abc")
s1.update(s2)
s1

set(['a', 'c', 'b', 'e', 'd'])

If I change the last line of find_problems to call
prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW)
complaining that the prob_dates argument of find_problems is unused
when I use the |= operator?


A bug in pylint. It should treat both cases the same.


--
Terry Jan Reedy

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


Re: When I need classes?

2016-01-11 Thread Bernardo Sulzbach
On Mon, Jan 11, 2016 at 9:45 PM, Travis Griggs  wrote:
>
>> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach  
>> wrote:
>>
>> Essentially, classes (as modules) are used mainly for organizational 
>> purposes.
>>
>> Although you can solve any problem you would solve using classes
>> without classes, solutions to some big problems may be cheaper and
>> more feasible using classes.
>
> I think, this is often why, for a simple script, OO just kind of gets in the 
> way. You have a straightforward procedure that you just want to do. The state 
> (data) is not rich enough to make making it the focal point of your program.

Your answer is quite good. I am not a purist myself (when it comes to
Java and C++, I am never going to instantiate a Math class to get a
logarithm function), but I understand the value of OO from experience.
As I mentioned those "tuples and dictionaries" to pass data around, I
would like to add that when a single script has two kinds of tuples or
dictionaries, you may be better of using two different classes, as
having "dedicated" types simplifies project organization and
enhances readability.

I have never gone "seriously OO" with Python though. I never wrote
from scratch an application with more than 10 classes as far as I can
remember. However, I would suppose that the interpreter can handle
thousands of user-defined classes simultaneously.

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


Re: Which Python editor has this feature?

2016-01-11 Thread Bernardo Sulzbach
On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico  wrote:
>
> Next IDLE feature request: Can you make it so that, across all
> platforms, it magically installs PostgreSQL and psycopg2? That would
> solve so many of my students' problems...
>

Wouldn't this make the installer much bigger?

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


Re: I'm missing something here...

2016-01-11 Thread Skip Montanaro
Sorry, I should have been explicit. prob_dates (the actual argument of the
call) is a set. As far as I know pylint does no type inference, so pylint
can't tell if the LHS and RHS of the |= operator are appropriate, nor can
it tell if it has an update() method.

Before writing, I had more-or-less concluded I had hit a bug, but in my
experience when I hit something I think is a bug, it's not. It's me.
Terry's reply convinced me that I had hit something.

Something else just occurred to me. I should have tried disassembling the
two versions of the function. Here's the output near prob_dates.update()
call:

 14
​  ​
   62 LOAD_FAST3 (prob_dates)
 65 LOAD_ATTR6 (update)
 68 LOAD_GLOBAL  7 (compare_prices)
 71 LOAD_CONST   3 ('E:%s')
 74 LOAD_FAST5 (sym)
 77 BINARY_MODULO
 78 LOAD_FAST0 (cx1)
 81 LOAD_FAST1 (cx2)
 84 LOAD_FAST2 (cx3)
 87 CALL_FUNCTION4
 90 CALL_FUNCTION1

Here's how the |= version disassembles in that region:

 20
​  ​
 62 LOAD_FAST3 (prob_dates)
 65 LOAD_GLOBAL  6 (compare_prices)
 68 LOAD_CONST   3 ('E:%s')
 71 LOAD_FAST5 (sym)
 74 BINARY_MODULO
 75 LOAD_FAST0 (cx1)
 78 LOAD_FAST1 (cx2)
 81 LOAD_FAST2 (cx3)
 84 CALL_FUNCTION4
 87 INPLACE_OR
 88 STORE_FAST   3 (prob_dates)

I think what's throwing pylint is that last
​STORE_FAST. That tells pylint the argument is ignored.

I'll at least bring up the issue on the code-quality list.

Thanks,

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


Re: Which Python editor has this feature?

2016-01-11 Thread Chris Angelico
On Tue, Jan 12, 2016 at 11:55 AM, Bernardo Sulzbach
 wrote:
> On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico  wrote:
>>
>> Next IDLE feature request: Can you make it so that, across all
>> platforms, it magically installs PostgreSQL and psycopg2? That would
>> solve so many of my students' problems...
>>
>
> Wouldn't this make the installer much bigger?

Yes, and it's also completely and utterly inappropriate. But I am
seeing a lot of cool magic getting added to Idle. Since I met Python,
it's gone from being "well, yeah, Python *does* include a GUI, but
it's pretty unexciting compared to others" to "Python includes a
pretty decent editor, but it's (unsurprisingly) Python-specific, so I
don't use it for multilingual work".

Shout-out to Terry and the other Idle devs for the work they've put in. Thanks!

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


Re: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface"

2016-01-11 Thread Steven D'Aprano
On Tue, 12 Jan 2016 08:54 am, Saran Ahluwalia wrote:

> Hi Steven:
> 
> Just as an update - apparently there were bytes in the Windows Command
> Terminal that were interrupting the process execution. I didn't realize
> this was happening until I dug around Windows' Q&A forum.

Thanks for letting us know, I'm glad you've solved your problem to your
satisfaction, but now I'm curious as to what sort of bytes in the Windows
terminal could cause the symptoms you were seeing. Could you share the
link(s) you found that explain this?



-- 
Steven

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


Re: When I need classes?

2016-01-11 Thread Chris Angelico
On Tue, Jan 12, 2016 at 11:53 AM, Bernardo Sulzbach
 wrote:
> On Mon, Jan 11, 2016 at 9:45 PM, Travis Griggs  wrote:
>>
>>> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach  
>>> wrote:
>>>
>>> Essentially, classes (as modules) are used mainly for organizational 
>>> purposes.
>>>
>>> Although you can solve any problem you would solve using classes
>>> without classes, solutions to some big problems may be cheaper and
>>> more feasible using classes.
>>
>> I think, this is often why, for a simple script, OO just kind of gets in the 
>> way. You have a straightforward procedure that you just want to do. The 
>> state (data) is not rich enough to make making it the focal point of your 
>> program.
>
> Your answer is quite good. I am not a purist myself (when it comes to
> Java and C++, I am never going to instantiate a Math class to get a
> logarithm function), but I understand the value of OO from experience.
> As I mentioned those "tuples and dictionaries" to pass data around, I
> would like to add that when a single script has two kinds of tuples or
> dictionaries, you may be better of using two different classes, as
> having "dedicated" types simplifies project organization and
> enhances readability.
>

Yeah. One thing I often recommend, especially to students, is to start
with the very simplest and most naive code they can knock together,
and then look at making it tidier afterwards. Classes, decorators, the
unittest setUp/tearDown methods, and even functions themselves, are
all just ways of improving code that could be written some other way.
They're not rigid structures that you HAVE to comply with or your code
is *just* *not* *good* *enough*. So start simplistic, and then look
into it like this: "Hey, see how you're doing this five times? There
HAS to be a better way!" (With acknowledgement to Raymond Hettinger.)

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


Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Terry Reedy at 2016/1/12 UTC+8 5:22:35AM wrote:
> IDLE has an optional 'code context' feature that shows header lines that 
> have scrolled up off the top of the screen.  This would let you see 
> which class you are in,

Thanks, Terry. It's just what I am looking for:-)
By the way, do you know how to open file in a new tab, instead of in a separate 
window, in the IDLE editor?

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


Re: How to remove item from heap efficiently?

2016-01-11 Thread Cem Karan

On Jan 11, 2016, at 9:53 AM, srinivas devaki  wrote:

> On Jan 11, 2016 12:18 AM, "Sven R. Kunze"  wrote:
>> Indeed. I already do the sweep method as you suggested. ;)
>> 
>> Additionally, you provided me with a reasonable condition when to do the
> sweep in order to achieve O(log n). Thanks much for that. I currently used
> a time-bases approached (sweep each 20 iterations).
>> 
>> PS: Could you add a note on how you got to the condition (
> 2*self.useless_b > len(self.heap_b))?
>> 
> 
> oh that's actually simple,
> that condition checks if more than half of heap is useless items.
> the sweep complexity is O(len(heap)), so to keep the extra amortized
> complexity as O(1), we have to split that work(virtually) with O(len(heap))
> operations, so when our condition becomes true we have done len(heap)
> operations, so doing a sweep at that time means we splitted that
> work(O(len(heap))) with every operation.

Jumping in late, but...

If you want something that 'just works', you can use HeapDict:

http://stutzbachenterprises.com/

I've used it in the past, and it works quite well.  I haven't tested its 
asymptotic performance though, so you might want to check into that.

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


Re: How to remove item from heap efficiently?

2016-01-11 Thread srinivas devaki
On Jan 10, 2016 12:05 AM, "Paul Rubin"  wrote:
>
> You could look up "timing wheels" for a simpler practical approach that
> the Linux kernel scheduler used to use (I think it changed a few years
> ago).

this is not related to OP's topic

I googled about "timing wheels" and "Linux kernel scheduler", I couldn't
find any learning resources or at least the resources that I can
understand. Could you please point me to some learning resources for a
beginner.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove item from heap efficiently?

2016-01-11 Thread Paul Rubin
srinivas devaki  writes:
> I googled about "timing wheels" and "Linux kernel scheduler"

Sorry, correct term was "timer wheel" rather than "timing wheel".

http://www.elinux.org/Kernel_Timer_Systems has some links.

The Erlang BEAM internal scheduler works the same way, iirc.

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


OT: There are no words for how broken everything is

2016-01-11 Thread Steven D'Aprano
There are no words to explain just how broken everything is. This post 
tries:

https://medium.com/message/everything-is-broken-81e5f33a24e1

but barely covers even a fraction of the breakage.

Thanks goodness for anti-virus, right?

One of the leading anti-virus vendors in the world, TrendMicro, has been 
opening their victims^W users' computers to trivially-discoverable remote 
execution attacks, exposing passwords to the internet, and running an old 
and insecure browser with security settings disabled (no sandbox).

https://code.google.com/p/google-security-research/issues/detail?id=693


What's the worst security screw-up you've seen? The worst I've seen was a 
sys admin I used to work with who put a new Linux server on the internet 
with root ssh enabled. Guess what password he used for the root account? 
"test". Guess how long it took before it was broken into? Less than two 
hours.

That is at the top of my list only because I can prove exactly what 
happened. Otherwise it would be an incident that I can't completely explain. 
I have my suspicions, but I'm not entire sure what happened.

This was one of the last incidents that drove me off Windows. I was running 
Windows XP, protected behind a firewall, with commercial up-to-date anti-
virus installed. I started up Windows update one day, and went out for a few 
hours, and came back to find the computer absolutely swarming with malware 
and the firewall turned off. I don't know what happened, I can only guess 
that the Windows update process turned off the firewall, but I don't really 
know. All I know is that whatever it was, it was a completely automated 
attack, as nobody was home to click on any buttons or visit any dubious 
websites.

Took me three weeks to remove the last of the malware, and another two weeks 
to track down the cause of an annoying glitch where every 30 seconds the PC 
would freeze up for a fraction of a second. It was one of the anti-virus 
programs I had installed.



-- 
Steve

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


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

2016-01-11 Thread ifeanyioprah
Please how did you back it to move over to the next question pls need your help
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-01-11 Thread ifeanyioprah
How do I use hack to move to the next question
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-01-11 Thread ifeanyioprah
How do I use hack to move to the next question
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-01-11 Thread ifeanyioprah
How do I use hack to move to the next question
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: There are no words for how broken everything is

2016-01-11 Thread Rick Johnson
On Monday, January 11, 2016 at 10:26:40 PM UTC-6, Steven D'Aprano wrote:
> [...]
> Took me three weeks to remove the last of the malware, and another two weeks 
> to track down the cause of an annoying glitch where every 30 seconds the PC 
> would freeze up for a fraction of a second. It was one of the anti-virus 
> programs I had installed.

Three weeks??? Dude, you could have rebuilt the system in a few hours! :-) But 
this is *WAY* off topic. Hey Steven, they have these new inventions now called 
"blogs", maybe you should sign up for one? Heck, *I* even have a blog now!

  http://arantadaykeepsthemonstersaway.blogspot.com/

PS: And there's an nice Easter Egg on my google profile you might enjoy. *wink*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm missing something here...

2016-01-11 Thread Cameron Simpson

On 11Jan2016 23:55, Erik  wrote:

On 11/01/16 23:26, Skip Montanaro wrote:

If I change the last line of find_problems to call
prob_dates.update(), the message disappears. Why is pylint (1.4.2 BTW)
complaining that the prob_dates argument of find_problems is unused
when I use the |= operator?


Is it complaining about that, or is it because the 'for' loop body might be 
executed zero times?


The former. Almost any loop _might_ be executed zero times. Compilers and 
linters etc should only complain if they can prove the loop is always executed 
zero times.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


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

2016-01-11 Thread mrkimanindegwa
On Saturday, December 12, 2015 at 12:05:29 PM UTC+3, 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.
> 
> 
> 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')



I would try.

class BankAccount:
def __init__(self,balance):
self.balance=balance
def deposit(self):
print("Please enter ammount to deposit")
dep=input()
global depbalance
depbalance=int(self.balance)+int(dep)
print("New balance is",depbalance)

def withdraw(self):
print("Please enter ammount to withdraw")
withd=input()
if int(withd) > int(depbalance):
print("Invalid Transaction")
else:
withbalance= depbalance-int(withd)
print("New balance after widthdrawal is",withbalance)

myAccount=BankAccount(0)
myAccount.deposit()
myAccount.withdraw()

class minimumBalanceAccount(BankAccount):
def msg(self):
print("This is a sub class")

mini=minimumBalanceAccount(0)
mini.msg()
mini.deposit()
mini.withdraw()

It may not be as fancy.
Although i dont understand the relevance of the test part in your question


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


Re: Which Python editor has this feature?

2016-01-11 Thread Terry Reedy

On 1/11/2016 8:51 PM, [email protected] wrote:

Terry Reedy at 2016/1/12 UTC+8 5:22:35AM wrote:

IDLE has an optional 'code context' feature that shows header lines that
have scrolled up off the top of the screen.  This would let you see
which class you are in,


Thanks, Terry. It's just what I am looking for:-)
By the way, do you know how to open file in a new tab, instead of in a separate 
window, in the IDLE editor?


Revamping IDLE to 1. use ttk widgets and 2. become a modern single 
window app with multiple panes, including a tabbed editor pane, is a 
goal for 2016.



--
Terry Jan Reedy

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