Issue with running programs in Python and imports, probably directories messed up
Dear developers, I have stuck upon a problem with all of my attempts to import libraries to Python. PyCharm and Anaconda both fail, as well as terminal. Find the screenshots enclosed. I have tried reinstalling both several times, of no help. All of the libraries I tried to import are already downloaded and were used successfully before something has messed up all Python in my system. Bests, Vlad [image: зображення.png] [image: зображення.png] Traceback (most recent call last): File "C:\ProgramData\Anaconda\Scripts\jupyter-notebook-script.py", line 6, in from notebook.notebookapp import main File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\notebook\notebookapp.py", line 47, in from zmq.eventloop import ioloop File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\__init__.py", line 47, in from zmq import backend File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\__init__.py", line 40, in reraise(*exc_info) File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise raise value File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\__init__.py", line 27, in _ns = select_backend(first) File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\select.py", line 28, in select_backend mod = __import__(name, fromlist=public_api) File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\__init__.py", line 6, in from . import (constants, error, message, context, ImportError: cannot import name 'constants' from 'zmq.backend.cython' (C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\__init__.py) -- https://mail.python.org/mailman/listinfo/python-list
error with installing a package(matplotlib)
Hello, I have been encountering problems with installing packages on python. I am using windows 10, pycharm and pip install order in command prompt to install packages.At first I had an error with installing numpy (something with visual c++ so i downloaded them and it worked).Now i want to download matplotlib and i have this error: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DFREETYPE_BUILD_TYPE=system -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_ft2font_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -Ic:\users\tdoults\appdata\local\programs\python\python38-32\lib\site-packages\numpy\core\include -Ic:\users\tdoults\appdata\local\programs\python\python38-32\include -Ic:\users\tdoults\appdata\local\programs\python\python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcsrc/checkdep_freetype2.c /Fobuild\temp.win32-3.8\Release\src/checkdep_freetype2.obj checkdep_freetype2.c src/checkdep_freetype2.c(1): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2 ERROR: Command errored out with exit status 1: 'c:\users\tdoults\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\tdoults\\AppData\\Local\\Temp\\pip-install-dl4grek0\\matplotlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\tdoults\\AppData\\Local\\Temp\\pip-install-dl4grek0\\matplotlib\\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\tdoults\AppData\Local\Temp\pip-record-8431q_7r\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output. If there is a solution it would be very helpful for me.Thank you nevertheless! Theodor Doultsinos -- https://mail.python.org/mailman/listinfo/python-list
Re: return a ctypes object to C
On 30-10-2019 09:32, Arnaud Loonstra wrote: Hi all, I'm trying to wrap my head around the ctypes API. I have a C structure I wish to create in Python and then return from python to C. So a python method is called from C and needs to return an object which we then process in C again. I have a binding to access and create the C methods and structures so in Python I can call the Zmsg() constructor. I now need to return this. My python test method is simply: def actor_test( *args, **kwargs): print("test") msg = Zmsg() frame = Zframe(b"Hello", 5) msg.prepend(frame) return msg the method is called from C as follows: PyObject *pReturn = PyObject_CallObject(pFunc, NULL); This correctly calls the method. However the returned object is of course a PyObject*. The debugger says it's "" PyObject [class] "" [super class] "" [meta type] "" ob_refcnt 1 Py_ssize_t However how I can I get it back to the original C type (zmsg_t *) Any help really appreciated. What I've found so far is that I can return the address of the ctypes object. msg = Zmsg() frame = Zframe(b"Hello", 5) msg.prepend(frame) return addressof(msg._as_parameter_.contents) In C I can then cast it back to the original type. PyObject *pReturn = PyObject_CallObject(pFunc, NULL); assert(pReturn); long bla = PyLong_AsLong(pReturn); zmsg_t* test = (zmsg_t *)bla; assert(test); char *hello = zmsg_popstr(test); assert(hello); assert(streq(hello, "Hello")); This works, I'm not sure if this is the right way. It also creates a complicated setup with the garbage collector. Anybody better ideas? Rg, Arnaud -- https://mail.python.org/mailman/listinfo/python-list
Re: return a ctypes object to C
On 31/10/2019 14.13, Arnaud Loonstra wrote: > On 30-10-2019 09:32, Arnaud Loonstra wrote: >> Hi all, >> >> I'm trying to wrap my head around the ctypes API. I have a C >> structure I wish to create in Python and then return from python to C. >> >> So a python method is called from C and needs to return an object >> which we then process in C again. >> >> I have a binding to access and create the C methods and structures so >> in Python I can call the Zmsg() constructor. I now need to return this. >> >> My python test method is simply: >> >> def actor_test( *args, **kwargs): >> print("test") >> msg = Zmsg() >> frame = Zframe(b"Hello", 5) >> msg.prepend(frame) >> return msg >> >> the method is called from C as follows: >> >> PyObject *pReturn = PyObject_CallObject(pFunc, NULL); >> >> This correctly calls the method. However the returned object is of >> course a PyObject*. The debugger says it's >> >> "" PyObject >> [class] "" >> [super class] "" >> [meta type] "" >> ob_refcnt 1 Py_ssize_t >> >> However how I can I get it back to the original C type (zmsg_t *) >> >> Any help really appreciated. >> > > What I've found so far is that I can return the address of the ctypes > object. > > msg = Zmsg() > frame = Zframe(b"Hello", 5) > msg.prepend(frame) > return addressof(msg._as_parameter_.contents) > > In C I can then cast it back to the original type. > > PyObject *pReturn = PyObject_CallObject(pFunc, NULL); > assert(pReturn); > long bla = PyLong_AsLong(pReturn); > zmsg_t* test = (zmsg_t *)bla; > assert(test); > char *hello = zmsg_popstr(test); > assert(hello); > assert(streq(hello, "Hello")); > > This works, I'm not sure if this is the right way. It also creates a > complicated setup with the garbage collector. > > Anybody better ideas? You've already got a complicated setup with your ctypes objects... If you're using the Python C API anyway, why would you use ctypes at all? You can create custom Python types in C to wrap your C pointers. Alternatively: if you're using ctypes anyway, why use the Python C API at all? You can create C function pointers from Python functions with ctypes. If you're mixing two different ways of interfacing Python and C, the result will ALWAYS be messy. Better to stick to one. Personally, I prefer cffi or cython depending on the situation, as I find them clearer and easier to use than ctypes. Using the Python C API directly is usually the hardest to understand and the easiest to get wrong. -- Thomas -- https://mail.python.org/mailman/listinfo/python-list
Re: return a ctypes object to C
On 31-10-2019 14:44, Thomas Jollans wrote: On 31/10/2019 14.13, Arnaud Loonstra wrote: On 30-10-2019 09:32, Arnaud Loonstra wrote: Hi all, I'm trying to wrap my head around the ctypes API. I have a C structure I wish to create in Python and then return from python to C. So a python method is called from C and needs to return an object which we then process in C again. I have a binding to access and create the C methods and structures so in Python I can call the Zmsg() constructor. I now need to return this. My python test method is simply: def actor_test( *args, **kwargs): print("test") msg = Zmsg() frame = Zframe(b"Hello", 5) msg.prepend(frame) return msg the method is called from C as follows: PyObject *pReturn = PyObject_CallObject(pFunc, NULL); This correctly calls the method. However the returned object is of course a PyObject*. The debugger says it's "" PyObject [class] "" [super class] "" [meta type] "" ob_refcnt 1 Py_ssize_t However how I can I get it back to the original C type (zmsg_t *) Any help really appreciated. What I've found so far is that I can return the address of the ctypes object. msg = Zmsg() frame = Zframe(b"Hello", 5) msg.prepend(frame) return addressof(msg._as_parameter_.contents) In C I can then cast it back to the original type. PyObject *pReturn = PyObject_CallObject(pFunc, NULL); assert(pReturn); long bla = PyLong_AsLong(pReturn); zmsg_t* test = (zmsg_t *)bla; assert(test); char *hello = zmsg_popstr(test); assert(hello); assert(streq(hello, "Hello")); This works, I'm not sure if this is the right way. It also creates a complicated setup with the garbage collector. Anybody better ideas? You've already got a complicated setup with your ctypes objects... If you're using the Python C API anyway, why would you use ctypes at all? You can create custom Python types in C to wrap your C pointers. Alternatively: if you're using ctypes anyway, why use the Python C API at all? You can create C function pointers from Python functions with ctypes. If you're mixing two different ways of interfacing Python and C, the result will ALWAYS be messy. Better to stick to one. Personally, I prefer cffi or cython depending on the situation, as I find them clearer and easier to use than ctypes. Using the Python C API directly is usually the hardest to understand and the easiest to get wrong. -- Thomas Hi Thomas, I have an engine running which can call handlers. These handlers return a zmsg_t (a message) which the engine then can process. In this engine we have Python embedded and I want to use a Python method as a handler. To embed Python we need to use the Python C API. To construct a zmsg_t type in Python we need to call the corresponding C method and we use ctypes to do that. I'm using a ctypes binding because it already exists, it's here: https://github.com/zeromq/czmq/blob/d6283985ba52fd8c3f8fbdc7cd5c08372ff69ca1/bindings/python/czmq/_czmq_ctypes.py#L4392 I know I can use cffi for example but that's IMHO just a ctypes alternative. Are you saying it's better to create some approach to create a zmsg_t using the Python C API? Please enlighten me if this should be done differently. Rg, Arnaud -- https://mail.python.org/mailman/listinfo/python-list
Main threads waits indefinitely on futures if single future calls condition.wait()
Hello, Recently I have been trying to use a reantrant read write lock in my project but discovered several problems when writing test cases. All the relevant material can be found on the following locations https://stackoverflow.com/questions/58410610/calling-condition-wait-inside-thread-causes-retrieval-of-any-future-to-block-o https://bugs.launchpad.net/futurist/+bug/1848457 https://github.com/Dantali0n/bug1848457 But let me describe it here as well. I am using the futurist library maintained by the OpenStack foundation. This library provides concurrency constructs similar to those of Python itself. Among the functionality is a wait_for_any method which waits on a list of futures and continuous once one of them is done(). However, when I submit two tasks to a threadpool which both attempt to get a reantrant read write lock this wait_for_any method behaves unexpectedly. Since both tasks attempt to get the lock concurrently one will succeed and the other will not. The behavior of this lock is to call condition.wait() if it does not succeed. The unexpected behavior of the wait_for_any method is that in this scenario it will block indefinitely when called even though one of the futures is done() and finished successfully. In https://github.com/Dantali0n/bug1848457 I have created a spin_for_any using the same lock but with 'native' Python concurrency and here calling future.done() does not block. I was hoping someone had any clue as to what could cause this and how it can be resolved. As mentioned before the question is also over on stackoverflow, I have been struggling with this for a month now. I hope someone has time to provide some help on this matter. Kind regards, Corne Lukken (Dantali0n) -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [WARNING] Some users who downloaded the Python 3.5.8 .xz tarball got the wrong version
On 31/10/2019 00:17, Larry Hastings wrote: > > > Due to awkward CDN caching, some users who downloaded the source code > tarballs of Python 3.5.8 got a preliminary version instead of the > final version. As best as we can tell, this only affects the .xz > release; there are no known instances of users downloading an > incorrect version of the .tgz file. > > If you downloaded "Python-3.5.8.tar.xz" during the first twelve hours > of its release, you might be affected. It's easy to determine this > for yourself. The file size (15,382,140 bytes) and MD5 checksum > (4464517ed6044bca4fc78ea9ed086c36) published on the release page have > always matched the correct version. Also, the GPG signature file will > only report a "Good signature" for the correct .xz file (using "gpg > --verify"). > > What's the difference between the two? The only difference is that > the final version also merges a fix for Python issue tracker #38243: > > https://bugs.python.org/issue38243 > > The fix adds a call to "html.escape" at a judicious spot, line 896 in > Lib/xmlrpc/server.py. The only other changes are one new test, to > ensure this new code is working, and an entry in the NEWS file. You > can see the complete list of changes here: > > https://github.com/python/cpython/pull/16516/files > > What should you do? It's up to you. > > * If you and your users aren't using the XMLRPC library built in to > Python, you don't need to worry about which version of 3.5.8 you > downloaded. > * If you downloaded the .tgz tarball or the Git repo, you already > have the correct version. > * If you downloaded the xz file and want to make sure you have the > fix, check the MD5 sum, and if it's wrong download a fresh copy > (and make sure that one matches the known good MD5 sum!). > > To smooth over this whole sordid mess, I plan to make a 3.5.9 release > in the next day or so. It'll be identical to the 3.5.8 release; its > only purpose is to ensure that all users have the same updated source > code, including the fix for #38243. > > > Sorry for the mess, everybody, > a) "Congratulations" on the 3.5.8 release b) excellent solution - to up the release number! c) Thanks!! > > //arry/ > > > ___ > Python-Dev mailing list -- python-...@python.org > To unsubscribe send an email to python-dev-le...@python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-...@python.org/message/OYNQS2BZYABXACBRHBHV4RCEPQU5R6EP/ > Code of Conduct: http://python.org/psf/codeofconduct/ signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Artifact repository?
Hi folks. Can anyone please recommend an opensource "Artifact Repository" suitable for use with CPython, including dozens of wheels, tar.gz's and .py's? By an Artifact Repository, I mean something that can version largish binaries that are mostly produced by a build process. It doesn't necessarily have to be written in Python, but it does need to cooperate with Python well. I'm thinking of something like Artifactory or Archiva or similar - but I have zero experience with these tools, so a recommendation would be really helpful. Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: Artifact repository?
Dan Stromberg : > Can anyone please recommend an opensource "Artifact Repository" suitable > for use with CPython, including dozens of wheels, tar.gz's and .py's? > > By an Artifact Repository, I mean something that can version largish > binaries that are mostly produced by a build process. > > It doesn't necessarily have to be written in Python, but it does need to > cooperate with Python well. > > I'm thinking of something like Artifactory or Archiva or similar - but I > have zero experience with these tools, so a recommendation would be really > helpful. This question doesn't seem to have much to do with Python. Anyway, at work, we use an in-house component system (written using Python) that uses Artifactory as an artifact store. The system works well. Artifactory's role in the system is to just be a "dumb disk" with a REST API. It supports a nice feature that you can allow developers to read and write *but not delete* from it. Marko -- https://mail.python.org/mailman/listinfo/python-list
Calculations and Variables
The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) total = bill + (bill / tip) eachPay = total / split print("Each person will have to pay %.2f" % eachPay) I am aiming for the result of 43.6, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 -- https://mail.python.org/mailman/listinfo/python-list
RE: Calculations and Variables
How are you getting any value at all? You are trying to do math on string values just like in your infinite loop question. This should raise TypeError: unsupported operand type(s) for /: 'str' and 'str' Also, tips are usually given as percentages. Here with a tip value of 9 you're saying that the tip is 1/9 th of the bill, which is where the number difference is coming from. If someone entered 50 this is saying the tip is 1/50 th of the bill, etc. -Original Message- From: Python-list On Behalf Of ferzan saglam Sent: Thursday, October 31, 2019 2:46 PM To: python-list@python.org Subject: Calculations and Variables The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) total = bill + (bill / tip) eachPay = total / split print("Each person will have to pay %.2f" % eachPay) I am aiming for the result of 43.6, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 10/31/19 11:46 AM, ferzan...@gmail.com wrote: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) total = bill + (bill / tip) Don't you mean total = bill + (bill * tip) ? eachPay = total / split print("Each person will have to pay %.2f" % eachPay) I am aiming for the result of 43.6, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculations and Variables
On 2019-10-31 18:46, ferzan saglam wrote: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? total = bill + (bill / tip) That adds a 1/9 of the bill. It should add 9% of the bill. eachPay = total / split print("Each person will have to pay %.2f" % eachPay) I am aiming for the result of 43.6, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 -- https://mail.python.org/mailman/listinfo/python-list
Restaurant Bill
The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. print('Enter the total cost of the meal') Total_cost= input() print('Enter how much the tip is') Tip= input() print('Enter how many people there are') People= input() Total_cost = (Tip + Total_cost) / People print('Each person will have to pay') print(Total_cost) (Total_cost * 9) / 100 I am aiming for the result of 43.6, but somehow get the result of 41.8. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 -- https://mail.python.org/mailman/listinfo/python-list
Restaurant Bill
The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 41.8. print('Enter the total cost of the meal') Total_cost= input() print('Enter how much the tip is') Tip= input() print('Enter how many people there are') People= input() Total_cost = (Tip + Total_cost) / People print('Each person will have to pay') print(Total_cost) Total_cost = (Total_cost * 9) / 100 I am aiming for the result of 41.8, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) (Equation: Total * Percentage Amount / 100) I seem to be implementing the correct equation, but instead of 43.6, I am getting the result of 41.8?. -- https://mail.python.org/mailman/listinfo/python-list
Re: Restaurant Bill
On Fri, Nov 1, 2019 at 7:51 AM ferzan saglam wrote: > > The code below which I have written should print the result of 43.6 with the > given values I have included at the end of this question, but for some odd > reason I get the result of 44.44. > You're posting multiple threads with the same question and different code. Are you reading the responses people give you? Are you learning from them? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Restaurant Bill
The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 41.8. print('Enter the total cost of the meal') Total_cost= input() print('Enter how much the tip is') Tip= input() print('Enter how many people there are') People= input() Total_cost = (Tip + Total_cost) / People print('Each person will have to pay') print(Total_cost) Total_cost = (Total_cost * 9) / 100 I am aiming for the result of 43.6, but somehow get the result of 41.8. (meal cost: 200) (Tip: 9) (people: 5) (Total * Percentage Amount / 100) I seem to be implementing the correct equation, but instead of obtaining the result of 43.6, I get the result of 41.8. -- https://mail.python.org/mailman/listinfo/python-list
Re: Jupyter Notebook -> PDF with A4 pages?
Den 2019-10-16 skrev Piet van Oostrum : > Martin Schöön writes: > >> Den 2019-10-15 skrev Piet van Oostrum : >>> >> pip is version 8.1.1 which is what Ubuntu 16.04 comes >> with. I have learnt -- the hard way -- that pip should be >> used with the --user option. Does this mean I am stuck with >> pip version 8.1.1? I mean, pip install --user pip seams like >> cheating... > > Why should that not work? > I have been too busy to look into this but today I did and found that pip install --user pip broke pip. I have not been able to repair pip but then I only had some ten minutes to spend on it. /Martin -- https://mail.python.org/mailman/listinfo/python-list
Re: Artifact repository?
In comp.lang.python, Paul Rubin wrote: > Dan Stromberg writes: >> By an Artifact Repository, I mean something that can version largish >> binaries that are mostly produced by a build process. > I'm not familiar with the term "artifact repository" and hadn't heard of > the ones you mentioned, but have you looked at git-annex ? Git-annex solves a different problem. Use git-annex for the problem of "revision control with git for binary files not suitable for normal git storage". Use Artifactory for the problem of "store the binary product of source code at a particular revision point". They are kinda related, but: git doesn't magically know that when you update foo.c that lib/libfoo.a linked into bin/projectfoo are now obsolete. Artifactory, doesn't either, but it doesn't slide files forward to new revisions the way git would unless you specifically replace or delete them. After you `make` your code, you can `make archive` (or whatever) to copy the compiled results to your artifact repository and your deploy code elsewhere can look to the artifact repository to get "latest" or a specific revision. git-annex is good for things like images used in a project that you do want to automatically persist into the next revision. Say if you have screenshots in your documentation and want the next `make pdfs` to have access to them. Or if you have a blog in source code control. Elijah -- the cheapest artifact repository is a webserver with zips / tars -- https://mail.python.org/mailman/listinfo/python-list
Re: return a ctypes object to C
On 10/30/19, Arnaud Loonstra wrote: > > I have a binding to access and create the C methods and structures so in > Python I can call the Zmsg() constructor. I now need to return this. > > My python test method is simply: > > def actor_test( *args, **kwargs): > print("test") > msg = Zmsg() > frame = Zframe(b"Hello", 5) > msg.prepend(frame) > return msg > > the method is called from C as follows: > > PyObject *pReturn = PyObject_CallObject(pFunc, NULL); > > This correctly calls the method. However the returned object is of > course a PyObject*. The debugger says it's > > "" PyObject > [class] "" > [super class] "" > [meta type] "" > ob_refcnt 1 Py_ssize_t > > However how I can I get it back to the original C type (zmsg_t *) I don't know what this Zmsg type is. It doesn't appear to be a ctypes type such as a Structure. Either way, I'd wager that it supports the buffer protocol. https://docs.python.org/3/c-api/buffer.html Call PyObject_GetBuffer to get a simple view, and try casting the `buf` pointer to a zmsg_t pointer. -- https://mail.python.org/mailman/listinfo/python-list
What's the difference between running a script under command box and interpreter?
The script test.py is something like this: ---test.py from pyeds import fsm ... ... class Rule_Parse: def __init__(self): ... self.current_char = '' ... ... def main(input_str): for c in input_str: ... rule.current_char = c ... if __name__ == '__main__': input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' rule = Rule_Parse() main(input_str) ... --- The test.py can run correctly under command box: D:\Works\Python\pyeds-master\src>py test.py but fails when running under interpreter: D:\Works\Python\pyeds-master\src>py Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from test import * >>> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" >>> rule = Rule_Parse() >>> main(input_str) Traceback (most recent call last): File "", line 1, in File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main rule.current_char = c NameError: name 'rule' is not defined >>> I did check the globals using dir() and the 'rule' is there, no doubt. I also tried "py -m pdb test.py" and step through it, no problem too. Why? --Jach -- https://mail.python.org/mailman/listinfo/python-list
Trouble trying to get started with pygame
It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? Any help would be appreciated, as I'm losing patience with it at the moment. -- https://mail.python.org/mailman/listinfo/python-list
Re: What's the difference between running a script under command box and interpreter?
On 31Oct2019 20:44, Jach Fong wrote: The script test.py is something like this: ---test.py from pyeds import fsm ... ... class Rule_Parse: def __init__(self): ... self.current_char = '' ... ... def main(input_str): for c in input_str: ... rule.current_char = c ... if __name__ == '__main__': input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' rule = Rule_Parse() main(input_str) ... --- The test.py can run correctly under command box: D:\Works\Python\pyeds-master\src>py test.py but fails when running under interpreter: D:\Works\Python\pyeds-master\src>py Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. from test import * input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" rule = Rule_Parse() main(input_str) Traceback (most recent call last): File "", line 1, in File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main rule.current_char = c NameError: name 'rule' is not defined I did check the globals using dir() and the 'rule' is there, no doubt. It matters how you checked this. This isn't apparent. I also tried "py -m pdb test.py" and step through it, no problem too. This: py test.py and this: py -m pdb test both run test.py with __name__ set to "__main__" to indicate that test.py is the main programme. When you "import test", the module's __name__ is from the import ("test") i.e. not the main programme. The bottom of your module has an if statement whose body only runs when this is the main programme. The core issue is that the global "rule" is _only_ defined inside that if statement. You might set it unconditionally to None at the start of the file, but that would only change the failure mode. You might set it unconditionally to Rule_Parse() at the top of the file but that pointlessly instantiates an instance of Rule_Parse which might never be needed (maybe that is cheap, but many other classes are not). The basic intent of an import is to define various classes and other names, but _not_, generally, to create class instances and do significant work. This is really an example illustrating one reason why global variables are considered things to avoid almost all of the time. Had main() required "rule" as a parameter then it would not have been possible to call it without at least providing a rule. The same applies with most other functions: if they all require their external state via parameters then you can't miss things out. (You can, of course, always pass incorrect values, but that is usually easier to debug.) Avoid globals; they are usually a source of bugs. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: What's the difference between running a script under command box and interpreter?
Cameron Simpson於 2019年11月1日星期五 UTC+8下午12時13分45秒寫道: > On 31Oct2019 20:44, Jach Fong wrote: > >The script test.py is something like this: > >---test.py > >from pyeds import fsm > >... > >... > >class Rule_Parse: > >def __init__(self): > >... > >self.current_char = '' > >... > >... > >def main(input_str): > >for c in input_str: > >... > >rule.current_char = c > >... > > > >if __name__ == '__main__': > >input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' > >rule = Rule_Parse() > >main(input_str) > >... > > > >--- > >The test.py can run correctly under command box: > >D:\Works\Python\pyeds-master\src>py test.py > > > >but fails when running under interpreter: > >D:\Works\Python\pyeds-master\src>py > >Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit > >(Intel)] on win32 > >Type "help", "copyright", "credits" or "license" for more information. > from test import * > input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" > rule = Rule_Parse() > main(input_str) > >Traceback (most recent call last): > > File "", line 1, in > > File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main > >rule.current_char = c > >NameError: name 'rule' is not defined > > > > >I did check the globals using dir() and the 'rule' is there, no doubt. > > It matters how you checked this. This isn't apparent. > > >I also tried "py -m pdb test.py" and step through it, no problem too. > > This: > py test.py > and this: > py -m pdb test > > both run test.py with __name__ set to "__main__" to indicate that > test.py is the main programme. > > When you "import test", the module's __name__ is from the import > ("test") i.e. not the main programme. > > The bottom of your module has an if statement whose body only runs when > this is the main programme. > > The core issue is that the global "rule" is _only_ defined inside that > if statement. > > You might set it unconditionally to None at the start of the file, but > that would only change the failure mode. > > You might set it unconditionally to Rule_Parse() at the top of the file > but that pointlessly instantiates an instance of Rule_Parse which might > never be needed (maybe that is cheap, but many other classes are not). > The basic intent of an import is to define various classes and other > names, but _not_, generally, to create class instances and do > significant work. > > This is really an example illustrating one reason why global variables > are considered things to avoid almost all of the time. Had main() > required "rule" as a parameter then it would not have been possible to > call it without at least providing a rule. The same applies with most > other functions: if they all require their external state via parameters > then you can't miss things out. (You can, of course, always pass > incorrect values, but that is usually easier to debug.) > > Avoid globals; they are usually a source of bugs. > > Cheers, > Cameron Simpson Yes, the 'if' body is not executed when I import test.py under interpreter, that's why I manually execute them there. What puzzles me is that the globals() has a 'rule' object in both cases. Why this one doesn't work? --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble trying to get started with pygame
On 2019-11-01 03:47, originallmo...@gmail.com wrote: It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? Actually, you do have the means: Python! But there's a simpler way. I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? Those commands are for the Windows command prompt. Any help would be appreciated, as I'm losing patience with it at the moment. Go to Christoph Gohlke's site at: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame Download one of these "wheel" files: pygame‑1.9.6‑cp38‑cp38‑win_amd64.whl for 64-bit or: pygame‑1.9.6‑cp38‑cp38‑win32.whl for 32-bit At the Windows command prompt type: py -3.8 -m pip install "path/to/wheel" -- https://mail.python.org/mailman/listinfo/python-list
Friday finking: TDD and EAFP
Is the practice of TDD fundamentally, if not philosophically, somewhat contrary to Python's EAFP approach? TDD = Test-Driven Development EAFP = it's easier to ask forgiveness than permission * WebRefs as footnote The practice of TDD* is that one writes test routines to prove a unit of code, eg method or function; BEFORE actually writing said function. The rationale is that TDD encourages proper identification and consideration of the routine's specification, and attempts to ensure that exceptions and "edge-cases" are not quietly forgotten. (in a broad-brush, nut-shell) However, I quite possibly like yourself, come from a time-before - before TDD, and before Python. So, have had to not only learn these things, but sometimes, un-learn points and habits (if not vices). Accordingly, I came (quite unknowing of the term, or that there might be an alternative) from the world of LBYL* (look before you leap). In other words, before you do anything with some data, check that it is what you think it is. Whereas in Python we "try" by assuming everything is compos-mentis* and handle the "except" when things are not how we'd like. That adaptation was not too difficult. After all, aren't programmers an optimistic bunch - I mean, I *never* introduce bugs into *my* code! Do you? Which brings us to TDD. Here we assume the likelihood of bugs, as-if (cue: manic giggling); and code a bunch of tests first - in an attempt to prove that the code is up-to-spec. In encouraging my mind to think about testing the code, I find myself searching for edge-cases, and attempting to anticipate the unusual. Accordingly to the gospel of TDD: so far, so good. The 'problem' is, that it puts my mind onto LBYL-rails before the Python-coding train (of thought) has even left the station. It then seems natural to start putting a bunch of if-then-else's up-front and before the 'main line' of code. Does TDD bend your mind in this (apparently) non-Pythonic fashion? Have you developed an answer? (other than: "@dn is 'nuts'*", which is not worthy of debate) WebRefs: https://duckduckgo.com/?q=TDD&ia=web https://devblogs.microsoft.com/python/idiomatic-python-eafp-versus-lbyl/ https://docs.python.org/3/glossary.html#term-eafp but: https://mail.python.org/pipermail/python-dev/2014-March/133118.html https://docs.python.org/3/glossary.html#term-lbyl Latin/legal term "compos mentis" https://www.thefreedictionary.com/compos+mentis English slang term "nuts": https://www.thefreedictionary.com/nuts -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list