distutils is not found

2006-08-03 Thread Saketh
Under openSUSE 10.0, I installed Python 2.4.1. I executed a setup.py
which imports distutils, but I received an error which gave an
"ImportError: module not found" for distutils. I thought that distutils
is part of the standard library under Python, but is there something
that I am missing? Can I (or should I) install distutils manually?

Thanks for the assistance.

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


distutils setup.py

2006-08-07 Thread Saketh
I'm having trouble getting the data_files argument of my setup.py to
work with "python setup.py sdist" under Windows XP. Here is the
data_files argument that I pass to setup().

data_files = [\
('res','app.ico'),
('', 'preferences.xml'),
('res', glob.glob(os.path.join('res','*.png')))],
)

My setup.py is in the same directory as "preferences.xml". I use this
setup.py for both py2exe and sdist. When I use it for py2exe, the
data_files are properly copied to the target directory. However, when I
use it for sdist, none of the data_files are copied. If this were a
directory problem, then setup.py would have failed earlier when I
specified Application.py in the "scripts" argument.

How can I get the data_files copied properly without having to manually
edit the MANIFEST file?

Thanks,
Saketh

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


wxPython: Keyboard events and TreeCtrl

2006-06-11 Thread Saketh
Hello, everyone.

I  am a writing an application that I want to make a stripped-down
framework of Leo for Cornell note-taking.  I have one TreeCtrl, a menu,
and a status bar. There are two classes currently - the Application
class and the Frame class. The Frame class contains all of the event
handling, such as OnAbout and OnExit.

I am trying to add keyboard shortcuts. When someone hits Ctrl-I, I want
a new node to be added at the bottom level - if you've ever used Leo,
you know what I am talking about. Like in Leo, when the new node is
created, I want the title to be highlighted so that you can type in the
title of the node.

For some reason, the way I am doing it is not working. It's probably
because OnKeyDown is not attached to anything, but I am not sure.
Anyway, here is what my OnKeyDown method looks like:

def OnKeyDown(self, e):
key = e.KeyCode()
controlDown = e.ControlDown()
altDown = e.AltDown()
elif (controlDown and key == WXK_I):
# I want the "Node Title" to be editable upon its creation
self.tree.AppendItem(root, 'Node Title')

Am I supposed to connect the method to the Frame somehow? Or does it
automatically get called when the user hits Ctrl-I, regardless of the
fact that no other methods call OnKeyDown?

Thank you for the assistance.

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


Re: how to get the length of a number

2006-06-11 Thread Saketh

Stan Cook wrote:
> Can anyone tell me how to get the length of a number.  I
> know len(string) will get the length of a string, but it
> doesn't like len(int).  I seem to remember something like %s
> string.  I tried to set a variable = to %s int, but that
> doesn't work.  Is there a function I've forgotten about to
> convert an integer to a string?
>
> Regards
>
> Stan

Use str(int). Then use len(). For example, len(str(12345)) will give
you 5.

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


Re: sorting two corresponding lists?

2009-04-20 Thread Saketh
On Apr 20, 12:10 pm, Esmail  wrote:
> Hello all,
>
> I wonder if someone could help me with sorting two corresponding lists.
>
> For instance the first list contains some items, and the second list
> contains their value (higher is better)
>
> items = [apple, car, town, phone]
> values = [5, 2, 7, 1]
>
> I would like to sort the 'items' list based on the 'values' list so
> that I end up with the following two list:
>
> items = [town, apple, car, phone]
> values = [7, 5, 2, 1]
>
> So I would like to keep the corresponding value still corresponding
> after the sorting.
>
> Is there an easy/nice/Pythonic way to do this?
>
> Thanks,
> Esmail

Why not use a dictionary instead of two lists? Then you can sort the
dictionary by value -- e.g.

d = dict(zip(items, values))
sorted_items = sorted(d.iteritems(), key=lambda (k,v): (v,k))

This produces a list of pairs, but demonstrates the general idea.
--
http://mail.python.org/mailman/listinfo/python-list


efficiently checking for string.maketrans conflicts?

2009-04-20 Thread Saketh
Hi everyone:

I'm using "translation" in the sense of string.maketrans here.

I am trying to efficiently compare if two string translations
"conflict" -- that is, either they differently translate the same
letter, or they translate two different letters to the same one. Here
are some examples:

# no conflict - equal
t1 = Translation('ab', 'cd')
t2 = Translation('ab', 'cd')

# no conflict - inverses
t1 = Translation('ab', 'cd')
t2 = Translation('cd', 'ab')

# conflict - same key, different value
t1 = Translation('ab', 'cd')
t2 = Translation('ab', 'ce')

# conflict - different key, same value
t1 = Translation('ab', 'cd')
t2 = Translation('xy', 'cd')

This conflict-checking is the bottleneck of my program, and the
obvious way to implement it -- looping through the translations and
explicitly checking for the above conditions -- is much slower than
I'd like.

Is there a more efficient, Pythonic way of checking if two
translations conflict?

Sincerely,
Saketh
--
http://mail.python.org/mailman/listinfo/python-list


Re: efficiently checking for string.maketrans conflicts?

2009-04-22 Thread Saketh
On Apr 20, 11:35 pm, Michael Spencer  wrote:
> Saketh wrote:
> > Hi everyone:
>
> > I'm using "translation" in the sense ofstring.maketranshere.
>
> > I am trying to efficiently compare if two string translations
> > "conflict" -- that is, either they differently translate the same
> > letter, or they translate two different letters to the same one.
>
> ...
>
> Another solution, similar to Peter's...
>
> def conflicts(from1,to1,from2,to2):
>      '''returns True for 'conflicting translations'
>
>       >>> conflicts('ab','cd','ab','cd')
>       False
>       >>> conflicts('ab','cd','ab','ce')
>       True
>       >>> conflicts('ab','cd','xy','cd')
>       True
>       >>> conflicts('ab','cd','cd','ab')
>       False
>      '''
>      # forward translations
>      trans1 = dict(zip(from1,to1))
>      trans2 = dict(zip(from2,to2))
>
>      for char in set(trans1).intersection(trans2):
>          if trans1[char] != trans2[char]:
>              return True
>
>      # reverse translations
>      revtrans1 = dict(zip(to1,from1))
>      revtrans2 = dict(zip(to2,from2))
>
>      for char in set(revtrans1).intersection(revtrans2):
>          if revtrans1[char] != revtrans2[char]:
>              return True
>
>      return False
>
> HTH
> Michael

Thank you, Peter and Michael, for your solutions! I think that
Michael's is what I was edging towards, but Peter's has demonstrated
to me how efficient Python's set functions are. I have a lot more to
learn about optimizing algorithms in Python... :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pyfora, a place for python

2009-11-07 Thread Saketh
On Nov 4, 5:28 pm, Alan Franzoni 
wrote:
> On 11/2/09 3:44 PM, Diez B. Roggisch wrote:
>
> > Being from germany, I can say that we *have* this fragmentation, and
> > frankly: I don't like it. I prefer my communication via NNTP/ML, and not
> > with those visually rather noisy and IMHO suboptimal forums. E.g. it
>
> That's right... forums, although more "accessible" to all the people who
> can't/doesn't want to use specific email or nntp clients, are quite slow
> to use.
>
> But I think Ubuntu forums support threads and are kind of "channeled"
> between ML and webinterface... something like Google Groups; I think
> THAT would be a good idea. What about trying to "channel"
> comp.lang.python and a forum?
>
> --
> Alan Franzoni
> contact me at pub...@[mysurname].eu

Hi everyone,

My small effort to create a place for discussing Python seems to have
sparked a larger discussion than I had anticipated. My intent in
creating Pyfora is not to splinter the community or encroach upon
comp.lang.python users, but to create an alternative location where
users can discuss Python. If this offends or irritates anyone, please
accept my humble apologies.

I understand that forums can be degenerate and uncivil, but my hope is
that with Pyfora, beginners will have a place to freely ask questions
in a genial environment. A large part of my computer upbringing was on
forums, and I wanted to share that experience with new Python users.

Sincerely,
Saketh
-- 
http://mail.python.org/mailman/listinfo/python-list