[issue45723] Improve and simplify configure.ac checks

2022-01-11 Thread Ant Man


Change by Ant Man :


--
nosy: +alwaysasetup

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



[issue45723] Improve and simplify configure.ac checks

2022-01-11 Thread Ant Man


Change by Ant Man :


--
components: +2to3 (2.x to 3.x conversion tool), Argument Clinic, C API, 
Cross-Build, Demos and Tools, Distutils, Documentation, Extension Modules, 
FreeBSD, IDLE, IO, Installation, Interpreter Core, Library (Lib), Parser, 
Regular Expressions, SSL, Subinterpreters, Tests, Tkinter, Unicode, Windows, 
XML, asyncio, ctypes, email, macOS
nosy: +Alex.Willmer, asvetlov, barry, dstufft, eric.araujo, ezio.melotti, 
koobs, larry, lys.nikolaou, mrabarnett, ned.deily, pablogsal, paul.moore, 
r.david.murray, ronaldoussoren, steve.dower, terry.reedy, tim.golden, vstinner, 
yselivanov, zach.ware

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



[issue45723] Improve and simplify configure.ac checks

2022-01-11 Thread Ant Man


Change by Ant Man :


--
type: enhancement -> security

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



[issue46314] Stray RESUME opcode for unused lambda

2022-01-11 Thread Ant Man


Change by Ant Man :


--
components: +2to3 (2.x to 3.x conversion tool), Argument Clinic, Build, C API, 
Cross-Build, Demos and Tools, Distutils, Documentation, Extension Modules, 
FreeBSD, IDLE, IO, Installation, Library (Lib), Parser, Regular Expressions, 
SSL, Subinterpreters, Tests, Tkinter, Unicode, Windows, XML, asyncio, ctypes, 
email, macOS
nosy: +Alex.Willmer, asvetlov, barry, dstufft, eric.araujo, ezio.melotti, 
koobs, larry, lys.nikolaou, mrabarnett, ned.deily, paul.moore, r.david.murray, 
ronaldoussoren, steve.dower, terry.reedy, tim.golden, vstinner, yselivanov, 
zach.ware
type: behavior -> security

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



next steps to make a python program more available

2018-12-27 Thread ant
  ok, i have the program going and installable for my
local Linux distribution.  aka i have it packaged and
on PyPI and it runs from my local terminal command line.

  i have people available for testing it out on Windows
and a Mac, but i don't have any way of knowing what to
do to make the program appear in their Menu system to
make it clickable.

  in MATE (which is what i run here) i can figure it out
as something to do with the desktop, so somehow i have
to do that, but i don't know what keywords to even search
for to do that, desktop icons i guess and menu, but is
there a more global way to set that up?  XDG seems to be
a part of that.

  i'm figuring if i get it working for MATE that it should
also work for Gnome.  i haven't touched KDE in quite a 
few years.

  Windows i'll figure out after the more Linux/Posix 
systems.

  so my priorties are about like:

  1. posix/other linux sytems (perhaps Macs fit into this anways)
  2. Macs
  3. Windows

  luckily i do have other examples of python 3 programs which
seem to be multiple platform oriented that i can look at and
see what they've done.  so i won't be forever lost in the
wilderness...

  thanks for help,  :)


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


Re: Why am I getting Error 405 while uploading my package to https://test.pypi.org/legacy?

2018-12-24 Thread ant
sntshkm...@gmail.com wrote:
>>   $ pip install readme_renderer[md]
>
> Thanks a lot for this, I wasn't able to figure it out earlier.

  does it work ok now?  got the upload to go to pypitest?


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


Re: Why am I getting Error 405 while uploading my package to https://test.pypi.org/legacy?

2018-12-23 Thread ant
sntshkm...@gmail.com wrote:
>>   did you check your dists via twine?
>> 
>>   $ twine check --verbose dist/*
>
> I checked with `twine check dist/*` (there's no --verbose option though).
> I only get warning about markdown

  right, i see later in my history i used the twine
check without the verbose option.

  you have to fix that for it to upload...

  $ pip install readme_renderer[md]


>>   also make sure you are using up to date versions of
>> setuptools, wheel and twine
>> 
>> 
>>   $ pip install --upgrade setuptools
>>   $ pip install --upgrade wheel
>>   $ pip install --upgrade twine
>
> [65]> import setuptools, wheel, twine
> [66]> print(setuptools.__version__)
> 40.6.3
> [67]> print(wheel.__version__)
> 0.32.3
> [68]> print(twine.__version__)
> 1.12.1
>
>
>>   i just used it earlier today...  worked fine for me.
>> is your account there and verified?
>
> Yes, I have an account on TestPyPI and is verified. 

  try the above...


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


Re: Why am I getting Error 405 while uploading my package to https://test.pypi.org/legacy?

2018-12-23 Thread ant
sntshkm...@gmail.com wrote:
>> .pypirc 
>>=
>> [distutils]
>> index-servers=
>> testpypi
>>
>> [testpypi]
>> repository: https://test.pypi.org/legacy/
>> username: UserName
>> password: Password
>
>
>> twine upload --repository testpypi dist/*
>
> Tried your suggestion for .pypirc file. Still the same error.
>
> Has something changed and is not reflected in the documentation?


  did you check your dists via twine?


  $ twine check --verbose dist/*

  also make sure you are using up to date versions of
setuptools, wheel and twine


  $ pip install --upgrade setuptools
  $ pip install --upgrade wheel
  $ pip install --upgrade twine


  i just used it earlier today...  worked fine for me.
is your account there and verified?


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


Re: Why am I getting Error 405 while uploading my package to https://test.pypi.org/legacy?

2018-12-23 Thread ant
ant wrote:

...

> .pypirc 
>=
> [distutils]
> index-servers=
> testpypi
>
> [testpypi]
> repository: https://test.pypi.org/legacy/
> username: UserName
> password: Password
>=
>
>
> and my upload command is:
>
>
>=
> #!/bin/sh
> #
> # upload ngfp to test pypi
>
> NGFP_SRC_HOME="/home/me/src/salsa/ngfp"
> if test ! -d "$NGFP_SRC_HOME" ; then
>   echo "  directory $NGFP_SRC_HOME does not exist!"
>   exit
> fi
>
> cd $NGFP_SRC_HOME
>
> twine upload --repository testpypi dist/*
>=


  since i just went through this myself i thought i'd
add a bit more.

  when you change over to post to the main pypi.org
you need to do it to upload.pypi.org like:

=
[pypi]
repository: https://upload.pypi.org/legacy/
=

  as i was getting 405 errors when using just pypi.org
i suspect your error above is that you're not using the
/legacy/ part at the end...

  good luck!


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


Re: Why am I getting Error 405 while uploading my package to https://test.pypi.org/legacy?

2018-12-23 Thread ant
sntshkm...@gmail.com wrote:
> I'm trying to upload my package to PyPi, but before that I wanted to upload 
> my package to TestPyPi.
>
> I'm following https://packaging.python.org/guides/using-testpypi/
>
> I'm issuing this command: `twine upload --repository-url 
> https://test.pypi.org/legacy/ dist/*`
>
> Here is the output:
>
> ```
> Enter your username: sntshkmr60
> Enter your password:
> Uploading distributions to https://test.pypi.org/
> Uploading mysecretpackage-0.0.1a0-py3-none-any.whl
> 100%||
>  16.7k/16.7k [00:06<00:00, 2.50kB/s]
> NOTE: Try --verbose to see response content.
> HTTPError: 405 Client Error: Method Not Allowed for url: 
> https://test.pypi.org/
> ```
>
> Here is the extra output from --verbose flag:
>
> ```
> Content received from server:
>
> 
>  405 Method Not Allowed
> 
> 
>  405 Method Not Allowed
>   The method POST is not allowed for this resource. 
>
> 
>
> HTTPError: 405 Client Error: Method Not Allowed for url: 
> https://test.pypi.org/
> ```
>
> What am I doing wrong?

  well, i used it earlier so here is how i have it set up
as follows.

  because this is testing repository i am not worried about
password being stored in a file:

.pypirc 
=
[distutils]
index-servers=
testpypi

[testpypi]
repository: https://test.pypi.org/legacy/
username: UserName
password: Password
=


and my upload command is:


=
#!/bin/sh
#
# upload ngfp to test pypi

NGFP_SRC_HOME="/home/me/src/salsa/ngfp"
if test ! -d "$NGFP_SRC_HOME" ; then
  echo "  directory $NGFP_SRC_HOME does not exist!"
  exit
fi

cd $NGFP_SRC_HOME

twine upload --repository testpypi dist/*
=


  note: it may take a while for what you uploaded to be made
available for download again even if it reflected in your
project page.  sometimes it has been as long as a half hour
or more before it comes down.  other times it has only been
a few minutes.

  hope this helps...


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


[SOLVED] Re: ah, progress...

2018-12-23 Thread ant
dieter wrote:

...

  thank you for your help.  :)  i finally worked through
the changes needed at last.


  my current package in testing PyPI is at:

  https://test.pypi.org/project/ngfp/

  which uses my code from:

  https://salsa.debian.org/ant-guest/gfpoken-in-python


  i ended up needing to do two things.  to get all the import
statements changed to include the package/module name and to
change all my image load statements to include the full path
as determined at runtime.

  this may not work on a non-linux or non-posix system from
the binary distribution but the source code distribution may
work ok.  if anyone wants to try it out.

  feedback is appreciated in any case.  :)


  now the next fun steps (figuring out the windows, other 
versions and then the Debian packaging for it).  since i
don't have windows or other machines to test on i don't 
know how that will go.

  cheers and thanks again,


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


Re: ah, progress...

2018-12-21 Thread ant
dieter wrote:
> ant  writes:
>> ...
>>   in order to get this far below i had to edit each
>> file and put a try: except: around each import
>> statment checking if the module could be found
>> like (as an example):
>>
>> try:
>> import config as cfg
>> except:
>> import frog.config as cfg
>
> Is "frog" the package, you want to install?
> Then always use "import frog.config ...".

  frog is my temporary adaptation of my project
to test out how to do this without actually making
all those changes until i'm sure it is doing what
i want.

  frog is a package as i understand it.  here is
the structure:

=
(env) me@ant(15)~/src/salsa/frog$ find . -print | grep -v ".git" | grep -v 
"__pycache__" | grep -v "dist" | grep -v "build" | sort
.
./frog
./frog/active.py
./frog/background.py
./frog/board.py
./frog/commands.py
./frog/config.py
./frog/dialog.py
./frog/doc
./frog/doc/ngfp.6
./frog.egg-info
./frog.egg-info/dependency_links.txt
./frog.egg-info/entry_points.txt
./frog.egg-info/PKG-INFO
./frog.egg-info/requires.txt
./frog.egg-info/SOURCES.txt
./frog.egg-info/top_level.txt
./frog/history.py
./frog/__init__.py
./frog/labels.py
./frog/__main__.py
./frog/marbles.py
./frog/my_init.py
./frog/ngfp.py
./frog/png
./frog/png/arrows
./frog/png/arrows/picDDownW.png
./frog/png/arrows/picDLeftW.png
...80 lines skipped...
./frog/png/misc/sink_inv.png
./frog/png/misc/sink_orig.png
./frog/randboard.py
./LICENSE
./LICENSE.GPL
./MANIFEST.in
./NOTICE
./README.md
./setup.cfg
./setup.py
=


> Python locates (top level) packages/modules via the so
> called "Python path" (--> "sys.path"). When
> you run a script, the "Python path" is extended by the
> directory the script resides in -- thus a script typically
> can import "local" packages/module (residing in its directory).
> However, it is good practise to always access installed
> packages via their "official package path" (which
> in your case likely means "frog.config").

  this is the first i'm hearing of a path being
extended.  why isn't that reflected when i print the
current working directory when the program is running
(in both cases the paths show identical)?

  this is also the first time i'm hearing of "official
package path".

  there are likely the details i'm beating my head
against...  thank you.  :)


> When you develop a package, it may not yet be installed.
> This might hinder you to import in the "official" way.

  correct.  when i am testing/writing code i am in the
source code directory above called frog which
looks like:

=
-rw---  1 me me  8962 Dec 21 00:20 active.py
-rw---  1 me me  6673 Dec 21 00:11 background.py
-rw---  1 me me 11796 Dec 21 00:10 board.py
-rw---  1 me me   217 Dec 20 23:16 commands.py
-rw---  1 me me  5987 Dec 21 00:12 config.py
-rw---  1 me me 34077 Dec 21 00:14 dialog.py
drwx--  2 me me  4096 Dec 18 09:26 doc
-rw---  1 me me  1943 Dec 21 00:15 history.py
-rw---  1 me me   310 Dec 20 23:39 __init__.py
-rw---  1 me me  1845 Dec 21 00:15 labels.py
-rw---  1 me me   140 Dec 20 22:39 __main__.py
-rw-------  1 me me 23973 Dec 21 00:17 marbles.py
-rw---  1 me me 13534 Dec 21 00:34 my_init.py
-rw---  1 me me 10354 Dec 21 09:02 ngfp.py
drwx-- 10 me me  4096 Dec 18 09:26 png
-rw---  1 me me  5514 Dec 21 00:18 randboard.py
(env) me@ant(18)~/src/salsa/frog/frog$ 
=

  so to test the code i simply run it via

$ python3 ngfp.py

  which works as i expect it.

=


> I work around this by using "setuptools" and its "setup"
> function in my "setup.py". "setuptools" supports the
> command "develop" (activated via "python setup.py develop")
> which "installs" the package in a way that it refers to
> the developped sources. This way, I can always
> import in the "official" way and nevertheless all
> my changes are effective immediately.

  i'm not sure how this works, but i will look into it.


> Another approach would be to lay out your package in such
> a way that it refects the installed structure and
> for testing put your script in the directory containing
> your top level packages (or extend "sys.path" with this directory).

  i think that is what i've always assumed that was
how the code is installed is exactly as how i have it
in my development directory as shown above.  your hint
here says that it probably isn't so...  heh...

  thanks, these are things a newbie doesn't know, but
someone experienced just considers common sense.

  for me coming from C code, packed and unpacked via
tarballs and such exactly where i want them to go is
the normal and it seems so strange to find things 
so hard to 

Re: Mask two images with python

2018-12-21 Thread ant
Umar Yusuf wrote:
...
> Hello Oscar,
> Thank you for your time.. Here is attached is an example set of the images: 
> https://drive.google.com/file/d/1hyiWswx4GCZQDepXZjktq2zgM_LBbxXt/view?usp=sharing
>  basically, it is "design + mask and glow = result"

  that didn't work for me at all...

  are the images .png or some other format that
allows transparency?

  is it critical that it be done via Python or do you
just want it done at all?  :)

  gimp and other tools (Graphics Magic) will allow 
this to be done interactively or via the command 
line.

  if it has to be done in python i'm only familiar
with pyglet and could do it easily enough that way
(sorry i'm a newbie about other ways in python :) ).

make a sprite in a certain location in a window with
the background image and then make another sprite with
the next layer on top of that one, one at a time, each
with it's own batch id.

then when it appears how you like it you can grab a
screen shot via:


The following example shows how to grab a screenshot of your application window:

pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')

Note that images can only be saved in the PNG format unless the Pillow library 
is installed.
=

  if you want an example of multiple layers i have
my work in progress that does exactly this sort of 
thing (except i never save an image yet - that could
be easily added as above).  you're welcome to take
the code and use it however you like:


  https://salsa.debian.org/ant-guest/gfpoken-in-python


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


Re: ah, progress...

2018-12-20 Thread ant
dieter wrote:
> ant  writes:
>> ant wrote:
>> ...
>>> (env) me@ant(26)~/src/test$ ngfp
>>> Traceback (most recent call last):
>>>   File "/home/me/src/env/bin/ngfp", line 7, in 
>>> from ngfp import main
>>> ImportError: cannot import name 'main' from 'ngfp' 
>>> (/home/me/src/salsa/env/lib/python3.7/site-packages/ngfp/__init__.py)
>> ...
>> hmmm, but my main is defined in ngfp.py
>
> The error message tells you that it looks for "main"
> in "...ngfp/__init__.py", not in "ngfp.py".

  i took an examply python program called afew and
edited it down to work for a very simple program
which i then took my other code and put it in that
directory structure to make sure i wasn't doing
anything strange, but i still ended up where 
running the program one way works and running it
the other way it seems to miss something important
which i don't understand.

  in order to get this far below i had to edit each
file and put a try: except: around each import
statment checking if the module could be found
like (as an example):

try:
import config as cfg
except:
import frog.config as cfg


this is very frustrating because the following makes 
no sense to me:

when i run the code within the directory like this i get:
=  this works as it should
(env) me@ant(30)~/src/salsa/frog/frog$ python3 ngfp.py 
current_dir :  /home/me/src/salsa/frog/frog
(env) me@ant(31)~/src/salsa/frog/frog$ 
=

when i pack it up and then install it using (and then run it via 
the script):
= it doesn't work, but the directory is the same...?
(env) me@ant(150)~/src/salsa/test$ pip3 --no-cache-dir install -e ../frog/ 
--force-reinstall
Obtaining file:///home/me/src/salsa/frog
Requirement already satisfied: pyglet>=1.3.0 in 
/home/me/src/salsa/env/lib/python3.7/site-packages (from frog==1.0.0)
Requirement already satisfied: future in 
/home/me/src/salsa/env/lib/python3.7/site-packages (from 
pyglet>=1.3.0->frog==1.0.0)
Installing collected packages: frog
  Found existing installation: frog 1.0.0
Uninstalling frog-1.0.0:
  Successfully uninstalled frog-1.0.0
  Running setup.py develop for frog
Successfully installed frog
(env) me@ant(151)~/src/salsa/test$ frog
current_dir :  /home/me/src/salsa/frog/frog
Traceback (most recent call last):
  File "/home/me/src/salsa/env/bin/frog", line 11, in 
load_entry_point('frog', 'console_scripts', 'frog')()
  File "/home/me/src/salsa/frog/frog/commands.py", line 12, in main
inner_main()
  File "/home/me/src/salsa/frog/frog/ngfp.py", line 284, in main
window = Window(width=cfg.img_pix*(cfg.game_cols+cfg.control_cols+3), 
height=cfg.img_pix*(cfg.game_rows+2), caption="Ngfp", resizable=True, 
fullscreen=False, visible=False)
  File "/home/me/src/salsa/frog/frog/ngfp.py", line 63, in __init__
MyInitStuff (self)
  File "/home/me/src/salsa/frog/frog/my_init.py", line 113, in MyInitStuff
self.game_bg_image  = pyglet.image.load("png/mirrors/00_bg.png")
  File 
"/home/me/src/salsa/env/lib/python3.7/site-packages/pyglet/image/__init__.py", 
line 180, in load
file = open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'png/mirrors/00_bg.png'
(env) me@ant(152)~/src/salsa/test$ 
=

  the paths are exactly the same when i print the current
directory.

  the png directory is there and the image is there.

  ugh, time to sleep...


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


Re: ah, progress...

2018-12-19 Thread ant
ant wrote:
> ant wrote:
>
> ...
>
>   script was there, but the package was not actually
> installed.
>
>   after installing again i get:
>
>=
>
> (env) me@ant(26)~/src/test$ ngfp
> Traceback (most recent call last):
>   File "/home/me/src/env/bin/ngfp", line 7, in 
> from ngfp import main
> ImportError: cannot import name 'main' from 'ngfp' 
> (/home/me/src/salsa/env/lib/python3.7/site-packages/ngfp/__init__.py)
>
>=
>
>   i'm not sure if this is because my __init__.py is
> another directory deeper (my project has a top level
> directory with the setup.py in it and then the
> ngfp directory with the __init__.py in it which 
> contains the following:
>
>=
> name = "ngfp"
>=
>
>   which obviously says nothing about main...
> i hate being a newbie.
>
>   but at least i'm making progress.  :)


hmmm, but my main is defined in ngfp.py


=

...


def main():
window = Window(width=cfg.img_pix*(cfg.game_cols+cfg.control_cols+3), 
height=cfg.img_pix*(cfg.game_rows+2), caption="Ngfp", resizable=True, 
fullscreen=False, visible=False)
pyglet.clock.schedule_interval(window.update, 1/120.0) # update at 60Hz
pyglet.app.run()


if __name__ == "__main__":
main()


=


  when i'm in the directory with the source code:


$ python3 ngfp.py


works exactly as it should.


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


ah, progress...

2018-12-19 Thread ant
ant wrote:

...

  script was there, but the package was not actually
installed.

  after installing again i get:

=

(env) me@ant(26)~/src/test$ ngfp
Traceback (most recent call last):
  File "/home/me/src/env/bin/ngfp", line 7, in 
from ngfp import main
ImportError: cannot import name 'main' from 'ngfp' 
(/home/me/src/salsa/env/lib/python3.7/site-packages/ngfp/__init__.py)

=

  i'm not sure if this is because my __init__.py is
another directory deeper (my project has a top level
directory with the setup.py in it and then the
ngfp directory with the __init__.py in it which 
contains the following:

=
name = "ngfp"
=

  which obviously says nothing about main...
i hate being a newbie.

  but at least i'm making progress.  :)


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


Re: setup.py, how to find main program/module?

2018-12-19 Thread ant
dieter wrote:
> ant  writes:
>> ...
>>   yet not quite all the way yet.  i run the 
>> commands to make the sdist and wheels and upload
>> it using twine to my test account, but when
>> i install it and try to run it the ngfp.py is
>> not found (i've also tried nfgp and main).
>> ...
>>   i suspect i've not really understood entry 
>> points and may not have it specified correctly in
>> setup.py.
>>
>>   any help appreciated.  :)
>
> I think you are right: the problem is likely with the
> "entry_points" specification.
>
>
> My "dm.zopepatches.ztest" package has
>   entry_points = dict(
>  console_scripts = [
>'ztest = dm.zopepatches.ztest:main',
>]
> ),
> This is responsible for the creation of a script called
> "ztest" in Python's "bin" directory.
>
>
> Does your "entry_points" specification look similar?

  yes.


> Do you find corresponding scripts in Python's "bin" directory?

  thank you,

  yes, it is there:


=
(env) me@ant(9)~/src/env/bin$ more ngfp 
#!/home/me/src/env/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'ngfp','console_scripts','ngfp'
__requires__ = 'ngfp'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('ngfp', 'console_scripts', 'ngfp')()
)


=

(env) me@ant(11)~/src/test$ ngfp
Traceback (most recent call last):
  File "/home/me/src/env/bin/ngfp", line 6, in 
from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3126, 
in 
@_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3110, 
in _call_aside
f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3139, 
in _initialize_master_working_set
working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 581, in 
_build_master
ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 898, in 
require
needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 784, in 
resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'ngfp' distribution was not found and 
is required by the application

=

  so, actually, the problem isn't what i expected it to be.
but i'm still not sure how to fix it.  :)


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


setup.py, how to find main program/module?

2018-12-18 Thread ant
  hello,

  i'm getting there...

  yet not quite all the way yet.  i run the 
commands to make the sdist and wheels and upload
it using twine to my test account, but when
i install it and try to run it the ngfp.py is
not found (i've also tried nfgp and main).


test upload:

  https://test.pypi.org/project/ngfp/


  i suspect i've not really understood entry 
points and may not have it specified correctly in
setup.py.

  any help appreciated.  :)


  to install it you'll need to use (to pull in pyglet):

$ pip install --index-url https://test.pypi.org/simple/ --extra-index-url 
https://pypi.org/simple ngfp==0.1.5.post3

  thank you and cheers,


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


Python in Linux - barrier to Python 3.x

2010-09-21 Thread Ant
Hi all,

I've just seen this: http://sheddingbikes.com/posts/1285063820.html

Whatever you think of Zed Shaw (author of the Mongrel Ruby server and
relatively recent Python convert), he has a very good point in this. I
run Fedora 12 on my home computers, and find it far too much hassle to
try to get Python 3 installed. Even the 2.x's are behind - IIRC think
it currently uses 2.5.

So I really think this is a barrier to entry to Python 3 that we could
do without - it's the only reason I do all of my Python work in 2.x, I
would jump at migrating to Python 3 if it was easily available on
Fedora.

Is there a solution to this that anyone knows of? Has Zed jumped to
conclusions? Have I?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in Linux - barrier to Python 3.x

2010-09-21 Thread Ant
On Sep 21, 2:04 pm, Philip Semanchuk phi...@semanchuk.com wrote:
 On Sep 21, 2010, at 8:29 AM, Ant wrote:
 Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org 
 reports that Fedora has been using Python = 2.6 since Fedora 11 which was 
 released in June of 2009.

Yes you are right - I've checked on my home machine, and it is indeed
2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading
an OS in order to get the latest version of one package is a bit much!

I know that this is a distribution issue, and not strictly a Python
one, but the issue exists primarily because python is such a
successful language it has become deeply embedded in linux
distributions, and so there is now a lot of work involved in checking
that a python upgrade doesn't break things.

Some solution involving virtualenv is perhaps a possibility.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs - A Modest Proposal

2010-06-10 Thread ant
I don't know whether this thread is going backwards, forwards or
sideways. But a lot of useful information is creeping out of the
woodwork.

I like the points about backwards compatibility. Presumably that
reason alone is enough to keep Tkinter in the standard library for a
long while.
But the point has also been made that there are several things there
that are - if not duplicates - at least alternatives.

So would it be so awful to have Tkinter and GUI2 (whatever it is) in
the stdlib, assuming that both had equivalent functionality? That
would be the way to give people the choice.
But it does imply that GUI2 is not too huge, to prevent excessive
bloat (is that a tautology?).
Other interesting comments: licencing. Can anyone give a concise
summary of whether the 'major' GUIs have any insuperable licencing
problems that would rule them out anyway? Programming is hard enough
without lawyers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs - A Modest Proposal

2010-06-09 Thread ant
Since I started this thread, I feel a sense of responsibility for it,
in some bizarre way.
Not to prolong its existence, which is clearly a troubling one for
some, but to try to steer it towards some kind of consensus that will
irritate the least number of people. Or better, that will gain some
kind of support and momentum so that something happens.
And since I have neither a reputation to lose, nor any great fondness
for most of the proposed solutions, I will try to summarise some of
the points made as impartially as I can. And I will add my own
opinions; but a group as sophisticated as
this will be able to spot them...

1 Although a few advocates of Tkinter have spoken in favour of it,
most seem to think that:
It's not particularly elegant, either in its use or its
implementation with Tcl/Tk
If we didn't have a GUI in the distribution, we wouldn't choose
Tkinter now; it seems like its inclusion
is  a sort of historical accident.
It may be all right for small projects, but once things get
bigger, you have to throw away what you've done
and use something else.
Not many people use it anyway, so why bother?

2 Most people who have used a GUI have some investment in it. So
arguments about which one is best tend to be
  partial and not wonderfully constructive.
  Indeed, about the only common thread that comes out seems to be a
general dislike of Tkinter.

3 There is a surprising number of people who think that Python
shouldn't have any 'favoured' association with a
  GUI at all. I find that surprising because of my own experience: I
have written a few hundred Python programs
  over the last few years, mostly small and almost entirely for my own
benefit. Most of those don't use a GUI. But  whenever I
  write a program that someone else is going to use, it has to have a
GUI. Is that not true for most people?

4 Some think that including any sort of GUI is 'bad'. People can
choose the one they want from the large list available.
  I certainly don't want to stop people doing what they want. However
many people have neither the time or the
  expertise to decide, and the experience of choosing the wrong one is
a real turn-off.
  That, in my opinion, is where a replacement for Tkinter should be
aimed: the beginning graphics programmer.
  But if it is built on the right foundation (which Tkinter seems not
to be), it could be extended to cover
  far more useful cases than Tkinter can.

5 I should stop pontificating, and write code. If it's better than the
existing, people will use it and it will
  become the standard.
  I don't think so. Even vast libraries of well-written code haven't
become the standard. I seem to remember a
  DEC assembler manual from the last century, which said A standard
doesn't have to be optimal, it just has to be
  standard (Feel free to correct me on that one. The last century
seems like a long time ago).

So I think comments like the system doesn't work like that - nothing
happens till code is working miss the point.
We are not talking about some vital but complex module or library here
- it's more important than that.
We are talking about the thing that the rest of the world sees as
Python's biggest missing piece - the thing that
beginning programmers look for and don't find - a decent, well-
supported and elegant GUI.

And who are the beginning programmers going to turn into? If we do our
stuff right, Python programmers. If not,
Java or PHP or Visual Basic programmers. Or website designers. Or
worse (is there a worse?).

So, to summarise the summary: I reiterate my call. Somebody has to get
Tkinter out of the distribution and replaced
by something that - as a minimum - doesn't get slagged off by nearly
everyone.

It can't be me - I don't have the clout.



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


Re: GUIs - A Modest Proposal

2010-06-07 Thread ant
I rather feel like I'm flogging a dead horse here, but time for
another mile...

First off, I'm not volunteering to lead this effort. I don't think
anyone should
even think about that until and unless the Python Powers That Be
actually
decide that it is worth doing. That is what I meant by 'strong
leadership'.

Second; 'A minor programming language'. According to

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Visual Basic is more popular than Python. That makes me feel that
there
is something wrong with the world.

Third: I'm curious why you think fragmented GUI choices is a
particular
 problem for Python compared to other languages? Or why this is the
 main issue holding Python back? 
It's not a particular problem for Python compared to other languages.
It's a general problem for all programming languages. But I presume
that you read this newgroup because you think Python is in some sense
'better' than other programming languages. And I think we can make it
better still.

Fourth:  BTW, what's your plan for producing such a leader?  Because
if we
 don't have a leader it's kind of a moot point.  (I know some people
 asked you to volunteer, but I suspect you would agree that you're
not
 up to the task, so I assume you are merely a visionary and have
 someone lined up that you've somehow convince to do the dirty work
of
 leadership.) 
I'm not a visionary and I don't have someone lined up. And I am
certainly
not up to the task myself. But I have watched with interest the
process of
turning Python2.x into Python3.x.  Does that give any hints about who
I
think should be considering this topic (see first point)?


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


Re: GUIs - A Modest Proposal

2010-06-06 Thread ant
On Jun 6, 2:22 pm, ant shi...@uklinux.net wrote:
 I get the strong feeling that nobody is really happy with the state of
 Python GUIs.
snip...

What an interesting set of responses I got!
And - even more interesting - how few of them actually seem to think
there is a problem, let
alone make any attempt to move the situation forward.
I appreciate that there are proponents of many different GUIs. I am
asking that all step back
from their particular interests and - for example - try to see the
situation from the viewpoint of
- say - a Python newbie, or an organisation that is thinking of
switching from (example only!) Visual Basic.

I obviously didn't make my main point clearly enough; I'll restate it
with a different emphasis:
The default GUI shipped with Python is Tkinter.
Few people seem to like it much. This has several consequences.
- It has not blossomed, like Python has.
- There are not hundreds of talented programmers making rapid and
impressive improvements to it.
- Books about Python use it in examples (because it IS the default),
but imply that one should move on.

The result that our hypothetical new recruit has to make a choice for
the new, big project. Remember that
GUIs have hundreds (sometimes thousands) of classes, functions and
constants. Let alone idioms and design
patterns. That is what I meant by 'Our resources are being
dissipated'; the effort of learning, remembering
and relearning a workable subset of these is substantial.
So it would be good to be able to use One Right Way, not try several
(as I have - I will admit I didn't try PyQt;
GUI fatigue was setting in by then).

If we are to make progress, I can see two obvious approaches:
1) Improve Tkinter to the point where it is supportable and supported
by a good fraction of Python programmers
or
2) Drop Tkinter as the default and use something else.

If we choose 2) then we have a new set of possibilities:
2a) Use one of the 'major' GUIs, pretty much as is, but presumably
with a lot more people supporting it if it is the default.
2b) Use one of the 'minor' GUIs, and get a lot of people working on it
to make it really good.
2c) Start from scratch. With a project supported by the Community as a
whole, with the agreed objective of being the default.

None of these is easy. All require strong leadership and great
committment.

What surprises me is the apparent willingness of the Python community
to let this issue slide.
I can see that many people have committed to one GUI and want to use
that forever. Fair enough. For the reasons I stated
originally, I've not found one. I think a lot of people deep down are
uneasy about this.

My concern is simple: I think that Python is doomed to remain a minor
language unless we crack this problem.

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


GUIs - A Modest Proposal

2010-06-05 Thread ant
I get the strong feeling that nobody is really happy with the state of
Python GUIs.
Tkinter is not widely liked, but is widely distributed. WxPython and
PyGtk are both
powerful, but quirky in different ways. PyQt is tied to one platform.
And there are
dozens more.

Whether or not we like graphics programming, it's not going to go
away. I get the
uneasy feeling whenever I start a new project that there should be a
'better' GUI
than the ones I currently use (WxPython and PyGtk).

Fragmentation is our enemy. Our resources are being dissipated. Is it
not time to
start again? We have shown that it is possible to do the right thing,
by creating Python3.

I ask the group; should we try to create a new GUI for Python, with
the following
properties?:

- Pythonic
- The default GUI (so it replaces Tkinter)
- It has the support of the majority of the Python community
- Simple and obvious to use for simple things
- Comprehensive, for complicated things
- Cross-platform
- Looks good (to be defined)
- As small as possible in its default form

If so, what are the next steps?

The Python SIG on GUIs closed years ago. Should that be revived?

This is A Modest Proposal (J. Swift). In a sense, I am suggesting
that
we eat our own babies.

But don't we owe it to the community?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Ant
On May 25, 6:35 pm, LittleGrasshopper seattleha...@yahoo.com wrote:
 With so many choices, I was wondering what editor is the one you
 prefer when coding Python, and why. I normally use vi, and just got

I use GVim or vim if on a terminal. There are quite a few plugins and
scripts I find invaluable, but most are not python specific, and many
are home grown (if compiled against python, you can script vim using
Python).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance java vs. python

2009-05-20 Thread Ant
On May 20, 6:46 pm, namekuseijin namekusei...@gmail.com wrote:
 anyway, again, thanks for the laughs.

I'm a Java developer in my day job, and I use Jython for testing out
ideas and prototyping, due to the way Jython makes writing Java so
much easier... Those examples were spot on - things weren't much
simpler before generics, as you had casting going on everywhere. Not
to mention the nice primitive / object divide to add to the languages
complexity.

And the libraries in Java... Compare cat implementations:

# Python
fh = open(myfile.txt)

for line in fh:
print line

// Java

...

BufferedReader reader = new BufferedReader(new FileReader
(myfile.txt));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
}

...

And that's without all of the class/main method boilerplate or try
catch block required due to checked exceptions.

I've taught both Java and Python, and the latter is far easier to pick
up and run with, from both a syntactic point of view and in the use of
the libraries.


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


matplotlib - overlaying plots.

2009-05-14 Thread Ant
Hi All,

I am trying to get matplotlib to overlay a couple of graphs, but am
getting nowhere. I originally thought that the following may work:

 x = [1,2,3,4,5]
 y = [2,4,6,8,10]
 y2 = [1,4,9,16,25]

 plot(x, y)
 plot(x, y2)

Now this works as desired, however, the actual case I have is more
like this:

 x = [1,2,3,4,5]
 y = [2,4,6,8,10]
 y2 = [.0001, .0002, .0003, .0004, .0005]

Now the graph is useless, since the results are plotted on the same
axis. What I really want is two different sets of axes, each scaled
appropriately, but overlayed.

The data I actually have, is one set of axes plotting distance against
elevation, and a second plotting distance against speed. The former
has (y-coord) units in the range 0-2000 ft and the latter 0 - 0.01
miles/second. I want them on the same graph, so points can be easily
correlated, but overlayed so that each line has a different scale on
the y-axis. The closest I can get is to have two subplots, one above
the other.

Thanks in advance,

Ant.

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


Re: matplotlib - overlaying plots.

2009-05-14 Thread Ant
On May 14, 3:52 pm, Hyuga hyugaricd...@gmail.com wrote:
...
 On the other hand, I just took a peek at the matplotlib example
 gallery, which is very diverse, and it has an example that I think is
 exactly what you're looking 
 for:http://matplotlib.sourceforge.net/examples/api/two_scales.html

Superb - spot on. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which python version do I use with virtualenv?

2009-05-07 Thread Ant
On May 7, 8:03 am, OldGrantonian oldgranton...@googlemail.com wrote:
...
 I had Python 2.6 on my laptop.

 I needed easyinstall to install virtualenv. During installation of
 easyinstall, I got the message Python 2.5 not found

 So I installed Python 2.5, then installed virtualenv

 So I now have c:\Python 2.5 and c:\Python 2.6
...

Sounds like you've downloaded the Python 2.5 version of Easy Install.
If I were you I'd uninstall Python 2.5, and re-install easy_install
using the correct exe for Python 2.6.

Check that typing 'python' on the commandline still works, as
installing and uninstalling 2.5 may have messed up your path. if it
has, either manually add the Python install directory to the path, or
reinstall Python 2.6.

Note: have you changed the default install folder? I haven't got
Vista, but on XP it installs to c:\Python26 not C:\Python 2.6. I'd
be carefull of changing the default install directory of Python,
particularly if you are non-techy as some packages installers may
look for Python in the default location.

--
Ant
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot find text in *.py files with Windows Explorer?

2009-04-06 Thread Ant
On Apr 4, 7:09 am, Tim Golden m...@timgolden.me.uk wrote:
 ... Now I think about it, try searching
 for xplorer2 ...

I'll second that. It's one of the few non-open source bits of software
that I'll willingly pay a license for. Have used it for around 5 or 6
years now. It's by a little 1 man company called Zabkat.

--
Ant.
--
http://mail.python.org/mailman/listinfo/python-list


Re: file.read() doesn't read the whole file

2009-03-24 Thread Ant
On Mar 24, 7:59 am, Sreejith K sreejith...@gmail.com wrote:
...
 data is the whole file, but 'less' gives only the two lines...

From this statement (that you are using less), it appears that you are
redirecting sys.stdout to a file or similar - if that is the case, you
may need to flush or close the output file before it picks up any
changes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2to3 Help?

2009-03-05 Thread Ant
On Jan 15, 6:43 am, James Mills prolo...@shortcircuit.net.au
wrote:
...
 That is a good idea :) Windows teaches you nothing!

Not true. Windows teaches you the art of the workaround...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regexp

2009-01-19 Thread Ant
A 0-width positive lookahead is probably what you want here:

 s = 
... hdhd a href=http://mysite.com/blah.html;Test iString/i OK/
a
...
... 
 p = r'href=(http://mysite.com/[^]+)(.*)(?=/a)'
 m = re.search(p, s)
 m.group(1)
'http://mysite.com/blah.html'
 m.group(2)
'Test iString/i OK'

The (?=...) bit is the lookahead, and won't consume any of the string
you are searching. I've binned the named groups for clarity.

The beautiful soup answers are a better bet though - they've already
done the hard work, and after all, you are trying to roll your own
partial HTML parser here, which will struggle with badly formed html...
--
http://mail.python.org/mailman/listinfo/python-list


Re: drive a desktop app from python?

2009-01-09 Thread Ant
On Jan 8, 9:06 pm, Tim Arnold tim.arn...@sas.com wrote:
 Is there any lib or recipe(s) for doing something like this via python?

Look into the PyWin32 extension module. It gives access to Windows
internals including the COM interface. You'll need to do some research
into how to automate the GUI you're using from other sources (there
are often VBA examples on the web that can be modified).

http://pywin32.sourceforge.net/

I've successfully used this in the past for automating MS Excel.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Generator metadata/attributes

2009-01-08 Thread Ant
You could look at something like the following to turn the class
iteslf into a decorator (changed lines *-ed):

 class TaggedWrapper():

*     def __init__(self, logMixin, stream):
         self.__tag = '%...@%s' % (logMixin.describe(), stream)
         logMixin._debug('Created %s' % self)

     def __next__(self):
         return next(self.__generator)

     def __str__(self):
         return self.__tag

  def __call__(self, generator):
 self.__generator = generator
 return self

and then decorate your generator:

@TaggedWrapper(mixin, stream)
def myGen;
   for a in range(1,100):
yield a

(Disclaimer: Completely untested...)

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


Re: My last working day of 2007

2009-01-05 Thread Ant
On Jan 5, 9:47 am, Jack.Chu working...@gmail.com wrote:
 Hello guys:
 I created a simple tool to count how I wasted my time day by day 
 ;-)http://www.flickr.com/photos/34017...@n07/3169438647/sizes/o/

Looks interesting - did you have some sort of time machine to be
spending that much time in Chrome at the end of 2007? ;-)

 I just want to get suggestions to improve it, ...

It's a bit hard to tell just from the screenshot... Do you have some
code we could look at? Would be perhaps good to sub-log each window's
title so that you could subdivide, for example, Firefox's time by the
pages you were looking at (this would work quite well for numerous
apps.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emacs vs. Eclipse vs. Vim

2008-11-30 Thread Ant
On Nov 29, 8:44 pm, Josh [EMAIL PROTECTED] wrote:
 If you were a beginning programmer and willing to make an investment in
 steep learning curve for best returns down the road, which would you pick?

Personally I'd choose Vim for the following reasons:

1) Vim is ubiquitous on Linux/Unix servers. If you learn Vim you will
be able to edit files on a server without doing the FTP to local
machine/edit locally/upload back by ftp dance I see so many
developers and even sys admins doing...
2) Vim is a proper editor. Eclipse is an IDE. They are really
incomparable. I personally hate working in Eclipse, but the IDE
features make it the obvious choice for Java development. I prefer Vim
for Python development. I also have Vim set up as an external editor
in Eclipse, so any repetitive or difficult editing in Eclipse is done
in Vim.
3) Vim makes it simple to cut log files down to size. The g command is
a godsend for this. :g/DEBUG/d will for example remove all debug lines
from the file. :g!/My message/d will delete all lines other than lines
containing My message, and :g/./norm dt- will delete everything up
until the first '-' (normal mode, delete 'till '-'). Combine these and
you'll have the info you want, formatted in the way you want it very
quickly.
4) Vim can be scripted in Python, and has a host of useful plugins.
5) Vim has close interaction with the command line (though no built-in
console like emacs). Finished editing a file? type :!svn commit -m
Done fixing this % and the current file (%) is committed into
subversion. :%!sort will filter the current buffer through an external
sort program, and change the buffer to the result.

Now emacs will also satisfy points 2-5 (not sure how easy 3 is, but
I'm certain it's comparable). In fact emacs will initially have a
lower learning curve, since it its not modal, and so wihout learning
any keystrokes, you can use it just like a basic editor and gradually
learn the commands.

(1) for me is a compelling reason to use vim all other things being
equal. Also, if you touch type, or aspire to, then Vim makes more
sense than emacs, since almost everything can be done from the main
keys, rather than emacs CTL-ALT-SHIFT x u type key contortions...

Certainly don't bother with Eclipse unless your starting as a Java
programmer (and even then learn vim as well) - it is very good at
inserting boilerplate code for you, but as an editor offers little
more than Windows Notepad...

I personally use Gvim for a great deal of my work, from those taskd

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


Re: Python search path (on Windows)

2008-10-22 Thread Ant
On Oct 22, 10:03 am, wooly booly [EMAIL PROTECTED] wrote:
 I would like to execute a Python script from Windows command line:

 Python myscript.py

 This works if myscript.py resides in the current folder. My question is:
 Is it possible to execute the command above from another folder?

 I put the script's folder in the PYTHONPATH environment variable but this
 didn't help.

 Thanks for your help!

You can put the script directory in the PATH environment variable, and
call it with just:

myscript.py
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Python shell through Cygwin Screen (Python/Vim/Screen combo)

2008-09-21 Thread Ant
On Sep 19, 7:08 pm, Jason Tishler [EMAIL PROTECTED] wrote:
...
 There are known issues when trying to run a Windows program that
 directly accesses the console under Cygwin.  For example:

    http://mail.python.org/pipermail/python-list/2004-June/21.html

 AFAICT, you will have to use Cygwin Python with screen.

Thanks for the info. Shame but - cygwin python for this setup it is
(Though I may hunt for a native windows port of screen rather than the
cygwin one.)

Cheers,

Ant.
--
http://mail.python.org/mailman/listinfo/python-list


Problem with Python shell through Cygwin Screen (Python/Vim/Screen combo)

2008-09-19 Thread Ant
Hi all,

There's a sweet combination of tools that you can assemble using Vim,
a Python shell (or any shell for that matter) and GNU screen, where
you essentially send selected text from Vim to the Python shell. (See
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/ for
more details - though I had to tweak the script a bit to get it to
work on Windows - line ending interpretation problem)

This works great in Linux, and also in Windows using the Cygwin build
of Python, but when you call:

screen -S py -s python

using the Windows build of Python, the shell just hangs. Does anyone
know if this is a known issue with screen/Python, or if there is a
workaround, as I'd prefer to have just a single Python instance
installed rather than having Cygwin python and windows Python both
installed.

Cheers,

Ant.
--
http://mail.python.org/mailman/listinfo/python-list


Re: complex numbers should respect the I representation

2008-06-28 Thread Ant
On Jun 28, 1:48 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 I think complex numbers should respect the i or I representation,
 instead of j.
 No reason being cute and using a different character instead of the
 traditional representation? At least have the decency of supporting
 the orginal representation?

You're looking at this from a very narrow perspective. i is indeed the
common notation in the realm of mathematics. However, in the realm of
engineering, j is more common (i is used for current). So given that
both i and j are in common usage for denoting a complex number, and
that i is common for indexing, then j is a perfectly reasonable
notation for Python to use.

 Programmers use j as frequently as i as indexing variable, I see no
 reason choosing j over i. Have some respect for majority's rules.
 This is childish.

Do some research before flaming on a subject on which you only have
one side of the story.

--
Ant
--
http://mail.python.org/mailman/listinfo/python-list


Pyparsing Question

2008-05-16 Thread Ant

Hi all,

I have a question on PyParsing. I am trying to create a parser for a 
hierarchical todo list format, but have hit a stumbling block. I have 
parsers for the header of the list (title and description), and the body 
(recursive descent on todo items).


Individually they are working fine, combined they throw an exception. 
The code follows:


#!/usr/bin/python
# parser.py
import pyparsing as pp

def grammar():
underline = pp.Word(=).suppress()
dotnum = pp.Combine(pp.Word(pp.nums) + .)
textline = pp.Combine(pp.Group(pp.Word(pp.alphas, pp.printables) + 
pp.restOfLine))

number = pp.Group(pp.OneOrMore(dotnum))

headtitle = textline
headdescription = pp.ZeroOrMore(textline)
head = pp.Group(headtitle + underline + headdescription)

taskname = pp.OneOrMore(dotnum) + textline
task = pp.Forward()
subtask = pp.Group(dotnum + task)
task  (taskname + pp.ZeroOrMore(subtask))
maintask = pp.Group(pp.LineStart() + task)

parser = pp.OneOrMore(maintask)

return head, parser

text = 


My Title


Text on a longer line of several words.
More test
and more.



text2 = 

1. Task 1
1.1. Subtask
1.1.1. More tasks.
1.2. Another subtask
2. Task 2
2.1. Subtask again

head, parser = grammar()

print head.parseString(text)
print parser.parseString(text2)

comb = head + pp.OneOrMore(pp.LineStart() + pp.restOfLine) + parser
print comb.parseString(text + text2)

#===

Now the first two print statements output the parse tree as I would 
expect, but the combined parser fails with an exception:


Traceback (most recent call last):
  File parser.py, line 50, in ?
print comb.parseString(text + text2)
.
. [Stacktrace snipped]
.
raise exc
pyparsing.ParseException: Expected start of line (at char 81), (line:9, 
col:1)


Any help appreciated!

Cheers,

--
Ant.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pyparsing Question

2008-05-16 Thread Ant

Hi Paul,


LineStart *really* wants to be parsed at the beginning of a line.
Your textline reads up to but not including the LineEnd.  Try making
these changes.

1. Change textline to:

 textline = pp.Combine(
pp.Group(pp.Word(pp.alphas, pp.printables) + pp.restOfLine)) +
\
pp.LineEnd().suppress()


Ah - so restOfLine excludes the actual line ending does it?


2. Change comb to:

comb = head + parser


Yes - I'd got this originally. I added the garbage to try to fix the 
problem and forgot to take it back out! Thanks for the advice - it works 
 fine now, and will provide a base for extending the list format.


Thanks,

Ant...
--
http://mail.python.org/mailman/listinfo/python-list


Batteries Included...

2008-04-21 Thread Ant
Today's XKCD comic has a nice Python reference!

http://xkcd.com/413/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Somebody *really* got fond of python

2008-04-21 Thread Ant
On Apr 21, 12:23 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 http://xkcd.com/413/

 :)

Didn't realise you'd posted this when I posted my Batteries
Included... post. Amused me as well!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient way of testing for substring being one of a set?

2008-04-03 Thread Ant
On Apr 3, 12:37 pm, [EMAIL PROTECTED] wrote:
 What's the neatest and/or most efficient way of testing if one of a

A different approach:

 words = [he, sh, bla]
 name = blah
 True in (word in name for word in words)
True

 name = bling
 True in (word in name for word in words)
False

Perhaps not as obvious or readable as Jeff's example, but is
essentially doing the same thing using generator syntax.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient way of testing for substring being one of a set?

2008-04-03 Thread Ant
On Apr 3, 2:27 pm, George Sakkis [EMAIL PROTECTED] wrote:
...
 It's even prettier in 2.5:

 any(word in name for word in words)

 George

And arguably the most readable yet!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a good time to start learning python?

2008-03-31 Thread Ant
On Mar 31, 5:40 pm, Rui Maciel [EMAIL PROTECTED] wrote:
...
 So far the decision seems to be a no brainer. Yet, Python 3000 will arrive
 in a few months. As it isn't backwards compatible with today's Python,
 there is the risk that no matter what I learn until then, I will end up
 having to re-learn at least a considerable part of the language. To put it
 in other words, I fear that I will be wasting my time.

Not at all. The lead developers have a plan for migrating older
scripts to 3000 automatically (or at least semi-automatically). This
can be done because the core syntax and builtin's are remaining
largely the same. The sort of thing that is changing in a way that
breaks backward compatibility are things such as removing the print
statement (e.g.  print Hello world) with a print function (e.g.
print(Hello world)) and rearranging the standard library.

As Terry said, the major changes are additions and deletions - to
expand on this, the deletions are generally likely to be modules that
are rarely used or  are unmaintained.

In any case, the python developers have a very good policy of making
the upgrade path to new versions of Python smooth. Generally new
features are released into the __future__ module in a release ready
for inclusion in the next release. This allows time to play with new
features before the official release of the feature comes out.
Module deletions usually hang around for a few releases as
deprecated before being permanently removed - again giving time to
catch up.

I believe that the deprecation speed may come rather abruptly with
3000, however the 2.6 release will contain a PyLint program for
identifying changes that will need to be made before migrating to 3k.
In addition, the 2.x branch is AFAIK going to be maintained up to (but
no further than) a 2.9 release. So there will be plenty of time to
adjust!

In short, any time invested in learning Python at this stage (except
perhaps old-style classes as pointed out above) will be time well
spent, as learning Python 3000 will be minor tweaks to what you'll
already know.

And for what it's worth, I've programmed in Haskell, C, Java (Java's
my profession), Javascript and Perl, and dabbled with Ruby, Lisp,
Groovy (and probably others), and Python is by far my favorite
language, not just for the clean syntax, rapid development,
readability 5 years down the line etc, but also for the community,
which is very helpful and knowledgeable.

BTW. I have to disagree with Andrew's comment: With Perl,
once you get the core syntax down, you don't need to master Perl.
Instead you just look up the module/feature you want to use and just
use
it.. This may be true for knocking up Perl scripts, but for reading
*other peoples* code in any language you need to have a good mastery
of the core language. In Perl this is a quagmire of strange syntax,
special cases, multiple ways to do the same thing and esoterica/magic,
whereas Python's design to make whitespace significant and its One
(obvious) way to do things philosophy makes reading other peoples
code much easier. (Of course other peoples code always sucks, but
hey ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: News from Jython world

2008-03-04 Thread Ant
On Mar 3, 6:40 pm, Sébastien Boisgérault
[EMAIL PROTECTED] wrote:
 Frank Wierzbicki and Ted Leung have been hired by Sun. Frank is a
 key Jython developer and is specifically hired to work full time on
 Jython, a version of the Python interpreter that runs on top of the
 JVM and provides full access to Java libraries. After a period where
 the development had slowed, Jython was recently getting seriously
 back on track. Now it's getting even better !

Development on Jython over the last year or so has been superb, and
it's good to see that Sun are getting really focused on dynamic
languages on the JVM. It may be that they are trying to play keep-up
with Microsoft and their support of IronPython - but regardless of the
reasons it is good news for Jython and Frank W, and for the Python
community in general.

A Sun endorsement of Jython means the possibility of more Python jobs
out there for us all in the future given the ubiquity of the JVM in
the enterprise and willingness of corporations to accept such
endorsements!

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python self-evaluating strings

2008-01-29 Thread Ant
In the spirit of Simple is better than complex. and totally
bypassing the intention of quines (though not necessarily the
definition):

--- probably_not_a_real_quine.py  
import sys

for line in open(sys.argv[0]):
print line,

--
;-)

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-10 Thread Ant
On Jan 10, 12:04 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 For the most part, I agree with you, which is why I chose Python in
 the first place.  I like quick development.  Unfortunately, this is
 one of those cases where execution time is a factor.  Who knows, maybe
 someone who's done camera vision with Python will come in and say it's
 just the algorithm in the example that needs work (I'm crossing my
 fingers that that's the case).

It would probably be worth reposting your question with a different
subject line. Something along the lines of Image/Video processing
performance in Python, and explaining what you actually want to
achieve. Python too slow? doesn't give enough information - clearly
Python is fast enough for many many tasks, since it is so widely used.
It also sounds like a troll - so many people who would actually be
able to assist you (such as the PIL, pygame and numpy/scipy
communities) may have ignored this thread.

Cheers,

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python via a little word frequency program

2008-01-09 Thread Ant
 I'm interested to learn how more experienced Python folks would solve
 this little problem.

I think I'd do the following:

from collections import defaultdict

names = freddy fred bill jock kevin andrew kevin kevin jock
freq = defaultdict(lambda: 0)

for name in names.split():
freq[name] += 1

pairs = [(v, k) for k, v in freq.iteritems()]

for v, k in reversed(sorted(pairs)):
print %-10s: %d % (k, v)


defaultdict makes the frequency accumulation neater.

reversed(sorted(pairs)) avoids the little -v hack and makes it more
obvious what you are doing. Of course this could also be achieved by
doing pairs.sort() and pairs.reverse() before iterating over the pairs
list.

Cheers,

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Jython: Honourable mention on Charles Nutter's blog.

2008-01-04 Thread Ant
Hi all,

The Jython team got an honourable mention on the Headius blog this
morning. Apparently they have got Django working with the latest
builds of Jython: http://headius.blogspot.com/2008/01/jythons-back-baby.html

So congratulations!

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting files from an ISO image?

2008-01-03 Thread Ant
On Jan 2, 7:07 pm, Rob Williscroft [EMAIL PROTECTED] wrote:
 Ant wrote in news:34a84caa-5387-40a2-a808-
  1) Is there a module out there for extracting files from an ISO?

 There are command line programs that can do this:

  http://cdrecord.berlios.de/old/private/cdrecord.html
...
 One problem you may have is daemon tools will mount cd images that
 aren't iso images, where as isoinfo appears to handle only genuine
 iso file systems.

Cheers for the pointers. I'll try out the isoinfo tool, as my
intention was to extract the images on the fly. If it turns out to be
slow though (or problematic - I assume you mean that images in e.g.
joliet format may not be parsed properly), I'll probably end up
extracting the images and caching them on disk on the addition of new
iso's by simply mounting the image as Grant pointed out.

And it looks like wxPython may have support for icons in an img2py
script, so that may sway me toward wxPython over TkInter.

Cheers,

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Extracting files from an ISO image?

2008-01-02 Thread Ant
Hi all,

My kids have a bunch of games that have to be run from CD (on Windows
XP). Now they're not very careful with them, and so I have a plan.
I've downloaded a utility (Daemon Tools) which allows me to mount and
unmount virtual CD drives onto an ISO image. This works well, but I
want to wrap this in a Python GUI which will present them with a list
of games in a particular directory.

Essentially the steps are this:

1) Look for all .iso files in a directory
2) Pull out the autorun.inf from the iso (if present) and parse it to
get the name of the icon file.
3) Extract the icon file from the iso and pull the image out.
4) Display the icon along with the iso name in a TKinter (of maybe
WxWidgets) app.

The images are important, as our 2 year old doesn't read (obviously),
but can navigate around the desktop by icon.

So I have two questions really:

1) Is there a module out there for extracting files from an ISO?
2) Is there a module out there for extracting icons from a Windows
exe?

Cheers,

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Python deques linked lists?

2007-12-10 Thread Ant
On Dec 9, 10:54 pm, John Machin [EMAIL PROTECTED] wrote:
 On Dec 10, 9:43 am, Just Another Victim of the Ambient Morality

 [EMAIL PROTECTED] wrote:
  I'm looking for a linked list implementation.  Something iterable with
  constant time insertion anywhere in the list.

 It's on the shelf between the jar of phlogiston and the perpetual
 motion machine.

lol!

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Why did no one tell me about import antigravity?

2007-12-05 Thread Ant
Python on xkcd:

http://xkcd.com/353/

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python vs pythonw

2007-11-30 Thread Ant
On Nov 30, 3:30 am, John Velman [EMAIL PROTECTED] wrote:
 New to mac.  I have leopard.  What's the difference between python and
 pythonw?  So far (which isn't very far)  I can't tell the difference.

 I have a small application using TKinter that I was working on under
 Linux.  Both python and pythonw run it, but on both it stops
 responding  (pinwheel of death) when I touch the vertical scrollbar.

On Windows, python runs in console mode (and pops up a console window
if you're not executing the script from a console already), pythonw
runs the script as a background process. I'd imagine that it is the
same for the Mac, and I shouldn't think it has anything to do with
your problem here.

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Witch editor to use!

2007-11-30 Thread Ant
On Nov 30, 9:10 am, SMALLp [EMAIL PROTECTED] wrote:
 Hello!

 I'm new in wxPython and before i start doing anything I have one qustion.

 Shoul I use some of editors like boa, spe or shoud i use my favorite
 text editor!

 i used IDLE on windows and it seamd nice. Now i have linux installed on
 my mashine and boa works, spe wont start, IDLE crashes when compailinfg!

 And if editor is bether choice witch one to use!

One with a spell checker would be a good start.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: foldr function in Python

2007-11-23 Thread Ant
On Nov 22, 7:14 pm, oj [EMAIL PROTECTED] wrote:
 On Nov 22, 3:02 pm, Ant [EMAIL PROTECTED] wrote:
...
 It's basically just one line to implement:

 foldr = lambda f, i: lambda s: reduce(f, s, i)

 It's just reduce with currying, I'm not sure it adds that much to what
 python already offers.

Yes it's easy to implement. I did it in two steps because I think it's
easier to read. That's not the point I'm trying to make though. sum,
any and all are trivial to implement, yet they made it into the
builtin methods.

The point of those functions I believe to be to promote easier to
understand idioms. Without them people will continue to write ad hoc
reduce based versions (which are less readable and less efficient).
With sum, any and all in the standard library, it becomes easier to
write readable code, and so people will be more likely to do so.

The other benefit is to promote ways of thinking about code that you
may not have come across or thought about before. This is a common
situation when learning new languages - before learning python I would
never have thought to use map or reduce functions, and these are
trivially easy to implement.

So my point really is that foldr (perhaps renamed to make_reducer or
something) could create idioms that are more readable than using
reduce directly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: foldr function in Python

2007-11-23 Thread Ant
On Nov 23, 10:54 am, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
...
 Alas and alack, I believe that Guido has a distaste for all but the
 simplest functional idioms, and an irrational belief that anything using
 reduce() must be too complex to bear. reduce() is going away, not just
 from the built-ins but (I believe) from the standard library as well.

I thought that at the last count it was merely being moved out into
functools (or somewhere similar).

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: may be a bug in string.rstrip

2007-11-23 Thread Ant
On Nov 23, 4:09 am, kyo guan [EMAIL PROTECTED] wrote:
...
  '120.exe'.rstrip('.exe')

Another approach since you seem to be working with filenames is using
the os.path module:

 import os.path as path
 s = test.torrent
 t = test.exe
 u = test
 path.splitext(s)[0]
'test'
 path.splitext(t)[0]
'test'
 path.splitext(u)[0]
'test'
-- 
http://mail.python.org/mailman/listinfo/python-list


foldr function in Python

2007-11-22 Thread Ant
Hi all,

I've just been reading with interest this article:
http://caos.di.uminho.pt/~ulisses/blog/2007/11/20/foldr-the-magic-function/

It's a useful function that (with a more intuitive name) could prove a
compelling addition to the itertools module. In it's python form, it
would be something like this:

def reduce2 (fn, init, seq):
 return reduce(fn, seq, init)

def foldr (function, initial):
return partial(reduce2, function, initial)

It's a bit different from the other itertools functions, in that
rather than producing an iterator, it produces a function which
reduces a iterator to a singe value.

The advantages I see over reduce are that (a) it provides incentive to
document the code and (b) it promotes reuse. For example:

value = reduce(lambda x, y: %s%s%s % (x, , if x else , y),
myList, )

vs.

commaSeparate = foldr(lambda x, y: %s%s%s % (x, , if x else ,
y), )
commaSeparate(myList)

Of course the lambda function in this case could be a named function,
helping with both readability and reuse, but I think the latter is
conceptually easier to grasp when reading the code.

Discuss.

--
Ant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python To Change The World :)

2007-11-14 Thread Ant
On Nov 14, 3:09 am, [EMAIL PROTECTED] wrote:
...
 so here is MY question:
 how would you replicate a street intersection in python? and
 furthermore, how would you do you have the cars move up and down those
 streets.

I've never used it, but I'd have thought that pygame would satisfy the
graphical side of things.

--
Ant

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


Re: Trouble with for loop

2007-11-06 Thread Ant
On Nov 6, 9:59 am, Shriphani [EMAIL PROTECTED] wrote:
...
 My main intention is to state that each of the variables namely a, b,
 c, ## can take value from 1 to 9.
 How do I go about this ?

It sounds like you are after something like:

for var in (a, b, c, d, e, f):
   assert var in [1, 2, 3, 4, 5, 6, 7, 8, 9]

but it's hard to tell without some more information from you on
exactly what you are trying to achieve.

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


Re: What is Jython?

2007-11-01 Thread Ant
On Nov 1, 6:54 am, [EMAIL PROTECTED] wrote:
...
 I would like to know more about Python and Jython?
 What is the difference between both of them?
 What is the future for Jython and which are the areas where it is
 used?

Jython is an implementation of Python for the Java VM. Currently it
stands as equivalent to Python v2.2, but progress has been rapidly
accelerating over the last year or so, and the next version will
probably be targeted at 2.5 AFAIK.

Jython also has access to all of the Java standard libraries (or any
Java libraries on the classpath for that matter.)

Jython is currently significantly slower than Python.

From my experience Jython is most typically used as an embedded
extension/scripting language for Java applications in areas where
rapid development/change is required. This includes such areas as
scripting business logic, writing unit or functional tests etc. Take a
look at 
http://antroy.blogspot.com/2007/04/swing-testing-with-jython-and-jemmy.html
for an example of how I have successfully used Jython for Swing
testing. More information can be found on 
http://www.jython.org/Project/index.html

Cheers,

--
Ant.

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


Re: permuting over nested dicts?

2007-11-01 Thread Ant
On Nov 1, 9:12 am, Anand [EMAIL PROTECTED] wrote:
...
 This code works for dictionaries of any nested level.

At least up to the max recursion depth.

--
Ant.

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


Re: What is Jython?

2007-11-01 Thread Ant
On Nov 1, 11:37 am, Ze'ev [EMAIL PROTECTED] wrote:
...
 ... Jython is currently significantly slower than Python.

 ...
 Not according to this 
 :http://blogs.warwick.ac.uk/dwatkins/entry/benchmarking_parallel_pytho...

Well I'm damned - I thought that I'd be writing about this being a
parallel example, and Java (and hence Jython)'s better threading
support. Decided to run a few of my old mathchallenge scripts
through both Python and Jython, and on some of the examples Python was
running almost 4 times slower...

So that's parallel processing and mathematical processing that seems
faster in Jython. It's be interesting to see a proper comparison of
how different types of program run.

The VM startup overhead is much slower mind, but then that's only an
issue for very small programs.

Cheers,

--
Ant.

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


Re: What is Jython?

2007-11-01 Thread Ant
On Nov 1, 1:23 pm, Ant [EMAIL PROTECTED] wrote:
 On Nov 1, 11:37 am, Ze'ev [EMAIL PROTECTED] wrote:
 ...

  ... Jython is currently significantly slower than Python.

  ...
  Not according to this 
  :http://blogs.warwick.ac.uk/dwatkins/entry/benchmarking_parallel_pytho...
...
 So that's parallel processing and mathematical processing that seems
 faster in Jython. It's be interesting to see a proper comparison of
 how different types of program run.

Simple rexex processing of a large log file on the other hand was 10x
faster in Python than Jython, so I guess it depends on what you want
to achieve.

--
Ant

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


Re: python with braces pre-processor

2007-10-22 Thread Ant
On Oct 22, 10:44 am, Paul Brauner [EMAIL PROTECTED] wrote:
 Hi, I'm working on a project that outputs several languages including
 (hopefully) python. My problem is that the generic backend architecture
 has not been designed to output correctly indented code, and that would
 be helpful if there were somewhere a python pre-processor that would take
 python with braces as an input and output regular python code. I thought
 that it must exists because everyone generating python code will
 encounter more or less the same problem, but I didn't find any 'official'

There's a tool in the standard Python distribution that processes code
with commented end statements. eg:

def my_funct():
pass
# end


or similar, and indents it correctly. This may be a possibility for
your purposes.



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


Re: python with braces pre-processor

2007-10-22 Thread Ant
On Oct 22, 10:58 am, Paul Brauner [EMAIL PROTECTED] wrote:
 I'll look at that. Thanks a lot !

I've just had a look, it's the pindent.py script in Tools/Scripts (at
least it is on Windows). It takes code of the following form:

def foobar(a, b):
   if a == b:
   a = a+1
   elif a  b:
   b = b-1
   if b  a: a = a-1
   # end if
   else:
   print 'oops!'
   # end if
# end def foobar

The help in the script looks pretty good.

--
Ant...

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


Re: Iteration for Factorials

2007-10-22 Thread Ant
On Oct 22, 1:26 pm, Py-Fun [EMAIL PROTECTED] wrote:
 I'm stuck trying to write a function that generates a factorial of a
 number using iteration and not recursion.  Any simple ideas would be
 appreciated.

The following simple adder functions should give you an idea of how
recursion can be recast as iteration:

def acc(i):
'''i should be a positive integer'''
if i  0:
return i + acc(i - 1)
return 0

print acc, acc(9)

def itt(i):
'''i should be a positive integer'''
out = 0

while i  0:
out += i
i = i - 1

return out

print itt, itt(9)

 ...
 Is it a factorial though?

Er, no. And neither is mine. You may want to google for the definition
of factorial! Here's a hint:

reduce(operator.mul, range(1, i + 1))

--
Anthony Roy


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


Re: question about for cycle

2007-09-29 Thread Ant
On Sep 29, 11:04 am, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
...
 What should I do if I want the outer for cycle to continue or break ? If I
 put a continue or break in the inner cycle, it has no effect on the outer
 cycle.

I'd also be interested in the idiomatic solution to this one. I can
see a number of solutions, from the ugly:

for i in range(10):
do_break = True
for j in range(10):
   if j == 6:
  break
else:
   do_break = False

if do_break:
   break

This will break the outer loop if the inner loop exited with a break.

Using exceptions:

for i in range(10):
  try:
for j in range(10):
   print i, j
   if j == 6:
  raise MyException
  except MyException, e:
break # or continue or whatever.

Encapsulating in a function and using return:

def get_value():
  for i in range(10):
for j in range(10):
   print i, j
   if j == 6:
  return fn(i, j)

I guess to an extent it would depend on the exact situation as to
which of these is more suitable. Are there any other recommended
solutions to this?

--
Ant...

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


Re: Python 3.0 migration plans?

2007-09-29 Thread Ant
I've posted my vote. However, I guess it won't be that simple in
practice. I suspect that the following is more likely:

1) Migrate to 3000 fairly soon after release for scripts and new
projects for which required third party modules are available for 3k
2) Migrate existing projects to 3k a) when frameworks/modules that
they use are available and b) if and when doing so would be
advantageous.

I suspect that many of the projects I have that are solid and are in
no imminent need of development will remain 3k for several years.

Cheers,

--
Ant

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


Re: An Editor that Skips to the End of a Def

2007-09-21 Thread Ant
On Sep 21, 4:47 am, W. Watson [EMAIL PROTECTED] wrote:
 How about in the case of MS Win?

Both emacs and vim have GUI versions that run on Windows.

--
Ant...

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


Re: How to insert in a string @ a index

2007-09-10 Thread Ant
On Sep 10, 3:15 am, a.m. [EMAIL PROTECTED] wrote:
 Thanks guys for you help. I ended up doing this way (for the
 records)...

 t1 = hello world hello. hello. \nwhy world hello
...

Another approach may be to use the re module's sub function:

import re

t1 = 'hello world hello. hello. \nwhy world hello'

def matchHandler(match):
if test here:
   return XYZ + match.group(0)
else:
   return match.group(0)

re.sub(keyword, matchHandler, t1)

The nice thing about this approach is that you could store keyword:
test_function pairs in a dictionary, and reuse this whole block of
code for arbitrary keywords with arbitrary rules.

--
Ant...

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


Re: python 2.5 problems

2007-09-10 Thread Ant
On Sep 9, 6:57 pm, O.R.Senthil Kumaran [EMAIL PROTECTED] wrote:
  Finally deleted 2.2 and loaded 2.5 (see below), using

 Dont delete. Uninstall python 2.2 and additional modules if you have 
 installed them.

But since you've already deleted 2.2, download and reinstall 2.2,
uninstall 2.2 and 2.5 via Add/Remove Programs and then reinstall 2.5
again.

--
Ant...

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


Re: sys.argv is munging my command line options

2007-08-29 Thread Ant
On Aug 29, 8:11 pm, Chris Allen [EMAIL PROTECTED] wrote:
...
 But I'm running into a problem with this which is that sys.argv splits
 my key=value options.  I need to know the option associations, and
 there's no way to know this by inspecting sys.argv.  Can I get access
 to the command line string as python saw it before it split it into
 sys.argv or is there another way?  Thanks.

Could you show us some example code that demonstrates this? The
following works as expected for me on win32:

# test.py
import sys

for arg in sys.argv[1:]:
print arg

From the command prompt:

C:\0test.py action key=value key=value
action
key=value
key=value

--
Ant.

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


Re: Newbee Question

2007-08-21 Thread Ant
On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote:
...
 Thanks for the help. By the way I am trying to learn the python after
 work and on weekends. If it was a dumb question, to this group, I will
 not bother you all again.

It's not so much that it was a dumb question, but that it was asked in
a dumb way :-) You'll get the most help in this group if you can show
some evidence that you've had a go (the size of this thread ironically
trounces that argument of course ;-) .)

It's better to learn if people give you a critique of your own attempt
at the code, rather than looking at other peoples efforts. There's a
guide on how to ask good questions here: 
http://www.catb.org/~esr/faqs/smart-questions.html

For what it's worth, here's a gratuitous version using generators, and
one you should come back to once you've mastered the basics of Python:

def counter(std_rate, over_rate, limit):
stops = 0
while True:
stops += 1
wage = stops * std_rate + max(0, stops - limit) * (over_rate -
std_rate)
yield stops, wage

truck = counter(0.4, 1.4, 22)

for i in range(30):
print Stopped %s times, with accumulated wage of $%s %
truck.next()

--
Ant...

http://antroy.blogspot.com/


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


Re: The folder a script is executed in

2007-08-21 Thread Ant
On Aug 21, 10:10 am, [EMAIL PROTECTED] wrote:
...
 myLocation = GetMyLocation()
 print myLocation

  C:/folder

Do you mean the folder containing the script? Or the current working
directory?

If the former, then look at os.path.split(sys.argv[0])[0]
If the latter, try something like: os.path.abspath(os.curdir)

--
Ant...

http://antroy.blogspot.com/


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


Re: The folder a script is executed in

2007-08-21 Thread Ant
On Aug 21, 10:29 am, [EMAIL PROTECTED] wrote:
 On 21 Aug, 11:27, Ant [EMAIL PROTECTED] wrote:



  On Aug 21, 10:10 am, [EMAIL PROTECTED] wrote:
  ...

   myLocation = GetMyLocation()
   print myLocation

C:/folder

  Do you mean the folder containing the script? Or the current working
  directory?

  If the former, then look at os.path.split(sys.argv[0])[0]
  If the latter, try something like: os.path.abspath(os.curdir)

  --
  Ant...

 http://antroy.blogspot.com/

 The following code -

 import os
 import sys
 print os.getcwd() + .
 print os.path.split(sys.argv[0])[0] + .

 gives me -

 C:\Documents and Settings\me\Desktop.
 .

Which looks correct. You've executed the code in an interactive
session launched from a desktop shortcut at a guess. You won't get the
location of the script unless you are actually running a script :-).
Of course you'll get a current working directory however you are
running python.

--
Ant...

http://antroy.blogspot.com/



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


Re: The folder a script is executed in

2007-08-21 Thread Ant
On Aug 21, 10:47 am, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
 Ant wrote:
...
 | print os.path.split(sys.argv[0])[0]

 $ cd tmp
 ~/tmp$ ../test.py
 ..
 ~/tmp$

 That's rather not what's intended. I'd try os.path.abspath(__file__)
 instead.

Fair point. On Win32 sys.argv[0] always seems to give the full path
rather than the relative path - hadn't realised it was different for
linux (?).

--
Ant...

http://antroy.blogspot.com/


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


Re: C# and Python

2007-08-21 Thread Ant
On Aug 21, 11:01 am, subeen [EMAIL PROTECTED] wrote:
 Hi,
...
 But I want to write the GUI and number generation program in C#.net.
 When the user clicks Quick Sort button, the quicksort.py will be
 called and it will sort the numbers.

Probably worth looking at IronPython, the Python implementation for
the .Net platform.

--
Ant...

http://antroy.blogspot.com/


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


Re: Python question (PyNoob)

2007-08-20 Thread Ant
On Aug 20, 1:33 am, Anonymous [EMAIL PROTECTED] wrote:
...
 1). Data Munging (text processing) - instead of Perl

Check out the re module (regexes) in the standard library, and the
pyparsing third party library: http://pyparsing.wikispaces.com/ for
more complex stuff.

 2). Automating my build process

You'll want to look into the os, sys and subprocess modules. The PMOTW
this week was subprocess: 
http://www.oreillynet.com/onlamp/blog/2007/08/pymotw_subprocess_1.html.
A few weeks back it covered os: 
http://blog.doughellmann.com/2007/05/pymotw-os.html.
In fact one of Doug Hellmann's previous articles on the getopt module
may also be useful if you want your build scripts to be controlled by
command line args: http://blog.doughellmann.com/2007/08/pymotw-getopt.html
(Though I prefer optparse personally).

 3). (Possibly) some web data retrieval jobs

urllib, urllib2 and cookielib in the standard library should do most
of what you want, perhaps with the addition of beautiful soup if you
need to scrape the pages for data: http://www.crummy.com/software/BeautifulSoup/

HTH.

--
Ant...

http://antroy.blogspot.com/


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


Re: creating and appending to a dictionary of a list of lists

2007-08-15 Thread Ant
On Aug 15, 3:30 am, [EMAIL PROTECTED] wrote:
 Hey,

 I started with this:

 factByClass = {}

...
 def update(key, *args):
 x = factByClass.setdefault(key, [[], [], [], [] ])
 for i, v in enumerate(args):
 x[i].append(v)

 Is there a better way?

Well, the following is perhaps neater:

 factByClass = defaultdict(lambda: [[],[],[],[]])
 def update(key, *args):
...   map(list.append, factByClass[key], args)
...
 update('one', 1, 2, 3, 4)
 update('one', 5, 6, 7, 8)
 update('two', 9, 10, 11, 12)

 print factByClass
defaultdict(function lambda at 0x00F73430, {'two': [[9], [1
0], [11], [12]], 'one': [[1, 5], [2, 6], [3, 7], [4, 8]]})

It abuses the fact that list.append modifies the list in place -
normally you would use map to get a new list object. In this case the
new list returned by map is just a list of None's (since append
returns None - a common idiom for functions that operate by side
effect), and so is not used directly.

--
Ant...

http://antroy.blogspot.com/



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


Re: buggie in else syntax ?

2007-08-15 Thread Ant
On Aug 15, 9:40 am, stef mientki [EMAIL PROTECTED] wrote:
 Thomas Jollans wrote:
...
 else: JSM(230) ; \
 if b3:  == SYNTAX ERROR pointing to the f of if

This is equivalent to:

 else: JSM(230) ;   if b3:

If statements (any compund statements in fact such as for loops etc)
*must* start on a new line (with indentation as necessary):

http://docs.python.org/ref/compound.html

--
Ant...

http://antroy.blogspot.com/


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


Re: The Future of Python Threading

2007-08-11 Thread Ant
On Aug 11, 5:43 am, Seun Osewa [EMAIL PROTECTED] wrote:
  I think I've heard Guido say the last attempt at removing the Global
  Interpreter Lock (GIL) resulted in a Python that was much slower...

 What is it about Python that makes a thread-safe CPython version much
 slower?  Why doesn'ttrue threading slow down other languages like Perl
 and Java?

I have no idea about Perl - but there's probably some hideous black
magic going on ;-)

As for Java, making code thread safe *does* slow down the code. It is
the very reason that the language designers made the collections API
non-thread safe by default (you have to wrap the standard collections
in a synchronised wrapper to make them thread safe).

--
Ant...


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


Re: py2exe with python 2.5

2007-08-10 Thread Ant
On Aug 10, 11:47 am, [EMAIL PROTECTED] wrote:
 On 10 kol, 11:02, Ant [EMAIL PROTECTED] wrote:
...
 yes,Python 2.5 is on the path, but how can I remove panda3d from that
 path?

Hit Win - Break to bring up the System Properties dialog (you can also
get here through the Control Panel).

Go to the Advanced tab, and click the Environment Variables button.
Find the PATH variable in one of the two lists, and edit it. Just
remove the Panda3D entry.

Note you'll have to restart your console to pick up any changes.

--
Ant...

http://antroy.blogspot.com/


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


Re: Smoother Lines in Turtle Graphics

2007-08-10 Thread Ant
On Aug 10, 11:41 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 tomy wrote:
  Hi All
...
 What turtle graphics? I'm not aware that there is some
 standard-turtle-graphics available, so it might be a problem of your
 turtle-graphics-package.

 Diez

import turtle

Its part of the standard Library! I don't know the answer to the OP's
question mind you, I'd played around a little with it a while ago, but
nothing more.

Python: Batteries and Turtles included!

--
Ant...

http://antroy.blogspot.com/




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


Re: py2exe with python 2.5

2007-08-10 Thread Ant
On Aug 10, 8:39 am, [EMAIL PROTECTED] wrote:
 Hello,

 Now,I was install python 2.5 and remove python 2.4 completely.After I
 write:
 $ python mysetup.py py2exe
 ...
  import py2exe_ util
 ImportError: Module use of conflicts with this version of Python

 ...ok, I know what is a problem, I haven't remove python completely,
 in my computer is one more folder Panda3D-1.4.0 but when I remove it
 and all dll files include python24.dll, I cannot run python or make
 that setup.
 (That panda3d contain python)

 Regards,
 Vedran

Sounds like your path needs setting up properly. Try typing echo %PATH
% into your console window to find out if Python2.5 is in the path. If
you are using the default setup, then c:\Python25 should be on the
path.

--
Ant...

http://antroy.blogspot.com/


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


Re: Seek the one billionth line in a file containing 3 billion lines.

2007-08-08 Thread Ant
On Aug 8, 11:10 am, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 Jay Loden a écrit :
 (snip)

  If we just want to iterate through the file one line at a time, why not 
  just:

  count = 0
  handle = open('hugelogfile.txt')
  for line in handle.xreadlines():
  count = count + 1
  if count == '10':
  #do something

 for count, line in enumerate(handle):
  if count == '10':
  #do something

You'd get better results if the test were:

if count == 10:

Or probably even:

if count == 9:

Since the 1 billionth line will have index 9.

Cheers,

--
Ant...

http://antroy.blogspot.com/






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

Re: regexp problem in Python

2007-08-07 Thread Ant
On Aug 3, 10:41 pm, Ehsan [EMAIL PROTECTED] wrote:
...
 what can I do? what's wrong whit this pattern? thanx for your comments

Nothing. There's something wrong with the code you are using the regex
with. Post it and we may be able to help. Like Lawrence has said, it's
likely to be that you are using m.group(1) with your match object
instead of m.group(0) - the former gets the first group (i.e.
everything between the first set of parens - in your case the wmv|3gp
expression), whereas the latter will return the entire match.

Post your actual code, not just the regex.

--
Ant...

http://antroy.blogspot.com/



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


Re: Best programs written completly in Python

2007-08-06 Thread Ant
On Aug 5, 12:31 pm, Campbell Barton [EMAIL PROTECTED] wrote:
...
 * ubuntu have some of their install tools in python.

Gentoo Linux's Portage package management tool is written in Python.

--
Ant...

http://antroy.blogspot.com/


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


Re: Where do they tech Python officialy ?

2007-08-01 Thread Ant
On Aug 1, 9:40 am, Alex Popescu [EMAIL PROTECTED] wrote:
...
 It depends :-). In my experience I met employers being concerned by my
 implication in the oss world :-).

I have the opposite experience. It was predominantly the fact that I
was involved in several open source projects that got me into
professional development 3 years ago. The employers in the market at
the time required 2 years+ of commercial experience - the fact that I
was involved in OSS helped on two counts, firstly that it showed that
I actually have an interest in development (rather than being another
Comp Sci graduate just after a wage), and secondly that I have
experience in good development practice (the open source projects I
worked on had better infrastructure in place than two of the three
companies I've worked for since!)

--
Ant...

http://antroy.blogspot.com/


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


Re: Can python access windows clipboard

2007-06-21 Thread Ant
On Jun 21, 9:59 am, MaHL [EMAIL PROTECTED] wrote:
 Can I use python to copy something(like a string) to the clipboard, so
 that I can paste it somewhere else. Is there a way to do this?

The following requires Mark Hammond's win32all package (http://
sourceforge.net/projects/pywin32/):

import win32clipboard, win32con, random

text = Some text to stick on the clipboard

win32clipboard.OpenClipboard()
win32clipboard.SetClipboardData(win32con.CF_TEXT, text)
win32clipboard.CloseClipboard()

--
Ant...

http://antroy.blogspot.com/


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


Re: static python classes ?

2007-06-19 Thread Ant
It's not clear what you mean here. If you mean something like static
inner classes in Java, then you can simply nest classes in Python:

 class A(object):
...   class B(object):
...  def aaa(self):
... print AA
...
 z = A.B()
 z.aaa()
AA

(In contrast the equivalent of Java's ordinary inner class:
 class A(object):
... def __init__(self):
... class B(object):
... def aa(self):
... print 
... self.B = B
...
 A().B().aa()


)

If you mean static class as in an class which only has static
methods and variables, then the python equivalent is a module.

 I'm new to python, and I can't seem to find in the docs how to create
 the python equivalent of what's called in most OOP languages static
 classes, can you give me a hint ?

Hope the above was what you are looking for.

--
Ant...

http://antroy.blogspot.com/

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


Re: MySQL - Jython2.2

2007-06-15 Thread Ant
On Jun 15, 3:31 pm, HMS Surprise [EMAIL PROTECTED] wrote:
 I thought I had a winner mySql-python but it require2 python 2.3-5 and
 the tool I am using (maxq) is based on jython 2.2. Is there another
 way that I could perform queries from python?

If you want to query via Jython, use the jdbc driver from www.mysql.com,
and you an then use JDBC from within Jython. You'll just need to add
the mysql jdbc jar to your classpath.

HTH.

--
Ant...

http://antroy.blogspot.com/




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


Re: Help a C++ escapee!

2007-06-07 Thread Ant
Hi Simon,

 When run, I come unstuck here:

 self.clientSocket, self.clientAddress = network.accept()

 I get a nameError on 'network', yet it is one in the global namespace,
 defined in server.py before CServerThread.Listen() is called.

You have imported everything from socketManager in server.py, but
socketManager knows nothing about any globals defined in the server
module! You'd need to import it in socketManager.py:

from server import network

However this may not work, since you have circular dependencies in
your code - server requires socketManager and vice versa. Even if this
does work it is bad practice, and is an indication that your classes
are in the wrong modules, or that your classes need refactoring
somewhat.

A simple solution would be to pass an instance of the CNetworkManager
into CServerThread. i.e.

...
def Listen(self):
self.threadArray =[]
self.ch = 0
while self.ch  self.maxClients:
#Create a thread listening to each socket
self.newThreadObject = CServerThread(self)
self.newThreadObject.start()
self. threadArray.append(self.newThreadObject)
self.ch=self.ch+1
class CServerThread(threading.Thread):
def __init__(self, network):
self.network = network

def run(self):
while (1):
self.clientSocket, self.clientAddress =
self.network.accept()

...

HTH.

--
Ant...

http://antroy.blogspot.com/





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


Re: Translating some Java to Python

2007-05-21 Thread Ant
On May 20, 9:24 pm, Daniel Gee [EMAIL PROTECTED] wrote:
...
 The Java version has static methods for common roll styles (XdY and XdY
 +Z) for classes that just want a result but don't want to bother
 keeping an object around for later.

 So the question is, assuming that I wanted to keep the static method
 behavior (which I'm not really sure I do), how does one format the
 method header on a 'static' method in Python? Is it just something
 like:

 class Foo:
   def statAdd(self,a):
 return a+5

 or do you drop the 'self' bit and just use a 1 variable parameter list?

Herman has shown you *how* to do static methods in Python, but
typically they are not used. Since Python has first class functions,
and they can be defined at the module level, there is no need to use
static methods.

There is a distinction in Python not present in Java between class and
static methods, class methods get the class passed in as the first
parameter, and can be useful if you want a function that acts on data
that the class provides. Static methods in Python are merely normal
functions that are associated with the class - for conceptual reasons
rather than practical ones, and are rarely used as far as I can tell.
I've certainly never bothered with them.

In the case of your statAdd above, self is never used in the method
body, and so this is a clear indication that a module level function
would be more appropriate.

--
Ant...

http://antroy.blogspot.com/


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


  1   2   3   4   >