Re: c interfacing in 2.5

2007-09-15 Thread Szabolcs Nagy

Diez B. Roggisch wrote:
 ctypes is for C. Where it is great to use.

if you need simple wrappers then swig and ctypes are both good since
they can generate it for you

pyrex is also good for wrapping and for writing c extension code

 If you need C++-wrapping, I recommend SIP.

i recommend py++ for wrapping c++

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


Re: Bragging about Python

2007-06-08 Thread Szabolcs Nagy

Steve Howell wrote:
 --- Georg Brandl [EMAIL PROTECTED] wrote:
  
   15 small programs here:
  
   http://wiki.python.org/moin/SimplePrograms
  
  
   IMHO a few python goodies are missing there.
 
  It's a Wiki. ;)
 

 Yes indeed.  Please feel free to add to the page, or
 make your own fork.  See link above.

the title of a program shouldn't be part of the code (or it should at
least start with #)
sorry i'm too lazy now to fix it, but imho it needs nicer layout to be
used as 'bragging about python' site

btw nice idea
a good example worth a 100 pages of documentation

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


Re: compiling python and calling it from C/C++

2007-06-08 Thread Szabolcs Nagy

Russ wrote:
 Is it possible to compile python code into a library (on unix), then
 link to it and call it from C/C++? If so, where can I learn how.
 Thanks.

not really but you may want to look into these:
http://codespeak.net/pypy
http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
http://sourceforge.net/projects/shedskin/

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


Re: url to image

2007-06-07 Thread Szabolcs Nagy

[EMAIL PROTECTED] wrote:
 just wondering are there any snippets out there where you can convert
 a url to an image using python

you mean render a webpage as an image?
does not sound a simple task
maybe you can use oss web rendering engines like gecco, khtml or
webcore

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


Re: Bragging about Python

2007-06-07 Thread Szabolcs Nagy

Cameron Laird wrote:
 In article [EMAIL PROTECTED],
 Mathias Panzenboeck  [EMAIL PROTECTED] wrote:
def fib():
generation, parent_rabbits, baby_rabbits = 1, 1, 1
while True:
yield generation, baby_rabbits
generation += 1
parent_rabbits, baby_rabbits = \
   baby_rabbits, parent_rabbits + baby_rabbits

 for pair in fib():
 if pair[0]  100:
 break
 print Generation %d has %d (baby) rabbits. % pair

 as more appealing to non-Pythoneers.  I'm still suspicious about
 how they're going to react to itertools.islice().  Now, though,
 I've begun to question my own sense of style ...

actually i don't like when a tutorial uses over complicated cute names
if the context is obvious (fibonacci) then we don't need to add
'parent_rabbits' and such identifiers
eg i find more readable and clear the following:

def fib():
a, b = 0, 1
while True:
yield a
a, b = b, a + b

for (n, fn) in enumerate(fib()):
if n  100:
break
print F[%d] = %d % (n, fn)

ymmv

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


Re: Graph plotting module

2007-06-04 Thread Szabolcs Nagy

Viewer T. wrote:
 Is there a python module anywhere out there that can plot straight
 line graphs, curves (quadratic, etc). If anyone knows where I can
 download one, please let me know.
http://matplotlib.sourceforge.net/

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


Re: writing to a file

2007-05-30 Thread Szabolcs Nagy

[EMAIL PROTECTED] wrote:
 as i understand there are two ways to write data to a file: using
 f.write(foo) and print f, foo.
well print will add a '\n' or ' ' if you use ',' after it

 what i want to know is which one is faster (if there is any difference
there shouldn't be any noticable difference

 in speed) since i'm working with very large files. of course, if there
 is any other way to write data to a file, i'd love to hear about it
other ways:
os.system('cat file1  file2')
or subprocess.Popen
or print but sys.stdout = f
or ctypes + printf/fputs/..

and probably there are other obscure ways, but the intended way is
obviously f.write

nsz

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Szabolcs Nagy

John DeRosa wrote:
 +1 QOTW

 Hey, did you hear about the object-oriented version of COBOL?  They call it
 ADD ONE TO COBOL.

actually it is ADD 1 TO COBOL GIVING COBOL

http://en.wikipedia.org/wiki/COBOL#Aphorisms_and_humor_about_COBOL

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Szabolcs Nagy

Joe Riopel wrote:
 Using camel case instead of the under_score means less typing. I am lazy.

 fooBar
 foo_bar

camel case makes source code extremely ugly in weird disturbing way

YMMV

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


Re: need advice on building core code for python and PHP

2007-05-24 Thread Szabolcs Nagy

 Is there a way I could code the base (core) code in Python and have
 PHP call it?  I've really liked using SQLAlchemy and there are other

* quick and dirty solution:
in a shell:
  $ python yourscript.py pipe_in pipe_out
in the php script:
  fwrite(pipe_in, input_data);
  results = fread(pipe_out, sizeof_results);

* simple and nice solution:
  do not ever use php

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


Re: python/C++ wrapper

2007-03-14 Thread Szabolcs Nagy
 - A c++ program receives a 2D-matrix from python as input and gives a
 2D-matrix as output back to python.

pyogre uses swig

ogre is a 3d realtime rendering engine written in c++ so there are
many matrix manipulation there and also pyogre does not modify the
original code

cgkit is a computer graphics toolkit written in c++ for python and it
uses boost-python and it uses matrices as well

if you want matrix manipulations in python then you may want to look
into numpy c api

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


Re: python/C++ wrapper

2007-03-14 Thread Szabolcs Nagy

 Well, pyogre has few problems with maintenance, and new bindings to
 Ogre engine was
 created using Boost.Python( http://www.ogre3d.org/wiki/index.php/PyOgre )

oh
last time i played with pyogre they made a transition from boost to
swig :)
so they are back again at boost
(the problem with boost was the slow recompilation time with all the
gccxml parsing and a few other problems which maybe got resolved)

 --
 Roman Yakovenko
 C++ Python language binding
 http://www.language-binding.net/

thanks for the info this py++ looks promising

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


Re: Request for a change in the csv module.

2007-03-13 Thread Szabolcs Nagy

 It would be much better to be able to specify an additional
 variabel to the Dialect class and change csv.

no it wouldn't
this is a locale specific problem so it should be handled there

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


Re: What is the best queue implemetation in Python?

2007-02-23 Thread Szabolcs Nagy
 For that purpose I have used the good deque that you can find in
 collections in the standard library. It's very good for queues, and
 it's a bit faster than regular lists for stacks too.

you mean *much* faster (since a list is a reference array so pop(0) is
O(n) operation)

never use a list as queue if len(queue)  1

=== benchmark

$ time ./deque_queue.py
34359607296

real0m0.286s
user0m0.264s
sys 0m0.016s

$ time ./list_queue.py
34359607296

real1m20.915s
user1m18.649s
sys 0m0.396s


=== the sources

--- deque_queue.py:
#!/usr/bin/python2.5

from collections import deque

def f(n):
sum = 0
queue = deque()
for i in range(n):
queue.append(i)
while queue:
sum += queue.popleft()
print sum

if __name__=='__main__':
f(118)

--- list_queue.py:
#!/usr/bin/python2.5

def f(n):
sum = 0
queue = list()
for i in range(n):
queue.append(i)
while queue:
sum += queue.pop(0)
print sum

if __name__=='__main__':
f(118)

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


Re: Regex Speed

2007-02-22 Thread Szabolcs Nagy
 Well, just as an idea, there is a portable C library for this at
 http://laurikari.net/tre/ released under LGPL.  If one is willing to
 give up PCRE extensions for speed, it might be worth the work to
 wrap this library using SWIG.

actually there is a python binding in the tre source with an example
python script so it is already done.

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


Re: f---ing typechecking

2007-02-14 Thread Szabolcs Nagy

Sergey Dorofeev wrote:
 Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on
 win32
 Type help, copyright, credits or license for more information.
  (1,)+[1]
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: can only concatenate tuple (not list) to tuple
  [1]+(1,)
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: can only concatenate list (not tuple) to list
 

 Its ugly and boring.

what?
for me it works fine:

 (1,)+tuple([1])
(1, 1)
 [1]+list((1,))
[1, 1]

also

 L=[1]
 L.extend((1,))
 L
[1, 1]

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


Re: Recursive calls and stack

2007-02-14 Thread Szabolcs Nagy

[EMAIL PROTECTED] wrote:
 Hi,
  I have a program which literately finds the object that overlapping a
 point. The horizontal and vertical search are called recursively from
 inside each other.
 ...

in case you ever need deeply nested recursion:
one solution is to use the already mentioned sys.setrecursionlimit(n)
another is to use your own stack

dummy example:

def fact_recursive(n):
if n0:
return fact_recursive(n-1)*n
else:
return 1

def fact_iterative(n):
stack = []
while n  0:
stack.append(n)
n -= 1
ret = 1
while stack:
ret *= stack.pop()
return ret

actually you can always rewrite recursion with a stack and iterations

note that if you use version = 2.4, then collections.deque is faster
for stack (and especially for queue) data structure than list.

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


Re: favourite editor

2007-02-11 Thread Szabolcs Nagy

azrael wrote:
 Since i'm new on this forum, and first time meeting a python comunity,
 i wanted to ask you for your python editors.

 Im looking for some good python editor, with integrated run function,
 without having to set it up manualy like komodo.
 I found the pyscripter, and it has all i need, but it's unsatble.
 bloated. it crashes when i close an yplication window run by python
 from pyscripter. please. tell me a good one with buil in run (-very
 important) and nice gui. if possible to suport projects, code
 highlighting, code completition, class browser, python comand line
 (), traceback.

 I didn't take a look on vista (and i dont want to), but i hope they
 improved the notepad.

*sigh*
this question arises at least three times a week on this group

you can use the googlegroups search function:
http://groups.google.com/group/comp.lang.python/search?group=comp.lang.pythonq=python+editor+ideqt_g=Search+this+group

also use the python wiki:
http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
http://wiki.python.org/moin/PythonEditors

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


Re: python linux distro

2007-02-10 Thread Szabolcs Nagy
 ^was(is)^may one day be, but probably not,^

  From the quoted page:

 The project is in an early development phase and as of January 2007,
 no significant progress was being made due to lack of developer time.[5]

well actually i managed to boot unununium in qemu so it _is_ an os

but obviously there isn't much code and the devs gave up so that's why
it _was_ an os project

anyway it was not an os about python, but a desktop os with a highly
different approach from current os-es they just happen to use a lot of
python

there were a lot of interesting ideas so the mail archives might be
useful for anyone who is interested in os development
http://unununium.org/pipermail/uuu-devel/

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


Re: Best Free and Open Source Python IDE

2007-02-09 Thread Szabolcs Nagy

Srikanth wrote:
 Yes,

 All I need is a good IDE, I can't find something like Eclipse (JDT).
 Eclipse has a Python IDE plug-in but it's not that great. Please
 recommend.

 Thanks,
 Srikanth

try pida
http://pida.co.uk/index.php/Main_Page

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


Re: python linux distro

2007-02-09 Thread Szabolcs Nagy

 Now what would be interesting (and *really* crazy) would be Linux (or
 BSD or whatever) distro written almost entirely *in* Python, with the
 goal of eliminating as much bash/sh as possible.

 That would be fun.

actually there was(is) an os whitch is written almost entirely *in*
Python:
http://en.wikipedia.org/wiki/Unununium_(operating_system)

(their main site http://unununium.org seems to be down)

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


Re: mplayer bug or python bug?

2007-02-07 Thread Szabolcs Nagy

Marco wrote:
 The following code is my test program for control mplayer.
 in movies/ there are about 20 movies, the code plays them in circle,
 but mplayer will crash silently after a circle, the sliently means I
 can handle popen2 without except, but no movie.

i had some problem with mplayer slave mode too.

everything worked ok, but after some movies i got broken pipe
caught signal xy error message on stderr and mplayer quit.

mplayer always crashed on the same files and always at the very end
(which you normally don't notice since you only want to view 1 file so
probably it has nothing to do with slave mode, but buggy mplayer +
buggy files)

my solution was: check for error and restart mplayer if it crashed (i
parsed every output so i knew where are we in the playlist)

btw if you just want to use the script to play files in loop, then
mplayer has a -loop option as well.

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


Re: C parsing fun

2007-02-05 Thread Szabolcs Nagy
 based on concepts my boss had. To do this I needed to represent C++
 code structure in Python somehow. I read the docs for Yapps, pyparsing
 and other stuff like those, then I came up with a very simple idea. I
 realized that bracketed code is almost like a Python list, except I
 have to replace curly brackets with squared ones and surround the
 remaining stuff with quotes. This process invokes no recursion or node

yes that's a nice solution
sometimes it's not enough though (won't work on code obfuscated with
macros)

anyway if you need something more sophisticated then i'd recommend
gccxml or it's python binding:

http://www.language-binding.net/pygccxml/pygccxml.html

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


Re: Python does not play well with others

2007-02-03 Thread Szabolcs Nagy

Paul Rubin wrote:
 George Sakkis [EMAIL PROTECTED] writes:
   What does batteries included mean to you?  To me, it means you don't
   have to install add-ons.
 
  So let's make a 500MB executable and add Numpy, Zope, Django, PIL,
  pretty much everything actually. Even better, make CheeseShop just a
  frontend to a build system that adds and updates automatically
  submitted packages to the core. Problem solved ! wink.

 Numpy should certainly be included and I think there are efforts in
 that direction.  There is also a movement to choose a web framework to
 include and Django might be a good choice.  I think the Zope
 maintainers want to keep Zope separate and I think PIL has an
 incompatible license...

do not do that

(1)
i love when i can create a minimalistic system

think about it this way: what if you want to run python on an embeded/
low resource system?

if you want python to do webhosting the solution is _not_ to include
every related package

look at eg. debian: you can use it for lowresource system, desktop,
scientific computation and for webserver as well because of it's
package management system -- you can build a min. system and a huge
system as well.

(2)
seriously, python is a programming language and not a flee market (so
don't compare it to java or php)

unfortunately lots of ppl working on web related stuff think web is
the only reason a programming language should exist, which is pretty
stupid

i don't want a webmodule in a stdlib at all. implementing the
standards and recommendations should be enough. web in general is a
huge and ugly bloat, keep it away from a language core.

(3)
having a maintained set of modules for every possible problem is nice,
but shouldn't be a part of the core lib.

eg. numpy, mysql, ssl, pil, ... are not needed in the stdlib since
most of the programming tasks don't need those

they should be maintained separately, with an easy way to find and
install them. that's what cheese shop and distutils are for.

for me batteries included means i get a clean and consistent stdlib
and if i need special functionality i can add modules and extensions
easily

nsz

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


Re: Python **kwargs ?

2007-01-31 Thread Szabolcs Nagy

johnny wrote:
 What is **kwargs mean in python?  When you put double **, does it mean
 passing by reference?

here's a little example:

 def f(a, *args, **kw):
... print 'a:',a
... print 'args:',args
... print 'kw:',kw
...
 f(1,2,3,x=4)
a: 1
args: (2, 3)
kw: {'x': 4}
 f(a=1,b=2,c=3)
a: 1
args: ()
kw: {'c': 3, 'b': 2}

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


Re: Is any python like linux shell?

2007-01-30 Thread Szabolcs Nagy

Brian Visel wrote:
 ipython is probably what you're looking for.

or
http://sourceforge.net/projects/pyshell

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


Re: How can I know both the Key c and Ctrl on the keyboard are pressed?

2007-01-30 Thread Szabolcs Nagy

[EMAIL PROTECTED] wrote:
 Hi;
 How can I know the Key c and Ctrl on the keyboard are pressed? Or how
 to let the program press the

 key Ctrl+c automatically? I just want to use python to develop a
 script program.
 gear

depends on where you got your input from and what do you exactly want

eg:
in a gui app you get input events from the gui toolkit (wx, gtk, sdl/
pygame...)
in a console app if you use curses lib then you can use getch() oslt

if you want a general solution to get input key events in a simple 
script then you cannot do that.

however Ctrl+C is a special key combination: running python in a unix 
terminal it raises KeyboardInterrupt exception, imho in a windows cmd 
promt it raises SystemExit

so you can emulate those by using:
raise KeyboardInterrupt
or
raise SystemExit

hope this helps

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


Re: data design

2007-01-30 Thread Szabolcs Nagy
 The lazy way to do this: have modules that initialize bunches of
 objects, attributes holding the data: the object is somehow the row of
 the table, attribute names being the column. This is the way I
 proceeded up to now.
 Data input this way are almost configuration data, with 2 big
 drawbacks:
   - Only a python programmer can fix the file: this cant be called a
 configuration file.
   - Even for the author, these data aint easy to maintain.

 I feel pretty much ready to change this:
 - make these data true text data, easier to read and fix.
 - write the module that will make python objects out of these data:
 the extra cost should yield ease of use.

 2 questions arise:
 - which kind of text data?
  - csv: ok for simple attributes, not easy for lists or complex
  data.
  - xml: the form wont be easier to read than python code,
but an xml editor could be used, and a formal description
of what is expected can be used.
 - how can I make the data-to-object transformation both easy, and able
to spot errors in text data?

 Last, but not least: is there a python lib implementing at least part
 of this dream?

there is a csv parser and multiple xml parsers in python (eg 
xml.etree) also there is a ConfigParser module (able to parse .ini 
like config files)

i personally like the python module as config file the most

eg if you need a bunch of key-value pairs or lists of data:
* python's syntax is pretty nice (dict, tuples and lists or just 
key=value)
* xml is absolutely out of question
* csv is very limited
* .ini like config file for more complex stuff is not bad but then you 
can use .py as well.

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


Re: data design

2007-01-30 Thread Szabolcs Nagy

 Hurray for yaml! A perfect fit for my need! And a swell tool!
 Thanks a lot!

i warn you against yaml
it looks nice, but the underlying format is imho too complex (just 
look at their spec.)

you said you don't want python source because that's too complex for 
the users.
i must say that yaml is not easier to use than python data structures.

if you want userfriedly config files then ConfigParser is the way to 
go.

if you want somthing really simple and fast then i'd recommend s-
expressions of lisp

also here is an identation based xml-like tree/hierarchical data 
structure syntax:
http://www.scottsweeney.com/projects/slip/

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


Re: Random passwords generation (Python vs Perl) =)

2007-01-29 Thread Szabolcs Nagy
 If you don't mind possibly getting a few nonalphanumeric characters:

 import os,binascii
 print binascii.b2a_base64(os.urandom(6))

what about

file('/dev/urandom').read(6).encode('base64')

(oneliner and without import sa op requested)

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


Re: Random passwords generation (Python vs Perl) =)

2007-01-29 Thread Szabolcs Nagy
 If you don't mind possibly getting a few nonalphanumeric characters:

 import os,binascii
 print binascii.b2a_base64(os.urandom(6))

what about

file('/dev/urandom').read(6).encode('base64')

(oneliner and without import as op requested)

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


Re: Random passwords generation (Python vs Perl) =)

2007-01-29 Thread Szabolcs Nagy

 Is os.urandom cryptographically strong on all platforms?

http://docs.python.org/lib/os-miscfunc.html

The returned data should be unpredictable enough for cryptographic 
applications, though its exact quality depends on the OS 
implementation.

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


Re: Random passwords generation (Python vs Perl) =)

2007-01-29 Thread Szabolcs Nagy
 If you really want a hack, here it is:

 while 1:print
 ''.join(__import__('random').choice(__import__('string').letters+'1234567890')
 for x in xrange(8)),;n=raw_input()

 This is a one-liner (though mail transmission may split it up), no
 import statements. If someone can come up with an even smaller version,
 feel free to post. :)

while 
1:i=__import__;print''.join(i('random').choice(i('string').letters
+'1234567890')for x in range(8)),;raw_input()

same but shorter:
i = __import__;
xrange - range (why use xrange? range is faster and simpler for small 
ranges)
n =(not needed)

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


Re: Random passwords generation (Python vs Perl) =)

2007-01-29 Thread Szabolcs Nagy

 while
 1:i=__import__;print''.join(i('random').choice(i('string').letters
 +'1234567890')for x in range(8)),;raw_input()


while 
1:i=__import__;r='random';print''.join(i(r).choice(i('string').letters
+'1234567890')for x in`r`),;raw_input()

even shorter:
range - `'random'`

:)

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


Re: [Boost.Graph] graph.vertices property creates new objects

2007-01-29 Thread Szabolcs Nagy
 It seems that the vertices iterator creates new vertex objects every
 time instead of iterating over the existing ones. This essentially

i don't know much about bgl, but this is possible since vertices are 
most likely not stored as python objects inside boost

 prevents, among other things, storing vertices as keys in a dictionary
 since the hashes of the stored and the new vertex differ although they
 compare equal. Is this really what's happening, and if so, why ?

that sounds bad, fortunately __hash__ can be overriden so even if id() 
differs hash() can be the same for the same vertex.
if __hash__ is not handled then it's a bug in bgl imho.

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


Re: python 2.3 module ref

2007-01-29 Thread Szabolcs Nagy

 any pointers to a 2.3 module ref?

also look at:
http://rgruet.free.fr/PQR2.3.html#OtherModules

when coding for different python versions i can reccommend this quick 
ref:
http://rgruet.free.fr/

(every language feature is colorcoded according to the version when it 
was included)

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


Re: deepcopy alternative?

2007-01-29 Thread Szabolcs Nagy
 I believe the only thing stopping me from doing a deepcopy is the
 function references, but I'm not sure.  If so is there any way to
 transform a string into a function reference(w/o eval or exec)?

what's your python version?
for me deepcopy(lambda:1) does not work in py2.4 but it works in py2.5
(in py2.4 i tried to override __deepcopy__ but it had no effect)

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


Re: Graph Data Structures

2006-11-25 Thread Szabolcs Nagy
i haven't read your code, but there are many graph implementations in
python.
in case you haven't found these yet:
http://wiki.python.org/moin/PythonGraphApi

if you only want to do some analysis i think you need this one (as it's
pretty complete and simple):
https://networkx.lanl.gov/

i also recommend Guido's essay to read:
http://www.python.org/doc/essays/graphs.html

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


gopherlib deprecated in 2.5

2006-11-22 Thread Szabolcs Nagy
I've just seen that gopherlib is deprecated in python 2.5
http://docs.python.org/lib/module-gopherlib.html

we still use this protocol (though there are only few working gopher
servers are left on the net)

My friend just wrote a standard compliant gopher server (pygopherd had
some problems oslt) and it's much better for hierarchycal content
sharing than the http (which is overrated and misused in this respect).

So i don't really understand why would one remove it from python. It's
a friendly, tiny, simple, standard protocol.

what is the opinion of the comp.lang.python crowd?

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


Re: Guide to using python for bash-style scripting

2006-05-23 Thread Szabolcs Nagy

python subprocess module docs:

http://docs.python.org/dev/lib/node517.html

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


Re: Best IDE for Python?

2006-04-03 Thread Szabolcs Nagy
ide unification effort:
http://pyxides.stani.be/
(there are some useful links and it's more recent than the python.org
wiki)

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


Re: editor for Python on Linux

2006-02-21 Thread Szabolcs Nagy
pida is a great ide as well:
http://pida.vm.bytemark.co.uk/projects/pida

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


Re: How to run shell commands within python

2006-02-16 Thread Szabolcs Nagy
use subprocess module

from subprocess import call
call(['cmd', 'arg1', 'arg2'], stdin='...', stdout='...')
eg:
call(['ls', '-l'])

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


Re: ANN: FreeImagePy 1.2.2

2006-02-16 Thread Szabolcs Nagy
eg.: .dds (compressed texture file format) widely used in 3d games but
not accessible in pil

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


Re: Encoding

2006-02-13 Thread Szabolcs Nagy
what about params='some data'.decode('utf8').encode('1250') ?

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


Re: Location of Python modules

2006-02-13 Thread Szabolcs Nagy
/usr/lib/python2.4/site-packages ?

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


Re: Location of Python modules

2006-02-13 Thread Szabolcs Nagy
LOL

a .py program is a module, you can import it:
if it is in the sys.path (import modulename).
if it sits in a directory that is in the sys.path and the directory
also has a __init__.py file (import dirname.modulename / from dirname
import modulname).
if there is a modulename.pth file in the sys.path containing the path
to your .py file.
(the current dir is always in the sys.path).

if you want to install your module (copy it under the site-packages
dir), then you should use distutils module and create a setup.py script

the compiled bytecode (.pyc file) is always automatically generated

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


unicodedata.name

2006-02-01 Thread Szabolcs Nagy
the unicodedata manual sais:

name(   unichr[, default])
Returns the name assigned to the Unicode character unichr as a
string. If no name is defined, default is returned, or, if not given,
ValueError is raised.

what is the difference between no name defined and not given?
eg. '\n' why gives a ValueError?

 unicodedata.name(u'\n')
Traceback (most recent call last):
  File stdin, line 1, in ?
ValueError: no such name

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


Re: unicodedata.name

2006-02-01 Thread Szabolcs Nagy
thank you
(it's so obvious i don't know how i could misunderstand)

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


Re: Numarray, numeric, NumPy, scpy_core ??!!

2006-01-22 Thread Szabolcs Nagy

 Basically all I need is vectors and 3x3 matrices.

hmm
is numpy really efficient for 3x3 (or 4x4) matrices and vectors?

IMHO an optimized matrix4x4 class can be much faster (i'm just guessing
here)

eg cgtypes is a simple c++ implementation with boost-python wrapper:
http://cgkit.sourceforge.net/

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


Re: Looking for standalone Python

2006-01-17 Thread Szabolcs Nagy
 Is this possible?
yes: movable python
http://www.voidspace.org.uk/python/movpy/introduction.html

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


Re: Arithmetic sequences in Python

2006-01-16 Thread Szabolcs Nagy
i would love to see a nice, clear syntax instead of
for i in xrange(start, stop, step): ...

because xrange is ugly and iteration over int sequences are important.
we don't need a range() alternative ( [0:10] or [0..10] )
(because no one would ever use range() if there were a nice
integer-for-loop)

there was a proposal (http://www.python.org/peps/pep-0284.html):
for start = i  stop: ...
but in this way you cannot specify the step parameter and it has some
problems when used in list comprehension.

pep 204 like syntax would be:
for i in (start:stop:step): ...
it is much nicer than xrange, but probably it has some inconsistency
with slicing
(eg (:3)=xrange(3), (-3:)=itertools.count(-3), (:-3)=?, (3::-1)=? )

your .. approach:
for i in (start, start+step .. stop): ...
here start written down twice if it's referred by a name (and if start
is a function call it's evaluated twice)
imho without a step it looks nice:
for i in (start .. stop): ...
but a new syntax would be good only if it can entirely replace the old
one (which then can be made deprecated).

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


Re: A bug for unicode strings in Python 2.4?

2006-01-11 Thread Szabolcs Nagy
 Thanks. I'll write my own split().

do you want to split character by character?
then use 
list(u'\u9019\u662f\u4e2d\u6587\u5b57\u4e32')

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


Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-10 Thread Szabolcs Nagy
 There are so many varieties of iterator that it's probably not workable
 to alter the iterator API for all of the them.

i always wondered if it can be implemented:

there are iterators which has length:
 i = iter([1,2,3])
 len(i)
3

now isn't there a way to make this length inheritible?
eg. generators could have length in this case:
 g = (x for x in [1,2,3])
 # len(g) == len([1,2,3]) == 3

of course in special cases length would remain undefined:
 f = (x for x in [1,2,3] if x2)
 # len(f) == ?

IMHO there are special cases when this is useful:
L=list(it)
here if it has length, then list creation can be more effective
(required memory is known in advance) 

nsz

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


Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-10 Thread Szabolcs Nagy
 There are so many varieties of iterator that it's probably not workable
 to alter the iterator API for all of the them.

i always wondered if it can be implemented:

there are iterators which has length:
 i = iter([1,2,3])
 len(i)
3

now isn't there a way to make this length inheritible?
eg. generators could have length in this case:
 g = (x for x in [1,2,3])
 # len(g) == len([1,2,3]) == 3

of course in special cases length would remain undefined:
 f = (x for x in [1,2,3] if x2)
 # len(f) == ?

IMHO there are special cases when this is useful:
L=list(it)
here if it has length, then list creation can be more effective
(required memory is known in advance) 

nsz

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


Re: How to create a script that list itself ?

2006-01-09 Thread Szabolcs Nagy
 But is there a way / a variable that contains the current file in
 memory ?
yes: import __main__

you can do:

import inspect
import __main__
print inspect.getsource(__main__)

or simply:

print open(__file__).read()


nsz

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


Re: Try Python update

2006-01-04 Thread Szabolcs Nagy
Hello
Thanks for trypython, it's a cool idea

I got TryPythonError after an IdentationError and i could not get rid
of it (other than refreshing the page):

Python 2.4.2 (#3, Dec 16 2005, 23:54:20)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type help, copyright, credits, or license for more information.
 if 1:
... qwerty
IndentationError: expected an indented block (stdin, line 2)
 a=2
TryPythonError: I couldn't find the prompt, so did nothing
 1
TryPythonError: I couldn't find the prompt, so did nothing
 
TryPythonError: I couldn't find the prompt, so did nothing


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


Re: python for with double test

2005-12-30 Thread Szabolcs Nagy
for i in range(0,10):
if f!=1: break
...

i=0
while i10 and f==1:
...
i+=1

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


Re: python coding contest

2005-12-30 Thread Szabolcs Nagy
my two solutions (well I wasn't so clever to encode everything in
strings instead of numbers, but at least it won't give warnings about
non ascii characters):
128:
j,seven_seg=''.join,lambda s:j(j(' |_ |'[i3*int(c)b]for c in s for b
in(4,2,1))+'\n'for i in(306775170,1060861645,524130191))

122:
seven_seg=lambda s,j=''.join:j(j(' _   _|_| |_
|'[i3*int(c)14:][:3]for c in s)+'\n'for i
in(8208,934111592,664455910))

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


Re: What is unique about Python?

2005-12-24 Thread Szabolcs Nagy
i don't know if they are unique, but my favourite features are:

readable and short code (consistent syntax, few keywords)
iterpreter (very useful for learning)
dir(obj) / vars(obj) (very useful for learning)
identation
dynamic typing
lightweight oo (no public/protected/private)
built-in types (list, dict, str have useful methods)
iterator protocol
generators (yield syntax)
list comprehension / generator expression
keyword args
slicing
tuple assignment (unpacking tuple: a,b =1,2)
return with multiple values (tuple makes it easy)
widespread (it's easy to find a python module for any kind of task)
extendible with low-level languages (pyrex/swig/boostpython)
crossplatform
free

nszabolcs

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


Re: Python IDE's

2005-12-24 Thread Szabolcs Nagy
it's a very common question here. try to search for an answer
http://groups.google.com/group/comp.lang.python/search?q=python+idestart=0scoring=d;

also see
http://wiki.python.org/moin/PythonEditors
and
http://wiki.python.org/moin/IntegratedDevelopmentEnvironments

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


Re: What is unique about Python?

2005-12-24 Thread Szabolcs Nagy

 identation

Feh.  A red herring.  At best, syntactic sugar.  At worst, something for
potential adopters to get hung up about.
i always ident my code, but in python i don't need to bother with the
{} and the ; (which is redundant if i ident anyway) so i like it
because i need to type less, and i can read other's code (because of
the same layout).

 lightweight oo (no public/protected/private)

This one is debatable.  This is value in private data (and methods).
Fortunately, Python does let you make things private with the
double-underscore syntax.
i like it because i need to type (and think) less. When i need to make
it clear, which method is private/protected, i can always add a '_' or
'__' prefix by convention.

 built-in types (list, dict, str have useful methods)

Python does come with a good assortment of built-in types and containers,
but most languages these days come with pretty much the same assortment.
python has very few built-in types and these are powerful. C++ stl or
java.util has more data structures but those are somewhat less usable.
Other languages with the same bult-in data types (thinking about perl,
php, ruby) always have a little bit differrent behaviour and i always
happen to prefer the python way. (nothing can beat python's list +
slicing or the ease of creating a dict).

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


Re: How to get started in GUI Programming?

2005-11-25 Thread Szabolcs Nagy
have you tried gtk.MessageDialog ?

http://www.pygtk.org/pygtk2reference/class-gtkmessagedialog.html

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


Re: JAPH

2005-11-12 Thread Szabolcs Nagy
charset, modulo, japh =  .JPacehknorstuy, 17, 
s =
69859911049503515105680510599913390885187193231927247909305172858127641629
for n in xrange(2,):
if s%n==0:
japh += charset[(n - 1) % modulo]
s /= n
if s==1:
break
print japh

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


Re: which feature of python do you like most?

2005-11-09 Thread Szabolcs Nagy
 which feature of python do you like most?
i cannot chose one but here is my list:

iterpreter (i can try out things at once)
dir(obj) (using dir() i can learn a new library quickly)
identation (code is readable, no need for {} and ;)
dynamictyping (no type declaration - less code to write)
lightweight oo (no public/protected/private - less code to write)
widespread (it's easy to find a python module for any kind of task)
built-in types (creating list, dict is easy, iterator protocol wins)
generators (creating an iterator is easy: replace return with yield)
listcomprehension (intuitive and clear way of creating lists)
pyrex/swig/boostpython (easily extendible with c/c++)
crossplatform (i can write code for my win/linux os)
free (yes it's free and it has a reasonable license)
comp.lang.python (good questions and even better answers, friendly
folks:)

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


Re: PNG processing with only base python install

2005-11-08 Thread Szabolcs Nagy
use pil for image processing in python
(http://www.pythonware.com/products/pil/)

if pil is not installed then i don't think you can process png files
(well at least there is a pure python jpeg decoder:
http://davidf.sjsoft.com/files/pyjpeg/)

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


Re: How to translate python into C

2005-10-28 Thread Szabolcs Nagy
python creates bytecode (like java classes)


you cannot translate python directly to c or machine code, but there
are some projects you probably want to look into


Pypy is a python implemetation in python and it can be used to
translate a python scrip to c or llvm code. (large project, work in
progress)
http://codespeak.net/pypy/dist/pypy/doc/news.html


Shedskin translates python code to c++ (not all language features
supported)
http://shed-skin.blogspot.com/


Pyrex is a nice language where you can use python and c like code and
it translates into c code. (it is useful for creating fast python
extension modules or a python wrapper around an existing c library)
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

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


Re: How to translate python into C

2005-10-28 Thread Szabolcs Nagy
python script crashed and you want to debug it?

if no trace back provided with the line number where the exception
raised, then the crash caused by an extension module (most likely
written in C), i don't know howto debug it, but at least you can find
the place where the crash occures by adding lots of print statements
with debug information.

i don't think compiling to c would make it easier.


there are python debuggers but i've never used one (these can only
debug python scripts not the binary extension modules).

pdb builtin module:
http://docs.python.org/lib/module-pdb.html

nice debugger with gui:
http://www.digitalpeers.com/pythondebugger/

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


Re: Where to find python c-sources

2005-10-03 Thread Szabolcs Nagy
if u just want to browse the code online then use this:

http://fisheye.cenqua.com/viewrep/python/python/dist/src

*much* nicer than sourceforge cvs viewer

nsz

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


Re: Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread Szabolcs Nagy
IMO sorted dict implementation can be useful, eg. one can get an
interval:
L = D['A' : 'K']

other useful data types:
linkedlist
queue, stack (well deque can do it efficiently in py 2.4)
prioritydict (for graph algorithms)
multimap, multiset (i've never used it but it's in the c++ stl)
mutable string (kind of list/array of chars, but with string functions)

nsz

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


Re: Python linear algebra module -- requesting comments on interface

2005-09-11 Thread Szabolcs Nagy
nice interface, but with 3d apps i prefer cgkit's approach, which has
vec3, vec4, mat3, mat4 and quat types with lots of useful functions for
3d graphics (like mat4.looakAt(pos, target, up) or mat3.toEulerXYZ())

there are other libs with similar types and functions:
cgkit (http://cgkit.sourceforge.net/)
pyogre (http://www.ogre3d.org/wiki/index.php/PyOgre)
panda3d (http://panda3d.org/)

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


Re: Possible improvement to slice opperations.

2005-09-05 Thread Szabolcs Nagy
with the current syntax L[i:i+1] returns [L[i]], with nxlist it returns
L[i+1] if i0.

L=range(10)
L[1:2]==[L[1]]==[1]
L[-2:-1]==[L[-2]]==[8]

L=nxlist(range(10))
L[1:2]==[L[1]]==[1]
L[-2:-1]==[L[-1]]==[9] # not [L[-2]]

IMHO in this case current list slicing is more consistent.

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


time.clock() problem under linux (precision=0.01s)

2005-08-18 Thread Szabolcs Nagy
I have to measure the time of a while loop, but with time.clock i
always get 0.0s, although python manual sais:
this is the function to use for benchmarking Python or timing
algorithms

So i tested timer functions capabilities with a short script:

import time
import os

def test_timer_func(func):
print 'min time-time: %.10f'%min(abs(func()-func()) for i in
xrange(10**5))
print 'max time-time: %.10f'%max(abs(func()-func()) for i in
xrange(10**5))

dt = 0.0
loopcount = 0
t = func()

while dt==0.0:
dt = func() - t
loopcount += 1

print min measurable loop time : %.10f%dt
print 'loopcount while dt==0 :',loopcount


print '\n time.clock()'
test_timer_func(time.clock)

print '\n time.time()'
test_timer_func(time.time)

print '\n os.times()'
ot = os.times
test_timer_func(lambda:ot()[4])


My output is:

 time.clock()
min time-time: 0.00
max time-time: 0.01
min measurable loop time : 0.01
loopcount while dt==0 : 2703

 time.time()
min time-time: 0.019073
max time-time: 0.460148
min measurable loop time : 0.050068
loopcount while dt==0 : 1

 os.times()
min time-time: 0.00
max time-time: 0.010007
min measurable loop time : 0.009998
loopcount while dt==0 : 2515


So the precision of time.clock is 0.01s under my ubuntu linux system,
which means it's not suitable for benchmarking. (i want to benchmark
the fps in my pygame+pyode program and it needs at least 0.001s
precision)

time.time seems much better solution, but python manual sais: not all
systems provide time with a better precision than 1 second

Should i use time.clock or time.time to be more crossplatform?
Is time.time ok for windows? (time()-time() != 0.0)

nszabolcs

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


Re: Python for Webscripting (like PHP)

2005-08-18 Thread Szabolcs Nagy
I don't think stdlib offers anything like that

The problem with python is it's white space sensible and html  is not.

However there are some nice solutions:
http://www.webwareforpython.org/Papers/Templates/
my favourite is not listed here:
http://karrigell.sourceforge.net/

For web development with python i'd rather recommend a complete
webframework:
http://www.djangoproject.com/
http://subway.python-hosting.com/
http://www.zope.org/

nszabolcs

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


Re: Python interpreter error: unsupported operand type(s) for |:

2005-08-11 Thread Szabolcs Nagy
you cannot use | with two dict (dict has no .__or__ method)

what are you trying to do?

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


Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Szabolcs Nagy
i found case sensitivity very useful

1. variables can be stored in a dict (think about  __dict__, globals())
and dict type should be case sensitive

2. It's necessary when i write short scripts and i use one letter
names. (eg. when i playing with linear algebra i always use a,b,c for
vectors and A,B,C for matrices).  I dont want to think about more than
one letter names when i run that script only once. And usually this is
the case with python (at least when i use it in interpreted mode).

3.  i write sometimes:
class Foo:
...
foo = Foo()

and i think it's readable and makes sense.

4. actually i never wanted to use 'foo', 'Foo' and 'FOO' for the same
variable and i can't imagine a situation when it's useful. it makes the
code less readable so i think the language should force the programmer
not to use different names for the same variable.

nsz

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


Re: PyGTK vs. wxPython

2005-04-27 Thread Szabolcs Nagy
it's not quite true since the latest stable release (2.6.0.0)

see the new wx doc (it's generated with epydoc so it's not for C++):
http://www.wxpython.org/docs/api/

i used wxPython with XRCed a few times and i liked the way it works
(worked under linux and win as well for me)

nsz

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


Re: PyGTK vs. wxPython

2005-04-27 Thread Szabolcs Nagy
I forgot to mention in my previous post that the best thing in wxPython
is the wxPython demo. It helped me a lot. Browsing through the examples
usually faster than browsing through the api doc.

About XRCed:
I put every static components of the window layout in an xml file with
XRCed
(not static components: buttons moving around, changing labels ...)

Generally my code looks like:

import wx
import wx.xrc

class Frame(wx.Frame):
def __init__(self, parent, resource):
w = resource.LoadFrame(parent, 'FrameName')
self.PostCreate(w)
self.SetIcon(wx.Icon('myapp.ico', wx.BITMAP_TYPE_ICO))

...
#lots of init code here

...
#event handlers here


class App(wx.App):
def OnInit(self):
resource = wx.xrc.XmlResource('myapp.xrc')
self.f = Frame(None, resource)
self.f.Show()
return True

if __name__ == '__main__':
app = App()
app.MainLoop()

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


Re: Modifying Call Tips and Intellisense Behavior

2005-03-07 Thread Szabolcs Nagy
have a look at eclipse + pyDev
http://pydev.sourceforge.net/

probably it works as you wish

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