Re: makepy.py not working

2008-04-08 Thread Gabriel Genellina
En Tue, 08 Apr 2008 10:18:48 -0300, <[EMAIL PROTECTED]> escribió:

> I've a problem getting makepy running. When I start the tool on my
> machine with doubleclick everything is fine.
> But when I try this in my Code:
>
> makepy.py -i "Microsoft Excel 11.0 Object Library(1.5)"

The above is supposed to be executed as a command, in a CMD console. It's  
not pyton code.

> I am getting an Syntax Error and command:
>
> makepy.py
>
> bring me this message on the screen:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'makepy' is not defined

Same as above: makepy.py is a filename, not a Python expression.

> Any ideas what I am doing wrong?

What do you actually want to do?
The documentation for makepy and win32com.client.gencache is in the  
pywin32 help files, section Quick-Starts to Python and COM.

-- 
Gabriel Genellina

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


Re: text adventure game problem

2008-04-08 Thread Carl Banks
On Apr 9, 1:24 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Tue, 8 Apr 2008 18:01:01 -0700 (PDT), [EMAIL PROTECTED]
> declaimed the following in comp.lang.python:
>
> > okay, I'm having this one problem with a text adventure game. It's
> > kind of hard to explain, but I'll do my best.
> > [code]
>
> > def prompt_kitchen():
> > global gold
> > gold_taken = False
> > while True:
> > prompt_kit = raw_input('>')
> > if prompt_kit == 'examine cabinet 1' and not gold_taken:
> > print '''This cabinet has a lot of cups in it with all
> > different
> > designs and shapes. Where are the people anyway? How come there's
> > nobody here?
> > In one of the cups you find 8 gold.'''
>
> Forgive me, but Ugh!
>
> It looks like you are defining a function for each possible room
> which incorporates code for the actions possible in that room...
>
> I suspect I'd try to create a generic room class which has as
> attributes a dictionary of actions and a dictionary of movable objects.
> Along with methods that work on objects... Working an action that digs
> into other objects may take some doing.
[snip]


I don't know about you, but I usually start with specific cases like
this and then generalize them.  This could be a baby step, or merely a
first stage of evolution.


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


Re: Cannot understand the detailedly the following code

2008-04-08 Thread Gabriel Genellina
En Tue, 08 Apr 2008 09:45:35 -0300, A.T.Hofkamp <[EMAIL PROTECTED]>  
escribió:

> On 2008-04-08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> [deleted a long piece of text by our BDFL about recursive graph  
> path-finding algorithm]
>
>> after first writing the inductive part ... for node in
>> graph[start] 
>> and then by trial and error put square brackets around path in the
>> Basis part. Can someone please explain how to write this code. Thanks!
>
> The same as any other function.
> (the trick with recursive functions is not to think about recursion.  
> Instead,
> pretend you are calling another function that happens to have the same  
> name.)

But our BDFL played some tricks to make both functions look more similar  
than they would instead. Take the "single path" variant:

 def find_path(graph, start, end, path=[]):
 path = path + [start]
 if start == end:
 return path
 if not graph.has_key(start):
 return None
 for node in graph[start]:
 if node not in path:
 newpath = find_path(graph, node, end, path)
 if newpath: return newpath
 return None

Why are those "return None" there, if not to be replaced by "return []"?  
Nobody writes that final one at least. Anyway, using the current Python  
version, it's easier to mutate the above function into a generator of all  
posible solutions; I hope the OP finds the mutation easier to follow:

def find_all_paths(graph, start, end, path=[]):
 path = path + [start]
 if start == end:
 yield path
 return
 if start not in graph:
 return
 for node in graph[start]:
 if node not in path:
 for newpath in find_all_paths(graph, node, end, path):
 yield newpath

The last two lines might be replaced in Python 3 by:
yield *find_all_paths
if this patch is accepted: http://bugs.python.org/issue2292

-- 
Gabriel Genellina

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


Can C.L.P.handle the load?

2008-04-08 Thread Paddy
On Apr 8, 7:51 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
> It's wonderful news for Python. It will definitely be a boost for
> Python's (and Django's) popularity. Python finally seems to be on
> every developers mind at the moment. Looks like it's showtime for
> Python!

I'm waiting for the rush of new users to c.l.p :-)
If it comes, then aren't regularly posted FAQ's newbie friendly?
Is their a good FAQ already around that we can regularly point newbies
to?

What else could we do to make c.l.p. of more use to the newbie whp may
also be new to usenet whilst keeping c.l.p a usefull place for all?

- Paddy.

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


Re: Setting default version among multiple python installations

2008-04-08 Thread Karthik

Gabriel Genellina wrote:
En Tue, 08 Apr 2008 06:48:54 -0300, Karthik <[EMAIL PROTECTED]>  
escribió:


  

I am an absolute linux and python newbie. The linux machine(red hat
version 7.2) that i managed to get my hands on had python 1.5(vintage
stuff, i guess) in it. I have installed python 2.5 using the source tar.
However, when i try to access python, i am taken to the older version  
only.



Have you actually compiled and installed it?
See http://docs.python.org/dev/using/index.html

  
Yes, i got the source from 
http://python.org/ftp/python/2.5.2/Python-2.5.2.tgz


if i type python2.5 i am able to use the latest python, but if i simply 
type python it taken me to the older version. (it is a minor annoyance, 
but I want to know how to fix it)


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

pprint module and newer standard types

2008-04-08 Thread Paddy
Hi,
When  I try and use pprint on standard types I get varying 'quality of
output'.

Lists will wrap nicely to multiple lines as will dicts, but sets and
defaultdicts give one long unreadable line.
Is their a chance to get this changed so that more built-in types look
pretty when printed with pprint?

I just did a small trial on an early version of Python 3 and sets
don't seem to obey pprint.pprints width argument, the same way that
lists do:

Python 3.0a1 (py3k:57844, Aug 31 2007, 16:54:27) [MSC v.1310 32 bit
(Intel)] on win32
>>> from pprint import pprint as pp
>>> pp(list(range(3)), width=4)
[0,
 1,
 2]
>>> pp(set(range(3)), width=4)
{0, 1, 2}
>>>


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


Re: Setting default version among multiple python installations

2008-04-08 Thread Gabriel Genellina
En Tue, 08 Apr 2008 06:48:54 -0300, Karthik <[EMAIL PROTECTED]>  
escribió:

> I am an absolute linux and python newbie. The linux machine(red hat
> version 7.2) that i managed to get my hands on had python 1.5(vintage
> stuff, i guess) in it. I have installed python 2.5 using the source tar.
> However, when i try to access python, i am taken to the older version  
> only.

Have you actually compiled and installed it?
See http://docs.python.org/dev/using/index.html

-- 
Gabriel Genellina

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


Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-08 Thread Gabriel Genellina
2008/4/8, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>> I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
>>  1310 32 bit (Intel)] on win32 with IDLE 1.2.1
>>  My O/S is Windows XP SP2 I use 512 MB RAM.

En Tue, 08 Apr 2008 06:02:00 -0300, Vladimir Kropylev  
<[EMAIL PROTECTED]> escribió:

> yes, ths is known problem. I can just recomend you to use Linux or
> FreeBSD, though cygwin maybe also possible

Disregard that comment.

-- 
Gabriel Genellina

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


Can't figure out traceback: (error_proto(-ERR EOF) line 121 poplib.py

2008-04-08 Thread erikcw
Hi,

I keep getting this error from poplib:
(error_proto(-ERR EOF) line 121 poplib.py

Does this mean the connection has timed out?  What can I do to deal
with it?

Thanks!
Erik
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String Literal to Blob

2008-04-08 Thread Gabriel Genellina
En Tue, 08 Apr 2008 13:55:07 -0300, Victor Subervi  
<[EMAIL PROTECTED]> escribió:

> Thanks. I apparently am printing some holder for the image. I stripped  
> out
> most of it with this
> content[0][0]

Yes, because of this:
   content = cursor.fetchall()
fetchall returns a list of rows, each row a tuple of columns.

> but then I am left with this:
>
> array('c', '\xff\xd8\xff\xe0\\0\x10JFI...)
> How do I extract an image from that?

print content.tostring()
Or perhaps, replace that line with content.tofile(sys.stdout)

http://docs.python.org/lib/module-array.html

>> > #  print 'Content-Type: image/jpeg\r\nContent-Length: %d\n' %
>> len(content)

Once you fix the former, you can re-enable that line.

>> >   print 'Content-Type: image/jpeg\r\n'
>> >   print '\n'
>> >   print content
>> >   print '\n'
>> >   cursor.close()
>> >
>> > test()

>> > The commented out line gives me a leading less than sign...and that´s
>> > it. What do?

Try to understand now *why* you got a single character with your previous  
code.

-- 
Gabriel Genellina

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

Re: Sorting a List of Objects by an Attribute of the Objects Case-Insensitively

2008-04-08 Thread Paddy
On Apr 9, 4:04 am, Jason <[EMAIL PROTECTED]> wrote:
> Hi folks--
>
> Basically, I have a pressing need for a combination of 5.2 "Sorting a
> List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
> by an Attribute of the Objects" from the Python Cookbook.
>
> My first guess isn't working:
>
> import operator
> def sort_by_attr(seq, attr):
>  key=operator.attrgetter(attr)
>  key=str.lower
>  return sorted(seq, key)
>
> ...would much appreciate any guidance!

HiJason,
Try  key= lambda x: x.attr.lower()
The above should calculate the key only once for the items to be
sorted rather than using cmp which calculates more than that.

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


Re: __init__.py file

2008-04-08 Thread Gabriel Genellina
En Tue, 08 Apr 2008 17:51:21 -0300, cesco <[EMAIL PROTECTED]>  
escribió:

> I need to instantiate an object (my_object) whose methods I have to
> use in two files (file1.py and file2.py) which are in the same
> directory. Is it possible to instantiate such object in the
> __init__.py file and then directly use it in file1.py and file2.py?
> If not, as I seem to experience, what is the best practice to follow
> in this case? (I thought __init__.py was somehow useful for that).

Yes, you can, but consider passing the object as an argument. Global  
objects aren't necesarily evil, anyway I don't have enough information to  
make an opinion.

If you insist on use the global object, there is another question.  
__init__.py defines the package namespace, and is the public interfase to  
it, I would not put an object there that is not supposed to be part of the  
package public interfase. You can instantiate the object in any other  
module, and import such module from both file1 and file2.

-- 
Gabriel Genellina

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


Re: style question - hasattr

2008-04-08 Thread Miles
On Tue, Apr 8, 2008 at 10:21 PM, ian <[EMAIL PROTECTED]> wrote:
>  Ok, so what about 'hasattr'  ??
> hasattr(myObject,'property')
>  seems equivalent to
> 'property' in dir(myObject)
>
>  I would suggest that using the 'in' is cleaner in this case also. Is
>  there a performance penalty here? Or is there reason why the two are
>  not actually the same?

>>> class HasAll(object):
... def __getattr__(self, name): pass
...
>>> hasattr(HasAll(), 'spam')
True
>>> 'spam' in dir(HasAll())
False

>From the docs:  "Because dir() is supplied primarily as a convenience
for use at an interactive prompt, it tries to supply an interesting
set of names more than it tries to supply a rigorously or consistently
defined set of names, and its detailed behavior may change across
releases.  ... [hasattr] is implemented by calling getattr(object,
name) and seeing whether it raises an exception or not."
http://docs.python.org/lib/built-in-funcs.html

> Which style is preferred??

Don't test for the existence of the attribute if you're going to get
it when it exists; just go ahead and get it.

try:
x = myObject.property
except AttributeError:
x = None

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


Re: Converting a tuple to a list

2008-04-08 Thread David Harrison
On 09/04/2008, Gabriel Ibanez <[EMAIL PROTECTED]> wrote:
> Hi all ..
>
>  I'm trying to using the map function to convert a tuple to a list, without
>  success.
>
>  I would like to have a lonely line that performs the same as loop of the
>  next script:
>
>  ---
>  # Conveting tuple -> list
>
>  tupla = ((1,2), (3,4), (5,6))
>
>  print tupla
>
>  lista = []
>  for a in tupla:
> for b in a:
> lista.append(b)
>  print lista
>  ---
>
>  Any idea ?
>
>  Thanks ...
>
>  # Gabriel

Not sure if you were looking for a method that retained the existing
nested structure or not, so the following is a recursive way of
turning an arbitrarily nested tuple structure into the list based
equivalent:

a = ((1,2), (3,4), (5,6), (7,(8,9)))

def t2l(a):
lst = []
for item in a:
if type(item) == tuple:
lst.append(t2l(item))
else:
lst.append(item)
return lst

print t2l(a)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a tuple to a list

2008-04-08 Thread CM
On Apr 8, 6:46 pm, "Gabriel Ibanez" <[EMAIL PROTECTED]> wrote:
> Gabriel Ibanez wrote:
> > Hi all ..
>
> > I'm trying to using the map function to convert a tuple to a list, without
> > success.
>
> > I would like to have a lonely line that performs the same as loop of the
> > next script:
>
> > ---
> > # Conveting tuple -> list
>
> > tupla = ((1,2), (3,4), (5,6))
>
> > print tupla
>
> > lista = []
> > for a in tupla:
> > for b in a:
> > lista.append(b)
> > print lista
> > ---
>
> > Any idea ?
>
> > Thanks ...
>
> > # Gabriel
>
> list(tupla)
>
> would probably do it.
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>
> --http://mail.python.org/mailman/listinfo/python-list
>
> That would just make a list of tuples, I think he wants [1, 2, 3, 4, 5, 6].
>
> Try:  l = [x for z in t for x in z]
>
> --Brian
>
> ---
>
> Thanks Steve and Brian,
>
> Brian: that is !!
>
> However, it's a bit difficult to understand now. I have read it several
> times :)

Doing it this way is called a "list comprehension", which means you
put the formula inside the brackets and that new list will be built
with the formula.  This one is also easier to understand if you
substitute more meaningful names than l, x,t,z...like so:

newlist = [number for subtuple in fulltuple for number in subtuple]

or, writing it in the typical for loop way (not using the list
comprehension shortcut):

for subtuple in fulltuple:
for number in subtuple:
newlist.append(number)

but the list comprehension doesn't need the append part, it is built
in.  They're handy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text adventure game problem

2008-04-08 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| In the above function, there's the option to examine a cabinet and get
| 8 gold. (everyone here knows that...but I'm just trying to state my
| problem...)
| Unfortunately, it kind of doesn't work.
| After the first time I 'examine cabinet 1' in my game, I get 8 gold
| and I can't get it again.
| But, If I leave the room and come back to it, then it's as if I had
| never gotten the gold the first time, and I can get it again.
| How do I fix this?

I would define a container class.  The init function gives it a name and 
contents (8 gold, for instance).  Give kitchen a container('cabinet', 8).
Give containers a .examine() method which gives the contents to the player.
and a message which varies with the contents.  You can even make some 
container 'refreshable' if you want.

tjr



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


Re: style question - hasattr

2008-04-08 Thread Terry Reedy

"ian" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| In old python code i would use 'has_key' to determine if an element
| was present in a dictionary.
|
| Python 3.0 will even removed 'has_key'. The reason for removal is that
| using the 'in' operator is a cleaner syntax and having two ways to
| achieve the same result is against the principle of the language.
|
| Ok, so what about 'hasattr'  ??
|hasattr(myObject,'property')
| seems equivalent to
|'property' in dir(myObject)
|
| I would suggest that using the 'in' is cleaner in this case also. Is
| there a performance penalty here?

Yes, the construction of the dir.
And I think there may be slight differences between the two.

tjr



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


gen_py target directory for makepy

2008-04-08 Thread Alan Meyer
I had an unusual problem tonight running makepy to install some
Microsoft COM interfaces in a Python 2.5 Windows XP installation
created using the ActiveState installer.

In earlier versions of Python, the files were generated to:

   \PythonXX\Lib\site-packages\win32com\gen_py

But in my 2.5 installation they were generated to my temp
directory, in my case this was:

  c:\temp\gen_py\2.5

I hadn't paid attention to the messages and when I cleared my
temp directory, which I occasionally do, the COM interfaces
stopped working.

Tracing through the makepy code, I found the following
(reformatted for email) in

\Python25\Lib\site-packages\win32com\__init__.py

if not __gen_path__:
  try:
import win32com.gen_py
__gen_path__ = sys.modules["win32com.gen_py"].__path__[0]
  except ImportError:
# If a win32com\gen_py directory already exists, then we use it
# (gencache doesn't insist it have an __init__, but our
# __import__ above does!
__gen_path__ = \
 os.path.abspath(os.path.join(__path__[0], "gen_py"))
if not os.path.isdir(__gen_path__):
  # We used to dynamically create a directory under win32com -
  # but this sucks.  If the dir doesn't already exist, we we
  # create a version specific directory under the user temp
  # directory.
  __gen_path__ = os.path.join(
win32api.GetTempPath(), "gen_py",
"%d.%d" % (sys.version_info[0],
sys.version_info[1]))

I was able to make everything work right by creating the gen_py
directory in the expected place and re-running makepy.  But I'm
curious to know:

 1. Why does it suck to create gen_py dynamically?

 2. Why didn't I have a gen_py directory already?  Did I somehow
destory it or is it not created by default?

 3. Why is the temp directory the alternate choice for where to
put these?

Thanks.

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


Re: Sorting a List of Objects by an Attribute of the Objects Case-Insensitively

2008-04-08 Thread Jason
On Apr 8, 8:26 pm, "David Harrison" <[EMAIL PROTECTED]> wrote:
> On 09/04/2008, Jason <[EMAIL PROTECTED]> wrote:
>
> > Hi folks--
>
> >  Basically, I have a pressing need for a combination of 5.2 "Sorting a
> >  List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
> >  by an Attribute of the Objects" from the Python Cookbook.
>
> >  My first guess isn't working:
>
> >  import operator
> >  def sort_by_attr(seq, attr):
> >  key=operator.attrgetter(attr)
> >  key=str.lower
> >  return sorted(seq, key)
>
> >  ...would much appreciate any guidance!
>
> You're probably looking for the built-in function sorted,
>
> e.g.
>
> class Foo:
> def __init__(self, value):
> self.value = value
>
> def __repr__(self):
> return self.value
>
> a = [Foo('c'), Foo('B'), Foo('A')]
>
> print sorted(
> a,
> cmp=lambda x,y: cmp(x.lower(), y.lower()),
> key=lambda x: x.value
> )

Hey-- thanks!

I actually figured out something that works quite nicely since I
posted:

def sort_by_attr_case_insensitive(seq, attr):
return sorted(seq, cmp=lambda x,y: cmp(x.lower(), y.lower()),
key=operator.attrgetter(attr))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a List of Objects by an Attribute of the Objects Case-Insensitively

2008-04-08 Thread David Harrison
On 09/04/2008, Jason <[EMAIL PROTECTED]> wrote:
> Hi folks--
>
>  Basically, I have a pressing need for a combination of 5.2 "Sorting a
>  List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
>  by an Attribute of the Objects" from the Python Cookbook.
>
>  My first guess isn't working:
>
>  import operator
>  def sort_by_attr(seq, attr):
>  key=operator.attrgetter(attr)
>  key=str.lower
>  return sorted(seq, key)
>
>  ...would much appreciate any guidance!

You're probably looking for the built-in function sorted,

e.g.

class Foo:
def __init__(self, value):
self.value = value

def __repr__(self):
return self.value

a = [Foo('c'), Foo('B'), Foo('A')]

print sorted(
a,
cmp=lambda x,y: cmp(x.lower(), y.lower()),
key=lambda x: x.value
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google App Engine

2008-04-08 Thread Jason Scheirer
On Apr 8, 7:50 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> Duncan Booth wrote:
> > Google have announced a new service called 'Google App Engine' which may
> > be of interest to some of the people here
>
> OK, now we need a compatibility layer so you can move apps from
> Google App Engine to your own servers.  You don't want to be locked
> into a single vendor solution, especially when they reserve the right
> to start charging.
>
> Their data store uses a subset of SQL, so it's probably possible
> to write a conversion layer allowing use of MySQL.
>
> John Nagle

It supports Django, and more importantly, WSGI, so any 'framework' you
build on top of it should transfer out. Heck, you have a stand-alone
python script that comes with the developer kit for hosting your apps
on YOUR computer that you could port to use YOUR database and be done
with it. Write your own ORM or just some decent OO code for handling
data access so the database access layer can be swapped out and you
are golden. I really doubt getting away from the Googe App Engine is
going to be too terribly difficult for any intermediate Python
programmer, assuming good up-front application design.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Google App Engine

2008-04-08 Thread Trent Nelson

> But people will always prefer complaining on the grounds of
> insufficient information to keeping quiet on the basis of knowledge.

+1 QOTW!

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


Sorting a List of Objects by an Attribute of the Objects Case-Insensitively

2008-04-08 Thread Jason
Hi folks--

Basically, I have a pressing need for a combination of 5.2 "Sorting a
List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
by an Attribute of the Objects" from the Python Cookbook.

My first guess isn't working:

import operator
def sort_by_attr(seq, attr):
 key=operator.attrgetter(attr)
 key=str.lower
 return sorted(seq, key)

...would much appreciate any guidance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google App Engine

2008-04-08 Thread John Nagle
Duncan Booth wrote:
> Google have announced a new service called 'Google App Engine' which may 
> be of interest to some of the people here 

OK, now we need a compatibility layer so you can move apps from
Google App Engine to your own servers.  You don't want to be locked
into a single vendor solution, especially when they reserve the right
to start charging.

Their data store uses a subset of SQL, so it's probably possible
to write a conversion layer allowing use of MySQL.

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


Re: import statement convention

2008-04-08 Thread Steve Holden
Ben Finney wrote:
> [EMAIL PROTECTED] writes:
> 
>> By convention, I've read, your module begins with its import
>> statements. Is this always sensible?
> 
> There are exceptions, but the benefits are great: It's very easy to
> see what this module requires, without needing to execute it.
> 
>> I put imports that are needed for testing in the test code at the
>> end of the module. If only a bit of the module has a visual
>> interface, why pollute the global namespace with 'from Tkinter
>> import *'? Wouldn't that be better done in a separate class or
>> function?
> 
> If your test code requires the Tkinter module but the rest of the code
> doesn't, why pollute the functional module with such test code? Move
> it to a separate unit test module.
> 
If your test code is the only part of the module that needs Tkinter I'd 
be perfectly happy seeing the import guarded by the if __name__ == 
"__main__" condition.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


python-com and vista

2008-04-08 Thread sniffer
hi all,

the problem i am facing is as follows:-
i have created a com component in python this registers and works fine
on winxp and stuff but on vista i need to turn off user account
control to get the component registered and every time i need to use
the component i again have to turn it UAC off if it is on, but this
component needs to be deployed on the end-users machine and so this
exercise of turning on/off UAC cannot be carried out there .
Any pointers on how to get this resolved ?

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


style question - hasattr

2008-04-08 Thread ian
In old python code i would use 'has_key' to determine if an element
was present in a dictionary.

Python 3.0 will even removed 'has_key'. The reason for removal is that
using the 'in' operator is a cleaner syntax and having two ways to
achieve the same result is against the principle of the language.

Ok, so what about 'hasattr'  ??
hasattr(myObject,'property')
seems equivalent to
'property' in dir(myObject)

I would suggest that using the 'in' is cleaner in this case also. Is
there a performance penalty here? Or is there reason why the two are
not actually the same?

Which style is preferred??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new user needs help!

2008-04-08 Thread Steve Holden
drjekil (or should that be mrhyde?):

Once again, *please* make sure you reply to the list. Personal replies 
are much less likely to get attention.

regards
  Steve

drjekil sayer wrote:
> u got it!
> thats what i am trying to explain with my bad english!
> thanks once again.
> 
> 
> On 4/9/08, *Steve Holden* <[EMAIL PROTECTED] 
> > wrote:
> 
> [EMAIL PROTECTED]  wrote:
> 
> thanks!
> 
> 
> Please keep all replies on the list: somebody else may also wish to
> help (and they will also pick up mistakes I make ;-)
> 
> I am working with a text filelooks like this:
> #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> 1lghB A i 79.8 H H -24.58
> 1lghB V i 79.6 H H -22.06
> 1lghB H i 71.9 H H -19.94
> i need to compare those lines which has a value between 10 to 22
> and presents in the following way
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here
> alfabets represents amino acids)
> 1 1:1 2:0 3:0 and so on for rest of the amino acids.
> 
> 
> I have given 2 examples below to make it clear a bit:
> 
> ex.1:
> #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> 1lghB A i 79.8 H H  -24.58  
> #for that line amino acid is A and z-COORED
> value is more than 22,so output should be look like
> 
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here
> alfabets represents amino acids)
> -1 1:1 2:0 3:o 4:0 so on upto 20 bcz there r 20 amino acids.and
> A presents in the 1st position.every line represents one amino
> acid with value,so output will show in which position is it(here
> A is in 1st position thats why its value 1:1 and all the other
> position o like 2:0,3:0,4:0 and if its Z-COORED value between
> 10-22 then true false value 1,otherwise -1.
> 
> another ex:
> 
> 1lghB H i 71.9 H H -19.94# for that line amino acid
> is H and it has value between 10-22.so output should looks like:
> 
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here
> alfabets represents 20 amino acids)
> 
> 1 1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0,every position is zero up to
> 20 bcz H presents in the 7th position.so  it will be 1.
> 
> so for every line, output will in 21 coulum,1st coulum for true
> false value,others r for 20 amino acids.true false value will be
> either 1 or -1,and  within  other 20 coulum one value will be
> n:1,others will be n:0.n=0,1,2,3..20.
> its a bit tricky.
> thank u so much for ur help
> waiting for ur opinion.
>  
> 
> So, you are using -1 for true and 1 for false? Can there be multiple
> amino acids on each line?
> 
> Would this be a possible input:
> 
> 1lghB AHG i 87.3 Q Q   -23.45
> 
> If so, would this be the required output?
> 
> -1 1:1 2:0 3:0 4:0 5:0 6:0 7:1 8:1 9:0 10:0 ... 19:0 20:0
> 
> There is no point trying to write more code until we understand the
> requirements properly.
> 
> regards
>  Steve
> -- 
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
> 
> 


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new user needs help!

2008-04-08 Thread drjekil

u got it!
thats the thing i am trying to explain by  my bad english!
thanks for the help.
-- 
View this message in context: 
http://www.nabble.com/new--user-needs-help%21-tp16571823p16578029.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: text adventure game problem

2008-04-08 Thread corvettecraz92
On Apr 8, 9:55 pm, André <[EMAIL PROTECTED]> wrote:
> On Apr 8, 10:44 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > On Apr 8, 9:25 pm, André <[EMAIL PROTECTED]> wrote:
>
> > > On Apr 8, 10:01 pm, [EMAIL PROTECTED] wrote:
>
> > > > okay, I'm having this one problem with a text adventure game. It's
> > > > kind of hard to explain, but I'll do my best.
> > > > [code]
>
> > > > def prompt_kitchen():
> > > >     global gold
> > > >     gold_taken = False
> > > >     while True:
> > > >         prompt_kit = raw_input('>')
> > > >         if prompt_kit == 'examine cabinet 1' and not gold_taken:
> > > >             print '''This cabinet has a lot of cups in it with all
> > > > different
> > > > designs and shapes. Where are the people anyway? How come there's
> > > > nobody here?
> > > > In one of the cups you find 8 gold.'''
> > > >             gold = gold+8
> > > >             gold_taken = True
> > > >             pass4()
> > > >         elif prompt_kit == 'examine cabinet 1' and gold_taken:
> > > >             print \
> > > >                   '''This cabinet has a lot of cups in it with all
> > > > different
> > > > designs and shapes. Where are the people anyway? How come there's
> > > > nobody here?'''
> > > >             pass4()
>
> > > > def pass4():
> > > >     global gold
> > > >     print 'You have', gold, 'gold'
> > > >     pass
> > > > [/code]
>
> > > > Okay, now for my problem.
> > > > In the above function, there's the option to examine a cabinet and get
> > > > 8 gold. (everyone here knows that...but I'm just trying to state my
> > > > problem...)
> > > > Unfortunately, it kind of doesn't work.
> > > > After the first time I 'examine cabinet 1' in my game, I get 8 gold
> > > > and I can't get it again.
> > > > But, If I leave the room and come back to it, then it's as if I had
> > > > never gotten the gold the first time, and I can get it again.
> > > > How do I fix this?
>
> > > quick guess: define gold_taken as a global variable and initialize it
> > > outside of the function.
>
> > > Warning: avoid global variables if at all possible.
>
> > > ;-)
> > > André
>
> > Here's a sample code that, in fact, does work. In this code, when run,
> > I can only get the gold once.
>
> > def prompt_house():
> >     global gold
> >     gold_taken = False
> >     while True:
> >         prompt_hou = raw_input('>')
> >         if prompt_hou == 'examine table' and not gold_taken:
> >             print \
> >                   '''There are a lot of car magazines here.
> > You flip through them and find 5 gold.
> > '''
> >             gold = gold+5
> >             gold_taken = True
> >         elif prompt_hou == 'go west':
> >             # this gets you out of the loop
>
> The above comment is wrong.
>
> >             go_west()
> >             # more elif choices here ...
> >         elif prompt_hou == 'examine table' and gold_taken:
> >             print '''There are a lot of car magazines here.'''
> >             go_west()
> > def go_west():
> > # just a dummy funk
> >     global gold
> >     print gold
> >     pass
>
> The "pass" statement is redundant.
>
> >                 # test
> > gold = 0
> > prompt_house()
>
> > But what's the difference between this and the one that I posted?
>
> It is hard to say as you are not posting the entire code.  As I
> indicated above, you wrote a comment indicating that a given choice
> was taking you out of the loop - which could only happen through a
> break statement.  You may want to post a ("small") code sample that
> can be run by itself and reproduces the problem behaviour you
> observe.  The sample you posted include infinite loops with no way to
> get out, so your original claim that you could leave the room and come
> back is highly suspicious ;-)
>
> André

Here ya go...this is an excerpt from my main code, with an example
room added on.
gold = 0
def kitchen():
print 'you have', gold, 'gold'
print '''You are in the kitchen of the house. There is a lot of
cooking
equipment here, along with 3 cabinets, a food pantry, and a drawer. At
the far end of the
room is an icebox and a stove. To the south there is a living room,
and to
the east is a den.'''
print
prompt_kitchen()
def prompt_kitchen():
global gold
gold_taken = False
while True:
prompt_kit = raw_input('>')
if prompt_kit == 'examine cabinet 1' and not gold_taken:
print '''This cabinet has a lot of cups in it with all
different
designs and shapes. Where are the people anyway? How come there's
nobody here?
In one of the cups you find 8 gold.'''
gold = gold+8
gold_taken = True
pass4()
elif prompt_kit == 'examine cabinet 1' and gold_taken:
print \
  '''This cabinet has a lot of cups in it with all
different
designs and shapes. Where are the people anyway? How come there's
nobody here?'''
pass4()

elif prompt_kit == 'south':
extra_room()

def extra_room():
print 'you

Re: text adventure game problem

2008-04-08 Thread André
On Apr 8, 10:44 pm, [EMAIL PROTECTED] wrote:
> On Apr 8, 9:25 pm, André <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Apr 8, 10:01 pm, [EMAIL PROTECTED] wrote:
>
> > > okay, I'm having this one problem with a text adventure game. It's
> > > kind of hard to explain, but I'll do my best.
> > > [code]
>
> > > def prompt_kitchen():
> > >     global gold
> > >     gold_taken = False
> > >     while True:
> > >         prompt_kit = raw_input('>')
> > >         if prompt_kit == 'examine cabinet 1' and not gold_taken:
> > >             print '''This cabinet has a lot of cups in it with all
> > > different
> > > designs and shapes. Where are the people anyway? How come there's
> > > nobody here?
> > > In one of the cups you find 8 gold.'''
> > >             gold = gold+8
> > >             gold_taken = True
> > >             pass4()
> > >         elif prompt_kit == 'examine cabinet 1' and gold_taken:
> > >             print \
> > >                   '''This cabinet has a lot of cups in it with all
> > > different
> > > designs and shapes. Where are the people anyway? How come there's
> > > nobody here?'''
> > >             pass4()
>
> > > def pass4():
> > >     global gold
> > >     print 'You have', gold, 'gold'
> > >     pass
> > > [/code]
>
> > > Okay, now for my problem.
> > > In the above function, there's the option to examine a cabinet and get
> > > 8 gold. (everyone here knows that...but I'm just trying to state my
> > > problem...)
> > > Unfortunately, it kind of doesn't work.
> > > After the first time I 'examine cabinet 1' in my game, I get 8 gold
> > > and I can't get it again.
> > > But, If I leave the room and come back to it, then it's as if I had
> > > never gotten the gold the first time, and I can get it again.
> > > How do I fix this?
>
> > quick guess: define gold_taken as a global variable and initialize it
> > outside of the function.
>
> > Warning: avoid global variables if at all possible.
>
> > ;-)
> > André
>
> Here's a sample code that, in fact, does work. In this code, when run,
> I can only get the gold once.
>
> def prompt_house():
>     global gold
>     gold_taken = False
>     while True:
>         prompt_hou = raw_input('>')
>         if prompt_hou == 'examine table' and not gold_taken:
>             print \
>                   '''There are a lot of car magazines here.
> You flip through them and find 5 gold.
> '''
>             gold = gold+5
>             gold_taken = True
>         elif prompt_hou == 'go west':
>             # this gets you out of the loop


The above comment is wrong.

>             go_west()
>             # more elif choices here ...
>         elif prompt_hou == 'examine table' and gold_taken:
>             print '''There are a lot of car magazines here.'''
>             go_west()
> def go_west():
> # just a dummy funk
>     global gold
>     print gold
>     pass

The "pass" statement is redundant.

>                 # test
> gold = 0
> prompt_house()
>
> But what's the difference between this and the one that I posted?

It is hard to say as you are not posting the entire code.  As I
indicated above, you wrote a comment indicating that a given choice
was taking you out of the loop - which could only happen through a
break statement.  You may want to post a ("small") code sample that
can be run by itself and reproduces the problem behaviour you
observe.  The sample you posted include infinite loops with no way to
get out, so your original claim that you could leave the room and come
back is highly suspicious ;-)

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


Re: Python Leopard DLL Hell

2008-04-08 Thread Michael Torrie
Brian Cole wrote:
> That appears to be working correctly at first glance. The argument to
> dlopen is the correct shared library. Unfortunately, either python or
> OS X is lying to me here. If I inspect the python process with OS X's
> Activity Monitor and look at the "Open Files and Ports" tab, it shows
> that the _foo.so shared library is actually the one located inside
> $DYLD_LIBRARY_PATH.
> 
> So this problem may not be python's, but I place it here as a first
> shot (maybe I'm using the imp module incorrectly).

Sounds like you're going to need to learn how to use dtrace.  Then you
can more closely monitor exactly what python and the loader are doing.
dtrace is very complicated (borrowed from Solaris) but extremely
powerful.  Worth learning anyway, but sounds like it's probably the
debugging tool you need.

Another thing you can do is check through the python source code and see
how the os x-specific code is handling this type of situation.

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


Re: text adventure game problem

2008-04-08 Thread corvettecraz92
On Apr 8, 9:25 pm, André <[EMAIL PROTECTED]> wrote:
> On Apr 8, 10:01 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > okay, I'm having this one problem with a text adventure game. It's
> > kind of hard to explain, but I'll do my best.
> > [code]
>
> > def prompt_kitchen():
> >     global gold
> >     gold_taken = False
> >     while True:
> >         prompt_kit = raw_input('>')
> >         if prompt_kit == 'examine cabinet 1' and not gold_taken:
> >             print '''This cabinet has a lot of cups in it with all
> > different
> > designs and shapes. Where are the people anyway? How come there's
> > nobody here?
> > In one of the cups you find 8 gold.'''
> >             gold = gold+8
> >             gold_taken = True
> >             pass4()
> >         elif prompt_kit == 'examine cabinet 1' and gold_taken:
> >             print \
> >                   '''This cabinet has a lot of cups in it with all
> > different
> > designs and shapes. Where are the people anyway? How come there's
> > nobody here?'''
> >             pass4()
>
> > def pass4():
> >     global gold
> >     print 'You have', gold, 'gold'
> >     pass
> > [/code]
>
> > Okay, now for my problem.
> > In the above function, there's the option to examine a cabinet and get
> > 8 gold. (everyone here knows that...but I'm just trying to state my
> > problem...)
> > Unfortunately, it kind of doesn't work.
> > After the first time I 'examine cabinet 1' in my game, I get 8 gold
> > and I can't get it again.
> > But, If I leave the room and come back to it, then it's as if I had
> > never gotten the gold the first time, and I can get it again.
> > How do I fix this?
>
> quick guess: define gold_taken as a global variable and initialize it
> outside of the function.
>
> Warning: avoid global variables if at all possible.
>
> ;-)
> André

Here's a sample code that, in fact, does work. In this code, when run,
I can only get the gold once.

def prompt_house():
global gold
gold_taken = False
while True:
prompt_hou = raw_input('>')
if prompt_hou == 'examine table' and not gold_taken:
print \
  '''There are a lot of car magazines here.
You flip through them and find 5 gold.
'''
gold = gold+5
gold_taken = True
elif prompt_hou == 'go west':
# this gets you out of the loop
go_west()
# more elif choices here ...
elif prompt_hou == 'examine table' and gold_taken:
print '''There are a lot of car magazines here.'''
go_west()
def go_west():
# just a dummy funk
global gold
print gold
pass
# test
gold = 0
prompt_house()

But what's the difference between this and the one that I posted?

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


Re: text adventure game problem

2008-04-08 Thread André
On Apr 8, 10:25 pm, André <[EMAIL PROTECTED]> wrote:
> On Apr 8, 10:01 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > okay, I'm having this one problem with a text adventure game. It's
> > kind of hard to explain, but I'll do my best.
> > [code]
>
> > def prompt_kitchen():
> >     global gold
> >     gold_taken = False
> >     while True:
> >         prompt_kit = raw_input('>')
> >         if prompt_kit == 'examine cabinet 1' and not gold_taken:
> >             print '''This cabinet has a lot of cups in it with all
> > different
> > designs and shapes. Where are the people anyway? How come there's
> > nobody here?
> > In one of the cups you find 8 gold.'''
> >             gold = gold+8
> >             gold_taken = True
> >             pass4()
> >         elif prompt_kit == 'examine cabinet 1' and gold_taken:
> >             print \
> >                   '''This cabinet has a lot of cups in it with all
> > different
> > designs and shapes. Where are the people anyway? How come there's
> > nobody here?'''
> >             pass4()
>
> > def pass4():
> >     global gold
> >     print 'You have', gold, 'gold'
> >     pass
> > [/code]
>
> > Okay, now for my problem.
> > In the above function, there's the option to examine a cabinet and get
> > 8 gold. (everyone here knows that...but I'm just trying to state my
> > problem...)
> > Unfortunately, it kind of doesn't work.
> > After the first time I 'examine cabinet 1' in my game, I get 8 gold
> > and I can't get it again.
> > But, If I leave the room and come back to it, then it's as if I had
> > never gotten the gold the first time, and I can get it again.
> > How do I fix this?
>
> quick guess: define gold_taken as a global variable and initialize it
> outside of the function.
>
> Warning: avoid global variables if at all possible.
>
> ;-)
> André

Actually, what I would do if I were designing such a game is probably
define an object with various states, so that instead of gold_taken,
I'd have
state.gold_taken_in_cabinet_1

Alternatively, you could define a dict at the beginning with things
like
gold_taken = {'cabinet 1': False,
  'cabinet 2': False, ...}

This approach would allow to identify at a glance all relevant game
situations rather than having to go through the entire code.

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


Re: text adventure game problem

2008-04-08 Thread André
On Apr 8, 10:01 pm, [EMAIL PROTECTED] wrote:
> okay, I'm having this one problem with a text adventure game. It's
> kind of hard to explain, but I'll do my best.
> [code]
>
> def prompt_kitchen():
>     global gold
>     gold_taken = False
>     while True:
>         prompt_kit = raw_input('>')
>         if prompt_kit == 'examine cabinet 1' and not gold_taken:
>             print '''This cabinet has a lot of cups in it with all
> different
> designs and shapes. Where are the people anyway? How come there's
> nobody here?
> In one of the cups you find 8 gold.'''
>             gold = gold+8
>             gold_taken = True
>             pass4()
>         elif prompt_kit == 'examine cabinet 1' and gold_taken:
>             print \
>                   '''This cabinet has a lot of cups in it with all
> different
> designs and shapes. Where are the people anyway? How come there's
> nobody here?'''
>             pass4()
>
> def pass4():
>     global gold
>     print 'You have', gold, 'gold'
>     pass
> [/code]
>
> Okay, now for my problem.
> In the above function, there's the option to examine a cabinet and get
> 8 gold. (everyone here knows that...but I'm just trying to state my
> problem...)
> Unfortunately, it kind of doesn't work.
> After the first time I 'examine cabinet 1' in my game, I get 8 gold
> and I can't get it again.
> But, If I leave the room and come back to it, then it's as if I had
> never gotten the gold the first time, and I can get it again.
> How do I fix this?

quick guess: define gold_taken as a global variable and initialize it
outside of the function.

Warning: avoid global variables if at all possible.

;-)
André
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text adventure game problem

2008-04-08 Thread Dan Bishop
On Apr 8, 8:01 pm, [EMAIL PROTECTED] wrote:
> okay, I'm having this one problem with a text adventure game. It's
> kind of hard to explain, but I'll do my best.
> [code]
>
> def prompt_kitchen():
> global gold
> gold_taken = False
> while True:
> prompt_kit = raw_input('>')
> if prompt_kit == 'examine cabinet 1' and not gold_taken:
> print '''This cabinet has a lot of cups in it with all
> different
> designs and shapes. Where are the people anyway? How come there's
> nobody here?
> In one of the cups you find 8 gold.'''
> gold = gold+8
> gold_taken = True
> pass4()
> elif prompt_kit == 'examine cabinet 1' and gold_taken:
> print \
>   '''This cabinet has a lot of cups in it with all
> different
> designs and shapes. Where are the people anyway? How come there's
> nobody here?'''
> pass4()
>
> def pass4():
> global gold
> print 'You have', gold, 'gold'
> pass
> [/code]
>
> Okay, now for my problem.
> In the above function, there's the option to examine a cabinet and get
> 8 gold. (everyone here knows that...but I'm just trying to state my
> problem...)
> Unfortunately, it kind of doesn't work.
> After the first time I 'examine cabinet 1' in my game, I get 8 gold
> and I can't get it again.
> But, If I leave the room and come back to it, then it's as if I had
> never gotten the gold the first time, and I can get it again.

That's because your function starts with "gold_taken = False".

The easiest fix is to make gold_taken a global variable initialized
outside the function, like you're already doing with gold.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import statement convention

2008-04-08 Thread Ben Finney
[EMAIL PROTECTED] writes:

> By convention, I've read, your module begins with its import
> statements. Is this always sensible?

There are exceptions, but the benefits are great: It's very easy to
see what this module requires, without needing to execute it.

> I put imports that are needed for testing in the test code at the
> end of the module. If only a bit of the module has a visual
> interface, why pollute the global namespace with 'from Tkinter
> import *'? Wouldn't that be better done in a separate class or
> function?

If your test code requires the Tkinter module but the rest of the code
doesn't, why pollute the functional module with such test code? Move
it to a separate unit test module.

-- 
 \ “Never do anything against conscience even if the state demands |
  `\ it.” —Albert Einstein |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Python Leopard DLL Hell

2008-04-08 Thread Brian Cole
Hello All,

I'm running into a strange problem on Leopard with how Python loads
shared libraries. I'll give you a background of what we are trying to
accomplish before describing the problem. I am not certain whether
this is an OS X problem, or a Python problem, though it appears with
the combination of the two.

We have swig wrapped C++ code. We used to require our users to set
LD_LIBRARY_PATH to the directory containing the dynamic libraries
because the swig generated .so needs to dynamically link in another
.so. The dependency tree looks like the following:

foo.py   <--- performs a "from libs import _foo"
libs/   <--- LD_LIBRARY_PATH required to point here
   | _foo.so
   | bar.so  <-- _foo.so depends on me

The dependency of bar.so can be taken care of by using $ORIGIN with
-rpath (http://linuxreviews.org/man/ld.so/). On Mac OS X this is done
by post-processing the shared library with install_name_tool
(http://lapcatsoftware.com/blog/2007/08/11/embedding-frameworks-in-loadable-bundles/).

Another design goal was to allow for the same directory structure to
be NFS mounted in a heterogeneous environment. Then the magic of
Python can choose the proper .so to load based upon introspection of
the machine architecture and the Python version being used. So the
directory structure becomes:

foo.py <--- performs a "from libs import
GetModule; _foo = GetModule('_foo')"
libs/
   | __init__.py   <--- contains code for GetModule
   | arch-specific-directory/
  | _foo.so
  | bar.so  <--
_foo.so depends on me

The GetModule function defined in libs/__init__.py looks like the following:
DLLS = os.path.join(os.path.basename(__file__),
"arch-specific-directory") <-- determined at runtime based on
platform, compiler, and python version

def GetModule(name):
args = imp.find_module(name, [DLLS])
return imp.load_module(name, *args)

This works great on Linux. LD_LIBRARY_PATH can even be set to a
directory that contains a different (incompatible) _foo.so and python
will force the correct .so to be loaded. However, there is a bug on OS
X Leopard (maybe Tiger too, I haven't tested it).

On OS X, when DYLD_LIBRARY_PATH (the OS X equivalent of
LD_LIBRARY_PATH) is set to a directory that contains an identically
named .so file imp.load_module pulls that .so file in. Even though the
.so has been specified by an absolute filename. Running a simple test
with the -v option of python shows the following:


[EMAIL PROTECTED]/debug/wrappers/python$ ls -1 $DYLD_LIBRARY_PATH
_foo.so
bar.so
[EMAIL PROTECTED]/debug/wrappers/python$ python -vc "import
openeye.oeshape; from time import sleep; sleep(10)"

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
# foo.pyc matches foo.py
import foo # precompiled from foo.pyc
import libs # directory libs
# libs/__init__.pyc matches libs/__init__.py
import libs # precompiled from libs/__init__.pyc
dlopen("/Users/coleb/debug/wrappers/python/openeye/libs/osx-10.5-g++4.0-x86+x64-python2.5/_foo.so",
2);  <--- This is the correct .so!
import _foo # dynamically loaded from
/Users/coleb/debug/wrappers/python/openeye/libs/osx-10.5-g++4.0-x86+x64-python2.5/_foo.so


That appears to be working correctly at first glance. The argument to
dlopen is the correct shared library. Unfortunately, either python or
OS X is lying to me here. If I inspect the python process with OS X's
Activity Monitor and look at the "Open Files and Ports" tab, it shows
that the _foo.so shared library is actually the one located inside
$DYLD_LIBRARY_PATH.

So this problem may not be python's, but I place it here as a first
shot (maybe I'm using the imp module incorrectly).

Thanks,
Brian
-- 
http://mail.python.org/mailman/listinfo/python-list


text adventure game problem

2008-04-08 Thread corvettecraz92
okay, I'm having this one problem with a text adventure game. It's
kind of hard to explain, but I'll do my best.
[code]

def prompt_kitchen():
global gold
gold_taken = False
while True:
prompt_kit = raw_input('>')
if prompt_kit == 'examine cabinet 1' and not gold_taken:
print '''This cabinet has a lot of cups in it with all
different
designs and shapes. Where are the people anyway? How come there's
nobody here?
In one of the cups you find 8 gold.'''
gold = gold+8
gold_taken = True
pass4()
elif prompt_kit == 'examine cabinet 1' and gold_taken:
print \
  '''This cabinet has a lot of cups in it with all
different
designs and shapes. Where are the people anyway? How come there's
nobody here?'''
pass4()

def pass4():
global gold
print 'You have', gold, 'gold'
pass
[/code]

Okay, now for my problem.
In the above function, there's the option to examine a cabinet and get
8 gold. (everyone here knows that...but I'm just trying to state my
problem...)
Unfortunately, it kind of doesn't work.
After the first time I 'examine cabinet 1' in my game, I get 8 gold
and I can't get it again.
But, If I leave the room and come back to it, then it's as if I had
never gotten the gold the first time, and I can get it again.
How do I fix this?
-- 
http://mail.python.org/mailman/listinfo/python-list


problem using import from PyRun_String

2008-04-08 Thread Patrick Stinson
I'm creating a module with PyModule_New(), and running a string buffer as
the module's text using PyRun_String and passing the module's __dict__ to
locals and globals. I'm having a problem using the import statement from
within PyRun_String(). It complains about "__import__ not found", which
after a quick grep it looks like the exception is raised from
PyExc_EvalFrameEx() in ceval.c after f->f_builtins module doesn't contain
"__import__".
What __builtin__ module does that point to? a quick print of the content of
__builtin__ in CPython code shows a function for the "__import__" key, and I
manually added all of the contents of __builtin__ to the module's dict,
which was empty before.

Any help?

Cheers

-- 
Patrick Kidd Stinson
http://www.patrickkidd.com/
http://pkaudio.sourceforge.net/
http://pksampler.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: new user needs help!

2008-04-08 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> thanks!

Please keep all replies on the list: somebody else may also wish to help 
(and they will also pick up mistakes I make ;-)

> I am working with a text filelooks like this:
> #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> 1lghB A i 79.8 H H -24.58
> 1lghB V i 79.6 H H -22.06
> 1lghB H i 71.9 H H -19.94
> i need to compare those lines which has a value between 10 to 22 and presents 
> in the following way
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets represents 
> amino acids)
> 1 1:1 2:0 3:0 and so on for rest of the amino acids.
> 
> 
> I have given 2 examples below to make it clear a bit:
> 
> ex.1:
> #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> 1lghB A i 79.8 H H  -24.58
>#for that line amino acid is A and z-COORED value is more than 22,so 
> output should be look like
> 
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets represents 
> amino acids)
> -1 1:1 2:0 3:o 4:0 so on upto 20 bcz there r 20 amino acids.and A presents in 
> the 1st position.every line represents one amino acid with value,so output 
> will show in which position is it(here A is in 1st position thats why its 
> value 1:1 and all the other position o like 2:0,3:0,4:0 and if its Z-COORED 
> value between 10-22 then true false value 1,otherwise -1.
> 
> another ex:
> 
> 1lghB H i 71.9 H H -19.94# for that line amino acid is H and it 
> has value between 10-22.so output should looks like:
> 
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets represents 
> 20 amino acids)
> 
> 1 1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0,every position is zero up to 20 bcz H 
> presents in the 7th position.so  it will be 1.
> 
> so for every line, output will in 21 coulum,1st coulum for true false 
> value,others r for 20 amino acids.true false value will be either 1 or -1,and 
>  within  other 20 coulum one value will be n:1,others will be 
> n:0.n=0,1,2,3..20.
> its a bit tricky.
> thank u so much for ur help
> waiting for ur opinion.
>  
So, you are using -1 for true and 1 for false? Can there be multiple 
amino acids on each line?

Would this be a possible input:

1lghB AHG i 87.3 Q Q   -23.45

If so, would this be the required output?

-1 1:1 2:0 3:0 4:0 5:0 6:0 7:1 8:1 9:0 10:0 ... 19:0 20:0

There is no point trying to write more code until we understand the 
requirements properly.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling variable function name ?

2008-04-08 Thread George Sakkis
On Apr 8, 3:52 pm, TkNeo <[EMAIL PROTECTED]> wrote:
> I don't know the exact terminology in python, but this is something i
> am trying to do
>
> i have 3 functions lets say
> FA(param1,param2)
> FB(param1,param2)
> FC(param1,param2)
>
> temp = "B" #something entered by user. now i want to call FB. I don't
> want to do an if else because if have way too many methods like
> this...
>
> var = "F" + temp
> var(param1, param2)

Try this:

func = globals()["F" + temp]
func(param1, param2)

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


How would I go about checking if urllib2 timed out?

2008-04-08 Thread Lamonte Harris
Can someone explain to me how I would do error handling to check if the
current proxy timed out on when trying to connect to the web page:

import urllib2
proxy=urllib2.ProxyHandler({'http':'24.232.167.22:80'})
opener=urllib2.build_opener(proxy)
f=opener.open('http://www.whatismyipaddress.com'
)
print f.read()

If someone could help me, thank you very much, I'm still very new to error
handling
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Converting a tuple to a list

2008-04-08 Thread Shane Geiger
from goopy.functional import *

tupla = ((1,2), (3,4), (5,6))

print flatten(tupla)




Gabriel Ibanez wrote:
> Hi all ..
>
> I'm trying to using the map function to convert a tuple to a list, without 
> success.
>
> I would like to have a lonely line that performs the same as loop of the 
> next script:
>
> ---
> # Conveting tuple -> list
>
> tupla = ((1,2), (3,4), (5,6))
>
> print tupla
>
> lista = []
> for a in tupla:
> for b in a:
> lista.append(b)
> print lista
> ---
>
> Any idea ?
>
> Thanks ...
>
> # Gabriel
>
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

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


Ctypes and C Infinite Callback Loops

2008-04-08 Thread Thomas Dimson
Hello,

I have quite a complex issue that is arising with regards to using
ctypes to hook into some legacy code. The legacy code is in infinite
loop - I can not touch this. It does some listening, and periodically
calls a specific callback function.

What I would like to be able to do is spawn a Python thread to handle
this infinite loop, and continue on my merry way. This works to an
extent, however if I try to raise the SystemExit exception (or any
other one) inside of this thread I get an error message of
"AssertionError: cannot join current thread".

I assume there is some issue with the global interpreter lock or that
you can't exit the infinite loop from above Python. Any suggestions on
how I can design this so the thread will be able to issue exits/raise
exceptions just like a regular thread? Is there a way of terminating
this thread from the python interpreter or ctypes.pythonapi?

I have also tried being sneaky by using a pthread in the C code, but I
had issues when I tried to create a new thread state using
ctypes.pythonapi (well, I had issues swapping it in when I get to the
callback). If this is the best solution, how do I create/swap in the
thread state from ctypes?

For some cooked up sample code that simulates this:

main.c (main.o -> main.so )
#include 
void loop( void (*callback)() )
{
while( 1 )
{
callback();
sleep(1);
}
}

void testLoop( void (*callback)() )
{
loop( callback );
}



test.py:
import threading,ctypes,time,sys,os

soPath = os.path.join( "/home/tdimson/ctypes/main.so" )

class callLoop( threading.Thread ):
def callback( self ):
sys.exit()

def run( self ):
ctypes.cdll.LoadLibrary( soPath )
mainLib = ctypes.CDLL( soPath )
_callback =  ctypes.CFUNCTYPE( None )( self.callback )

mainLib.testLoop( _callback )

loopThread = callLoop()
loopThread.start()

while 1:
print "Not blocking"
time.sleep(10)



Then I execute: python test.py and get
Not blocking
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.4/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "/usr/lib/python2.4/threading.py", line 634, in __exitfunc
t.join()
  File "/usr/lib/python2.4/threading.py", line 532, in join
assert self is not currentThread(), "cannot join current thread"
AssertionError: cannot join current thread
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.4/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "/usr/lib/python2.4/threading.py", line 634, in __exitfunc
t.join()
  File "/usr/lib/python2.4/threading.py", line 532, in join
assert self is not currentThread(), "cannot join current thread"
AssertionError: cannot join current thread


Thanks for even reading this much :)

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


Re: Converting a tuple to a list

2008-04-08 Thread John Krukoff

On Wed, 2008-04-09 at 00:46 +0200, Gabriel Ibanez wrote:
> Gabriel Ibanez wrote:
> > Hi all ..
> >
> > I'm trying to using the map function to convert a tuple to a list, without
> > success.
> >
> > I would like to have a lonely line that performs the same as loop of the
> > next script:
> >
> > ---
> > # Conveting tuple -> list
> >
> > tupla = ((1,2), (3,4), (5,6))
> >
> > print tupla
> >
> > lista = []
> > for a in tupla:
> > for b in a:
> > lista.append(b)
> > print lista
> > ---
> >
> > Any idea ?
> >
> > Thanks ...
> >
> > # Gabriel
> >
> 
> list(tupla)
> 
> would probably do it.
> 
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> 
> That would just make a list of tuples, I think he wants [1, 2, 3, 4, 5, 6].
> 
> Try:  l = [x for z in t for x in z]
> 
> --Brian
> 
> 
> ---
> 
> 
> Thanks Steve and Brian,
> 
> Brian: that is !!
> 
> However, it's a bit difficult to understand now. I have read it several 
> times :)
> 
> 

Another solution using the itertools module:

>>> import itertools
>>> t = ( ( 1, 2 ), ( 3, 4 ), ( 5, 6 ) )
>>> list( itertools.chain( *t ) )
[1, 2, 3, 4, 5, 6]

Though the list part is probably unnecessary for most uses. The problem
gets interesting when you want to recursively flatten an iterable of
arbitratrily deeply nested iterables.

-- 
John Krukoff <[EMAIL PROTECTED]>
Land Title Guarantee Company

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


Re: Converting a tuple to a list

2008-04-08 Thread Brian
On Tue, Apr 8, 2008 at 6:36 PM, Brian <[EMAIL PROTECTED]> wrote:

>
>
> On Tue, Apr 8, 2008 at 6:22 PM, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> > Gabriel Ibanez wrote:
> > > Hi all ..
> > >
> > > I'm trying to using the map function to convert a tuple to a list,
> > without
> > > success.
> > >
> > > I would like to have a lonely line that performs the same as loop of
> > the
> > > next script:
> > >
> > > ---
> > > # Conveting tuple -> list
> > >
> > > tupla = ((1,2), (3,4), (5,6))
> > >
> > > print tupla
> > >
> > > lista = []
> > > for a in tupla:
> > > for b in a:
> > > lista.append(b)
> > > print lista
> > > ---
> > >
> > > Any idea ?
> > >
> > > Thanks ...
> > >
> > > # Gabriel
> > >
> > list(tupla)
> >
> > would probably do it.
> >
> > regards
> >  Steve
> > --
> > Steve Holden+1 571 484 6266   +1 800 494 3119
> > Holden Web LLC  http://www.holdenweb.com/
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
>
> That would just make a list of tuples, I think he wants [1, 2, 3, 4, 5,
> 6].
>
> Try:  l = [x for z in t for x in z]


Edit:  Assuming t is tupla from your code.

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

Re: Converting a tuple to a list

2008-04-08 Thread Gabriel Ibanez
Gabriel Ibanez wrote:
> Hi all ..
>
> I'm trying to using the map function to convert a tuple to a list, without
> success.
>
> I would like to have a lonely line that performs the same as loop of the
> next script:
>
> ---
> # Conveting tuple -> list
>
> tupla = ((1,2), (3,4), (5,6))
>
> print tupla
>
> lista = []
> for a in tupla:
> for b in a:
> lista.append(b)
> print lista
> ---
>
> Any idea ?
>
> Thanks ...
>
> # Gabriel
>

list(tupla)

would probably do it.

regards
 Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/


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




That would just make a list of tuples, I think he wants [1, 2, 3, 4, 5, 6].

Try:  l = [x for z in t for x in z]

--Brian


---


Thanks Steve and Brian,

Brian: that is !!

However, it's a bit difficult to understand now. I have read it several 
times :)


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


Re: Converting a tuple to a list

2008-04-08 Thread Brian
On Tue, Apr 8, 2008 at 6:22 PM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Gabriel Ibanez wrote:
> > Hi all ..
> >
> > I'm trying to using the map function to convert a tuple to a list,
> without
> > success.
> >
> > I would like to have a lonely line that performs the same as loop of the
> > next script:
> >
> > ---
> > # Conveting tuple -> list
> >
> > tupla = ((1,2), (3,4), (5,6))
> >
> > print tupla
> >
> > lista = []
> > for a in tupla:
> > for b in a:
> > lista.append(b)
> > print lista
> > ---
> >
> > Any idea ?
> >
> > Thanks ...
> >
> > # Gabriel
> >
> list(tupla)
>
> would probably do it.
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



That would just make a list of tuples, I think he wants [1, 2, 3, 4, 5, 6].

Try:  l = [x for z in t for x in z]

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

Re: Data structure recommendation?

2008-04-08 Thread bearophileHUGS
More bits from your code:

neighbours = list()
==>
neighbours = []

If you have a recent enough version of Python you can use:
candidate_is_neighbour = any(distance < n[1] for n in neighbours)
Instead of:
candidate_is_neighbour = bool([1 for n in neighbours if distance <
n[1]])

It's shorter & simpler, and it stops as soon as it finds a true
condition.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a tuple to a list

2008-04-08 Thread Steve Holden
Gabriel Ibanez wrote:
> Hi all ..
> 
> I'm trying to using the map function to convert a tuple to a list, without 
> success.
> 
> I would like to have a lonely line that performs the same as loop of the 
> next script:
> 
> ---
> # Conveting tuple -> list
> 
> tupla = ((1,2), (3,4), (5,6))
> 
> print tupla
> 
> lista = []
> for a in tupla:
> for b in a:
> lista.append(b)
> print lista
> ---
> 
> Any idea ?
> 
> Thanks ...
> 
> # Gabriel
> 
list(tupla)

would probably do it.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: makepy.py not working

2008-04-08 Thread Konstantin Veretennicov
On Tue, Apr 8, 2008 at 4:18 PM,  <[EMAIL PROTECTED]> wrote:
> Hallo,
>
>  I've a problem getting makepy running. When I start the tool on my
>  machine with doubleclick everything is fine.
>  But when I try this in my Code:
>
>  makepy.py -i "Microsoft Excel 11.0 Object Library(1.5)"

This syntax is used to run makepy.py script from command line.

>
>  I am getting an Syntax Error and command:
>
>  makepy.py
>
>  bring me this message on the screen:
>
>  Traceback (most recent call last):
>   File "", line 1, in 
>  NameError: name 'makepy' is not defined
>
>  Any ideas what I am doing wrong?

Python interpreter obviously accepts only valid python code, like this:

import win32com.client.makepy
win32com.client.makepy.ShowInfo("Microsoft Excel 11.0 Object Library(1.5)")

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


Re: Data structure recommendation?

2008-04-08 Thread bearophileHUGS
Few more notes on the code:

You may use the @property in such situations (or you may just use
attributes, dropping the property). Note that Python doesn't inline
functions calls like Java HotSpot does quite often.
def __children(self):
raise NotImplementedError()
children = property(__children)
==> (not tested!)
@property
def __children(self):
raise NotImplementedError()


If the profiling shows this is s slow, and it's used on lot of items,
there are faster O(1) algorithms for this, like this one:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466330
@staticmethod
def determine_median(numbers):
return sorted(numbers)[ len(numbers) / 2  ]

I have seen you use lot of double underscores (I think one may often
suffice, but usually two aren't a problem):
def __children(self):

Stripped of comments, docstrings, and empty lines the code is just 280
lines long (it's 1498 with them!), so a translation doesn't seem too
much work (expecially if the original version was Java). The code seem
really well commented, organized, etc. And I like it, it looks better
than 90+% of the commercial Python code I see :-)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting a tuple to a list

2008-04-08 Thread Gabriel Ibanez
Hi all ..

I'm trying to using the map function to convert a tuple to a list, without 
success.

I would like to have a lonely line that performs the same as loop of the 
next script:

---
# Conveting tuple -> list

tupla = ((1,2), (3,4), (5,6))

print tupla

lista = []
for a in tupla:
for b in a:
lista.append(b)
print lista
---

Any idea ?

Thanks ...

# Gabriel

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


Re: Python 3.0 new integer division

2008-04-08 Thread Jonathan Gardner
On Apr 8, 2:25 pm, Grzegorz Słodkowicz <[EMAIL PROTECTED]> wrote:
>
> Isn't Decimal a BCD implementation?

Yep, you are right and I am wrong. 
http://www.python.org/dev/peps/pep-0327/#why-not-rational


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


Re: Best way to check if string is an integer?

2008-04-08 Thread Steve Holden
Martin Marcher wrote:
> hmmm
> 
> int() does miss some stuff:
> 
 1E+1
> 10.0
 int("1E+1")
> Traceback (most recent call last):
>   File "", line 1, in 
> ValueError: invalid literal for int() with base 10: '1E+1'
> 
> I wonder how you parse this?
> 
> I honestly thought until right now int() would understand that and
> wanted to show that case as ease of use, I was wrong, so how do you
> actually cast this type of input to an integer?
> 
> thanks
> martin
> 
> 
int(float("1E+1")) # untested

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: CPython VM & byte code resources wanted

2008-04-08 Thread Steve Holden
Aaron Gray wrote:
> "Aaron Gray" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Hi,
>>
>> I am looking to study the CPython source code, but I cannot seem to find 
>> the VM code.
> 
> Found it :)
> 
> Python/ceval.c
> 
>> Also is there any where a detailed  list of the opcodes ?
> 
> Still could do with an opcodes chart.
> 
Be sure and post it on the Wiki when you finish it ;-)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: new user needs help!

2008-04-08 Thread Steve Holden
Tim Chase wrote:
>> f = open("/tmp/data.txt", 'w')
>>
>> will open that file.
>>
>> You can throw the first line away with
>>
>> headings = f.next()
>>
>> Then you can loop over the rest with
>>
>> for name, aa, topo, access, dssp, stride, z in file:
>>  #
>>  # Then process each line here
> 
> 
> Small caveat here...Steve changed file-variables on you here, and 
> assumed a tuple-unpacking that won't work.  You'll want something like
> 
>   for line in f:
> (name, aa, topo, access, dssp, stride, z) = (
> line.rstrip('\n').split('\t')
> # process the line here
> 
> I don't know how your fields are delimited, whether by spaces or tabs.  
> In the above code, I split by tabs, but you can just use .split() if it 
> should be split on any white-space.  It's a bit more complex if you need 
> to split by column-offsets.
> 
Hmm, perhaps I shoudl wait until I get my brain fixed before I post 
again! Sorry, Tim, I got distracted and shouldn't have tried to dash off 
the post before coping with the distraction. Just a minor flood in the 
basement ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 new integer division

2008-04-08 Thread Grzegorz Słodkowicz

> If you want precision with fractions, you should be using the Decimal
> type, which uses a rational. A rational, if you recall from your math
> classes, is one integer divided by another.
>   

Isn't Decimal a BCD implementation?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a python code periodically

2008-04-08 Thread Mike Driscoll
On Apr 8, 3:01 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> paul wrote:
> > Maryam Saeedi schrieb:
> >> Hi,
>
> >> I was wondering if you know how can I run a python code once every five
> >> minutes for a period of time either using python or some other program
> >> like
> >> a bash script.
>
> > See the sched module in the standard library or here:
> >http://pypi.python.org/simple/Recur/
>
> > cheers
> >  Paul
>
> You could use cron also.
>
> -Larry

And if you're on Windows, you can use the Scheduled Task Manager.

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


Re: __init__.py file

2008-04-08 Thread Steven W. Orr
On Tuesday, Apr 8th 2008 at 16:51 -, quoth cesco:

=>Hi,
=>
=>I need to instantiate an object (my_object) whose methods I have to
=>use in two files (file1.py and file2.py) which are in the same
=>directory. Is it possible to instantiate such object in the
=>__init__.py file and then directly use it in file1.py and file2.py?
=>If not, as I seem to experience, what is the best practice to follow
=>in this case? (I thought __init__.py was somehow useful for that).

Sounds more like a job for a singleton. I recently found one that I like a 
lot better than the standard recipe:

class Singleton(object):
__single = None # the one, true Singleton
  
def __new__(classtype, *args, **kwargs):
if classtype != type(classtype.__single): 
classtype.__single = object.__new__(classtype, *args, **kwargs)
return classtype.__single
  
def __init__(self,name=None):
"""Arg doesn't have to be str."""
self.name = name

def display(self):
print self.name,id(self),type(self)

The advantage of this one is that it can be nicely subclassed.

if __name__ == "__main__":
  
class SubSingleton(Singleton):
def __init__(self, name=None):
Singleton.__init__(self, name)
self.aa = 123
self.bb = 456
self.cc = 789

o1 = Singleton('foo')
o1.display()
o2 = Singleton('bar')
o2.display()
o3 = SubSingleton('foobar')
o3.display()
o4 = SubSingleton('barfoo')
o4.display()
print 'o1 = o2:',o1 == o2
print 'o1 = o3:',o1 == o3
print 'o3 = o4:',o3 == o4

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython VM & byte code resources wanted

2008-04-08 Thread Aaron Gray
>Bytecodes:
>http://docs.python.org/lib/bytecodes.html
>
>VM:
>Python/ceval.c

Thanks,

Aaron



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


Re: Translating keywords

2008-04-08 Thread Lie
On Apr 7, 9:54 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Ronn Ross wrote:
> > This is my first post and I'm new to Python. How would someone go about
> > adding keywords to Python? It would be great to add support for
> > Esperanto keywords in the language instead of English being the only
> > option.
>
> Unfortunately the resulting language would no longer be Python.
>
> You need to consider software portability: Python has been very
> conservative about declaring words to be "keywords" in the language,
> though clearly words like "def" and "class" must necessarily be part of
> the syntax.
>
> When you start to replace the keywords, though, your programs are no
> longer runnable on all Python installations, and simple transliteration
> fails because sometimes a keyword in one (natural) language will
> conflict with a programmer's choice of name(s) in another.

I think it might be possible to create a translation table, where this
native-language code would be accompanied by an extra file that maps
the replaced keywords with Python keywords. And before the code is
compiled, it's preprocessed to map the native-language keywords to
Python keyword. But I think if such feature is made available, it
would crack the language into lots of sub-languages and that would
make code exchange hard, and it wouldn't be long before people start
being creative and added language support for languages like Klingon
or Pig Latin.

On Apr 8, 12:47 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Apr 8, 3:47 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>
> > Python 3 allows for unicode identifiers, but I don'k know any plans for  
> > using unicode keywords too. Looks funny:
>
> > ∀ x ∈ values:
> >    if x ∉ forbidden ∧ x ≠ y:
> >      print(x, Γ(x), √(x))
> > print(∑(values))
> > near = λ a,b,ε=0.01: a-ε ≤ b ≤ a+ε
>
> It's all in the eye of the beholder: to me it looks readable, but
> that's because I've spent 10 years of my life reading and writing
> stuff like that.  Although I would use ∀ and ∃ as aliases for all()
> and exists() :)
>
> --
> Arnaud

It looks readable to a mathematician, but not to a regular person or
even a regular programmer not specializing in mathematics. And the
single downside why I think using symbols is bad is because you can't
Google with those. And if you don't know Greek (or whatever language
the symbol comes from), you can't even name the symbol to search for
the meaning.
-- 
http://mail.python.org/mailman/listinfo/python-list

__init__.py file

2008-04-08 Thread cesco
Hi,

I need to instantiate an object (my_object) whose methods I have to
use in two files (file1.py and file2.py) which are in the same
directory. Is it possible to instantiate such object in the
__init__.py file and then directly use it in file1.py and file2.py?
If not, as I seem to experience, what is the best practice to follow
in this case? (I thought __init__.py was somehow useful for that).

Many thanks
Francesco
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new user needs help!

2008-04-08 Thread Tim Chase
> f = open("/tmp/data.txt", 'w')
> 
> will open that file.
> 
> You can throw the first line away with
> 
> headings = f.next()
> 
> Then you can loop over the rest with
> 
> for name, aa, topo, access, dssp, stride, z in file:
>  #
>  # Then process each line here


Small caveat here...Steve changed file-variables on you here, and 
assumed a tuple-unpacking that won't work.  You'll want something 
like

   for line in f:
 (name, aa, topo, access, dssp, stride, z) = (
line.rstrip('\n').split('\t')
 # process the line here

I don't know how your fields are delimited, whether by spaces or 
tabs.  In the above code, I split by tabs, but you can just use 
.split() if it should be split on any white-space.  It's a bit 
more complex if you need to split by column-offsets.

-tkc


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


RE: Best way to check if string is an integer?

2008-04-08 Thread Stephen Cattaneo
1E+1 is short hand for a floating point number, not an interger.
>>> float("1E+1")
10.0

You could convert the float to an integer if you wanted (i.e. ceiling,
floor, rounding, truncating, etc.).

Cheers,

Steve

-Original Message-
From: Martin Marcher [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 08, 2008 1:32 PM
To: python-list@python.org
Subject: Re: Best way to check if string is an integer?

hmmm

int() does miss some stuff:

>>> 1E+1
10.0
>>> int("1E+1")
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid literal for int() with base 10: '1E+1'

I wonder how you parse this?

I honestly thought until right now int() would understand that and
wanted to show that case as ease of use, I was wrong, so how do you
actually cast this type of input to an integer?

thanks
martin


-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: new user needs help!

2008-04-08 Thread Mike Driscoll
On Apr 8, 3:38 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> drjekil wrote:
> > I am totally new in biopython and its my first program.so may be i am asking
> > stupid question.
>
> New? Most questions are sensible.
>
> Let's suppose that the four lines you give below are stored in a text
> file called "/tmp/data.txt".
>
> > I am working with a text filelooks like this:
> > #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> > 1lghB A i 79.8 H H -24.58
> > 1lghB V i 79.6 H H -22.06
> > 1lghB H i 71.9 H H -19.94
>
> f = open("/tmp/data.txt", 'w')
>
> will open that file.


Don't do that! You will overwrite the original!


>
> You can throw the first line away with
>
> headings = f.next()


I forgot to throw away the first line in my code though...so mine has
errors too.



>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/

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


Re: new user needs help!

2008-04-08 Thread Mike Driscoll
On Apr 8, 2:55 pm, drjekil <[EMAIL PROTECTED]> wrote:
> I am totally new in biopython and its my first program.so may be i am asking
> stupid question.
> I am working with a text filelooks like this:
> #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> 1lghB A i 79.8 H H -24.58
> 1lghB V i 79.6 H H -22.06
> 1lghB H i 71.9 H H -19.94
> i need to compare those lines which has a Z-COORED value between 10 to 22
> and presents in the following way
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets
> represents amino acids)
> 1 1:1 2:0 3:0 and so on for rest of the amino acids.
> IF PRESENT IN THAT RANGE
> IF not PRESENT IN THAT RANGE then
> -1 1:0 2:0 so on,it should be 1 instead of 0 when it will find corresponding
> amino acid for that line.say here,for 2nd line it will be 16:1.
> true will represent 1,false -1.
> i have to cheek all the lins in the file and print it.
> u have to tell simply otherwise i cant understand even,so stupid am i!
> I will be really greatful!Thanks in advance
> --
> View this message in 
> context:http://www.nabble.com/new--user-needs-help%21-tp16571823p16571823.html
> Sent from the Python - python-list mailing list archive at Nabble.com.

To read the file, do something like this:



f = open('path/to/filename')
for line in f.readlines():
# do something
print line



See http://docs.python.org/lib/bltin-file-objects.html for more
information.

You'll want to look at using "if" statements to do the various
conditions and you'll probably need to use string slicing/splitting to
get the correct part of the line to do the comparison.

So, something like



f = open('path/to/filename')
for line in f.readlines():
parts = line.split()
zcoord = parts[-1]
if zcoord > 10 and zcoord < 22:
   # do something
   pass
print line



Resources:

http://docs.python.org/ref/if.html
http://www.ibiblio.org/g2swap/byteofpython/read/if-statement.html
http://docs.python.org/lib/string-methods.html
http://www.diveintopython.org/native_data_types/joining_lists.html

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


Re: Coping with cyclic imports

2008-04-08 Thread Jeffrey Froman
Torsten Bronger wrote:

> I know that cyclic imports work in Python under certain
> circumstances.  Can anyone refer me to a page which explains when
> this works?

I don't know of a specific URL offhand.

Cyclic imports are not a problem by themselves, but cyclic definitions are.
Thus:

# a.py
import b
x = 1

# b.py
import a
x = 2

works fine, but:

# a.py
import b
x = 1

# b.py
import a
x = a.x + 1  # circular definition

does not.


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

Re: CPython VM & byte code resources wanted

2008-04-08 Thread Aaron Gray
"Aaron Gray" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>
> I am looking to study the CPython source code, but I cannot seem to find 
> the VM code.

Found it :)

Python/ceval.c

> Also is there any where a detailed  list of the opcodes ?

Still could do with an opcodes chart.

Thanks,

Aaron


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


Re: new user needs help!

2008-04-08 Thread Steve Holden
drjekil wrote:
> I am totally new in biopython and its my first program.so may be i am asking
> stupid question.

New? Most questions are sensible.

Let's suppose that the four lines you give below are stored in a text 
file called "/tmp/data.txt".

> I am working with a text filelooks like this:
> #NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
> 1lghB A i 79.8 H H -24.58
> 1lghB V i 79.6 H H -22.06
> 1lghB H i 71.9 H H -19.94

f = open("/tmp/data.txt", 'w')

will open that file.

You can throw the first line away with

headings = f.next()

Then you can loop over the rest with

for name, aa, topo, access, dssp, stride, z in file:
 #
 # Then process each line here
 #
 if 10.0 <= z <= 22.0:
 #
 # select on other criteria here
 #

> i need to compare those lines which has a Z-COORED value between 10 to 22
> and presents in the following way
> True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets
> represents amino acids)
> 1 1:1 2:0 3:0 and so on for rest of the amino acids.
> IF PRESENT IN THAT RANGE
> IF not PRESENT IN THAT RANGE then
> -1 1:0 2:0 so on,it should be 1 instead of 0 when it will find corresponding
> amino acid for that line.say here,for 2nd line it will be 16:1.
> true will represent 1,false -1.

I am afraid I am having trouble understanding that last bit. Perhaps you 
could find some other way to say the same thing? Sometimes my 
understanding is not too good.

> i have to cheek all the lins in the file and print it.
> u have to tell simply otherwise i cant understand even,so stupid am i!

"Poor at English" != "Stupid"

> I will be really greatful!Thanks in advance

That's the first step. Now, what's next?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


RE: Running a python code periodically

2008-04-08 Thread Stephen Cattaneo
If your on a *NIX just use cron.  

Execute 'crontab -e'  

edit the file as desired and save

 

see man crontab for formatting.

 

Cheers,

 

Steve

 



From: Maryam Saeedi [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 08, 2008 10:54 AM
To: python-list@python.org
Subject: Running a python code periodically

 

Hi,

 

I was wondering if you know how can I run a python code once every five
minutes for a period of time either using python or some other program
like a bash script.

 

Thanks,

 

Maryam


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

Re: CPython VM & byte code resources wanted

2008-04-08 Thread Arnaud Delobelle
On Apr 8, 9:29 pm, "Aaron Gray" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am looking to study the CPython source code, but I cannot seem to find the
> VM code.
> Also is there any where a detailed  list of the opcodes ?
>
> Many thanks in advance,
>
> Aaron

Bytecodes:
http://docs.python.org/lib/bytecodes.html

VM:
Python/ceval.c

HTH

--
Arnaud

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


Re: Best way to check if string is an integer?

2008-04-08 Thread Martin Marcher
arg, as posted earlier:

int("10.0") fails, it will of course work with float("1E+1") sorry for
the noise...

On Tue, Apr 8, 2008 at 10:32 PM, Martin Marcher <[EMAIL PROTECTED]> wrote:
> hmmm
>
>  int() does miss some stuff:
>
>  >>> 1E+1
>  10.0
>  >>> int("1E+1")
>  Traceback (most recent call last):
>   File "", line 1, in 
>  ValueError: invalid literal for int() with base 10: '1E+1'
>
>  I wonder how you parse this?
>
>  I honestly thought until right now int() would understand that and
>  wanted to show that case as ease of use, I was wrong, so how do you
>  actually cast this type of input to an integer?
>
>  thanks
>  martin
>
>
>  --
>  http://tumblr.marcher.name
>  https://twitter.com/MartinMarcher
>  http://www.xing.com/profile/Martin_Marcher
>  http://www.linkedin.com/in/martinmarcher
>
>  You are not free to read this message,
>  by doing so, you have violated my licence
>  and are required to urinate publicly. Thank you.
>



-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if string is an integer?

2008-04-08 Thread Martin Marcher
hmmm

int() does miss some stuff:

>>> 1E+1
10.0
>>> int("1E+1")
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid literal for int() with base 10: '1E+1'

I wonder how you parse this?

I honestly thought until right now int() would understand that and
wanted to show that case as ease of use, I was wrong, so how do you
actually cast this type of input to an integer?

thanks
martin


-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


CPython VM & byte code resources wanted

2008-04-08 Thread Aaron Gray
Hi,

I am looking to study the CPython source code, but I cannot seem to find the 
VM code.
Also is there any where a detailed  list of the opcodes ?

Many thanks in advance,

Aaron


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


new user needs help!

2008-04-08 Thread drjekil

I am totally new in biopython and its my first program.so may be i am asking
stupid question.
I am working with a text filelooks like this:
#NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
1lghB A i 79.8 H H -24.58
1lghB V i 79.6 H H -22.06
1lghB H i 71.9 H H -19.94
i need to compare those lines which has a Z-COORED value between 10 to 22
and presents in the following way
True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets
represents amino acids)
1 1:1 2:0 3:0 and so on for rest of the amino acids.
IF PRESENT IN THAT RANGE
IF not PRESENT IN THAT RANGE then
-1 1:0 2:0 so on,it should be 1 instead of 0 when it will find corresponding
amino acid for that line.say here,for 2nd line it will be 16:1.
true will represent 1,false -1.
i have to cheek all the lins in the file and print it.
u have to tell simply otherwise i cant understand even,so stupid am i!
I will be really greatful!Thanks in advance
-- 
View this message in context: 
http://www.nabble.com/new--user-needs-help%21-tp16571823p16571823.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


new user needs help!

2008-04-08 Thread drjekil

I am totally new in biopython and its my first program.so may be i am asking
stupid question.
I am working with a text filelooks like this:
#NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
1lghB A i 79.8 H H -24.58
1lghB V i 79.6 H H -22.06
1lghB H i 71.9 H H -19.94
i need to compare those lines which has a value between 10 to 22 and
presents in the following way
True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets
represents amino acids)
1 1:1 2:0 3:0 and so on for rest of the amino acids.
IF PRESENT IN THAT RANGE
IF not PRESENT IN THAT RANGE then
-1 1:0 2:0 so on,it should be 1 instead of 0 when it will find corresponding
amino acid for that line.say here,for 2nd line it will be 16:1.
true will represent 1,false -1.
i have to cheek all the lins in the file and print it.
u have to tell simply otherwise i cant understand even,so stupid am i!
I will be really greatful!Thanks in advance
-- 
View this message in context: 
http://www.nabble.com/new--user-needs-help%21-tp16571784p16571784.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Coping with cyclic imports

2008-04-08 Thread Torsten Bronger
Hallöchen!

I have a rather fat module that represents a document parser --
inline elements, block elements, and the like.  Now I want to split
it into many modules to make everything more manageable.

But at the moment I don't see how to avoid cyclic imports:  A
document element A, which is represented my module parser.A, may
contain the element B, as defined in parser.B.  And vice versa.  So
both modules must import each other, as far as I can see.

I know that cyclic imports work in Python under certain
circumstances.  Can anyone refer me to a page which explains *when*
this works?  Because at least once, the imported module was not
"finished" and thus largely unusual.

Thank you!

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a python code periodically

2008-04-08 Thread Larry Bates
paul wrote:
> Maryam Saeedi schrieb:
>> Hi,
>>
>> I was wondering if you know how can I run a python code once every five
>> minutes for a period of time either using python or some other program 
>> like
>> a bash script.
> 
> See the sched module in the standard library or here:
> http://pypi.python.org/simple/Recur/
> 
> cheers
>  Paul
> 
You could use cron also.

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


Re: calling variable function name ?

2008-04-08 Thread Arnaud Delobelle
On Apr 8, 8:52 pm, TkNeo <[EMAIL PROTECTED]> wrote:
> I don't know the exact terminology in python, but this is something i
> am trying to do
>
> i have 3 functions lets say
> FA(param1,param2)
> FB(param1,param2)
> FC(param1,param2)
>
> temp = "B" #something entered by user. now i want to call FB. I don't
> want to do an if else because if have way too many methods like
> this...
>
> var = "F" + temp
> var(param1, param2)
>
> This does not work ofcourse. Does anyone know how to implement this ?

F = { 'A': FA, 'B':FB, 'C':FC }

F['A'](param1, param2)

HTH

--
Arnaud

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


Re: Reproducing a web page and add own content to it.

2008-04-08 Thread LaundroMat
On Apr 8, 4:11 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> LaundroMat wrote:
> > On Apr 8, 2:04 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> LaundroMat wrote:
> >>> Hi -
> >>> I'm working on a Django powered site where one of the required
> >>> functionalities is the possibility of displaying the content of
> >>> external pages, with an extra banner at the top where specific
> >>> information is displayed. In other words, I'm looking for a way to
> >>> reproduce an existing web page and add some HTML code to it. (I can't
> >>> think of an example right now, but the idea is similar to sites that
> >>> let you see an external page and have some site-specific text above it
> >>> (often stating that the content below is not part of the site the user
> >>> comes from)).
> >>> To test this, I've been downloading an external page, adding some text
> >>> to it and re-opening it in a browser (with the help of built-in
> >>> modules such as urllib2 etc). This works of course, but the external
> >>> page's links such as , or 
> >>> are evidently no longer correct.
> >>> Apart from parsing the whole file and trying to inject the external
> >>> site's domain in links such as the above (with the added inconvenience
> >>> of having to store the external page locally), is there an easier way
> >>> of accomplishing what I want?
> >> Using a frame?
>
> >> Diez
>
> > Ack. I was too focused on importing the external web page and
> > redisplaying the information (I've just been reading up on
> > BeautifulSoup) instead of looking for an HTML based approach.
>
> > Thanks!
>
> You could also look at adding a  tag to your generated page's
>  section.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/

True, but I suppose that users would no longer see the top banner
added by me when they click on one of the links on the external site's
page. I'm a bit hesitant about using frames however, but reading up on
them makes me think the application I have in mind for them might be
the generally accepted exception to the rule that frames are bad :)

Anyway. Thanks for the help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is the Python for statement the same as for each in other languages?

2008-04-08 Thread [EMAIL PROTECTED]
On 8 avr, 19:55, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> jmDesktop schrieb:
>
> > Thank you.  It looks like it is, but I wanted to make sure I
> > understood.  Also, I didn't see a "regular" for loop construct either
> > (i=0;i<=10;i++), etc.  I'm still new at it, but is there one of those?
>
> Yes, it's foreach. And for your usecase, use
>
> for i in xrange(11):
>  ...

Or if you want to both iterate over an iterable and have the 'loop
index', use enumerate:

for index, item in enumerate('this is a test'):
print index, ' : ', item


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


calling variable function name ?

2008-04-08 Thread TkNeo
I don't know the exact terminology in python, but this is something i
am trying to do

i have 3 functions lets say
FA(param1,param2)
FB(param1,param2)
FC(param1,param2)

temp = "B" #something entered by user. now i want to call FB. I don't
want to do an if else because if have way too many methods like
this...

var = "F" + temp
var(param1, param2)

This does not work ofcourse. Does anyone know how to implement this ?



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


Re: Best way to check if string is an integer?

2008-04-08 Thread Tobiah

> byte twiddling if the need arouse.

I'm excited already :)

** Posted from http://www.teranews.com **
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a python code periodically

2008-04-08 Thread paul
Maryam Saeedi schrieb:
> Hi,
> 
> I was wondering if you know how can I run a python code once every five
> minutes for a period of time either using python or some other program like
> a bash script.

See the sched module in the standard library or here:
http://pypi.python.org/simple/Recur/

cheers
  Paul

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


Re: Calling CVF-Fortran-dll with ctypes and simple structure

2008-04-08 Thread Gabriel Genellina
En Tue, 08 Apr 2008 06:02:17 -0300, Michael Schäfer <[EMAIL PROTECTED]>  
escribió:

> Gabriel,
>
> works perfect - even in complex nested structures!
> Thank you very much!
>
>> (If both Fortran and VB say "char*9", why did you choose a pointer  
>> here?)
> I do not know this possibility. Could you please drop me a few lines?

(It's just what I posted and you said it worked)
In C, strings are usually represented as an array of characters  
implicitely ending at the first NULL character. By example: `char foo[20]`  
declares a string variable named foo with enough space for up to 19  
characters (plus the final NULL character).
A very common way of refer to such strings is to pass a pointer to its  
first character: `char *pfoo` declares a variable pfoo which can hold a  
reference to a string variable allocated somewhere (this is the usual way  
to pass a string argument to a function).
In ctypes terminology, the first type is declared as c_char*20, and the  
second one is c_char_p.
In FORTRAN you'd use CHARACTER*20 FOO (or CHARACTER(20)::FOO) to declare a  
string variable with up to 20 characters, right padded with spaces. The  
appropiate way to declare this with ctypes is then to use c_char*20 (and  
probably initialize it with spaces, and trim spaces on the right coming  
 from Fortran). c_char_p declares a pointer, but Fortran filled it as it  
were an array of characters: the first 4 letters of "Sample", when read as  
a little-endian integer, give 0x706D6153, the "invalid pointer" you got.

-- 
Gabriel Genellina

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


Re: Google App Engine

2008-04-08 Thread Steve Holden
Duncan Booth wrote:
[...]
> Yes, it says you can use almost any Python web framework but django is the 
> preferred one.
> 
> Some of the comments at 
> http://www.techcrunch.com/2008/04/07/google-jumps-head-first-into-web-services-with-google-app-engine/
> sound kind of upset, e.g.: "Python will be a deal breaker for many…"
> or "Python only. What a weird decision. Not business and community-friendly 
> at all."

Right, but that's people for you. If you watch the announcement video 
Guido specifically says that other languages will be supported and 
Python is merely the first. That decision wasn't Guido's, either.

But people will always prefer complaining on the grounds of insufficient 
information to keeping quiet on the basis of knowledge.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: list.sort(): heaviest item?

2008-04-08 Thread Raymond Hettinger
On Apr 8, 8:15 am, "Steven Clark" <[EMAIL PROTECTED]> wrote:
> If I have a list of items of mixed type, can I put something into it
> such that after a list.sort(), is guaranteed to be at the end of the
> list?

Since the other guys gave you the real answer, how about this:

sentinel = object()
mylist.sort()
mylist.append(sentinel)

_ ~
@ @
\_/

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


Re: Google App Engine

2008-04-08 Thread Duncan Booth
William Dode <[EMAIL PROTECTED]> wrote:

> On 08-04-2008, Duncan Booth wrote:
>> Google have announced a new service called 'Google App Engine' which
>> may be of interest to some of the people here (although if you want
>> to sign up you'll have to join the queue behind me):
>>
>> From the introduction:
>>
>>> What Is Google App Engine?
> ...
> 
> It's also interesting to see that we can find django, webob and pyyaml
> in their sdk (license apache 2)
> 
Yes, it says you can use almost any Python web framework but django is the 
preferred one.

Some of the comments at 
http://www.techcrunch.com/2008/04/07/google-jumps-head-first-into-web-services-with-google-app-engine/
sound kind of upset, e.g.: "Python will be a deal breaker for many…"
or "Python only. What a weird decision. Not business and community-friendly at 
all."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: set file permission on windows

2008-04-08 Thread Tim Golden
Tim Arnold wrote:
> "Mike Driscoll" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> On Apr 8, 12:03 pm, "Tim Arnold" <[EMAIL PROTECTED]> wrote:
>>>
> 
>> According to the following thread, you can use os.chmod on Windows:
>>
>> http://mail.python.org/pipermail/python-list/2003-June/210268.html
>>
>> You can also do it with the PyWin32 package. Tim Golden talks about
>> one way to do it here:
>>
>> http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
>>
>> Also see the following thread:
>>
>> http://mail.python.org/pipermail/python-win32/2004-July/002102.html
>>
>> or
>>
>> http://bytes.com/forum/thread560518.html
>>
>> Hope that helps!
>>
>> Mike
> 
> Hi Mike,
> It does help indeed, especially the last two links.

Hi, Tim. For the purposes of improving that page of mine linked
above, would you mind highlighting what made it less useful
than the last two links? On the surface, it seems to match your
use case pretty closely. Was there too much information? Too
little? Poor formatting? Just didn't feel right? I've a small set
of security-related pages in train and I'd rather produce something 
which people find useful.

Thanks

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


Re: Running a python code periodically

2008-04-08 Thread Gabriel Ibanez

Hi,

On Linux/Unix:

$ man at

You could create a bash script using this command. Keep in mind that the script 
must "schedule" itself again.

There's other way: using the cron daemon (crond). Its programming depends on 
the used distro.

I hope this helps.

Regards ..

  - Original Message - 
  From: Maryam Saeedi 
  To: python-list@python.org 
  Sent: Tuesday, April 08, 2008 7:53 PM
  Subject: Running a python code periodically


  Hi,

  I was wondering if you know how can I run a python code once every five 
minutes for a period of time either using python or some other program like a 
bash script.

  Thanks,

  Maryam




--


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

Re: set file permission on windows

2008-04-08 Thread Mike Driscoll
On Apr 8, 1:19 pm, "Tim Arnold" <[EMAIL PROTECTED]> wrote:
> "Mike Driscoll" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
>
>
> > On Apr 8, 12:03 pm, "Tim Arnold" <[EMAIL PROTECTED]> wrote:
> >>
> > According to the following thread, you can use os.chmod on Windows:
>
> >http://mail.python.org/pipermail/python-list/2003-June/210268.html
>
> > You can also do it with the PyWin32 package. Tim Golden talks about
> > one way to do it here:
>
> >http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
>
> > Also see the following thread:
>
> >http://mail.python.org/pipermail/python-win32/2004-July/002102.html
>
> > or
>
> >http://bytes.com/forum/thread560518.html
>
> > Hope that helps!
>
> > Mike
>
> Hi Mike,
> It does help indeed, especially the last two links. That certainly gets me
> started in the right direction. I'm always amazed at the helpful generosity
> of the folks on this list.
> thanks again for the help.
> --Tim Arnold

Hi Tim,

I thought I'd used the methods in those last two links before, but I
was thinking of changing permissions on running services to reboot a
PC, which is not quite the same. If you run into more issues, there's
a PyWin32 mailing list with helpful people there too. You can find it
here: http://mail.python.org/mailman/listinfo/python-win32

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


Re: Google App Engine

2008-04-08 Thread Berco Beute
It's wonderful news for Python. It will definitely be a boost for
Python's (and Django's) popularity. Python finally seems to be on
every developers mind at the moment. Looks like it's showtime for
Python!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: set file permission on windows

2008-04-08 Thread Tim Arnold
"Mike Driscoll" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Apr 8, 12:03 pm, "Tim Arnold" <[EMAIL PROTECTED]> wrote:
>>

> According to the following thread, you can use os.chmod on Windows:
>
> http://mail.python.org/pipermail/python-list/2003-June/210268.html
>
> You can also do it with the PyWin32 package. Tim Golden talks about
> one way to do it here:
>
> http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html
>
> Also see the following thread:
>
> http://mail.python.org/pipermail/python-win32/2004-July/002102.html
>
> or
>
> http://bytes.com/forum/thread560518.html
>
> Hope that helps!
>
> Mike

Hi Mike,
It does help indeed, especially the last two links. That certainly gets me 
started in the right direction. I'm always amazed at the helpful generosity 
of the folks on this list.
thanks again for the help.
--Tim Arnold


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


need help to upload file to webserver

2008-04-08 Thread Sells, Fred
I am automating the client side of a simple web interface.  I need to upload a 
file to a webserver that requires authentication.  I've got the authentication 
working with urllib2 (see below), but the only examples I've found to upload 
files use httplib without authentication.  I'm competent with Python but no 
whiz with web api's.  Could I get a little help please.

-the form I'm trying to simulate looks like this--




 
--my code follows-
import urllib2, urllib, socket, base64, cookielib
import webtools # from 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
STANDARD_HEADERS = {'User-agent':'Mozilla/5.0 (compatible; MSIE 5.5; Windows 
NT)'}
COOKIEFILE = 'cokies.lwp'
socket.setdefaulttimeout(30)

HTTP = "http://";
HTTPS = "https://";
#IP, UNAME, PW = "." #deleted for security
top_level_url = "http://...";


PasswordManager = urllib2.HTTPPasswordMgrWithDefaultRealm()
PasswordManager.add_password(None, top_level_url, UNAME, PW)
AuthenticationHandler = urllib2.HTTPBasicAuthHandler(PasswordManager)
opener = urllib2.build_opener(AuthenticationHandler)
urllib2.install_opener(opener)


class MyConnection:
def __init__(self, ipaddr="192.168.1.0", uname=None, password=None):
self.SERVER_AND_PORT = "%s:81" % ipaddr
self.UNAME = uname


def getPage(self, url, kwargs, headers=None):
headers = headers or STANDARD_HEADERS
request = urllib2.Request(url, urllib.urlencode(kwargs), headers)
handle = urllib2.urlopen(request)
page = handle.read()
handle.close()
return  page

def getValidationReportsPage(self):  this works
self.getPage(HTTPS+self.SERVER_AND_PORT+"/cgi/listrpts.exe",{})

def login(self): #this works
try:print 
self.getPage(HTTPS+self.SERVER_AND_PORT+"/cgi/mainhtml.exe",{})
except: print 'login failed'

def uploadFile(self, filepath):  #? need help here
buffer = open(filepath).read()
headers = dict(STANDARD_HEADERS)  #make a copy
parms = ('file', filepath, buffer )
contenttype, body = webtools.encode_multipart_formdata([], [parms])
headers['Content-Type']= contenttype
data = {'file':body}
self.getPage(HTTPS+self.SERVER_AND_PORT+"/cgi/upload.exe",data,headers)
   
  

def unittest():
print 'start unittest of '+ __file__
X = MyConnection(uname=UNAME, password=PW)
X.login()
X.uploadFile('testdata/MouseMds.txt')
  
if __name__ == "__main__":
unittest()

 



You rock. That's why Blockbuster's offering you one month of Blockbuster Total 
Access, No Cost. 

---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is the Python for statement the same as for each in other languages?

2008-04-08 Thread Diez B. Roggisch
jmDesktop schrieb:
> Thank you.  It looks like it is, but I wanted to make sure I
> understood.  Also, I didn't see a "regular" for loop construct either
> (i=0;i<=10;i++), etc.  I'm still new at it, but is there one of those?

Yes, it's foreach. And for your usecase, use

for i in xrange(11):
 ...


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


Is the Python for statement the same as for each in other languages?

2008-04-08 Thread jmDesktop
Thank you.  It looks like it is, but I wanted to make sure I
understood.  Also, I didn't see a "regular" for loop construct either
(i=0;i<=10;i++), etc.  I'm still new at it, but is there one of those?
-- 
http://mail.python.org/mailman/listinfo/python-list


Running a python code periodically

2008-04-08 Thread Maryam Saeedi
Hi,

I was wondering if you know how can I run a python code once every five
minutes for a period of time either using python or some other program like
a bash script.

Thanks,

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

Re: set file permission on windows

2008-04-08 Thread Mike Driscoll
On Apr 8, 12:03 pm, "Tim Arnold" <[EMAIL PROTECTED]> wrote:
> hi, I need to set file permissions on some directory trees in windows using
> Python.
>
> When I click on properties for a file and select the 'Security' tab, I see a
> list of known 'Group or user names' with permissions for each entry such as
> Full Control, Modify, Read&Execute,  etc.
>
> I need to (for example) periodically set Group Permissions for one group to
> Read, and another Group to None. I need to apply the settings to several
> directory trees recursively.
>
> If this was on Unix, I'd just use os.stat I guess. I don't think that will
> work in this case since all I know is the Group names and the permissions I
> need to allow.
>
> thanks for any pointers,
> --Tim Arnold

According to the following thread, you can use os.chmod on Windows:

http://mail.python.org/pipermail/python-list/2003-June/210268.html

You can also do it with the PyWin32 package. Tim Golden talks about
one way to do it here:

http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html

Also see the following thread:

http://mail.python.org/pipermail/python-win32/2004-July/002102.html

or

http://bytes.com/forum/thread560518.html

Hope that helps!

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


  1   2   >