[Tutor] Module for browsing Windows?

2010-08-11 Thread Chorn, Guillaume
Hello,

I'm pretty new to Python programming and it is my first programming
language.  I made a script that uses data from two different .csv files
to make calculations and then spit the results out in a third .csv file.
However, the process of typing in the path to each of the two input
files and the output file (or even copying and pasting those paths) is
somewhat cumbersome from a UI perspective, and so I was wondering if
there is a Python module out there that allows you to browse to and
select files using a Windows-style interface.  Thanks!

Cheers,
Guillaume

Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates Direct contact information
for affiliates is available at 
http://www.merck.com/contact/contacts.html) that may be confidential,
proprietary copyrighted and/or legally privileged. It is intended solely
for the use of the individual or entity named on this message. If you are
not the intended recipient, and have received this message in error,
please notify us immediately by reply e-mail and then delete it from 
your system.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Indentation woes in elif statement

2010-08-11 Thread rara avis
Hi: I am trying to teach myself Python, and am stuck at the indentation with
the elif statement.
This is what I am trying to type:

x=3
if x==0:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Module for browsing Windows?

2010-08-11 Thread Tim Golden

On 11/08/2010 01:17, Chorn, Guillaume wrote:

Hello,

I'm pretty new to Python programming and it is my first programming
language.  I made a script that uses data from two different .csv files
to make calculations and then spit the results out in a third .csv file.
However, the process of typing in the path to each of the two input
files and the output file (or even copying and pasting those paths) is
somewhat cumbersome from a UI perspective, and so I was wondering if
there is a Python module out there that allows you to browse to and
select files using a Windows-style interface.  Thanks!


Take you pick of any of these:

  http://wiki.python.org/moin/GuiProgramming

Although (to select one) you might find that EasyGui
gets you going the quickest:

  http://easygui.sourceforge.net/

TJG
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] elif statement

2010-08-11 Thread Dipo Elegbede
You need to check the indentation properly.
In this case, elif has to be on the same indentation level with if. I
should think so.
If you're working straight from the python interactive console, like I
think you're doing, you need to manually do the indentation thing by
yourself.
First, I don't understand why you chose to set x to 3. That is not the
main thing though.
After x = 3, if you press enter, you'd get the python prompt
>>>
Then you type the next statement to have
>>> if x == 0:
What you get after this if statement is either a whitespace or ...,
from my phone, I get a ...
So you manually press the spacebar twice to get an indentation for the
first print statement.
As soon as you press enter again, you get the dots, just type in the
elif statements without pressing the spacebar. Then press enter to
move to a new line where the second print statement would be,and press
the spacebar twice again for indentation.
For the second elif statement, follow the procedure for the first elif
statement.
Go ahead and press enter twice to tell the console you are done, you
shouldn't get an error that way.
You should get something like below:

>>> x=3
>>> if x==0:
...   print x,'is zero'
... elif x//1==1:
...   print x,'is odd'
... elif x//1==0:
...   print x,'is even'
... else:
...   print'what is this'
...

The else statement is optional.
Hope it helps.

On 8/11/10, Adam Bark  wrote:
> On 11/08/10 02:34, Sudarshana Banerjee wrote:
>> Hi: I am trying to teach myself Python, and am stuck at the
>> indentation with the elif statement.
>>
>> This is what I am trying to type (as copied from the textbook):
>>
>> x=3
>> if x==0:
>> print "x is 0"
>> elif x&1 ==1:
>> print "x is a odd number"
>> elif x&1==0: -- Line 6
>> print "x is a even number"
>>
>> If I am combining the if and the print statement, then the elif
>> statement is in the next line, and all is well with the world. If
>> however, I write the print as a separate statement, I am getting a
>> syntax error after I press Enter after keying the first elif statement.
>>
>> >>> x=3
>> >>> if x==0:
>> print x
>> elif x==2:
>
> Here you have indented the elif statement but it should be at the same
> level as the if:
>  >>> x=3
>  >>> if x==0:
> ... print x
> ... elif x==2:
> ... print "something else"
> ...
>  >>>
>
>
>> SyntaxError: invalid syntax
>>
>> Again:
>> >>> x=3
>> >>> if x==2: print x
>> elif x&1 == 1: print 'x is odd'
>> >>> elif x&1 ==0: print 'x is even'
>> SyntaxError: invalid syntax
>
> I'm not sure what's going on here but the second elif is being
> interpreted separate to the rest of the if statement hence a SyntaxError:
>  >>> elif x&1 == 0: print "x is even"
>File "", line 1
>  elif x&1 == 0: print "x is even"
> ^
> SyntaxError: invalid syntax
>
> This works:
>  >>> if x==2: print x
> ... elif x&1 == 1: print 'x is odd'
> ... elif x&1 ==0: print 'x is even'
> ...
> x is odd
>
>
>>
>> If I am pressing two Enters, the code executes; so I have a elif
>> without a if, and again, a syntax error. What am I not doing right?
>>
>> Thank you.
>>
>> Sudarshana.
> HTH,
> Adam.
>
>
>


-- 
Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com
Mobile Banking Solutions | Transaction Processing | Enterprise
Application Development
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Richard D. Moores
I already own the PDF, as well as the paperback (1160 pages), but I
thought I'd let the list know. See the deal, good for just today, on
.

The 4th edition covers both Python 2.6 and 3.x.

So what does "today" mean? Beats me. O'Reilly's corporate headquarters
are in California, but there are also O'Reilly offices in
Massachusetts, Japan, China, Taiwan, Germany, and the UK.


Dick Moores
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Indentation woes in elif statement

2010-08-11 Thread Andre Engels
On Wed, Aug 11, 2010 at 3:11 AM, rara avis  wrote:
> Hi: I am trying to teach myself Python, and am stuck at the indentation with
> the elif statement.
> This is what I am trying to type:
>
> x=3
> if x==0:

What are you trying to accomplish? What result did you expect to get?
What result did you actually get?


-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making String

2010-08-11 Thread Joel Goldstick
On Tue, Aug 10, 2010 at 6:22 PM, Steven D'Aprano wrote:

> On Wed, 11 Aug 2010 06:09:28 am Joel Goldstick wrote:
> > The str part of str.join() is the string where the result is stored,
> > so you can start off with an empty string: ""
>
> I don't understand what you mean by that. I can only imagine you think
> that the string part is a fixed-width buffer that has the result stored
> into it, but of course that's ridiculous because that's nothing like
> what join does. Python strings are immutable so you can't store
> something inside an existing string, but even if they weren't, since
> the result of join is usually larger than the initial string you pass,
> what would be the point?
>
> The string part of str.join is the string which is used to join the rest
> of the arguments. This:
>
> "spam".join([ "a", "b", "c" ])
>
> is equivalent to:
>
> "a" + "spam" + "b" + "spam" + "c"
>
> except more efficient and faster. The result is stored in a new string.
>
>
>
> --
> Steven D'Aprano
>
> Steve, thanks for correcting me. The str being the 'glue' that joins
between each of the list members.
-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Indentation woes in elif statement

2010-08-11 Thread Joel Goldstick
On Tue, Aug 10, 2010 at 9:11 PM, rara avis  wrote:

> Hi: I am trying to teach myself Python, and am stuck at the indentation
> with the elif statement.
> This is what I am trying to type:
>
> x=3
> if x==0:
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
x = 3
if x == 0:
  print 'x == 0'
elif x != 0:
  print 'x != 0'

x != 0
-- 
The block of code under 'if x...' is indented.  Most people use 4 spaces.
You can use any number of spaces, but you need to be consistant
The elif indentation must match its matching if statement.  In this case
neither are indented
The block which executes under the elif is indented to the same level as
that under the original if


Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Benjamin Castillo
The site shows 39.99 for ebook.

Ben


--- On Wed, 8/11/10, Richard D. Moores  wrote:

> From: Richard D. Moores 
> Subject: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook form 
> for USD  9.99
> To: tutor@python.org
> Date: Wednesday, August 11, 2010, 1:45 AM
> I already own the PDF, as well as the
> paperback (1160 pages), but I
> thought I'd let the list know. See the deal, good for just
> today, on
> .
> 
> The 4th edition covers both Python 2.6 and 3.x.
> 
> So what does "today" mean? Beats me. O'Reilly's corporate
> headquarters
> are in California, but there are also O'Reilly offices in
> Massachusetts, Japan, China, Taiwan, Germany, and the UK.
> 
> 
> Dick Moores
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 


  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Felix Santiago

On Aug 11, 2010, at 9:30 AM, Benjamin Castillo wrote:


The site shows 39.99 for ebook.

Ben


--- On Wed, 8/11/10, Richard D. Moores  wrote:


From: Richard D. Moores 
Subject: [Tutor] O'Reilly is offering Learning Python (4th ed.),  
eBook form for USD  9.99

To: tutor@python.org
Date: Wednesday, August 11, 2010, 1:45 AM
I already own the PDF, as well as the
paperback (1160 pages), but I
thought I'd let the list know. See the deal, good for just
today, on
.

The 4th edition covers both Python 2.6 and 3.x.

So what does "today" mean? Beats me. O'Reilly's corporate
headquarters
are in California, but there are also O'Reilly offices in
Massachusetts, Japan, China, Taiwan, Germany, and the UK.


Dick Moores
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



If you go to http://oreilly.com/store/ddbst.html you can see the  
discounted price.


--Felix


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Scripting Blender

2010-08-11 Thread aug dawg
Are there any Python modules to script Blender? For example, placing
predefined objects into a new Blender project to create a 3D model.

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Robert
Rather depressing to see what's generally considered "Bible on Python"
among those other boring, nondescript books.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [SPAM]Re: O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Todd Nannie
If you click on the ONE DAY DEAL on the front page it still list the Python
book and several others.
I just bought the python book for 9.99

Todd

-Original Message-
From: tutor-bounces+tnannie=strdetail@python.org
[mailto:tutor-bounces+tnannie=strdetail@python.org] On Behalf Of
Benjamin Castillo
Sent: Wednesday, August 11, 2010 8:30 AM
To: tutor@python.org; Richard D. Moores
Subject: [SPAM]Re: [Tutor] O'Reilly is offering Learning Python (4th
ed.),eBook form for USD 9.99

The site shows 39.99 for ebook.

Ben


--- On Wed, 8/11/10, Richard D. Moores  wrote:

> From: Richard D. Moores 
> Subject: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook
form for USD  9.99
> To: tutor@python.org
> Date: Wednesday, August 11, 2010, 1:45 AM
> I already own the PDF, as well as the
> paperback (1160 pages), but I
> thought I'd let the list know. See the deal, good for just
> today, on
> .
> 
> The 4th edition covers both Python 2.6 and 3.x.
> 
> So what does "today" mean? Beats me. O'Reilly's corporate
> headquarters
> are in California, but there are also O'Reilly offices in
> Massachusetts, Japan, China, Taiwan, Germany, and the UK.
> 
> 
> Dick Moores
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 


  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.851 / Virus Database: 271.1.1/3060 - Release Date: 08/11/10
01:34:00

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scripting Blender

2010-08-11 Thread Corey Richardson
Yes. It's called the Python API, it comes with Blender ;) bpy and 
Blender are the top modules. There are submodules for everything. The 
reference is here: 
http://www.blender.org/documentation/249PythonDoc/index.html


HTH,
~Corey Richardson

aug dawg wrote:
Are there any Python modules to script Blender? For example, placing 
predefined objects into a new Blender project to create a 3D model.


Thanks!



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Module for browsing Windows?

2010-08-11 Thread Wayne Werner
On Tue, Aug 10, 2010 at 7:17 PM, Chorn, Guillaume  wrote:

>  Hello,
>
> I'm pretty new to Python programming and it is my first programming
> language.  I made a script that uses data from two different .csv files to
> make calculations and then spit the results out in a third .csv file.
> However, the process of typing in the path to each of the two input files
> and the output file (or even copying and pasting those paths) is somewhat
> cumbersome from a UI perspective, and so I was wondering if there is a
> Python module out there that allows you to browse to and select files using
> a Windows-style interface.  Thanks!
>
Tkinter is pretty easy:

import Tkinter as tk
import tkFileDialog as fd

root = tk.Tk()
root.widthdraw()

csv1 =  fd.askopenfilename()
csv2 = fd.askopenfilename()

# Do the rest of your stuff here.

HTH!
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] import errors

2010-08-11 Thread Pete
Hi,

A common line I've seen in Python code I come across is:

#!/usr/bin/python
import os
import sys
import errors

I was wondering about the line that says, "import errors". I understand what 
it's for, but what I don't get is how Python knows which 'errors.py' to import.

On my laptop:

macbook:bin han$ locate errors.py | grep -E 'py$'
/Library/Frameworks/Mono.framework/Versions/2.4.2.1/lib/IPCE/Lib/_codecs_errors.py
/Library/Frameworks/Mono.framework/Versions/2.4.2.1/lib/IPCE/Lib/fepy/codecs_errors.py
/Library/Python/2.6/site-packages/Skype4Py/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/distutils/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/macerrors.py
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/email/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/macerrors.py
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/email/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/macerrors.py

... so there seem to be more than one 'errors.py' - one for the email module, 
one for Skype4Py, etc.

How does the interpreter know which one to import?

Thanks for all your time, btw - I'm learning a lot lurking on this list and 
greatly appreciate all the people offering help and advice.

cheers,

Pete
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [SPAM]Re: O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread David Hutto
I thought the open source mentality of python was it own 'perpetual
bible'. A building of disciples so to speak.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import errors

2010-08-11 Thread Emile van Sebille

On 8/11/2010 8:48 AM Pete said...

Hi,

A common line I've seen in Python code I come across is:

#!/usr/bin/python
import os
import sys
import errors



... so there seem to be more than one 'errors.py' - one for the email module, 
one for Skype4Py, etc.

How does the interpreter know which one to import?


Importing looks in directories in sequence as held in sys.path

Python 2.4.3 (#1, Sep  3 2009, 15:37:12)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for ii in sys.path: ii
...
''
'/usr/lib/python24.zip'
'/usr/lib/python2.4'
'/usr/lib/python2.4/plat-linux2'
'/usr/lib/python2.4/lib-tk'
'/usr/lib/python2.4/lib-dynload'
'/usr/lib/python2.4/site-packages'
'/usr/lib/python2.4/site-packages/Numeric'
'/usr/lib/python2.4/site-packages/gtk-2.0'


HTH,

Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import errors

2010-08-11 Thread Joel Goldstick
On Wed, Aug 11, 2010 at 12:06 PM, Emile van Sebille  wrote:

> On 8/11/2010 8:48 AM Pete said...
>
>  Hi,
>>
>> A common line I've seen in Python code I come across is:
>>
>> #!/usr/bin/python
>> import os
>> import sys
>> import errors
>>
> 
>
>  ... so there seem to be more than one 'errors.py' - one for the email
>> module, one for Skype4Py, etc.
>>
>> How does the interpreter know which one to import?
>>
>
> Importing looks in directories in sequence as held in sys.path
>
> Python 2.4.3 (#1, Sep  3 2009, 15:37:12)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> for ii in sys.path: ii
> ...
> ''
> '/usr/lib/python24.zip'
> '/usr/lib/python2.4'
> '/usr/lib/python2.4/plat-linux2'
> '/usr/lib/python2.4/lib-tk'
> '/usr/lib/python2.4/lib-dynload'
> '/usr/lib/python2.4/site-packages'
> '/usr/lib/python2.4/site-packages/Numeric'
> '/usr/lib/python2.4/site-packages/gtk-2.0'
>
>
> HTH,
>
> Emile
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


To import the errors module which handles email do this:
import email.errors

There is no top level errors module, but several 'packages' contain error
modules.  A package is a directory which can contain several modules in its
subdirectories
-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] elif statement

2010-08-11 Thread Karim


Hello,

This code works for me:

>>> x=3
>>> if x==0:
... print "x is 0"
... elif x&1 ==1:
... print "x is a odd number"
... elif x&1==0:
... print "x is a even number"
...
x is a odd number

So I think you copied by error the string '-- Line 6' in you example 
given that has nothing to

do with the rest of the code.

Regards
Karim


On 08/11/2010 03:34 AM, Sudarshana Banerjee wrote:

print "x is a even number"


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scripting Blender

2010-08-11 Thread Mark Young
2010/8/11 Corey Richardson 

> Yes. It's called the Python API, it comes with Blender ;) bpy and Blender
> are the top modules. There are submodules for everything. The reference is
> here: http://www.blender.org/documentation/249PythonDoc/index.html
>
> HTH,
> ~Corey Richardson
>
> aug dawg wrote:
>
>> Are there any Python modules to script Blender? For example, placing
>> predefined objects into a new Blender project to create a 3D model.
>>
>> Thanks!
>>
>> 
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>  ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


Questions about coding in blender will likely be answered better at
http://blenderartists.org/forum/ .
Also, the previously mentioned docs are outdated, documenting blender 2.4x,
which is supposed to become obsolete sometime soon. Blender 2.5x is pretty
different from 2.4x, so those docs won't help too much.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Lost in the control flow

2010-08-11 Thread Eduardo Vieira
On Tue, Aug 10, 2010 at 1:56 PM, Adam Bark  wrote:

>
> The problem is you don't call make_dict unless there's a "FUEL SURCHARGE" or
> multiple pins. Also you don't add the first pin to mydict["tracking"] unless
> there's a "FUEL SURCHARGE".
>
> HTH,
> Adam.
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Hi, I made these changes, got rid of the functions, and changed some logic:
here is the link: http://pastebin.com/F19vKUjr

Now mydict will be changing, of course with every loop, as the output below:
{'company': 'CITY SIGNS', 'tracking': ['600775301143'], 'id': '1'}
{'city': 'MEDICINE HAT', 'company': 'CITY SIGNS', 'tracking':
['600775301143'], 'id': '1', 'prov': 'AB'}
{'city': 'MEDICINE HAT', 'company': 'TRIMLINE', 'tracking':
['600775301150'], 'id': '2', 'prov': 'AB'}
{'city': 'ROCKY MOUNTAIN HOUSE', 'company': 'TRIMLINE', 'tracking':
['600775301150'], 'id': '2', 'prov': 'AB'}
{'city': 'ROCKY MOUNTAIN HOUSE', 'company': 'TS SIGNS PRINTING &
PROMO', 'tracking': ['600775301168'], 'id': '3', 'prov': 'AB'}
{'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
'tracking': ['600775301168'], 'id': '3', 'prov': 'AB'}
{'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
'tracking': ['600775301168', '600775301168'], 'id': '3', 'prov': 'AB'}
{'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
'tracking': ['600775301168', '600775301168', '600775301176'], 'id':
'3', 'prov': 'AB'}
{'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
'tracking': ['600775301168', '600775301168', '600775301176',
'600775301184'], 'id': '3', 'prov': 'AB'}
{'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
'tracking': ['600775301168', '600775301168', '600775301176',
'600775301184', '600775301192'], 'id': '3', 'prov': 'AB'}
{'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
'tracking': ['600775301168', '600775301168', '600775301176',
'600775301184', '600775301192', '600775301200'], 'id': '3', 'prov':
'AB'}
so I appended everything to a bigdata list and used it to update the
dictionary data_dict

I can't understand why I get only one value:
{'18': {'city': 'ESTEVAN',
'company': 'BRAKE & DRIVE SYSTEMS',
'id': '18',
'prov': 'SK',
'tracking': ['600775301515', '600775301515', '600775301523']}}

Regards,

Eduardo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Executing Python from TCL

2010-08-11 Thread Karim


Hello Tutors,

I want to know if there are modules or whatever to execute
python functions inside TCL.
These functions should returns python lists as TCL lists and
Python dictionary as TCL Hash tables.

Existing (opensource) tools, packages are welcome!
I want to avoid to do it myself (anyway I don't have
any idea how to do it :o) )

In fact, I develop parser for xml using xml.etree.ElementTree
and another team which develop in TCL need to access it via
an API I should do. Great Challenge.

Regards
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need help understanding output...

2010-08-11 Thread Laurens Vets

Hello list,

I'm learning Python and I'm currently facing an issue with a small 
script I'm writing.


I need to generate a list of 30 numbers randomly chosen from 1, 2, 3, 4, 
5 & 6. However, I cannot have more than 2 numbers which are the same 
next to each other. I came up with the following (Please ignore the fact 
that I'm trying to avoid an IndexError in a stupid way :)):


import random
reeks = []
while len(reeks) <= 1:
  number = random.randrange(1, 7, 1)
  reeks.append(number)

while len(reeks) <= 29:
  nummer = random.randrange(1, 7, 1)
  if nummer != reeks[-1] and nummer != reeks[-2]:
reeks.append(nummer)
print reeks

So far so good (I think). From what I can see from the output, I get 30 
numbers, without more than 2 being the same next to each other.


However, I wanted to look deeper in the above script and I created the 
following:


import random
iteraties = 5
cijferreeks = 6
aantal_cijfers = iteraties * cijferreeks
reeks = []
while len(reeks) <= 1:
  nummer = random.randrange(1, cijferreeks + 1, 1)
  print 'Nummer: ', nummer
  print 'Reeks: ', reeks
  reeks.append(nummer)
  print '\n'

while len(reeks) <= aantal_cijfers:
  nummer = random.randrange(1, cijferreeks + 1, 1)
  print 'Nummer: ',  nummer
  print 'Voorlaatste vd reeks (-2): ', reeks[-2]
  print 'Laatste vd reeks (-1): ', reeks[-1]
  print 'Reeks: ', reeks
  if nummer != reeks[-1] and nummer != reeks[-2]:
reeks.append(nummer)
  else:
print 'Nummer: ', nummer, 'is gelijk aan vorige 2 nummers: ', 
reeks[-1], '&', reeks[-2], '!'

  print '\n'
print reeks

When I run that, I can see there's something wrong with my if statement, 
it triggers the else condition even when the 2 previous numbers in my 
list are not the same...  I'm not sure what is happening here...




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help understanding output...

2010-08-11 Thread Evert Rol
> I'm learning Python and I'm currently facing an issue with a small script I'm 
> writing.
> 
> I need to generate a list of 30 numbers randomly chosen from 1, 2, 3, 4, 5 & 
> 6. However, I cannot have more than 2 numbers which are the same next to each 
> other. I came up with the following (Please ignore the fact that I'm trying 
> to avoid an IndexError in a stupid way :)):

Ok, we'll ignore that (for now ;-D).



> However, I wanted to look deeper in the above script and I created the 
> following:
> 
> import random
> iteraties = 5
> cijferreeks = 6
> aantal_cijfers = iteraties * cijferreeks
> reeks = []
> while len(reeks) <= 1:
>  nummer = random.randrange(1, cijferreeks + 1, 1)
>  print 'Nummer: ', nummer
>  print 'Reeks: ', reeks
>  reeks.append(nummer)
>  print '\n'
> 
> while len(reeks) <= aantal_cijfers:
>  nummer = random.randrange(1, cijferreeks + 1, 1)
>  print 'Nummer: ',  nummer
>  print 'Voorlaatste vd reeks (-2): ', reeks[-2]
>  print 'Laatste vd reeks (-1): ', reeks[-1]
>  print 'Reeks: ', reeks
>  if nummer != reeks[-1] and nummer != reeks[-2]:
>reeks.append(nummer)
>  else:
>print 'Nummer: ', nummer, 'is gelijk aan vorige 2 nummers: ', reeks[-1], 
> '&', reeks[-2], '!'
>  print '\n'
> print reeks
> 
> When I run that, I can see there's something wrong with my if statement, it 
> triggers the else condition even when the 2 previous numbers in my list are 
> not the same...  I'm not sure what is happening here...

For an 'and' in a condition, only one part of the condition needs to be False 
for the condition to fail and skip to the else clause.
Eg, with nummer=1, reeks[-1]=1 and reeks[-2]=2, it finds that 1 != 1 is False, 
and immediately skips to the else part. Ditto if nummer=2 and same reeks: first 
part is then True, but second part False, hence skip to else.
I leave it up to you to find the correct if statement. (Hint: it's phrased in 
your third sentence at the top.)


Btw, tip: always code in English. It just makes things easier for yourself when 
using other code examples, for example. But I just find generally good practice.

Cheers,

  Evert

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help understanding output...

2010-08-11 Thread Emile van Sebille

On 8/11/2010 2:04 PM Laurens Vets said...

Hello list,

I'm learning Python and I'm currently facing an issue with a small
script I'm writing.

I need to generate a list of 30 numbers randomly chosen from 1, 2, 3, 4,
5 & 6. However, I cannot have more than 2 numbers which are the same
next to each other. I came up with the following (Please ignore the fact
that I'm trying to avoid an IndexError in a stupid way :)):

import random
reeks = []
while len(reeks) <= 1:
number = random.randrange(1, 7, 1)
reeks.append(number)

while len(reeks) <= 29:
nummer = random.randrange(1, 7, 1)
if nummer != reeks[-1] and nummer != reeks[-2]:
reeks.append(nummer)
print reeks

So far so good (I think). From what I can see from the output, I get 30
numbers, without more than 2 being the same next to each other.

However, I wanted to look deeper in the above script and I created the
following:

import random
iteraties = 5
cijferreeks = 6
aantal_cijfers = iteraties * cijferreeks
reeks = []
while len(reeks) <= 1:
nummer = random.randrange(1, cijferreeks + 1, 1)
print 'Nummer: ', nummer
print 'Reeks: ', reeks
reeks.append(nummer)
print '\n'

while len(reeks) <= aantal_cijfers:
nummer = random.randrange(1, cijferreeks + 1, 1)
print 'Nummer: ', nummer
print 'Voorlaatste vd reeks (-2): ', reeks[-2]
print 'Laatste vd reeks (-1): ', reeks[-1]
print 'Reeks: ', reeks
if nummer != reeks[-1] and nummer != reeks[-2]:


You're testing here if nummer is niet gelijk van _both_ vorige twee 
nummers, maar je wil testen als het niet gelijk is van _either_ nummer:


if nummer != reeks[-1] _or_ nummer != reeks[-2]:

For then it is true that

   nummer == reeks[-1] and nummer == reeks[-2]

You should review/create or/and truth tables to determine the validity 
of your logical tests.  Also, particularly when starting, it is known 
that negatives often lead to confusion, with use of multiple negatives 
leading to even more confusion.  Next time, try eliminating the 
negatives and look for a positive test when you have this kind of issue. 
 Then you might have written:


if nummer == reeks[-1] and nummer == reeks[-2]:
  print "it's the same as the prior two"
else:
  reeks.append(nummer)

HTH,

Emile





reeks.append(nummer)
else:
print 'Nummer: ', nummer, 'is gelijk aan vorige 2 nummers: ', reeks[-1],
'&', reeks[-2], '!'
print '\n'
print reeks

When I run that, I can see there's something wrong with my if statement,
it triggers the else condition even when the 2 previous numbers in my
list are not the same... I'm not sure what is happening here...



___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help understanding output...

2010-08-11 Thread Steven D'Aprano
On Thu, 12 Aug 2010 07:04:15 am Laurens Vets wrote:

> I need to generate a list of 30 numbers randomly chosen from 1, 2, 3,
> 4, 5 & 6. However, I cannot have more than 2 numbers which are the
> same next to each other. I came up with the following (Please ignore 
> the fact that I'm trying to avoid an IndexError in a stupid way :)):

I can't possible do that! :)


> import random
> reeks = []
> while len(reeks) <= 1:
>number = random.randrange(1, 7, 1)
>reeks.append(number)
>
> while len(reeks) <= 29:
>nummer = random.randrange(1, 7, 1)
>if nummer != reeks[-1] and nummer != reeks[-2]:
>  reeks.append(nummer)
> print reeks

This is probably a simpler way:


import random
reeks = []
for i in range(30):
temp = [random.randint(1, 6)]
while reeks[-2:-1] == reeks[-1:] == temp:
# print "Triplet found:", reeks, temp
temp = [random.randint(1, 6)]
reeks.extend(temp)

print reeks

Note that you can avoid dealing with IndexError by extracting slices and 
comparing lists.


> However, I wanted to look deeper in the above script and I created
> the following:
[...]
>if nummer != reeks[-1] and nummer != reeks[-2]:
>  reeks.append(nummer)
>else:
>  print 'Nummer: ', nummer, 'is gelijk aan vorige 2 nummers: ',
> reeks[-1], '&', reeks[-2], '!'
>print '\n'
> print reeks
>
> When I run that, I can see there's something wrong with my if
> statement, it triggers the else condition even when the 2 previous
> numbers in my list are not the same...  I'm not sure what is
> happening here...

nummer != reeks[-1] and nummer != reeks[-2]

gives a true result if all three numbers are different, otherwise it 
gives a false result.

Negative conditions are often hard to reason with. It might be better to 
write that as:

nummer == reeks[-1] and nummer == reeks[-2]

and swap the if/else clauses. But even better is to use Python's chained 
comparisons, and write:

nummer == reeks[-1] == reeks[-2]




-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem loading and array from an external file

2010-08-11 Thread Bill Allen
On Tue, Aug 10, 2010 at 9:59 AM, bob gailer  wrote:
> On 8/10/2010 10:42 AM, Bill Allen wrote:
>>
>> Bob,
>>
>> I was really off on that algorithm and had way over complicated it.
>> I have it working correctly now, but for the sake of those who saw my
>> earlier really botched code, here is the resultant code that works.
>> The entire inner loop and intermediate variables are removed, but
>> shown commented out.  I had somehow thought I needed to read each
>> member of each subarray in individually.  That was not the case and
>> that inner loop was overwriting the array.
>>
>> # reads one line at a time from file and puts data into array
>>     for line in textf:
>>         #tempwords = line.split(None)
>>         #for n in range(0, len(room)-1):
>>         #    roomx[n] = tempwords[n]
>>         #room[m] = roomx
>>         room[m] = line.split(None)
>>         m += 1
>>
>>
>
> Great. Good work. Teach a man to fish?
>
> Now for the refinements. First you can use enumerate to obtain the room
> index:
>
>    for m, line in enumerate(textf):
>        room[m] = line.split(None)
>
>
> Second you can start with an empty list and append:
>
>    rooms = []
>    for line in textf:
>        rooms.append(line.split(None))
>
> Third you can use list comprehension:
>
>    rooms = [line.split(None) for line in textf]
>
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
>

Bob,

Great pointer!

I had not gotten back on the email until just now.  I figured out the
second method today on my own.  That third method is fascinating.  I
have not heard of "list comprehension" before.  That must be unique
Python lingo.  What is the principle behind that?

Thanks for the help.

Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem loading and array from an external file

2010-08-11 Thread Bill Allen
On Tue, Aug 10, 2010 at 11:11 AM, Hugo Arts  wrote:
> On Tue, Aug 10, 2010 at 9:59 AM, bob gailer  wrote:
>> On 8/10/2010 10:42 AM, Bill Allen wrote:
>>>
>>> Bob,
>>>
>>> I was really off on that algorithm and had way over complicated it.
>>> I have it working correctly now, but for the sake of those who saw my
>>> earlier really botched code, here is the resultant code that works.
>>> The entire inner loop and intermediate variables are removed, but
>>> shown commented out.  I had somehow thought I needed to read each
>>> member of each subarray in individually.  That was not the case and
>>> that inner loop was overwriting the array.
>>>
>>> # reads one line at a time from file and puts data into array
>>>     for line in textf:
>>>         #tempwords = line.split(None)
>>>         #for n in range(0, len(room)-1):
>>>         #    roomx[n] = tempwords[n]
>>>         #room[m] = roomx
>>>         room[m] = line.split(None)
>>>         m += 1
>>>
>>>
>>
>> Great. Good work. Teach a man to fish?
>>
>> Now for the refinements. First you can use enumerate to obtain the room
>> index:
>>
>>    for m, line in enumerate(textf):
>>        room[m] = line.split(None)
>>
>>
>> Second you can start with an empty list and append:
>>
>>    rooms = []
>>    for line in textf:
>>        rooms.append(line.split(None))
>>
>> Third you can use list comprehension:
>>
>>    rooms = [line.split(None) for line in textf]
>>
>
> Nice going, this is the best way of getting your answer from the
> tutors list IMO, high fives all around. I wish more threads went like
> this.
>
> You don't actually have to specify the None in line.split AFAIK, but
> it might be better to be explicit. thoughts on this, anyone?
>
> Hugo
>

Hugo,

I had wondered about the use of None in that context.  I had seen it
used that way in some examples and just followed suit.  Just do
line.split() ?

Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scripting Blender

2010-08-11 Thread Lee Harr

> Are there any Python modules to script Blender? For example, placing
> predefined objects into a new Blender project to create a 3D model.


If you are using 2.5, I saw this posted on blendernation.com
just today:

http://blenderartists.org/forum/showthread.php?t=193908

  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem loading and array from an external file

2010-08-11 Thread Alan Gauld


"Bill Allen"  wrote


second method today on my own.  That third method is fascinating.  I
have not heard of "list comprehension" before.  That must be unique
Python lingo.  What is the principle behind that?


Its not unique to Python, Haskell had it first.
It is based on mathematical set notation, you can define a set of
numbers using a (somewhat) similar construct.

You will find a basic description in the Functional Programming
topic of my tutorial.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Module for browsing Windows?

2010-08-11 Thread Alan Gauld


"Chorn, Guillaume"  wrote


there is a Python module out there that allows you to browse to and
select files using a Windows-style interface.  Thanks!



EasyGUI is designed for exactly that kind of mixed mode programming.

You can find a basic intro in the Talking to the User topic 
of my tutorial.


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing Python from TCL

2010-08-11 Thread Alan Gauld


"Karim"  wrote 


I want to know if there are modules or whatever to execute
python functions inside TCL.


Not that I know of, unless Google tells you something different.
You can of course call Python programs from Tcl and vice-versa. 
If you use the Java versions of both you might succeed.


Or you could wrap your parser as a separate server process 
and expose it as a Web service or XML RPC...


But given the wealth of xml parsers available for Tcl I'm 
surprised that they need yours...



These functions should returns python lists as TCL lists and
Python dictionary as TCL Hash tables.


You could probably do some C level integration using Boost 
or SWIG or somesuch but I doubt the benefit would be worth 
it.


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help understanding output...

2010-08-11 Thread Alan Gauld


"Laurens Vets"  wrote

next to each other. I came up with the following (Please ignore the 
fact that I'm trying to avoid an IndexError in a stupid way :)):


Others have answered your question.

I'll suggest that instead of using indexes its easier to just cache 
the

last two values in variables - back1 and back2 say.
initialise them to values outside the range for the first two values
then the loop body becomes (in pseudo code)

x = random number
if x == back1 == back2:   # a triple
print 'error'
else
  back2,back1 = back1,x
  append(x)

HTH,

Alan G. 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem loading and array from an external file

2010-08-11 Thread Bill Allen
On Wed, Aug 11, 2010 at 6:59 PM, Alan Gauld wrote:

>
>
> You will find a basic description in the Functional Programming
> topic of my tutorial.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
Alan,

Awesome website!   Thanks!

I have a buddy that is also working on learning Python with me, I will
definitely point him there.

Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem loading and array from an external file

2010-08-11 Thread Luke Paireepinart
Don't pass none. It's an optional parameter. It's accepted practice to not pass 
optional parameters.

Sent from my iPhone

On Aug 11, 2010, at 6:46 PM, Bill Allen  wrote:

> On Tue, Aug 10, 2010 at 11:11 AM, Hugo Arts  wrote:
>> On Tue, Aug 10, 2010 at 9:59 AM, bob gailer  wrote:
>>> On 8/10/2010 10:42 AM, Bill Allen wrote:
 
 Bob,
 
 I was really off on that algorithm and had way over complicated it.
 I have it working correctly now, but for the sake of those who saw my
 earlier really botched code, here is the resultant code that works.
 The entire inner loop and intermediate variables are removed, but
 shown commented out.  I had somehow thought I needed to read each
 member of each subarray in individually.  That was not the case and
 that inner loop was overwriting the array.
 
 # reads one line at a time from file and puts data into array
 for line in textf:
 #tempwords = line.split(None)
 #for n in range(0, len(room)-1):
 #roomx[n] = tempwords[n]
 #room[m] = roomx
 room[m] = line.split(None)
 m += 1
 
 
>>> 
>>> Great. Good work. Teach a man to fish?
>>> 
>>> Now for the refinements. First you can use enumerate to obtain the room
>>> index:
>>> 
>>>for m, line in enumerate(textf):
>>>room[m] = line.split(None)
>>> 
>>> 
>>> Second you can start with an empty list and append:
>>> 
>>>rooms = []
>>>for line in textf:
>>>rooms.append(line.split(None))
>>> 
>>> Third you can use list comprehension:
>>> 
>>>rooms = [line.split(None) for line in textf]
>>> 
>> 
>> Nice going, this is the best way of getting your answer from the
>> tutors list IMO, high fives all around. I wish more threads went like
>> this.
>> 
>> You don't actually have to specify the None in line.split AFAIK, but
>> it might be better to be explicit. thoughts on this, anyone?
>> 
>> Hugo
>> 
> 
> Hugo,
> 
> I had wondered about the use of None in that context.  I had seen it
> used that way in some examples and just followed suit.  Just do
> line.split() ?
> 
> Bill
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem loading and array from an external file

2010-08-11 Thread Bill Allen
On Wed, Aug 11, 2010 at 10:09 PM, Luke Paireepinart
wrote:

> Don't pass none. It's an optional parameter. It's accepted practice to not
> pass optional parameters.
>
> Sent from my iPhone
>
> On Aug 11, 2010, at 6:46 PM, Bill Allen  wrote:
>
> >>
> >> You don't actually have to specify the None in line.split AFAIK, but
> >> it might be better to be explicit. thoughts on this, anyone?
> >>
> >> Hugo
> >>
> >
> > Hugo,
> >
> > I had wondered about the use of None in that context.  I had seen it
> > used that way in some examples and just followed suit.  Just do
> > line.split() ?
> >
> > Bill
>
> Luke,

Thanks for the confirmation on not passing None.

Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] a graceful program exit

2010-08-11 Thread Bill Allen
I have only learned a couple of ways to cause a Python program to exit:
sys.exit(0)  &  raise.SystemExit .  I am using this in a try/except block.
Which is preferred?  Are there other, better ways?


Thanks,
Bill Allen
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a graceful program exit

2010-08-11 Thread James Mills
On Thu, Aug 12, 2010 at 1:42 PM, Bill Allen  wrote:
> I have only learned a couple of ways to cause a Python program to exit:
> sys.exit(0)  &  raise.SystemExit .  I am using this in a try/except block.
> Which is preferred?  Are there other, better ways?

The normal pattern is to have an entry point and an exit point.

main() and SystemExit exception.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Executing Python from TCL

2010-08-11 Thread Karim


Hello Alan,

I want to take benefit of xml.etree.ElementTree and 
xml.etree.CElementTree, which are very
good and do most of the job for me (create automatically database with 
lists and dictionary for me).
My point is to do a same API used by team developing with Python and 
another team developing in TCL. I want to facilitate the reuse and make 
everybody happy (no war between the 2 languages supporters) though for 
me Python is largely superior.


Anyway, you're right I found what I needed at:

http://sourceforge.net/projects/elmer/files/elmer/elmer1.1.5/elmer1.1.5.tar.gz/download

This is the open source Elmer distribution.

Thanks
Karim

On 08/12/2010 02:13 AM, Alan Gauld wrote:


"Karim"  wrote

I want to know if there are modules or whatever to execute
python functions inside TCL.


Not that I know of, unless Google tells you something different.
You can of course call Python programs from Tcl and vice-versa. If you 
use the Java versions of both you might succeed.


Or you could wrap your parser as a separate server process and expose 
it as a Web service or XML RPC...


But given the wealth of xml parsers available for Tcl I'm surprised 
that they need yours...



These functions should returns python lists as TCL lists and
Python dictionary as TCL Hash tables.


You could probably do some C level integration using Boost or SWIG or 
somesuch but I doubt the benefit would be worth it.


HTH,




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Performance list vs. deque for [-1]

2010-08-11 Thread Knacktus

Hi everyone,

I'm wondering what's the fastet datatype in python to lookup the last 
element in an ordered collection. I know about lists, of course, and 
read about deques. As I understand deques have better performance for 
popping and adding elements, but I didn't understand what's the behavior 
for look-up's without any changes to the collection.


I will not pop() out of my ordered collection, and only recently append. 
Also, the collections will be small (about 10-20 elements), but I will 
have huge amount (5-10) of those collections which need to be 
processed for certain tasks in my application.


Thanks in advance and cheers,

Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a graceful program exit

2010-08-11 Thread Hugo Arts
On Wed, Aug 11, 2010 at 11:06 PM, James Mills
 wrote:
> On Thu, Aug 12, 2010 at 1:42 PM, Bill Allen  wrote:
>> I have only learned a couple of ways to cause a Python program to exit:
>> sys.exit(0)  &  raise.SystemExit .  I am using this in a try/except block.
>> Which is preferred?  Are there other, better ways?
>
> The normal pattern is to have an entry point and an exit point.
>
> main() and SystemExit exception.
>
> cheers
> James
>

I usually just have the top of the program as entry point, and the
bottom as exit. I like the simplicity.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor