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

2017-02-04 Thread Cameron Simpson
sed in this manor? Hmm. I've compromised my friends (with harmless pranks) in this way. These days that doesn't work so well became having "." in your path is not done. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Cameron Simpson
is a good idea depends on the clock implementation and your program. In Python there is a naming convention: values which may be directy accessed are given ordinary names (like ".time") and values which are part of the internals, subject to change, or tricky to keep correct are given names starting with underscores (like "._time"). If you're accessing a _name that is a clue that you're probably doing the wrong thing (if your outside the class - obviously the class itself must work on these values). Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: Which part of the loop is it going through in this class frame?

2018-03-09 Thread Cameron Simpson
written: class Clock: to achieve the same purpose. Being a subclass of "object" gets you an assortment of methods immediately, such as __str__ and __repr__ (used to present a class as a string). You even get an __init__ for free, but the default does nothing and that is usually not what you need. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: test

2018-03-12 Thread Cameron Simpson
script for sendmail which intercepted group.name@usenet and send that via NNTP (obviously my puller inserted those addresses in the pull). What are most active pythoniacs doing with this these days? I use the mailing lists and mutt for reading. Cheers, Cameron Simpson (formerly c...@zip.com.au) -

Re: Python gotcha of the day

2018-03-13 Thread Cameron Simpson
' But remove the spaces, and two of the quotation marks disappear: py> """\"""""" '"' """\"""" "" Implicit string concatenation of an empty string. I confess I try to have my quote delimiters d

Re: Regex Doubts

2018-03-30 Thread Cameron Simpson
are not there, you have two "MEMR : N valid M free" strings up there. It sounds like you want only the nonzero one. Notice that your regexp includes: [0-9]+ to match 1 or more digits. If you don't want to recognise zero values, consider that any such number doesn'

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Cameron Simpson
heers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Cameron Simpson
problem is Python don't know its size (or decides it wrong:-). I think you'll need to show us your code. It isn't clear to me your problem is. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Print Failure or success based on the value of the standalone tool

2018-05-10 Thread Cameron Simpson
shell interprets. The latter directly runs your script. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Extract

2018-05-14 Thread Cameron Simpson
ad of just finding their names, you would need to know about the data format within those files, which you have not described. See the Python docs here: https://docs.python.org/3/ and look up the "os" and "glob" modules for the functions mentioned above. Cheers, Cameron Simps

Re: Extract data from multiple text files

2018-05-15 Thread Cameron Simpson
th.join function. And finally, _please_ post follow on questions to this list as _replies_ to the appropriate list message. By just posting new messages from scratch your new message is disconnected from all the earlier ones. Anyone trying to follow your discussion will lose all the other contex

Re: Simplest way to clobber/replace one populated directory with another?

2018-05-16 Thread Cameron Simpson
routinely type: rmr Previous && mv Current Previous Prompt back instantly, "rm" of the temp name proceeding siletnly in the background. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: how to get INDEX count, or last number of Index

2018-05-23 Thread Cameron Simpson
instance of particular records. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Some Issues on Tagging Text

2018-05-24 Thread Cameron Simpson
ecause "Hawaiian" has already received a tag earlier in the list. Or are there other criteria. If you want to solve this problem with a programme you must first clearly define what makes an unwanted tag "unwanted". For example, "Hawaiian" is an adjective, and therefore will always be part of a compound term. Can you clarify what makes these taggings you mention "unwanted"? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: List replication operator

2018-05-24 Thread Cameron Simpson
gainst the "**" spelling I find, for much the same reasons that people oppose allowing "=" and "==" in the same syntactic location: they're easy to get wrong through typing inaccuracy. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: List replication operator

2018-05-24 Thread Cameron Simpson
less opposed - _that_ is practically exponential memory use, and so the "**" is much more apt :-) I think I'm basicly against a shallow copy and not against a deep copy, because the shallow copy only pushes the issue out one layer. So, how to various forms of multidimensional lists pl

Re: List replication operator

2018-05-24 Thread Cameron Simpson
On 25May2018 02:32, Steven D'Aprano wrote: On Fri, 25 May 2018 08:02:38 +1000, Cameron Simpson wrote: I'm also against the "**" spelling I find, for much the same reasons that people oppose allowing "=" and "==" in the same syntactic location:

Re: Some Issues on Tagging Text

2018-05-25 Thread Cameron Simpson
On 25May2018 04:23, Subhabrata Banerjee wrote: On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote: On 24May2018 03:13, wrote: >I have a text as, > >"Hawaii volcano generates toxic gas plume called laze PAHOA: The eruption of Kilauea volcano in Hawaii spark

Re: Some Issues on Tagging Text

2018-05-26 Thread Cameron Simpson
On 26May2018 04:02, Subhabrata Banerjee wrote: On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote: It sounds like you want a more general purpose parser, and that depends upon your purposes. If you're coding to learn the basics of breaking up text, what you'r

Re: '_' and '__'

2018-05-26 Thread Cameron Simpson
sion in that variable. 6 * 7 42 _ + 1 43 Other than that, it is simply an ordinary name, but one that has some conventions attached to it. Also, various lint tools know that the name "_" is used in this way, and don't complain that a variable is assigned to and not

Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-27 Thread Cameron Simpson
() code into a function of your own (i.e. in your own codebase) modify that to suit, then monkeypatch the class: Image.show = your_personal_show_function when your programme starts. That way the code changes are not in the PIL code. Cheers, Cameron Simpson -- https://mail.python.org/mailman

Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Cameron Simpson
h path) to be suitable already. Every hardwired path is a maintenance and fragility nightmare. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-07 Thread Cameron Simpson
directory, so you can now check (a) whether you're where you thought you were, and (b) what is in the current directory (in case it doesn't contain what you expected). The "ls -la" command will provide a longer and more detailed listing too. Let us know what you find out. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-08 Thread Cameron Simpson
context needed for your reply to make sense. Sometimes that involves keeping some message quote from even earlier messages, in which case _their_ intro line and text is preserved, with an extra level of ">", like this: On Thu, Jun 7, 2018 at 10:27 PM Cameron Simpson wrote:

Re: Problem finding my folder via terminal

2018-06-08 Thread Cameron Simpson
the folder in the Finder and look around: open ~/Desktop/mymodules I'm thinking you've just made an additional "mymodules" inside your main "mymodules" by accident. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-08 Thread Cameron Simpson
On 08Jun2018 10:23, Tamara Berger wrote: On Fri, Jun 8, 2018 at 5:35 AM Cameron Simpson wrote: On 08Jun2018 01:52, Tamara Berger wrote: >192:~ TamaraB$ cd Desktop/mymodules >192:mymodules TamaraB$ pwd >/Users/TamaraB/Desktop/mymodules >192:mymodules TamaraB$ ls >mymodules It

Re: Distribution file error

2018-06-08 Thread Cameron Simpson
(I’m working in the OS Sierra terminal.) The immediate reason that comes to mind is that there's isn't a "setup.py" file in that folder. What _is_ in that folder? We're already discussing this in another thread; it's better to keep all this stuff

Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-08 Thread Cameron Simpson
vely end of life. it runs completey fine in python 2, so for me the issue is with python 3 and its changes relative to python 2 It is possible that Python 2 is just glossing over the problem; Python 3 has a more rigorous view of character data. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-08 Thread Cameron Simpson
what I'm doing: select text in the terminal, type Cmd-C to copy it, click in my new message window and type Cmd-V to paste the copied text. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-09 Thread Cameron Simpson
ist in Desktop, then youre "mymodules" will get moved into the Desktop. However, if mv's final argument is an _existing_ directory, mv puts things inside it. So if you went: mkdir Desktop/mymodules mv mymodules Desktop/mymodules then mv would put your top level "mymodules" _inside_ the "Desktop/mymodules" folder that already exists, producing the structure you currently have. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-09 Thread Cameron Simpson
Instead, use pip's "--user" option, thus: python3 -m pip install --user vsearch-1.0.tar.gz Note: there is _no_ "sudo" command there. This command runs as you, not root, and installs in your home directory in an area for user supplied packages. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem finding my folder via terminal

2018-06-09 Thread Cameron Simpson
On 09Jun2018 22:50, Tamara Berger wrote: On Sat, Jun 9, 2018 at 5:05 AM Cameron Simpson wrote: A third possibility is that you made a mymodules somewhere else (such as in your top level home directory), and later decided to put it on your Desktop to make it easy to find/access. I did save

Re: Problem finding my folder via terminal

2018-06-09 Thread Cameron Simpson
about it makes a lot of sense. Again, thanks for all your help. No worries, that's what the list is for. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-10 Thread Cameron Simpson
der has to do something with the data: drop it or replace it with something wrong. The former loses data while the latter puts in bad data, but at least it is visible if you inspect the data later. The full documentation for Python 3's open() call is here: https://docs.python.org/3/library/functions.html#open where the various encoding= and errors= choices are described. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Posting warning message

2018-06-10 Thread Cameron Simpson
vely comfortable about spam. So when I post to a public forum I usually use my normal email address. This is a personal decision and anyone might choose differently. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Posting warning message

2018-06-11 Thread Cameron Simpson
or so and for that message choose GMail's "filter messages like this" action. I like to choose "Apply the label Python" and "Skip the inbox" for such things. Then you'll get a nice little "Python" mail folder in your collection where the list

Re: Posting warning message

2018-06-11 Thread Cameron Simpson
noring the current thread (google/groups/email) can see it and respond. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Posting warning message

2018-06-12 Thread Cameron Simpson
installing the packages in your personal Python tree. It will work just as well for almost every purpose and avoid risk to your machine's OS. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Posting warning message

2018-06-12 Thread Cameron Simpson
hange/fix as a new messge. And it works even though the messages get copied everywhere, because all that has to happen is to copy your own new message. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Posting warning message

2018-06-12 Thread Cameron Simpson
On 12Jun2018 07:14, Tamara Berger wrote: On Tuesday, June 12, 2018 at 3:28:29 AM UTC-4, Cameron Simpson wrote: On 11Jun2018 22:51, Tamara Berger wrote: [...] >192:~ TamaraB$ sudo python3 -m pip install pytest >Password: >The directory '/Users/TamaraB/Library/Caches/pip/http&

pep8 Re: Posting warning message

2018-06-12 Thread Cameron Simpson
ions that oveeride their default checks to better match my preffered code style. or am I supposed to root around for my module and make the edits one by one? Finally, no you don't normally root around and change an installed module. Instead, modify your original copy and reinstall the ne

Re: Splitting up large python module impact on performance?

2018-06-12 Thread Cameron Simpson
frequently and/or doing almost nothing after the "import" phase) or you notice a significant slowdown after your changes. And it is usually easier to stick things back together than it was to pull them apart if that happens. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Index of entity in List with a Condition

2018-06-12 Thread Cameron Simpson
evious.word == word2 and test "W.is_preceeded_by('president')". In short, write out what you would like to express. Then write methods that implement the smaller parts of what you just wrote. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

helpfulness Re: Index of entity in List with a Condition

2018-06-12 Thread Cameron Simpson
rom him, just ask without overtones. If you're unwilling to engage with his post for whatever criteria, just don't engage. Easy! It is better for all concerned, both the OP and we the list readers. Thanks, Cameron Simpson Next time, please try to present your question in a formal,

Re: Splitting up large python module impact on performance?

2018-06-12 Thread Cameron Simpson
commendations just aren't applicable.""" I may exaggerate on this a bit more if you're interested. Isn't it normal for you to exaggerate everything? Shhh! Don't discourage his restraint! Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: pep8 Re: Posting warning message

2018-06-12 Thread Cameron Simpson
he same indent as the one I just completed) and syntax highlighting, which colours keywords and identifiers and strings differently. When you make trivial mistakes like not closing a quote or misspelling a keyword or leaving off a colon there is often a visual cue. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Posting warning message

2018-06-12 Thread Cameron Simpson
ck and proofread it once more. But that would be a pain in the proverbial bifurcated derriere. Part of the experience of flaming is to load a searing missive into the conceptual breech of my SPARCcannon and pull the imaginary lanyard whilst flushed with the adrenaline of mortal combat. -

Re: Posting warning message

2018-06-12 Thread Cameron Simpson
On 13Jun2018 00:29, Tamara Berger wrote: On Tue, Jun 12, 2018 at 7:57 PM Cameron Simpson wrote: On 12Jun2018 07:14, Tamara Berger wrote: >Just one more thing, Cameron. I was looking at an Apple support page, and it says "When you're logged in to your Mac using an administ

Re: Index of entity in List with a Condition

2018-06-12 Thread Cameron Simpson
accepted. Of course, as consideration to others, I try to avoid reciting someone else's contact info unless it is already publicly in play where I am. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Splitting up large python module impact on performance?

2018-06-12 Thread Cameron Simpson
Tags files. A mapping from names to their definition lines. Tres handy. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Design of my project

2018-06-13 Thread Cameron Simpson
tside the storage class, and also leaves scrope for changing the storage mechanism later without changing the main code (eg from a conventional SQL database to some other service). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: pep8 Re: Posting warning message

2018-06-13 Thread Cameron Simpson
o. In fact, you should be doing both: run and test the code _before_ installing it, and also lint it (when you care) and test again (because if you made lint changes you want to check they haven't done something unwanted). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: pep8 Re: Posting warning message

2018-06-14 Thread Cameron Simpson
On 14Jun2018 02:35, Tamara Berger wrote: On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson wrote: Just as you can run your code before you install it, you can lint your code beforehand also. In fact, you should be doing both: run and test the code _before_ installing it, and also lint it (when

Re: pattern

2018-06-14 Thread Cameron Simpson
ntext. Where did you find this code? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to apply filters to posts

2018-06-14 Thread Cameron Simpson
;re interested in have a new reply, that thread should be up near the top. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread Cameron Simpson
That way an unhandled exception gets reported. else: os.rename(new_filename, filename + 'txt') os.rename(new_filename, path) Importantly: os.rename(path, new_filename) The old name comes first, then the new name. Also, you might want to ensure that new_filename doesn't already exist... Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to apply filters to posts

2018-06-14 Thread Cameron Simpson
your main inbox. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread Cameron Simpson
On 15Jun2018 00:24, Steven D'Aprano wrote: On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: Francois, unless your regex can cross multiple lines it is better to search files like this: with open(the_filename) as f: for line in f: ... search the line for the r

Re: pattern

2018-06-14 Thread Cameron Simpson
;word" strings. The documents list gets this tuple: (w, pattern['class']) added to it. In this way the documents list ends up with tuples of (words, classification), with the words coming from the sentence via nltk and the classification coming straight from the train item

Re: Posting warning message

2018-06-15 Thread Cameron Simpson
On 14Jun2018 21:09, Tamara Berger wrote: On Monday, June 11, 2018 at 4:32:56 AM UTC-4, Cameron Simpson wrote: This is one reason to prefer the mailing list. You can subscribe here: https://mail.python.org/mailman/listinfo/python-list [...] Wait for the first message or so and for that

Re: pattern

2018-06-16 Thread Cameron Simpson
repr(): it will print out the structure of lists and so forth, very useful. Just reviewing that loop, the logic does look a little weird to me. I think the "documents.append" should be inside the loop because otherwise it only accrues the _last_ "w" and "pattern". Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: syntax difference

2018-06-16 Thread Cameron Simpson
named", repr(name), "is", age, "years old." I'd be inclined to prefer the former one because I can see the shape of the message. Also, I notice you're using Python 2 (from the print syntax). In Python 3 we have "format strings", which let you write:

Re: syntax difference

2018-06-17 Thread Cameron Simpson
ns in a dynamic language, and type checking would impose a performance penalty for no semantic effect. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: translating foreign data

2018-06-21 Thread Cameron Simpson
esentation Can't you just read the file as a text file using the correct codepage->decoding setting to get strings, _then_ parse numbers either with some clunky regexp based approach or some flexible external library for common numeric forms? (Someone suggested babel, I'v

Re: I'm getting a spamassassin party here

2018-06-25 Thread Cameron Simpson
rlap between my problematic messages and yours. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Where's the junk coming from?

2018-06-26 Thread Cameron Simpson
what transpires. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: I'm getting a spamassassin party here

2018-06-26 Thread Cameron Simpson
On 26Jun2018 07:44, Richard Damon wrote: On 6/26/18 2:50 AM, Cameron Simpson wrote: On 24Jun2018 17:03, Gene Heskett wrote: Generally spamassassin only gets picky about this occasionally, but for the past several hours its working overtime on python list messages, with the major problem

Re: I'm getting a spamassassin party here

2018-06-26 Thread Cameron Simpson
On 27Jun2018 08:55, Cameron Simpson wrote: On closer inspection it looks like a FIDONET gateway may be the cause. I've made enquiries of ab...@news.bbs.nz and newsmas...@news.bbs.nz, and am awaiting a response. I've also asked at Castle Rock BBS, based on a different heade

Re: EXTERNAL: OSError: [Errno 48] Address already in use

2018-06-27 Thread Cameron Simpson
f you were using port 8000. This also points the way to a workaround: since you're running the script yourself on an ad hoc basis, change ports! Maybe provide the listening port on the command line, and just bump it by one when this happens. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: EXTERNAL: OSError: [Errno 48] Address already in use

2018-06-29 Thread Cameron Simpson
se both will try to use the same local port and There Can Be Only One. Do you need to run from both environments at the same time? I'd have thought not, which also leads me to: why are you flicking from IDLE to Terminal? I would have imagined using one or the other normally, not both. It i

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Cameron Simpson
27;t know what you meant exactly, although I suspect it wasn't complimentary. ;-) It tends to mean "weird", but perhaps a more nuanced phrasing might be unusual and strange, and usually connotes some degree of over complication. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: $s and %d in python

2018-06-30 Thread Cameron Simpson
lue. The variable my_height is an int, and for an int both these things are the same. Try: my_height = 7.3 and see what you get. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: .replace("a" or "b")

2018-07-02 Thread Cameron Simpson
o there's no gap in the documentation for replace: it accepts an old string and a new string. When you write: "a" or "b" you're computing that value to pass to replace _before_ replace gets called. I hope this clarifies what's going on. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: about main()

2018-07-05 Thread Cameron Simpson
s None: argv = sys.argv ... code here ... return meaningful_exit_code The "argv is None" shuffle is for PyPI packaging, where the standard script wrapper _doesn't_ pass in sys.argv, (no idea why, I should submit an enhancement proposal). Otherwise, there's argv, rea

Re: Is there a nice way to switch between 2 different packages providing the same APIs?

2018-07-05 Thread Cameron Simpson
; code should work directly, as all those names you import become simple flat names inside Qt (Qt.Qt, Qt.QIcon, Qt.QDialog, etc). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Dealing with dicts in doctest

2018-07-05 Thread Cameron Simpson
#x27;b': 2, 'c': 3} """ which is correct, *except* that dict keys have arbitrary order in the versions of Python I'm using. I have three ways of dealing with this. Which do you prefer? Option 4: >>> func(1) == {'a': 1, 'b': 2, 'c': 3} True Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Dealing with dicts in doctest

2018-07-05 Thread Cameron Simpson
On 06Jul2018 01:43, Steven D'Aprano wrote: On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: On 05Jul2018 17:57, Steven D'Aprano wrote: I have three ways of dealing with this. Which do you prefer? Option 4: >>> func(1) == {'a': 1, 'b':

Re: testing code

2018-07-05 Thread Cameron Simpson
hat is the name of the module. So that "main" function and the "if" at the bottom is standard Python boilerplate code for what you're trying to do. Import this in my test program (file/module) and then initiate calls present in the program. If there is some simpl

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

2018-07-07 Thread Cameron Simpson
stalled with "g" prefixes. It does exactly this, and has done for decades :-) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

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

2018-07-07 Thread Cameron Simpson
On 07Jul2018 20:11, Skip Montanaro wrote: Have you looked at the ptx command? Might be called "gptx" on a system with the GNU coreutils installed with "g" prefixes. Thanks, Cameron. I was unaware of it. Will check it out. BTW, it well predates the GNU coreutils; I used i

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

2018-07-07 Thread Cameron Simpson
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 "gptx" > >Thanks, Cameron. I was unaware of it. Will check it out. BTW, it well predates the

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

2018-07-08 Thread Cameron Simpson
On 08Jul2018 06:47, Tim Chase wrote: 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 cal

Re: can't install/run pip (Latest version of Python)

2018-07-15 Thread Cameron Simpson
, not a Python internal. With a transcript of what you're doing people will be better able to help you. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Reading EmailMessage from file

2018-07-15 Thread Cameron Simpson
file I do it like this: msg = email.parser.Parser().parse(msgfile, headersonly=headersonly) where `msgfile` is an open file (just "open(pathname, errors='replace')"). That returns a Message object. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-16 Thread Cameron Simpson
w you exactly what system calls the processis making. A real spin lock situation will be very apparent. 100% CPU with no system calls means a busy wait (polling). Strace is an outstandingly useful and often overlooked tool for debugging otherwise opaque behaviour. Cheers, Cameron Simpson --

Re: test for absence of infinite loop

2018-07-17 Thread Cameron Simpson
your fix in a test case? Not as time, but in loop iterations? Put a counter in the loop and check that its value doesn't exceed that. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: test for absence of infinite loop

2018-07-17 Thread Cameron Simpson
On 17Jul2018 12:39, Robin Becker wrote: On 17/07/2018 12:16, Cameron Simpson wrote: On 17Jul2018 10:10, Robin Becker wrote: A user reported an infinite loop in reportlab. I determined a possible cause and fix and would like to test for absence of the loop. Is there any way to check for

Re: doubling the number of tests, but not taking twice as long

2018-07-18 Thread Cameron Simpson
ed test though. These are filenames, yes? So shouldn't the stuff*() functions be openin the file or something: I would expect that to dominate the runtime and your extra name testing to not be the slowdown. What's going on inside the stuff*() functions? Might they also have become more complex with your new cases? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: try except inside a with open

2018-07-21 Thread Cameron Simpson
gs can go wrong, including the code _calling_ your function asking for the wrong thing. Letting the exception out lets these situations get debugged. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: import in code

2018-07-21 Thread Cameron Simpson
t. All of these situations may benefit from doing conditional or deferred imports. But try to avoid them until you have a specific need. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: import in code

2018-07-21 Thread Cameron Simpson
On 22Jul2018 14:45, Cameron Simpson wrote: Circular imports: 2 codependent modules. If you have: module A: import B module B: import B That won't work: the second import (whichever it turns out to be) will fail. One workaround is to make one of the modules put off the import. A b

Re: print & string formatting

2018-07-21 Thread Cameron Simpson
usually for (a) more complex messages or (b) separating the message format from the values. Example: print("The time is %s and the place is %s." % (when, where)) Instead of the much harder to read and maintain: print("The time is", str(when), "and the place is

Re: import in code

2018-07-23 Thread Cameron Simpson
On 22Jul2018 15:38, Mark Lawrence wrote: On 22/07/18 05:45, Cameron Simpson wrote: Circular imports: 2 codependent modules. If you have:  module A:    import B  module B:    import B That won't work: the second import (whichever it turns out to be) will fail. One workaround is to mak

why doesn't an mmap.mmap object have some kind of memoryview method?

2018-08-05 Thread Cameron Simpson
to me that a method returning a memoryview of the mapped file would be very handy here: no data copies at all, and not even any I/O unless the data are accessed. But I see no such method in the documentation. Does anyone have any insight here? Cheers, Cameron Simpson -- https://mail.python.

Re: why doesn't an mmap.mmap object have some kind of memoryview method?

2018-08-05 Thread Cameron Simpson
I should add that I'm using CPython 3 on a Mac, happy to receive CPython 3 UNIX-specific advice. - Cameron On 06Aug2018 09:28, Cameron Simpson wrote: I'm tinkering with a module which scans video files. The MP4 parser has a `discard_data` parameter which tells certain parts of the

Re: why doesn't an mmap.mmap object have some kind of memoryview method?

2018-08-05 Thread Cameron Simpson
On 05Aug2018 23:55, eryk sun wrote: On Sun, Aug 5, 2018 at 11:28 PM, Cameron Simpson wrote: It seems obvious to me that a method returning a memoryview of the mapped file would be very handy here: no data copies at all, and not even any I/O unless the data are accessed. But I see no such

QOTW! (was: NLTK)

2018-08-08 Thread Cameron Simpson
On 08Aug2018 21:03, ma...@mail.com wrote: [...] It seems that I do not really need NLTK. split() will do me. [...] +1 QOTW Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Non-unicode file names

2018-08-08 Thread Cameron Simpson
ree. Suppose you're verbally reciting a filename (or, of course, printing the filename to a voder). Only Victor Borge will provide a full verbal pronunciation of things [1] [1] https://www.youtube.com/results?search_query=victor+gorge+phonetic+punctuation Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to pass Python command line options (vs arguments) when running script directly vs via Python interpreter?

2018-08-15 Thread Cameron Simpson
benefit, but after you've done it a few times it is easy and I at least now have a suite of little modules whose components get reused all the time. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: printing to stdout

2018-08-16 Thread Cameron Simpson
om, _before_ the sleep() call: sys.stdout.flush() Your call; the performance difference will be small, so it tends to come down to keeping your code readable and maintainable. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

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