Basic Python help

2020-10-23 Thread mikael petterson
Hi,

I need to use the following code but in java.

 END_DELIM = '\n##\n'
 def start_delim(data_len): return '\n#%s\n' % (data_len)
  data = "%s%s%s" % (start_delim(len(data)), data, END_DELIM)

Can anyone help me to understand what it means:

I am guessing now:

a function defined "start_delim" takes the length of a data string.
function does modulo on something. This something I am not sure of
:-) 
Does '\n#%s\n' will this be evaluated to a number  when %s i replaced with 
data_len? 

Then the result is used as one parameter in "%s%s%s" 
start_delim then for the other
data
END_DELIM

Your help is greatly appreciated!

br,

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


Re: Basic Python help

2020-10-23 Thread Frank Millman

On 2020-10-23 12:41 PM, mikael petterson wrote:

Hi,

I need to use the following code but in java.

  END_DELIM = '\n##\n'
  def start_delim(data_len): return '\n#%s\n' % (data_len)
   data = "%s%s%s" % (start_delim(len(data)), data, END_DELIM)

Can anyone help me to understand what it means:

I am guessing now:

a function defined "start_delim" takes the length of a data string.
function does modulo on something. This something I am not sure of
:-)
Does '\n#%s\n' will this be evaluated to a number  when %s i replaced with 
data_len?

Then the result is used as one parameter in "%s%s%s"
start_delim then for the other
data
END_DELIM



I think it is simpler than that.

>>>
>>> '\n#%s\n' % 2
'\n#2\n'
>>>

All it is doing is replacing '%s' with the length of the string.

So the result is the concatenation of -

1. '\n' + '#' + length of string + '\n'  as the start delimiter

2. the string itself

3. '\n' + '#' + '#' + '\n'  as the end delimiter

Frank Millman

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


Re: Basic Python help

2020-10-23 Thread mikael petterson
fredag 23 oktober 2020 kl. 13:22:55 UTC+2 skrev Frank Millman:
> On 2020-10-23 12:41 PM, mikael petterson wrote:
> > Hi, 
> > 
> > I need to use the following code but in java. 
> > 
> > END_DELIM = '\n##\n' 
> > def start_delim(data_len): return '\n#%s\n' % (data_len) 
> > data = "%s%s%s" % (start_delim(len(data)), data, END_DELIM) 
> > 
> > Can anyone help me to understand what it means: 
> > 
> > I am guessing now: 
> > 
> > a function defined "start_delim" takes the length of a data string. 
> > function does modulo on something. This something I am not sure of 
> > :-) 
> > Does '\n#%s\n' will this be evaluated to a number when %s i replaced with 
> > data_len? 
> > 
> > Then the result is used as one parameter in "%s%s%s" 
> > start_delim then for the other 
> > data 
> > END_DELIM 
> >
> I think it is simpler than that. 
> 
> >>> 
> >>> '\n#%s\n' % 2 
> '\n#2\n' 
> >>> 
> 
> All it is doing is replacing '%s' with the length of the string. 
> 
> So the result is the concatenation of - 
> 
> 1. '\n' + '#' + length of string + '\n' as the start delimiter 
> 
> 2. the string itself 
> 
> 3. '\n' + '#' + '#' + '\n' as the end delimiter 
> 
> Frank Millman

Yes that was simpler than I thought. Thanks a lot!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread Grant Edwards
On 2020-10-22, Michael Torrie  wrote:

> I doubt you'll find any jobs connected a particular Python GUI toolkit.
> Except maybe at Red Hat.

A couple years ago my employer was looking for (and hired) a Python wx
application developer.

> Most likely you'll find Python used in web app development, back-end
> server system programming, scripting, etc.

Where I work, we use it exclusively for command line and GUI
application development. That may not be terribly common, but there
are jobs in actual application development.

> Of course Python can be used with a variety of GUI toolkits including
> Tk, wx, GTK+, and Qt, to make desktop applications of course, but it's
> not commercially common and I wouldn't ever expect to see that on a job
> posting.

Really? Never?

--
Grant


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


Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread Grant Edwards
On 2020-10-22, Terry Reedy  wrote:
> On 10/22/2020 2:58 PM, Lammie Jonson wrote:
>
>> I looked at tkinter which seems to have quite a few examples out
>> there, but when I searched indeed.com for tkinter and wxpython it
>> appeared that there was hardly any job listings mentioning
>> those. Why is that ?
>
> I think that commercial desktop applications with a python
> compatible GUI would likely use QT or a Python binding thereof.

Agreed. If you want to improve you "hirability" for GUI application
development, I would probably put Qt first.  Then gobject or
wx. Tkinter would probably be last.

--
Grant




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


Issue with Python

2020-10-23 Thread Ifeanyi Obinelo
Hello! I am a Python programmer and I love the language. However, I
installed Python 3.9 and suddenly, pip does not install Python libraries
anymore. It says that I need Visual Studio C++ 2014 and exits with:

"ERROR: Command errored out with exit status 1:..error: Microsoft Visual
C++ 14.0 is required. Get it with "Build Tools for Visual Studio":
https://visualstudio.microsoft.com/downloads/";
(The complete output is about 302 lines long. I will attach at the end of
the email.)

But I never needed Visual C++ 14 to install modules. Plus I have a bunch of
C++ redistributables (but not 14). Is there any thing I can do to fix this?

Also, is there any way to carry over my libraries and modules from my
previous Python installation (Python 3.8.5)? Or do I need to manually
reinstall them?

Thank you for your help. Python is awesome!

CMD OUTPUT BELOW...

C:\Users\USER-1>pip install pandas
Defaulting to user installation because normal site-packages is not
writeable
Collecting pandas
  Using cached pandas-1.1.3.tar.gz (5.2 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\program files\python39\python.exe' 'c:\program
files\python39\lib\site-packages\pip' install --ignore-installed --no-user
--prefix
'C:\Users\USER-1\AppData\Local\Temp\pip-build-env-mhg8fpe_\overlay'
--no-warn-script-location --no-binary :none: --only-binary :none: -i
https://pypi.org/simple -- setuptools wheel 'Cython>=0.29.21,<3'
'numpy==1.15.4; python_version=='"'"'3.6'"'"' and
platform_system!='"'"'AIX'"'"'' 'numpy==1.15.4;
python_version=='"'"'3.7'"'"' and platform_system!='"'"'AIX'"'"''
'numpy==1.17.3; python_version>='"'"'3.8'"'"' and
platform_system!='"'"'AIX'"'"'' 'numpy==1.16.0;
python_version=='"'"'3.6'"'"' and platform_system=='"'"'AIX'"'"''
'numpy==1.16.0; python_version=='"'"'3.7'"'"' and
platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3;
python_version>='"'"'3.8'"'"' and platform_system=='"'"'AIX'"'"''
   cwd: None
  Complete output (302 lines):
  Ignoring numpy: markers 'python_version == "3.6" and platform_system !=
"AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_system !=
"AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6" and platform_system ==
"AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_system ==
"AIX"' don't match your environment
  Ignoring numpy: markers 'python_version >= "3.8" and platform_system ==
"AIX"' don't match your environment
  Collecting setuptools
Using cached setuptools-50.3.2-py3-none-any.whl (785 kB)
  Collecting wheel
Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
  Collecting Cython<3,>=0.29.21
Using cached Cython-0.29.21-py2.py3-none-any.whl (974 kB)
  Collecting numpy==1.17.3
Using cached numpy-1.17.3.zip (6.4 MB)
  Using legacy 'setup.py install' for numpy, since package 'wheel' is not
installed.
  Installing collected packages: setuptools, wheel, Cython, numpy
  Running setup.py install for numpy: started
  Running setup.py install for numpy: finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: 'c:\program files\python39\python.exe' -u -c 'import sys,
setuptools, tokenize; sys.argv[0] =
'"'"'C:\\Users\\USER-1\\AppData\\Local\\Temp\\pip-install-vtk9r3ug\\numpy\\setup.py'"'"';
__file__='"'"'C:\\Users\\USER-1\\AppData\\Local\\Temp\\pip-install-vtk9r3ug\\numpy\\setup.py'"'"';f=getattr(tokenize,
'"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
install --record
'C:\Users\USER-1\AppData\Local\Temp\pip-record-1i78k7r5\install-record.txt'
--single-version-externally-managed --prefix
'C:\Users\USER-1\AppData\Local\Temp\pip-build-env-mhg8fpe_\overlay'
--compile --install-headers
'C:\Users\USER-1\AppData\Local\Temp\pip-build-env-mhg8fpe_\overlay\Include\numpy'
   cwd:
C:\Users\USER-1\AppData\Local\Temp\pip-install-vtk9r3ug\numpy\
  Complete output (277 lines):
  Running from numpy source directory.

  Note: if you need reliable uninstall behavior, then install
  with pip instead of using `setup.py install`:

- `pip install .`   (from a git repo or downloaded source
 release)
- `pip install numpy`   (last NumPy release on PyPi)


  blas_opt_info:
  blas_mkl_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils;
trying from distutils
  customize MSVCCompiler
libraries mkl_rt not found in ['c:\\program files\\python39\\lib',
'C:\\', 'c:\\program files\\python39\\libs']
NOT AVAILABLE

  blis_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils;
trying from distutils
  customize MSVCCompiler
libraries blis not found in ['c:\\program files\\python39\\lib',
'C:\\', 'c:\\program files\\p

Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread John Pote



On 23/10/2020 05:47, Grant Edwards wrote:



I think that commercial desktop applications with a python
compatible GUI would likely use QT or a Python binding thereof.

Agreed. If you want to improve you "hirability" for GUI application
development, I would probably put Qt first.  Then gobject or
wx. Tkinter would probably be last.


I've used tkinter and wxPython occasionally in the past for 1 off test 
tasks (and interest). What's the advantage of Qt?


John

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


Re: Issue with Python

2020-10-23 Thread Mats Wichmann
On 10/23/20 3:52 AM, Ifeanyi Obinelo wrote:
> Hello! I am a Python programmer and I love the language. However, I
> installed Python 3.9 and suddenly, pip does not install Python libraries
> anymore. It says that I need Visual Studio C++ 2014 and exits with:
> 
> "ERROR: Command errored out with exit status 1:..error: Microsoft Visual
> C++ 14.0 is required. Get it with "Build Tools for Visual Studio":
> https://visualstudio.microsoft.com/downloads/";
> (The complete output is about 302 lines long. I will attach at the end of
> the email.)
> 
> But I never needed Visual C++ 14 to install modules. Plus I have a bunch of
> C++ redistributables (but not 14). Is there any thing I can do to fix this?
> 
> Also, is there any way to carry over my libraries and modules from my
> previous Python installation (Python 3.8.5)? Or do I need to manually
> reinstall them?

Sometimes it's good to be a little patient!

*Some* modules, certainly not all, use compiled binary components.
Usually if they're big and consider they have performance-critical
elements, so they use the C API to make binary bits.  When pip goes to
install, it tries to find a wheel that matches your configuration.  If
there are no binary bits, an "any" type wheel will work fine, and there
are no issues.  If there are binary bits, it looks for a combination of
python version, architecture, and maybe bit-ness.  Failing to find a
suitable wheel, it pulls the source distribution and tries to install
that (by calling setup.py), and that will try to compile.

Since Windows doesn't come with a C compiler by default, that fails for
you. You could be ambitious and install Visual Studio Build Tools
(Community edition) or some such, and hope it works; it usually doesn't
without further setup.

Check if modules you care about exist for 3.9 by searching for them on
pypi.org and clicking on Download to see the available versions.  The
projects you care about will inevitably catch up, but it's still early
days for 3.9 and they have their own release processes to go through.

Or you can look on an unofficial site that does early builds - take to
heart the warning about the unsupported nature of these and tread carefully:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-image

Or... stick with 3.8 for a while longer, there's nothing at all wrong
with 3.8!

"Do I need to manually reinstall" - get pip to dump out the modules into
a requirements.txt file, and use that to populate your new environment.
Then at least it won't be manual.

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


Re: Debugging a memory leak

2020-10-23 Thread Dieter Maurer
Pasha Stetsenko wrote at 2020-10-22 17:51 -0700:
> ...
>I'm a maintainer of a python library "datatable" (can be installed from
>PyPi), and i've been recently trying to debug a memory leak that occurs in
>my library.
>The program that exposes the leak is quite simple:
>```
>import datatable as dt
>import gc  # just in case
>
>def leak(n=10**7):
>for i in range(n):
>z = dt.update()
>
>leak()
>gc.collect()
>input("Press enter")
>```
>Note that despite the name, the `dt.update` is actually a class, though it
>is defined via Python C API. Thus, this script is expected to create and
>then immediately destroy 10 million simple python objects.
>The observed behavior, however,  is  that the script consumes more and more
>memory, eventually ending up at about 500M. The amount of memory the
>program ends up consuming is directly proportional to the parameter `n`.
>
>The `gc.get_objects()` does not show any extra objects however.

For efficiency reasons, the garbage collector treats only
objects from types which are known to be potentially involved in cycles.
A type implemented in "C" must define `tp_traverse` (in its type
structure) to indicate this possibility.
`tp_traverse` also tells the garbage collector how to find referenced
objects.
You will never find an object in the result of `get_objects` the
type of which does not define `tp_traverse`.

> ...
>Thus, the object didn't actually "leak" in the normal sense: its refcount
>is 0 and it was reclaimed by the Python runtime (when i print a debug
>message in tp_dealloc, i see that the destructor gets called every time).
>Still, Python keeps requesting more and more memory from the system instead
>of reusing the memory  that was supposed to be freed.

I would try to debug what happens further in `tp_dealloc` and its callers.
You should eventually see a `PyMem_free` which gives the memory back
to the Python memory management (built on top of the C memory management).

Note that your `tp_dealloc` should not call the "C" library's "free".
Python builds its own memory management (--> "PyMem_*") on top
of the "C" library. It handles all "small" memory requests
and, if necessary, requests big data chunks via `malloc` to split
them into the smaller sizes.
Should you "free" small memory blocks directly via "free", that memory
becomes effectively unusable by Python (unless you have a special
allocation as well).
-- 
https://mail.python.org/mailman/listinfo/python-list


Logic Bank

2020-10-23 Thread gMail
Hello, All

I am pleased to announce the release of Logic Bank.

Logic Bank introduces spreadsheet-like rules for multi-table derivation and 
constraint logic for SQLAchemy databases - 40X more concise than legacy code, 
extensible and manageable using Python.  Described in this article 
, open 
source on git. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread Christian Gollwitzer

Am 22.10.20 um 23:52 schrieb Paul Rubin:

Michael Torrie  writes:

I doubt you'll find any jobs connected a particular Python GUI toolkit.



It would be really nice if there was a way to straightforwardly run
Tkinter applications on Android.  You'd install a single .apk and that
would let you run your Tkinter apps and make launchers for them.


It's not unrealistic - there is AndroWish to run Tcl/Tk on Android 
including GUI and connection to Android specific services (subcommand 
"borg"). Someone in the Python community would need to make the Tkinter 
bridge with a native Python for Android.



https://www.androwish.org/home/home

Christian

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


Re: Debugging a memory leak

2020-10-23 Thread Pasha Stetsenko
Thanks for all the replies!
Following Chris's advice, I tried to reduce the code to the smallest
reproducible example (I guess I should have done it sooner),
but here's what I came up with:
```
  #include 
  #include 

  static int my_init(PyObject*, PyObject*, PyObject*) { return 0; }
  static void my_dealloc(PyObject*) {}

  static void init_mytype(PyObject* module) {
PyTypeObject* type = new PyTypeObject();
std::memset(type, 0, sizeof(PyTypeObject));
Py_INCREF(type);

type->tp_basicsize = static_cast(sizeof(PyObject));
type->tp_itemsize = 0;
type->tp_flags = Py_TPFLAGS_DEFAULT;
type->tp_new   = &PyType_GenericNew;
type->tp_name  = "mytype";
type->tp_doc   = "[temporary]";
type->tp_init  = my_init;
type->tp_dealloc = my_dealloc;
PyType_Ready(type);
PyModule_AddObject(module, "mytype", reinterpret_cast(type));
  }
```
(my original `update` object had some fields in it, but it turns out they
don't need to be present in order for the problem to manifest. So in this
case I'm creating a custom object which is the same as basic PyObject).
The `init_mytype()` function creates a custom type and attaches it to a
module. After this, creating 100M instances of the object will cause the
process memory to swell to 1.5G:
```
for i  in range(10**8):
z = dt.mytype()
```
I know this is not normal because if instead i used a builtin type such as
`list`, or a python-defined class such as `class  A: pass`, then the
process will remain at steady RAM usage of about 6Mb.

I've  tested this on a Linux platform as well (using docker image
quay.io/pypa/manylinux2010_x86_64), and the problem is present there as
well.

---
PS: The library I'm working on is open source, available at
https://github.com/h2oai/datatable, but the code I posted  above is
completely independent from my library.

On Fri, Oct 23, 2020 at 10:44 AM Dieter Maurer  wrote:

> Pasha Stetsenko wrote at 2020-10-22 17:51 -0700:
> > ...
> >I'm a maintainer of a python library "datatable" (can be installed from
> >PyPi), and i've been recently trying to debug a memory leak that occurs in
> >my library.
> >The program that exposes the leak is quite simple:
> >```
> >import datatable as dt
> >import gc  # just in case
> >
> >def leak(n=10**7):
> >for i in range(n):
> >z = dt.update()
> >
> >leak()
> >gc.collect()
> >input("Press enter")
> >```
> >Note that despite the name, the `dt.update` is actually a class, though it
> >is defined via Python C API. Thus, this script is expected to create and
> >then immediately destroy 10 million simple python objects.
> >The observed behavior, however,  is  that the script consumes more and
> more
> >memory, eventually ending up at about 500M. The amount of memory the
> >program ends up consuming is directly proportional to the parameter `n`.
> >
> >The `gc.get_objects()` does not show any extra objects however.
>
> For efficiency reasons, the garbage collector treats only
> objects from types which are known to be potentially involved in cycles.
> A type implemented in "C" must define `tp_traverse` (in its type
> structure) to indicate this possibility.
> `tp_traverse` also tells the garbage collector how to find referenced
> objects.
> You will never find an object in the result of `get_objects` the
> type of which does not define `tp_traverse`.
>
> > ...
> >Thus, the object didn't actually "leak" in the normal sense: its refcount
> >is 0 and it was reclaimed by the Python runtime (when i print a debug
> >message in tp_dealloc, i see that the destructor gets called every time).
> >Still, Python keeps requesting more and more memory from the system
> instead
> >of reusing the memory  that was supposed to be freed.
>
> I would try to debug what happens further in `tp_dealloc` and its callers.
> You should eventually see a `PyMem_free` which gives the memory back
> to the Python memory management (built on top of the C memory management).
>
> Note that your `tp_dealloc` should not call the "C" library's "free".
> Python builds its own memory management (--> "PyMem_*") on top
> of the "C" library. It handles all "small" memory requests
> and, if necessary, requests big data chunks via `malloc` to split
> them into the smaller sizes.
> Should you "free" small memory blocks directly via "free", that memory
> becomes effectively unusable by Python (unless you have a special
> allocation as well).
>
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Question on ABC classes

2020-10-23 Thread Schachner, Joseph
I'm a C++ programmer and Python programmer as well.  Python classes are not 
exactly like C++ classes.

If you define a class where every method has an implementation, then it really 
isn't abstract.  It can be instantiated.  You can force it to be abstract by 
doing from abc import ABCMeta and declare class myclass(metaClass=ABCMeta).  
Otherwise, Python does not have a way to know that you intend the class to be 
abstract unless it contains an @abstractmethod that makes it actually abstract. 
  Such a method must be overridden.

Usually, an Abstract Base Class defines an interface.  You can make all the 
functions @abstractmethod, and separately make a another class that is based on 
your ABC and provides default implementations for all the functions.  Other 
classes can be based on that class.   I am not an authority on this so let me 
refer you to actual documentation:

See: https://docs.python.org/3/library/abc.html, that should help you. 

-Original Message-
From: Julio Di Egidio  
Sent: Thursday, October 22, 2020 12:26 PM
To: [email protected]
Subject: Question on ABC classes

Hello guys,

I am professional programmer but quite new to Python, and I am trying to get 
the grips of some peculiarities of the language.

Here is a basic question: if I define an ABC class, I can still instantiate the 
class unless there are abstract methods defined in the class.

(In the typical OO language the class would be not instantiable, period, since 
it's "abstract".  But this is not so in Python, to the point that, also for 
uniformity, I am feeling compelled to define an @abstractmethod __init__ in my 
ABC classes, whether they need one or not, and whether there are other abstract 
methods in the class or not.)

Now, I do read in the docs that that is as intended, but I am not understanding 
the rationale of it: why only if there are abstract methods defined in an ABC 
class is instantiation disallowed?  IOW, why isn't subclassing from ABC enough?

Thanks for any enlightenment,

Julio

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


Re: Debugging a memory leak

2020-10-23 Thread MRAB

On 2020-10-23 19:32, Pasha Stetsenko wrote:

Thanks for all the replies!
Following Chris's advice, I tried to reduce the code to the smallest
reproducible example (I guess I should have done it sooner),
but here's what I came up with:
```
   #include 
   #include 

   static int my_init(PyObject*, PyObject*, PyObject*) { return 0; }
   static void my_dealloc(PyObject*) {}

   static void init_mytype(PyObject* module) {
 PyTypeObject* type = new PyTypeObject();
 std::memset(type, 0, sizeof(PyTypeObject));
 Py_INCREF(type);

 type->tp_basicsize = static_cast(sizeof(PyObject));
 type->tp_itemsize = 0;
 type->tp_flags = Py_TPFLAGS_DEFAULT;
 type->tp_new   = &PyType_GenericNew;
 type->tp_name  = "mytype";
 type->tp_doc   = "[temporary]";
 type->tp_init  = my_init;
 type->tp_dealloc = my_dealloc;
 PyType_Ready(type);
 PyModule_AddObject(module, "mytype", reinterpret_cast(type));
   }
```


You're setting the deallocation function to 'my_dealloc', but that 
function isn't deallocating the object.


Try something like this:

static void my_dealloc(PyObject* obj) {
PyObject_DEL(obj);
}

[snip]
--
https://mail.python.org/mailman/listinfo/python-list


Re: Debugging a memory leak

2020-10-23 Thread Pasha Stetsenko
Thanks MRAB, this was it.
I guess I was thinking about tp_dealloc as a C++ destructor, where the base
class' destructor is called automatically.

On Fri, Oct 23, 2020 at 11:59 AM MRAB  wrote:

> On 2020-10-23 19:32, Pasha Stetsenko wrote:
> > Thanks for all the replies!
> > Following Chris's advice, I tried to reduce the code to the smallest
> > reproducible example (I guess I should have done it sooner),
> > but here's what I came up with:
> > ```
> >#include 
> >#include 
> >
> >static int my_init(PyObject*, PyObject*, PyObject*) { return 0; }
> >static void my_dealloc(PyObject*) {}
> >
> >static void init_mytype(PyObject* module) {
> >  PyTypeObject* type = new PyTypeObject();
> >  std::memset(type, 0, sizeof(PyTypeObject));
> >  Py_INCREF(type);
> >
> >  type->tp_basicsize = static_cast(sizeof(PyObject));
> >  type->tp_itemsize = 0;
> >  type->tp_flags = Py_TPFLAGS_DEFAULT;
> >  type->tp_new   = &PyType_GenericNew;
> >  type->tp_name  = "mytype";
> >  type->tp_doc   = "[temporary]";
> >  type->tp_init  = my_init;
> >  type->tp_dealloc = my_dealloc;
> >  PyType_Ready(type);
> >  PyModule_AddObject(module, "mytype",
> reinterpret_cast(type));
> >}
> > ```
>
> You're setting the deallocation function to 'my_dealloc', but that
> function isn't deallocating the object.
>
> Try something like this:
>
> static void my_dealloc(PyObject* obj) {
>  PyObject_DEL(obj);
> }
>
> [snip]
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Debugging a memory leak

2020-10-23 Thread Dieter Maurer
Pasha Stetsenko wrote at 2020-10-23 11:32 -0700:
> ...
>  static int my_init(PyObject*, PyObject*, PyObject*) { return 0; }
>  static void my_dealloc(PyObject*) {}

I think, the `dealloc` function is responsible to actually
free the memory area.

I see for example:
static void
Spec_dealloc(Spec* self)
{
/* PyType_GenericAlloc that you get when you don't
   specify a tp_alloc always tracks the object. */
PyObject_GC_UnTrack((PyObject *)self);
if (self->weakreflist != NULL) {
PyObject_ClearWeakRefs(OBJECT(self));
}
Spec_clear(self);
Py_TYPE(self)->tp_free(OBJECT(self));
}


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


Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread Grant Edwards
On 2020-10-23, John Pote  wrote:
> On 23/10/2020 05:47, Grant Edwards wrote:
>>
>>> I think that commercial desktop applications with a python
>>> compatible GUI would likely use QT or a Python binding thereof.
>> Agreed. If you want to improve you "hirability" for GUI application
>> development, I would probably put Qt first.  Then gobject or
>> wx. Tkinter would probably be last.
>
> I've used tkinter and wxPython occasionally in the past for 1 off test 
> tasks (and interest). What's the advantage of Qt?

I think it may look/act more "native" than the others. It has also had
good support for multiple platforms for a long time. For whatever
reason, it seems to the more popular choice for commercially
distributed Python apps.

Getting Tkinter to look and act like a "native" app takes a lot of
effort, and sometimes is just not possible. Distributing Tkinter apps
is a PITA. Even trivial apps tend to turn into large bundles because
you're including all of TCL with them.

--
Grant


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


Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread Terry Reedy

On 10/23/2020 12:52 PM, John Pote wrote:


On 23/10/2020 05:47, Grant Edwards wrote:



I think that commercial desktop applications with a python
compatible GUI would likely use QT or a Python binding thereof.

Agreed. If you want to improve you "hirability" for GUI application
development, I would probably put Qt first.  Then gobject or
wx. Tkinter would probably be last.


I've used tkinter and wxPython occasionally in the past for 1 off test 
tasks (and interest). What's the advantage of Qt?


For you usage, perhaps None.  Qt is an *application* framework that 
includes a GUI module likely bigger than tkinter.  Its non-GUI parts 
replace things other than tkinter in the stdlib or on pypi.


--
Terry Jan Reedy


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