Re: Passing a list into a list .append() method

2014-09-08 Thread Frank Millman

"JBB"  wrote in message 
news:loom.20140909t073428-...@post.gmane.org...
>I have a list with a fixed number of elements which I need to grow; ie. add
> rows of a fixed number of elements, some of which will be blank.
>
> e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['',
> 'bb', 'binky', ''], ... ]
>
> This is a reduced representation of a larger list-of-lists problem that 
> had
> me running in circles today.
>
> I think I figured out _how_ to get what I want but I am looking to
> understand why one approach works and another doesn't.
>
[...]
>
> Next, I tried passing it as list(tuple(blank_r)) which worked.  Then, I
> finally settled on 2) where I dispensed with the tuple conversion.
>

I am sure that someone will give you a comprehensive answer, but here is a 
quick clue which may be all you need.

>>> x = [1, 2, 3]
>>> id(x)
16973256
>>> y = x
>>> id(y)
16973256
>>> z = list(x)
>>> id(z)
17004864

Wrapping a list with 'list()' has the effect of making a copy of it.

This is from the docs (3.4.1) -

"""
Lists may be constructed in several ways:

- Using a pair of square brackets to denote the empty list: []
- Using square brackets, separating items with commas: [a], [a, b, c]
- Using a list comprehension: [x for x in iterable]
- Using the type constructor: list() or list(iterable)

The constructor builds a list whose items are the same and in the same order 
as iterable's items.
iterable may be either a sequence, a container that supports iteration, or 
an iterator object.
If iterable is already a list, a copy is made and returned, similar to 
iterable[:]. [*]
For example, list('abc') returns ['a', 'b', 'c'] and list( (1, 2, 3) ) 
returns [1, 2, 3].
If no argument is given, the constructor creates a new empty list, [].
"""

I marked the relevant line with [*]

HTH

Frank Millman



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


Passing a list into a list .append() method

2014-09-08 Thread JBB
I have a list with a fixed number of elements which I need to grow; ie. add
rows of a fixed number of elements, some of which will be blank.  

e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['',
'bb', 'binky', ''], ... ]

This is a reduced representation of a larger list-of-lists problem that had
me running in circles today.  

I think I figured out _how_ to get what I want but I am looking to
understand why one approach works and another doesn't.

1) What does NOT work as desired:

proc_file = []
proc_file = [['a','b','c','d']]
proc_file.append(['A','B','C','D'])
blank_r = ['','','','']

qq = ['aa','bb','cc','dd']
rr = ['inky', 'binky', 'pinky', 'clyde']

for i,j in enumerate(zip(qq,rr)):
proc_file.append((blank_r))  # Add a row of blanks
proc_file[i+2][1] = j[0]
proc_file[i+2][2] = j[1]
print len(proc_file), blank_r, proc_file

print
print
proc_file

3 ['', 'aa', 'inky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['',
'aa', 'inky', '']]
4 ['', 'bb', 'binky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['',
'bb', 'binky', ''], ['', 'bb', 'binky', '']]
5 ['', 'cc', 'pinky', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['',
'cc', 'pinky', ''], ['', 'cc', 'pinky', ''], ['', 'cc', 'pinky', '']]
6 ['', 'dd', 'clyde', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['',
'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['', 'dd', 'clyde', ''], ['',
'dd', 'clyde', '']]


Out[82]:

[['a', 'b', 'c', 'd'],
 ['A', 'B', 'C', 'D'],
 ['', 'dd', 'clyde', ''],
 ['', 'dd', 'clyde', ''],
 ['', 'dd', 'clyde', ''],
 ['', 'dd', 'clyde', '']]

2) What works as desired:

proc_file = []
proc_file = [['a','b','c','d']]
proc_file.append(['A','B','C','D'])
blank_r = ['','','','']

qq = ['aa','bb','cc','dd']
rr = ['inky', 'binky', 'pinky', 'clyde']

for i,j in enumerate(zip(qq,rr)):
proc_file.append(list(blank_r))  # Change it to list(blank_r) and it works
proc_file[i+2][1] = j[0]
proc_file[i+2][2] = j[1]
print len(proc_file), blank_r, proc_file

print
print
proc_file

3 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa',
'inky', '']]
4 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa',
'inky', ''], ['', 'bb', 'binky', '']]
5 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa',
'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', '']]
6 ['', '', '', ''] [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['', 'aa',
'inky', ''], ['', 'bb', 'binky', ''], ['', 'cc', 'pinky', ''], ['', 'dd',
'clyde', '']]


Out[83]:

[['a', 'b', 'c', 'd'],
 ['A', 'B', 'C', 'D'],
 ['', 'aa', 'inky', ''],
 ['', 'bb', 'binky', ''],
 ['', 'cc', 'pinky', ''],
 ['', 'dd', 'clyde', '']]

 Due diligence

I've read extensively on how arguments are passed to functions but I don't
think they are completely applicable here (though interesting nevertheless)

http://www.jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/


https://www.udacity.com/wiki/common-python-pitfalls

and others.

It looks like .append binds blank_r to proc_file in 1).  I change proc_file
and blank_r changes along with it.  Should I expect this? I understand lists
are mutable but I didn't expect that they could be associated/bound in this
manner.

I first tried "protecting" blank_r by passing it as a tuple.  That caused an
expected mismatch error.

Next, I tried passing it as list(tuple(blank_r)) which worked.  Then, I
finally settled on 2) where I dispensed with the tuple conversion.







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


Re: pip install PyOpenGL have problem

2014-09-08 Thread Michael Torrie
On 09/08/2014 08:18 PM, Michael Torrie wrote:
> On 09/06/2014 11:15 PM, วรรณพงษ์ ภัททิยไพบูลย์ wrote:
>> pip install -U PyOpenGL PyOpenGL_accelerate 
>> :(
> 
> I don't recognize that particular error message...
> 
> If you require assistance you need to copy and paste the output from the
> command so people can know exactly what failed.

You might try googling as well:

https://www.google.ca/search?q=python3+pip+windows

There seems to be a number of pages that talk about installing pip if
it's not there (using easy_install if I recall correctly).

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


Re: weakref, memory management and execution slow down in PyQt4

2014-09-08 Thread kjs
Thanks for the consideration Michael. If you do get the data, and are
able to run the code, let me know if you notice anything interesting.


Michael Torrie:
> On 09/07/2014 02:39 PM, kjs wrote:
>> The code is minimal[0]. The only other widgets are a start button that
>> fires off the plotting and a stop button that calls sys.exit().
> 
> Unfortunately there are no data files in your git repository so I can't
> run it.

The data is available from the internet[0] in the form of 3+GB gziped
blobs. In case you don't want to register an account with Kaggle and
download 3GB to execute the code, I have uploaded a sample file to a
Tahoe LAFS grid accessible via tor. If you're interested in downloading
the data, please let me know and I'll share the read capability with
you. Additionally, I should write some tests the use mock data. I'll let
you know if I get around to this.

> 
>>
>> Lines 112-114 appear to be causing the weakref proliferation.
> 
> Is there a reason you are using setattr and getattr instead of a proper
> data structure?  both of those calls are rather expensive.  Would
> probably be cheaper to use some kind of array, dictionary, or other
> purpose-built data structure?
> 

You're right, a dictionary can do everything I need and more. This
happened to be the first thing I thought of, and I didn't imagine it
would be very expensive. I figured it was simply a different way of
defining and retrieving a class variable. IE setattr(self, foo, True) ==
self.foo = True.

Thanks,
Kevin

[0] http://www.kaggle.com/c/seizure-prediction/data


0x8A61431E.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Python 3

2014-09-08 Thread Ned Deily
In article 
,
 Ashley Forman  wrote:
>   My name is Ashley Forman, and I am emailing because I cannot install
> python onto my Mac laptop! I have installed Active-TCl 8.5 along with
> Python 3.3 and tried with 3.4, and couldn't figure out a solution to my
> problem. When I click on IDLE to open, it does not open at all. Therefore,
> if you have any information that could help me, then I would really
> appreciate it! Thank you!

Clicking on the IDLE icon is fine - unless it is doesn't work, in which 
case error messages associated with the failure may end up in a system 
log rather than being display directly to you.  It's easier to debug 
problems like this by launching IDLE from a terminal session than by 
double-clicking on it.  Assuming you installed Python 3.4 (3.4.1 is 
current) from one of the python.org installers, open a terminal shell 
window, for example by using the Terminal.app (found in 
/Applications/Utilities).  Then, in the shell window, try typing:

/usr/local/bin/idle3.4 

If IDLE fails, there should be some sort of error message in the 
terminal window.  If it is not clear what the problem is, copy and paste 
them to the group here.

You can also just try launching Python itself and verify that it works 
without IDLE:

/usr/local/bin/python3.4

Good luck!

-- 
 Ned Deily,
 n...@acm.org

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


Re: pip install PyOpenGL have problem

2014-09-08 Thread Michael Torrie
On 09/06/2014 11:15 PM, วรรณพงษ์ ภัททิยไพบูลย์ wrote:
> pip install -U PyOpenGL PyOpenGL_accelerate 
> :(

I don't recognize that particular error message...

If you require assistance you need to copy and paste the output from the
command so people can know exactly what failed.

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


Re: Newer Debian versions of python on older Debian distros?

2014-09-08 Thread Chris Angelico
On Tue, Sep 9, 2014 at 5:04 AM, Travis Griggs  wrote:
> Does anyone have experience with using newer versions of python debian 
> packages (in particular, python3 and python3-bson-ext from ‘testing’) on 
> older stable versions (‘wheezy’ in this case)? If someone’s figured out how 
> to do this easily, I’d love to hear the recipe!
>

I don't know about grabbing from testing, because that's fraught with
peril... but there's a pretty easy way to get a newer Python: build
from source. Basically, the standard incantation:

$ sudo apt-get build-dep python3
$ hg clone http://hg.python.org/cpython
$ cd cpython
$ ./configure && make && sudo make install

(I like to separate the last three steps, but putting them together works too.)

Alternatively, you could just run Debian Jessie. I have a few Jessie
systems on the network, with a Python 3.4 IIRC, and there've been no
stability problems lately. Both options are pretty easy.

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


Re: weakref, memory management and execution slow down in PyQt4

2014-09-08 Thread Michael Torrie
On 09/07/2014 02:39 PM, kjs wrote:
> The code is minimal[0]. The only other widgets are a start button that
> fires off the plotting and a stop button that calls sys.exit().

Unfortunately there are no data files in your git repository so I can't
run it.

> 
> Lines 112-114 appear to be causing the weakref proliferation.

Is there a reason you are using setattr and getattr instead of a proper
data structure?  both of those calls are rather expensive.  Would
probably be cheaper to use some kind of array, dictionary, or other
purpose-built data structure?
-- 
https://mail.python.org/mailman/listinfo/python-list


Installing Python 3

2014-09-08 Thread Ashley Forman
Hello,
  My name is Ashley Forman, and I am emailing because I cannot install
python onto my Mac laptop! I have installed Active-TCl 8.5 along with
Python 3.3 and tried with 3.4, and couldn't figure out a solution to my
problem. When I click on IDLE to open, it does not open at all. Therefore,
if you have any information that could help me, then I would really
appreciate it! Thank you!
Best,
Ashley Forman
-- 
https://mail.python.org/mailman/listinfo/python-list


Newer Debian versions of python on older Debian distros?

2014-09-08 Thread Travis Griggs
(I realize that this may be seen as off topic for as a general python question, 
but given my historical experience with the Debian community’s predilection to 
answer all questions with a grumpy “go read the very very very very large and 
ever shifting fine manual”, I’m hoping for better luck here.)

Does anyone have experience with using newer versions of python debian packages 
(in particular, python3 and python3-bson-ext from ‘testing’) on older stable 
versions (‘wheezy’ in this case)? If someone’s figured out how to do this 
easily, I’d love to hear the recipe!

TIA


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


Re: "We made from water every living thing"...

2014-09-08 Thread David H. Lipman

From: "Chris Angelico" 


On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau  wrote:

I don't think allowing people to be disrespectful because they
accessed the forum in a different way is a good idea. I'd rather we
all just be nice.


May I just point out that lots of us didn't even see the original
post? If "Tony the Tiger" hadn't bothered to quote it, it would
quietly have dropped into oblivion. Let's let this thread finish and
have done with the whole matter.

ChrisA


That true.

One should *never* quote spam.

--
Dave
Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk
http://www.pctipp.ch/downloads/dl/35905.asp
--
https://mail.python.org/mailman/listinfo/python-list


Re: "We made from water every living thing"...

2014-09-08 Thread Grant Edwards
On 2014-09-08, Gene Heskett  wrote:
> On Monday 08 September 2014 09:06:46 Chris Angelico did opine
> And Gene did reply:
>> On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau  wrote:
>>
>> > I don't think allowing people to be disrespectful because they
>> > accessed the forum in a different way is a good idea. I'd rather we
>> > all just be nice.
>> 
>> May I just point out that lots of us didn't even see the original
>> post? If "Tony the Tiger" hadn't bothered to quote it, it would
>> quietly have dropped into oblivion. Let's let this thread finish and
>> have done with the whole matter.
>
> I am with you on that Chris, nothing with googlegroups in a header last 
> long enough to even be seen by fetchmail, its in a mailfilter rule and 
> gets nuked on the server.  And life is much simpler.

I plonked everything coming from Google Groups years ago. I never
regretted it for a second, and can recommend doing so without
reservation.  All you have to do is toss anything with a Message-ID
ending in googlegroups.com. For the benefit of anybody using slrn to
read the Usenet group (or presumably reading the mailing list via
gmane), here's the .score file rule:

[*]
Score:: =-
 Message-ID: .*googlegroups.com
 
-- 
Grant Edwards   grant.b.edwardsYow! Now KEN and BARBIE
  at   are PERMANENTLY ADDICTED to
  gmail.comMIND-ALTERING DRUGS ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "We made from water every living thing"...

2014-09-08 Thread Gene Heskett
On Monday 08 September 2014 09:06:46 Chris Angelico did opine
And Gene did reply:
> On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau  wrote:
> > I don't think allowing people to be disrespectful because they
> > accessed the forum in a different way is a good idea. I'd rather we
> > all just be nice.
> 
> May I just point out that lots of us didn't even see the original
> post? If "Tony the Tiger" hadn't bothered to quote it, it would
> quietly have dropped into oblivion. Let's let this thread finish and
> have done with the whole matter.
> 
> ChrisA

I am with you on that Chris, nothing with googlegroups in a header last 
long enough to even be seen by fetchmail, its in a mailfilter rule and 
gets nuked on the server.  And life is much simpler.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "We made from water every living thing"...

2014-09-08 Thread Mark Lawrence

On 08/09/2014 14:06, Chris Angelico wrote:

On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau  wrote:

I don't think allowing people to be disrespectful because they
accessed the forum in a different way is a good idea. I'd rather we
all just be nice.


May I just point out that lots of us didn't even see the original
post? If "Tony the Tiger" hadn't bothered to quote it, it would
quietly have dropped into oblivion. Let's let this thread finish and
have done with the whole matter.

ChrisA



+1

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

Mark Lawrence

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


Re: "We made from water every living thing"...

2014-09-08 Thread Chris Angelico
On Mon, Sep 8, 2014 at 10:41 PM, Joshua Landau  wrote:
> I don't think allowing people to be disrespectful because they
> accessed the forum in a different way is a good idea. I'd rather we
> all just be nice.

May I just point out that lots of us didn't even see the original
post? If "Tony the Tiger" hadn't bothered to quote it, it would
quietly have dropped into oblivion. Let's let this thread finish and
have done with the whole matter.

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


Re: "We made from water every living thing"...

2014-09-08 Thread Joshua Landau
On 8 September 2014 12:54, David H. Lipman  wrote:
> From: "Ned Batchelder" 
>> On 9/7/14 5:41 PM, Tony the Tiger wrote:
>>
>>> Now, kindly get the fuck outta here, you fucking retard!
>>>
>> That was unnecessary, ineffective, and totally outside the bounds of this
>> community's norms: http://www.python.org/psf/codeofconduct
>
> The Python.Org CoC does not extend to Usenet unless a FAQ is properly
> published for news:comp.lang.python

I don't think allowing people to be disrespectful because they
accessed the forum in a different way is a good idea. I'd rather we
all just be nice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "We made from water every living thing"...

2014-09-08 Thread David H. Lipman

From: "Ned Batchelder" 


On 9/7/14 5:41 PM, Tony the Tiger wrote:


Now, kindly get the fuck outta here, you fucking retard!

  /Grrr

That was unnecessary, ineffective, and totally outside the bounds of this 
community's norms: http://www.python.org/psf/codeofconduct


Behave.




He posted via Astraweb to Usenet.  He is not using GMane or a listserver.

The Python.Org CoC does not extend to Usenet unless a FAQ is properly 
published for news:comp.lang.python


You need to filter out Google Groupers who are the cause of spam and abuse.


--
Dave
Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk
http://www.pctipp.ch/downloads/dl/35905.asp 


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


Re: How to turn a string into a list of integers?

2014-09-08 Thread Terry Reedy

On 9/8/2014 1:44 AM, Marko Rauhamaa wrote:

Chris Angelico :


The original question was regarding storage - how PEP 393 says that
strings will be encoded in memory in any of three ways (Latin-1,
UCS-2/UTF-16, or UCS-4/UTF-32). But even in our world, that is not
what a string *is*, but only what it is made of.


I'm a bit surprised that kind of CPython implementation detail would go
into a PEP. I had thought PEPs codified Python independently of CPython.


There are multiple PEP that are not strictly about Python the language: 
meta-peps, informational peps, and others about the cpython api, 
implementation, and distribution issues. 393 is followed by

397  Python launcher for Windows  Hammond, v. Löwis
http://legacy.python.org/dev/peps/

The PEP process is a tool for the core development team and the product 
is documentation of decisions and actions thereby



But maybe CPython is to Python what England is to the UK: even the
government is having a hard time making a distinction.


We don't.

--
Terry Jan Reedy


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


Re: weakref, memory management and execution slow down in PyQt4

2014-09-08 Thread kjs


Michael Torrie:
> On 09/07/2014 01:11 PM, kjs wrote:
>> Thanks for the advice. I commented out the graph generation and PyQt call
>>
> self.app.processEvents()
>>
>> where in the class __init__
>>
> self.app = QtGui.QApplication(sys.argv)
>>
>> This stopped the weakref proliferation. All other objects grow and
>> shrink in number as expected.
> 
> Can you make an absolute minimal example with no widgets save the graph
> itself?  You could then go to the PyQt folks with that.  Could be a bug,
> or could be an improper use of something by your code.  This is one of
> the problems with using Qt in other languages: it's not a perfect fit
> for Python's object model as it is C++-based.  So you have to think like
> a C++ programmer, and you might have to manage some resources manually,
> unlike normal Python objects which for the most part take care of
> themselves.
> 

The code is minimal[0]. The only other widgets are a start button that
fires off the plotting and a stop button that calls sys.exit().

Lines 112-114 appear to be causing the weakref proliferation.

I do not doubt that I could be using PyQt4 incorrectly. I'll send a
message to the pyqt mailing list as well.

> Also you could try a minimal example using PySide instead of PyQt and
> see if that also manifests the leak.  If so, then the problem could be
> in Qt itself.  Though I suspect the problem is some kind of impedance
> mismatch between C++ and Python.
> 

Thanks much,
Kevin

[0]
https://github.com/kevinjos/kaggle-aes-seizure-prediction/blob/master/explore.py


0x8A61431E.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list