Re: Python Interview Questions

2012-07-09 Thread yeryomin . igor
On Tuesday, 30 October 2007 21:24:04 UTC+2, Tim Chase  wrote:
> > I have used Python for a couple of projects last year and
>  > I found it extremely useful. I could write two middle size
>  > projects in 2-3 months (part time). Right now I am a bit
>  > rusty and trying to catch up again with Python.
>  >
>  > I am now appearing for Job Interviews these days and I am
>  > wondering if anybody of you appeared for a Python
>  > Interview. Can you please share the questions you were
>  > asked. That will be great help to me.
> 
> While I haven't interviewed precisely for Python, I've been
> on the other (interviewing) end and can offer a few of the
> sorts of things I ask.  I don't expect perfect answers to
> all of them, but they show me a range of what the
> interviewee knows.  I try and give a scattershot of
> questions from the following areas to try and narrow down
> where they fall in terms of pythonability, and then grill
> more deeply around the edges that I find.
> 
> Basic Python:
> =
> - do they know a tuple/list/dict when they see it?
> 
> - when to use list vs. tuple vs. dict. vs. set
> 
> - can they use list comprehensions (and know when not to
>abuse them? :)
> 
> - can they use tuple unpacking for assignment?
> 
> - string building...do they use "+=" or do they build a list
>and use .join() to recombine them efficiently
> 
> - truth-value testing questions and observations (do they
>write "if x == True" or do they just write "if x")
> 
> - basic file-processing (iterating over a file's lines)
> 
> - basic understanding of exception handling
> 
> Broader Basic Python:
> =
> - questions about the standard library ("do you know if
>there's a standard library for doing X?", or "in which
>library would you find [common functionality Y]?")  Most
>of these are related to the more common libraries such as
>os/os.path/sys/re/itertools
> 
> - questions about iterators/generators
> 
> - questions about map/reduce/sum/etc family of functions
> 
> - questions about "special" methods ()
> 
> More Advanced Python:
> =
> - can they manipulate functions as first-class objects
>(Python makes it easy, but do they know how)
> 
> - more detailed questions about the std. libraries (such as
>datetime/email/csv/zipfile/networking/optparse/unittest)
> 
> - questions about testing (unittests/doctests)
> 
> - questions about docstrings vs. comments, and the "Why" of
>them
> 
> - more detailed questions about regular expressions
> 
> - questions about mutability
> 
> - keyword/list parameters and unpacked kwd args
> 
> - questions about popular 3rd-party toolkits (BeautifulSoup,
>pyparsing...mostly if they know about them and when to use
>them, not so much about implementation details)
> 
> - questions about monkey-patching
> 
> - questions about PDB
> 
> - questions about properties vs. getters/setters
> 
> - questions about classmethods
> 
> - questions about scope/name-resolution
> 
> - use of lambda
> 
> Python History:
> ===
> - decorators added in which version?
> 
> - "batteries included" SQL-capible DB in which version?
> 
> - the difference between "class Foo" and "class Foo(object)"
> 
> - questions from "import this" about pythonic code
> 
> Python Resources:
> =
> - what do they know about various Python web frameworks
>(knowing a few names is usually good enough, though
>knowledge about the frameworks is a nice plus) such as
>Django, TurboGears, Zope, etc.
> 
> - what do they know about various Python GUI frameworks and
>the pros/cons of them (tkinter, wx, pykde, etc)
> 
> - where do they go with Python related questions (c.l.p,
>google, google-groups, etc)
> 
> Other Process-releated things:
> ==
> - do they use revision control
>(RCS/CVS/Subversion/Mercurial/Git...anything but VSS) and
>know how to use it well
> 
> - do they write automated tests for their code
> 
> Touchy-feely things:
> 
> - tabs vs. spaces, and their reasoning
> 
> - reason for choosing Python
> 
> - choice of editor/IDE
> 
> Good luck with your interviewing and hope this helped,
> 
> -tkc

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


How can I disable module of tkinter when compiling Python 2.5 on redhat9 ?

2012-07-09 Thread cheetah
I don't need it.

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


Re: How to safely maintain a status file

2012-07-09 Thread Christian Heimes
Am 09.07.2012 07:50, schrieb Plumo:
>> Windows doesn't suppport atomic renames if the right side exists.  I
>> suggest that you implement two code paths:
>
> Problem is if the process is stopped between unlink and rename there
> would no status file.

Yeah, you have to suffer all of Windows' design flaws. You could add a
backup status file or use a completely different approach.

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


Re: Discussion on some Code Issues

2012-07-09 Thread Chris Angelico
On Mon, Jul 9, 2012 at 10:57 AM, Steven D'Aprano
 wrote:
> On Mon, 09 Jul 2012 07:54:47 +1000, Chris Angelico wrote:
>
>> It's like
>> the difference between reminder text on a Magic: The Gathering card and
>> the actual entries in the Comprehensive Rules. Perfect example is the
>> "Madness" ability - the reminder text explains the ability, but uses
>> language that actually is quite incorrect. It's a better explanation,
>> though.
>
> Hang on, you say that an explanation which is "quite incorrect" is
> *better* than one which is correct?
>
> I can see why they call the card "Madness".
>
> :-P

Agreed about the ability name :) The fact is, though, that when you're
explaining something, it's often better to have a one-sentence
explanation that's not quite technically accurate than two paragraphs
explaining it in multiple steps and are opaque to anyone who doesn't
have the rules-lawyer mind. (I happen to have such a mind. It's not
always a good thing, but it makes me a better debugger.)

Does it really hurt to anthropomorphize and say that "Python looks for
modules in the directories in sys.path" instead of "Module lookup
consists of iterating over the elements in sys.path [and that's
leaving out the worst-case DFS where you explain THAT in detail],
calling combine_path [or whatever it is] with the element and the
module name, and attempting to stat/open the result"? While your
listener's getting bogged down in unnecessary detail, s/he isn't
grokking the overall purpose of what you're saying.

One option is more accurate. The other is far more helpful.

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


Re: How to safely maintain a status file

2012-07-09 Thread Nobody
On Sun, 08 Jul 2012 22:57:56 +0200, Laszlo Nagy wrote:

> Yes, this is much better. Almost perfect. Don't forget to consult your
> system documentation, and check if the rename operation is atomic or not.
> (Most probably it will only be atomic if the original and the renamed file
> are on the same physical partition and/or mount point).

On Unix, rename() is always atomic, and requires that source and
destination are on the same partition (if you want to "move" a file across
partitions, you have to copy it then delete the original).

> But even if the rename operation is atomic, there is still a race
> condition. Your program can be terminated after the original status file
> has been deleted, and before the temp file was renamed. In this case, you
> will be missing the status file (although your program already did
> something just it could not write out the new status).

In the event of abnormal termination, losing some data is to be expected.
The idea is to only lose the most recent data while keeping the old copy,
rather than losing everything. Writing to a temp file then rename()ing
achieves that.

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


migrating from python 2.4 to python 2.6

2012-07-09 Thread Mark Devine
Hi
I have a large code base that was written in python 2.4. I want to migrate
to python 2.6. Are there any tools that will aid me in this migration?

Thanks

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


Re: How can I disable module of tkinter when compiling Python 2.5 on redhat9 ?

2012-07-09 Thread Putilov Roman

09.07.12 13:21, cheetah ?:

I don't need it.

thanks


In python's setup.py replace:
self.detect_tkinter(inc_dirs, lib_dirs)
of
def detect_modules(self):

This will ignore the compilation of _tkinter.c and tkappinit.c of
the python distribution.

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


Re: migrating from python 2.4 to python 2.6

2012-07-09 Thread Mark Lawrence

On 09/07/2012 10:37, Mark Devine wrote:

Hi
I have a large code base that was written in python 2.4. I want to migrate
to python 2.6. Are there any tools that will aid me in this migration?

Thanks

A





Check the what's new for python 2.6.  If, and I doubt that there are, 
any compatabilty issues change your code accordingly.  If not your code 
should run as is. An alternative is simply to run your code and see if 
it breaks, again I doubt it.


--
Cheers.

Mark Lawrence.



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


Re: Python Interview Questions

2012-07-09 Thread Tim Chase
On 07/09/12 01:39, yeryomin.i...@gmail.com wrote:
> On Tuesday, 30 October 2007 21:24:04 UTC+2, Tim Chase  wrote:

yes, yes I did, almost 5 years ago. :-)

You didn't include any questions/comments on my email, so it's a bit
hard to respond.

>> While I haven't interviewed precisely for Python, I've been
>> on the other (interviewing) end and can offer a few of the
>> sorts of things I ask. 
[snip]
>> Python History:
>> ===
>> - decorators added in which version?
>>
>> - "batteries included" SQL-capible DB in which version?

I've long wanted to update my original post in this department to
include things like the "with" statement as well as my reasoning.
Some of our deployments were stuck on earlier versions (currently
our oldest is a 2.4 deployment that is merrily chugging along,
somewhat stuck due to an external binary dependency for which terms
changed between versions).  At the time I wrote that, we had some
2.2 and 2.3 code in production that couldn't use decorators, and
sqlite wasn't officially added until 2.5 (IIRC).   Now that
everything is at least 2.4, code can now use decorators freely.

I'd also likely include questions about integer division and other
stuff added in 3.x (such as the default new-class behavior).

So my main motivation was to make sure applicants knew that, in some
of our environments, certain features might not be available.  Not
that I wanted to hire a Python historian.

>> Other Process-releated things:
>> ==
>> - do they use revision control
>>(RCS/CVS/Subversion/Mercurial/Git...anything but VSS) and
>>know how to use it well
>>
>> - do they write automated tests for their code

Don't let the importance of these two escape.  It's SOOO easy to
grab any of the freely available VCS tools and learn the ropes, or
to write some test code.  Failure to do so just seems like
negligence these days.

-tkc





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


Re: Deditor 0.4.0

2012-07-09 Thread Jean-Michel Pichavant

Kruptein wrote:

Hey I released a new version of my python-focused text-editor.
you can download it at http://launchpad.net/deditor

What is it?
Deditor is aimed to be a text-editor which can be used as a basic text-editor 
as gedit or with the right plugins become a full-feature ide.
I focus on making it a python specific editor but you can use it to edit other 
files as well.
It is python specific because the plugin system that is used (DPlug) is written 
in python and thus all plugins are written in python.  Also some of the plugins 
there is one plugin that comes bundled with deditor that adds some python 
specific features like code-analyzing, code-inspection, auto-completion etc.

So plugins are the main core of the program you can disable and enable plugins 
at your will.  The plugins that come bundled are made to increase the joy of 
programming.

NOTICE that this I don't regard this as a stable product yet.  There is no high 
risk in data loss and there are definitely no privacy concerns but you should 
still be aware that there are bugs/malfunctions and that you will encounter 
them.

I hope some of you like it and if you don't try to give some constructive 
criticism :)


Most changes in regard to previous release are under the hood.  so existing 
users might not notice a lot.
Also the customize plugin's second configuration tab: syntax highlighting is 
bugged try to avoid it :p
  

Good job.

I have 2 question:
Aren't you reinventing the wheel ?
No way to use tabs for tabulation ??? (I'm CEO of the 'space haters club')

Otherwise, I found this bug :
Start the editor, click twice on 'Analyse code', and you'll get a traceback.
I looked into the related code:

def dUpdate(self, trig, value=None):
   if trig == "tabclosed":
   return self.tabClosed(value)

def tabClosed(self, tab):
   """Checks if the tab that is closing is a project"""
   if tab.parentTab == None:
   pass


Your method interfaces are quite inconsistent, I sense this is quite 
global to your code:


1/ dUpdate has None as default value for 'value'
2/ tab.parentTab will fail if tab is None
3/ on the traceback you get from the bug above, a bool has been given, 
bool has no parentTab.



Here are 2 advices:

1/ Default values are for the fool/weak/noob/..., your pick. I tend to 
use them only for backward compatibilty or for interface stability. 
Otherwise, it's better not to use them. Some people still use them 
appropriately but in your I think it may help.


2/ In your docstrings, note down the expected type of your parameters 
(only 1 type ! (except for the None alternative)) and stick to it.


Regards,

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


Re: Deditor 0.4.0

2012-07-09 Thread Kruptein
Op maandag 9 juli 2012 13:05:58 UTC+2 schreef Jean-Michel Pichavant het 
volgende:
> Kruptein wrote:
> > Hey I released a new version of my python-focused text-editor.
> > you can download it at http://launchpad.net/deditor
> >
> > What is it?
> > Deditor is aimed to be a text-editor which can be used as a basic 
> > text-editor as gedit or with the right plugins become a full-feature ide.
> > I focus on making it a python specific editor but you can use it to edit 
> > other files as well.
> > It is python specific because the plugin system that is used (DPlug) is 
> > written in python and thus all plugins are written in python.  Also some of 
> > the plugins there is one plugin that comes bundled with deditor that adds 
> > some python specific features like code-analyzing, code-inspection, 
> > auto-completion etc.
> >
> > So plugins are the main core of the program you can disable and enable 
> > plugins at your will.  The plugins that come bundled are made to increase 
> > the joy of programming.
> >
> > NOTICE that this I don't regard this as a stable product yet.  There is no 
> > high risk in data loss and there are definitely no privacy concerns but you 
> > should still be aware that there are bugs/malfunctions and that you will 
> > encounter them.
> >
> > I hope some of you like it and if you don't try to give some constructive 
> > criticism :)
> >
> >
> > Most changes in regard to previous release are under the hood.  so existing 
> > users might not notice a lot.
> > Also the customize plugin's second configuration tab: syntax highlighting 
> > is bugged try to avoid it :p
> >   
> Good job.
> 
> I have 2 question:
> Aren't you reinventing the wheel ?
> No way to use tabs for tabulation ??? (I'm CEO of the 'space haters club')
> 
> Otherwise, I found this bug :
> Start the editor, click twice on 'Analyse code', and you'll get a traceback.
> I looked into the related code:
> 
> def dUpdate(self, trig, value=None):
> if trig == "tabclosed":
> return self.tabClosed(value)
> 
> def tabClosed(self, tab):
> """Checks if the tab that is closing is a project"""
> if tab.parentTab == None:
> pass
> 
> 
> Your method interfaces are quite inconsistent, I sense this is quite 
> global to your code:
> 
> 1/ dUpdate has None as default value for 'value'
> 2/ tab.parentTab will fail if tab is None
> 3/ on the traceback you get from the bug above, a bool has been given, 
> bool has no parentTab.
> 
> 
> Here are 2 advices:
> 
> 1/ Default values are for the fool/weak/noob/..., your pick. I tend to 
> use them only for backward compatibilty or for interface stability. 
> Otherwise, it's better not to use them. Some people still use them 
> appropriately but in your I think it may help.
> 
> 2/ In your docstrings, note down the expected type of your parameters 
> (only 1 type ! (except for the None alternative)) and stick to it.
> 
> Regards,
> 
> JM

To begin with not everything that I want to see is yet implemented.  A lot 
still has to be done for example indentation although I really hate tabs ;D I 
will give the option in a future release maybe even the next one.

I'll check the bug as it probably is indeed a bug.

Regarding the default value dUpdate is a method from the plugin system and is 
called when a trigger is updated.  some triggers give an additional value for 
example a trigger that registers pressed buttons could potentially give which 
exact key as value.  However some triggers don't need this additional value.  
If a plugin needs both types of triggers the method will need this default 
value to work.  Also the dev version already changed that there always will be 
sent a value so no need for the default value anymore.

Regarding the docstrings: as deditor still is under heavy development not all 
docstrings are correct or even there.

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


recompiling standard modules

2012-07-09 Thread Rita
I noticed that active state python Tk inter isnt compiled with
--enable-threads therefore I would like to recompile the module with a new
version of TCL/TK which is compiled with threads. How can I do this?



-- 
--- Get your facts first, then you can distort them as you please.--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Discussion on some Code Issues

2012-07-09 Thread Steven D'Aprano
On Mon, 09 Jul 2012 18:41:28 +1000, Chris Angelico wrote:

> Does it really hurt to anthropomorphize 

Don't anthropomorphise computers. They don't like it when you do.


> and say that "Python looks for
> modules in the directories in sys.path" instead of "Module lookup
> consists of iterating blah blah blah yadda watermelon yadda blah".

I don't think so, I often talk about Python looking for files myself. The 
intentional stance is an incredibly powerful technique for understanding 
behaviour of all sorts of entities, sentient or not, from DNA to 
computers to corporations, and even people.

But it does depend on context. Sometimes you need more detail than just 
"Python looks". You need to know precisely *how* Python looks, and how it 
decides whether it has found or not. 

And note that I'm still using the intentional stance.



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


how to write configure

2012-07-09 Thread contro opinion
PyGObject uses the standard autotools for the build infrastructure.  To
build, it should be as simple as running:

$ ./configure --prefix=

my python2.7 is  in  /usr/lib/python2.7

will  i  write :
./configure --prefix=/usr/lib/python2.7

or

./configure --prefix=/usr/lib
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deditor 0.4.0

2012-07-09 Thread Jean-Michel Pichavant

Kruptein wrote:

Op maandag 9 juli 2012 13:05:58 UTC+2 schreef Jean-Michel Pichavant het 
volgende:
  

Kruptein wrote:


Hey I released a new version of my python-focused text-editor.
you can download it at http://launchpad.net/deditor

What is it?
Deditor is aimed to be a text-editor which can be used as a basic text-editor 
as gedit or with the right plugins become a full-feature ide.
I focus on making it a python specific editor but you can use it to edit other 
files as well.
It is python specific because the plugin system that is used (DPlug) is written 
in python and thus all plugins are written in python.  Also some of the plugins 
there is one plugin that comes bundled with deditor that adds some python 
specific features like code-analyzing, code-inspection, auto-completion etc.

So plugins are the main core of the program you can disable and enable plugins 
at your will.  The plugins that come bundled are made to increase the joy of 
programming.

NOTICE that this I don't regard this as a stable product yet.  There is no high 
risk in data loss and there are definitely no privacy concerns but you should 
still be aware that there are bugs/malfunctions and that you will encounter 
them.

I hope some of you like it and if you don't try to give some constructive 
criticism :)


Most changes in regard to previous release are under the hood.  so existing 
users might not notice a lot.
Also the customize plugin's second configuration tab: syntax highlighting is 
bugged try to avoid it :p
  
  

Good job.

I have 2 question:
Aren't you reinventing the wheel ?
No way to use tabs for tabulation ??? (I'm CEO of the 'space haters club')

Otherwise, I found this bug :
Start the editor, click twice on 'Analyse code', and you'll get a traceback.
I looked into the related code:

def dUpdate(self, trig, value=None):
if trig == "tabclosed":
return self.tabClosed(value)

def tabClosed(self, tab):
"""Checks if the tab that is closing is a project"""
if tab.parentTab == None:
pass


Your method interfaces are quite inconsistent, I sense this is quite 
global to your code:


1/ dUpdate has None as default value for 'value'
2/ tab.parentTab will fail if tab is None
3/ on the traceback you get from the bug above, a bool has been given, 
bool has no parentTab.



Here are 2 advices:

1/ Default values are for the fool/weak/noob/..., your pick. I tend to 
use them only for backward compatibilty or for interface stability. 
Otherwise, it's better not to use them. Some people still use them 
appropriately but in your I think it may help.


2/ In your docstrings, note down the expected type of your parameters 
(only 1 type ! (except for the None alternative)) and stick to it.


Regards,

JM



To begin with not everything that I want to see is yet implemented.  A lot 
still has to be done for example indentation although I really hate tabs ;D I 
will give the option in a future release maybe even the next one.

I'll check the bug as it probably is indeed a bug.

Regarding the default value dUpdate is a method from the plugin system and is 
called when a trigger is updated.  some triggers give an additional value for 
example a trigger that registers pressed buttons could potentially give which 
exact key as value.  However some triggers don't need this additional value.  
If a plugin needs both types of triggers the method will need this default 
value to work.  Also the dev version already changed that there always will be 
sent a value so no need for the default value anymore.

  

If you can, use the **kwargs syntax.
def foo(tabs, **kwargs):
   # optional arg
   if kwargs.get('saveFile', False):
  self.saveFile(tab.file)
   # required arg
   if kwargs['saveFile']:
   self.saveFile()
  

The type of kwargs will be consistent, it will be always a dictionnary, 
possibly an empty one, but still a dictionnary, and best part of it, if 
you change the number of argument in the call, you don't break your 
interface.



Regarding the docstrings: as deditor still is under heavy development not all 
docstrings are correct or even there.

  
Yep, but writing the expected type of your parameters always help, in 
particular during the dev phase. you can save the verbose part of the 
documentation for later.


Cheers,

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


Re: Python Interview Questions

2012-07-09 Thread Roy Smith
In article <3e0ef383-9615-4b4d-89c1-e55199711...@googlegroups.com>,
 yeryomin.i...@gmail.com wrote:

> On Tuesday, 30 October 2007 21:24:04 UTC+2, Tim Chase  wrote:

> > - more detailed questions about the std. libraries (such as
> >datetime/email/csv/zipfile/networking/optparse/unittest)

You need to be careful when you ask questions like this.  I would expect 
somebody to be aware of those and have a high-level understanding of 
what they do, but certainly not remember the details of the exact syntax 
and argument order.  Even with stuff I use everyday (like unittest and 
datetime), I have a browser open to the reference manual most of the 
time.

> > - questions about PDB

Heh.  I would answer that with, "Python Debugger?  I've never used it".

> > Python History:
> > ===
> > - decorators added in which version?
> > 
> > - "batteries included" SQL-capible DB in which version?
> > 
> > - the difference between "class Foo" and "class Foo(object)"
> > 
> > - questions from "import this" about pythonic code

With the exception of the question about new-style classes, these are 
silly questions.  I was around when both decorators and sqlite3 were 
added.  I couldn't possible tell you when to any precision better than 
"2 dot something".  As for the zen of python, it's cute, and a piece of 
python folklore, but hardly an essential part of being a good python p
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deditor 0.4.0

2012-07-09 Thread Kruptein
Op maandag 9 juli 2012 14:54:03 UTC+2 schreef Jean-Michel Pichavant het 
volgende:
> Kruptein wrote:
> > Op maandag 9 juli 2012 13:05:58 UTC+2 schreef Jean-Michel Pichavant het 
> > volgende:
> >   
> >> Kruptein wrote:
> >> 
> >>> Hey I released a new version of my python-focused text-editor.
> >>> you can download it at http://launchpad.net/deditor
> >>>
> >>> What is it?
> >>> Deditor is aimed to be a text-editor which can be used as a basic 
> >>> text-editor as gedit or with the right plugins become a full-feature ide.
> >>> I focus on making it a python specific editor but you can use it to edit 
> >>> other files as well.
> >>> It is python specific because the plugin system that is used (DPlug) is 
> >>> written in python and thus all plugins are written in python.  Also some 
> >>> of the plugins there is one plugin that comes bundled with deditor that 
> >>> adds some python specific features like code-analyzing, code-inspection, 
> >>> auto-completion etc.
> >>>
> >>> So plugins are the main core of the program you can disable and enable 
> >>> plugins at your will.  The plugins that come bundled are made to increase 
> >>> the joy of programming.
> >>>
> >>> NOTICE that this I don't regard this as a stable product yet.  There is 
> >>> no high risk in data loss and there are definitely no privacy concerns 
> >>> but you should still be aware that there are bugs/malfunctions and that 
> >>> you will encounter them.
> >>>
> >>> I hope some of you like it and if you don't try to give some constructive 
> >>> criticism :)
> >>>
> >>>
> >>> Most changes in regard to previous release are under the hood.  so 
> >>> existing users might not notice a lot.
> >>> Also the customize plugin's second configuration tab: syntax highlighting 
> >>> is bugged try to avoid it :p
> >>>   
> >>>   
> >> Good job.
> >>
> >> I have 2 question:
> >> Aren't you reinventing the wheel ?
> >> No way to use tabs for tabulation ??? (I'm CEO of the 'space haters club')
> >>
> >> Otherwise, I found this bug :
> >> Start the editor, click twice on 'Analyse code', and you'll get a 
> >> traceback.
> >> I looked into the related code:
> >>
> >> def dUpdate(self, trig, value=None):
> >> if trig == "tabclosed":
> >> return self.tabClosed(value)
> >>
> >> def tabClosed(self, tab):
> >> """Checks if the tab that is closing is a project"""
> >> if tab.parentTab == None:
> >> pass
> >>
> >>
> >> Your method interfaces are quite inconsistent, I sense this is quite 
> >> global to your code:
> >>
> >> 1/ dUpdate has None as default value for 'value'
> >> 2/ tab.parentTab will fail if tab is None
> >> 3/ on the traceback you get from the bug above, a bool has been given, 
> >> bool has no parentTab.
> >>
> >>
> >> Here are 2 advices:
> >>
> >> 1/ Default values are for the fool/weak/noob/..., your pick. I tend to 
> >> use them only for backward compatibilty or for interface stability. 
> >> Otherwise, it's better not to use them. Some people still use them 
> >> appropriately but in your I think it may help.
> >>
> >> 2/ In your docstrings, note down the expected type of your parameters 
> >> (only 1 type ! (except for the None alternative)) and stick to it.
> >>
> >> Regards,
> >>
> >> JM
> >> 
> >
> > To begin with not everything that I want to see is yet implemented.  A lot 
> > still has to be done for example indentation although I really hate tabs ;D 
> > I will give the option in a future release maybe even the next one.
> >
> > I'll check the bug as it probably is indeed a bug.
> >
> > Regarding the default value dUpdate is a method from the plugin system and 
> > is called when a trigger is updated.  some triggers give an additional 
> > value for example a trigger that registers pressed buttons could 
> > potentially give which exact key as value.  However some triggers don't 
> > need this additional value.  If a plugin needs both types of triggers the 
> > method will need this default value to work.  Also the dev version already 
> > changed that there always will be sent a value so no need for the default 
> > value anymore.
> >
> >   
> If you can, use the **kwargs syntax.
> def foo(tabs, **kwargs):
> # optional arg
> if kwargs.get('saveFile', False):
>self.saveFile(tab.file)
> # required arg
> if kwargs['saveFile']:
> self.saveFile()
>
> 
> The type of kwargs will be consistent, it will be always a dictionnary, 
> possibly an empty one, but still a dictionnary, and best part of it, if 
> you change the number of argument in the call, you don't break your 
> interface.
> 
> > Regarding the docstrings: as deditor still is under heavy development not 
> > all docstrings are correct or even there.
> >
> >   
> Yep, but writing the expected type of your parameters always help, in 
> particular during the dev phase. you can save the verbose part of the 
> documentation for later.
> 
> Cheers,
> 
> JM

Yeah I started to use kwargs in some method

Re: How to safely maintain a status file

2012-07-09 Thread Duncan Booth
Richard Baron Penman  wrote:

> Is there a better way? Or do I need to use a database?

Using a database would seem to meet a lot of your needs. Don't forget that 
Python comes with a sqlite database engine included, so it shouldn't take 
you more than a few lines of code to open the database once and then write 
out your status every few seconds.

import sqlite3

con = sqlite3.connect('status.db')

...
with con:
cur = con.cursor()
cur.execute('UPDATE ...', ...)

and similar code to restore the status or create required tables on 
startup.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Discussion on some Code Issues

2012-07-09 Thread Chris Angelico
On Mon, Jul 9, 2012 at 10:24 PM, Steven D'Aprano
 wrote:
> But it does depend on context. Sometimes you need more detail than just
> "Python looks". You need to know precisely *how* Python looks, and how it
> decides whether it has found or not.

Agreed. So, looking back at the original context: A question was posed
that isn't really about Python at all, but more about file systems. I
gave a simple one-sentence answer that omitted heaps of details. It
didn't seem likely that someone confused by path names would be
changing the current directory inside the script, nor that the
distinction of who evaluates a path would be significant (how often
does _anyone_ care whether your path is parsed by Python, by the OS,
or by the underlying file system?).

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


Re: tiffany 0.6.1 released

2012-07-09 Thread Christian Tismer

On 30.06.12 18:25, Paul Rubin wrote:

Christian Tismer  writes:

Tiffany stands for any tiff. The tiny module solves a large set of
problems, has no dependencies and just works wherever Python works.
Tiffany was developed in the course of the *DiDoCa* project and will
always appear on PyPi.

This sounds pretty neat.  I didn't comment on it earlier because I
haven't tried it out, since I haven't had occasion to deal with tiff
files anytime recently.  But I've had to process them for some projects
in the past, and tiffany would have been useful then.  It's good to know
that it's out there.


Meanwhile I got some feedback and test data.
(Thanks to Christian and Anthon)
It turns out to be a problem with multiple strips in a tiff file.
PIL does not support that. Maybe I can find an easy solution,
maybe I'm better off using

smc.freeimage

as suggested by Christian Heimes,

we will see. Right now I'm pretty exhaused after EuroPython...

cheers - chris

--
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121 :*Starship* http://starship.python.net/
14482 Potsdam: PGP key -> http://pgp.uni-mainz.de
work +49 173 24 18 776  mobile +49 173 24 18 776  fax n.a.
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/

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


Re: Python Interview Questions

2012-07-09 Thread Tim Chase
On 07/09/12 08:25, Roy Smith wrote:
>> On Tuesday, 30 October 2007 21:24:04 UTC+2, Tim Chase  wrote:
> 
>>> - more detailed questions about the std. libraries (such as
>>>datetime/email/csv/zipfile/networking/optparse/unittest)
> 
> You need to be careful when you ask questions like this.  I would expect 
> somebody to be aware of those and have a high-level understanding of 
> what they do, but certainly not remember the details of the exact syntax 
> and argument order.  Even with stuff I use everyday (like unittest and 
> datetime), I have a browser open to the reference manual most of the 
> time.

Yeah, the aim isn't to grill them on the minutia, but to get a
feeling that they know the basics.  The zipfile module offers a
ZipFile object for reading/writing zip files with or without
compression.  The CSV file allows for reading/writing CSV files with
definable delimiters and quoting/escaping.  Etc.


>>> - questions about PDB
> 
> Heh.  I would answer that with, "Python Debugger?  I've never used it".

The ability to know off the top of your head that it's the "Python
Debugger" is more than enough :-)  That's just first-order
ignorance:  you know what you don't know and can spend a few minutes
reading up on it if you need it.  The second[or higher]-order
ignorance of not knowing what pdb is (or, if you need more powerful
debugging, how to do it) is sign the person hasn't been programming
in Python much.

>>> Python History:
>>> ===
>>> - decorators added in which version?
>>>
>>> - "batteries included" SQL-capible DB in which version?
>>>
>>> - the difference between "class Foo" and "class Foo(object)"
>>>
>>> - questions from "import this" about pythonic code
> 
> With the exception of the question about new-style classes, these are 
> silly questions.  I was around when both decorators and sqlite3 were 
> added.  I couldn't possible tell you when to any precision better than 
> "2 dot something". 

I'd even be satisfied if a person just knew that such features
weren't there all along and might need to be worked around for older
deployments.

> As for the zen of python, it's cute, and a piece of python
> folklore, but hardly an essential part of being a good python p

[Ed: something appears to have gotten truncated there]  Yeah, it's
more about a person being sufficiently steeped in python to know
bits and pieces of the zen, and their ability to recognize/create
pythonic code.  I've seen enough Java-written-in-Python to know what
I don't want :-)

-tkc


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


Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-09 Thread Rick Johnson
On Jul 9, 12:58 am, Terry Reedy  wrote:
> When posting problem code, you should post a minimal, self-contained
> example that people can try on other systems and versions. Can you
> create the problem with one record, which you could give, and one
> binding? Do you need 4 fields, or would 1 'work'?

I'll firmly back that sentiment. Fredric, if you cannot get the
following simple code events to work properly, then how do you think
you can get events working properly on something more complex?

## START CODE ARTISTRY ##
import Tkinter as tk
from Tkconstants import *

class MyFrame(tk.Frame):
def __init__(self, master, **kw):
tk.Frame.__init__(self, master, **kw)
self.bind('', self.evtMouseEnter)
self.bind('', self.evtMouseLeave)
self.bind('', self.evtButtonOneClick)

def evtMouseEnter(self, event):
event.widget.config(bg='magenta')

def evtMouseLeave(self, event):
event.widget.config(bg='SystemButtonFace')

def evtButtonOneClick(self, event):
event.widget.config(bg='green')

if __name__ == '__main__':
root = tk.Tk()
for x in range(10):
f = MyFrame(root, height=20, bd=1, relief=SOLID)
f.pack(fill=X, expand=YES, padx=5, pady=5)
root.mainloop()
## END CODE ARTISTRY ##

---
More points to ponder:
---
1. Just because the Tkinter designers decided to use idiotic names for
event sequences does not mean you are required to blindly follow their
bad example (the whole: "if johnny jumps off a cliff...", thing comes
to mind)

2. I would strongly recommend you invest more thought into your event
handler identifiers. ALL event handlers should marked as *event
handlers* using a prefix. I like to use the prefix "evt". Some people
prefer other prefixes. In any case, just remember to be consistent.
Also, event handler names should reflect WHAT event they are
processing, not some esoteric functionality of the application like
"pick_record" or "info_profile". However if you like, simply have the
event handler CALL an outside func/meth. This type of consistency is
what separates the men from the boys.

3. The Python Style Guide[1] frowns on superfluous white space (be it
horizontal OR vertical!) I would strongly recommend you read and adapt
as much of this style as you possibly can bear. Even if we don't all
get along, it IS *very* important that we structure our code in a
similar style.

[1] http://www.python.org/dev/peps/pep-0008/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Rick Johnson
On Jul 9, 12:40 pm, Tim Chase  wrote:
> The second[or higher]-order
> ignorance of not knowing what pdb is (or, if you need more powerful
> debugging, how to do it) is sign the person hasn't been programming
> in Python much.

So guru knowledge of pdb is prerequisite to being accepted as a
Pythonista? I find that ridiculous since *real* programmers don't use
debuggers anyway.

> [Ed: something appears to have gotten truncated there]  Yeah, it's
> more about a person being sufficiently steeped in python to know
> bits and pieces of the zen, and their ability to recognize/create
> pythonic code.  I've seen enough Java-written-in-Python to know what
> I don't want :-)

I know you are a member of the group who has an aversion to strict OOP
paradigm but is this a justified aversion, or just fear of OOP due to
static evolution? Look, i don't like java's strict approach either,
however, i do not have an aversion to OOP.

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


Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-09 Thread Terry Reedy

On 7/9/2012 1:49 PM, Rick Johnson wrote:

On Jul 9, 12:58 am, Terry Reedy  wrote:

When posting problem code, you should post a minimal, self-contained
example that people can try on other systems and versions. Can you
create the problem with one record, which you could give, and one
binding? Do you need 4 fields, or would 1 'work'?


I'll firmly back that sentiment. Fredric, if you cannot get the
following simple code events to work properly, then how do you think
you can get events working properly on something more complex?

## START CODE ARTISTRY ##
import Tkinter as tk
from Tkconstants import *

class MyFrame(tk.Frame):
 def __init__(self, master, **kw):
 tk.Frame.__init__(self, master, **kw)
 self.bind('', self.evtMouseEnter)
 self.bind('', self.evtMouseLeave)
 self.bind('', self.evtButtonOneClick)

 def evtMouseEnter(self, event):
 event.widget.config(bg='magenta')

 def evtMouseLeave(self, event):
 event.widget.config(bg='SystemButtonFace')

 def evtButtonOneClick(self, event):
 event.widget.config(bg='green')

if __name__ == '__main__':
 root = tk.Tk()
 for x in range(10):
 f = MyFrame(root, height=20, bd=1, relief=SOLID)
 f.pack(fill=X, expand=YES, padx=5, pady=5)
 root.mainloop()
## END CODE ARTISTRY ##


I copied and pasted this self-contained code into a 3.3 Idle edit window 
and lightly edited for 3.x. Change 'Tkinter' to 'tkinter', remove 
tkconstants import and prefix constants with 'tk.'. (The alternative: 
change 'tkconstants' to 'tkinter.constants', but I prefer prefixes). It 
runs as expected.


import tkinter as tk

class MyFrame(tk.Frame):
def __init__(self, master, **kw):
tk.Frame.__init__(self, master, **kw)
self.bind('', self.evtMouseEnter)
self.bind('', self.evtMouseLeave)
self.bind('', self.evtButtonOneClick)

def evtMouseEnter(self, event):
event.widget.config(bg='magenta')

def evtMouseLeave(self, event):
event.widget.config(bg='SystemButtonFace')

def evtButtonOneClick(self, event):
event.widget.config(bg='green')

if __name__ == '__main__':
root = tk.Tk()
for x in range(10):
f = MyFrame(root, height=20, bd=1, relief=tk.SOLID)
f.pack(fill=tk.X, expand=tk.YES, padx=5, pady=5)
root.mainloop()

Add details and data (maybe less than 10 records) until you get what you 
want or recreate problem.


--
Terry Jan Reedy



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


Re: Python Interview Questions

2012-07-09 Thread Demian Brecht
On Monday, 9 July 2012 10:40:59 UTC-7, Tim Chase  wrote:
> On 07/09/12 08:25, Roy Smith wrote:
> >> On Tuesday, 30 October 2007 21:24:04 UTC+2, Tim Chase  wrote:
> > 
> >>> - more detailed questions about the std. libraries (such as
> >>>datetime/email/csv/zipfile/networking/optparse/unittest)
> > 
> > You need to be careful when you ask questions like this.  I would expect 
> > somebody to be aware of those and have a high-level understanding of 
> > what they do, but certainly not remember the details of the exact syntax 
> > and argument order.  Even with stuff I use everyday (like unittest and 
> > datetime), I have a browser open to the reference manual most of the 
> > time.
> 
> Yeah, the aim isn't to grill them on the minutia, but to get a
> feeling that they know the basics.  The zipfile module offers a
> ZipFile object for reading/writing zip files with or without
> compression.  The CSV file allows for reading/writing CSV files with
> definable delimiters and quoting/escaping.  Etc.
> 
> 
> >>> - questions about PDB
> > 
> > Heh.  I would answer that with, "Python Debugger?  I've never used it".
> 
> The ability to know off the top of your head that it's the "Python
> Debugger" is more than enough :-)  That's just first-order
> ignorance:  you know what you don't know and can spend a few minutes
> reading up on it if you need it.  The second[or higher]-order
> ignorance of not knowing what pdb is (or, if you need more powerful
> debugging, how to do it) is sign the person hasn't been programming
> in Python much.
> 
> >>> Python History:
> >>> ===
> >>> - decorators added in which version?
> >>>
> >>> - "batteries included" SQL-capible DB in which version?
> >>>
> >>> - the difference between "class Foo" and "class Foo(object)"
> >>>
> >>> - questions from "import this" about pythonic code
> > 
> > With the exception of the question about new-style classes, these are 
> > silly questions.  I was around when both decorators and sqlite3 were 
> > added.  I couldn't possible tell you when to any precision better than 
> > "2 dot something". 
> 
> I'd even be satisfied if a person just knew that such features
> weren't there all along and might need to be worked around for older
> deployments.
> 
> > As for the zen of python, it's cute, and a piece of python
> > folklore, but hardly an essential part of being a good python p
> 
> [Ed: something appears to have gotten truncated there]  Yeah, it's
> more about a person being sufficiently steeped in python to know
> bits and pieces of the zen, and their ability to recognize/create
> pythonic code.  I've seen enough Java-written-in-Python to know what
> I don't want :-)
> 
> -tkc

Definitely appreciate your approach, I've asked similar questions when 
interviewing.

I also usually like to ask what a candidate likes and dislikes about Python, 
hoping for the GIL to creep up, along with an explanation as to what it is, 
implementations that don't have it along with methods of getting around the 
lock (although that would be a fairly advanced topic IMHO). If it doesn't come 
up, sometimes I'll pop it in depending on their level of experience.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to safely maintain a status file

2012-07-09 Thread John Nagle

On 7/8/2012 2:52 PM, Christian Heimes wrote:

You are contradicting yourself. Either the OS is providing a fully
atomic rename or it doesn't. All POSIX compatible OS provide an atomic
rename functionality that renames the file atomically or fails without
loosing the target side. On POSIX OS it doesn't matter if the target exists.


Rename on some file system types (particularly NFS) may not be atomic.


You don't need locks or any other fancy stuff. You just need to make
sure that you flush the data and metadata correctly to the disk and
force a re-write of the directory inode, too. It's a standard pattern on
POSIX platforms and well documented in e.g. the maildir RFC.

You can use the same pattern on Windows but it doesn't work as good.


  That's because you're using the wrong approach. See how to use
ReplaceFile under Win32:

http://msdn.microsoft.com/en-us/library/aa365512%28VS.85%29.aspx

Renaming files is the wrong way to synchronize a
crawler.  Use a database that has ACID properties, such as
SQLite.  Far fewer I/O operations are required for small updates.
It's not the 1980s any more.

I use a MySQL database to synchronize multiple processes
which crawl web sites.  The tables of past activity are InnoDB
tables, which support transactions.  The table of what's going
on right now is a MEMORY table.  If the database crashes, the
past activity is recovered cleanly, the MEMORY table comes back
empty, and all the crawler processes lose their database
connections, abort, and are restarted.  This allows multiple
servers to coordinate through one database.

John Nagle




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


Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-09 Thread Frederic Rentsch
On Mon, 2012-07-09 at 01:58 -0400, Terry Reedy wrote:
> On 7/8/2012 5:19 PM, Frederic Rentsch wrote:
> > Hi widget wizards,
> >
> > The manual describes the "event" attribute "widget" as "The widget
> > which generated this event. This is a valid Tkinter widget instance, not
> > a name. This attribute is set for all events."
> 
> Same in 3.3, with nice example of using it.
> 
> def turnRed(self, event):
>  event.widget["activeforeground"] = "red"
> 
> self.button.bind("", self.turnRed)
> 
> > Ans so it is--has been until on the latest occasion "event.widget" was
> > not the widget, but its name, crashing the handler.
> 
> Has event.widget been the widget only in other programs or previously
> with the same program?

I bind  to Frames, each Frame calling the same handler that is
supposed to change the background color. It is the Enter action that
generates the event. No later the handler receives the event whose
attribute widget is the widget's name (full path). My code doesn't
create events anywhere. I suppose events vanish when the last handler
terminates.

. . .

> When posting problem code, you should post a minimal, self-contained 
> example that people can try on other systems and versions. 

Attempting to strip the critical code, throwing out everything
incidental to the problem so I could post something intelligible, I
failed to fail: the bare essentials work. The problem appears to be in
the incidental.

> Can you 
> create the problem with one record, which you could give, and one 
> binding? Do you need 4 fields, or would 1 'work'?
> 
It fails even with the Frame containing no Labels at all, like this:

for n, record in enumerate(records):
line_frame = Frame (self, name = _verbalize_number (n), width = 600, 
height = 20, relief = RAISED, **BUTTON_FRAME_)
line_frame.bind ('', self.enter)
## No Labels at all:
##  for i in self.range_n_fields:
##  field = Label (line_frame, text = record [self.INDICES [i]], 
anchor = W, width = self.COLUMN_WIDTHS [i], **DB_LIST_LABEL_)
##  field.grid (row = 0, column = i, sticky = NW)

def enter (self, event):
w = event.widget
print 'hit list.enter (). Event, widget', event, w, w.__class__
w.config (bg = ENTERED_BG_COLOR)

hit list.leave (). Event, widget  
.main-frame.data-frame.title-hit-list.one-zero 
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
  File "/home/fr/python/finance/piam/hit_list.py", line 114, in enter
w.config (bg = ENTERED_BG_COLOR)
AttributeError: 'str' object has no attribute 'config'

_verbalize_number spells out the line numbers, because the manual says
something about digits being reserved for the auto-generated widget
names. I thought that assigned names containing digits might be a
problem, but it wasn't.
   The dictionary arguments, by the way, are just style elements:
colors, fonts, reliefs, etc. nothing functionally essential.

> >
> > # Dell E6500, Ubuntu 10.04, Python 2.6
> 
> You might try a current Python release, and the latest tcl/tk 8.5.11 
> released last March (comes with 3.3.0 Windows release, don't know how on 
> Ubuntu). There might be (have been?) a bug with events on Frames, or on 
> Frames within Frames treated as widgets.
> 
> -- 
> Terry Jan Reedy
> 

Terry,

I interspersed a couple of answers above. As to your last suggestion I
got Python 2.7.3 and managed to compile it. I would have preferred
something ready to install, but that doesn't seem to be available for
Linux. The compile went smoothly. But it'll take me another day to
reorganize, beginning with the Applications menu which still shows "IDLE
(Python 2.6)", while terminals already call the new version 2.7.3, but
it doesn't know where MySQLdb is, and possibly where other things are.
So for now I can't report on this effort either.

But I certainly appreciate your help. Many thanks.


Frederic


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


Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-09 Thread Frederic Rentsch
On Mon, 2012-07-09 at 10:49 -0700, Rick Johnson wrote:
> On Jul 9, 12:58 am, Terry Reedy  wrote:
> > When posting problem code, you should post a minimal, self-contained
> > example that people can try on other systems and versions. Can you
> > create the problem with one record, which you could give, and one
> > binding? Do you need 4 fields, or would 1 'work'?
> 
> I'll firmly back that sentiment. Fredric, if you cannot get the
> following simple code events to work properly, then how do you think
> you can get events working properly on something more complex?
> 
> ## START CODE ARTISTRY ##
> import Tkinter as tk
> from Tkconstants import *
> 
> class MyFrame(tk.Frame):
> def __init__(self, master, **kw):
> tk.Frame.__init__(self, master, **kw)
> self.bind('', self.evtMouseEnter)
> self.bind('', self.evtMouseLeave)
> self.bind('', self.evtButtonOneClick)
> 
> def evtMouseEnter(self, event):
> event.widget.config(bg='magenta')
> 
> def evtMouseLeave(self, event):
> event.widget.config(bg='SystemButtonFace')
> 
> def evtButtonOneClick(self, event):
> event.widget.config(bg='green')
> 
> if __name__ == '__main__':
> root = tk.Tk()
> for x in range(10):
> f = MyFrame(root, height=20, bd=1, relief=SOLID)
> f.pack(fill=X, expand=YES, padx=5, pady=5)
> root.mainloop()
> ## END CODE ARTISTRY ##
> 
> ---
> More points to ponder:
> ---
> 1. Just because the Tkinter designers decided to use idiotic names for
> event sequences does not mean you are required to blindly follow their
> bad example (the whole: "if johnny jumps off a cliff...", thing comes
> to mind)
> 
> 2. I would strongly recommend you invest more thought into your event
> handler identifiers. ALL event handlers should marked as *event
> handlers* using a prefix. I like to use the prefix "evt". Some people
> prefer other prefixes. In any case, just remember to be consistent.
> Also, event handler names should reflect WHAT event they are
> processing, not some esoteric functionality of the application like
> "pick_record" or "info_profile". However if you like, simply have the
> event handler CALL an outside func/meth. This type of consistency is
> what separates the men from the boys.
> 
> 3. The Python Style Guide[1] frowns on superfluous white space (be it
> horizontal OR vertical!) I would strongly recommend you read and adapt
> as much of this style as you possibly can bear. Even if we don't all
> get along, it IS *very* important that we structure our code in a
> similar style.
> 
> [1] http://www.python.org/dev/peps/pep-0008/

Rick,
Thanks for your remarks. I spent most of the day working with Terry's
input. And now I am falling asleep. So I shall study your inspirations
tomorrow.

Frederic


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


Re: How to safely maintain a status file

2012-07-09 Thread Michael Hrivnak
Please consider batching this data and doing larger writes.  Thrashing
the hard drive is not a good plan for performance or hardware
longevity.  For example, crawl an entire FQDN and then write out the
results in one operation.  If your job fails in the middle and you
have to start that FQDN over, no big deal.  If that's too big of a
chunk for your purposes, perhaps break each FQDN up into top-level
directories and crawl each of those in one operation before writing to
disk.

There are existing solutions for managing job queues, so you can
choose what you like.  If you're unfamiliar, maybe start by looking at
celery.

Michael

On Mon, Jul 9, 2012 at 1:52 AM, Plumo  wrote:
>> What are you keeping in this status file that needs to be saved
>> several times per second?  Depending on what type of state you're
>> storing and how persistent it needs to be, there may be a better way
>> to store it.
>>
>> Michael
>
> This is for a threaded web crawler. I want to cache what URL's are
> currently in the queue so if terminated the crawler can continue next
> time from the same point.
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Peter
One of my favourite questions when interviewing - and it was 100% reliable :-) 
- "what are your hobbies?"

If the answer included programming then they were hired, if not, then they went 
to the "B" list.

In my experience, anybody who is really interested in programming will have it 
as a hobby (and is keen to learn even if they don't currently have the 
knowledge you require) - otherwise it is "just a job". Every job has a learning 
curve - whether it is just the particular domain or even a new language, the 
individual who sees programming as more "than a job" will come up to speed much 
faster and be more productive in both the short and long term.

Every programmer I have ever hired using this criteria worked out well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to safely maintain a status file

2012-07-09 Thread Dan Stromberg
On Mon, Jul 9, 2012 at 8:24 PM, John Nagle  wrote:

> On 7/8/2012 2:52 PM, Christian Heimes wrote:
>
>> You are contradicting yourself. Either the OS is providing a fully
>> atomic rename or it doesn't. All POSIX compatible OS provide an atomic
>> rename functionality that renames the file atomically or fails without
>> loosing the target side. On POSIX OS it doesn't matter if the target
>> exists.
>>
>
> Rename on some file system types (particularly NFS) may not be atomic.
>

Actually, ISTR that rename() is one of the few things on NFS that is
atomic.

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


Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-09 Thread Chris Angelico
On Tue, Jul 10, 2012 at 3:49 AM, Rick Johnson
 wrote:
> ALL event handlers should marked as *event
> handlers* using a prefix. I like to use the prefix "evt". Some people
> prefer other prefixes. In any case, just remember to be consistent.
> Also, event handler names should reflect WHAT event they are
> processing, not some esoteric functionality of the application like
> "pick_record" or "info_profile". However if you like, simply have the
> event handler CALL an outside func/meth. This type of consistency is
> what separates the men from the boys.

Or perhaps it separates the half-elves from the hobgoblins.
Hard-and-fast rules are seldom valid in stylistic questions. There's
nothing wrong with having a prefix like "evt" or "on" or whatever;
there's also nothing wrong with a naming convention of PB_Open_Click
(PB for "PushButton" (which is what that GUI toolkit called them),
Open being what the button does, and Click is the event being handled
- that's the VX-REXX convention). Or having no specific event handler
and going straight to your "pick_record" function; that's fine too,
especially if you have multiple entry-points to that.

Frederic, you'll get a lot of advice on this list, but treat it as
just that - advice. There are very few actual rules; read what people
say and then make your own choices.

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


Re: Python Interview Questions

2012-07-09 Thread Devin Jeanpierre
On Mon, Jul 9, 2012 at 5:22 PM, Peter  wrote:
> One of my favourite questions when interviewing - and it was 100% reliable 
> :-) - "what are your hobbies?"
> If the answer included programming then they were hired, if not, then they 
> went to the "B" list.

Woe is the poor college grad, who wants to appear like a well-rounded
individual and lists capoeira and gardening, instead.

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


Re: Python Interview Questions

2012-07-09 Thread Cameron Simpson
On 09Jul2012 11:44, Rick Johnson  wrote:
| On Jul 9, 12:40 pm, Tim Chase  wrote:
| > The second[or higher]-order
| > ignorance of not knowing what pdb is (or, if you need more powerful
| > debugging, how to do it) is sign the person hasn't been programming
| > in Python much.
| 
| So guru knowledge of pdb is prerequisite to being accepted as a
| Pythonista? I find that ridiculous since *real* programmers don't use
| debuggers anyway.

You've misread him. He's saying not knowing what PDB is and what it may
be used for is a sign of low experience. Whether one uses it or not
isn't what he's measuring, it's whether one knows what it is for and how
it may be used.

| > [...]  I've seen enough Java-written-in-Python to know what
| > I don't want :-)
| 
| I know you are a member of the group who has an aversion to strict OOP
| paradigm but is this a justified aversion, or just fear of OOP due to
| static evolution? Look, i don't like java's strict approach either,
| however, i do not have an aversion to OOP.

More misreading. "Java-written-in-Python" (and its variants) means non-python
code written in python, in this case from someone with a strong (or
rigid) Java background who is not adept with Python idioms. It has
nothing to do with OOP one way or the other. Surely we've all seen
(and doubtless written) clumsy python code; this is an example.

Cheers,
-- 
Cameron Simpson 

A strong conviction that something must be done is the parent of many
bad measures.   - Daniel Webster
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Roy Smith
In article ,
 Peter  wrote:

> One of my favourite questions when interviewing - and it was 100% reliable 
> :-) - "what are your hobbies?"

"My hobby happens to be gardening, for which I don't expect to be paid."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Cameron Simpson
On 09Jul2012 18:53, Devin Jeanpierre  wrote:
| On Mon, Jul 9, 2012 at 5:22 PM, Peter  wrote:
| > One of my favourite questions when interviewing - and it was 100% reliable 
:-) - "what are your hobbies?"
| > If the answer included programming then they were hired, if not, then they 
went to the "B" list.
| 
| Woe is the poor college grad, who wants to appear like a well-rounded
| individual and lists capoeira and gardening, instead.

A new word! A quick google search confused me as to whether this was
martial art or a form of dance. The GF suggested it was both. Having
seen this:

  http://www.youtube.com/watch?v=Z8xxgFpK-NM

I am now convinced :-)
-- 
Cameron Simpson 

Hit the button Chewie!  - Han Solo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Christian Heimes
Am 09.07.2012 23:22, schrieb Peter:
> One of my favourite questions when interviewing - and it was 100% reliable 
> :-) - "what are your hobbies?"
> 
> If the answer included programming then they were hired, if not, then they 
> went to the "B" list.

on the contrary! When a potential candidate has computer stuff as her
main hobby then she goes on the no-hire list. I prefer people that can
cope with stress and pressure as well as people who can think outside
the box. When you work with computers all day at work *and* at home then
you are unable to shut off mentally.

Gardening is great hobbies for a developer. You need to be patient,
reliable and provide constantly good work to grow your own vegetables.

Christian

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


Re: Python Interview Questions

2012-07-09 Thread Tim Chase
On 07/09/12 17:53, Devin Jeanpierre wrote:
>> One of my favourite questions when interviewing - and it was
>> 100% reliable :-) - "what are your hobbies?" If the answer
>> included programming then they were hired, if not, then they
>> went to the "B" list.
> 
> Woe is the poor college grad, who wants to appear like a
> well-rounded individual and lists capoeira and gardening,
> instead.

The problem is the "instead...if your list of hobbies includes
capoeira and gardening in addition to programming, you're at least
considered. :-)

-tkc


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


Re: How to safely maintain a status file

2012-07-09 Thread Christian Heimes
Am 09.07.2012 22:24, schrieb John Nagle:
> Rename on some file system types (particularly NFS) may not be atomic.

The actual operation is always atomic but the NFS server may not notify
you about success or failure atomically.

See http://linux.die.net/man/2/rename, section BUGS.

>   That's because you're using the wrong approach. See how to use
> ReplaceFile under Win32:
> 
> http://msdn.microsoft.com/en-us/library/aa365512%28VS.85%29.aspx

The page doesn't say that ReplaceFile is an atomic op.

Christian

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


Re: Python Interview Questions

2012-07-09 Thread Tim Chase
On 07/09/12 18:12, Cameron Simpson wrote:
> On 09Jul2012 18:53, Devin Jeanpierre  wrote:
> | On Mon, Jul 9, 2012 at 5:22 PM, Peter  wrote:
> | > One of my favourite questions when interviewing - and it was 100% 
> reliable :-) - "what are your hobbies?"
> | > If the answer included programming then they were hired, if not, then 
> they went to the "B" list.
> | 
> | Woe is the poor college grad, who wants to appear like a well-rounded
> | individual and lists capoeira and gardening, instead.
> 
> A new word! A quick google search confused me as to whether this was
> martial art or a form of dance. The GF suggested it was both.

You were unfamiliar with the word "gardening" and unsure whether it
was a martial art or a form of dance?

http://groovewitch.files.wordpress.com/2011/07/ninja-garden-gnome-1.jpeg

«grins, ducks & runs»

-tkc



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


Re: Python Interview Questions

2012-07-09 Thread Roy Smith
In article ,
 Christian Heimes  wrote:

> Am 09.07.2012 23:22, schrieb Peter:
> > One of my favourite questions when interviewing - and it was 100% reliable 
> > :-) - "what are your hobbies?"
> > 
> > If the answer included programming then they were hired, if not, then they 
> > went to the "B" list.
> 
> on the contrary! When a potential candidate has computer stuff as her
> main hobby then she goes on the no-hire list.

I think this points out the silliness of these kinds of questions.  
There is no "right" answer.  More to the point, the interviewee, when 
he/she gets one of these questions, probably goes into hyper-analysis 
mode: "Now, just what did he mean by that question?"  He's likely to 
give the answer he thinks you want to hear.

Do you really want to make hire/no-hire decisions based on somebody's 
ability to second-guess what you probably wanted to hear when you asked 
a pointless question?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Emile van Sebille

On 7/9/2012 2:22 PM Peter said...

One of my favourite questions when interviewing - and it was 100% reliable :-) - 
"what are your hobbies?"

If the answer included programming then they were hired, if not, then they went to the 
"B" list.

In my experience, anybody who is really interested in programming will have it as a hobby (and is 
keen to learn even if they don't currently have the knowledge you require) - otherwise it is 
"just a job". Every job has a learning curve - whether it is just the particular domain 
or even a new language, the individual who sees programming as more "than a job" will 
come up to speed much faster and be more productive in both the short and long term.

Every programmer I have ever hired using this criteria worked out well.



Hence the age bias.

Personally, I'm quite happy now that I've divorced my hobby from my 
career.  And my family likes me better too.


Emile





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


Re: Python Interview Questions

2012-07-09 Thread Christian Heimes
Am 10.07.2012 01:40, schrieb Roy Smith:
> Do you really want to make hire/no-hire decisions based on somebody's 
> ability to second-guess what you probably wanted to hear when you asked 
> a pointless question?

I don't want her/him to second-guess at all. I expect a straight and
honest answer. Second-guessing leads to cheating and lying which doesn't
work in the long run.

"I don't like to disclose my personal life" is also a good answer as it
shows that the candidate self-confidence and doesn't sell privacy for a job.


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


Re: Python Interview Questions

2012-07-09 Thread dncarac
Tim,

I've read your list and with one exception it all looks very reasonable.  (As 
an hobbiest, I'm amazed at just how much I have picked up.)

The set of questions I'm not sure I understand is the 'What version did ... 
appear?' questions.  This, to me, doesn't seem to indicate any programming 
experience or expertise.  A question asking 'Do you understand different 
versions?' and 'How would you find out whether a particular version can do a 
particular thing?'  (i.e. which version can you use on GAE?) would seem to give 
good information.  'How do decorators work?' would seem to give good 
information.

So my question is: what information are you looking for by asking which version 
introduced decorators?

With respect,

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


Re: Python Interview Questions

2012-07-09 Thread Tim Chase
On 07/09/12 19:01, dnca...@gmail.com wrote:
> The set of questions I'm not sure I understand is the 'What
> version did ... appear?' questions.  This, to me, doesn't seem to
> indicate any programming experience or expertise.  A question
> asking 'Do you understand different versions?' and 'How would you
> find out whether a particular version can do a particular thing?'
> (i.e. which version can you use on GAE?) would seem to give good
> information.

The reason *I* ask them is that we have some 2.4 installations
(where things like "with" aren't available) and at the time I typed
up the list, there was some earlier 2.2 and 2.3 code out there where
decorators or sqlite[*] didn't work.

So I guess it's a bit of a "how long have they been programming in
python" experience aspect.  Programmers that have been around a
while often remember the frustration of $FEATURE_LACK and then the
relief of a much better way to do it.  The functionality of
decorators was around far earlier, but the clean syntactic sugar
made it much nicer to use.  The sqlite/sqlite3 libraries were
around, but you had to install them yourself (whether from source, a
custom installer, or your package manager).

As mentioned in another branch of this thread, I don't require
python historians, but do prefer folks that know which features to
check availability for deployment.

-tkc

[*] without installing an add-on







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


Re: Python Interview Questions

2012-07-09 Thread Roy Smith
In article ,
 Tim Chase  wrote:

> As mentioned in another branch of this thread, I don't require
> python historians, but do prefer folks that know which features to
> check availability for deployment.

Heh.  Tell me, when did strings get methods? :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread Tim Chase
On 07/09/12 19:27, Roy Smith wrote:
>> prefer folks that know which features to check availability for
>> deployment.
> 
> Heh.  Tell me, when did strings get methods? :-)

IIRC, ~2.0?  I'm cognizant of the shift happening from the string
module to string methods, but I wouldn't expect deep history
knowledge--last I checked, RedHat still supports a RHEL version that
ships with 2.4, so that's about as far back as I'd probe these days
(so I'd drop the decorators question now).  Certainly not a
deal-breaker either way.  Just more data points.

-tkc



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


Re: Python Interview Questions

2012-07-09 Thread Mark Lawrence

On 10/07/2012 00:33, Christian Heimes wrote:

Am 09.07.2012 23:22, schrieb Peter:

One of my favourite questions when interviewing - and it was 100% reliable :-) - 
"what are your hobbies?"

If the answer included programming then they were hired, if not, then they went to the 
"B" list.


on the contrary! When a potential candidate has computer stuff as her
main hobby then she goes on the no-hire list. I prefer people that can
cope with stress and pressure as well as people who can think outside
the box. When you work with computers all day at work *and* at home then
you are unable to shut off mentally.

Gardening is great hobbies for a developer. You need to be patient,
reliable and provide constantly good work to grow your own vegetables.

Christian



I guess that's why I detest gardening :-)

--
Cheers.

Mark Lawrence.



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


Re: How to safely maintain a status file

2012-07-09 Thread alex23
On Jul 10, 6:24 am, John Nagle  wrote:
> That's because you're using the wrong approach. See how to use
> ReplaceFile under Win32:
>
> http://msdn.microsoft.com/en-us/library/aa365512%28VS.85%29.aspx

I'm not convinced ReplaceFile is atomic:

"The ReplaceFile function combines several steps within a single
function. An application can call ReplaceFile instead of calling
separate functions to save the data to a new file, rename the original
file using a temporary name, rename the new file to have the same name
as the original file, and delete the original file."

About the best you can get in Windows, I think, is MoveFileTransacted,
but you need to be running Vista or later:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365241(v=vs.85).aspx

I agree with your suggestion of using something transactional that
isn't bound to later Window versions, though.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to pick content from html using beatifulsoup

2012-07-09 Thread Sheetal Singh
Hi,

I am a newbie in python, I need to fetch names of side filters and save in csv 
[PFA screen shot].

Following is snippet from code:
  soup = BeautifulStoneSoup(html)
#for e in soup.findAll('div'):
# for c in e.findAll('h3'):
#for d in c.findAll('li'):
#print'@@@', d.extract()
#

##select_pod=soup.findAll('div', {"class":"win aboutUs"})
##promeg= select_pod[0].findAll("p")[0]
#
#



#for dv in soup.findAll('div', {"class":"attribution"}):
#ds = dv.findAll("")
#print ds



select_pod = soup.findAll('div')
print select_pod
for j in select_pod:
if j is not None:
print j.findall('a')
promeg = select_pod.findAll("")
#print '--', promeg




#hreflist = [ each.get('value') for each in 
soup.findAll('') ]


for m in promeg :
if m:
print 'Data values', m
fd1.writerow([x[2], m, i[0], "Data 
Found"])


Structure of HTML:



By Brand


http://www.xyz.com/cellphones/nokia/nokia/259-33902/buy";>Nokia












By Seller


http://www.xyz.com/cellphones/nokia/amazon-marketplace/296935-184059/buy";>Amazon
 Marketplace
http://www.xyz.com/cellphones/nokia/amazon-marketplace/296935-184059/buy";>
















Output required in csv:

By Brands
Nokia
Samsung
.
.

By Seller
Amazon
Buy.com
.
.
.



Please suggest how to fetch details.

Sheetal Singh
<>-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Interview Questions

2012-07-09 Thread Shambhu Rajak
I agree with Christian, a developer should have hobbies other than computer 
stuffs. Versatile environment give more
Ability to think differently. 
I like playing guitar :-) 

Be enthu, run foolishly and learn intelligently.

-Shambhu

-Original Message-
From: Christian Heimes [mailto:li...@cheimes.de] 
Sent: 10/07/2012 5:03 AM
To: python-list@python.org
Subject: Re: Python Interview Questions

Am 09.07.2012 23:22, schrieb Peter:
> One of my favourite questions when interviewing - and it was 100% reliable 
> :-) - "what are your hobbies?"
> 
> If the answer included programming then they were hired, if not, then they 
> went to the "B" list.

on the contrary! When a potential candidate has computer stuff as her
main hobby then she goes on the no-hire list. I prefer people that can
cope with stress and pressure as well as people who can think outside
the box. When you work with computers all day at work *and* at home then
you are unable to shut off mentally.

Gardening is great hobbies for a developer. You need to be patient,
reliable and provide constantly good work to grow your own vegetables.

Christian


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


Re: How can I disable module of tkinter when compiling Python 2.5 on redhat9 ?

2012-07-09 Thread Tim Roberts
cheetah  wrote:
>
>I don't need it.

It's not worth worrying about.  You're talking about way less than a
megabyte of disk space, and there is no performance penalty unless you're
using it.

In general, the parts of the Python standard library are not individually
selectable.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Interview Questions

2012-07-09 Thread rusi
On Jul 10, 4:40 am, Roy Smith  wrote:
> In article ,
>  Christian Heimes  wrote:
>
> > Am 09.07.2012 23:22, schrieb Peter:
> > > One of my favourite questions when interviewing - and it was 100% reliable
> > > :-) - "what are your hobbies?"
>
> > > If the answer included programming then they were hired, if not, then they
> > > went to the "B" list.
>
> > on the contrary! When a potential candidate has computer stuff as her
> > main hobby then she goes on the no-hire list.
>
> I think this points out the silliness of these kinds of questions.
> There is no "right" answer.  More to the point, the interviewee, when
> he/she gets one of these questions, probably goes into hyper-analysis
> mode: "Now, just what did he mean by that question?"  He's likely to
> give the answer he thinks you want to hear.
>
> Do you really want to make hire/no-hire decisions based on somebody's
> ability to second-guess what you probably wanted to hear when you asked
> a pointless question?

Add to that the Heisenberging that happens to interviewees (and
interviewers) from reading this thread
-- 
http://mail.python.org/mailman/listinfo/python-list