Re: Opportunity missed by Python ?

2011-11-15 Thread Jack Keegan
On Thu, Oct 13, 2011 at 11:07 AM, Chris Angelico  wrote:

> On Thu, Oct 13, 2011 at 8:45 PM, candide  wrote:
> > Dart is the very new language created by Google to replace Javascript.
> > So Python was not able to do the job? Or may be they don't know about
> Python
> > at Google ;) ?
> >
>
> Also, Dart is looking to support (optional) strict typing, which
> Python doesn't do. That's a fairly major performance enhancement.
>
> Traits from Enthought has defined types. I'm no expert mind so might not
be suitable.

Cheers,

Jack


-- 
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
-- 
http://mail.python.org/mailman/listinfo/python-list


Execute a command on remote machine in python

2011-11-15 Thread Roark
Hi,

I am first time trying my hands on python scripting and would need
some guidance from the experts on my problem.

I want to execute a windows command within python script from a client
machine on a remote target server, and would want the output of the
command written in a file on client machine. What is the way it could
be achieved.


Thanks in advance,
Roark.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute a command on remote machine in python

2011-11-15 Thread Martin P. Hellwig

On 11/15/11 12:04, Roark wrote:

Hi,

I am first time trying my hands on python scripting and would need
some guidance from the experts on my problem.

I want to execute a windows command within python script from a client
machine on a remote target server, and would want the output of the
command written in a file on client machine. What is the way it could
be achieved.



If your doing windows to windows then you could wrap PsExec 
(sysinternals) or the open source but more or less abandoned RemCom 
(http://sourceforge.net/projects/rce).


Disadvantage is that both of them are a royal PITA to wrap nicely.
There are multiple problems with re-redirected STDOUT/STDERR

Advantage is that you don't need to configure anything on the target 
machine.


hth
--
mph


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


PREFIX directory for pip command

2011-11-15 Thread Makoto Kuwata
Is it possible to specify PREFIX directory for pip command by
environment variable?

I found that 'pip install --install-option=--prefix=PREFIX' works well,
but I don't want to specify '--install-option=--prefix=PREFIX' every time.
I prefer to specify it by environment variable such as::

export PIP_INSTALL_DIR=$PWD/local

Is it possible? Or any idea?

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


Re: Execute a command on remote machine in python

2011-11-15 Thread Jean-Michel Pichavant

Martin P. Hellwig wrote:

On 11/15/11 12:04, Roark wrote:

Hi,

I am first time trying my hands on python scripting and would need
some guidance from the experts on my problem.

I want to execute a windows command within python script from a client
machine on a remote target server, and would want the output of the
command written in a file on client machine. What is the way it could
be achieved.



If your doing windows to windows then you could wrap PsExec 
(sysinternals) or the open source but more or less abandoned RemCom 
(http://sourceforge.net/projects/rce).


Disadvantage is that both of them are a royal PITA to wrap nicely.
There are multiple problems with re-redirected STDOUT/STDERR

Advantage is that you don't need to configure anything on the target 
machine.


hth

have a look at execnet

http://codespeak.net/execnet/

It allows you to execute python code on a remote machine, assuming the 
distant machine has python installed. Work fine with either nix or 
windows systems.


Regarding the file transfert, it sounds like pywin32 provides the 
netcopy service, but I'm not sure, I'm not working with windows.


JM

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


Re: Execute a command on remote machine in python

2011-11-15 Thread Chris Angelico
On Tue, Nov 15, 2011 at 11:04 PM, Roark  wrote:
> Hi,
>
> I want to execute a windows command within python script from a client
> machine on a remote target server, and would want the output of the
> command written in a file on client machine. What is the way it could
> be achieved.

This looks like a job for SSH.

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


Re: Execute a command on remote machine in python

2011-11-15 Thread Xavier Ho
It sounds like Fabric is what you're after. We use it at work and it's the
best thing since ssh. ;]

http://docs.fabfile.org/en/1.3.2/index.html

(Actually, it uses ssh internally and allows you to do remote shell-like
programming in a pythonic fashion.)

Cheers,
Xav



On 15 November 2011 22:04, Roark  wrote:

> Hi,
>
> I am first time trying my hands on python scripting and would need
> some guidance from the experts on my problem.
>
> I want to execute a windows command within python script from a client
> machine on a remote target server, and would want the output of the
> command written in a file on client machine. What is the way it could
> be achieved.
>
>
> Thanks in advance,
> Roark.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute a command on remote machine in python

2011-11-15 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Tue, Nov 15, 2011 at 11:04 PM, Roark  wrote:
> > Hi,
> >
> > I want to execute a windows command within python script from a client
> > machine on a remote target server, and would want the output of the
> > command written in a file on client machine. What is the way it could
> > be achieved.
> 
> This looks like a job for SSH.

You might also want to look at fabric (http://fabfile.org).  It's a nice 
python library for remote command execution built on top of SSH.

A more general answer is that, yes, SSH is the right thing to be looking 
at for your basic connectivity, data transport and remote command 
execution.  But trying to deal with raw SSH will drive you batty.  
Something like fabric, layered on top of SSH, will make things a lot 
easier.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: else in try/except

2011-11-15 Thread Grant Edwards
On 2011-11-15, Barry W Brown  wrote:

> I thought that the point of the else clause is that it is reached
> only if there is no exception in the try clause.

Not really.  If that's all you wanted, then you just put the code at
the end of the try block.

-- 
Grant Edwards   grant.b.edwardsYow! ... I see TOILET
  at   SEATS ...
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PREFIX directory for pip command

2011-11-15 Thread Marc Christiansen
Makoto Kuwata  wrote:
> Is it possible to specify PREFIX directory for pip command by
> environment variable?
> 
> I found that 'pip install --install-option=--prefix=PREFIX' works well,
> but I don't want to specify '--install-option=--prefix=PREFIX' every time.
> I prefer to specify it by environment variable such as::
> 
>export PIP_INSTALL_DIR=$PWD/local
> 
> Is it possible? Or any idea?

I'd try
 export PIP_INSTALL_OPTION=--prefix=$PWD/local

using a config file is also possible. See
http://www.pip-installer.org/en/latest/configuration.html

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


Re: else in try/except

2011-11-15 Thread Robert Kern

On 11/15/11 2:31 PM, Grant Edwards wrote:

On 2011-11-15, Barry W Brown  wrote:


I thought that the point of the else clause is that it is reached
only if there is no exception in the try clause.


Not really.  If that's all you wanted, then you just put the code at
the end of the try block.


No, he's right. You should only put code in the try: block where you want 
exceptions to be caught. Everything else should be outside of the block. You 
really do want to minimize the amount of code inside the try: block.


try:
# minimal code that might raise exceptions that you want to catch
except ThisError:
# handle ThisError exceptions, and probably continue execution
except ThatError:
# handle ThatError exceptions, and probably continue execution
else:
# Code that only runs if ThisError or ThatError were not
# raised in the try: block. This code may raise ThisError or ThatError
# exceptions that should not be caught by the above except: blocks.

# Other code that runs regardless if a caught-and-continued exception
# was raised or not

--
Robert Kern

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

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


Re: Execute a command on remote machine in python

2011-11-15 Thread Marco Nawijn
On Nov 15, 1:04 pm, Roark  wrote:
> Hi,
>
> I am first time trying my hands on python scripting and would need
> some guidance from the experts on my problem.
>
> I want to execute a windows command within python script from a client
> machine on a remote target server, and would want the output of the
> command written in a file on client machine. What is the way it could
> be achieved.
>
> Thanks in advance,
> Roark.


Hello Roark,

If the command does not change over time, an option could be to
encapsulate the command and the output behind an XML-RPC interface. I
used it several times now and for me this works perfectly. XML-RPC is
part of the Python standard library, so it should work out of the box
on windows and linux. It also supports mixed programming languages
(maybe C# on windows to get the info you want and python on linux on
the client).

Kind regards,

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


Re: PREFIX directory for pip command

2011-11-15 Thread Makoto Kuwata
On Tue, Nov 15, 2011 at 11:33 PM, Marc Christiansen
 wrote:
>
> I'd try
>  export PIP_INSTALL_OPTION=--prefix=$PWD/local

It works very well. Thank you.

--
regards,
makoto

>
> using a config file is also possible. See
> http://www.pip-installer.org/en/latest/configuration.html
>
> Ciao
> Marc
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute a command on remote machine in python

2011-11-15 Thread Rodrick Brown
You could easily script this with popen calling secure shell to execute a 
command and capture the output.  

Sent from my iPhone

On Nov 15, 2011, at 7:04 AM, Roark  wrote:

> Hi,
> 
> I am first time trying my hands on python scripting and would need
> some guidance from the experts on my problem.
> 
> I want to execute a windows command within python script from a client
> machine on a remote target server, and would want the output of the
> command written in a file on client machine. What is the way it could
> be achieved.
> 
> 
> Thanks in advance,
> Roark.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all() is slow?

2011-11-15 Thread BOOK-AZ
On Nov 7, 1:00 pm, "OKB (not okblacke)"
 wrote:
>         I noticed this (Python 2.6.5 on Windows XP):
> http://book-az.com
> >>> import random, timeit
> >>> def myAll(x):
>
> ...     for a in x:
> ...         if a not in (True, False):
> ...             return False
> ...     return True>>> x = [random.choice([True, False]) for a in xrange(0, 
> 500)]
> >>> timeit.timeit('myAll(x)', 'from __main__ import myAll, x',
>
> number=10)
> 0: 9.7685158309226452>>> timeit.timeit('all(a in (True, False) for a in x)', 
> 'from __main__
>
> import x', number=10)
> 1: 12.348196768024984>>> x = [random.randint(0,100) for a in xrange(0, 
> 500)]
> >>> def myAll(x):
>
> ...     for a in x:
> ...         if not a <= 100:
> ...             return False
> ...     return True>>> timeit.timeit('myAll(x)', 'from __main__ import myAll, 
> x',
>
> number=10)
> 4: 2.8248207523582209>>> timeit.timeit('all(a <= 100 for a in x)', 
> 'gc.enable(); from
>
> __main__ import x', number=10)
> 5: 4.6433557896324942
>
>         What is the point of the all() function being a builtin if it's
> slower than writing a function to do the check myself?
>
> --
> --OKB (not okblacke)
> Brendan Barnwell
> "Do not follow where the path may lead.  Go, instead, where there is
> no path, and leave a trail."
>         --author unknown

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


RE: Extracting elements over multiple lists?

2011-11-15 Thread Prasad, Ramit
>>for x in a, b, c:
>>del x[0]
>for arr in [a,b,c]:
>  arr.pop(0)

>(Peter's "del" solution is quite close, but I find the 'del' statement 
>tricky in python and will mislead many python newcomers)

Can you expand on why 'del' is "tricky"/misleading?

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


suppressing import errors

2011-11-15 Thread Andreea Babiuc
Hi,

Is there a way to suppress all the errors when importing a module in
python?

By that I mean.. If I have other imports in the module I'm trying to import
that fail, I still want my module to be imported that way..

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


Re: suppressing import errors

2011-11-15 Thread Chris Kaynor
As with any Python code, you can wrap the import into a try: except block.

try:
 import badModule
except:
 pass # Or otherwise handle the exception - possibly importing an
alternative module.

As with any except statement, specific exceptions may be caught
(rather than the blank, catch everything).

Chris

On Tue, Nov 15, 2011 at 9:11 AM, Andreea Babiuc  wrote:
> Hi,
>
> Is there a way to suppress all the errors when importing a module in python?
>
> By that I mean.. If I have other imports in the module I'm trying to import
> that fail, I still want my module to be imported that way..
>
> Many thanks.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: overview on dao

2011-11-15 Thread Prasad, Ramit
>> Perhaps you should call it "LaoZiDao".
>I just prefer shorter name.

DAO as Data Access Objects is a common acronym in several languages (i.e. 
Java), 
so you will continually have this naming conflict. Just be aware that this
conflict will happen frequently in the minds of many programmers.

Ramit

P.S. I vote for PyLaoziDao :P


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suppressing import errors

2011-11-15 Thread Andreea Babiuc
On 15 November 2011 17:24, Chris Kaynor  wrote:

> As with any Python code, you can wrap the import into a try: except block.
>
> try:
>  import badModule
> except:
>



>  pass # Or otherwise handle the exception - possibly importing an
> alternative module.
>
>
Hmm, I know this might sound silly, but if it fails I still want to import
the module and disable those lines of code that are related to the reason
while the module failed to be imported in the first place.  Even if that
makes the code not 100% correct.

Does that make sense ?









> As with any except statement, specific exceptions may be caught
> (rather than the blank, catch everything).
>
> Chris
>
> On Tue, Nov 15, 2011 at 9:11 AM, Andreea Babiuc 
> wrote:
> > Hi,
> >
> > Is there a way to suppress all the errors when importing a module in
> python?
> >
> > By that I mean.. If I have other imports in the module I'm trying to
> import
> > that fail, I still want my module to be imported that way..
> >
> > Many thanks.
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Blog: Http://andreeababiuc.ro
Photo Portfolio: http://royaa.daportfolio.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suppressing import errors

2011-11-15 Thread David Riley
On Nov 15, 2011, at 12:35 PM, Andreea Babiuc wrote:

> 
> 
> On 15 November 2011 17:24, Chris Kaynor  wrote:
> As with any Python code, you can wrap the import into a try: except block.
> 
> try:
>  import badModule
> except:
> 
>  
>  pass # Or otherwise handle the exception - possibly importing an
> alternative module.
> 
> 
> Hmm, I know this might sound silly, but if it fails I still want to import 
> the module and disable those lines of code that are related to the reason 
> while the module failed to be imported in the first place.  Even if that 
> makes the code not 100% correct.
> 
> Does that make sense ?

It makes sense.  It probably also makes sense to only do an "except 
ImportError", since if there are other errors (say, syntax errors in a module 
you're trying to import, rather than its absence, you probably want to know 
about it.

To disable code that won't work without the module you're trying to import, you 
can always set flags in your module.  For example, I've got a project at work 
that can use a variety of communications interfaces, including using PySerial 
for serial port comms.  But if someone doesn't have PySerial installed, I want 
it to fail gracefully and just not support serial.  So I can do the following:


try:
   import serial
   _serial_enabled = True
except ImportError:
   print("PySerial not installed - serial ports not supported!")
   _serial_enabled = False


And then elsewhere in my module, I can check the value of _serial_enabled to 
see if I should e.g. list the serial ports in available communications 
interfaces.

Of course, if there's some other error in PySerial (maybe I installed a broken 
version with a syntax error?), that error will get propagated up, which is a 
good thing, because I'd rather know that PySerial is broken than just have it 
tell me it's not installed (which is what would happen if I simply caught all 
exceptions).  Your mileage may vary.

- Dave

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


Re: Extracting elements over multiple lists?

2011-11-15 Thread Dave Angel

On 11/15/2011 12:01 PM, Prasad, Ramit wrote:



(Peter's "del" solution is quite close, but I find the 'del' statement
tricky in python and will mislead many python newcomers)

Can you expand on why 'del' is "tricky"/misleading?

Ramit


a = someexpression...
b = a

del a

Does not (necessarily) delete the object that a refers to.  It merely 
deletes the symbol a.




--

DaveA

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


Re: overview on dao

2011-11-15 Thread MRAB

On 15/11/2011 17:26, Prasad, Ramit wrote:

Perhaps you should call it "LaoZiDao".

I just prefer shorter name.


DAO as Data Access Objects is a common acronym in several languages (i.e. Java),
so you will continually have this naming conflict. Just be aware that this
conflict will happen frequently in the minds of many programmers.

Ramit

P.S. I vote for PyLaoziDao :P


Just don't confuse it with PyDao, which is already taken. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: suppressing import errors

2011-11-15 Thread Jean-Michel Pichavant

David Riley wrote:

On Nov 15, 2011, at 12:35 PM, Andreea Babiuc wrote:

  

On 15 November 2011 17:24, Chris Kaynor  wrote:
As with any Python code, you can wrap the import into a try: except block.

try:
 import badModule
except:

 
 pass # Or otherwise handle the exception - possibly importing an

alternative module.


Hmm, I know this might sound silly, but if it fails I still want to import the 
module and disable those lines of code that are related to the reason while the 
module failed to be imported in the first place.  Even if that makes the code 
not 100% correct.

Does that make sense ?



It makes sense.  It probably also makes sense to only do an "except 
ImportError", since if there are other errors (say, syntax errors in a module you're 
trying to import, rather than its absence, you probably want to know about it.

To disable code that won't work without the module you're trying to import, you 
can always set flags in your module.  For example, I've got a project at work 
that can use a variety of communications interfaces, including using PySerial 
for serial port comms.  But if someone doesn't have PySerial installed, I want 
it to fail gracefully and just not support serial.  So I can do the following:


try:
   import serial
   _serial_enabled = True
except ImportError:
   print("PySerial not installed - serial ports not supported!")
   _serial_enabled = False


And then elsewhere in my module, I can check the value of _serial_enabled to 
see if I should e.g. list the serial ports in available communications 
interfaces.

Of course, if there's some other error in PySerial (maybe I installed a broken 
version with a syntax error?), that error will get propagated up, which is a 
good thing, because I'd rather know that PySerial is broken than just have it 
tell me it's not installed (which is what would happen if I simply caught all 
exceptions).  Your mileage may vary.

- Dave

  
If I'm not wrong the OP wants to disable the line *in the module being 
imported*, which is kindof silly and doesn't make sense to answer his 
question.


Anreea, tell us why the module you are importing is failing and if this 
module is yours, we may provide you a proper way to handle this 
situation (though I'm pretty sure everything is in Dave's proposal).


JM
PS : @Dave there is a way to avoiding adding symbols to your global 
namespace, assign None to the module's name on import errors. Then 
before using it, just test the module bool value : if serial: 
serial.whateverMethod()

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


Gossip Protocol in Python

2011-11-15 Thread alisha alisha
Hi All,

I am new to Python. I have to implement a overlay network of around
500 nodes which are arranged as a random graph. To generate theoverlay
network I will be using networkx.

My query is, is there a way to implement Gossip protocol in my overlay
network using Python. Like one node initiated the Gossip of a message,
then in how many epoch time it reaches all the nodes in the network.

Thanks.

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


Wing IDE 4.1.1 released

2011-11-15 Thread Wingware

Hi,

Wingware has released version 4.1.1 of Wing IDE, an integrated development
environment designed specifically for the Python programming language.

Wing IDE is a cross-platform Python IDE that provides a professional code
editor with vi, emacs, and other key bindings, auto-completion, call tips,
refactoring, context-aware auto-editing, a powerful graphical debugger,
version control, unit testing, search, and many other features.

**Changes in Version 4.1.1**

Highlights of this release include:

* Goto-definition on symbols in the shells
* Expanded and improved auto-editing support (enable this in the Edit >
  Keyboard Personality menu):
  * Auto-closing
  * Auto-enter invocation args
  * Apply quote/comment/paren/etc to selection
  * Auto-enter spaces
  * Insert EOL and indent for new block
  * Continue comment on new line
* Auto-indent when pasting multi-line text in Python code (undo once 
restores

  original indentation)
* Improved Smart Tab key option for Python
* Indent to Match menu and tool bar items toggle indentation to one indent
  position lower if already at matching indent level
* Improved auto-indent of else, elif, except, and finally
* Experimental Turbo auto-completer mode for Python that treats any non-word
  key as a completion key and Ctrl, Alt, and Command as a cancel keys
* Link to docs.python.org in Source Assistant
* Include argument names in auto-completer during invocation
* About 30 other bug fixes and minor improvements

Complete change log:  http://wingware.com/pub/wingide/4.1.1/CHANGELOG.txt

**New Features in Version 4**

Version 4 adds the following new major features:

* Refactoring -- Rename/move symbols, extract to function/method, and 
introduce variable

* Find Uses -- Find all points of use of a symbol
* Auto-Editing -- Reduce typing burden by auto-entering expected code
* Diff/Merge -- Graphical file and repository comparison and merge
* Django Support -- Debug Django templates, run Django unit tests, and more
* matplotlib Support -- Maintains live-updating plots in shell and debugger
* Simplified Licensing -- Includes all OSes and adds Support+Upgrades 
subscriptions


Details on licensing changes:  http://wingware.com/news/2011-02-16

**About Wing IDE**

Wing IDE is an integrated development environment designed specifically for
the Python programming language.  It provides powerful editing, testing, and
debugging features that help reduce development and debugging time, cut down
on coding errors, and make it easier to understand and navigate Python code.
Wing IDE can be used to develop Python code for web, GUI, and embedded
scripting applications.

Wing IDE is available in three product levels:  Wing IDE Professional is
the full-featured Python IDE, Wing IDE Personal offers a reduced feature
set at a low price, and Wing IDE 101 is a free simplified version designed
for teaching beginning programming courses with Python.

Version 4.0 of Wing IDE Professional includes the following major features:

* Professional quality code editor with vi, emacs, and other keyboard
  personalities
* Code intelligence for Python:  Auto-completion, call tips, find uses,
  goto-definition, error indicators, refactoring, context-aware 
auto-editing,

  smart indent and rewrapping, and source navigation
* Advanced multi-threaded debugger with graphical UI, command line 
interaction,

  conditional breakpoints, data value tooltips over code, watch tool, and
  externally launched and remote debugging
* Powerful search and replace options including keyboard driven and 
graphical

  UIs, multi-file, wild card, and regular expression search and replace
* Version control integration for Subversion, CVS, Bazaar, git, 
Mercurial, and

  Perforce
* Integrated unit testing with unittest, nose, and doctest frameworks
* Django support:  Debugs Django templates, provides project setup tools,
  and runs Django unit tests
* Many other features including project manager, bookmarks, code snippets,
  diff/merge tool, OS command integration, indentation manager, PyLint
  integration, and perspectives
* Extremely configurable and may be extended with Python scripts
* Extensive product documentation and How-Tos for Django, matplotlib,
  Plone, wxPython, PyQt, mod_wsgi, Autodesk Maya, and many other frameworks

Please refer to http://wingware.com/wingide/features for a detailed listing
of features by product level.

System requirements are Windows 2000 or later, OS X 10.3.9 or later 
(requires
X11 Server), or a recent Linux system (either 32 or 64 bit).  Wing IDE 
supports

Python versions 2.0.x through 3.2.x and Stackless Python.

For more information, see the http://wingware.com/

**Downloads**

Wing IDE Professional and Wing IDE Personal are commercial software and
require a license to run. A free trial can be obtained directly from the
product when launched.

Wing IDE Pro -- Full-featured product:
http://wingware.com/downloads/wingide/4.1

Wing IDE Personal -- A simplified IDE:
http://wingware.com/

Re: suppressing import errors

2011-11-15 Thread David Riley
On Nov 15, 2011, at 1:58 PM, Jean-Michel Pichavant wrote:

> PS : @Dave there is a way to avoiding adding symbols to your global 
> namespace, assign None to the module's name on import errors. Then before 
> using it, just test the module bool value : if serial: serial.whateverMethod()

True, and that does avoid polluting namespace.  However, you shouldn't be 
testing for None as a bool; you should instead do an "if  is None:" 
(or, of course, "is not None").

- Dave

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


Re: Extracting elements over multiple lists?

2011-11-15 Thread Chris Angelico
On Wed, Nov 16, 2011 at 5:17 AM, Dave Angel  wrote:
> a = someexpression...
> b = a
> 
> del a
>
> Does not (necessarily) delete the object that a refers to.  It merely
> deletes the symbol a.

I'd have to classify that as part of the change of thinking necessary
for a refcounted language, and not specific to del at all. The del
statement is identical to "a = None" in terms of deleting objects;
someone who's come from C++ might want to explicitly del every
variable before returning, but that's the only way that it's tied to
'del'.

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


Re: suppressing import errors

2011-11-15 Thread Chris Angelico
On Wed, Nov 16, 2011 at 6:39 AM, David Riley  wrote:
> True, and that does avoid polluting namespace.  However, you shouldn't be 
> testing for None as a bool; you should instead do an "if  is None:" 
> (or, of course, "is not None").

Why not? Is there some other way for the module object to evaluate as false?

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


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Chris Angelico
On Wed, Nov 16, 2011 at 7:37 AM, Passiday  wrote:
> The app would have basic IDE for writing and debugging the python code, but 
> the interpretation, of course, would be done in JavaScript. I'd like to avoid 
> any client-server transactions, so all the interpretation should take place 
> on the client side. The purpose of all this would be to create educational 
> platform for learning the programming in python.

Hmm. If it's to be an educational platform, I would recommend doing
something like the W3Schools "tryit" page [1] and just go back to the
server each time. You have potential security issues to watch out for
(so it may be worth chrooting your interpreter), but it's sure to be
easier than rewriting the entire interpreter in another language. You
would have to maintain your implementation as the language evolves,
keep it bug-free, etc, etc.

ChrisA

[1] eg http://www.w3schools.com/html/tryit.asp?filename=tryhtml_basic
-- 
http://mail.python.org/mailman/listinfo/python-list


(don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Passiday
Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order 
to provide a web-based application with python scripting capabilities. The app 
would have basic IDE for writing and debugging the python code, but the 
interpretation, of course, would be done in JavaScript. I'd like to avoid any 
client-server transactions, so all the interpretation should take place on the 
client side. The purpose of all this would be to create educational platform 
for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up 
anything. I've found some crazy project emulating PC in JavaScript (and even 
running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, 
but that seems like awful lot of work to do. Any ideas how I should proceed 
with this project?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Ian Kelly
On Tue, Nov 15, 2011 at 1:37 PM, Passiday  wrote:
> Hello,
>
> I am looking for a way how to bring Python interpreter to JavaScript, in 
> order to provide a web-based application with python scripting capabilities. 
> The app would have basic IDE for writing and debugging the python code, but 
> the interpretation, of course, would be done in JavaScript. I'd like to avoid 
> any client-server transactions, so all the interpretation should take place 
> on the client side. The purpose of all this would be to create educational 
> platform for learning the programming in python.
>
> I hoped somebody already had done something like this, but I couldn't google 
> up anything. I've found some crazy project emulating PC in JavaScript (and 
> even running Linux on top of it), but not a python interpreter.

You could take a look at pyjamas, but it's precompiled.  I don't know
whether they have support for runtime compilation at all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Stef Mientki

On 15-11-2011 21:37, Passiday wrote:

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order 
to provide a web-based application with python scripting capabilities. The app 
would have basic IDE for writing and debugging the python code, but the 
interpretation, of course, would be done in JavaScript. I'd like to avoid any 
client-server transactions, so all the interpretation should take place on the 
client side. The purpose of all this would be to create educational platform 
for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up 
anything. I've found some crazy project emulating PC in JavaScript (and even 
running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, 
but that seems like awful lot of work to do. Any ideas how I should proceed 
with this project?

skulpt ?

cheers,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


Re: suppressing import errors

2011-11-15 Thread David Riley
On Nov 15, 2011, at 3:01 PM, Chris Angelico wrote:

> On Wed, Nov 16, 2011 at 6:39 AM, David Riley  wrote:
>> True, and that does avoid polluting namespace.  However, you shouldn't be 
>> testing for None as a bool; you should instead do an "if  is None:" 
>> (or, of course, "is not None").
> 
> Why not? Is there some other way for the module object to evaluate as false?

Well, probably not.  It was my understanding that "None" evaluating to a 
Boolean false was not necessarily guaranteed; I've even gotten some warnings 
from Python to that effect, though I can't recall the context in which that 
happened.  In any case, PEP 8 states:

  Comparisons to singletons like None should always be done with
  'is' or 'is not', never the equality operators.

  Also, beware of writing "if x" when you really mean "if x is not None"
  -- e.g. when testing whether a variable or argument that defaults to
  None was set to some other value.  The other value might have a type
  (such as a container) that could be false in a boolean context!

Obviously, that last bit doesn't apply to modules; they're not going to 
evaluate as False in general.  I just bristle when I see people writing "if x" 
when they really mean "if x is not None", perhaps because it's not The Right 
Way(tm)?  It mostly comes down to aesthetics, I guess.  Write what you really 
mean.

- Dave

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


Re: suppressing import errors

2011-11-15 Thread Chris Angelico
On Wed, Nov 16, 2011 at 8:20 AM, David Riley  wrote:
>      Comparisons to singletons like None should always be done with
>      'is' or 'is not', never the equality operators.
>
>      Also, beware of writing "if x" when you really mean "if x is not None"
>      -- e.g. when testing whether a variable or argument that defaults to
>      None was set to some other value.  The other value might have a type
>      (such as a container) that could be false in a boolean context!

It's probably quicker to execute "if x is None" than "if x"
(presumably the former just compares the two pointers). On the other
hand, it's more compact to leave off the "is None". And on the
gripping hand, neither "quicker to execute" nor "more compact" equates
to "more Pythonic".

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


Re: suppressing import errors

2011-11-15 Thread Arnaud Delobelle
On 15 November 2011 21:34, Chris Angelico  wrote:
> On Wed, Nov 16, 2011 at 8:20 AM, David Riley  wrote:
>>      Comparisons to singletons like None should always be done with
>>      'is' or 'is not', never the equality operators.
>>
>>      Also, beware of writing "if x" when you really mean "if x is not None"
>>      -- e.g. when testing whether a variable or argument that defaults to
>>      None was set to some other value.  The other value might have a type
>>      (such as a container) that could be false in a boolean context!
>
> It's probably quicker to execute "if x is None" than "if x"
> (presumably the former just compares the two pointers). On the other
> hand, it's more compact to leave off the "is None". And on the
> gripping hand, neither "quicker to execute" nor "more compact" equates
> to "more Pythonic".

It's idiomatic to write "x is None" when you want to know whether x is None.

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


Re: suppressing import errors

2011-11-15 Thread Ian Kelly
On Tue, Nov 15, 2011 at 2:42 PM, Arnaud Delobelle  wrote:
> It's idiomatic to write "x is None" when you want to know whether x is None.

It's also idiomatic to just write "if x:" when you want to know
whether x is something or nothing, and that's what I would probably do
here.  Either is correct.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Terry Reedy

On 11/15/2011 3:52 PM, Ian Kelly wrote:

On Tue, Nov 15, 2011 at 1:37 PM, Passiday  wrote:

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order 
to provide a web-based application with python scripting capabilities. The app 
would have basic IDE for writing and debugging the python code, but the 
interpretation, of course, would be done in JavaScript. I'd like to avoid any 
client-server transactions, so all the interpretation should take place on the 
client side. The purpose of all this would be to create educational platform 
for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up 
anything. I've found some crazy project emulating PC in JavaScript (and even 
running Linux on top of it), but not a python interpreter.


You could take a look at pyjamas, but it's precompiled.  I don't know
whether they have support for runtime compilation at all.


Perhaps one could use pyjamas to compile pypy to javascript ;-).

--
Terry Jan Reedy

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


Re: suppressing import errors

2011-11-15 Thread Chris Kaynor
On Tue, Nov 15, 2011 at 1:34 PM, Chris Angelico  wrote:
> On Wed, Nov 16, 2011 at 8:20 AM, David Riley  wrote:
>>      Comparisons to singletons like None should always be done with
>>      'is' or 'is not', never the equality operators.
>>
>>      Also, beware of writing "if x" when you really mean "if x is not None"
>>      -- e.g. when testing whether a variable or argument that defaults to
>>      None was set to some other value.  The other value might have a type
>>      (such as a container) that could be false in a boolean context!
>
> It's probably quicker to execute "if x is None" than "if x"
> (presumably the former just compares the two pointers). On the other
> hand, it's more compact to leave off the "is None". And on the
> gripping hand, neither "quicker to execute" nor "more compact" equates
> to "more Pythonic".

I decided to run some tests to see which is faster. As is turns out,
in simple cases (eg, True), "if x: pass" is faster than "if x is None:
pass" if x is True, and otherwise its the same. If x is a custom type
(I only tested a simple custom class written in Python), "if x is
None: pass" is significantly faster.

Overall, performance-wise, it is irrelevant - use the code that is the
most clear in the situation. Only if there is a custom type involved,
and then only if that type defines Python code to be executed, does it
matter.

The tests (the code is shown later - its about 53 lines, with lots of
copy+paste...):
1a: 0.04 usec/pass  --  if None: pass
1b: 0.03 usec/pass  --  if True: pass
1c: 0.27 usec/pass  --  if customObjectWithNonZero: pass
1d: 0.04 usec/pass  --  if customObjectNoNonZero: pass
2a: 0.04 usec/pass  --  if None is None: pass
2b: 0.04 usec/pass  --  if True is None: pass
2c: 0.04 usec/pass  --  if customObjectWithNonZero is None: pass
2d: 0.04 usec/pass  --  if customObjectNoNonZero is None: pass

The tests were run on Python 2.6x64 on Windows:
2.6.4 (r264:75706, Aug  4 2010, 17:00:56) [MSC v.1500 64 bit (AMD64)]

The code:
import timeit

def test():
numRuns = 1000

statement1 = 'if x: pass'
statement2 = 'if x is None: pass'
setup1 = 'x = None'
setup2 = 'x = True'
setup3 = '''
class Test(object):
def __nonzero__(self):
return True
x = Test()'''
setup4 = '''
class Test(object):
pass
x = Test()'''

t1a = timeit.Timer(stmt=statement1, setup=setup1)
t1b = timeit.Timer(stmt=statement1, setup=setup2)
t1c = timeit.Timer(stmt=statement1, setup=setup3)
t1d = timeit.Timer(stmt=statement1, setup=setup4)
t2a = timeit.Timer(stmt=statement2, setup=setup1)
t2b = timeit.Timer(stmt=statement2, setup=setup2)
t2c = timeit.Timer(stmt=statement2, setup=setup3)
t2d = timeit.Timer(stmt=statement2, setup=setup4)

a1 = []
b1 = []
c1 = []
d1 = []
a2 = []
b2 = []
c2 = []
d2 = []
for i in xrange(10):
a1.append(100 * t1a.timeit(number=numRuns)/numRuns)
b1.append(100 * t1b.timeit(number=numRuns)/numRuns)
c1.append(100 * t1c.timeit(number=numRuns)/numRuns)
d1.append(100 * t1d.timeit(number=numRuns)/numRuns)
a2.append(100 * t2a.timeit(number=numRuns)/numRuns)
b2.append(100 * t2b.timeit(number=numRuns)/numRuns)
c2.append(100 * t2c.timeit(number=numRuns)/numRuns)
d2.append(100 * t2d.timeit(number=numRuns)/numRuns)
print "1a: %.2f usec/pass" % (sum(a1) / len(a1),)
print "1b: %.2f usec/pass" % (sum(b1) / len(b1),)
print "1c: %.2f usec/pass" % (sum(c1) / len(c1),)
print "1d: %.2f usec/pass" % (sum(d1) / len(d1),)
print "2a: %.2f usec/pass" % (sum(a2) / len(a2),)
print "2b: %.2f usec/pass" % (sum(b2) / len(b2),)
print "2c: %.2f usec/pass" % (sum(c2) / len(c2),)
print "2d: %.2f usec/pass" % (sum(d2) / len(d2),)


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


Re: Extracting elements over multiple lists?

2011-11-15 Thread Steven D'Aprano
On Tue, 15 Nov 2011 17:01:23 +, Prasad, Ramit wrote:

> Can you expand on why 'del' is "tricky"/misleading?

People often imagine that the del statement sends a message to the object 
"please delete yourself", which then calls the __del__ method. That is 
incorrect.

"del x" is an unbinding operation, it removes the *name* "x" from the 
current namespace. As a side-effect, if the object which was bound to x 
no longer has any other references to it, then the garbage collector will 
delete it and __del__ may be called.

(I say "may be called" rather than "will" because there are circumstances 
where __del__ methods won't get called, such as during interpreter 
shutdown.)

On the other hand, "del x[i]" does work like the way people expect. It 
deletes items from collections (lists, dicts, etc.) and does so by 
calling the method x.__delitem__(i). This also may cause the garbage 
collector to delete the object which was at x[i] if that was the last 
reference to that object.

CPython's implementation keeps a count of references for each object, and 
the garbage collector deletes the object immediately that reference count 
reaches zero. This is fast, simple, deterministic (objects will be 
predictably deleted as soon as they can be), but simple-minded, and so it 
is aided by a second garbage collector which runs periodically, looking 
for reference cycles. You can set how often this second garbage collector 
runs using the gc module.

Jython uses the Java garbage collector, and IronPython the .Net garbage 
collector. Neither are reference counters, and (as far as I know) neither 
guarantees that objects will be deleted as soon as they are free to be 
deleted. They will be deleted whenever the garbage collector gets around 
to it.


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


Re: Extracting elements over multiple lists?

2011-11-15 Thread Steven D'Aprano
On Wed, 16 Nov 2011 06:53:26 +1100, Chris Angelico wrote:

> On Wed, Nov 16, 2011 at 5:17 AM, Dave Angel  wrote:
>> a = someexpression...
>> b = a
>> 
>> del a
>>
>> Does not (necessarily) delete the object that a refers to.  It merely
>> deletes the symbol a.
> 
> I'd have to classify that as part of the change of thinking necessary
> for a refcounted language, and not specific to del at all. 

Languages aren't refcounted. Or at least, *Python* isn't a refcounted 
language. CPython is a refcounted implementation. IronPython and Jython 
are not. del behaves exactly the same in IronPython and Jython as it does 
in CPython: it removes the name, which may have a side-effect of deleting 
the object.


> The del
> statement is identical to "a = None" in terms of deleting objects;

I'm not entirely sure what you arr trying to say here. I *think* you are 
trying to say is this:

Given that `a` is bound to my_object initially, `del a` 
from the point of view of my_object is no different 
from re-binding a to some other object such as None 
(or any other object).

which is true as far as it goes, but it fails to note that the name "a" 
no longer exists after `del a` while it does exist after `a = None`.


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


Re: suppressing import errors

2011-11-15 Thread Steven D'Aprano
On Tue, 15 Nov 2011 14:22:21 -0800, Chris Kaynor wrote:

> The tests (the code is shown later - its about 53 lines, with lots of
> copy+paste...):

Holy unnecessarily complicated code Batman!

This is much simpler:

[steve@ando ~]$ python -m timeit -s "x = None" "if x is None: pass"
1000 loops, best of 3: 0.0738 usec per loop
[steve@ando ~]$ python -m timeit -s "x = True" "if x is None: pass"
1000 loops, best of 3: 0.0799 usec per loop

The difference is too small to be significant. If I run the same tests 
multiple times, the winner could easily change.


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


Re: Extracting elements over multiple lists?

2011-11-15 Thread Chris Angelico
On Wed, Nov 16, 2011 at 9:25 AM, Steven D'Aprano
 wrote:
> Languages aren't refcounted. Or at least, *Python* isn't a refcounted
> language. CPython is a refcounted implementation. IronPython and Jython
> are not. del behaves exactly the same in IronPython and Jython as it does
> in CPython: it removes the name, which may have a side-effect of deleting
> the object.

Yes, I was sloppy there. A non-manually-memory-managed language, if
you will; it's part of Python's spec that you do NOT have to
explicitly release objects you're no longer using.

>> The del
>> statement is identical to "a = None" in terms of deleting objects;
>
> I'm not entirely sure what you arr trying to say here. I *think* you are
> trying to say is this:
>
>    Given that `a` is bound to my_object initially, `del a`
>    from the point of view of my_object is no different
>    from re-binding a to some other object such as None
>    (or any other object).
>
> which is true as far as it goes, but it fails to note that the name "a"
> no longer exists after `del a` while it does exist after `a = None`.

Right. Both actions have the same effect wrt deleting my_object; the
only connection between Python's "del" and C++'s "delete" is that,
which del shares with "a = None".

The fact is that, regardless of the Python implementation, deleting
*objects* is not the programmer's responsibility. The only thing he
can or must do is delete *names*.

del a
del globals()['a']
globals().__delitem__('a')

are all roughly equivalent (assuming that a is global). Maybe this is
the best way to explain it - that you're deleting from a "dictionary"
(which may or may not actually be implemented as a dict) of local
names.

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


Re: suppressing import errors

2011-11-15 Thread Alan Meyer

On 11/15/2011 4:20 PM, David Riley wrote:
...

   None was set to some other value.  The other value might have a type
   (such as a container) that could be false in a boolean context!

Obviously, that last bit doesn't apply to modules; they're not going to evaluate as False in 
general.  I just bristle when I see people writing "if x" when they really mean "if 
x is not None", perhaps because it's not The Right Way(tm)?  It mostly comes down to 
aesthetics, I guess.  Write what you really mean.


Actually Dave, as your quote from PEP 8 says, the difference is real. 
It's not just aesthetics.


Consider this:

x = None
if x:
  print('if x == true')
else:
  print('if x == false')
if x is None:
  print('x is None == true')
else:
  print('x is none == false')

y = ''
if y:
  print('if y == true')
else:
  print('if y == false')
if y is None:
  print('y is None == true')
else:
  print('y is none == false')

The result is:

if x == false
x is None == true
if y == false
y is none == false

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


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Alan Meyer

On 11/15/2011 3:37 PM, Passiday wrote:

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order 
to provide a web-based application with python scripting capabilities. The app 
would have basic IDE for writing and debugging the python code, but the 
interpretation, of course, would be done in JavaScript. I'd like to avoid any 
client-server transactions, so all the interpretation should take place on the 
client side. The purpose of all this would be to create educational platform 
for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up 
anything. I've found some crazy project emulating PC in JavaScript (and even 
running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, 
but that seems like awful lot of work to do. Any ideas how I should proceed 
with this project?


I don't have any good ideas for how to do this, but I do have a warning. 
 The JavaScript security model prohibits a lot of things that Python 
does not prohibit.  So if you need to do anything like access a file on 
the user's machine or talk to some computer other than the one you came 
from, it won't work.


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


Re: suppressing import errors

2011-11-15 Thread David Riley
On Nov 15, 2011, at 5:59 PM, Alan Meyer wrote:

> On 11/15/2011 4:20 PM, David Riley wrote:
> ...
>>   None was set to some other value.  The other value might have a type
>>   (such as a container) that could be false in a boolean context!
>> 
>> Obviously, that last bit doesn't apply to modules; they're not going to 
>> evaluate as False in general.  I just bristle when I see people writing "if 
>> x" when they really mean "if x is not None", perhaps because it's not The 
>> Right Way(tm)?  It mostly comes down to aesthetics, I guess.  Write what you 
>> really mean.
> 
> Actually Dave, as your quote from PEP 8 says, the difference is real. It's 
> not just aesthetics.

 I guess I meant it's aesthetics when it comes down to determining whether a 
module is None or not; a module is never going to evaluate to False under any 
feasible circumstances.  It's not an aesthetic difference when you consider 
that the global (or local) namespace may be polluted with other variables that 
have the same name as your module, but then your evaluation would be entirely 
invalid anyway.

But yes, in the general case, it's much more than an aesthetic difference, 
which is why I always write "if x is None" when I want to know if it's None 
(rather than False, 0, [], "", etc).  I have been bitten way too many times by 
doing the lazy thing to keep doing it.

- Dave

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


redis beginner question

2011-11-15 Thread Jabba Laci
Hi,

I'm reading the redis documentation and there is one thing that
bothers me. For redis, you need to start a server on localhost. Is
there an easy way that my Python script starts this server
automatically? Before using my script, I don't want to start
redis-server each time. When my program terminates, the server could
be shut down automatically.

Thanks,

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


Re: (n00b) Tkinter trouble

2011-11-15 Thread Jason Swails
On Tue, Nov 15, 2011 at 12:32 AM, Chris Angelico  wrote:

>
> As a general rule, if any parent is invisible, you won't see the
> child, and if any parent is disabled, you can't access the child.


Yea, I'm becoming more familiar and comfortable with the GUI hierarchy as I
play around.  I do like how simple it is to test a concept in Tkinter (just
a couple lines builds you a window with any kind of widget you want).


> You
> may find that there's even a one-line command that will disable the
> window, open a new window, wait for the new window to close, and
> automatically reenable the window - an "open modal dialog" function or
> something.
>

Apparently I could not do what I was wanting to (state=DISABLED is not a
valid option to Toplevel).  What I wanted to do was something similar to
what the dialogs were doing from tkMessageBox.  The window didn't appear
changed, but no buttons could be clicked.  After looking through the
tkMessageBox.py source code, I found the method I was looking for:
grab_set.  Essentially, I just have to have my new window call its
grab_set() method to hog all events.  Not really "disabling" the root
window (which is why I had a hard time finding it on Google), but it's the
exact behavior I was looking for.
http://www.python-forum.org/pythonforum/viewtopic.php?f=15&t=4930 was
helpful here.

The only other approach I (successfully) tried was to use the .withdraw()
method on the window during the constructor of the *new* window and execute
.deiconify() on it during the new window's destroy() method (before calling
Toplevel's destroy on self).  I still like the first way better.

Thanks!
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Carl Banks
On Tuesday, November 15, 2011 12:37:03 PM UTC-8, Passiday wrote:
> Hello,
> 
> I am looking for a way how to bring Python interpreter to JavaScript, in 
> order to provide a web-based application with python scripting capabilities. 
> The app would have basic IDE for writing and debugging the python code, but 
> the interpretation, of course, would be done in JavaScript. I'd like to avoid 
> any client-server transactions, so all the interpretation should take place 
> on the client side. The purpose of all this would be to create educational 
> platform for learning the programming in python.
> 
> I hoped somebody already had done something like this, but I couldn't google 
> up anything. I've found some crazy project emulating PC in JavaScript (and 
> even running Linux on top of it), but not a python interpreter.
> 
> Of course, I could take the python source and brutally recode it in 
> JavaScript, but that seems like awful lot of work to do. Any ideas how I 
> should proceed with this project?


Some people have already made an LLVM-to-Javascript compiler, and have managed 
to build Python 2.7 with it.

The LLVM-to-Javascript project is called emscripten.

https://github.com/kripken/emscripten/wiki

Demo of Python (and a bunch of other languages) here:

http://repl.it/


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


Re: redis beginner question

2011-11-15 Thread Roy Smith
In article ,
 Jabba Laci  wrote:

> Hi,
> 
> I'm reading the redis documentation and there is one thing that
> bothers me. For redis, you need to start a server on localhost. Is
> there an easy way that my Python script starts this server
> automatically? Before using my script, I don't want to start
> redis-server each time. When my program terminates, the server could
> be shut down automatically.
> 
> Thanks,
> 
> Laszlo

Why do you want to stop redis after your program terminates?  Generally, 
you just start redis up when the system boots and leave it running.
-- 
http://mail.python.org/mailman/listinfo/python-list


python shell that saves history of typed in commands that will persist between reboots

2011-11-15 Thread goldtech
Hi,

Using Windows. Is there a python shell that has a history of typed in
commands?

I don't need output of commands just what I typed it. I need it to
save between sessions - something that no shell seems to do. If I
reboot there will still be a command history somewhere.

Like bash history in Linux.

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


Re: (n00b) Tkinter trouble

2011-11-15 Thread Chris Angelico
On Wed, Nov 16, 2011 at 2:02 PM, Jason Swails  wrote:
> Apparently I could not do what I was wanting to (state=DISABLED is not a
> valid option to Toplevel).  What I wanted to do was something similar to
> what the dialogs were doing from tkMessageBox.

Yes, that would be what you'd want. I wonder, though: Is Toplevel the
right window class? There may be a better class for a subwindow.
Again, I'm not familiar with Tkinter, but a quick google suggests that
Frame or Window might be worth looking into. Ideally, you want the
window to disable its parent and claim all events.

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


Re: python shell that saves history of typed in commands that will persist between reboots

2011-11-15 Thread sword
Maybe you're looking for ipython? History, tab-complete, sort of
things in it.

goldtech wrote:
> Hi,
>
> Using Windows. Is there a python shell that has a history of typed in
> commands?
>
> I don't need output of commands just what I typed it. I need it to
> save between sessions - something that no shell seems to do. If I
> reboot there will still be a command history somewhere.
>
> Like bash history in Linux.
>
> Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Stucked with python logging module

2011-11-15 Thread sword
I just scaned through the beginer's guide of logging module, but I
can't get anything from console. The demo just like this:

import logging
logging.debug("This is a demo")

Maybe I should do sth to put the log to stdout in basicConfig first?
Thanks in advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stucked with python logging module

2011-11-15 Thread Kushal Kumaran
On Wed, Nov 16, 2011 at 8:58 AM, sword  wrote:
> I just scaned through the beginer's guide of logging module, but I
> can't get anything from console. The demo just like this:
>
> import logging
> logging.debug("This is a demo")
>
> Maybe I should do sth to put the log to stdout in basicConfig first?

Actually, the problem is not of the output location, but of the
logging level.  In the default configuration, logs at DEBUG level are
suppressed.  logging.basicConfig will be a simple way to change this.
Are you following the logging documentation at
http://docs.python.org/py3k/howto/logging.html#logging-basic-tutorial?
 This page is part of the documentation of the logging module, and is
suitable for first-time logging module users.

In your case, you can do this:

import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("This is a demo")

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


Got some problems when using logging Filter

2011-11-15 Thread sword
The logging cookbook gives an Filter example, explainning how to add
contextural info to log. I can't figure out how to filter log from it.

Suppose I have 3 file, a.py, b.py and main.py
#file: a.py
import logging

logger=logging.getLogger(__name__)
def print_log():
logger.debug("I'm module a")

#file: b.py just like a.py
import logging
logger=logging.getLogger(__name__)
def print_log():
logger.debug("I'm module b")

#file: main.py
import logging
from logging import Filter
logging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger("main")
logger.debug("This is main process")
logger.addFilter(Filter("a"))

And I expected that the console output would contain main and b module
log only. But it turned out that all logs there.  Is it the problem of
root logger?


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


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Passiday
Thanks Carl, this looks like a good base to start from.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-15 Thread Passiday
Of course, I am aware of this. But the file system can be emulated, and certain 
networking can be mediated via the server, too. But for starts, I don't plan to 
go beyond the basic file operations, if at all.
-- 
http://mail.python.org/mailman/listinfo/python-list