Set tkinter top-level window to "always on visible workspace"

2022-03-27 Thread Skip Montanaro
I have a tkinter app (Ubuntu/X11 env) whose main window should always be displayed on the currently visible workspace. Is there some way to set that attribute programmatically? I see that there is a tkinter.Wm class and that Toplevel widgets have a wm_attributes method, but haven't found any exampl

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-27 Thread Skip Montanaro
> So you might tell your window manager to keep that window on the main workspace. Thanks. I'd forgotten about the possibility of doing this sort of thing in the window manager config. That would certainly be fine in this case. (It's been ages since I messed with this sort of thing.) Skip -- htt

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-28 Thread Skip Montanaro
> I might be misguided, but on modern desktops that should be possible > with a few mouseclicks. E.g. in KDE, there is a little pin icon > displayed in every title bar of a toplevel window on the left side. Correct, and that's what I'm currently doing. I'm lazy though. I want the program to start

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-28 Thread Skip Montanaro
> I think you must be using xfce4, not fvwm4 (there's an fvwm3 in > development). See https://xfce.org/ Both? % pgrep -fla xfwm4 1803 xfwm4 --replace 539426 xfwm4-settings % pgrep -fla xfce 1599 xfce4-session 1755 /usr/bin/ssh-agent /usr/bin/im-launch startxfce4 1782 /usr/lib/x86_64-linux-gnu/xf

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-28 Thread Skip Montanaro
> Would you accept a solution that involves a subprocess call? > > wmctrl -ir {id} -b add,sticky I'm already checking idle time with xprintidle(1), so what's one more (one-time) subprocess call? Small amount of history, I'm referring to this mouse/typing watcher: https://github.com/smontanaro/py

Re: Set tkinter top-level window to "always on visible workspace"

2022-03-29 Thread Skip Montanaro
> Also, wmctrl accepts window names instead of ids if you omit the -i > option. In case winfo_id() is not returning the id you need. Nice. That worked. FWIW, Tk never gave me the very outermost window as the parent of the tkinter.Tk instance. Here's the start of hierarchy: % xwininfo -tree xwini

Re: asyncio+tkinter

2022-03-31 Thread Skip Montanaro
> > > Given that both asyncio & tkinter are modules in the standard lib and > both > > have event loops, I would have expected to find some "best practice" > > solution to mixing the two. > > Agreed. For GTK, you can use a dedicated loop policy like this: > > import asyncio_glib > asyncio.set_event

Converting PyMember_Get usage to PyMember_GetOne - no docs?

2016-10-01 Thread Skip Montanaro
I'm trying to convert the python-sybase module C code from oldish Python 2 usage to work in Python 3. The code currently calls PyMember_Get(), which is obsolete. In later versions of Python 2, PyMember_GetOne became the official way to do things, the the former function was still available. In Pyth

Re: Lawrence D'Oliveiro

2016-10-02 Thread Skip Montanaro
On Sun, Oct 2, 2016 at 1:05 AM, Bob Martin wrote: > It's in several of the groups that I follow. Yeah, we've been struggling with it over at mail.python.org. While incoming mail has all sorts of spam fighting bells and whistles, messages arriving from Usenet only has the SpamBayes filter. I'm s

Re: Lawrence D'Oliveiro

2016-10-02 Thread Skip Montanaro
If you have one or more of these messages saved, please forward it along to me (in its entirety, headers and all). Attaching it as a compressed tar file will help sneak it past other spam filters. Thanks, Skip On Sun, Oct 2, 2016 at 8:00 AM, Skip Montanaro wrote: > > On Sun, Oct 2, 201

Re: Italian libel spam

2016-10-02 Thread Skip Montanaro
On Sun, Oct 2, 2016 at 9:14 AM, Marko Rauhamaa wrote: > I'd imagine just having a list of 100 Italian words should give you a > pretty accurate spam score. Extra points for all caps. > Thanks, but that's not how SpamBayes works. Have a look here if you're interested: http://www.spambayes.org/

Re: print to previous line in console

2016-10-03 Thread Skip Montanaro
> When we are printing to the console, is there a way to display to the > previous line in the console. Check out the curses module: https://docs.python.org/3.6/library/curses.html Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: print to previous line in console

2016-10-03 Thread Skip Montanaro
On Mon, Oct 3, 2016 at 10:23 AM, udhay prakash pethakamsetty wrote: > Hi skip, > > I am unable to even install that curses package > > > C:\>pip install curses > Collecting curses > Could not find a version that satisfies the requirement curses (from > versions: ) > No matching distribution foun

repr/str diff between Python 2 and 3

2016-10-11 Thread Skip Montanaro
I'm trying to port some code from Python 2 to 3, and beyond the usual mechanical stuff, I've encountered a difference between the str() of floats. Here's an example. In Python 3 I get: >>> print(repr(27.04 - 0.01)) 27.028 >>> print(str(27.04 - 0.01)) 27.028 but in Python 2

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Skip Montanaro
> https://docs.python.org/3/whatsnew/3.1.html > > It's the third hit when searching for 'float'. Assuming I understand what it's saying. ;) Thanks. Is that the "David Gay's algorithm"? That seems to apply only to repr(), while the change I observed was in str(). Skip -- https://mail.python.or

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Skip Montanaro
> Only that one should not rely on ‘str’ preserving the value accurately, > as documented in Python 2. Sure, but this choice is out of my hands. It's csv.writerow that calls str(), not me. I could probably subclass csv.writer and csv.DictWriter, and override the writerow method, but I would prefer

Re: repr/str diff between Python 2 and 3

2016-10-12 Thread Skip Montanaro
Thanks everyone. I'm not going to try to be too cute, and will just change my test case. I'm leaving Python 2 behind in this particular case for now anyway. I can always return to the issue if I decide I need Python 2.7 support at some point in the future. Skip -- https://mail.python.org/mailman/

Re: Without compilation, how to find bugs?

2016-10-13 Thread Skip Montanaro
> I can execute the script without any problem and I will not notice the bug until I > test exactly the erroneous line of code (the call with only one argument). The key phrase there being "until I test..." There are static analysis tools for Python like pylint. Given this simple module: #!/usr/

Re: Without compilation, how to find bugs?

2016-10-13 Thread Skip Montanaro
One other thing. The OP mentioned coming from C. If you are old enough, you will remember that many errors caught by gcc and other modern compilers used to be detected by external checkers like lint. Most Makefiles had "lint" targets in them. So although you might associate all sorts of error dete

Re: Namespace for timeit

2016-10-14 Thread Skip Montanaro
> timeit('sorter( array, size )', number=1) I'm not a timeit whiz, but I'm kind of surprised there isn't a call form where it goes something like timeit(callable, *args, ...) There is a globals keyword argument though. I think you could probably call it with globals=locals() in your case

Re: New to python

2016-10-17 Thread Skip Montanaro
> So to learn this language is there an online > tutorial? Yup, go to https://docs.python.org/3/ and check out the tutorial links. Also, if you want useful replies in the future, please provide a valid email address. A private reply to this particular question would have been better than bombing t

Lua tutorial help for Python programmer?

2016-11-07 Thread Skip Montanaro
I just got Lua scripting dumped in my lap as a way to do some server side scripting in Redis. The very most basic stuff isn't too hard (i = 1, a = {"x"=4, ...}, for i = 1,10,2 do ... end), but as soon as I get beyond that, I find it difficult to formulate questions which coax Google into useful sug

Re: Lua tutorial help for Python programmer?

2016-11-08 Thread Skip Montanaro
On Tue, Nov 8, 2016 at 2:12 AM, Andrea D'Amore wrote: > There's lua-list, I figure all your questions fit better there than here. > There's the official wiki on lua-users [1], I don't know about a > Py-Lua Rosetta Stone. Thanks. I asked here specifically because I was interested in Lua from a Pyt

Re: is modulefinder.ModuleFinder working at all?

2016-11-09 Thread Skip Montanaro
I've not used it before, but I suspect it's meant to be used in "freeze" type environments. In that situation, you really do want everything reachable, whether the script imported it or not. It doesn't take much to wind up importing much of the stdlib either. Try: python -m modulefinder -m /path/t

Re: Python rules!

2016-11-09 Thread Skip Montanaro
> Too bad that the indentation is still not actually significant. One little > undetectable mistake with the braces and the meaning of the code is totally > changed. Maybe an Emacs mode which can toggle between "Java view/mode" (normal) and "Python view/mode" (Rustom's Twitter example) would be us

Re: Python rules!

2016-11-09 Thread Skip Montanaro
On Wed, Nov 9, 2016 at 7:53 PM, Chris Angelico wrote: > It's called Jython. :) Well, sure, but that didn't look enough like Python, so no chance that I would mistake it for Jython. I suspect that whoever worked out that arrangement of semicolons and braces had some help from her tools. Skip --

Re: Python rules!

2016-11-10 Thread Skip Montanaro
Alister> i think whoever did that WAS a tool Perhaps, but maybe she is a Python programmer forced to write Java (not Jython). If so, props to her for making the best of a bad situation. :-) Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Numpy slow at vector cross product?

2016-11-21 Thread Skip Montanaro
Perhaps your implementation isn't as general as numpy's? I pulled out the TestCross class from numpy.core.tests.test_numeric and replaced calls to np.cross with calls to your function. I got an error in test_broadcasting_shapes: ValueError: operands could not be broadcast together with shapes (1,2

Re: Numpy slow at vector cross product?

2016-11-22 Thread Skip Montanaro
> I'm simply suggesting there is plenty of room for improvement. I even showed a version that did *exactly* what numpy does (AFAIK) that was three times the speed of numpy even executed by CPython. So there is some mystery there. As I indicated in my earlier response, your version doesn't pass all

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-05 Thread Skip Montanaro
On Mon, Dec 5, 2016 at 10:49 AM, Steve D'Aprano wrote: > > In DOS, it might be the dir command itself. The disadvantage of the DOS way > of doing this is that *every single command and application* has to > re-implement its own globbing, very possibly inconsistently. That's a lot > of duplicated w

"Best" websocket implementation for Python 2.x?

2016-12-07 Thread Skip Montanaro
I've recently inherited a small bit of code which uses websockets. I think the package it uses is Horoki Ohtani's package dating from 2010. I have v. 0.34.0. Looking on PyPI, I see another websocket package (not Ohtani's) with a version of 0.2.1 (also dating from 2010, I believe). These two packag

Re: "Best" websocket implementation for Python 2.x?

2016-12-07 Thread Skip Montanaro
PyPI came back. A bit more sleuthing suggests that the websocket-client package on PyPI is Ohtani's package, and is more up-to-date than the copyright notices would suggest. The package was updated a few days ago on GitHub. Taking the path of least resistance (no changes necessary to the code), I

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Skip Montanaro
On Wed, Dec 7, 2016 at 12:17 PM, Anton Mamaenko wrote: > Wow... this thread gets to finally become a holy war. It's not like this particular holy war is new, either. I'm sure it was beaten to death in the days before Windows was a thing. As I indicated in an earlier note, VMS and Unix did command

Re: Get min and max dates

2016-12-08 Thread Skip Montanaro
Datetime has greater range I believe. I can't paste from my work computer, but try this: min(datetime.datetime.strptime(s, "%d-%b-%Y") for s in dts) You should get the 1908 date instead of the 1969 date. In general, you should always use datetime instead of time for doing date manipulation and d

Re: MacOSX SpeechRecognition installation problems

2016-12-08 Thread Skip Montanaro
Sorry, I haven't been following this thread carefully. Michael's use of "sudo" caught my eye though. I know virtualenv might be "special", but shouldn't this work? pip install --user virtualenv It will wind up in $HOME/.local/lib/python2.7/site-packages (or similar) I believe. Skip On Thu, Dec

Re: CLP stats: last 500 posts

2016-12-10 Thread Skip Montanaro
On Sat, Dec 10, 2016 at 4:28 AM, Terry Reedy wrote: >> comp.lang.python is a mirror of the python-list at python dot org mailing >> list, which has an official web archive: >> >> https://mail.python.org/pipermail/python-list/ > > > These slanderous posts, in particular, are hand-removed from the a

OT - "Soft" ESC key on the new MacBook Pro

2016-12-13 Thread Skip Montanaro
I know this isn't a Python-specific question, but i got zero useful responses from the help-gnu-emacs list for some reason. I think this expression should not evaluate to the empty set: set(python_programmers) & set(emacs_users) & set(new_macbookpro_owners) Hopefully there are a few people out th

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-14 Thread Skip Montanaro
> If you need a full time ESC key then you are just "typing it wrong" as Steve > Jobs > would say if he wasn't dead. Shouldn't the use of ESC, C-[, Alt, or some other mapped key be treated as a valid personal preference? I've been using some variety of Emacs (there have been many) since the earl

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-14 Thread Skip Montanaro
On Wed, Dec 14, 2016 at 11:40 AM, Peter Pearson wrote: > Train your fingers to use C-[. As I recall, the location of the Ctrl key was one of the differences between Sun and PC101 keyboards. Doesn't matter so much now, as Sun has gone the way of the dodo, but it moved around more for me than ESC o

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-18 Thread Skip Montanaro
> +1 for knowing where CTRL should be. Bonus +1 for having used an ASR33. ;-) I'm sure I must have used an ASR33, but can't recall what it might have been connected to. I do remember using card punch machines for IBM 360 input in 1972 at USC, and toggling front panel switches for binary input on

US/Eastern offset

2016-12-22 Thread Skip Montanaro
In a small application I realized I needed all my timestamps to have timezone info. Some timestamp strings come in with no TZ markings, but I know they are US/Eastern. so, I built one: >>> import pytz >>> tz = pytz.timezone("US/Eastern") >>> tz What's with those extra four minutes? Here is one s

Re: dateutil timezone question

2016-12-23 Thread Skip Montanaro
> I need to compare these datetimes, and if I do that I get the dreaded > "can't compare offset-naive and offset-aware datetimes" error. If you're sure the naive datetimes are UTC, this should work: import pytz dt = pytz.utc.localize(dateutil.parser.parse('2016-04-27T00:00:00')) You can then co

Re: US/Eastern offset

2016-12-23 Thread Skip Montanaro
Okay, problem solved. My thanks to Chris Barker over on the Anaconda group for help. (I originally thought there might be something amiss with the pytz package in Anaconda, as our older non-Anaconda Python seemed not to have the problem.) It turns out to be a problem I solved several years ago at m

Re: dateutil timezone question

2016-12-23 Thread Skip Montanaro
> I did mess around with pytz a bit but I was getting a lot of > exceptions - something related to the TZ already being set or > something like that. I don't recall exactly, and I can't scroll back > far enough to find it. Yes, if the tzinfo attribute has already been set, you will get errors from

encoding="utf8" ignored when parsing XML

2016-12-27 Thread Skip Montanaro
I am trying to parse some XML which doesn't specify an encoding (Python 2.7.12 via Anaconda on RH Linux), so it barfs when it encounters non-ASCII data. No great surprise there, but I'm having trouble getting it to use another encoding. First, I tried specifying the encoding when opening the fil

Re: encoding="utf8" ignored when parsing XML

2016-12-27 Thread Skip Montanaro
Peter> Isn't UTF-8 the default? Apparently not. I believe in my reading it said that it used whatever locale.getpreferredencoding() returned. That's problematic when you live in a country that thinks ASCII is everything. Personally, I think UTF-8 should be the default, but that train's long left t

Re: The hardest problem in computer science...

2017-01-06 Thread Skip Montanaro
"VT52 special graphics characters", anyone? Credit where credit is due. Who hasn't borked their output and wound up with their VT(52|100) in graphics mode? :-) https://en.wikipedia.org/wiki/VT52 Skip -- https://mail.python.org/mailman/listinfo/python-list

timers in threaded application

2017-01-12 Thread Skip Montanaro
I know signals and threads are a bad mix, but I only discovered I was playing with fire a few minutes ago. I've been using the websocket-client library (https://pypi.python.org/pypi/websocket-client/) to interact with another system at work. It implements its own event loop, but doesn't seem to pla

Re: timers in threaded application

2017-01-13 Thread Skip Montanaro
On Fri, Jan 13, 2017 at 3:23 AM, dieter wrote: > If what you want to timeout are not I/O operations, you can have a > look at "threading.Timer". It uses a separate thread, lets it wait > a specified time and then starts a specified function, unless > "cancel"ed. > Ooh, hadn't considered that. Th

Re: Is it possible to get the Physical memory address of a variable in python?

2017-01-23 Thread Skip Montanaro
On Mon, Jan 23, 2017 at 12:49 PM, Chris Angelico wrote: > > On Tue, Jan 24, 2017 at 4:49 AM, Sourabh Kalal wrote: > > how we can access the value from using id.. > > like x=10 > > id(x) > > 3235346364 > > > > how i can read value 10 using id 3235346364 > > No, you can't. That isn't a memory addre

Re: Is it possible to get the Physical memory address of a variable in python?

2017-01-23 Thread Skip Montanaro
On Mon, Jan 23, 2017 at 2:17 PM, Chris Angelico wrote: >> There. *Now* you have an address. Hack to your heart's content. > > No, you now have a hexadecimal representation of an integer. You missed my attempt at levity, I think. S -- https://mail.python.org/mailman/listinfo/python-list

Re: How coding in Python is bad for you

2017-01-24 Thread Skip Montanaro
I have nothing to add to the discussion other than too note that Gmail marks many of the messages as spam. :-) Skip -- https://mail.python.org/mailman/listinfo/python-list

Strategies when hunting for dictionary corruption

2017-02-06 Thread Skip Montanaro
I'm wrapping some C++ libraries using pybind11. On the pybind11 side of things, I've written a simple type converter between Python's datetime.date objects and our internal C++ date objects. The first thing the type converter needs to do is to insure that the datetime C API is initialized: if

Futurize maps StringIO.StringIO to io.StringIO

2018-03-07 Thread Skip Montanaro
I had some deja vu recently, cuz of this old thread: https://mail.python.org/pipermail/python-list/2013-May/648245.html Today the context is different, but the problem remains the same. One of the futurize refactoring tools converts usage of StringIO.StringIO to io.StringIO, which, given that the

Unnoticed traceback in a thread

2018-03-08 Thread Skip Montanaro
I have a program which is almost always running in a single thread. It uses a daemon thread (via threading.Timer) to periodically checkpoint some state. The program runs for days at a time. Over the past couple days, two instances of the subthread croaked with tracebacks because while they were it

Re: Futurize maps StringIO.StringIO to io.StringIO

2018-03-08 Thread Skip Montanaro
Thanks. In one instance I used six.StringIO, which seems to work. The question I had was more why futurize makes a transformation which is an obvious semantic change. Skip On Thu, Mar 8, 2018, 7:55 PM Mark Lawrence wrote: > On 08/03/18 02:34, Skip Montanaro wrote: > > I had som

Re: Unnoticed traceback in a thread

2018-03-11 Thread Skip Montanaro
> Concretely: instead of "start_new_thread(my_thread_function, ...)", > I use > > def wrapped_thread_function(*args, **kw): > try: > my_thread_function(*args, **kw) > except: > ... do whatever is necessary should "my_thread_function" fails ... > >

Re: Enumerating all 3-tuples

2018-03-12 Thread Skip Montanaro
>>> 4 (0, 0, 1) >>> 9 (0, 0, 1) >>> 18 (0, 0, 2) >>> 32 (0, 0, 2) > > I spy duplicates. I didn't realize we'd started playing "I Spy ." ​ ​ Skip -- https://mail.python.org/mailman/listinfo/python-list

logging.FileHandler diff Py2 v Py3

2018-04-03 Thread Skip Montanaro
I've encountered a problem in an application I'm porting from Python 2.7 to 3.6. The logginng.FileHandler class likes "/dev/stderr" as a destination in Python 2, but complains in Python 3. Python 2.7.14: >>> import logging >>> logging.FileHandler("/dev/stderr") Python 3.6.4: >>> import logging

Re: logging.FileHandler diff Py2 v Py3

2018-04-03 Thread Skip Montanaro
> > >> I think the culprit is io.open() rather than the logging module. Why > does > Thanks, Peter. It never even occurred to me to look at the source code around the call. I saw open() and thought "built-in open". I forgot that the io package supplanted a bunch of lower level i/o. I'll poke arou

Re: logging.FileHandler diff Py2 v Py3

2018-04-05 Thread Skip Montanaro
> I'll poke around a little and maybe open a bug report if I can't find any > explanation for the change in behavior. Turns out to be a known problem with a bit of history: https://bugs.python.org/issue27805 Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Filtering computer.lang.python

2018-04-11 Thread Skip Montanaro
> I fetch comp.lang.python from eternal.september with leafnode, and after > 30 years of Usenet I recently had to install a news filter to remove the > garbage. After the initial flurry the filter doesn't need much updating, > but here's why it's necessary: ... > for totals of 2168 fetched and 438

The basics of the logging module mystify me

2018-04-18 Thread Skip Montanaro
This session is from Python 3.6.5 on Linux: >>> import logging >>> log = logging.getLogger() >>> log.level 30 >>> logging.WARN 30 >>> log.warn("Awk! Goodbye...") Awk! Goodbye... >>> log.level = logging.INFO >>> log.info("Awk! Goodbye...") >>> log.level 20 >>> log.level == logging.INFO True >>> log

Re: The basics of the logging module mystify me

2018-04-20 Thread Skip Montanaro
> I've no idea what setting log.level does; I would normally use > logging.basicConfig to set that sort of thing. > > logging.basicConfig(level=logging.INFO) The log.level setting is what calling log.setLevel(...) does under the covers. What neither apparently do is have any effect on whatever han

detect laptop open/close from within Python?

2018-04-26 Thread Skip Montanaro
I'm going through a bout of RSI problems with my wrists, so klst night I refreshed an old typing watcher program I wrote a couple decades ago (there's a comment about Python 1.4 in the code!): https://github.com/smontanaro/python-bits/blob/master/watch.py It's far from perfect and I'm sure miles

Re: detect laptop open/close from within Python?

2018-04-26 Thread Skip Montanaro
> No idea if it'll work on your system, but on my laptop, there's a > pseudo-file /proc/acpi/button/lid/LID0/state that has whether the lid > is open or closed. Thanks, I do have that. Now to figure out when it changes state... Unfortunately, the timestamp on the file seems to update continuously,

Re: detect laptop open/close from within Python?

2018-04-26 Thread Skip Montanaro
> Thanks, I do have that. Now to figure out when it changes state... > Unfortunately, the timestamp on the file seems to update continuously, > not just on state changes. Maybe /proc/acpi/wakeup will be of some > use. It appears that I can, at least some of the time. Might need to check it more fr

Tk covering the entire screen

2018-05-04 Thread Skip Montanaro
I have a little typing watcher (buggy as can be, nearly 20 years old): https://github.com/smontanaro/python-bits/tree/master/watch It does the trick most of the time, so I ignore the bugs for the most part. I had to drag it out last week after my wrists started flairing up again. I moved it to P

Re: Tk covering the entire screen

2018-05-04 Thread Skip Montanaro
I forgot to mention that when running on Linux (displaying back on Windows), the Python 3 version (3.6.4, Tk 8.6) does cover all three screens. The Windows Python 2.7.14 version with Tk 8.5 has problems. -- https://mail.python.org/mailman/listinfo/python-list

Re: Tk covering the entire screen

2018-05-06 Thread Skip Montanaro
> Try to upgrade to 2.7.15. It should be shipped with Tk 8.6. Thanks. I'm using an internal (to work) Anaconda distro at work. Hopefully it will update soon. Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Tk covering the entire screen

2018-05-07 Thread Skip Montanaro
On Sun, May 6, 2018 at 6:47 PM Skip Montanaro wrote: > > Try to upgrade to 2.7.15. It should be shipped with Tk 8.6. > > Thanks. I'm using an internal (to work) Anaconda distro at work. Hopefully > it will update soon. > ​I got everything up-to-date, but still the cover

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Skip Montanaro
> > This gave the following error: > > Syntax Error: invalid token: C:\Users\Virgil Stokes\Desktop\Important > Notes_Files\CheckProcessingDate_02.py, line 7, pos 17 > d0 = date(2018,02,01) > Note that this is a Python syntax error. It actually has nothing to do with the datetime module. In Python

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Skip Montanaro
> I wonder why someone would take a feature generally agreed to be a > poorly designed feature of C, and incorporate it into a new language. I think you might be looking at a decision made in the late 1980s through a pair of glasses made in 2018. As a C programmer back then I never had a problem

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Skip Montanaro
> This whole thread is reminding me PHP 2, which would magically treat > the second parameter of ChMod() as octal, because clearly if weak > typing is good then *no* typing must be best of all! >ChMod($filename, 644); // second parameter is actually 420 base 10 I knew there was a reason I nev

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Skip Montanaro
> Bear in mind that Unix file modes are traditionally written in octal, > because they have no meaning as numbers. They're more like > enumerations, or bitfields. The current chmod(2) man page says that the type of the second is mode_t, but back in the early days, it appears it was just declared t

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-11 Thread Skip Montanaro
> > And, if it is really necessary to retain > octal, why not preface it with anything BUT a "0". > I believe "0o" offers some symmetry with the "0x" prefix used for hex literals. (And "0b" for binary.) It's a bit unfortunate that zero and capital "oh" are visually so similar. Not much to be done

What's the rationale for b"..." in this example?

2018-05-15 Thread Skip Montanaro
Consider this: >>> bytes("abc", encoding="utf-8") b'abc' Looks reasonable. Then consider this: >>> str(bytes("abc", encoding="utf-8")) "b'abc'" Why is the b'...' bit still there? I suppose it's because I didn't tell it explicitly how to decode the bytes object, as when I do, I get the expected

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Skip Montanaro
> Personally, I never use the str(..., encoding="...") notation; I prefer to use the > .decode() method of the bytes object. Thanks. And thanks for the other responses. I obviously didn't have my thinking cap on this morning. (It was too late in the morning to plead lack of coffee.) Skip -- http

logging date format with milliseconds and timezone

2018-05-17 Thread Skip Montanaro
It seems that the logging.Formatter class uses two formats by default to format a time, default_time_format (%Y-%m-%d %H:%M:%S) and default_msec_format (%s,%03d). The former is a format string for time.strftime (and thus can't represent fractions of a second). The latter accomplishes that, but expa

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

2018-05-19 Thread Skip Montanaro
As Chris indicated, you'll have to figure out the correct encoding. You might want to check out the chardet module (available on PyPI, I believe) and see if it can come up with a better guess. I imagine there are other encoding guessers out there. That's just one I'm familiar with. Skip -- https:

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

2018-05-20 Thread Skip Montanaro
> how exactly am i supposed to find oout what is the correct encodeing? It seems you are a Python beginner. Rather than just tell you how to use this one module, I'll point you at some of the ways to get help through Python. * On pypi.org, search for "chardet" and see if the author provided onlin

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

2018-07-07 Thread Skip Montanaro
I just generated a static website which is nothing more than around ten years of email messages from a defunct vintage bike mailing list (170k messages, one per file). Though I've submitted the front page URL to both Google and Bing, I was thinking that it would be handy to have something like a st

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

2018-07-07 Thread Skip Montanaro
> 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. Skip -- https://mail.python.org/mailman/listinfo/python-list

Is this a known futurize problem?

2018-07-12 Thread Skip Montanaro
I'm using futurize to update the SpamBayes codebase to Python 3. It doesn't seem to properly handle code which already has __future__ imports. When it wants to insert imports, it blindly puts them ahead of the earliest import, even if it happens to be a __future__ import. For example, here's the fi

Re: Google weirdness

2018-07-13 Thread Skip Montanaro
> euhh where is the original mail, may i ask? Gmail routed the original to my spam folder. Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Google weirdness

2018-07-13 Thread Skip Montanaro
> btw google wants to hide even the mention of it? -- https://mail.python.org/mailman/listinfo/python-list

Re: Guido van Rossum resigns as Python leader

2018-07-14 Thread Skip Montanaro
> Is it irrational to wonder whether projects should be looking to migrate to > new languages? This kind of announcement makes me worry for the future. Umm, yeah. The language is stable, widely used packages are stable. Guido actually has little involvement in the larger Python ecosystem. It's not

Reading EmailMessage from file

2018-07-15 Thread Skip Montanaro
I have an email message in a file (see attached). According to this page: https://docs.python.org/3/library/email.examples.html something like this should construct an email message from the file: >>> from email.message import EmailMessage >>> msg = EmailMessage() >>> fp = open("/home/skip/tmp/7

Re: Reading EmailMessage from file

2018-07-15 Thread Skip Montanaro
> What are you actually trying to do? You're talking like you're trying > to read an existing RFC822 email-with-headers from a file, but you're > showing code that creates a new email with body content set from > a file, which is a completely different thing. Yes, that's exactly what I'm trying to

Why did logging not undergo PEP8 API change?

2018-07-30 Thread Skip Montanaro
In the run-up to Python 3, the threading module's API went from a Java-reminiscent set of names to a PEP-9 set of names, so threading.currentThread became threading.current_thread. Also (though they didn't get a change in case), some of the set/get methods in threading.Thread received the property

lxml namespace as an attribute

2018-08-15 Thread Skip Montanaro
Much of XML makes no sense to me. Namespaces are one thing. If I'm parsing a document where namespaces are defined at the top level, then adding namespaces=root.nsmap works when calling the xpath method. I more-or-less get that. What I don't understand is how I'm supposed to search for a tag when

Re: lxml namespace as an attribute

2018-08-15 Thread Skip Montanaro
Ack. Of course I meant the subject to be "XML namespace as an attribute". I happen to be using lxml.etree. (Long day, I guess...) S On Wed, Aug 15, 2018 at 4:25 PM Skip Montanaro wrote: > > Much of XML makes no sense to me. Namespaces are one thing. If I'm > parsing a d

Re: lxml namespace as an attribute

2018-08-15 Thread Skip Montanaro
> See https://lxml.de/tutorial.html#namespaces and > https://lxml.de/2.1/FAQ.html#how-can-i-specify-a-default-namespace-for-xpath-expressions > for direction. I had read at least the namespaces section of the tutorial. I could see the namespace definition right there in the XML and figured somehow

Re: lxml namespace as an attribute

2018-08-16 Thread Skip Montanaro
> You seem to think that you need to take the namespace definitions > from the XML document itself. This is not the case: you can > provide them from whatever soure you want. I was under the impression that XML was a self-describing format. I've been disabused of that notion. Skip -- https://mai

Re: Hi I'm trying to get live data from stock using python , is it possible?

2018-09-04 Thread Skip Montanaro
> I want to know if AAPL is more than value 300 and if it does I want it to > send to me mail with gmail :) . thanks for the help.. Try searching pypi.org for "finance", then scroll through the many returned packages. A few show how to get stock data from Yahoo! or Google. Skip -- https://mail.

Re: Hi I'm trying to get live data from stock using python ,

2018-09-05 Thread Skip Montanaro
> I want to know if AAPL is more than value 300 and if it does I want it to send to me mail with gmail :) . thanks for the help.. Try searching pypi.org for "finance", then scroll through the many returned packages. A few show how to get stock data from Yahoo! or Google. Skip -- https://mail.py

Re: ESR "Waning of Python" post

2018-10-12 Thread Skip Montanaro
themselves in the foot. When your code is called, the GIL insures that nobody else can stomp on your data when you are executing. Skip Montanaro -- https://mail.python.org/mailman/listinfo/python-list

Getting Pandas NaT to propagate like NaN

2018-10-30 Thread Skip Montanaro
I'm trying to take the min and max of a couple Pandas Series objects in the face of NaT. np.minimum and np.maximum work the way I want if the elements are floats. For example: >>> s1 00.0 11.8 23.6 35.4 dtype: float64 >>> s2 010.0 117.0 2 NaN 314.0 dtype: float64 >>

What Python books to you recommend to beginners?

2018-11-28 Thread Skip Montanaro
I've been using Python since long before Mark Lutz's book was first released, so I've never paid much attention to what's out there. Still, every now and then, someone asks me for a recommendation (as just happened a few minutes ago). "Learning Python" was last released in 2013 (Python 3.3), so lac

Transparently treating tar files and zip archives as directories

2019-01-06 Thread Skip Montanaro
I find it useful in some of the work I do to treat Zip archives as if they were directories. I don't think it would be too difficult to make it pretty much transparent, so that you could execute something like: fileobj = magic_open("/path/to/some/archive.zip/some/internal/path/magic.txt") or equi

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