Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Thomas Nyberg via Python-list
vacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 20.03.24 um 09:22 schrieb Thomas Nyberg via Python-list: Hello, I have a simple (and not working) example of what I'm trying to do. This is a simplified version of what I'm trying to achieve (obviously the

Using a background thread with asyncio/futures with flask

2024-03-20 Thread Thomas Nyberg via Python-list
Hello, I have a simple (and not working) example of what I'm trying to do. This is a simplified version of what I'm trying to achieve (obviously the background workers and finalizer functions will do more later): `app.py` ``` import asyncio import threading import time from queue import

[issue34319] Clarify pathlib.Path("filepath").read_text()

2018-08-03 Thread Thomas Nyberg
Thomas Nyberg added the comment: For what it's worth as the original opener of the bug report, I think Terry's recommendation clarifies things quite well. -- ___ Python tracker <https://bugs.python.org/issue34

[issue34319] Clarify pathlib.Path("filepath").read_text()

2018-08-02 Thread Thomas Nyberg
New submission from Thomas Nyberg : This came out of the following posts: https://mail.python.org/pipermail/python-ideas/2018-August/052549.html https://mail.python.org/pipermail/python-ideas/2018-August/052553.html Basically my request would be to change the documentation here: https

[issue32980] Remove functions that do nothing in _Py_InitializeCore()

2018-03-03 Thread Thomas Nyberg
Thomas Nyberg <tomnyb...@gmail.com> added the comment: ince I originated this issue and I think I understand the concerns, I figured I could speed up the back and forth in this thread by opening this new PR which removes the `_PyFrame_Init()` function. I couldn't find any `_PyFram

[issue32980] Remove functions that do nothing in _Py_InitializeCore()

2018-03-03 Thread Thomas Nyberg
Change by Thomas Nyberg <tomnyb...@gmail.com>: -- pull_requests: +5732 ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32980> ___

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Thomas Nyberg
On 03/01/2018 04:58 PM, Ned Batchelder wrote: > This sounds like it could make a good contribution to CPython :) > > --Ned. Thanks for the recommendation. Issue/PR created: https://bugs.python.org/issue32980 https://github.com/python/cpython/pull/5953 Cheers, Thomas --

[issue32980] Remove functions that do nothing in _Py_InitializeCore()

2018-03-01 Thread Thomas Nyberg
Change by Thomas Nyberg <tomnyb...@gmail.com>: -- keywords: +patch pull_requests: +5719 stage: -> patch review ___ Python tracker <rep...@bugs.python.org> <https://bugs.pyt

[issue32980] Remove functions that do nothing in _Py_InitializeCore()

2018-03-01 Thread Thomas Nyberg
New submission from Thomas Nyberg <tomnyb...@gmail.com>: The `_PyFrame_Init()` and `PyByteArray_Init()` functions are called in these two locations in the `_Py_InitializeCore()` function: https://github.com/python/cpython/blob/master/Python/pylifecycle.c#L693-L694

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Thomas Nyberg
On 03/01/2018 12:46 PM, bartc wrote: > If they're only called once, then it probably doesn't matter too much in > terms of harming performance. Oh yeah there's no way this has any affect on performance. A smart compiler might even be able optimize the call away entirely. Even if it couldn't, it's

Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Thomas Nyberg
Hello, I was playing around with cpython and noticed the following. The `_PyFrame_Init()` and `PyByteArray_Init()` functions are called in these two locations: https://github.com/python/cpython/blob/master/Python/pylifecycle.c#L693-L694

Re: Why does __ne__ exist?

2018-01-08 Thread Thomas Nyberg
On 01/08/2018 03:25 PM, Oren Ben-Kiki wrote: > I am hard pressed to think of a case where __ne__ is actually useful. Assuming you're talking about a case specifically for IEEE 754, I'm starting to agree. In general, however, it certainly is useful for some numpy objects (as mentioned elsewhere in

Re: Why does __ne__ exist?

2018-01-08 Thread Thomas Nyberg
On 01/08/2018 12:36 PM, Thomas Jollans wrote: > > Interesting sentence from that PEP: > > "3. The == and != operators are not assumed to be each other's > complement (e.g. IEEE 754 floating point numbers do not satisfy this)." > > Does anybody here know how IEE 754 floating point numbers need

Re: Spectre/Meltdown bug affecting Python ?

2018-01-06 Thread Thomas Nyberg
On 01/06/2018 10:23 PM, Etienne Robillard wrote: > It's unclear to me whether AMD CPUs are affected by theses design flaws. As far as I understand, AMD (and possibly ARM) is unaffected by Meltdown (except for possibly some very new processors). It seems like basically all modern out of order

Re: SystemError: error return without exception set

2017-12-07 Thread Thomas Nyberg
On 12/07/2017 05:15 PM, Natalie Leung wrote: > Hi Thomas, > > You are correct in that the software and its packages are close-sourced. I > have emailed the provider but their technical support staff has stated that > they have exhausted of all ideas. > > An interesting thing to note is that

Re: SystemError: error return without exception set

2017-12-07 Thread Thomas Nyberg
On 12/07/2017 04:36 PM, Natalie Leung wrote: > The code stops at "py_send(openModel)" with an error message that reads: > Traceback (most recent call last): File "[my file path]", line 11, in > py_send(openModel) > SystemError: error return without exception set > > I tried running the code on

Re: integer copy

2017-10-20 Thread Thomas Nyberg
On 10/20/2017 10:30 AM, ast wrote: > I am aware that it is useless to copy an integer > (or any immutable type). > > ... > > any comments ? > > Why is this a problem for you? Cheers, Thomas -- https://mail.python.org/mailman/listinfo/python-list

Re: multiprocessing shows no benefit

2017-10-20 Thread Thomas Nyberg
Correct me if I'm wrong, but at a high level you appear to basically just have a mapping of strings to values and you are then shifting all of those values by a fixed constant (in this case, `z = 5`). Why are you using a dict at all? It would be better to use something like a numpy array or a

Re: multiprocessing shows no benefit

2017-10-18 Thread Thomas Nyberg
On 10/18/2017 05:10 PM, Jason wrote: > I've read the docs several times, but I still have questions. > I've even used multiprocessing before, but not map() from it. > > I am not sure if map() will let me use a common object (via a manager) and if > so, how to set that up. > As I said earlier,

Re: multiprocessing shows no benefit

2017-10-17 Thread Thomas Nyberg
Could you post a full code snippet? If the lists of 16k numpy arrays are fixed (say you read them from a file), you could just generate random values that could be fed into the code as your list would. It's hard to say how things could be sped up without a bit more specificity. Cheers, Thomas --

Re: How do native namespaces work?

2017-10-05 Thread Thomas Nyberg
On 10/05/2017 04:07 PM, Peter Otten wrote: > Are you sure you are using the correct interpreter? When I activate a > virtual environment it changes the prompt like so: Sorry I just cut out the extra cruft from my prompt for clarity. (In hindsight, I should probably have left the `(venv)` prompt

How do native namespaces work?

2017-10-05 Thread Thomas Nyberg
Hello, I'm trying to understand native namespaces. I'm currently using python 3.5 as packaged in debian 9. I've been following the instructions here: https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages Those instructions link to the following

Re: Multithreaded compression/decompression library with python bindings?

2017-10-05 Thread Thomas Nyberg
Btw if anyone knows a better way to handle this sort of thing, I'm all ears. Given my current implementation I could use any compression that works with stdin/stdout as long as I could sort out the waiting on the subprocess. In fact, bzip2 is probably more than I need...I've half used it out of

Re: Multithreaded compression/decompression library with python bindings?

2017-10-05 Thread Thomas Nyberg
On 10/04/2017 05:08 PM, Steve D'Aprano wrote: > pbip2? Never heard of it, and googling comes up with nothing relevant. > > Got a link? Sorry it was a typo as Paul Moore said. pbzip2 is a parellelized implementation of bzip2: http://compression.ca/pbzip2/ > Why obviously? Sorry again.

Multithreaded compression/decompression library with python bindings?

2017-10-04 Thread Thomas Nyberg
Hello, I was wondering if anyone here knew of any python libraries with interfaces similar to the bzip2 module which is also multithreaded in (de)compression? Something along the lines of (say) the pbip2 program but with bindings for python? Obviously the multi-threaded part will need to be

Re: @lru_cache on functions with no arguments

2017-08-01 Thread Thomas Nyberg
On 08/01/2017 02:50 PM, t...@tomforb.es wrote: > 2. Django has a long-standing no-dependencies rule, which may change in the > near future but for now it is stdlib only. We can't add a dependency on > `lazy-property`. Apologies for continuing going off-topic, but the actual code in that package

Re: @lru_cache on functions with no arguments

2017-08-01 Thread Thomas Nyberg
On 08/01/2017 01:06 PM, Matt Wheeler wrote: > A function which is moderately expensive to run, that will always return > the same result if run again in the same process, and which will not be > needed in every session. > What about just using a lazy getter property? E.g.:

Re: Users of namedtuple: do you use the _source attribute?

2017-07-19 Thread Thomas Nyberg
On 07/19/2017 05:12 AM, Steve D'Aprano wrote: > On Wed, 19 Jul 2017 08:39 am, Gregory Ewing wrote: > Um... well, people want to do all sorts of wild and wacky things... but why > would you define a named tuple with *private* fields? Especially since that > privateness isn't enforced when you

Re: School Management System in Python

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 03:30 PM, YOUR_NAME_HERE wrote: > Hey that was simple enough! Thanks for the code! I was also considering the > use of JSON. Which one would be better? > If you have hierarchical data best described by dicts/lists (in the python meaning), then json isn't a bad approach. But if you

Re: School Management System in Python

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 03:34 PM, Sam Chats wrote: > Just curious, is it better, performance wise, to read from a text file (css > or tsv) compared to reading from a binary pickle file? > I honestly don't know. You should probably measure it if you're wondering. However, I don't think it's worth thinking

Re: School Management System in Python

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 02:56 PM, Tim Golden wrote: > There's been some discussion recently on the Computing At School forums > here in the UK where at least one teacher explained that they taught > pickle in the way it's being used here essentially because it's really > simple: you just through your object

Re: School Management System in Python

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 03:18 PM, YOUR_NAME_HERE wrote: > On Wed, 5 Jul 2017 13:02:36 + (UTC) YOUR_NAME_HERE wrote: >> I can use either tsv or csv. Which one would be better? > > > Some people complain that tsv has problems, so maybe csv would be the way to > go. > I almost always use csv

Re: School Management System in Python

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 02:14 PM, Sam Chats wrote: > Thanks for your suggestions. I would've not used pickle had I been aware > about other tools while developing this. > I was thinking about migrating to sqlite3. How about that? And yes, I need > more comprehanesive documentation. > Will work on that

Re: School Management System in Python

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 01:31 PM, Sam Chats wrote: > Feel free to comment on my high school project. I really enjoyed building it > and it is the biggest project I've developed so far > (in terms of lines of code). All you need to do is to run the S-Koo-L.py > script. > > I've built more eye-catchy

Re: Python threading and sharing variables

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 10:40 AM, Chris Angelico wrote: > What would the lock surround? Sorry yes I agree with you that no lock is needed in this method. I was a bit confused by the code and probably was thinking something like "a += 1" in my head (even though that's not what he was doing...). Thanks for

Re: Python threading and sharing variables

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 10:20 AM, Thomas Nyberg wrote: > [...snip...] Btw I forgot to mention that you'd probably want to use q.get_nowait() instead of q.get() in my code example if you don't want the main thread to block (which what I think you want to avoid from your code example). ht

Re: Python threading and sharing variables

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 10:05 AM, pozz wrote: > > Ok, maybe this atomic behaviour depends on the Python implementation, so > it's better to avoid relying on atomicity and use a lock to access > shared variables from different running thread. > > However in my simple case one thread writes the variable and

Re: Python threading and sharing variables

2017-07-05 Thread Thomas Nyberg
On 07/05/2017 09:56 AM, pozz wrote: > It seems it works, but I'm not sure it is the correct way to share the > variable self.cnt. It is only written in the long thread and only read > in the main thread. > Could a single Python instruction be interrupted (in this case, self.cnt > = i)? Should I

Re: Best way to ensure user calls methods in correct order?

2017-06-24 Thread Thomas Nyberg
On 06/24/2017 11:53 AM, Thomas Jollans wrote: > If the data is modified in-place, maybe it makes sense to to use a class > like the one you have, but then it's a bit bizarre to make your methods > create an artificial side effect (self._a_dirty) - why don't you simply > check for the actual effect

Re: Best way to ensure user calls methods in correct order?

2017-06-22 Thread Thomas Nyberg
[I accidentally sent this only to Peter, but wanted instead to send it to the list for anyone else who happens upon it...now sending to the list...] On 06/22/2017 04:31 PM, Peter Otten wrote: > If the order is linear like it seems to be the following might work: Thanks a lot! This removes the

Re: Best way to ensure user calls methods in correct order?

2017-06-22 Thread Thomas Nyberg
/2017 04:40 PM, Steve D'Aprano wrote: > On Thu, 22 Jun 2017 11:53 pm, Thomas Nyberg wrote: > > Don't do that. It's fragile and an anti-pattern. Your methods have too much > coupling. If c() relies on b() being called first, then either b() or c() > aren't good methods. They

Best way to ensure user calls methods in correct order?

2017-06-22 Thread Thomas Nyberg
Hello, I have a situation in which I want a user to call methods in a certain order and to force the re-calling of methods "down-stream" if upstream methods are called again. An example of this sort of thing would be a pipeline where calling methods again invalidates the results of methods called

Re: Test String Contents

2017-06-13 Thread Thomas Nyberg
On 06/13/2017 03:34 PM, Matt wrote: > What is easiest way to determine if a string ONLY contains a-z upper > or lowercase. I also want to allow the "-" and "_" symbols. No > spaces or anything else. > I'm not sure it's the best way, but the following seems okay: >>> s = 'hello_world' >>>

Re: In which order many functions are executed in a python code

2017-06-09 Thread Thomas Nyberg
On 06/09/2017 11:39 AM, sondes kalboussi wrote: > > Am a bit confused I was thinking that the order of execution of functions in > a code is from the first to the last function but sometimes it is the > opposite, for instance, some parameters or outputs from the second function > are called in

Re: Unhelpful error message

2017-06-06 Thread Thomas Nyberg
On 06/06/2017 02:32 PM, Chris Angelico wrote: > > That's what I thought. If the OP's happy to upgrade to 3.6/3.7, of > course, the problem disappears. > > ChrisA > As far as I can tell this affects all versions of python. Here are some versions I played with: 2.7: >>> float("") Traceback

Re: Unhelpful error message

2017-06-06 Thread Thomas Nyberg
On 06/06/2017 11:38 AM, Jon Ribbens wrote: > On 2017-06-06, Peter Otten <__pete...@web.de> wrote: >> ...but not the empty string: >> > float("") >> Traceback (most recent call last): >> File "", line 1, in >> ValueError: could not convert string to float: >> >> Maybe there were some

Re: Unhelpful error message

2017-06-06 Thread Thomas Nyberg
On 06/06/2017 11:46 AM, Jon Ribbens wrote: > On 2017-06-06, Thomas Nyberg <tomuxi...@gmx.com> wrote: >> My changes feel a bit hacky. I wanted to just drop a straight repr() in, >> but I didn't want to change the code too much since I assume the string >> formatting is

Re: Unhelpful error message

2017-06-06 Thread Thomas Nyberg
On 06/06/2017 11:22 AM, Skip Montanaro wrote: > On Tue, Jun 6, 2017 at 12:27 PM, Chris Angelico wrote: >> Or perhaps showing the repr of the string would be clearer. > > This would definitely be better, I think, and require no special > casing of the empty string. Still, I

Re: How to update python from 3.5.2 to 3.5.3 on Linux

2017-05-03 Thread Thomas Nyberg
On 05/03/2017 01:14 PM, Matt Ruffalo wrote: > This isn't quite true -- Ubuntu 14.04 shipped with Python 3.4.0, but was > updated at some point to 3.4.3 (which will be installed automatically > through normal update mechanisms). > > MMR... > Well I'm less worried about whether it is _always_

Re: How to update python from 3.5.2 to 3.5.3 on Linux

2017-05-03 Thread Thomas Nyberg
On 05/03/2017 11:47 AM, Wolfgang Maier wrote: > On 03.05.2017 17:11, Thomas Nyberg wrote: >> On 05/03/2017 11:04 AM, Daiyue Weng wrote: >>> nope, I was thinking it might be good to update to 3.5.3 for security >>> reasons? >>> >> >> (CCing

Re: How to update python from 3.5.2 to 3.5.3 on Linux

2017-05-03 Thread Thomas Nyberg
On 05/03/2017 11:04 AM, Daiyue Weng wrote: > nope, I was thinking it might be good to update to 3.5.3 for security > reasons? > (CCing back in python-list since I accidentally dropped it.) I wouldn't worry about it. Package managers tend to usually take care of security updates. (Of course

Re: How to update python from 3.5.2 to 3.5.3 on Linux

2017-05-03 Thread Thomas Nyberg
On 05/03/2017 10:34 AM, Daiyue Weng wrote: > Hi, I am using Python 3.5.2 on Linux Mint (X64) at the moment, and > wondering how to update it to 3.5.3. Are there some simple commands to do > that? > > cheers > I wouldn't mess with the system python if I were you. That could clash with Linux

Re: Basics of pythons 

2017-04-21 Thread Thomas Nyberg
On 04/21/2017 08:06 AM, harounelyaako...@gmail.com wrote: > Hey everyone, I'm willing to learn python , ant advices ? > Thanks in advance > Here is a tutorial: https://docs.python.org/3/tutorial/ -- https://mail.python.org/mailman/listinfo/python-list

Re: "Goto" statement in Python

2017-04-13 Thread Thomas Nyberg
On 04/12/2017 04:42 PM, Mikhail V wrote: > For me it looks clear and I'd say easy to comprehend, > Main critic would be obviously that it is not > a good, *scalable application*, but quite often I don't > even have this in mind, and just want to express a > step-by-step direct instructions. I

Re: Python and the need for speed

2017-04-08 Thread Thomas Nyberg
On 04/08/2017 05:20 PM, breamore...@gmail.com wrote: > I've an idea that http://www.mos6581.org/python_need_for_speed is a week late > for April Fool's but just in case I'm sure that some of you may wish to > comment. > > Kindest regards. > > Mark Lawrence. > Regarding your restricted subset

Re: Recompilation of Python3.6.x

2017-03-23 Thread Thomas Nyberg
On 03/23/2017 03:45 AM, Klaus Jantzen wrote: The information must be somewhere because Python must have been compiled frequently and correctly for the various (important) OSs before making it available to the public. And I do not think that it is left up to "your luck" that the required packages

Re: python source code

2017-03-22 Thread Thomas Nyberg
On 03/22/2017 05:57 PM, M. R.P. wrote: does anyone know were I can python source code programs? The source code for cpython (i.e. the most common interpreter) can be found here: https://www.python.org/downloads/source/ https://github.com/python/cpython Unless you mean the

Re: Recompilation of Python3.6.x

2017-03-22 Thread Thomas Nyberg
On 03/22/2017 03:22 PM, Jon Ribbens wrote: A simple table with a list of the library names, the debian package names, and the rpm names would provide the information in a way that would be useful to everyone. I definitely agree, but it would be kind of difficult to maintain. I mean if you

Re: Recompilation of Python3.6.x

2017-03-22 Thread Thomas Nyberg
On 03/22/2017 12:42 PM, Klaus Jantzen wrote: Hello, in order to have the Python-SQLite support available one has to recompile Python. For the recompiliation to succeed a number of 'modules/libs' have to be present. In the internet I found the following list build-essential libz-dev

Is requests[security] required for python 3.5+ ?

2017-02-02 Thread Thomas Nyberg
Hello, I'm trying to understand whether requests[security] or just plain requests should be installed for python 3.5. I.e. do the following packages need to be installed: pyOpenSSL, cryptography, idna. The reason I'm asking is because I'm moving an application to python 3 and I am testing

Re: PEP 393 vs UTF-8 Everywhere

2017-01-20 Thread Thomas Nyberg
On 01/20/2017 03:06 PM, Chris Kaynor wrote: [...snip...] -- Chris Kaynor I was able to delete my response which was a wholly contained subset of this one. :) But I have one extra question. Is string indexing guaranteed to be constant-time for python? I thought so, but I

Re: Problem while building Python 3.6 from source.

2017-01-13 Thread Thomas Nyberg
On 01/13/2017 10:00 AM, Michael S wrote: '*** Error in ./python'" free(): invalid next size (normal): 0x015bdf90 ***'. Are you possibly running out of memory due to the extra concurrent compilations? Cheers, Thomas -- https://mail.python.org/mailman/listinfo/python-list

[issue24875] pyvenv doesn´t install PIP inside a new venv with --system-site-package

2017-01-13 Thread Thomas Nyberg
Thomas Nyberg added the comment: Hi Vinay, You should probably upload a patch with the changes you made (however trivial) if you want that version considered. Makes it easier to comment and can then point to it for others to consider. Cheers, Thomas

[issue24875] pyvenv doesn´t install PIP inside a new venv with --system-site-package

2017-01-12 Thread Thomas Nyberg
Thomas Nyberg added the comment: Hi Vinay, I just checked and yes that code works fine on my end (debian 8 box). Personally, I think either this or Mark's second patch would be fine. Cheers, Thomas -- ___ Python tracker <rep...@bugs.python.

[issue24875] pyvenv doesn´t install PIP inside a new venv with --system-site-package

2017-01-12 Thread Thomas Nyberg
Changes by Thomas Nyberg <tomnyb...@gmail.com>: Removed file: http://bugs.python.org/file46250/venv_site_packages.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue24875] pyvenv doesn´t install PIP inside a new venv with --system-site-package

2017-01-11 Thread Thomas Nyberg
Thomas Nyberg added the comment: Hi Mark Haase, I've gone through both of your patches and they both work for me as they should. I'm not sure why the first one isn't working for you, since it works for me. That one seems like it's solving the problem the "right" way. In any case,

[issue24875] pyvenv doesn´t install PIP inside a new venv with --system-site-package

2017-01-10 Thread Thomas Nyberg
Thomas Nyberg added the comment: Now that I look over this thread again, I realize that my patch ended up basically evolving to being extremely similar to Mark Haase's. The only thing that I don't understand though is that he says that his shebangs are somehow messed up. For me the shebangs

[issue24875] pyvenv doesn´t install PIP inside a new venv with --system-site-package

2017-01-10 Thread Thomas Nyberg
Thomas Nyberg added the comment: I'm attaching a small patch (against the current hg master branch) that I believe solves the problem, however, I think it was quite hacky. Here is a walk-through of the logic. 1) If '--system-site-packages' is requested, then it is overrided initially

Re: Mapping with continguous ranges of keys

2016-12-16 Thread Thomas Nyberg
On 12/15/2016 11:57 PM, Terry Reedy wrote: On 12/15/2016 4:30 PM, Thomas Nyberg wrote: On 12/15/2016 12:48 PM, Terry Reedy wrote: A sparse array has at least half missing values. This one has none on the defined domain, but contiguous dupicates. I'm sorry for devolving into semantics

Re: Mapping with continguous ranges of keys

2016-12-15 Thread Thomas Nyberg
On 12/15/2016 12:48 PM, Terry Reedy wrote: On 12/15/2016 12:27 PM, Thomas Nyberg wrote: I haven't dealt with a data structure exactly like this, but it's basically a sparse array. A sparse array has at least half missing values. This one has none on the defined domain, but contiguous

Re: Mapping with continguous ranges of keys

2016-12-15 Thread Thomas Nyberg
On 12/15/2016 09:06 AM, Steve D'Aprano wrote: Has anyone dealt with data like this and could give a recommendation of the right data structure to use? I haven't dealt with a data structure exactly like this, but it's basically a sparse array. (I'm sure it has a name somewhere in the

Re: Splitting text into lines

2016-12-13 Thread Thomas Nyberg
On 12/13/2016 08:45 AM, George Trojan - NOAA Federal wrote: Ideally I'd like to have code that handles both '\r\r\n' and '\n' as the split character. George Are repeated newlines/carriage returns significant at all? What about just using re and just replacing any repeated instances of '\r' or

Re: NameError

2016-11-24 Thread Thomas Nyberg
On 11/24/2016 09:00 AM, Cai Gengyang wrote: CaiGengYangs-MacBook-Pro:~ CaiGengYang$ import pygame -bash: import: command not found That indicates you're running "import pygame" at the bash interpreter prompt. You should first start "python" (type the word python without quotes and press

Re: NameError

2016-11-23 Thread Thomas Nyberg
On 11/23/2016 10:02 PM, Cai Gengyang wrote: I tried to import pygame by using these commands https://www.google.com.sg/#q=how+to+import+pygame but this is the error I got : CaiGengYangs-MacBook-Pro:~ CaiGengYang$ sudo apt-get install

Re: Random number help

2016-11-23 Thread Thomas Nyberg
On 11/23/2016 02:17 PM, Thomas Grops via Python-list wrote: I need a way of generating a random number but there is a catch: I don't want to include certain numbers, is this possible? random.randint(1,100) works as it will randomly pick numbers between 1 and 100 but say i don't want 48 to

Re: How to concatenate strings in different lists

2016-11-23 Thread Thomas Nyberg
On 11/23/2016 12:40 PM, Daiyue Weng wrote: Hi, I am wondering how to concatenate corresponding strings in two lists, assuming that the lists are of same length, e.g. val_1 = ['a', 'b', 'c'] val_2 = ['A', 'B', 'C'] # concatenate corresponding strings in 'val_1' and 'val_2' # and put results in

Re: Quick help for a python newby, please

2016-11-23 Thread Thomas Nyberg
On 11/23/2016 09:18 AM, jones.day...@gmail.com wrote: but how do I replace the "2008, 8, 18" and "2008, 9, 26" with *my* values? I've tried several things (which I can't remember all of) but usually end up with an error like this: Does this not work for you? d = date(byear,

Re: Python String Handling

2016-11-11 Thread Thomas Nyberg
On 11/11/2016 05:29 PM, subhabangal...@gmail.com wrote: I have a string "Hello my name is Richard" I want to identify the match of 'Hello' and 'Richard' in list, and replace them with 'Hello/Hi" and 'Richard/P' respectively. The result should look like, "Hello/Hi my name is Richard/P". Simple

Re: Windows: subprocess won't run different Python interpreter

2016-11-10 Thread Thomas Nyberg
On 11/10/2016 05:32 PM, Thorsten Kampe wrote: Yes. That works. But it's not like subprocess should work. It certainly is odd. I can at least confirm that when I try to run your code I get the error that you're expecting, but I run debian. Have you tried using os.unsetenv()?

Re: Windows: subprocess won't run different Python interpreter

2016-11-10 Thread Thomas Nyberg
On 11/10/2016 04:58 PM, Thorsten Kampe wrote: Hi, I'm trying to run a script with a different Python version by extending the path variable and executing "python.exe". It looks like subprocess will always run the current executing Python. > [...] > Thorsten Have you tried using the full

Re: multiprocess passing arguments double asterisks

2016-10-24 Thread Thomas Nyberg
On 10/24/2016 12:45 PM, pic8...@gmail.com wrote: Thanks for the reply. The code snippet given by Peter is not very clear I would like to multiprocess a function which is written in python of the form bar(**kwargs) which returns a value. This example does not return anything Would you please

Re: multiprocess passing arguments double asterisks

2016-10-23 Thread Thomas Nyberg
On 10/23/2016 03:12 AM, pic8...@gmail.com wrote: import multiprocessing as mp def bar(**kwargs): for a in kwargs: print a,kwargs[a] arguments={'name':'Joe','age':20} p=mp.Pool(processes=4) p.map(bar,**arguments) p.close() p.join() What are you trying to do? The map method is similar

[issue23076] list(pathlib.Path().glob("")) fails with IndexError

2016-01-23 Thread Thomas Nyberg
Thomas Nyberg added the comment: I added a patch which causes glob to raise a ValueError exception if it is called with an empty string. I also added a test verifying the change and have run all the tests and they pass. Though I've been reading the developer guide, I'm a bit unfamiliar