pip and venvs on Debian (was: Terminal Emulator)

2024-05-20 Thread Akkana Peck via Python-list
Alan Gauld via Python-list writes:
> On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote:
> 
> >> So venvs make managing all that pretty convenient. Dunno why everybody's 
> >> so down on venvs...
> 
> Not so much down on them, they are just one extra step that's
> mostly not needed(in my use case)

Years ago, I used to have trouble with pip install --user on Debian -- 
sometimes things would end up under .local, sometimes in other places that I've 
forgotten. So I reluctantly started using venvs.

And you know, they work fine. I have one master venv that I created with
python3 -m venv --system-site-packages ~/pythonenv/envname
and I activate that automatically when I log in, so when I need to install 
anything that Debian doesn't package, I just pip install it (no --user or 
--break-system-packages needed) and it installs to that venv.

Every so often I need to regenerate it (like when Debian updates the system 
Python version) but that's easy to do: I don't try to duplicate what's 
installed there, I just delete the old venv, create a new one and then pip 
install packages as needed.

I have a few special venvs (without --system-site-packages) for specific 
purposes, but most of the time I'm just using my default venv and it's all 
pretty transparent and automatic.

I know this isn't the usual pythonista model of "you should have a zillion 
different venvs, one for each program you use, and never use system Python 
packages", but it works well for me: my pip installed packages are all in a 
predictable place, and I get security updates for all the software Debian 
*does* package. That's my biggest beef with pip, the lack of an easy way to 
update everything at once, and it's the reason I prefer Debian packages when 
available.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about garbage collection

2024-01-15 Thread Akkana Peck via Python-list
I wrote:
> > Also be warned that some modules (particularly if they're based on 
> > libraries not written in Python) might not garbage collect, so you may need 
> > to use other methods of cleaning up after those objects.

Chris Angelico writes:
> Got any examples of that?

The big one for me was gdk-pixbuf, part of GTK. When you do something like 
gtk.gdk.pixbuf_new_from_file(), there's a Python object that gets created, but 
there's also the underlying C code that allocates memory for the pixbuf. When 
the object went out of scope, the Python object was automatically garbage 
collected, but the pixbuf data leaked. Calling gc.collect() caused the pixbuf 
data to be garbage collected too.

There used to be a post explaining this on the pygtk mailing list: the link was
http://www.daa.com.au/pipermail/pygtk/2003-December/006499.html
but that page is gone now and I can't seem to find any other archives of that 
list (it's not on archive.org either). And this was from GTK2; I never checked 
whether the extra gc.collect() is still necessary in GTK3, but I figure leaving 
it in doesn't hurt anything. I use pixbufs in a tiled map application, so there 
are a lot of small pixbufs being repeatedly read and then deallocated.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about garbage collection

2024-01-15 Thread Akkana Peck via Python-list
> Frank Millman wrote at 2024-1-15 15:51 +0200:
> >I have read that one should not have to worry about garbage collection 
> >in modern versions of Python - it 'just works'.

Dieter Maurer via Python-list writes:
> There are still some isolated cases when not all objects
> in an unreachable cycle are destroyed
> (see e.g. step 2 of
> "https://devguide.python.org/internals/garbage-collector/index.html#destroying-unreachable-objects;).

Also be warned that some modules (particularly if they're based on libraries 
not written in Python) might not garbage collect, so you may need to use other 
methods of cleaning up after those objects.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behavior of the for-else construct

2022-03-03 Thread Akkana Peck
computermaster360 writes:
> I want to make a little survey here.
> 
> Do you find the for-else construct useful? 

No.

> Have you used it in practice?

Once or twice, but ended up removing it, see below.

> Do you even know how it works, or that there is such a thing in Python?

I always have to look it up, because to my mind, "else" implies
it does something quite different from what it actually does.

Which means that even if I worked hard at memorizing what it does,
so I didn't have to look it up, I still wouldn't use it in code,
because I want my code to be easily readable (including by future-me).
for..else makes code difficult to understand by anyone who doesn't
use for..else frequently: they might be misled into misunderstanding
the control flow.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-23 Thread Akkana Peck
2qdxy4rzwzuui...@potatochowder.com writes:
> I think someone said it way upthread:  don't check, just do whatever you
> came to do, and it will work or it will fail (presumably, your program
> can tell the difference, regardless of a past snapshot of being able to
> retrieve data from an arbitrary URL).
> 
> EAFP, anyone?

Yes, but the code being discussed is still helpful, if only for
error handling: yes, the network isn't fully up, but *why" isn't it?

while True:
try:
do_whatever_I_came_to_do()
except NetworkError:
net_config_with_good_error_detection()

Aside from error handling, it's useful in a network-up script:
when you've just enabled a network, it's good to check right then if
there's a captive portal and deal with it. If you just assume that
the first thing the user wants is to go to an http: page in a
browser, and so don't bother to check for a captive portal,
that'll be annoying for people who want to fetch IMAP mail,
or run ssh, or load an https: page.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Akkana Peck
Abdur-Rahmaan Janhangeer writes:
> results = []
> with console.status("Checking internet ...", spinner="dots"):
> for domain in domains:
> try:
> requests.get(domain)
> results.append(1)
> except Exception as e:
> results.append(0)
> if not any(results):
> print('No internet connection')
> sys.exit()
> 
> gist link:
> https://gist.github.com/Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7
> 
> I think for me having the internet means ability to request urls

Request urls and get the right answer?

This won't work if you're behind a captive portal: every URL you
try to get will return successfully, but the content will be
the captive portal page.

You need to compare the output of at least one of those pages to
known output to be sure you're really connected.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue45802] MozillaCookieJar can't read cookies, should support cookies.sqlite

2021-11-13 Thread Akkana Peck


New submission from Akkana Peck :

http.cookiejar.MozillaCookieJar only reads from cookies.txt, a format that 
Mozilla hasn't used in over a decade. It should read the file mozilla actually 
uses, cookies.sqlite.

Here's some code that works to turn cookies.sqlite into cookies.txt in order to 
read it in to MozillaCookieJar:
 http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python

This was requested in 2008 in issue 2277, around the time Mozilla made the 
switch. The issue was rejected back then because it was too late to make the 
final beta for Python 2.6/3.0. I'd like to bring it up again now.

I can write a patch (since a real fix should read the cookies into the 
cookiejar directly, not use StringIO to create an intermediate cookies.txt) if 
there's any chance it would be accepted.

--
components: Library (Lib)
messages: 406288
nosy: akkana
priority: normal
severity: normal
status: open
title: MozillaCookieJar can't read cookies, should support cookies.sqlite

___
Python tracker 
<https://bugs.python.org/issue45802>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Selenium py3.8+ DepreciationWarnings - where to find doc to update code?

2021-10-16 Thread Akkana Peck
jkk writes:
> Selenium 3.141+
> python 3.8+
> ubuntu 20.04 or windows 10
> 
> I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several 
> DepreciationWarnings.
> 
> Can someone point me to where I can find the documentation that explains how 
> to to remedy these warnings. What are the new preferred coding practices?

I've also been looking for that (Selenium 4.0.0a1, Python 3.9.5,
Ubuntu 21.04). For instance:

>>> from selenium import webdriver
>>> profiledir = "/path/to/profile/dir"
>>> driver = webdriver.Firefox(firefox_profile=profiledir)
:1: DeprecationWarning: firefox_profile has been deprecated, please pass 
in a Service object

What is a Service object and how do you use it to pass in profiles?
I've found API references like
https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/Service.html
https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.service
but how do you create one, or use it to reference a specific profile?
I haven't been able to find any examples. 

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: XAMPP control panel python

2021-07-19 Thread Akkana Peck
Mike Easter writes:
> the CP readme says:
> 
> To run the XAMPP Control Panel, you will need:
> 
>  Linux (may work on other OSs)
>  GTK 2.x
>  PyGTK (also known as python-gtk) 2.x
>  XAMPP
> 
> I installed py2 to my Linux Mint Cinnamon 20.2 (off Ub LTS 20.04) but that
> didn't solve the problem w/ running the .py file w/ python2; I got a
> traceback saying there was no gtk module.  The pip I have is for py3. I can
> put the .py file on pastebin if anyone wants.

Unfortunately python-gtk has been dropped from the last few Ubuntu
releases. I assume Mint must have followed suit. Nobody seems to
know why they dropped python-gtk while keeping other python2 packages.

Pip2 wouldn't have helped you; the pip version of python-gtk didn't
build on Linux even back when python2 was still supported.

The place where this gets the most discussion is the GIMP community,
so it may help to add gimp to your web search terms, e.g. search on
gimp python2 mint ppa
and you'll find lots of discussions on how to get python-gtk.

There are various repositories that still maintain builds of python-gtk:
for instance, see
https://ubuntuhandbook.org/index.php/2020/07/ppa-install-gimp-2-10-20-ubuntu-20-04/
or the python-gtk2_2.24.0-5 packages at
http://mirrors.edge.kernel.org/ubuntu/pool/universe/p/pygtk/

Good luck!

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Replacement for pygtk?

2020-09-05 Thread Akkana Peck
Grant Edwards writes:
> Is pygobject the replacement for pygtk?

The easiest way to use it, if you want a quick port with the
fewest code changes, is:

from gi import pygtkcompat
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

I don't know if pygtkcompat is going to be supported forever, or
will eventually be deprecated, but it does make porting very easy.
The harder way,

from gi.repository import Gtk

(plus Gdk, GdkPixbuf, Pango, PangoCairo etc.) might be more
future-proof but requires more porting effort.

Grant Edwards writes:
> I assume that difference is because pygtk was hand-written and gi is
> built auto-magically using SWIG or something like that?

Right. Which also has the unfortunate side effect that gi-imported
libraries usually have no built-in documentation -- you can't learn
much by typing help(object) or help(classname) in the Python console.
So you usually have to use the C documentation and guess at the
Python signatures.

> For native Linux apps I definitely prefer Gtk.  The other choices are
>extra complexity doesn't ever seem to buy me anything except
>MS-Windows compatibility [which did matter for a few of the apps I
>used to maintain].  The last time I looked into Gtk on Windows, it
>didn't sound usable, but that was many years ago.

A few years ago, pip install pygtk worked on Windows for gtk2 (in
fact, it *only* worked on Windows; it didn't work on Mac or Linux).
I suspect you can install the new gi version of GTK3 etc. via pip3,
but I haven't actually verified that.

On Mac, python-gtk2 was extremely difficult to install. I hope
python3/gi/GTK3 is easier. You can install these packages via pip
now on Linux, so I'd hope that's true on Mac as well.

>  * PyQt -- I run Gtk-centric Linux systems, and the second you try to
>use one Qt widget, it always seems to pull in hundreds of packages
>that take a week to build.

I haven't generally found that about PyQt. Most KDE apps do pull in
hundreds of packages, but I haven't had to install that many just to
use PyQt. I usually prefer GTK, but there are a few things PyQt
offers that aren't available in GTK any more, like an HTML
browser/viewer: python-webkit was only available for Python2
and there seems to be no GTK web viewer option now, whereas
PyQt5.QtWebEngineWidgets allow for a reasonably functional, if not
particularly well documented or configurable, HTML viewer.

>  * WxPython ­- It's bigger and far more complex than pygtk/gi and
>  [ ... ]
>  * Tkinter -- It's ugly on Linux (yea, I know there are supposed to be

TkInter and WxPython are fine for bringing up a quick window, but
when I've tried to use them for more complex apps, I usually
hit limitations in low-level areas like event handling or window
management. Though admittedly it's been years since I tried to write
anything nontrivial in either one, and they may have matured.

Grant Edwards writes:
> I'm still trying to figure out to "freeze" the size of a button so
> that when I change its contained label text on-the-fly it doesn't
> resize and shift everying else slightly.  I don't remember that
> happening with gtk2 (which I can no longer run), but I've no idea
> why...

If you figure that out, let me know: I have a couple of apps that
have that problem as well, and I've just been putting up with it.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What kind of magic do I need to get python to talk to Excel xlsm file?

2020-09-01 Thread Akkana Peck
Steve writes:
> Glutton for punishment, I am looking into designing another .py program.  I
> would like to pull two columns of information from Excel but the more I look

I've found the xlrd module easy to use for extracting data from
Excel files. But I've only used it on .xsl and .xsls. I've never
encountered a .xlsm, but a web search tells me that extension means
it has macros, and if you want macros to be executed, that may be
quite a bit more difficult.

One person says xlrd works for xlsm:
https://stackoverflow.com/questions/23554808/how-to-extract-sheet-from-xlsm-and-save-it-as-csv-in-python
and the discussion also includes an example using pandas. So now
you have three possible options (including the openpyxl someone
else suggested).

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread Akkana Peck
> > On 2020-08-11 02:20, Ganesh Pal wrote:
> > > How do I check if it the value was  (a) i.e string started and ended
> > > with a quote

Of course the original question was simple and there have been lots
of solutions given.

But I find this comes up periodically, and I'm always leery of using
something like line.replace("'", "").replace('"', '') because it
gets not only quote pairs, but things like "unmatched quotes'
or "it's a contraction".

I was thinking shlex had something like this, but it doesn't (it
can do the opposite, add quotation marks with appropriate escaping).
So I did a little playing around with re.sub.

At first I tried:
line = re.sub('"([^"]*)"', "\\1", line)
line = re.sub("'([^']*)'", "\\1", line)
which works for simple cases, but it can't detect apostrophes
properly, so it didn't work for one of my test strings,
"This one's apostrophe is in a more 'difficult' place."
(it sees the apostrophe as an open single quote, closes it
before difficult, leaving the one after difficult as an apostrophe).

Then I tried to use \b:
line = re.sub('\\b"([^"]*)"\\b', "\\1", line)
line = re.sub("\\b'([^']*)'\\b", "\\1", line)
but punctuation isn't considered part of a word, so it didn't work
right for strings like "some word."

I decided that really, the important thing was that the open quote
can't have an alphanumeric before it, and the end quote can't have
an alphanumeric after it:
line = re.sub('\W"([^"]*)"\W', "\\1", line)
line = re.sub("\W'([^']*)'\W", "\\1", line)
but no, that wasn't quite right since it didn't pick up quotes at
the beginning or end, and it loses some spaces too.

After some fiddling I ended up with
line = re.sub('(^|\W)"([^"]*)"(\W|$)', "\\1\\2\\3", line)
line = re.sub("(^|\W)'([^']*)'(\W|$)", "\\1\\2\\3", line)
which seems to work pretty well.

Any suggested improvements? I find this comes up now and then, so I'm
going to keep this around in my library for times when I need it,
and I'm sure there are cases I didn't think of. (And yes, I know
this is overkill for the original poster's question, but when I
need this I usually want something a little smarter.)

I've appended my test program below.

...Akkana

import re

s = '''Here are some strings.
"This string is quoted with double-quotes."
"Same, except this time the end quote is inside the period".
'This one is quoted with singles.'
"This has one of each and so shouldn't be changed.
"This has 'single quotes' inside double quotes, and it's got an apostrophe too."
"This one's apostrophe is in a more 'difficult' place."
'This has "double quotes" inside single quotes.'
'''

def remquotes(line):
"""Remove pairs of single and/or double quotes from the string passed in.
   Try to preserve things that aren't quotes, like parentheses.
"""
line = re.sub('(^|\W)"([^"]*)"(\W|$)', "\\1\\2\\3", line)
line = re.sub("(^|\W)'([^']*)'(\W|$)", "\\1\\2\\3", line)

return line

if __name__ == '__main__':
for line in s.split('\n'):
print(remquotes(line))

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?

2020-08-07 Thread Akkana Peck
I wrote:
> > > Trying to maintain that recursive list of unclosed lists in your
> > > brain is fun. It stretches the brain in interesting ways.
> > > [ ... ] But I never found Lisp code very maintainable, [ ... ]

2qdxy4rzwzuui...@potatochowder.com writes:
> "[R]ecursive list of unclosed lists"?  Can you (whoever you are) expand
> on that?  Yes, if you eschew helper functions and local variables, then
> you can end up with depply nested code, but that's true in any language.

To pick a function that I know is readily available in lots
of languages, let's look at a couple implementations of the
Haversine function (from http://rosettacode.org/wiki/Haversine_formula).
Comments to illustrate language differences are mine.

Here's the Common Lisp version.

(defparameter *earth-radius* 6372.8)
(defparameter *rad-conv* (/ pi 180))
;; Minor complication right off: assignment of variables or constants
;; is completely different depending on whether you're
;; defining something in general, like here, or only for
;; a subsequent clause, like the let* functions later on.

(defun deg->rad (x)
  (* x *rad-conv*))
;; Prefix notation for arithmatic is unfamiliar to most people
;; since that's not what we learn in school, so that's a first
;; hurdle for readability.

(defun haversine (x)
  (expt (sin (/ x 2)) 2))
;; To grok this function you need to have four levels of
;; parentheses simultaneously open in your head.

(defun dist-rad (lat1 lng1 lat2 lng2)
  (let* ((hlat (haversine (- lat2 lat1)))
;; Then there's the let vs. let* issue,
;; no big deal for experienced programmers
;; but not entirely easy to explain to a beginner.
;; On the other hand, Python has its own confusing points on
;; that issue, like when you need to specify "global".
 (hlng (haversine (- lng2 lng1)))
 (root (sqrt (+ hlat (* (cos lat1) (cos lat2) hlng)
   ;; for that expression you need 7 levels of mental parens open
(* 2 *earth-radius* (asin root

(defun dist-deg (lat1 lng1 lat2 lng2)
  (dist-rad (deg->rad lat1)
(deg->rad lng1)
(deg->rad lat2)
(deg->rad lng2)))

;; End Lisp example

Seven levels of unclosed lists that you need to keep in your head
in order to read and understand the program at its deepest point.

Here's the same thing in Python:

from math import radians, sin, cos, sqrt, asin
 
def haversine(lat1, lon1, lat2, lon2):
R = 6372.8  # Earth radius in kilometers
 
dLat = radians(lat2 - lat1)
dLon = radians(lon2 - lon1)
lat1 = radians(lat1)
lat2 = radians(lat2)
 
a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2
c = 2 * asin(sqrt(a))
 
return R * c

# end Python example

The equation is still the same equation, but it looks a lot more
like the equation you'd see in a math textbook, or write on a
homework assignment, modulo notational issues like ** instead of
superscripts. The deepest level of parentheses you ever need to
keep in your head is two, but the second level is just a very
simple function call, sqrt(a). The indentation level (the program
structure) never gets beyond one.

On the other hand, your brain does need to keep track of more
intermediate variables (dLat, dLon etc.) Perhaps some people might
find that harder.

And yes, you could write the Lisp to look more like the Python or
vice versa. You're welcome to try that, but I predict you'll find that
even if you use the same number of intermediate variables, Lisp will
always require you to keep that larger mental stack of open parens.

> Because of Lisp's simple syntax, text editors can nearly completely
> relieve the programmer from the tedium of indenting and formatting, and
> even closing parenthesis, which also highlights missing/extra/unbalanced
> parentheses pretty quickly.

I find that emacs mostly does a pretty good job of figuring out
indentation, closing parentheses, highlighting syntax errors and
similar boilerplate in Python. Maybe you need a smarter text editor?

But my comment about levels of parens had nothing to do with editors.
To understand the code, you need to build up that list/tree
structure in your head, because that's what defines the program logic.

Again, my point isn't that Python is a better or simpler language
than Lisp. It's that it stretches the brain in different ways, and that
I would guess (but it's just a guess) that most beginners will find
the Python approach more intuitive and easier to learn, since it
emphasizes things they've done before (simple declarative statements,
equations written out in a familiar way) rather than new and unfamiliar
concepts (prefix notation, deeply nested parentheses, tree structures).

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?

2020-08-06 Thread Akkana Peck
Christian Seberino writes:
> Python is my favorite language and the easiest to use in my opinion.
> 
> Lisp has a far simpler grammar and syntax.   A beginner I think could
> learn Lisp much faster than Python.
> 
> Therefore, it seems like Lisp *should* be easier to work with and more 
> readable.  I don't feel like it is easier to use but I can't see *why* that 
> is.

First, everybody's brain is different so be cautious of sweeping
statements. What's true for one person isn't necessarily true for another.

That said, for me, Lisp's simpler syntax arises from the fact that
there's basically one data structure: a list. To do anything in
Lisp, you have to think in lists, map everything to lists (including
the program's own structure), build up list-based data structures in
your head. It's also functional and recursive, which means that as
you're programming, you have to maintain a stack (which is also a
list) in your head of all the lists that aren't yet closed. Of
course, you can use tricks like let and setq to hold intermediate
variables and mitigate that a little, but that isn't really Lispish.

Trying to maintain that recursive list of unclosed lists in your
brain is fun. It stretches the brain in interesting ways. I was
way into Lisp at one point, including writing several Lisp
interpreters (that simple structure makes Lisp very easy to
implement). But I never found Lisp code very maintainable, because
any time you read a program, you have to build up that list in your
head every time just to follow the logic structure and figure out
what the return value will be. I suspect most people find that more
difficult than reading an inherently procedural language like
Python. I know I do.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need to 'import gtk' on Ubuntu 20.04, what do I need?

2020-07-23 Thread Akkana Peck
Chris Green writes:
> I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
> 20.04.  [ ... ]
> The error I am getting is:-
[ ... ]
> ImportError: No module named gtk
> 
> So what do I need to install on my Ubuntu 20.04 system to provide the
> gtk module?  

Ubuntu doesn't provide python-gtk any more at all. Which makes a
number of programs rather difficult now ...

> Alternatively (but much harder work) what is the Python 3 equivalent
> of the the Python 2 pygtk and gtk modules.

... because there is no close equivalent. In Python 3, GTK is
accessed via something called GObject Introspection (module "gi")
which requires significant changes to code beyond the usual 2to3
Python migration.

You might be able to get the program working using pygtkcompat.
Try inserting these lines near the beginning of the program:

from gi import pygtkcompat
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

If that doesn't work, you might be able to get the old Python 2/GTK 2
packages working by installing these two files with dpkg -i.
No warranty of safety or efficacy implied.

http://mirrors.kernel.org/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-6_amd64.deb
http://mirrors.kernel.org/ubuntu/pool/universe/g/gimp/gimp-python_2.10.8-2_amd64.deb

Good luck! It was a nasty shock discovering that Ubuntu had removed
python-gtk, especially since they kept lots of other python2 packages
(I could have understood it if they'd removed python2 entirely).
I don't know what the reasoning was for removing python-gtk while
keeping python2.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Troubleshooting

2019-12-13 Thread Akkana Peck
Michael Torrie writes:
> On 12/12/19 6:33 PM, Python wrote:
> > What happened exactly? Did you download the official installer from
> > python.org, then click on next, next, next, checking the box (if it's
> > still there about updating PATH)? There is nothing more to do.
> 
> I've seen github bug reports about Windows launching the store when
> trying to run Python, but those appear to be after a successful
> installation, and the solution there is making sure the installed
> version of Python is set in the $PATH.

I installed Python on a Windows 10 box for the first time a few weeks
ago (normally I'm a Linux user and get Python via distro packages).

Typing "python" at a command prompt before installing anything
gave a prompt for the MS store.

If you run an installer from Python.org, the checkbox to add to the
system path is not at all obvious. It's at the very bottom of a long
scrolled list of options, *and it's the only one not checked by
default*. The first time I installed, I looked at the list, scrolled
down a little way and concluded that all options were checked,
so I didn't scroll down to the bottom to notice the one crucial
un-checked one. (Go ahead and think poorly of me for making
assumptions, but I'm sure I'm not the only person to do that.)
And of course, the install didn't work and I had to reinstall.
Fortunately I know what a path is and knew to hunt for that the
second time through; I doubt a typical Windows person knows about paths.

It would make the install a lot easier for less technical Windows
people if the installer had a separate screen for the path option,
perhaps with an explanation of what path means (and that if you don't
understand the explanation, you really, really should check the box).
Or enable it by default -- would anyone besides an expert user
want it disabled? Or at least put it first in the long list of
options, so it always shows.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Testing a TestPyPI package with dependencies

2019-12-09 Thread Akkana Peck
I'm a novice packager, trying to test a package I built and
uploaded to TestPyPI. It has dependencies and I want to make
sure my setup.py works before uploading to the real PyPI.

https://packaging.python.org/guides/using-testpypi/
says that if a package has dependencies, to use this command to get
the package from TestPyPI while getting dependencies from PyPI:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url 
https://pypi.org/simple your-package

That doesn't seem to work, though. It seems like it never checks
pypi.org and looks for everything in test.pypi.org. Here's what I'm
doing, starting from a new virtualenv:

..
$ python3 -m venv /tmp/test3env

$ source /tmp/test3env/bin/activate

(test3env) $ pip install wheel
Collecting wheel
  Using cached 
https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.33.6

(test3env) $ pip install --index-url https://test.pypi.org/simple/ 
--extra-index-url https://pypi.org/simple pytopo==1.6.1
Looking in indexes: https://test.pypi.org/simple/, https://pypi.org/simple
Collecting pytopo
  Using cached 
https://test-files.pythonhosted.org/packages/1d/dd/f46722bed2296676053b333a97babf05cb31b20e4a621161d44399a3ed18/pytopo-1.6.1-py3-none-any.whl
Collecting simplejson (from pytopo)
Could not install packages due to an EnvironmentError: 404 Client Error: 
Not Found for url: https://test.pypi.org/simple/simplejson/
..

I can pip install simplejson without errors, so I know it's in PyPI.
(If I then try the install again, it fails on pycairo, same error.)

Am I misunderstanding that packaging.python.org guide, or making
some silly typo? Is there a trick it doesn't mention to getting pip
to use both PyPI and TestPyPI?

Thanks for any suggestions!

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Recommendations for intro to python+programming lecture to Humanities MA students

2019-11-20 Thread Akkana Peck
Chris Angelico writes:
> On Thu, Nov 21, 2019 at 4:42 AM Nick Sarbicki  
> wrote:
> > RE Conda and distros - I'd forget about them, in my experience you may as
> > well learn to use pip and install what you need that way, in the long term
> 
> Agreed. 

More agreement. Someone at the local makerspace recently tried to
teach a beginning Python class; the first hour and a half lecture
was entirely devoted to trying to get Anaconda installed on
everyone's machines, and most of the people still didn't have it
installed by the end. I heard a lot of the people from the first
lecture gave up and didn't come back for the second lecture because
they still didn't have a working environment. Of the people who did
return, I saw some of them (fairly technical users to begin with, just
not in Python) later struggling with conda updates that went wrong.

Installing Python on Windows isn't trivial, but if you lead them
through each of the steps (hint: be sure not to miss the small
checkbox about adding Python to the path -- you have to scroll down
to the bottom of the options list to see it, and it's not checked by
default) it shouldn't be too bad. Also, have a copy of the installer
available on a USB stick or three unless the lecture hall is
guaranteed to have flawless wi-fi.

Can you get a couple of Windows and Mac using friends (who don't
already have Python) to help you try out the installers before the class?
Or, for Windows, you could try one of these virtualbox images:
https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

> In fact, given the tight context here, I would go even further
> and stick to JUST the standard library - there's already way more in
> there than you need for a single lecture. Maybe just name-drop pip and

For a general Python class I'd agree, but since these are linguists,
it will help to have a linguistics package or two to show how Python
can help them in their work.

That means that if you don't use conda, you should probably have
them create a virtualenv so they can run pip safely.

> > In summary I'd aim to inspire not to teach - so show some basics at the
> > beginning to show how accessible it can be, and then feel free to jump off
> > into advanced python land to showcase what is possible using whatever you
> > are most comfortable with. Essentially show them they can learn python, and
> > then inspire them to want to learn python.
> 
> Absolutely agreed. Your job is not to turn them into programmers. Your
> job is just to inspire them - to show them possibilities, to excite
> them, to empower them to play.

More agreement.

But that's why it's important to have linguistics packages. If you
can give them a simple program that actually does something useful
and relevant to their jobs, that will be a lot more inspiring than
implementing Hello World or Fibonacci numbers or even web scraping.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: question about making an App for Android

2019-10-11 Thread Akkana Peck
> pyotr filipivich 
> >"A simple program" to divide the amount of "today's" daylight into 12
> >even '"hours", so that Dawn begins the First hour, the third hour is
> >mid-morning, noon is the middle of the day, the ninth hour mid after
> >noon, and the twelfth hour ends at sunset.  Is simple, no?  {no.}

Dennis Lee Bieber writes:
>   Even ignoring "phone" this is anything but simple. It relies upon
> knowing one's latitude and date to allow computing the angle of the sun.
[Details of some excellent references -- I like Duffett-Smith's
calculator book best for readability).

But if you don't need it to be a phone app, if you use PyEphem, it's
all simple and you don't need to know any of the equations behind
it. So it really depends on your goals and what you want to learn.

> >But getting from the development environment (the desktop) to the
> >phone is something I am clueless about.
> 
>   Getting anything that is not written in Java onto an Android phone is
> likely going to be a pain. You will most likely need an environment that
> runs on ARM architecture. And I have no idea what iOS requires.

For an app with a relatively simple user interface, you can write a
web page in HTML/Javascript and make it installable on both Android
and iOS. Google "Progressive Web App" for details. Although it means
you can't use Python (alas!), it's *much* simpler than dealing with
either an Android Java devkit or a cross-platform setup like Kivy.
I've used PWAs for simple astronomy programs like showing Jupiter's
or Saturn's moons.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handle foreign character web input

2019-06-28 Thread Akkana Peck
On Sat, Jun 29, 2019 at 6:31 AM Tobiah  wrote:
> Also, what do people do when searching for a record.
> Is there some way to get 'Ronngren' to match the other
> possible foreign spellings?

SequenceMatcher in difflib can do fuzzy string comparisons and
should work for cases like that. There are other methods too --
include "fuzzy" in your web searches and you'll probably find
several options.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes:
> Actually, only the Python interpreter has to be able to do those
> steps. That's why I put the comment *on the same line* as the import
> statement (not immediately above it, for instance). It comes out like
> this:
> 
> (env) rosuav@sikorsky:~/shed$ python3 BL2_find_items.py
> Traceback (most recent call last):
>   File "BL2_find_items.py", line 19, in 
> import lzo # ImportError? pip install python-lzo
> ModuleNotFoundError: No module named 'lzo'
> (env) rosuav@sikorsky:~/shed$

Oh, I see: because it prints the full line that caused the exception.
Clever!

> > for regular users, when you know an error is both likely and unclear
> > to read, it might make sense to catch the exception and print
> > a clearer message.
> 
> Define "clearer", though. Given that many MANY users won't read *any*
> error message, the clarity becomes largely moot, and only a handful of
> people will (a) read what you print out, (b) be able to resolve the
> problem, and (c) not be able to figure it out from four lines of
> output.

When writing programs for general use (which this admittedly wasn't),
it seems sad to accept unclear errors on the assumption that some
users don't read error messages. Even most of the nontechnical
users I know will read a one-line error message, though they
certainly wouldn't try to read a 4-line stack trace. I usually try
to catch errors that I expect will be common, and print something
clearer than the default traceback.

> Indeed. But the biggest argument in favour of this style of thing is
> that it requires almost zero effort and has almost zero code
> readability cost. Imagine having half a dozen dependencies and tagging
> each one with a comment like mine... and now imagine having to bracket
> each one of them with a try/except and an appropriate message.

Certainly. I don't use try/except on imports in general. And I
like your short form, and there are definitely places where I'll use
that now where a try/except would have been overkill.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes:
> I write this as:
> 
> import whois # ImportError? pip install python-whois
[ ... ]
> it means that normal exception handling is still
> happening (which might be important if I import this into something
> else), plus it's printing the message to stderr rather than stdout
[ ... ]
> About the only downside is that it assumes the .py file is available -
> this won't work with a .pyc-only setup.

It also assumes the user is capable of (1) finding the .py file
(maybe not so easy if it's imported from another program) and
(2) knowing Python well enough to find and understand the line with
the comment. Which in my example is not a problem since I'm probably
the only user of my domaincheck script; but when writing programs
for regular users, when you know an error is both likely and unclear
to read, it might make sense to catch the exception and print
a clearer message.

Your counterarguments are quite valid, though. It's a trade-off.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
DL Neil writes:
> On 18/04/19 8:44 AM, Grant Edwards wrote:
> >   2. When the program can still do something useful (if perhaps
> >  feature-limited) without the imported module by substituting
> >  something else in its place.
> 
> Any (publishable) examples?

One of the targets my RSS fetching program supports is Plucker on
PalmOS, which used to be how I read RSS feeds back in the day
(nowadays I use simplified HTML on Android). Plucker on Palm had
problems with accented characters, so I added a little module called
ununicode to translate strings to plain ASCII (so á would become a).
For most target platforms, it was a nonissue.

try:
import ununicode
has_ununicode = True
except ImportError as e:
has_ununicode = False

def output_encode(s, encoding):
if encoding == 'ascii' and has_ununicode:
return ununicode.toascii(s, in_encoding=encoding)
else:
return s

The program still worked fine if the module wasn't there, it just
wrote accented characters because it couldn't simplify them.

And yes, it could have tested "if 'ununicode' in sys.modules" instead
of setting a variable; I didn't know about that at the time.

> but... what of the third inherent assumption: that the user(s) will be able
> to handle the situation (discussed in another msg 'here')?

One example: there are a gazillion whois modules, and when I run my
domaincheck program on a machine where I haven't yet installed
whois, it's helpful to have a reminder of which one I should
install. (Of course, if you have one of the other whois modules
installed, the program will fail somewhere else.)

try:
import whois
# python-whois from pypi, not whois from pypi or python-whois from debian
# https://bitbucket.org/richardpenman/pywhois
except ImportError:
print("Couldn't import whois. Try: pip3 install python-whois")
sys.exit(1)

The third case has already been mentioned: modules that change name
but don't change their APIs much.

# Tkinter changed capitalization from Python 2 to Python 3.
try:
import tkinter
except ModuleNotFoundError:
import Tkinter as tkinter

I thought I had examples for gtk and qt -- GUI libraries change
their import syntax a lot -- but I can't find them.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handy utilities = Friday Filosofical Finking

2019-03-29 Thread Akkana Peck
DL Neil writes:
> How do you keep, use, and maintain those handy snippets, functions,
> classes... - units of code, which you employ over-and-over again?

Fun topic!

I have two methods:

First, in my scripts directory I have a file called
"python-cheatsheet.py" where I save small tips that I
think I might not remember; mostly 2- to 5-liners.

Second, I wrote a script called langgrep that searches in known
places for files written in a specified language (it looks at file
extensions and shebangs), then greps for a pattern in all those
files. It looks in ~/bin plus a set of other directories, like
certain projects under ~/src.

So for instance if I'm trying to remember the syntax to read a CSV
file as a dictionary, I might run

langgrep python csv.DictReader
or
langgrep python -i csv | grep -i dict

Since you asked about importing libraries: in my ~/bin I have a
directory pythonlibs, which is in my PYTHONPATH, where I put
(usually symlinks to) python files and packages I use regularly
that aren't installed systemwide.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I wrote a free book about TDD and clean architecture in Python

2019-03-20 Thread Akkana Peck
> On 20/03/19 7:18 AM, Leonardo Giordani wrote:
> > Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub 
> > processing chain (I believe, I'll have a look just to be sure). I hope the 
> > book will be useful even with this little issue. Thanks for reading it!

DL Neil writes:
> Yes, I'm happy reading from cover-to-cover. Unfortunately, not being able to
> refer back to (say) the Mocks chapter, means it will be of little utility
> (to me) in-future. 

For what it's worth, the epub version has chapter links that work
fine. So maybe you could download the epub version, and use calibre's
ebook-convert to make a mobi version?

Nice book, Leonardo. I haven't finished part 2 yet, but part 1
inspired me to go write some new tests for some of my existing programs,
and I'm planning to try test-first development for my next project.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is your experience porting Python 2.7.x scripts to Python 3.x?

2019-01-22 Thread Akkana Peck
Grant Edwards writes:
> On 2019-01-22, Schachner, Joseph  wrote:
> 
> > For anyone who has moved a substantial bunch of Python 2 to Python
> > 3, can you please reply with your experience?
> 
> If you used bytes (or raw binary strings) at all (e.g. for doing
> things like network or serial protocols) you're in for a lot of pain.
> 
> Everything else is pretty minor.

2to3 handles most porting issues nicely. The three pain points I've
hit are the bytes vs strings vs unicode problem Grant mentions;
GUIs in either Qt or (especially) GTK; and networking, anything that
uses urllib, urllib2 or related libraries. For those three issues I
usually have to do a lot of porting and debugging by hand, and a lot
of testing afterward because there are always problems that crop up
later upon discovering that the Python3 version of some library is
returning bytes when Python3 wants chars, or some such.

If you don't have automated tests set up, consider writing some now,
before you start porting, with particular emphasis on anything that
gets data from a network or writes it to a file.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get the terminal's size

2019-01-16 Thread Akkana Peck
> On Mon, 14 Jan 2019 11:57:33 +, Alex Ternaute wrote:
> 
> > Hi there,
> > 
> > I want to know the number of columns of the terminal where python2 writes 
> > it's outputs.

A couple days late to the party, a discussion of several ways I tried:
http://shallowsky.com/blog/hardware/serial-24-line-terminals.html
and the script I ended up with:
https://github.com/akkana/scripts/blob/master/termsize

(I've only tested these on Linux).

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiple JSON documents in one file, change proposal

2018-12-01 Thread Akkana Peck
Grant Edwards  writes:
> This is what "archive" file formats are for.  Just use tar, zip, ar,
> cpio, or some other file format designed to store multiple "files" of
> arbitrary data -- there are plenty of "standard" formats to choose
> from and plenty of libraries to deal with them.

Then the data files wouldn't be human readable, making debugging
a lot more hassle.

Cameron Simpson writes:
> There's a common format called Newline Delimited JSON (NDJSON) for just this
> need.
> 
> Just format the outbound records as JSON with no newlines (i.e. make the
> separator a space or the empty string), put a newline at the end of each.
> 
> On ingest, read lines of text, and JSON parse each line separately.

I'll second that. It's very easy to deal with. A shorter name for it
is JSONL -- I use .jsonl for filenames.
https://en.wikipedia.org/wiki/JSON_streaming#Line-delimited_JSON
discusses that as well as several other solutions.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing clipboard through software built on Python

2018-10-28 Thread Akkana Peck
Tim Daneliuk writes:
> However, the highlighted text must be copied explicitly:
> 
> Highlight
> Ctl-C
[ ... ]
> X actually has several clipboard buffers and it can be tricky to get this 
> going.  I don't recall,
> but either clipboard or pyperclip have a way to get to them all IIRC ...

To get the highlighted text in X without needing a copy, you want the
PRIMARY X selection rather than CLIPBOARD.

I think pyperclip can get it (it uses an external program like xsel,
and xsel can get any of the three X selections), or you can get the
selection using a GUI library like GTK, Qt or Tk. Some examples:
https://github.com/akkana/scripts/blob/master/pyclip

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2018-09-04 Thread Akkana Peck
Skip Montanaro writes:
> > 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.

Yahoo and Google both used to offer APIs for financial data, and
matplotlib (later moved into a separate module, mpl_finance) used to
have a Python wrapper around Yahoo's API; but Yahoo shut their
financial API down in mid-2017 and Google followed suit soon after. See:
http://www.financial-hacker.com/bye-yahoo-and-thank-you-for-the-fish/

The comments include links to a lot of possible alternatives.
Most of them require API keys and some charge a fee.
You should probably try several to find out which works best
for you, and expect to update your code every year or two as
financial quote services seem to come and go.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Writing bytes to stdout reverses the bytes

2018-08-20 Thread Akkana Peck
> Thomas Jollans :
> > Wonderful. Now why don't we all forget about hexdump and use xxd? ;-)

Marko Rauhamaa writes:
> Fedora:
> 
>$ xxd
>bash: xxd: command not found
>$ hd
>bash: hd: command not found
>$ od -Ax -tx1z -v <<00 68 65 6c 6c 6f 0a>hello.<
>06

Or, since this is Python, why be frustrated over imperfect command
output when you can write something that gives whatever format you
like best?  Long ago the old Unix od used to give something like this,
and when I was learning Python writing it seemed like a good exercise:

$ bdump hello
>hello.<   ^J 
  20   3e   68   65   6c   6c   6f   2e   3ca 
  32   62  104  101  108  108  111   46   60   10 

https://github.com/akkana/scripts/blob/master/bdump

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to decide (and know) which Python GTK version to use?

2018-07-30 Thread Akkana Peck
Chris Green writes:
> I wrote a Python GUI program a little while ago that uses Python GTK
> with:-
> 
> import gtk
> 
> I *think* this is probably GTK 2, or something.  I can't find the
> proper documentation for this.  Is it old/obsolescent?

Yes, it's obsolete, and AFAIK it only works with Python 2, making
it even more obsolete; but the documentation is at
https://developer.gnome.org/pygtk/stable/

> I'm just starting to write another program now and I seem to be using
> GTK 3 (maybe!) by doing:-
> 
> import gi
> gi.require_version('Gtk', '3.0')
> from gi.repository import Gtk
> 
> Is this the right/best place to be?

Yes, this is the future, since it lets you use both GTK3 and Python3.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ongoing browser projects

2018-07-23 Thread Akkana Peck
> > On 23/07/18 03:43, Akkana Peck wrote:
> >> You'd think there would be something newer (ideally
> >> based on Blink) that worked with GTK3/GIO, but I never found anything.

Thomas Jollans writes:
> > This gi-based example looks like Gtk3, right?
> 
> https://gist.github.com/kklimonda/890640#file-pybrowser-py-L14

Sure enough, that works, at least with the webkit in Debian's
gir1.2-webkit-3.0 package. It didn't work with gir1.2-webkit2-4.0:
  File "", line 888, in _find_spec"
  AttributeError: 'DynamicImporter' object has no attribute 'find_spec'
and then various further errors resulting from those; but at
least it's possible to make a Python 3, GTK3, webkit 3.0 browser.
And it even handles fullscreen events (like from youtube), something
I've never managed in QtWebEngine.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ongoing browser projects

2018-07-22 Thread Akkana Peck
> On 22/07/18 21:43, Abdur-Rahmaan Janhangeer wrote:
> > i need an html renderer (one of the most badly missed features of py, PEP
> > anyone?)

I think both GTK and Qt have basic HTML rendering widgets, for
simple tasks, but if you want something that behaves more like
a browser (javascript, link following, events), those probably
won't be good enough.

Thomas Jollans writes:
> Nobody writes browser engines. It's too hard to do what the available
> open source ones do half as well as they already do it.
> 
> You can use webkit (of safari/chrome/etc. fame), or you can use gecko
> (mozilla). Webkit is easy to embed with PyQt or PyGObject/gtk+3. I don't
> know about gecko.

More specifically, QtWebEngine under PyQt5 (possibly also PyQt4).
The documentation is scanty, and doesn't cover Python at all, only
C++, but it works very well, using Blink (the library behind
Chromium) so it handles nearly all modern web pages.

There used to be a Python-WebKit-GTK2 library that was fairly easy
to use and even had documentation, but it's been orphaned for years,
and in any case a lot of the modern web no longer works with the old
WebKit engine. You'd think there would be something newer (ideally
based on Blink) that worked with GTK3/GIO, but I never found anything.
I don't know of any way to use Gecko from Python (except, of course,
sending remote commands to Firefox).

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multi-threading with a simple timer?

2018-07-03 Thread Akkana Peck
David D wrote:
> Is there a SIMPLE method that I can have a TIMER count down at a user input
> prompt - if the user doesn't enter information within a 15 second period, it
> times out.

Does this do what you want?

from threading import Timer
import sys
import os

def run_later():
print("Timed out!")

# sys.exit doesn't kill the main thread, but os._exit does.
os._exit(1)

if __name__ == '__main__':
t = Timer(15, run_later)
t.start()
ans = input("Enter something, or time out in 15 seconds: ")
print("You entered", ans)
t.cancel()
sys.exit(0)

The only problem with that is if you want to continue with execution
after the timeout (you didn't say what you want to do in that case).
I couldn't find any straightforward way to interrupt the main thread
in a way that interrupts the input(). There's something called
_thread.interrupt_main() but it doesn't seem to work with
threading.Timer threads; maybe it would work if you created the
timer thread using _thread. Or signals, of course, as already discussed.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue5978] cProfile and profile don't work with pygtk/pyqt and sys.exit(0)

2009-05-09 Thread Akkana Peck

New submission from Akkana Peck akkzi...@shallowsky.com:

I was following the steps at http://docs.python.org/library/profile.html
to try to profile a pygtk program, but it wasn't working -- I was
getting no output at all from either cProfile or profile.

The problem turned out to be that I was exiting by calling sys.exit(0),
because that's what most pygtk programs I'd seen were doing. Changing
that to gtk.main_quit() made profiling work (but it took a long time to
track that down).

Apparently the same thing happens in pyqt if you call sys.exit(0).

--
components: Demos and Tools
files: pywin
messages: 87504
nosy: akkana
severity: normal
status: open
title: cProfile and profile don't work with pygtk/pyqt and sys.exit(0)
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file13943/pywin

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5978
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com