Re: [OT] VCS tools (was "Development tools and practices for Pythonistas")

2011-04-27 Thread Tim Chase
On 04/27/2011 04:24 AM, Jean-Michel Pichavant wrote: Ben Finney wrote: Mercurial – are the ones to choose from. Anoyone recommending a VCS tool that has poor merging support (such as Subversion or, heaven help us, CVS) is doing the newcomer a disservice. True enough. But the modern crop of fir

Re: [OT] Comparing VCS tools

2011-04-27 Thread Tim Chase
On 04/26/2011 09:45 PM, Ben Finney wrote: Tim Chase writes: Bazaar (bzr) Cons: - was slow, though I understand they've worked on improving this Right, that's not a count against Bazaar for at least the last several versions (since 2009 at least). Bazaar is easily fast

Re: [OT] VCS tools

2011-04-28 Thread Tim Chase
On 04/28/2011 04:50 PM, Ben Finney wrote: This has been a pretty informative thread so far. Please keep it coming. I am a hardware development guy and do very little software development. I have been vaguely aware of tools for version control but inspired by this thread I have started looking at

Re: [OT] From svn to something else?

2011-04-29 Thread Tim Chase
On 04/29/2011 05:07 AM, Hans Georg Schaathun wrote: How easy and reliable is it to import my svn version history into one of the three big DVCS-s mentioned here? I'd say that one of the things SVN has going for it is that it's the lingua-franca of VCSes, so just about everything (especially t

Re: [OT] From svn to something else?

2011-04-29 Thread Tim Chase
On 04/29/2011 12:01 PM, Hans Georg Schaathun wrote: wrote: : I'd say that one of the things SVN has going for it is that it's : the lingua-franca of VCSes, so just about everything (especially : the 3 big names mentioned in this thread: hg, bzr, git) can talk : to svn pretty uneventfully

Re: [OT] VCS for non-text (was Development tools and practices for Pythonistas)

2011-04-30 Thread Tim Chase
On 04/30/2011 04:15 AM, Martin Schöön wrote: You guys are very code focused, which is natural given where we are. Having absorbed what I have seen here, looked a little at Mercurial, read a little on the webs of Fossil and Bazaar I start to think there is great merit in all this VCS stuff for ot

Re: obviscating python code for distribution

2011-05-16 Thread Tim Chase
On 05/15/2011 10:29 PM, Ben Finney wrote: What is it you think you would gain by obfuscating the code, and why is that worthwhile? What evidence do you have that code obfuscation would achieve that? Based on past experience at several employers', the preeminent reason for obfuscating is to mak

Sanitizing filename strings across platforms

2011-05-31 Thread Tim Chase
Scenario: a file-name from potentially untrusted sources may have odd filenames that need to be sanitized for the underlying OS. On *nix, this generally just means "don't use '/' or \x00 in your string", while on Win32, there are a host of verboten characters and file-names. Then there's also

Re: Case-insensitive string equality

2017-09-04 Thread Tim Chase
On 2017-09-02 12:21, Steve D'Aprano wrote: > On Fri, 1 Sep 2017 01:29 am, Tim Chase wrote: > > I'd want to have an optional parameter to take locale into > > consideration. E.g. > > Does regular case-sensitive equality take the locale into > consideration

Standard for dict-contants with duplicate keys?

2017-09-15 Thread Tim Chase
Looking through docs, I was unable to tease out whether there's a prescribed behavior for the results of defining a dictionary with the same keys multiple times d = { "a": 0, "a": 1, "a": 2, } In my limited testing, it appears to always take the last one, resulting in {"

Re: Standard for dict-contants with duplicate keys?

2017-09-15 Thread Tim Chase
On 2017-09-15 17:45, Terry Reedy wrote: > On 9/15/2017 3:36 PM, Tim Chase wrote: > >d = { > > "a": 0, > > "a": 1, > > "a": 2, > >} > > > > In my limited testing, it appears to always take the

Re: Old Man Yells At Cloud

2017-09-17 Thread Tim Chase
On 2017-09-18 00:42, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: > Presumably you've never wanted to print to something other than > std.out. The syntax in Python 2 is horrid: > > print >>sys.stderr, args For those cases, the old syntax was sufficiently horrid that ind

Re: Old Man Yells At Cloud

2017-09-17 Thread Tim Chase
On 2017-09-17 14:16, bartc wrote: > print() is used for its side-effects; what relevant value does it > return? depending on the sink, errors can be returned (at least for the printf(3) C function). The biggest one I've encountered is writing to a full disk. The return value is how many characte

Re: Old Man Yells At Cloud

2017-09-17 Thread Tim Chase
On 2017-09-17 16:15, Rick Johnson wrote: > > I've wanted to do all those things, and more. I love the > > new print function. For the cost of one extra character, > > the closing bracket, > > Oops, _two_ characters! What about the opening "bracket"? >>> print(len('print "hello"')) 13 >>>

Re: Old Man Yells At Cloud

2017-09-17 Thread Tim Chase
On 2017-09-18 01:41, INADA Naoki wrote: > > > That said, I'm neither here nor there when it comes to > > > using print-as-a-statement vs print-as-a-function. I like > > > the consistency it brings to the language, but miss the > > > simplicity that Py2 had for new users. I'd almost want to > > >

Re: Change project licence?

2017-09-23 Thread Tim Chase
On 2017-09-23 19:14, Chris Angelico wrote: > On Sat, Sep 23, 2017 at 7:07 PM, Kryptxy > wrote: > > Thank you all! I opened a ticket about the same (on github). > > I got response from most of them, and all are agreeing to the > > change. However, one contributor did not respond at all. I tried > >

Re: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code]

2017-09-25 Thread Tim Chase
On 2017-09-26 02:29, Steve D'Aprano wrote: > x = Parrot(name="Polly") > > (using Python syntax for simplicity) and somebody tries to tell me > that the value of x is anything but a Parrot instance named "Polly", So this is a Polly-morphic constructor? -tkc -- https://mail.python.org/mailman/l

Re: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code]

2017-09-26 Thread Tim Chase
On 2017-09-26 18:25, alister via Python-list wrote: >>> We've been asked nicely by the list mod to stop :) >> >> Perhaps we could agree on a subject line tag to be used in all >> threas arguing about what to call the Python argument passing >> scheme? That way the other 99% of us could pre-empt

Re: choice of web-framework

2017-10-22 Thread Tim Chase
On 2017-10-22 12:24, Patrick Vrijlandt wrote: > I would like your recommendation on the choice of a web framework. Might depend on what skills you already bring to the table. If you already know an ORM like SQLAlchemy or a template language like Jinja, you might want to take the "bring the pieces

Re: choice of web-framework

2017-10-22 Thread Tim Chase
On 2017-10-22 15:26, Patrick Vrijlandt wrote: > The version control I was referring to, is indeed users' data. I > plan to use Mercurial for the source code. The questionnaires being > developed will go through many revisions. The questionnaires being > filled in, are enough work to have a provisio

Re: What use is of this 'cast=float ,'?

2017-10-27 Thread Tim Chase
[rearranging for easier responding] On 2017-10-27 13:35, Robert wrote: > self.freqslider=forms.slider( > parent=self.GetWin( ), > sizer=freqsizer, > value=self.freq, > callback= self.setfreq, > minimum=−samprate/2, > maximum=samprate/2, > num_steps=100, > st

__contains__ classmethod?

2017-12-18 Thread Tim Chase
Playing around, I had this (happens to be Py2, but gets the same result in Py3) code class X(object): ONE = "one" TWO = "two" _ALL = frozenset(v for k,v in locals().items() if k.isupper()) @classmethod def __contains__(cls, v): return v in cls._ALL print(dir(X)) print(X._ALL) Runnin

Re: Goto

2017-12-28 Thread Tim Chase
On 2017-12-29 08:42, Ben Finney wrote: > Duram writes: > > > How to use goto in python? > > Step 0: what is goto in Python? > > Step 1: that's not something that exists in Python. So why are you > asking how to use something that doesn't exist? so quick to shoot down a poor soul. http://ent

virtualenvwrapper under OpenBSD's ksh

2018-02-02 Thread Tim Chase
Under a new user account with ksh (the default) as the shell I issued the following: $ pip3 install --user virtualenvwrapper Successfully installed pbr-3.1.1 six-1.11.0 stevedore-1.28.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.8.2 $ export WORKON_HOME=~/code/virtualenvs $ mkdir -p $WORK

Re: virtualenvwrapper under OpenBSD's ksh & FreeBSD's /bin/sh

2018-02-08 Thread Tim Chase
at least support ksh. Thanks, -tkc On 2018-02-02 13:10, Tim Chase wrote: > Under a new user account with ksh (the default) as the shell I > issued the following: > > $ pip3 install --user virtualenvwrapper > Successfully installed pbr-3.1.1 six-1.11.0 stevedore-1.28.0 > vi

Fw: [issue22167] iglob() has misleading documentation (does indeed store names internally)

2018-02-17 Thread Tim Chase
Has anybody else been getting unexpected/unsolicited emails from the Python bug-tracker? I'm not associated with (didn't submit/lurk/follow/sign-up-for) this bug or its notifications but somehow I'm getting messages on this particular issue. I've now received two notifications (both on this same

Re: Is there are good DRY fix for this painful design pattern?

2018-02-27 Thread Tim Chase
Something like the following might do the trick. As an added benefit, it's easy to set all the defaults automatically in __init__ as well without hand-adding "self.dopey = dopey". On the down side, in the non-__init__ functions, you have to use kwargs["dopey"] and the like. It also involves tackin

Re: csv module and NULL data byte

2018-02-28 Thread Tim Chase
While inelegant, I've "solved" this with a wrapper/generator f = file(fname, …) g = (line.replace('\0', '') for line in f) reader = csv.reader(g, …) for row in reader: process(row) My actual use at $DAYJOB cleans out a few other things too, particularly non-breaking spaces coming from

Re: csv module and NULL data byte

2018-02-28 Thread Tim Chase
On 2018-02-28 21:38, Dennis Lee Bieber wrote: > >     with open( fname, 'rt', encoding='iso-8859-1' ) as csvfile: > > Pardon? Has the CSV module changed in the last year or so? > > Last time I read the documentation, it was recommended that > the file be opened in BINARY mode ("rb")

Re: csv module and NULL data byte

2018-03-01 Thread Tim Chase
On 2018-03-01 23:57, John Pote wrote: > On 01/03/2018 01:35, Tim Chase wrote: > > While inelegant, I've "solved" this with a wrapper/generator > > > >f = file(fname, …) > >g = (line.replace('\0', '') for line in f) > I won

Accuracy of multiprocessing.Queue.qsize before any Queue.get invocations?

2022-05-12 Thread Tim Chase
The documentation says[1] > Return the approximate size of the queue. Because of > multithreading/multiprocessing semantics, this number is not > reliable. Are there any circumstances under which it *is* reliable? Most germane, if I've added a bunch of items to the Queue, but not yet launched an

Re: count consecutive elements

2021-01-13 Thread Tim Chase
On 2021-01-13 21:20, Bischoop wrote: > I want to to display a number or an alphabet which appears mostly > consecutive in a given string or numbers or both > Examples > s= ' aabskaaabad' > output: c > # c appears 4 consecutive times > 8bbakebaoa > output: b > #b appears 2 consecutive times I

Re: count consecutive elements

2021-01-13 Thread Tim Chase
On 2021-01-13 18:20, Dan Stromberg wrote: > I'm kind of partial to: > > import collections > import typing > > > def get_longest(string: str) -> typing.Tuple[int, str]: > """Get the longest run of a single consecutive character.""" > dict_: typing.DefaultDict[str, int] = > collections.de

Re: count consecutive elements

2021-01-15 Thread Tim Chase
On 2021-01-16 03:32, Bischoop wrote: >> The OP didn't specify what should happen in that case, so it would >> need some clarification. > > In that case maybe good solution would be to return three of them? That's the solution I chose in my initial reply, you get a tuple back of ([list of longest

Re: name for a mutually inclusive relationship

2021-02-24 Thread Tim Chase
On 2021-02-24 08:12, Ethan Furman wrote: > I'm looking for a name for a group of options that, when one is > specified, all of them must be specified. [snip] > - ???: a group of options where, if one is specified, all must be > specified (mutually inclusive) [snip] > Is there a name out there alrea

Re: string storage [was: Re: imaplib: is this really so unwieldy?]

2021-05-26 Thread Tim Chase
On 2021-05-26 08:18, Alan Gauld via Python-list wrote: > Does that mean that if I give Python a UTF8 string that is mostly > single byte characters but contains one 4-byte character that > Python will store the string as all 4-byte characters? As best I understand it, yes: the cost of each "chara

Re: string storage [was: Re: imaplib: is this really so unwieldy?]

2021-05-26 Thread Tim Chase
On 2021-05-26 18:43, Alan Gauld via Python-list wrote: > On 26/05/2021 14:09, Tim Chase wrote: >>> If so, doesn't that introduce a pretty big storage overhead for >>> large strings? >> >> Yes. Though such large strings tend to be more rare, largely >

Re: Create a contact book

2021-10-26 Thread Tim Chase
On 2021-10-25 22:40, anders Limpan wrote: > i would like to create a contact book were you can keep track of > your friends. With this contact book you will both be able to add > friends and view which friends that you have added. anyone > interested in helping me out with this one ?=) -- Python p

Re: Timezone jokes (was: All permutations from 2 lists)

2022-03-03 Thread Tim Chase
On 2022-03-03 06:27, Grant Edwards wrote: > On 2022-03-03, Chris Angelico wrote: > > Awww, I was going to make a really bad joke about timezones :) > > As opposed to all the really good jokes about timezones... ;) And here I thought you were just Trolling with timezones... https://en.wikipedi

Re: Behavior of the for-else construct

2022-03-03 Thread Tim Chase
On 2022-03-04 02:02, Chris Angelico wrote: >> I want to make a little survey here. >> >> Do you find the for-else construct useful? Have you used it in >> practice? Do you even know how it works, or that there is such a >> thing in Python? > > Yes, yes, and yes-yes. It's extremely useful. Just

Re: Behavior of the for-else construct

2022-03-04 Thread Tim Chase
On 2022-03-04 11:55, Chris Angelico wrote: > In MS-DOS, it was perfectly possible to have spaces in file names DOS didn't allow space (0x20) in filenames unless you hacked it by hex-editing your filesystem (which I may have done a couple times). However it did allow you to use 0xFF in filenames wh

Re: Add a method to list the current named logging levels

2022-03-30 Thread Tim Chase
On 2022-03-30 16:37, Barry wrote: > Is logging.getLevelNamesMapping() what you are looking for? Is this in some version newer than the 3.8 that comes stock on my machine? $ python3 -q >>> import logging >>> logging.getLevelNamesMapping() Traceback (most recent call last): File "", lin

Re: Anyone here running Python on a PowerPC?

2016-08-14 Thread Tim Chase
On 2016-08-14 12:28, Steven D'Aprano wrote: > Is there anyone here running Python on a PowerPC willing to help me > diagnose and fix this issue? > > http://bugs.python.org/issue27761 Not so savvy in the building, but I've got a Mac PPC (still on 10.4 or whatever the last-ish PPC build of OS X was

Re: How do I tell if I'm running on a PowerPC?

2016-08-19 Thread Tim Chase
On 2016-08-14 13:54, Steven D'Aprano wrote: > I need to be able to programmatically test whether I'm running on a > PowerPC. How can I do that? > > import platform > if platform.machine() in ('ppc', 'ppc64'): > print('running PowerPC') > > > Is that right? Running OpenBSD on a PPC iBook G4:

Re: The Joys Of Data-Driven Programming

2016-08-21 Thread Tim Chase
On 2016-08-21 04:53, Rustom Mody wrote: > 2. Basic computing theory shows that re-s and dfas are equivalent. > Which would one prefer to write/debug? [Thats not a rhetorical > question] I'm curious where REs and DFAs are shown to be equivalent (serious, not trying to be snarky). I can see with no

Re: The dangerous, exquisite art of safely handing user-uploaded files: Tom Eastman (was: Does This Scare You?)

2016-08-22 Thread Tim Chase
On 2016-08-23 00:21, Ben Finney wrote: > So yes, filenames from arbitrary sources should be *completely* > untrusted, and never used to access any file on the system. Throw > the entire filename away and make a filename locally, without using > any part of the original name. Sadly, this ideal advi

Re: The dangerous, exquisite art of safely handing user-uploaded files: Tom Eastman (was: Does This Scare You?)

2016-08-22 Thread Tim Chase
On 2016-08-23 02:20, Chris Angelico wrote: > It generally will (or rather, only if the file has one of a > particular set of extensions). Automatic thumbnailing is usually > done only for certain file names. I don't know of anything that > opens every single file to see if it has a JFIF signature (

Re: Does This Scare You?

2016-08-22 Thread Tim Chase
On 2016-08-22 22:39, Chris Angelico wrote: > Nope. On Windows, you would try/except it. There are myriad other > ways something could fail, and the only correct action is to > attempt it. Most of the reserved names will simply give an error; The problem is that when opening such a pseudo-file, you

Re: What is the correct form for saying "licensed under the same terms as Python itself"?

2016-09-14 Thread Tim Chase
On 2016-09-14 11:57, Brendan Abel wrote: > Also, according to the python web site, they only accept > contributions under the following licenses: > >- Academic Free License v. 2.1 > >- Apache License, Version 2.0 >

Re: Obtain the raw line of text read by CSVDictReader when reporting errors?

2016-09-23 Thread Tim Chase
On 2016-09-23 16:58, Lawrence D’Oliveiro wrote: > Duck type is great for sticking pieces of Python code together. > > And anybody who doesn’t like it can go Java themselves... Sorry, my source code doesn't declare that I support JavaInterface... -tkc -- https://mail.python.org/mailman/lis

Case insensitive replacement?

2016-09-27 Thread Tim Chase
I'd like to do a case-insensitive replacement in a string but want to do it pythonically. Ideally, the code would something like needle = "World" haystack = "Hello, world!" replacement = "THERE" result = haystack.replace(needle, replacement, ignore_case=True) # result would be "Hello, T

Re: Case insensitive replacement?

2016-09-28 Thread Tim Chase
On 2016-09-27 18:10, MRAB wrote: > The disadvantage of your "string-hacking" is that you're assuming > that the uppercase version of a string is the same length as the > original: Ah, good point. I went with using the regexp version for now since I needed to move forward with something, so I'm gl

Syncing up iterators with gaps

2016-09-28 Thread Tim Chase
I've got several iterators sharing a common key in the same order and would like to iterate over them in parallel, operating on all items with the same key. I've simplified the data a bit here, but it would be something like data1 = [ # key, data1 (1, "one A"), (1, "one B"), (2, "tw

Re: Syncing up iterators with gaps

2016-09-28 Thread Tim Chase
On 2016-09-29 10:20, Steve D'Aprano wrote: > On Thu, 29 Sep 2016 05:10 am, Tim Chase wrote: > > data1 = [ # key, data1 > > (1, "one A"), > > (1, "one B"), > > (2, "two"), > > (5, "five"), > >

Reversing \N{...} notation?

2016-10-25 Thread Tim Chase
I like the clarity of using the "\N{...}" notation when creating string literals involving Unicode chars. Is there a built-in way to get such strings back from Python? >>> s = 'ma\N{LATIN SMALL LETTER N WITH TILDE}ana' >>> s 'mañana' >>> magic(s) 'ma\\N{LATIN SMALL LETTER N WITH TILDE}ana'

Re: Reversing \N{...} notation?

2016-10-26 Thread Tim Chase
On 2016-10-25 20:14, Peter Otten wrote: > Tim Chase wrote: > > I like the clarity of using the "\N{...}" notation when creating > > string literals involving Unicode chars. > > > > Is there a built-in way to get such strings back from Python? > >

Re: update certain key-value pairs of a dict from another dict

2016-11-11 Thread Tim Chase
On 2016-11-11 11:17, Daiyue Weng wrote: > dict1 = {'A': 'a', 'B': 'b', 'C': 'c'} > dict2 = {'A': 'aa', 'B': 'bb', 'C': 'cc'} > > I am wondering how to update dict1 using dict2 that > > only keys 'A' and 'B' of dict1 are udpated. It will result in > > dict1 = {'A': 'aa', 'B': 'bb', 'C': 'c'} Use

Re: update certain key-value pairs of a dict from another dict

2016-11-11 Thread Tim Chase
On 2016-11-11 13:29, Peter Otten wrote: > The same using update(), with a generator expression that avoids > the intermediate dict: > > >>> dict1 = {'A': 'a', 'B': 'b', 'C': 'c'} > >>> dict1.update((k, dict2[k]) for k in desired & dict1.keys() & > dict2.keys()) Huh. Handy to file that new knowl

Re: Is this pythonic?

2016-11-23 Thread Tim Chase
On 2016-11-23 22:15, Steve D'Aprano wrote: > On Wed, 23 Nov 2016 08:10 pm, Frank Millman wrote: > > The class has a getval() method to return the current value. > > > > Usually the value is stored in the instance, and can be returned > > immediately, but sometimes it has to be computed, incurring

Re: Can I print 2 calendars side by side?

2016-11-23 Thread Tim Chase
On 2016-11-23 10:02, Dayton Jones wrote: > I'd like to be able to display 2 calendars side by side, instead of > stacked... is this possible? > > for instance: > > print(calendar.month(year_a,month)) > print() > print(calendar.month(year_b,month)) > > prints: > June 1971 > Mo Tu

Re: The Case Against Python 3

2016-11-26 Thread Tim Chase
On 2016-11-26 01:01, Ian Kelly wrote: > When I read that Python 3.6 would include f-strings, I turned to the > coworker sitting next to me and said, "Oh my god, Python is adding > yet another new syntax for string formatting." It's getting to be a > joke. Pretty soon Python will have one string-fo

Re: Merge Two List of Dict

2016-12-01 Thread Tim Chase
On 2016-12-01 12:44, Nikhil Verma wrote: > A = [{'person_id': '1', 'adop_count': '2'}, {'person_id': '3', > 'adop_count': '4'}] > *len(A) might be above 10L* > > B = [{'person_id': '1', 'village_id': '3'}, {'person_id': '3', > 'village_id': '4'}] > *len(B) might be above 20L* > > > OutPut List s

Re: Can json.dumps create multiple lines

2016-12-01 Thread Tim Chase
On 2016-12-01 17:30, Cecil Westerhof wrote: > When I have a value dummy which contains: > ['An array', 'with several strings', 'as a demo'] > Then json.dumps(dummy) would generate: > '["An array", "with several strings", "as a demo"]' > I would prefer when it would generate: > '[ >

Re: Detect Linux Runlevel

2016-12-05 Thread Tim Chase
On 2016-12-05 14:58, Wildman via Python-list wrote: > I there a way to detect what the Linux runlevel is from > within a Python program? I would like to be able to do > it without the use of an external program such as 'who' > or 'runlevel'. You can use something like https://gist.github.com/lik

Re: Detect Linux Runlevel

2016-12-05 Thread Tim Chase
On 2016-12-05 18:26, Wildman via Python-list wrote: > On Mon, 05 Dec 2016 16:08:57 -0600, Tim Chase wrote: > > > On 2016-12-05 14:58, Wildman via Python-list wrote: > >> I there a way to detect what the Linux runlevel is from > >> within a Python program? I would

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-05 23:00, Wildman via Python-list wrote: > On Mon, 05 Dec 2016 21:42:52 -0600, Tim Chase wrote: > > This works based on my poking at it in both Py2 and Py3: > > That works perfectly. I owe you a big thanks. That was a > lot of work and time on your part. I really

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-06 01:14, Bernd Nawothnig wrote: > > I am a hobby programmer and I've been trying to learn python > > for a few months now. The program is 'worthlessware' but it > > is a 'learning experience' for me. > > It looks for me like a worthless learning experience. Eh, one person's "wort

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-06 12:10, Wildman via Python-list wrote: > If I had tried this in the beginning, it would have > save you a lot of work. > > Since both versions of the code works, which one do > you recommend? Or does it matter? Heh, I'm not sure it matters much. The code I provided should be expand

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-07 00:29, Marko Rauhamaa wrote: > Tim Chase : > > > This works based on my poking at it in both Py2 and Py3: > > Great info, Tim. > > A word a warning: your code doesn't lock /var/run/utmp before > access, which is a race condition. The file may be upd

Re: Detect Linux Runlevel

2016-12-06 Thread Tim Chase
On 2016-12-06 21:27, Wildman via Python-list wrote: > On Tue, 06 Dec 2016 13:06:35 -0600, Tim Chase wrote: > I forgot to mention that I want to include your name in the > final script as a contributor, if that is ok. No issues here. > You will get a cut of the royalties. Lets see,

Re: Detect Linux Runlevel

2016-12-08 Thread Tim Chase
On 2016-12-07 07:30, Marko Rauhamaa wrote: > Tim Chase : > > On 2016-12-07 00:29, Marko Rauhamaa wrote: > >> A word a warning: your code doesn't lock /var/run/utmp before > >> access, which is a race condition. The file may be updated at any > >> time, an

Re: Cleaning up conditionals

2016-12-31 Thread Tim Chase
On 2016-12-30 19:59, Deborah Swanson wrote: > Similar, actually the same as Cameron suggested. I really need to > revisit testing for empty. I probably rejected it early on for some > bad reason (you don't understand everything that goes wrong when > you're learning). If your data is anything like

Re: Clickable hyperlinks

2017-01-03 Thread Tim Chase
On 2017-01-03 11:46, Deborah Swanson wrote: > Excel has a formula: > > =HYPERLINK(url,description) > > that will put a clickable link into a cell. > > Does python have an equivalent function? Probably the most common > use for it would be output to the console, similar to a print > statement, bu

Re: Clickable hyperlinks

2017-01-05 Thread Tim Chase
On 2017-01-03 11:46, Deborah Swanson wrote: > Excel has a formula: > > =HYPERLINK(url,description) > > that will put a clickable link into a cell. > > Does python have an equivalent function? Probably the most common > use for it would be output to the console, similar to a print > statement, but c

Re: The hardest problem in computer science...

2017-01-06 Thread Tim Chase
On 2017-01-06 13:44, Dan Sommers wrote: > On Sat, 07 Jan 2017 00:03:37 +1100, Steve D'Aprano wrote: > > what do we call the vertical and horizontal line elements? I want > > to make them configurable, which means the user has to be able to > > pass an argument that specifies them ... > > pstree(1)

Re: Temporary variables in list comprehensions

2017-01-09 Thread Tim Chase
On 2017-01-09 02:46, Paul Rubin wrote: > > gen = (expensive_calculation(x) for x in data) > > result = [(tmp, tmp + 1) for tmp in gen] > > result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)] As charmingly expressive as map() is, the wildly different behavior in py3 (it's a gener

Re: Clickable hyperlinks

2017-01-09 Thread Tim Chase
On 2017-01-09 05:00, Deborah Swanson wrote: > Code does in fact have the power to control what happens > in the console. How do you think Linux does it on their terminals > with clickable links? Granted, the code may have to specify > parameters for a particular console, but I certainly wasn't aski

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

2017-01-09 Thread Tim Chase
On 2017-01-08 22:58, Deborah Swanson wrote: > 1) I have a section that loops through the sorted data, compares two > adjacent rows at a time, and marks one of them for deletion if the > rows are identical. > > I'm using > > for i in range(len(records)-1): > r1 = records[i] > r2 = records

Re: Temporary variables in list comprehensions

2017-01-09 Thread Tim Chase
On 2017-01-09 04:59, Rustom Mody wrote: > What happens when the expensive is on an inner generator? > Something like: > > [expensive₂(y) for x in data for y in foo(x)] > > [The ₂ representing the 2 or more occurrences in Steven's eg] Well, if I understand your question correctly, the goal would

Re: Temporary variables in list comprehensions

2017-01-09 Thread Tim Chase
On 2017-01-09 13:16, Paul Rubin wrote: > Tim Chase writes: > >> result = [(tmp, tmp+1) for tmp in map(expensive_calculation, > >> data)] > > > > As charmingly expressive as map() is, the wildly different > > behavior in py3 (it's a generator that e

Re: Clickable hyperlinks

2017-01-09 Thread Tim Chase
On 2017-01-09 14:33, Deborah Swanson wrote: > Ok, here is the crux of this thread's communication problem. I > didn't ask, or particularly care for all these lectures on the > technology of terminal emulators. I asked how to code Python to > make clickable links. The crux of the problem is that wo

Re: Find and append file path

2017-01-12 Thread Tim Chase
On 2017-01-12 19:28, Iranna Mathapati wrote: > Example: > CLI Input: /root/user/branches/xyz > > find latest file and append to CLI path: > "/root/user/branches/xyz/Apple" I've used something like the below to find the most recent file in a directory tree (it also works for pulling other attribu

Re: Find and append file path

2017-01-12 Thread Tim Chase
On 2017-01-12 18:32, Peter Otten wrote: > Why did you add an explicit isdir() check? My understanding is that > the names in dirs are known to be directories. Ah, right. The code I had laying around that did something similar but processes both the dirs and the files, so when the OP asked for jus

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Tim Chase
On 2017-01-21 11:58, Chris Angelico wrote: > So, how could you implement this function? The current > implementation maintains an index - an integer position through the > string. It repeatedly requests the next character as string[idx], > and can also slice the string (to check for keywords like "

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Tim Chase
On 2017-01-22 01:44, Steve D'Aprano wrote: > On Sat, 21 Jan 2017 11:45 pm, Tim Chase wrote: > > > but I'm hard-pressed to come up with any use case where direct > > indexing into a (non-byte)string makes sense unless you've already > > processed/searched

Re: How coding in Python is bad for you

2017-01-24 Thread Tim Chase
On 2017-01-24 20:04, Dennis Lee Bieber wrote: >>You don't know that. If this has been pasted from elsewhere, you >>need to match up the indentation level with the current code. > > So? The editor(s) I tend to use have the ability to shift > indent in/out for selected blocks. Do the paste, hi

Meta: mailing list, bounces, and SPF?

2017-02-03 Thread Tim Chase
Thanks to an abysmal failure of my hosting service (Site5), I was without email for multiple days, and when it came back up, the SPF record was pointed at the wrong place. I normally get a steady stream of comp.lang.python/python-list@ messages at my email address, so when they/I finally got thing

Re: 2.7 EOL = 2020 January 1

2018-03-13 Thread Tim Chase
On 2018-03-13 10:58, Terry Reedy wrote: > Two days later, Benjamin Peterson, the 2.7 release manager, replied > "Sounds good to me. I've updated the PEP to say 2.7 is completely > dead on Jan 1 2020." adding "The final release may not literally be > on January 1st". Am I the only one saddened by

Re: Converting list of tuple to list

2018-03-29 Thread Tim Chase
On 2018-03-29 20:42, Ganesh Pal wrote: > I have a list of tuple say [(1, 2, 1412734464L, 280), (2, 5, > 1582956032L, 351), (3, 4, 969216L, 425)] . I need to convert the > above as ['1,2,1412734464:280', > '2,5,1582956032:351', '3,4,969216:425'] > > Here is my Solution , Any suggestion or optim

Re: The perils of multiple Pythons

2018-04-30 Thread Tim Chase
On 2018-05-01 06:40, Chris Angelico wrote: >>> >> https://xkcd.com/1987/ >> >> I feel like this problem is pretty handily solved by virtual >> environments. Also, if a single project requires all of this, >> perhaps Python isn't the best choice for the project. > > Some of it is definitely solve

Re: Why exception from os.path.exists()?

2018-06-02 Thread Tim Chase
On 2018-06-02 00:14, Steven D'Aprano wrote: > Since /wibble doesn't exist, neither does /wibble/a\0b > > > py> os.path.exists("/wibble") > False > py> os.path.exists("/wibble/a\0b") > Traceback (most recent call last): > File "", line 1, in > File "/storage/torrents/torrents/python/Pytho

Re: Why exception from os.path.exists()?

2018-06-07 Thread Tim Chase
On 2018-06-07 22:46, Chris Angelico wrote: > On Thu, Jun 7, 2018 at 10:18 PM, Steven D'Aprano > 3. http://localhost:8000/te%00st.html > >>> Actually, I couldn't even get Chrome to make that request, so it > >>> obviously was considered by the browser to be invalid. It doesn't matter wheth

Re: Python web server weirdness

2018-06-07 Thread Tim Chase
On 2018-06-07 13:32, Steven D'Aprano wrote: > I'm following the instructions here: > > https://docs.python.org/3/library/http.server.html > > and running this from the command line as a regular unprivileged > user: > > python3.5 -m http.server 8000 > > What I expected was a directory listing of

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Tim Chase
On 2018-06-24 05:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, > since this is about your EXPECTATIONS, not what Python actually > does. > > Given this function: > > def test(): > a = 1 > b = 2 > result = [value for key, value in local

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Tim Chase
On 2018-06-23 23:08, Jim Lee wrote: >>> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result what would you expect the result of calling test() to be? >>>

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Tim Chase
From: Tim Chase On 2018-06-24 05:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, > since this is about your EXPECTATIONS, not what Python actually > does. > > Given this function: > > def test(): > a = 1 >

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Tim Chase
From: Tim Chase On 2018-06-23 23:08, Jim Lee wrote: >>> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >>>> def test(): >>>> a = 1 >>>> b = 2 >>>> result = [value for key, value in locals().items()] >>>>

Re: Generate a static back-of-a-book style index?

2018-07-07 Thread Tim Chase
On 2018-07-08 12:12, Cameron Simpson wrote: > On 07Jul2018 20:11, Skip Montanaro wrote: > >> Have you looked at the ptx command? Might be called "gptx" > > > >Thanks, Cameron. I was unaware of it. Will check it out. > > BTW, it well predates the GNU coreutils; I used it on V7 UNIX. Interesti

Re: Generate a static back-of-a-book style index?

2018-07-08 Thread Tim Chase
On 2018-07-08 13:34, Cameron Simpson wrote: > On 07Jul2018 21:57, Tim Chase wrote: > >On 2018-07-08 12:12, Cameron Simpson wrote: > >> On 07Jul2018 20:11, Skip Montanaro > >> wrote: > >> >> Have you looked at the ptx command? Might be called "gp

Re: Unicode [was Re: Cult-like behaviour]

2018-07-16 Thread Tim Chase
On 2018-07-16 18:31, Steven D'Aprano wrote: > You say that all you want is a switch to turn off Unicode (and > replace it with what? Kanji strings? Cyrillic? Shift_JS? no of > course not, I'm being absurd -- replace it with ASCII, what else > could any right-thinking person want, right?). But we a

<    1   2   3   4   5   6   7   8   9   10   >