Re: best way to determine sequence ordering?

2006-04-30 Thread Kay Schluehr
> * building a dict of indicies::
>
>positions = dict((item, i) for i, item in enumerate(L))
>
>if positions['A'] < positions['D']:
># do some stuff
>
>You'll only get a gain from this version if you need to do several
> comparisons instead of just one.

Hi Steven,

your solution may not create the correct answer if an item occurs twice
in the list because the later occurrence overwrites the former during
dict creation:

>>> L = ['C', 'A', 'D', 'B', 'A']
>>> dict((item, i) for i, item in enumerate(L))
{'A': 4, 'C': 0, 'B': 3, 'D': 2}

This gives the impression that 'D' always precedes 'A' which is wrong.

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


Re: basic python programing

2006-04-30 Thread Ravi Teja
How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html

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


Re: Unpacking of query result

2006-04-30 Thread DarkBlue

Hello

Following part of an database query works fine :

self.cur=con1.cursor
self.cur.execute('select a,b,c,d from t1')
for (a,b,c,d) in self.cur:
print a,b,c,d


but how to do this:

self.cur.execute(sql_select_text_put_in_at_runtime)
for (whatever_was_in_the_select_text_part_of_the_query) in self.cur:
print 'returned result set'

Will it be necessary to parse the sql string and find any possible
return columns or is there a better way so that the query can be used
generically , that is without knowing at coding time
what or how many columns will be returned ?


Thanks
Db




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


Re: time conversions [hh:mm:ss.ms <-> sec(.ms)

2006-04-30 Thread Faber
kpp9c wrote:

> timedelta looks to be just the ticket! bravo, thank you... i guess this
> must be pretty new to Python.

Well, since Python 2.3 (July 2003):
http://www.python.org/doc/2.3.5/whatsnew/node18.html#SECTION000181

:-)

-- 
Faber
http://faberbox.com/
http://smarking.com/

Only wimps use tape backup: _real_ men just upload their important stuff on
ftp and let the rest of the world mirror it  -- Linus Torvalds
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unpacking of query result

2006-04-30 Thread Fredrik Lundh
"DarkBlue" <[EMAIL PROTECTED]> wrote:

> Following part of an database query works fine :
>
> self.cur=con1.cursor
> self.cur.execute('select a,b,c,d from t1')
> for (a,b,c,d) in self.cur:
> print a,b,c,d
>
>
> but how to do this:
>
> self.cur.execute(sql_select_text_put_in_at_runtime)
> for (whatever_was_in_the_select_text_part_of_the_query) in self.cur:
> print 'returned result set'
>
> Will it be necessary to parse the sql string and find any possible
> return columns or is there a better way so that the query can be used
> generically , that is without knowing at coding time
> what or how many columns will be returned ?

reading the DB-API documentation might help:

http://www.python.org/dev/peps/pep-0249/

/.../

Cursor Objects should respond to the following methods and
attributes:

.description

This read-only attribute is a sequence of 7-item
sequences.  Each of these sequences contains information
describing one result column: (name, type_code,
display_size, internal_size, precision, scale,
null_ok). The first two items (name and type_code) are
mandatory, the other five are optional and must be set to
None if meaningfull values are not provided.

This attribute will be None for operations that
do not return rows or if the cursor has not had an
operation invoked via the executeXXX() method yet.

The type_code can be interpreted by comparing it to the
Type Objects specified in the section below.

/.../





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


Re: Unpacking of query result

2006-04-30 Thread DarkBlue
Thank you
Mission accomplished.

Have a nice sunday
Db
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self modifying code

2006-04-30 Thread Robin Becker
Ben C wrote:
...
> 
> Why not just:
> 
> data = None
> def func(a):
> global data
> 
> if not data:
> data = somethingcomplexandcostly()
> 
> return simple(data, a)
> 

well in the original instance the above reduced to something like

data=None
def func(arg):
 global data
 if data:
data = ..
 return ''.join(map(data.__getitem__,arg))

so the actual function is pretty low cost, but the extra cost of the 
test is actually not very significant, but if the actual function had 
been cheaper eg

def func(arg):
 global data
 if data is None:
data = 
 return data+arg

then the test is a few percent of the total cost; why keep it?

All the other more complex solutions involving namespaces, singletons 
etc seem to add even more overhead.

> Or nicer to use a "singleton" perhaps than a global, perhaps something
> like this:
> 
> class Func(object):
> exists = False
> 
> def __init__(self):
> assert not Func.exists
> Func.exists = True
> 
> self.data = None
> 
> def simple(self, a):
> assert self.data is not None
> # ... do something with self.data presumably
> return something
> 
> def __call__(self, a):
> if self.data is None:
> self.data = somethingcomplexandcostly()
> return self.simple(a)
> 
> func = Func()
> 
> func(a)


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


Re: setting file permissions on a web server

2006-04-30 Thread Rene Pijlman
John Salerno:
>I always read about how you need to set certain file permissions (for 
>cgi files, for example), but it's never been clear to me *how* you do 
>this. I know you can run the line
>
>chmod 755 scriptname.py
>
>but *where* do you run this? 

This is a Unix/Linux command. You run it in a shell login on the server
(e.g. in Putty, SecureCRT, or some other ssh client you're using).

>Is there a way to put the above line within the script perhaps, so that 
>the script sets its permission automatically?

Not in the script itself via cgi of course, because it needs certain
permissions before it can be run as cgi script. But you could put the
command in an installation script that installs the cgi script.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Daniel Nogradi
> I always read about how you need to set certain file permissions (for
> cgi files, for example), but it's never been clear to me *how* you do
> this. I know you can run the line
>
> chmod 755 scriptname.py
>
> but *where* do you run this? Is this done on your personal system, or on
> the server? What if you are using Windows? If it's done on the server,
> how do you do it?
>
> The only way I've figured out so far how to do this is to upload my cgi
> files to my server, then within my FTP program I right-click the file
> and change its permission number that way, but that seems an inefficient
> way to do it, especially having to do it each time.
>
> Is there a way to put the above line within the script perhaps, so that
> the script sets its permission automatically? Or do certain editors
> allow you to save files with a predetermined permission?
>
> Aside from my right-clicking method, I don't know how else to do it.

I guess this would be a good starting point:

http://www.linuxcommand.org/man_pages/chmod1.html

In short, chmod refers to local files so wherever you run it it will
refer to files on that machine. You run it simply by typing it in a
shell as a user who has privilage to perform the operatation, which
can mean you have to be an owner of the file but if you are root you
can do it in any case. Depending on your ftp, scp, http or whatever
method you use to transfer files the file permissions may or may not
change during the transfer. If permissions are kept intact you can
chmod on your local machine and then transfer, if they are not then
you transfer first and chmod on the server. When you transfer files
from a windows machine to *nix it again depends on the particular
method you choose how the permissions will be set.

There is no way of putting this permission information into the file
itself but some (most?) editors can be set to save the file with a
permission of your choice.

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


bonobo bindings?

2006-04-30 Thread Patrick Jacquot
Hi group!
Did anybosy here have some success using the bonobo bindings
to interact with nautilus?

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


Re: ANN: Leo 4.4 rc1 released

2006-04-30 Thread Fulvio
Alle 19:15, sabato 29 aprile 2006, Fredrik Lundh ha scritto:
> emacs
I didn't like Emacs since the glory day of Amiga. Also vim look pretty rough 
for my tastes.
I fill more confortable in Kate, but I don't deny any furter trial. May I'm 
gonna reconsidering Emacs :)

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


Re: how not use memmove when insert a object in the list

2006-04-30 Thread Fredrik Lundh
"kyo guan" wrote:

> for (i = n; --i >= where; ) /// here, why not use memmove? it would be more 
> speed then this loop.
>items[i+1] = items[i];

have you benchmarked this on a wide variety of platforms, or are
you just guessing?





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


unable to resize mmap object

2006-04-30 Thread Fabiano Sidler
Hi folks!

I created an mmap object like so:
--- snip ---
from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE
fl = file('/dev/zero','rw')
mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS)
--- snap ---

Now, when I try to resize mm to 10 byte
--- snip ---
mm.resize(10)
--- snap ---
I get an EnvironmentError:[Errno 22] Invalid argument.

How can I implement a resizeable anonymous memory mapping?
Thanks for your reply!

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


Re: resume picking items from a previous list

2006-04-30 Thread [EMAIL PROTECTED]

kpp9c wrote:
> I have a several list of songs that i pick from, lets, say that there
> are 10 songs in each list and there are 2 lists.
>
> For a time i pick from my songs, but i only play a few of the songs in
> that list... now my wife, Jessica Alba, comes home, and i start playing
> from Jessica's list of songs. After playing a few songs, Jessica, who
> needs her beauty sleep, goes to bed, and i start my play loop which
> starts picking from my songs again...
>

Not sure I follow. Jessica goes to bed, and you... _listen to music_??

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


Re: how not use memmove when insert a object in the list

2006-04-30 Thread John Machin
On 30/04/2006 11:57 AM, kyo guan wrote:
> Hi :
> 
>   python list object like a stl vector, if insert a object in the front 
> or the middle of it,
> all the object after the insert point need to move backward.
> 
> look at this code ( in python 2.4.3)
> 

>   for (i = n; --i >= where; ) /// here, why not use 
> memmove? it would be more speed then this loop.
>   items[i+1] = items[i];

Here's a guess, based on similar work on another language a few 
reincarnations ago :-)

memmove() is very general-purpose, and starts with byte addresses and a 
byte count. For a small number of list elements, by the time that 
memmove has determined (1) the move overlaps (2) both source and target 
are on word boundaries and it is moving a whole number of words (3) what 
direction (up or down), the DIY code has already finished. For a large 
number of items, memmove *may* be faster (depending on the architecture 
and the compiler) but you are using the wrong data structure anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin: processing characters

2006-04-30 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Edward Elliott  <[EMAIL PROTECTED]> wrote:
>Kevin Simmons wrote:
>> I have a python script that prompts the user for input from stdin via a
>> menu. I want to process that input when the user types in two characters
>> and not have to have the user press . As a comparison, in the bash
>> shell one can use (read -n 2 -p "-->" CHOICE; case $CHOICE in...). Works
>> great and is very
>
>I did something like this a couple years ago, curses was the easiest way I
>found to do it.  It's pretty painless with the wrapper function, which
>restores your terminal on error/exit.
>

Kevin, the bad news is that curses() is as good as Python gets in
this regard.  For better or worse, to the best of my knowledge,
unextended Python caNOT implement bash's read.  Here's the closest
small approximation I know:

  import curses
  import os

  msvcrt = curses.initscr()
  msvcrt.addstr("-->")
  first = msvcrt.getch()
  second = msvcrt.getch()
  os.system("stty echo -nl")
  print "\nThe two characters are '%s' and '%s'." % (first, second)

I hope someone proves me wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: eric3 3.9.0 released

2006-04-30 Thread Detlev Offenbach
Hi,

this is to inform you of the release of eric3 3.9.0. This version
includes support for Qt4 and PyQt4. It will be the last major release in
the eric3 line of development. From now on the development effort will
concentrate on eric4, the PyQt4 variant of the IDE. As usual the release
is available via

http://www.die-offenbachs.de/detlev/eric3.html

Eric3 is a Python and Ruby IDE with all batteries included.

Regards,
Detlev
-- 
Detlev Offenbach
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Can I collapse a Panel in wxPython?

2006-04-30 Thread nuffnough
Hi.

I have a gui with one frame and 5 panels.  The second panel will only
be required in some cases,  so I am wondering if there is some way I
can only create this panel in the circumstances where it is required,
confirmed by a simple len(list) > 1

If it is possible, I am wondering how I might go about it  I am not
sure where to put an if statement as there are many different referrals
to panel_2

Letting me know or just pointing me to an example of such a thing would
be fabulous.

TIA

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


Converting tuple to String

2006-04-30 Thread Byte
Is their a command to convert a tuple to string? e.g.

xyz = "Hello", "There"
print xyz

Is their any way of getting print to see xyz as being one string i.e.
"Hello There" rather than "Hello" and "There", despite "Hello" and
"There" being, in reality, seperate?

Thanks in advance,
 -- /usr/bin/byte

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


Re: Converting tuple to String

2006-04-30 Thread Tim Williams
On 30 Apr 2006 08:32:47 -0700, Byte <[EMAIL PROTECTED]> wrote:
xyz = "Hello", "There"print xyzIs their any way of getting print to see xyz as being one string i.e."Hello There" rather than "Hello" and "There", despite "Hello" and
"There" being, in reality, seperate?
>>> print  " ".join(xyz)Hello There

HTH :)
-- Tim Williams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: best way to determine sequence ordering?

2006-04-30 Thread Steven Bethard
Kay Schluehr wrote:
>> * building a dict of indicies::
>>
>>positions = dict((item, i) for i, item in enumerate(L))
>>
>>if positions['A'] < positions['D']:
>># do some stuff
>>
>>You'll only get a gain from this version if you need to do several
>> comparisons instead of just one.
> 
> Hi Steven,
> 
> your solution may not create the correct answer if an item occurs twice
> in the list because the later occurrence overwrites the former during
> dict creation:
> 
 L = ['C', 'A', 'D', 'B', 'A']
 dict((item, i) for i, item in enumerate(L))
> {'A': 4, 'C': 0, 'B': 3, 'D': 2}
> 
> This gives the impression that 'D' always precedes 'A' which is wrong.

Yeah, thanks for the update.  I meant to include that too.

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


Re: Converting tuple to String

2006-04-30 Thread Stefan Lang
On Sunday 30 April 2006 17:32, Byte wrote:
> Is their a command to convert a tuple to string? e.g.
>
> xyz = "Hello", "There"
> print xyz
>
> Is their any way of getting print to see xyz as being one string
> i.e. "Hello There" rather than "Hello" and "There", despite "Hello"
> and "There" being, in reality, seperate?

Use the "join" method of strings:

  print ' '.join(xyz)

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


Re: Converting tuple to String

2006-04-30 Thread Daniel Nogradi
> Is their a command to convert a tuple to string? e.g.
>
> xyz = "Hello", "There"
> print xyz
>
> Is their any way of getting print to see xyz as being one string i.e.
> "Hello There" rather than "Hello" and "There", despite "Hello" and
> "There" being, in reality, seperate?

Try

one_big_string = ''.join( xyz )
print one_big_string

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting tuple to String

2006-04-30 Thread Byte
Great, that works thanks

 -- /usr/bin/byte

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


Re: setting file permissions on a web server

2006-04-30 Thread John Salerno
Daniel Nogradi wrote:

> In short, chmod refers to local files so wherever you run it it will
> refer to files on that machine. You run it simply by typing it in a
> shell as a user who has privilage to perform the operatation, which
> can mean you have to be an owner of the file but if you are root you
> can do it in any case. Depending on your ftp, scp, http or whatever
> method you use to transfer files the file permissions may or may not
> change during the transfer. If permissions are kept intact you can
> chmod on your local machine and then transfer, if they are not then
> you transfer first and chmod on the server. When you transfer files
> from a windows machine to *nix it again depends on the particular
> method you choose how the permissions will be set.

Thanks, but I'm still a little confused. Since I'm running Windows, I 
assume that I can't run the chmod line on my own computer. My web server 
uses Unix, but is it possible for me to have access to a command line 
for the server? I didn't know that was possible for basic web hosting 
plans (I'm using 1and1 right now).

I suppose I could write a script that would set the permissions of all 
the files in a particular folder on my computer to 755, but is there a 
Windows equivalent command for chmod to do this? Or am I stuck having to 
do it on the server side?
-- 
http://mail.python.org/mailman/listinfo/python-list


Hierarchy - how?

2006-04-30 Thread veracon
I'd like to know how to make the following string:
food
 fruit
  red
   cherry
  yellow
   banana
 meat
  pork
foo
 bar
  baz
 qux

Result in a dictionary like this:
{'food': {'fruit': {'red': 'cherry', 'yellow': 'banana'}, 'meat':
'pork'}, 'foo': {'bar': 'baz', 'qux': {}}}

Or something like that (if you understand). What would be the best way
of doing so? I'm thinking re.finditer might be appropriate, but I'm not
sure. I'd prefer not looping TOO much, since it's actually made using a
loop or two.

Actually, if anyone has a better idea of how to do the entire thing,
that'd be even better:
def hierarchy(data, parent='', level=0, out=''):
for item in which_parent(data, parent):
out += ' ' * level + item + '\n'
out = hierarchy(data, item, level + 1, out)

return out

def which_parent(data, parent):
return filter(None, [item[1] == parent and item[0] or None for item
in data])

data = (('food', ''),
('fruit', 'food'),
('red', 'fruit'),
('yellow', 'fruit'),
('cherry', 'red'),
('banana', 'yellow'),
('meat', 'food'),
('pork', 'meat'),
('foo', ''),
('bar', 'foo'),
('baz', 'bar'),
('qux', 'foo'))

print hierarchy(data)

-- Keep in mind that I don't want a string, I want a dictionary (but I
can't figure out how to do it).

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


Re: Hierarchy - how?

2006-04-30 Thread Heiko Wundram
Am Sonntag 30 April 2006 19:26 schrieb veracon:
> -- Keep in mind that I don't want a string, I want a dictionary (but I
> can't figure out how to do it).

The following code does what you want:

>>>
# -*- coding: iso-8859-15 -*-

data = """food
 fruit
  red
   cherry
  yellow
   banana
 meat
  pork
foo
 bar
  baz
 qux"""

top = {}
stack = [-1]
items = {-1:top}
for l in data.split("\n"):
lindent, ldata = len(l[:-len(l.lstrip())].expandtabs()), l.lstrip()
while stack[-1] >= lindent:
del items[stack[-1]]
stack.pop()
items[lindent] = {}
items[stack[-1]][ldata] = items[lindent]
stack.append(lindent)

print top
>>>

Making a function out of it is up to you. ;-)

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


Re: basic python programing

2006-04-30 Thread gregarican
Ravi Teja wrote:

> How To Ask Questions The Smart Way
> http://www.catb.org/~esr/faqs/smart-questions.html

Actual the parent post on the thread wasn't asking a question. They
were making a somewhat puzzling dangling statement.

"here we discuss the most basic concepts about python"

Where is _here__? The comp.lang.python newsgroup? In the poster's head?
These are but a sampling of my own stoopid questions.

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


Re: setting file permissions on a web server

2006-04-30 Thread Diez B. Roggisch
> I suppose I could write a script that would set the permissions of all 
> the files in a particular folder on my computer to 755, but is there a 
> Windows equivalent command for chmod to do this? Or am I stuck having to 
> do it on the server side?

The chmod has to be executed on the machine the file resides on - aka 
the server. If your plan includes a ssh-account you can use that. 
Otherwise you might be able to create an ftplib-based script that will 
automate this over ftp.

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


Re: Add file to zip, or replace file in zip

2006-04-30 Thread Scott David Daniels
Roger Miller wrote:
> First note that zipfile is a plain Python module, so reading
> Python.../Lib/zipfile.py will reveal all its secrets.
> 
> I don't think it is possible to replace archive members using the
> module. You could copy all the files into a new zip file, replacing the
> ones you want to change as you go. But it might be easier just to use
> os.system() or something similar to run an external zip program.
> 
It is not currently possible to delete or replace individual elements
in a zip file, nor (in all likelihood) would you want to do so.  It
would require having the zip[ file in a broken state for some time
as you copy data from one area of the zip to another.  Any error
(or raised exception like Control-C) during this process is likely
to leave you with an inconsistent and therefore unreadable zip file.
The typical technique is to mark some files "deleted" in the directory,
add new files (possibly the replacements for the deleted files), and,
in one pass, copy all non-deleted files to a new zip (which you can then
swap for the original zip).  Shortcutting this process puts all data in
your zip file at risk.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic python programing

2006-04-30 Thread Grant Edwards
On 2006-04-30, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> here we  discuss the most basic concepts  about python.

Yes we do.

As well as the most basic concepts about Usenet.

-- 
Grant Edwards
[EMAIL PROTECTED]

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


Re: stdin: processing characters

2006-04-30 Thread Serge Orlov

Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Edward Elliott  <[EMAIL PROTECTED]> wrote:
> >Kevin Simmons wrote:
> >> I have a python script that prompts the user for input from stdin via a
> >> menu. I want to process that input when the user types in two characters
> >> and not have to have the user press . As a comparison, in the bash
> >> shell one can use (read -n 2 -p "-->" CHOICE; case $CHOICE in...). Works
> >> great and is very
> >
> >I did something like this a couple years ago, curses was the easiest way I
> >found to do it.  It's pretty painless with the wrapper function, which
> >restores your terminal on error/exit.
> >
>
> Kevin, the bad news is that curses() is as good as Python gets in
> this regard.  For better or worse, to the best of my knowledge,
> unextended Python caNOT implement bash's read.  Here's the closest
> small approximation I know:
>
>   import curses
>   import os
>
>   msvcrt = curses.initscr()
>   msvcrt.addstr("-->")
>   first = msvcrt.getch()
>   second = msvcrt.getch()
>   os.system("stty echo -nl")
>   print "\nThe two characters are '%s' and '%s'." % (first, second)
>
> I hope someone proves me wrong.

I'm not sure what "unextended Python" means, but on POSIX platforms
termios module can disable echo and command line option -u can disable
buffering. I think there should be a way to disable buffering after
program started. Probably fcntl module.

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


Re: unable to resize mmap object

2006-04-30 Thread Serge Orlov

Fabiano Sidler wrote:
> Hi folks!
>
> I created an mmap object like so:
> --- snip ---
> from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE
> fl = file('/dev/zero','rw')
> mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS)
> --- snap ---
>
> Now, when I try to resize mm to 10 byte
> --- snip ---
> mm.resize(10)
> --- snap ---
> I get an EnvironmentError:[Errno 22] Invalid argument.

Just a guess: try a new size argument that is multiple of page size.

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



Re: Can I collapse a Panel in wxPython?

2006-04-30 Thread rbann11

[EMAIL PROTECTED] wrote:
> Hi.
>
> I have a gui with one frame and 5 panels.  The second panel will only
> be required in some cases,  so I am wondering if there is some way I
> can only create this panel in the circumstances where it is required,
> confirmed by a simple len(list) > 1
>
> If it is possible, I am wondering how I might go about it  I am not
> sure where to put an if statement as there are many different referrals
> to panel_2
>
> Letting me know or just pointing me to an example of such a thing would
> be fabulous.
>
> TIA

Check out http://wiki.wxpython.org/index.cgi/FoldPanelBar

Roger

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


Re: installing pyodbc

2006-04-30 Thread Paul Watson
timw.google wrote:
> I just downloaded the  pyodbc source to try and install on my Linux FC3
> box. I see that there is a setup.py file, but when I try to do a
> 'python setup.py build' (or just 'python setup.py') I get
> 
> Traceback (most recent call last):
>   File "setup.py", line 27, in ?
> revision = latest_revision('.')
>   File "setup.py", line 25, in latest_revision
> return int(output)
> ValueError: invalid literal for int(): exported
> 
> The README.txt doesn't really say anything about how to install, exept
> that the easiest way is to use the Windows installer. That's fine for
> Windows, but what about Linux?
> 
> Thanks for any help.

Have you read the http://sourceforge.net/projects/pyodbc/ summary page 
where the "Operating System" indicates which platforms are supported? 
That might be relevant information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Daniel Nogradi
> > In short, chmod refers to local files so wherever you run it it will
> > refer to files on that machine. You run it simply by typing it in a
> > shell as a user who has privilage to perform the operatation, which
> > can mean you have to be an owner of the file but if you are root you
> > can do it in any case. Depending on your ftp, scp, http or whatever
> > method you use to transfer files the file permissions may or may not
> > change during the transfer. If permissions are kept intact you can
> > chmod on your local machine and then transfer, if they are not then
> > you transfer first and chmod on the server. When you transfer files
> > from a windows machine to *nix it again depends on the particular
> > method you choose how the permissions will be set.
>
> Thanks, but I'm still a little confused. Since I'm running Windows, I
> assume that I can't run the chmod line on my own computer.

Correct, chmod is a *nix command.

> My web server
> uses Unix, but is it possible for me to have access to a command line
> for the server?

This depends on your arrangements with your web server provider.
Perhaps you are allowed to ssh into that machine, perhaps not, you
need to ask your provider. In case you can use ssh, then you can log
in with putty (an ssh client for windows, grab it from here:
http://www.chiark.greenend.org.uk/~sgtatham/putty/) and you will have
a command line on the server so you can run chmod there.

> I didn't know that was possible for basic web hosting plans (I'm using 1and1 
> right now).

I have absolutely no experience with public web hosting but I guess
some might provide ssh-ing possibilities although I imagine most
don't.

> I suppose I could write a script that would set the permissions of all
> the files in a particular folder on my computer to 755, but is there a
> Windows equivalent command for chmod to do this?

I have next to zero experience with windows but as far as I know
windows doesn't have file permissions at all (anyone, please correct
me if I'm wrong :)) so in windows land it doesn't make any sense to
"change file permissions". Even if it has some sort of a notion of
file permissions I wouldn't know how that gets translated into unix.

> Or am I stuck having to do it on the server side?

I guess so. But that's not a terribly big problem even if you can't
use ssh. What I would do is write a script (in python of course :))
that does the file permission changing and run that script over the
web. Since this can have serious security implications my strategy
would be to place this script somewhere which is not reachable through
the web and only relocate it to a web accessible directory when you
want to run it over the web, and when you are done, you place it back
to its secure location so nobody can reach it. You can find out how to
write this script from http://docs.python.org/lib/os-file-dir.html

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


Re: basic python programing

2006-04-30 Thread John Kirkland
On 30 Apr 2006 00:48:47 -0700, Ravi Teja wrote:

> How To Ask Questions The Smart Way
> http://www.catb.org/~esr/faqs/smart-questions.html

Damn, that's one of the best respones ever. :)

WTG.

Oh, and I'm not being sarcastic. That's a truly useful set of ideals. It's
now joined my short and distinguished bookmark list. :)


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


Re: Add file to zip, or replace file in zip

2006-04-30 Thread Edward Elliott
Scott David Daniels wrote:
> It is not currently possible to delete or replace individual elements
> in a zip file, nor (in all likelihood) would you want to do so.  It
> would require having the zip[ file in a broken state for some time
> as you copy data from one area of the zip to another.  

If zips just used sequential access like tar files, you could append newer
versions without a problem.  You windows kids and your crazy data formats.

> Any error 
> (or raised exception like Control-C) during this process is likely
> to leave you with an inconsistent and therefore unreadable zip file.

Isn't that true of any modifications to the zip archive, e.g. appending a
new file rather than replacing an existing one?

> in one pass, copy all non-deleted files to a new zip (which you can then
> swap for the original zip).  Shortcutting this process puts all data in
> your zip file at risk.

Again, isn't this true of any substantive change to any file whatsoever?  
Errors during write can always leave your data in an inconsistent state,
unless your data uses a structured append format like journaled
filesystems.  That seems like an orthogonal issue to replacing a file in
the archive.

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


Re: setting file permissions on a web server

2006-04-30 Thread Edward Elliott
John Salerno wrote:
> Thanks, but I'm still a little confused. Since I'm running Windows

You misplaced your period, it goes at the end of that line. ;)

> assume that I can't run the chmod line on my own computer. 

Sure you can, install cygwin.  chmod only affects files on your computer,
and won't alter the Windows permissions (which use a different scheme), but
you can do it.

> My web server 
> uses Unix, but is it possible for me to have access to a command line
> for the server? I didn't know that was possible for basic web hosting
> plans (I'm using 1and1 right now).

It is entirely possible (indeed, I don't know how most things would ever get
done without it).  Most basic hosting plans however don't provide shell
access.

> I suppose I could write a script that would set the permissions of all
> the files in a particular folder on my computer to 755, but is there a
> Windows equivalent command for chmod to do this? Or am I stuck having to
> do it on the server side?

1. Settings permissions on your computer won't do a thing.
2. There's probably a Windows-equiv of chmod for your own files, but it
won't affect files placed on another machine.
3. You're stuck having to do it on the server side.  Now a good ftp program
can automate this for you, but it's still your job, not the servers.

These sound like good questions for your hosting provider, or failing that,
google.

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


Re: basic python programing

2006-04-30 Thread Edward Elliott
gregarican wrote:
>> How To Ask Questions The Smart Way
>> http://www.catb.org/~esr/faqs/smart-questions.html
> 
> Actual the parent post on the thread wasn't asking a question. They
> were making a somewhat puzzling dangling statement.

Maybe it's time for the sequel, How To Make Smart Statements :)

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


Re: setting file permissions on a web server

2006-04-30 Thread Edward Elliott
Daniel Nogradi wrote:
> I have next to zero experience with windows but as far as I know
> windows doesn't have file permissions at all (anyone, please correct
> me if I'm wrong :)) so in windows land it doesn't make any sense to
> "change file permissions". 

Actually Windows has a quite good permission scheme, with full owner/group
ACLs and granular permissions for read, write, append, delete, and several
others I can't recall.  The problem is no one uses them much.  The
manipulation tools are a pain, and developers routinely ignore them
(including Microsoft's own developers, although I hear they've gotten much
better lately).

> I guess so. But that's not a terribly big problem even if you can't
> use ssh. What I would do is write a script (in python of course :))
> that does the file permission changing and run that script over the
> web. Since this can have serious security implications my strategy 
> would be to place this script somewhere which is not reachable through
> the web and only relocate it to a web accessible directory when you
> want to run it over the web, and when you are done, you place it back
> to its secure location so nobody can reach it. 

You're right about the security concerns, but your solution sounds like more
trouble than it's worth.  With a bit more effort, you could write a local
python script that acts as an ftp client and applies permissions remotely. 
But why bother when a good ftp client already has that built-in (and is
much less likely to contain destructive bugs).

> You can find out how to
> write this script from http://docs.python.org/lib/os-file-dir.html

You're worried about security and you turn a novice with a scripting
language loose in the briar patch of unix permissions, on a remote server
no less?  And I thought I was sadistic! :)

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


Re: setting file permissions on a web server

2006-04-30 Thread Kirk McDonald
Daniel Nogradi wrote:
> I have next to zero experience with windows but as far as I know
> windows doesn't have file permissions at all (anyone, please correct
> me if I'm wrong :)) so in windows land it doesn't make any sense to
> "change file permissions". Even if it has some sort of a notion of
> file permissions I wouldn't know how that gets translated into unix.

This is getting a little off-topic, I admit, but the NT-derived versions 
of Windows do indeed have file permissions. The Windows-equivalent of 
chmod (and chown) is cacls ("Change Access Control Lists"):

http://www.ss64.com/nt/cacls.html

In essence, each file has an owner and a list of other users and groups, 
who may each have "Full control" (meaning they can change permissions), 
read-only, write-only, read-write, or no access.

Windows 95 and its descendants don't have permissions any more than DOS 
does. (Except with respect to Windows network file-sharing.)

(Heh, I checked just before posting this and someone beat me to it. 
Here's my post anyway.) :-)

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


WAP page, Python and creating a file on file system - Newbie

2006-04-30 Thread Digital
HELP!!

All I need to do is to create a file in a folder. I am running Abyss WEB 
server and Python. and googling many sites has taught me how to create a 
file in a folder. BUT. I need to do this from a WML file - This is proving 
difficult...

I can setup an index.wml and a deck of cards. Each card points to a 
.py file. This file creates a file in the folder of my choice but 
always returns an error to the WAP browser.

I have tried PRINTing WML content within the Python code and thought I had 
formed a WML output but still the WAP browser returns an error.

It seems an awful lot of trouble to go to, load Python to create a file in a 
folder. Is there any way I can easily do this?

Before people reply with how to do stuff in OOP. I have no knowledge of OOP 
and class instantiation etc etc. I really do need a noddy guide in what I am 
doing.

Regards
Dave


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


Measure memory usage in Python

2006-04-30 Thread Rune Strand
Is there a way to measure how much memory a data structure use? For
instance, what is the footprint of a particular list object like
[0,1,2,3,4,5,6,7,8,9]?

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


From the Tutorial Wiki: suggested restructure

2006-04-30 Thread Gerard Flanagan
For anyone interested, here's a blog entry I've added over at the
Tutorial Wiki:


As mentioned by effbot in the previous post I've put together a
suggested alternative factoring of the Tutorial
here(http://pytut.infogami.com/gerard_refactor). At the minute it just
amounts to a carving-up of the existing material into two sections:
beginners and intermediate. It's a bit stilted in places, but not
excessively. There's also a suggested advanced section - I'm not an
advanced user myself so I don't really know what would be appropriate
here. Each section in the beginners tutorial has links to relevant FAQS
at pyfaq.infogami.com. I also thought the FAQS could be preceded by
suitable examples, and maybe there could be a final chapter of
exercises.

I've been sitting for half an hour trying to articulate why I think
this is a good idea, but the well has dried up...and I seem to have
gone a bit snow-blind looking at the blank screen! I just remember that
when I was learning Python, although the Tutorial was incredibly useful
and a key source of info, it seemed that I always had to hunt
excessively when I had questions like 'how does **kwargs work?', 'what
does extend do again?' etc. - I always thought that things weren't
ordered in the best way, and the chapter titles weren't that helpful.
so this is how I think it should be done! I hope it's a positive
contribution - maybe it will provoke discussion if nothing else.

Unfortunately, I won't have easy access to a computer for the next few
months, so I can't contribute any more at this point.
--

Comments welcome. Or contributions - particularly to the advanced
section.

All the best.

Gerard

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


How to efficiently read binary files?

2006-04-30 Thread David Lees
I want to process large binary files (>2GB) in Python.  I have played 
around with prototypes in pure Python and profiled the code.  Most of 
the time seems to be spent converting back and forth to and from strings 
using the struct module.  Is there a way to directly read into an array 
of integers in Python?

TIA

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


Re: How to efficiently read binary files?

2006-04-30 Thread Grant Edwards
On 2006-04-30, David Lees <[EMAIL PROTECTED]> wrote:
> I want to process large binary files (>2GB) in Python.  I have played 
> around with prototypes in pure Python and profiled the code.  Most of 
> the time seems to be spent converting back and forth to and from strings 
> using the struct module.  Is there a way to directly read into an array 
> of integers in Python?

Perhaps the numarray module?

-- 
Grant Edwards
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to efficiently read binary files?

2006-04-30 Thread Robert Kern
Grant Edwards wrote:
> On 2006-04-30, David Lees <[EMAIL PROTECTED]> wrote:
> 
>>I want to process large binary files (>2GB) in Python.  I have played 
>>around with prototypes in pure Python and profiled the code.  Most of 
>>the time seems to be spent converting back and forth to and from strings 
>>using the struct module.  Is there a way to directly read into an array 
>>of integers in Python?
> 
> Perhaps the numarray module?

numpy for new code, please. In particular, numarray is limited by 32-bit APIs
even on 64-bit platforms, so a >2GB file will be difficult to process even when
using mmap. numpy removed this restriction on 64-bit platforms. 32-bit users
will still have to split up the file into <2GB chunks, though.

  http://numeric.scipy.org/
  https://lists.sourceforge.net/lists/listinfo/numpy-discussion

-- 
Robert Kern
[EMAIL PROTECTED]

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: How to efficiently read binary files?

2006-04-30 Thread Alex Martelli
David Lees <[EMAIL PROTECTED]> wrote:

> I want to process large binary files (>2GB) in Python.  I have played
> around with prototypes in pure Python and profiled the code.  Most of
> the time seems to be spent converting back and forth to and from strings
> using the struct module.  Is there a way to directly read into an array
> of integers in Python?

>>> import array
>>> x=array.array('l')
>>> help(x.fromfile)

Help on built-in function fromfile:

fromfile(...)
fromfile(f, n)

Read n objects from the file object f and append them to the end of
the array.  Also called as read.


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


Re: setting file permissions on a web server

2006-04-30 Thread John Salerno
Daniel Nogradi wrote:

> This depends on your arrangements with your web server provider.
> Perhaps you are allowed to ssh into that machine, perhaps not, you
> need to ask your provider. In case you can use ssh, then you can log
> in with putty (an ssh client for windows, grab it from here:
> http://www.chiark.greenend.org.uk/~sgtatham/putty/) and you will have
> a command line on the server so you can run chmod there.

Turns out that my web hosting company provides ssh access on the next 
highest plan and up, but not mine. :)

Oh well, I think I'll explore FileZilla a little more and see if there's 
more of an automated way to do it than just right-clicking each file (or 
even right-clicking multiple files at once, if possible). It shouldn't 
be too big of a deal anyway, but I'm always after more automated ways to 
do things...call me lazy! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


ending a string with a backslash

2006-04-30 Thread John Salerno
I have this:

subdomain = raw_input('Enter subdomain name: ')

path = r'C:\Documents and Settings\John Salerno\My Documents\My 
Webs\1and1\johnjsalerno.com\' + subdomain

Obviously the single backslash at the end of 'path' will cause a 
problem, and escaping it with a backslash seems to fix this problem, but 
how does escaping work when I already have it as a raw string? When I 
test it out and then print string, I get something like this:

C:\Documents and Settings\John Salerno\My Documents\My 
Webs\1and1\johnjsalerno.com\\test

But I don't see how this is valid, since all the backslashes are single 
(which is correct) except the last one. Somehow this still works when I 
tried to create the new directory -- os.mkdir(path) -- but I wasn't sure 
if this is the right way to go about it, or if there is some other, 
better way to handle the final backslash.
-- 
http://mail.python.org/mailman/listinfo/python-list


python and xulrunner

2006-04-30 Thread joe . hrbek
Hi everyone, sorry, this post is a bit off topic.  I posted this on a
devel xul thread on the mozilla groups but didn't get a response.  My
hope is that some of you may have interest in this and have tried it
yourself.

I've been trying to get xulrunner compiled with python (in windows) but
have been unsuccessful.  I've been following this:
.

I know it's a linux based tutorial, but the steps are generally the
same aside from required os linkers/compilers - which i've obtained
reading the standard mozilla compile instructions for windows.

Has anyone else tried this and had luck with it?

-j

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


critique this little script, if you like

2006-04-30 Thread John Salerno
# Create new subdomain directory (with subdirectories) in my 1and1 folder

import os
import sys

subdirs = [r'\cgi-bin', r'\images', r'\styles']

#if len(sys.argv) == 1:
#   subdomain = raw_input('Enter subdomain name: ')
#else:
#   subdomain = sys.argv[1]

try:
 subdomain = sys.argv[1]
except IndexError:
 subdomain = raw_input('Enter subdomain name: ')

path = r'C:\Documents and Settings\John Salerno\My Documents\My 
Webs\1and1\johnjsalerno.com\\' + subdomain

os.mkdir(path)
for subdir in subdirs:
 os.mkdir(path + subdir)


Just a simple script I wrote as an experiment, and it works nicely 
anyway. My two questions are these:

1. Like my other post, I'm wondering if it's okay to handle the ending 
backlash as I did in path

2. Between the if block or the try block, which is more Pythonic? The 
try block seems nicer because it doesn't have such an ugly-looking check 
to make.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Martin P. Hellwig
John Salerno wrote:


Most FTP servers do allow to use chmod in a ftp session, although you're 
client must support it. See for example a cli ftp client (and server) on 
FreeBSD.

> [EMAIL PROTECTED]:~$ ftp ftp.xs4all.nl
> Connected to ftp2.xs4all.nl.
> 220 XS4ALL ftpd DCLXVI
> Name (ftp.xs4all.nl:mhellwig):
> 331 Password required for mhellwig.
> Password:
> 230 User mhellwig logged in.
> Remote system type is UNIX.
> Using binary mode to transfer files.
> ftp> ls MHellwigCV_02_10_01.pdf
> 150 Opening ASCII mode data connection for file list
> --   1 mhellwig user   211102 May 19  2003 MHellwigCV_02_10_01.pdf
> 226 Transfer complete.
> ftp> chmod 400 MHellwigCV_02_10_01.pdf
> 200 SITE CHMOD command successful
> ftp> ls MHellwigCV_02_10_01.pdf
> 150 Opening ASCII mode data connection for file list
> -r   1 mhellwig user   211102 May 19  2003 MHellwigCV_02_10_01.pdf
> 226 Transfer complete.
> ftp>

See?

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


ANN: nose 0.9.0a1

2006-04-30 Thread [EMAIL PROTECTED]
I'm pleased to announce the 0.9.0a1 release of nose, a test runner that
brings py.test convenience to unittest, without resorting to (too much)
magic.

nose 0.9 includes a host of new features, as well as numerous
backwards-incompatible changes to interfaces and implementation. For
this reason, I'm releasing it first as an alpha version.

Thanks to the many folks who have contributed patches and ideas and
made bug reports for the development version of 0.9, especially Mika
Eloranta, Jay Parlar, Kevin Dangoor, Scot Doyle and Philip J. Eby.

Here's a quick rundown of what's new in 0.9.0a1.

- Plugins

 The most important new feature is support for plugins using
setuptools entrypoints. nose plugins can select and load tests (like
the builtin doctest plugin), reject tests (like the builtin attrib
plugin, contributed by Mika Eloranta, that allows users to select tests
by attribute), watch and report on tests (like the builtin coverage and
profiler plugins), completely replace test result output (like the html
result plugin in the examples directory) or any combination of the
above. Writing plugins is simple: subclass nose.plugins.Plugin and
implement any of the methods in nose.plugins.IPluginInterface.

- Better compatibility with unittest

 Test loading has been consolidated into a test loader class that is
drop-in compatible with unittest.TestLoader. Likewise test result
output, including output capture, assert introspection, and support for
skipped and deprecated tests, in nose.result.TextTestResult. If you
want those features and not the rest of nose, you can use just those
classes. nose.main() has also been rewritten to have the same signature
as unittest.main().

- Better command line interface

 Command line test selection is more intuitive and powerful, enabling
easy and correct running of single tests while ensuring that fixtures
(setup and teardown) are correctly executed at all levels. No more -f
-m or -o options; now simply specify the tests to run:

   nosetests this/file.py that.module

 Tests may be specified down to the callable:

   nosetests this/file.py:TestClass that.module:this_test
   nosetests that.module:TestClass.test_method

 There are also new options for dropping into pdb on errors or
failures, and stopping the test run on the first error or failure
(thanks to Kevin Dangoor for the idea).

- More!

 Helpful test decorators and functions in nose.tools. Support for
generators in test classes. Better import path handling -- that you can
shut off! Detailed verbose logging using the logging package. And
more...

For more information, installation instructions, etc, see:

http://somethingaboutorange.com/mrl/projects/nose/

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


ANN: nose 0.9.0a1

2006-04-30 Thread [EMAIL PROTECTED]
I'm pleased to announce the 0.9.0a1 release of nose, a test runner that
brings py.test convenience to unittest, without resorting to (too much)
magic.

nose 0.9 includes a host of new features, as well as numerous
backwards-incompatible changes to interfaces and implementation. For
this reason, I'm releasing it first as an alpha version.

Thanks to the many folks who have contributed patches and ideas and
made bug reports for the development version of 0.9, especially Mika
Eloranta, Jay Parlar, Kevin Dangoor, Scot Doyle and Philip J. Eby.

Here's a quick rundown of what's new in 0.9.0a1.

- Plugins

 The most important new feature is support for plugins using
setuptools entrypoints. nose plugins can select and load tests (like
the builtin doctest plugin), reject tests (like the builtin attrib
plugin, contributed by Mika Eloranta, that allows users to select tests
by attribute), watch and report on tests (like the builtin coverage and
profiler plugins), completely replace test result output (like the html
result plugin in the examples directory) or any combination of the
above. Writing plugins is simple: subclass nose.plugins.Plugin and
implement any of the methods in nose.plugins.IPluginInterface.

- Better compatibility with unittest

 Test loading has been consolidated into a test loader class that is
drop-in compatible with unittest.TestLoader. Likewise test result
output, including output capture, assert introspection, and support for
skipped and deprecated tests, in nose.result.TextTestResult. If you
want those features and not the rest of nose, you can use just those
classes. nose.main() has also been rewritten to have the same signature
as unittest.main().

- Better command line interface

 Command line test selection is more intuitive and powerful, enabling
easy and correct running of single tests while ensuring that fixtures
(setup and teardown) are correctly executed at all levels. No more -f
-m or -o options; now simply specify the tests to run:

   nosetests this/file.py that.module

 Tests may be specified down to the callable:

   nosetests this/file.py:TestClass that.module:this_test
   nosetests that.module:TestClass.test_method

 There are also new options for dropping into pdb on errors or
failures, and stopping the test run on the first error or failure
(thanks to Kevin Dangoor for the idea).

- More!

 Helpful test decorators and functions in nose.tools. Support for
generators in test classes. Better import path handling -- that you can
shut off! Detailed verbose logging using the logging package. And
more...

For more information, installation instructions, etc, see:

http://somethingaboutorange.com/mrl/projects/nose/

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


file open "no such file"

2006-04-30 Thread Gary Wessle
I am getting this error when I try to run the code below


f = open("~/m", "r")
print f.read()



:~$ python python/my.py 
Traceback (most recent call last):
  File "python/my.py", line 1, in ?
f = open("~/m", "r")
IOError: [Errno 2] No such file or directory: '~/m'


but I have the "m" file in my home/username/


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


python colorfinding

2006-04-30 Thread pain . and . cookies
how would i use python to find colors and click on them without
actually moving the mouse

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


Re: file open "no such file"

2006-04-30 Thread Robert Kern
Gary Wessle wrote:
> I am getting this error when I try to run the code below
> 
> 
> f = open("~/m", "r")
> print f.read()
> 
> 
> 
> :~$ python python/my.py 
> Traceback (most recent call last):
>   File "python/my.py", line 1, in ?
> f = open("~/m", "r")
> IOError: [Errno 2] No such file or directory: '~/m'
> 
> 
> but I have the "m" file in my home/username/

There is no automatic ~expansion. You will need to use the function
os.path.expanduser().

-- 
Robert Kern
[EMAIL PROTECTED]

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: ending a string with a backslash

2006-04-30 Thread Edward Elliott
John Salerno wrote:
> Obviously the single backslash at the end of 'path' will cause a
> problem, and escaping it with a backslash seems to fix this problem, but
> how does escaping work when I already have it as a raw string? 

see the first two items here:
http://www.ferg.org/projects/python_gotchas.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a browser as a GUI: which Python package

2006-04-30 Thread Don Taylor
John J. Lee wrote:
> "André" <[EMAIL PROTECTED]> writes:
> [...]
> 
>>I would like to use a browser (e.g. Firefox) as a simple GUI
>>"framework".  Note that this is to be done on a single user machine, so
>>the question of sandboxing is not really relevant here.
> 
> [...]
> 
>>My ultimate goal would be to port the main features of two
>>wxPython-based apps I wrote (rur-ple and Lightning Compiler, both found
>>at https://sourceforge.net/project/showfiles.php?group_id=125834)
>>within a standard browser.
> 
> 
> If you can stick to Firefox, you might find XUL useful.  There are
> various different styles of development that use XUL and Python -- a
> bit of Googling and reading should find them.
> 
Bear in mind that I don't know what I am talking about, but I stumbled 
across 'ZK' the other day put it on my list of thinkgs to check out.  It 
provides a range of XUL and XHTML widgets, see:

http://zk1.sourceforge.net/

Has anyone tried this?  I would really like to find a GUI toolkit that 
allowed me to program XUL in Firefox using Python.  ZK is not quite 
that, but it looks close.

Don.

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


Re: ending a string with a backslash

2006-04-30 Thread Terry Reedy

"John Salerno" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I have this:
>
> subdomain = raw_input('Enter subdomain name: ')
>
> path = r'C:\Documents and Settings\John Salerno\My Documents\My
> Webs\1and1\johnjsalerno.com\' + subdomain

For any direct use of paths within Python (to open a file, change 
directory, etc), forward slashes work fine, avoiding backslash problems.

tjr



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


Re: How to efficiently read binary files?

2006-04-30 Thread David Lees
Alex Martelli wrote:
> David Lees <[EMAIL PROTECTED]> wrote:
> 
>> I want to process large binary files (>2GB) in Python.  I have played
>> around with prototypes in pure Python and profiled the code.  Most of
>> the time seems to be spent converting back and forth to and from strings
>> using the struct module.  Is there a way to directly read into an array
>> of integers in Python?
> 
 import array
 x=array.array('l')
 help(x.fromfile)
> 
> Help on built-in function fromfile:
> 
> fromfile(...)
> fromfile(f, n)
> 
> Read n objects from the file object f and append them to the end of
> the array.  Also called as read.
> 
> 
> Alex

Thank you.  This is exactly what I was looking for.  I just tried it and 
it works great.

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


How can I implement a timeout with subprocess.Popen()?

2006-04-30 Thread I. Myself
I want my Python program to invoke a compiled C program, and capture the 
text output.
Here's a fragment from a program that works, using subprocess.Popen:

p = Popen(execName, stdout=PIPE)
while(1):
line = p.stdout.readline() # get next line
outfile.write(line)
(Then I test for a certain unique phrase in line, and then break 
if it occurs)

The above works fine as long as the target program runs for a little 
while and then stops.  But what if  it does not stop?   It might run 
forever, with or without outputting any lines.  How can I make this 
robust?  The keyword might not occur.  The target might crash.  It might 
run forever, with or without text output.

Thanks,

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


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


Re: critique this little script, if you like

2006-04-30 Thread Dave Jones
Hi John!

About the path and the \'s, take a look at the os.path.join function.
The function is smart enough to add the correct slash when joining
directories.

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


Re: finding IP address of computer

2006-04-30 Thread Paul Watson
DarkBlue wrote:
> Chris wrote:
> 
> 
>>How do I find and print to screen the IP address of the computer my
>>python program is working on?
> 
> 
> def readip():
>  import re, urllib
>  f = urllib.urlopen('http://checkip.dyndns.org')
>  s = f.read()
>  m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
>  return m.group(0)
> 
> myip = readip()

IP address and other browser header information available at:

http://xhaus.com/headers
-- 
http://mail.python.org/mailman/listinfo/python-list


How to prevent this from happening?

2006-04-30 Thread phil_nospam_schmidt
Regarding this expression:  1 << x

I had a bug in my code that made x become Very Large - much larger than
I had intended. This caused Python, and my PC, to lock up tight as a
drum, and it appeared that the Python task (Windows XP) was happily and
rapidly consuming all available virtual memory.

Presumably, Python was trying to create a really really long integer,
just as I had asked it.

Is there a way to put a limit on Python, much like there is a stack
limit, so that this sort of thing can't get out of hand?

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


Re: ending a string with a backslash

2006-04-30 Thread John Salerno
Edward Elliott wrote:
> John Salerno wrote:
>> Obviously the single backslash at the end of 'path' will cause a
>> problem, and escaping it with a backslash seems to fix this problem, but
>> how does escaping work when I already have it as a raw string? 
> 
> see the first two items here:
> http://www.ferg.org/projects/python_gotchas.html

#2 was very helpful. But if I want to use forward slashes instead, can I 
just replace the backslashes with them, or must I use the 
os.path.normcase() function to do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: critique this little script, if you like

2006-04-30 Thread John Salerno
Dave Jones wrote:
> Hi John!
> 
> About the path and the \'s, take a look at the os.path.join function.
> The function is smart enough to add the correct slash when joining
> directories.
> 
> Dave

Interesting, thanks! I was reading about the normcase() function, but 
your suggestion might be better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: critique this little script, if you like

2006-04-30 Thread John Salerno
John Salerno wrote:
> Dave Jones wrote:
>> Hi John!
>>
>> About the path and the \'s, take a look at the os.path.join function.
>> The function is smart enough to add the correct slash when joining
>> directories.
>>
>> Dave
> 
> Interesting, thanks! I was reading about the normcase() function, but 
> your suggestion might be better.

Excellent, works great! But one more question: do I need to import 
os.path for this? I tried it with and without it, and it worked both 
ways, so I'm a little uncertain about whether os.path is really a 
separate module, or if it is still contained within os and doesn't need 
to be imported separately (it seems like it doesn't, but it is listed 
separately in the docs).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measure memory usage in Python

2006-04-30 Thread gene tani

Rune Strand wrote:
> Is there a way to measure how much memory a data structure use? For
> instance, what is the footprint of a particular list object like
> [0,1,2,3,4,5,6,7,8,9]?

i have a note to try this, but haven't got around to it, if you want to
blog/post

http://pysizer.8325.org/

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


Re: wxpython - new line in radiobutton's label?

2006-04-30 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>I am creating a small gui using wxGlade and wxPython.  I am using a
>radio button, and the text next to the options needs to be over two
>lines.  I tried using a \n character,  but it seems to get ignored.
>
>Looking around in the various wikis and the example code also didn't
>turn up anything.

The native Windows radio button cannot do multiline labels.  You'll have to
do the first line in the radio button, and the second line as a
wx.StaticText.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


returning none when it should be returning a list?

2006-04-30 Thread randomtalk
hello, i have another problem i feel that i have to be missing
something.. Basically, i've written a recursive function to find all
the prime up to a number (lim).. here is the function:

The function basically takes in a list of all the prime number found,
it takes the next number to be tested for (next) and the limit it will
go up to. It divide next by the list of previous prime numbers if next
is not bigger than lim, count up all the times where it's not evenly
divdided, if the result is equal the length of prime number, then we
have another prime number, lather rinse and repeat :)

def findPrime(seed, next, lim):
print("seed: " + str(seed) + " next: " + str(next) + " lim: " +
str(lim))
print(seed)
if(next >= lim):
print(seed)
return seed
else:
count = 0;
for num in seed:
modu = math.modf(float(next)/float(num));
if(modu[0] > 0):
count += 1
if(count == len(seed)):
seed.append(next)
findPrime(seed, next+2, lim)
else:
findPrime(seed, next+2, lim)

As you can probably see, i've printed the value of seed up until the
point where i'm returning the seed, however, the function still returns
None..

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


Re: How to prevent this from happening?

2006-04-30 Thread John Machin
On 1/05/2006 12:55 PM, [EMAIL PROTECTED] wrote:
> Regarding this expression:  1 << x
> 
> I had a bug in my code that made x become Very Large - much larger than
> I had intended. This caused Python, and my PC, to lock up tight as a
> drum, and it appeared that the Python task (Windows XP) was happily and
> rapidly consuming all available virtual memory.
> 
> Presumably, Python was trying to create a really really long integer,
> just as I had asked it.
> 
> Is there a way to put a limit on Python, much like there is a stack
> limit, so that this sort of thing can't get out of hand?
> 

If you mean a command line argument to specify an upper limit for the 
RHS of a << operator, no there isn't one, and no there shouldn't be one.

To cater for sillinesses that aren't caught by exceptions (or where it 
may be a very long time before the exception is triggered, as in your 
case), I'd suggest placing tests close to the action. For example, if 
you are doing some bit-bashing, "assert nshift <= wordsize" or something 
like that may be appropriate.




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


SPE / winpdb problem

2006-04-30 Thread MakaMaka
Hi All,
I'm having a problem with Stani's Python Editor (SPE) that I'm hoping
somebody has run into before.  If I create a simple hello world
program:

print "hello"

and try and run it in winpdb via the SPE command ALT-F9, the program
does not launch and the following results (It's at the bottom):


Spe Warning: Spe was developped on wxPython v2.6.1.0., but v2.6.3.2.
was found.
If you experience any problems please install wxPython v2.6.1.0.


SPE v0.8.2.a (c)2003-2005 www.stani.be

If spe fails to start:
 - type "python SPE.py --debug > debug.txt 2>&1" at the command prompt
   (or if you use tcsh: "python SPE.py --debug >& debug.txt")
 - send debug.txt with some info to spe.stani.be[at]gmail.com


Spe Warning: Spe was developped on wxPython v2.6.1.0., but v2.6.3.2.
was found.
If you experience any problems please install wxPython v2.6.1.0.

Blender support disabled (run SPE inside Blender to enable).

Encrypted debugging disabled.
  If you prefer encrypted debugging, install the "Python Cryptography
Toolkit"
  from http://www.amk.ca/python/code/crypto

Launching application...
Traceback (most recent call last):
  File "C:\Python24\lib\site-packages\_spe\plugins\winpdb\winpdb.py",
line 3313,
 in ?
ret = main()
  File "C:\Python24\lib\site-packages\_spe\plugins\winpdb\winpdb.py",
line 3303,
 in main
return rpdb2.main(StartClient)
  File "C:\Python24\Lib\site-packages\_spe\plugins\winpdb\rpdb2.py",
line 7221,
in main
StartClient_func(_args, fAttach, fchdir, pwd, fAllowUnencrypted,
fRemote, ho
st)
  File "C:\Python24\lib\site-packages\_spe\plugins\winpdb\winpdb.py",
line 3293,
 in StartClient
app = CWinpdbApp(sm, fchdir, command_line, fAttach,
fAllowUnencrypted)
  File "C:\Python24\lib\site-packages\_spe\plugins\winpdb\winpdb.py",
line 1528,
 in __init__
wx.App.__init__(self, redirect = False)
  File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_core.py",
line 7700, i
n __init__
self._BootstrapApp()
  File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_core.py",
line 7352, i
n _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "C:\Python24\lib\site-packages\_spe\plugins\winpdb\winpdb.py",
line 1533,
 in OnInit
self.m_settings.load_settings()
  File "C:\Python24\lib\site-packages\_spe\plugins\winpdb\winpdb.py",
line 638,
in load_settings
d = cPickle.load(f)
EOFError



Any ideas what is going on?

Thanks!

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


Re: returning none when it should be returning a list?

2006-04-30 Thread John Machin
On 1/05/2006 2:52 PM, [EMAIL PROTECTED] wrote:
> hello, i have another problem i feel that i have to be missing
> something.. Basically, i've written a recursive function to find all
> the prime up to a number (lim).. here is the function:
> 
> The function basically takes in a list of all the prime number found,
> it takes the next number to be tested for (next) and the limit it will
> go up to. It divide next by the list of previous prime numbers if next
> is not bigger than lim, count up all the times where it's not evenly
> divdided, if the result is equal the length of prime number, then we
> have another prime number, lather rinse and repeat :)
> 
> def findPrime(seed, next, lim):
> print("seed: " + str(seed) + " next: " + str(next) + " lim: " +
> str(lim))
> print(seed)
> if(next >= lim):
> print(seed)
> return seed
> else:
> count = 0;
> for num in seed:
> modu = math.modf(float(next)/float(num));
> if(modu[0] > 0):
> count += 1
> if(count == len(seed)):
> seed.append(next)
> findPrime(seed, next+2, lim)
> else:
> findPrime(seed, next+2, lim)
> 
> As you can probably see, i've printed the value of seed up until the
> point where i'm returning the seed, however, the function still returns
> None..
> 

That's because it "falls off the end" of the function, which causes it 
to return None. However that's not your only problem. Major other 
problem is updating "seed" in situ.

Consider the following:

=== file: pseed.py ===
def findPrime(seed, next, lim):
 print "seed: %r, next: %d, lim: %d" % (seed, next, lim)
 if next >= lim:
 return seed
 for num in seed:
 # modu = math.modf(float(next)/float(num));
 # Try integer arithmetic:
 if num > 2 and not (next % num):
 # "next" is not a prime number
 return findPrime(seed, next+2, lim)
 return findPrime(seed + [next], next+2, lim)

# results:
"""
 >>> pseed.findPrime([1, 2], 3, 30)
seed: [1, 2], next: 3, lim: 30
seed: [1, 2, 3], next: 5, lim: 30
seed: [1, 2, 3, 5], next: 7, lim: 30
seed: [1, 2, 3, 5, 7], next: 9, lim: 30
seed: [1, 2, 3, 5, 7], next: 11, lim: 30
seed: [1, 2, 3, 5, 7, 11], next: 13, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13], next: 15, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13], next: 17, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17], next: 19, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17, 19], next: 21, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17, 19], next: 23, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17, 19, 23], next: 25, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17, 19, 23], next: 27, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17, 19, 23], next: 29, lim: 30
seed: [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29], next: 31, lim: 30
[1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
 >>>
"""

# Doh! Looks like recursion not necessary. Google 'eliminate tail 
recursion' :-)

def findPrime2(lim):
 seed = [1, 2]
 for next in xrange(3, lim, 2):
 prime = True
 for num in seed:
 if num > 2 and not (next % num):
 prime = False
 break
 if prime:
 seed.append(next)
 return seed

# results:
"""
 >>> pseed.findPrime2(30)
[1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
 >>>
"""
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: returning none when it should be returning a list?

2006-04-30 Thread Edward Elliott
[EMAIL PROTECTED] wrote:
> The function basically takes in a list of all the prime number found,
> it takes the next number to be tested for (next) and the limit it will
> go up to. It divide next by the list of previous prime numbers if next
> is not bigger than lim, count up all the times where it's not evenly
> divdided, if the result is equal the length of prime number, then we
> have another prime number, lather rinse and repeat :)

Your basic algorithm as described above sounds workable, but can be made
more efficient (I didn't look closely at your code for bugs).  I won't even
go near the complicated number theory algorithms.

1. integer mod will be faster than floating point mod (unless you're getting
into numbers too large to store efficiently as ints, but you'll probably
run into other limitations before you get near that point in this code).

2. you can stop as soon as you find a zero remainder, no need to keep
testing the rest of the primes in the list.

3. you can stop testing numbers at the halfway point.  there are no primes
smaller than 2, so no number x can have a factor larger than x/2.

4. in fact you can do even better.  a simple proof by contradiction shows
that if primes 1..y don't divide x and y^2 > x then x must be prime.  put
another way, once you test up to the square root of x, there's no point
continuing.  if one factor were bigger than sqrt(x), the other would have
to be smaller than sqrt(x).  but you've already tested the factors smaller
than sqrt(x), so there can't be any factors.

5. you can do better than checking every odd number (next+2) to find the
next prime, but I'm too tired to look into it right now.  it may require
more complex machinery.

Locating primes is an interesting challenge because of the seemingly endless
grades of refinements over simple brute-force search.  Like I said though,
if speed and size aren't concerns, your algorithm is fine.

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