Re: instance as module

2015-06-20 Thread Steven D'Aprano
On Fri, 19 Jun 2015 07:29 pm, Robin Becker wrote:

> I'm trying to overcome a recursive import issue in reportlab.
> 
> Module reportlab.rl_config uses various sources (eg ~/.reportlab_settings)
> to initialize various defaults eg canvas_basefontname. If a user wants to
> utilize reportlab to set up such a default, it's not possible to do so in
> the settings file because a recursive import would occur. Normal defaults
> are always primitive python objects eg float/int/str etc etc.

I'm afraid I don't understand what you are trying to say here. Why can't the
user just set up "such a default" e.g. canvas_basefontname. Surely that is
a string, e.g. "Comic Sans".

Why will a recursive import occur? If the user doesn't want a recursive
import, they need only ensure that they don't import anything that relies
on rl_config.


> If I make the rl_config module into an object

I'd just like to point out that modules are already objects.

py> import sys
py> isinstance(sys, object)
True



> (using the GvR blessed approach indicated here
> http://stackoverflow.com/questions/2447353/getattr-on-a-module) then I can
> use callables in the settings module and get them evaluated lazily which
> overcomes the recursion.
> 
> Are there any gotcha's that need to be considered when using this instance
> as module approach? My trial implementation seems to work, but it's not
> clear exactly how a module differs from an instance. 

Um, precisely the same way an int or a str or an instance of Foo class
differs from an instance. An instance of what?

> I have set various 
> dunders on the instance eg __file__, __doc__, __all__ & __name__ and I
> made the object a borg, but it still seems a bit hacky.

Making it a borg is one concrete difference. Modules are singletons, not
borgs, so anyone who does

if the_thing is somemodule

may be surprised. I wouldn't necessarily worry about borgifying the module
proxy, since the import mechanics will ensure[1] it remains a singleton.

But frankly, this approach sounds complex and complicated, and we know what
the Zen says about them.




[1] For some definition of "ensure".


-- 
Steven

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


Re: Catching exceptions with multi-processing

2015-06-20 Thread Fabien

On 06/19/2015 10:58 PM, Chris Angelico wrote:

AIUI what he's doing is all the subparts of task1 in parallel, then
all the subparts of task2:

pool.map(task1, dirs, chunksize=1)
pool.map(task2, dirs, chunksize=1)
pool.map(task3, dirs, chunksize=1)

task1 can be done on all of dirs in parallel, as no instance of task1
depends on any other instance of task1; but task2 should be started
only if all task1s finish successfully. OP, is this how it is? If not,
I apologize for the noise.


That's it! Thanks for clarifying, I might have trouble explaining myself 
sometimes ;-)


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


Re: Catching exceptions with multi-processing

2015-06-20 Thread Fabien

On 06/20/2015 05:14 AM, Cameron Simpson wrote:

I would keep your core logic Pythonic, raise exceptions. But I would
wrap each task in something to catch any Exception subclass and report
back to the queue. Untested example:

  def subwrapper(q, callable, *args, **kwargs):
try:
  q.put( ('COMPLETED', callable(*args, **kwargs)) )
except Exception as e:
  q.put( ('FAILED', e, callable, args, kwargs) )

then dispatch tasks like this:

  pool.map(subwrapper, q, task1, dirs, chunksize=1)

and have a thread (or main program) collect things from the queue for
logging and other handling. Obviously you might return something more
sophisticated that my simple tuple above, but I'm sure you get the idea.

Cheers,
Cameron Simpson


Perfect! Much more elegant and easier to implement on top of my existing 
workflow based on raising exceptions.


thanks to all responses,

Fabien



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


Working with jython in openSUSE 13.2

2015-06-20 Thread Cecil Westerhof
I installed Jython in openSUSE 13.2. But when calling jython I get:
/usr/bin/build-classpath: error: JAVA_LIBDIR must be set
Error: Could not find or load main class org.python.util.jython

Does anyone have an idea what I need to do to get it working?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with jython in openSUSE 13.2

2015-06-20 Thread Laura Creighton
In a message of Sat, 20 Jun 2015 12:58:33 +0200, Cecil Westerhof writes:
>I installed Jython in openSUSE 13.2. But when calling jython I get:
>/usr/bin/build-classpath: error: JAVA_LIBDIR must be set
>Error: Could not find or load main class org.python.util.jython
>
>Does anyone have an idea what I need to do to get it working?

Go look for something called java.conf

Mine is in /etc/java

It looks like this:

# System-wide Java configuration file -*- sh -*-
#
# JPackage Project 
# Location of jar files on the system
JAVA_LIBDIR=/usr/share/java
# Location of arch-specific jar files on the system
JNI_LIBDIR=/usr/lib/java
# List of known java homes (used for autodetection if none is provided)
JAVA_HOME_LIST=$JAVA_LIBDIR-utils/java_home.list
# Root of all JVM installations
JVM_ROOT=/usr/lib/jvm
# Default jvm
JAVA_HOME=$JVM_ROOT/java
# Options to pass to the java interpreter
JAVACMD_OPTS=

---

This is the version for Suse, which I think is the one you ought
to have.  But I am not sure if this is where you ought to find it.

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


Re: Working with jython in openSUSE 13.2

2015-06-20 Thread Cecil Westerhof
On Saturday 20 Jun 2015 15:01 CEST, Laura Creighton wrote:

> In a message of Sat, 20 Jun 2015 12:58:33 +0200, Cecil Westerhof
> writes:
>> I installed Jython in openSUSE 13.2. But when calling jython I get:
>> /usr/bin/build-classpath: error: JAVA_LIBDIR must be set
>> Error: Could not find or load main class org.python.util.jython
>>
>> Does anyone have an idea what I need to do to get it working?
>
> Go look for something called java.conf
>
> Mine is in /etc/java
>
> It looks like this:
>
> # System-wide Java configuration file -*- sh -*- JPackage Project
> # Location of jar files on the system
> #JAVA_LIBDIR=/usr/share/java Location of arch-specific jar files on
> #the system JNI_LIBDIR=/usr/lib/java List of known java homes (used
> #for autodetection if none is provided)
> #JAVA_HOME_LIST=$JAVA_LIBDIR-utils/java_home.list Root of all JVM
> #installations JVM_ROOT=/usr/lib/jvm Default jvm
> #JAVA_HOME=$JVM_ROOT/java Options to pass to the java interpreter
> #JAVACMD_OPTS=
>
> ---
>
> This is the version for Suse, which I think is the one you ought
> to have.  But I am not sure if this is where you ought to find it.

Thanks. Some things where there, but commented out. And some things
where not there. I changed it and now I can run jython, but it is
version 2.2.1. So probably it is better to download and install the
latest version.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keypress Input

2015-06-20 Thread John McKenzie

 Christian, are you suggesting I learn to do everything perfectly before 
I ask how to do everything perfectly?

 Despite your tone and insults I honestly appreciate the response. I know 
what to focus on and less than 5 minutes from now I will be looking for e-
books on the specific subjects you point me to and will have a better 
idea of where the issues are.


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


Re: Keypress Input

2015-06-20 Thread John McKenzie

 Guys, thanks for the various code examples for GPIO and the warning 
about debouncing issues. I am still considering going the route of more 
complex wiring and doing it a more traditional GPIO way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Relation: a new standard (PEP) container?

2015-06-20 Thread Ned Batchelder
On Saturday, June 20, 2015 at 2:10:50 AM UTC-4, Scott wrote:
> We've been using a simple container implementation of a mathematical relation 
> (https://simple.wikipedia.org/wiki/Relation_(mathematics)) (i.e. an 
> invertible M:M mapping) for some time.
> 
>  
> We've been waiting for many years (decades actually) to have this concept 
> incorporated as a standard container in one of the modern programming 
> languages so we could swap our code with a language-standard container.  To 
> further these efforts, we have decided to initiate a conversation with the 
> python community on adding a relation as a standard Python container package.
>  
> Briefly the uses of a relation are:
>  
> - quickly finding the values/range associated with keys/domain (e.g. 
> *inversion*)
> - maintaining a unique relationship between keys and values,(e.g. 
> *isomorphism* or *aliasing*)
> - using keys to categorize (one-to-many) values (e.g. *partitioning*)
> - associating two sets in an arbitrary/bipartite manner (e.g. *tagging*)
>  
> Below is a link to an implementation, including an ipython notebook with 
> light exposition and some canonical examples.  We'll also be presenting a 
> poster at SciPy 2015. Let us know if this, or something like it, seems like a 
> worthwhile addition to the standard Python distribution.

When people propose new additions to the standard library, the ususal
question is, Why is it important to be in the standard library, why not
simply let people use it as a third-party package?

You've already made it available on PyPI.  People who need it can find
it there, right?

The standard library is extended very conservatively.  The Python-Ideas
mailing list is where previous discussions like this have take place. You
can search there for similar suggestions.

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


Re: JSON Object to CSV Question

2015-06-20 Thread Ned Batchelder
On Saturday, June 20, 2015 at 2:10:51 AM UTC-4, Sahlusar wrote:
> @Joonas:
> 
> 
> The previous example was a typo. Please use the below example as a case 
> study. 
> 
> 
> 
> 
> {'D_B': ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], 'F_Int32': 
> ['0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0', 
>  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0'], 
> 'OTF': '0', 'PBDS_Double': ['0', '0', '0', '0', '0', '0', '0', '0'], 
> 'SCS_String': ['1', '2']}
> 
> 
> All of the questions regarding XML I have asked. I have to work within their 
> parameters. The CSV, for example may look like this:
> 
> 
> DLA,FC,PC,WC,CN,Description,Code,CMC 
> 0,0,0,0,,,0,0

There isn't a single word in common between the Python dictionary you've
shown and the CSV sample output you've shown.  There's no way anyone can
tell what mapping you intend here.

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


Re: Keypress Input

2015-06-20 Thread Michael Torrie
On 06/20/2015 09:02 AM, John McKenzie wrote:
> 
>  Guys, thanks for the various code examples for GPIO and the warning 
> about debouncing issues. I am still considering going the route of more 
> complex wiring and doing it a more traditional GPIO way.

You can wire up the button without a little breadboard or circuit board
using this general diagram:

https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/

Just solder the resistors to the wires themselves, and keep them close
to the pi to keep them clean.  Then you you just have to route one wire
per switch, with one common wire hitting the other side of each switch.
 Probably you will want to use the pull-up version where the switch
pulls the signal down to ground.  You may want to use a header to plug
into the rpi.  But besides that should just be a matter of routing wires.

But on the original track, you might want to ask on the kade forums if
there's any way to interact with kade and get events besides HID
emulation.  For example, maybe you could communicate with it over a
virtual serial port.  Or some other protocol so you don't have to worry
about ttys and Linux kernel HID handling for your program, especially in
a headless environment.  Using HID emulation makes sense in a MAME
arcade environment but not for a headless raspberry pi application.


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


Re: JSON Object to CSV Question

2015-06-20 Thread Saran Ahluwalia
Here is the dictionary that corresponds with the CSV printed to the console:


   1. {
   2. "PAC": {
   3. "Account": [{
   4. "PC": "0",
   5. "CMC": "0",
   6. "WC": "0",
   7. "DLA": "0",
   8. "CN": null,
   9. "FC": {
   10. "Int32": ["0",
   11. "0",
   12. "0",
   13. "0",
   14. "0"]
   15. },
   16. "F": {
   17. "Description": null,
   18. "Code": "0"
   19. }
   20. }]
   21. }
   22. }


On Sat, Jun 20, 2015 at 11:04 AM, Ned Batchelder 
wrote:

> On Saturday, June 20, 2015 at 2:10:51 AM UTC-4, Sahlusar wrote:
> > @Joonas:
> >
> >
> > The previous example was a typo. Please use the below example as a case
> study.
> >
> >
> >
> >
> > {'D_B': ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
> 'F_Int32': ['0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',
> '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',
> '0',  '0',  '0'], 'OTF': '0', 'PBDS_Double': ['0', '0', '0', '0', '0', '0',
> '0', '0'], 'SCS_String': ['1', '2']}
> >
> >
> > All of the questions regarding XML I have asked. I have to work within
> their parameters. The CSV, for example may look like this:
> >
> >
> > DLA,FC,PC,WC,CN,Description,Code,CMC
> > 0,0,0,0,,,0,0
>
> There isn't a single word in common between the Python dictionary you've
> shown and the CSV sample output you've shown.  There's no way anyone can
> tell what mapping you intend here.
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (unknown)

2015-06-20 Thread Ned Deily
In article 
<6264c933-0ed4-4055-baad-01b322bb6dd4@Calculus-Fantasticus-2.local>,
 Scott  wrote:
> We've been using a simple container implementation of a mathematical relation 
> (https://simple.wikipedia.org/wiki/Relation_(mathematics)) (i.e. an 
> invertible M:M mapping) for some time.
[...]
> Below is a link to an implementation, including an ipython notebook with 
> light exposition and some canonical examples. We'll also be presenting a 
> poster at SciPy 2015. Let us know if this, or something like it, seems like a 
> worthwhile addition to the standard Python distribution.

Scott, James:

The best place to have a discussion about adding new features to Python 
is on the python-ideas mailing list:

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

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

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


Re: Classic OOP in Python

2015-06-20 Thread Mark Lawrence

On 19/06/2015 00:01, Laura Creighton wrote:

In a message of Thu, 18 Jun 2015 11:50:28 +0100, Mark Lawrence writes:

Throw in http://clonedigger.sourceforge.net/ as well and you've a really
awesome combination.

Mark Lawrence



I didn't know about that one.
Hey thank you, Mark.  Looks great.

It needs its own entry in
https://wiki.python.org/moin/PythonTestingToolsTaxonomy

You add it, or me?

Laura



Thanks all the same but I'll leave it to you, as I suspect I'd be my 
usual combination of headless chicken and bull in a china shop if let 
loose on a wiki :)


--
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


HOPE: A Python just-in-time compiler for astrophysical computations

2015-06-20 Thread Mark Lawrence
Another beasty I've just stumbled across which you may find interesting 
http://www.sciencedirect.com/science/article/pii/S2213133714000687


--
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


How to construct matrix from vectors?

2015-06-20 Thread Nasser M. Abbasi

I just started to learn some python today for first time,
so be easy on me.

I am having some trouble figuring how do the problem shown in this link

http://12000.org/my_notes/mma_matlab_control/KERNEL/KEse44.htm

Given 4 column vectors, v1,v2,v3,v4, each is 3 rows.

I want to use these to construct matrix mat, which is

  [[v1,v2],
   [v3,v4]]

So the resulting matrix is as shown in the link.  i.e.
it will be 6 rows and 2 columns.

This is what I tried:

import numpy as np
v1=np.array([1,2,3]);
v2=np.array([4,5,6]);
v3=np.array([7,8,9]);
v4=np.array([10,11,12]);

And now I get stuck, I tried

m=np.array([[v1,v2],[v3,v4]])  #no good

Also

m=np.array([v1,v2,v3,v4])
m.shape
   Out[153]: (4L, 3L)
m.T

array([[ 1,  4,  7, 10],
   [ 2,  5,  8, 11],
   [ 3,  6,  9, 12]])

Not what I want.

I need to get the shape as in the above link, 6 rows by 2 columns,
where each column vector is stacked as shown.  I also tried

v1=np.array([1,2,3]); v1.shape=3,1
v2=np.array([4,5,6]); v2.shape=3,1
v3=np.array([7,8,9]); v3.shape=3,1
v4=np.array([10,11,12]); v4.shape=3,1
mat=np.array([[v1,v2],[v3,v4]])

What is the correct way to do this in Python?

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


Re: Lawful != Mutable (was Can Python function return multiple data?)

2015-06-20 Thread Rustom Mody
On Sunday, June 7, 2015 at 10:04:37 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Jun 8, 2015 at 2:20 AM, Rustom Mody  wrote:
> > Ok now rewrite that para above with
> > s/tuple/numbers like 3 or 666/
> > So I put '3' on the ram and grind it to finest powder.
> > Have all trinities (of religious or secular variety) disappeared?
> > 666 gone has the devil been banished from God's (or Steven's) universe?
> 
> If you write down your phone number and give it to a girl you like,
> and she burns that piece of paper, do you no longer have a phone
> number? No, but she certainly doesn't have your phone number any more.
> There's a difference between destroying a representation and
> destroying the original entity. But Steven's point wasn't about how
> easy/hard it is to destroy something; it was about a tuple's
> immutability NOT being a prevention of its destruction, and therefore
> it's not that sense of the word in which they're immutable. Similarly,
> you could destroy a document on which God's laws are written (in the
> original dictionary sense; if you don't want to believe in immutable
> laws of a Deity, you can substitute in a law of physics - for
> instance, the law that two objects with mass exert a force of
> attraction on each other due to gravity), and it wouldn't destroy the
> law itself.
> 
> ChrisA

Recent thread on python ideas
https://mail.python.org/pipermail/python-ideas/2015-June/034177.html

Since "python's immutable" ≠ "really immutable", we now need a "really 
immutable"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to construct matrix from vectors?

2015-06-20 Thread MRAB

On 2015-06-21 02:57, Nasser M. Abbasi wrote:

I just started to learn some python today for first time,
so be easy on me.

I am having some trouble figuring how do the problem shown in this link

http://12000.org/my_notes/mma_matlab_control/KERNEL/KEse44.htm

Given 4 column vectors, v1,v2,v3,v4, each is 3 rows.

I want to use these to construct matrix mat, which is

[[v1,v2],
 [v3,v4]]

So the resulting matrix is as shown in the link.  i.e.
it will be 6 rows and 2 columns.

This is what I tried:

import numpy as np
v1=np.array([1,2,3]);
v2=np.array([4,5,6]);
v3=np.array([7,8,9]);
v4=np.array([10,11,12]);

And now I get stuck, I tried

m=np.array([[v1,v2],[v3,v4]])  #no good

Also

m=np.array([v1,v2,v3,v4])
m.shape
 Out[153]: (4L, 3L)
m.T

array([[ 1,  4,  7, 10],
 [ 2,  5,  8, 11],
 [ 3,  6,  9, 12]])

Not what I want.

I need to get the shape as in the above link, 6 rows by 2 columns,
where each column vector is stacked as shown.  I also tried

v1=np.array([1,2,3]); v1.shape=3,1
v2=np.array([4,5,6]); v2.shape=3,1
v3=np.array([7,8,9]); v3.shape=3,1
v4=np.array([10,11,12]); v4.shape=3,1
mat=np.array([[v1,v2],[v3,v4]])

What is the correct way to do this in Python?


Here's one way, one step at a time:


r1 = np.concatenate([v1, v2])
r1

array([1, 2, 3, 4, 5, 6])

r2 = np.concatenate([v3, v4])
r2

array([ 7,  8,  9, 10, 11, 12])

m = np.array([r1, r2])
m

array([[ 1,  2,  3,  4,  5,  6],
   [ 7,  8,  9, 10, 11, 12]])

m.transpose()

array([[ 1,  7],
   [ 2,  8],
   [ 3,  9],
   [ 4, 10],
   [ 5, 11],
   [ 6, 12]])




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


Re: Lawful != Mutable (was Can Python function return multiple data?)

2015-06-20 Thread Chris Angelico
On Sun, Jun 21, 2015 at 11:59 AM, Rustom Mody  wrote:
> Recent thread on python ideas
> https://mail.python.org/pipermail/python-ideas/2015-June/034177.html
>
> Since "python's immutable" ≠ "really immutable", we now need a "really 
> immutable"

That's because it requires mutable memory to keep track of reference
counts. In a non-refcountinig Python, strings and integers can be
truly immutable; that thread is suggesting (among other options)
simply storing the refcounts in a separate table. Conceptually, a
string or integer IS immutable, but CPython currently needs to be able
to fiddle with some bookkeeping data about them, in order to pretend
it has plenty of memory. A Python implementation could theoretically
just abandon its strings whenever it's done with them, wasting gobs of
memory in the process, and having them in read-only memory. More
practically, a pure mark-and-sweep GC (such as MicroPython uses)
trades prompt disposal for simple management, and in doing so,
achieves (I think) the same total immutability.

You have to distinguish between Python (the language) and CPython (the
implementation) here. Python's notion of mutability has nothing to do
with thread safety. You could achieve perfect thread safety for
immutables by simply replicating them into every thread; it'd be
inefficient, but perfectly legal.

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


Re: Lawful != Mutable (was Can Python function return multiple data?)

2015-06-20 Thread Rustom Mody
On Sunday, June 21, 2015 at 8:03:18 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Jun 21, 2015 at 11:59 AM, Rustom Mody wrote:
> > Recent thread on python ideas
> > https://mail.python.org/pipermail/python-ideas/2015-June/034177.html
> >
> > Since "python's immutable" ≠ "really immutable", we now need a "really 
> > immutable"
> 
> That's because it requires mutable memory to keep track of reference
> counts. In a non-refcountinig Python, strings and integers can be
> truly immutable; that thread is suggesting (among other options)
> simply storing the refcounts in a separate table. Conceptually, a
> string or integer IS immutable, but CPython currently needs to be able
> to fiddle with some bookkeeping data about them, in order to pretend
> it has plenty of memory. A Python implementation could theoretically
> just abandon its strings whenever it's done with them, wasting gobs of
> memory in the process, and having them in read-only memory. More
> practically, a pure mark-and-sweep GC (such as MicroPython uses)
> trades prompt disposal for simple management, and in doing so,
> achieves (I think) the same total immutability.
> 
> You have to distinguish between Python (the language) and CPython (the
> implementation) here. Python's notion of mutability has nothing to do
> with thread safety. You could achieve perfect thread safety for
> immutables by simply replicating them into every thread; it'd be
> inefficient, but perfectly legal.
> 
> ChrisA

Here is Eric Snow:

| Keep in mind that by "immutability" I'm talking about *really*
| immutable, perhaps going so far as treating the full memory space
| associated with an object as frozen.  For instance, we'd have to
| ensure that "immutable" Python objects like strings, ints, and tuples
| do not change (i.e. via the C API).  The contents of involved
| tuples/containers would have to be likewise immutable.  Even changing
| refcounts could be too much, hence the idea of moving refcounts out to
| a separate table.
|  
| This level of immutability would be something new to Python.  We'll
| see if it's necessary.  If it isn't too much work it might be a good
| idea regardless of the multi-core proposal.

Does the second para look like CPython implementation or python-the-language?

Also note the 'Even' in the first para. ie Eric is talking of low-level
(ie thread-safety, refcounting etc) immutability after the even and higher
level semantic immutability before
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Opening PDF Using subprocess.Popen Failing

2015-06-20 Thread Naftali
On Friday, June 19, 2015 at 1:25:12 PM UTC-4, Naftali wrote:
> It actually doesn't fail but it 'cannot open in protected mode' (see here 
> http://blogs.adobe.com/dmcmahon/2012/07/27/adobe-reader-cannot-open-protected-mode-due-to-a-problem-with-your-system-configuration/)
> 
> I am using subprocess.Popen("AcroRe32.exe /n ") which is the 
> actuall adobe reader command I'd issue on the command line to open the pdf 
> (the /n option opens it the file in a new instance of reader).
> 
> Now, when I issue the command straight from powershell, the pdf opens no 
> problem, but when I open in my script (whether a .py or py2exe) I get the pop 
> up complaining that the PDF cannot be opened in 'protected mode.' One of the 
> options is to open it anyways, which works. 
> 
> Looking into it (see the link in the first paragraph) my best guess is that 
> it's due to something like "JS-invoked processes: Launching a process through 
> JavaScript is not allowed with Protected Mode enabled." 
> 
> But my naive understanding was that when I give Popen instruction, the 
> command is handed off to windows and the called program is unaware of how it 
> got called, so my thinking is that either that is incorrect or windows 
> somehow 'cooperates' with reader to figure things out. 
> 
> I am looking for *any* insight as to how to deal with this, and the 'turn off 
> protected mode" option wont work for me. 
> 
> Here is my code,
> 
> outputname = " unlocked.pdf"
> 
> commandstr = "qpdf --decrypt " + sys.argv[1] + outputname
> os.system(commandstr)
> 
> new_command_str = "AcroRd32.exe /n" + outputname
> subprocess.Popen(new_command_str)
> 
> sys.exit(0)


I am running the script via powershell. that sounds very promising. I'm going 
to read the link Laura pointed to upthread and see what happens outside 
powershell on Monday when I get back to the windows environment. 

But thank you for the heads up cause that makes a lot sense. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to construct matrix from vectors?

2015-06-20 Thread Nasser M. Abbasi

On 6/20/2015 9:20 PM, MRAB wrote:


Here's one way, one step at a time:


r1 = np.concatenate([v1, v2])
r1

array([1, 2, 3, 4, 5, 6])

r2 = np.concatenate([v3, v4])
r2

array([ 7,  8,  9, 10, 11, 12])

m = np.array([r1, r2])
m

array([[ 1,  2,  3,  4,  5,  6],
 [ 7,  8,  9, 10, 11, 12]])

m.transpose()

array([[ 1,  7],
 [ 2,  8],
 [ 3,  9],
 [ 4, 10],
 [ 5, 11],
 [ 6, 12]])






But your output is wrong.

I did manage to find a way:

-
r1 =np.hstack([(v1,v2)]).T
r2 =np.hstack([(v3,v4)]).T
mat = np.vstack((r1,r2))
-

Out[211]:
array([[ 1,  4],
   [ 2,  5],
   [ 3,  6],
   [ 7, 10],
   [ 8, 11],
   [ 9, 12]])

But it is not as intuitive as with Matlab, where one can just write

---
  v1=[1,2,3]'; v2=[4,5,6]';
  v3=[7,8,9]'; v4=[10,11,12]';
  m=[v1 v2;v3 v4]
---

--Nasser



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


Re: Time saving tips for Pythonists

2015-06-20 Thread Miki Tebeka
> What are your best time saving tips when programming Python?
* Use the REPL. Write small chunks of code and test them as you go
* Know what's available in the standard library (sets, Counter, deque ...)
* Learn how to pick good packages from PyPI (community, last commit ...)
* import this
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to construct matrix from vectors?

2015-06-20 Thread Nasser M. Abbasi

On 6/20/2015 10:47 PM, Nasser M. Abbasi wrote:


I did manage to find a way:

-
r1 =np.hstack([(v1,v2)]).T
r2 =np.hstack([(v3,v4)]).T
mat = np.vstack((r1,r2))
-

Out[211]:
array([[ 1,  4],
 [ 2,  5],
 [ 3,  6],
 [ 7, 10],
 [ 8, 11],
 [ 9, 12]])

But it is not as intuitive as with Matlab, where one can just write

---
v1=[1,2,3]'; v2=[4,5,6]';
v3=[7,8,9]'; v4=[10,11,12]';
m=[v1 v2;v3 v4]
---


Here is a way a little closer to Matlab's method: First
make all the vectors column vectors

v1=np.array([(1,2,3)]).T
v2=np.array([(4,5,6)]).T
v3=np.array([(7,8,9)]).T
v4=np.array([(10,11,12)]).T

mat =np.hstack(( np.vstack((v1,v3)), np.vstack((v2,v4))) )

Out[236]:
array([[ 1,  4],
   [ 2,  5],
   [ 3,  6],
   [ 7, 10],
   [ 8, 11],
   [ 9, 12]])

There are way too many '(([[]]))' things  in Python :)


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


Re: JSON Object to CSV file

2015-06-20 Thread Denis McMahon
On Wed, 17 Jun 2015 08:00:11 -0700, Saran A wrote:

> I would like to have this JSON object written out to a CSV file so that
> the keys are header fields (for each of the columns) and the values are
> values that are associated with each header field.

> {
> "CF": {
...
> "CF": "Fee",

Your json object seems to have the same key used for two elements at the 
same level, are you sure this is legal json?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JSON Object to CSV File Troubleshooting

2015-06-20 Thread Denis McMahon
On Thu, 18 Jun 2015 18:47:30 -0700, Sahlusar wrote:

> I have a conundrum regarding JSON objects and converting them to CSV:
> 
> Context
> 
> I am converting XML files to a JSON object (please see snippet below)
> and then finally producing a CSV file. Here is a an example JSON object:

This is where you're going wrong. If you want CSV data, take the XML and 
generate CSV data from it. Converting and writing it out to JSON and then 
reading it back and converting to CSV involves an extra conversion step 
where errors can creep in.

If you want to convert XML to CSV, go straight from XML to CSV, there is 
little added value in using some arbitrary intermediate format unless 
you're actually going to use the data in the intermediate format for 
something other than converting to the final format.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JSON Object to CSV File Troubleshooting

2015-06-20 Thread Denis McMahon
On Thu, 18 Jun 2015 18:47:30 -0700, Sahlusar wrote:

> I have a conundrum regarding JSON objects and converting them to CSV:

I think your conundrum is that you've taken on a coding task beyond your 
abilities to comprehend, and as a result not only can you not code it, 
you can't even adequately describe it.

At least, it seems that every time you do try and describe it either the 
data format or the task description changes.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list