Re: Proposed new syntax

2017-08-14 Thread Jussi Piitulainen
Paul Rubin writes: >> Jussi Piitulainen writes: >>> But what is "set comprehension" in French, German, or Finnish? > > The idea comes from set theory: for some reason English Wikipedia > doesn't have Finnish cross-wiki links for most of the relevant ter

Re: Proposed new syntax

2017-08-12 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Marko Rauhamaa <ma...@pacujo.net>: > >> Jussi Piitulainen <jussi.piitulai...@helsinki.fi>: >> >>> But what is "set comprehension" in French, German, or Finnish? >> >> [...] >> >> Mys

Re: Proposed new syntax

2017-08-12 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> Rustom Mody writes: >>> [ My conjecture: The word ‘comprehension’ used this way in English is >>> meaningless and is probably an infelicious translation of something >>> which makes sense in Germ

Re: Proposed new syntax

2017-08-12 Thread Jussi Piitulainen
Rustom Mody writes: > [ My conjecture: The word ‘comprehension’ used this way in English is > meaningless and is probably an infelicious translation of something > which makes sense in German] From a Latin word for "taking together", through Middle French, according to this source, which has

Re: Proposed new syntax

2017-08-10 Thread Jussi Piitulainen
MRAB writes: > On 2017-08-10 15:28, Steve D'Aprano wrote: >> Every few years, the following syntax comes up for discussion, with >> some people saying it isn't obvious what it would do, and others >> disagreeing and saying that it is obvious. So I thought I'd do an >> informal survey. >> >> What

Re: Proposed new syntax

2017-08-10 Thread Jussi Piitulainen
Steve D'Aprano writes: > Every few years, the following syntax comes up for discussion, with > some people saying it isn't obvious what it would do, and others > disagreeing and saying that it is obvious. So I thought I'd do an > informal survey. > > What would you expect this syntax to return? >

Re: Installing matplotlib on python3

2017-07-27 Thread Jussi Piitulainen
FS writes: > I just installed matplotlib on debian and I tried to import it on > python3. It cannot be found however it can be found on python 2.x. No > surprise: > A 'find -name matplotliib' reveals: > /usr/share/matplotlib > /usr/lib/python2.7/dist-packages/matplotlib > > I am not sure how

Re: Regular expression

2017-07-26 Thread Jussi Piitulainen
Kunal Jamdade writes: > There is a filename say:- 'first-324-True-rms-kjhg-Meterc639.html' . > > I want to extract the last 4 characters. I tried different regex. but > i am not getting it right. > > Can anyone suggest me how should i proceed.? os.path.splitext(name) # most likely; also:

Re: About the implementation of del in Python 3

2017-07-06 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen: > >> For me it's enough to know that it's the object itself that is passed >> around as an argument, as a returned value, as a stored value, as a >> value of a variable. This is the basic fact that lets me understand >>

Re: About the implementation of del in Python 3

2017-07-06 Thread Jussi Piitulainen
MRAB <pyt...@mrabarnett.plus.com> writes: > On 2017-07-06 15:29, Jussi Piitulainen wrote: >> Marko Rauhamaa writes: >> >>> While talking about addresses might or might not be constructive, >>> let me just point out that there is no outwardly visible distinc

Re: About the implementation of del in Python 3

2017-07-06 Thread Jussi Piitulainen
Marko Rauhamaa writes: > While talking about addresses might or might not be constructive, let > me just point out that there is no outwardly visible distinction > between "address" or "identity". With a generational or otherwise compacting garbage collector there would be. I believe that to be

Re: About the implementation of del in Python 3

2017-07-06 Thread Jussi Piitulainen
Chris Angelico writes: > On Thu, Jul 6, 2017 at 5:35 PM, Jussi Piitulainen > <jussi.piitulai...@helsinki.fi> wrote: >> Incidentally, let no one point out that ids are not memory addresses. >> It says in the interactive help that they are (Python 3.4.0): >> &

Re: About the implementation of del in Python 3

2017-07-06 Thread Jussi Piitulainen
Dan Wissme writes: > I thought that del L[i] would slide L[i+1:] one place to the left, > filling the hole, but : > L > [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] id(L) > 4321967496 id(L[5])# address of 50 ? > 4297625504 del L[2] id(L[4]) # new address of 50 ? >

Re: How to write raw strings to Python

2017-07-05 Thread Jussi Piitulainen
Binary Boy writes: > On Wed, 05 Jul 2017 20:37:38 +0300, Jussi Piitulainen wrote: >> Sam Chats writes: >> >> > On Wednesday, July 5, 2017 at 9:09:18 PM UTC+5:30, Grant Edwards wrote: >> >> On 2017-07-05, Sam Chats <blahb...@blah.org> wrote: >>

Re: How to write raw strings to Python

2017-07-05 Thread Jussi Piitulainen
Sam Chats writes: > On Wednesday, July 5, 2017 at 9:09:18 PM UTC+5:30, Grant Edwards wrote: >> On 2017-07-05, Sam Chats wrote: >> >> > I want to write, say, 'hello\tworld' as-is to a file, but doing >> > f.write('hello\tworld') makes the file look like: >> [...] >> > How can

Re: how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency

2017-06-23 Thread Jussi Piitulainen
Dennis Lee Bieber writes: > On Thu, 22 Jun 2017 22:46:28 +0300, Jussi Piitulainen declaimed the > following: > >> >> A pair of methods, str.maketrans to make a translation table and then >> .translate on every string, allows to do all that in one step: >&g

Re: how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency

2017-06-22 Thread Jussi Piitulainen
Dennis Lee Bieber writes: > # lowerecase all, open hyphenated and / separated words, parens, > # etc. > ln = ln.lower().replace("/", " ").replace("-", " ").replace(".", " ") > ln = ln.replace("\\", " ").replace("[", " ").replace("]", " ") > ln = ln.replace("{", " ").replace("}", " ") >

Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Jussi Piitulainen
Andre Müller writes: > I'm a fan of infinite sequences. Try out itertools.islice. > You should not underestimate this very important module. > > Please read also the documentation: > https://docs.python.org/3.6/library/itertools.html > > from itertools import islice > > iterable =

Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Jussi Piitulainen
Malcolm Greene writes: > Wondering if there's a standard lib version of something like > enumerate() that takes a max count value? > Use case: When you want to enumerate through an iterable, but want to > limit the number of iterations without introducing if-condition-break > blocks in code. >

Re: How to store some elements from a list into another

2017-06-13 Thread Jussi Piitulainen
Peter Otten writes: ... > def edges(items): > first = last = next(items) > for last in items: > pass > return [first, last] ... > However, this is infested with for loops. Therefore ... > I don't immediately see what to do about the for loop in edges(), so > I'll use the

Re: How to store some elements from a list into another

2017-06-13 Thread Jussi Piitulainen
breamore...@gmail.com writes: > On Monday, June 12, 2017 at 7:33:03 PM UTC+1, José Manuel Suárez Sierra wrote: >> Hello, >> I am stuck with a (perhaps) easy problem, I hope someone can help me: >> >> My problem is: >> I have a list of lists like this one: >> [[55, 56, 57, 58, 83, 84, 85, 86, 89,

Re: Generator and return value

2017-06-07 Thread Jussi Piitulainen
Frank Millman writes: > It would be nice to write a generator in such a way that, in addition > to 'yielding' each value, it performs some additional work and then > 'returns' a final result at the end. > >> From Python 3.3, anything 'returned' becomes the value of the >> StopIteration >

Re: Is An Element of a Sequence an Object?

2017-06-05 Thread Jussi Piitulainen
Peter Otten writes: > Thomas Jollans wrote: > >> On 04/06/17 09:52, Rustom Mody wrote: >>> On Sunday, June 4, 2017 at 12:45:23 AM UTC+5:30, Jon Forrest wrote: I'm learning about Python. A book I'm reading about it says "... a string in Python is a sequence. A sequence is an ordered

Re: Bug or intended behavior?

2017-06-02 Thread Jussi Piitulainen
sean.diza...@gmail.com writes: > Can someone please explain this to me? Thanks in advance! > > ~Sean > > > Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information.

Re: zeep, infinite recursion

2017-05-29 Thread Jussi Piitulainen
Nagy László Zsolt writes: > Running this command: > > python3.6 -m zeep exmaple.wsdl > > I get this (this is only the end of the traceback): > ... > from zeep.xsd import ComplexType > RecursionError: maximum recursion depth exceeded > > Looks like an infinite recursion to me. Due to a

Re: Check for regular expression in a list

2017-05-26 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Or use a regex match if the condition becomes more complex. Even then, > there is re.match to attemp a match at the start of the string, which > helps to keep the expression simple. Soz: attemp' a match. -- https://mail.python.org/mailman/listinfo/python-list

Re: Check for regular expression in a list

2017-05-26 Thread Jussi Piitulainen
Rustom Mody writes: > On Friday, May 26, 2017 at 5:02:55 PM UTC+5:30, Cecil Westerhof wrote: >> To check if Firefox is running I use: >> if not 'firefox' in [i.name() for i in list(process_iter())]: >> >> It probably could be made more efficient, because it can stop

Re: Scala considering significant indentation like Python

2017-05-22 Thread Jussi Piitulainen
Cholo Lennon writes: > On 22/05/17 00:53, Steve D'Aprano wrote: >> The creator of Scala, Martin Odersky, has proposed introducing >> Python-like significant indentation to Scala and getting rid of >> braces: >> >> I was playing for a while now with ways to make Scala's syntax >>

Re: How to install Python package from source on Windows

2017-05-22 Thread Jussi Piitulainen
Gregory Ewing writes: > Jussi Piitulainen wrote: >> I was surprised that Git (or GitHub Desktop) simply failed so badly. >> Not sure what it could have done instead. > > It's not really git's fault, it's a consequence of differing > filename conventions on different platf

Re: How to install Python package from source on Windows

2017-05-21 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, May 21, 2017 at 9:43 PM, Jussi Piitulainen wrote: >> It happened to me recently when cloning a git repository from GitHub, >> using GitHub Desktop, to a Mac OS file system. Some filenames differed >> only in case, like "INFO" and &q

Re: How to install Python package from source on Windows

2017-05-21 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, May 21, 2017 at 8:23 PM, bartc wrote: >> On 20/05/2017 19:37, Chris Angelico wrote: >> >>> rosuav@sikorsky:~/linux$ find -name \*.c -or -name \*.h | wc -l >>> 44546 >>> >>> These repositories, by the way, correspond to git URLs >>>

Re: Rawest raw string literals

2017-04-21 Thread Jussi Piitulainen
Tim Chase <python.l...@tim.thechases.com> writes: > On 2017-04-21 08:23, Jussi Piitulainen wrote: >> Tim Chase writes: >>> Bash: >>> cat <>> "single and double" with \ and / >>> EOT >>> >>> PS: ye

Re: Rawest raw string literals

2017-04-20 Thread Jussi Piitulainen
Tim Chase writes: > A number of tools use a custom quote-string: > > Bash: > > cat < "single and double" with \ and / > EOT [snip] > PS: yes, bash's does interpolate strings, so you still need to do > escaping within, but the arbitrary-user-specified-delimiter idea still > holds. If you

Re: Bigotry and hate speech on the python mailing list

2017-04-18 Thread Jussi Piitulainen
Joel Goldstick writes: > On Tue, Apr 18, 2017 at 5:30 AM, James McMahon wrote: >> Can the moderators please get involved here and remind people to >> address python related topics and questions on the python mailing >> list? While I can only speak to my interest when joining this list, >> isn't

Re: Looping [was Re: Python and the need for speed]

2017-04-18 Thread Jussi Piitulainen
Christian Gollwitzer writes: > Am 18.04.17 um 08:21 schrieb Chris Angelico: >> On Tue, Apr 18, 2017 at 4:06 PM, Christian Gollwitzer >> wrote: >>> Am 18.04.17 um 02:18 schrieb Ben Bacarisse: >>> Thanks (and to Grant). IO seems to be the canonical example. Where some

Re: Python and the need for speed

2017-04-12 Thread Jussi Piitulainen
bart4...@gmail.com writes: > On Wednesday, 12 April 2017 16:50:01 UTC+1, Jussi Piitulainen wrote: >> bart4...@gmail.com writes: >> >> > On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: >> >> bartc writes: >> >> >> >

Re: Python and the need for speed

2017-04-12 Thread Jussi Piitulainen
bart4...@gmail.com writes: > On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote: >> bartc writes: >> > >> > These are straightforward language enhancements. >> >> FYI, the question is not how to optimize the code but how to prevent >

Re: Python and the need for speed

2017-04-12 Thread Jussi Piitulainen
bart4...@gmail.com writes: > On Wednesday, 12 April 2017 10:57:10 UTC+1, bart...@gmail.com wrote: >> On Wednesday, 12 April 2017 07:48:57 UTC+1, Steven D'Aprano wrote: > >> > for i in range(10): >> > answer += 1 > >> > So... how exactly does the compiler prohibit stupid code? > >>

Re: Temporary variables in list comprehensions

2017-04-07 Thread Jussi Piitulainen
Roel Schroeven writes: > Lele Gaifax schreef op 6/04/2017 20:07: >> Piet van Oostrum writes: >> >>> It is a poor man's 'let'. It would be nice if python had a real 'let' >>> construction. Or for example: >>> >>> [(tmp, tmp + 1) for x in data with tmp =

Re: Quick questions about globals and database connections

2017-04-06 Thread Jussi Piitulainen
DFS writes: > On 4/6/2017 10:54 AM, Python wrote: >> Le 06/04/2017 à 16:46, DFS a écrit : >>> On 4/5/2017 10:52 PM, Dan Sommers wrote: On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: > I have a simple hard-coded check in place before even trying to > connect:

Re: Quick questions about globals and database connections

2017-04-06 Thread Jussi Piitulainen
DFS writes: > On 4/5/2017 10:52 PM, Dan Sommers wrote: >> On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: >> >>> I have a simple hard-coded check in place before even trying to connect: >>> >>> if dbtype not in ('sqlite postgres'): >>>print "db type must be sqlite or postgres" >>>exit() >>

Re: Temporary variables in list comprehensions

2017-04-06 Thread Jussi Piitulainen
Vincent Vande Vyvre writes: > Le 06/04/17 à 14:25, Piet van Oostrum a écrit : >> Steven D'Aprano writes: >> >>> Suppose you have an expensive calculation that gets used two or more >>> times in a loop. The obvious way to avoid calculating it twice in an >>>

Re: Appending data to a json file

2017-04-04 Thread Jussi Piitulainen
Michael Torrie writes: > On 04/03/2017 11:31 PM, dieter wrote: >> Dave writes: >> >>> I created a python program that gets data from a user, stores the data >>> as a dictionary in a list of dictionaries. When the program quits, it >>> saves the data file. My desire is to

Re: Python under PowerShell adds characters

2017-03-29 Thread Jussi Piitulainen
lyngw...@gmail.com writes: > I wrote a Python script, which executed as intended on Linux and from > cmd.exe on Windows. Then, I ran it from the PowerShell command line, > all print statements added ^@ after every character. > > Have you seen this? Do you know how to prevent this? Script is

Re: Escaping confusion with Python 3 + MySQL

2017-03-27 Thread Jussi Piitulainen
Gregory Ewing writes: > Νίκος Βέργος wrote: > >> Its still a mystery to em whay this fails syntactically when at the >> same time INSERT works like that. > > I don't think *anyone* understands why SQL was designed with > INSERT and UPDATE having completely different syntaxes. > But it was, and we

Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Jussi Piitulainen
Νίκος Βέργος writes: > print('''UPDATE visitors SET (pagesID, host, ref, location, useros, > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE > "%s"''', (pID, domain, ref, location, useros, browser, lastvisit, > domain) ) > > prints out: > > UPDATE visitors SET (pagesID, host,

Re: Who are the "spacists"?

2017-03-21 Thread Jussi Piitulainen
Grant Edwards writes: > Well written code _is_ ASCII-art. :) -- https://mail.python.org/mailman/listinfo/python-list

Re: The ternaery operator

2017-03-16 Thread Jussi Piitulainen
William Mayor writes: >> I think it would be nice to have a way of getting the 'true' value as >> the return with an optional value if false. The desire comes about >> when the thing I'm comparing is an element of a collection: >> >>drugs['choice'] if drugs['choice'] else 'pot' >> >>

Re: Regular expression query

2017-03-12 Thread Jussi Piitulainen
rahulra...@gmail.com writes: > Hi All, > > I have a string which looks like > > a,b,c "4873898374", d, ee "3343,23,23,5,,5,45", f > "5546,3434,345,34,34,5,34,543,7" > > It is comma saperated string, but some of the fields have a double > quoted string as part of it (and

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

2017-03-08 Thread Jussi Piitulainen
Chris Green writes: > 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:- > > # > # > # Address Book field details, dictionary key is the database column > # >

Re: Better way to do this dict comprehesion

2017-03-08 Thread Jussi Piitulainen
Sayth Renshaw writes: >> To find an unpaired number in linear time with minimal space, try >> stepping through the list and either adding to a set or removing from >> it. At the end, your set should contain exactly one element. I'll let >> you write the actual code :) >> >> ChrisA > > ChrisA the

Re: Better way to do this dict comprehesion

2017-03-08 Thread Jussi Piitulainen
Sayth Renshaw writes: > Peter I really like this > > The complete code: > from collections import Counter def find_it(seq): > ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] > ... return result You confirmed to Chris that you want the item that occurs an

Re: str.title() fails with words containing apostrophes

2017-03-06 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Steve D'Aprano wrote: >> I came across this book title: >> >> Täällä Pohjantähden alla (‘Here beneath the North Star’) >> >> http://www.booksfromfinland.fi/1980/12/the-strike/ >> >> which is partly title case, but I'm not sure what rule is being >> applied there. My

Re: str.title() fails with words containing apostrophes

2017-03-06 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Tue, 7 Mar 2017 03:28 am, Grant Edwards wrote: >> >> Besides locale-aware, it'll need to be style-guide-aware so that it >> knows whether you want MLA, Chicago, Strunk & White, NYT, Gregg, >> Mrs. Johnson from 9th grade English class, or any of a dozen or two >>

Re: str.title() fails with words containing apostrophes

2017-03-06 Thread Jussi Piitulainen
gvm...@gmail.com writes: > On Monday, March 6, 2017 at 2:37:11 PM UTC+5:30, Jussi Piitulainen wrote: >> gvm...@gmail.com writes: >> >> > On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: >> >> I'm trying to convert strings to

Re: str.title() fails with words containing apostrophes

2017-03-06 Thread Jussi Piitulainen
gvm...@gmail.com writes: > On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: >> I'm trying to convert strings to Title Case, but getting ugly results >> if the words contain an apostrophe: >> >> >> py> 'hello world'.title() # okay >> 'Hello World' >> py> "i can't be

Re: list of the lists - append after search

2017-03-02 Thread Jussi Piitulainen
Andrew Zyman writes: > On Thursday, March 2, 2017 at 2:57:02 PM UTC-5, Jussi Piitulainen wrote: >> Peter Otten <__pete...@web.de> writes: >> >> > Andrew Zyman wrote: >> > >> >> On Thursday, March 2, 2017 at 11:27:34 AM

Re: list of the lists - append after search

2017-03-02 Thread Jussi Piitulainen
Peter Otten <__pete...@web.de> writes: > Andrew Zyman wrote: > >> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: >>> Andrew Zyman wrote: >>> . >>> . >>> > End result: >>> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] >>> >>> >>> outer = [["a", 1], ["b",

Re: Looking for documentation on how Python assigns to function parameters

2017-03-01 Thread Jussi Piitulainen
Steve D'Aprano writes: > Given a function like this: > > > def func(alpha, beta, gamma, delta=4, *args, **kw): > ... > > > which is called in some fashion: > > # say > func(1, 2, gamma=3, epsilon=5) > > which may or may not be valid: > > func(1, 2, alpha=0) > > how does Python match up the

Re: How to flatten only one sub list of list of lists

2017-02-28 Thread Jussi Piitulainen
Sayth Renshaw writes: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], > ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], >

Re: Usage of ast.

2017-02-27 Thread Jussi Piitulainen
Vincent Vande Vyvre writes: > I've this strange error: > > Python 3.4.3 (default, Nov 17 2016, 01:08:31) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. import ast l = "print('hello world')" ast.literal_eval(l) > Traceback (most

Re: CSV

2017-02-22 Thread Jussi Piitulainen
Braxton Alfred writes: > Why does this not run? It is right out of the CSV file in the Standard Lib. > > > > > Python ver 3.4.4, 64 bit. > > > > > > > > import csv > """ READ EXCEL FILE """ > filename = 'c:\users\user\my documents\Braxton\Excel\personal\bp.csv' '\b' is backspace. A

Re: str.format fails with JSON?

2017-02-21 Thread Jussi Piitulainen
carlopi...@gmail.com writes: > Hi, > > When I run this piece of code: > > 'From {"value": 1}, value={value}'.format(value=1) > > Python complains about the missing "value" parameter (2.7.12 and > 3.6.x): Perhaps you know this, but just to be sure, and for the benefit of any reader who doesn't:

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

2017-02-17 Thread Jussi Piitulainen
Makoto Kuwata writes: > On Thu, Feb 16, 2017 at 6:53 AM, Erik wrote: >> >> (Python code examples of what you think is "bad" vs "good" would be >> useful). > > You are right. > > Bad code Example: > > # >

Re: Extract sigle file from zip file based on file extension

2017-02-10 Thread Jussi Piitulainen
loial writes: > I need to be able to extract a single file from a .zip file in python. > > The zip file will contain many files. The file to extract will be the > only .csv file in the zip, but the full name of the csv file will not > be known. > > Can this be done in python? Find the one member

Re: Rename file without overwriting existing files

2017-02-09 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Mon, 30 Jan 2017 09:39 pm, Peter Otten wrote: > > def rename(source, dest): >> ... os.link(source, dest) >> ... os.unlink(source) >> ... > rename("foo", "baz") > os.listdir() >> ['bar', 'baz'] > rename("bar", "baz") >> Traceback (most recent

Re: best way to ensure './' is at beginning of sys.path?

2017-02-04 Thread Jussi Piitulainen
Wildman writes: > On Sat, 04 Feb 2017 11:27:01 +0200, Jussi Piitulainen wrote: > >> Wildman writes: >> >> [snip] >> >>> If anyone is interested the correct way is to add this to >>> /etc/profile (at the bottom): >>> >>> P

Re: best way to ensure './' is at beginning of sys.path?

2017-02-04 Thread Jussi Piitulainen
Wildman writes: [snip] > If anyone is interested the correct way is to add this to > /etc/profile (at the bottom): > > PATH=$PATH:./ > export PATH Out of interest, can you think of a corresponding way that a mere user can remove the dot from their $PATH after some presumably well-meaning system

Re: update a list element using an element in another list

2017-01-31 Thread Jussi Piitulainen
Daiyue Weng writes: > Hi, I am trying to update a list of dictionaries using another list of > dictionaries correspondingly. In that, for example, > > # the list of dicts that need to be updated > dicts_1 = [{'dict_1': '1'}, {'dict_2': '2'}, {'dict_3': '3'}] > > # dict used to update dicts_1 >

Re: Rename file without overwriting existing files

2017-01-30 Thread Jussi Piitulainen
Peter Otten writes: > Jussi Piitulainen wrote: > >> Peter Otten writes: >> >>> Steve D'Aprano wrote: > >>>> The wider context is that I'm taking from 1 to >>>> path names to existing files as arguments, and for each path name I >&g

Re: Rename file without overwriting existing files

2017-01-30 Thread Jussi Piitulainen
Peter Otten writes: > Steve D'Aprano wrote: > >> On Mon, 30 Jan 2017 03:33 pm, Cameron Simpson wrote: >> >>> On 30Jan2017 13:49, Steve D'Aprano wrote: This code contains a Time Of Check to Time Of Use bug: if os.path.exists(destination)

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, Jan 22, 2017 at 2:56 AM, Jussi Piitulainen wrote: >> Steve D'Aprano writes: >> >> [snip] >> >>> You could avoid that error by increasing the offset by the right >>> amount: >>> >>> stuff = text[offse

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Jussi Piitulainen
Steve D'Aprano writes: [snip] > You could avoid that error by increasing the offset by the right > amount: > > stuff = text[offset + len("ф".encode('utf-8'):] > > which is awful. I believe that's what Go and Julia expect you to do. Julia provides a method to get the next index. let text = "ἐπὶ

Re: PEP 393 vs UTF-8 Everywhere

2017-01-20 Thread Jussi Piitulainen
Chris Angelico writes: > On Sat, Jan 21, 2017 at 11:30 AM, Pete Forman wrote: >> I was asserting that most useful operations on strings start from >> index 0. The r* operations would not be slowed down that much as >> UTF-8 has the useful property that attempting to interpret from a >> byte that

Re: Enum with only a single member

2017-01-09 Thread Jussi Piitulainen
Steven D'Aprano writes: > Is it silly to create an enumeration with only a single member? That > is, a singleton enum? > > from enum import Enum > > class Unique(Enum): > FOO = auto() > > > The reason I ask is that I have two functions that take an enum > argument. The first takes one of

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Jussi Piitulainen
Paul Rubin writes: > I think Python's version of iterators is actually buggy and at least > the first element of the rest of the sequence should be preserved. > There are ways to fake it but they're too messy for something like > this. It should be the default and might have been a good change

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Jussi Piitulainen
Paul Rubin writes: > Jussi Piitulainen writes: >> That would return 0 even when there is no 0 in xs at all. > > Doesn't look that way to me: > > >>> minabs([5,3,1,2,4]) > 1 Sorry about that. I honestly meant to say it would return 1 even when there was a

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Pablo Lucena writes: > How about using the second usage of builtin iter()? > > In [92]: iter? > Docstring: > iter(iterable) -> iterator > iter(callable, sentinel) -> iterator Nice to learn about that. But it has the same problem as itertools.takewhile: > In [88]: numbers > Out[88]: [1, 9, 8,

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Paul Rubin writes: > Jussi Piitulainen writes: >>> Use itertools.takewhile >> How? It consumes the crucial stop element: > > Oh yucch, you're right, it takes it from both sides. How about this: > > from itertools import takewhile, islice > def minabs(xs

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Rustom Mody writes: > On a Saturday, Jussi Piitulainen wrote: [snip] >> You switched to a simpler operator. Would Haskell notice that >> >>def minabs(x, y): return min(x, y, key = abs) >> >> has a meaningful zero? Surely it has its limits somewhere

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Chris Angelico writes: > On Sat, Jan 7, 2017 at 7:12 PM, Jussi Piitulainen wrote: >> You switched to a simpler operator. Would Haskell notice that >> >>def minabs(x, y): return min(x, y, key = abs) >> >> has a meaningful zero? Surely it has its limits som

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Rustom Mody writes: > On Saturday, Jussi Piitulainen wrote: >> Paul Rubin writes: >> >> > Peter Otten writes: >> >> How would you implement stopmin()? >> > >> > Use itertools.takewhile >> >> How? It consumes the crucial stop elem

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Jussi Piitulainen
Paul Rubin writes: > Peter Otten writes: >> How would you implement stopmin()? > > Use itertools.takewhile How? It consumes the crucial stop element: it = iter('what?') list(takewhile(str.isalpha, it)) # ==> ['w', 'h', 'a', 't'] next(it, 42) # ==> 42 --

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Jussi Piitulainen
Peter Otten writes: > Example: you are looking for the minimum absolute value in a series of > integers. As soon as you encounter the first 0 it's unnecessary extra work > to check the remaining values, but the builtin min() will continue. > > The solution is a minimum function that allows the

Re: Cleaning up conditionals

2017-01-02 Thread Jussi Piitulainen
Deborah Swanson writes: > Jussi Piitulainen wrote: [snip] >> With your particular conditions of non-emptiness, which is taken to >> be truth, you can achieve variations of this result with any of the >> following statements: >> >> w = ( l1[v] if len(l1[v]) &g

Re: Cleaning up conditionals

2017-01-01 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Sun, 1 Jan 2017 02:58 pm, Deborah Swanson wrote: > >>> It's possible to select either l1 or l2 using an expression, >>> and then subscript that with [v]. However, this does not >>> usually make for readable code, so I don't recommend it. >>> >>> (l1 if whatever else

Re: Cleaning up conditionals

2016-12-31 Thread Jussi Piitulainen
Deborah Swanson writes: > Jussi Piitulainen wrote: >> Sent: Saturday, December 31, 2016 8:30 AM >> Deborah Swanson writes: >> >> > Is it possible to use some version of the "a = expression1 if >> > condition else expression2" syntax with

Re: Cleaning up conditionals

2016-12-31 Thread Jussi Piitulainen
Deborah Swanson writes: > Is it possible to use some version of the "a = expression1 if > condition else expression2" syntax with an elif? And for expression1 > and expression2 to be single statements? That's the kind of > shortcutting I'd like to do, and it seems like python might be able to >

Re: Cleaning up conditionals

2016-12-30 Thread Jussi Piitulainen
"Deborah Swanson" writes: > Michael Torrie wrote: >> On 12/30/2016 05:26 PM, Deborah Swanson wrote: >> > I'm still wondering if these 4 lines can be collapsed to one or two >> > lines. >> >> If the logic is clearly expressed in the if blocks that you >> have, I

Re: python list index - an easy question

2016-12-19 Thread Jussi Piitulainen
Ben Bacarisse writes: > BartC writes: > >> You need to take your C hat off, I think. > > It's a computing hat. Indexes are best seen as offsets (i.e. as a > measured distances from some origin or base). It's a model that grew > out of machine addressing and assembler address modes many, many >

Re: Simple code and suggestion

2016-11-30 Thread Jussi Piitulainen
g thakuri writes: > I would want to avoid using multiple split in the below code , what > options do we have before tokenising the line?, may be validate the > first line any other ideas > > cmd = 'utility %s' % (file) > out, err, exitcode = command_runner(cmd) > data =

Re: best way to read a huge ascii file.

2016-11-29 Thread Jussi Piitulainen
Heli writes: > Hi all, > > Let me update my question, I have an ascii file(7G) which has around > 100M lines. I read this file using : > > f=np.loadtxt(os.path.join(dir,myfile),delimiter=None,skiprows=0) > > x=f[:,1] > y=f[:,2] > z=f[:,3] > id=f[:,0] > > I will need the x,y,z and id arrays

Re: dictionary mutability, hashability, __eq__, __hash__

2016-11-27 Thread Jussi Piitulainen
Veek M writes: > Jussi Piitulainen wrote: > >> Veek M writes: >> >> [snip] >> >>> Also if one can do x.a = 10 or 20 or whatever, and the class instance >>> is mutable, then why do books keep stating that keys need to be >>> immu

Re: dictionary mutability, hashability, __eq__, __hash__

2016-11-27 Thread Jussi Piitulainen
Veek M writes: [snip] > Also if one can do x.a = 10 or 20 or whatever, and the class instance > is mutable, then why do books keep stating that keys need to be > immutable? After all, __hash__ is the guy doing all the work and > maintaining consistency for us. One could do: > > class Fruit: >

Re: Clean way to return error codes

2016-11-20 Thread Jussi Piitulainen
Steven D'Aprano writes: > I have a script that can be broken up into four subtasks. If any of > those subtasks fail, I wish to exit with a different exit code and > error. > > Assume that the script is going to be run by system administrators who > know no Python and are terrified of tracebacks,

Re: Why does this list swap fail?

2016-11-14 Thread Jussi Piitulainen
38016226...@gmail.com writes: > L=[2,1] > L[0],L[L[0]-1]=L[L[0]-1],L[0] > > The L doesn't change. Can someone provide me the detail procedure of > this expression? The right-hand side evaluates to (1,2), but then the assignments to the targets on the left-hand side are processed in order from

Re: how to print variable few time?

2016-11-13 Thread Jussi Piitulainen
andy writes: > Sat, 12 Nov 2016 04:58:20 -0800 wrote guy asor: > >> hello! >> >> this is my code: >> >> word=raw_input() >> print word*3 >> >> >> with this code im getting - wordwordword. >> what changes i need to make to get - word word word - instead? >> >> thanks > > using python3.x: > >

Re: Appending to a list, which is value of a dictionary

2016-10-15 Thread Jussi Piitulainen
Chris Angelico writes: > On Sat, Oct 15, 2016 at 11:35 PM, Uday J wrote: > bm=dict.fromkeys(l,['-1','-1']) > > When you call dict.fromkeys, it uses the same object as the key every > time. If you don't want that, try a dict comprehension instead: s/key/value/ --

Re: Appending to a list, which is value of a dictionary

2016-10-15 Thread Jussi Piitulainen
Uday J writes: > Hi, > > Here is the code, which I would like to understand. > l=['a','b','c'] bm=dict.fromkeys(l,['-1','-1']) u={'a':['Q','P']} bm.update(u) bm > {'a': ['Q', 'P'], 'c': ['-1', '-1'], 'b': ['-1', '-1']} for k in bm.keys(): > bm[k].append('DDD') >

Re: Python-based monads essay part 2

2016-10-13 Thread Jussi Piitulainen
Gregory Ewing writes: > A bit more on SMFs, and then some I/O. > > http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/DemystifyingMonads2.html Thanks. It would be good to spell out SMF at the start of the page. "The definition of / above" (__truediv__ method) was not given "above" (in

  1   2   3   4   5   6   7   >