Re: Python List is Not Dead

2024-12-30 Thread Erik Max Francis via Python-list
list gatewayed to usenet though, there's really nothing so good as usenet for proper discourse (!). Hear, hear! -- Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && Skype erikmaxfrancis The quality

ANN: EmPy 4.2 -- a powerful, robust and mature templating system for Python

2024-08-25 Thread Erik Max Francis via Python-list
. See [Full list of changes between EmPy 3._x_ and 4.0](http://www.alcyone.com/software/empy/ANNOUNCE.html#all-changes) for a more comprehensive list. -- Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W &am

ANN: EmPy 4.0.1

2024-01-01 Thread Erik Max Francis via Python-list
nges between EmPy 3._x_ and 4.0](http://www.alcyone.com/software/empy/ANNOUNCE.html#full-list-of-changes-between-empy-3-x-and-4-0) for a more comprehensive list. -- Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57

Re: Passing info to function used in re.sub

2023-09-05 Thread Jan Erik Moström via Python-list
On 3 Sep 2023, at 18:10, Jan Erik Moström via Python-list wrote: > I'm looking for some advice for how to write this in a clean way Thanks for all the suggestion, I realize that I haven't written Python code in a while. I should have remembered this myself !!! Thanks for remindi

Re: Passing info to function used in re.sub

2023-09-03 Thread Jan Erik Moström via Python-list
On 3 Sep 2023, at 19:13, MRAB via Python-list wrote: > You could use pass an anonymous function (a lambda) to re.sub: Of course !! Thanks. = jem -- https://mail.python.org/mailman/listinfo/python-list

Passing info to function used in re.sub

2023-09-03 Thread Jan Erik Moström via Python-list
I'm looking for some advice for how to write this in a clean way I want to replace some text using a regex-pattern, but before creating replacement text I need to some file checking/copying etc. My code right now look something like this: def fix_stuff(m): # Do various things that invol

ImportError: No module named spambayes.resources (line 12 of setup_all.py)

2022-08-24 Thread Erik M. Brown via Python-list
how to resolve this module import error? I can provide files and/or more details as well. Thank you all for the help! Take care, Erik Brown -- https://mail.python.org/mailman/listinfo/python-list

Recommendation for drawing graphs and creating tables, saving as PDF

2021-06-11 Thread Jan Erik Moström
I'm doing something that I've never done before and need some advise for suitable libraries. I want to a) create diagrams similar to this one https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more nodes) and save them as PDFs or some format that can easily be converted to PD

Library for text substitutions with calculations?

2020-12-15 Thread Jan Erik Moström
I want to do some text substitutions but a bit more advanced than what string.Template class can do. I addition to plain text substitution I would like to be able to do some calculations: $value+1 - If value is 16 this would insert 17 in the text. I would also like to subtract. $value+1w - I

Re: nonlocal fails ?

2019-11-14 Thread Jan Erik Moström
On 14 Nov 2019, at 15:15, R.Wieser wrote: Too bad though, it means that procedures that want to share/use its callers variables using nonlocal can never be called from main. And that a caller of a procedure using nonlocal cannot have the variable declared as global (just tested it). So wha

Re: nonlocal fails ?

2019-11-14 Thread Jan Erik Moström
On 14 Nov 2019, at 14:06, R.Wieser wrote: I've also tried moving "MyVar = 7" to the first line, but that doesn't change anything. Using "global MyVar" works.. Try def outer(): MyVar = 10 def Proc1(): nonlocal MyVar MyVar = 5 Proc1()

Re: bool(Enum) should raise ValueError

2019-07-28 Thread Erik Aronesty
class Status: valid = 1 invalid = 2 unknown = 3 On Fri, Jul 26, 2019, 3:37 PM Chris Angelico wrote: > On Sat, Jul 27, 2019 at 5:16 AM Erik Aronesty wrote: > > > > I just spend a while tracking down and killing all "if Enum" and "if not > > En

bool(Enum) should raise ValueError

2019-07-26 Thread Erik Aronesty
I just spend a while tracking down and killing all "if Enum" and "if not Enum" bugs in my code. I was frankly shocked that this didn't raise a ValueError to begin with. Apparently all enums are true/false depending on whether the underlying value is truthy or falsy. Which breaks the abstraction

site package does not work

2018-06-05 Thread Erik Martinson via Python-list
I am trying to dynamically add a site-package to a script that is run as a cron job. The method adduseristepackages does not seem to do anything. import sys import site print('-')print(site.getusersitepackages()) print('add', site.addusersitepackage

Help with 'site' package.

2018-06-04 Thread Erik Martinson via Python-list
I am trying to dynamically add a site-package to a script that is run as a cron job. The method adduseristepackages does not seem to do anything. import sys import site print('-')print(site.getusersitepackages()) print('add', site.addusersitepackage

Re: Asynchronous processing is more efficient -- surely not?

2018-04-04 Thread Jan Erik Moström
On 4 Apr 2018, at 9:27, Steven D'Aprano wrote: Its as hard to wrap your brain around as parallel processing in general, but with even worse performance than sequential processing. Am I totally wrong? I would say that it all depends on what kind of stuff you're doing. I'm no scheduling exper

Re: macOS specific - reading calendar information

2018-03-15 Thread Jan Erik Moström
On 14 Mar 2018, at 21:40, Larry Martell wrote: I've been trying to find some example of how to read calendar info on macOS but I haven't found anything ... I'm probably just bad at searching !! What I want to do is to read calendar info for a date range. Does anyone know of an example of ho

macOS specific - reading calendar information

2018-03-14 Thread Jan Erik Moström
I've been trying to find some example of how to read calendar info on macOS but I haven't found anything ... I'm probably just bad at searching !! What I want to do is to read calendar info for a date range. Does anyone know of an example of how to do this? = jem -- https://mail.python.org/m

Re: Simple graphic library for beginners

2018-01-11 Thread Jan Erik Moström
On 10 Jan 2018, at 13:40, Jan Erik Moström wrote: I'm looking for a really easy to use graphic library. The target users are teachers who have never programmed before and is taking a first (and possible last) programming course. Thanks for all the suggestions, I'm going to take

Simple graphic library for beginners

2018-01-10 Thread Jan Erik Moström
I'm looking for a really easy to use graphic library. The target users are teachers who have never programmed before and is taking a first (and possible last) programming course. I would like to have the ability to draw lines, circles, etc. Nothing fancy, as little window management as possibl

Re: Old Man Yells At Cloud

2017-09-19 Thread Jan Erik Moström
On 19 Sep 2017, at 13:01, bartc wrote: My bill in a store came to £3.20 (GBP3.20), so I handed over £10.20. I was given back £16.90 in change! It turned out the cashier had entered £20.10 as the amount tendered. It was sorted out in the end. Sometimes its easier not to be bother making the

Re: print without ()

2017-09-06 Thread Jan Erik Moström
On 7 Sep 2017, at 8:14, Andrej Viktorovich wrote: If I use command print "aaa" in console I get error. So, why this is allowed in sample? You're probably using Python 2 for the listed script and Python 3 when you try in the console. = jem -- https://mail.python.org/mailman/listinfo/python-l

Re: Why is my class undefined?

2017-08-16 Thread Jan Erik Moström
On 17 Aug 2017, at 0:48, Sayth Renshaw wrote: > what exactly am I doing wrong? Outdent the if-statement = jem -- https://mail.python.org/mailman/listinfo/python-list

Re: Syntax error for simple script

2017-06-28 Thread Erik
On 28/06/17 03:46, Steve D'Aprano wrote: All of this is irrelevant if beginners don't read the error message. "if". End-users don't read error messages, no matter how well written they are, Reference? and every word you add probably cuts the number of people reading it by half. "probabl

Re: Syntax error for simple script

2017-06-27 Thread Erik
On 27/06/17 15:05, Steve D'Aprano wrote: On Tue, 27 Jun 2017 08:34 am, Erik wrote about the print function error message: To be fair, this already seems to be a special case: [...] >>> len "bar" File "", line 1 len "bar"

Re: Syntax error for simple script

2017-06-26 Thread Erik
On 27/06/17 00:21, Stefan Ram wrote: Erik writes:Using 'print' as a statement is obsolete syntax in Python 3. »print« never was a statement. »print« was a keyword (2.7.6 2.3.1). *sigh* Whatever. You have completely ignored my point (that perhaps the message c

Re: Syntax error for simple script

2017-06-26 Thread Erik
On 26/06/17 18:30, Chris Angelico wrote: On Tue, Jun 27, 2017 at 2:41 AM, Rurpy via Python-list wrote: How about: In Python 2, 'print' was a statement and did not require parenthesis around its argument. In Python 3 'print' has been changed to a function and now, like all functions,

Re: [OT] is JSON all that great? - was Re: API Help

2017-06-16 Thread Erik
On 16/06/17 12:03, alister wrote: (The non native English speaker excuse is not an option for me) Does that mean it's mandatory for you? I'm confused :D :D E. -- https://mail.python.org/mailman/listinfo/python-list

Re: [OT] is JSON all that great? - was Re: API Help

2017-06-15 Thread Erik
On 15/06/17 15:10, Chris Angelico wrote: On Fri, Jun 16, 2017 at 12:00 AM, alister wrote: Json is designed to be legal Javascript code & therefore directly executable so no parser is posible. "no parser is possible"??? I *think* alister meant "so it is possible to not use a parser [librar

Re: API Help

2017-06-15 Thread Erik
On 15/06/17 01:30, Ray Cote wrote: On Wed, Jun 14, 2017 at 6:14 PM, Erik <mailto:pyt...@lucidity.plus.com>> wrote: If that makes it definitely JSON, then this makes it definitely Python ;) : >>> [{"itemNumber":"75-5044",

Re: API Help

2017-06-14 Thread Erik
On 15/06/17 00:45, Chris Angelico wrote: Add all that kind of thing together, and you get my original conclusion that this is JSON. It's also perfectly parseable as various other things, but it's still most likely to be JSON. It "is JSON" but is also "parsable as various other things" yet is "m

Re: API Help

2017-06-14 Thread Erik
On 15/06/17 00:08, justin walters wrote: I should also specify that the data you have received is malformed. JSON should always have an object as the top level structure, not an array as in your data. So it's not JSON then? :D E. -- https://mail.python.org/mailman/listinfo/python-list

Re: API Help

2017-06-14 Thread Erik
On 14/06/17 22:30, Chris Angelico wrote: It wouldn't be the repr() of a Python structure, as that wouldn't have all those trailing zeroes. That depends on what class represents those float values. It doesn't have to be the built-in float. Same with the double-quotes instead of single-quotes o

Re: API Help

2017-06-14 Thread Erik
On 14/06/17 22:54, Ray Cote wrote: Definitely JSON: json.loads(“""[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.

Re: API Help

2017-06-14 Thread Erik
On 14/06/17 22:16, Matt Wheeler wrote: ? JSON keys are quoted Thanks Matt, I was confusing myself between JS source and JSON. Good to have this reminder (I always use libraries for reading and writing JSON in whatever language, so while I view it often I very rarely have to type it in direc

Re: API Help

2017-06-14 Thread Erik
On 14/06/17 22:18, Grant Edwards wrote: What makes it look like JSON to you? The fact that it _is_ valid JSON (at least according to the parsers I've tried on it, both locally and using things like jsonlint.com). And I tried it on the Python REPL. It's Python too. If someone wrote the follow

Re: API Help

2017-06-14 Thread Erik
On 14/06/17 21:47, Erik wrote: What makes it look like JSON to you? (I'm not arguing, I'm asking what I've missed). If I cut-and-paste the OP's structure into the REPL, it replies with a valid Python structure that's equivalent (albeit with single-quotes instead

Re: API Help

2017-06-14 Thread Erik
On 14/06/17 21:38, Chris Angelico wrote: On Thu, Jun 15, 2017 at 6:33 AM, Bradley Cooper wrote: I am working with an API and I get a return response in this format. [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US"

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

2017-06-09 Thread Erik
On 10/06/17 00:18, Terry Reedy wrote: On 6/9/2017 6:00 PM, Erik wrote: On 09/06/17 19:39, 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

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

2017-06-09 Thread Erik
On 09/06/17 19:39, 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 the first one eve

Re: Is An Element of a Sequence an Object?

2017-06-03 Thread Erik
On 04/06/17 00:42, Jon Forrest wrote: On 6/3/2017 12:38 PM, Thomas Jollans wrote: >> I'd like to suggest an explanation of what a sequence is >> that doesn't use the word 'object' because an object has >> a specific meaning in Python. >> >> Am I on the right track here? > > No, strings do

Re: Concatenating files in order

2017-05-23 Thread Erik
On 23/05/17 22:14, Mahmood Naderan via Python-list wrote: sorted=[[int(name.split("_")[-1]), name] for name in files] This isn't sorting anything. At no point do you invoke a sort operation. It's processing the list in the original order and generating a new list with a different format but *

Re: Iterating through a list. Upon condition I want to move on to next item in list

2017-05-10 Thread Erik
On 10/05/17 23:41, Dan Stromberg wrote: On Wed, May 10, 2017 at 1:46 PM, MRAB wrote: NEVER use a 'bare except' to suppress exceptions! It'll catch _all_ exceptions, even NameError (if you've misspelled a name, it'll catch that too). Catch only those exceptions that you're prepared to deal with

Re: Iterating through a list. Upon condition I want to move on to next item in list

2017-05-10 Thread Erik
On 10/05/17 20:25, aaron.m.weisb...@gmail.com wrote: As my code stands right now, it counts through the stateList[0] and then when associationsCount gets to 0 it just stops. I know I need to add another couple lines of code to get it back going again It's very difficult to see what you're tryi

Re: getting memory usage of varaibles

2017-05-03 Thread Erik
On 03/05/17 23:21, Larry Martell wrote: But not for a variable like a list or dict? What name should "[1, 2, 3]", or "{1, 'a': 2: 'b'}" be given? The thing about functions or classes is that you can't (at the literal source level) define them *without* giving them a name: def func(): pass c

Re: getting memory usage of varaibles

2017-05-02 Thread Erik
On 02/05/17 23:28, Larry Martell wrote: Anyone have any thoughts on how I can monitor the variables' memory usage as the script runs? This is application-specific, but sometimes it helps to look at the objects' types, or even their values. The types are dict and list, so they are not very use

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
On 30/04/17 01:17, breamore...@gmail.com wrote: On Sunday, April 30, 2017 at 12:23:19 AM UTC+1, Erik wrote: The other is that the documentation of collections.OrderedDict seems to be lacking (it is talking in terms of being a "dict" subclass, but it actually isn't one). E. Co

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
On 30/04/17 01:31, Ben Finney wrote: Erik writes: On 29/04/17 23:40, Ned Batchelder wrote: For creating your own class that acts like a dict, you should derive from collections.abc.MutableMapping, which only requires implementing __getitem__, __setitem__, __delitem__, __iter__, and __len__

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
On 29/04/17 23:40, Ned Batchelder wrote: For creating your own class that acts like a dict, you should derive from collections.abc.MutableMapping, which only requires implementing __getitem__, __setitem__, __delitem__, __iter__, and __len__. Or, I could derive from collections.OrderedDict and j

Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
I have a subclass of dict that enforces which keys are allowed to be set and only allows each key to be set at most once: class StrictDict(dict): def __init__(self, validkeys, *args, **kwargs): self.validkeys = validkeys super(StrictDict, self).__init__(*args, **kwargs) def __setite

Re: Data exchange between python script and bash script

2017-04-19 Thread Erik
[Disclaimer: I have not fully read this thread. If I'm jumping in with something that's irrelevant for other reasons, please just ignore me] On 19/04/17 22:06, Venkatachalam Srinivasan wrote: On Thursday, April 6, 2017 at 12:55:41 AM UTC+2, Gregory Ewing wrote: sensor_data=$(python execute_sen

Re: Bigotry (you win, I give up)

2017-04-19 Thread Erik
On 19/04/17 21:25, Ethan Furman wrote: Asking that you not denigrate non-Python ideas on the Python list is not asking for "special respect", I have no idea what you just said! :D This is why I dislike code such as: if not no_results(data) != not_valid: pass ... and I've seen lots of

Re: Test if Script Already Running

2017-04-18 Thread Erik
On 19/04/17 01:31, Matt wrote: In perl I did it with this at the start of every script: use Fcntl ':flock'; [snip] How can I do something like this in Python? >>> import fcntl >>> help(fcntl.flock) E. -- https://mail.python.org/mailman/listinfo/python-list

Re: Python and the need for speed

2017-04-18 Thread Erik
On 19/04/17 00:33, bartc wrote: So that's 'label-pointers' which I assume must correspond to computed goto. Yes - just different terminology. Being able to take the address of a label and "goto address" rather than "goto label". (I don't know why they should be faster than a switch; they ju

Re: Python and the need for speed

2017-04-18 Thread Erik
On 19/04/17 00:08, Gregory Ewing wrote: Erik wrote: When considering special-casing this opcode sequence, remember that in-place operations can be performed on anonymous objects (i.e., those referenced by a collection and not bound directly to a namespace): I think this means you would want

Re: Python and the need for speed

2017-04-18 Thread Erik
On 18/04/17 11:30, bartc wrote: On 18/04/2017 10:32, Erik wrote: the improvements over the original huge switch() to dispatch the bytecodes to the correct handler appear to have made this type of optimization less effective. What did they do to it, and on which version? It's the com

Re: Python and the need for speed

2017-04-18 Thread Erik
On 13/04/17 18:50, MRAB wrote: On 2017-04-13 09:08, Steven D'Aprano wrote: On Wed, 12 Apr 2017 16:30:38 -0700, bart4858 wrote: Is it possible to skip the STORE_NAME op-code? If you knew *for sure* that the target (x) was a mutable object which implemented += using an in- place mutation, then you

Re: Merging multiple sorted sequences.

2017-04-13 Thread Erik
On 13/04/17 07:30, Peter Otten wrote: Verdict: not greedy ;) Great (as I mentioned I did look at the code VERY quickly whilst VERY tired and at first glance missed that it's doing almost exactly what my code is doing except using the heapq to manage tracking the smallest value rather than so

Re: Merging multiple sorted sequences.

2017-04-12 Thread Erik
Hi Ian, On 13/04/17 00:09, Erik wrote: On 12/04/17 23:44, Ian Kelly wrote: I would just use "lowest = min(items, key=itemgetter(0))". I had it in my head for some reason that min() would return the smallest key, not the object (and hence I wouldn't be able to know which seq

Re: Merging multiple sorted sequences.

2017-04-12 Thread Erik
Hi Peter, On 12/04/17 23:42, Peter Otten wrote: Erik wrote: I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. https://docs.python.org/dev/library/heapq.html#heapq.merge AFAICT (looking at the Python 3.5 heapq

Re: Merging multiple sorted sequences.

2017-04-12 Thread Erik
On 12/04/17 23:44, Ian Kelly wrote: This might be okay since Timsort on an already-sorted list should be O(n). But there's not really any need to keep them sorted and I would just use "lowest = min(items, key=itemgetter(0))". Sure (and this was my main worry). I had it in my head for some reaso

Merging multiple sorted sequences.

2017-04-12 Thread Erik
Hi. I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. The merge should continue until the longest sequence has been exhausted. (*) They may in practice be a lazy source of data known to only ever be generated in

Re: Python and the need for speed

2017-04-10 Thread Erik
On 10/04/17 03:23, Chris Angelico wrote: Okay, I have a pretty thick skin, but this is getting a bit obnoxious. Can you PLEASE post something that isn't just insulting me? Thanks. Are you suggesting he should post something that insults you *and* others? If so, I'm up for being insulted too ;)

Re: read in a list in a file to list

2017-04-10 Thread Erik
On 09/04/17 22:22, john polo wrote: The new attempt gives me a list, now I have to figure out how to deal with unwanted quotation marks and spaces. datFil = open("apelist.txt") datObj = datFil.read() datObj2 = datObj.replace('" ','') #added this comment while writing this email: I guess I c

Re: PYTHON

2017-04-06 Thread Jan Erik Moström
On 6 Apr 2017, at 14:43, aldersilva...@gmail.com wrote: > Hello, how can I start programming? Let me google that for you => http://www.learnpython.org -- https://mail.python.org/mailman/listinfo/python-list

Re: Python question

2017-03-25 Thread Erik
On 25/03/17 20:26, MRAB wrote: On 2017-03-25 20:10, Terry Reedy wrote: On 3/25/2017 6:50 AM, Steve D'Aprano wrote: they BCC or CC me without a good excuse. As I was in this case: the OP BCCed me in his post. I'm not *that* special, so my guess is that he did a mass BCC of many regulars here, wh

Re: python source code

2017-03-22 Thread Erik
On 22/03/17 21:57, M. R.P. wrote: does anyone know were I can [find?] python source code programs? Are you looking for the source to a Python language implementation itself? If so, see this link: https://www.python.org/downloads/ If not, what are you looking for, exactly? What sort of Pytho

Re: Who are the "spacists"?

2017-03-19 Thread Erik
On 19/03/17 23:23, Jon Ribbens wrote: On 2017-03-19, Erik wrote: On 19/03/17 22:29, Jon Ribbens wrote: Not to mention plenty of editors (e.g. vim) will unindent when you press backspace. I don't think that's strictly true. If you have just indented with a tab character, then back

Re: Who are the "spacists"?

2017-03-19 Thread Erik
On 19/03/17 22:29, Jon Ribbens wrote: On 2017-03-19, breamore...@gmail.com wrote: On Sunday, March 19, 2017 at 9:54:52 PM UTC, Larry Hudson wrote: A trivial point (and irrelevant)... The thing I find annoying about an editor set to expand tabs to spaces is that it takes one keypress to indent

Re: When will os.remove fail?

2017-03-14 Thread Erik
On 14/03/17 13:56, Chris Angelico wrote: On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: rm does not ask before deleting. However some Linux distributions take it upon themselves to put "alias rm='rm -i'" in /etc/profile. I have no such alias, but it still prompts. [snip] This is the

Re: Precision reading and writing data frames to csv

2017-03-11 Thread Erik
Hi Paulo, On 11/03/17 22:01, Paulo da Silva wrote: I have a dir with lots of csv files. These files are updated +- once a day. I could see that some values are converted, during output, to very close values but with lots of digits. I understand that is caused by the internal bits' representation

Re: What's the neatest way of getting dictionary entries in a specified order?

2017-03-09 Thread Erik
On 09/03/17 13:09, Chris Green wrote: Michael Torrie wrote: On 03/08/2017 12:27 PM, Chris Green wrote: I have a fairly simple application that populates a GUI window with fields from a database table. The fields are defined/configured by a dictionary as follows:- Instead of ordering the dat

Re: Python replace multiple strings (m*n) combination

2017-02-24 Thread Erik
On 24/02/17 22:18, kar wrote: Thanks, what is the idea behind storing the keys and values in a list, I assume looking up for a value in a map is faster getting the value from the list. What do you not understand? MRAB's extensive comments explain what is being done and why. In summary, the

Re: Python replace multiple strings (m*n) combination

2017-02-24 Thread Erik
On 24/02/17 18:54, kar6...@gmail.com wrote: for example is the search string is not a variable we can say re.search(r"\$%^search_text", "replace_text", "some_text") but when I read from the dict where shd I place the "r" keyword, unfortunately putting inside key doesnt work "r key" like this

Re: Namedtuples problem

2017-02-23 Thread Erik
On 23/02/17 23:00, Deborah Swanson wrote: It looks to me like you are indexing into a single-element list that you are creating using the literal list syntax in the middle of the expression. Actually, group is essentially a 2-element list. Each group has a list of rows, and each row has a set o

Re: Namedtuples problem

2017-02-23 Thread Erik
Hi, On 23/02/17 09:38, Deborah Swanson wrote: group[[idx][records_idx[label]]] gets an Index Error: list index out of range [snip] Can anyone see why I'm getting this Index error? and how to fix it? It looks to me like you are indexing into a single-element list that you are creating usin

Re: WANT: bad code in python (for refactoring example)

2017-02-15 Thread Erik
On 15/02/17 21:53, Erik wrote: process(data) Before I get jumped on by a pack of rabid wolves, I of course meant: process(d) E. -- https://mail.python.org/mailman/listinfo/python-list

Re: WANT: bad code in python (for refactoring example)

2017-02-15 Thread Erik
Hi, On 15/02/17 09:36, Makoto Kuwata wrote: I'm sorry that my explanation is not enough. I'm looking for bad python code, not refactoring examples. I think you need to explain what you mean by "bad". Do you mean something like: i = 0 data = ["bad", "example", "of", "python", "code"] while i

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:34, Chris Angelico wrote: The unit "\t" always means U+0009, even if it's following a raw string literal; and the unit "\d" always means "\\d", regardless of the rawness of any of the literals involved. The thing that's biting you here is that unrecognized escapes get rendered as b

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:23, Erik wrote: r"hello \the" "worl\d" "\t" 'hello \\theworl\\d\t' The initial string is raw. The following string adopts that (same as the second example), but the _next_ string does not! Why is the first string token parsed as a &q

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:13, Chris Angelico wrote: On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: The string "\t" gets shown in the repr as "\t". It is a string consisting of one character, U+0009, a tab. The string r"\t" is shown as "\\t" and consists of two characters, REVERSE SOLIDUS and LATI

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:11, Chris Angelico wrote: Firstly, be aware that there's no such thing as a "raw string" - what you have is a "raw string literal". It's a purely syntactic feature. I do understand that. When I said "is raw"/"rawness", I am talking about what the _parser_ is doing. I don't think

Re: os.path.isfile

2017-02-12 Thread Erik
On 12/02/17 23:56, Erik wrote: r"hello \the" "worl\d" 'hello \\theworl\\d' Slightly surprising. The concatenated string adopts the initial string's 'rawness'. "hello \the" r"worl\d" "\t" 'hello \theworl\\d\

Re: os.path.isfile

2017-02-12 Thread Erik
On 12/02/17 04:53, Steve D'Aprano wrote: py> s = r'documents\' File "", line 1 s = r'documents\' ^ SyntaxError: EOL while scanning string literal (I still don't understand why this isn't just treated as a bug in raw string parsing and fixed...) I would imagine that i

Re: int vs. float

2017-02-11 Thread Erik
[Dan, this isn't "aimed" at you personally, it's just a follow-up on the general point I am (and I think you are also) making] On 11/02/17 02:17, Dan Sommers wrote: At least it works both ways: Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright"

Re: int vs. float

2017-02-10 Thread Erik
On 10/02/17 19:15, Peter Pearson wrote: > On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron wrote: >> Use: >> >> try: >>num=int(str) >> except ValueError e: >>print "Error: not an integer" > > What should happen if the user types "1.0"? > > To be flexible about this possibility, you could

Re: Strategies when hunting for dictionary corruption

2017-02-07 Thread Erik
On 06/02/17 12:56, Skip Montanaro wrote: Is there a better way to approach this problem? (I also have valgrind at my disposal, but am not very skilled in its use.) valgrind is what I was going to suggest. You have to compile Python with extra flags to get it to integrate well with valgrind tho

Re: How coding in Python is bad for you

2017-02-01 Thread Erik
On 02/02/17 01:41, Chris Angelico wrote: On Thu, Feb 2, 2017 at 10:49 AM, Erik wrote: Well, _logically_ there is a flag (in as much as it could be thought of like that to make it easy to understand - and in C, that's pretty much what you have to actually do unless you really want to use

Re: How coding in Python is bad for you

2017-02-01 Thread Erik
On 02/02/17 02:05, MRAB wrote: Both suggestions are a little long-winded. Couldn't we just abbreviate them to "else:"? :-) You are not wrong ;) E. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to know what to install (Ubuntu/Debian) for a given import?

2017-02-01 Thread Erik
On 01/02/17 23:20, Wildman via Python-list wrote: On Wed, 01 Feb 2017 21:29:00 +, Chris Green wrote: Wildman wrote: On Wed, 01 Feb 2017 19:15:13 +, Chris Green wrote: OK, no problem, but isn't it very non-portable? I don't see why not. It should work on any system that has Python3

Re: How coding in Python is bad for you

2017-02-01 Thread Erik
On 30/01/17 02:14, Steve D'Aprano wrote: On Mon, 30 Jan 2017 10:52 am, Erik wrote: It would be even better if it was "else if not break:" to make the meaning clearer. break is not the only way to exit the for loop Fine - "else if not break or raise or return:"

Re: How coding in Python is bad for you

2017-01-29 Thread Erik
On 29/01/17 14:42, Steve D'Aprano wrote: 1. for...else is misspelled, and should be for...then; 2. Same for while...else; I don't think I'll ever agree with you on this one. "then", to me, implies the code following it is always executed. "else" implies it's conditional. In those constructs

Re: Need reviews for my book on introductory python

2017-01-27 Thread Erik
On 27/01/17 21:36, MRAB wrote: "loose"? Don't you mean "lose"? (Or possible "lack"?) Don't you mean 'Or possibly "lack"'? https://en.wikipedia.org/wiki/Muphry%27s_law ;) E. -- https://mail.python.org/mailman/listinfo/python-list

Re: Emulating Final classes in Python

2017-01-17 Thread Erik
Hi Steven, On 17/01/17 07:05, Steven D'Aprano wrote: I wish to emulate a "final" class using Python, similar to bool: [snip] It doesn't have to be absolutely bulletproof, but anyone wanting to subclass my class should need to work for it, which hopefully will tell them that they're doing som

Re: working with classes, inheritance, _str_ returns and a list

2017-01-15 Thread Erik
Hi, On 15/01/17 19:58, David D wrote: I am creating a parent class and a child class. I am inheriting from the parent with an additional attribute in the child class. I am using __str__ to return the information. When I run the code, it does exactly what I want, it returns the __str__ informa

Re: How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-14 Thread Erik
[Replying to direct email. David - please respond to the list so that you can receive other people's suggestions also] Hi David, On 14/01/17 15:30, David D wrote: > 1) No this is not homework, I am doing this all on my own. In that case I apologise - I gave you the benefit of the doubt though

Re: How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-13 Thread Erik
Hi, On 13/01/17 22:26, daviddsch...@gmail.com wrote: The issue I am having is that when i enter the sentinel value of QUIT, it gets initialized as the name and printed out. How can I get around this? If I understand the question correctly (which looks like it's just a re-worded homework que

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Erik
On 10/01/17 03:02, Deborah Swanson wrote: Erik wrote, on January 09, 2017 5:47 PM IIRC, you create it using a list comprehension which creates the records. A list comprehension always creates a list. Well no. The list is created with: records.extend(Record._make(row) for row in rows) No

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Erik
On 10/01/17 00:54, Deborah Swanson wrote: Since I won't change the order of the records again after the sort, I'm using records.sort(key=operator.attrgetter("Description", "Date")) once, which also works perfectly. So both sorted() and sort() can be used to sort namedtuples. Good to know! A

Re: Hey, I'm new to python so don't judge.

2017-01-06 Thread Erik
On 04/01/17 02:47, Callum Robinson wrote: > On Wednesday, January 4, 2017 at 3:35:53 PM UTC+13, Erik wrote: > I did it and this is what it states when i run it > > hello. > I have thought of a number between 1 and 100. > Can you guess it? > 5 > Low > Sorry , you are to

  1   2   3   4   5   6   7   8   9   10   >