Re: str(int_var) formatted

2010-10-30 Thread Tracubik
Il Fri, 29 Oct 2010 19:18:41 -0700, John Yeung ha scritto:

> On Oct 29, 11:59 am, Tracubik  wrote:
>> i've to convert integer x to string, but if x < 10, the string have to
>> be '0x' instead of simple 'x'
>>
>> for example:
>>
>> x = 9
>> str(x) --> '09'
> 
> Everyone else seems to prefer the format-based solutions, which is fine.
>  I will give zfill a little exposure, as it seems unloved/ underused:
> 
> str(x).zfill(2)
> 
> John

I've also used zfill in my code, it make code more readable imo. Thanks to 
all for their kind help

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


Re: functions, list, default parameters

2010-10-30 Thread Steven D'Aprano
On Sat, 30 Oct 2010 19:31:53 +1300, Gregory Ewing wrote:

> Steven D'Aprano wrote:
> 
>> And how does Python know whether some arbitrary default object is
>> mutable or not?
> 
> It doesn't, that's the whole point.

I think we're in violent agreement :)



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


Re: embarrassing class question

2010-10-30 Thread Steven D'Aprano
On Sat, 30 Oct 2010 19:30:21 +1300, Gregory Ewing wrote:

> (BTW, there are no function names that have a special meaning in a
> module dict -- a module is not like a class.)

Pity... it would be nice to have a __main__() function, or perhaps 
main(), that was automatically called when you call the module like a 
script.

There are, however, a few special module attributes -- they just aren't 
functions. __doc__, __name__, __file__ and __package__ come to mind.


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


Re: multiprocessing signal defect

2010-10-30 Thread Adam Skutt
On Oct 29, 10:08 am, Adam Tauno Williams 
wrote:
> No, I don't think so.  You're asking the module to over generalize
> behavior.  Reaping of the child is important, and that the child needs
> to be reaped may matter to the master child (why? did something go
> wrong?).
And such information is made available when you reap the child
process.  There are a ton of ways for the module to provide sane and
proper default behavior and still provide hooks for people who need to
modify the behavior or retrieve information.  However, I can't imagine
a use case where the end-developer cares about the process' exit
status from a multiprocess.Pool.

> Silently reaping them [which would reduce the size of the
> Pool? Or would it dynamically create a new worker?] might have
> unintended side effects.
Such as?  Personally, even if you do enumerate one, I'm not sure how
much it matters, as an unintended side effect has already occurred.
It's too late to avoid side effects, they've already happened.
Moreover, merely blithely continuing on invites all sorts of fun side
effects, like the lovely "undefined behavior" side effect.

> How would a 'traditional' thread pool behave if a thread abended?  [of
> course, that depends on the thread-pool implementation]  The correct
> behavior in case of an exception in a thread is a topic of some debate.
Yes, but we're not talking about an exception in a thread, we're
talking about a thread being terminated by the OS.  Which should be
treated like every other OS termination: as a fatal error.  There's
not way for the multiprocessing module to fully recover from such an
event to a known state, so the only sensible thing left is
termination.  Anything else runs the risk of undefined behavior.

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


Using PHP to Dynamically Compress CSS and JavaScript ...

2010-10-30 Thread neha shena
Using PHP to Dynamically Compress CSS and JavaScript ...

 CSS and JavaScript files are simple plain text files with large
amounts of unused space. Compressing all your style sheets into one
page ... read more >

http://childschooledu.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python changes

2010-10-30 Thread Steve Holden
On 10/28/2010 2:14 PM, Craig McRoberts wrote:
> First off, greetings from a newbie!
> 
> Here's the deal. I gained a passable knowledge of Python nearly ten
> years ago. Then I decided a career in the computer sciences wasn't
> for me, and I let it go. Now I find myself back in the development
> arena, and I'd like to pick up Python again. How much has it changed
> in my ten years' absence? I've already resigned myself to starting
> over from the beginning, but are my books from that time period even
> worth using now?
> 
> Thanks so much.
> 
Welcome back. You will find that Python 2.7 retains just about
everything you already know. Python 3.x would have some surprises, but
2.7 is currently the best-supported all-purpose install.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: How on Factorial

2010-10-30 Thread Wolfram Hinderer
On 27 Okt., 10:27, Arnaud Delobelle  wrote:
> True.  It's far too verbose.  I'd go for something like:
>
>     f=lambda n:n<=0 or n*f(~-n)
>
> I've saved a few precious keystrokes and used the very handy ~- idiom!

You can replace "n<=0" with "n<1". Then you can leave out the space
before "or" ("0or" wouldn't work with newer python versions).

f=lambda n:n<1or n*f(~-n)

Much better, isn't it? ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Pyspread 0.1.2 released

2010-10-30 Thread Martin Manns

Pyspread 0.1.2 released
===

I am pleased to announce the new release 0.1.2 of pyspread.

 
About: 
--

Pyspread is a cross-platform Python spreadsheet application. 
It is based on and written in the programming language Python.

Instead of spreadsheet formulas, Python expressions are entered into
the spreadsheet cells. Each expression returns a Python object that can
be accessed from other cells. These objects can represent anything
including lists or matrices.

Pyspread runs on Linux and *nix platforms with GTK support as well as
on Windows (XP and Vista tested). On Mac OS X, some icons are too small
but the application basically works.


Homepage


http://pyspread.sourceforge.net


Changes to 0.1.1


New features:

* Added function to make a cell visible
* Third cell justification "center" added
* Ctrl-F now points to find toolbar instead of find dialog
* Frozen state is now saved
* Entering text in a cell now deletes old text
* Added function F5 (in menu View) for refreshing selected cells
* Save option "pys file with/without gpg signature" added

Bug fixes:

* Grid flicker reduced
* Printing works again
* Changing the table now empties the entry line and does not mess
  up  data any more (BUG 3030172)
* 1D printing bug fixed (BUG 2790444)
* Loading a file from command line no longer deletes cell 0,0,0
  (BUG 3030880)
* Undoing paste operations now works (BUG 3019334)
* Bitmap toggle buttons now work in Windows as well
* Marks undo and redo operation do not accumulate any more
* Undoing text font and textattribute changes works now
* CSV import dialog apply button removed
* Cell limit (2**26) for 32 bit systems removed
* Prints of off-screen areas now correctly center on page
* Help now works when not in the home directory
* Double underscores in Tutorial corrected
* Pyspread gpg key name changed to pyspread_
* Deleting rows and columns can be undone again
* When reversing search, all values are now found
* Saved pys files now have .pys suffix added automatically
* Fixed font size reset bug when setting font attributes
* Loading a file from command line now checks signature correctly
* Fixed moving cells bug for edits in non top-left grid position in
  wx.GTK


Enjoy

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


Tkinter Scrollbar bad behavior [re. bug #10232]

2010-10-30 Thread Robert A. Lerche
I am trying to use Tkinter to create a custom scrollable widget,
similar to a list box but with 3 Entry fields per row.  In the real
application each Entry has a separate input validation routine.

I have placed a test case file in the bug I reported:
http://bugs.python.org/issue10232

The most serious issue is the behavior on MS Windows.  In my sample
program the scroll bar slider has a problem.  When slowly moved down
it works for the first few rows but fails near the bottom of travel.
Near the bottom it rapidly generates "moveto" commands that jump
between rows 4 and 7, causing the display to flash until button 1 is
released.

This behavior does not occur on Linux -- there scrolling using the
slider is smooth top to bottom.

Terry Reedy confirmed this behavior still exists in Python 3 (I tested
in 2.7 on Windows and 2.6.2 on Linux.

He suggested I post here as there may be someone more familiar with
Tkinter who could shed some light.  Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OFF] sed equivalent of something easy in python

2010-10-30 Thread Mark Wooding
Jussi Piitulainen  writes:

> Daniel Fetchinson writes:
>
> > The pattern is that the first line is deleted, then 2 lines are
> > kept, 3 lines are deleted, 2 lines are kept, 3 lines are deleted,
> > etc, etc.
>
> So, is there some simple expression in Python for this?

(item for i, item in enumerate(input) if (i + 4)%5 < 2)

-- [mdw]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating PDF file in Python

2010-10-30 Thread David Boddie
On Saturday 30 October 2010 04:27, Lawrence D'Oliveiro wrote:

> In message , Ed Keith
> wrote:
> 
>> I need to generate PDF files and I'm exploring what tools to use. I was
>> planing on using ReportLab, but recently found some references to pango
>> (http://www.pango.org/) and ciaro (http://cairographics.org/) being able
>> to generate PDF files. But am having difficulty finding details.

[...]

>> Are there other options I have overlooked?
> 
> How about Poppler?

Poppler is first and foremost a rendering library, not a PDF generator,
though it's very good at what it does:

  http://poppler.freedesktop.org/

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


Re: curses and processing terminal escape characters

2010-10-30 Thread Tim Harig
On 2010-10-30, Lawrence D'Oliveiro  wrote:
> In message , Tim Harig wrote:
>
>> Python could easily process the escape codes for any given terminal; but,
>> in general, you would want something that works for more then a single
>> terminal type.
>
> Does anyone still bother with anything other than VT1xx-type terminals?

1. Actually, most modern terminals and emulators have color which means
that they must by in the VT2xx range or above.

2. Yes there are still hardware terminals being used and not all of them
are VTxxxs.

3. Even assuming that the OP is only conserned about VTxxx terminals, it is
still a better coding practice to use a layer of abstraction so as
to keep the "magic numbers" out of his code.

4. Just because VTxxx style terminals and emulators currently dominate
doesn't mean that they will do so forever.  It is quite possible
that in an age where most terminals are emulated, that somebody
will create a new style of terminal that fits in better to the
virtual/graphical world in which they inhabit.

5. Although it is offtopic for this question, using the curses abstraction
rather then hardcoded values, allows a visual text based program to
work in places that do not act like a traditional terminal.
Microsoft Windows console fits this description because formating
commands are not sent in-band with the text data.  By using
something like PDCurses, it is possible to run curses programs on
non-terminal environments such as these.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curses and processing terminal escape characters

2010-10-30 Thread Emile van Sebille

On 10/29/2010 9:48 PM Lawrence D'Oliveiro said...

In message, Tim Harig wrote:


Python could easily process the escape codes for any given terminal; but,
in general, you would want something that works for more then a single
terminal type.


Does anyone still bother with anything other than VT1xx-type terminals?


I'm still supporting about 150 green screen user seats (CHUIs), and no, 
they're all running vt100 emulators.


Done-with-termcap-hacking-ly y'rs,

Emile



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


Re: Tkinter Scrollbar bad behavior [re. bug #10232]

2010-10-30 Thread rantingrick
Robert,

First and foremost if you wish to scroll a window then why not use the
TIX.ScrolledWindow widget instead. It even shows and hides the
scrollbar when necessary.

#-- Start Script --#
from Tix import *
#from Tkconstants import *

class App(Tk): # Must use Tk  for Tix incompability
def __init__(self):
Tk.__init__(self)
self._createWidgets()

def _createWidgets(self):
swin = ScrolledWindow(self, width=400, height=300)
swin.pack(fill=BOTH, expand=1)
frame = swin.window
col, row = 0,0
for row in range(100):
for col in range(3):
w=Button(frame, text='This is button (%02d, %02d)' %
(col, row))
w.grid(row=row, column=col)
col += 1
row += 1


if __name__ == '__main__':
app = App()
app.mainloop()
#-- End Script --#
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 or 3.1

2010-10-30 Thread Lawrence D'Oliveiro
In message , Christian 
Heimes wrote:

> Am 29.10.2010 23:16, schrieb Lawrence D'Oliveiro:
>
>> In message , Jorge
>> Biquez wrote:
>> 
>>> I was wondering if you can comment more about what alternatives to
>>> use instead to MySql. My web solutions do not need "all the power" of
>>> a true database,
>> 
>> Is more than one process likely to access the data at the same time? If
>> so, use MySQL.
> 
> You have to store and acces a LOT of data? Hadoop may the solution.

I don’t think the OP is quite at the level where they need to think in terms 
of something as heavy-hitting as that.

I suggested MySQL because that’s the usual thing people start with for a 
multiuser situation, unless/until they decide they need something more.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 or 3.1

2010-10-30 Thread bradenf
I agree +1
Sent wirelessly from my BlackBerry.

-Original Message-
From: Lawrence D'Oliveiro 
Sender: python-list-bounces+bradenf=hotmail@python.org
Date: Sun, 31 Oct 2010 13:30:38 
To: 
Subject: Re: Python 2.7 or 3.1

In message , Christian 
Heimes wrote:

> Am 29.10.2010 23:16, schrieb Lawrence D'Oliveiro:
>
>> In message , Jorge
>> Biquez wrote:
>> 
>>> I was wondering if you can comment more about what alternatives to
>>> use instead to MySql. My web solutions do not need "all the power" of
>>> a true database,
>> 
>> Is more than one process likely to access the data at the same time? If
>> so, use MySQL.
> 
> You have to store and acces a LOT of data? Hadoop may the solution.

I don’t think the OP is quite at the level where they need to think in terms 
of something as heavy-hitting as that.

I suggested MySQL because that’s the usual thing people start with for a 
multiuser situation, unless/until they decide they need something more.
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: factorial of negative one (-1)

2010-10-30 Thread Robert Kern

On 2010-10-30 00:29 , Bj Raz wrote:

Thank you Robert for the clarification.  Since I'm an amateur programmer, could
you please give me a sample of how I would do it.


Chris Rebert just showed you.


I'll take some time to study
arrays as well, and how to write them, I know of lists, and tuples, and
dictionaries; from "Dive into Python". but I am very green around the ears
still. :|


You don't need anything other than lists here.

--
Robert Kern

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

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


How to write pbm file in Python 3?

2010-10-30 Thread André
I'm trying to create pbm (portable bitmap) files using Python 3 and
have run into a problem.   The example I am using is the Python 2
Mandelbrot program found at
http://shootout.alioth.debian.org/u32/program.php?test=mandelbrot&lang=python&id=1

When I run it using Python 2 with size=100, I get a file of size 1311
bytes.  This file contains the correct image.

When I run it using Python 3 with the same parameter (and replacing
xrange by range - the only change suggested by 2to3), I get a file of
size 1812 bytes; this file does not contain the right image.

Any help would be much appreciated.

André

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


Re: How to write pbm file in Python 3?

2010-10-30 Thread bradenf
Sorry for the newb question but, what would this be for?

Just out of curiousuty 
Thanks 

--Original Message--
From: André
Sender: python-list-bounces+bradenf=hotmail@python.org
To: Python List
Subject: How to write pbm file in Python 3?
Sent: Oct 30, 2010 11:32 PM

I'm trying to create pbm (portable bitmap) files using Python 3 and
have run into a problem.   The example I am using is the Python 2
Mandelbrot program found at
http://shootout.alioth.debian.org/u32/program.php?test=mandelbrot&lang=python&id=1

When I run it using Python 2 with size=100, I get a file of size 1311
bytes.  This file contains the correct image.

When I run it using Python 3 with the same parameter (and replacing
xrange by range - the only change suggested by 2to3), I get a file of
size 1812 bytes; this file does not contain the right image.

Any help would be much appreciated.

André

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



Sent wirelessly from my BlackBerry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write pbm file in Python 3?

2010-10-30 Thread Chris Rebert
On Sat, Oct 30, 2010 at 8:32 PM, André  wrote:
> I'm trying to create pbm (portable bitmap) files using Python 3 and
> have run into a problem.   The example I am using is the Python 2
> Mandelbrot program found at
> http://shootout.alioth.debian.org/u32/program.php?test=mandelbrot&lang=python&id=1
>
> When I run it using Python 2 with size=100, I get a file of size 1311
> bytes.  This file contains the correct image.
>
> When I run it using Python 3 with the same parameter (and replacing
> xrange by range - the only change suggested by 2to3), I get a file of
> size 1812 bytes; this file does not contain the right image.
>
> Any help would be much appreciated.

Have you tried changing all instances of chr() to
bytes([]) ?
In Python 3, chr() always returns Unicode rather than a bytestring; I
suspect this might be the cause of your problem.

If my suggestion fixes things, then arguably 2to3 ought to have warned
about chr() and thus you should report this as a bug.

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


Re: How to write pbm file in Python 3?

2010-10-30 Thread André
On Oct 31, 1:11 am, Chris Rebert  wrote:
> On Sat, Oct 30, 2010 at 8:32 PM, André  wrote:
> > I'm trying to create pbm (portable bitmap) files using Python 3 and
> > have run into a problem.   The example I am using is the Python 2
> > Mandelbrot program found at
> >http://shootout.alioth.debian.org/u32/program.php?test=mandelbrot&lan...
>
> > When I run it using Python 2 with size=100, I get a file of size 1311
> > bytes.  This file contains the correct image.
>
> > When I run it using Python 3 with the same parameter (and replacing
> > xrange by range - the only change suggested by 2to3), I get a file of
> > size 1812 bytes; this file does not contain the right image.
>
> > Any help would be much appreciated.
>
> Have you tried changing all instances of chr() to
> bytes([]) ?
Yes, I had.  And I got the following traceback:

Traceback (most recent call last):
  File "mandel_orig.py", line 39, in 
main()
  File "mandel_orig.py", line 30, in main
cout(bytes([byte_acc]))
TypeError: must be str, not bytes

André

> In Python 3, chr() always returns Unicode rather than a bytestring; I
> suspect this might be the cause of your problem.
>
> If my suggestion fixes things, then arguably 2to3 ought to have warned
> about chr() and thus you should report this as a bug.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

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


Re: How to write pbm file in Python 3?

2010-10-30 Thread Chris Rebert
On Sat, Oct 30, 2010 at 9:21 PM, André  wrote:
> On Oct 31, 1:11 am, Chris Rebert  wrote:
>> On Sat, Oct 30, 2010 at 8:32 PM, André  wrote:
>> > I'm trying to create pbm (portable bitmap) files using Python 3 and
>> > have run into a problem.   The example I am using is the Python 2
>> > Mandelbrot program found at
>> >http://shootout.alioth.debian.org/u32/program.php?test=mandelbrot&lan...
>>
>> > When I run it using Python 2 with size=100, I get a file of size 1311
>> > bytes.  This file contains the correct image.
>>
>> > When I run it using Python 3 with the same parameter (and replacing
>> > xrange by range - the only change suggested by 2to3), I get a file of
>> > size 1812 bytes; this file does not contain the right image.
>>
>> > Any help would be much appreciated.
>>
>> Have you tried changing all instances of chr() to
>> bytes([]) ?
> Yes, I had.  And I got the following traceback:
>
> Traceback (most recent call last):
>  File "mandel_orig.py", line 39, in 
>    main()
>  File "mandel_orig.py", line 30, in main
>    cout(bytes([byte_acc]))
> TypeError: must be str, not bytes

Ah, right. This is the problem of not having Python 3 to test with.
Try also changing:
cout = sys.stdout.buffer.write

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


Re: How to write pbm file in Python 3?

2010-10-30 Thread Andre Roberge
On Sun, Oct 31, 2010 at 1:32 AM, Chris Rebert  wrote:

> On Sat, Oct 30, 2010 at 9:21 PM, André  wrote:
> > On Oct 31, 1:11 am, Chris Rebert  wrote:
> >> On Sat, Oct 30, 2010 at 8:32 PM, André  wrote:
> >> > I'm trying to create pbm (portable bitmap) files using Python 3 and
> >> > have run into a problem.   The example I am using is the Python 2
> >> > Mandelbrot program found at
> >> >http://shootout.alioth.debian.org/u32/program.php?test=mandelbrot&lan.
> ..
> >>
> >> > When I run it using Python 2 with size=100, I get a file of size 1311
> >> > bytes.  This file contains the correct image.
> >>
> >> > When I run it using Python 3 with the same parameter (and replacing
> >> > xrange by range - the only change suggested by 2to3), I get a file of
> >> > size 1812 bytes; this file does not contain the right image.
> >>
> >> > Any help would be much appreciated.
> >>
> >> Have you tried changing all instances of chr() to
> >> bytes([]) ?
> > Yes, I had.  And I got the following traceback:
> >
> > Traceback (most recent call last):
> >  File "mandel_orig.py", line 39, in 
> >main()
> >  File "mandel_orig.py", line 30, in main
> >cout(bytes([byte_acc]))
> > TypeError: must be str, not bytes
>
> Ah, right. This is the problem of not having Python 3 to test with.
> Try also changing:
> cout = sys.stdout.buffer.write
>

Yes, that worked.  Thanks!

Now I know what to look for, time to read the documentation for
sys.stdout.buffer ...   Thanks again.

André


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


Is there a way to pring a list object in Python?

2010-10-30 Thread Zeynel
class Rep(db.Model):
author = db.UserProperty()
replist = db.ListProperty(str)
unique = db.ListProperty(str)
date = db.DateTimeProperty(auto_now_add=True)



Rep().replist = L
Rep().put()
mylist = Rep().all().fetch(10)

I am trying to display mylist; but I am getting the object. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list