Re: empty clause of for loops

2016-03-19 Thread André Roberge
On Wednesday, 16 March 2016 07:23:48 UTC-3, Sven R. Kunze  wrote:
> Hi,
> 
> a colleague of mine (I write this mail because I am on the list) has the 
> following issue:
> 
> 
> for x in my_iterable:
>  # do
> empty:
>  # do something else
> 
> 
> What's the most Pythonic way of doing this?
> 
> Best,
> Sven

for x in my_iterable:
   # do something

if not my_iterable:
   # do something else

André
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Still off-top] Physics [was Requests author discusses MentalHealthError exception]

2016-03-04 Thread André Roberge
This discussion about energy and masses of particles has nothing to do with 
Python, and I am hoping that it will be dropped.  That being said, I feel 
compelled to correct what are completely wrong statements.

On Friday, 4 March 2016 13:36:11 UTC-4, Oscar Benjamin  wrote:
> On 4 March 2016 at 10:38, Marko Rauhamaa <ma...@pacujo.net> wrote:
> > Oscar Benjamin <oscar.j.benja...@gmail.com>:
> >
...
> 
> That's just a casual use of terminology. If we want to be precise then
> it's pointless to even refer to the "rest mass" of something that is
> never at rest. The masslessness of photons comes from an extrapolation
> that leads to a divide by infinity: strictly speaking it's just
> undefined.

This is simply wrong.  In Quantum Field Theory, particles can have "bare" mass 
term included in the Lagrangian and the measured mass either includes the bare 
mass + quantum corrections OR is a purely dynamically generated term.

In the Standard Model, there is no bare mass term for the photon, nor is there 
any dynamically generated mass.  In fact, to preserve gauge invariance 
symmetry, the mass of the photon MUST be identically equal to zero.

(Of course, the Standard Model could be incorrect but all meausurements done so 
far are completely consistent with a massless photon; see 
http://pdg.lbl.gov/2015/listings/rpp2015-list-photon.pdf for current 
experimental limits.)


> 
> > As for the existence of a negative mass, it is interesting to note that
> > the (rest) mass of an alpha particle is less than the sum of the (rest)
> > masses of its constituents. About 1% of the mass is "missing."
> 
> Since the binding is associated with negative energy it has a negative
> contribution to the energy/mass of the particle as a whole. This is
> true of any bound state.
> 
> Something I don't know is if there's some theoretical reason why the
> binding energy could never exceed the sum of the energies of the
> constituent particles (resulting in an overall negative mass).

The (magnitude of the) binding energy is DEFINED as the difference between the 
(energy equivalent) sums of the individual masses of the consistuents and that 
of the bound state.

===
Now, could we forget about Physics and go back to discussions related to Python?

André Roberge


> 
> --
> Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: variable vs. object

2015-11-29 Thread André Roberge
On Sunday, 29 November 2015 22:06:58 UTC-4, fl  wrote:
> Hi,
> 
> I read several parts on line about Python that everything in Python is an 
> object. Yes, it is a key difference with other languages. Then, I read a page
> it says variables: global and local variable at:
> 
> http://www.tutorialspoint.com/python/python_functions.htm
> 
> 
> I have a question that whether variables are objects?
> 
> For example,
> 
> a=10
> 
> 'a' is an integer. Is it an object too?
> 
> Thanks,

In Python, a "variable" is a name given to an object.  In Python, the "=" sign 
is used to assign a name to an object: the name is on the left-hand side, and 
the object is on the right hand side.   Multiple names can be assigned to the 
same object.  In the example you gave, "a" is a name given to the object "10" 
which is an integer.

If you do:

a = 10
b = a
a = "hello"

b will be 10.  b was just another name given to object 10 to which the name "a" 
was referring to at that point, even though we decided later that a should 
refer to the string "hello" (which is an object).

André
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python PEP suggestion

2015-11-08 Thread André Roberge
On Sunday, 8 November 2015 11:35:32 UTC-4, Dan Strohl  wrote:
> All,
> 
> I wanted to run the following thought past the list as a possible PEP 
> enhancement suggestion to see if it feels like something that is worth 
> proposing.   I know it is not in the PEP format at this point, I can, and 
> will, clean it up if needed, I am just trying to throw it against the wall at 
> this point to see if it resonates... (or if it falls flat and goes "splat" 
> ).
> 
> Thoughts?
> 
> Dan Strohl
>
Snip

You might want to post this to the python-ideas list.

André
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can anybody explain the '-' in a 2-D creation code?

2015-06-25 Thread André Roberge
On Thursday, 25 June 2015 22:07:42 UTC-3, fl  wrote:
 Hi,
 
 I read Ned's tutorial on Python. It is very interesting. On its last
 example, I cannot understand the '_' in:
 
 
 
 board=[[0]*8 for _ in range(8)]
 
 
 I know  '_' is the precious answer, but it is still unclear what it is
 in the above line. Can you explain it to me?

'_' is the previous answer ONLY when using the read-eval-print-loop interpreter.

Here, it is the name of a variable; since we don't care about the particular 
name (it is used just for looping a fixed number of times), the common practice 
of using '_' has been used.  As you will have noted (since it confused you), 
'_' doesn't seem to designate anything of interest - unlike a variable name 
like 'string_index' or 'character', etc.

Sometimes, people will use the name dummy instead of '_', with the same idea 
in mind.
 
 
 Thanks,

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


Re: An object is an instance (or not)?

2015-01-27 Thread André Roberge
On Tuesday, 27 January 2015 17:43:38 UTC-4, Mario Figueiredo  wrote:
 In article a771f6f2-9aa3-44ca-9f87-88a984c7c...@googlegroups.com, 
 andre.robe...@gmail.com says...
  
  It is appropriate to refer to an instance as an object.  It might not 
  be appropriate to refer to an object as an instance ... but Python
  does not do so as your explicit examples demonstrate, and contrary to 
  your claim.
 
 I'll try one more time: It - Is - Not - My - Claim.
 
 It is the claim of a few users in here that replied to that thread.

At the very beginning of the first message I replied to, you wrote:

**This is a follow up from a previous discussion in which it is argued 
that the following code produces the correct error message terminology **

I pointed out to you that the word object WAS used correctly: hence, the 
correct terminology was used in that error message.

You are just wasting people's time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An object is an instance (or not)?

2015-01-27 Thread André Roberge
On Tuesday, 27 January 2015 16:12:47 UTC-4, Mario Figueiredo  wrote:
 This is a follow up from a previous discussion in which it is argued 
 that the following code produces the correct error message terminology, 
 considering that in Python an object is also an instance.
 
  class Sub:
  pass
 
  foo = Sub()
  foo.__bases__
 [...]
 AttributeError: 'Sub' object has no attribute '__bases__'
 
 I'm making this into a new thread, because the particular discussion of 
 whether an object is an instance in Python seems more interesting than 
 discussing whether that error message should be changed or not.
 
 Here's another example where the terminology keeps indicating that in 
 Python an object is an instance:
 
  class Sub:
   pass
 
  x = Sub()
  x
 __main__.Sub object at 0x02631690
 
 The problem is that I personally cannot agree with this terminology and 
 I would like to hear arguments that could convince me to adopt the 
 Python way. But before your replies, here's my argumentation:
 
 An instance IS an object. On that we can agree. After all, everything in 
 Python is an object. Even classes are. We can even pass them as function 
 arguments:
 
  class Sub:
   pass
 
  def show(aClass):
   print(type(aClass))
   
  show(Sub)
 class 'type'
 
 The problem is that an object isn't always an instance. The word 
 instance in OOP has a very formal meaning. In programming languages in 
 which the classes aren't fully realized objects, it is ok to speak of 
 'instance' and 'object' interchangeably. But even then, sometimes the 
 term 'object instance' is preferred, as a way to separate these 
 'instances' from other variable instances that may not be created from 
 class definitions (e.g. C++ built-in types).
 
 The fact that in Python classes are objects, should not just eliminate 
 this distinction. The OOP terminology should exist beyond the language 
 implementing it. It facilitates discourse and helps transmiting concepts 
 when describing your ideas to another programmer. And because in python, 
 classes are of the type 'type' and they exist as fully realized objects, 
 is no excuse to make a distinction between them and their own fully 
 realized instances. The language implementation details should not exist 
 as a way for us to freely reformulate long standing terms.
 
 Because, from my own study of Python, I've came to realize that the 
 distinction between objects and instances of objects actually exists. In 
 Python, class objects cannot participate in OOP, only their instances. 
 This is why I say that even in Python, where a class is an object, an 
 object is not always an instance. The language itself forces that 
 distinction.
 
 ...
 
 I don't think that any of this is reason enough to rewrite error 
 messages in Python. Seems unnecessary. What I'm arguing thought is that 
 error messages in Python cannot become the source of new terminology. 
 The language itself implements a very clear distinction between class 
 objects and their instances. And it is thus wrong of us to say that 
 Object = Instance. At least from an OOP perspective.

You keep writing an object is not an instance, making statements such as the 
terminology keeps indicating that in Python an object is an instance and yet, 
none of the examples you show from Python (tracebacks or repr outputs) include 
the word instance.   

To phrase it differently: all the examples of output from Python that you show 
use the word object and not the word instance.  Yet **you** claim that 
Python states that objects are instances Can you point out at least 
one example where Python wrongly use the word instance instead of object?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An object is an instance (or not)?

2015-01-27 Thread André Roberge
On Tuesday, 27 January 2015 17:06:50 UTC-4, Mario Figueiredo  wrote:
 In article 80a9f882-6b13-45a7-b514-8c47b3a4c...@googlegroups.com, 
 andre.robe...@gmail.com says...
  
  You keep writing an object is not an instance, making statements
  such as the terminology keeps indicating that in Python an object is 
  an instance and yet, none of the examples you show from Python
  (tracebacks or repr outputs) include the word instance.   
 
 I think you misread my argument. Look at the first example on my post, 
 or follow the discussion on __bases__ misleading error message here on 
 the newsgroups.


 
 That error message has me start that thread arguing that the error is 
 misleading because the Sub object does have the __bases__ attribute. 
 It's the Sub instance object that does not have it.
 

To use the word object to describe an instance is perfectly appropriate. Your 
claims imply the the opposite is happening.

 Some of the answers that were given argued that in Python object = 
 instance.
 
  Yet
  **you** claim that Python states that objects are instances 
 
 That is no my claim. I said that much. You should probably read my post 
 more carefully.

I read your post carefully: not once did I see an output from Python using the 
word instance.


From your post:

 Python's output ==
AttributeError: 'Sub' object has no attribute '__bases__' 
=
Python uses the word object, not instance.



++ your words +++

Here's another example where the terminology keeps indicating that in 
Python an object is an instance: 
++

==Python's output ===
__main__.Sub object at 0x02631690 
===
Python uses the word object, not instance, contrary to what you wrote.



+++ your words ++

The problem is that an object isn't always an instance. 
+


 your words 

What I'm arguing thought is that 
error messages in Python cannot become the source of new terminology. 


Not a single output from Python uses the word instance.

It is appropriate to refer to an instance as an object.  It might not be 
appropriate to refer to an object as an instance ... but Python does not do so 
as your explicit examples demonstrate, and contrary to your claim.

A.R.


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


Re: How to wow someone new to Python

2015-01-21 Thread André Roberge
On Friday, 16 January 2015 11:04:20 UTC-4, Chris Angelico  wrote:
 Scenario: You're introducing someone to Python for the first time.
 S/he may have some previous programming experience, or may be new to
 the whole idea of giving a computer instructions. You have a couple of
 minutes to show off how awesome Python is. What do you do?
 
 I was thinking along the lines of a simple demo in the REPL, showing
 off some of Python's coolest features. But then I got stuck on the
 specifics. What are Python's best coolnesses? What makes for a good
 demo?
 
 Ideally, this should be something that can be demo'd quickly and
 easily, and it should be impressive without going into great details
 of and see, this is how it works on the inside. So, how would you
 brag about this language?
 
 ChrisA
If you are willing to install an older version of Python (because the program I 
am going to mention has not been updated in years ... but it *should* work with 
2.6), I'm going to suggest an odd one:  Crunchy!  (ok, I'm biased :-).

The home page is at https://code.google.com/p/crunchy/ where you can find a 
link to some screencasts (based on an even older version ...)   So, before you 
install anything, just have a quick look at the screencast to see if it's 
worthwhile.

A demo using Crunchy seems to  be even more impressive if the person knows some 
programming.

(Here is what was said about an even older version of Crunchy by people at the 
Omaha Python group:  Jeff gave a presentation on Crunchy ([WWW]
http://crunchy.sourceforge.net/) Talk about a gee whiz app.  
[https://mail.python.org/pipermail/omaha/2007-July/65.html])

In a nutshell, I would open the official Python tutorial in my browser, showing 
the official Python tutorial.   (boring)

Then, I would open the exact same page using a browser tab served by Crunchy: 
magically some text-input boxes would have been inserted allowing you to try 
out the code in the REPL provided by Crunchy.  Then I'd use Crunchy to launch 
an external app (perhaps a tkinter program), etc.

As I said at the beginning, Crunchy has not been updated in *years* ... more or 
less since the IPython and Sage notebooks came along...

André
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to wow someone new to Python

2015-01-21 Thread André Roberge
On Wednesday, 21 January 2015 15:06:33 UTC-4, Chris Angelico  wrote:
 On Thu, Jan 22, 2015 at 5:20 AM, Irmen de Jong  wrote:
  On 21-1-2015 18:59, Steve Hayes wrote:
 
  3. When I started to look at it, I found that strings could be any length 
  and
  were not limited to swomething arbitrary, like 256 characters.
 
  Even more fun is that Python's primitive integer type (longs for older 
  Python versions)
  has no arbitrary limitation either.
 
  That amazed me at the time I discovered python :)
 
 I hadn't worked with length-limited strings in basically forever
 (technically BASIC has a length limit, but I never ran into it; and I
 never did much with Pascal), but you're right, arbitrary-precision
 integers would have impressed me a lot more if I hadn't first known
 REXX. So... is there a way to show that off efficiently? 

How about:

  def fac(n):
 ... ans = 1
 ... while n  1:
 ... ans *= n
 ... n -= 1
 ... return ans
 ...
  a = fac(100)
  a
 
9332621544394415268169923885626670049071596826438162146859296389521753229915608941463976156518286253697920827223758251185210916864
  b = fac(102)
  b
 
961446671503512660926865558697259548455355905059659464369444714048531715130254590603314961882364451384985595980362059157503710042865532928
  b//a
 10302
  b//a == 102 * 101
 True

André


Normally, any
 calculation that goes beyond 2**32 has already gone way beyond most
 humans' ability to hold the numbers in their heads.
 
 ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to run a python script with functions

2015-01-20 Thread André Roberge
On Tuesday, 20 January 2015 17:11:58 UTC-4, faiz@gmail.com  wrote:
 Hi
 
 I have a file with a python scripts that has many functions in it. To run the 
 script I did the following:
 1. $ python (to initiate python, using the python command)
 2.  import file_name (without .py)
 3.  file_name.function_name(argument) (to run the function_name with 
 argument (argument)
 
 My question is: Is there any other way that I can just use the function name 
 (function_name) without having to use the file_name. part? That is, use only:
  function_name(argument)
 

from file_name import function1, function2

 ~faizlo

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


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-13 Thread André Roberge
On Tuesday, 13 January 2015 08:23:30 UTC-4, stephen...@gmail.com  wrote:
 I found a solution that I'm happy with.
 
 from datetime import datetime
 from easygui_qt import *
 
 datestring = get_date()
 mydate = datetime.strptime(datestring, '%b %d %Y')

I'm thinking of having the new version return a datetime object automatically.

André

 
 On Saturday, January 10, 2015 at 1:02:30 AM UTC, André Roberge wrote:
  On Friday, 9 January 2015 19:09:15 UTC-4, stephen...@gmail.com  wrote:
   On Wednesday, December 31, 2014 at 4:24:50 PM UTC-6, André Roberge wrote:
EasyGUI_Qt version 0.9 has been released.  This is the first 
announcement about EasyGUI_Qt on this list.

Like the original EasyGUI (which used Tkinter), 
EasyGUI_Qt seeks to provide simple GUI widgets
that can be called in a procedural program. 

EasyGUI_Qt is NOT event-driven: all GUI interactions are invoked by 
simple function calls.

The archetype is get_string(message)
which pops a box whose purpose is exactly the same as Python's 
input(prompt),
that is, present the user with a question/prompt, have the user enter an
answer, and return the provided answer as a string.  Thus
easygui_qt.get_string() can be used as a drop-in replacement for
input().

Similarly, instead of using a print() function to display a message,
show_message() is used which pops a message window.

EasyGUI_Qt requires PyQt4 and is really targeted for Python 3.3+ - 
although it can work (possibly with some unicode problems ...) using 
Python 2.7.

More information can be found at 
http://easygui-qt.readthedocs.org/en/latest/index.html

Feedback is most welcome, including reporting bugs to 
https://github.com/aroberge/easygui_qt/issues

Happy 2015 everyone,

André Roberge
   
   Very nice, thanks.
   
   One issue is the format returned for the calendar selection. For today, 
   the string returned is Fri Jan 9 2015. My script needs to convert the 
   date to a datetime.date, and having the month returned as a string 
   instead of an integer makes this harder.
  
  Would today's date be represented as the string 09.01.2015 useful to you? 
  (I found out how to do this.)  If so, I could perhaps add an argument like 
  numeric_format = True.
  
  André

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


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-09 Thread André Roberge
On Friday, 9 January 2015 19:09:15 UTC-4, stephen...@gmail.com  wrote:
 On Wednesday, December 31, 2014 at 4:24:50 PM UTC-6, André Roberge wrote:
  EasyGUI_Qt version 0.9 has been released.  This is the first announcement 
  about EasyGUI_Qt on this list.
  
  Like the original EasyGUI (which used Tkinter), 
  EasyGUI_Qt seeks to provide simple GUI widgets
  that can be called in a procedural program. 
  
  EasyGUI_Qt is NOT event-driven: all GUI interactions are invoked by simple 
  function calls.
  
  The archetype is get_string(message)
  which pops a box whose purpose is exactly the same as Python's 
  input(prompt),
  that is, present the user with a question/prompt, have the user enter an
  answer, and return the provided answer as a string.  Thus
  easygui_qt.get_string() can be used as a drop-in replacement for
  input().
  
  Similarly, instead of using a print() function to display a message,
  show_message() is used which pops a message window.
  
  EasyGUI_Qt requires PyQt4 and is really targeted for Python 3.3+ - although 
  it can work (possibly with some unicode problems ...) using Python 2.7.
  
  More information can be found at 
  http://easygui-qt.readthedocs.org/en/latest/index.html
  
  Feedback is most welcome, including reporting bugs to 
  https://github.com/aroberge/easygui_qt/issues
  
  Happy 2015 everyone,
  
  André Roberge
 
 Very nice, thanks.
 
 One issue is the format returned for the calendar selection. For today, the 
 string returned is Fri Jan 9 2015. My script needs to convert the date to a 
 datetime.date, and having the month returned as a string instead of an 
 integer makes this harder.

Would today's date be represented as the string 09.01.2015 useful to you? (I 
found out how to do this.)  If so, I could perhaps add an argument like 
numeric_format = True.

André
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-09 Thread André Roberge
On Friday, 9 January 2015 19:09:15 UTC-4, stephen...@gmail.com  wrote:

 Very nice, thanks.
 
 One issue is the format returned for the calendar selection. For today, the 
 string returned is Fri Jan 9 2015. My script needs to convert the date to a 
 datetime.date, and having the month returned as a string instead of an 
 integer makes this harder.

Unfortunately, this is the default calendar widget from Qt - I just use the 
default:
 ... def confirm(self):
self.date = self.cal.selectedDate()

Perhaps I can find something in the docs to see if I could have the format 
configurable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-03 Thread André Roberge
On Saturday, 3 January 2015 04:52:21 UTC-4, wxjm...@gmail.com  wrote:
 Le vendredi 2 janvier 2015 20:11:25 UTC+1, André Roberge a écrit :
  On Friday, 2 January 2015 06:29:37 UTC-4, wxjm...@gmail.com  wrote:
   Le mercredi 31 décembre 2014 23:24:50 UTC+1, André Roberge a écrit :
EasyGUI_Qt version 0.9 has been released.  This is the first 
announcement about EasyGUI_Qt on this list.
  snip
   I toyed and I spent a couple of hours with it.
   I do not know to much what to say.
  Well, this is more positive than your previous comment expressing doubt 
  that it would work. ;-)   So, thank you!
 
 Do not get me wrong, I do not wish to be rude.
 You are building a tool upon a toolkit which
 simply does not work properly.
 
 If for some reason you are not aware of this,
 you are not aware of this, it is unfortunately
 a simple as this.
 
 (Not only I know why, I'm able to explain the
 cause).

Would you care to elaborate?  All the code I have written works correctly on 
all the tests I have done.  I do have reports from a user using a Mac with 
Python 2.7 for which some widgets did not quite work properly ... but that's 
all I have heard about problems with it. 

I would like to hear about the problems you know about either here, on by 
filing an issue at https://github.com/aroberge/easygui_qt/issues
 
 jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-02 Thread André Roberge
On Friday, 2 January 2015 15:22:22 UTC-4, Emil Oppeln-Bronikowski  wrote:
 On Fri, Jan 02, 2015 at 11:11:05AM -0800, André Roberge wrote:
 
 Sorry if this was asked before: have you tried building a portable version 
 using py2exe/Nuitka/etc? I always hit a wall when it comes to building 
 against huge libraries like Python-Qt.
 
No, this would seem really silly since the widgets created by EasyGUI_Qt need 
to be used within a Python program, like Python's own input() function.  What 
would happen if you took a simple module containing the following:

def get_string(prompt):
return input(prompt)

and tried to package it into an exe?  How could it then be used?

 -- 
 People are like potatos. They die when you eat them.

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


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-02 Thread André Roberge
On Friday, 2 January 2015 06:29:37 UTC-4, wxjm...@gmail.com  wrote:
 Le mercredi 31 décembre 2014 23:24:50 UTC+1, André Roberge a écrit :
  EasyGUI_Qt version 0.9 has been released.  This is the first announcement 
  about EasyGUI_Qt on this list.
snip
 I toyed and I spent a couple of hours with it.
 I do not know to much what to say.
Well, this is more positive than your previous comment expressing doubt that it 
would work. ;-)   So, thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] EasyGUI_Qt version 0.9

2015-01-02 Thread André Roberge
On Friday, 2 January 2015 16:22:21 UTC-4, Emil Oppeln-Bronikowski  wrote:
 On Fri, Jan 02, 2015 at 11:53:26AM -0800, André Roberge wrote:
  How could it then be used?
 
 Maybe I failed to explain myself fully. What I meant to say is building a 
 distribution-ready program that utilizes your library; not your library being 
 turn into a executable.

Ah, this makes sense.  But I have not had the need to do so mysefl.
 
 Or maybe something is going over my head? Tell you what, once I get to some 
 decent network I'll try it on my own. :)
Please, let me know what you think - direct email is probably better.
 -- 
 People are like potatos. They die when you eat them.

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


[ANN] EasyGUI_Qt version 0.9

2014-12-31 Thread André Roberge
EasyGUI_Qt version 0.9 has been released.  This is the first announcement about 
EasyGUI_Qt on this list.

Like the original EasyGUI (which used Tkinter), 
EasyGUI_Qt seeks to provide simple GUI widgets
that can be called in a procedural program. 

EasyGUI_Qt is NOT event-driven: all GUI interactions are invoked by simple 
function calls.

The archetype is get_string(message)
which pops a box whose purpose is exactly the same as Python's input(prompt),
that is, present the user with a question/prompt, have the user enter an
answer, and return the provided answer as a string.  Thus
easygui_qt.get_string() can be used as a drop-in replacement for
input().

Similarly, instead of using a print() function to display a message,
show_message() is used which pops a message window.

EasyGUI_Qt requires PyQt4 and is really targeted for Python 3.3+ - although it 
can work (possibly with some unicode problems ...) using Python 2.7.

More information can be found at 
http://easygui-qt.readthedocs.org/en/latest/index.html

Feedback is most welcome, including reporting bugs to 
https://github.com/aroberge/easygui_qt/issues

Happy 2015 everyone,

André Roberge
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problems with Methods in Python 3.4.2

2014-12-18 Thread André Roberge
On Thursday, 18 December 2014 13:28:33 UTC-4, Marcus Lütolf  wrote:
 Hello Dears,
 1)I am trying to do this:
  
  dir(_builtins_)
You need two underscore characters on each sides:

dir(__builtins__)

  
 I am getting this:
 Traceback (most recent call last):
   File pyshell#0, line 1, in module
 dir(_builtins_)
 NameError: name '_builtins_' is not defined
  
 2)I am trying to do this:
  
  'TTA',_add_('GGA')
Same; magic methods have two underscore characters on each side.
  
 I'am getting this :
 Traceback (most recent call last):
   File pyshell#0, line 1, in module
 'TTA',_add_('GGA')
 NameError: name '_add_' is not defined
  
 3)I am trying to do this:
  
  -3  .abs()
abs(-3)  abs is a function in Python.

See http://lucumr.pocoo.org/2011/7/9/python-and-pola/ for a good explanation...

  
 I'am getting this
 Traceback (most recent call last):
   File pyshell#1, line 1, in module
 -3 .abs()
 AttributeError: 'int' object has no attribute 'abs'
  
 4) finally, after printing
  
 abs._doc_()
  

Guess why!  ;-)

 I am getting this (and so on) :
 Traceback (most recent call last):
   File pyshell#2, line 1, in module
 abs._doc_()
 AttributeError: 'builtin_function_or_method' object has no attribute '_doc_'
 
 What did I do wrong ? Thanks for help, Marcus Luetolf, M.D., 90 Bondastreet, 
 CH-7000 Chur, Switzerland.
  
 
 
 
 
 
   
   
   
   
   
   
   
   
 
   Diese E-Mail wurde von Avast Antivirus-Software 
 auf Viren geprüft.
   
 www.avast.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Puzzled by FiPy's use of ==

2012-03-26 Thread André Roberge
In FiPy (a finite volume PDE solver), equations are magically set up as 

eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)

and solved via

eqX.solve(...)

How can eqX be anything than True or False?...  This must be via a redefinition 
of == but I can't see how that is done.  I did look at many of the source 
files, thinking that it must be via a redefinition of __eq__ somewhere but 
with no luck.   Any pointers would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Puzzled by FiPy's use of ==

2012-03-26 Thread André Roberge
On Monday, 26 March 2012 09:16:07 UTC-3, Robert Kern  wrote:
 On 3/26/12 12:47 PM, André Roberge wrote:
  In FiPy (a finite volume PDE solver), equations are magically set up as
 
  eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)
 
  and solved via
 
  eqX.solve(...)
 
  How can eqX be anything than True or False?...  This must be via a 
  redefinition of == but I can't see how that is done.  I did look at many 
  of the source files, thinking that it must be via a redefinition of 
  __eq__ somewhere but with no luck.   Any pointers would be appreciated.
 
 It's in the root base class Term:
 
http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374
 

I thought I looked at terms.py ... but I must have missed that.  Thanks!

 -- 
 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: IDLE won't wrap lines of text

2011-02-20 Thread André Roberge
On Sunday, February 20, 2011 10:51:38 PM UTC-4, Dick Moores wrote:
 On Sun, Feb 20, 2011 at 18:32, Rhodri James rho...@wildebst.demon.co.uk 
 wrote:
  On Mon, 21 Feb 2011 01:41:12 -, Richard D. Moores rdmo...@gmail.com
  wrote:
 
  On Sun, Feb 20, 2011 at 16:31, Rhodri James rho...@wildebst.demon.co.uk
  wrote:
 
  On Sat, 19 Feb 2011 23:56:45 -, Richard D. Moores
  rdmo...@gmail.com
  wrote:
 
  Vista
  Python 3.1.3
 
  I can't figure out how to get IDLE to wrap text pasted in from, say, a
  newspaper article. Usually, a each paragraph will appear as one long
  unwrapped line, with no way to read the whole line, because no
  horizontal bar is created. I haven't found anything about this in
  either the options or the help.
 
  I hate to ask, but why are you doing this?  IDLE isn't a general-purpose
  editor, it's a programming editor specifically for Python, and as such
  it's
  entirely appropriate for it to discourage overly long lines.
 
  Take a look at http://tutoree7.pastebin.com/EmyQTaYt
 
  I see.  I'd recommend the approach of sticking your source data in a
  separate text file (using a text editor rather than IDLE) in any case;
  it's much less of a pain to change what you are working on that way.
 
 Problem is I know of no text editor that can handle Japanese.
 
 Thanks,
 
 Dick


The editor in Crunchy (http://code.google.com/p/crunchy) appears to be working 
just fine with the sample code you posted (at least when using Python 3 - I got 
an error when using it to run the code with Python 2). That being said, I would 
not recommend it for heavy work 

An editor that seems to work just fine (although it took a long time to load 
the sample code) is SublimeText (http://www.sublimetext.com/) - version 2 
alpha; it is becoming my editor of choice.

André

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


Re: floating point woes

2011-02-15 Thread André Roberge
On Tuesday, February 15, 2011 7:49:34 PM UTC-4, Hans-Peter Jansen wrote:
 Hi,
 
 while I usually cope with the woes of floating point issues, this is 
 one, that I didn't expect:
 
  round(2.385, 2)
 2.3799
 
 Doesn't the docs say, it's rounded up for this case?

The problem is probably that 2.385 can not be represented as 2.3850

 a = 2.385
 a
2.3848

André
 
 quote
 Values are rounded to the closest multiple of 10 to the power minus n; 
 if two multiples are equally close, rounding is done away from 0
 /quote
 
 Well, that one is clearly rounding down.
 
 What's up, eh, down here?
 
 Pete
 
 Python 2.6 (r26:66714, Feb  8 2011, 08:50:11) 
 [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2

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


Re: Arrays/List, filters, Pytho, Ruby

2011-02-11 Thread André Roberge
On Friday, February 11, 2011 5:24:15 PM UTC-4, LL.Snark wrote:
 Hi,
 
 I'm looking for a pythonic way to translate this short Ruby code :
 t=[6,7,8,6,7,9,8,4,3,6,7]
 i=t.index {|x| xt.first}
 
 If you don't know Ruby, the second line means :
 What is the index, in array t, of the first element x such that xt[0].
 
 If can write it in python several ways :
 t=[6,7,8,6,7,9,8,4,3,6,7]
 i=0
 while t[i]=t[0] : i+=1
 
 ... not pythonic I think...
 
 Or :
 t=[6,7,8,6,7,9,8,4,3,6,7]
 i=[j for j in range(len(t)) if t[j]t[0]][0]
 
 ...too cryptic...
 
You could go with something like (untested)
t = [6,7,8,6,7,9,8,4,3,6,7]
for i, j in enumerate(t):
if j  t[0]:
break
else:
i = 0

;-)



 I'm using Python 3.
 
 Thx

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


Re: Print docstrings to shell

2011-02-01 Thread André Roberge
On Tuesday, February 1, 2011 8:11:51 PM UTC-4, Gnarlodious wrote:
 Can I run a script in bash and print out its docstrings to the bash
 shell? I tried this at the end:
 
 print(help(__file__))
 
 Runnig the script:
 python ~/Sites/Sectrum/Harmonics.py
 
 but all it spit out was:
 
 no Python documentation found for '~/Sites/Sectrum/Harmonics.py'
 
 However in the interactive shell it prints out the class structure
 nicely. What I really want to see is this output in the bash window.
 
 -- Gnarlie

Try the following:

test.py==
import pydoc

'''this is a test'''

class A(object):
'''docstring'''
pass

print(pydoc.help(__file__[:-3]))
=

python test.py

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


Re: Print docstrings to shell

2011-02-01 Thread André Roberge
On Tuesday, February 1, 2011 9:05:28 PM UTC-4, Gnarlodious wrote:
 On Feb 1, 5:30 pm, André Roberge andre@gmail.com wrote:
 
  test.py==
  import pydoc
 
  '''this is a test'''
 
  class A(object):
          '''docstring'''
          pass
 
  print(pydoc.help(__file__[:-3]))
  =
 
  python test.py
 
 
 OK that works, but only if I cd into the folder of the script. If I
 run it from ~ I get the same error. How to get around that prob?
 
 -- Gnarlie

===
import pydoc
import os
import sys

'''this is a test'''

class A(object):
'''docstring'''
pass

_path, _file_name = os.path.split(__file__)
_module_name = _file_name[:-3]
sys.path.append(_path)
pydoc.help(_module_name)
=

Note: I've included an underscore in variables names so that they would not 
appear.
Note 2: for some reason, which I do not understand, it shows the help twice 
(i.e. I have to hit q twice to make it go away).  Sorry that I can not help 
with this.

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


Re: Print docstrings to shell

2011-02-01 Thread André Roberge
On Tuesday, February 1, 2011 9:21:48 PM UTC-4, André Roberge wrote:
SNIP
 
 ===
 import pydoc
 import os
 import sys
 
 '''this is a test'''
 
 class A(object):
   '''docstring'''
   pass
 
 _path, _file_name = os.path.split(__file__)
 _module_name = _file_name[:-3]
 sys.path.append(_path)
 pydoc.help(_module_name)
 =
 

Actually, one does not need to import pydoc; using help() without importing 
seems to work just as well (or as badly, as it displays it twice...)
André


 Note: I've included an underscore in variables names so that they would not 
 appear.
 Note 2: for some reason, which I do not understand, it shows the help twice 
 (i.e. I have to hit q twice to make it go away).  Sorry that I can not help 
 with this.
 
 André

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


Re: Wheel-reinvention with Python

2005-07-31 Thread André Roberge
Paul McNett wrote:
[snip]
Terry Hancock [EMAIL PROTECTED] writes:
 
I know I'm diving into this conversation late, and I haven't read
the whole thread, but has someone yet mentioned the anygui
project?  This has stalled, but it was IMHO a good idea.

Well, it appears to be more than stalled!
 From http://anygui.sourceforge.net/:
Note: Anygui is no longer being actively developed or supported. These 
pages are not up to date.

[snip]
 
 Now, that was only one part of the original Dabo vision, and the other 
 parts of the vision may actually add too much baggage and bloat for 
 people just interested in the UI aspect. Dabo also provides an 
 Application object, a database layer, and a business object layer. Ed 
 and I have discussed the possibility of ripping out the UI layer and 
 putting it into a completely separate project for the purpose of getting 
 more wxPython users interested. It wouldn't be all that hard to do, 
 because we've kept all the UI code separate from the the other stuff by 
 design.
 
Please do!

On a somewhat unrelated note: is there any overlap/possibility of 
collaboration between Dabo-UI and Wax?  (I have use neither, sticking
to pure wxPython so far.)

André

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


Re: print ending with comma

2005-07-19 Thread André Roberge
[EMAIL PROTECTED] wrote:
[snip]
 
 A \n character is written at the end, unless the print statement ends
 with a comma.
 
 What it doesn't say is that if the print statement does end with a
 comma, a trailing space is printed.
 --
 But this isn't exactly correct either. If you run this program:
 import sys
 print '+',
 print '-',
 sys.stdout.write('=')
 print
 --
 the output is:
 + -=
[snip]
 I know that this is not a massively important issue, but can someone
 explain what's going on?
 
Actually, it is not a trailing space but a leading space
that is stored and displayed when print is called next.
  import sys
  print 'a',
a
  print 'b',
  b
 
---
sys.stdout.write() does not include such a leading space.

Time to consult python.org about the print statement.:
[http://www.python.org/doc/2.0.1/ref/print.html]

...A space is written before each object is (converted and) written, 
unless the output system believes it is positioned at the beginning of a 
line...

Yep, another case of RTM :-)

André

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


BUG-FIX: RUR-PLE 0.9.0.1

2005-06-01 Thread André Roberge
RUR is a Python Learning Environment, based after Pattis's Karel the 
robot. More details can be found at http://rur-ple.sourceforge.net

Version 0.9.0.1 is a bug-fix.  Version 0.9 relied on the presence of a 
unicode version of wxPython  (version 2.6 preferred).  Version 0.9.0.1 
should work with both the unicode and the ansi version of wxPython.

André

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


Re: ANN: new release of RUR-PLE available

2005-05-20 Thread André Roberge
Michael Hoffman wrote:
 André Roberge wrote:
 
Version 0.8.6a is now available.
 
 
 You might see a bit more interest if you briefly explain what RUR-PLE 
 is, and where to find it.
Oops.. sorry about that.

RUR - a Python Learning Environment.
Its purpose is to provide an environment where people with no prior 
experience can learn computer programming (using Python of course!).

RUR-PLE currently requires that both Python and wxPython be installed.
More information can be found at http://rur-ple.sourceforge.net

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


Re: Advice needed on __del__

2005-05-10 Thread André Roberge
stasz wrote:
 On Mon, 09 May 2005 22:49:06 -0300, André Roberge wrote:
 
 
Scott David Daniels wrote:

André Roberge wrote:


...  Each time I refresh the screen, I could
force that call, then check to see if Evil has been
destroyed by Python, which would give me the information
I need to destroy Evil_twin behind the scene myself -
which is what I am really after.
 
 Wouldn't it be better if the robots draw themselfs onto the canvas?
 That way you don't have to worry about deletion, a robot would only
 draw itself when he's has to.
 So perhaps it's an idea to delegate the drawing of stuff to the objects
 themself rather then in the 'visibleworld' class.
 

I thought about doing something like this... but gave it up.  The other 
way works well.

 
However (famous last words follow...) I feel it's not going to bite me
this time.  The main reason is that, when Evil is gone, before the
screen gets updated, lots of drawing calls and wxYield() calls are made,
so that __del__ has lots of time to get called.
 
 Your relying on something that *will* bite you, the question is rather
 *when* will it bite you :-)
 
Well, since
1) this is used only as a demonstration of scoping in Python, in one example
2) other examples do not involve the temporary creation of robots (i.e. 
they would never go out of scope)
3) it works so far...

I'll wait for someone telling me that demonstration doen't work for 
them. ;-)

 IMHO, the approach to rely on Python to do your dirty work and then
 checks if it's done seems a bit VB to me :-)
 
Ouch!  You don't mince words, do you?  Trying to get the QOTW? ;-)
 
 Stas Zytkiewicz
 
Unless I am sorely mistaken, I believe *you* have a full copy of the 
source code.  Why don't you try and see if your approach can be 
incorporated in the program? I'll buy you a beer if you make it work! ;-)

André

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


Re: Advice needed on __del__

2005-05-10 Thread André Roberge
Fredrik Lundh wrote:
 André Roberge wrote:
If I need to have the user call Evil.destroy() as Evil
is getting out of scope, it would miss the whole point
of teaching about the natural way scope and namespace
work.
 
 
 well, if you insist on using finalizers to keep track of what's in the current
 scope, I'd say that you are missing the point about how scopes and name-
 spaces work...
 
I don't think I do, but I think I didn't explain things well enough.
1. The user creates an object, within a local scope.  When he does 
that, I update a list of images in a global scope.  I then use that 
list of images to decide what to display on the screen.

The user is unaware of the connection I am making behind the scene.
 
[Snip]
 
 the correct solution is to inspect the current namespace every time you
 refresh the screen, and make sure the screen contents matches what's
 in the namespace.

To do that, I would need to put a link, in the global scope between 
the object created by the user, and the user. However, in doing so
(if I am not missing the point about how scopes and namespaces work...)
the object created by the user would always have a reference in the 
global scope ... and thus would never disappear from the namespace.

I understand that, if the link is a weak reference, then it might 
disappear when the object goes out of scope.  Is that what you mean I 
should do?

André
 /F 


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


Advice needed on __del__

2005-05-09 Thread André Roberge
Suppose I have two classes: 'Jekyll' and 'Hyde' that are
related in a particular way.

When I create a Jekyll object, a Hyde one gets automatically
created (and displayed on a screen).

 drum roll to announce Python script ===

Nice = Jekyll()# Nice_twin, a Hyde object, gets created.

Nice.doStuff() # Nice_twin is doing his own stuff

def subplot():
 Evil = Jekyll()   # Evil_twin gets created and displayed
 Evil.doStuff()# Evil_twin does stuff on the screen

subplot()

#Evil.doMoreStuff()  would raise an error, as it no longer exists
   # in this namespace; however, Evil_twin still displayed

Nice.doMoreStuff()   # continues to work.

==End of script, and ask question===
Evil_twin is still displayed on the screen at the end.
I would like for Evil_twin to disappear.
(I would like for this Hyde, to hide  ok, bad pun!)

This morning I had the following thought:
I can, when I create a Jekyll object, update
an outside_list.
If, somehow, I could update that list when
a Jekyll object disappears
(perhaps by using __del__, which I have never touched)
that would solve my problem.

I could check outside_list each time I update
the screen display, and remove Evil_twin when
Evil no longer exists.

Any suggestions?

I've already tried lots of things, but nothing works properly.
Every attempt I make involves quite a bit of coding, as
the real-life situation is a bit more complicated than
what I explain here.
So, before I try again, I thought I would ask the
Collective Wisdom on this list.

--
André

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


Re: Advice needed on __del__

2005-05-09 Thread André Roberge
Fredrik Lundh wrote:
 André Roberge wrote:
 
 
 
This morning I had the following thought:
I can, when I create a Jekyll object, update
an outside_list.
If, somehow, I could update that list when
a Jekyll object disappears
(perhaps by using __del__, which I have never touched)
 
 
 Python makes no guarantees whatsover about when and how to
 run __del__, so relying on it to remove user-visible resources is a
 rather bad idea

[See idea at the very end about this.]

 
Any suggestions?
 
 why wouldn't
 
 def subplot():
  Evil = Jekyll()   # Evil_twin gets created and displayed
  Evil.doStuff()# Evil_twin does stuff on the screen
  Evil.destroy()
 
 work for you?
 
 /F
Unfortunately, it wouldn't.
It's difficult to explain in a few words why, but I'll try anyway!

I'm developping a program (rur-ple) which is designed to
help learning Python.  In an earlier version (that didn't provide
support for deriving classes from existing one) I had it working so that 
when Evil would get out of scope, Evil_twin would disappear
from the screen.  This came as an initial surprise for me,
but a pleasant one.  Better than having an example like:

def boring():
x = 1
print x
boring()
print x  # gives an error message.

When I added the possibility of deriving classes, I had to
change the connection between Jekyll and Hyde ... and, so
far, lost that feature.

If I need to have the user call Evil.destroy() as Evil
is getting out of scope, it would miss the whole point
of teaching about the natural way scope and namespace
work.

I guess I'll have to try and learn how to use __del__,
and see if it can solve my problem.

===
A thought occurred to me, regarding when __del__
is called.  Can I force Python, through some function call,
to perform this.  Each time I refresh the screen, I could
force that call, then check to see if Evil has been
destroyed by Python, which would give me the information
I need to destroy Evil_twin behind the scene myself -
which is what I am really after.


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


Re: Advice needed on __del__

2005-05-09 Thread André Roberge
Scott David Daniels wrote:
 André Roberge wrote:
 
...  Each time I refresh the screen, I could
force that call, then check to see if Evil has been
destroyed by Python, which would give me the information
I need to destroy Evil_twin behind the scene myself -
which is what I am really after.
 
 
 What might work is to keep a weakref to Evil in Evil_twin.
 Upon refresh, you could check if the weakref has gone stale.
 Is that good enough?

It might be I guess ... but I don't know how to keep a weakref.
(Whips out Python in a Nutshell... yes, it's there :-)

Hmmm... The way my program is structured, Evil_twin gets created
immediately *after* Evil is created.  If it were the reverse, I think I 
could do it, but I am really not sure in this case.

However, I did try it with __del__ as I described, and, after a bit of 
fiddling got it to work perfectly.  I understand about the possible 
platform dependence issue.  However (famous last words follow...) I feel 
it's not going to bite me this time.  The main reason is that, when Evil 
is gone, before the screen gets updated, lots of drawing calls and 
wxYield() calls are made, so that __del__ has lots of time to get called.

===
For the curious, here's how I do it:
(Sorry, no Jekyll and Hyde here :-(

class UsedRobot(object):
   def __init__(self, ..., parent=Visible_world()):
  # Visible_world is a Singleton - see Python cookbook
  true_robot = parent.addOneRobot(...)# ---Evil_twin created
  self.robot = parent.robot_dict[true_robot.name]
  self.name = true_robot.name
  self.program = rur_program() # Singleton
  self.parent = parent
  self.parent.object_dict[self.name] = True  # --- new trick
  self.program.wait_update_refresh(self.robot, self.name)
   def __del__(self):
  self.parent.object_dict[self.name] = False

 class Visible_world() stuff below:
# lots os stuff omitted
 def DoDrawing(self):

# start doing lots of background stuff
# enough time to call __del__ ?

 self.world_image = wxEmptyBitmap(self.maxWidth, self.maxHeight)
 dc = wxMemoryDC()
 dc.SelectObject(self.world_image)
 dc.Clear()
 dc.BeginDrawing()
 self.DrawBackground(dc)
 self.DrawWalls(dc)
 self.DrawBeepers(dc)

 # ok, were we go with the important stuff for this post

 list_to_ignore = []
 for item in self.object_dict:  # see new trick above
 if not self.object_dict[item]:
 list_to_ignore.append(item)

 for name in self.robot_dict:
 if name not in list_to_ignore:
 self.DrawRobot(dc, name)
 dc.EndDrawing()
 self.updateImage = True

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


[ANN] new version of rur-ple (0.8.5)

2005-05-09 Thread André Roberge
Version 0.8.5 of rur-ple has been released.
The web site has completely changed; it includes over 35 pages.
http://rur-ple.sourceforge.net/

--
Learning to program computer should be fun, for adults and children 
alike. RUR-PLE is an environment designed to help you learn computer 
programming using the language Python. To use RUR-PLE, you need 
wxPython. You can learn more about RUR-PLE or you can go to the download 
page.

===
Apprendre à programmer devrait être amusant,
que l'on soit un adulte ou un enfant.

RUR-PLE est un environnement conçu pour vous aider à apprendre la 
programmation informatique avec le langage Python. Pour utiliser 
RUR-PLE, vous aurez besoin de wxPython. Vous pouvez en apprendre 
davantage au sujet de RUR-PLE ou vous pouvez aller à la page de 
téléchargement.

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


Re: Python features

2005-05-08 Thread André Roberge
[EMAIL PROTECTED] wrote:
 To which degree python language support features of following langauage
 categories? 
 
 Imperative, Object Oriented, Scriptig or Functional.
 

Sounds like a homework assignment to me  How about your do some 
research on your own, like the following:

google for python and functional; first link:
http://www-106.ibm.com/developerworks/linux/library/l-prog.html

google for python and imperative; 10th link:
http://www.everything2.com/index.pl?node=programming%20languages

Quoting from that link:
There are three main types of programming languages.

 * Imperative
 * Functional
 * Declarative

Imperative programming languages are the most commonly used languages. 
Examples of this type of language are C, C++, Ada, Fortran, Algol, Java, 
Python, Perl, and so on. Programming in an imperative language is 
generally easier than in functional or declarative languages since it 
involves a more linear process of solving problems. These languages have 
been evolving more and more toward the object-oriented paradigm.


etc.

Python is Object Oriented and is described most often as scripting 
language.  (search left as an exercise).

Time required to find these links: about two minutes!

Total time spent by the thousands of people that will read your message 
and this reply: say 1 minute * 1200 person / 60 (minutes/hour) = 20 
person-hour

André

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


Question about Pycon 2005 (Python Visual Sandbox)

2005-05-08 Thread André Roberge
Hi all,

I was wondering if the session:
  Intuition and Python Programming - the Python Visual Sandbox
did occur, of if it was canceled.  To this day, there is
still no sign of a corresponding paper on
http://www.python.org/pycon/2005/papers/
nor did I see any report about it.

Just curious,

André

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


ANN: RUR-PLE version 0.8

2005-05-06 Thread André Roberge
RUR-PLE is a Python Learning Environment.

It contains four main elements:
1. Lessons viewable within an incorporated browser. Version 0.8 includes 
25 lessons introducing Python.
2. A robot world with a robot that can accomplish tasks through Python 
programs.
3. A built-in interpreter which can be used to play with Python
4. A built-in file editor which can be used for futher Python explorations.

Version 0.8 includes a bilingual (English or French) interface.
Only English lessons are included.

RUR-PLE requires wxPython.  It can be found on sourceforge:

https://sourceforge.net/project/showfiles.php?group_id=125834

RUR-PLE has been inspired from GvR (Guido van Robot), also available on 
sourceforge.  RUR-PLE can be though of as GvR++.

The relatively large size of the download is due to the many graphical 
elements included with the lessons.

André Roberge

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


Re: New Python regex Doc

2005-05-05 Thread André Roberge
alex23 wrote:
 Xah Lee wrote:
 
99% of programers really don't need to give a flying fuck about the
history of a language.
 
 
 Ironically, I'm pretty confident that the same percentage of readers on
 this group feel _exactly the same way_ about your 'improvements'.
 
 -alex23
 
I take it that when you use the expression same percentage, you must 
mean within a percent or so!
André

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


Better way to do parsing?

2005-05-04 Thread André Roberge
Hi all,

I posted the following on the python tutor list 3 days ago ... and 
haven't heard a peep from anyone - which is highly unusual on that list.

[Apologies for the slightly longer post due to code
with tests cases included at the end .]

I have created a severely restricted environment within with
users can learn the basics of programming in Python.

[note: eval, exec, chr, input, raw_input are not allowed.]

Within that environment, I want to have the user test the five
valid forms that an import statement can have, by attempting to
import a fake module whose name is useful.  Other import
statements are disallowed.

1. import useful
2. from useful import *
3. from useful import valid_function1 [, valid_function2, ...]
4. from useful import valid_function as better_named_function
5. import useful as not_so_useful_after_all

As far as I can tell, the following works, but it looks rather
clunky to me.  My *very limited* experience with the
re module may have something to do with this.

Any suggestion would be most welcome.

André

===Here's the code formatted (fingers crossed) to work if cut and
pasted from email =


# test_import.py

import re

isolate_words = re.compile(r'\W+')  # used with .split()

# pre-compiled some regular expression with allowable use of import

imp_use = re.compile('^import useful', re.MULTILINE)
imp_use_as = re.compile('^import useful as (\w+)', re.MULTILINE)
from_use_imp_star = re.compile('^from useful import \*', re.MULTILINE)
from_use_imp_names = re.compile(
 ^from useful import (\w+(,[ ]*\w+)*),
  re.MULTILINE)
from_use_imp_as = re.compile(
^from useful import (\w+) as (\w+),
re.MULTILINE)


# In the following, r is used so that \b identifies a word boundary,
# and is not interpreted as backslash by Python.

import_misuse = re.compile(r'\bimport\b', re.MULTILINE)

# use to commenting out the valid import statements after processed.

comment_from = re.compile('^from ', re.MULTILINE)
comment_import = re.compile('^import ', re.MULTILINE)

# Create a fake module which can be imported

right = turn_right():\n+\
  turn_left()\n+\
  turn_left()\n+\
  turn_left()\n\n

around = turn_around():\n+\
  turn_left()\n+\
  turn_left()\n\n

up_east = climb_up_east():\n+\
  turn_left()\n+\
  move()\n+\
  turn_left()\n+\
  turn_left()\n+\
  turn_left()\n\n

up_west = climb_up_west():\n+\
  turn_left()\n+\
  turn_left()\n+\
  turn_left()\n+\
  move()\n+\
  turn_left()\n\n

down_west =  climb_down_west():\n+\
  turn_left()\n+\
  move()\n+\
  turn_left()\n+\
  turn_left()\n+\
  turn_left()\n\n

down_east =  climb_down_east():\n+\
  turn_left()\n+\
  turn_left()\n+\
  turn_left()\n+\
  move()\n+\
  turn_left()\n\n

commands = {'turn_right': right, 'turn_around': around,
  'climb_up_east': up_east, 'climb_up_west': up_west,
  'climb_down_east': down_east, 'climb_down_west': down_west}

#=== end of info on fake module

# The following fonctions are helper functions to
# process the import statement:
# they add the appropriate imported commands
# before the import statement,
# before commenting out (by pre-pending #) the import statement line

def import_useful():
  added_text = ''
  for instruction in commands:
  new = def  + 'useful.' + commands[instruction]
  added_text += new
  return added_text, True

def from_useful_import_star():
  added_text = ''
  for instruction in commands:
  new = def  + commands[instruction]
  added_text += new
  return added_text, True

def import_useful_as(syn):
  added_text = ''
  for instruction in commands:
  new = def  + syn + '.' + commands[instruction]
  added_text += new
  return added_text, True

def from_useful_import_names(names):
  added_text = ''
  for instruction in isolate_words.split(names):
  try:
  new = def  + commands[instruction]
  except:
  print instruction,  not found in module useful
  added_text += new
  return added_text, True

def from_useful_import_as(name, syn):
  added_text = ''
  try:
  new = def  + commands[name].replace(name, syn)
  except:
  print name,  not found in module useful
  added_text += new
  return added_text, True

def process_no_import():
  added_text = ''
  return added_text, True

# the basic processing function

def process_file(file_text):
  if imp_use_as.search(file_text): # look for import useful as ...
  syn = imp_use_as.findall(file_text)
  

python and Tile Studio

2005-04-23 Thread André Roberge
Has anyone used Python with Tile Studio to create games?
http://tilestudio.sourceforge.net/
André
--
http://mail.python.org/mailman/listinfo/python-list


Using Ming on Windows

2005-04-23 Thread André Roberge
I tried to install Ming
(http://sourceforge.net/projects/ming/)
on Windows to use with Python *but*
I can't [/don't know how to] use make to install it.
Does anyone know where I could find a ready-made compiled
version for Windows to just put in my site-packages directory.
Any help would be appreciated.
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using Ming on Windows

2005-04-23 Thread André Roberge
Colin J. Williams wrote:
Jack Diederich wrote:
On Sat, Apr 23, 2005 at 05:13:29PM -0300, Andr? Roberge wrote:
I tried to install Ming
(http://sourceforge.net/projects/ming/)
on Windows to use with Python *but*
I can't [/don't know how to] use make to install it.

I installed MinGW on a Windows XP with no trouble.  One needs to install 
MSYS, as well as MinGW, since some modules (eg. make) are only available
in MSYS.

Currently, I am trying to build a package from source and have some 
unresolved problems.  Earlier I had tried to use the Borland 
commandline, without success.

Colin W.
MinGW is a minimalistic Gnu for Windows.
Ming is a Flash/swf library.
A.
--
http://mail.python.org/mailman/listinfo/python-list


Troll? was: Re: goto statement

2005-04-20 Thread André Roberge
Maxim Kasimov wrote:
by the way, goto statement will be useful for writing more powerful 
obfuscators

Let me get that clear: you want a goto to help with debugging.
And you want to obfuscate your code even more?
!?
Perhaps you need to write in Perl, or some other similar language.
Writing in Python is for those that seek clarity (not obfuscation) and 
less bugs.   Which is why a goto statement should definitely never be 
part of Python!

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


Re: Using something other than ';' to separate statements

2005-03-30 Thread André Roberge
Jaime Wyant wrote:
[snip]
After goofing around with this idea, I've realized you can't be very
expressive with a bunch of python statements strung together.  My
biggest problem is that I can't figure out (i don't think you can),
how to do conditionals that are strung together:
# This won't work
if a  5: print a  5;else print Doh
I've decided to just call a function from the semicolon delimited
record, using the return value in my `C' app...
The following might work based on the context:
code = '''if a  5: \nprint a  5\nelse:\nprint Doh\n'''
or, formatted differently
code = '''
if a  5:
print a  5
else:
print Doh
'''
Then, you could do
exec(code)
Yeah, I tried to make it work, but it just won't.  At least not in a
satisfactory way.
Thanks!
jw
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass parameter when importing a module?

2005-03-20 Thread André Roberge
Bo Peng wrote:
Dear list,
What I would like to do is something like:
In myModule.py ( a wrapper module for different versions of the module),
  if lib == 'standard':
from myModule_std import *
  elsif lib == 'optimized'
from myModule_op import *
but I do not know how to pass variable lib to myModule.py to achieve the 
following effect:

How about this:
#= constants.py
lib = whatever   #assigned somewhere else
#= myModule.py
from constants import lib
etc.
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to turn a variable name into a string?

2005-03-11 Thread André Roberge
[EMAIL PROTECTED] wrote:
lots of good answers there, and quickly, too!
I can see that I need to explain a bit further what I'm up to.
I have a number of variables (environmental variables, actually), most
of which will have a value. But some may not have been found by
os.environ.get(), so I set those to None. Now, if any of them are None,
the app cannot proceed, so I want to test for this and warn the user.
I could do something like this (actually, there are more than 3 vars):
a = c:\\programs
b = d:\\data
c = None  (result of an assignment after the os.environ.get() returned
a KeyError).
if (a is None) or (b is None) or (c is None):
#do something here
print 'you are missing some env vars'
But, that seemed clumsy to me, so I wanted to do something more
pythonic, hence my previous post.   So, any suggestions?
Why not build a list of problematic variables as you assign them?
In this case, you would have
problem_list = [c]
if problem_list != []:
# do something here
etc.
André
--
http://mail.python.org/mailman/listinfo/python-list


Simple (newbie) regular expression question

2005-01-21 Thread André Roberge
Sorry for the simple question, but I find regular
expressions rather intimidating.  And I've never
needed them before ...
How would I go about to 'define' a regular expression that
would identify strings like
__alphanumerical__  as in __init__
(Just to spell things out, as I have seen underscores disappear
from messages before, that's  2 underscores immediately
followed by an alphanumerical string immediately followed
by 2 underscore; in other words, a python 'private' method).
Simple one-liner would be good.
One-liner with explanation would be better.
One-liner with explanation, and pointer to 'great tutorial'
(for future reference) would probably be ideal.
(I know, google is my friend for that last part. :-)
Andre
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple (newbie) regular expression question

2005-01-21 Thread André Roberge
John Machin wrote:
André Roberge wrote:
Sorry for the simple question, but I find regular
expressions rather intimidating.  And I've never
needed them before ...
How would I go about to 'define' a regular expression that
would identify strings like
__alphanumerical__  as in __init__
(Just to spell things out, as I have seen underscores disappear
from messages before, that's  2 underscores immediately
followed by an alphanumerical string immediately followed
by 2 underscore; in other words, a python 'private' method).
Simple one-liner would be good.
One-liner with explanation would be better.
One-liner with explanation, and pointer to 'great tutorial'
(for future reference) would probably be ideal.
(I know, google is my friend for that last part. :-)
Andre

Firstly, some corrections: (1) google is your friend for _all_ parts of
your question (2) Python has an initial P and doesn't have private
methods.
Read this:

pat1 = r'__[A-Za-z0-9_]*__'
pat2 = r'__\w*__'
import re
tests = ['x', '__', '', '_', '__!__', '__a__', '__Z__',
'__8__', '__xyzzy__', '__plugh']
[x for x in tests if re.search(pat1, x)]
['', '_', '__a__', '__Z__', '__8__', '__xyzzy__']
[x for x in tests if re.search(pat2, x)]
['', '_', '__a__', '__Z__', '__8__', '__xyzzy__']
I've interpreted your question as meaning valid Python identifier that
starts and ends with two [implicitly, or more] underscores.
In the two alternative patterns, the part in the middle says zero or
more instances of a character that can appear in the middle of a Python
identifier. The first pattern spells this out as capital letters,
small letters, digits, and underscore. The second pattern uses the \w
shorthand to give the same effect.
You should be able to follow that from the Python documentation.
Now, read this: http://www.amk.ca/python/howto/regex/
HTH,
John
Thanks for it all. It does help!
André
--
http://mail.python.org/mailman/listinfo/python-list