Re: Help with PyQt4 tabwidget setup

2010-05-24 Thread Neil Wallace
On Fri, 21 May 2010 08:03:43 +0200, dpalmboom wrote:

> I am creating an application and I'm busy designing the main layout on
> the main window. What I would like to do is the following:
> 
> Create a QTabWidget with a QVBoxLayout already inside it and also a
> scrollbar inside it. When a user triggers a menu item, a QDockWidget
> must be created and inserted into the QVBoxLayout, but it must not
> stretch to the bottom of the QTabWidget. The QDockWidget must keep a set
> size in the QVBoxLayout. When the user triggers another menu item, the
> next QDockWidget must go above or below the existing QDockWidgets in the
> QVBoxLayout.
> 
> I currently have the following code for the QTabWidget:
> 
> class PaneTabWidget(PyQt4.QtGui.QTabWidget):
> 
> def __init__(self, tabs, parent=None):
> 
> """
> A tabwidget to go inside a Pane.
> """
> 
> super(PaneTabWidget, self).__init__(parent)
> 
> for tab in tabs:
> 
> if tab == "Properties":
> self.propertiesBin()
> elif tab == "Schedule":
> self.scheduleBin()
> elif tab == "Pricelist":
> self.pricelistBin()
> 
> def setLayoutAndScrollBar(self, page):
> pass
> 
> def addPanel(self, panel, type):
> self.addTab(panel, type)
> 
> def propertiesBin(self):
> self.page = PyQt4.QtGui.QWidget()
> self.addTab(self.page, "Properties")
> self.setLayoutAndScrollBar(self.page)
> 
> Right now, the dockwidget gets put into a new tab in the tab widget, but
> I would like to put it into an existing QVBoxLayout. I currently have a
> blank QWidget as a "placeholder" page of the tabwidget.
> 
> If anyone can help me with this, it would be greatly appreciated.
> 
> Thanks


Hi,

not 100% sure what you are after, but perhaps a standard tabWidget, with 
a customised Scrollarea forming the panel is one way?

from PyQt4 import QtGui

class TabPane(QtGui.QScrollArea):
def __init__(self, parent=None):
super(TabPane, self).__init__(parent)
frame = QtGui.QFrame(self)
frame.setFixedSize(300,200)
self.setWidget(frame)
self.layout = QtGui.QVBoxLayout(frame) 

def addDock(self, title):
dw = QtGui.QDockWidget(title, self)
self.layout.addWidget(dw)

if __name__ == "__main__":
app = QtGui.QApplication([])

tab_widget = QtGui.QTabWidget()
for heading in ["Properties", "Schedule", "Pricelist"]:
pane = TabPane()
pane.addDock("Hello World")
pane.addDock("Hello Galaxy")
pane.addDock("Hello Universe")

tab_widget.addTab(pane , heading)

tab_widget.show()
app.exec_()

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


Re: logging: AttributeError: 'module' object has no attribute 'getLogger'

2010-05-24 Thread Frank GOENNINGER
Simon Brunning  writes:

> On 23 May 2010 14:46, Frank GOENNINGER  wrote:
>> Traceback (most recent call last):
>>  File "/.../src/pib/logging.py", line 37, in 
>>    main()
>
> Here's a clue - looks like your own module is called logging. That's
> what's getting imported by your import. Try naming your module
> something else, and you should be golden.

Yep. That was it. Thanks !!

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


Re: logging: AttributeError: 'module' object has no attribute 'getLogger'

2010-05-24 Thread Frank GOENNINGER
Philip Semanchuk  writes:

> On May 23, 2010, at 9:46 AM, Frank GOENNINGER wrote:
>>
>> I double checked and yes, getLogger is there. Why is the interpreter
>> asking for an "attribute" here ? Any hints on what I am doing wrong ?
>
>
> Short answer: Change the name of src/pib/logging.py to something else.

Done.

> Long answer: When Python hits the line "import logging", it first
> looks in the current directory and imports logging.py, which in this
> case is the file it's already executing. It never finds the standard
> library's logging module.
>
> One way you could have figured this out would be to add this as the
> first line of main():
>print dir(logging)
>
> That would have told you what Python thought the logging module looked
> like, and would have perhaps recognized it as your own.

Thanks - learned a lot from your post.

>
> Cheers
> Philip

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


launching vi/vim from console

2010-05-24 Thread adm
I am newbie to python.
Is there a way to launch vi/vim or any other editor from python
console? I find editing in console very limiting. I can either have a
console which launches vi and remembers it's content and then executes
or invoke python interpreter from vim.

Since I could not find anything I wrote this: 
http://python.pastebin.com/MFTHxuLe
Please suggest if there is any better alternative for this.
I tried googling for this but could not find anything interesting.

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


Email in 2.6.4

2010-05-24 Thread dirknbr
I am trying to run

from email.mime.text import MIMEText

but I get an

ImportError: No module named mime.text

Since email was pre-installed how do I fix this?

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


Re: launching vi/vim from console

2010-05-24 Thread Jean-Michel Pichavant

adm wrote:

I am newbie to python.
Is there a way to launch vi/vim or any other editor from python
console? I find editing in console very limiting. I can either have a
console which launches vi and remembers it's content and then executes
or invoke python interpreter from vim.

Since I could not find anything I wrote this: 
http://python.pastebin.com/MFTHxuLe
Please suggest if there is any better alternative for this.
I tried googling for this but could not find anything interesting.

Thanks,
Adm
  

import os
os.system.('vi')


or you can start an ipython shell
and start vi using
!vi
--
http://mail.python.org/mailman/listinfo/python-list


Can upper() or lower() ever change the length of a string?

2010-05-24 Thread Steven D'Aprano
Do unicode.lower() or unicode.upper() ever change the length of the 
string?

The Unicode standard allows for case conversions that change length, e.g. 
sharp-S in German should convert to SS:

http://unicode.org/faq/casemap_charprop.html#6

but I see that Python doesn't do that:

>>> s = "Paßstraße"
>>> s.upper()
'PAßSTRAßE'


The more I think about this, the more I think that upper/lower/title case 
conversions should change length (at least sometimes) and if Python 
doesn't do so, that's a bug. Any thoughts?


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


Re: Can upper() or lower() ever change the length of a string?

2010-05-24 Thread Mark Dickinson
On May 24, 1:13 pm, Steven D'Aprano  wrote:
> Do unicode.lower() or unicode.upper() ever change the length of the
> string?

>From looking at the source, in particular the fixupper and fixlower
functions in Objects/unicode.c [1], it looks like not:  they do a
simple character-by-character replacement.

[1] http://svn.python.org/view/python/trunk/Objects/unicodeobject.c?view=markup
--
Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launching vi/vim from console

2010-05-24 Thread adm
On May 24, 4:59 pm, Jean-Michel Pichavant 
wrote:
> adm wrote:
> > I am newbie to python.
> > Is there a way to launch vi/vim or any other editor from python
> > console? I find editing in console very limiting. I can either have a
> > console which launches vi and remembers it's content and then executes
> > or invoke python interpreter from vim.
>
> > Since I could not find anything I wrote 
> > this:http://python.pastebin.com/MFTHxuLe
> > Please suggest if there is any better alternative for this.
> > I tried googling for this but could not find anything interesting.
>
> > Thanks,
> > Adm
>
> import os
> os.system.('vi')
>
> or you can start an ipython shell
>  and start vi using
> !vi

Thanks. I wanted something like ipython.
I will give it a try.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can upper() or lower() ever change the length of a string?

2010-05-24 Thread Mark Dickinson
On May 24, 1:13 pm, Steven D'Aprano  wrote:
> Do unicode.lower() or unicode.upper() ever change the length of the
> string?
>
> The Unicode standard allows for case conversions that change length, e.g.
> sharp-S in German should convert to SS:
>
> http://unicode.org/faq/casemap_charprop.html#6
>
> but I see that Python doesn't do that:
>
> >>> s = "Paßstraße"
> >>> s.upper()
>
> 'PAßSTRAßE'
>
> The more I think about this, the more I think that upper/lower/title case
> conversions should change length (at least sometimes) and if Python
> doesn't do so, that's a bug. Any thoughts?

Digging a bit deeper, it looks like these methods are using the
Simple_{Upper,Lower,Title}case_Mapping functions described at
http://www.unicode.org/Public/5.1.0/ucd/UCD.html fields 12, 13 and 14
of the unicode data;  you can see this in the source in Tools/unicode/
makeunicodedata.py, which is the Python code that generates the
database of unicode properties.  It contains code like:

if record[12]:
upper = int(record[12], 16)
else:
upper = char
if record[13]:
lower = int(record[13], 16)
else:
lower = char
if record[14]:
title = int(record[14], 16)

... and so on.

I agree that it might be desirable for these operations to product the
multicharacter equivalents.  That idea looks like a tough sell,
though:  apart from backwards compatibility concerns (which could
probably be worked around somehow), it looks as though it would
require significant effort to implement.

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


Re: Email in 2.6.4

2010-05-24 Thread Jean-Michel Pichavant

dirknbr wrote:

I am trying to run

from email.mime.text import MIMEText

but I get an

ImportError: No module named mime.text

Since email was pre-installed how do I fix this?

Dirk
  
Did you make sure you didn't hide the standard email module by one of 
your own.

Check
print email.__file__
/usr/lib/python2.5/email/__init__.pyc

If the path is correct, you may want to look in the code, or if anything 
has changed in 2.6, I guess it is documented somewhere.


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


extracting unicode text from pdfs

2010-05-24 Thread Eknath Venkataramani
I have around 45 pdfs to convert into raw text containing text in _HINDI_ .
When I use the xpdf package, the generated text is very weird, so I'd like
to write a program which would convert the pdf text into Unicode text as it
is.

The fonts used in the pdfs:
name   type  emb sub uni object
ID
 - --- --- --- -
APKAPP+Usha-Bold Type 1C   yes yes yes 72  0
APKBBB+Agenda-Light  Type 1C   yes yes yes 77  0
APKBGF+Usha  Type 1C   yes yes yes 41  0
APKBKJ+Agenda-Medium Type 1C   yes yes yes 46  0
APKBON+Agenda-Bold   Type 1C   yes yes yes 49  0

For eg. in the pdf: आदमी मुसाफिर है
  when I use pdftotext, I get some very weird symbols: '...
...'
 while i'd like 'आदमी मुसाफिर है' to be the output


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


Re: Email in 2.6.4

2010-05-24 Thread dirknbr
I have now easy_installled email and I still get errors.

It doesn't error on 'import email' but does on call to MimeText.

import email
msg = MIMEText('test')

NameError: name 'MIMEText' is not defined

What should I do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-24 Thread Raymond Hettinger
On May 19, 12:58 pm, superpollo  wrote:
> ... how many positive integers less than n have digits that sum up to m:
>
> In [197]: def prttn(m, n):
>      tot = 0
>      for i in range(n):
>          s = str(i)
>          sum = 0
>          for j in range(len(s)):
>              sum += int(s[j])
>          if sum == m:
>              tot += 1
>      return tot
>     .:
>
> In [207]: prttn(25, 1)
> Out[207]: 348
>
> any suggestion for pythonizin' it?

Your code is readable and does the job just fine.
Not sure it is an improvement to reroll it into a one-liner:

def prttn(m, n):
return sum(m == sum(map(int, str(x))) for x in range(n))
>>> prttn(25, 1)
348

Some people find the functional style easier to verify because of
fewer auxilliary variables and each step is testable independently.
The m==sum() part is not very transparent because it relies on
True==1, so it's only readable if it becomes a common idiom (which it
could when you're answering questions of the form "how many numbers
have property x").

If speed is important, the global lookups can be localized:

def prttn(m, n, map=itertools.imap, int=int, str=str, range=range):
return sum(m == sum(map(int, str(x))) for x in range(n))

Raymond



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


Re: [BangPypers] extracting unicode text from pdfs

2010-05-24 Thread Dhananjay Nene
You may want to try out pdfminer. Its very similar to xpdf in structure and
should give you the parsed data into unicode directly.

On Mon, May 24, 2010 at 7:13 PM, Eknath Venkataramani  wrote:

> I have around 45 pdfs to convert into raw text containing text in _HINDI_ .
> When I use the xpdf package, the generated text is very weird, so I'd like
> to write a program which would convert the pdf text into Unicode text as it
> is.
>
> The fonts used in the pdfs:
> name   type  emb sub uni object
> ID
>  - --- --- ---
> -
> APKAPP+Usha-Bold Type 1C   yes yes yes 72
>  0
> APKBBB+Agenda-Light  Type 1C   yes yes yes 77
>  0
> APKBGF+Usha  Type 1C   yes yes yes 41
>  0
> APKBKJ+Agenda-Medium Type 1C   yes yes yes 46
>  0
> APKBON+Agenda-Bold   Type 1C   yes yes yes 49
>  0
>
> For eg. in the pdf: आदमी मुसाफिर है
>  when I use pdftotext, I get some very weird symbols: '...
> ...'
> while i'd like 'आदमी मुसाफिर है' to be the output
>
>
> --
> Eknath Venkataramani
> ___
> BangPypers mailing list
> bangpyp...@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 

blog: http://blog.dhananjaynene.com
twitter: http://twitter.com/dnene
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email in 2.6.4

2010-05-24 Thread Simon Brunning
On 24 May 2010 14:59:24 UTC+1, dirknbr  wrote:
> It doesn't error on 'import email' but does on call to MimeText.
>
> import email
> msg = MIMEText('test')
>
> NameError: name 'MIMEText' is not defined

Here you want:

msg = email.MIMEText('test')

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email in 2.6.4

2010-05-24 Thread Jean-Michel Pichavant

dirknbr wrote:

I have now easy_installled email and I still get errors.

It doesn't error on 'import email' but does on call to MimeText.

import email
msg = MIMEText('test')

NameError: name 'MIMEText' is not defined

What should I do?
  
Using easy_install will not prevent the standard lib to be shadowed by 
another (user) module.


did you print email.__file__ to verify the path ?
Can you show us the output ?

To give you an example, on a lenny python 2.5 distrib, the MIMEText 
class is in

/usr/lib/python2.5/email/mime/text.py

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


Re: Email in 2.6.4

2010-05-24 Thread Mark Lawrence

On 24/05/2010 14:59, dirknbr wrote:

I have now easy_installled email and I still get errors.
I've done this as well, but don't see why I have to.  Is this a 
documentation bug, an installation bug or what?


It doesn't error on 'import email' but does on call to MimeText.

import email
msg = MIMEText('test')

NameError: name 'MIMEText' is not defined

What should I do?

Give the fully qualified name i.e. email.mime.text.MIMEText.

Regards.

Mark Lawrence.

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


Re: Email in 2.6.4

2010-05-24 Thread Dirk Nachbar
Sorry guys, I had named my file email.py and hence the error.



On 24 May 2010 15:22, Jean-Michel Pichavant  wrote:

> dirknbr wrote:
>
>> I have now easy_installled email and I still get errors.
>>
>>
>> It doesn't error on 'import email' but does on call to MimeText.
>>
>> import email
>> msg = MIMEText('test')
>>
>> NameError: name 'MIMEText' is not defined
>>
>> What should I do?
>>
>>
> Using easy_install will not prevent the standard lib to be shadowed by
> another (user) module.
>
> did you print email.__file__ to verify the path ?
> Can you show us the output ?
>
> To give you an example, on a lenny python 2.5 distrib, the MIMEText class
> is in
> /usr/lib/python2.5/email/mime/text.py
>
> JM
>



-- 
http://dirknbr.googlepages.com
http://maximum-likely.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can upper() or lower() ever change the length of a string?

2010-05-24 Thread MRAB

Mark Dickinson wrote:

On May 24, 1:13 pm, Steven D'Aprano  wrote:

Do unicode.lower() or unicode.upper() ever change the length of the
string?

The Unicode standard allows for case conversions that change length, e.g.
sharp-S in German should convert to SS:

http://unicode.org/faq/casemap_charprop.html#6

but I see that Python doesn't do that:


s = "Paßstraße"
s.upper()

'PAßSTRAßE'

The more I think about this, the more I think that upper/lower/title case
conversions should change length (at least sometimes) and if Python
doesn't do so, that's a bug. Any thoughts?


Digging a bit deeper, it looks like these methods are using the
Simple_{Upper,Lower,Title}case_Mapping functions described at
http://www.unicode.org/Public/5.1.0/ucd/UCD.html fields 12, 13 and 14
of the unicode data;  you can see this in the source in Tools/unicode/
makeunicodedata.py, which is the Python code that generates the
database of unicode properties.  It contains code like:

if record[12]:
upper = int(record[12], 16)
else:
upper = char
if record[13]:
lower = int(record[13], 16)
else:
lower = char
if record[14]:
title = int(record[14], 16)

... and so on.

I agree that it might be desirable for these operations to product the
multicharacter equivalents.  That idea looks like a tough sell,
though:  apart from backwards compatibility concerns (which could
probably be worked around somehow), it looks as though it would
require significant effort to implement.


If we were to make such a change, I think we should also cater for
locale-specific case changes (passing the locale to 'upper', 'lower' and
'title').

For example, normally "i".upper() returns "I", but in Turkish
"i".upper() should return "İ" (the uppercase version of lowercase dotted
i is uppercase dotted I).
--
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-24 Thread Jean-Michel Pichavant

Jerry Hill wrote:

On Wed, May 19, 2010 at 3:58 PM, superpollo  wrote:
  

... how many positive integers less than n have digits that sum up to m:


...
  

any suggestion for pythonizin' it?



This is how I would do it:

def prttn(m, n):
"""How many positive integers less than n have digits that sum up to m"""
total = 0
for testval in range(n):
sumofdigits = sum(int(char) for char in str(testval))
if sumofdigits == m:
total += 1
return total

I added a docstring to the function, saying what it does, and what the
arguments are supposed to represent.  I also moved the
convert-to-string-and-sum-the-digits logic into a single generator
expression that's passed to the builtin sum function.  Oh, and I tried
to use slightly more expressive variable names.

  

my favorite solutio nso far.

@ OP

What means prttn ? is it any Dutch word :D ? m & n are also very poors 
argument names.
I will be difficult to name properly the function, as it is doing 
something ... I don't find the word, something like un-intuitive. Sounds 
like homework.


def how_many_positive_integers_less_than_n_have_digits_that_sum_up_to_m(m, n)


:o)

JM

PS : read http://tottinge.blogsome.com/meaningfulnames/


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


Re: function that counts...

2010-05-24 Thread Matteo Landi
What about avoiding the string conversion and use mod/div operations
in order to create a list of digits for a number?

Now that you have the sequences it's easy to count which sums up to m.

On Mon, May 24, 2010 at 4:14 PM, Raymond Hettinger  wrote:
> On May 19, 12:58 pm, superpollo  wrote:
>> ... how many positive integers less than n have digits that sum up to m:
>>
>> In [197]: def prttn(m, n):
>>  tot = 0
>>  for i in range(n):
>>  s = str(i)
>>  sum = 0
>>  for j in range(len(s)):
>>  sum += int(s[j])
>>  if sum == m:
>>  tot += 1
>>  return tot
>> .:
>>
>> In [207]: prttn(25, 1)
>> Out[207]: 348
>>
>> any suggestion for pythonizin' it?
>
> Your code is readable and does the job just fine.
> Not sure it is an improvement to reroll it into a one-liner:
>
> def prttn(m, n):
>return sum(m == sum(map(int, str(x))) for x in range(n))
 prttn(25, 1)
> 348
>
> Some people find the functional style easier to verify because of
> fewer auxilliary variables and each step is testable independently.
> The m==sum() part is not very transparent because it relies on
> True==1, so it's only readable if it becomes a common idiom (which it
> could when you're answering questions of the form "how many numbers
> have property x").
>
> If speed is important, the global lookups can be localized:
>
> def prttn(m, n, map=itertools.imap, int=int, str=str, range=range):
>return sum(m == sum(map(int, str(x))) for x in range(n))
>
> Raymond
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email in 2.6.4

2010-05-24 Thread Jean-Michel Pichavant

Dirk Nachbar wrote:

Sorry guys, I had named my file email.py and hence the error.



On 24 May 2010 15:22, Jean-Michel Pichavant > wrote:


dirknbr wrote:

I have now easy_installled email and I still get errors.


It doesn't error on 'import email' but does on call to MimeText.

import email
msg = MIMEText('test')

NameError: name 'MIMEText' is not defined

What should I do?
 


Using easy_install will not prevent the standard lib to be
shadowed by another (user) module.

did you print email.__file__ to verify the path ?
Can you show us the output ?

To give you an example, on a lenny python 2.5 distrib, the
MIMEText class is in
/usr/lib/python2.5/email/mime/text.py

JM




Classic error, you're not the first one, and my guess is that you won't 
be the last.


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


Re: launching vi/vim from console

2010-05-24 Thread Shashwat Anand
or in a reverse way you can open vim and use ':shell' followed by python. I
prefer it that way generally

On Mon, May 24, 2010 at 6:01 PM, adm  wrote:

> On May 24, 4:59 pm, Jean-Michel Pichavant 
> wrote:
> > adm wrote:
> > > I am newbie to python.
> > > Is there a way to launch vi/vim or any other editor from python
> > > console? I find editing in console very limiting. I can either have a
> > > console which launches vi and remembers it's content and then executes
> > > or invoke python interpreter from vim.
> >
> > > Since I could not find anything I wrote this:
> http://python.pastebin.com/MFTHxuLe
> > > Please suggest if there is any better alternative for this.
> > > I tried googling for this but could not find anything interesting.
> >
> > > Thanks,
> > > Adm
> >
> > import os
> > os.system.('vi')
> >
> > or you can start an ipython shell
> >  and start vi using
> > !vi
>
> Thanks. I wanted something like ipython.
> I will give it a try.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Nathan Rice
I'm trying to do some fairly deep introspection and instrumentation of
instances and classes at runtime, and in order for everything to be properly
behaved I need to have radically different behavior in the event that the
thing passed to me is a wrapped class/instance.  Is there a really good way,
given an instance of a class, to determine if it is wrapped or native?
Currently I check to see if it has __slots__ then try to setattr a dummy
variable but I imagine there is probably a cleaner way.

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


A Quick MySQL Question

2010-05-24 Thread Victor Subervi
Hi;
I have the following:

#sql = 'alter table %s alter column %s set default "%%s";' % (store,
col)
#cursor.execute(sql, colValue)
cursor.execute('alter table %s alter column %s set default "%s";' %
(store, col, colValue))
database.commit()

Now I don't like that third line, so I tried the commented out lines, but I
got an MySQLdb.OperationalError that the suggested default value could not
be inserted. However, when I printed it out and tried to insert directly, no
problem, and the 3rd line works fine. What gives?
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can upper() or lower() ever change the length of a string?

2010-05-24 Thread Terry Reedy

On 5/24/2010 10:42 AM, MRAB wrote:

Mark Dickinson wrote:



Digging a bit deeper, it looks like these methods are using the
Simple_{Upper,Lower,Title}case_Mapping functions described at
http://www.unicode.org/Public/5.1.0/ucd/UCD.html fields 12, 13 and 14
of the unicode data; you can see this in the source in Tools/unicode/
makeunicodedata.py, which is the Python code that generates the
database of unicode properties. It contains code like:

if record[12]:
upper = int(record[12], 16)
else:
upper = char
if record[13]:
lower = int(record[13], 16)
else:
lower = char
if record[14]:
title = int(record[14], 16)

... and so on.

I agree that it might be desirable for these operations to product the
multicharacter equivalents. That idea looks like a tough sell,
though: apart from backwards compatibility concerns (which could
probably be worked around somehow), it looks as though it would
require significant effort to implement.


If we were to make such a change, I think we should also cater for
locale-specific case changes (passing the locale to 'upper', 'lower' and
'title').

For example, normally "i".upper() returns "I", but in Turkish
"i".upper() should return "İ" (the uppercase version of lowercase dotted
i is uppercase dotted I).


Given that the current (siimple) functions implement standard-defined 
functions, I think any change should be to *add* new 
'complex-case-change' functions.


Terry Jan Reedy




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


Re: Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Terry Reedy

On 5/24/2010 12:56 PM, Nathan Rice wrote:

I'm trying to do some fairly deep introspection and instrumentation of
instances and classes at runtime, and in order for everything to be
properly behaved I need to have radically different behavior in the
event that the thing passed to me is a wrapped class/instance.  Is there
a really good way, given an instance of a class, to determine if it is
wrapped or native?  Currently I check to see if it has __slots__ then
try to setattr a dummy variable but I imagine there is probably a
cleaner way.


I am not sure what you mean by 'wrapped'. Your subject line says 
something different. In any case, is your universe *all* Python objects 
or some subset?


Builtin classes, named or not, do not have dotted names

>>> 1 .__class__

>>> class C: pass

I believe all others do, including C-coded extension classes.

>>> C().__class__


tjr

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


Chatroom

2010-05-24 Thread narcissus
Hello , I want to create a program that is one chatroom and everyone
has this program can Enter into that chatroom. how can i do this?

and i want gui for it too (GTK)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Chatroom

2010-05-24 Thread Martin P. Hellwig

On 05/24/10 19:50, narcissus wrote:

Hello , I want to create a program that is one chatroom and everyone
has this program can Enter into that chatroom. how can i do this?

and i want gui for it too (GTK)


What have you tried so far?

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


D-CM IDE

2010-05-24 Thread Kruptein
I'm developing an "IDE" in python (wxPython toolkit).  it's an
application that combines a file-manager,text-editor,sql-manager,ftp-
manager and more in one simple to use GUI.

I'm releasing a new version soon and I hoped that there were some
folks in here that would like to test if it worked well..

It is a linux program and can be found here: https://launchpad.net/d-cm
the windows version (is some releases behind the linux version) can be
found here: https://launchpad.net/d-cm-win
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Duncan Booth
Terry Reedy  wrote:

> Builtin classes, named or not, do not have dotted names
> 
> >>> 1 .__class__
>
> >>> class C: pass
> 
> I believe all others do, including C-coded extension classes.
> 
> >>> C().__class__
>
> 

Not quite all. Classes created by calling the type constructor directly 
don't have to follow that rule:

>>> C = type('Fred', (object,), {})
>>> C.__name__
'Fred'
-- 
http://mail.python.org/mailman/listinfo/python-list


Question on Python Function

2010-05-24 Thread joy99


Dear Group,

I have a small question on function.

If I write two functions like the following:

IDLE 2.6.5
>>> def function1(n):
element1=5
element2=6
add=element1+element2
print "PRINT THE ADDITION",add


>>> def function2(n):
element3=7
element4=22
mult=element3*element4
print "PRINT THE MULTIPLICATION",mult

Can I now write a third function where the above two functions can be
passed as argument or parameter?

Best Regards,
Subhabrata.

NB: As I copied the code from IDLE to MS-Word befor posting here,
codes may have slight indentation errors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-24 Thread superpollo

Jean-Michel Pichavant ha scritto:

Jerry Hill wrote:

On Wed, May 19, 2010 at 3:58 PM, superpollo  wrote:
 

... how many positive integers less than n have digits that sum up to m:


...
 

any suggestion for pythonizin' it?



This is how I would do it:

def prttn(m, n):
"""How many positive integers less than n have digits that sum up 
to m"""

total = 0
for testval in range(n):
sumofdigits = sum(int(char) for char in str(testval))
if sumofdigits == m:
total += 1
return total

I added a docstring to the function, saying what it does, and what the
arguments are supposed to represent.  I also moved the
convert-to-string-and-sum-the-digits logic into a single generator
expression that's passed to the builtin sum function.  Oh, and I tried
to use slightly more expressive variable names.

  

my favorite solutio nso far.

@ OP

What means prttn ? 


i already answered this downthreads...

something ... I don't find the word, something like un-intuitive. Sounds 
like homework.


it is not.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python Function

2010-05-24 Thread Alister
On Mon, 24 May 2010 13:15:01 -0700, joy99 wrote:

> Dear Group,
> 
> I have a small question on function.
> 
> If I write two functions like the following:
> 
> IDLE 2.6.5
 def function1(n):
>   element1=5
>   element2=6
>   add=element1+element2
>   print "PRINT THE ADDITION",add
> 
> 
 def function2(n):
>   element3=7
>   element4=22
>   mult=element3*element4
>   print "PRINT THE MULTIPLICATION",mult
> 
> Can I now write a third function where the above two functions can be
> passed as argument or parameter?
> 
> Best Regards,
> Subhabrata.
> 
> NB: As I copied the code from IDLE to MS-Word befor posting here, codes
> may have slight indentation errors.

I don't quite see the point of your functions as they do not use their 
parameters in any way, but you need to set a return value

 IDLE 2.6.5
>>> def function1(n):
element1=5
element2=6
add=element1+element2
return add
 
>>> def function2(n):
element3=7
element4=22
mult=element3*element4
return mult

>>> def function3(x,y):
print "add= %s mult=%s" % (x , y)

>>>function3(function1(1),funtcion2(2))


-- 
Your digestive system is your body's Fun House, whereby food goes on a 
long,
dark, scary ride, taking all kinds of unexpected twists and turns, being
attacked by vicious secretions along the way, and not knowing until the 
last
minute whether it will be turned into a useful body part or ejected into 
the
Dark Hole by Mister Sphincter.  We Americans live in a nation where the
medical-care system is second to none in the world, unless you count maybe
25 or 30 little scuzzball countries like Scotland that we could vaporize 
in
seconds if we felt like it.
-- Dave Barry, "Stay Fit & Healthy Until You're Dead"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python Function

2010-05-24 Thread Vlastimil Brom
2010/5/24 joy99 :
>
>
> Dear Group,
>
> I have a small question on function.
>
> If I write two functions like the following:
>
> IDLE 2.6.5
 def function1(n):
>        element1=5
>        element2=6
>        add=element1+element2
>        print "PRINT THE ADDITION",add
>
>
 def function2(n):
>        element3=7
>        element4=22
>        mult=element3*element4
>        print "PRINT THE MULTIPLICATION",mult
>
> Can I now write a third function where the above two functions can be
> passed as argument or parameter?
>
> Best Regards,
> Subhabrata.
>
> NB: As I copied the code from IDLE to MS-Word befor posting here,
> codes may have slight indentation errors.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Hi,
while it is quite unclear to me, what you are trying to achieve (what
are the passed n arguments supposed to do?), you can well pass an
already defined function as an argument to another function; if you
want to select a function for the needed operation, if can be e.g.:

def compute(arg1, arg2, fn):
fn(arg1, arg2)

- supposing you don't want to "return" the result but just print it as
your functions do;
is it what you were after or did I miss something more complex?

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


Re: Question on Python Function

2010-05-24 Thread Alister
On Mon, 24 May 2010 22:56:34 +0200, Vlastimil Brom wrote:

> 2010/5/24 joy99 :
>>
>>
>> Dear Group,
>>
>> I have a small question on function.
>>
>> If I write two functions like the following:
>>
>> IDLE 2.6.5
> def function1(n):
>>        element1=5
>>        element2=6
>>        add=element1+element2
>>        print "PRINT THE ADDITION",add
>>
>>
> def function2(n):
>>        element3=7
>>        element4=22
>>        mult=element3*element4
>>        print "PRINT THE MULTIPLICATION",mult
>>
>> Can I now write a third function where the above two functions can be
>> passed as argument or parameter?
>>
>> Best Regards,
>> Subhabrata.
>>
>> NB: As I copied the code from IDLE to MS-Word befor posting here, codes
>> may have slight indentation errors. --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
> Hi,
> while it is quite unclear to me, what you are trying to achieve (what
> are the passed n arguments supposed to do?), you can well pass an
> already defined function as an argument to another function; if you want
> to select a function for the needed operation, if can be e.g.:
> 
> def compute(arg1, arg2, fn):
> fn(arg1, arg2)
> 
> - supposing you don't want to "return" the result but just print it as
> your functions do;
> is it what you were after or did I miss something more complex?
> 
> hth
>   vbr
I did not realise you could pass a function like this, I am sure it could 
lead to some interesting programming.

I am still new to OOP & the light is only just starting to switch on.

analysing your examples I now realise that all function parameters are 
Objects & EVERYTHING(well almost anyway) is an object.

It just goes to show that even when you know 1 answer to the original 
question You can still learn by looking at others







-- 
"And, of course, you have the commercials where savvy businesspeople Get 
Ahead 
by using their MacIntosh computers to create the ultimate American 
business 
product: a really sharp-looking report."
-- Dave Barry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python Function

2010-05-24 Thread joy99
On May 25, 1:56 am, Vlastimil Brom  wrote:
> 2010/5/24 joy99 :
>
>
>
>
>
>
>
> > Dear Group,
>
> > I have a small question on function.
>
> > If I write two functions like the following:
>
> > IDLE 2.6.5
>  def function1(n):
> >        element1=5
> >        element2=6
> >        add=element1+element2
> >        print "PRINT THE ADDITION",add
>
>  def function2(n):
> >        element3=7
> >        element4=22
> >        mult=element3*element4
> >        print "PRINT THE MULTIPLICATION",mult
>
> > Can I now write a third function where the above two functions can be
> > passed as argument or parameter?
>
> > Best Regards,
> > Subhabrata.
>
> > NB: As I copied the code from IDLE to MS-Word befor posting here,
> > codes may have slight indentation errors.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Hi,
> while it is quite unclear to me, what you are trying to achieve (what
> are the passed n arguments supposed to do?), you can well pass an
> already defined function as an argument to another function; if you
> want to select a function for the needed operation, if can be e.g.:
>
> def compute(arg1, arg2, fn):
>     fn(arg1, arg2)
>
> - supposing you don't want to "return" the result but just print it as
> your functions do;
> is it what you were after or did I miss something more complex?
>
> hth
>   vbr- Hide quoted text -
>
> - Show quoted text -

Dear Vlastimil,

You are right. Your approach will do to me. I was trying Python Doc
either I do not know where to check, or I could not find.
I am trying to work out. Numbers I can pass, I was checking the last
example in Python Docs with "def cheeseshop(kind, *arguments,
**keywords):" if that gives me any clue.

If you can kindly try.

Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python Function

2010-05-24 Thread joy99
On May 25, 1:56 am, Vlastimil Brom  wrote:
> 2010/5/24 joy99 :
>
>
>
>
>
>
>
> > Dear Group,
>
> > I have a small question on function.
>
> > If I write two functions like the following:
>
> > IDLE 2.6.5
>  def function1(n):
> >        element1=5
> >        element2=6
> >        add=element1+element2
> >        print "PRINT THE ADDITION",add
>
>  def function2(n):
> >        element3=7
> >        element4=22
> >        mult=element3*element4
> >        print "PRINT THE MULTIPLICATION",mult
>
> > Can I now write a third function where the above two functions can be
> > passed as argument or parameter?
>
> > Best Regards,
> > Subhabrata.
>
> > NB: As I copied the code from IDLE to MS-Word befor posting here,
> > codes may have slight indentation errors.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Hi,
> while it is quite unclear to me, what you are trying to achieve (what
> are the passed n arguments supposed to do?), you can well pass an
> already defined function as an argument to another function; if you
> want to select a function for the needed operation, if can be e.g.:
>
> def compute(arg1, arg2, fn):
>     fn(arg1, arg2)
>
> - supposing you don't want to "return" the result but just print it as
> your functions do;
> is it what you were after or did I miss something more complex?
>
> hth
>   vbr- Hide quoted text -
>
> - Show quoted text -

Dear Vlastimir,

As pointed out by Alister, I can print the values of function1 and
function2 with the help of another function3, but my target is to call
the "add" value of function1 and "mult" value of function2 in a third
function or the values and parameters of the third function in fourth
function. While calling, I am looking not only to print, but to use
them or manipulate them.

I hope I am bit clear now.

Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Generator expressions vs. comprehensions

2010-05-24 Thread Ian Kelly
Hi all,

I just ran into an interesting but rather subtle little wart today.
The following expressions are not functionally equivalent, even in
Python 3:

tuple(iterator.next() for i in xrange(n))

tuple([iterator.next() for i in xrange(n)])

In the first case, if iterator.next() raises a StopIteration, the
exception is swallowed by the generator expression.  The expression
evaluates to a truncated tuple, and the StopIteration is not
propagated.

In the second case, the StopIteration exception is propagated as
expected by the list comprehension.  Set and dict comprehensions also
behave this way in Python 3.

Is this distinction generally known?  The generator expression
behavior is understandable since a generator would do the same thing,
but I'm disappointed that the inconsistency exists and wasn't fixed in
Python 3 when we had the chance.

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Carl Banks
[Following up to Terry Reedy's post since I don't see the original]

On May 24, 11:30 am, Terry Reedy  wrote:
> On 5/24/2010 12:56 PM, Nathan Rice wrote:
>
> > I'm trying to do some fairly deep introspection and instrumentation of
> > instances and classes at runtime, and in order for everything to be
> > properly behaved I need to have radically different behavior in the
> > event that the thing passed to me is a wrapped class/instance.  Is there
> > a really good way, given an instance of a class, to determine if it is
> > wrapped or native?  Currently I check to see if it has __slots__ then
> > try to setattr a dummy variable but I imagine there is probably a
> > cleaner way.


There is no foolproof way, but the simplest and most reliable way is
to check the __flags__ attribute to see if it's a heap type, which all
Python new-style classes are and almost all C-defined types aren't:

cls.__flags__ & 512 # Py_TPFLAGS_HEAPTYPE


However, in Python 2.x, old-style classes aren't types and so don't
have a __flags__ attribute, so to cover that case you should check if
it's a classobj.

isinstance(cls,types.ClassType)


So a complete function would look something like this:

def is_probably_python_class(cls):
return isinstance(cls,types.ClassType) \
or (isinstance(cls,type) and cls.__flags__ & 512)


It's not foolproof for a couple reasons: it's possible to define heap
types in C, and it's possible to define a metatype that does things
differently, but I would suppose these cases are rare.

Incidentally, depending on  your use case, you might find it helpful
also to know whether a type is a base type (meaning that it can be
subclassed).  You can check that with cls.__flags__ & 1024.  A
complete list of flags is in the include file object.h.  Note that, in
order to be subclassable, a type defined in C has to behave like a
Python class to a certain extent.  Thus you can assume a little bit
more about it.


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


Re: Generator expressions vs. comprehensions

2010-05-24 Thread Carl Banks
On May 24, 3:31 pm, Ian Kelly  wrote:
> Hi all,
>
> I just ran into an interesting but rather subtle little wart today.
> The following expressions are not functionally equivalent, even in
> Python 3:
>
> tuple(iterator.next() for i in xrange(n))
>
> tuple([iterator.next() for i in xrange(n)])
>
> In the first case, if iterator.next() raises a StopIteration, the
> exception is swallowed by the generator expression.  The expression
> evaluates to a truncated tuple, and the StopIteration is not
> propagated.
>
> In the second case, the StopIteration exception is propagated as
> expected by the list comprehension.  Set and dict comprehensions also
> behave this way in Python 3.
>
> Is this distinction generally known?  The generator expression
> behavior is understandable since a generator would do the same thing,
> but I'm disappointed that the inconsistency exists and wasn't fixed in
> Python 3 when we had the chance.


As a general rule you shouldn't call the next() method/function
without arranging to catch StopIteration, unless you know the iterator
will never raise StopIteration (such as it if it itertools.count()).
The problem is that if a StopIteration "leaks", as it does with the
generator examples, another iterator further up the stack might catch
it and exit.

The situation here is known.  It can't be corrected, even in Python 3,
without modifying iterator protocol to tie StopIteration to a specific
iterator.  This is possible and might be worth it to avoid hard-to-
diagnose bugs but it would complicate iterator protocol, which becomes
less useful as it becomes more complex.


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


python command line manual

2010-05-24 Thread Peng Yu
I mainly check online python manual. But I feel that it would be nice
if there is command line manual available (just like perl command line
manual). Could you please let me know if such command line manual
available?

-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python command line manual

2010-05-24 Thread Chris Rebert
On Mon, May 24, 2010 at 3:52 PM, Peng Yu  wrote:
> I mainly check online python manual. But I feel that it would be nice
> if there is command line manual available (just like perl command line
> manual). Could you please let me know if such command line manual
> available?

98% sure that there isn't. You could instead use a text-based console
web browser such as lynx to view the online docs to much the same
effect though.

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Internationalizing an application via Babel

2010-05-24 Thread python
I'm evaluating Babel 0.9.5 [1] under Windows (Python 2.6) and
have the following questions that I haven't been able to solve
through reading the documentation or googling.

1. I would like to use an _ like abbreviation for ungettext.  Is
there a concencus on whether one should use n_ or N_ for this?

n_ does not appear to work. Babel does not extract text.

N_ appears to partially work. Babel extracts text like it does
for gettext, but does not format for ngettext (missing plural
argument and msgstr[ n ].)


2. Is there a way to set the initial msgstr fields like the
following when creating a POT file?

I suspect there may be a way to do this via Babel cfg files, but
I've been unable to find documentation on the Babel cfg file
format.

"Project-Id-Version: PROJECT VERSION\n"
"Language-Team: en_US \n"


3. Is there a way to preserve 'obsolete' msgid/msgstr's in our PO
files? When I use the Babel update command, newly created 
obsolete strings are marked with #~ prefixes, but existing 
obsolete message strings get deleted.

Thanks,
Malcolm


[1] http://babel.edgewall.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython 2.8.11.0 release

2010-05-24 Thread Robin Dunn

Announcing
--

The 2.8.11.0 release of wxPython is now available for download at
http://wxpython.org/download.php. This release adds Python 2.7 builds,
PySlices, new pubsub implementation, lots of updates to AGW, and lots
of bugs fixed.  A summary of changes is listed below and also at
http://wxpython.org/recentchanges.php.

Source code is available as a tarball and a source RPM, as well as
binaries for Python 2.5, 2.6 and 2.7, for Windows and Mac, as well
some packages for various Linux distributions.



What is wxPython?
-

wxPython is a GUI toolkit for the Python programming language. It
allows Python programmers to create programs with a robust, highly
functional graphical user interface, simply and easily. It is
implemented as a Python extension module that wraps the GUI components
of the popular wxWidgets cross platform library, which is written in
C++.

wxPython is a cross-platform toolkit. This means that the same program
will usually run on multiple platforms without modifications.
Currently supported platforms are 32-bit and 64-bit Microsoft Windows,
most Linux or other Unix-like systems using GTK2, and Mac OS X 10.4+.
In most cases the native widgets are used on each platform to provide
a 100% native look and feel for the application.



Changes in 2.8.11.0
---

Lots of bug fixes in both wxWidgets and wxPython.

Added the context manager protocol methods to some wx classes so they
can be used with the new Python 'with' statement.  (The with statement
is always available starting in Python 2.6, and can also be used in
Python 2.5 with a __future__ import statement.)  There are several
wx classes where this is a natural fit, such as wx.BusyInfo.  The
__enter__ and __exit__ methods have also been added to wx.Dialog where
it will do the dialog.Destroy() call for you.  This means that you can
use code like this::

with MyDialog(self, foo, bar) as dlg:
 if dlg.ShowModal() == wx.ID_OK:
# do something with dlg values

The list of wx classes that can now be used as context managers is:

  * wx.Dialog
  * wx.BusyInfo
  * wx.BusyCursor
  * wx.WindowDisabler
  * wx.LogNull
  * wx.DCTextColourChanger
  * wx.DCPenChanger
  * wx.DCBrushChanger
  * wx.DCClipper

A new class has been added that is also a context manager, called
wx.FrozenWindow.  It will freeze the window passed to it upon entry to
the context, and will thaw the window upon exit from the context.

Applied the final version of patch #10959 to the PyCrust code.  It
adds many enhancements to the Py suite, inlcuding the ability to edit
blocks of code (called slices) as a whole before executing them, and
also the ability to execute some simple shell commands.

Replaced the wx.lib.pubsub module with the new pubsub package from
http://pubsub.sf.net.  By default it is backwards compatible with the
old pubsub module, but it also has a more advanced API available that
can be switched on at import time.  See the pubsub web site for more
details.

The wx.Effects class is deprecated.

Added Python 2.7 builds for Windows and Mac.

Added Debian package builds for Ubuntu 9.10 and 10.4.

Many fixes and enhancements for the wx.lib.agw pacakge, including the
addition of pybusyinfo, ribbon, ultimatelistctrl and zoombar.



--
Robin Dunn
Software Craftsman
http://wxPython.org

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


Re: Generator expressions vs. comprehensions

2010-05-24 Thread Antoine Pitrou
On Mon, 24 May 2010 15:47:32 -0700 (PDT)
Carl Banks  wrote:
> >
> > Is this distinction generally known?

Yes, it is.

> > The generator expression
> > behavior is understandable since a generator would do the same thing,
> > but I'm disappointed that the inconsistency exists and wasn't fixed in
> > Python 3 when we had the chance.

Why don't you use itertools.islice()?



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


Re: python command line manual

2010-05-24 Thread Steven D'Aprano
On Mon, 24 May 2010 17:52:13 -0500, Peng Yu wrote:

> I mainly check online python manual. But I feel that it would be nice if
> there is command line manual available (just like perl command line
> manual). Could you please let me know if such command line manual
> available?

>From the shell, you can call:

python --help

If you are using Linux, your distro probably has also installed the 
Python man pages, which you access with either of:

man python
info python

And from inside the Python interactive interpreter, you can call 
help(obj) to get help on any object, or just help() to enter an 
interactive help session.



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


Re: MySQL, Python, NumPy and formatted read

2010-05-24 Thread Ian Hoffman
On May 24, 2:11 am, Dennis Lee Bieber  wrote:
> On Sun, 23 May 2010 21:44:30 -0700 (PDT), Ian Hoffman 
> declaimed the following in gmane.comp.python.general:
>
> > The problem is the tuple is contained in a single value separated by
> > newlines (only a[0] has a record), otherwise I could do as you
> > suggest...
>
> >>> blob = "1\n2\n3\n4\n"
> >>> tple = (blob,)
> >>> tple
> ('1\n2\n3\n4\n',)
> >>> values = [int(f) for f in tple[0].split()]
> >>> values
> [1, 2, 3, 4]
>
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Perfect!  Thanks for your help.  When I tried to do what you did, I
had explictly tried to for it as an array by using the array keyword
in from of the loop.  Everything works, and now I can move on to my
next problem.

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


Re: Chatroom

2010-05-24 Thread alex23
"Martin P. Hellwig"  wrote:
> What have you tried so far?

Alternatively, how much is it worth to you?

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


Re: python command line manual

2010-05-24 Thread Asun Friere
On May 25, 8:52 am, Peng Yu  wrote:
> I mainly check online python manual. But I feel that it would be nice
> if there is command line manual available (just like perl command line
> manual). Could you please let me know if such command line manual
> available?
>
> --
> Regards,
> Peng

It's not really a manual, but if you want the documentation written
into a module try 'pydoc '.  This is gives you the same output
as you get running help() in the python shell.




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


Re: Chatroom

2010-05-24 Thread Shashwat Anand
seems like an academic project which is worth grades

On Tue, May 25, 2010 at 7:01 AM, alex23  wrote:

> "Martin P. Hellwig"  wrote:
> > What have you tried so far?
>
> Alternatively, how much is it worth to you?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Chatroom

2010-05-24 Thread Mark Lawrence

On 24/05/2010 19:50, narcissus wrote:

Hello , I want to create a program that is one chatroom and everyone
has this program can Enter into that chatroom. how can i do this?

and i want gui for it too (GTK)
Use your favourite editor and/or IDE to create your program, run it and 
when you run into problems ask here or on the Python tutor ng/ml.


Regards.

Mark Lawrence

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


Re: Generator expressions vs. comprehensions

2010-05-24 Thread Michele Simionato
On May 25, 12:47 am, Carl Banks  wrote:
> The situation here is known.  It can't be corrected, even in Python 3,
> without modifying iterator protocol to tie StopIteration to a specific
> iterator.  This is possible and might be worth it to avoid hard-to-
> diagnose bugs but it would complicate iterator protocol, which becomes
> less useful as it becomes more complex.

The situation here is a known and could be corrected by changing the
meaning of list comprehension,
for instance by having [x for x in iterable] to be an alias for list(x
for x in iterable). In such a way the StopIteration exception would be
always swallowed and there would be consistency with generator
expressions (by construction). However, the list comprehension would
become non-equivalent to the corresponding for-loop with an .append,
so somebody would be un happy anyway :-/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with the Python 3 version of the decorator module

2010-05-24 Thread Michele Simionato
On May 22, 10:49 am, Michele Simionato 
wrote:
> I have finally decided to port the decorator module to Python 3.
> Changing the module was zero effort (2to3 worked) but changing the
> documentation was quite an effort, since I had to wait for docutils/
> pygements to support Python 3 and to change all my custom build
> process. Also, I am relying on distribute for installing on Python 3.
> I would welcome feedback for people using Python 3 on various
> platforms (including Windows) to see if
> they can install the module and how much of effort it is.
>
> Here is the 
> tarball:http://micheles.googlecode.com/files/decorator-3.2beta.tar.gz
> Here is the 
> documentation:http://micheles.googlecode.com/hg/decorator/index.html
>
> The installation process should work for Python 2.4, 2.5, 2.6, 2.7,
> 3.0, 3.1 and all platforms were Python runs, but I have only tested it
> on Linux for Python 2.6 and 3.1. The module has no relevant changes,
> so I expect problems only from the building process, if any. I am not
> sure of what will happen if you do not have distribute or if you have
> a previous version of the module, or if you use pip or something else
> (even in Python 2.X). The packaging in Python has become a real mess!
>
> TIA for you help,
>
>    Michele Simionato

decorator-3.2.0 has been released on PyPI: http://pypi.python.org/pypi/decorator
-- 
http://mail.python.org/mailman/listinfo/python-list


Drilling down in a dict with "complex" objects

2010-05-24 Thread Six
I am trying to access an objects sub-object attributes. I can boil the
code I am working with down to this problem section:
(snip)
class Pt:
  x = None
  y = None
  def __init__(self, x, y):
self.x, self.y = x, y
  pass

class Pts:
  curr_point = None
  next_point = None
  def __init__(self, n, m):
self.next_point = Pt(n, m)
  def update(self, point):
self.curr_point = self.next_point
self.next_point = point

class PtManage:
  points = {}
  def __init__(self):
pass

point = Pts(3,5)
pman = PtManage()
pman.points["odds"] = point
print dir(pman)

print pman["odds"].next_point.x

(snip)

It's this last line that doesn't work. What am I doing wrong? Is this
a failure of the design or am I missing something obvious? How do I
get down and see that "Pt" classes x attribute within the PtManage
dict?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python command line manual

2010-05-24 Thread Vito 'ZeD' De Tullio
Peng Yu wrote:

> I mainly check online python manual. But I feel that it would be nice
> if there is command line manual available (just like perl command line
> manual). Could you please let me know if such command line manual
> available?

pydoc?


-- 
By ZeD

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


Re: Drilling down in a dict with "complex" objects

2010-05-24 Thread Sean DiZazzo
On May 24, 9:34 pm, Six  wrote:
> I am trying to access an objects sub-object attributes. I can boil the
> code I am working with down to this problem section:
> (snip)
> class Pt:
>   x = None
>   y = None
>   def __init__(self, x, y):
>     self.x, self.y = x, y
>   pass
>
> class Pts:
>   curr_point = None
>   next_point = None
>   def __init__(self, n, m):
>     self.next_point = Pt(n, m)
>   def update(self, point):
>     self.curr_point = self.next_point
>     self.next_point = point
>
> class PtManage:
>   points = {}
>   def __init__(self):
>     pass
>
> point = Pts(3,5)
> pman = PtManage()
> pman.points["odds"] = point
> print dir(pman)
>
> print pman["odds"].next_point.x
>
> (snip)
>
> It's this last line that doesn't work. What am I doing wrong? Is this
> a failure of the design or am I missing something obvious? How do I
> get down and see that "Pt" classes x attribute within the PtManage
> dict?

Don't you mean?

pman.points["odds"].next_point.x
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Drilling down in a dict with "complex" objects

2010-05-24 Thread Benjamin Kaplan
On Mon, May 24, 2010 at 9:34 PM, Six  wrote:
> I am trying to access an objects sub-object attributes. I can boil the
> code I am working with down to this problem section:
> (snip)
> class Pt:
>  x = None
>  y = None
>  def __init__(self, x, y):
>    self.x, self.y = x, y
>  pass
>
> class Pts:
>  curr_point = None
>  next_point = None

First of all, don't do this. Python doesn't have variable
declarations, only assignments. So this creates a variable called
curr_point for the *class*, not for the instance. What Java calls
static variables. It doesn't matter here but...

>  def __init__(self, n, m):
>    self.next_point = Pt(n, m)
>  def update(self, point):
>    self.curr_point = self.next_point
>    self.next_point = point
>
> class PtManage:
>  points = {}

Here you have a single mutable dict shared by all instances of PtManage.
a = PtManage()
b = PtManage()
a.points["a"] = Pts(3,2)
print b.points

>  def __init__(self):
>    pass
>
> point = Pts(3,5)
> pman = PtManage()
> pman.points["odds"] = point
> print dir(pman)
>
> print pman["odds"].next_point.x

PtManage doesn't define __getitem__, so pman["odds"] won't work.
pman.points["odds"] should.

>
> (snip)
>
> It's this last line that doesn't work. What am I doing wrong? Is this
> a failure of the design or am I missing something obvious? How do I
> get down and see that "Pt" classes x attribute within the PtManage
> dict?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Drilling down in a dict with "complex" objects

2010-05-24 Thread Terry Reedy

On 5/25/2010 12:34 AM, Six wrote:

[snip]
It's this last line that doesn't work. What am I doing wrong?


When posting such questios, print the traceback if there is one or 
otherwise describe 'does not work' in much more detail.



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


Re: Drilling down in a dict with "complex" objects

2010-05-24 Thread Chris Rebert
On Mon, May 24, 2010 at 9:34 PM, Six  wrote:
> I am trying to access an objects sub-object attributes. I can boil the
> code I am working with down to this problem section:
> (snip)
> class Pt:
>  x = None
>  y = None
>  def __init__(self, x, y):
>    self.x, self.y = x, y
>  pass
>
> class Pts:
>  curr_point = None
>  next_point = None
>  def __init__(self, n, m):
>    self.next_point = Pt(n, m)
>  def update(self, point):
>    self.curr_point = self.next_point
>    self.next_point = point
>
> class PtManage:
>  points = {}
>  def __init__(self):
>    pass
>
> point = Pts(3,5)
> pman = PtManage()
> pman.points["odds"] = point
> print dir(pman)
>
> print pman["odds"].next_point.x
>
> (snip)
>
> It's this last line that doesn't work. What am I doing wrong? Is this
> a failure of the design or am I missing something obvious? How do I
> get down and see that "Pt" classes x attribute within the PtManage
> dict?

I suggest you read the part of Python's tutorial concerning classes
(http://docs.python.org/tutorial/classes.html ). Note that "curr_point
= None" and similar at the class level *does not* declare an object
field, because Python does not have instance variable declarations.
Here is a fixed and normalized version of the classes in your example:

class Pt(object):
def __init__(self, x, y):
self.x, self.y = x, y

class Pts(object):
def __init__(self, n, m):
self.curr_point = None
self.next_point = Pt(n, m)
def update(self, point):
self.curr_point = self.next_point
self.next_point = point

class PtManage(object):
def __init__(self):
self.points = {}


As for why your last line fails:
> print pman["odds"].next_point.x
As Sean said, you're missing a ".points":
print pman.points["odds"].next_point.x

Also, is there any reason for PtManage over just using a `points`
dictionary directly?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Python Function

2010-05-24 Thread Kushal Kumaran
On Tue, May 25, 2010 at 3:38 AM, joy99  wrote:
> 
>
> Dear Vlastimir,
>
> As pointed out by Alister, I can print the values of function1 and
> function2 with the help of another function3, but my target is to call
> the "add" value of function1 and "mult" value of function2 in a third
> function or the values and parameters of the third function in fourth
> function. While calling, I am looking not only to print, but to use
> them or manipulate them.
>
> I hope I am bit clear now.
>

If you need to use the values in another function, you need a way to
let that function get its hands on the values.  Your function1 and
function2 should return the values they compute instead of printing
them out.

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