dll files

2005-06-20 Thread Sabin
How can i create dll files in Python?
Is it possible?

If yes,
how to enclose image and font files in a dll ?

Plis reply.
SABIN.
B'lore.

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


Dealing with name clashes in pypi

2011-05-22 Thread Patrick Sabin
I wanted to register my project (epdb) in pypi. Unfortunately there 
already exists a project with the same name. It is not possible for me 
to change the name of the project, because I used it in multiple 
writings. Any ideas how I can deal with the situation? Is it possible to 
register a project under a different name in pypi than the actual 
project name?


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


Re: Dealing with name clashes in pypi

2011-05-23 Thread Patrick Sabin

On 2011-05-22 23:23, Terry Reedy wrote:

On 5/22/2011 2:34 PM, Patrick Sabin wrote:

I wanted to register my project (epdb) in pypi. Unfortunately there
already exists a project with the same name. It is not possible for me
to change the name of the project, because I used it in multiple
writings. Any ideas how I can deal with the situation? Is it possible to
register a project under a different name in pypi than the actual
project name?


I presume so. How would pypi know the 'actual' name?
However, there is a catalog sig list (mirrored as
gmane.comp.python.catalog) where you might get specific suggestions on
how to handle this.



Thanks for the tip. I will try it there.

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


Re: Simple greatest common factor script

2009-11-29 Thread Patrick Sabin

I don't see how this script is able to divide by zero. If a and b
switch places everything works ok.


Have a look at your if-statements. It is possible, that both your if's 
are executed in one loop iteration (you can check this using pdb). You 
may want to try elif instead.


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


Re: Call C program

2009-12-03 Thread Patrick Sabin
Have a look at the ctypes module 
http://python.net/crew/theller/ctypes/tutorial.html


e.g.:

from ctypes import *

cdll.LoadLibrary("libc.so.6")
libc = CDLL("libc.so.6")

print libc.rand()
print libc.atoi("34")

- Patrick
Patxi Bocos wrote:

Hi!,

I am developing a Python application and I need to call a C program 
which needs one parameter and it returns another one.


How could I do it?

Thanks :)



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


Re: Python book

2009-09-30 Thread Patrick Sabin

My favorite book is "Python Essential Reference" from David M. Beazley.
It is not a beginner book. It is about the python language and not about 
 a framework or third-party library. It is much more complete than for 
instance "Dive into python", but maybe somewhat more difficult.


- Patrick

lallous wrote:

Hello

Can anyone suggest a good book Python book for advancing from beginner 
level?


(I started with Learning Python 3rd ed)

Regards,
Elias


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


SVG PIL decoder

2009-09-30 Thread Patrick Sabin
I would like to open svg files with PIL, but svg doesn't seem to be 
supported. Does anyone know about a svg decoder for the PIL?


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


Re: SVG PIL decoder

2009-09-30 Thread Patrick Sabin

Donn wrote:
Have a look at Cairo (python-cairo) in conjunction with librsvg (python-rsvg) 
-- that'll fix you up. You can go from an SVG to a PNG/array and thence into 
PIL if you need to.


Thanks for the tip. Got it work, although it was a bit tricky, as 
resizing doesn't seem to be supported by python-rsvg and 
cairo.ImageSurface.create_from_png doesn't allow StringIO or 
TemporaryFile for some reason (got Memory Error). So the code, if 
someone else needs it or someone can improve it:


def open_svg_as_image(fn, width, height):
tmpfd, tmppath = tempfile.mkstemp(".png")
tmpfile = os.fdopen(tmpfd,'w')

file = StringIO.StringIO()
svgsurface = cairo.SVGSurface (file, width, height)
svgctx = cairo.Context(svgsurface)
svg = rsvg.Handle(file=fn)
svgwidth = svg.get_property('width')
svgheight = svg.get_property('height')
svgctx.scale(width/float(svgwidth),height/float(svgheight))
svg.render_cairo(svgctx)

svgsurface.write_to_png(tmpfile)
tmpfile.close()
svgsurface.finish()

tmpfile = open(tmppath, 'r')
imgsurface = cairo.ImageSurface.create_from_png(tmpfile)
imgwidth = imgsurface.get_width()
imgheight = imgsurface.get_height()

data = imgsurface.get_data()

im = Image.frombuffer("RGBA",(imgwidth, imgheight),
data ,"raw","RGBA",0,1)
os.remove(tmppath)
return im

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


setuptools, accessing ressource files

2009-10-02 Thread Patrick Sabin
I use setuptools to create a package. In this package I included some 
images and I checked that they are in the egg-file. The problem is how 
can I access the images in the package?


I tried pkgutil.get_data, but only got an IOError, because the EGG-INFO 
directory doesn't exist.


I tried
pkg_resources.get_distribution('dist').get_metadata('images/image.png')
with a similar error (IOError)

What is the best way to access images distributed in an egg file?

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


Re: Python & Go

2009-11-12 Thread Patrick Sabin

Carl Banks wrote:

Well, it's hard to argue with not being like C++, but the lack of
inheritance is a doozie.


Well it has the concept of embedding, which seems to be similar to 
inheritance.


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


Re: Python & Go

2009-11-12 Thread Patrick Sabin

kj wrote:


I'm just learning about Google's latest: the GO (Go?) language.
(e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s).
There are some distinctly Pythonoid features to the syntax, such
as "import this_or_that", the absence of parentheses at the top of
flow control constructs, and quite a few statements without a
trailing semicolon.  Then again, there's a lot that looks distinctly
un-Pythonlike, such as the curly brackets all over the place.  And
among the un-Pythonlike stuff there's a lot that looks like nothing
else that I've ever seen...


I don't see many similarities with python, especially it's syntax looks
completely different to me. Google Go introduces many new concepts. 
Interfaces work a little bit like duck typing. You may call that 
python-style. And it has go-routines, which are a bit similar to 
generators (although I haven't look at them in detail). There is no 
exception handling, but channels should be able to substitute them, 
although I haven't checked that.


At a first look it seems, that using Google Go effectively, someone has 
to relinquish many programming habits and adapt lots of new ones.


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


Re: Is there something similar to list comprehension in dict?

2009-11-20 Thread Patrick Sabin

Peng Yu wrote:

I'm wondering if there is something similar to list comprehension for
dict (please see the example code below).


Do you mean something like this:

>>> {i:i+1 for i in [1,2,3,4]}
{1: 2, 2: 3, 3: 4, 4: 5}

This works in python3, but not in python2

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


Re: Dictionary or Database—Please advise

2010-02-26 Thread Patrick Sabin



Shelve looks like an interesting option, but what might pose an issue
is that I'm reading the data from a disk instead of memory.  I didn't
mention this in my original post, but I was hoping that by using a
database it would be more memory efficient in storing data in RAM so I
wouldn't have to read from (or swap to/from) disk.


A database usually stores data on disk and not in RAM. However you could 
use sqlite with :memory:, so that it runs in RAM.



Would using the
shelve package make reading/writing data from disk faster since it is
in a binary format?

Faster than what? Shelve uses caching, so it is likely to be faster than 
a self-made solution. However, accessing disk is much slower than 
accessing RAM.



Jeremy

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


Reversible Debugging

2009-07-03 Thread Patrick Sabin

Hello,

I am interested if there are any python modules, that supports 
reversible debugging aka stepping backwards. Any links or ideas would be 
helpful, because I am thinking of implementing something like that.


Thanks in advance,
Patrick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reversible Debugging

2009-07-04 Thread Patrick Sabin

Gabriel Genellina schrieb:
Do you want reverse execution, like an undo function? Undo all changes 
made by executing some piece of code?
I am not completly sure, if I really want to make exact undo, i.e. 
undoing commands by reversing all their effects, or just restoring the
program state to an arbitrary state of its history, which would not 
effect things like files.
There are many cases where that's hard to do, or impossible. How to 
undo object destruction? How to undo external effects, like writing to 
files?
Object destruction should not be a big problem to restore. But writing 
files or other resources is because it is not guaranted that it is even 
possible or wanted.
I considered either ignoring undoing external commands completly or 
adding some plugin system to do it.

You should think carefully what can and cannot be done - good luck!


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


Re: Reversible Debugging

2009-07-04 Thread Patrick Sabin

Horace Blegg schrieb:
You might consider using a VM with 'save-points'. You run the program 
(in a debugger/ida/what have you) to a certain point (logical point 
would be if/ifelse/else statements, etc) and save the VM state. Once 
you've saved, you continue. If you find the path you've taken isn't 
what you are after, you can reload a previous save point and start 
over, trying a different path the next time.
That was my idea to implement it. I thought of taking snapshots of the 
current state every time a "unredoable instruction", e.g random number 
generation, is done.  For every other instruction I count the number of 
instructions done since the last snapshot. So I can go back one 
instruction by restoring to the previous state and go the number of 
instructions minus one forward.


This is also somewhat useful if you're trying to debug an error that 
happens deep inside of a program, so you can continually jump to the 
point right before the error happens, instead of needing to run 
through the entire program each time it crashes. Just beware of tunnel 
vision.
I think of implementing some snapshot/restore mechanism first. That may 
help in many other situations.

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


Re: Reversible Debugging

2009-07-04 Thread Patrick Sabin


Now, if the snapshot is a feature of the Python VM, that's another 
matter entirely.
I thought of taking a snapshot using fork, which creates a copy of the 
process. It may not be the
most performant, but it should be quite portable. Of course there are 
some issues with

multithreading/multiprocessing.

If someone has another idea of taking a snapshot let me know. Using 
VMWare is not a

very elegant way in my opinion.

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


Re: How can I format unicode strings?

2009-09-09 Thread Patrick Sabin

gentlestone schrieb:

 return u"{}".format(self.name)


u"{0}".format(u"blah")

works for me with python-2.6.2
Maybe your format string is wrong.

- Patrick

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


Re: Creating a local variable scope.

2009-09-11 Thread Patrick Sabin

Johan Grönqvist schrieb:

Hi All,

I find several places in my code where I would like to have a variable
scope that is smaller than the enclosing function/class/module definition.

One representative example would look like:

--
spam = { ... }
eggs = { ... }

ham = (a[eggs], b[spam])
--

The essence is that for readability, I want spam and eggs in separate
definitions, but for clarity, I would like to express the fact that they
are "local to the definition of ham", i.e., they are not used outside of
 the definition of ham.

The language reference at
 says that "The
following are blocks: a module, a function body, and a class
definition." (all other cases seem to refer to dynamic execution using
eval() or similar). Python 3 and 2.6 seem to have identical scope rules.

In the other languages I have used I can either use braces (C and
descendants) or use let-bindings (SML, Haskell etc.) to form local scopes.

Are there suggestions or conventions to maximize readability for these
cases in python? (Execution time is not important in the cases I
currently consider.)


Regards

Johan


I think it is not possible to realize something like braces in C or 
let-bindings in python. But here are some Ideas to work around this problem:


1) If you define all this in the global namespace you could remove your 
temporary variables afterwards, e.g.


spam = 1
ham = (spam,)
del globals()['spam']

This only works for the global namespace and not for the local! I 
wouldn't recommend it.


2) create a method, which initializes ham

def make_ham():
spam = {...}
egg = {...}
return (egg, spam)

ham = make_ham()

This makes it easier to reuse ham in other situations and wouldn't 
expose spam or egg.


3) Make a class for your ham data structure

If ham is so complex that you have to split it up, it may makes sense to 
create a class for it. Of course this would need refactoring of the 
code, but it's more readable and extensible than packing your data in 
tuples, lists or dictionaries.


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


Re: Python strict mode?

2009-09-13 Thread Patrick Sabin

 > You could write a class with a custom __setattr__() method that checks

for valid attribute names for that class (a list of strings given to
it's __init__() method). That way you could form several restricted
"namespaces" for variables simply as different instances of that class.



This can be easier accomplished using __slots__, e.g.:

>>> class X(object):
... __slots__ = ['a']


But in my opinion, it isn't worth it. You still don't get compile time
errors, which is probably the main reason to use strict mode.


I agree.

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