Re: Python MySQL Guide
Thank you for this offer. My reaction is I don't like having to scroll through one very long page to find what I'm looking for. Might you consider breaking it up into a number of smaller pages and giving an index as the main page? On Aug 9, 2018 5:18 PM, wrote: > Refer this complete guide on working with Python and MySQL > > https://pynative.com/python-mysql-tutorial/ > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Multiprocessing "Pool" aborts without any error message or return code? (Python 3.6.4, cygwin 32 bit, Windows Server 2012)
Please refer to: https://docs.python.org/3.6/library/multiprocessing.html the first example program. If I run it on Windows 10 (Python 3.6.4) or Linux Mint 18 (Python 3.5.2), it works as expected. On Windows Server 2012, however, I get no (none!) output, no matter if I run with admin rights or not: adminnkj@DTDKCPHAS1060 ~ $ python3 -V Python 3.6.4 adminnkj@DTDKCPHAS1060 ~ $ cat test.py from multiprocessing import Pool def f(x): return x*x if __name__ == '__main__': p = Pool(5) print(p.map(f, [1, 2, 3])) adminnkj@DTDKCPHAS1060 ~ $ python3 test.py ---> NB: no output <--- adminnkj@DTDKCPHAS1060 ~ $ echo $? 0 ---> NB: Normal exit code <--- I am a bit lost, running with -v -vv or -vvv does not help me much (here are the last lines of the latter): (cut) import 'multiprocessing.connection' # <_frozen_importlib_external.SourceFileLoader object at 0xffc913f0> import 'multiprocessing.queues' # <_frozen_importlib_external.SourceFileLoader object at 0xffc7ab10> # trying /usr/lib/python3.6/multiprocessing/synchronize.cpython-36m-i386-cygwin.dll # trying /usr/lib/python3.6/multiprocessing/synchronize.abi3.dll # trying /usr/lib/python3.6/multiprocessing/synchronize.dll # trying /usr/lib/python3.6/multiprocessing/synchronize.py # /usr/lib/python3.6/multiprocessing/__pycache__/synchronize.cpython-36.pyc matches /usr/lib/python3.6/multiprocessing/synchronize.py # code object from '/usr/lib/python3.6/multiprocessing/__pycache__/synchronize.cpython-36.pyc' import 'multiprocessing.synchronize' # <_frozen_importlib_external.SourceFileLoader object at 0xffc91af0> # trying /usr/lib/python3.6/multiprocessing/popen_fork.cpython-36m-i386-cygwin.dll # trying /usr/lib/python3.6/multiprocessing/popen_fork.abi3.dll # trying /usr/lib/python3.6/multiprocessing/popen_fork.dll # trying /usr/lib/python3.6/multiprocessing/popen_fork.py # /usr/lib/python3.6/multiprocessing/__pycache__/popen_fork.cpython-36.pyc matches /usr/lib/python3.6/multiprocessing/popen_fork.py # code object from '/usr/lib/python3.6/multiprocessing/__pycache__/popen_fork.cpython-36.pyc' import 'multiprocessing.popen_fork' # <_frozen_importlib_external.SourceFileLoader object at 0xffc57190> then it exits with no further output. Best regards, Niels Kristian Jensen (from Denmark) -- https://mail.python.org/mailman/listinfo/python-list
Import issue in python packages
Hi All, I am facing issue with python package import. In my project, I have many directories with different python classes defined within them. I am trying to import those classes in another python program, but not able to import them. Here are my directories and file structures. src/platform/operatingsys.py : Defined OperatingSystem Class src/platform/ipc.py : Defined IPC class src/platform/MyThread.py: Defined MyThread class src/platform/__init__.py - zero sized file src/utils/abc.py src/utils/def.py src/utils/__init__.py src/api/xyz.py src/api/__init__.py src/unittest/TestSuite.py - Defined UnitTest Class src/unittest/__init__.py src/__init__.py Now, I am trying to use the above classes in another python program( TestPackage.py) as below: *from src.platform.operatingsys import OperatingSystem* . -- Execution of TestPackage.py throws an error as below ImportError: No module named 'src' Currently I have a working code which prefixes sys.path with every directory defined in the package list before import any classes. sys.path.append("src/unittest/") import OperatingSystem But I do not have the hard-coded path and append to sys.path variable. So my question is: 1) Is there any better way of having the sys.path variable appended by directory listing? 2) What changes i need to do so that my import statement looks like below: *from src.platform.operatingsys import OperatingSystem* Please suggest... Thanks Venkat -- https://mail.python.org/mailman/listinfo/python-list
Re: Python MySQL Guide
Sure, no problem. I also added a table of contents at the start of the article you can also refer that On Fri, 10 Aug 2018, 6:43 pm Bob Gailer, wrote: > Thank you for this offer. My reaction is I don't like having to scroll > through one very long page to find what I'm looking for. Might you consider > breaking it up into a number of smaller pages and giving an index as the > main page? > > On Aug 9, 2018 5:18 PM, wrote: > >> Refer this complete guide on working with Python and MySQL >> >> https://pynative.com/python-mysql-tutorial/ >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- https://mail.python.org/mailman/listinfo/python-list
Re: Import issue in python packages
Venkatesh Adiga wrote: > Hi All, > > I am facing issue with python package import. > In my project, I have many directories with different python classes > defined within them. I am trying to import those classes in another python > program, but not able to import them. > Here are my directories and file structures. > src/platform/operatingsys.py : Defined OperatingSystem Class > src/platform/ipc.py : Defined IPC class > src/platform/MyThread.py: Defined MyThread class > src/platform/__init__.py - zero sized file > > src/utils/abc.py > src/utils/def.py > src/utils/__init__.py > > src/api/xyz.py > src/api/__init__.py > > src/unittest/TestSuite.py - Defined UnitTest Class > src/unittest/__init__.py > src/__init__.py > > > Now, I am trying to use the above classes in another python program( > TestPackage.py) as below: > > > *from src.platform.operatingsys import OperatingSystem* > . > -- > Execution of TestPackage.py throws an error as below > > ImportError: No module named 'src' > > Currently I have a working code which prefixes sys.path with every > directory defined in the package list before import any classes. > > sys.path.append("src/unittest/") > import OperatingSystem > > But I do not have the hard-coded path and append to sys.path variable. > So my question is: > 1) Is there any better way of having the sys.path variable appended by > directory listing? > 2) What changes i need to do so that my import statement looks like > below: >*from src.platform.operatingsys import OperatingSystem* > > Please suggest... Ensure that src is in your PYTHONPATH, preferrably as an absolute path. Then import the packages and modules without the src prefix, e. g. sys.path.append("/path/to/src") import platform.operatingsys If you insist on src as part of the import the directory's parent needs to be in the path: sys.path.append("/path/to") import src.platform.operatingsys Note that it's better to avoid manipulating sys.path from within your scripts. If at all possible install your packages or at least add .pth files or a PYTHONPATH environment variable. -- https://mail.python.org/mailman/listinfo/python-list
plot not showing up
What is wrong with the following code. Python does not show the plot. from sklearn.datasets import load_digits from sklearn.cluster import KMeans import matplotlib.pyplot as plt digits = load_digits() digits.data.shape kmeans = KMeans(n_clusters=10,random_state=0) clusters = kmeans.fit_predict(digits.data) kmeans.cluster_centers_.shape fig, ax = plt.subplots(2,5,figsize=(8,3)) centers = kmeans.cluster_centers_.reshape(10,8,8) for axi, center in zip(ax.flat, centers): axi.set(xticks=[], yticks=[]) axi.imshow(center, interpolation='nearest', cmap=plt.cm.binary) -- https://mail.python.org/mailman/listinfo/python-list
Re: plot not showing up
try adding plt.show() Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius On Fri, 10 Aug 2018, 21:50 Sharan Basappa, wrote: > What is wrong with the following code. Python does not show the plot. > > from sklearn.datasets import load_digits > from sklearn.cluster import KMeans > import matplotlib.pyplot as plt > > digits = load_digits() > digits.data.shape > > kmeans = KMeans(n_clusters=10,random_state=0) > clusters = kmeans.fit_predict(digits.data) > kmeans.cluster_centers_.shape > > fig, ax = plt.subplots(2,5,figsize=(8,3)) > centers = kmeans.cluster_centers_.reshape(10,8,8) > for axi, center in zip(ax.flat, centers): > axi.set(xticks=[], yticks=[]) > axi.imshow(center, interpolation='nearest', cmap=plt.cm.binary) > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Embedded Python and multiprocessing on Windows?
On Friday, August 10, 2018 at 2:28:45 AM UTC-4, Léo El Amri wrote: > That may be something simple: Did you actually protected the entry-point > of your Python script with if __name__ == '__main__': ? That was my first thought too; the script technically doesn't have top-level code, so I figured I didn't need a main catch. Just to be sure, I added one and it still didn't resolve. The function in the second script that correctly multiprocesses doesn't have a main (or top level code) either. I'm wondering if it's related to how I call the script in code. I'm using boost.python, but I'm not sure I'm doing it entirely correctly (the boost.python documentation is weirdly hazy on the semantics of calling script files, but is drowning in examples of how to execute hard-coded lines, which seems insane to me; who on earth would go to the trouble to embed an interpreter to run hardcoded Python strings?) Anyway, those lines look like this: py::object main_module = py::import("__main__"); py::dict global = py::extract(main_module.attr("__dict__")); py::object result = py::exec_file(scriptName, global, global); py::object runner = global["EntryFunction"]; retval = py::extract(runner(py::ptr(taskPtr))); // we pass a pointer to the entry function -- https://mail.python.org/mailman/listinfo/python-list
Can't figure out how to do something using ctypes (and maybe struct?)
I need to make a list of instances of a Structure, then I need to make an instance of another Structure, one of the fields of which needs to be an arbitrary-length array of pointers to the instances in the list. How do I do that? Just in case it helps, I'll include what I tried that didn't work: -- class NoteEvent(ctypes.Structure): _fields_ = [('type', ctypes.c_int), ('byteSize', ctypes.c_int), ('deltaFrames', ctypes.c_int), ('flags', ctypes.c_int), ('noteLength', ctypes.c_int), ('noteOffset', ctypes.c_int), ('commandCode', ctypes.c_char), ('noteNumber', ctypes.c_char), ('velocity', ctypes.c_char)] def mkVstEvents(events): class Events(ctypes.Structure): _fields_ = [('numEvents', ctypes.c_int), ('reserved', ctypes.c_int), ('eventspointerarray', ctypes.c_void_p * len(events))] return Events(len(events), 0, tuple([ctypes.pointer(event) for event in events])) def mkNoteEvent(deltaFrames, flags, noteNumber, channel, velocity, noteLength, noteOffset, detune, noteOffVelocity): vstEvent = NoteEvent(type=1, bytesize=11, deltaFrames=deltaFrames, flags=1, noteLength=0, noteOffset=0, commandCode=chr(144+channel), noteNumber=chr(noteNumber), velocity=chr(velocity)) return vstEvent def onSendMidiButton(self, event): plugins[0].plugin.process_events(ctypes.pointer(mkVstEvents([mkNoteEvent(deltaFrames=0, flags=1, noteNumber=60, channel=0, velocity=127, noteLength=0, noteOffset=0, detune=0, noteOffVelocity=0)]))) -- Here's the error I got: -- Traceback (most recent call last): File "soundshop.9.1.2.py", line 216, in onSendMidiButton noteOffVelocity=0)]))) File "soundshop.9.1.2.py", line 76, in mkVstEvents return Events(len(events), 0, tuple([ctypes.pointer(event) for event in events])) RuntimeError: (c_void_p_Array_1) : incompatible types, LP_NoteEvent instance instead of c_void_p instance -- I also tried to use struct.pack: -- def mkVstEvents(events): st = struct.pack("=ii"+"L"*len(events), len(events), 0, *(ctypes.pointer(event) for event in events)) return st --- Here's the error I got: -- Traceback (most recent call last): File "soundshop.9.3.py", line 213, in onSendMidiButton noteOffVelocity=0)]))) File "soundshop.9.3.py", line 72, in mkVstEvents st = struct.pack("=ii"+"p"*len(events), len(events), 0, *(ctypes.pointer(event) for event in events)) struct.error: argument for 'p' must be a string -- I also tried replacing "p"*len(events) with "i"*len(events) and also with "L"*len(events), both of which gave me errors. Thanks for your help. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can't figure out how to do something using ctypes (and maybe struct?)
On Fri, 10 Aug 2018 18:40:11 -0400, inhahe wrote: > I need to make a list of instances of a Structure, then I need to make > an instance of another Structure, one of the fields of which needs to be > an arbitrary-length array of pointers to the instances in the list. How > do I do that? > > Just in case it helps, I'll include what I tried that didn't work: How about simplifying your example to the smallest and simplest example of the problem? Your example has: - two functions; - one method that seems to have become unattached from its class; - two classes; - using 12 different fields. Surely not all of that detail is specific to the problem you are happening. If you can simplify the problem, the solution may be more obvious. It might help to read this: http://sscce.org/ By the way, unrelated to your specific problem but possibly relevant elsewhere, you have this function: > def mkVstEvents(events): > class Events(ctypes.Structure): > _fields_ = [ ... ] > return Events( ... ) You might not be aware of this, but that means that every time you call mkVstEvents, you get a singleton instance of a new and distinct class that just happens to have the same name and layout. So if you did this: a = mkVstEvents( ... ) b = mkVstEvents( ... ) then a and b would *not* be instances of the same class: isinstance(a, type(b)) # returns False isinstance(b, type(a)) # returns False type(a) == type(b) # also False Each time you call the function, it creates a brand new class, always called Events, creates a single instance of that class, and returns it. That is especially wasteful of memory, since classes aren't small. py> class Events(ctypes.Structure): ... pass ... py> sys.getsizeof(Events) 508 Unless that's what you intended, you ought to move the class outside of the function. class Events(ctypes.Structure): _fields_ = [ ... ] def mkVstEvents(events): return Events( ... ) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list