How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Musbur

Hi guys,

I'm wondering how to create an instance of an extension class I wrote. 
There's a minimal self-contained C module at the bottom of this post 
which exports two things: 1) a class Series, and 2) a function 
make_series() which is supposed to create a Series object on the C side 
and return it. The make_series function uses PyObject_New() and 
PyObject_Init() to create the new instance, but all it produces is some 
kind of zombie instance which tends to crash the application with a 
segfault in real life. When instantiated from Python using Series(), I 
get a well-behaved instance.


I've sprinkled the New, Init and Finalize functions with fprintf()s to 
see what happens to the object during its lifetime.


When I run this test script:

from series import *

print("From Python")
s1 = Series()
del s1

print("\nFrom C")
s2 = make_series()
del s2

I get this output:

From Python
New Series at 0x7f89313f6660
Init Series at 0x7f89313f6660
Finalize Series at 0x7f89313f6660

From C
Finalize Series at 0x7f89313f6678

So when created from C, neither the "new" nor the "init" functions are 
called on the object, only "finalize". No wonder I get segfaults in the 
real life application.


So how is this done right? Here's the C module:

#include 

typedef struct {
PyObject_HEAD
void *data;
} Series;

static PyObject *Series_new(PyTypeObject *type,
PyObject *args, PyObject *kw) {
Series *self;

self = (Series *) type->tp_alloc(type, 0);
self->data = NULL;
fprintf(stderr, "New Series at %p\n", self);
return (PyObject*)self;
}

static int Series_init(Series *self, PyObject *args, PyObject *kw) {
fprintf(stderr, "Init Series at %p\n", self);
return 0;
}

static void Series_finalize(PyObject *self) {
fprintf(stderr, "Finalize Series at %p\n", self);
}

static PyMethodDef series_methods[] = {
{NULL, NULL, 0, NULL}
};

static PyTypeObject series_type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "_Series",
.tp_basicsize = sizeof(Series),
.tp_flags = 0
| Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE,
.tp_doc = "Series (msec, value) object",
.tp_methods = series_methods,
.tp_new = Series_new,
.tp_init = (initproc) Series_init,
.tp_dealloc = Series_finalize,
};

/* To create a new Series object directly from C */
PyObject *make_series(void *data) {
Series *pyseries;
pyseries = PyObject_New(Series, &series_type);
PyObject_Init((PyObject *)pyseries, &series_type);
pyseries->data = data;
return (PyObject *) pyseries;
}

static PyMethodDef module_methods[] = {
{"make_series",  (PyCFunction)make_series, METH_NOARGS,
 "Instantiate and return a new Series object."},
{NULL, NULL, 0, NULL}
};

static PyModuleDef series_module = {
PyModuleDef_HEAD_INIT,
"series",
"Defines the Series (time, value) class"
,
-1,
module_methods
};

PyMODINIT_FUNC PyInit_series(void) {
PyObject *m;

m = PyModule_Create(&series_module);

if (PyType_Ready(&series_type) < 0) {
return NULL;
}
PyModule_AddObject(m, "Series", (PyObject*)&series_type);
return m;
}


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


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Rhodri James

On 01/04/2020 13:42, Musbur wrote:
So when created from C, neither the "new" nor the "init" functions are 
called on the object, only "finalize". No wonder I get segfaults in the 
real life application.


So how is this done right? Here's the C module:


I believe you do it in C as you would in Python: you call the Series class!

pyseries = PyObject_CallObject((PyObject *)&series_type, NULL);

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Identifying tkinter version

2020-04-01 Thread Rich Shepard

Here, on Slackware-14.2, Python3-3.8.2 is installed. I would like to learn
which version of tkinter is provided with it. There's no local VERSION file
and tkinter.version() returns nothing.

How do I determine the installed version?

Regards,

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


Re: Identifying tkinter version

2020-04-01 Thread Tony van der Hoff




On 01/04/2020 17:34, Rich Shepard wrote:

Here, on Slackware-14.2, Python3-3.8.2 is installed. I would like to learn
which version of tkinter is provided with it. There's no local VERSION file
and tkinter.version() returns nothing.

How do I determine the installed version?

>>> import tkinter
>>> tkinter.TkVersion
8.6

--
Tony van der Hoff| mailto:t...@vanderhoff.org
Buckinghamshire, England |
--
https://mail.python.org/mailman/listinfo/python-list


Re: Identifying tkinter version [ANSWERED]

2020-04-01 Thread Rich Shepard

On Wed, 1 Apr 2020, Tony van der Hoff wrote:


How do I determine the installed version?

import tkinter
tkinter.TkVersion

8.6


Thanks, Tony. I was close, but still too far away.

Stay healthy,

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


Python3 module with financial accounts?

2020-04-01 Thread Peter Wiehe

Is there a Python3 module with financial accounts?

--
Greetings
Peter Wiehe
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Musbur

Am 01.04.2020 15:01 schrieb Rhodri James:

I believe you do it in C as you would in Python: you call the Series 
class!


pyseries = PyObject_CallObject((PyObject *)&series_type, NULL);


Well, that dumps core just as everything else I tried.

What does work, however, is calling PyType_Ready first:

PyType_Ready(&series_type);
pyseries = PyObject_New(Series, &series_type);
PyObject_Init((PyObject *)pyseries, &series_type);o

I don't understand, though, why I have to do that and when. Didn't that 
already happen when the module was imported? Do I need to do it whenever 
I create a new instance in C?

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


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Rhodri James

On 01/04/2020 18:24, Musbur wrote:

Am 01.04.2020 15:01 schrieb Rhodri James:

I believe you do it in C as you would in Python: you call the Series 
class!


pyseries = PyObject_CallObject((PyObject *)&series_type, NULL);


Well, that dumps core just as everything else I tried.

What does work, however, is calling PyType_Ready first:

     PyType_Ready(&series_type);
     pyseries = PyObject_New(Series, &series_type);
     PyObject_Init((PyObject *)pyseries, &series_type);o

I don't understand, though, why I have to do that and when. Didn't that 
already happen when the module was imported? Do I need to do it whenever 
I create a new instance in C?


It should have happened on your module being imported, the line was 
there in your code.  Stick a breakpoint on your module init function and 
see if it is being called.


(The "from thingy import *" always makes me nervous, but it shouldn't be 
responsible for this.)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Fw: Python installation problem

2020-04-01 Thread HERNANDEZ AGUIRRE JOSE GABRIEL DE LA DOLOROSA



En Mar, 31 Marzo, 2020 en 18:48, yo  escribió:
 

Para: python-list@python.org

I  installed  the Python software , but I could not find the python.exe file 
with the Unscramble software


What do you advise ?


Regards



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


Re: about to resolve problem in installation

2020-04-01 Thread anson freer
Re: Calvin Spealman,Terry Reedyreading Kapuganti Rakesh post
Terry Reedy said"You are re-running the installer.  Hit 'start' in lower
left corner andfind python under 'p'. Kapuganti Rakesh looks like he is
refering to modify setup and cancel is the only otheroption no "p". Then
Kapuganti Rakesh"I have already search in my pc but it is showing nothing
and later isearched python and started that app.After some it showingI am
getting confuse over this. pls help me"I did a Search user/"C"   and found
Anaconda2, Python2, jupyter and many applications for python.But what one
to pick?
I'm not versed with w10 but w8 is left click the four square box a menu popsup
right click search then press "p" and it came right up!I self taught myself
ms Access VBA and in my 80+ years I never assume I know everything,never
place blameJust fix the problem.Everyone is ignonant until there not and
can learn anything if they never give up.Now Anson Freer(me) had a simlar
problem I used the Python web site asked a question and was rejected""Hello!
I see you want to post a message to the Python List.  Wewould be happy to
help, but you must subscribe first:"I did now my mail has many "install"
problems. It's OK as I did fix my issue by reading them.questions:Will
Anaconda2, Python2, jupyter and many applications for python harm the
3.8.2?should
I be in Python Tutor and in this one(current email)at the same time?I want
to learn how to use PDF to read files that have racing form style forms(my
hobbie is Horse handicapping)I know I need to"get" the correct
modules.(trial an error)Youtube is Ok but I think your members and staff
want all to succeed and for me I help others because it makes me feel good
not the other way aroundI see boB Stepp nailed it
Thank you for your time

On Tue, Mar 31, 2020 at 6:59 PM boB Stepp  wrote:

> On Tue, Mar 31, 2020 at 12:02 PM Kapuganti Rakesh
>  wrote:
>
> > I have already search in my pc but it is showing nothing and later i
> > searched python and started that app.After some it showing
> > I am getting confuse over this. pls help me
>
> If you press your Windows key (or click on the Windows symbol on the
> task bar) you will have an alphabetically arranged list of programs.
> Scroll down till you reach Python 3.8.  Expand that entry by clicking
> on it.  If you did a normal installation you should see "IDLE...",
> "Python 3.8..." and "Python 3.8 Module Docs..."  For your purposes you
> probably would want to start with IDLE.  It will take you to Python's
> interactive interpreter.  You will see a prompt that looks like ">>>"
> You may type in Python statements after the prompt such as ">>> 3*2"
> You can do more in IDLE (Much more), but you will need to have a
> beginner's Python book or tutorial to guide you in what to do next.
>
> By the way, there is a Python Tutor list that exists to help newcomers
> to Python and/or programming.  Its subscription page may be found at:
>
> https://mail.python.org/mailman/listinfo/tutor
>
> Hope this helps you through your first steps!
>
> Cheers!
> boB
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 module with financial accounts?

2020-04-01 Thread Tim Chase
On 2020-04-01 19:27, Peter Wiehe wrote:
> Is there a Python3 module with financial accounts?

You'd have to be more specific.  For interacting with online accounts
with financial institutions?  For tracking financial data locally?

There's beancount (http://furius.ca/beancount/ and written in Python)
which does plaintext accounting (https://plaintextaccounting.org/)
for wrangling financial account information using double-entry
bookkeeping methods.

-tkc



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


Re: Identifying tkinter version [ANSWERED]

2020-04-01 Thread Christian Gollwitzer

Am 01.04.20 um 19:22 schrieb Rich Shepard:

On Wed, 1 Apr 2020, Tony van der Hoff wrote:


How do I determine the installed version?

import tkinter
tkinter.TkVersion

8.6


Thanks, Tony. I was close, but still too far away.


This only shows you the major version. There have been many updates to 
Tcl/Tk in "minor" releases, including lots of rework on Tk internals. 
Therefore, you need the patchlevel. YOu can get this by


root.eval('info patchlevel')

Apfelkiste:Test chris$ python3
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> root=tkinter.Tk()
>>> root.eval('info patchlevel')
'8.5.9'
>>>

(urks, I'll have to upgrade. 8.5.9 on OSX is seriously broken)

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


Re: Fw: Python installation problem

2020-04-01 Thread Michael Torrie
On 4/1/20 11:09 AM, HERNANDEZ AGUIRRE JOSE GABRIEL DE LA DOLOROSA wrote:
> I  installed  the Python software , but I could not find the python.exe file 
> with the Unscramble software

What is this "Unscramble software?"

After Python is installed, you probably will find the "Idle" integrated
development environment in your start menu under "Python."

Looks like recent versions of Python default to installing into your
home directory under AppData\Local\Programs\Python-38-32 (or -64).  Look
in there for python.exe and pythonw.exe.  Please note that Python is not
like Visual Studio. It's an interpreter that is meant to be run from the
command line with python script files you create in an editor.

It may also be helpful to click the option in the installed to add
Python to the PATH. That way you can just run python.exe from any
command prompt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fw: Python installation problem

2020-04-01 Thread Michael Torrie
On 4/1/20 11:09 AM, HERNANDEZ AGUIRRE JOSE GABRIEL DE LA DOLOROSA wrote:
> Para: python-list@python.org
> 
> I  installed  the Python software , but I could not find the python.exe file 
> with the Unscramble software

Actually in windows 10, Idle shows up in the start menu under the "I"s,
not in a python  folder.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: Problemas para ejecutar Python en windows 7

2020-04-01 Thread Honori R. Camacho
Ok.
1.- Necesitamos ayuda. No podemos ejecutar Python 3.5.4 en windows 7, se
descargo la version Python 3.5.4 y se instalo correctamente.Y se
corrigieron los path.
Pero no permite ejecutar los .py ni los .pyw por acceso directo. gracias.


* Usa (SL) Software Libre ...Twitter: @rhonoricBlog Spot:
http://rhonoric.blogspot.com/ *


-- Forwarded message -
De: Honori R. Camacho 
Date: mié., 1 abr. 2020 a las 13:45
Subject: Problemas para ejecutar Python en windows 7
To: 


1.- Necesitamos ayuda. No podemos ejecutar Python 3.5.4 en windows 7, se
descargo la version Python 3.5.4 y se instalo correctamente.Y se
corrigieron los path.
Pero no permite ejecutar los .py ni los .pyw por acceso directo. gracias.


* Usa (SL) Software Libre ...Twitter: @rhonoricBlog Spot:
http://rhonoric.blogspot.com/ *
-- 
https://mail.python.org/mailman/listinfo/python-list


questions:

2020-04-01 Thread anson freer
Will Anaconda2, Python2, jupyter and many applications I have for python
harm the 3.8.2?
should I be in Python Tutor and in this one(current email)at the same time?
Or is it one or the other not both
I want to learn how to use PDF to read files that have racing form style
forms(my hobbie is Horse handicapping)
I know I need to"get" the correct modules.(trial an error)but I don't know
all the correct terms yet
Be kind I'm in my 80's bu t age is just a number my brain thinks like a
teen my body refuses to listen.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 module with financial accounts?

2020-04-01 Thread Peter Wiehe

On 01.04.20 20:02, Tim Chase wrote:

On 2020-04-01 19:27, Peter Wiehe wrote:

Is there a Python3 module with financial accounts?

You'd have to be more specific.  For interacting with online accounts
with financial institutions?  For tracking financial data locally?

There's beancount (http://furius.ca/beancount/ and written in Python)
which does plaintext accounting (https://plaintextaccounting.org/)
for wrangling financial account information using double-entry
bookkeeping methods.

-tkc





It's for tracking my own expenses and income, using double-entries.

On first glance this is exactly what I was looking for!

Thank you

Peter

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


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread MRAB

On 2020-04-01 13:42, Musbur wrote:

Hi guys,

I'm wondering how to create an instance of an extension class I wrote.
There's a minimal self-contained C module at the bottom of this post
which exports two things: 1) a class Series, and 2) a function
make_series() which is supposed to create a Series object on the C side
and return it. The make_series function uses PyObject_New() and
PyObject_Init() to create the new instance, but all it produces is some
kind of zombie instance which tends to crash the application with a
segfault in real life. When instantiated from Python using Series(), I
get a well-behaved instance.

I've sprinkled the New, Init and Finalize functions with fprintf()s to
see what happens to the object during its lifetime.

When I run this test script:

  from series import *

  print("From Python")
  s1 = Series()
  del s1

  print("\nFrom C")
  s2 = make_series()
  del s2

I get this output:

  From Python
  New Series at 0x7f89313f6660
  Init Series at 0x7f89313f6660
  Finalize Series at 0x7f89313f6660

  From C
  Finalize Series at 0x7f89313f6678

So when created from C, neither the "new" nor the "init" functions are
called on the object, only "finalize". No wonder I get segfaults in the
real life application.

So how is this done right? Here's the C module:


[snip]

Try this instead:

#include 

typedef struct {
PyObject_HEAD
void* data;
} SeriesObject;

static PyTypeObject SeriesType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "_Series",
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "SeriesObject (msec, value) object",
};

PyObject* make_series(PyObject* unused) {
SeriesObject* series;

series = PyObject_New(SeriesObject, &SeriesType);
series->data = NULL;
fprintf(stderr, "New SeriesObject at %p\n", series);

return (PyObject*)series;
}

static void Series_dealloc(PyObject* self_) {
SeriesObject* self;

self = (SeriesObject*)self_;
fprintf(stderr, "Deallocate SeriesObject at %p\n", self);

PyObject_DEL(self);
}

PyObject* Series_new(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
SeriesObject* self;

self = (SeriesObject*)type->tp_alloc(type, 0);
self->data = NULL;
fprintf(stderr, "New Series at %p\n", self);

return (PyObject*)self;
}

static PyMethodDef Series_methods[] = {
{NULL, NULL, 0, NULL}
};

static PyMethodDef module_methods[] = {
{"make_series", (PyCFunction)make_series, METH_NOARGS,
  "Instantiate and return a new SeriesObject object."},
{NULL, NULL, 0, NULL}
};

static PyModuleDef series_module = {
PyModuleDef_HEAD_INIT,
"series",
"Defines the SeriesObject (time, value) class"
,
-1,
module_methods
};

PyMODINIT_FUNC PyInit_series(void) {
PyObject* m;

m = PyModule_Create(&series_module);

SeriesType.tp_dealloc = Series_dealloc;
SeriesType.tp_new = Series_new;
SeriesType.tp_methods = Series_methods;
if (PyType_Ready(&SeriesType) < 0)
return NULL;

PyModule_AddObject(m, "Series", (PyObject*)&SeriesType);

return m;
}
--
https://mail.python.org/mailman/listinfo/python-list


ANN: Wing Python IDE version 7.2.2 released

2020-04-01 Thread Wingware
Wing Python IDE version 7.2.2 introduces a How-To for using Wing Pro's 
remote development features with AWS, adds support for Python 3 enums, 
allows constraining Find Uses of imported symbols to only the current 
file, and makes a number of usability and stability improvements.


== Downloads ==

Wing Pro: https://wingware.com/downloads/wing-pro/7.2/binaries
Wing Personal: https://wingware.com/downloads/wing-personal/7.2/binaries
Wing 101: https://wingware.com/downloads/wing-101/7.2/binaries

Compare products: https://wingware.com/downloads

== Upgrading ==

See https://wingware.com/doc/install/upgrading for details on upgrading 
from Wing 6 and earlier, and https://wingware.com/doc/install/migrating 
for a list of compatibility notes.


== Details ==

For more information on this release please see 
https://wingware.com/news/2020-03-30


For more information on Wing Python IDE see https://wingware.com/

Thanks,

Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python
--
https://mail.python.org/mailman/listinfo/python-list


How To Change Package Representation on Shell?

2020-04-01 Thread Abdur-Rahmaan Janhangeer
Greetings list,

I have a custom package.

>>> import package
>>> package
'>

what do i have to modify from my package to have like

>>> package
Hi!

Thanks!

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy.com  | github

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


Re: How To Change Package Representation on Shell?

2020-04-01 Thread Rhodri James

On 01/04/2020 21:22, Abdur-Rahmaan Janhangeer wrote:

Greetings list,

I have a custom package.


import package
package

'>

what do i have to modify from my package to have like


package

Hi!


Do you mean "How do I override the str() or repr() of a module"?  I 
don't think you can.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How To Change Package Representation on Shell?

2020-04-01 Thread Chris Angelico
On Thu, Apr 2, 2020 at 7:37 AM Rhodri James  wrote:
>
> On 01/04/2020 21:22, Abdur-Rahmaan Janhangeer wrote:
> > Greetings list,
> >
> > I have a custom package.
> >
>  import package
>  package
> > '>
> >
> > what do i have to modify from my package to have like
> >
>  package
> > Hi!
>
> Do you mean "How do I override the str() or repr() of a module"?  I
> don't think you can.
>

Not easily. It is possible but only by replacing the module as you're
importing it.

Also, I'm not sure why you would even need/want to do this - Abdur,
can you elaborate on the use-case here?

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


Re: How To Change Package Representation on Shell?

2020-04-01 Thread Abdur-Rahmaan Janhangeer
Having fun with packages

Since i don't master packaging completely thought there was a __repr__.py
protocol nearby!
Might be useful maybe to replace it by a help message

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy.com  | github

Mauritius


On Thu, Apr 2, 2020 at 12:41 AM Chris Angelico  wrote:

> On Thu, Apr 2, 2020 at 7:37 AM Rhodri James  wrote:
> >
> > On 01/04/2020 21:22, Abdur-Rahmaan Janhangeer wrote:
> > > Greetings list,
> > >
> > > I have a custom package.
> > >
> >  import package
> >  package
> > > '>
> > >
> > > what do i have to modify from my package to have like
> > >
> >  package
> > > Hi!
> >
> > Do you mean "How do I override the str() or repr() of a module"?  I
> > don't think you can.
> >
>
> Not easily. It is possible but only by replacing the module as you're
> importing it.
>
> Also, I'm not sure why you would even need/want to do this - Abdur,
> can you elaborate on the use-case here?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


confused by matplotlib and subplots

2020-04-01 Thread Luca



Hello Covid fighters and dodgers,

I'm sort of confused by what I am seeing in a Pandas book.

This works:

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax3.plot(np.random.randn(50).cumsum(), 'k--');

but also this works!

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
plt.plot(np.random.randn(50).cumsum(), 'k--');

(the second one is actually the example in the book).

Why does it work? Isn't axX referring to one of the subplots and plt to 
the plot as a whole?


Thanks

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


Re: questions:

2020-04-01 Thread DL Neil via Python-list

On 2/04/20 6:49 AM, anson freer wrote:

Will Anaconda2, Python2, jupyter and many applications I have for python
harm the 3.8.2?
should I be in Python Tutor and in this one(current email)at the same time?
Or is it one or the other not both
I want to learn how to use PDF to read files that have racing form style
forms(my hobbie is Horse handicapping)
I know I need to"get" the correct modules.(trial an error)but I don't know
all the correct terms yet
Be kind I'm in my 80's bu t age is just a number my brain thinks like a
teen my body refuses to listen.



Welcome to the Python community!

(To my knowledge/I am not ListAdmin) Someone may *belong* to both lists 
(and more). If not, you'll be able to light your cigar from me, as we 
both go-down-in-flames...


*However,* posting the same question to both lists concurrently will not 
win you any friends! For 'beginner level' questions I recommend the 
Tutor list (per its stated objectives). That said, people do try to be 
helpful... and us 'silver surfers' need to stick-together (well, 
2-meters apart, together)


I'm not sure what you mean by "harm the 3.8.2". Is that the Python which 
your OpSys needs to operate?


The "pythonic" way to separate multiple Python environments is "virtual 
environments" (aka venv).


Because it is incumbent upon me to maintain client safety and security, 
I use separate Virtual Machines for each client/project. This is not 
typical.


The Anaconda system is well-regarded as a convenient entry into the 
Python eco-system. It is designed to be self-contained and to avoid 
'tainting' the underlying OpSys. They also try to 'shield' users from 
unfortunate gaffes and 'gotchas' in facilitating adding libraries from 
their own sources by providing their own mechanisms. Accordingly, it has 
a lot going for it - be aware of their 'freemium' business model.


There are a few Python libraries to read .PDF files. The 'problem' is 
that sometimes .PDF 'pages' are actually graphics, ie a 
photograph/photo-copy of the ink-squiggles on an original page; and 
sometimes they contain text which has been nicely formatted for 
(printed) presentation. The latter are considerably easier to access. 
Graphics must be interpreted using an OCR process (Optical Character 
Recognition), and that will make life considerably more complicated.


Take things slowly. Don't try to 'bite-off more than you can chew'. 
There are a number of good tutorials in book form, and on-line lectures 
which will help you to learn Python and pick-up the terminology. Such is 
a perennial question, answered many times on the Tutor discussion list 
and therefore accessible through those archives!



Web.Refs:
https://docs.python.org/3/tutorial/venv.html
https://www.anaconda.com/distribution/

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


How Does requests.get Work?

2020-04-01 Thread Abdur-Rahmaan Janhangeer
Greetings list,

I was viewing requests https://github.com/psf/requests

I know we can do `requests.get`

Found `get` defined in api.py

I would appreciate an explanation as to how to configure the package so
that we can use get directly. Thanks.

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy.com  | github

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


Re: How to uninstall Python3.7 in Windows using cmd ?

2020-04-01 Thread Barry Scott



> On 30 Mar 2020, at 02:03, Dennis Lee Bieber  wrote:
> 
> On Sun, 29 Mar 2020 07:24:03 -0400, Terry Reedy 
> declaimed the following:
> 
>> To clarify, the pydev/python.org installer does not use msi.  I don't 
>> know that anyone else does.  And if someone did, why do you think it 
>> would also uninstall the current installation?
> 
>   Because, if you did find an MSI installer, and installed the same
> version /over/ the existing install (same directory), then the MSI
> uninstall would be removing contents from that directory.

And then you will have a registry that knows about 2 installs only one of which 
you can remove.
This is not a good idea.

Barry

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


why are the ticker and date column labels lower than High Low Open Close

2020-04-01 Thread Rakesh Kapoor
I am using this to download stock prices. But i find that the column names are 
not in same row. I am guessing i am missing something.

import pandas as pd
import numpy as np
import datetime
import pandas_datareader as pdr



py.init_notebook_mode(connected=True)

# we download the stock prices for each ticker and then we do a mapping between 
data and name of the ticker
def get(tickers, startdate, enddate):
  def data(ticker):
return (pdr.get_data_yahoo(ticker, start=startdate, end=enddate))
  datas = map (data, tickers)
  return(pd.concat(datas, keys=tickers, names=['ticker', 'date']))

# Define the stocks to download. We'll download of Apple, Microsoft and the 
S&P500 index.
tickers = ['AAPL','IBM']

# We would like all available data from 01/01/2000 until 31/12/2018.
start_date = datetime.datetime(2016, 1, 1)
end_date = datetime.datetime(2019, 12, 31)

all_data = get(tickers, start_date, end_date)

see screenshot
https://i.imgur.com/Cmw20am.png


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


Re: How Does requests.get Work?

2020-04-01 Thread Juergen Brendel


Hello!

Can you elaborate on what you mean by "use directly"?

Juergen


On Thu, 2020-04-02 at 01:12 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
> 
> I was viewing requests https://github.com/psf/requests
> 
> I know we can do `requests.get`
> 
> Found `get` defined in api.py
> 
> I would appreciate an explanation as to how to configure the package
> so
> that we can use get directly. Thanks.
> 
> Kind Regards,
> 
> Abdur-Rahmaan Janhangeer
> compileralchemy.com  | github
> 
> Mauritius

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


Re: Fwd: Problemas para ejecutar Python en windows 7

2020-04-01 Thread DL Neil via Python-list

On 2/04/20 7:15 AM, Honori R. Camacho wrote:

Ok.
1.- Necesitamos ayuda. No podemos ejecutar Python 3.5.4 en windows 7, se
descargo la version Python 3.5.4 y se instalo correctamente.Y se
corrigieron los path.
Pero no permite ejecutar los .py ni los .pyw por acceso directo. gracias.


Hola!

Python installs differently to other MS-Windows packages. We expect to 
use it from the Command Line, although some components may be available 
from the Windows-Menu (varies by version of MS-Windows).


You will find the primary installation advice at 
https://docs.python.org/3/using/index.html. However, there are some 
translations at https://wiki.python.org/moin/SpanishLanguage

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


numpy array question

2020-04-01 Thread jagmit sandhu
python newbie. I can't understand the following about numpy arrays:

x = np.array([[0, 1],[2,3],[4,5],[6,7]])
x
array([[0, 1],
   [2, 3],
   [4, 5],
   [6, 7]])
x.shape
(4, 2)
y = x[:,0]
y
array([0, 2, 4, 6])
y.shape
(4,)

Why is the shape for y reported as (4,) ? I expected it to be a (4,1) array.
thanks in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Identifying tkinter version [ANSWERED]

2020-04-01 Thread Terry Reedy

On 4/1/2020 2:47 PM, Christian Gollwitzer wrote:

Am 01.04.20 um 19:22 schrieb Rich Shepard:

On Wed, 1 Apr 2020, Tony van der Hoff wrote:


How do I determine the installed version?

import tkinter
tkinter.TkVersion

8.6


Thanks, Tony. I was close, but still too far away.


This only shows you the major version. There have been many updates to 
Tcl/Tk in "minor" releases, including lots of rework on Tk internals. 
Therefore, you need the patchlevel. YOu can get this by


root.eval('info patchlevel')

Apfelkiste:Test chris$ python3
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import tkinter
 >>> root=tkinter.Tk()
 >>> root.eval('info patchlevel')
'8.5.9'


Or run IDLE, select Help > About IDLE and the patchlevel is displayed.


--
Terry Jan Reedy

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


Re: How Does requests.get Work?

2020-04-01 Thread Abdur-Rahmaan Janhangeer
When dev a package, if you can do:

>>> from package import x

does not mean you can do

>>> import package
>>> package.x

for requests i was wondering how requests package can have

>>> requests.get

while requests is defined in api.py

Kind Regards,


Abdur-Rahmaan Janhangeer

https://www.compileralchemy.com
https://www.github.com/Abdur-RahmaanJ

Mauritius

sent from gmail client on Android, that's why the signature is so ugly.

On Thu, 2 Apr 2020, 01:33 Juergen Brendel,  wrote:

>
> Hello!
>
> Can you elaborate on what you mean by "use directly"?
>
> Juergen
>
>
> On Thu, 2020-04-02 at 01:12 +0400, Abdur-Rahmaan Janhangeer wrote:
> > Greetings list,
> >
> > I was viewing requests https://github.com/psf/requests
> >
> > I know we can do `requests.get`
> >
> > Found `get` defined in api.py
> >
> > I would appreciate an explanation as to how to configure the package
> > so
> > that we can use get directly. Thanks.
> >
> > Kind Regards,
> >
> > Abdur-Rahmaan Janhangeer
> > compileralchemy.com  | github
> > 
> > Mauritius
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How Does requests.get Work?

2020-04-01 Thread Chris Angelico
On Thu, Apr 2, 2020 at 5:12 PM Abdur-Rahmaan Janhangeer
 wrote:
>
> When dev a package, if you can do:
>
> >>> from package import x
>
> does not mean you can do
>
> >>> import package
> >>> package.x
>
> for requests i was wondering how requests package can have
>
> >>> requests.get
>
> while requests is defined in api.py
>

Did you have a look at __init__.py?

https://github.com/psf/requests/blob/master/requests/__init__.py

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


Re: How Does requests.get Work?

2020-04-01 Thread Abdur-Rahmaan Janhangeer
Ah i get it

from .api import request, get, head, post, patch, put, delete, options

Whatever you import in __init__.py, you can access it directly. Thanks!

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy.com  | github

Mauritius


On Thu, Apr 2, 2020 at 10:15 AM Chris Angelico  wrote:

> On Thu, Apr 2, 2020 at 5:12 PM Abdur-Rahmaan Janhangeer
>  wrote:
> >
> > When dev a package, if you can do:
> >
> > >>> from package import x
> >
> > does not mean you can do
> >
> > >>> import package
> > >>> package.x
> >
> > for requests i was wondering how requests package can have
> >
> > >>> requests.get
> >
> > while requests is defined in api.py
> >
>
> Did you have a look at __init__.py?
>
> https://github.com/psf/requests/blob/master/requests/__init__.py
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list