Earn $2 Per Click For Free Join Make Money

2011-01-29 Thread Ravi chandran
www.workfrominter.com
-- 
http://mail.python.org/mailman/listinfo/python-list


multiple values for keyword argument

2011-01-29 Thread Tobias Blass
Hi all
I'm just learning python and use it to write a GUI (with Tkinter) for a C
program I already wrote. When trying to execute the program below I get the
following error message.

Traceback (most recent call last):
  File "./abirechner.py", line 64, in 
  win =MainWin()
  File "./abirechner.py", line 43, in __init__
  self.create_edit(row=i);
TypeError: create_edit() got multiple values for keyword argument 'row'

I don't really understand why create_edit gets multiple values, it gets one
Integer after another (as I see it)
Thanks for your help

abirechner.py:

# line 37
class MainWin(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.grid()
self.edits=()
for i in range(10):
self.create_edit(row=i);
def create_edit(row,self):
# LineEdit is defined, but I don't consider it important here
self.edits+=LineEdit()
self.edits[-1].grid(row=row,column=0)
# ...
#line 64
win = MainWin()
win.mainLoop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use the Source Luke

2011-01-29 Thread TP
On Fri, Jan 28, 2011 at 10:32 AM, Raymond Hettinger  wrote:
> I hoping a new trend will start with dev's putting direct
> source code links in their documentation:
>
>  http://rhettinger.wordpress.com/2011/01/28/open-your-source-more/
>
> I'm looking for more examples of projects that routinely
> link their docs back into relavant sections of code.
> Have any of you all seen other examples besides
> the Go language docs and the Python docs?
>
>
> Raymond
> --
> http://mail.python.org/mailman/listinfo/python-list
>

The Sphinx Python Documentation Generator
(http://sphinx.pocoo.org/index.html), used for documenting lots of
things other than Python, has an extension called "sphinx.ext.viewcode
– Add links to highlighted source code"
(http://sphinx.pocoo.org/ext/viewcode.html).

You can see my use of it here on a small PyQt project:
http://tpgit.github.com/MDIImageViewer/imageviewer.html. You can even
view the Sphinx documentation "code" by clicking the "Show Source"
link on the left.

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


Re: multiple values for keyword argument

2011-01-29 Thread Francesco Bochicchio
On 29 Gen, 12:10, Tobias Blass  wrote:
> Hi all
> I'm just learning python and use it to write a GUI (with Tkinter) for a C
> program I already wrote. When trying to execute the program below I get the
> following error message.
>
> Traceback (most recent call last):
>   File "./abirechner.py", line 64, in 
>       win =MainWin()
>   File "./abirechner.py", line 43, in __init__
>       self.create_edit(row=i);
> TypeError: create_edit() got multiple values for keyword argument 'row'
>
> I don't really understand why create_edit gets multiple values, it gets one
> Integer after another (as I see it)
> Thanks for your help
>
> abirechner.py:
>
> # line 37
> class MainWin(Frame):
>         def __init__(self,master=None):
>                 Frame.__init__(self,master)
>                 self.grid()
>                 self.edits=()
>                 for i in range(10):
>                         self.create_edit(row=i);
>         def create_edit(row,self):
>                 # LineEdit is defined, but I don't consider it important here
>                 self.edits+=LineEdit()
>                 self.edits[-1].grid(row=row,column=0)
> # ...
> #line 64
> win = MainWin()
> win.mainLoop()

Try this:

> def create_edit(self, row):

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


Re: multiple values for keyword argument

2011-01-29 Thread Tobias Blass


On Sat, 29 Jan 2011, Francesco Bochicchio wrote:

>On 29 Gen, 12:10, Tobias Blass  wrote:
>> Hi all
>> I'm just learning python and use it to write a GUI (with Tkinter) for a C
>> program I already wrote. When trying to execute the program below I get the
>> following error message.
>>
>> Traceback (most recent call last):
>>   File "./abirechner.py", line 64, in 
>>       win =MainWin()
>>   File "./abirechner.py", line 43, in __init__
>>       self.create_edit(row=i);
>> TypeError: create_edit() got multiple values for keyword argument 'row'
>>
>> I don't really understand why create_edit gets multiple values, it gets one
>> Integer after another (as I see it)
>> Thanks for your help
>>
>> abirechner.py:
>>
>> # line 37
>> class MainWin(Frame):
>>         def __init__(self,master=None):
>>                 Frame.__init__(self,master)
>>                 self.grid()
>>                 self.edits=()
>>                 for i in range(10):
>>                         self.create_edit(row=i);
>>         def create_edit(row,self):
>>                 # LineEdit is defined, but I don't consider it important here
>>                 self.edits+=LineEdit()
>>                 self.edits[-1].grid(row=row,column=0)
>> # ...
>> #line 64
>> win = MainWin()
>> win.mainLoop()
>
>Try this:
>
>> def create_edit(self, row):
>
>Ciao
>---
>FB
>

Ok it works now. So the problem was that python requires 'self' to be the first
parameter?-- 
http://mail.python.org/mailman/listinfo/python-list


EARN 1000 DOLLARS PER DAY - WITHOUT INVESTMENT

2011-01-29 Thread success all
http://USAforextradingonline.blogspot.com

http://USAforextradingonline.blogspot.com

http://USAforextradingonline.blogspot.com

http://USAforextradingonline.blogspot.com

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


Re: multiple values for keyword argument

2011-01-29 Thread Frank Dierkes
On Sat, 29 Jan 2011 14:18:30 +0100, Tobias Blass wrote:

> On Sat, 29 Jan 2011, Francesco Bochicchio wrote:
> 
>>> class MainWin(Frame):
>>>         def create_edit(row,self):

>>> def create_edit(self, row):
>>

>>
>>
> Ok it works now. So the problem was that python requires 'self' to be
> the first parameter?

If you define an instance method, the first parameter is always the 
instance passed to the method - regardless of the parameters name.

In your case the instance was passed to the row parameter. Then again you 
wanted to pass i to it. That's why the exception was raised. If you just 
had typed self.create_edit(i), then row would have been the instance 
(*self*.create_edit(...)) and self would have been i.

Naming the first parameter self is only a convention. It could be any 
other name, too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread Peter Otten
Tobias Blass wrote:

> 
> 
> On Sat, 29 Jan 2011, Francesco Bochicchio wrote:
> 
>>On 29 Gen, 12:10, Tobias Blass  wrote:
>>> Hi all
>>> I'm just learning python and use it to write a GUI (with Tkinter) for a
>>> C program I already wrote. When trying to execute the program below I
>>> get the following error message.
>>>
>>> Traceback (most recent call last):
>>> File "./abirechner.py", line 64, in 
>>> win =MainWin()
>>> File "./abirechner.py", line 43, in __init__
>>> self.create_edit(row=i);
>>> TypeError: create_edit() got multiple values for keyword argument 'row'
>>>
>>> I don't really understand why create_edit gets multiple values, it gets
>>> one Integer after another (as I see it)
>>> Thanks for your help

>>> class MainWin(Frame):
>>> def create_edit(row,self):

>>Try this:
>>> def create_edit(self, row):

> Ok it works now. So the problem was that python requires 'self' to be the
> first parameter?

When you invoke a method Python implicitly passes the instance as the first 
positional parameter to it, regardless of the name:

>>> class A:
... s = "yadda"
... def yadda(but_i_dont_want_to_call_it_self):
... print but_i_dont_want_to_call_it_self.s
...
>>> A().yadda()
yadda

You can provoke the same error with a function:

>>> def f(a, b):
... pass
...
>>> f(1, b=2)
>>> f(a=1, b=2)
>>> f(2, a=1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: f() got multiple values for keyword argument 'a'

You can think of argument binding as a two-step process.
At first positionals are bound to the formal parameters in the order of 
appearance from left to right; then named arguments are bound to parameters 
with the same name. If a name is already catered by a positional argument 
(or a name doesn't occur at all and doesn't have a default value) you get an 
Exception.

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


Re: multiple values for keyword argument

2011-01-29 Thread Roy Smith
In article <8qijsgfgu...@mid.dfncis.de>,
 Frank Dierkes  wrote:

> Naming the first parameter self is only a convention. It could be any 
> other name, too.

But it shouldn't.  The use of "self" is so universal that using anything 
else will just make your code more difficult for other people to 
understand.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread Ethan Furman

Roy Smith wrote:

In article <8qijsgfgu...@mid.dfncis.de>,
 Frank Dierkes  wrote:

Naming the first parameter self is only a convention. It could be any 
other name, too.


But it shouldn't.  The use of "self" is so universal that using anything 
else will just make your code more difficult for other people to 
understand.


Nevertheless, if you have a good reason to, go ahead.

I, myself, use the spanish word 'yo' instead (less keystrokes, I hate 
'self', and it amuses me); if I'm working with my numerical experiments 
I'll use 'n' or 'x'... although, when posting sample code to c.l.py I do 
try to use 'self' to avoid possible confusion.  :)


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


Re: multiple values for keyword argument

2011-01-29 Thread Tobias Blass


On Sat, 29 Jan 2011, Peter Otten wrote:

>Tobias Blass wrote:
>
>> 
>> 
>> On Sat, 29 Jan 2011, Francesco Bochicchio wrote:
>> 
>>>On 29 Gen, 12:10, Tobias Blass  wrote:
 Hi all
 I'm just learning python and use it to write a GUI (with Tkinter) for a
 C program I already wrote. When trying to execute the program below I
 get the following error message.

 Traceback (most recent call last):
 File "./abirechner.py", line 64, in 
 win =MainWin()
 File "./abirechner.py", line 43, in __init__
 self.create_edit(row=i);
 TypeError: create_edit() got multiple values for keyword argument 'row'

 I don't really understand why create_edit gets multiple values, it gets
 one Integer after another (as I see it)
 Thanks for your help
>
 class MainWin(Frame):
 def create_edit(row,self):
>
>>>Try this:
 def create_edit(self, row):
>
>> Ok it works now. So the problem was that python requires 'self' to be the
>> first parameter?
>
>When you invoke a method Python implicitly passes the instance as the first 
>positional parameter to it, regardless of the name:
>
 class A:
>... s = "yadda"
>... def yadda(but_i_dont_want_to_call_it_self):
>... print but_i_dont_want_to_call_it_self.s
>...
 A().yadda()
>yadda
>
>You can provoke the same error with a function:
>
 def f(a, b):
>... pass
>...
 f(1, b=2)
 f(a=1, b=2)
 f(2, a=1)
>Traceback (most recent call last):
>  File "", line 1, in 
>TypeError: f() got multiple values for keyword argument 'a'
>
>You can think of argument binding as a two-step process.
>At first positionals are bound to the formal parameters in the order of 
>appearance from left to right; then named arguments are bound to parameters 
>with the same name. If a name is already catered by a positional argument 
>(or a name doesn't occur at all and doesn't have a default value) you get an 
>Exception.
>
>
Thanks for your replies, as soon as I knew that python always passes the object
reference as first parameter everything was clear (It's just like argc and argv
in C, you could also call argc fish and argv chips)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use the Source Luke

2011-01-29 Thread Miki
Clojure a "source" that shows the source of a function (doh!).
It's probably easy to implement in Python with the inspect module. Sadly this 
won't work for built-ins.

Clojure's irc clojurebot will answer "source " with a link to github 
that points to the first line of definition.
-- 
http://mail.python.org/mailman/listinfo/python-list


Distress sale/JBR/1 Bed /AED790sqft / 15th floor/050-8320722

2011-01-29 Thread PETER WONG F H (+971 50 8320722)
Distress sale/JBR/1 Bed /AED790sqft / 15th floor/050-8320722


JBR
Lower Price
AED790per/sqft
15th floor
1,465.90sqft(AED1,160,000.00)
+Transfer Fee 2 % + Broker Fee 2%
JBR Apartments
Located near to Dubai Marina and lying in a beach front location
comprises
the area of JBR or Jumeirah Beach Residences*Features:*
   - Swimming Pool - Community
   - Hot Property
   - 24hr Door Man
   - Built-in Wardrobes
   - Central A/C
   - Walking distance to Beaches
   - Balcony
The Best

Peter Wong F.H   王福兴

Mob  手提   : +971   50 83 20 722
E-mail   电邮   : peterwfh2...@gmail.com
Group:
http://groups.google.com/group/dubai-property-club/boxsubscribe?p=FixAddr&email&_referer
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] python-ghostscript 0.4

2011-01-29 Thread Hartmut Goebel
Announcing:

python-ghostscript 0.4

A Python-Interface to the Ghostscript
 C-API using ctypes

:Copyright: GNU Public License v3 (GPLv3)
:Author:  Hartmut Goebel 
:Homepage: http://bitbucket.org/htgoebel/python-ghostscript
:Download: http://pypi.python.org/pypi/ghostscript

`Ghostscript`__, is a well known interpreter for the PostScript
language and for PDF. This package implements a interface to the
Ghostscript C-API using `ctypes`__. Both a low-level and a pythonic,
high-level interface are provided.

__ http://www.ghostscript.com/
__ http://docs.python.org/library/ctypes.html

This package is currently tested only under GNU/Linux. Please report
whether it works in your environment, too. Thanks.


Latest Changes


  * Fixed bug: typo in function call name ctypes.util.find_library

  * (Unix) No longer try to load a specific version (version 8) of
libgs.so

  * Added low-level interface for set_stdio() plus wrappers for
file handles

  * (win32) Improved search for best Ghostscript installation:
Consider Aladdin and GNU Ghostscript, too; Check for existence of
DLL found in registry; take highest version available.

  * Added win32 example-batch file for testing and other
improvements/fixes on examples an documentation.


Example


Here is an example for how to use the high-level interface of
`python-ghostscript`. This implements a very basic ps2pdf-tool::

  import sys
  import ghostscript

  args = [
  "ps2pdf", # actual value doesn't matter
  "-dNOPAUSE", "-dBATCH", "-dSAFER",
  "-sDEVICE=pdfwrite",
  "-sOutputFile=" + sys.argv[1],
  "-c", ".setpdfwrite",
  "-f",  sys.argv[2]
  ]

  ghostscript.Ghostscript(*args)


-- 
Regards
Hartmut Goebel

| Hartmut Goebel  | h.goe...@crazy-compilers.com   |
| www.crazy-compilers.com | compilers which you thought are impossible |
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to read the last line of a huge file???

2011-01-29 Thread Aahz
In article ,
John O'Hagan  wrote:
>
>file.seek takes an optional 'whence' argument which is 2 for the end, so you 
>can just work back from there till you hit the first newline that has anything 
>after it:
>
>
>def lastline(filename):
>offset = 0
>line = ''
>with open(filename) as f:
>while True:
>offset -= 1
>f.seek(offset, 2)
>nextline = f.next()
>if nextline == '\n' and line.strip():
>return line
>else:
>line = nextline

It's a Bad Idea to mix direct file operations with the iterator API.
Use f.read() instead of f.next().
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread patty
> Roy Smith wrote:
>> In article <8qijsgfgu...@mid.dfncis.de>,
>>  Frank Dierkes  wrote:
>>
>>> Naming the first parameter self is only a convention. It could be any
>>> other name, too.
>>
>> But it shouldn't.  The use of "self" is so universal that using anything
>> else will just make your code more difficult for other people to
>> understand.
>
> Nevertheless, if you have a good reason to, go ahead.
>
> I, myself, use the spanish word 'yo' instead (less keystrokes, I hate
> 'self', and it amuses me); if I'm working with my numerical experiments
> I'll use 'n' or 'x'... although, when posting sample code to c.l.py I do
> try to use 'self' to avoid possible confusion.  :)
>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list

I am glad you said this.  I have been avoiding understanding this 'self',
just accepting it :}  For the time being, since my programs I am creating
are for my own use, I think I will make my own names up, that are
descriptive to me as the programmer, it's all going to be interpreted
anyway.  And the other email equating to C's argv, etc. - now I get it.

Regards,

Patty
>
>


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


Re: how to read the last line of a huge file???

2011-01-29 Thread Tim Chase

On 01/26/2011 04:59 AM, Xavier Heruacles wrote:

I have do some log processing which is usually huge. The
length of each line is variable. How can I get the last line??
Don't tell me to use readlines or something like linecache...


I wrote a modestly tested version (including missing 
terminal-EOL, files with no newlines, and empty files) at


http://www.mail-archive.com/python-list@python.org/msg226537.html

which minimizes the number of seeks (reading chunks rather than 
seeking for every character as you work backwards).


You might find it useful.

-tkc



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


Re: Use the Source Luke

2011-01-29 Thread Raymond Hettinger
On Jan 29, 3:22 am, TP  wrote:
> On Fri, Jan 28, 2011 at 10:32 AM, Raymond Hettinger  wrote:
> > I hoping a new trend will start with dev's putting direct
> > source code links in their documentation:
>
> >  http://rhettinger.wordpress.com/2011/01/28/open-your-source-more/
>
> > I'm looking for more examples of projects that routinely
> > link their docs back into relavant sections of code.
> > Have any of you all seen other examples besides
> > the Go language docs and the Python docs?
>
> > Raymond
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> The Sphinx Python Documentation Generator
> (http://sphinx.pocoo.org/index.html), used for documenting lots of
> things other than Python, has an extension called "sphinx.ext.viewcode
> – Add links to highlighted source code"
> (http://sphinx.pocoo.org/ext/viewcode.html).

Thanks, I didn't know about that extension.

To support my effort to add source links to the Python docs,
Georg Brandl added a new directive :source: so that we could
write :source:`Lib/heapq.py` and the set the prefix somewhere else
(i.e. pointing at the py3k branch on subversion or on mercurial).


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


Looking for Remote Python Project

2011-01-29 Thread joy99
Dear Room,

I am a Python Programmer from India(New Delhi Region), and I worked
for quite a long time in Bangalore. I have been working in Python for
the last 4 years or so. I have successfully built around 15 projects
in Python. I am looking for some remote Python Projects, which can be
done from home.

If any one knows of anything, I may be helpful enough.

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


Re: Use the Source Luke

2011-01-29 Thread Ben Finney
rusi  writes:

> On Jan 29, 4:10 am, Ben Finney  wrote:
> > I have a quibble with the framing:
> >
> > > The rest of the blame lies with installers. They all treat
> > > human-readable scripts like they were binaries and tuck the code
> > > away in a dark corner.
>
> Consider this example:
> The emacs source if compiled from source will give you help for each
> lisp or even builtin (C) function out of the box from inside emacs.
> However if you get the emacs package from debian/ubuntu you will get
> neither unless you install el files -- which is fine -- just install
> the el package. […]

That's an example of the point I made in what followed in my message you
quoted. The description can be interpreted as accurate, but it's framed
poorly.

> Isn't this an instance of the problem that Raymond is talking of?

The “problem”, which I don't consider to be a problem per se, is one of
OS-wide policy, not “installers”. The policy is a matter of tradeoffs
across the system, and isn't “tucking the code away in a dark corner”.

> [Personal note:  Ive been a python user and teacher for nearly 10
> years and would eagerly welcome more easy code-open-ness]

Agreed.

-- 
 \ “When people believe that they have absolute knowledge, with no |
  `\ test in reality, this [the Auschwitz crematorium] is how they |
_o__) behave.” —Jacob Bronowski, _The Ascent of Man_, 1973 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread Ben Finney
Tobias Blass  writes:

> Ok it works now. So the problem was that python requires 'self' to be
> the first parameter?

More accurately, the instance is passed as the first parameter, and
Python doesn't care what you name it. (Your fellow programmers do care,
though, so please stick to the ‘self’ convention despite this freedom.)

-- 
 \   “The lift is being fixed for the day. During that time we |
  `\regret that you will be unbearable.” —hotel, Bucharest |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread Ben Finney
pa...@cruzio.com writes:

> > I, myself, use the spanish word 'yo' instead (less keystrokes, I
> > hate 'self', and it amuses me); if I'm working with my numerical
> > experiments I'll use 'n' or 'x'... although, when posting sample
> > code to c.l.py I do try to use 'self' to avoid possible confusion.
> > :)
>
> I am glad you said this. I have been avoiding understanding this
> 'self', just accepting it :} For the time being, since my programs I
> am creating are for my own use, I think I will make my own names up,
> that are descriptive to me as the programmer, it's all going to be
> interpreted anyway.

Please consider that your code is written primarily for humans to read,
and only incidentally for the machine to execute. (If it were primarily
for the machine to execute and communication with humans was not an
issue, you would be writing in machine code.)

Consider that code written “only for my own use” frequently becomes more
widespread; and it's impossible to know at the time of writing it
whether that will be the case. It's prudent to write all such code as
though it were for public consumption.

-- 
 \  “Generally speaking, the errors in religion are dangerous; |
  `\those in philosophy only ridiculous.” —David Hume, _A Treatise |
_o__)   of Human Nature_, 1739 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for Remote Python Project

2011-01-29 Thread Ben Finney
joy99  writes:

> I am looking for some remote Python Projects, which can be done from
> home.
>
> If any one knows of anything, I may be helpful enough.

One of the best ways to begin contributing is to fix bugs and provide
patches. For Python itself, see the Python bug tracker
http://bugs.python.org/>; for other projects, see the project's
site and browse its bug tracker.

-- 
 \“Please to bathe inside the tub.” —hotel room, Japan |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: apscheduler error

2011-01-29 Thread Aahz
In article ,
=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=   wrote:
>
>A package of mine, TurboMail, suffers from the same threading issue if 
>used improperly; you enqueue e-mail, it starts a thread, then you 
>immediately exit.  TM tries to work around the issue, but in most cases 
>that workaround does not work properly.  (You get strange uncatchable 
>exceptions printed on stderr though AFIK the e-mail does get sent 
>correctly, your application may hang waiting for the thread pool to 
>drain if you have a "minimum thread count" option set.)

Why not write an exit handler that converts your thread to daemon?  (Or
something like that.)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: apscheduler error

2011-01-29 Thread Ben Finney
a...@pythoncraft.com (Aahz) writes:

> In article ,
> =?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=   wrote:
> >A package of mine, TurboMail, suffers from the same threading issue
> >if used improperly; you enqueue e-mail, it starts a thread, then you
> >immediately exit.
>
> Why not write an exit handler that converts your thread to daemon?  (Or
> something like that.)

For that purpose, I'll ask that you try the ‘python-daemon’ library
http://pypi.python.org/pypi/python-daemon>. It's designed
specifically for making the current process into a well-behaved Unix
daemon.

-- 
 \  “I knew things were changing when my Fraternity Brothers threw |
  `\   a guy out of the house for mocking me because I'm gay.” |
_o__)  —postsecret.com, 2010-01-19 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread Steven D'Aprano
On Sat, 29 Jan 2011 09:03:28 -0500, Roy Smith wrote:

> In article <8qijsgfgu...@mid.dfncis.de>,
>  Frank Dierkes  wrote:
> 
>> Naming the first parameter self is only a convention. It could be any
>> other name, too.
> 
> But it shouldn't.  The use of "self" is so universal that using anything
> else will just make your code more difficult for other people to
> understand.

It's a strong convention, true, but for Python to prohibit names other 
than self would be a serious mistake. It would add complication to the 
parser, for no real benefit. Remember, there's nothing special about 
methods. They're just ordinary functions which happen to be passed an 
extra argument at runtime. Making it compulsory to call the first 
argument "self" would seriously cripple Python's usefulness in at least 
three cases.

(1) Class methods receive the class, not the instance, and the convention 
is to call that first argument "cls". It would be confusing and 
misleading to call it "self".

Similarly, I sometimes use a similar descriptor which combines the 
functionality of class methods and ordinary methods. Since neither "self" 
nor "cls" would be appropriate, I use the name "this" for the first 
argument:

http://code.activestate.com/recipes/577030-dualmethod-descriptor/

Descriptors are a general protocol, so there may be other such 
technologies being used by people.

(2) Sometimes people use functions inside a class namespace as an 
ordinary function, perhaps as a factory function, called at class 
creation time. Here is a toy example that automates the building of 
properties:

class K(object):
def build(name):  # called at class creation time
def getter(self):
return getattr(self, "_" + name)
def setter(self, value):
setattr(self, "_" + name, value)
return property(getter, setter)
spam = build("spam")
ham = build("ham")


(3) Because methods are just a wrapper around an ordinary function, you 
can inject almost any function into a class at runtime. You don't know 
what the first argument of that function is called:

>>> class K(object):
... def __init__(self, value='spam'):
... self.attr = value
...
>>> def get_attr(obj):
... return obj.attr
...
>>> k = K()
>>> get_attr(k)
'spam'
>>>
>>> K.method = get_attr
>>> k.method()
'spam'




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


Re: Use the Source Luke

2011-01-29 Thread rusi
On Jan 30, 2:22 am, Ben Finney  wrote:
>
> The “problem”, which I don't consider to be a problem per se, is one of
> OS-wide policy, not “installers”. The policy is a matter of tradeoffs
> across the system, and isn't “tucking the code away in a dark corner”.

Earlier mail:

> If you want to blame anything for this (though I think it’s inaccurate
> to frame it as a problem), the correct target of your accusation is the
> fact that a filesystem path is the identifier for these modules that
> will be used by programs to find them.

I think this is a fairly accurate description of (one aspect of) the
problem.
If you dont see it as a problem how do you explain that google can
search the World Wide Web better than we can search our individual
hard disks?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use the Source Luke

2011-01-29 Thread Steven D'Aprano
On Sat, 29 Jan 2011 19:59:33 -0800, rusi wrote:

> On Jan 30, 2:22 am, Ben Finney  wrote:
>>
>> The “problem”, which I don't consider to be a problem per se, is one of
>> OS-wide policy, not “installers”. The policy is a matter of tradeoffs
>> across the system, and isn't “tucking the code away in a dark corner”.
> 
> Earlier mail:
> 
>> If you want to blame anything for this (though I think it’s inaccurate
>> to frame it as a problem), the correct target of your accusation is the
>> fact that a filesystem path is the identifier for these modules that
>> will be used by programs to find them.
> 
> I think this is a fairly accurate description of (one aspect of) the
> problem.
> If you dont see it as a problem how do you explain that google can
> search the World Wide Web better than we can search our individual hard
> disks?

I fail to see any connection between the location that operating systems 
store files, and the ability of Google to index publicly available 
websites. It sounds to me like the equivalent of "If you don't think 
Python programmers are a problem, how do you explain that it takes me 45 
minutes to drive to work in the morning but nearly an hour to drive home 
in the evening?"

Google has approximately one million servers indexing the web, and 
they're willing to use hundreds of terabytes of disk space to store the 
indexes. My desktop is *one* PC with little free space, and I'd rather 
trade off time for storage, so I don't keep any indexes of file content 
on my system. If I *wanted* to index my files, I could do so, although in 
fairness I'm not aware of any Linux tools which do this -- I know of 
`locate`, which indexes file *names* but not content, and `grep`, which 
searches file content but doesn't index what it finds.

On Windows and Mac, though, I believe there are standard utilities which 
will index file content if you allow them.

So... Google can search the web better than we can search our local hard 
drives because Google has invested tens or hundreds of millions into 
building a world-class search engine, and we haven't.


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


[pygame-bug] Pygame.cdrom bug

2011-01-29 Thread rantingrick

Hello folks,

Pygame  --the best little 2d game engine in Pythoina-- is great for
little 2d one off games and such (or so i've heard). I really don't do
much 2d graphics but pygame has some other helpful modules so i
downloded it about a year or so ago although i had not used it until
today. I just wanted to be ready just incase the 2d bug bit me. So
recently I wanted to do some cdrom automation for one of my Tkinter
scripts and thought... Hey, i finally found a good use for that old
pygame module!

So with much anticipation i moseyed on over to my site-packages folder
and dusted off the old pygame module and docs and i was coding away
just happy as a clam. I had my initialization working well, my
ejections were a breeze, and i even had some boolean testing
functionality all wrapped up nicely. Boy was i on cloud nine! And just
as i was finishing up the interface class with a "close" method i
realized in horror... YOU CAN OPEN THE CD TRAY WITH PYGAME HOWEVER FOR
SOME CRUEL AND UNJUST REASON YOU CANNOT CLOSE IT!  WTF?

Yes at this point i realized that without a method to close the cd
tray my little module was useless. Sure i could drop into my OS
functionality and close the cdtray by first setting up a device handle
and calling a few underlying Windows functions however i am convinced
that this basic functionality should be a part of any cdrom interface.
Why would someone create such an interface and leave out such an
important method? Surely this functionality must be available through
the SDL API? What gives pygame developers? What gives?

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


Re: [pygame-bug] Pygame.cdrom bug

2011-01-29 Thread Benjamin Kaplan
On Sat, Jan 29, 2011 at 11:25 PM, rantingrick  wrote:
>
> Hello folks,
>
> Pygame  --the best little 2d game engine in Pythoina-- is great for
> little 2d one off games and such (or so i've heard). I really don't do
> much 2d graphics but pygame has some other helpful modules so i
> downloded it about a year or so ago although i had not used it until
> today. I just wanted to be ready just incase the 2d bug bit me. So
> recently I wanted to do some cdrom automation for one of my Tkinter
> scripts and thought... Hey, i finally found a good use for that old
> pygame module!
>
> So with much anticipation i moseyed on over to my site-packages folder
> and dusted off the old pygame module and docs and i was coding away
> just happy as a clam. I had my initialization working well, my
> ejections were a breeze, and i even had some boolean testing
> functionality all wrapped up nicely. Boy was i on cloud nine! And just
> as i was finishing up the interface class with a "close" method i
> realized in horror... YOU CAN OPEN THE CD TRAY WITH PYGAME HOWEVER FOR
> SOME CRUEL AND UNJUST REASON YOU CANNOT CLOSE IT!  WTF?
>
> Yes at this point i realized that without a method to close the cd
> tray my little module was useless. Sure i could drop into my OS
> functionality and close the cdtray by first setting up a device handle
> and calling a few underlying Windows functions however i am convinced
> that this basic functionality should be a part of any cdrom interface.
> Why would someone create such an interface and leave out such an
> important method? Surely this functionality must be available through
> the SDL API? What gives pygame developers? What gives?
>
> --

1) That's a feature request (something isn't there that should be
there), not a bug (something that doesn't follow documented behaviors)

2) If you have a feature request or bug for a 3rd party package,
moaning about it here won't do anything. Try asking nicely either on
the project's mailing list or on the project's bug tracker.
http://www.pygame.org/wiki/patchesandbugs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use the Source Luke

2011-01-29 Thread rusi
On Jan 30, 9:21 am, Steven D'Aprano  wrote:
>
> > I think this is a fairly accurate description of (one aspect of) the
> > problem.
> > If you dont see it as a problem how do you explain that google can
> > search the World Wide Web better than we can search our individual hard
> > disks?
>
> I fail to see any connection between the location that operating systems
> store files, and the ability of Google to index publicly available
> websites.

http://en.wikipedia.org/wiki/Content-addressable_storage#Content-addressed_vs._Location-addressed
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use the Source Luke

2011-01-29 Thread Raymond Hettinger
On Jan 28, 3:10 pm, Ben Finney  wrote:
> Raymond Hettinger  writes:
> > The rest of the blame lies with installers. They all treat
> > human-readable scripts like they were binaries and tuck the code away
> > in a dark corner.
>
> That’s hardly a “blame” of installers. The modules are placed in such
> locations because they need to be accessible in a hierarchy at a
> location that is known to not conflict with anything else, and be
> predictable for the Python interpreter on the system.

Sure.  Installers are just installing where they're supposed to.
And good people have given a lot of thought to the preferred
target directories.  I'm just observing that the source files
are often ending-up out-of-sight and out-of-mind so that fewer
users ever see the source.

It's not deep a problem -- it would only take a symlink to
provide quick access.

My thesis is that we can do even better than that by adding
direct links from the docs to the relevant code with nice
syntax highlighting.


Raymond


P.S.  Making it easy to get to relevant source is only half of
the solution.  The remaining problem is cultural.  Perhaps every
project should have a recommended reading list.

As a start, I think the following are instructive and make for a good
read:

http://svn.python.org/view/python/branches/py3k/Lib/ftplib.py?view=markup
http://svn.python.org/view/python/branches/py3k/Lib/heapq.py?view=markup
http://svn.python.org/view/python/branches/py3k/Lib/collections.py?view=markup
http://svn.python.org/view/python/branches/py3k/Lib/queue.py?view=markup
http://svn.python.org/view/python/branches/py3k/Lib/functools.py?view=markup





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


Re: Python critique

2011-01-29 Thread rantingrick
On Dec 10 2010, 5:15 pm, Steven D'Aprano  wrote:

> n = 1
> [print(n) for n in (2,)]
> print n

Oh *thats* why we have print as a function! I always wanted to put
print in a list cmp. :-)


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


Re: Python critique

2011-01-29 Thread rantingrick
On Dec 13 2010, 4:40 am, Jean-Michel Pichavant
 wrote:

> It's more a demonstration that you can do it with python.
> The reason is that Python developpers will not put themself in the
> situation where they need to use a variable 'orange' line 32 and use the
> same variable 'orange' line 33 to refer to something else.

Yes and when a programmer does something like this he does not
demonstrate *scope-y* problems, he demonstrates *dope-y* problems. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple values for keyword argument

2011-01-29 Thread Ethan Furman

pa...@cruzio.com wrote:

I, myself, use the spanish word 'yo' instead (less keystrokes, I hate
'self', and it amuses me); if I'm working with my numerical experiments
I'll use 'n' or 'x'... although, when posting sample code to c.l.py I do
try to use 'self' to avoid possible confusion.  :)


I am glad you said this.  I have been avoiding understanding this 'self',
just accepting it :}  For the time being, since my programs I am creating
are for my own use, I think I will make my own names up, that are
descriptive to me as the programmer, it's all going to be interpreted
anyway.  And the other email equating to C's argv, etc. - now I get it.


Careful about the names you make-up -- to aid yourself and others you 
don't want to have dozen's of different names that all basically mean 
'this instance that I'm currently working on'.


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


Re: how to read the last line of a huge file???

2011-01-29 Thread John O'Hagan
On Sat, 29 Jan 2011, Aahz wrote:
> In article ,
> 
> John O'Hagan  wrote:
[...]
> >
> >def lastline(filename):
> >offset = 0
> >line = ''   
> >with open(filename) as f:
> >while True:
> >offset -= 1
> >f.seek(offset, 2)
> >nextline = f.next()
> >if nextline == '\n' and line.strip():
> >return line  
> >else:
> >line = nextline
> 
> It's a Bad Idea to mix direct file operations with the iterator API.

I didn't know that; from the docs on file objects:

"As a consequence of using a read-ahead buffer, combining next() with other 
file 
methods (like readline()) does not work right. However, using seek() to 
reposition the file to an absolute position will flush the read-ahead buffer."

You are right in general, but the second sentence is why I got away with it in 
this case.

> Use f.read() instead of f.next().

Which actually ends up improving the code as well:

def lastline(filename):
offset = 0
with open(filename) as f:
while 1:
f.seek(offset, 2)
if f.tell() == 0:
return f.read().strip()
line = f.read()
if line.strip() and line[0] == '\n':
return line.strip()
offset -= 1

although Tim Chase's solution covers files with very long lines.


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


Re: Looking for Remote Python Project

2011-01-29 Thread joy99
On Jan 30, 2:49 am, Ben Finney  wrote:
> joy99  writes:
> > I am looking for some remote Python Projects, which can be done from
> > home.
>
> > If any one knows of anything, I may be helpful enough.
>
> One of the best ways to begin contributing is to fix bugs and provide
> patches. For Python itself, see the Python bug tracker
> http://bugs.python.org/>; for other projects, see the project's
> site and browse its bug tracker.
>
> --
>  \                “Please to bathe inside the tub.” —hotel room, Japan |
>   `\                                                                   |
> _o__)                                                                  |
> Ben Finney

Thanks Ben for a nice reply and suggestion. This experience will
surely be rewarding one.
But do you know whether it would be a paying one, I am looking to be a
freelancer.
>From this room of expert Python programmers, developers I am trying to
get nice suggestions.

Wishing You a Happy Day Ahead,
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list