Re: bash: testing whether anyone is or has recently been logged in?

2011-07-07 Thread Adam Funk
On 2011-04-20, Bill Marcum wrote: > On 2011-04-20, Adam Funk wrote: >> I'd appreciate any suggestions for testing (preferably from a bash >> script, although perl or python would be OK too) whether anyone is >> currently logged in, and whether anyone has been logge

pyicloud: TypeError: 'dict_values' object does not support indexing

2016-09-30 Thread Adam Funk
I'm trying to use pyicloud in idle3 (installed by pip3 on Ubuntu). The basic stuff works, but access to photos (following the instructions) fails: >>> photos = api.photos.all >>> for photo in photos: print(photo.filename) Traceback (most recent cal

Making IDLE3 ignore non-BMP characters instead of throwing an exception?

2016-10-17 Thread Adam Funk
I'm using IDLE 3 (with python 3.5.2) to work interactively with Twitter data, which of course contains emojis. Whenever the running program tries to print the text of a tweet with an emoji, it barfs this & stops running: UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 10

Re: Making IDLE3 ignore non-BMP characters instead of throwing an exception?

2016-10-17 Thread Adam Funk
On 2016-10-17, Adam Funk wrote: > I'm using IDLE 3 (with python 3.5.2) to work interactively with > Twitter data, which of course contains emojis. Whenever the running > program tries to print the text of a tweet with an emoji, it barfs > this & stops running: > >

Re: Making IDLE3 ignore non-BMP characters instead of throwing an exception?

2016-10-21 Thread Adam Funk
On 2016-10-17, eryk sun wrote: > On Mon, Oct 17, 2016 at 2:20 PM, Adam Funk wrote: >> I'm using IDLE 3 (with python 3.5.2) to work interactively with >> Twitter data, which of course contains emojis. Whenever the running >> program tries to print the text of a twe

Suggestions for plotting slide rule & sector scales?

2018-11-08 Thread Adam Funk
I like old scientific instruments & that sort of thing, & am wondering what libraries I could use for programmatically generating mathematical scales, ideally able to display the result in the GUI & save it as a png (or other standard graphics format). Ideally, I'd like to be able to write code li

Why does pathlib not have is_readable() & things like that?

2016-04-26 Thread Adam Funk
I recently discovered pathlib in the Python 3 standard library, & find it very useful, but I'm a bit surprised that it doesn't offer things like is_readable() and is_writable. Is there a good reason for that? I've been improvising with things like this: import pathlib, os path = pathlib.Path('s

Re: Why does pathlib not have is_readable() & things like that?

2016-04-28 Thread Adam Funk
On 2016-04-26, Steven D'Aprano wrote: > On Tue, 26 Apr 2016 11:30 pm, Adam Funk wrote: >> I've been improvising with things like this: >> >> import pathlib, os >> >> path = pathlib.Path('some/directory') >> writable = os.access(str(pat

Re: Why does pathlib not have is_readable() & things like that?

2016-04-28 Thread Adam Funk
On 2016-04-26, Random832 wrote: > On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >> I recently discovered pathlib in the Python 3 standard library, & find >> it very useful, but I'm a bit surprised that it doesn't offer things >> like is_readable() and is_wr

Re: Why does pathlib not have is_readable() & things like that?

2016-04-29 Thread Adam Funk
On 2016-04-28, Grant Edwards wrote: > On 2016-04-28, Adam Funk wrote: >> On 2016-04-26, Random832 wrote: >> >>> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >>>> I recently discovered pathlib in the Python 3 standard library, & find >>>

bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread Adam Funk
Hi, I'm using bottledaemon to run a little REST service on a Pi that takes input from other machines on the LAN and stores stuff in a database. I have a cron job to call 'stop' and 'start' on it daily, just in case of problems. Occasionally the oom-killer runs overnight and kills the process usin

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-19 Thread Adam Funk
On 2018-11-19, Dennis Lee Bieber wrote: > On Sun, 18 Nov 2018 15:33:47 -0600, Dan Sommers ><2qdxy4rzwzuui...@potatochowder.com> declaimed the following: > >> >>What if the oom-killer kills the watchdog? >> > > Then you have TWO processes with out-of-control memory growth. > > The out-o

Basic pynomo instructions not working

2018-11-20 Thread Adam Funk
Hi, I'm trying to use the basic stuff in pynomo which I've installed with pip3, but I run into this problem trying to the basic stuff in the documentation: #v+ $ python3 Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0] on linux Type "help", "copyrig

Re: Suggestions for plotting slide rule & sector scales?

2018-11-20 Thread Adam Funk
On 2018-11-08, Stefan Ram wrote: > Adam Funk writes: >>and get a line 100 mm long with a log scale on the top and a linear >>scale on the bottom. > > From what I have heard, > > pyqt.sourceforge.net/Docs/PyQt4/qx11info.html#appDpiX > > will give you the

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-20 Thread Adam Funk
On 2018-11-18, Dan Sommers wrote: > On 11/18/18 1:21 PM, MRAB wrote:> On 2018-11-18 17:50, Adam Funk wrote: > >> Hi, > >> > >> I'm using bottledaemon to run a little REST service on a Pi that takes > >> input from other machines on the LAN and stores

Re: Basic pynomo instructions not working

2018-12-10 Thread Adam Funk
On 2018-11-22, dieter wrote: > The "pynomo" version you have installed may have been developped for > Python 2 and not run in "python3". > > In Python 2, you have implicit relative imports. > As an example, it allows modules in the package "pynomo" > to use "import nomo_wrapper" to import the subm

Creating LF, NEL line terminators by accident? (python3)

2019-03-26 Thread Adam Funk
Hi, I have a Python 3 (using 3.6.7) program that reads a TSV file, does some churning with the data, and writes a TSV file out. #v+ print('reading', options.input_file) with open(options.input_file, 'r', encoding='utf-8-sig') as f: for line in f.readlines(): row = line.split('\t')

Bulletproof json.dump?

2020-07-06 Thread Adam Funk
Hi, I have a program that does a lot of work with URLs and requests, collecting data over about an hour, & then writing the collated data to a JSON file. The first time I ran it, the json.dump failed because there was a bytes value instead of a str, so I had to figure out where that was coming fr

Re: Bulletproof json.dump?

2020-07-06 Thread Adam Funk
On 2020-07-06, Frank Millman wrote: > On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: >> On 2020-07-06, Chris Angelico wrote: >>> On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >>>> Is there a "bulletproof" version of json.dump somewhere that w

Re: Bulletproof json.dump?

2020-07-06 Thread Adam Funk
On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >> >> Hi, >> >> I have a program that does a lot of work with URLs and requests, >> collecting data over about an hour, & then writing the collated data >> to

Re: Bulletproof json.dump?

2020-07-06 Thread Adam Funk
On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list > wrote: >> >> On 2020-07-06, Chris Angelico wrote: >> > On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >> >> Is there a "bulletproof" version of

Re: Bulletproof json.dump?

2020-07-07 Thread Adam Funk
On 2020-07-06, Adam Funk wrote: > On 2020-07-06, Chris Angelico wrote: >> On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list >> wrote: >>> While I agree entirely with your point, there is however perhaps room >>> for a bit more helpfulness from the

Re: Bulletproof json.dump?

2020-07-09 Thread Adam Funk
On 2020-07-07, Stephen Rosen wrote: > On Mon, Jul 6, 2020 at 6:37 AM Adam Funk wrote: > >> Is there a "bulletproof" version of json.dump somewhere that will >> convert bytes to str, any other iterables to list, etc., so you can >> just get your data into a file

getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
I'm having trouble with some input files that are almost all proper UTF-8 but with a couple of troublesome characters mixed in, which I'd like to ignore instead of throwing ValueError. I've found the openhook for the encoding for line in fileinput.input(options.files, openhook=fileinput.hook_enc

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
On 2015-12-03, Adam Funk wrote: > I'm having trouble with some input files that are almost all proper > UTF-8 but with a couple of troublesome characters mixed in, which I'd > like to ignore instead of throwing ValueError. I've found the > openhook for t

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
On 2015-12-03, Peter Otten wrote: > def my_hook_encoded(encoding, errors=None): > import io > def openhook(filename, mode): > mode = mode.replace('U', '').replace('b', '') or 'r' > return io.open( > filename, mode, > encoding=encoding, newline='',

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
On 2015-12-03, Terry Reedy wrote: > fileinput is an ancient module that predates iterators (and generators) > and context managers. Since by 2.7 open files are both context managers > and line iterators, you can easily write your own multi-file line > iteration that does exactly what you want.

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
On 2015-12-03, Laura Creighton wrote: > In a message of Thu, 03 Dec 2015 15:12:15 +0000, Adam Funk writes: >>I'm having trouble with some input files that are almost all proper >>UTF-8 but with a couple of troublesome characters mixed in, which I'd >>like to ignore

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-07 Thread Adam Funk
On 2015-12-04, Oscar Benjamin wrote: > Or you can use fileinput which is designed to be exactly this kind of > context manager and to be used in this way. Although fileinput is slightly > awkward in defaulting to reading stdin. That default is what I specifically like about fileinput --- it's a n

writing an email.message.Message in UTF-8

2015-12-07 Thread Adam Funk
I'm trying to write an instance of email.message.Message, whose body contains unicode characters, to a UTF-8 file. (Python 2.7.3 & 2.7.10 again.) reply = email.message.Message() reply.set_charset('utf-8') ... # set various headers reply.set_payload('\n'.join(body_lines) + '\n')

Re: writing an email.message.Message in UTF-8

2015-12-07 Thread Adam Funk
On 2015-12-07, Adam Funk wrote: > I'm trying to write an instance of email.message.Message, whose body > contains unicode characters, to a UTF-8 file. (Python 2.7.3 & 2.7.10 > again.) > > reply = email.message.Message() > reply.set_charset('utf-8&#

Re: writing an email.message.Message in UTF-8

2015-12-08 Thread Adam Funk
On 2015-12-08, dieter wrote: > Adam Funk writes: > >> I'm trying to write an instance of email.message.Message, whose body >> contains unicode characters, to a UTF-8 file. (Python 2.7.3 & 2.7.10 >> again.) >> >> reply = email.mess

Re: writing an email.message.Message in UTF-8

2015-12-08 Thread Adam Funk
On 2015-12-07, Terry Reedy wrote: > On 12/7/2015 9:57 AM, Adam Funk wrote: >> I'm trying to write an instance of email.message.Message, whose body >> contains unicode characters, to a UTF-8 file. (Python 2.7.3 & 2.7.10 >> again.) > > The email package w

trying to force stdout to utf-8 with errors='ignore' or 'replace'

2015-12-11 Thread Adam Funk
I'm fiddling with a program that reads articles in the news spool using email.parser (standard library) & email_reply_parser.EmailReplyParser (installed with pip). Reading is fine, & I don't get any errors writing output extracted from article bodies *until* I try to suppress invalid characters.

Re: trying to force stdout to utf-8 with errors='ignore' or 'replace'

2015-12-11 Thread Adam Funk
On 2015-12-11, Peter Otten wrote: > Adam Funk wrote: >> but with either or both of those, I get the dreaded >> "UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position >> 562: ordinal not in range(128)". How can I force the output

Testing whether the VPN is running?

2016-02-18 Thread Adam Funk
I'd like to test (inside a python 3 program) whether the VPN is running or not. The only thing I can think of so far is to use subprocess to run the 'ifconfig' command, then check its output for 'tun0'. Is there a better way? Thanks. -- Nam Sibbyllam quidem Cumis ego ipse oculis meis vidi in

Re: Testing whether the VPN is running?

2016-02-18 Thread Adam Funk
On 2016-02-18, Ervin Hegedüs wrote: > Hi Adam, > > On Thu, Feb 18, 2016 at 09:26:58AM +0000, Adam Funk wrote: >> I'd like to test (inside a python 3 program) whether the VPN is >> running or not. The only thing I can think of so far is to use >> subprocess to

Re: Testing whether the VPN is running?

2016-02-25 Thread Adam Funk
On 2016-02-23, Cameron Simpson wrote: > On 18Feb2016 10:03, Adam Funk wrote: >>On 2016-02-18, Ervin Hegedüs wrote: >>> I think that the psutil modul could be better for you for this >>> task: >>> https://pypi.python.org/pypi/psutil/ >>> >>

Re: Permissions on files installed by pip?

2014-10-22 Thread Adam Funk
On 2014-10-17, Jean-Michel Pichavant wrote: > - Original Message - >> From: "Adam Funk" >> To: python-list@python.org >> Sent: Thursday, 16 October, 2014 9:29:46 PM >> Subject: Permissions on files installed by pip? >> >> I've be

Why does argparse return None instead of [] if an append action isn't used?

2015-01-09 Thread Adam Funk
I noticed in use that if an option with the 'append' action isn't used, argparse assigns None to it rather than an empty list, & confirmed this interactively: #v+ >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='append') _AppendAction(option_strin

Re: Why does argparse return None instead of [] if an append action isn't used?

2015-01-09 Thread Adam Funk
On 2015-01-09, Skip Montanaro wrote: >> I noticed in use that if an option with the 'append' action isn't >> used, argparse assigns None to it rather than an empty list, & >> confirmed this interactively: > > I don't use argparse (or optparse), being a getopt Luddite myself, but > can you set the

Re: Why does argparse return None instead of [] if an append action isn't used?

2015-01-26 Thread Adam Funk
On 2015-01-09, Wolfgang Maier wrote: > On 01/09/2015 03:44 PM, Adam Funk wrote: >> I noticed in use that if an option with the 'append' action isn't >> used, argparse assigns None to it rather than an empty list, & >> confirmed this interactively: >

Re: Why does argparse return None instead of [] if an append action isn't used?

2015-01-26 Thread Adam Funk
On 2015-01-09, Ned Batchelder wrote: > On 1/9/15 9:44 AM, Adam Funk wrote: >> This makes it a bit more trouble to use: >> >>if options.bar: >> for b in options:bar >> do_stuff(b) >> >> instead of >> >>for b in options

Re: Why does argparse return None instead of [] if an append action isn't used?

2015-01-26 Thread Adam Funk
On 2015-01-26, Peter Otten wrote: > Adam Funk wrote: > >> On 2015-01-09, Ned Batchelder wrote: >> >>> On 1/9/15 9:44 AM, Adam Funk wrote: >>>> This makes it a bit more trouble to use: >>>> >>>>if options.bar: >>>>

Re: sqlite3 and dates

2015-02-19 Thread Adam Funk
On 2015-02-18, Johannes Bauer wrote: > On 18.02.2015 12:21, Chris Angelico wrote: > >> SQLite3 is fine for something that's basically just a more structured >> version of a flat file. You assume that nobody but you has the file >> open, and you manipulate it just the same as if it were a big fat b

Re: sqlite3 and dates

2015-02-19 Thread Adam Funk
On 2015-02-18, Chris Angelico wrote: > On Thu, Feb 19, 2015 at 9:17 AM, wrote: >>> SQLite3 is fine for something that's basically just a more structured >>> version of a flat file. You assume that nobody but you has the file >>> open, and you manipulate it just the same as if it were a big fat b

Re: Significant digits in a float?

2014-04-29 Thread Adam Funk
On 2014-04-29, Roy Smith wrote: > Another possibility is that they're latitude/longitude coordinates, some > of which are given to the whole degree, some of which are given to > greater precision, all the way down to the ten-thousandth of a degree. That makes sense. 1° of longitude is about 11

Re: Off-topic circumnavigating the earth in a mile or less

2014-05-01 Thread Adam Funk
On 2014-05-01, Terry Reedy wrote: > On 4/30/2014 7:46 PM, Ian Kelly wrote: > >> It also works if your starting point is (precisely) the north pole. I >> believe that's the canonical answer to the riddle, since there are no >> bears in Antarctica. > > For the most part, there are no bears within a

Re: Significant digits in a float?

2014-05-01 Thread Adam Funk
On 2014-05-01, Dennis Lee Bieber wrote: > On Tue, 29 Apr 2014 20:42:33 -0400, Roy Smith declaimed the > following: > >>In article , >> Dennis Lee Bieber wrote: >>> (one reason slide-rules were acceptable for so long -- and even my high >>> school trig course only required slide-rule significanc

Re: Off-topic circumnavigating the earth in a mile or less

2014-05-01 Thread Adam Funk
On 2014-04-30, Ethan Furman wrote: > Wow. It's amazing how writing something down, wrongly (I originally had > north and south reversed), correcting it, > letting some time pass (enough to post the message so one can be properly > embarrassed ;), and then rereading it later > can make somethi

Re: Significant digits in a float?

2014-05-01 Thread Adam Funk
On 2014-05-01, Larry Hudson wrote: > On 05/01/2014 05:56 AM, Roy Smith wrote: >> For those who have no idea what we're talking about, take a look at >> http://www.ted.com/talks/clifford_stoll_on_everything. If you just want >> to see what you do with a slide rule, fast forward to 14:20, but you

Re: Significant digits in a float?

2014-05-08 Thread Adam Funk
On 2014-05-02, Dennis Lee Bieber wrote: > On Thu, 01 May 2014 21:55:20 +0100, Adam Funk > declaimed the following: > >>On 2014-05-01, Dennis Lee Bieber wrote: >>> Math teacher was selling them in my 10th grade... Actually I already >>> owned a Faber-Castell

hashing strings to integers for sqlite3 keys

2014-05-22 Thread Adam Funk
I'm using Python 3.3 and the sqlite3 module in the standard library. I'm processing a lot of strings from input files (among other things, values of headers in e-mail & news messages) and suppressing duplicates using a table of seen strings in the database. It seems to me --- from past experience

Re: hashing strings to integers for sqlite3 keys

2014-05-22 Thread Adam Funk
On 2014-05-22, Peter Otten wrote: > Adam Funk wrote: > >> I'm using Python 3.3 and the sqlite3 module in the standard library. >> I'm processing a lot of strings from input files (among other things, >> values of headers in e-mail & news messages) and supp

Re: hashing strings to integers for sqlite3 keys

2014-05-22 Thread Adam Funk
On 2014-05-22, Chris Angelico wrote: > On Thu, May 22, 2014 at 9:47 PM, Adam Funk wrote: >> I'm using Python 3.3 and the sqlite3 module in the standard library. >> I'm processing a lot of strings from input files (among other things, >> values of headers

Re: hashing strings to integers for sqlite3 keys

2014-05-22 Thread Adam Funk
On 2014-05-22, Tim Chase wrote: > On 2014-05-22 12:47, Adam Funk wrote: >> I'm using Python 3.3 and the sqlite3 module in the standard library. >> I'm processing a lot of strings from input files (among other >> things, values of headers in e-mail & news mess

Re: hashing strings to integers for sqlite3 keys

2014-05-22 Thread Adam Funk
On 2014-05-22, Chris Angelico wrote: > On Thu, May 22, 2014 at 11:41 PM, Adam Funk wrote: >> On further reflection, I think I asked for that. In fact, the table >> I'm using only has one column for the hashes --- I wasn't going to >> store the strings at all in

Re: hashing strings to integers for sqlite3 keys

2014-05-22 Thread Adam Funk
On 2014-05-22, Chris Angelico wrote: > On Thu, May 22, 2014 at 11:54 PM, Adam Funk wrote: >> That ties in with a related question I've been wondering about lately >> (using MD5s & SHAs for other things) --- getting a hash value (which >> is internally numeric, rath

hashing strings to integers (was: hashing strings to integers for sqlite3 keys)

2014-05-23 Thread Adam Funk
On 2014-05-22, Peter Otten wrote: > Adam Funk wrote: >> Well, J*v* returns a byte array, so I used to do this: >> >> digester = MessageDigest.getInstance("MD5"); >> ... >> digester.reset(); >> byte[] digest = digester.diges

Re: hashing strings to integers

2014-05-23 Thread Adam Funk
On 2014-05-23, Adam Funk wrote: > On 2014-05-22, Peter Otten wrote: >> In Python 3 there's int.from_bytes() >> >>>>> h = hashlib.sha1(b"Hello world") >>>>> int.from_bytes(h.digest(), "little") >> 53805907168366771184661

Re: hashing strings to integers

2014-05-27 Thread Adam Funk
On 2014-05-23, Chris Angelico wrote: > On Fri, May 23, 2014 at 8:27 PM, Adam Funk wrote: >> I've also used hashes of strings for other things involving >> deduplication or fast lookups (because integer equality is faster than >> string equality). I guess if it's

Re: hashing strings to integers

2014-05-27 Thread Adam Funk
On 2014-05-23, Terry Reedy wrote: > On 5/23/2014 6:27 AM, Adam Funk wrote: > >> that. The only thing that really bugs me in Python 3 is that execfile >> has been removed (I find it useful for testing things interactively). > > The spelling has been changed to exec(open(.

Re: hashing strings to integers

2014-06-03 Thread Adam Funk
On 2014-05-28, Dan Sommers wrote: > On Tue, 27 May 2014 17:02:50 +, Steven D'Aprano wrote: > >> - rather than "zillions" of them, there are few enough of them that >> the chances of an MD5 collision is insignificant; > >> (Any MD5 collision is going to play havoc with your strategy of >>

Re: hashing strings to integers

2014-06-03 Thread Adam Funk
On 2014-05-27, Steven D'Aprano wrote: > On Tue, 27 May 2014 16:13:46 +0100, Adam Funk wrote: >> Well, here's the way it works in my mind: >> >>I can store a set of a zillion strings (or a dict with a zillion >>string keys), but every time

Standard way to generate mail/news reply?

2014-06-24 Thread Adam Funk
Is there some standard library or code for taking an e-mail or newsgroup message & generating a reply to it? (I mean things like quoting the original message, >> quoting etc. where necessary, & generating the right References & In-Reply-To headers.) I homebrewed some code for this in Perl (sorry)

Re: Standard way to generate mail/news reply?

2014-06-26 Thread Adam Funk
On 2014-06-24, Skip Montanaro wrote: > On Tue, Jun 24, 2014 at 6:46 AM, Adam Funk wrote: >> Is there some standard library or code for taking an e-mail or >> newsgroup message & generating a reply to it? > > You might try searching for "mail reply" on pypi.pyth

Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-01 Thread Adam Funk
I have some code that reads files in a leafnode2 news spool & needs to check for new files periodically. The full paths are all like '/var/spool/news/message.id/345/<123...@example.com>' with a 3-digit subdirectory & a Message-ID for the filename itself. I'm using Python 3 & sqlite3 in the standa

Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-01 Thread Adam Funk
On 2014-07-01, Chris Angelico wrote: > On Tue, Jul 1, 2014 at 9:26 PM, Adam Funk wrote: >> cursor.execute('SELECT filename FROM files WHERE filename IS ?', >> (filename,)) > > Shouldn't this be an equality check rather than IS, which normally I'd

Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Adam Funk
On 2014-07-01, Chris Angelico wrote: > On Wed, Jul 2, 2014 at 1:15 AM, Adam Funk wrote: >> On 2014-07-01, Chris Angelico wrote: >> >>> On Tue, Jul 1, 2014 at 9:26 PM, Adam Funk wrote: >>>> cursor.execute('SELECT filename FROM fi

Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Adam Funk
On 2014-07-01, Chris Angelico wrote: > On Wed, Jul 2, 2014 at 1:15 AM, Adam Funk wrote: >> On 2014-07-01, Chris Angelico wrote: >>> There is one critical consideration, though. What happens if the >>> directory name contains an underscore or percent sign? Or can y

Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Adam Funk
On 2014-07-02, Chris Angelico wrote: > On Wed, Jul 2, 2014 at 7:32 PM, Adam Funk wrote: >> Well, I've changed it to the following anyway. >> >> subdir_glob = subdir + '/*' >> cursor.execute('SELECT filename FROM files WHERE filename

Permissions on files installed by pip?

2014-10-16 Thread Adam Funk
I've been using the python-nltk package on Ubuntu, but I need ntlk 3.0 now. I used 'sudo aptitude purge python-nltk' to get rid of my existing installation, & followed instructions on the nltk website [1] starting at step 4 (since I already have python-pip & python-numpy packages installed). $ su

recommend a graphics library for plotting by the pixel?

2011-10-04 Thread Adam Funk
I'd like to create a window with a "pause" button and a large plotting area, in which I'd like to draw a polygon, detect the pixel coördinates of a mouse click, and then start setting the colors of pixels by (x,y) coördinates. (This is just for my own amusement, to play with some formulas for gene

Re: recommend a graphics library for plotting by the pixel?

2011-10-05 Thread Adam Funk
On 2011-10-04, Derek Simkowiak wrote: > If this is strictly for 2D pixel graphics, I recommend using PyGame > (aka SDL). Why do you not think it's the way to go? It was built for > this type of thing. I only know PyGame because we did an exercise in recreating the old breakout game and m

Re: recommend a graphics library for plotting by the pixel?

2011-10-07 Thread Adam Funk
On 2011-10-04, Ian Kelly wrote: > On Tue, Oct 4, 2011 at 3:56 AM, Adam Funk wrote: >> I'd like to create a window with a "pause" button and a large plotting >> area, in which I'd like to draw a polygon, detect the pixel >> coördinates of a mouse cl

Re: recommend a graphics library for plotting by the pixel?

2011-10-07 Thread Adam Funk
On 2011-10-05, Westley Martínez wrote: > On Wed, Oct 05, 2011 at 02:29:38PM +0100, Adam Funk wrote: >> I only know PyGame because we did an exercise in recreating the old >> breakout game and messing around with it at a local Python group. >> >> I was under the mi

suppressing bad characters in output PCDATA (converting JSON to XML)

2011-11-25 Thread Adam Funk
I'm converting JSON data to XML using the standard library's json and xml.dom.minidom modules. I get the input this way: input_source = codecs.open(input_file, 'rb', encoding='UTF-8', errors='replace') big_json = json.load(input_source) input_source.close() Then I recurse through the contents of

Re: suppressing bad characters in output PCDATA (converting JSON to XML)

2011-11-29 Thread Adam Funk
On 2011-11-28, Stefan Behnel wrote: > Adam Funk, 25.11.2011 14:50: >> I'm converting JSON data to XML using the standard library's json and >> xml.dom.minidom modules. I get the input this way: >> >> input_source = codecs.open(input_file, 'rb',

Re: suppressing bad characters in output PCDATA (converting JSON to XML)

2011-11-29 Thread Adam Funk
On 2011-11-28, Steven D'Aprano wrote: > On Fri, 25 Nov 2011 13:50:01 +0000, Adam Funk wrote: > >> I'm converting JSON data to XML using the standard library's json and >> xml.dom.minidom modules. I get the input this way: >> >> input_source =

Re: suppressing bad characters in output PCDATA (converting JSON to XML)

2011-12-02 Thread Adam Funk
On 2011-11-29, Stefan Behnel wrote: > Adam Funk, 29.11.2011 13:57: >> On 2011-11-28, Stefan Behnel wrote: >>> If the name "big_json" is supposed to hint at a large set of data, you may >>> want to use something other than minidom. Take a look at the >

mutually exclusive arguments to a constructor

2011-12-30 Thread Adam Funk
(Warning: this question obviously reflects the fact that I am more accustomed to using Java than Python.) Suppose I'm creating a class that represents a bearing or azimuth, created either from a string of traditional bearing notation ("N24d30mE") or from a number indicating the angle in degrees as

Re: mutually exclusive arguments to a constructor

2011-12-31 Thread Adam Funk
On 2011-12-30, Roy Smith wrote: > "But!", some C++/Java type bondage addicts might cry, "there's nothing > to prevent somebody from creating a DirectionIndicatingThingie directly, > bypassing the factory functions. There's no way to make the constructor > private!". To which the free-willed p

Re: mutually exclusive arguments to a constructor

2011-12-31 Thread Adam Funk
On 2011-12-30, Günther Dietrich wrote: > Adam Funk wrote: > >>Suppose I'm creating a class that represents a bearing or azimuth, >>created either from a string of traditional bearing notation >>("N24d30mE") or from a number indicating the angle in degree

UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-04 Thread Adam Funk
(I'm using Python 2.7.2+ on Ubuntu.) When I'm running my program in an xterm, the print command with an argument containing unicode works fine (it correctly detects my UTF-8 environment). But when I run it with a pipe or redirect to a file (| or >), unicode strings fail with the following (for ex

Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-06 Thread Adam Funk
On 2012-01-04, Peter Otten wrote: > Adam Funk wrote: >> How can I force python (preferably within my python program, rather >> than having to set something externally) to treat stdout as UTF-8? > > > $ cat force_utf8.py > # -*- coding: utf-8 -*- > import sys >

Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-06 Thread Adam Funk
On 2012-01-06, Peter Otten wrote: > Adam Funk wrote: > >> On 2012-01-04, Peter Otten wrote: >> >>> Adam Funk wrote: >> >>>> How can I force python (preferably within my python program, rather >>>> than having to set something externally)

Detecting a click on the turtle screen when the turtle isn't doing anything?

2013-02-05 Thread Adam Funk
I'm trying to get a program to do some plotting with turtle graphics, then wait for the user to click on the graphics window, then do some more plotting, &c. So far I have the following, which doesn't work: #v+ waiting = False def clicked(x, y): global waiting print('clicked at %f %f' %

Re: Detecting a click on the turtle screen when the turtle isn't doing anything?

2013-02-05 Thread Adam Funk
On 2013-02-05, woo...@gmail.com wrote: > Note that the code you posted does not call onclick(). It does, actually, but I accidentally snipped it when C&Ping code into my original post. Sorry! > Globals are > confusing IMHO. Code becomes cleaner and easier to write and read > when you becom

Re: Detecting a click on the turtle screen when the turtle isn't doing anything?

2013-02-05 Thread Adam Funk
On 2013-02-05, Adam Funk wrote: > I'm trying to get a program to do some plotting with turtle graphics, > then wait for the user to click on the graphics window, then do some > more plotting, &c. So far I have the following, which doesn't work: > > #v+ > wait

Re: Detecting a click on the turtle screen when the turtle isn't doing anything?

2013-02-06 Thread Adam Funk
On 2013-02-05, Dave Angel wrote: > I'm no fan of Java. But it's not about a "main" method, it's about > sharing data between functions. Most of the time non-constant globals > are a mistake. If the data can't be passed as an argument, then it > should probably be part of the instance data of

Re: Detecting a click on the turtle screen when the turtle isn't doing anything?

2013-02-06 Thread Adam Funk
On 2013-02-05, Dennis Lee Bieber wrote: > I'll echo the "Ugh" about the use of global AND ADD a dislike of the > busy loop that only exits if some other return sets a value. If the busy > loop were performing some action that changed the test state within the > loop itself, okay... TBH, I w

Equivalent of perl's Pod::Usage?

2007-12-07 Thread Adam Funk
I'm using to using Pod::Usage in my Perl programs (a snipped example is shown below, if you're interested) to generate a little man page when they are called with the -h option. Is there an equivalent in Python? Thanks, Adam ## use Pod::Usage; getopts("ha:b:c", \%option) ; if ($optio

Re: Equivalent of perl's Pod::Usage?

2007-12-10 Thread Adam Funk
On 2007-12-08, Neil Cerutti wrote: > On 2007-12-08, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >> On Fri, 7 Dec 2007 20:12:21 +, Adam Funk <[EMAIL PROTECTED]> >> declaimed the following in comp.lang.python: >> >>> I'm using to using Pod::Usag

Re: Equivalent of perl's Pod::Usage?

2007-12-10 Thread Adam Funk
On 2007-12-08, Dennis Lee Bieber wrote: > On Fri, 7 Dec 2007 20:12:21 +0000, Adam Funk <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> I'm using to using Pod::Usage in my Perl programs (a snipped example >> is shown below, if you're

Re: Is a "real" C-Python possible?

2007-12-11 Thread Adam Funk
On 2007-12-10, sturlamolden wrote: > We have seen several examples that 'dynamic' and 'interpreted' > languages can be quite efficient: There is an implementation of Common > Lisp - CMUCL - that can compete with Fortran in efficiency for > numerical computing. There are also versions of Lisp than

Re: Equivalent of perl's Pod::Usage?

2007-12-13 Thread Adam Funk
On 2007-12-10, Nick Craig-Wood wrote: > That said, python does a good job of turning doc strings and class > descriptions into man pages even without any special markup, if you > wrote docstrings everywhere. Try pydoc on any bit of python (without > the .py) and you'll see what I mean > > As for

Does fileinput.input() read STDIN all at once?

2007-12-18 Thread Adam Funk
I'm using this sort of standard thing: for line in fileinput.input(): do_stuff(line) and wondering whether it reads until it hits an EOF and then passes lines (one at a time) into the variable line. This appears to be the behaviour when it's reading STDIN interactively (i.e. from the ke

Re: Does fileinput.input() read STDIN all at once?

2007-12-19 Thread Adam Funk
On 2007-12-18, Jonathan Gardner wrote: >> As a test, I tried this: >> >>for line in fileinput.input(): >> print '**', line >> >> and found that it would print nothing until I hit Ctl-D, then print >> all the lines, then wait for another Ctl-D, and so on (until I pressed >> Ctl-D twice in

Re: Does fileinput.input() read STDIN all at once?

2007-12-21 Thread Adam Funk
On 2007-12-20, Tim Roberts wrote: >>As a test, I tried this: >> >> for line in fileinput.input(): >> print '**', line >> >>and found that it would print nothing until I hit Ctl-D, then print >>all the lines, then wait for another Ctl-D, and so on (until I pressed >>Ctl-D twice in succession

managing the RDFLib NamespaceManager

2017-03-14 Thread Adam Funk
I'm using RDFLib 4.2.2 (installed with pip3) in Python 3.5.2, and the automatic behaviour of the NamespaceManager is giving me conniptions, because the automatically generated namespaces go too far to the right in the URIs and make the right-hand parts of the QNames meaningless. For example, I hav

  1   2   >