Roundup Issue Tracker release 1.1.1

2006-03-03 Thread Richard Jones
I'm proud to release this, the 1.1.1 release of Roundup.

Fixed in this release:

- failure with browsers not sending Accept-Language header
  (sf bugs 1429646 and 1435335)
- translate class name in required property not supplied error message
  (sf bug 1429669)
- error in link property lookups with numeric-alike key values (sf bug
  1424550)
- ignore UTF-8 BOM in .po files
- add permission filter to menu() implementations (sf bug 1431188)
- lithuanian translation updated by Nerijus Baliunas (sf patch 1411175)
- incompatibility with python2.3 in the mailer module (sf bug 1432602)
- typo in SMTP TLS option name: MAIL_TLS_CERFILE (sf bug 1435452)
- email obfuscation code in html templating is more robust
- blank-title subject line handling (sf bug 1442121)
- All users may only view and edit issues, files and messages they
  create example in docs (sf bug 1439086)
- saving of queries (sf bug 1436169)
- Adding a new constrained field to the classic schema example in docs
  (sf bug 1433118)
- security check in mailgw (sf bug 1442145)
- clear this message (sf bug 1429367)
- escape all uses of schema in mysql backend (sf bug 1397569)
- date spec wasn't allowing week intervals

If you're upgrading from an older version of Roundup you *must* follow
the Software Upgrade guidelines given in the maintenance documentation.

Roundup requires python 2.3 or later for correct operation.

To give Roundup a try, just download (see below), unpack and run::

python demo.py

Release info and download page:
 http://cheeseshop.python.org/pypi/roundup
Source and documentation is available at the website:
 http://roundup.sourceforge.net/
Mailing lists - the place to ask questions:
 http://sourceforge.net/mail/?group_id=31577


About Roundup
=

Roundup is a simple-to-use and -install issue-tracking system with
command-line, web and e-mail interfaces. It is based on the winning design
from Ka-Ping Yee in the Software Carpentry Track design competition.

Note: Ping is not responsible for this project. The contact for this
project is [EMAIL PROTECTED]

Roundup manages a number of issues (with flexible properties such as
description, priority, and so on) and provides the ability to:

(a) submit new issues,
(b) find and edit existing issues, and
(c) discuss issues with other participants.

The system will facilitate communication among the participants by managing
discussions and notifying interested parties when issues are edited. One of
the major design goals for Roundup that it be simple to get going. Roundup
is therefore usable out of the box with any python 2.3+ installation. It
doesn't even need to be installed to be operational, though a
disutils-based install script is provided.

It comes with two issue tracker templates (a classic bug/feature tracker and
a minimal skeleton) and five database back-ends (anydbm, sqlite, metakit,
mysql and postgresql).

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: help in converting perl re to python re

2006-03-03 Thread Joel Hedlund
Hi


 the perl code finds a line that matches something like
 tag1sometext\tag1 in the line and then assign $variable the value
 of  sometext

No, but if you use a closing /tag1 instead of \tag1 it does. You had me 
scratching my head for a while there. :-)

This should do it in python:


#!/usr/bin/python

import re

regexp = re.compile(r(tag1)(.*)/\1)
line = tag1sometext/tag1
match = regexp.search(line) 

if match:
variable = match.group(2)



Good luck!
/Joel Hedlund


[EMAIL PROTECTED] wrote:
 hi
 
 i have some regular exp code in perl that i want to convert to python.
 
 
 if $line =~ m#(tag1)(.*)/\1#
{
  $variable = $2;
 }
 
 the perl code finds a line that matches something like
 
 tag1sometext\tag1 in the line and then assign $variable the value
 of  sometext
 
 how can i do an equivalent of that using re module?
 thanks
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question

2006-03-03 Thread P Boy
Since you are a Windows user, I strongly recommend that you install
activestate python instead of the one you download from python.org. The
PythonWin from active state is much more user friendly. It's basically
an IDE (integrated development environment), which includes interactive
shell, editor, debugger, online help. Just to name a few.

Good luck.

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


Re: Question

2006-03-03 Thread P Boy
You may want to read up on http://python.org/doc/faq/installed.html

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


Importing Files

2006-03-03 Thread anushya beauty
Hi, I am very sorry for confusing you with the file  names. Now i want to say you one more thing and i change my ex  filenames to the exact filenames.  The below is what i explained in my previous mail:  **  My files are:   1. D:\TestDir\module\config.py  2. D:\TestDir\scripts\http.py  3. D:\TestDir\work\path_config.pyHere I am running config.py, imported the http.py and path_config.py  (from path_config import * and from http import *). Now, i can access  the values from path_config in config.py, where, not the values from  http.py.  as you said, My sys.path gives as:  sys.path['C:\\Python24\\Lib\\idlelib', 'C:\\Python24\\python24.zip',  'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib',  'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',  'C:\\Python24\\lib\\site-packages'](My files are in D:\\)  IMP: Now, i found, In  this C:\\Python24 directory, the path_config.pyc is created.(I am  sorry, i dont know when and how it is created). So, it is able to  access the values of path_config file. I tried to create http.pyc file  in the Python24 directory(manually) and import in config file, now it  is imported, but not able to access the values (may be because of  creating manually). From this I understood that the module should be in  the sys.path directory (as you said). (I am very sorry, if it again confused you, and please bare with me)How this pyc file is automatically created?. Or else, please tell me, How to create a pyc file for a py file?thanks and regards,  abbi  
		 Yahoo! Mail 
Use Photomail to share photos without annoying attachments.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: string stripping issues

2006-03-03 Thread P Boy
This seems like a web page parsing question. Another approach can be as
follows if you know the limiting token strings:

a.split('TD WIDTH=175FONT
SIZE=2')[1].split('/FONT/TD\r\n')[0]

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


Re: slicing the end of a string in a list

2006-03-03 Thread P Boy
One liners are cool. Personally however, I would not promote one liners
in Python. Python code is meant to be read. Cryptic coding is in perl's
world.

Code below is intuitive and almost a three year old would understand.

   for line in open('C:\\switches.txt'):
 print line.rstrip()

BTW, if the file is huge, one may want to consider using
open('c:\\switches.txt', 'rb') instead.

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


Re: setattr question

2006-03-03 Thread bruno at modulix
bruno at modulix wrote:
(snip)

 Je ne vois pas très bien à quoi sert cette classe (à moins bien sûr
 qu'il y ait d'autre code). Pour ce que je vois là, pourquoi ne pas
 appeler directement les classes HtmlPage, HtmlElement et HtmlLiteral ?
 
oops, sorry, forgot to remove this before posting :(
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string stripping issues

2006-03-03 Thread Tim Williams (gmail)
On 3 Mar 2006 00:20:21 -0800, P Boy [EMAIL PROTECTED] wrote:
This seems like a web page parsing question. Another approach can be asfollows if you know the limiting token strings:a.split('TD WIDTH=175FONTSIZE=2')[1].split('/FONT/TD\r\n')[0]


As others have mentioned , you really need a an HTML parser. But the following would work better than strip()

 a = ' TD WIDTH=175FONT SIZE=2Hughes. John/FONT/TD\r\n'
 a.replace(' TD WIDTH=175FONT
SIZE=2', '' ) # '' = 2 single quotes not 1 double quote
'Hughes. John/FONT/TD\r\n'

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

Re: slicing the end of a string in a list

2006-03-03 Thread Peter Otten
P Boy wrote:

 BTW, if the file is huge, one may want to consider using
 open('c:\\switches.txt', 'rb') instead.

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


Re: Question

2006-03-03 Thread Duncan Booth
Tom Leggio wrote:

 Do I need this on my computer---Python---can I remove it without hurting 
 anything?

Without further information it is hard to answer, you haven't even said 
what operating system you are running, let alone what programs you have 
installed. Your message headers imply you are running some variant of 
Microsoft Windows, so I'll work on that assumption.

Windows itself does not use Python, so if you have Python installed it has 
been installed to run some other software. For example, my parents' 
computer has Python installed because my mum likes playing patience games 
(so it has Pysol installed).

If you uninstall Python then your system won't stop running, but it is 
likely that some other programs on the system will stop working. One option 
is to make sure you record the exact version of Python which you have 
installed, download that version from python.org and save the install file. 
Then uninstall it and if you notice later something no longer works you can 
reinstall it.

Alternatively, search your entire hard disc for files with the extensions 
.pyo, .pyc, .py, .pyw. You'll find a bunch of these in the directory where 
Python is installed (probably c:\python23 or c:\python24), but if you find 
any more elsewhere on your disc that will give you a clue what else is 
using Python. That isn't perfect (some applications use Python but change 
the file extensions), but it might help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setattr question

2006-03-03 Thread bruno at modulix
Gerard Flanagan wrote:
 bruno at modulix wrote:
 
(snip french)
 
 I was trying to implement the factory pattern.
 The recipe above uses 'apply' which is deprecated according to the
 docs, and I suppose I was curious how to do the same sort of thing
 without 'apply'.

def fun(*args, **kwargs):
  pass

def otherfun(*args, **kwargs):
  fun(*args, **kwargs)

 
Err... I don't see the point of this class. Why not just calling the
HtmlPage|Element|Literal classes directly ?


(snip)

'to_string' ?
Let's see... 'to_string', a class with only staticmethods in it...
You're coming from Java, aren't you ?-)

 
 Never been to Java in my life!

bad guess.

 I don't know if I understand you, HtmlElement has a 'to_string' method

I don't know this HtmlElement class, nor where it comes from.
'to_string()' (or is it toString() ?) is javaish. The pythonic idiom for
this is implementing the __str__() method and calling str(obj) on the
obj (which will call obj.__str__()). Hence my (bad) guess about you
being a Javaer.

 but no static methods:

Not the HtmlElement class, but the HtmlBuilder one. Here again, a class
defining only staticmethods is a pretty javaish idiom - in Python, we
just use good old functions !-) (in a separate module if you want a
separate namespace).

 class HtmlElement(list):
 
 def __init__(self, tag, text=None, **attrib):
 self.tag = tag
 self.text = text
 self.attrib = attrib
 
 def write(self, writer):
 writer.start(self.tag, self.attrib)
 if self.text is not None:
 writer.data(self.text)
 for node in self:
 node.write(writer)
 writer.end()
 
 def to_string(self):
 out = StringIO()
 writer = HtmlWriter(out)
 self.write(writer)
 ret = out.getvalue()
 out.close()
 return ret
 

If it's your own code, you may want to rename this last method __str__().


ie. to pass along *args and **kwargs to the HtmlElement constructor.
Any suggestions?

yes : pass along *args and **kwargs to the HtmlElement constructor !-)


Or is there a better way to this kind of thing?

yes again : kiss (Keep It Simple Stupid)

There's not enough code to really grasp what you're trying to do, but
from what I see, I'd say you're having a bad case of arbitrary
overcomplexification.
 
 
 My code itself is just a learning project ( etant sans emploi a ce
 moment, moi-meme...) and it is no doubt a bit 'over-egged' at the
 minute, but it is a first attempt and I can always refactor later.

My experience is that it's far easier to start simple and add
flexibility where needed than to simplify useless complexity. KISS,
yagni and all that kind of things...

 
 Merci bien pour votre reponse.
 
You're welcome.

BTW, there's also a french speaking python newsgroup at fr.comp.lang.py.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re-posting: web.py, incomplete

2006-03-03 Thread Magnus Lycka
_wolf wrote:
 then the output is ::
 
 Hello, oops!
 Hello, oops!
 20 lines omitted/
 Hello, oops!
 Hel

Are you running Python unbuffered? I.e. python -u
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: slicing the end of a string in a list

2006-03-03 Thread P Boy
I had some issues while ago trying to open a large binary file.

Anyway, from file() man page:

If mode is omitted, it defaults to 'r'. When opening a binary file, you
should append 'b' to the mode value for improved portability. (It's
useful even on systems which don't treat binary and text files
differently, where it serves as documentation.) The optional bufsize
argument specifies the file's desired buffer size: 0 means unbuffered,
1 means line buffered, any other positive value means use a buffer of
(approximately) that size. A negative bufsize means to use the system
default, which is usually line buffered for tty devices and fully
buffered for other files. If omitted, the system default is used.2.3

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


scipy

2006-03-03 Thread computer1
I want to install scipy 0.4.6 (windows)on my computer ,but i cannot
download it from www.scipy.org. who can tell me another place to
download it?

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


Re: do design patterns still apply with Python?

2006-03-03 Thread bruno at modulix
ajones wrote:

(snip)

 I would suggest getting a good grasp on OOP before you get into design
 patterns. When most people start with any new concept they tend to try
 and see everything in terms of their new toy, so sticking to one or two
 new concepts at a time will make things a little easier.
 
 Design patterns are kind of like sarcasm: hard to use well, not always
 appropriate, and disgustingly bad when applied to problems they are not
 meant to solve. You will do just fine without them until OOP is at
 least familiar to you, and by that time you should be a little better
 able to use them appropriately.
 

aolWell, I mostly agree here/aol but OTOH, studying the GoF has been
a real 'OO mind-opener' for me.

I'd say the key here is to study existing patterns to try and understand
how to best design and structure OO code instead of insisting on
copy/pasting canonical patterns everywhere (IOW : trying to get the
'spirit' of patterns instead of sticking to the 'letter').

My 2 cents...
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert dictionary to HTTP POST

2006-03-03 Thread Laszlo Zsolt Nagy

  Hello,

How can I convert a dictionary into a HTTP POST string?
I have an example below, but this is not working correctly for special 
characters. ( ' and others). In other words, if I use Bessy's cat 
instead of Bessy then the http server will parse that to Bessy#39;s cat
Probably the problem is that I should not use urllib.quote but something 
else.
Can you please advise?

   Laszlo

form_values = {'name':'Bessy','age':'10','gender':'female'}
for key,value in form_values.iteritems():
values.append('%s=%s' % (urllib.quote(key),urllib.quote(value)) )
   
values.append('x=33')
values.append('y=14')
post_data = (''.join(values)).replace('/','%2F')
txheaders = {  

'Accept':'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Accept-Language':'en,hu;q=0.8,en-us;q=0.5,hu-hu;q=0.3',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
}
req = urllib2.Request(url, post_data, txheaders)
u = urllib2.build_opener()
req.add_data(post_data)
page2 = self.download(action,post_data,{
  'Content-Type': 'application/x-www-form-urlencoded'
})
openerdirector = u.open(req)
data = openerdirector.read()   

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


Re: Write a GUI for a python script?

2006-03-03 Thread Matthias Huening
Glurt Wuntal (02.03.2006 15:56):
 I am a newbie with Python. It's a great language, but I would like to be
 able to present a simple gui menu for some of my scripts; something better
 than using 'raw_input' prompts.
 

If you only need some dialogs, input and/or message boxes, you could start 
with EasyGUI.
http://www.ferg.org/easygui/

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


Re: Write a GUI for a python script?

2006-03-03 Thread peter . mosley
Hi

I, too, am a python newbie and have wrestled with GUI programming.  I
think I am winning, but its been a struggle.

From what I have gleaned, there are three and a half options.  The half
is easygui - see http://www.ferg.org/easygui - which allows you to
place pop up dialogues in procedural code.  Apart from that there's
Tkinter, PyGtk and wxPython.  I never tried wxPython as it wasn't
installed on my system.  I struggled with PyGtk (http://www.pygtk.org/)
and eventually gave up - somehow I could never get to work any code
which wasn't an exact copy of the tutorial.  Which leaves Tkinter, and
here, with the help of Frederik Lundh's tutorial and manual
(http://www.pythonware.com/library/tkinter/introduction/) , I have been
able to get results.  Not perfect - if you search you'll find a number
of my posts on this newsgroup when I was stuck, and the manual is
incomplete (why - given that Tkinter is the de facto standard?). But
for me at least Tkinter provided a way forwards.

Good Luck

Peter

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


Re: PEP 354: Enumerations in Python

2006-03-03 Thread Christos Georgiou
On 26 Feb 2006 22:30:28 -0800, rumours say that Crutcher
[EMAIL PROTECTED] might have written:

This seems great, except why can't I compare strings? It seems too
useful when dealing with user input, or parsing messages or config
files.

 Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
 Weekdays.mon.__cmp__('mon')

some_value = Weekdays.thu
...
user_input = raw_input(Enter day name)
if user_input == str(some_value):

Additionaly, perhaps the call method of the enumeration object should
construct a value from strings?
 Weekdays.mon == Weekdays('mon')

Either way works for me.
-- 
TZOTZIOY, I speak England very best.
Dear Paul,
please stop spamming us.
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: white space in expressions and argument lists

2006-03-03 Thread Sybren Stuvel
Scott David Daniels enlightened us with:
 One reason is such code changes too much on code edits, which makes
 code differences hard to read.

Good point. I'll keep it in mind :)

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: white space in expressions and argument lists

2006-03-03 Thread Sybren Stuvel
rtilley enlightened us with:
 I took it literally when I first read it b/c it made sense to me and
 I did not notice the date. I don't think it will ever be _required_
 of all Python hackers, but I may be wrong.

Well, part of it is a serious PEP. It being _required_ was the joke.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonWin: any way to delete all objects without exiting and without doing it with del?

2006-03-03 Thread dananrg
Steven, does your technique fix my problem? Would that delete the
objects I've created within a program if I suffix my code with it?

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


Re: Convert dictionary to HTTP POST

2006-03-03 Thread Sybren Stuvel
Laszlo Zsolt Nagy enlightened us with:
 How can I convert a dictionary into a HTTP POST string?  I have an
 example below, but this is not working correctly for special
 characters. ( ' and others).

URL-quote it.

 In other words, if I use Bessy's cat instead of Bessy then the
 http server will parse that to Bessy#39;s cat

The HTTP server won't perform HTML-quoting out of thin air.

 Probably the problem is that I should not use urllib.quote but
 something else.

URL-quoting is the right thing to do:

In [1]: import urllib

In [2]: urllib.quote(Bessy's cat)
Out[2]: 'Bessy%27s%20cat'

If you want to give yourself an example of how it's done, run a
network sniffer and post something to a website.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


How much does Python optimize?

2006-03-03 Thread Blackbird
Hello!

I think

for i in range(10):
some code that depends on i


is more readable than a while loop with explicit incrementation of i.
However, range(10) in the command interpreter obviously returns a list.  Is
this list optimized away in the code above, or is it actually constructed
internally? (With, say, CPython in one of the recent versions.)


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


Re: How much does Python optimize?

2006-03-03 Thread Felipe Almeida Lessa
Em Sex, 2006-03-03 às 10:26 +0100, Blackbird escreveu:
 However, range(10) in the command interpreter obviously returns a list.  Is
 this list optimized away in the code above, or is it actually constructed
 internally? (With, say, CPython in one of the recent versions.)

It's constructed. That's why you should use xrange.

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: Convert dictionary to HTTP POST

2006-03-03 Thread Steve Holden
Laszlo Zsolt Nagy wrote:
   Hello,
 
 How can I convert a dictionary into a HTTP POST string?
 I have an example below, but this is not working correctly for special 
 characters. ( ' and others). In other words, if I use Bessy's cat 
 instead of Bessy then the http server will parse that to Bessy#39;s cat
 Probably the problem is that I should not use urllib.quote but something 
 else.
 Can you please advise?
 
Laszlo
 
 form_values = {'name':'Bessy','age':'10','gender':'female'}
 for key,value in form_values.iteritems():
 values.append('%s=%s' % (urllib.quote(key),urllib.quote(value)) )

 values.append('x=33')
 values.append('y=14')
 post_data = (''.join(values)).replace('/','%2F')
 txheaders = {  
 
 'Accept':'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
 'Accept-Language':'en,hu;q=0.8,en-us;q=0.5,hu-hu;q=0.3',
 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
 }
 req = urllib2.Request(url, post_data, txheaders)
 u = urllib2.build_opener()
 req.add_data(post_data)
 page2 = self.download(action,post_data,{
   'Content-Type': 'application/x-www-form-urlencoded'
 })
 openerdirector = u.open(req)
 data = openerdirector.read()   
 
See urllib.urlencode(). No idea why they don't include it in urllib2 as 
well, but there you go.

  from urllib import urlencode
  urlencode({'a':' Simple string', 'b': '[EMAIL PROTECTED]*()_+='})
'a=%26+%22Simple+string%22b=%3C%3E%21%40%23%24%25%5E%26%2A%28%29_%2B%3D'
 

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Re: how to overload sqrt in a module?

2006-03-03 Thread david mugnai
On Thu, 02 Mar 2006 19:24:48 -0800, mforbes wrote:

[snip]

 I know, but the point is that I want to allow the user of the module to be 
 able to specify which sqrt function should be used depending on the type 
 of x.  Importing math in the module would prevent the user from using f() 
 with complex types (or dimensioned types for another example).

If I don't misunderstood the problem, you can define an init method for
your module_g

(code not tested)

module_g.py
---

_functions = {}
def init(mathmodule):
  _function['sqrt'] = getattr(mathmodule, 'sqrt', None)

def _get(name):
  try:
return _functions[name]
  except KeyError:
raise TypeError(you have to initialize module_g)

def sqrt(x):
  return _get('sqrt')(x)

main.py
---

import math
import module_g

module_g.init(math)
print module_g.sqrt(2)


HTH

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


Re: how do you move to a new line in your text editor?

2006-03-03 Thread Duncan Booth
John Salerno wrote:

 But I read in the PEP that spaces are recommended over tabs. If this is 
 the case, it would involve pressing backspace 4 times (or 8, etc.) to 
 get back to column 1.

In the editor which I use, pressing the tab key indents the current line 
under the previous one the first time you press it near the start of a 
line, then indents a further 4 spaces every other time you press it. The 
backspace key deletes the previous character, unless there is only 
whitespace before it in the line in which case it deletes back to the 
previous tabstop.

This sort of configuration is common to most programming editors: keys 
should work in an intuitive manner and don't have to be dumb.

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


getting the reference count of an object ...

2006-03-03 Thread Wildemar Wildenburger
... how?

I'm writing an app that holds a public data dictionary from which other 
objects obtain part of their __dict__ values so they all work on the 
same dataset (yes I'm fiendishly clever and a constructor of unreadable 
sentences (and code) ;)).

My problem is that I haven't found an easy way to determine if said 
dictionary contents are still in use (so it is ok to delete them from 
the dictionary). I've thought about creating a dict subclass that counts 
the number of assignments and deletions but that seems cumbersome (an 
bug-prone).

Is there a way to get the reference count of these datadict items? I 
imagine that this would be a more stable implementation of such a feature.

Hope this gets my problem accross; if not just bash me and I'll 
reformulate. I'm not the best of explainers.

Oh, and sorry if the solution to my problem is obvious (such as an 
__refcount__ attribute or some stupid oversight like that).

c.u.
wildemar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to overload sqrt in a module?

2006-03-03 Thread Steven D'Aprano
On Thu, 02 Mar 2006 22:35:51 -0800, Michael McNeil Forbes wrote:

 What I was thinking was: is there some way to pass a parameter to the 
 module on import so that the module can then use the correct environment.
 
 If I could pass a dictionary to the module with all of the overloaded 
 functions, then they could become part of the module's environment and 
 used appropriately.  I could not find a way of passing such a dictionary.

Not on import, but you can do this:


import my_module
my_module.set_environment(math) # or cmath, or numeric, or whatever

Your my_module will be like this:

# Warning: untested code.
ENVIRON = None  # global variables sometimes have their uses

def f(x): 
if ENVIRON is None:
raise ValueError(Uninitialised module!)
# or use a custom exception
return ENVIRON.sqrt(x)

def set_environment(name):
global ENVIRON
ENVIRON = __import__(name)


Does this help?


-- 
Steven.

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


Re: do design patterns still apply with Python?

2006-03-03 Thread Paul Boddie
Paul Rubin wrote:
 Roy Smith [EMAIL PROTECTED] writes:
   Somewhat less often, something is easy in Java and difficult in
   Python.
  Example?

 Sandboxed code is a real obvious one.

I don't disagree that this is true in general, but is that actually
covered in the design patterns book [1] or in other related literature?

Paul

[1] Design Patterns: Elements of Reusable Object-Oriented Software

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


Re: slicing the end of a string in a list

2006-03-03 Thread Steven D'Aprano
On Fri, 03 Mar 2006 01:03:38 -0800, P Boy wrote:

 I had some issues while ago trying to open a large binary file.

The important term there is BINARY, not large. Many problems *reading*
(not opening) binary files will go away if you use 'rb', regardless of
whether they are small, medium or large.

 Anyway, from file() man page:
 
 If mode is omitted, it defaults to 'r'. When opening a binary file, you
 should append 'b' to the mode value for improved portability. (It's
 useful even on systems which don't treat binary and text files
 differently, where it serves as documentation.) 

Which does not suggest that using 'rb' is better for large files and 'r'
for small. It suggests that using 'rb' is better for binary files and 'r'
for text.

 The optional bufsize
 argument specifies the file's desired buffer size: 0 means unbuffered,
 1 means line buffered, any other positive value means use a buffer of
 (approximately) that size. A negative bufsize means to use the system
 default, which is usually line buffered for tty devices and fully
 buffered for other files. If omitted, the system default is used.2.3

If you are having problems with large files, changing the buffering will
help far more than changing the mode.


-- 
Steven.

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


Re: do design patterns still apply with Python?

2006-03-03 Thread Nick Craig-Wood
ajones [EMAIL PROTECTED] wrote:
  I would suggest getting a good grasp on OOP before you get into design
  patterns. When most people start with any new concept they tend to try
  and see everything in terms of their new toy, so sticking to one or two
  new concepts at a time will make things a little easier.

Having read the design patterns book a long time after learning OOP, I
came at it with a different perspective.  I found it was useful for
naming techniques which I'd been using all along.  A good programmer
will find it easy to re-invent nearly all the patterns, but having a
name for them is important.

As programmers we name everything and as a corollary if it hasn't got
a name it is difficult to talk about, so from that angle the book is
good and very applicable to python.  That said I found wading though
pages of language-specific waffle extremely dull!

  Design patterns are kind of like sarcasm: hard to use well, not always
  appropriate, and disgustingly bad when applied to problems they are not
  meant to solve. You will do just fine without them until OOP is at
  least familiar to you, and by that time you should be a little better
  able to use them appropriately.

;-)

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting the reference count of an object ...

2006-03-03 Thread Just
In article [EMAIL PROTECTED],
 Wildemar Wildenburger [EMAIL PROTECTED] wrote:

 ... how?
 
 I'm writing an app that holds a public data dictionary from which other 
 objects obtain part of their __dict__ values so they all work on the 
 same dataset (yes I'm fiendishly clever and a constructor of unreadable 
 sentences (and code) ;)).
 
 My problem is that I haven't found an easy way to determine if said 
 dictionary contents are still in use (so it is ok to delete them from 
 the dictionary). I've thought about creating a dict subclass that counts 
 the number of assignments and deletions but that seems cumbersome (an 
 bug-prone).
 
 Is there a way to get the reference count of these datadict items? I 
 imagine that this would be a more stable implementation of such a feature.
 
 Hope this gets my problem accross; if not just bash me and I'll 
 reformulate. I'm not the best of explainers.
 
 Oh, and sorry if the solution to my problem is obvious (such as an 
 __refcount__ attribute or some stupid oversight like that).

Direct answer: sys.getrefcount()

Better answer: look at the weakref module, especially at the various 
Dict helper classes.

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


Re: setattr question

2006-03-03 Thread Gerard Flanagan
bruno at modulix wrote:
[...]

 I don't know this HtmlElement class, nor where it comes from.
 'to_string()' (or is it toString() ?) is javaish. The pythonic idiom for
 this is implementing the __str__() method and calling str(obj) on the
 obj (which will call obj.__str__()). Hence my (bad) guess about you
 being a Javaer.


I've made this change, thanks. ( I had a year with C# so maybe that's
why I'm so idiomatically-challenged ! )

 Not the HtmlElement class, but the HtmlBuilder one. Here again, a class
 defining only staticmethods is a pretty javaish idiom - in Python, we
 just use good old functions !-) (in a separate module if you want a
 separate namespace).


But it's personal preference, no? The functions were kind of related
and meaningless outside the module they were declared - but I'll take
it on board, anyway.

[...]


 My experience is that it's far easier to start simple and add
 flexibility where needed than to simplify useless complexity. KISS,
 yagni and all that kind of things...


yagni - I'd never heard that one!

I've ditched the factory class in any case:

http://gflanagan.net/site/python/htmlbuilder/HtmlBuilder.py
(FWIW)

 
  Merci bien pour votre reponse.
 
 You're welcome.

 BTW, there's also a french speaking python newsgroup at fr.comp.lang.py.


I wasn't aware of that, I'll have a lurk!

Thanks again.

Gerard

 --
 bruno desthuilliers
 python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
 p in '[EMAIL PROTECTED]'.split('@')])

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


Re: help in converting perl re to python re

2006-03-03 Thread Sybren Stuvel
Joel Hedlund enlightened us with:
 regexp = re.compile(r(tag1)(.*)/\1)

I'd go for

regexp = re.compile(r(tag1)(.*?)/\1)

Otherwise this:

line = tag1sometext/tag1tag1othertext/tag1
match = regexp.search(line) 

will result in 'sometext/tag1tag1othertext'

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


relocate python compiled file

2006-03-03 Thread anushya beauty
Hi,   When i run the python file, the python compiled file  is created. Is it possible to relocate the python compiled file to some  other directory?. Is it possible to frequent update the relocated pyc  file while running the py file?thanks and regards,  abbi  
		Yahoo! Mail
Bring photos to life! New PhotoMail  makes sharing a breeze. 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: when do two names cease to refer to the same string object?

2006-03-03 Thread Steven D'Aprano
On Thu, 02 Mar 2006 20:45:10 -0500, John Salerno wrote:

 To test this out a wrote a little script as an exercise:
 
 for num in range(1, 10):
   x = 'c' * num
   y = 'c' * num
   
   if x is y:
  print 'x and y are the same object with', num, 'characters'
   else:
  print 'x and y are not the same object at', num, 'characters'
  break
 
 But a few questions arise:
 
 1. As it is above, I get the 'not the same object' message at 2 
 characters. But doesn't Python only create one instance of small strings 
 and use them in multiple references? Why would a two character string 
 not pass the if test?

Watch this:

 aa is aa
True
 aa is aaa + aaa
False


Does this give you a hint as to what is happening?

Some more evidence:

 a[0:1] is a[0:1]
True
 a[0:2] is a[0:2]
False


 2. If I say x = y = 'c' * num instead of the above, the if test always 
 returns true. Does that mean that when you do a compound assignment like 
 that, it's not just setting each variable to the same value, but setting 
 them to each other?

Yes. Both x and y will be bound to the same object, not just two objects
with the same value. This is not an optimization for strings, it is a
design decision for all objects:

 x = y = []
 x.append(1)
 y
[1]


 Finally, I'd like to see how others might write a script to do this 
 exercise. 

filename = string_optimization_tester.py
s = if '%s' is not '%s':\nraise ValueError('stopped at n=%d')\n
f = file(filename, w)
for n in range(1000):
f.write(s % (c*n, c*n, n))

f.write(if 'ccc' is not 'c'*3:
print 'Expected failure failed correctly'
else:
print 'Expected failure did not happen'
)
f.write(print 'Done!'\n)
f.close()
execfile(filename)



-- 
Steven.

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


encoding problem

2006-03-03 Thread Yves Glodt
Hi list,


Playing with the great pysvn I get this problem:


Traceback (most recent call last):
   File D:\avn\mail.py, line 80, in ?
 mailbody += diff
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 
10710: ordinal not in range(128)



It seems the pysvn.client.diff function returns bytes (as I read in 
the changelog of pysvn: http://svn.haxx.se/dev/archive-2005-10/0466.shtml)

How can I convert this string so that I can contatenate it to my 
regular string?


Best regards,
Yves
-- 
http://mail.python.org/mailman/listinfo/python-list


sockets, where can I find documentation?

2006-03-03 Thread John Pote
Hi all,

I want to use python on a server to access incoming TCP port accesses. So I 
need to use the socket interface which is new to me. To quote the Py Library 
Reference 7.2 socket -- Low-level networking interface:-

For an introduction to socket programming (in C), see the following papers: 
An Introductory 4.3BSD Interprocess Communication Tutorial, by Stuart 
Sechrest and An Advanced 4.3BSD Interprocess Communication Tutorial, by 
Samuel J. Leffler et al, both in the Unix Programmer's Manual, Supplementary 
Documents 1 (sections PS1:7 and PS1:8). The platform-specific reference 
material for the various socket-related system calls are also a valuable 
source of information on the details of socket semantics. For Unix, refer to 
the manual pages; for Windows, see the WinSock (or Winsock 2) specification. 
For IPv6-ready APIs, readers may want to refer to RFC 2553 titled Basic 
Socket Interface Extensions for IPv6.

Where can I get the various papers mentioned in the manual? And as I like 
books sitting on the shelf can someone recommend a book on sockets.

many thanks,

John Pote 


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


Re: Printing a file

2006-03-03 Thread David Boddie
Fabian Steiner wrote:
 David Boddie wrote:

  In Qt 4, the demos/textedit demo does this with a lot less code.
 
  Or are you think of something else?

 Thank you very much for this hint! Thanks to this example I was able to
 print out my first pages :)

That's good to hear. :-)

 But some questions still remain. At the moment I am using
 QSimpleRichtext and a personal HTML-File. I had a look at the
 example.html of textedit.cpp (/usr/share/doc/qt-4.1.1/demos/textedit)
 and found out that it contains quite a lot of proprietary HTML elements,
 attributes and CSS style definitions. So far I didn't even know that
 QSimpleRichText even supports CSS since I couldn't find anything related
 to this point in the official docs (-- e.g. QStylesheet).

I think I may have confused you by mentioning Qt 4. Since you are using
QSimpleRichText, you must be using Qt 3, so you should probably ignore
what I said about the /usr/share/doc/qt-4.1.1/demos/textedit demo. :-/

 Is there any tool out there with which I can write those special HTML
 files? I am quite familiar with HTML and CSS but I don't want to waste
 my time with that.

You don't need to include all those style attributes in the HTML.
Anyway, that's a different version of Qt to the one you are using, so
you can safely ignore it. You should probably look at the text drawing
part of the demo included in Qt 3 (examples/demo/textdrawing) and see
how printing is done for the rich text editor there (in the
TextEdit::filePrint() function). Translating it to Python _shouldn't_
be a problem.

I hope I didn't confuse you too much by talking about two different
versions of Qt at the same time.

Let us know how it goes.

David

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


Re: help in converting perl re to python re

2006-03-03 Thread Joel Hedlund
 I'd go for
 regexp = re.compile(r(tag1)(.*?)/\1)

Indeed. I second that.

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


Re: how do you move to a new line in your text editor?

2006-03-03 Thread Eric Deveaud
John Salerno wrote:
  This is a real small point, but I'd like to hear what others do in this 
  case. It's more an 'administrative' type question than Python code 
  question, but it still involves a bit of syntax.
 
  One thing I like to do is use tabs for my indentation, because this 
  makes it easy to outdent when I need to start a new line in column 1. I 
  can press backspace once and move 4 spaces to the left.
 
  But I read in the PEP that spaces are recommended over tabs. If this is 
  the case, it would involve pressing backspace 4 times (or 8, etc.) to 
  get back to column 1.

you can still use tabs for editing, and if you want to provide space indented
code you can write a small tab2space converter in python 

more seriously, most of the editors (at least Emacs and vim) may use tab for
automatic indentation but convert the tabs to a specified space number

Eric


-- 
 Le lecteur c'est Outlook express (ceci explique sans doute celà)
Outlook Express, c'est fait pour demander comment configurer Emacs
pour lire le courrier et les news.
-+- GK in Guide du linuxien pervers - De l'utilité de Outlook -+-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encoding problem

2006-03-03 Thread Sebastjan Trepca
I think you are trying to concatenate a unicode string with regular
one so when it tries to convert the regular string to unicode with
ASCII(default one) encoding it fails. First find out which of these
strings is regular and how it was encoded, then you can decode it like
this(if regular string is diff):

mailbody +=diff.decode('correct encoding')

Sebastjan

On 3/3/06, Yves Glodt [EMAIL PROTECTED] wrote:
 Hi list,


 Playing with the great pysvn I get this problem:


 Traceback (most recent call last):
File D:\avn\mail.py, line 80, in ?
  mailbody += diff
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position
 10710: ordinal not in range(128)



 It seems the pysvn.client.diff function returns bytes (as I read in
 the changelog of pysvn: http://svn.haxx.se/dev/archive-2005-10/0466.shtml)

 How can I convert this string so that I can contatenate it to my
 regular string?


 Best regards,
 Yves
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: re-posting: web.py, incomplete

2006-03-03 Thread _wolf
it does look like it, no? but i don't---at least i think i don't. in my
httpd conf it says
``AddHandler cgi-script .py``, and at the top of my script,
``#!/usr/local/bin/python``. standard, no ``-u`` here.

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


Re: sockets, where can I find documentation?

2006-03-03 Thread Mc Osten
On Fri, 03 Mar 2006 11:41:05 GMT, John Pote wrote:

 Where can I get the various papers mentioned in the manual? And as I like 
 books sitting on the shelf can someone recommend a book on sockets.

Unix Network Programming by Stevens

-- 
USB Priests for only 10$
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in need of some sorting help

2006-03-03 Thread Kent Johnson
ianaré wrote:
 you did make me understand  a way to sort this thing finally: sort by
 base path then by full path, which is how i came up with:
 
 files.sort(key=lambda x: x.lower())
 files.sort(key=lambda x: os.path.dirname(x))
 
 well actually i am sorting first by full name, then by base, taking
 advantage of python2.4's stable sort().
 
 If you can think of a more efficient (faster) way of doing this please
 let me know. i'm not crazy about having to sort this list twice, it can
 get pretty big (50,000 entries)

Use a key function that returns a tuple of the two values you want to 
sort on:
def make_key(f):
   return (os.path.dirname(f), f.lower())

files.sort(key=make_key)

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


Re: Exception not raised - May be the end

2006-03-03 Thread Sion Arrowsmith
Michele Petrazzo  [EMAIL PROTECTED] wrote:
some days ago I posted here and say that python forgot to raise an
exception, but my code was too long for make some tries possible.
But now I can reproduce the problem into another, little, project:

www.unipex.it/vario/wxFrameSchedule.py
www.unipex.it/vario/metamenus.py
 [ ... ]

It looks like a wx sandwich issue to me: the exception is certainly
being raised and can be caught in wxFrameSchedule.OnMbWorkHour, but
OnMbWorkHour is being called from the C++ wx event loop and I'd guess
that the Python exception isn't being propogated across the C++ layer
back out to the default handler in the Python interpretter. Robin gave
a full explanation to someone else having similar problems on
wxPython-users a couple of days ago, but I'm having trouble finding
that.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

object's list index

2006-03-03 Thread William Meyer
hi,

I need to get the index of an object in a list. I know that no two objects
in the list are the same, but objects might evaluate as equal. for example

list = [obj1, obj2, obj3, obj4, obj5]
for object in list:
objectIndex = list.index(object)
print objectIndex
 
prints 0, 1, 2, 3, 2 instead of 0, 1, 2, 3, 4 because obj3 == obj5. I could loop
through the list a second time comparing id()'s

for object in list:
objectIndex = 0
for i in list:
if id(object) == id(i):
break
objectIndex += 1
print objectIndex

but that seems like a real ugly pain. Somewhere, someplace python is keeping
track of the current index in list, does anyone know how to access it? Or have
any other suggestions?

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


Re: Write a GUI for a python script?

2006-03-03 Thread Peter Decker
On 3 Mar 2006 01:16:23 -0800, [EMAIL PROTECTED]

 I, too, am a python newbie and have wrestled with GUI programming.  I
 think I am winning, but its been a struggle.

I started with wxPython and struggled with it for a long time. I was
able to get the job done, but using it never seemed natural. Then I
found the Dabo project, whose ui module wraps wxPython into a much
more Pythonic, consistent interface. Since then I've been able to
create GUIs without much effort at all. I highly recommend Dabo if you
are thinking about wxPython.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you move to a new line in your text editor?

2006-03-03 Thread Mc Osten
On Thu, 02 Mar 2006 18:58:50 GMT, John Salerno wrote:

 I use UltraEdit right now, and it is possible to convert spaces and tabs 
 back and forth, but it's just an extra step.

I wouldn't definitely suggest UltraEdit to code Python.
Probably you should try scite. 

 I'm using TextMate (but it's MacOS only). When on Linux I use Emacs or vim
(depends on what I find on the machine). On Windows I prefer gvim to Emacs,
since I've not yet found a well integrated Emacs distribution (I said I
did't find it, not that it doesn't exist).


-- 
USB Priests for only 10$
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string stripping issues

2006-03-03 Thread Iain King

Ben Cartwright wrote:
 Ben Cartwright wrote:
  orangeDinosaur wrote:
   I am encountering a behavior I can think of reason for.  Sometimes,
   when I use the .strip module for strings, it takes away more than what
   I've specified.  For example:
  
a = 'TD WIDTH=175FONT SIZE=2Hughes. John/FONT/TD\r\n'
  
a.strip('TD WIDTH=175FONT SIZE=2')
  
   returns:
  
   'ughes. John/FONT/TD\r\n'
  
   However, if I take another string, for example:
  
b = 'TD WIDTH=175FONT SIZE=2Kim, Dong-Hyun/FONT/TD\r\n'
  
b.strip('TD WIDTH=175FONT SIZE=2')
  
   returns:
  
   'Kim, Dong-Hyun/FONT/TD\r\n'
  
   I don't understand why in one case it eats up the 'H' but in the next
   case it leaves the 'K' alone.
 
 
  That method... I do not think it means what you think it means.  The
  argument to str.strip is a *set* of characters, e.g.:
 
 foo = 'abababaXabbaXababa'
 foo.strip('ab')
'XabbaX'
 foo.strip('aabababaab') # no difference!
'XabbaX'
 
  For more info, see the string method docs:
  http://docs.python.org/lib/string-methods.html
  To do what you're trying to do, try this:
 
 prefix = 'hello '
 bar = 'hello world!'
 if bar.startswith(prefix): bar = bar[:len(prefix)]
...
 bar
'world!'


 Apologies, that should be:
 prefix = 'hello '
 bar = 'hello world!'
 if bar.startswith(prefix): bar = bar[len(prefix):]
...
 bar
'world!'


or instead of:

 a.strip('TD WIDTH=175FONT SIZE=2')

use:

a.replace('TD WIDTH=175FONT SIZE=2','')

Iain

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


Re: Exception not raised - May be the end

2006-03-03 Thread Michele Petrazzo
Sion Arrowsmith wrote:
 Michele Petrazzo  [EMAIL PROTECTED] wrote:
 some days ago I posted here and say that python forgot to raise
 an exception, but my code was too long for make some tries
 possible. But now I can reproduce the problem into another, little,
 project:
 
 www.unipex.it/vario/wxFrameSchedule.py 
 www.unipex.it/vario/metamenus.py [ ... ]
 
 It looks like a wx sandwich issue to me

Yes! Now I think the same

 Robin gave a full explanation to someone else having similar problems
 on wxPython-users a couple of days ago, but I'm having trouble
 finding that.
 

Yes, I had read it, but I didn't think that was I similar problem!

This is the message
http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3034524

I hope that, like Robin says, this will be changed into 2.7!

Thanks a lot for the tip!

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


Re: object's list index

2006-03-03 Thread Iain King

William Meyer wrote:
 hi,

 I need to get the index of an object in a list. I know that no two objects
 in the list are the same, but objects might evaluate as equal. for example

 list = [obj1, obj2, obj3, obj4, obj5]
 for object in list:
 objectIndex = list.index(object)
 print objectIndex

 prints 0, 1, 2, 3, 2 instead of 0, 1, 2, 3, 4 because obj3 == obj5. I could 
 loop
 through the list a second time comparing id()'s

 for object in list:
 objectIndex = 0
 for i in list:
 if id(object) == id(i):
 break
 objectIndex += 1
 print objectIndex

 but that seems like a real ugly pain. Somewhere, someplace python is keeping
 track of the current index in list, does anyone know how to access it? Or have
 any other suggestions?

Um, one of us is being really really dense today :)  I hope it's not
me...
 what's wrong with:

i = 0
for object in list:
objectIndex = i
print objectIndex
i += 1

Iain

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


Re: object's list index

2006-03-03 Thread Sebastjan Trepca
Um, what about:

for oindex in xrange(len(list)):
   object = list[oindex]
   print oindex

You can't create a generic function for this.

Sebastjan

On 3/3/06, William Meyer [EMAIL PROTECTED] wrote:
 hi,

 I need to get the index of an object in a list. I know that no two objects
 in the list are the same, but objects might evaluate as equal. for example

 list = [obj1, obj2, obj3, obj4, obj5]
 for object in list:
 objectIndex = list.index(object)
 print objectIndex

 prints 0, 1, 2, 3, 2 instead of 0, 1, 2, 3, 4 because obj3 == obj5. I could 
 loop
 through the list a second time comparing id()'s

 for object in list:
 objectIndex = 0
 for i in list:
 if id(object) == id(i):
 break
 objectIndex += 1
 print objectIndex

 but that seems like a real ugly pain. Somewhere, someplace python is keeping
 track of the current index in list, does anyone know how to access it? Or have
 any other suggestions?

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

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


Re: object's list index

2006-03-03 Thread Fredrik Lundh
William Meyer wrote:

I need to get the index of an object in a list. I know that no two objects
 in the list are the same, but objects might evaluate as equal. for example

 list = [obj1, obj2, obj3, obj4, obj5]
 for object in list:
objectIndex = list.index(object)
print objectIndex

   for objectIndex, object in enumerate(list):
print objectIndex, object

(note that both object and list are commonly used builtins, so you should 
probably
use other names in your code to avoid weird TypeErrors later on).

/F 



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


Re: object's list index

2006-03-03 Thread William Meyer
Iain King iainking at gmail.com writes:

  what's wrong with:
 
 i = 0
 for object in list:
 objectIndex = i
 print objectIndex
 i += 1
 
 Iain
 

The issues with that is you might have a complex structure below the for object
in list: with lots of continues or breaks and you don't want to have to remember
to change the index everytime. There is an old pep
(http://www.python.org/peps/pep-0212.html) that describes some proposed
solutions, but I was wondering if anything has happened since aug 2000. I might
just use the 

for objectIndex in range(len(list)):
e = list[objectIndex]

solution, though its ugly too.


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


Re: object's list index

2006-03-03 Thread William Meyer
Kent Johnson kent at kentsjohnson.com writes:

 In either case enumerate() is your friend. To find an 
 item by identity:
 
 def index_by_id(lst, o):
for i, item in enumerate(lst):
  if item is o:
return i
raise ValueError, %s not in list % o
 
 If you just want the index available inside the loop, this replaces your 
 original loop:
 for i, object in enumerate(lst):
print i
 
 Kent

Thanks, both you and Fredrik Lundh suggested enumerate, which seems like the
best solution. I just need the index inside the loop, but thanks again for both
solutions.



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


Re: RPC client class?

2006-03-03 Thread Dick Watson
Fredrik Lundh [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 if the RPC you're talking about is Sun RPC, the whole concept is pretty
 dated (the original RFCs are from the late eighties).

Just because it's dated doesn't meant it isn't still something that 
occasionally needs done. Thanks for the advice! 


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


Re: object's list index

2006-03-03 Thread Iain King

Iain King wrote:
 William Meyer wrote:
  hi,
 
  I need to get the index of an object in a list. I know that no two 
  objects
  in the list are the same, but objects might evaluate as equal. for example
 
  list = [obj1, obj2, obj3, obj4, obj5]
  for object in list:
  objectIndex = list.index(object)
  print objectIndex
 
  prints 0, 1, 2, 3, 2 instead of 0, 1, 2, 3, 4 because obj3 == obj5. I could 
  loop
  through the list a second time comparing id()'s
 
  for object in list:
  objectIndex = 0
  for i in list:
  if id(object) == id(i):
  break
  objectIndex += 1
  print objectIndex
 
  but that seems like a real ugly pain. Somewhere, someplace python is keeping
  track of the current index in list, does anyone know how to access it? Or 
  have
  any other suggestions?

 Um, one of us is being really really dense today :)  I hope it's not
 me...
  what's wrong with:

 i = 0
 for object in list:
 objectIndex = i
 print objectIndex
 i += 1

 Iain

Reading it again, I'm thinking it probably is me...

If you aren't looking them up sequentially then I think your second
example is the only way.  You can make it a little prettier by using
'object is i' rather than 'id(object) == id(i)'.
I think python only stores lists one way - i.e. each index maps to it's
value, but no backwards trace is kept from value to index.

Iain

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


Re: object's list index

2006-03-03 Thread Felipe Almeida Lessa
Em Sex, 2006-03-03 às 12:48 +, William Meyer escreveu:
 Kent Johnson kent at kentsjohnson.com writes:
 
  In either case enumerate() is your friend. To find an 
  item by identity:
  
  def index_by_id(lst, o):
 for i, item in enumerate(lst):
   if item is o:
 return i
 raise ValueError, %s not in list % o
  
  If you just want the index available inside the loop, this replaces your 
  original loop:
  for i, object in enumerate(lst):
 print i
  
  Kent
 
 Thanks, both you and Fredrik Lundh suggested enumerate, which seems like the
 best solution. I just need the index inside the loop, but thanks again for 
 both
 solutions.

You should *always* use enumerate. list.index has a high cost and
shouldn't be used that way.

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: object's list index

2006-03-03 Thread Iain King

Iain King wrote:
 Iain King wrote:
  William Meyer wrote:
   hi,
  
   I need to get the index of an object in a list. I know that no two 
   objects
   in the list are the same, but objects might evaluate as equal. for example
  
   list = [obj1, obj2, obj3, obj4, obj5]
   for object in list:
   objectIndex = list.index(object)
   print objectIndex
  
   prints 0, 1, 2, 3, 2 instead of 0, 1, 2, 3, 4 because obj3 == obj5. I 
   could loop
   through the list a second time comparing id()'s
  
   for object in list:
   objectIndex = 0
   for i in list:
   if id(object) == id(i):
   break
   objectIndex += 1
   print objectIndex
  
   but that seems like a real ugly pain. Somewhere, someplace python is 
   keeping
   track of the current index in list, does anyone know how to access it? Or 
   have
   any other suggestions?
 
  Um, one of us is being really really dense today :)  I hope it's not
  me...
   what's wrong with:
 
  i = 0
  for object in list:
  objectIndex = i
  print objectIndex
  i += 1
 
  Iain

 Reading it again, I'm thinking it probably is me...

 If you aren't looking them up sequentially then I think your second
 example is the only way.  You can make it a little prettier by using
 'object is i' rather than 'id(object) == id(i)'.
 I think python only stores lists one way - i.e. each index maps to it's
 value, but no backwards trace is kept from value to index.

 Iain

OTOH, if memory is not an issue, you can create a lookup yourself:

def createLookup(l):
d = {}
for index in xrange(len(l)):
objID = id(l[index])
d[objID] = index
return d

lookup = createLookup(list)
for i in list:
objectIndex = lookup[id(i)]
print objectIndex


Iain

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


socket freezes

2006-03-03 Thread Luis P. Mendes
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

I've developed a program that uses a socket to receive information 24h a
~ day.

The problem is that the socket seems to freeze.  By that I mean the
program stops getting information but doesn't raise any error.

I tried to solve this by writing the following functions, in order to
try to start the socket connection again:

def keepAlive(self):
~self.alive = 0
~tnow = time.time()
~if tnow - self.lastTime  90:   # last time got from last string
received from the socket
~self.alive = 1

def reSocket():
~print socket has failed, time.strftime('%X', time.localtime())
~time.sleep(60)
~l=GServer()# new instance that contains the socket

reSocket is triggered when self.alive is 1.

But it hasn't solved my problem.  These functions have effect only after
I do a ^C, and even then, the socket doesn't start to acquire new input.

Any clues you can give me about this?


Luis P. Mendes


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFECEF8Hn4UHCY8rB8RAtaaAKCnFb2O28AE4uRTK0sPSpnOifaDzACdG2EA
imVqvzcRX4qGWqMzLRUcyao=
=Cqkb
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object's list index

2006-03-03 Thread Kent Johnson
William Meyer wrote:
 hi,
 
 I need to get the index of an object in a list. I know that no two objects
 in the list are the same, but objects might evaluate as equal. for example
 
 list = [obj1, obj2, obj3, obj4, obj5]
 for object in list:
 objectIndex = list.index(object)
 print objectIndex
  
 prints 0, 1, 2, 3, 2 instead of 0, 1, 2, 3, 4 because obj3 == obj5. I could 
 loop
 through the list a second time comparing id()'s
 
 for object in list:
 objectIndex = 0
 for i in list:
 if id(object) == id(i):
 break
 objectIndex += 1
 print objectIndex
 
 but that seems like a real ugly pain. Somewhere, someplace python is keeping
 track of the current index in list, does anyone know how to access it? Or have
 any other suggestions?
 
Do you actually need to find the index of an arbitrary object in the 
list or are you iterating the whole list and you need the list index 
inside the list? In either case enumerate() is your friend. To find an 
item by identity:

def index_by_id(lst, o):
   for i, item in enumerate(lst):
 if item is o:
   return i
   raise ValueError, %s not in list % o

If you just want the index available inside the loop, this replaces your 
original loop:
for i, object in enumerate(lst):
   print i

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


Re: sockets, where can I find documentation?

2006-03-03 Thread Rene Pijlman
John Pote:
I want to use python on a server to access incoming TCP port accesses. So I 
need to use the socket interface which is new to me. 

You may also want to look at Twisted:
http://twistedmatrix.com/trac/

Where can I get the various papers mentioned in the manual? And as I like 
books sitting on the shelf can someone recommend a book on sockets.

Stevens++

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


Re: Convert dictionary to HTTP POST

2006-03-03 Thread Laszlo Zsolt Nagy


See urllib.urlencode(). No idea why they don't include it in urllib2 as 
well, but there you go.

  from urllib import urlencode
  urlencode({'a':' Simple string', 'b': '[EMAIL PROTECTED]*()_+='})
'a=%26+%22Simple+string%22b=%3C%3E%21%40%23%24%25%5E%26%2A%28%29_%2B%3D'
 
  

Hmm. urlencode is using quote_plus internally. Looks like there is no 
difference in the encoding of the apostrophe.
I tried to create a very basic form and realized that the problem is NOT 
with the quoting.
I'm writting a program that puts orders into a wholesaler's database.
They do not have a programatic interface, so I have to login and post 
forms using a program.
There are some fields that I must not change, so I have to read the 
value from the HTML source and then post it back.
Here is the problem:

html
body
form method=POST
  input name=name value=Bessy#39;s cat
  input type=submit
/form
/body
/html

The values of some inputs are encoded using html entities.
How can I decode a string like Bessy#39;s cat  in Bessy's cat?

Thanks,

   Laszlo

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


Re: object's list index

2006-03-03 Thread Sybren Stuvel
Iain King enlightened us with:
 i = 0
 for object in list:
 objectIndex = i
 print objectIndex
 i += 1

Why not:

for index, object in enumerate(list):
print index

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setattr question

2006-03-03 Thread bruno at modulix
Gerard Flanagan wrote:
 bruno at modulix wrote:
 [...]
 
I don't know this HtmlElement class, nor where it comes from.
'to_string()' (or is it toString() ?) is javaish. The pythonic idiom for
this is implementing the __str__() method and calling str(obj) on the
obj (which will call obj.__str__()). Hence my (bad) guess about you
being a Javaer.

 
 
 I've made this change, thanks. ( I had a year with C# so maybe that's
 why I'm so idiomatically-challenged ! )

Well, C# being somewhat inspired by Java...

 
Not the HtmlElement class, but the HtmlBuilder one. Here again, a class
defining only staticmethods is a pretty javaish idiom - in Python, we
just use good old functions !-) (in a separate module if you want a
separate namespace).
 
 
 But it's personal preference, no? 

Well, in Python, there are a lot of things that can be done the way you
like it, but are better done the idiomatic way. Python relies quite a
lot on conventions and idioms where other languages try to inforce
strict rules.

 The functions were kind of related
 and meaningless outside the module they were declared - 

FWIW (and from the snippet I saw), these functions are useless even in
the module !-)

Unless you want to dynamically choose the concrete class at runtime
based on platform/settings/phase of the moon/whatnot (which seems not to
be te case in the snippet you posted), you don't need these functions,
just instanciating the concrete class is enough. Remember that Python
classes *are* factory already - and that you can freely replace a class
by any callable returning an instance, ie:

== before refactoring, directly instanciating concrete class ==
# myhtmlmodule.py
class HtmlElement(tag, *args, **kw):
  # code here

# myclientmodule.py
from myhtmlmodule import HtmlElement
ul = HtmlElement('ul')


== after refactoring, using a factory function ==
# myhtmlmodule.py
class _HtmlElement1(tag, *args, **kw):
  # code here

class _HtmlElement2(tag, *args, **kw):
  # other code here

# yes, it's now a function...
def HtmlElement(tag, *args, **kw):
  if phase_of_the_moon():
klass = _HtmlElement1
  else:
klass = _HtmlElement2
  return klass(tag, *args, **kw)

# myclientmodule.py
# well... nothing changed here !-)
from myhtmlmodule import HtmlElement
ul = HtmlElement('ul')


You could also do the trick with metaclass black magic, but what, KISS...

 but I'll take
 it on board, anyway.
 
 [...]
 
 
My experience is that it's far easier to start simple and add
flexibility where needed than to simplify useless complexity. KISS,
yagni and all that kind of things...

 
 yagni - I'd never heard that one!

You Aint Gonna Need It.

Code not written is the best code, so don't write code just in case.
Python is usually dynamic enough to make refactoring easy (cf example above)

 I've ditched the factory class in any case:
 
 http://gflanagan.net/site/python/htmlbuilder/HtmlBuilder.py
 (FWIW)

Seems mostly clean. May I suggest a couple small corrections/improvements ?

1/ potential bugfix:
try:
from tidy import parseString
except ImportError:
def parseString(text):
# woops, this function is supposed to return something
#pass
return text

2/ safer and cleaner
class HtmlPage(HtmlElement):
# removed class vars,
# replaced with default in __init__
def __init__(self, title, **kw):
self.title = title
self.stylesheets = kw.get('stylesheets', [])
self.doctype = kw.get('doctype', HTML4_STRICT)


BTW, there's also a french speaking python newsgroup at fr.comp.lang.py.
 
 I wasn't aware of that, I'll have a lurk!

see you there !-)

--
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
 
 


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module written in C does not repond to Ctrl-C interruption.

2006-03-03 Thread fraca7
Bo Peng a écrit :
 Dear list,
 
 I have not done a thorough test, but it occurs to me that
 
 1. python code can be interrupted by Ctrl-C.
 2. A C module, if I add a main() function and run independently, can be 
 interrupted by Ctrl-C.
 3. If I load the C module in python and run, the program will not 
 respond to Ctrl-C interruption. I have to kill python explicitly.
 
 If this is a known behavior or just a special case of mine? Any fix to 
 it? I am using python 2.3.4 under Redhat EL4 with gcc 3.3.4.

You may want to call intrcheck() or PyErr_CheckSignals in your C code 
and react accordingly.

 From what I can see, PyErr_CheckSignals() returns 0 if no interrupt 
occurred and -1 (setting a KeyboardInterrupt exception) if one did.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do design patterns still apply with Python?

2006-03-03 Thread msoulier
Personally, I find many of the design patterns apply but require
modification.

For example, the Factory pattern is mostly to work around the fact that
it's difficult in Java and C++ to dynamically load classes. Not so in
Python, especially with exec. A simple configuration file and an exec
call can replace an entire Factory pattern, with the same result.

The ideas are fine, but sometimes it's best to keep things simple. I
find that DP junkies don't tend to keep things simple.

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


Re: Convert dictionary to HTTP POST

2006-03-03 Thread Steve Holden
[copied to list]

Laszlo Zsolt Nagy wrote:


 See urllib.urlencode(). No idea why they don't include it in urllib2 
 as well, but there you go.

  from urllib import urlencode
  urlencode({'a':' Simple string', 'b': '[EMAIL PROTECTED]*()_+='})
 'a=%26+%22Simple+string%22b=%3C%3E%21%40%23%24%25%5E%26%2A%28%29_%2B%3D'
 
  

 Hmm. urlencode is using quote_plus internally. Looks like there is no 
 difference in the encoding of the apostrophe.
 I tried to create a very basic form and realized that the problem is NOT 
 with the quoting.
 I'm writting a program that puts orders into a wholesaler's database.
 They do not have a programatic interface, so I have to login and post 
 forms using a program.
 There are some fields that I must not change, so I have to read the 
 value from the HTML source and then post it back.
 Here is the problem:
 
 html
 body
 form method=POST
  input name=name value=Bessy#39;s cat
  input type=submit
 /form
 /body
 /html
 
 The values of some inputs are encoded using html entities.
 How can I decode a string like Bessy#39;s cat  in Bessy's cat?
 
 Thanks,
 
   Laszlo
 
 
Well I don't understand what's encoding the apostrophe as an encoded 
entity anyway. That's only supposed to be done for HTML content, not 
form content. You will find that the string Bessy's cat works just as 
well.

That should actually be transmitted as Bessy%39s cat when sent to the 
server.

How about an RE that turned all #DD; into %DD ?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does '#hash' mean anything in IDLE?

2006-03-03 Thread John Coleman

John Salerno wrote:
 John Coleman wrote:
  John Coleman wrote:
  Greetings,
 I am currently trying to learn Python through the excellent
  Learning Python book.

 me too!

  It isn't just #hash, but also things like #dict, #int, #len at the
  start of a comment line which defeats IDLE's colorization algorithm.
  Interestingly, things like #while or #for behave as expected so it
  seems to be built-ins rather than keywords which are the problem. To
  answer my own question - this is pretty clearly a (harmless) bug.

 also notice that putting a space after # stops the problem

How do you like Python so far? I like dictionary objects the best so
far. I'm coming to Python from VBScript, so I already knew the value of
such things, but in Python they are better supported.

Here is the program I was talking about, which *really* shows the power
of dictionaries:

*

#Python program to discover word with most 1-word anagrams

#The following hash function has the property
#that words which are anagrams of each other
#hash to the same string. It assumes that input
#is lower case in range 'a' to 'z'

def letter_hash(word):
codes = 26 * [0]
for c in word:
codes[ord(c)-97] +=1
return_string = ''
for i in range(26):
j = codes[i]
if j  0:
return_string += (str(j)+chr(i+97))
return return_string

#main program:

hashes = {}

#first load dictionary of hashes

for line in open('C:\\yawl.txt').readlines():
word = line.strip().lower() #to be safe
my_hash = letter_hash(word)
hashes.setdefault(my_hash,[]).append(word)

#now find word with most anagrams

max_len = 0
max_words = []
for word_list in hashes.itervalues():
if len(word_list)  max_len:
max_len = len(word_list)
max_words = word_list
print max_words


**

yawl stands for Yet Another Word List. It is a text-list of some
240,000 English words, including all sorts of archaic and technical
phrases. Google for yawl word list if you want to track down a copy.
The output is

['apers', 'apres', 'asper', 'pares', 'parse', 'pears', 'prase',
'presa', 'rapes', 'reaps', 'spaer', 'spare', 'spear']

These 13 words are anagrams of each other. They contain some pretty
obscure words: asper is a 17th century Turkish coin and spaer is an
archaic Scottish-dialect word word for prophet (you can see speaker
if you squint).

-John Coleman

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


How to get and set the content of system clip-board.

2006-03-03 Thread Peter Cai
Question 1 : How to set and get the content of my system clip-board?
2 : How to print the current line no in a python program? -- 
每一种结局都有可能感触动观众心底的某一颗眼泪。以死亡为结尾的故事和大团圆故事一样多,是因为人们最不能承受的反
倒是漫长而不可知的人生,让传奇湮灭,让真情淡去,让英雄苍老,让美人迟暮。他爱他,他死了,另一个人终身铭记。再没有了世俗压力,他与他的往昔相依相伴
在断臂山下,他与他的未来活在永恒的回忆里。



《断背山》的影评
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Convert dictionary to HTTP POST

2006-03-03 Thread Sybren Stuvel
Laszlo Zsolt Nagy enlightened us with:
 The values of some inputs are encoded using html entities.  How can
 I decode a string like Bessy#39;s cat  in Bessy's cat?

This should help:
http://docs.python.org/lib/module-htmlentitydefs.html

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert dictionary to HTTP POST

2006-03-03 Thread Laszlo Zsolt Nagy

 Well I don't understand what's encoding the apostrophe as an encoded 
 entity anyway. That's only supposed to be done for HTML content, not 
 form content. 

You are right. I was wrong. The problem was not with quote. It was 
reading out the VALUE of an INPUT from HTML source.

 How about an RE that turned all #DD; into %DD ?

Good idea, but then I still need to examine for nbsp;  gt; and the 
others. I just wonder if there is a standard function in Python that can 
convert HTML escaped value into plain string.

Regards,

   Laszlo


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


Re: do design patterns still apply with Python?

2006-03-03 Thread Roy Smith
In article [EMAIL PROTECTED],
 msoulier [EMAIL PROTECTED] wrote:

 For example, the Factory pattern is mostly to work around the fact that
 it's difficult in Java and C++ to dynamically load classes.

You're over-specifying.  Most of most design patterns is to work around the 
fact that it's difficult in Java and C++ to do many things.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert dictionary to HTTP POST

2006-03-03 Thread Kent Johnson
Laszlo Zsolt Nagy wrote:
 The values of some inputs are encoded using html entities.
 How can I decode a string like Bessy#39;s cat  in Bessy's cat?

http://groups.google.com/group/comp.lang.python/browse_frm/thread/819731a536a4c1a2/fce6c2f6c3d46e9c?q=htmlentitydefsrnum=2#fce6c2f6c3d46e9c

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


Re: how to write file with cp1250 encodings?

2006-03-03 Thread jean-michel bain-cornu
Hi,
Grzegorz Smith wrote:
 Hi all. I have got situation: i load data from database(MSSQL) wchich are
 encoded cp1250 and I fill template with that data (Cheetah Template), after
 all i want to save template to file on disk. I'm using 
 newfile = open(template.html,w)
 newfile.write(str(template))
 newfile.close()
 But data encodings are saved wrong, and I try diffrent programs to convert
 but all i get was only mess. So is this any way to save data with encodings
 cp1250 properly? 
 Any help will be very appreciated
 Gregor
I had to do it recently, reading from mysql and pushing data into a 
browser by cherryPy.
I used :
 try:
 val= dbString.decode('utf8').encode('iso-8859-1')
 except UnicodeDecodeError:
 val= dbString
The 'try:' was needed because of some extra-character on top of the 7 
bits limit raising an exception.
I have no more explanations about that, and I must say it was a pain in 
the neck to find a solution.
I guess in your case, you have to replace iso-8859-1 by something else 
in the case it's not strictly the same that cp1250. The '4.9.2 Standard 
Encodings' documentation section give some explanations.
Regards,
jm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket freezes

2006-03-03 Thread Rene Pijlman
Luis P. Mendes:
I've developed a program that uses a socket to receive information 24h a
~ day.

The problem is that the socket seems to freeze.  By that I mean the
program stops getting information but doesn't raise any error.

That's weird. There's probably a bug in your program.

I tried to solve this by writing the following functions, in order to
try to start the socket connection again:

So now you have two problems. When there's a bug in your program, it's
usually best to hunt it down, rather than to add more code with more bugs
:-)

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


Re: Does '#hash' mean anything in IDLE?

2006-03-03 Thread Blackbird
John Coleman [EMAIL PROTECTED] skrev:

 John Salerno wrote:
 John Coleman wrote:
 John Coleman wrote:
 Greetings,
I am currently trying to learn Python through the excellent
 Learning Python book.

 me too!

 It isn't just #hash, but also things like #dict, #int, #len at the
 start of a comment line which defeats IDLE's colorization algorithm.
 Interestingly, things like #while or #for behave as expected so it
 seems to be built-ins rather than keywords which are the problem. To
 answer my own question - this is pretty clearly a (harmless) bug.

 also notice that putting a space after # stops the problem

 How do you like Python so far? I like dictionary objects the best so
 far. I'm coming to Python from VBScript, so I already knew the value
 of such things, but in Python they are better supported.

 Here is the program I was talking about, which *really* shows the
 power of dictionaries:



*

 #Python program to discover word with most 1-word anagrams
[...]

Nice!

I think this simpler version of letter_hash should work too:

def letter_hash(word):
w = [c for c in word]
w.sort()
return .join(w)


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


Re: do design patterns still apply with Python?

2006-03-03 Thread Irmen de Jong
Roy Smith wrote:
 
 For example, the Factory pattern is mostly to work around the fact that
 it's difficult in Java and C++ to dynamically load classes.
 
 You're over-specifying.  Most of most design patterns is to work around the 
 fact that it's difficult in Java and C++ to do many things.

+1 QOTW!

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


Re: how do you move to a new line in your text editor?

2006-03-03 Thread Mystilleef
On Linux you can try out Scribes. It has a function to convert tabs to
spaces. Personally, I use tabs in all my projects.

http://scribes.sf.net/snippets.htm

http://scribes.sf.net/

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


Re: Convert dictionary to HTTP POST

2006-03-03 Thread Fredrik Lundh
Laszlo Zsolt Nagy wrote:

 The values of some inputs are encoded using html entities.
 How can I decode a string like Bessy#39;s cat  in Bessy's cat?

this snippet might help:

http://effbot.org/zone/re-sub.htm#strip-html

/F 



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


Re: Write a GUI for a python script?

2006-03-03 Thread Lou Pecora
In article [EMAIL PROTECTED],
 Matthias Huening [EMAIL PROTECTED] wrote:

 Glurt Wuntal (02.03.2006 15:56):
  I am a newbie with Python. It's a great language, but I would like to be
  able to present a simple gui menu for some of my scripts; something better
  than using 'raw_input' prompts.
  
 
 If you only need some dialogs, input and/or message boxes, you could start 
 with EasyGUI.
 http://www.ferg.org/easygui/
 
 Matthias


Matthias,

Thanks for pointing that out.  I got EasyGUI and it works right out of 
the box.  Very nice for quick and dirty GUI stuff.  Maybe some good 
examples of using Tkinter, too.  It is only version 0.72 and hasn't been 
updated by the author since 2004.  But it does work and is simple enough 
that novice users like me might be able to maintain it and extend it.  
Many thanks to the author (Stephen Ferg) for producing EasyGUI.

By the way it was written on a Windows machine and worked perfectly (so 
far) on my Mac OS X machine.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket freezes

2006-03-03 Thread Steve Holden
Luis P. Mendes wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hi,
 
 I've developed a program that uses a socket to receive information 24h a
 ~ day.
 
 The problem is that the socket seems to freeze.  By that I mean the
 program stops getting information but doesn't raise any error.
 
 I tried to solve this by writing the following functions, in order to
 try to start the socket connection again:
 
 def keepAlive(self):
 ~self.alive = 0
 ~tnow = time.time()
 ~if tnow - self.lastTime  90:   # last time got from last string
 received from the socket
 ~self.alive = 1
 
 def reSocket():
 ~print socket has failed, time.strftime('%X', time.localtime())
 ~time.sleep(60)
 ~l=GServer()  # new instance that contains the socket
 
 reSocket is triggered when self.alive is 1.
 
 But it hasn't solved my problem.  These functions have effect only after
 I do a ^C, and even then, the socket doesn't start to acquire new input.
 
 Any clues you can give me about this?
 
Try setting a default timeout on the socket, and if it times out 
recontact the other system on a new socket. See socket.setdefaultimeout()

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-03-03 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 # Print new list
 print recordList
 
 
[872L, 'ACTIVE', DbiDate object at 011F6000, DbiDate object at 
00EA1428, None, '1.0.0.0', None, None, None]

Read the Python library manual chapter 2. Read all of it, it's all
very useful information, but take a particular look at str() and
repr(). All Python object can be viewed in two standard ways, via
the str() or repr() functions. In short, the str() stringification
is typically to be more end-user friendly, while the repr() stringi-
fication is more intended to properly identify exactly what kind of
an object we see: what type it is, and often the value too. (Above,
you don't see any reasonable value at all in the DbiDate objects,
but for some reason that didn't seem to bother you as much as the
suffixed L on the long ints.)

When you just print a Python object x of some kind, i.e.

print x

it will be equivalent of

print str(x)

To see the other representation, use

print repr(x)

Python collections, such as lists, tuples and dicts, aren't really
intended to be printed as is to end users. If recordList is a list,
and there is a statement print recordList, it's probable that it
is intended as a diagnostic help to a programmer during development,
rather than to an end user. So, it's rather clever to use the repr()
stringification, so that it's clear exactly what we see, e.g. all
strings are quoted, so you clearly see things as trailing spaces,
can differentiate between tabs and sequences of spaces, and aren't
confused by commas inside the strings. Also, for longs, you get a
trailing L to indicate that this isn't simply a normal integer, but
an arbitrarily long one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best python module for Oracle, but portable to other RDBMSes

2006-03-03 Thread dananrg
[EMAIL PROTECTED] wrote:
 dananrg Are you saying I'm getting the L as an artifact of printing?

 No, you're getting the L because you're printing a long integer.  If you
 execute

 x = 872L
 y = 872

 at a Python prompt, x will be a long integer and y will be an integer.  Long

Thanks Skip. Much appreciated.

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


Re: Write a GUI for a python script?

2006-03-03 Thread Jeff Quandt
Title: Re: Write a GUI for a python script?






Glurt Wuntal (02.03.2006 15:56):

 I am a newbie with Python. It's a great language, but I would like to be

 able to present a simple gui menu for some of my scripts; something better

 than using 'raw_input' prompts.




Another option is to use Jython, which allows you access to Java as well. So, you can can write the procedural aspects in Python and add GUI support from Java. You're probably looking for Tkinter, but I thought I'd throw the Jython option out there.

Jeff 



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

Re: Printing a file

2006-03-03 Thread Florian Diesch
Fabian Steiner [EMAIL PROTECTED] wrote:
 I am currently working on an application where the user is able to 
 create new worksheets and to delete existing ones. All of these 
 worksheets have the same structure (-- template?), only some values 
 should be changed. A minimal example would be something like this:

 Name: ...
 Role: 
 Address: 

 The values are stored in a SQLite database. Now I would like to offer 
 the possibility to print out a single record on a DinA4 paper. In order 
 to do this, the dots (...) above of course have to be replaced by the 
 current record's values and the different parts have to fit on one page.

 Unfortunately I don't know how to realize this, since also some images 
 and different boxes should be printed out. As the whole application is 
 based on QT, QPrinter might be used, but I couldn't find any examples 
 how to use it.

 What do you suggest? Which format should the template have? (XML, etc.?)

I would either use something like ReportLab to create PDF or some
external type-setting language like LaTeX, *roff or docbook if they are
availabled.




   Florian
-- 
No no no! In maths things are usually named after Euler, or the first
person to discover them after Euler.
[Steven D'Aprano in [EMAIL PROTECTED]]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setattr question

2006-03-03 Thread Gerard Flanagan
bruno at modulix wrote:
 Gerard Flanagan wrote:
  The functions were kind of related
  and meaningless outside the module they were declared -

 FWIW (and from the snippet I saw), these functions are useless even in
 the module !-)


ok, ok... :-)

 Unless you want to dynamically choose the concrete class at runtime
 based on platform/settings/phase of the moon/whatnot (which seems not to
 be te case in the snippet you posted), you don't need these functions,
 just instanciating the concrete class is enough. Remember that Python
 classes *are* factory already - and that you can freely replace a class
 by any callable returning an instance, ie:

 == before refactoring, directly instanciating concrete class ==
 # myhtmlmodule.py
 class HtmlElement(tag, *args, **kw):
   # code here

 # myclientmodule.py
 from myhtmlmodule import HtmlElement
 ul = HtmlElement('ul')


 == after refactoring, using a factory function ==
 # myhtmlmodule.py
 class _HtmlElement1(tag, *args, **kw):
   # code here

 class _HtmlElement2(tag, *args, **kw):
   # other code here

 # yes, it's now a function...
 def HtmlElement(tag, *args, **kw):
   if phase_of_the_moon():
 klass = _HtmlElement1
   else:
 klass = _HtmlElement2
   return klass(tag, *args, **kw)

 # myclientmodule.py
 # well... nothing changed here !-)
 from myhtmlmodule import HtmlElement
 ul = HtmlElement('ul')


ah, I'm getting it.


  I've ditched the factory class in any case:
 
  http://gflanagan.net/site/python/htmlbuilder/HtmlBuilder.py
  (FWIW)

 Seems mostly clean. May I suggest a couple small corrections/improvements ?

 1/ potential bugfix:
 try:
 from tidy import parseString
 except ImportError:
 def parseString(text):
 # woops, this function is supposed to return something
 #pass
 return text

 2/ safer and cleaner
 class HtmlPage(HtmlElement):
 # removed class vars,
 # replaced with default in __init__
 def __init__(self, title, **kw):
 self.title = title
   self.stylesheets = kw.get('stylesheets', [])
 self.doctype = kw.get('doctype', HTML4_STRICT)


That's much better - thanks very much for taking the time, I'm a little
bit wiser!

regards

Gerard

 --
 bruno desthuilliers
 python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
 p in '[EMAIL PROTECTED]'.split('@')])

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


Re: How to find cause for Python/Pythonwin crash only on Dual Core Machines ?

2006-03-03 Thread Larry Bates
robert wrote:
 There is a strange freeze/crash only on dual core machines:
 
 I have a python app (Python 2.3.5 /Pythonwin build 203 / Windows)
 running with no stability problems on normal machines (Or a crash is so
 rare, that absolutely nobody obverses it, though the overall majority of
 users uses single core machines). Threads, network  pythonwin/win32ui
 all in use.
 
 Yet, from 3 users, _all_ using a Dual Processor System (XEON, amd x2
 3800+) computer, I have reports, that the application freezes hard
 and/or crashes with a kind of random stack dump (operating system). I
 cannot experiment with those machines.
 
 I found no hints other than:
 
 http://groups.google.de/group/comp.lang.python/browse_frm/thread/64ca033e1a7f6c61/719b147e870bd5e6
 
 
 http://sourceforge.net/tracker/?group_id=5470atid=105470func=detailaid=480325
 
 
 .. both discussions remaining in uncertainty.
 
 Are there (known) problems with Python/Pythonwin specific for dual
 core's  (py2.3.5 / pywin203) ?
 
 What could I do to find the problem?
 
 Robert
 
 
 --
 
 PS: there is very little C extension-code (SWIG) involved, yet I looked
 over that so often, I guess its save:
 
 
 //
 
 #include stdafx.h
 #include commctrl.h
 #include ext.h
 
 BOOL APIENTRY DllMain( HANDLE hModule,
DWORD  ul_reason_for_call,
LPVOID lpReserved
  )
 {
 return TRUE;
 }
 
 class CAllowThreads {
 public:
 PyThreadState *_save; \
 CAllowThreads() {
 _save = PyEval_SaveThread();
 }
 ~CAllowThreads() {
 PyEval_RestoreThread(_save);
 }
 };
 
 PyObject* PyListView_GetSubItemRect(
 HWND hwndLV,
 int iItem,
 int iSubItem,
 int code
 //LPRECT lpRect
 )
 {
 RECT r;
 {
   CAllowThreads _t;
   ListView_GetSubItemRect(
 hwndLV,
 iItem,
 iSubItem,
 code,
 r );
 }
 return Py_BuildValue(, r.left,r.top,r.right,r.bottom);
 
 }
 
 int GetStringAddr(const char* s) {
 return (int)s;
 }
 
 int PlaySoundResource(int resid, HMODULE hmod)
 {
 CAllowThreads _t;
 return PlaySound(MAKEINTRESOURCE(resid), hmod, SND_RESOURCE);
 }
 
 int PlaySoundFile(const char* fname, int flag)
 {
 CAllowThreads _t;
 return PlaySound(fname, NULL, flag);
 }
 
 PyObject* py_ToolTipRelayMsg(  PyObject* self, PyObject* args )
 {
 MSG msg;
 HWND hwTT;
 if(!PyArg_ParseTuple(args,i(i(ii)):ToolTipRelayMsg,
  hwTT,
 
 msg.hwnd,msg.message,msg.wParam,msg.lParam,msg.time,
  msg.pt, ((int*)msg.pt)+1) )
 return NULL;
 
 
 {
   CAllowThreads _t;
   SendMessage(hwTT,TTM_RELAYEVENT,0,(LPARAM)msg);
 }
 
 Py_INCREF( Py_None );
 return Py_None;
 }
 
 ---
 
 GetStringAddress is used only once like this (leades to correct NUL
 termination I think):
 
 self.sb.SendMessage(commctrl.SB_SETTEXT,iPane,extension.GetStringAddr(text))
 
 
 --- swig:
 static PyObject *_wrap_GetStringAddr(PyObject *self, PyObject *args) {
 PyObject *resultobj;
 char *arg0 ;
 int result ;
 
 if(!PyArg_ParseTuple(args,(char *)s:GetStringAddr,arg0)) return
 NULL;
 result = (int )GetStringAddr((char const *)arg0);
 resultobj = PyInt_FromLong((long)result);
 return resultobj;
 }

I've run on Dual 1.7, 2.4Ghz Xeon machines and a hyperthreaded
3.0Ghz machine for several years with no problems.  I don't think
there is an inherent problem.

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


Re: ODBC module and strange date reference ...

2006-03-03 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 Incidentally, I have just ordered:
 
 * Learning Python
 * Python Cookbook
 * Python Pocket Reference
 
 Are there any other books y'all would recommend as essential Python
 references and/or books for becoming fluent in Python?

Both Beazley's Python Essential Reference and Martelli's
Python in a Nutshell are good reference books. I think
Beazley's book has just been released in its 3rd edition,
and I understand that Alex is working on the 2nd edition
of the Nutshell book.

They are both good, so if you don't want to wait, I think
you should get Beazley's book, which should be more up to
date than the 1st ed of the Nutshell book.

I think Chris Fehily's Python: Visual Quickstart Quide
was good too. The 2nd ed is due in April. It might be a
bit redundant if you have Learning Python though.

I guess the same goes for Magnus Lie Hetlands new book.

If you are working with Python on Windows and want to use
COM or other Windows features, you might want to get Python
Programming on Win32 by Hammond and Robinson. It's six
years old, so it's not 100% up to date, but I think it's
the only book that covers Windows programming with Python
in detail.

There are also good books concerning other spcific topics
such as text processing, networking, GUI development etc,
but don't get all the books at once. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string stripping issues

2006-03-03 Thread Larry Bates
orangeDinosaur wrote:
 Hello,
 
 I am encountering a behavior I can think of reason for.  Sometimes,
 when I use the .strip module for strings, it takes away more than what
 I've specified.  For example:
 
 a = 'TD WIDTH=175FONT SIZE=2Hughes. John/FONT/TD\r\n'
 
 a.strip('TD WIDTH=175FONT SIZE=2')
 
 returns:
 
 'ughes. John/FONT/TD\r\n'
 
 However, if I take another string, for example:
 
 b = 'TD WIDTH=175FONT SIZE=2Kim, Dong-Hyun/FONT/TD\r\n'
 
 b.strip('TD WIDTH=175FONT SIZE=2')
 
 returns:
 
 'Kim, Dong-Hyun/FONT/TD\r\n'
 
 I don't understand why in one case it eats up the 'H' but in the next
 case it leaves the 'K' alone.
 
Others have explained the exact problem, I'll make a suggestion.
Take a few minutes to look at BeautifulSoup.  It parses HTML code
and allows for extractions of data from strings like this in a
very easy to use way.  If this is a one-off thing, don't bother.
If you do this commonly, BeautifulSoup is worth a little study.

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


cx_Freeze 3.0.2 and Linux sax problem.

2006-03-03 Thread 1stpoint
I am banging my head against the wall.

I have a Web application server that uses xml.sax.  When I build it
using FreezePython I get the following error when trying to use it:


File /usr/lib/python2.3/site-packages/_xmlplus/sax/sax2exts.py, line
37, in make_parser
File /usr/lib/python2.3/site-packages/_xmlplus/sax/saxexts.py, line
77, in make_parser
SAXReaderNotAvailable: No parsers found

My command is ./FreezePython --include-modules encodings myscript.py  I
don't see any errors during the build process.  I also statically
import xml and pyexpat within the script itself.

Please help ASAP.

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


Incorrect Decimal-Float behaviour in comparison tests

2006-03-03 Thread Cassiano, Marco
I have difficulties with a weird Python 2.4.2 behaviour in comparing Decimal to 
Floats.

For Example :


 from decimal import Decimal
 a=Decimal('3.7')
 b=6.3

 if a  b :print a,b,'a is greater than b - NOT TRUE'
... else: print a,b,'b is greater than a - CORRECT'
... 


3.7 6.3 a is greater than b - NOT TRUE


Have you ever encountered this behaviour ? It seems a bug to me...
Do you konw if there is any patch available for this?

Thank you very much
 

Marco Cassiano 
  
Manifatture del Nord srl unipersonale
Gruppo MaxMara 

viale Regina Elena 13-15 
42100 Reggio Emilia RE 
ITALY 

Sede operativa:
via Mazzacurati 6
42100 Reggio Emilia RE
ITALY 

Tel. +39 0522 358215 
Fax +39 0522 268715 
email : [EMAIL PROTECTED] 


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


Re: Incorrect Decimal-Float behaviour in comparison tests

2006-03-03 Thread Steve Holden
Cassiano, Marco wrote:
 I have difficulties with a weird Python 2.4.2 behaviour in comparing Decimal 
 to Floats.
 
 For Example :
 
 
 
from decimal import Decimal
a=Decimal('3.7')
b=6.3
 
 
if a  b :print a,b,'a is greater than b - NOT TRUE'
 
 ... else: print a,b,'b is greater than a - CORRECT'
 ... 
 
 
 3.7 6.3 a is greater than b - NOT TRUE
 
 
 Have you ever encountered this behaviour ? It seems a bug to me...
 Do you konw if there is any patch available for this?
 
   if a  Decimal(str(b)):
  ...   print oh oh!
  ... else:
  ...   print This looks better
  ...
This looks better
  

Decimals and floats aren't meant to be directly compared. You can't 
even convert a float directly into a Decimal:

   Decimal(3.7)
Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/lib/python2.4/decimal.py, line 534, in __new__
 raise TypeError(Cannot convert float to Decimal.   +
TypeError: Cannot convert float to Decimal.  First convert the float to 
a string

So what you are seeing is the result of a comparison based on types: you 
will probably find that all floats compare less than all Decimals.

The correct thing to do is apply the float() function to Decimals before 
comparing them with other floats:

   if float(a)  float(b):
  ...   print a  b
  ... else:
  ...   print b  a
  ...
b  a
  

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Re: scipy

2006-03-03 Thread Robert Kern
computer1 wrote:
 I want to install scipy 0.4.6 (windows)on my computer ,but i cannot
 download it from www.scipy.org. who can tell me another place to
 download it?

http://www.scipy.org/Download

links to the Sourceforge download site. I assume that you are trying to download
the files by simply right-clicking the URL and picking Save Link As... from
the context menu (or whatever it is in your browser). Sourceforge has a mirror
selection system that gets in the way. Just click on the link, and select an
appropriate mirror from that page. Then your real download will continue.

I expect that we will be placing tarballs on PyPI soon.

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter

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


Re: how do you move to a new line in your text editor?

2006-03-03 Thread John Salerno
Mc Osten wrote:
 On Thu, 02 Mar 2006 18:58:50 GMT, John Salerno wrote:
 
 I use UltraEdit right now, and it is possible to convert spaces and tabs 
 back and forth, but it's just an extra step.
 
 I wouldn't definitely suggest UltraEdit to code Python.

Why do you say that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incorrect Decimal-Float behaviour in comparison tests

2006-03-03 Thread Fredrik Lundh
Cassiano, Marco wrote:

 I have difficulties with a weird Python 2.4.2 behaviour in comparing
 Decimal to Floats.

 For Example :


  from decimal import Decimal
  a=Decimal('3.7')
  b=6.3

  if a  b :print a,b,'a is greater than b - NOT TRUE'
 ... else: print a,b,'b is greater than a - CORRECT'
 ...


 3.7 6.3 a is greater than b - NOT TRUE

is this

 1.0  0
False

also a bug ?

http://www.python.org/doc/ref/comparisons.html

Most other types compare unequal unless they are the
same object; the choice whether one object is considered
smaller or larger than another one is made arbitrarily but
consistently within one execution of a program.

you can find more information on the design of the decimal type
here:

http://www.python.org/peps/pep-0327.html

and various issues with floating point are described here:

http://docs.python.org/tut/node16.html

/F



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


  1   2   3   >