a &= b
Hi, Could you please give me some more hints on: a &= b It's very difficult for me to understand. -- https://mail.python.org/mailman/listinfo/python-list
Re: a &= b
On Fri, Oct 4, 2019 at 5:01 AM Hongyi Zhao wrote: > > Hi, > > Could you please give me some more hints on: > > a &= b > > It's very difficult for me to understand. > -- > https://mail.python.org/mailman/listinfo/python-list & is bitwise And. a &= b is equivalent to a = a & b -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: a &= b
On Fri, 4 Oct 2019 at 19:02, Hongyi Zhao wrote: > > Could you please give me some more hints on: > > a &= b $ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> a = 15 >>> b = 3 >>> c = a & b >>> d = a >>> d &= b >>> for i in [a, b, c, d]: ... print('{:04b}'.format(i)) ... 0011 0011 0011 >>> -- https://mail.python.org/mailman/listinfo/python-list
from ./.. import
Hi, See this file: https://github.com/hongyi-zhao/dotbot/blob/master/dotbot/messenger/ messenger.py It has the following codes: from ..util.singleton import Singleton from ..util.compat import with_metaclass from .color import Color from .level import Level I just cannot figure out why they using the ``from ./.. import'' to import modules. Any hints? -- https://mail.python.org/mailman/listinfo/python-list
Re: from ./.. import
On 2019-10-04, Hongyi Zhao wrote: > See this file: > https://github.com/hongyi-zhao/dotbot/blob/master/dotbot/messenger/ > messenger.py > > It has the following codes: > > from ..util.singleton import Singleton > from ..util.compat import with_metaclass > from .color import Color > from .level import Level > > I just cannot figure out why they using the ``from ./.. import'' to > import modules. Why wouldn't they be? That's how you import things from the current/parent package. -- https://mail.python.org/mailman/listinfo/python-list
Re: pathlib
> On 3 Oct 2019, at 13:04, Richard Damon wrote: > > I am not sure that Concrete is really the right term here, but the > beginning of the documentation for Pathlib does sort of define what it > means here: There is a need to describe three ideas. The PurePath The OS Specific PurePath's, WindowPurePath and PosixPurePath. The OS Specific Path's with IO operations. WindowsPath and PosixPath. And lets not forget the Path is a factory for for one of OS Specific objects. Barry -- https://mail.python.org/mailman/listinfo/python-list
Re: pathlib
> On 2 Oct 2019, at 23:58, DL Neil via Python-list > wrote: > > In my mind, I'm wondering if it will come to that (having 'got past' the > original observation/issue, I'm concerned by .rename()'s silent errors, for > example). However, that 'outside' research, eg StackOverflow, shows that > sub-classing pathlib is problematic, and quite possibly not part of the > design (this is repeating 'gossip' - I'm not going to try to justify the > comment or the claim). That said, last night my code sub-classing Path() > seemed to work quite happily (albeit only tested on a 'Posix' box). The > yawning chasm/gaping jaws below, however, are that I've probably made yet > another 'assumption' about how things 'should' work. Run for the hills! What silent error? It raise expects if the rename does not work. Or do you mean it does not mutate the path on a rename? Thats a feature not a bug. Barry -- https://mail.python.org/mailman/listinfo/python-list
Re: Print to Paper
Daniel writes: > How to do a code to print to paper? please post here a "Hello World" > code to be printed on paper with an inkjet. > Thanks > Daniel It depends on the Operating System. Python doesn't have a standard, system-independent way to print to paper. On most Unix-like systems (like my MacOS) the following works: from subprocess import Popen, PIPE p = Popen('lpr', stdin=PIPE) p.communicate(b'Hello World') p.stdin.close() p.wait() In a production system error checking should be added. Also if a nice layout is desired, you should probably want to generate a PDF file and send that to the printer, possibly with the use of LaTeX. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Print to Paper
How to do a code to print to paper? please post here a "Hello World" code to be printed on paper with an inkjet. Thanks Daniel --- Este email foi escaneado pelo Avast antivĂrus. https://www.avast.com/antivirus -- https://mail.python.org/mailman/listinfo/python-list
Access violation in Python garbage collector (visit_decref) - how to debug?
Hi all, We are running Python embedded in our C++ product and are now experiencing crashes (access violation reading 0xff on Windows) in the Python garbage collector. We got this on Python 3.6.4 originally, but I can reproduce it with both Python 3.6.8 and Python 3.7.4. The chances of producing a minimal example that reproduces it reliably are currently small I would say. All attempts to simplify the set up seem to cause the problem to go away. Indeed I can only reproduce it by sending a fairly large amount of data 2 or 3 times to our server - sending either half of the data does not reproduce it. I note that there have been a lot of crashes in this method reported over the years, and that efforts are underway in Python 3.8 to make it easier to find issues like this, i.e. https://bugs.python.org/issue36389. I won't be able to use Python 3.8 yet but I could potentially use it as a debugging tool I guess, if there was documentation available how to use these new features. I tried setting PYTHONMALLOC=debug but didn't get any more information that way. The python code is calling "json.loads" on a fairly large json unicode string with plenty of Swedish characters in it. It works at least once, and then crashes on the second or third send of the same data. I paste the stacktrace from Python 3.7.4 below. Please let me know how I can debug this further. I'm using Visual Studio 2017 on Windows 10 if that helps. Regards, Geoff Bache > [Inline Frame] python37.dll!visit_decref(_object *) Line 271 C python37.dll!dict_traverse(_object * op, int(*)(_object *, void *) visit, void * arg) Line 2982 C python37.dll!subtract_refs(_gc_head * containers) Line 296 C python37.dll!collect(int generation, __int64 * n_collected, __int64 * n_uncollectable, int nofail) Line 861 C python37.dll!collect_with_callback(int generation) Line 1029 C python37.dll!collect_generations() Line 1051 C [Inline Frame] python37.dll!_PyObject_GC_Alloc(int) Line 1708 C [Inline Frame] python37.dll!_PyObject_GC_Malloc(unsigned __int64 basicsize) Line 1718 C python37.dll!_PyObject_GC_New(_typeobject * tp) Line 1730 C python37.dll!new_dict(_dictkeysobject * keys, _object * * values) Line 584 C python37.dll!PyDict_New() Line 678 C python37.dll!_parse_object_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 730 C python37.dll!scan_once_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 1162 C python37.dll!_parse_array_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 869 C python37.dll!scan_once_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 1101 C python37.dll!scanner_call(_object * self, _object * args, _object * kwds) Line 1188 C python37.dll!_PyObject_FastCallKeywords(_object * callable, _object * const * stack, __int64 nargs, _object * kwnames) Line 199 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4619 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3095 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C python37.dll!_PyEval_EvalCodeWithName(_object * _co, _object * globals, _object * locals, _object * const * args, __int64 argcount, _object * const * kwnames, _object * const * kwargs, __int64 kwcount, int kwstep, _object * const * defs, __int64 defcount, _object * kwdefs, _object * closure, _object * name, _object * qualname) Line 3930 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 433 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4621 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3140 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C python37.dll!_PyEval_EvalCodeWithName(_object * _co, _object * globals, _object * locals, _object * const * args, __int64 argcount, _object * const * kwnames, _object * const * kwargs, __int64 kwcount, int kwstep, _object * const * defs, __int64 defcount, _object * kwdefs, _object * closure, _object * name, _object * qualname) Line 3930 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 433 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4621 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3111 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C python37.dll!_PyEval_EvalCodeWithName(_object * _co, _object * globals, _object * locals, _object * const * args, __int64 argcount, _object * const * kwnames, _object * const * kwargs, __int64 kwcount, int kwstep, _object * const * defs, __int64 defcount, _object * kwdefs, _object * closure, _object * name, _object * qualname) Line 3930 C [Inline Frame] python37.dll!_PyFunction_FastCall
Re: Access violation in Python garbage collector (visit_decref) - how to debug?
On Sat, Oct 5, 2019 at 5:38 AM Geoff Bache wrote: > > Hi all, > > We are running Python embedded in our C++ product and are now experiencing > crashes (access violation reading 0xff on Windows) in the Python > garbage collector. > > We got this on Python 3.6.4 originally, but I can reproduce it with both > Python 3.6.8 and Python 3.7.4. > > The chances of producing a minimal example that reproduces it reliably are > currently small I would say. All attempts to simplify the set up seem to > cause the problem to go away. > Indeed I can only reproduce it by sending a fairly large amount of data 2 > or 3 times to our server - sending either half of the data does not > reproduce it. Have you tried to reproduce the issue outside of your application? Even if it means creating a gigantic Python script with a whopping triple-quoted string for the input data, it'd be helpful to try this. If you CAN repro the problem, it'd be way easier to diagnose (since we don't need your code, just your test case); and if you CAN'T, it may mean an issue with the embedding aspects. What's your definition of "fairly large" here? How many kilobytes/megabytes/gigabytes, and how deeply nested is the JSON object? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Access violation in Python garbage collector (visit_decref) - how to debug?
On 2019-10-04 20:32, Geoff Bache wrote: Hi all, We are running Python embedded in our C++ product and are now experiencing crashes (access violation reading 0xff on Windows) in the Python garbage collector. We got this on Python 3.6.4 originally, but I can reproduce it with both Python 3.6.8 and Python 3.7.4. The chances of producing a minimal example that reproduces it reliably are currently small I would say. All attempts to simplify the set up seem to cause the problem to go away. Indeed I can only reproduce it by sending a fairly large amount of data 2 or 3 times to our server - sending either half of the data does not reproduce it. [snip] In my experience, it's most likely caused by incorrect refcounting, DECREFing too many times. -- https://mail.python.org/mailman/listinfo/python-list
Using a logging.Logger in a C extension
I am working my way through writing a C extension, and I've realized that I need to log a few messages from the C code. Ideally, I would pass my existing Logging.logger object into my C function and use PyObject_CallMethod to call the appropriate method on it (info, debug, etc.). PyArg_ParseTuple should be able to handle this with an "O!" format unit, but I can't figure out how to retrieve the type object for logging.Logger. Any hints, links, etc. appreciated. Thanks! -- Ian Pilcher arequip...@gmail.com "I grew up before Mark Zuckerberg invented friendship" -- https://mail.python.org/mailman/listinfo/python-list
Re: Print to Paper
On 2019-10-04, Daniel wrote: > How to do a code to print to paper? please post here a "Hello World" > code to be printed on paper with an inkjet. os.popen('lpr','w').write('Hello World\n') That's a bit old-school -- you should probably use subprocess.Popen instead. -- https://mail.python.org/mailman/listinfo/python-list
Re: Print to Paper
On 10/4/19 8:59 AM, Daniel wrote: > How to do a code to print to paper? please post here a "Hello World" > code to be printed on paper with an inkjet. What operating system? Are you using a graphical UI toolkit or is this a command-line program you're making? -- https://mail.python.org/mailman/listinfo/python-list
Re: Access violation in Python garbage collector (visit_decref) - how to debug?
Geoff Bache writes: > ... > We are running Python embedded in our C++ product and are now experiencing > crashes (access violation reading 0xff on Windows) in the Python > garbage collector. Errors like this are very difficult to analyse. The main reason: the memory corruption is likely far away from the point when it is finally detected (by an access violation in your case). Python can be built in a special way to add marks to its allocated memory blocks and verify their validity. This increases the chance to detect a memory corruption earlier and thereby facilitates the detection of the root cause. There are tools for the analysis of memory management problems (e.g. "valgrind", though this may be for Linux). In my experience, even with those tools, the analysis is very difficult. I have several times successfully analysed memory corruption problems. In those cases, I have been lucky that the corruption was reproducible and affected typically the same address. Thus, I could put a (hardware) memory breakpoint at this address stopping the program as soon as this address was written and then analyse the state in the debugger. This way, I could detect precisely which code caused the corruption. However, this was quite a long time ago; nowadays, modern operating systems employ address randomization thus reducing significantly that the corruption affects the same address (which may mean that you need to deactivate address randomization to get a better chance for this kind of analysis. -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a logging.Logger in a C extension
Ian Pilcher writes: > I am working my way through writing a C extension, and I've realized > that I need to log a few messages from the C code. Have a look at "cython". It significantly facilitates the realisation of C extensions, drastically reduces risks to make something wrong and makes it very easy to call back to Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: from ./.. import
On 10/4/2019 9:01 AM, Hongyi Zhao wrote: Hi, See this file: https://github.com/hongyi-zhao/dotbot/blob/master/dotbot/messenger/ messenger.py It has the following codes: from ..util.singleton import Singleton from ..util.compat import with_metaclass from .color import Color from .level import Level I just cannot figure out why they using the ``from ./.. import'' to import modules. These are 'relative imports'. Read the doc for import statements. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list