Loading modules from files through C++

2014-05-16 Thread Roland Plüss
I'm using Python in an embedded situation. In particular I have to load
python scripts through a memory interface so regular python module
loading can not be used. I got working so far a module loader object
I've added using C++ to sys.meta_path . Now I'm totally stuck at the
finally loading step.

I've got this a C++ loader method "load_module(fullname)" which does
load the requested module script files into a null-terminated string. I
know that "load_module" has to return the module PyObject*. But I can't
get the python source in the c-string into a module PyObject*.

I've tried so far this:

#CODE#
return Py_CompileStringFlags( content.GetString(),
lookupPath.GetPathNative(), Py_file_input, NULL );
#CODE#

This did not result in a module that worked. In particular the module
script in question contains a method "create". Using "dir(module)" on
the returned value I see no "create" method and the type is a compiled
string. So I tried this:

#CODE#
loadedModule = Py_InitModule3( fullname, NULL, "Loaded module" );
if( ! PyRun_StringFlags( content.GetString(), Py_file_input,
loadedModule, loadedModule, NULL ) ){
if( PyErr_Occurred() ) PyErr_Print();
Py_INCREF( Py_None );
return Py_None;
}
Py_INCREF( loadedModule );
return loadedModule;
#CODE#

I concluded that I have to create the module myself and somehow
eval/compile the c-string into the module. For this I figured out
PyRun_StringFlags would be a suitable candidate. But doing the above I
get an error:

#CODE#
Traceback (most recent call last):
  File "", line 22, in 
ImportError: __import__ not found
#CODE#

Looks like builtins are not existing. But from the internet I read that
if code is parsed from a module both globals and locals are the module.
The above code should do this but yet it fails. I tried also with
PyEval_GetGlobals() and PyEval_GetBuiltins() I had no luck either except
the function complaining about receiving NULL values.

Can anybody help how in gods name one is supposed to create a module
from an in-memory c-string when called from within load_module (or
anywhere)?

-- 
Yours sincerely
Plüss Roland

Leader and Head Programmer
- Game: Epsylon ( http://www.indiedb.com/games/epsylon )
- Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine
, http://dragengine.rptd.ch/wiki )
- Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php )
- As well as various Blender export scripts und game tools



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


Re: Everything you did not want to know about Unicode in Python 3

2014-05-16 Thread Marko Rauhamaa
Steven D'Aprano :

> On Fri, 16 May 2014 14:46:23 +, Grant Edwards wrote:
>
>> At least in the US, there doesn't seem to be such a thing as "placing
>> a work into the public domain". The copyright holder can transfer
>> ownershipt to soembody else, but there is no "public domain" to which
>> ownership can be trasferred.
>
> That's factually incorrect. In the US, sufficiently old works, or works 
> of a certain age that were not explicitly registered for copyright, are 
> in the public domain. Under a wide range of circumstances, works created 
> by the federal government go immediately into the public domain.

Steven, you're not disputing Grant. I am. The sole copyright holder can
simply state: "this work is in the Public Domain," or: "all rights
relinquished," or some such. Ultimately, everything is decided by the
courts, of course.


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


Re: Everything you did not want to know about Unicode in Python 3

2014-05-16 Thread Steven D'Aprano
On Fri, 16 May 2014 14:46:23 +, Grant Edwards wrote:

> At least in the US, there doesn't seem to be such a thing as "placing a
> work into the public domain".  The copyright holder can transfer
> ownershipt to soembody else, but there is no "public domain" to which
> ownership can be trasferred.

That's factually incorrect. In the US, sufficiently old works, or works 
of a certain age that were not explicitly registered for copyright, are 
in the public domain. Under a wide range of circumstances, works created 
by the federal government go immediately into the public domain.

It is true that under the Mickey Mouse Copyright Grab Act[1] of , every time Mickey Mouse is about to reach the end of 
copyright, Congress retroactively extends copyright terms for another few 
decades, but that's another story.




[1] Not the real name of the act.

-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Ernest Bonat, Ph.D.
1. There are a lot of spinet codes in many languages for numerical
integration. I may find a good one in Python for you? try SciPy.org (
http://www.scipy.org/about.html) you may find something there.

2. Look at the wiki too: https://wiki.python.org/moin/NumericAndScientific.

I hope this help a bit!

Ernest Bonat, Ph.D.



On Fri, May 16, 2014 at 10:55 AM, Terry Reedy  wrote:

> On 5/16/2014 4:49 AM, Enlong Liu wrote:
>
>> Dear All,
>>
>> I have a question about the integration with Python.
>>
>
> For numerical integration, you should look as numpy and scipy and perhaps
> associated packages.
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Thanks

Ernest Bonat, Ph.D.
Senior Software Engineer
Senior Business Statistics Analyst
Mobile: 503.730.4556
Email: ernest.bo...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread duncan smith

On 16/05/14 16:01, Johannes Schneider wrote:

If you do not have a closed form for T(E) you cannot calculate the exact
value of I(V).

Anyway. Assuming T is integrable you can approximate I(V).

1. Way to do:
interpolate T(E) by a polynomial P and integrate P. For this you need
the equation (coefficients and exponents) of P. Integrating is easy
after that.

2. other way:
Use Stair-functions: you can approximate the Value of IV() by the sum
over T(E_i) * (E_{i+1} - E_i) s.t. E_0 = E_F-\frac{eV}{2} and E_n =
E_F+\frac{eV}{2}.



snip]

Or piecewise polynomials (splines).

Duncan

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


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Terry Reedy

On 5/16/2014 4:49 AM, Enlong Liu wrote:

Dear All,

I have a question about the integration with Python.


For numerical integration, you should look as numpy and scipy and 
perhaps associated packages.


--
Terry Jan Reedy

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


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Ernest Bonat, Ph.D.
Hi Enlong

You may try standard numerical integration solutions based on the E and
T(E) columns data provided.

Ernest Bonat, Ph.D.



On Fri, May 16, 2014 at 1:49 AM, Enlong Liu  wrote:

> Dear All,
>
> I have a question about the integration with Python. The equation is as
> below:
> and I want to get values of I with respect of V. E_F is known. But for
> T(E), I don't have explicit equation, but a .dat file containing
> two columns, the first is E, and the second is T(E). It is also in the
> attachment for reference. So is it possible to do integration in Python?
>
> Thanks a lot for your help!
>
> Best regards,
> ​
>
> --
> Faculty of Engineering@K.U. Leuven
> BIOTECH@TU Dresden
> Email: liuenlon...@gmail.com; enlong@student.kuleuven.be;
> enlong@biotech.tu-dresden.de
> Mobile Phone: +4917666191322
> Mailing Address: Zi. 0108R, Budapester Straße 24, 01069, Dresden, Germany
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Thanks

Ernest Bonat, Ph.D.
Senior Software Engineer
Senior Business Statistics Analyst
Mobile: 503.730.4556
Email: ernest.bo...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Johannes Schneider
If you do not have a closed form for T(E) you cannot calculate the exact 
value of I(V).


Anyway. Assuming T is integrable you can approximate I(V).

1. Way to do:
interpolate T(E) by a polynomial P and integrate P. For this you need 
the equation (coefficients and exponents) of P. Integrating is easy 
after that.


2. other way:
Use Stair-functions: you can approximate the Value of IV() by the sum 
over T(E_i) * (E_{i+1} - E_i) s.t. E_0 = E_F-\frac{eV}{2} and E_n = 
E_F+\frac{eV}{2}.



3 one more way:
use a computer algebra system like sage.

bg,
Johannes

On 16.05.2014 10:49, Enlong Liu wrote:

Dear All,

I have a question about the integration with Python. The equation is as
below:
and I want to get values of I with respect of V. E_F is known. But for
T(E), I don't have explicit equation, but a .dat file containing
two columns, the first is E, and the second is T(E). It is also in the
attachment for reference. So is it possible to do integration in Python?

Thanks a lot for your help!

Best regards,
​

--
Faculty of Engineering@K.U. Leuven
BIOTECH@TU Dresden
Email:liuenlon...@gmail.com ;
enlong@student.kuleuven.be ;
enlong@biotech.tu-dresden.de 
Mobile Phone: +4917666191322
Mailing Address: Zi. 0108R, Budapester Straße 24, 01069, Dresden, Germany






--
Johannes Schneider
Webentwicklung
johannes.schnei...@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Everything you did not want to know about Unicode in Python 3

2014-05-16 Thread Grant Edwards
On 2014-05-14, alister  wrote:
> On Wed, 14 May 2014 10:08:57 +1000, Chris Angelico wrote:
>
>> On Wed, May 14, 2014 at 9:53 AM, Steven D'Aprano
>>  wrote:
>>> With the current system, all of us here are technically violating
>>> copyright every time we reply to an email and quote more than a small
>>> percentage of it.
>> 
>> Oh wow... so when someone quotes heaps of text without trimming, and
>> adding blank lines, we can complain that it's a copyright violation -
>> reproducing our work with unauthorized modifications and without
>> permission...
>> 
>> I never thought of it like that.

> I think I could make a very strong case that anything sent to a public 
> forum with the intention of being broadcast has been placed into the 
> public domain by this action.

At least in the US, there doesn't seem to be such a thing as "placing
a work into the public domain".  The copyright holder can transfer
ownershipt to soembody else, but there is no "public domain" to which
ownership can be trasferred.  IIRC, there is a way under Germain
copyright law to release certain rights.  The mere act of widely
widely distributing something does not in any way relinquish
copyrights.

-- 
Grant Edwards   grant.b.edwardsYow! Am I elected yet?
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


urllib with x509 certs

2014-05-16 Thread Luis Miguel Rojas Aguilera
Hi, i tried what you suggest but still asking me for the password, this 
time twice.

Please i need help so this is for my thesis.
VII Escuela Internacional de Verano en la UCI del 30 de junio al 11 de julio de 
2014. Ver www.uci.cu
--
https://mail.python.org/mailman/listinfo/python-list


Re: Everything you did not want to know about Unicode in Python 3

2014-05-16 Thread wxjmfauth
Le vendredi 16 mai 2014 13:50:47 UTC+2, Antoine Pitrou a écrit :
> Terry Reedy  udel.edu> writes:
> 
> > 
> 
> > On 5/13/2014 8:53 PM, Ethan Furman wrote:
> 
> > > On 05/13/2014 05:10 PM, Steven D'Aprano wrote:
> 
> > >> On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote:
> 
> > >>
> 
> > >>> Because Python 3 presents stdin and stdout as text streams however, it
> 
> > >>> makes them more difficult to use with binary data, which is why Armin
> 
> > >>> sets up all that extra code to make sure his file objects are binary.
> 
> > >>
> 
> > >> What surprises me is how hard that is. Surely there's a simpler way to
> 
> > >> open stdin and stdout in binary mode? If not, there ought to be.
> 
> > >
> 
> > > Somebody already posted this:
> 
> > >
> 
> > > https://docs.python.org/3/library/sys.html#sys.stdin
> 
> > >
> 
> > > which talks about .detach().
> 
> > 
> 
> > I sent a message to Armin about this.
> 
> 
> 
> And the documentation has now been fixed:
> 
> http://bugs.python.org/issue21364
> 
> 
> 
> So something *can* come out of a python-list rantfest, it seems.
> 
> 
> 
> Regards
> 
> 
> 
> Antoine.

==

http://www.unicode.org/

Avec mes meilleures salutations.

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


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread duncan smith

On 16/05/14 13:57, Enlong Liu wrote:

Sorry for this inconvenience. Since my file is a little large, I think it will 
be more difficult for fellows to check. I will now paste the attachment below.

The file for T(E) consists of two columns, the first is E and the second is 
T(E). What I want is to integrate this function in a certain range.

   E   T(E)
   -6.2578958.96247678929291
   -6.2378958.90487115888237
   -6.2178957.96907432610510


[snip]

http://en.wikipedia.org/wiki/Numerical_integration

Duncan

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


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Enlong Liu
Sorry for this inconvenience. Since my file is a little large, I think it will 
be more difficult for fellows to check. I will now paste the attachment below.

The file for T(E) consists of two columns, the first is E and the second is 
T(E). What I want is to integrate this function in a certain range. 

  E   T(E)   
  -6.2578958.96247678929291 
  -6.2378958.90487115888237 
  -6.2178957.96907432610510 
  -6.1978957.92011229305473 
  -6.1778956.99973958998368 
  -6.1578956.99959200703257 
  -6.1378956.99960349124858 
  -6.1178956.99960255937428 
  -6.0978957.02338574542792 
  -6.0778958.93135475951887 
  -6.0578959.96750726601798 
  -6.03789510.9408732001956 
  -6.01789510.9415058589703 
  -5.9978958.94537541754214 
  -5.97789510.8097100967606 
  -5.9578958.85226193360772 
  -5.9378956.99661653557932 
  -5.9178956.9965473639 
  -5.8978956.99670347299879 
  -5.8778956.99673218445900 
  -5.8578956.99659826270511 
  -5.8378956.99623464091850 
  -5.8178956.99548818932425 
  -5.7978956.99394489936466 
  -5.7778956.99005017803712 
  -5.7578956.96962543581676 
  -5.7378955.99747630590266 
  -5.7178956.94845928621193 
  -5.6978956.98766975985479 
  -5.6778956.97758798116556 
  -5.6578956.95055436382018 
  -5.6378956.87176971154089 
  -5.6178956.54273589313568 
  -5.5978955.86175895258116 
  -5.5778955.9282973331 
  -5.5578954.99981497444712 
  -5.5378954.99980834464660 
  -5.5178954.99980420721252 
  -5.4978954.99979886872216 
  -5.4778954.99978991290910 
  -5.4578954.99977459415969 
  -5.4378954.99974900970110 
  -5.4178954.99970628963861 
  -5.3978954.99963148201658 
  -5.3778954.99948355338835 
  -5.3578954.99911446459881 
  -5.3378954.99695076010531 
  -5.3178954.99843069856951 
  -5.2978954.99936037524651 
  -5.2778956.35475207677864 
  -5.2578956.82856665022716 
  -5.2378956.14018744222317 
  -5.2178956.36919461746248 
  -5.1978956.99756897433419 
  -5.1778956.99744749888663 
  -5.1578956.99680114447542 
  -5.1378956.99567111628791 
  -5.1178956.99382008170924 
  -5.0978956.99072617412210 
  -5.0778956.98523875355823 
  -5.0578956.97440300478140 
  -5.0378956.94799835685808 
  -5.0178956.8329785804 
  -4.9978955.99940020401670 
  -4.9778955.99938810939229 
  -4.9578955.02927710403357 
  -4.9378954.99915975390103 
  -4.9178954.99890278935809 
  -4.8978954.99859914243363 
  -4.8778954.99821739336097 
  -4.8578954.99773235771017 
  -4.8378954.99710904566381 
  -4.8178954.99629369410517 
  -4.7978954.99519763548885 
  -4.7778954.99366188069830 
  -4.7578954.99136763606374 
  -4.7378954.98756326792036 
  -4.7178954.97994414169979 
  -4.6978954.95655109792192 
  -4.6778954.29448749155961 
  -4.6578953.99951693213742 
  -4.6378953.99942050837630 
  -4.6178953.99929275933828 
  -4.5978953.99907888035628 
  -4.5778954.91566360421753 
  -4.5578953.00063522267926 
  -4.5378953.99325633047260 
  -4.5178953.98716883843963 
  -4.4978953.99345892791020 
  -4.4778953.86300434156207 
  -4.4578952.98361846417016 
  -4.4378951.00328787566656 
  -4.417895   0.999797612478520 
  -4.397895   0.999727944291486 
  -4.377895   0.999702219681149 

Re: Everything you did not want to know about Unicode in Python 3

2014-05-16 Thread Antoine Pitrou
Terry Reedy  udel.edu> writes:
> 
> On 5/13/2014 8:53 PM, Ethan Furman wrote:
> > On 05/13/2014 05:10 PM, Steven D'Aprano wrote:
> >> On Tue, 13 May 2014 10:08:42 -0600, Ian Kelly wrote:
> >>
> >>> Because Python 3 presents stdin and stdout as text streams however, it
> >>> makes them more difficult to use with binary data, which is why Armin
> >>> sets up all that extra code to make sure his file objects are binary.
> >>
> >> What surprises me is how hard that is. Surely there's a simpler way to
> >> open stdin and stdout in binary mode? If not, there ought to be.
> >
> > Somebody already posted this:
> >
> > https://docs.python.org/3/library/sys.html#sys.stdin
> >
> > which talks about .detach().
> 
> I sent a message to Armin about this.

And the documentation has now been fixed:
http://bugs.python.org/issue21364

So something *can* come out of a python-list rantfest, it seems.

Regards

Antoine.


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


Re: Psycopg2 : error message.

2014-05-16 Thread Chris Angelico
On Fri, May 16, 2014 at 8:18 PM, dandrigo  wrote:
> Please read the 2 usefull files below :
>
> Dandrigo pg_test.py 
>
> SS_dos.JPG 

These would be MUCH better included inline. Please, in future, copy
and paste the *text* of the error message - don't post a screenshot.

As to the actual problem: You're masking a potentially useful
exception behind a bare except that just prints a generic message *and
then continues*. This is a very bad idea. Don't do it. Take all that
out and just attempt the connection; then you'll get a useful error.
Same further down. Just don't.

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


Re: The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Dave Angel

On 05/16/2014 04:49 AM, Enlong Liu wrote:

Dear All,

I have a question about the integration with Python. The equation is as
below:
and I want to get values of I with respect of V. E_F is known. But for
T(E), I don't have explicit equation, but a .dat file containing
two columns, the first is E, and the second is T(E). It is also in the
attachment for reference. So is it possible to do integration in Python?

You posted in html, and you tried to make an attachment.  Either of 
these will stop many people from seeing what you intended them to see.


Presumably the rest of the explanation is in the source code, which you 
didn't include in your message.  This is a text-mailing-list, and many 
of us cannot see attachments, and many others of us cannot see html.


Please tell your email program to use plain text, not html.

Please paste any attachments into the same text message, unless it's too 
big.  In that case, you'd need to paste a link instead, but many people 
won't be able and/or willing to follow such links.



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


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Marko Rauhamaa
Chris Angelico :

> Compare these two assignment statements:
>
> area = (base*base + extension*extension
> + annex*annex + (annex-extension)*annex
> + triangle*triangle/2
> + circle*circle*math.PI + sphere*sphere*4*math.PI)
>
> area = (base*base + extension*extension + annex*annex
> + (annex-extension)*annex + triangle*triangle/2
> + circle*circle*math.PI + sphere*sphere*4*math.PI)
>
> [...]
> How are you going to cope with this distinction? That's real, useful
> information, which the AST doesn't carry.

Such nuances would be lost, yes. However, the nuances are constantly
abused and misinterpreted anyway.


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


Psycopg2 : error message.

2014-05-16 Thread dandrigo
Dear all, 

I'm writing a python script for a web service. I have to connect to my
postgres/postgis databases via Psycopg2. 

I writed a little first script just to connect to my pg/postgis db and drop
a test db. 

But when i execute the python file, i have several error messages. 

Please read the 2 usefull files below : 

Dandrigo pg_test.py   

SS_dos.JPG   


In advance, thank you to throw light for me. 

Regards. 





--
View this message in context: 
http://python.6.x6.nabble.com/Psycopg2-error-message-tp5057062.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Chris Angelico
On Fri, May 16, 2014 at 7:18 PM, Marko Rauhamaa  wrote:
> If every bit of your Python text conveys information, obviously, it
> can't be abstracted. I don't believe that to be the case, though. So
> this AST should contain all *actual* information worth conveying and
> strip away irrelevant stuff.
>
> Examples:
>
>  * Function definition order.
>
>  * Indentation depth.
>
>  * Vertical empty space.

* Logical layout as expressed by whitespace and specific line breaks.

Compare these two assignment statements:

area = (base*base + extension*extension
+ annex*annex + (annex-extension)*annex
+ triangle*triangle/2
+ circle*circle*math.PI + sphere*sphere*4*math.PI)

area = (base*base + extension*extension + annex*annex
+ (annex-extension)*annex + triangle*triangle/2
+ circle*circle*math.PI + sphere*sphere*4*math.PI)

Both are wrapped to sixty characters, which means they can be indented
twenty without breaking PEP 8. One of them takes up only three lines,
the other takes up four. But the first one groups the annex's terms,
separates out the triangle, groups the circular elements, and
presumably corresponds accurately to the (mythical) real-world
geometry that it's implementing. How are you going to cope with this
distinction? That's real, useful information, which the AST doesn't
carry.

(You might argue that each of these lines should have a comment at the
end of it or above it, which would provide that grouping. But in that
case, you lose the canonicalization of anything with trailing comments
or interspersed comments, meaning that you effectively can't reformat
anything with comments in it.)

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


The possibility integration in Python without an equation, just an array-like file

2014-05-16 Thread Enlong Liu
Dear All,

I have a question about the integration with Python. The equation is as
below:
and I want to get values of I with respect of V. E_F is known. But for
T(E), I don't have explicit equation, but a .dat file containing
two columns, the first is E, and the second is T(E). It is also in the
attachment for reference. So is it possible to do integration in Python?

Thanks a lot for your help!

Best regards,
​

-- 
Faculty of Engineering@K.U. Leuven
BIOTECH@TU Dresden
Email: liuenlon...@gmail.com; enlong@student.kuleuven.be;
enlong@biotech.tu-dresden.de
Mobile Phone: +4917666191322
Mailing Address: Zi. 0108R, Budapester Straße 24, 01069, Dresden, Germany


tunneling_pure_BNT30.dat
Description: Binary data
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Marko Rauhamaa
Chris Angelico :

> You still haven't answered my biggest objection from earlier. Source
> code contains more information than the AST does; even if you make a
> frAnkenSTein's monster that includes comments, there's still the point
> that whitespace carries information, and that information is
> frequently communicative of the programmer's intent. Any automated
> reformatter destroys that information, and that is, by definition, a
> net loss to the code. How do you propose to fix that? Or if not, will
> you at least acknowledge that the AST cannot perfectly transmit what
> the source code says?

If every bit of your Python text conveys information, obviously, it
can't be abstracted. I don't believe that to be the case, though. So
this AST should contain all *actual* information worth conveying and
strip away irrelevant stuff.

Examples:

 * Function definition order.

 * Indentation depth.

 * Vertical empty space.


Of course, I'm not being completely serious about all this stuff because
the surface coding style questions are among the least relevant problems
in the code. But at least that kind of arrangement would free us from
the heated debates concerning the maximum line length etc.

(BTW, regardless of PEP8, the maximum line length *must* be 79, and the
maximum function length *must* be whatever can be seen on the screen at
once.)


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


Extracting the value from Netcdf file with longitude and lattitude

2014-05-16 Thread Isaac Won
Hi,
My question may be confusing.

Now I would like to extract temperature values from model output with python.

My model output have separate temperature, longitude and latitude variables.

So, I overlap these three grid variables on one figure to show temperature with 
longitude and latitude through model domain.

Up to this point, everything is fine. The problem is to extract temperature 
value at certain longitude and latitude. 

Temperature variable doesn't have coordinate, but only values with grid.

Do you have idea about this issue?

Below is my code for the 2 D plot with temperature on model domain.

varn1 = 'T2'
varn2 = 'XLONG'
varn3 = 'XLAT'
Temp  = read_netcdf(filin,varn1)
Lon  = read_netcdf(filin,varn2)
Lat  = read_netcdf(filin,varn3)

Temp_plt =  Temp[12,:,:]
Lon_plt = Lon[12,:,:]
Lat_plt = Lat[12,:,:]
x = Lon_plt
y = Lat_plt

Temp_c = Temp_plt-273.15
myPLT = plt.pcolor(x,y,Temp_c)
mxlabel = plt.xlabel('Latitude')
mylabel = plt.ylabel('Longitude')
plt.xlim(126.35,127.35)
plt.ylim(37.16,37.84)
myBAR = plt.colorbar(myPLT)
myBAR.set_label('Temperature ($^\circ$C)')
plt.show()

--
read_netcdf is a code for extracting values of [time, x,y] format.

I think that the point is to bind x, y in Temp_plt with x, y in Lon_plt and 
Lat_plt to extract temperature values with longitude and latitude input.

This question might be confusing. If you can't understand please let me know.

Any idea or help will be really appreciated.

Best regards,

Hoonill




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


Re: IndexError: pop from empty list

2014-05-16 Thread Peter Otten
ch...@freeranger.com wrote:

> No, that was pretty much what I was looking for.  If anyone has an answer
> to the deeper question, that would be icing on the cake.
> 
> What is interesting is that usually the traceback shows the line of code
> that I invoke which, deep inside a library I'm using, has generated an
> error.  In this case I don't know which of my commands has spawned the
> error.
> 
> I can experiment, I suppose, with putting a try/catch around suspected
> lines of code...

It looks like the xbee library is responsible for reading the right amount 
of bytes and then fails to parse them properly.

So it is possible (even likely I think) that you have run into a bug in the 
library.

A report to the author/maintainer should be in order. Of course it would 
help if you can find a way to reproduce the error. One way to do that is to 
modify the code

def _parse_samples(self, io_bytes):
try:
... # original code of the method
except IndexError:
# replace path with something that makes sense on your system
with open("/path/to/io_bytes.data", "wb") as f:
f.write(io_bytes)
raise
 
wait until the error occurs again and then send the contents of the 
io_bytes.data file along with your bug report.

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


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Chris Angelico
On Fri, May 16, 2014 at 5:00 PM, Marko Rauhamaa  wrote:
> Well, actually, any .py file *does* specify a unique AST. Nothing would
> prevent the text editor from presenting it according to your
> preferences. They all do that to a degree anyway (colors, fonts), but
> they could take even more liberties (which some IDE's do: hiding/showing
> comments and function definitions).
>
> There are tools that reindent and refactor code automatically. The text
> editor could do that on the fly.

You still haven't answered my biggest objection from earlier. Source
code contains more information than the AST does; even if you make a
frAnkenSTein's monster that includes comments, there's still the point
that whitespace carries information, and that information is
frequently communicative of the programmer's intent. Any automated
reformatter destroys that information, and that is, by definition, a
net loss to the code. How do you propose to fix that? Or if not, will
you at least acknowledge that the AST cannot perfectly transmit what
the source code says?

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


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Chris Angelico
On Fri, May 16, 2014 at 4:25 PM, Steven D'Aprano
 wrote:
> Containing *what*? You can't just wave your hands and say "binary". What
> sort of binary file? Perhaps a JPEG file, where red triangles of
> different sizes represent keywords. Variable names can be encoded using a
> pattern of purple dots. Expressions and blocks of code can be formed by
> joining components with lines. Operators by squares of different colours
> (green means +, blue means -, etc.).

http://www.dangermouse.net/esoteric/piet.html

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


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Steven D'Aprano
On Thu, 15 May 2014 17:06:13 -0700, Rustom Mody wrote:

> The claim being made is that 79/80 is a fundamental, cognitive limit and
> has no relation to technological changes.

I don't believe anyone has made that claim. You are reading a statement 
about general (typical, average) behaviour, and turning it into an absurd 
statement of a "fundamental" (your word) which applies to every single 
human being on earth.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 : Maximum line Length :

2014-05-16 Thread Marko Rauhamaa
Steven D'Aprano :

> On Thu, 15 May 2014 17:12:57 +0300, Marko Rauhamaa wrote:
>
>> A definitive Python source file could be binary, XML, .py, .ast,
>> whatever, 
>
> Containing *what*? You can't just wave your hands and say "binary".

I sure can and am.

> Besides, where does the information inside the file come from?

The file would a canonical serialization of the AST. The information
would come from an editor (say, emacs) that displays the AST as
two-dimensional text according to your preferences.

Analogy: How do you edit a .png file? With an editor (say, gimp).
Programming languages could work the same way.

> Source code is, *by definition*, the definitive version.

The AST file would be the source code, only it wouldn't have line
numbers or columns. Maybe it could even leave out
capitalization/camel-casing so the editor can display the variable,
function and class names according to your preferences.

> The AST is not definitive. Human beings write *text*, which is what the 
> source code is.

You are stuck to the status quo. I'm proposing the AST should be the
definitive source and the human beings would express AST through the
editor. Yes, it would probably be text, at least partly, but for example
the AST wouldn't specify the order of the function or class definitions.

> This is what code obfuscators do, deliberately: mangle the
> presentation while keeping the semantics the same. You're
> inadvertently proposing the same thing (albeit to a lesser degree).

At least, we could stop debating silly surface presentation issues
(indentation, line width, spacing around operators...).

Well, actually, any .py file *does* specify a unique AST. Nothing would
prevent the text editor from presenting it according to your
preferences. They all do that to a degree anyway (colors, fonts), but
they could take even more liberties (which some IDE's do: hiding/showing
comments and function definitions).

There are tools that reindent and refactor code automatically. The text
editor could do that on the fly.


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